/** Uninstall module * * @return bool */ public function uninstallModule() { global $Database, $Parser; // search for uninstall-scripts in 'setup'-dir if (file_exists($this->path . '/setup/uninstall.sql')) { // 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) { return false; } } if (file_exists($this->path . '/setup/uninstall.php')) { // run php-file include $this->path . '/setup/uninstall.php'; } // successful deinstallation (set uninstall-time in database) $sql = "UPDATE #__modules\n\t SET dateOfUninstall = NOW()\n\t WHERE id__module = '" . $this->id . "';"; if (!$Database->doUpdate($sql)) { return false; } return true; }
/** Parse format.css file of this module * * @return bool */ protected function parseFormat() { global $FormatHandler, $Parser; // get path $path_source = $this->path . '/format.css'; // get format of module $format = ts_FileHandler::readFile($path_source); // replace modules $format = $Parser->replaceModule($format); $format = $Parser->trim($format, false, true); // add to format if ($FormatHandler->add($format, $this->id)) { return true; } return false; }
/** 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; }
/** Preparse file * @param string $source * Source file * @param string $destination * Destination file * @param string $path_to_cut * Path to root * @param bool $rm_flags * Remove flag comments? * * @return bool */ public function parseFile($source, $destination, $path_to_cut = "", $rm_flags = false) { global $Config, $Log; // is packet set? if (empty($this->Packet)) { return false; } // read $Log->doLog(8, "PreParser: Read file '{$source}'"); $content = ts_FileHandler::readFile($source); if ($content === false) { $Log->doLog(3, "PreParser: Unable to read file '{$source}'"); return false; } // get filetype $cache = explode('.', basename($source)); $filetype = end($cache); // filetype to move only? if (!in_array($filetype, $this->parse_ext)) { if ($source != $destination and !ts_FileHandler::writeFile($destination, $content)) { $Log->doLog(3, "PreParser: Unable to move file to '{$destination}'"); return false; } return true; } // split flag comment from rest of content if (substr($content, 0, 4) != '<!--') { $content = '<!-- | -->' . chr(10) . $content; } $content_lines = explode(chr(10), $content); $flag_comment = trim($content_lines[0]); unset($content_lines[0]); $content = implode(chr(10), $content_lines); // read flags and get path to display $flags = $this->getFlags($flag_comment); if (isset($flags['p'])) { return true; } $displaypath = substr($destination, strlen($path_to_cut) + 1); // add header if (!isset($flags['h'])) { // remove existing headers $content = preg_replace('#(\\/\\*\\* header .* \\*\\/)#Usi', '', $content); $content = preg_replace('#(\\<\\?php[\\s]*\\?\\>)#Usi', '', $content); $content = preg_replace('#(\\<!--[\\s]*--\\>)#Usi', '', $content); // generate new header // First two lines have to be separated or the publish // script will remove the following header definition! $header = '/*' . '* header *********************************************************' . chr(10) . ' * project: TSunic ' . $Config->get('version') . ' | ' . $this->Packet->getInfo('name') . ' ' . $this->Packet->getInfo('version') . chr(10) . ' * file: ' . $displaypath . chr(10); if ($this->Packet->getInfo('author')) { $header .= ' * author: ' . $this->Packet->getInfo('author') . chr(10); } if ($this->Packet->getInfo('copyright')) { $header .= ' * copyright: ' . $this->Packet->getInfo('copyright') . chr(10); } if ($this->Packet->getInfo('licence')) { $cache = explode(chr(10), $this->Packet->getInfo('licence')); $header .= ' * licence: ' . trim($cache[0]) . chr(10); if (count($cache) > 1) { for ($i = 1; $i < count($cache); $i++) { $cache[$i] = trim($cache[$i]); $header .= empty($cache[$i]) ? ' *' . chr(10) : ' * ' . $cache[$i] . chr(10); } } } $header .= ' * ************************************************************** */' . chr(10); // embed header in required tags switch ($filetype) { case 'php': $header = '<?php' . chr(10) . $header . '?>'; break; case 'js': case 'css': break; default: $header = '<!--' . chr(10) . $header . '-->'; break; } // add header to content $content = $header . chr(10) . $content; // skip empty lines at the beginning $cache = explode(chr(10), $content); foreach ($cache as $index => $value) { $value = trim($value); if (empty($value)) { unset($cache[$index]); continue; } elseif ($value == '<?php') { continue; } break; } $content = implode(chr(10), $cache); } // add flag comment again if (!$rm_flags) { $content = $flag_comment . chr(10) . $content; } // trim $content = str_replace('?>' . chr(10) . '<?php', '', $content); // write $Log->doLog(8, "PreParser: Write file '{$source}'"); if (!ts_FileHandler::writeFile($destination, $content, 1)) { $Log->doLog(3, "PreParser: Unable to write file ({$destination})"); return false; } return true; }