/** * @param string $to - path where the archive should be extracted to * @return bool */ public function extract($to) { $r = false; $ext = SPFs::getExt($this->_filename); switch ($ext) { case 'zip': $zip = new ZipArchive(); if ($zip->open($this->_filename) === true) { SPException::catchErrors(SPC::WARNING); try { $zip->extractTo($to); $zip->close(); $r = true; } catch (SPException $x) { $t = Sobi::FixPath(Sobi::Cfg('fs.temp') . DS . md5(microtime())); SPFs::mkdir($t, 0777); $dir = SPFactory::Instance('base.fs.directory', $t); if ($zip->extractTo($t)) { $zip->close(); $dir->moveFiles($to); $r = true; } SPFs::delete($dir->getPathname()); } SPException::catchErrors(0); } break; } return $r; }
public static function __callStatic($name, $args) { if (defined('SOBIPRO_ADM')) { return call_user_func_array(array('self', '_' . $name), $args); } else { static $className = false; if (!$className) { $package = Sobi::Reg('current_template'); if (SPFs::exists(Sobi::FixPath($package . '/input.php'))) { $path = Sobi::FixPath($package . '/input.php'); ob_start(); $content = file_get_contents($path); $class = array(); preg_match('/\\s*(class)\\s+(\\w+)/', $content, $class); if (isset($class[2])) { $className = $class[2]; } else { Sobi::Error('Custom Input Class', SPLang::e('Cannot determine class name in file %s.', str_replace(SOBI_ROOT, null, $path)), SPC::WARNING, 0); return false; } require_once $path; } else { $className = true; } } if (is_string($className) && method_exists($className, $name)) { return call_user_func_array(array($className, $name), $args); } else { return call_user_func_array(array('self', '_' . $name), $args); } } }
public function install() { $id = $this->xGetString('id'); $name = $this->xGetString('name'); if (SPLoader::dirPath('usr.templates.' . $id) && !SPRequest::bool('force')) { throw new SPException(SPLang::e('TEMPLATE_INST_DUPLICATE', $name) . ' ' . Sobi::Txt('FORCE_TPL_UPDATE', Sobi::Url(array('task' => 'extensions.install', 'force' => 1, 'root' => basename($this->root) . '/' . basename($this->xmlFile))))); } $requirements = $this->xGetChilds('requirements/*'); if ($requirements && $requirements instanceof DOMNodeList) { SPFactory::Instance('services.installers.requirements')->check($requirements); } $language = $this->xGetChilds('language/file'); $folder = @$this->xGetChilds('language/@folder')->item(0)->nodeValue; if ($language && $language instanceof DOMNodeList && $language->length) { $langFiles = array(); foreach ($language as $file) { $adm = false; if ($file->attributes->getNamedItem('admin')) { $adm = $file->attributes->getNamedItem('admin')->nodeValue == 'true' ? true : false; } $langFiles[$file->attributes->getNamedItem('lang')->nodeValue][] = array('path' => Sobi::FixPath("{$this->root}/{$folder}/" . trim($file->nodeValue)), 'name' => $file->nodeValue, 'adm' => $adm); } SPFactory::CmsHelper()->installLang($langFiles, false, true); } $path = SPLoader::dirPath('usr.templates.' . $id, 'front', false); if (SPRequest::bool('force')) { /** @var $from SPDirectory */ $from = SPFactory::Instance('base.fs.directory', $this->root); $from->moveFiles($path); } else { if (!SPFs::move($this->root, $path)) { throw new SPException(SPLang::e('CANNOT_MOVE_DIRECTORY', $this->root, $path)); } } if (!SPRequest::bool('force')) { $section = $this->xGetChilds('install'); if ($section instanceof DOMNodeList && $section->length) { $this->section($id); } } //05 Oct 2015 Kishore $exec = $this->xGetString('exec'); if ($exec && SPFs::exists($path . DS . $exec)) { include_once "{$path}/{$exec}"; } /** @var $dir SPDirectory */ $dir =& SPFactory::Instance('base.fs.directory', $path); $zip = array_keys($dir->searchFile('.zip', false)); if (count($zip)) { foreach ($zip as $file) { SPFs::delete($file); } } Sobi::Trigger('After', 'InstallTemplate', array($id)); $dir =& SPFactory::Instance('base.fs.directory', SPLoader::dirPath('tmp.install')); $dir->deleteFiles(); return Sobi::Txt('TP.TEMPLATE_HAS_BEEN_INSTALLED', array('template' => $name)); }
/** * @param string $dir - path * @return SPDirectoryIterator */ public function __construct($dir) { $Dir = scandir($dir); $this->_dir = new ArrayObject(); foreach ($Dir as $file) { $this->append(new SPFile(Sobi::FixPath($dir . '/' . $file))); } $this->uasort(array($this, '_spSort')); }
/** * Move files from directory to given path * @param string $target - target path * @return array */ public function moveFiles($target) { $this->iterator(); $log = array(); foreach ($this->_dirIterator as $child) { if (!$child->isDot() && !SPFs::exists(Sobi::FixPath($target . DS . $child->getFileName()))) { if (SPFs::move($child->getPathname(), Sobi::FixPath($target . DS . $child->getFileName()))) { $log[] = Sobi::FixPath($target . DS . $child->getFileName()); } } } return $log; }
/** */ private function edit() { $pid = $this->get('category.parent'); $path = null; if (!$pid) { $pid = SPRequest::int('pid'); } $this->assign($pid, 'parent'); $id = $this->get('category.id'); if ($id) { $this->addHidden($id, 'category.id'); } if (!strstr($this->get('category.icon'), 'font')) { if ($this->get('category.icon') && SPFs::exists(Sobi::Cfg('images.category_icons') . '/' . $this->get('category.icon'))) { $i = Sobi::FixPath(Sobi::Cfg('images.category_icons_live') . $this->get('category.icon')); $this->assign($i, 'category_icon'); } else { $i = Sobi::FixPath(Sobi::Cfg('images.category_icons_live') . Sobi::Cfg('icons.default_selector_image', 'image.png')); $this->assign($i, 'category_icon'); } } // else { // $i = SPLang::clean( $this->get( 'category.icon' ) ); // $this->assign( $i, 'category_icon' ); // } /* if editing - get the full path. Otherwise get the path of the parent element */ $id = $id ? $id : $pid; if ($this->get('category.id')) { $path = $this->parentPath($id); $parentCat = $this->parentPath($id, false, true); } else { $path = $this->parentPath(SPRequest::sid()); $parentCat = $this->parentPath(SPRequest::sid(), false, true, 1); } $this->assign($path, 'parent_path'); $this->assign($parentCat, 'parent_cat'); if (SPRequest::sid()) { $this->assign(Sobi::Url(array('task' => 'category.chooser', 'sid' => SPRequest::sid(), 'out' => 'html'), true), 'cat_chooser_url'); } elseif (SPRequest::int('pid')) { $this->assign(Sobi::Url(array('task' => 'category.chooser', 'pid' => SPRequest::int('pid'), 'out' => 'html'), true), 'cat_chooser_url'); } $this->assign(Sobi::Url(array('task' => 'category.icon', 'out' => 'html'), true), 'icon_chooser_url'); }
public function cachedView($xml, $template, $cacheId, $config = array()) { $this->_xml = $xml; Sobi::Trigger('Start', ucfirst(__FUNCTION__), array(&$this->_xml)); $templatePackage = SPLoader::translateDirPath(Sobi::Cfg('section.template'), 'templates'); $templateOverride = SPRequest::cmd('sptpl'); if ($templateOverride) { if (strstr($templateOverride, '.')) { $templateOverride = str_replace('.', '/', $templateOverride); } $template = $templateOverride . '.xsl'; } if (file_exists(Sobi::FixPath($templatePackage . '/' . $template))) { $template = Sobi::FixPath($templatePackage . '/' . $template); } else { $type = SPFactory::db()->select('oType', 'spdb_object', array('id' => SPRequest::sid()))->loadResult(); $template = $templatePackage . '/' . $type . '/' . $template; } SPFactory::registry()->set('current_template', $templatePackage); $this->_templatePath = $templatePackage; $this->_template = str_replace('.xsl', null, $template); $ini = array(); if (count($config)) { foreach ($config as $file) { $file = parse_ini_file($file, true); foreach ($file as $section => $keys) { if (isset($ini[$section])) { $ini[$section] = array_merge($ini[$section], $keys); } else { $ini[$section] = $keys; } } } } $this->setConfig($ini, SPRequest::task('get')); $this->parseXml(); $this->validateData($cacheId); Sobi::Trigger('After', ucfirst(__FUNCTION__), array(&$this->_xml)); }
/** * @param array $head * @return bool */ public function addHead($head) { if (strlen(SPRequest::cmd('format')) && SPRequest::cmd('format') != 'html') { return true; } /** @var JDocument $document */ $document = JFactory::getDocument(); $c = 0; if (count($head)) { $document->addCustomTag("\n\t<!-- SobiPro Head Tags Output -->\n"); $document->addCustomTag("\n\t<script type=\"text/javascript\">/*\n<![CDATA[*/ \n\tvar SobiProUrl = '" . Sobi::FixPath(self::Url(array('task' => '%task%'), true, false, true)) . "'; \n\tvar SobiProSection = " . (Sobi::Section() ? Sobi::Section() : 0) . "; \n\tvar SPLiveSite = '" . Sobi::Cfg('live_site') . "'; \n/*]]>*/\n</script>\n"); if (defined('SOBI_ADM_PATH')) { $document->addCustomTag("\n\t<script type=\"text/javascript\">/* <![CDATA[ */ \n\tvar SobiProAdmUrl = '" . Sobi::FixPath(Sobi::Cfg('live_site') . SOBI_ADM_FOLDER . '/' . self::Url(array('task' => '%task%'), true, false)) . "'; \n/* ]]> */</script>\n"); } foreach ($head as $type => $code) { switch ($type) { default: if (count($code)) { foreach ($code as $html) { ++$c; $document->addCustomTag($html); } } break; case 'robots': case 'author': $document->setMetaData($type, implode(', ', $code)); // $document->setHeadData( array( $type => implode( ', ', $code ) ) ); break; case 'keywords': $metaKeys = trim(implode(', ', $code)); if (Sobi::Cfg('meta.keys_append', true)) { $metaKeys .= Sobi::Cfg('string.meta_keys_separator', ',') . $document->getMetaData('keywords'); } $metaKeys = explode(Sobi::Cfg('string.meta_keys_separator', ','), $metaKeys); if (count($metaKeys)) { $metaKeys = array_unique($metaKeys); foreach ($metaKeys as $i => $p) { if (strlen(trim($p))) { $metaKeys[$i] = trim($p); } else { unset($metaKeys[$i]); } } $metaKeys = implode(', ', $metaKeys); } else { $metaKeys = null; } $document->setMetadata('keywords', $metaKeys); break; case 'description': $metaDesc = implode(Sobi::Cfg('string.meta_desc_separator', ' '), $code); if (strlen($metaDesc)) { if (Sobi::Cfg('meta.desc_append', true)) { $metaDesc .= $this->getMetaDescription($document); } $metaDesc = explode(' ', $metaDesc); if (count($metaDesc)) { foreach ($metaDesc as $i => $p) { if (strlen(trim($p))) { $metaDesc[$i] = trim($p); } else { unset($metaDesc[$i]); } } $metaDesc = implode(' ', $metaDesc); } else { $metaDesc = null; } $document->setDescription($metaDesc); } break; } } $jsUrl = Sobi::FixPath(self::Url(array('task' => 'txt.js', 'format' => 'json'), true, false, false)); $document->addCustomTag("\n\t<script type=\"text/javascript\" src=\"" . str_replace('&', '&', $jsUrl) . "\"></script>\n"); $c++; $document->addCustomTag("\n\t<!-- SobiPro ({$c}) Head Tags Output -->\n"); // we would like to set our own canonical please :P // https://groups.google.com/forum/?fromgroups=#!topic/joomla-dev-cms/sF3-JBQspQU if (count($document->_links)) { foreach ($document->_links as $index => $link) { if ($link['relation'] == 'canonical') { unset($document->_links[$index]); } } } } }
/** * @param $dir SPDirectoryIterator * @param $nodes string * @param $current int * @param $count * @param bool $package * @return void */ private function travelTpl($dir, &$nodes, $current, &$count, $package = false) { $ls = Sobi::FixPath(Sobi::Cfg('img_folder_live') . '/tree'); static $root = null; if (!$root) { $root = new SPFile(SOBI_PATH); } $exceptions = array('config.xml', 'config.json'); foreach ($dir as $file) { $task = null; $fileName = $file->getFilename(); if (in_array($fileName, $exceptions)) { continue; } if ($file->isDot()) { continue; } $count++; if ($file->isDir()) { if ($current == 0 || $package) { if (strstr($file->getPathname(), $root->getPathname())) { $filePath = str_replace($root->getPathname() . '/usr/templates/', null, $file->getPathname()); } else { $filePath = 'cms:' . str_replace(SOBI_ROOT . '/', null, $file->getPathname()); } $filePath = str_replace('/', '.', $filePath); $insertTask = Sobi::Url(array('task' => 'template.info', 'template' => $filePath)); $nodes .= "spTpl.add( {$count}, {$current},'{$fileName}','', '', '', '{$ls}/imgfolder.gif', '{$ls}/imgfolder.gif' );\n"; if (!Sobi::Section()) { $count2 = $count * -100; $fileName = Sobi::Txt('TP.INFO'); $nodes .= "spTpl.add( {$count2}, {$count},'{$fileName}','{$insertTask}', '', '', '{$ls}/info.png' );\n"; if (file_exists($file->getPathname() . "/config.xml")) { $fileName = Sobi::Txt('TP.SETTINGS'); $count2--; $insertTask = Sobi::Url(array('task' => 'template.settings', 'template' => $filePath)); $nodes .= "spTpl.add( {$count2}, {$count},'{$fileName}','{$insertTask}', '', '', '{$ls}/settings.png' );\n"; } } } else { $nodes .= "spTpl.add( {$count}, {$current},'{$fileName}','');\n"; } $this->travelTpl(new SPDirectoryIterator($file->getPathname()), $nodes, $count, $count); } else { $ext = SPFs::getExt($fileName); if (in_array($ext, array('htaccess', 'zip')) || $fileName == 'index.html') { continue; } switch (strtolower($ext)) { case 'php': $ico = $ls . '/php.png'; break; case 'xml': $ico = $ls . '/xml.png'; break; case 'xsl': $ico = $ls . '/xsl.png'; break; case 'css': $ico = $ls . '/css.png'; break; case 'jpg': case 'jpeg': case 'png': case 'bmp': case 'gif': $ico = $ls . '/img.png'; $task = 'javascript:void(0);'; break; case 'ini': $ico = $ls . '/ini.png'; break; case 'less': $ico = $ls . '/less.png'; break; case 'js': $ico = $ls . '/js.png'; break; default: $ico = $ls . '/page.gif'; } if (!$task) { if (strstr($file->getPathname(), $root->getPathname())) { $filePath = str_replace($root->getPathname() . '/usr/templates/', null, $file->getPathname()); } else { $filePath = 'cms:' . str_replace(SOBI_ROOT . DS, null, $file->getPathname()); } $filePath = str_replace('/', '.', $filePath); if (Sobi::Section()) { $task = Sobi::Url(array('task' => 'template.edit', 'file' => $filePath, 'sid' => Sobi::Section())); } else { $task = Sobi::Url(array('task' => 'template.edit', 'file' => $filePath)); } } $nodes .= "spTpl.add( {$count}, {$current},'{$fileName}','{$task}', '', '', '{$ico}' );\n"; } } }
protected function parseResponse($response) { if (!strlen($response)) { return 204; } $links = array(); if (strlen($response) && strstr($response, 'SobiPro')) { // we need to limit the "explode" to two pieces only because otherwise // if the separator is used somewhere in the <body> it will be split into more pieces list($header, $response) = explode("\r\n\r\n", $response, 2); $header = explode("\n", $header); $SobiPro = false; foreach ($header as $line) { if (strstr($line, 'SobiPro')) { $line = explode(':', $line); if (trim($line[0]) == 'SobiPro') { $sid = trim($line[1]); if ($sid != Sobi::Section()) { return 412; } else { $SobiPro = true; } } } } if (!$SobiPro) { return 412; } preg_match_all('/href=[\'"]?([^\'" >]+)/', $response, $links, PREG_PATTERN_ORDER); if (isset($links[1]) && $links[1]) { $liveSite = Sobi::Cfg('live_site'); $host = Sobi::Cfg('live_site_root'); $links = array_unique($links[1]); foreach ($links as $index => $link) { $link = trim($link); $http = preg_match('/http[s]?:\\/\\/.*/i', $link); if (!strlen($link)) { unset($links[$index]); } elseif (strstr($link, '#')) { $link = explode('#', $link); if (strlen($link[0])) { $links[$index] = Sobi::FixPath($host . '/' . $link[0]); } else { unset($links[$index]); } } elseif ($http && !strstr($link, $liveSite)) { unset($links[$index]); } elseif (!$http) { $links[$index] = Sobi::FixPath($host . '/' . $link); } } } return $links; } else { return 501; } }
public function remove() { $pid = $this->xGetString('id'); $function = $this->xGetString('uninstall'); if ($function) { $obj = explode(':', $function); $function = $obj[1]; $obj = $obj[0]; return SPFactory::Instance($obj)->{$function}($this->definition); } $permissions = $this->xGetChilds('installLog/permissions/*'); if ($permissions && $permissions instanceof DOMNodeList) { $permsCtrl =& SPFactory::Instance('ctrl.adm.acl'); for ($i = 0; $i < $permissions->length; $i++) { $perm = explode('.', $permissions->item($i)->nodeValue); $permsCtrl->removePermission($perm[0], $perm[1], $perm[2]); } } /** it doesn't make much sense that way - a backup is ok but this action is called uninstall and not revert */ // $mods = $this->xGetChilds( 'installLog/modified/*' ); // if ( $mods && ( $mods instanceof DOMNodeList ) ) { // $this->revert( $mods ); // } $files = $this->xGetChilds('installLog/files/*'); if ($files && $files instanceof DOMNodeList) { for ($i = 0; $i < $files->length; $i++) { $file = $files->item($i)->nodeValue; if (!strstr($file, SOBI_ROOT)) { $file = Sobi::FixPath(SOBI_ROOT . "/{$file}"); } if (SPFs::exists($file)) { SPFs::delete($file); } } } $actions = $this->xGetChilds('installLog/actions/*'); if ($actions && $actions instanceof DOMNodeList) { for ($i = 0; $i < $actions->length; $i++) { try { SPFactory::db()->delete('spdb_plugin_task', array('pid' => $pid, 'onAction' => $actions->item($i)->nodeValue)); } catch (SPException $x) { Sobi::Error('installer', SPLang::e('Cannot remove plugin task "%s". Db query failed. Error: %s', $actions->item($i)->nodeValue, $x->getMessage()), SPC::WARNING, 0); } } if ($this->xGetString('type') == 'payment') { try { SPFactory::db()->delete('spdb_plugin_task', array('pid' => $pid, 'onAction' => 'PaymentMethodView')); } catch (SPException $x) { Sobi::Error('installer', SPLang::e('Cannot remove plugin task "PaymentMethodView". Db query failed. Error: %s', $x->getMessage()), SPC::WARNING, 0); } } } $field = $this->xdef->query("/{$this->type}/fieldType[@typeId]"); if ($field && $field->length) { try { SPFactory::db()->delete('spdb_field_types', array('tid' => $field->item(0)->getAttribute('typeId'))); } catch (SPException $x) { Sobi::Error('installer', SPLang::e('CANNOT_REMOVE_FIELD_DB_ERR', $field->item(0)->getAttribute('typeId'), $x->getMessage()), SPC::WARNING, 0); } } $tables = $this->xGetChilds('installLog/sql/tables/*'); if ($tables && $tables instanceof DOMNodeList) { for ($i = 0; $i < $tables->length; $i++) { try { SPFactory::db()->drop($tables->item($i)->nodeValue); } catch (SPException $x) { Sobi::Error('installer', SPLang::e('CANNOT_DROP_TABLE', $tables->item($i)->nodeValue, $x->getMessage()), SPC::WARNING, 0); } } } $inserts = $this->xGetChilds('installLog/sql/queries/*'); if ($inserts && $inserts instanceof DOMNodeList) { for ($i = 0; $i < $inserts->length; $i++) { $table = $inserts->item($i)->attributes->getNamedItem('table')->nodeValue; $where = array(); $cols = $inserts->item($i)->childNodes; if ($cols->length) { for ($j = 0; $j < $cols->length; $j++) { $where[$cols->item($j)->nodeName] = $cols->item($j)->nodeValue; } } try { SPFactory::db()->delete($table, $where, 1); } catch (SPException $x) { Sobi::Error('installer', SPLang::e('CANNOT_DELETE_DB_ENTRIES', $table, $x->getMessage()), SPC::WARNING, 0); } } } $type = strlen($this->xGetString('type')) ? $this->xGetString('type') : ($this->xGetString('fieldType') ? 'field' : null); switch ($type) { default: case 'SobiProApp': case 'plugin': $t = Sobi::Txt('EX.PLUGIN_TYPE'); break; case 'field': $t = Sobi::Txt('EX.FIELD_TYPE'); break; case 'payment': $t = Sobi::Txt('EX.PAYMENT_METHOD_TYPE'); break; case 'language': $t = Sobi::Txt('EX.LANGUAGE_TYPE'); break; case 'module': $t = Sobi::Txt('EX.MODULE_TYPE'); break; } try { SPFactory::db()->delete('spdb_plugins', array('pid' => $pid, 'type' => $type), 1); } catch (SPException $x) { Sobi::Error('installer', SPLang::e('CANNOT_DELETE_PLUGIN_DB_ERR', $pid, $x->getMessage()), SPC::ERROR, 0); } try { SPFactory::db()->delete('spdb_plugin_section', array('pid' => $pid)); } catch (SPException $x) { Sobi::Error('installer', SPLang::e('CANNOT_DELETE_PLUGIN_SECTION_DB_ERR', $pid, $x->getMessage()), SPC::WARNING, 0); } SPFs::delete($this->xmlFile); return ucfirst(Sobi::Txt('EX.EXTENSION_HAS_BEEN_REMOVED', array('type' => $t, 'name' => $this->xGetString('name')))); }
private function _cssFiles() { if (Sobi::Cfg('cache.include_css_files', false) && !defined('SOBIPRO_ADM')) { if (count($this->_cache['css'])) { /* * create the right checksum */ $check = array('section' => Sobi::Section()); foreach ($this->_cache['css'] as $file) { if (file_exists($file)) { $check[$file] = filemtime($file); } } $check = md5(serialize($check)); if (!SPFs::exists(SOBI_PATH . "/var/css/{$check}.css")) { $cssContent = "\n/* Created at: " . date(SPFactory::config()->key('date.log_format', 'D M j G:i:s T Y')) . " */\n"; foreach ($this->_cache['css'] as $file) { $fName = str_replace(Sobi::FixPath(SOBI_ROOT), null, $file); $cssContent .= "\n/** \n========\nFile: {$fName}\n========\n*/\n"; $fc = SPFs::read($file); preg_match_all('/[^\\(]*url\\(([^\\)]*)/', $fc, $matches); // we have to replace url relative path $fPath = str_replace(Sobi::FixPath(SOBI_ROOT . '/'), SPFactory::config()->get('live_site'), $file); $fPath = str_replace('\\', '/', $fPath); $fPath = explode('/', $fPath); if (count($matches[1])) { foreach ($matches[1] as $url) { // if it is already absolute - skip or from root if (preg_match('|http(s)?://|', $url) || preg_match('|url\\(["\\s]*/|', $url)) { continue; } elseif (strpos($url, '/') === 0) { continue; } $c = preg_match_all('|\\.\\./|', $url, $c) + 1; $tempFile = array_reverse($fPath); for ($i = 0; $i < $c; $i++) { unset($tempFile[$i]); } $rPath = Sobi::FixPath(implode('/', array_reverse($tempFile))); if ($c > 1) { //WHY?!! //$realUrl = Sobi::FixPath( str_replace( '..', $rPath, $url ) ); $realUrl = Sobi::FixPath($rPath . '/' . str_replace('../', null, $url)); } else { $realUrl = Sobi::FixPath($rPath . '/' . $url); } $realUrl = str_replace(array('"', "'", ' '), null, $realUrl); $fc = str_replace($url, $realUrl, $fc); } } // and add to content $cssContent .= $fc; } SPFs::write(SOBI_PATH . "/var/css/{$check}.css", $cssContent); } $cfile = SPLoader::CssFile('front.var.css.' . $check, false, true, true); $this->cssFiles[++$this->count] = "<link rel=\"stylesheet\" href=\"{$cfile}\" type=\"text/css\" />"; } } return $this->cssFiles; }
protected function cleanDir($dir, $ext, $force = false) { if ($dir) { $js = scandir($dir); if (count($js)) { foreach ($js as $file) { if ($file != '.' && $file != '..' && is_file(Sobi::FixPath("{$dir}/{$file}")) && (SPFs::getExt($file) == $ext || $ext == -1) && ($force || time() - filemtime(Sobi::FixPath("{$dir}/{$file}")) > 60 * 60 * 24 * 7)) { SPFs::delete(Sobi::FixPath("{$dir}/{$file}")); } } } } }
/** * @param string $path * @param int $mode * @throws SPException * @return bool */ public static function mkdir($path, $mode = 0755) { $path = Sobi::FixPath($path); if (!JFolder::create($path, $mode)) { throw new SPException(SPLang::e('CANNOT_CREATE_DIR', str_replace(SOBI_ROOT, null, $path))); } else { return true; } }
/** */ private function createScript($lastNode, $childs, $matrix, $head) { $params = array(); $params['ID'] = $this->_id; $params['LAST_NODE'] = (string) $lastNode; $params['IMAGES_ARR'] = null; $params['IMAGES_MATRIX'] = $matrix; foreach ($this->_images as $img => $loc) { $params['IMAGES_ARR'] .= "\n{$this->_id}_stmImgs[ '{$img}' ] = '{$loc}';"; } $params['URL'] = Sobi::Url(array('task' => $this->_task, 'sid' => $this->_sid, 'out' => 'xml', 'expand' => '__JS__', 'pid' => '__JS2__'), true, false); $params['URL'] = str_replace('__JS__', '" + ' . $this->_id . '_stmcid + "', $params['URL']); $params['URL'] = str_replace('__JS2__', '" + ' . $this->_id . '_stmPid + "', $params['URL']); $params['FAIL_MSG'] = Sobi::Txt('AJAX_FAIL'); $params['TAG'] = $this->_tag; $params['SPINNER'] = Sobi::FixPath(Sobi::Cfg('img_folder_live') . '/adm/spinner.gif'); Sobi::Trigger('SigsiuTree', ucfirst(__FUNCTION__), array(&$params)); $head->addJsVarFile('tree', md5(count($childs, COUNT_RECURSIVE) . $this->_id . $this->_sid . $this->_task . serialize($params)), $params); }
private function delImgs() { $files = SPConfig::unserialize($this->getRaw()); if (is_array($files) && count($files)) { SPLoader::loadClass('cms.base.fs'); foreach ($files as $file) { if (!strlen($file)) { continue; } $file = Sobi::FixPath(SOBI_ROOT . "/{$file}"); // should never happen but who knows .... if ($file == SOBI_ROOT) { continue; } if (SPFs::exists($file)) { SPFs::delete($file); } } } }
/** * */ public function display() { $tpl = SPLoader::path($this->_template . '_override', 'adm.template'); if (!$tpl) { if (strstr($this->_template, 'absolute://')) { $tpl = Sobi::FixPath(str_replace('absolute://', null, $this->_template)); } else { $tpl = SPLoader::path($this->_template, 'adm.template'); } } if (!$tpl) { $tpl = SPLoader::translatePath($this->_template, 'adm.template', false); Sobi::Error($this->name(), SPLang::e('TEMPLATE_DOES_NOT_EXISTS', $tpl), SPC::ERROR, 500, __LINE__, __FILE__); exit; } Sobi::Trigger('Display', $this->name(), array(&$this)); $action = $this->key('action'); echo "\n<!-- SobiPro output -->\n"; echo '<div class="SobiPro" id="SobiPro">' . "\n"; if ($this->_legacy) { echo SPFactory::AdmToolbar()->render(); echo $this->legacyMessages(); echo '<div class="row-fluid">' . "\n"; } echo $action ? "\n<form action=\"{$action}\" method=\"post\" name=\"adminForm\" id=\"SPAdminForm\" enctype=\"multipart/form-data\" accept-charset=\"utf-8\" >\n" : null; $prefix = null; if (!$this->_legacy) { $prefix = 'SP_'; } include $tpl; if (count($this->_hidden)) { $this->_hidden[SPFactory::mainframe()->token()] = 1; $this->_hidden['spsid'] = microtime(true) + Sobi::My('id') * mt_rand(5, 15) / mt_rand(5, 15); foreach ($this->_hidden as $name => $value) { echo "\n<input type=\"hidden\" name=\"{$name}\" id=\"{$prefix}{$name}\" value=\"{$value}\"/>"; } } echo $action ? "\n</form>\n" : null; if ($this->_legacy) { echo '</div>' . "\n"; } echo '</div>' . "\n"; echo "\n<!-- SobiPro output end -->\n"; Sobi::Trigger('AfterDisplay', $this->name()); }
/** * Get file from the request and upload to the given path * @param string $name - file name from the request * @param string $destination - destination path * @throws SPException * @return bool */ public function upload($name, $destination) { $destination = Sobi::FixPath($destination); if (SPFs::upload($name, $destination)) { $this->_filename = $destination; return $this->_filename; } else { // Sun, Jan 18, 2015 20:41:09 // stupid windows exception. I am not going to waste my time trying to find why the hell it doesn't work as it should if (SPFs::upload(Sobi::FixPath($name), $destination)) { $this->_filename = $destination; return $this->_filename; } else { throw new SPException(SPLang::e('CANNOT_UPLOAD_FILE_TO', str_replace(SOBI_ROOT, null, $destination))); } } }
/** * @param $dir * @param $view * @param $templateName * @return mixed */ protected function getTemplateData($dir, $view, $templateName) { $info = new DOMDocument(); $info->load($dir . '/template.xml'); $xinfo = new DOMXPath($info); $template = array(); $template['name'] = $xinfo->query('/template/name')->item(0)->nodeValue; $view->assign($template['name'], 'template_name'); $template['author'] = array('name' => $xinfo->query('/template/authorName')->item(0)->nodeValue, 'email' => $xinfo->query('/template/authorEmail')->item(0)->nodeValue, 'url' => $xinfo->query('/template/authorUrl')->item(0)->nodeValue ? $xinfo->query('/template/authorUrl')->item(0)->nodeValue : null); $template['copyright'] = $xinfo->query('/template/copyright')->item(0)->nodeValue; $template['license'] = $xinfo->query('/template/license')->item(0)->nodeValue; $template['date'] = $xinfo->query('/template/creationDate')->item(0)->nodeValue; $template['version'] = $xinfo->query('/template/version')->item(0)->nodeValue; $template['description'] = $xinfo->query('/template/description')->item(0)->nodeValue; $template['id'] = $xinfo->query('/template/id')->item(0)->nodeValue; if ($xinfo->query('/template/previewImage')->length && $xinfo->query('/template/previewImage')->item(0)->nodeValue) { $template['preview'] = Sobi::FixPath(Sobi::Cfg('live_site') . str_replace('\\', '/', str_replace(SOBI_ROOT . DS, null, $dir)) . '/' . $xinfo->query('/template/previewImage')->item(0)->nodeValue); } if ($xinfo->query('/template/files/file')->length) { $files = array(); foreach ($xinfo->query('/template/files/file') as $file) { $filePath = $dir . '/' . $file->attributes->getNamedItem('path')->nodeValue; if ($filePath && is_file($filePath)) { $filePath = $templateName . '.' . str_replace('/', '.', $file->attributes->getNamedItem('path')->nodeValue); } else { $filePath = null; } $files[] = array('file' => $file->attributes->getNamedItem('path')->nodeValue, 'description' => $file->nodeValue, 'filepath' => $filePath); } $template['files'] = $files; $view->assign($files, 'files'); } $view->assign($template, 'template'); return $file; }
private function file($file, $exits = true) { $ext = SPFs::getExt($file); $file = explode('.', $file); unset($file[count($file) - 1]); if (strstr($file[0], 'cms:')) { $file[0] = str_replace('cms:', null, $file[0]); $file = SPFactory::mainframe()->path(implode('.', $file)); $file = Sobi::FixPath(SPLoader::path($file, 'root', $exits, $ext)); } else { $file = Sobi::FixPath(SPLoader::path('usr.templates.' . implode('.', $file), 'front', $exits, $ext)); } if (!$file) { $file = SPLoader::path('usr.templates.' . implode('.', $file), 'front', false, $ext); Sobi::Error($this->name(), SPLang::e('FILE_NOT_FOUND', $file), SPC::WARNING, 404, __LINE__, __FILE__); } return $file; }
/** * @return array */ public function struct() { $files = $this->getRaw(); if (is_string($files)) { try { $files = SPConfig::unserialize($files); } catch (SPException $x) { $files = null; } } $exifToPass = array(); if (isset($files['original'])) { $files['orginal'] = $files['original']; } if (isset($files['data']['exif']) && Sobi::Cfg('image_field.pass_exif', true)) { $exif = json_encode($files['data']['exif']); $exif = str_replace('UndefinedTag:', null, $exif); $exif = preg_replace('/\\p{Cc}+/u', null, $exif); $exif = json_decode(preg_replace('/[^a-zA-Z0-9\\{\\}\\:\\.\\,\\(\\)\\"\'\\/\\\\!\\?\\[\\]\\@\\#\\$\\%\\^\\&\\*\\+\\-\\_]/', '', $exif), true); if (isset($exif['EXIF'])) { $tags = Sobi::Cfg('image_field.exif_data', array()); if (count($tags)) { foreach ($tags as $tag) { $exifToPass['BASE'][$tag] = isset($exif['EXIF'][$tag]) ? $exif['EXIF'][$tag] : 'unknown'; } } } if (isset($exif['FILE'])) { $exifToPass['FILE'] = $exif['FILE']; } if (isset($exif['FILE'])) { $exifToPass['FILE'] = $exif['FILE']; } if (isset($exif['IFD0'])) { $tags = Sobi::Cfg('image_field.exif_id_data', array()); if (count($tags)) { foreach ($tags as $tag) { $exifToPass['IFD0'][$tag] = isset($exif['IFD0'][$tag]) ? $exif['IFD0'][$tag] : 'unknown'; } } } if (isset($files['data']['exif']['GPS'])) { $exifToPass['GPS']['coordinates']['latitude'] = $this->convertGPS($files['data']['exif']['GPS']['GPSLatitude'][0], $files['data']['exif']['GPS']['GPSLatitude'][1], $files['data']['exif']['GPS']['GPSLatitude'][2], $files['data']['exif']['GPS']['GPSLatitudeRef']); $exifToPass['GPS']['coordinates']['longitude'] = $this->convertGPS($files['data']['exif']['GPS']['GPSLongitude'][0], $files['data']['exif']['GPS']['GPSLongitude'][1], $files['data']['exif']['GPS']['GPSLongitude'][2], $files['data']['exif']['GPS']['GPSLongitudeRef']); $exifToPass['GPS']['coordinates']['latitude-ref'] = isset($files['data']['exif']['GPS']['GPSLatitudeRef']) ? $files['data']['exif']['GPS']['GPSLatitudeRef'] : 'unknown'; $exifToPass['GPS']['coordinates']['longitude-ref'] = isset($files['data']['exif']['GPS']['GPSLongitudeRef']) ? $files['data']['exif']['GPS']['GPSLongitudeRef'] : 'unknown'; $tags = Sobi::Cfg('image_field.exif_gps_data', array()); if (count($tags)) { foreach ($tags as $tag) { $exifToPass['GPS'][$tag] = isset($files['data']['exif']['GPS']['GPS' . $tag]) ? $files['data']['exif']['GPS']['GPS' . $tag] : 'unknown'; } } } } $float = null; if (is_array($files) && count($files)) { $this->cssClass = strlen($this->cssClass) ? $this->cssClass : 'spFieldsData'; $this->cssClass = $this->cssClass . ' ' . $this->nid; $this->cleanCss(); switch ($this->currentView) { default: case 'vcard': $img = $this->inVcard; break; case 'details': $img = $this->inDetails; break; } if (isset($files[$img])) { $show = $files[$img]; } elseif (isset($files['thumb'])) { $show = $files['thumb']; } elseif (isset($files['ico'])) { $show = $files['ico']; } if (isset($show)) { switch ($img) { case 'thumb': $float = $this->thumbFloat; break; case 'image': $float = $this->imageFloat; break; } $data = array('_complex' => 1, '_data' => null, '_attributes' => array('class' => $this->cssClass, 'src' => Sobi::FixPath(Sobi::Cfg('live_site') . $show), 'alt' => '')); if ($float) { $data['_attributes']['style'] = "float:{$float};"; } return array('_complex' => 1, '_data' => array('img' => $data), '_attributes' => array('icon' => isset($files['ico']) ? Sobi::FixPath($files['ico']) : null, 'image' => isset($files['image']) ? Sobi::FixPath($files['image']) : null, 'thumbnail' => isset($files['thumb']) ? Sobi::FixPath($files['thumb']) : null, 'original' => isset($files['original']) ? Sobi::FixPath($files['original']) : null, 'class' => $this->cssClass), '_options' => array('exif' => $exifToPass)); } } }
private function registerFunctions() { $functions = array(); $package = Sobi::Reg('current_template'); if (SPFs::exists(Sobi::FixPath($package . '/' . $this->key('functions')))) { $path = Sobi::FixPath($package . '/' . $this->key('functions')); ob_start(); $content = file_get_contents($path); $class = array(); preg_match('/\\s*(class)\\s+(\\w+)/', $content, $class); if (isset($class[2])) { $className = $class[2]; } else { Sobi::Error($this->name(), SPLang::e('Cannot determine class name in file %s.', str_replace(SOBI_ROOT . DS, null, $path)), SPC::WARNING, 0); return false; } require_once $path; $methods = get_class_methods($className); if (count($methods)) { foreach ($methods as $method) { $functions[] = $className . '::' . $method; } } } else { Sobi::Error($this->name(), SPLang::e('FUNCFILE_DEFINED_BUT_FILE_DOES_NOT_EXISTS', $this->_template . DS . $this->key('functions')), SPC::WARNING, 0); } return $functions; }
protected function listTemplates(&$arr, $path, $type) { $stdTemplates = array('view.xsl', 'details.xsl', 'edit.xsl'); switch ($type) { case 'entry': case 'entry.add': case 'section': case 'category': case 'search': $path = Sobi::FixPath($path . '/' . $type); break; case 'list.user': case 'list.date': $path = Sobi::FixPath($path . '/listing'); break; default: if (strstr($type, 'list')) { $path = Sobi::FixPath($path . '/listing'); } break; } if (file_exists($path)) { $files = scandir($path); if (count($files)) { foreach ($files as $file) { if (in_array($file, $stdTemplates)) { continue; } $stack = explode('.', $file); if (array_pop($stack) == 'xsl') { $arr[$stack[0]] = $file; } } } } }
/** * Creating URL from a array for the current CMS * @param array $var * @param bool $js * @param bool $sef * @param bool $live * @param bool $forceItemId * @return string */ public static function url($var = null, $js = false, $sef = true, $live = false, $forceItemId = false) { $url = self::baseUrl; if ($var == 'current') { return SPRequest::raw('REQUEST_URI', self::baseUrl, 'SERVER'); } // don't remember why :( // Nevertheless it is generating & in URL fro ImEx // $sef = Sobi::Cfg( 'disable_sef_globally', false ) ? false : ( defined( 'SOBIPRO_ADM' ) && !( $forceItemId ) ? false : $sef ); $sef = Sobi::Cfg('disable_sef_globally', false) ? false : $sef; Sobi::Trigger('Create', 'Url', array(&$var, $js)); if (is_array($var) && !empty($var)) { if (isset($var['option'])) { $url = str_replace('com_sobipro', $var['option'], $url); unset($var['option']); } if (isset($var['sid']) && (!defined('SOBIPRO_ADM') || $forceItemId) || defined('SOBIPRO_ADM') && $sef && $live) { if (!isset($var['Itemid']) || !$var['Itemid']) { SPFactory::mainframe()->getItemid($var); } } if (isset($var['title'])) { if (Sobi::Cfg('url.title', true)) { $var['title'] = trim(SPLang::urlSafe($var['title'])); $var['sid'] = $var['sid'] . ':' . $var['title']; } unset($var['title']); } if (isset($var['format']) && $var['format'] == 'raw' && $sef) { unset($var['format']); } foreach ($var as $k => $v) { if ($k == 'out') { switch ($v) { case 'html': $var['tmpl'] = 'component'; unset($var['out']); break; case 'xml': $var['tmpl'] = 'component'; $var['format'] = 'raw'; case 'raw': $var['tmpl'] = 'component'; $var['format'] = 'raw'; break; case 'json': $var['out'] = 'json'; $var['format'] = 'raw'; $var['tmpl'] = 'component'; break; } } } foreach ($var as $k => $v) { $url .= "&{$k}={$v}"; } } elseif (is_string($var)) { if (strstr($var, 'index.php?')) { $url = null; } else { $url .= '&'; } if (strstr($var, '=')) { $var = str_replace('&', '&', $var); $var = str_replace('&', '&', $var); $url .= $var; } else { $url .= SOBI_TASK . '='; $url .= $var; } } elseif (is_array($var)) { } if ($sef && !$live) { $url = JRoute::_($url, false); } else { $url = preg_replace('/&(?![#]?[a-z0-9]+;)/i', '&', $url); } if ($live) { /* * SubDir Issues: * when using SEF Joomla! router returns also the subdir * and JURI::base returns the subdir too * So if the URL should be SEF we have to remove the subdirectory once * Otherwise it doesn't pass the JRoute::_ method so there is no subdir included * */ if ($sef) { $base = JURI::base(true); $root = str_replace($base, null, Sobi::Cfg('live_site')); $url = explode('/', $url); $url = $url[count($url) - 1]; // if ( defined( 'SOBIPRO_ADM' ) ) { // $router = JApplication::getInstance( 'site' )->getRouter(); // $a = $router->build( $url ); // $url = $router->build( $url )->toString(); // } if (!defined('SOBIPRO_ADM')) { $url = JRoute::_($url, false); } $url = Sobi::FixPath("{$root}{$url}"); } else { $adm = defined('SOBIPRO_ADM') ? SOBI_ADM_FOLDER : null; $url = Sobi::FixPath(Sobi::Cfg('live_site') . $adm . '/' . $url); } } $url = str_replace('%3A', ':', $url); // all urls in front are passed to the XML/XSL template are going to be encoded anyway $o = SPRequest::cmd('format', SPRequest::cmd('out')); if (!in_array($o, array('raw', 'xml')) && !defined('SOBI_ADM_PATH')) { $url = html_entity_decode($url); } $url = str_replace(' ', '%20', urldecode($url)); return $js ? str_replace('amp;', null, $url) : $url; }
/** * Returns Joomla! depend additional path with alternative templates loaction * @return array */ public function templatesPath() { SPLoader::loadClass('base.fs.directory_iterator'); $jTemplates = new SPDirectoryIterator(SPLoader::dirPath('templates', 'root', true)); $tr = array(); foreach ($jTemplates as $template) { if ($template->isDot()) { continue; } if ($template->isDir()) { if (file_exists(implode('/', array($template->getPathname(), 'html', 'com_sobipro'))) && file_exists(implode('/', array($template->getPathname(), 'templateDetails.xml')))) { $data = new DOMDocument('1.0', 'utf-8'); $data->load(Sobi::FixPath($template->getPathname() . '/templateDetails.xml')); $name = $data->getElementsByTagName('name')->item(0)->nodeValue; $tr[$name] = Sobi::FixPath(implode(DS, array($template->getPathname(), 'html', 'com_sobipro'))); } } } return array('name' => Sobi::Txt('TP.TEMPLATES_OVERRIDE'), 'icon' => Sobi::Cfg('live_site') . 'media/sobipro/tree/joomla.gif', 'data' => $tr); }
/** * @author Radek Suski * @version 1.0 * @param string $path * @param bool $adm * @param bool $checkExist * @param bool $toLive * @param string $ext * @param bool $count * @internal param string $root * @internal param bool $existCheck * @return string */ public static function CssFile($path, $adm = false, $checkExist = true, $toLive = true, $ext = 'css', $count = false) { if (strstr($path, 'root.')) { $file = self::translatePath(str_replace('root.', null, $path), 'root', $checkExist, $ext, $count); } elseif (strstr($path, 'front.')) { $file = self::translatePath(str_replace('front.', null, $path), 'front', $checkExist, $ext, $count); } elseif (strstr($path, 'absolute.')) { $file = self::translatePath(str_replace('absolute.', null, $path), 'absolute', $checkExist, $ext, $count); } else { $root = $adm ? 'adm.' : null; $file = self::translatePath($root . $path, 'css', $checkExist, $ext, $count); } if ($toLive) { $file = str_replace(SOBI_ROOT, SPFactory::config()->get('live_site'), $file); $file = str_replace('\\', '/', $file); } return Sobi::FixPath($file); }
private function view() { $type = $this->key('template_type', 'xslt'); if ($type != 'php' && Sobi::Cfg('global.disable_xslt', false)) { $type = 'php'; } if ($type == 'xslt') { $visitor = $this->get('visitor'); $current = $this->get($this->_type); $orderings = $this->get('orderings'); $categories = $this->get('categories'); $entries = $this->get('entries'); $cUrl = array('title' => Sobi::Cfg('sef.alias', true) ? $current->get('nid') : $current->get('name'), 'sid' => $current->get('id')); if (SPRequest::int('site', 0)) { $cUrl['site'] = SPRequest::int('site', 0); } SPFactory::header()->addCanonical(Sobi::Url($cUrl, true, true, true)); $data = array(); $data['id'] = $current->get('id'); $data['counter'] = $current->get('counter'); $data['section'] = array('_complex' => 1, '_data' => Sobi::Section(true), '_attributes' => array('id' => Sobi::Section(), 'lang' => Sobi::Lang(false))); $data['name'] = array('_complex' => 1, '_data' => $current->get('name'), '_attributes' => array('lang' => Sobi::Lang(false))); if (Sobi::Cfg('category.show_desc') || $current->get('oType') == 'section') { $desc = $current->get('description'); if (Sobi::Cfg('category.parse_desc')) { Sobi::Trigger('prepare', 'Content', array(&$desc, $current)); } $data['description'] = array('_complex' => 1, '_cdata' => 1, '_data' => $desc, '_attributes' => array('lang' => Sobi::Lang(false))); } $showIcon = $current->get('showIcon'); if ($showIcon == SPC::GLOBAL_SETTING) { $showIcon = Sobi::Cfg('category.show_icon', true); } if ($showIcon && $current->get('icon')) { if (SPFs::exists(Sobi::Cfg('images.category_icons') . '/' . $current->get('icon'))) { $data['icon'] = Sobi::FixPath(Sobi::Cfg('images.category_icons_live') . $current->get('icon')); } } $data['meta'] = array('description' => $current->get('metaDesc'), 'keys' => $this->metaKeys($current), 'author' => $current->get('metaAuthor'), 'robots' => $current->get('metaRobots')); $data['entries_in_line'] = $this->get('$eInLine'); $data['categories_in_line'] = $this->get('$cInLine'); $data['number_of_subcats'] = Sobi::Cfg('list.num_subcats'); $this->menu($data); $this->alphaMenu($data); $data['visitor'] = $this->visitorArray($visitor); if (count($categories)) { $this->loadNonStaticData($categories); foreach ($categories as $category) { $cat = $this->category($category); $data['categories'][] = array('_complex' => 1, '_attributes' => array('id' => $cat['id'], 'nid' => $cat['nid']), '_data' => $cat); } if (strstr($orderings['categories'], 'name') && Sobi::Cfg('lang.multimode', false)) { usort($data['categories'], 'self::orderByName'); if ($orderings['categories'] == 'name.desc') { $data['categories'] = array_reverse($data['categories']); } } } if (count($entries)) { $this->loadNonStaticData($entries); $manager = Sobi::Can('entry', 'edit', '*', Sobi::Section()) ? true : false; foreach ($entries as $eid) { $en = $this->entry($eid, $manager); $data['entries'][] = array('_complex' => 1, '_attributes' => array('id' => $en['id'], 'nid' => $en['nid']), '_data' => $en); } if (strstr($orderings['entries'], 'name') && Sobi::Cfg('lang.multimode', false)) { usort($data['entries'], 'self::orderByName'); if ($orderings['entries'] == 'name.desc') { $data['entries'] = array_reverse($data['entries']); } } $this->navigation($data); } $this->fixTimes($data); $this->_attr = $data; } Sobi::Trigger($this->_type, ucfirst(__FUNCTION__), array(&$this->_attr)); }