/** * Overloaded function that is resopnsible for the creation of the Special Page */ public function execute($par) { global $wgOut, $wgUser; if (!$wgUser->isAllowed('delete')) { $wgOut->permissionRequired('delete'); return; } $wgOut->setPageTitle(wfMsg('smw_ti_termimport')); $cl = new CL(); $cl->execute(); }
/** * Processes raw text with regex patterns * @param string $text The raw string to apply the regex on * @return string The processes string */ public static function process($text) { /* * Since we have changed directories through code we need to get the file location for *this* class * We then load all regex files */ $thisClassReference = new ReflectionClass('Regex'); $filePaths = glob(dirname(dirname($thisClassReference->getFileName())) . "/Extensions/Regex/regex.*.php"); CL::printDebug("Applying Regexes", 1); foreach ($filePaths as $filePath) { // For every regex in the regex extensions include_once $filePath; // Include the file if (preg_match("/regex\\.(\\w+)\\.php/", basename($filePath), $matches)) { // We extract out the class name from the file, and load that as the class //CL::printDebug("Regex: " . $matches[1], 2); // Extensive debug option here $rules = $matches[1]::getRegexs(); // We then get the regexes array (pattern => replace) foreach ($rules as $regex => $replacement) { if (is_callable($matches[1] . "::" . $replacement)) { $text = preg_replace_callback($regex, $matches[1] . "::" . $replacement, $text); } else { $text = preg_replace($regex, $replacement, $text); } } } } return $text; }
/** * Process data that is going to be inserted into the export * @param array $data A mixed array of data to be processed * @return array An array of processed data ready to be plugged into the file */ public static function process($data, $extensions) { /* * Since we have changed directories through code we need to get the file location for *this* class * We then load the data processor extensions, find out what fields they want to edit and then apply them */ $ref = new ReflectionClass('DataProcessor'); $dataExtensionsPath = dirname(dirname($ref->getFileName())) . "/Extensions/Data/"; foreach ($extensions as $extension => $appliesTo) { // For every extension that the config file wants us to apply to $classFilePath = $dataExtensionsPath . "data." . $extension . ".php"; // Get the class filepath from the extension folder if (file_exists($classFilePath)) { include_once $classFilePath; // Include the class foreach ($appliesTo as $applies) { // For every @data it should be applied to $applies = trim($applies); // Trim any leading or trailing whitespace if (array_key_exists($applies, $data)) { // If the @data actually exists CL::printDebug("Applying " . $extension . " to: " . $applies, 1); // Notify we're applying the extension $data[$applies] = $extension::process($data[$applies], $applies, $data); } } } } return $data; }
public static function process($directory = "", $defaults, $config = array()) { PipelineHooks::beforeProcessingFilesIn($directory, $defaults, $config); // Hook for before this directory is processed $configPath = $directory . "config.json"; if (file_exists($configPath)) { CL::printDebug("Config File at: " . $configPath, 1); } $config = Secretary::getJSON($configPath, $config); if (array_key_exists("Content", $config)) { CL::println("WARNING: You've declared field \"Content\" in JSON file: " . $directory . "config.json", 0, Colour::Red); CL::println("The \"Content\" keyword is reserved for storing the file contents in.", 0, Colour::Red); CL::println("The value for \"Content\" stored in the JSON file will be ignored.", 0, Colour::Red); } $files = array(); $markdowns = glob($directory . "*.md"); foreach ($markdowns as $markdown) { CL::printDebug("Processing: " . $markdown); $file = new File($markdown); // Set up our @data $data = array_merge($config, $file->data); // Renaming to make more semantic sense as we're now working with the "data" $data["Content"] = $file->contents; // Pass in our file contents $raw = $data; // Store raw data before processing // Process our data through data extensions if (array_key_exists("DataExtensions", $defaults)) { $data = DataProcessor::process($data, $defaults["DataExtensions"]); // Process our data to be filled in CL::printDebug("Processed data", 1, Colour::Green); } else { CL::printDebug("No data extensions declared", 1); } $data["Content"] = Regex::process($data["Content"]); // Now regex it all CL::printDebug("Processed Regex", 1, Colour::Green); $templateFile = Templater::process($data["Template"]); // Generate our template CL::printDebug("Processed template: " . $data["Template"], 1, Colour::Green); $processedFile = LTM::process($templateFile, $data, $raw); // Fill in any conditions and optionals CL::printDebug("Processed LTM", 1, Colour::Green); $file->contents = $processedFile; // Store the complete processed file back into the file object array_push($files, $file); // Add it to the array ready to be exported! } PipelineHooks::afterProcessing($files, $directory, $defaults, $config); // Hook for after this directory is processed - and lets pass some files! $directories = glob($directory . "*", GLOB_ONLYDIR); foreach ($directories as $directory) { $newFiles = self::process($directory . "/", $defaults, $config); foreach ($newFiles as $newFile) { array_push($files, $newFile); } } return $files; }
/** * Class constructor - autorun of modules, etc ... */ function __construct() { CL::initConfHandler(); $handler = CL::$configHandler; $result = $handler->xpath("/CL_config/CLE_Modules/module[@autorun='1'][@enabled='1'][@installed='1']"); foreach ($result as $module) { $this->load($module); } }
/** * Process source code for any data requests and optional requests and fill them * @param string $text Text to process * @param array $data Data used to fill * @return string Processed text */ public static function process($text, $data, $raw) { $lines = []; foreach (preg_split("/((\r?\n)|(\r\n?))/", $text) as $line) { array_push($lines, $line); } $renderableLines = self::parse($lines, $data, $raw); // We know using $data which conditionals are able to be used $text = ""; foreach ($renderableLines as $line) { // Go through line by line $text .= $line . "\n"; } /* * Optional values such as tags we'll omit - RAW */ $text = preg_replace_callback("/@data\\?\\((\\w+)\\)::RAW/", function ($matches) use($raw) { if (array_key_exists($matches[1], $raw)) { return $raw[$matches[1]]; } return ""; }, $text); /* * Optional values such as tags we'll omit */ $text = preg_replace_callback("/@data\\?\\((\\w+)\\)/", function ($matches) use($data) { if (array_key_exists($matches[1], $data)) { return $data[$matches[1]]; } return ""; }, $text); /* * Optional values such as tags we'll omit - RAW */ $text = preg_replace_callback("/@data\\((\\w+)\\)::RAW/", function ($matches) use($raw) { if (array_key_exists($matches[1], $raw)) { return $raw[$matches[1]]; } CL::println("ERROR: Template requested " . $matches[1] . "::RAW but was not found. Please review file.", 0, Colour::Red); return $matches[0]; }, $text); /* * Non-Optionals we'll need to alert to the CLI to let the user know there's something up */ $text = preg_replace_callback("/@data\\((\\w+)\\)/", function ($matches) use($data) { if (array_key_exists($matches[1], $data)) { return $data[$matches[1]]; } CL::println("ERROR: Template requested " . $matches[1] . " but was not found. Please review file.", 0, Colour::Red); return $matches[0]; }, $text); return $text; }
public static function afterProcessing($files, $directory, $defaults, $config) { foreach ($defaults["Hooks"] as $appliesTo => $hookExtensions) { // Cycle through the paths that apply to if ($appliesTo == $directory) { // If the path matches the current directory foreach ($hookExtensions as $hookExtension => $arguments) { // For every hook for this directory CL::printDebug($hookExtension . " after-hook called upon: " . $directory, 0, Colour::Blue); include_once self::getHookPath($hookExtension); $hookExtension::afterProcessing($files, $directory, $config, $arguments); } } } }
/** * Request a template from the templates directory * @param String $templateName The name of the template to request * @return String The processed template file */ static function process($templateName) { $ref = new ReflectionClass('Templater'); $filePath = dirname(dirname($ref->getFileName())) . "/templates/" . $templateName . ".html"; if (!file_exists($filePath)) { // Does the requested file actuallye exist? CL::println("Template at " . $filePath . " does not exist.", 0, Colour::Red); CL::println("Warehouse cannot continue. Please fix. Exiting program.", 0, Colour::Red); exit; } $rawFile = file_get_contents($filePath); // If it does get it's contents $regex = "/@template\\(([\\w|.]+)\\)/"; // Check to see if there are any @template calls $processedFile = preg_replace_callback($regex, function ($matches) { return Templater::process($matches[1]); // recursion recursion recursion recursion.. }, $rawFile); return $processedFile; }
/** * Set up Warehouse and load any defaults * Return configuration file by loading Classes/config.defaults.json and then config.json */ public static function initDefaults() { $_SESSION["exportFiles"] = array(); $defaults = array(); if (file_exists("Classes/config.defaults.json")) { CL::printDebug("Loading default Warehouse configuration", 0, Colour::Green); $defaults = self::getJSON("Classes/config.defaults.json"); } else { CL::printDebug("File: Classes/config.defaults.json was not found.", 0, Colour::Red); CL::printDebug("Warehouse may not function correctly without this file.", 0, Colour::Red); CL::printDebug("Please re-download from Github.", 0, Colour::Red); } if (file_exists("config.json")) { CL::printDebug("Loading config file.", 0, Colour::Green); $defaults = self::getJSON("config.json", $defaults); } else { CL::printDebug("No custom config file found. #BareBones"); } return $defaults; }
/** * This function resizes given image, if it has bigger dimensions, than we need and saves it (also makes chmod 0777 on the file) ... * It uses GD or ImageMagick, setting is available to change in CL's config file. * * @param string $inputFileName the input file to work with * @param string $outputFileName the file to write into the final (resized) image * @param integer $maxNewWidth maximal width of image * @param integer $maxNewHeight maximal height of image * @return bool TRUE, if everything was successful (resize and chmod), else FALSE */ function resize($inputFileName, $outputFileName, $maxNewWidth, $maxNewHeight) { $imageInfo = getimagesize($inputFileName); $fileType = $imageInfo['mime']; $extension = strtolower(str_replace('.', '', substr($outputFileName, -4))); $originalWidth = $imageInfo[0]; $originalHeight = $imageInfo[1]; if ($originalWidth > $maxNewWidth or $originalHeight > $maxNewHeight) { $newWidth = $maxNewWidth; $newHeight = $originalHeight / ($originalWidth / $maxNewWidth); if ($newHeight > $maxNewHeight) { $newHeight = $maxNewHeight; $newWidth = $originalWidth / ($originalHeight / $maxNewHeight); } $newWidth = ceil($newWidth); $newHeight = ceil($newHeight); } else { $newWidth = $originalWidth; $newHeight = $originalHeight; } $ok = FALSE; if (CL::getConf('CL_Images/engine') == 'imagick-cli') { exec("convert -thumbnail " . $newWidth . "x" . $newHeight . " " . $inputFileName . " " . $outputFileName); $ok = TRUE; } elseif (CL::getConf('CL_Images/engine') == 'imagick-php') { $image = new Imagick($inputFileName); $image->thumbnailImage($newWidth, $newHeight); $ok = (bool) $image->writeImage($outputFileName); $image->clear(); $image->destroy(); } else { $out = imageCreateTrueColor($newWidth, $newHeight); switch (strtolower($fileType)) { case 'image/jpeg': $source = imageCreateFromJpeg($inputFileName); break; case 'image/png': $source = imageCreateFromPng($inputFileName); break; case 'image/gif': $source = imageCreateFromGif($inputFileName); break; default: break; } imageCopyResized($out, $source, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight); switch (strtolower($extension)) { case 'jpg': case 'jpeg': if (imageJpeg($out, $outputFileName)) { $ok = TRUE; } break; case 'png': if (imagePng($out, $outputFileName)) { $ok = TRUE; } break; case 'gif': if (imageGif($out, $outputFileName)) { $ok = TRUE; } break; default: break; } imageDestroy($out); imageDestroy($source); } if ($ok and chmod($outputFileName, 0777)) { return TRUE; } else { return FALSE; } }
/** * Verifies token sent by user * * @return boolean do the tokens match? */ function tokenVerify() { if (self::$tokenVerified) { return self::$tokenVerifiedStatus; } else { self::$tokenVerified = TRUE; $name = $_SESSION['token_name']; if (isset($_POST[$name]) and $_POST[$name] == $_SESSION['token']) { self::$tokenVerifiedStatus = TRUE; self::tokenGenerate(); } return self::$tokenVerifiedStatus; } }
// We then remove all configs as well - we definitely don't want them going across CL::printDebug("Copying " . count($remaining) . " misc files to the upload folder."); CL::printDebug("Copying: "); foreach ($remaining as $filepath) { CL::printDebug($filepath, 1); $fileContents = file_get_contents($filepath); // This is a really dirty way to do it, and creates a nasty memory foot print - alternatives? chdir("../upload"); // Change to our upload if (!file_exists(dirname($filepath))) { // If the directory path for the file doesn't already exist, recursively make it mkdir(dirname($filepath), 0777, TRUE); } file_put_contents(dirname($filepath) . "/" . basename($filepath), $fileContents); // We then put the file contents there as a clone chdir("../source"); // Move back to the source for the next possible file } chdir("../upload"); $remaining = Secretary::getExportFiles(); CL::printDebug("Creating " . count($remaining) . " hook generated files in the upload folder."); foreach ($remaining as $filePath => $fileContents) { if (!file_exists(dirname($filePath))) { // If the directory path for the file doesn't already exist, recursively make it mkdir(dirname($filePath), 0777, TRUE); } file_put_contents($filePath, $fileContents); // We then put the file contents there as a clone } CL::println("Done!", 0, Colour::Green); // That wasn't so bad, right?
/* Including of the CLE engine */ require_once './sys/CLE/class.cle.ibdi.php'; require_once './sys/CLE/class.cle.modules.php'; require_once './sys/CLE/class.cle.basemodule.php'; require_once './sys/CLE/class.cle.json.php'; /* CL base object */ $_CL = CL::getInstance(); /* Some object and arrays related to (auto)loading of modules */ $_autoloadArray = array(); $_setVarsArray = array(); $_addVarsArray = array(); /* Array of modules, that support SOAP | JSON */ $_jsonEnabledModules = array(); if (CL::getConf('CLE_Ibdi/enabled') == 1) { require_once './sys/external/dibi.min.php'; if (!CLE_Ibdi::getInstance()->connect() and CL::getConf('CLE_Ibdi/terminateScriptOnError') == 1) { exit(' CLE error message: Database connection failed, script execution terminated. <br /><br /> Please check your database connection settings in conf/config.xml<br /> (if you do not wish to automatically start DB connection, you can as well deactivate it). <br /><br /> If you do not wish CLE to terminate script execution on DB connection error,<br /> you can set that in configuration file as well. <br /><br /> '); } } /* Autoload of classes */ function __autoload($class) {
/** * Quickway to print text if we're in debug * @param string $text Text to print to console */ public static function printDebug($text, $indent = 0, $colour = Colour::White) { if (DEBUG) { CL::println($text, $indent, $colour); } }
<?php /** * @package CLE * @subpackage SysFiles * @author Rene Kliment <*****@*****.**> * @version 1.1 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License - Version 3, 19 November 2007 * * This software is dual-licensed - it is also available under a commercial license, * so there's possibility to use this software or its parts in software which is not license-compatible. * For more information about licensing, contact the author. */ $_CL_Xety = $GLOBALS['_CL_Xety'] = CL_Xety::getInstance(); $_CL = $GLOBALS['_CL']; /* And set default language (if not set other) */ if (!isset($_SESSION['language']) or empty($_SESSION['language'])) { $_SESSION['language'] = (string) CL::getConf('main/default_language'); } if (isset($_SESSION['_sessionSetMessageBuffer']) and $_SESSION['_sessionSetMessageBuffer']) { $_CL->setMessage($_SESSION['_sessionSetMessageBuffer']); unset($_SESSION['_sessionSetMessageBuffer']); } if (isset($GLOBALS['_setMessageBuffer']) and $GLOBALS['_setMessageBuffer']) { $_CL->setMessage(constant($GLOBALS['_setMessageBuffer'])); } /* Let's load default layout */ CL_Templates::setDirectory(CL::getConf('CL_Templates/dir_default')); if (@(!defined(CLE_DONT_LOAD_LAYOUT))) { $_CL_Templates = $GLOBALS['_CL_Templates'] = CL_Templates::getInstance(); }
$_CL_Templates->add($v1); } } /* Are there any other variables to set? (for example from init stage of modules) */ if (count($_setVarsArray)) { $_CL_Templates->set($_setVarsArray); } /* Set some info to head tag, verification tokens, navigation, ... */ $_CL_Templates->set(array('footer' => CL::getConf('main/footer'), 'header-language' => CL::getConf('main/default_language'), 'header-title' => CL::getConf('main/website_name'), 'header-description' => CL::getConf('main/website_description'), 'header-keywords' => CL::getConf('main/website_keywords'), 'header-author' => CL::getConf('main/website_webmaster'), 'header-add' => '', '_id' => $_id, 'address_ssl' => CL::getConf('main/address_ssl'), 'nonRootPrefix' => CL::getConf('main/nonRootPrefix'), 'token' => $_SESSION['token'], 'token-name' => $_SESSION['token_name'], 'currentYear' => date('Y'), 'header-navigation' => strip_tags($_CL->getNavigation()), 'message' => $_CL->getMessage() ? str_replace('${message}', $_CL_Xety->basic($_CL->getMessage()), $_CL_Templates->getTpl('##base.tpl', 'MESSAGE')) : '', 'layout-directory' => $_CL_Templates->getDirectory(), 'layout-directory-fullpath' => CL::getConf('CL_Templates/dir') . $_CL_Templates->getDirectory(), 'layout-css' => CL::getConf('main/nonRootPrefix') . CL::getConf('CL_Templates/dir') . $_CL_Templates->getDirectory() . '/default.css')); /* Any cookie variables to fill into layout vars? */ if (isset($_autoFillInCookieVars)) { $tempArray = array(); foreach ($_autoFillInCookieVars as $var) { if (isset($_POST[$var]) and $_POST[$var]) { $_COOKIE[$var] = $_POST[$var]; setcookie($var, $_POST[$var], time() + 3600 * 24 * 365, CL::getConf('main/nonRootPrefix')); } $tempArray['_autoFillInCookieVars-' . $var] = isset($_COOKIE[$var]) ? $_CL_Xety->plain($_COOKIE[$var]) : ''; } $_CL_Templates->set($tempArray); } /* At last, any $_POST variables? */ if (isset($_autoFillInPostVars)) { $tempArray = array(); foreach ($_autoFillInPostVars as $var) { $tempArray['_autoFillInPostVars-' . $var] = (isset($_POST[$var]) and $_POST[$var]) ? $_CL_Xety->plain($_POST[$var]) : ''; } $_CL_Templates->set($tempArray); } /* Finally, send output to user ... */ echo $_CL_Templates->getContent();
/** * Obtain filename from configuration file, if there is any match with parameters in given URL * * @return string|bool filename or FALSE */ function lookUpInXMLFile() { if (!$this->fileHandler) { $this->fileHandler = simplexml_load_file(CL::getConf('CL_SEO/fileName')); } return $this->checkSection($this->fileHandler, 0); }
<?php /** * @package CLE-Modules * @subpackage simpleStatic * @author Rene Kliment <*****@*****.**> * @version 1.1 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License - Version 3, 19 November 2007 * * This software is dual-licensed - it is also available under a commercial license, * so there's possibility to use this software or its parts in software which is not license-compatible. * For more information about licensing, contact the author. */ if (isset($_stringId) and $_stringId) { $dir = 'data/simpleStatic/'; $urlArray = CL_SEO::getInstance()->URLArray; $h = dir($dir); while (false !== ($file = $h->read())) { if ($_stringId . '.html' == $file) { $navString = CL::getConf('simpleStatic/' . $_stringId) ? CL::getConf('simpleStatic/' . $_stringId) : $_stringId; $_CL->setNavigation($navString); $_CL_Templates->set(array('' => file_get_contents($dir . $_stringId . '.html'), 'simpleStatic-title' => $navString)); } } }
/** * Gets the full table name according to the table label and prefix * (everything according to the .xml config file) * * @param string $table name of DB table * @return string the table full name */ static function getNameOfTable($table) { return CL::getConf('CLE_Ibdi/prefix') . $table; }
/** * This function returns the path (according to the root of our website) of given file. * Example: "guestbook/form.tpl" -> "layouts/theBestWorldsTemplate/guestbook/form.tpl" * * @param string $file the file whom path we wanna know * @return string the file's path */ function getFilePath($file) { if (substr($file, 0, 2) == '##') { $fileNew = CL::getConf('CL_Templates/dir') . self::$directory . substr($file, 2); if (!file_exists($fileNew)) { $fileNew = CL::getConf('CL_Templates/dir') . 'default/' . substr($file, 2); } $file = $fileNew; } elseif (substr($file, 0, 1) == '#') { $file = substr($file, 1); } elseif (substr($file, 0, 8) == 'modules/' or substr($this->moduleNamespace, 0, 8) == 'modules/') { $file = $this->moduleNamespace . $file; } else { $file = CL::getConf('CL_Templates/dir') . self::$directory . '/' . $file; } if (file_exists($file)) { return $file; } else { return FALSE; } }