Example #1
0
 function __construct($pharName)
 {
     echo "<pre>";
     $buildRoot = realpath(Ruth::getDOCUMENT_ROOT() . "/../build");
     $srcRoot = realpath(Ruth::getDOCUMENT_ROOT());
     echo "Building {$pharName}.phar to " . $buildRoot . "\n";
     echo "Source: {$srcRoot} \n";
     echo "Have you cleaned up the path yet ?";
     //clean up things
     $phar = new Phar($buildRoot . "/" . $pharName . ".phar", FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, $pharName . ".phar");
     $phar["index.php"] = file_get_contents($srcRoot . "/index.php");
     $phar->buildFromDirectory($srcRoot);
     $phar->setStub('<?php Phar::webPhar(); __HALT_COMPILER();');
     echo "<pre>";
 }
Example #2
0
 /**
  * The constructor for Reta
  * @param String $reportPath Relative to the document root
  * @param String $outputPath Relative to the document root
  * @param String $iniFile Path to the iniFile, normally is in the same folder as reta, but you may want more.
  * @param String $retaPath Path to reta if the system can't determine it, usually one folder below the document root
  */
 function __construct($reportPath = "reports", $outputPath = "output", $iniFile = "reta.ini", $retaPath = "")
 {
     $this->reportPath = Ruth::getDOCUMENT_ROOT() . "/" . $reportPath;
     $this->outputPath = Ruth::getDOCUMENT_ROOT() . "/" . $outputPath;
     $this->iniFile = $iniFile;
     if (empty($retaPath)) {
         $this->retaPath = realpath(Ruth::getDOCUMENT_ROOT() . '/../reta') . '/reta.exe';
         $this->iniFile = realpath(Ruth::getDOCUMENT_ROOT() . '/../reta') . '/reta.ini';
     } else {
         $this->retaPath = $retaPath;
     }
     if (!file_exists($this->iniFile)) {
         echo "<pre>";
         echo "Please setup a reta.ini in the same folder as {$this->retaPath}  for reporting to work:\n";
         echo "[Database]\nProtocol=firebird-2.5,sqlite-3,mysql\nHostName=127.0.0.1\nPath={DBPATH}\nUser=SYSDBA\nPassword=masterkey\n";
         die;
     }
     //Check if we may be on Linux - then we need to run the shell script
     if (PHP_OS === 'Linux') {
         $this->retaPath = str_replace(".exe", ".sh", $this->retaPath);
         $this->iniFile = "z:" . $this->iniFile;
     }
 }
Example #3
0
 function getCodeNavigator()
 {
     $content = div(["id" => "codeNavigator", "title" => "Navigator"], $this->getFileTree(Ruth::getDOCUMENT_ROOT()));
     $content .= script("\$(function() {  \$('#codeNavigator').dialog({position:{my: '0 0', at: 'left bottom', of: \$('#fileExplorer') }, height:400 }); } );");
     return $content;
 }
Example #4
0
 function updateMigration()
 {
     $fileName = Ruth::getDOCUMENT_ROOT() . "/" . $this->migrationPath . "/" . date("Ymdhis") . " " . Ruth::getREQUEST("txtDESCRIPTION") . ".sql";
     file_put_contents($fileName, Ruth::getREQUEST("txtSQL"));
     Ruth::setSESSION("maggyCreateMessage", "{$fileName} created successfully!");
     Ruth::redirect("/maggy/create");
 }
