This commit is contained in:
kindlm
2016-08-01 13:48:20 +02:00
8 changed files with 314 additions and 42 deletions
@@ -0,0 +1,262 @@
<?php
/**
* FH-Complete
*
* @package FHC-API
* @author FHC-Team
* @copyright Copyright (c) 2016, fhcomplete.org
* @license GPLv3
* @link http://fhcomplete.org
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
if(!defined("BASEPATH")) exit("No direct script access allowed");
class PCRM extends APIv1_Controller
{
// Black list of resources that are no allowed to be used
private static $RESOURCES_BLACK_LIST = array("LogLib", "FilesystemLib", "MigrationLib", "REST_Controller");
/**
* Message API constructor.
*/
public function __construct()
{
parent::__construct();
}
/**
* @return void
*/
public function getCall()
{
$parameters = $this->_getParameters($this->get());
$validation = $this->_validateCall($parameters);
// If the validation was passed
if($validation->error == EXIT_SUCCESS)
{
$loaded = null;
// Check if the resource is already loaded, it works only with libraries and drivers
if (($loaded = $this->load->is_loaded($parameters->resourceName)) === false)
{
// If the given resource is a model
if(strpos($parameters->resourceName, "_model") !== false)
{
try
{
// Try to load it
$loaded = $this->load->model($parameters->resourcePath . $parameters->resourceName);
}
catch(Exception $e)
{
// Errors while loading the model
$loaded = null;
$result = $this->_error($e->getMessage());
}
}
// If the given resource is a library
else if(strpos($parameters->resourceName, "Lib") !== false)
{
// The method "library" of the class CI_Loader provided by CI has some limitations,
// so to be able to check errors was used this workaround
try
{
// Gets all the configured resources paths
$packagePaths = $this->load->get_package_paths();
// Looking for a file in every paths with the same name of the resource
$found = null;
for ($i = 0; $i < count($packagePaths) && is_null($found); $i++)
{
if (file_exists($packagePaths[$i] . "libraries/" . $parameters->resourcePath . $parameters->resourceName . ".php"))
{
$found = $packagePaths[$i] . "libraries/" . $parameters->resourcePath . $parameters->resourceName . ".php";
}
}
// If the file was found
if (!is_null($found))
{
// Load the file
$loaded = $this->load->file($found);
// If the resource is not present inside the file
if (!class_exists($parameters->resourceName))
{
$loaded = null;
// Same phrase error as load->model()
$result = $this->_error($found . " exists, but doesn't declare class " . $parameters->resourceName);
}
}
else
{
$loaded = null;
// Same phrase error as load->model()
$result = $this->_error("Unable to load the requested class: " . $parameters->resourceName);
}
}
catch(Exception $e)
{
$result = $this->_error($e->getMessage());
}
}
// Wrong selection!
else
{
$result = $this->_error("Neither a lib nor model: " . $parameters->resourcePath . $parameters->resourceName);
}
}
// If the resource was found and loaded
if(!is_null($loaded))
{
try
{
// Get informations about the function
$reflectionMethod = new ReflectionMethod($parameters->resourceName, $parameters->function);
// If the number of given parameters is equal to the number of parameters required by the function
if ($reflectionMethod->getNumberOfRequiredParameters() == count($parameters->parameters))
{
// If the function is static
if ($reflectionMethod->isStatic() === true)
{
$classMethod = $parameters->resourceName . "::" . $parameters->function;
}
// If the function is not static
else
{
$classMethod = array(new $parameters->resourceName(), $parameters->function);
}
// If the function of that resource is callable
if(is_callable($classMethod))
{
// Call resource->function()
$resultCall = @call_user_func_array($classMethod, $parameters->parameters);
// If errors occurred while running it
if($resultCall === false)
{
$result = $this->_error("Error running " . $parameters->resourceName . "->" . $parameters->function . "()");
}
// Returns the result of resource->function()
else
{
$result = $resultCall;
}
}
else
{
$result = $this->_error($parameters->resourceName . "->" . $parameters->function . "() is not callable!");
}
}
else
{
$result = $this->_error("Wrong parameters number");
}
}
catch(Exception $e)
{
$result = $this->_error($e->getMessage());
}
}
}
else
{
$result = $validation;
}
// Print the result
$this->response($result, REST_Controller::HTTP_OK);
}
/**
* @return void
*/
public function postCall()
{
$validation = $this->_validatePostMessage($this->post());
if(is_object($validation) && $validation->error == EXIT_SUCCESS)
{
$result = $this->messagelib->sendMessage(
$this->post()['person_id'], $this->post()['subject'], $this->post()['body'], PRIORITY_NORMAL, $this->post()['relationmessage_id'], $this->post()['oe_kurzbz']
);
$this->response($result, REST_Controller::HTTP_OK);
}
else
{
$this->response($validation, REST_Controller::HTTP_OK);
}
}
/**
* Gets the parameters from the call
*/
private function _getParameters($parametersArray)
{
$parameters = new stdClass();
$parameters->parameters = array();
$count = 0;
foreach($parametersArray as $parameterName => $parameterValue)
{
// The name of the resource, path included
if($parameterName == "resource")
{
// Separates the resource path from the resource name
$splittedResource = preg_split("/\//", $parameterValue);
$parameters->resourceName = $splittedResource[count($splittedResource) - 1];
$parameters->resourcePath = str_replace($parameters->resourceName, "", $parameterValue);
}
// The name of the function
else if($parameterName == "function")
{
$parameters->function = $parameterValue;
}
// It is assumed that all other parameters are parameters to be passed to the function
// They will be passed to the function in the same order in which they are passed to
// this controller
else
{
$parameters->parameters[$count++] = $parameterValue;
}
}
return $parameters;
}
/**
* Validate the given parameters
*/
private function _validateCall($parameters)
{
if (!is_object($parameters))
{
return $this->_error("Parameter is not an object");
}
if (!isset($parameters->resourcePath))
{
return $this->_error("Resource path is not specified");
}
if (!isset($parameters->resourceName))
{
return $this->_error("Resource name is not specified");
}
if (!isset($parameters->function))
{
return $this->_error("Function is not specified");
}
if (!is_array($parameters->parameters))
{
return $this->_error("Parameters are not specified");
}
if (in_array($parameters->resourceName, PCRM::$RESOURCES_BLACK_LIST))
{
return $this->_error("You are trying to access to unauthorized resources");
}
return $this->_success("Input data are valid");
}
}
@@ -54,10 +54,11 @@ class Phrase extends APIv1_Controller
$phrase = $this->get('phrase');
$orgeinheit_kurzbz = $this->get('orgeinheit_kurzbz');
$orgform_kurzbz = $this->get('orgform_kurzbz');
$blockTags = $this->get('blockTags');
if (isset($app) && isset($sprache))
{
$result = $this->phraseslib->getPhrases($app, $sprache, $phrase, $orgeinheit_kurzbz, $orgform_kurzbz);
$result = $this->phraseslib->getPhrases($app, $sprache, $phrase, $orgeinheit_kurzbz, $orgform_kurzbz, $blockTags);
$this->response($result, REST_Controller::HTTP_OK);
}
+14 -2
View File
@@ -111,7 +111,7 @@ class PhrasesLib
*
* @return struct
*/
function getPhrases($app, $sprache, $phrase = null, $orgeinheit_kurzbz = null, $orgform_kurzbz = null)
function getPhrases($app, $sprache, $phrase = null, $orgeinheit_kurzbz = null, $orgform_kurzbz = null, $blockTags = null)
{
if (isset($app) && isset($sprache))
{
@@ -123,7 +123,19 @@ class PhrasesLib
for ($i = 0; $i < count($result->retval); $i++)
{
$result->retval[$i]->text = $parser->textileThis($result->retval[$i]->text);
// If no <p> tags required
if ($blockTags == "no")
{
// Removes tags <p> and </p> from the beginning and from the end of the string
$tmpText = $parser->textileThis($result->retval[$i]->text);
$tmpText = substr($tmpText, 3, strlen($tmpText));
$tmpText = substr($tmpText, 0, strlen($tmpText) - 4);
$result->retval[$i]->text = $tmpText;
}
else
{
$result->retval[$i]->text = $parser->textileThis($result->retval[$i]->text);
}
}
}
}
+1 -1
View File
@@ -86,7 +86,7 @@
"json-forms": "1.4.0",
"wikimedia/composer-merge-plugin": "^1.3",
"fzaninotto/faker": "1.*",
"netcarver/textile": "3.5.*"
"netcarver/textile": "^3.5"
},
"require-dev":
{
+26 -31
View File
@@ -68,22 +68,6 @@ foreach($prestudent_ids as $pid)
if(!$prestudent->load($pid))
cleanUpAndDie($p->t('tools/studentWurdeNichtGefunden')."(".$pid.")", $tmpDir);
/*
* Deckblatt
*/
$filename = $tmpDir . "/".uniqid();
$doc = new dokument_export('Bewerberakt');
$doc->addDataArray(array('vorname' => $prestudent->vorname, 'nachname' => $prestudent->nachname),'bewerberakt');
if(!$doc->create('pdf'))
die($doc->errormsg);
// $doc->temp_filename = $filename;
$document = $doc->output(false);
$filename = $tmpDir.'/'.uniqid();
file_put_contents($filename, $document);
$doc->close();
$allDocs[] = $filename;
/*
* Get all Documents
@@ -100,31 +84,29 @@ foreach($prestudent_ids as $pid)
AND prestudent_id='.$db->db_add_param($pid, FHC_INTEGER).';
';
$preDocs = array();
$result = $db->db_query($query);
while($row = $db->db_fetch_object($result))
{
$filename = "";
if($row->dms_id != null)
if($row->inhalt != null)
{
$filename = $tmpDir . "/".uniqid();
$fileData = base64_decode($row->inhalt);
file_put_contents($filename, $fileData);
}
else if($row->dms_id != null)
{
$dms = new dms();
$dms->load($row->dms_id);
$filename = DMS_PATH . $dms->filename;
}
else if($row->inhalt != null)
{
$filename = $tmpDir . "/".uniqid();
$fileData = base64_decode($row->inhalt);
file_put_contents($filename, $fileData);
}
if($filename == "")
continue;
/*
* Determine the filetype
* and convert, if nessecary
@@ -146,18 +128,31 @@ foreach($prestudent_ids as $pid)
{
$fullFilename = $row->titel;
}
else
cleanUpAndDie("falscher typ TODO", $tmpDir);
// only filled, if the file is supported
if($fullFilename != "")
{
$allDocs[] = $fullFilename;
$preDocs[] = $fullFilename;
}
}
}
/*
* Deckblatt
*/
$filename = $tmpDir . "/".uniqid();
$doc = new dokument_export($_GET["vorlage_kurzbz"]);
$doc->addDataArray(array('vorname' => $prestudent->vorname, 'nachname' => $prestudent->nachname),"bewerberakt");
if(!$doc->create('pdf'))
die($doc->errormsg);
$filename = $tmpDir.'/'.uniqid();
file_put_contents($filename, $doc->output(false));
$doc->close();
$allDocs[] = $filename;
$allDocs = array_merge($allDocs, $preDocs);
unset($doc);
}
/*
* generate the merged PDF
+7 -5
View File
@@ -168,7 +168,7 @@ class dokument_export
$contentbuffer = $proc->transformToXml($this->xml_data);
$this->temp_folder = '/tmp/fhcunoconv-'.uniqid();
$this->temp_folder = sys_get_temp_dir().'/fhcunoconv-'.uniqid();
mkdir($this->temp_folder);
chdir($this->temp_folder);
file_put_contents('content.xml', $contentbuffer);
@@ -201,7 +201,8 @@ class dokument_export
if(!$vorlage_found)
$zipfile = DOC_ROOT.'system/vorlage_zip/'.$this->vorlage_file;
$tempname_zip = 'out.zip';
$tempname_zip = $this->temp_folder . '/out.zip';
if(!copy($zipfile, $tempname_zip))
die('copy failed');
@@ -254,8 +255,9 @@ class dokument_export
switch($this->outputformat)
{
case 'pdf':
$this->temp_filename='out.pdf';
$this->temp_filename = $this->temp_folder . '/out.pdf';
exec("unoconv -e IsSkipEmptyPages=false --stdout -f pdf $tempname_zip > ".$this->temp_filename, $out, $ret);
if($ret!=0)
{
$this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte informieren Sie den Administrator';
@@ -341,8 +343,9 @@ class dokument_export
if($this->styles_xsl!='')
unlink('styles.xml');
unlink('out.zip');
unlink($this->temp_filename);
if(file_exists("out.zip"))
unlink('out.zip');
if(count($this->images)>0)
{
@@ -406,7 +409,6 @@ class dokument_export
$command = 'unoconv --format %s --output %s %s';
$command = sprintf($command, $format, $outFile, $inFile);
exec($command, $out, $ret);
if($ret!=0)
{
+1 -1
View File
@@ -44,7 +44,7 @@ class Pdf
}
if(finfo_file($finfo, $f) != "application/pdf")
{
$this->errormsg = "Wrong format: '$f'";
$this->errormsg = "Wrong format(".finfo_file($finfo, $f)."): '$f'";
return false;
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn
<xsl:output method="xml" version="1.0" indent="yes"/>
<xsl:template match="bewerberakt">
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2"><office:scripts/><office:font-face-decls><style:font-face style:name="Liberation Serif" svg:font-family="&apos;Liberation Serif&apos;" style:font-family-generic="roman" style:font-pitch="variable"/><style:font-face style:name="Liberation Sans" svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/><style:font-face style:name="DejaVu Sans" svg:font-family="&apos;DejaVu Sans&apos;" style:font-family-generic="system" style:font-pitch="variable"/></office:font-face-decls><office:automatic-styles><style:style style:name="P1" style:family="paragraph" style:parent-style-name="Heading_20_1"><style:paragraph-properties fo:text-align="center" style:justify-single-word="false"/></style:style><style:style style:name="P2" style:family="paragraph" style:parent-style-name="Standard"><style:text-properties officeooo:rsid="0003bc74" officeooo:paragraph-rsid="0003bc74"/></style:style></office:automatic-styles><office:body><office:text><text:sequence-decls><text:sequence-decl text:display-outline-level="0" text:name="Illustration"/><text:sequence-decl text:display-outline-level="0" text:name="Table"/><text:sequence-decl text:display-outline-level="0" text:name="Text"/><text:sequence-decl text:display-outline-level="0" text:name="Drawing"/></text:sequence-decls><text:p text:style-name="Title">Bewerberakt</text:p><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:h text:style-name="P1" text:outline-level="1"><xsl:value-of select="vorname" /> <xsl:value-of select="nachname" /></text:h></office:text></office:body></office:document-content>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2"><office:scripts/><office:font-face-decls><style:font-face style:name="Liberation Serif" svg:font-family="&apos;Liberation Serif&apos;" style:font-family-generic="roman" style:font-pitch="variable"/><style:font-face style:name="Liberation Sans" svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/><style:font-face style:name="DejaVu Sans" svg:font-family="&apos;DejaVu Sans&apos;" style:font-family-generic="system" style:font-pitch="variable"/></office:font-face-decls><office:automatic-styles><style:style style:name="P1" style:family="paragraph" style:parent-style-name="Heading_20_1"><style:paragraph-properties fo:text-align="center" style:justify-single-word="false"/></style:style><style:style style:name="P2" style:family="paragraph" style:parent-style-name="Standard"><style:text-properties officeooo:rsid="0003bc74" officeooo:paragraph-rsid="0003bc74"/></style:style></office:automatic-styles><office:body><office:text><text:sequence-decls><text:sequence-decl text:display-outline-level="0" text:name="Illustration"/><text:sequence-decl text:display-outline-level="0" text:name="Table"/><text:sequence-decl text:display-outline-level="0" text:name="Text"/><text:sequence-decl text:display-outline-level="0" text:name="Drawing"/></text:sequence-decls><text:p text:style-name="Title">Bewerberakt</text:p><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:h text:style-name="P1" text:outline-level="1"><xsl:value-of select="vorname" /><xsl:text> </xsl:text><xsl:value-of select="nachname" /></text:h></office:text></office:body></office:document-content>
</xsl:template>