/** 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; }
/** Update module * * @return bool */ public function updateModule() { global $Database, $Parser, $Log; $Log->doLog(3, "Update module " . $this->getName()); // get versions $sql = "SELECT version_installed, version\n\t FROM #__modules\n\t WHERE id__module = '" . mysql_real_escape_string($this->id) . "'\n\t;"; $result = $Database->doSelect($sql); if (empty($result)) { return false; } $result = $result[0]; // skip update, if version is older if ($result['version'] <= $result['version_installed']) { return false; } // get all available updaters $files = ts_FileHandler::getSubfiles($this->path . '/setup'); $files_update = array(); foreach ($files as $index => $value) { $cache = explode('.', $value); $filename = substr($value, 0, strlen($value) - strlen(end($cache)) - 1); $cache = explode('_to_', substr($filename, strlen('update_'))); if (substr($value, 0, strlen('update_')) != 'update_' or count($cache) != 2) { continue; } // save $files_update[$cache[0]] = $cache[1]; } // try to find best way to update to new version $best_way = $this->_findWay($files_update, $result['version_installed'], $result['version']); // follow best way and update // if there is no way, just use new files without updating database $version_installed = $result['version']; if ($best_way) { $version_installed = $result['version_installed']; foreach ($best_way as $index => $value) { // search for update-files and run them if (file_exists($this->path . '/setup/update_' . $index . '_to_' . $value . '.sql')) { // run sql-file // read sql-file $content = ts_FileHandler::readFile($this->path . '/setup/uninstall.sql'); // parse module replacements $content = $Parser->replaceModule($content, $this->id, $Database->getPreffix()); // run sql statements if ($Database->runString($content) === false) { break; } } if (file_exists($this->path . '/setup/update_' . $index . '_to_' . $value . '.php')) { // run php-file $break = false; include $this->path . '/setup/update_' . $index . '_to_' . $value . '.php'; if ($break) { break; } } $version_installed = $value; } } // set update time and new version in database $sql = "UPDATE #__modules\n\t SET dateOfUpdate = NOW(),\n\t\tversion_installed =\n\t\t '" . mysql_real_escape_string($version_installed) . "'\n\t WHERE id__module = '" . mysql_real_escape_string($this->id) . "'\n\t;"; if (!$Database->doUpdate($sql)) { return false; } if ($version_installed != $result['version']) { return false; } return true; }
/** 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; }
/** Parse template files of this module * * @return bool */ protected function _parseLanguages() { global $LanguageHandler; // get lang-files $path_source = $this->path . '/lang'; $files = ts_FileHandler::getSubfiles($path_source); // parse all files foreach ($files as $index => $value) { // get language of lang-file $cache = explode('.', $value); // read lang-file if (!$LanguageHandler->add('style', $this->id, $cache[0], $path_source . '/' . $value)) { return false; } } return true; }