コード例 #1
0
 /** Preparse
  * @param string $path
  *	Source path
  * @param string $path_new
  *	Destination path
  * @param string|bool $path_to_cut
  *	Common path of module/style (internal use)
  * @param bool $rm_flags
  *	Remove flag comments?
  *
  * @return string
  */
 public function parse($path, $path_new, $path_to_cut = "", $rm_flags = false)
 {
     global $Config, $Log;
     // is packet set?
     if (empty($this->Packet)) {
         return false;
     }
     // get all files
     $files = ts_FileHandler::getSubfiles($path);
     // preparse all files
     foreach ($files as $index => $value) {
         if (substr($value, -4) == ".swp") {
             continue;
         }
         if (!$this->parseFile("{$path}/{$value}", "{$path_new}/{$value}", $path_to_cut, $rm_flags)) {
             return false;
         }
     }
     // get all subfolders
     $subfolders = ts_FileHandler::getSubfolders($path);
     // parse all subfolders
     foreach ($subfolders as $index => $value) {
         // only move directories named static
         if ($value == 'static') {
             ts_FileHandler::copyFolder("{$path}/{$value}", "{$path_new}/{$value}");
             continue;
         }
         if (!$this->parse("{$path}/{$value}", "{$path_new}/{$value}", $path_to_cut, $rm_flags)) {
             $Log->doLog(3, "PreParser: Failed to preparse subfolder ({$path}/{$value})");
             return false;
         }
     }
     return true;
 }
コード例 #2
0
 /** Validate source code
  * @param bool $force_update
  *	Force to get new list from database (not a cached one from obj-var)
  *
  * @return array
  */
 public function getModules($force_update = false)
 {
     global $Database, $Config;
     // already in obj-var?
     if (!$force_update and isset($this->modules) and !empty($this->modules)) {
         return $this->modules;
     }
     // get module-ids from database
     $sql = "SELECT id__module as id__module\n\t\tFROM #__modules\n\t\tORDER BY id__module ASC;";
     $result = $Database->doSelect($sql);
     if ($result === false) {
         return false;
     }
     // get available sources
     $subfolders = ts_FileHandler::getSubfolders($Config->get('dir_data') . '/source/modules/');
     if (!is_array($subfolders)) {
         return false;
     }
     // get module-objects and save them in obj-var
     $modules_files = array();
     foreach ($subfolders as $index => $value) {
         $modules_files[] = new ts_Module(false, $value);
     }
     // add already deleted modules and rearrange
     $this->modules = array();
     foreach ($modules_files as $index => $Value) {
         $this->modules[$Value->getInfo('name') . '__' . $Value->getInfo('nameid')] = $Value;
     }
     foreach ($result as $index => $values) {
         $Module = new ts_Module($values['id__module']);
         if (!isset($this->modules[$Module->getInfo('name') . '__' . $Module->getInfo('nameid')])) {
             $this->modules[$Module->getInfo('name') . '__' . $Module->getInfo('nameid')] = $Module;
         }
     }
     // sort
     ksort($this->modules);
     // sort modules by dependencies
     usort($this->modules, array($this, 'cb_sortByDependencies'));
     $this->modules = array_reverse($this->modules);
     return $this->modules;
 }
コード例 #3
0
 /** Get all styles
  * @param bool $force_update
  *	Force to get new list from database (not a cached one from obj-var)?
  *
  * @return array
  */
 public function getStyles($force_update = false)
 {
     global $Database, $Config;
     // already in obj-var?
     if (!$force_update and isset($this->styles) and !empty($this->styles)) {
         return $this->styles;
     }
     // get module-ids from database
     $sql = "SELECT id__style as id__style\n\t    FROM #__styles\n\t    ORDER BY name ASC;";
     $result = $Database->doSelect($sql);
     if ($result === false) {
         return false;
     }
     // get available sources
     $subfolders = ts_FileHandler::getSubfolders($Config->get('dir_data') . '/source/styles');
     if (!is_array($subfolders)) {
         return false;
     }
     // get style objects and save them in obj-var
     $style_files = array();
     foreach ($subfolders as $index => $value) {
         $style_files[] = new ts_Style(false, $value);
     }
     // add already deleted styles
     $this->styles = array();
     foreach ($style_files as $index => $Value) {
         $this->styles[$Value->getInfo('name') . '__' . $Value->getInfo('nameid')] = $Value;
     }
     foreach ($result as $index => $values) {
         $Style = new ts_Style($values['id__style']);
         if (!isset($this->styles[$Style->getInfo('name') . '__' . $Style->getInfo('nameid')])) {
             $this->styles[$Style->getInfo('name') . '__' . $Style->getInfo('nameid')] = $Style;
         }
     }
     // sort
     ksort($this->styles);
     return $this->styles;
 }