Example #5
0
 function parseTemplate($template, $data = "", $respond = false)
 {
     //echo "Parsing {$template} <br>";
     try {
         //get a checksum for the template
         $checkSum = "template" . md5($template . print_r($data, 1));
         if (TINA4_HAS_CACHE && !empty(xcache_get($checkSum)) && !empty($data)) {
             //echo "Loading from Cache <br>";
             $template = xcache_get($checkSum);
             //echo "Getting template for ".print_r ($data);
             if (strpos("{", $template) === false) {
                 return $template;
             }
             //TODO: work out how to refresh cache dynamically
         } else {
             //first eval the template . this will load code parts into memory which are PHP code.
             $assetFolder = Ruth::getDOCUMENT_ROOT() . "/assets/";
             foreach ($this->defaultExtensions as $eid => $extension) {
                 if (file_exists($assetFolder . $template . $extension)) {
                     $template = file_get_contents($assetFolder . $template . $extension);
                     if (TINA4_HAS_CACHE && !empty($data) && strpos($template, "{{") === false) {
                         xcache_set($checkSum, $template);
                     }
                     break;
                 }
             }
         }
         $originalTemplate = $template;
         //get PHP code snippets
         //We can parse out all the stuff on the first run
         if (strpos($template, "<?php") !== false) {
             $code = explode("<?php", $template);
             $snippets = "";
             $template = "";
             foreach ($code as $cid => $codeValue) {
                 $codeValue = explode('?>', $codeValue);
                 if (count($codeValue) > 1) {
                     $snippets .= $codeValue[0] . "\n";
                 } else {
                     $template .= $codeValue[0];
                 }
                 if (!empty($codeValue[1])) {
                     $template .= $codeValue[1];
                 }
             }
             eval($snippets);
         }
         if (strpos($template, "{") !== false) {
             //then variables, global & local, local will be first
             foreach (get_defined_vars() as $varName => $varValue) {
                 if (!is_object($varValue) && $varName !== "template" && $varName !== "data" && $varName !== "originalTemplate") {
                     if (is_array($varValue)) {
                         foreach ($varValue as $vName => $vValue) {
                             $template = $this->parseValue("{" . $vName . "}", $vValue, $template);
                         }
                     } else {
                         $template = $this->parseValue("{" . $varName . "}", $varValue, $template);
                     }
                 }
             }
             //then defines
             foreach (get_defined_constants() as $varName => $varValue) {
                 if (!is_object($varValue)) {
                     if (is_array($varValue)) {
                         foreach ($varValue as $vName => $vValue) {
                             $template = $this->parseValue("{" . $vName . "}", $vValue, $template);
                         }
                     } else {
                         $template = $this->parseValue("{" . $varName . "}", $varValue, $template);
                     }
                 }
             }
         }
         $elements = null;
         $template = str_replace(" {{", "\n{{", $template);
         $template = str_replace("}} ", "}}\n", str_replace("}}\n", "}} ", $template));
         preg_match_all('/{{(.*)}}/i', $template, $elements, PREG_OFFSET_CAPTURE);
         //then see about parsing methods & functions
         $parsedSnippets = $this->parseSnippets($elements[1], $template, $data);
         //Reset the elements & template to the parsed elements
         $elements = $parsedSnippets["elements"];
         $controls = $parsedSnippets["controls"];
         $template = $parsedSnippets["template"];
         //print_r ($controls);
         if (!empty($controls)) {
             $ifResult = "";
             foreach ($controls as $cid => $control) {
                 //go through all the ifs
                 if (empty($control["if"])) {
                     continue;
                 }
                 $found = false;
                 foreach ($control["if"] as $ifId => $ifStatement) {
                     if (!empty($ifStatement["expression"])) {
                         $myIf = '$expression = (' . $ifStatement["expression"] . ');';
                         if (!empty($data)) {
                             preg_match_all('/{([a-zA-Z0-9\\_\\-\\>\\[\\]\\"]+)}/i', $myIf, $variables);
                             foreach ($variables[1] as $index => $variable) {
                                 if (!empty($data->{$variable})) {
                                     $varValue = $data->{$variable};
                                     $myIf = $this->parseValue("{" . $variable . "}", $varValue, $myIf);
                                 }
                             }
                         }
                         @eval($myIf);
                         if (!empty($expression)) {
                             if ($expression) {
                                 $found = true;
                                 //TODO: Optimize
                                 $ifResult = $this->parseTemplate($ifStatement["code"], $data);
                                 break;
                             }
                         }
                     }
                 }
                 if (!$found && !empty($control["else"]["code"])) {
                     //TODO: Optimize
                     $ifResult = $this->parseTemplate($control["else"]["code"], $data);
                 }
                 //if we didn't get a true above then result as else
                 $template = str_replace($control["ifTag"], $ifResult, $template);
             }
         }
         if (!empty($elements)) {
             $response = [];
             foreach ($elements as $eid => $element) {
                 $elementParts = explode(":", $element[0]);
                 $elementHash = md5(print_r($element[0], 1));
                 $response[$elementHash] = "";
                 switch ($elementParts[0]) {
                     case "call":
                         $callParts = explode("?", $elementParts[1]);
                         if (!empty($callParts[1])) {
                             $params = $this->getCallParams($callParts[1]);
                         } else {
                             $params = [];
                         }
                         if (function_exists($callParts[0])) {
                             $response[$elementHash] = call_user_func_array($callParts[0], $params);
                         } else {
                             $response[$elementHash] = "Function: {$callParts[0]} not found";
                         }
                         break;
                     case "include":
                         //include a template file.
                         $response[$elementHash] = $this->parseTemplate($elementParts[1], $data);
                         break;
                     default:
                         if (class_exists($elementParts[0])) {
                             $callParts = explode("?", $elementParts[1]);
                             eval('$classObject = new ' . $elementParts[0] . '();');
                             if (!empty($callParts[1])) {
                                 $params = $this->getCallParams($callParts[1]);
                             } else {
                                 $params = [];
                             }
                             try {
                                 if (method_exists($classObject, $callParts[0])) {
                                     $result = call_user_func_array(array($classObject, $callParts[0]), $params);
                                 } else {
                                     $result = "[Could not call \"{$callParts[0]}\" on \"{$elementParts[0]}\"]";
                                 }
                             } catch (Exception $e) {
                                 $result = "[Could not call \"{$callParts[0]}\" on \"{$elementParts[0]}\"]";
                             }
                             if (is_array($result)) {
                                 $result = (object) $result;
                             }
                             if (is_object($result) && get_class($result) !== "htmlElement") {
                                 $html = "";
                                 foreach ($result as $rid => $resultData) {
                                     if (!empty($element["snippet"])) {
                                         $html .= $this->parseTemplate($element["snippet"], $resultData);
                                     }
                                 }
                                 $response[$elementHash] = $html;
                             } else {
                                 $response[$elementHash] = $result;
                             }
                         } else {
                             $response[$elementHash] = "Class: {$elementParts[0]} not found";
                         }
                         break;
                 }
             }
             if (strpos($template, "{{") !== false) {
                 if (!empty($data)) {
                     preg_match_all('/{([a-zA-Z0-9\\_\\-\\>\\[\\]\\"]+)}/i', $template, $variables);
                     foreach ($variables[1] as $index => $variable) {
                         if (!empty($data->{$variable})) {
                             $template = $this->parseValue("{" . $variable . "}", $data->{$variable}, $template);
                         }
                     }
                 }
                 foreach ($elements as $eid => $element) {
                     $elementHash = md5(print_r($element[0], 1));
                     $element[0] = str_replace("?", '\\?', $element[0]);
                     $template = preg_replace('{{{' . $element[0] . '}}}', $response[$elementHash], $template, 1);
                 }
             }
         }
         //see if we can parse the data variable
         if (!empty($data)) {
             if (TINA4_HAS_CACHE && empty(xcache_get(md5(print_r($data, 1))))) {
                 //Parse through the data variables
                 foreach ($data as $keyName => $keyValue) {
                     if (class_exists("finfo")) {
                         $fi = new finfo(FILEINFO_MIME);
                         $mimeType = explode(";", $fi->buffer($keyValue));
                         if ($mimeType[0] !== "text/html" && $mimeType[0] !== "text/plain" && $mimeType[0] !== "application/octet-stream" && $mimeType[0] !== "application/x-empty") {
                             if (is_object($data)) {
                                 $data->{$keyName} = (new Debby())->encodeImage($keyValue, $imagestore = "/imagestore", $size = "", $noimage = "/imagestore/noimage.jpg");
                             } else {
                                 $data[$keyName] = (new Debby())->encodeImage($keyValue, $imagestore = "/imagestore", $size = "", $noimage = "/imagestore/noimage.jpg");
                             }
                             //$value = "data:".$mimeType[0].";base64,".base64_encode($value);
                         }
                     }
                 }
                 xcache_set(md5(print_r($data, 1)), serialize($data));
             } else {
                 if (TINA4_HAS_CACHE && !empty(xcache_get(md5(print_r($data, 1))))) {
                     $data = unserialize(xcache_get(md5(print_r($data, 1))));
                 }
             }
             foreach ($data as $name => $value) {
                 $template = $this->parseValue("{" . $name . "}", $value, $template);
             }
         }
         //any variables that could not be found in the form {variable}
         preg_match_all('/{([a-zA-Z0-9\\_\\-\\>\\[\\]\\"]+)}/i', $template, $elements);
         if (!empty($elements[1])) {
             foreach ($elements[1] as $eid => $element) {
                 $testVar = explode("->", $element);
                 if (count($testVar) > 1) {
                     eval('if (empty($' . $testVar[0] . ')) { global $' . $testVar[0] . '; }');
                 }
                 eval('if (!empty($' . $element . ')) { $var = $' . $element . '; }');
                 if (empty($var)) {
                     $template = str_replace("{" . $element . "}", "<span style=\"color:red; font-weight:bold\">[{$element} is not defined, please check your template]</span>", $template);
                 } else {
                     $template = str_replace("{" . $element . "}", $var, $template);
                 }
             }
         }
         if (TINA4_HAS_CACHE && strpos($template, "{") === false) {
             xcache_set($checkSum, $template);
         }
     } catch (Exception $error) {
         $template = "Error parsing {$error}";
         xcache_set($checkSum, null);
     }
     //return the parsed information as a text string
     return $template;
 }