/** * Scans the directory structure for modules and adds them to the list of optional modules */ private function loadModules() { // fetch modules $tmpModules = SpoonDirectory::getList(PATH_WWW . '/backend/modules', false, null, '/^[a-z0-9_]+$/i'); // loop modules foreach ($tmpModules as $module) { // not required nor hidden if (!in_array($module, $this->modules['required']) && !in_array($module, $this->modules['hidden'])) { // add to the list of optional installs $this->modules['optional'][] = $module; } } }
/** * Set the module * * We can't rely on the parent setModule function, because a cronjob requires no login * * @param string $module The module to load. */ public function setModule($module) { // does this module exist? $modules = SpoonDirectory::getList(BACKEND_MODULES_PATH); $modules[] = 'core'; if (!in_array($module, $modules)) { // set correct headers SpoonHTTP::setHeadersByCode(403); // throw exception throw new BackendException('Module not allowed.'); } // set property $this->module = $module; }
/** * Delete the cached data */ private function deleteCachedData() { // init some vars $foldersToLoop = array('/backend/cache', '/frontend/cache'); $foldersToIgnore = array('/backend/cache/navigation'); $filesToIgnore = array('.gitignore'); $filesToDelete = array(); // loop folders foreach ($foldersToLoop as $folder) { // get folderlisting $subfolders = (array) SpoonDirectory::getList(PATH_WWW . $folder, false, array('.svn', '.gitignore')); // loop folders foreach ($subfolders as $subfolder) { // not in ignore list? if (!in_array($folder . '/' . $subfolder, $foldersToIgnore)) { // get the filelisting $files = (array) SpoonFile::getList(PATH_WWW . $folder . '/' . $subfolder); // loop the files foreach ($files as $file) { if (!in_array($file, $filesToIgnore)) { $filesToDelete[] = PATH_WWW . $folder . '/' . $subfolder . '/' . $file; } } } } } // delete cached files if (!empty($filesToDelete)) { // loop files and delete them foreach ($filesToDelete as $file) { SpoonFile::delete($file); } } }
/** * Get all data for templates in a format acceptable for SpoonForm::addRadioButton() and SpoonForm::addMultiCheckbox() * * @param string $language The language. * @return array */ public static function getTemplatesForCheckboxes($language) { // load all templates in the 'templates' folder for this language $records = SpoonDirectory::getList(BACKEND_MODULE_PATH . '/templates/' . $language . '/', false, array('.svn')); // stop here if no directories were found if (empty($records)) { return array(); } // loop and complete the records foreach ($records as $key => $record) { // add additional values $records[$record]['language'] = $language; $records[$record]['value'] = $record; $records[$record]['label'] = BL::lbl('Template' . SpoonFilter::toCamelCase($record, array('-', '_'))); // unset the key unset($records[$key]); } return (array) $records; }
/** * Get the filetree * * @param string $path The path to get the filetree for. * @param array[optional] $tree An array to hold the results. * @return array */ private static function getTree($path, array $tree = array()) { // paths that should be ignored $ignore = array(BACKEND_CACHE_PATH, BACKEND_CORE_PATH . '/js/ckeditor', BACKEND_CACHE_PATH, BACKEND_CORE_PATH . '/js/ckfinder', FRONTEND_CACHE_PATH); // get modules $modules = BackendModel::getModules(); // get the folder listing $items = SpoonDirectory::getList($path, true, array('.svn', '.git')); // already in the modules? if (substr_count($path, '/modules/') > 0) { // get last chunk $start = strpos($path, '/modules') + 9; $end = strpos($path, '/', $start + 1); if ($end === false) { $moduleName = substr($path, $start); } else { $moduleName = substr($path, $start, $end - $start); } // don't go any deeper if (!in_array($moduleName, $modules)) { return $tree; } } foreach ($items as $item) { // if the path should be ignored, skip it if (in_array($path . '/' . $item, $ignore)) { continue; } // if the item is a directory we should index it also (recursive) if (is_dir($path . '/' . $item)) { $tree = self::getTree($path . '/' . $item, $tree); } else { // if the file has an extension that has to be processed add it into the tree if (in_array(SpoonFile::getExtension($item), array('js', 'php', 'tpl'))) { $tree[] = $path . '/' . $item; } } } return $tree; }
/** * Fetch the list of available themes * * @return array */ public static function getThemes() { // fetch themes $records = (array) SpoonDirectory::getList(FRONTEND_PATH . '/themes/', false, array('.svn')); // loop and complete the records foreach ($records as $key => $record) { try { // path to info.xml $pathInfoXml = PATH_WWW . '/frontend/themes/' . $record . '/info.xml'; // load info.xml $infoXml = @new SimpleXMLElement($pathInfoXml, LIBXML_NOCDATA, true); // convert xml to useful array $information = BackendExtensionsModel::processThemeXml($infoXml); if (!$information) { throw new BackendException('Invalid info.xml'); } } catch (Exception $e) { // spoon thumbnail value $information['thumbnail'] = 'thumbnail.png'; } // add additional values $records[$record]['value'] = $record; $records[$record]['label'] = $record; $records[$record]['thumbnail'] = '/frontend/themes/' . $record . '/' . $information['thumbnail']; // doublecheck if templates for this theme are installed already $records[$record]['installed'] = self::isThemeInstalled($record); $records[$record]['installable'] = isset($information['templates']); // unset the key unset($records[$key]); } // add core theme $core = array('core' => array()); $core['core']['value'] = 'core'; $core['core']['label'] = BL::lbl('NoTheme'); $core['core']['thumbnail'] = '/frontend/core/layout/images/thumbnail.png'; $core['core']['installed'] = self::isThemeInstalled('core'); $core['core']['installable'] = false; $records = array_merge($core, $records); return (array) $records; }
/** * Get the thumbnail folders * * @param string $path The path * @param bool[optional] $includeSource Should the source-folder be included in the return-array. * @return array */ public static function getThumbnailFolders($path, $includeSource = false) { $folders = SpoonDirectory::getList((string) $path, false, null, '/^([0-9]*)x([0-9]*)$/'); if ($includeSource && SpoonDirectory::exists($path . '/source')) { $folders[] = 'source'; } $return = array(); foreach ($folders as $folder) { $item = array(); $chunks = explode('x', $folder, 2); // skip invalid items if (count($chunks) != 2 && !$includeSource) { continue; } $item['dirname'] = $folder; $item['path'] = $path . '/' . $folder; if (substr($path, 0, strlen(PATH_WWW)) == PATH_WWW) { $item['url'] = substr($item['path'], strlen(PATH_WWW)); } if ($folder == 'source') { $item['width'] = null; $item['height'] = null; } else { $item['width'] = $chunks[0] != '' ? (int) $chunks[0] : null; $item['height'] = $chunks[1] != '' ? (int) $chunks[1] : null; } $return[] = $item; } return $return; }
/** * Fetch the list of available themes * * @return array */ public static function getThemes() { // fetch themes $themes = (array) SpoonDirectory::getList(FRONTEND_PATH . '/themes/', false, array('.svn')); // create array $themes = array_combine($themes, $themes); // add core templates $themes = array_merge(array('core' => BL::lbl('NoTheme')), $themes); return $themes; }
/** * 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 = PATH_WWW . '/backend/modules/mailmotor/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['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; }