コード例 #4
0
 /** Inject all subcodes and complete file-rendering
  * @param string|bool $path
  *	Path to folder in which all files will be
  *
  * @return bool
  */
 public function parseAll($path = false)
 {
     global $Config, $Parser, $Log;
     // run all?
     if ($path == false) {
         if ($this->parseAll($Config->get('dir_runtime') . '/functions') and $this->parseAll($Config->get('dir_runtime') . '/classes') and $this->parseAll($Config->get('dir_runtime') . '/templates')) {
             return true;
         }
         return false;
     }
     // validate path
     if (!is_dir($path)) {
         $Log->doLog(3, "SubcodeHandler: Failed to parse path '{$path}'");
         return false;
     }
     // parse all files
     $subfiles = ts_FileHandler::getSubfiles($path);
     foreach ($subfiles as $index => $value) {
         // get filepath
         $filepath = $path . '/' . $value;
         // read file
         $content = ts_FileHandler::readFile($filepath);
         if ($content === false) {
             $Log->doLog(3, "SubcodeHandler: Failed to read file '{$filepath}'");
             return false;
         }
         // check, if anything to replace in this file
         if (isset($this->subcodes[$filepath])) {
             // parse all lines to be add
             foreach ($this->subcodes[$filepath] as $in => $val) {
                 $to_add = '';
                 // sum everything to add to this line
                 foreach ($val as $i => $v) {
                     $to_add .= $v;
                 }
                 // replace line by subfunctions
                 $content = str_replace('{line_' . $in . '}', $to_add, $content);
             }
         }
         // strip all {line_xx}
         $content = preg_replace('#\\{line_[0-9]*\\}#Usi', '', $content);
         // trim again
         $content = $Parser->trim($content, true);
         // write file
         if (!ts_FileHandler::writeFile($filepath, $content, true)) {
             $Log->doLog(3, "SubcodeHandler: Failed to write file '{$filepath}'");
             return false;
         }
     }
     // parse all subfolders
     $subfolders = ts_FileHandler::getSubfolders($path);
     foreach ($subfolders as $index => $value) {
         if (!$this->parseAll($path . '/' . $value)) {
             return false;
         }
     }
     return true;
 }
コード例 #5
0
ファイル: ts_Style.class.php プロジェクト: nfrickler/tsunic
 /** Parse template files of this module
  *
  * @return bool
  */
 protected function parseTemplates()
 {
     global $Config, $Parser;
     // source-path
     $path_source = $this->path . '/modules';
     // loop modules
     $modules = ts_FileHandler::getSubfolders($path_source);
     foreach ($modules as $index => $value) {
         // get id__module
         $id__module = $Parser->replaceModule('$' . $value . '$');
         if (!$id__module) {
             continue;
         }
         $id__module = substr($id__module, 3, strlen($id__module) - 5);
         // set id__module
         $Parser->setModule($id__module);
         // get path_new
         $path_new = $Config->get('dir_runtime') . '/templates';
         $prefix = 'style' . $this->id . '__mod' . $id__module . '__';
         // get current path
         $path_current = $path_source . '/' . $value;
         // get all files
         $files = ts_FileHandler::getSubfiles($path_current);
         // parse all files
         foreach ($files as $in => $val) {
             // read
             $content = ts_FileHandler::readFile($path_current . '/' . $val);
             // parse
             $content = $Parser->parse($content, true);
             // write
             if (!$content or !ts_FileHandler::writeFile($path_new . '/' . $prefix . $val, $content, true)) {
                 return false;
             }
         }
     }
     return true;
 }