private $attachments = array(); /** * BCC storage * * @var array */ private $BCC = array(); /** * CC storage * * @var array */ private $CC = array(); /** * Charset * * @var string */ private $charset = 'utf-8'; /** * Template compile directory * * @var string */ private $compileDirectory; /** * Email content storage
/** * Process the content of the file. * * @param string $file The file to process. * @return boolean|array */ private function processFile($file) { // if the files doesn't exists we can stop here and just return an empty string if (!SpoonFile::exists($file)) { return array(); } // fetch content from file $content = SpoonFile::getContent($file); $json = @json_decode($content, true); // skip invalid JSON if ($json === false || $json === null) { return array(); } $return = array(); // loop templates foreach ($json as $template) { // skip items without a title if (!isset($template['title'])) { continue; } if (isset($template['file'])) { if (SpoonFile::exists(PATH_WWW . $template['file'])) { $template['html'] = SpoonFile::getContent(PATH_WWW . $template['file']); } } // skip items without HTML if (!isset($template['html'])) { continue; } $image = ''; if (isset($template['image'])) { // we have to remove the first slash, because that is set in the wrapper. Otherwise the images don't work $image = ltrim($template['image'], '/'); } $temp['title'] = $template['title']; $temp['description'] = isset($template['description']) ? $template['description'] : ''; $temp['image'] = $image; $temp['html'] = $template['html']; // add the template $return[] = $temp; } return $return; }
/** * Sets the headers so we may download the CSV file in question * * @param string $path The full path to the CSV file you wish to download. * @return array */ private function downloadCSV($path) { // check if the file exists if (!SpoonFile::exists($path)) { throw new SpoonFileException('The file ' . $path . ' doesn\'t exist.'); } // fetch the filename from the path string $explodedFilename = explode('/', $path); $filename = end($explodedFilename); // set headers for download $headers[] = 'Content-type: application/csv; charset=' . SPOON_CHARSET; $headers[] = 'Content-Disposition: attachment; filename="' . $filename . '"'; $headers[] = 'Pragma: no-cache'; // overwrite the headers SpoonHTTP::setHeaders($headers); // get the file contents $content = SpoonFile::getContent($path); // output the file contents echo $content; exit; }
public static function correct(&$frm) { if ($frm->getField('photo')->isFilled()) { $imagename = uniqid(); SpoonFile::setContent(IMAGE_PATH . '/' . $imagename . '.' . $frm->getField('photo')->getExtension(), gzcompress(SpoonFile::getContent($frm->getField('photo')->getTempFileName()), 9)); //create Thumbnail $frm->getField('photo')->createThumbnail(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension(), 130, 130); SpoonFile::setContent(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension(), gzcompress(SpoonFile::getContent(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension()), 9)); } if ($frm->getField('attachment')->isFilled()) { $attachname = uniqid(); SpoonFile::setContent(ATTACH_PATH . '/' . $attachname . '.' . $frm->getField('attachment')->getExtension(), gzcompress(SpoonFile::getContent($frm->getField('attachment')->getTempFileName()), 9)); } $company = ""; for ($i = 1; $i < 6; $i++) { $company .= $frm->getField('company' . $i)->getValue() . ', ' . $frm->getField('registerno' . $i)->getValue() . ', ' . $frm->getField('companyno' . $i)->getValue() . ', ' . $frm->getField('companyemail' . $i)->getValue() . ', ' . $frm->getField('shareholder' . $i)->getValue() . ', ' . $frm->getField('registeraddr' . $i)->getValue() . ', ' . $frm->getField('businessaddr' . $i)->getValue() . ', '; } $company = substr($company, 0, -2); //company field names $values = array(); for ($i = 1; $i < 6; $i++) { $values = array_merge($values, array('company' . $i, 'registerno' . $i, 'companyno' . $i, 'companyemail' . $i, 'shareholder' . $i, 'registeraddr' . $i, 'businessaddr' . $i)); } $values = array_merge($frm->getValues(array_merge(array('form', 'submit', '_utf8'), $values)), $frm->getField('photo')->isFilled() ? array('photo' => $imagename, 'photoext' => $frm->getField('photo')->getExtension()) : array(), $frm->getField('attachment')->isFilled() ? array('attachment' => $attachname, 'attachext' => $frm->getField('attachment')->getExtension()) : array(), array("company" => $company, 'lastupdate' => time())); foreach ($values as $key => $value) { if ($value == NULL) { unset($values[$key]); } } return $values; }
/** * Get the template record * * @param string $language The language. * @param string $name The name of the template. * @return array */ public static function getTemplate($language, $name) { // set the path to the template folders for this language $path = BACKEND_MODULE_PATH . '/templates/' . $language; // load all templates in the 'templates' folder for this language $templates = SpoonDirectory::getList($path, false, array('.svn')); // stop here if no directories were found if (empty($templates) || !in_array($name, $templates)) { return array(); } // load all templates in the 'templates' folder for this language if (!SpoonFile::exists($path . '/' . $name . '/template.tpl')) { throw new SpoonException('The template folder "' . $name . '" exists, but no template.tpl file was found. Please create one.'); } if (!SpoonFile::exists($path . '/' . $name . '/css/screen.css')) { throw new SpoonException('The template folder "' . $name . '" exists, but no screen.css file was found. Please create one in a subfolder "css".'); } // set template data $record = array(); $record['name'] = $name; $record['language'] = $language; $record['label'] = BL::lbl('Template' . SpoonFilter::toCamelCase($record, array('-', '_'))); $record['path_content'] = $path . '/' . $name . '/template.tpl'; $record['path_css'] = $path . '/' . $name . '/css/screen.css'; $record['url_css'] = SITE_URL . '/backend/modules/mailmotor/templates/' . $language . '/' . $name . '/css/screen.css'; // check if the template file actually exists if (SpoonFile::exists($record['path_content'])) { $record['content'] = SpoonFile::getContent($record['path_content']); } if (SpoonFile::exists($record['path_css'])) { $record['css'] = SpoonFile::getContent($record['path_css']); } return $record; }
/** * Get the locale that is used in the frontend but doesn't exists. * * @param string $language The language to check. * @return array */ public static function getNonExistingFrontendLocale($language) { // get files to process $tree = self::getTree(FRONTEND_PATH); $used = array(); // loop files foreach ($tree as $file) { // grab content $content = SpoonFile::getContent($file); // process the file based on extension switch (SpoonFile::getExtension($file)) { // javascript file case 'js': $matches = array(); // get matches preg_match_all('/\\{\\$(act|err|lbl|msg)(.*)(\\|.*)?\\}/iU', $content, $matches); // any matches? if (isset($matches[2])) { // loop matches foreach ($matches[2] as $key => $match) { // set type $type = $matches[1][$key]; // init if needed if (!isset($used[$match])) { $used[$type][$match] = array('files' => array()); } // add file if (!in_array($file, $used[$type][$match]['files'])) { $used[$type][$match]['files'][] = $file; } } } break; // PHP file // PHP file case 'php': $matches = array(); // get matches preg_match_all('/(FrontendLanguage|FL)::(get(Action|Label|Error|Message)|act|lbl|err|msg)\\(\'(.*)\'\\)/iU', $content, $matches); // any matches? if (!empty($matches[4])) { // loop matches foreach ($matches[4] as $key => $match) { $type = 'lbl'; if ($matches[3][$key] == 'Action') { $type = 'act'; } if ($matches[2][$key] == 'act') { $type = 'act'; } if ($matches[3][$key] == 'Error') { $type = 'err'; } if ($matches[2][$key] == 'err') { $type = 'err'; } if ($matches[3][$key] == 'Message') { $type = 'msg'; } if ($matches[2][$key] == 'msg') { $type = 'msg'; } // init if needed if (!isset($used[$type][$match])) { $used[$type][$match] = array('files' => array()); } // add file if (!in_array($file, $used[$type][$match]['files'])) { $used[$type][$match]['files'][] = $file; } } } break; // template file // template file case 'tpl': $matches = array(); // get matches preg_match_all('/\\{\\$(act|err|lbl|msg)([a-z-_]*)(\\|.*)?\\}/iU', $content, $matches); // any matches? if (isset($matches[2])) { // loop matches foreach ($matches[2] as $key => $match) { // set type $type = $matches[1][$key]; // init if needed if (!isset($used[$type][$match])) { $used[$type][$match] = array('files' => array()); } // add file if (!in_array($file, $used[$type][$match]['files'])) { $used[$type][$match]['files'][] = $file; } } } break; } } // init var $nonExisting = array(); // set language FrontendLanguage::setLocale($language); // check if the locale is present in the current language foreach ($used as $type => $items) { // loop items foreach ($items as $key => $data) { // process based on type switch ($type) { case 'act': // if the action isn't available add it to the list if (FL::act($key) == '{$' . $type . $key . '}') { $nonExisting['frontend' . $key . $type] = array('language' => $language, 'application' => 'frontend', 'module' => 'core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files'])); } break; case 'err': // if the error isn't available add it to the list if (FL::err($key) == '{$' . $type . $key . '}') { $nonExisting['frontend' . $key . $type] = array('language' => $language, 'application' => 'frontend', 'module' => 'core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files'])); } break; case 'lbl': // if the label isn't available add it to the list if (FL::lbl($key) == '{$' . $type . $key . '}') { $nonExisting['frontend' . $key . $type] = array('language' => $language, 'application' => 'frontend', 'module' => 'core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files'])); } break; case 'msg': // if the message isn't available add it to the list if (FL::msg($key) == '{$' . $type . $key . '}') { $nonExisting['frontend' . $key . $type] = array('language' => $language, 'application' => 'frontend', 'module' => 'core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files'])); } break; } } } ksort($nonExisting); return $nonExisting; }
/** * Parse the template. */ protected function parse() { // not yet parsed if (!$this->parsed) { // while developing, you might want to know about the undefined indexes $errorReporting = $this->debug ? 'E_ALL | E_STRICT' : 0; $displayErrors = $this->debug ? 'On' : 'Off'; // add to the list of parsed files $this->files[] = $this->getCompileName($this->template); // map modifiers $this->modifiers = SpoonTemplateModifiers::getModifiers(); // set content $this->content = SpoonFile::getContent($this->template); // strip php code $this->content = $this->stripCode($this->content); // strip comments $this->content = $this->stripComments($this->content); // prepare iterations $this->content = $this->prepareIterations($this->content); // parse iterations $this->content = $this->parseIterations($this->content); // parse variables $this->content = $this->parseVariables($this->content); // parse options $this->content = $this->parseOptions($this->content); // includes $this->content = $this->parseIncludes($this->content); // parse cache tags $this->content = $this->parseCache($this->content); // parse forms $this->content = $this->parseForms($this->content); // replace variables $this->content = $this->replaceVariables($this->content); // add error_reporting setting $this->content = '<?php error_reporting(' . $errorReporting . '); ini_set(\'display_errors\', \'' . $displayErrors . '\'); ?>' . "\n" . $this->content; // parsed $this->parsed = true; } }
public function execute() { parent::execute(); $txtText = \SpoonFile::getContent(BACKEND_MODULE_PATH . "/meubelwinkels.txt"); $arrText = explode("\n", $txtText); $strShop = ""; $arrShops = array(); $arrShopsFinal = array(); $arrElements = array("company", "phone", "zipcode", "city", "address", "contact", "email", "website", "fax", "vat", "assort", "m�", "open", "gesloten", "visit"); $arrElementsDash = array("assort", "m�", "open", "gesloten", "visit"); foreach ($arrText as $line) { //--Check if the line is only a zipcode or pagenumbers (1000 or 52 53) if (preg_match("/^\\d+\$/", $line) || preg_match("/^[0-9 ]+\$/", $line)) { continue; } //--Search for T : in the line (this is the first line of the address) if (strpos($line, "T :") !== false) { //--If line is not empty, add it to the array if (!empty($strShop)) { $arrShops[] = $strShop; } $strShop = ""; } //--Add the line + add a marker [LINE] $strShop .= $line . "[LINE]"; } //--Loop all the shops foreach ($arrShops as $shop) { //--Explode the shop with [LINE] $arrShop = explode("[LINE]", $shop); $arrShopFinal = array(); //--Get the phone number and name of the shop $strPosTelephone = strpos($arrShop[0], "T :"); //--Create array $arrShopFinal["company"] = ucwords(mb_strtolower(substr($arrShop[0], 0, $strPosTelephone))); $arrShopFinal["phone"] = trim(str_replace("T :", "", substr($arrShop[0], $strPosTelephone))); //--Get the address $strAddress = ucwords(mb_strtolower($arrShop[1])); //--Get position of the space $strPosSpaceZipcode = strpos($strAddress, " "); //--Add the zipcode $arrShopFinal["zipcode"] = substr($strAddress, 0, $strPosSpaceZipcode); //--Alter the address-string $strAddress = substr($strAddress, $strPosSpaceZipcode); //--Search comma $strPosCommaCity = strpos($strAddress, ","); //--Add the city $arrShopFinal["city"] = substr($strAddress, 0, $strPosCommaCity); //--Add the address $arrShopFinal["address"] = trim(substr($strAddress, $strPosCommaCity + 1)); //--Unset first and second item unset($arrShop[0]); unset($arrShop[1]); //--Loop the shop foreach ($arrShop as $key => $row) { //--Get the contact if (!isset($arrShopFinal["contact"]) && strpos($row, "contact:") !== false) { $arrShopFinal["contact"] = ucwords(mb_strtolower(trim(substr($row, 8)))); } //--Find the e-mailaddress in the string if (!isset($arrShopFinal["email"])) { preg_match("/[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})/i", $row, $matches); if (!empty($matches)) { $arrShopFinal["email"] = $matches[0]; } } //--Find the website address if (!isset($arrShopFinal["website"])) { preg_match("/www\\.[a-zA-Z0-9-]+\\.[a-z]{2,7}/i", $row, $matches); if (!empty($matches)) { $arrShopFinal["website"] = $matches[0]; } } //--Find the fax if (!isset($arrShopFinal["fax"])) { preg_match("/F: ([\\s0-9]+)/i", $row, $matches); if (!empty($matches)) { $arrShopFinal["fax"] = $matches[1]; } } //--Find the VAT if (!isset($arrShopFinal["btw"])) { preg_match("/BTW : ([A-Z]{2}[\\s]*[0-9-\\.\\s]+)/i", $row, $matches); if (!empty($matches)) { $arrShopFinal["vat"] = $matches[1]; } } //--Check if the dash is for a numeric value (not - assort:) preg_match("/([0-9]{1}[\\s]-[\\s][0-9]{1})/i", $row, $matches); if (!empty($matches)) { foreach ($matches as $match) { $strMatchReplace = str_replace(" - ", "-", $match); $row = str_replace($match, $strMatchReplace, $row); } } //--Split the text with " - "; $arrDashes = explode(" - ", $row); //--Check if there are elements if (!empty($arrDashes)) { //--Loop the different pieces foreach ($arrDashes as $dash) { //--Loop the elements that are possible for the dash-element foreach ($arrElementsDash as $element) { //--Check if the element is found, if true, add the element to the array if (strpos($dash, $element . ":") !== false) { $arrShopFinal[$element] = str_replace($element . ":", "", $dash); } } } } } //--Check if all elements are filled in foreach ($arrElements as $element) { //--If key not exists, add an empty value to it if (!isset($arrShopFinal[$element])) { //--Fill in empty value $arrShopFinal[$element] = ""; } else { //--Replace to utf8 $arrShopFinal[$element] = trim($arrShopFinal[$element]); //--Replace ? to ' $arrShopFinal[$element] = str_replace("?", "'", $arrShopFinal[$element]); } } //--Replace m� by size (for the database) $arrShopFinal["size"] = $arrShopFinal["m�"]; unset($arrShopFinal["m�"]); //--Replace gesloten by closed (for the database) $arrShopFinal["closed"] = $arrShopFinal["gesloten"]; unset($arrShopFinal["gesloten"]); $arrShopFinal["country"] = substr($arrShopFinal["vat"], 0, 2); $arrShopFinal["country"] = $arrShopFinal["country"] == "" ? "BE" : $arrShopFinal["country"]; //--Add final shop to all shops $arrShopsFinal[] = $arrShopFinal; } print "<pre>"; //--Loop all the shops foreach ($arrShopsFinal as $row) { $arrId = (array) BackendModel::getContainer()->get('database')->getVar('SELECT i.id FROM addresses AS i WHERE i.email = ? AND i.address = ? ', array($row['email'], $row['address'])); $id = (int) $arrId[0]; if ($id > 0) { $arrUpdate = array("contact" => $row['contact']); BackendModel::getContainer()->get('database')->update('addresses', $arrUpdate, 'id = ?', (int) $id); } else { echo $id; print_r($row); } } die; }
/** * Set the busy file * * @return void */ protected function setBusyFile() { // do not set busy file in debug mode if (SPOON_DEBUG) { return; } // build path $path = BACKEND_CACHE_PATH . '/cronjobs/' . $this->getId() . '.busy'; // init var $isBusy = false; // does the busy file already exists. if (SpoonFile::exists($path)) { $isBusy = true; // grab counter $counter = (int) SpoonFile::getContent($path); // check the counter if ($counter > 9) { // build class name $className = 'Backend' . SpoonFilter::toCamelCase($this->getModule() . '_cronjob_' . $this->getAction()); // notify user throw new BackendException('Cronjob (' . $className . ') is still busy after 10 runs, check it out!'); } } else { $counter = 0; } // increment counter $counter++; // store content SpoonFile::setContent($path, $counter, true, false); // if the cronjob is busy we should NOT proceed if ($isBusy) { exit; } }
/** * Start processing the hooks */ public static function startProcessingHooks() { // is the queue already running? if (SpoonFile::exists(FRONTEND_CACHE_PATH . '/hooks/pid')) { // get the pid $pid = trim(SpoonFile::getContent(FRONTEND_CACHE_PATH . '/hooks/pid')); // running on windows? if (strtolower(substr(php_uname('s'), 0, 3)) == 'win') { // get output $output = @shell_exec('tasklist.exe /FO LIST /FI "PID eq ' . $pid . '"'); // validate output if ($output == '' || $output === false) { // delete the pid file SpoonFile::delete(FRONTEND_CACHE_PATH . '/hooks/pid'); } else { return true; } } elseif (strtolower(substr(php_uname('s'), 0, 6)) == 'darwin') { // get output $output = @posix_getsid($pid); // validate output if ($output === false) { // delete the pid file SpoonFile::delete(FRONTEND_CACHE_PATH . '/hooks/pid'); } else { return true; } } else { // check if the process is still running, by checking the proc folder if (!SpoonFile::exists('/proc/' . $pid)) { // delete the pid file SpoonFile::delete(FRONTEND_CACHE_PATH . '/hooks/pid'); } else { return true; } } } // init var $parts = parse_url(SITE_URL); $errNo = ''; $errStr = ''; $defaultPort = 80; if ($parts['scheme'] == 'https') { $defaultPort = 433; } // open the socket $socket = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : $defaultPort, $errNo, $errStr, 1); // build the request $request = 'GET /backend/cronjob.php?module=core&action=process_queued_hooks HTTP/1.1' . "\r\n"; $request .= 'Host: ' . $parts['host'] . "\r\n"; $request .= 'Content-Length: 0' . "\r\n\r\n"; $request .= 'Connection: Close' . "\r\n\r\n"; // send the request fwrite($socket, $request); // close the socket fclose($socket); // return return true; }
/** * Adds an attachment to the headers. * * @param string $filename The path to (including the filename for) the attachment. * @param string[optional] $newName The new name of the attachment. * @param string[optional] $disposition The disposition of the attachment. Can be 'attachment' or 'inline'. * @param string[optional] $encoding The attachment encoding (only base64 for now). */ public function addAttachment($filename, $newName = null, $disposition = 'attachment', $encoding = 'base64') { // check input if (!SpoonFile::exists($filename)) { throw new SpoonEmailException('File not found.'); } // no name was found in the input if (empty($newName)) { // use the source file's base name $newName = basename($filename); } // store file extension $extension = SpoonFile::getExtension($newName); // store attachment disposition $disposition = SpoonFilter::getValue($disposition, array('attachment', 'inline'), 'attachment'); // store type according to disposition if ($disposition === 'attachment') { $extension = 'default'; } // store file info $this->attachments[] = array('file' => $filename, 'name' => $newName, 'encoding' => $encoding, 'type' => $this->getAttachmentContentType($extension), 'disposition' => $disposition, 'data' => chunk_split(base64_encode(SpoonFile::getContent($filename)))); }
/** * Insert a page * * @return void * @param array $revision An array with the revision data. * @param array[optional] $meta The meta-data. * @param array[optional] $block The blocks. */ protected function insertPage(array $revision, array $meta = null, array $block = null) { // redefine $revision = (array) $revision; $meta = (array) $meta; // deactive previous revisions if (isset($revision['id']) && isset($revision['language'])) { $this->getDB()->update('pages', array('status' => 'archive'), 'id = ? AND language = ?', array($revision['id'], $revision['language'])); } // build revision if (!isset($revision['language'])) { throw new SpoonException('language is required for installing pages'); } if (!isset($revision['title'])) { throw new SpoonException('title is required for installing pages'); } if (!isset($revision['id'])) { $revision['id'] = (int) $this->getDB()->getVar('SELECT MAX(id) + 1 FROM pages WHERE language = ?', array($revision['language'])); } if (!$revision['id']) { $revision['id'] = 1; } if (!isset($revision['user_id'])) { $revision['user_id'] = $this->getDefaultUserID(); } if (!isset($revision['template_id'])) { $revision['template_id'] = $this->getDB()->getVar('SELECT id FROM pages_templates WHERE theme = ? ORDER BY path = ? DESC, id ASC', array($this->getSetting('core', 'theme'), 'core/layout/templates/default.tpl')); } if (!isset($revision['type'])) { $revision['type'] = 'page'; } if (!isset($revision['parent_id'])) { $revision['parent_id'] = $revision['type'] == 'page' ? 1 : 0; } if (!isset($revision['navigation_title'])) { $revision['navigation_title'] = $revision['title']; } if (!isset($revision['navigation_title_overwrite'])) { $revision['navigation_title_overwrite'] = 'N'; } if (!isset($revision['hidden'])) { $revision['hidden'] = 'N'; } if (!isset($revision['status'])) { $revision['status'] = 'active'; } if (!isset($revision['publish_on'])) { $revision['publish_on'] = gmdate('Y-m-d H:i:s'); } if (!isset($revision['created_on'])) { $revision['created_on'] = gmdate('Y-m-d H:i:s'); } if (!isset($revision['edited_on'])) { $revision['edited_on'] = gmdate('Y-m-d H:i:s'); } if (!isset($revision['data'])) { $revision['data'] = null; } if (!isset($revision['allow_move'])) { $revision['allow_move'] = 'Y'; } if (!isset($revision['allow_children'])) { $revision['allow_children'] = 'Y'; } if (!isset($revision['allow_edit'])) { $revision['allow_edit'] = 'Y'; } if (!isset($revision['allow_delete'])) { $revision['allow_delete'] = 'Y'; } if (!isset($revision['sequence'])) { $revision['sequence'] = (int) $this->getDB()->getVar('SELECT MAX(sequence) + 1 FROM pages WHERE language = ? AND parent_id = ? AND type = ?', array($revision['language'], $revision['parent_id'], $revision['type'])); } if (!isset($revision['extra_ids'])) { $revision['extra_ids'] = null; } if (!isset($revision['has_extra'])) { $revision['has_extra'] = $revision['extra_ids'] ? 'Y' : 'N'; } // meta needs to be inserted if (!isset($revision['meta_id'])) { // build meta if (!isset($meta['keywords'])) { $meta['keywords'] = $revision['title']; } if (!isset($meta['keywords_overwrite'])) { $meta['keywords_overwrite'] = false; } if (!isset($meta['description'])) { $meta['description'] = $revision['title']; } if (!isset($meta['description_overwrite'])) { $meta['description_overwrite'] = false; } if (!isset($meta['title'])) { $meta['title'] = $revision['title']; } if (!isset($meta['title_overwrite'])) { $meta['title_overwrite'] = false; } if (!isset($meta['url'])) { $meta['url'] = SpoonFilter::urlise($revision['title']); } if (!isset($meta['url_overwrite'])) { $meta['url_overwrite'] = false; } if (!isset($meta['custom'])) { $meta['custom'] = null; } if (!isset($meta['data'])) { $meta['data'] = null; } // insert meta $revision['meta_id'] = $this->insertMeta($meta['keywords'], $meta['description'], $meta['title'], $meta['url'], $meta['keywords_overwrite'], $meta['description_overwrite'], $meta['title_overwrite'], $meta['url_overwrite'], $meta['custom'], $meta['data']); } // insert page $revision['revision_id'] = $this->getDB()->insert('pages', $revision); // get number of blocks to insert $numBlocks = $this->getDB()->getVar('SELECT MAX(num_blocks) FROM pages_templates WHERE theme = ? AND active = ?', array($this->getSetting('core', 'theme'), 'Y')); // get arguments (this function has a variable length argument list, to allow multiple blocks to be added) $blocks = array(); // loop blocks for ($i = 0; $i < $numBlocks; $i++) { // get block $block = @func_get_arg($i + 2); if ($block === false) { $block = array(); } else { $block = (array) $block; } // build block if (!isset($block['id'])) { $block['id'] = $i; } if (!isset($block['revision_id'])) { $block['revision_id'] = $revision['revision_id']; } if (!isset($block['status'])) { $block['status'] = 'active'; } if (!isset($block['created_on'])) { $block['created_on'] = gmdate('Y-m-d H:i:s'); } if (!isset($block['edited_on'])) { $block['edited_on'] = gmdate('Y-m-d H:i:s'); } if (!isset($block['extra_id'])) { $block['extra_id'] = null; } else { $revision['extra_ids'] = trim($revision['extra_ids'] . ',' . $block['extra_id'], ','); } if (!isset($block['html'])) { $block['html'] = ''; } elseif (SpoonFile::exists($block['html'])) { $block['html'] = SpoonFile::getContent($block['html']); } // insert block $this->getDB()->insert('pages_blocks', $block); } // blocks added if ($revision['extra_ids'] && $revision['has_extra'] == 'N') { // update page $revision['has_extra'] = 'Y'; $this->getDB()->update('pages', $revision, 'revision_id = ?', array($revision['revision_id'])); } // return page id return $revision['id']; }
} if (!in_array($frm->getField('blood')->getValue(), array('', 'O+', 'A+', 'B+', 'AB+', 'O-', 'A-', 'B-', 'AB-'))) { $frm->getField('blood')->setError('Please choose from the list only!'); } if ($frm->getField('height')->isFilled()) { $frm->getField('height')->isNumeric('Digits only please! eg: 180'); //it needs to be numeric! } if ($frm->getField('weight')->isFilled()) { $frm->getField('weight')->isNumeric('Digits only please! eg: 80'); //it needs to be numeric! } if ($frm->isCorrect()) { if ($frm->getField('photo')->isFilled()) { $imagename = uniqid(); SpoonFile::setContent(IMAGE_PATH . '/' . $imagename . '.' . $frm->getField('photo')->getExtension(), SpoonFile::getContent($frm->getField('photo')->getTempFileName())); //create Thumbnail $frm->getField('photo')->createThumbnail(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension(), 130, 130); } $company = ""; for ($i = 1; $i < 6; $i++) { $company .= $frm->getField('company' . $i)->getValue() . ', ' . $frm->getField('registerno' . $i)->getValue() . ', ' . $frm->getField('companyno' . $i)->getValue() . ', ' . $frm->getField('companyemail' . $i)->getValue() . ', ' . $frm->getField('shareholder' . $i)->getValue() . ', ' . $frm->getField('registeraddr' . $i)->getValue() . ', ' . $frm->getField('businessaddr' . $i)->getValue(); if ($i < 6) { $company .= ', '; } } //get values from form $values = array(); for ($i = 1; $i < 6; $i++) { $values = array_merge($values, array('company' . $i, 'shareholder' . $i, 'registerno' . $i, 'companyno' . $i, 'companyemail' . $i, 'registeraddr' . $i, 'businessaddr' . $i)); }
/** * Minify a javascript-file * * @return string * @param string $file The file to be minified. */ private function minifyJavascript($file) { // create unique filename $fileName = md5($file) . '.js'; $finalURL = FRONTEND_CACHE_URL . '/minified_js/' . $fileName; $finalPath = FRONTEND_CACHE_PATH . '/minified_js/' . $fileName; // file already exists (if SPOON_DEBUG is true, we should reminify every time if (SpoonFile::exists($finalPath) && !SPOON_DEBUG) { return $finalURL; } // grab content $content = SpoonFile::getContent(PATH_WWW . $file); // remove comments $content = preg_replace('/\\/\\*(.*)\\*\\//iUs', '', $content); $content = preg_replace('/([\\t\\w]{1,})\\/\\/.*/i', '', $content); // remove tabs $content = preg_replace('/\\t/i', ' ', $content); // remove faulty newlines $content = preg_replace('/\\r/iU', '', $content); // remove empty lines $content = preg_replace('/(^[\\r\\n]*|[\\r\\n]+)[\\s\\t]*[\\r\\n]+/', "\n", $content); // store SpoonFile::setContent($finalPath, $content); // return return $finalURL; }
/** * Converts a CSV file to an array * * @return array * @param array $path The full path to the CSV-file you want to extract an array from. * @param array[optional] $columns The column names you want to use. * @param array[optional] $excludeColumns The columns to exclude. * @param string[optional] $delimiter The field delimiter of the CSV. * @param string[optional] $enclosure The enclosure character of the CSV. */ public static function fileToArray($path, array $columns = array(), array $excludeColumns = null, $delimiter = ',', $enclosure = '"') { // reset variables $path = (string) $path; // validation if (!SpoonFile::exists($path)) { throw new SpoonFileException($path . ' doesn\'t exists.'); } // get delimiter and enclosure from the contents if (!$delimiter || !$enclosure) { $autoDetect = self::getDelimiterAndEnclosure(SpoonFile::getContent($path), $delimiter, $enclosure); } if (!$delimiter) { $delimiter = $autoDetect[0]; } if (!$enclosure) { $enclosure = $autoDetect[1]; } // automagicaly detect line endings @ini_set('auto_detect_line_endings', 1); // init var $rows = array(); // open file $handle = @fopen($path, 'r'); // loop lines and store the rows while (($row = @fgetcsv($handle, 0, $delimiter == '' ? ',' : $delimiter, $enclosure == '' ? '"' : $enclosure)) !== false) { $rows[] = $row; } // close file @fclose($handle); // no lines if (count($rows) == 0) { return false; } // no column names are set if (empty($columns)) { $columns = array_values($rows[0]); } // remove the first row array_shift($rows); // loop the rows foreach ($rows as $rowId => &$row) { // the keys of this row $keys = array_keys($row); // some columns are excluded if (!empty($excludeColumns)) { // unset the keys related to the excluded columns foreach ($excludeColumns as $columnKey => $column) { unset($keys[array_search($columnKey, $columns)], $row[$columnKey]); } } // loop the keys foreach ($keys as $columnId) { // add the field to this row $row[$columns[$columnId]] = $row[$columnId]; // remove the original field from this row unset($row[$columnId]); } } // return the array return $rows; }
/** * Add an attachment * * @return void * @param string[optional] $url A url to the file. * @param string[optional] $filePath The Path to the file if you want to include it in the ical file. * @param string[optional] $fmType Reccomended when using filePAth, the media type of file. */ public function addAttachment($url = null, $filePath = null, $fmtType = null) { // validate if ($url == null && $filePath == null) { throw new SpoonIcalException('Please provide either a file or url'); } // init var $attachment = array(); if ($url == null) { $attachment['ENCODING'] = "BASE64"; $attachment['VALUE'] = "BINARY"; if ($fmtType !== null) { $attachment['FMTTYPE'] = $fmtType; } $attachment['content'] = base64_encode(SpoonFile::getContent($filePath)); } else { $attachment['VALUE'] = 'URI'; $attachment['content'] = $url; } // init the array if empty if ($this->attach == null) { $this->attach = array(); } $attach[] = $attachment; }
public function execute() { parent::execute(); $txtText = \SpoonFile::getContent(BACKEND_MODULE_PATH . "/fabrikanten.txt"); $arrText = explode("\n", $txtText); $arrShop = array(); $arrShops = array(); $arrCompanyNames = array(); foreach ($arrText as $intKey => $strValue) { //--Check for phone $strPosTelephone = strpos($strValue, "Tel.:"); if ($strPosTelephone !== false) { $arrShop["phone"] = trim(str_replace("Tel.:", "", substr($strValue, $strPosTelephone))); } //--Check for fax $strPosFax = strpos($strValue, "Fax:"); if ($strPosFax !== false) { $arrShop["fax"] = trim(str_replace("Fax:", "", substr($strValue, $strPosFax))); } //--Find the e-mailaddress in the string if (!isset($arrShopFinal["email"])) { preg_match("/[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})/i", $strValue, $matchesEmail); if (!empty($matchesEmail)) { $arrShop["email"] = $matchesEmail[0]; } } //--Find the website address if (!isset($arrShopFinal["website"])) { preg_match("/www\\.[a-zA-Z0-9-]+\\.[a-z]{2,7}/i", $strValue, $matchesWebsite); if (!empty($matchesWebsite)) { $arrShop["website"] = $matchesWebsite[0]; } } //--Check the value if ($strValue != "" && !in_array($strValue, $arrCompanyNames) && $arrText[$intKey + 1] == "" && $arrText[$intKey + 2] == "" && empty($matchesWebsite)) { //--Check if shop is empty if (!empty($arrShop)) { //--Add shop to shops-array $arrShops[] = $arrShop; } $arrCity = explode(" ", $arrText[$intKey + 4], 2); //--New shop $arrShop = array(); $arrShop['company'] = $strValue; $arrShop['address'] = ucwords(strtolower($arrText[$intKey + 3])); $arrShop['zipcode'] = ucwords(strtolower($arrCity[0])); $arrShop['city'] = ucwords(strtolower($arrCity[1])); $arrShop['country'] = "BE"; //--Split zipcode $arrCountry = explode("-", $arrShop['zipcode']); if (count($arrCountry) > 1) { $arrShop['country'] = strtoupper($arrCountry[0]); } //--Add companyname to the values $arrCompanyNames[] = $strValue; } } //--Loop all the shops foreach ($arrShops as $row) { $meta = array(); $meta["keywords"] = $row["company"]; $meta["description"] = "import-address"; //$row["company"]; $meta["title"] = $row["company"]; $meta["url"] = $row["company"]; //--Replace the values with utf8 foreach ($row as &$value) { $value = utf8_encode($value); } //--Insert meta $row["meta_id"] = BackendAddressesModel::insertMeta($meta); //--Add address to the database $address_id = BackendAddressesModel::insert($row); //--Add address to group $address = array("address_id" => $address_id, "group_id" => 2); BackendAddressesModel::insertAddressToGroup($address); } }
/** * Install example data * * @param string $language The language to use. */ private function installExampleData($language) { // get db instance $db = $this->getDB(); // check if blogposts already exist in this language if (!(bool) $db->getVar('SELECT COUNT(id) FROM blog_posts WHERE language = ?', array($language))) { // insert sample blogpost 1 $db->insert('blog_posts', array('id' => 1, 'category_id' => $this->defaultCategoryId, 'user_id' => $this->getDefaultUserID(), 'meta_id' => $this->insertMeta('Nunc sediam est', 'Nunc sediam est', 'Nunc sediam est', 'nunc-sediam-est'), 'language' => $language, 'title' => 'Nunc sediam est', 'introduction' => SpoonFile::getContent(PATH_WWW . '/backend/modules/blog/installer/data/' . $language . '/sample1.txt'), 'text' => SpoonFile::getContent(PATH_WWW . '/backend/modules/blog/installer/data/' . $language . '/sample1.txt'), 'status' => 'active', 'publish_on' => gmdate('Y-m-d H:i:00'), 'created_on' => gmdate('Y-m-d H:i:00'), 'edited_on' => gmdate('Y-m-d H:i:00'), 'hidden' => 'N', 'allow_comments' => 'Y', 'num_comments' => '3')); // insert sample blogpost 2 $db->insert('blog_posts', array('id' => 2, 'category_id' => $this->defaultCategoryId, 'user_id' => $this->getDefaultUserID(), 'meta_id' => $this->insertMeta('Lorem ipsum', 'Lorem ipsum', 'Lorem ipsum', 'lorem-ipsum'), 'language' => $language, 'title' => 'Lorem ipsum', 'introduction' => SpoonFile::getContent(PATH_WWW . '/backend/modules/blog/installer/data/' . $language . '/sample1.txt'), 'text' => SpoonFile::getContent(PATH_WWW . '/backend/modules/blog/installer/data/' . $language . '/sample1.txt'), 'status' => 'active', 'publish_on' => gmdate('Y-m-d H:i:00', time() - 60), 'created_on' => gmdate('Y-m-d H:i:00', time() - 60), 'edited_on' => gmdate('Y-m-d H:i:00', time() - 60), 'hidden' => 'N', 'allow_comments' => 'Y', 'num_comments' => '0')); // insert example comment 1 $db->insert('blog_comments', array('post_id' => 1, 'language' => $language, 'created_on' => gmdate('Y-m-d H:i:00'), 'author' => 'Matthias Mullie', 'email' => '*****@*****.**', 'website' => 'http://www.mullie.eu', 'text' => 'cool!', 'type' => 'comment', 'status' => 'published', 'data' => null)); // insert example comment 2 $db->insert('blog_comments', array('post_id' => 1, 'language' => $language, 'created_on' => gmdate('Y-m-d H:i:00'), 'author' => 'Davy Hellemans', 'email' => '*****@*****.**', 'website' => 'http://www.spoon-library.com', 'text' => 'awesome!', 'type' => 'comment', 'status' => 'published', 'data' => null)); // insert example comment 3 $db->insert('blog_comments', array('post_id' => 1, 'language' => $language, 'created_on' => gmdate('Y-m-d H:i:00'), 'author' => 'Tijs Verkoyen', 'email' => '*****@*****.**', 'website' => 'http://www.sumocoders.be', 'text' => 'wicked!', 'type' => 'comment', 'status' => 'published', 'data' => null)); } }
/** * Insert a page * * @param array $revision An array with the revision data. * @param array[optional] $meta The meta-data. * @param array[optional] $block The blocks. */ protected function insertPage(array $revision, array $meta = null, array $block = null) { $revision = (array) $revision; $meta = (array) $meta; // deactive previous revisions if (isset($revision['id']) && isset($revision['language'])) { $this->getDB()->update('pages', array('status' => 'archive'), 'id = ? AND language = ?', array($revision['id'], $revision['language'])); } // build revision if (!isset($revision['language'])) { throw new SpoonException('language is required for installing pages'); } if (!isset($revision['title'])) { throw new SpoonException('title is required for installing pages'); } if (!isset($revision['id'])) { $revision['id'] = (int) $this->getDB()->getVar('SELECT MAX(id) + 1 FROM pages WHERE language = ?', array($revision['language'])); } if (!$revision['id']) { $revision['id'] = 1; } if (!isset($revision['user_id'])) { $revision['user_id'] = $this->getDefaultUserID(); } if (!isset($revision['template_id'])) { $revision['template_id'] = $this->getTemplateId('default'); } if (!isset($revision['type'])) { $revision['type'] = 'page'; } if (!isset($revision['parent_id'])) { $revision['parent_id'] = $revision['type'] == 'page' ? 1 : 0; } if (!isset($revision['navigation_title'])) { $revision['navigation_title'] = $revision['title']; } if (!isset($revision['navigation_title_overwrite'])) { $revision['navigation_title_overwrite'] = 'N'; } if (!isset($revision['hidden'])) { $revision['hidden'] = 'N'; } if (!isset($revision['status'])) { $revision['status'] = 'active'; } if (!isset($revision['publish_on'])) { $revision['publish_on'] = gmdate('Y-m-d H:i:s'); } if (!isset($revision['created_on'])) { $revision['created_on'] = gmdate('Y-m-d H:i:s'); } if (!isset($revision['edited_on'])) { $revision['edited_on'] = gmdate('Y-m-d H:i:s'); } if (!isset($revision['data'])) { $revision['data'] = null; } if (!isset($revision['allow_move'])) { $revision['allow_move'] = 'Y'; } if (!isset($revision['allow_children'])) { $revision['allow_children'] = 'Y'; } if (!isset($revision['allow_edit'])) { $revision['allow_edit'] = 'Y'; } if (!isset($revision['allow_delete'])) { $revision['allow_delete'] = 'Y'; } if (!isset($revision['sequence'])) { $revision['sequence'] = (int) $this->getDB()->getVar('SELECT MAX(sequence) + 1 FROM pages WHERE language = ? AND parent_id = ? AND type = ?', array($revision['language'], $revision['parent_id'], $revision['type'])); } // meta needs to be inserted if (!isset($revision['meta_id'])) { // build meta if (!isset($meta['keywords'])) { $meta['keywords'] = $revision['title']; } if (!isset($meta['keywords_overwrite'])) { $meta['keywords_overwrite'] = false; } if (!isset($meta['description'])) { $meta['description'] = $revision['title']; } if (!isset($meta['description_overwrite'])) { $meta['description_overwrite'] = false; } if (!isset($meta['title'])) { $meta['title'] = $revision['title']; } if (!isset($meta['title_overwrite'])) { $meta['title_overwrite'] = false; } if (!isset($meta['url'])) { $meta['url'] = $revision['title']; } if (!isset($meta['url_overwrite'])) { $meta['url_overwrite'] = false; } if (!isset($meta['custom'])) { $meta['custom'] = null; } if (!isset($meta['data'])) { $meta['data'] = null; } // insert meta $revision['meta_id'] = $this->insertMeta($meta['keywords'], $meta['description'], $meta['title'], $meta['url'], $meta['keywords_overwrite'], $meta['description_overwrite'], $meta['title_overwrite'], $meta['url_overwrite'], $meta['custom'], $meta['data']); } // insert page $revision['revision_id'] = $this->getDB()->insert('pages', $revision); // array of positions and linked blocks (will be used to automatically set block sequence) $positions = array(); // loop blocks: get arguments (this function has a variable length argument list, to allow multiple blocks to be added) for ($i = 0; $i < func_num_args() - 2; $i++) { // get block $block = @func_get_arg($i + 2); if ($block === false) { $block = array(); } else { $block = (array) $block; } // save block position if (!isset($block['position'])) { $block['position'] = 'main'; } $positions[$block['position']][] = $block; // build block if (!isset($block['revision_id'])) { $block['revision_id'] = $revision['revision_id']; } if (!isset($block['html'])) { $block['html'] = ''; } elseif (SpoonFile::exists($block['html'])) { $block['html'] = SpoonFile::getContent($block['html']); } if (!isset($block['created_on'])) { $block['created_on'] = gmdate('Y-m-d H:i:s'); } if (!isset($block['edited_on'])) { $block['edited_on'] = gmdate('Y-m-d H:i:s'); } if (!isset($block['extra_id'])) { $block['extra_id'] = null; } if (!isset($block['visible'])) { $block['visible'] = 'Y'; } if (!isset($block['sequence'])) { $block['sequence'] = count($positions[$block['position']]) - 1; } $this->getDB()->insert('pages_blocks', $block); } // return page id return $revision['id']; }
/** * Creates the configuration files */ private function createConfigurationFiles() { // build variables $variables = array(); $variables['\'<debug-mode>\''] = SpoonSession::get('debug_mode') ? 'true' : 'false'; $variables['<spoon-debug-email>'] = SpoonSession::get('different_debug_email') ? SpoonSession::get('debug_email') : SpoonSession::get('email'); $variables['<database-name>'] = SpoonSession::get('db_database'); $variables['<database-hostname>'] = addslashes(SpoonSession::get('db_hostname')); $variables['<database-username>'] = addslashes(SpoonSession::get('db_username')); $variables['<database-password>'] = addslashes(SpoonSession::get('db_password')); $variables['<database-port>'] = SpoonSession::exists('db_port') && SpoonSession::get('db_port') != '' ? addslashes(SpoonSession::get('db_port')) : 3306; $variables['<site-domain>'] = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'fork.local'; $variables['<site-default-title>'] = 'Fork CMS'; $variables['\'<site-multilanguage>\''] = SpoonSession::get('multiple_languages') ? 'true' : 'false'; $variables['<path-www>'] = PATH_WWW; $variables['<path-library>'] = PATH_LIBRARY; $variables['<site-default-language>'] = SpoonSession::get('default_language'); $variables['<action-group-tag>'] = '@actiongroup'; $variables['<action-rights-level>'] = 7; // globals files $configurationFiles = array('globals.base.php' => 'globals.php', 'globals_frontend.base.php' => 'globals_frontend.php', 'globals_backend.base.php' => 'globals_backend.php'); // loop files foreach ($configurationFiles as $sourceFilename => $destinationFilename) { // grab content $globalsContent = SpoonFile::getContent(PATH_LIBRARY . '/' . $sourceFilename); // assign the variables $globalsContent = str_replace(array_keys($variables), array_values($variables), $globalsContent); // write the file SpoonFile::setContent(PATH_LIBRARY . '/' . $destinationFilename, $globalsContent); } // general configuration file $globalsContent = SpoonFile::getContent(PATH_LIBRARY . '/config.base.php'); // assign the variables $globalsContent = str_replace(array_keys($variables), array_values($variables), $globalsContent); // write the file SpoonFile::setContent(PATH_WWW . '/backend/cache/config/config.php', $globalsContent); SpoonFile::setContent(PATH_WWW . '/frontend/cache/config/config.php', $globalsContent); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get parameters $page = trim(SpoonFilter::getPostValue('page', null, '')); $identifier = trim(SpoonFilter::getPostValue('identifier', null, '')); // validate if ($page == '' || $identifier == '') { $this->output(self::BAD_REQUEST, null, 'No page provided.'); } // init vars $filename = BACKEND_CACHE_PATH . '/analytics/' . $page . '_' . $identifier . '.txt'; // does the temporary file still exits? $status = SpoonFile::getContent($filename); // no file - create one if ($status === false) { // create file with initial counter SpoonFile::setContent($filename, 'missing1'); // return status $this->output(self::OK, array('status' => false), 'Temporary file was missing. We created one.'); } // busy status if (strpos($status, 'busy') !== false) { // get counter $counter = (int) substr($status, 4) + 1; // file's been busy for more than hundred cycles - just stop here if ($counter > 100) { // remove file SpoonFile::delete($filename); // return status $this->output(self::ERROR, array('status' => 'timeout'), 'Error while retrieving data - the script took too long to retrieve data.'); } // change file content to increase counter SpoonFile::setContent($filename, 'busy' . $counter); // return status $this->output(self::OK, array('status' => 'busy'), 'Data is being retrieved. (' . $counter . ')'); } // unauthorized status if ($status == 'unauthorized') { // remove file SpoonFile::delete($filename); // remove all parameters from the module settings BackendModel::setModuleSetting($this->getModule(), 'session_token', null); BackendModel::setModuleSetting($this->getModule(), 'account_name', null); BackendModel::setModuleSetting($this->getModule(), 'table_id', null); BackendModel::setModuleSetting($this->getModule(), 'profile_title', null); // remove cache files BackendAnalyticsModel::removeCacheFiles(); // clear tables BackendAnalyticsModel::clearTables(); // return status $this->output(self::OK, array('status' => 'unauthorized'), 'No longer authorized.'); } // done status if ($status == 'done') { // remove file SpoonFile::delete($filename); // return status $this->output(self::OK, array('status' => 'done'), 'Data retrieved.'); } // missing status if (strpos($status, 'missing') !== false) { // get counter $counter = (int) substr($status, 7) + 1; // file's been missing for more than ten cycles - just stop here if ($counter > 10) { // remove file SpoonFile::delete($filename); // return status $this->output(self::ERROR, array('status' => 'missing'), 'Error while retrieving data - file was never created.'); } // change file content to increase counter SpoonFile::setContent($filename, 'missing' . $counter); // return status $this->output(self::OK, array('status' => 'busy'), 'Temporary file was still in status missing. (' . $counter . ')'); } /* FALLBACK - SOMETHING WENT WRONG */ // remove file SpoonFile::delete($filename); // return status $this->output(self::ERROR, array('status' => 'error'), 'Error while retrieving data.'); }
/** * Get all data for a given revision. * * @return array * @param string[optional] $language The language to use. */ public static function getLinkList($language = null) { // redefine $language = $language !== null ? (string) $language : BackendLanguage::getWorkingLanguage(); // there is no cache file if (!SpoonFile::exists(FRONTEND_CACHE_PATH . '/navigation/tinymce_link_list_' . $language . '.js')) { return array(); } // read the cache file $cacheFile = SpoonFile::getContent(FRONTEND_CACHE_PATH . '/navigation/tinymce_link_list_' . $language . '.js'); // get the array preg_match('/new Array\\((.*)\\);$/s', $cacheFile, $matches); // no matched if (empty($matches)) { return array(); } // create array $matches = explode('],', str_replace('[', '', $matches[count($matches) - 1])); // init vars $cacheList = array(); // loop list foreach ($matches as $item) { // trim item $item = explode('", "', trim($item, " \n\r\t\"")); // build cache list $cacheList[$item[1]] = $item[0]; } // return cache list return $cacheList; }
/** * Get the supported methods by module. * * @param string $module The module we are fetching the supported methods for. * @return array */ public static function getSupportedMethodsByModule($module) { $helperFile = FRONTEND_MODULES_PATH . '/' . $module . '/engine/slideshows.php'; $helperFileContents = \SpoonFile::getContent($helperFile); $results = array(); preg_match_all('/public static function (.*)\\((.*)\\)/', $helperFileContents, $matches); if (isset($matches[1]) && !empty($matches[1])) { foreach ($matches[1] as $key => $method) { $results[$key]['class'] = 'Frontend' . ucwords($module) . 'SlideshowsModel'; $results[$key]['methods'][] = $method; } } return $results; }