Ejemplo n.º 1
0
 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);
         }
     }
 }
Ejemplo n.º 2
0
 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));
 }
Ejemplo n.º 3
0
 /**
  */
 public function execute()
 {
     SPFactory::mainframe()->cleanBuffer()->customHeader();
     if (SPFs::exists($this->file)) {
         echo SPFs::read($this->file);
     } else {
         echo json_encode(array('progress' => 0, 'message' => '', 'interval' => 100, 'type' => ''));
     }
     exit;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
 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);
     }
     $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);
         }
     }
     $exec = $this->xGetString('exec');
     if ($exec && SPFs::exists($this->root . DS . $exec)) {
         include_once "{$this->root}/{$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));
 }
Ejemplo n.º 6
0
 /**
  */
 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');
 }
Ejemplo n.º 7
0
 public function validate()
 {
     $type = $this->type == 'SobiProApp' ? 'application' : $this->type;
     $schemaDef = SPLoader::path('lib.services.installers.schemas.' . $type, 'front', false, 'xsd');
     if (!SPFs::exists($schemaDef) || time() - filemtime($schemaDef) > 60 * 60 * 24 * 7) {
         $connection = SPFactory::Instance('services.remote');
         $def = "https://xml.sigsiu.net/SobiPro/{$type}.xsd";
         $connection->setOptions(array('url' => $def, 'connecttimeout' => 10, 'header' => false, 'returntransfer' => true, 'ssl_verifypeer' => false, 'ssl_verifyhost' => 2));
         $schema =& SPFactory::Instance('base.fs.file', SPLoader::path('lib.services.installers.schemas.' . $type, 'front', false, 'xsd'));
         $file = $connection->exec();
         if (!strlen($file)) {
             throw new SPException(SPLang::e('CANNOT_ACCESS_SCHEMA_DEF', $def));
         }
         $schema->content($file);
         $schema->save();
         $schemaDef = $schema->filename();
     }
     if (!$this->definition->schemaValidate($schemaDef)) {
         throw new SPException(SPLang::e('CANNOT_VALIDATE_SCHEMA_DEF_AT', str_replace(SOBI_ROOT . DS, null, $this->xmlFile), $def));
     }
 }
Ejemplo n.º 8
0
 private function purge()
 {
     try {
         SPFactory::db()->truncate('spdb_errors');
     } catch (SPException $x) {
         $this->response(Sobi::Url('error'), Sobi::Txt('ERR.ERROR_LOG_NOT_DELETED', array('error' => $x->getMessage())), false, SPC::ERROR_MSG);
     }
     if (SPFs::exists(SOBI_PATH . '/var/log/error.log')) {
         SPFs::delete(SOBI_PATH . '/var/log/error.log');
     }
     $this->response(Sobi::Url('error'), Sobi::Txt('ERR.ERROR_LOG_DELETED'), false, SPC::SUCCESS_MSG);
 }
Ejemplo n.º 9
0
 protected function cleanTemp($force = false)
 {
     $this->cleanJCache();
     $this->cleanDir(SPLoader::dirPath('var.js'), 'js', $force);
     $this->cleanDir(SPLoader::dirPath('var.css'), 'css', $force);
     $this->cleanDir(SPLoader::dirPath('tmp.edit'), -1, $force);
     $this->cleanDir(SPLoader::dirPath('tmp.img'), -1, $force);
     $this->cleanDir(SPLoader::dirPath('tmp'), -1, $force);
     try {
         SPFactory::db()->delete('spdb_search', array('lastActive<' => 'FUNCTION:DATE_SUB( CURDATE() , INTERVAL 7 DAY )'));
     } catch (SPException $x) {
         Sobi::Error('cache', SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     $updatesDef = SPLoader::path('etc.updates', 'front', false, 'xml');
     if (SPFs::exists($updatesDef)) {
         SPFs::delete($updatesDef);
     }
 }
Ejemplo n.º 10
0
 private function getNews()
 {
     $out = array();
     $path = SPLoader::path('etc.news', 'front', false, 'xml');
     if (SPFs::exists($path) && time() - filemtime($path) < 60 * 60 * 12) {
         $content = SPFs::read(SPLoader::path('etc.news', 'front', false, 'xml'));
     } else {
         try {
             $connection = SPFactory::Instance('services.remote');
             $news = 'http://rss.sigsiu.net';
             $connection->setOptions(array('url' => $news, 'connecttimeout' => 10, 'header' => false, 'returntransfer' => true));
             $file = SPFactory::Instance('base.fs.file', $path);
             $content = $connection->exec();
             $cinf = $connection->info();
             if (isset($cinf['http_code']) && $cinf['http_code'] != 200) {
                 return Sobi::Error('about', sprintf('CANNOT_GET_NEWS', $news, $cinf['http_code']), SPC::WARNING, 0, __LINE__, __FILE__);
             }
             $file->content($content);
             $file->save();
         } catch (SPException $x) {
             return Sobi::Error('about', SPLang::e('CANNOT_LOAD_NEWS', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     try {
         if (strlen($content)) {
             $news = new DOMXPath(DOMDocument::loadXML($content));
             $atom = false;
             if ($atom) {
                 //Atom
                 $news->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
                 $out['title'] = $news->query('/atom:feed/atom:title')->item(0)->nodeValue;
                 $items = $news->query('/atom:feed/atom:entry[*]');
                 $c = 5;
                 $open = false;
                 foreach ($items as $item) {
                     $date = $item->getElementsByTagName('updated')->item(0)->nodeValue;
                     if (!$open && time() - strtotime($date) < 60 * 60 * 24) {
                         $open = true;
                     }
                     $feed = array('url' => $item->getElementsByTagName('link')->item(0)->nodeValue, 'title' => $item->getElementsByTagName('title')->item(0)->nodeValue, 'content' => $item->getElementsByTagName('content')->item(0)->nodeValue);
                     if (!$c--) {
                         break;
                     }
                     $out['feeds'][] = $feed;
                 }
             } else {
                 //RSS
                 $out['title'] = $news->query('/rss/channel/title')->item(0)->nodeValue;
                 $items = $news->query('/rss/channel/item[*]');
                 $c = 5;
                 $open = false;
                 foreach ($items as $item) {
                     $date = $item->getElementsByTagName('pubDate')->item(0)->nodeValue;
                     if (!$open && time() - strtotime($date) < 60 * 60 * 24) {
                         $open = true;
                     }
                     $feed = array('url' => $item->getElementsByTagName('link')->item(0)->nodeValue, 'title' => $item->getElementsByTagName('title')->item(0)->nodeValue, 'content' => $item->getElementsByTagName('description')->item(0)->nodeValue, 'image' => $item->getElementsByTagName('enclosure')->item(0)->attributes->getNamedItem('url')->nodeValue);
                     if (!$c--) {
                         break;
                     }
                     $out['feeds'][] = $feed;
                 }
             }
         }
         if ($open) {
             SPFactory::header()->addJsCode('SobiPro.jQuery( document ).ready( function () { SobiPro.jQuery( \'#SobiProNews\' ).trigger(\'click\'); } );');
         }
     } catch (DOMException $x) {
         return Sobi::Error('about', SPLang::e('CANNOT_LOAD_NEWS', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     return $out;
 }
Ejemplo n.º 11
0
 public function save(&$attr)
 {
     static $lang = null;
     static $defLang = null;
     if (!$lang) {
         $lang = Sobi::Lang();
         $defLang = Sobi::DefLang();
     }
     $file = SPRequest::file('spfieldsopts', 'tmp_name');
     if ($file) {
         $data = parse_ini_file($file, true);
     } elseif (is_string($attr['options'])) {
         $data = parse_ini_string($attr['options'], true);
     } else {
         $data = null;
     }
     $options = $this->parseOptsFile($data);
     if (!count($options) && count($attr['options'])) {
         $p = 0;
         $hold = array();
         foreach ($attr['options'] as $o) {
             if (is_numeric($o['id'])) {
                 $o['id'] = $this->nid . '_' . $o['id'];
             }
             if (isset($o['id'])) {
                 $i = 0;
                 $oid = $o['id'];
                 while (isset($hold[$oid])) {
                     $oid = $o['id'] . '_' . ++$i;
                 }
                 $options[] = array('id' => $oid, 'name' => $o['name'], 'parent' => null, 'position' => ++$p);
                 $hold[$oid] = $oid;
             }
         }
     }
     if (count($options)) {
         unset($attr['options']);
         $optionsArr = array();
         $labelsArr = array();
         $optsIds = array();
         $defLabelsArr = array();
         $duplicates = false;
         foreach ($options as $i => $option) {
             /* check for doubles */
             foreach ($options as $pos => $opt) {
                 if ($i == $pos) {
                     continue;
                 }
                 if ($option['id'] == $opt['id']) {
                     $option['id'] = $option['id'] . '_' . substr((string) microtime(), 2, 8) . rand(1, 100);
                     $duplicates = true;
                 }
             }
             $optionsArr[] = array('fid' => $this->id, 'optValue' => $option['id'], 'optPos' => $option['position'], 'optParent' => $option['parent']);
             $defLabelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $defLang, 'oType' => 'field_option', 'fid' => $this->id);
             $labelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $lang, 'oType' => 'field_option', 'fid' => $this->id);
             $optsIds[] = $option['id'];
         }
         if ($duplicates) {
             SPFactory::message()->warning('FIELD_WARN_DUPLICATE_OPT_ID');
         }
         $db = SPFactory::db();
         /* try to delete the existing labels */
         try {
             $db->delete('spdb_field_option', array('fid' => $this->id));
             $db->delete('spdb_language', array('oType' => 'field_option', 'fid' => $this->id, '!sKey' => $optsIds));
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_STORE_FIELD_OPTIONS_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         /* insert new values */
         try {
             $db->insertArray('spdb_field_option', $optionsArr);
             $db->insertArray('spdb_language', $labelsArr, true);
             if ($defLang != $lang) {
                 $db->insertArray('spdb_language', $defLabelsArr, false, true);
             }
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_DELETE_SELECTED_OPTIONS', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     if (!isset($attr['params'])) {
         $attr['params'] = array();
     }
     $myAttr = $this->getAttr();
     $properties = array();
     if (count($myAttr)) {
         foreach ($myAttr as $property) {
             $properties[$property] = isset($attr[$property]) ? $attr[$property] : null;
         }
     }
     $this->sets['field.options'] = SPFactory::Instance('types.array')->toINIString($data);
     /** handle upload of new definition file */
     $XMLFile = SPRequest::file('select-list-dependency', 'tmp_name');
     if ($XMLFile && file_exists($XMLFile)) {
         $XMLFileName = SPRequest::file('select-list-dependency', 'name');
         if (SPFs::getExt($XMLFileName) == 'zip') {
             $arch = SPFactory::Instance('base.fs.archive');
             $name = str_replace('.zip', null, $XMLFileName);
             $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false);
             $c = 0;
             while (SPFs::exists($path)) {
                 $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false);
             }
             $arch->upload($XMLFile, $path . '/' . $XMLFileName);
             $arch->extract($path);
             $files = scandir($path);
             if (count($files)) {
                 foreach ($files as $defFile) {
                     switch (SPFs::getExt($defFile)) {
                         case 'xml':
                             $properties['dependencyDefinition'] = $defFile;
                             SPFs::move($path . '/' . $defFile, SOBI_PATH . '/etc/fields/select-list/' . $defFile);
                             break;
                         case 'ini':
                             $defLang = explode('.', $defFile);
                             $defLang = $defLang[0];
                             if (file_exists(SOBI_ROOT . '/language/' . $defLang)) {
                                 SPFs::move($path . '/' . $defFile, SOBI_ROOT . '/language/' . $defLang . '/' . $defFile);
                             }
                             break;
                     }
                 }
             }
         } elseif (SPFs::getExt($XMLFileName) == 'xml') {
             if (SPFs::upload($XMLFile, SOBI_PATH . '/etc/fields/select-list/' . $XMLFileName)) {
                 $properties['dependencyDefinition'] = $XMLFileName;
             }
         }
     }
     /** if we use it - let's transform the XML file  */
     if ($properties['dependency'] && $properties['dependencyDefinition']) {
         $this->parseDependencyDefinition($properties['dependencyDefinition']);
     }
     $attr['params'] = $properties;
 }
Ejemplo n.º 12
0
 public function templatesList($params = null)
 {
     $cms = SPFactory::CmsHelper()->templatesPath();
     $dir = new SPDirectoryIterator(SPLoader::dirPath('usr.templates'));
     $templates = array();
     foreach ($dir as $file) {
         if ($file->isDir()) {
             if ($file->isDot() || in_array($file->getFilename(), array('common', 'front'))) {
                 continue;
             }
             if (SPFs::exists($file->getPathname() . DS . 'template.xml') && ($tname = $this->templateName($file->getPathname() . DS . 'template.xml'))) {
                 $templates[$file->getFilename()] = $tname;
             } else {
                 $templates[$file->getFilename()] = $file->getFilename();
             }
         }
     }
     if (is_array($cms) && isset($cms['name']) && isset($cms['data']) && is_array($cms['data']) && count($cms['data'])) {
         $templates[$cms['name']] = array();
         foreach ($cms['data'] as $name => $path) {
             $templates[$cms['name']][$name] = array();
             $dir = new SPDirectoryIterator($path);
             foreach ($dir as $file) {
                 if ($file->isDot()) {
                     continue;
                 }
                 $fpath = 'cms:' . str_replace(SOBI_ROOT . DS, null, $file->getPathname());
                 $fpath = str_replace(DS, '.', $fpath);
                 if (SPFs::exists($file->getPathname() . DS . 'template.xml') && ($tname = $this->templateName($file->getPathname() . DS . 'template.xml'))) {
                     $templates[$cms['name']][$name][$fpath] = $tname;
                 } else {
                     $templates[$cms['name']][$name][$fpath] = $file->getFilename();
                 }
             }
         }
     }
     if ($params) {
         $p = array('select', 'spcfg_' . $params[1], $templates, Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE), false, $params[3]);
     } else {
         $p = $templates;
     }
     return $p;
 }
Ejemplo n.º 13
0
 private function _jsFiles()
 {
     if (Sobi::Cfg('cache.include_js_files', false) && !defined('SOBIPRO_ADM')) {
         if (count($this->_cache['js'])) {
             $compression = Sobi::Cfg('cache.compress_js', false);
             $comprLevel = Sobi::Cfg('cache.compress_level', 0);
             $check = array('section' => Sobi::Section(), 'compress_level' => $comprLevel, 'compress_js' => $compression);
             foreach ($this->_cache['js'] as $file) {
                 $check[$file] = filemtime($file);
             }
             $check = md5(serialize($check));
             if (!SPFs::exists(SOBI_PATH . "/var/js/{$check}.js")) {
                 $noCompress = explode(',', Sobi::Cfg('cache.js_compress_exceptions'));
                 $jsContent = "\n/* Created at: " . date(SPFactory::config()->key('date.log_format', 'D M j G:i:s T Y')) . " */\n";
                 foreach ($this->_cache['js'] as $file) {
                     $fName = str_replace(SOBI_ROOT, null, $file);
                     $jsContent .= "\n// ========\n// File: {$fName}\n// ========\n\n";
                     if ($compression && !in_array(basename($file), $noCompress)) {
                         $compressor = SPFactory::Instance('env.jspacker', SPFs::read($file), $comprLevel, false, true);
                         $jsContent .= $compressor->pack();
                     } else {
                         $jsContent .= SPFs::read($file);
                     }
                     $jsContent .= ";\n";
                 }
                 SPFs::write(SOBI_PATH . "/var/js/{$check}.js", $jsContent);
             }
             $cfile = SPLoader::JsFile('front.var.js.' . $check, false, true, true);
             $this->jsFiles[++$this->count] = "\n<script type=\"text/javascript\" src=\"{$cfile}\"></script>";
         }
     }
     return $this->jsFiles;
 }
Ejemplo n.º 14
0
 /**
  * Install language file
  * @param string $lang
  * @param bool $force
  * @param bool $move
  * @return array
  */
 public static function installLang($lang, $force = true, $move = false)
 {
     $log = array();
     if (count($lang)) {
         foreach ($lang as $language => $files) {
             $language = str_replace('_', '-', $language);
             if (count($files)) {
                 foreach ($files as $file) {
                     $target = $file['adm'] ? implode('/', array(JPATH_ADMINISTRATOR, 'language', $language)) : implode('/', array(SOBI_ROOT, 'language', $language));
                     if ($force || SPFs::exists($target)) {
                         $iFile = $target . '/' . trim($file['name']);
                         $log[] = $iFile;
                         $move ? SPFs::move(Sobi::FixPath($file['path']), $iFile) : SPFs::copy(Sobi::FixPath($file['path']), $iFile);
                     }
                 }
             }
         }
     }
     return $log;
 }
Ejemplo n.º 15
0
 private function install($file = null)
 {
     $arch = SPFactory::Instance('base.fs.archive');
     $ajax = strlen(SPRequest::cmd('ident', null, 'post'));
     if (!$file && SPRequest::string('root')) {
         $file = str_replace('.xml', null, SPRequest::string('root'));
         $file = SPLoader::path('tmp.install.' . $file, 'front', true, 'xml');
     }
     if (!$file) {
         $ident = SPRequest::cmd('ident', null, 'post');
         $data = SPRequest::file($ident);
         $name = str_replace(array('.' . SPFs::getExt($data['name']), '.'), null, $data['name']);
         $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false);
         $c = 0;
         while (SPFs::exists($path)) {
             $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false);
         }
         /*
          * temp directory - will be removed later but it needs to be writable for apache and Joomla! fs (FTP mode)
          */
         try {
             if (Sobi::Cfg('ftp_mode')) {
                 SPFs::mkdir($path, 0777);
             } else {
                 SPFs::mkdir($path);
             }
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
         $file = $path . '/' . $data['name'];
         try {
             $arch->upload($data['tmp_name'], $file);
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
     } elseif (SPRequest::string('root') && $file) {
         $path = dirname($file);
     } else {
         $arch->setFile($file);
         $name = str_replace(array('.' . SPFs::getExt($file), '.'), null, basename($file));
         $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false);
         $c = 0;
         while (SPFs::exists($path)) {
             $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false);
         }
         /*
          * temp directory - will be removed later but it needs to  writable for apache and Joomla! fs (FTP mode)
          */
         try {
             if (Sobi::Cfg('ftp_mode')) {
                 SPFs::mkdir($path, 0777);
             } else {
                 SPFs::mkdir($path);
             }
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
     }
     if ($path) {
         if (!SPRequest::string('root')) {
             if (!$arch->extract($path)) {
                 return $this->ajaxResponse($ajax, SPLang::e('CANNOT_EXTRACT_ARCHIVE', basename($file), $path), false, SPC::ERROR_MSG);
             }
         }
         $dir =& SPFactory::Instance('base.fs.directory', $path);
         $xml = array_keys($dir->searchFile('.xml', false, 2));
         if (!count($xml)) {
             return $this->ajaxResponse($ajax, SPLang::e('NO_INSTALL_FILE_IN_PACKAGE'), false, SPC::ERROR_MSG);
         }
         $definition = $this->searchInstallFile($xml);
         if (!$definition) {
             if (SPFactory::CmsHelper()->installerFile($xml)) {
                 try {
                     $message = SPFactory::CmsHelper()->install($xml, $path);
                     return $this->ajaxResponse($ajax, $message['msg'], $ajax, $message['msgtype']);
                 } catch (SPException $x) {
                     return $this->ajaxResponse($ajax, $x->getMessage(), $ajax, SPC::ERROR_MSG);
                 }
             } else {
                 return $this->ajaxResponse($ajax, SPLang::e('NO_INSTALL_FILE_IN_PACKAGE'), false, SPC::ERROR_MSG);
             }
         }
         /** @var $installer SPInstaller */
         $installer =& SPFactory::Instance('services.installers.' . trim(strtolower($definition->documentElement->tagName)), $xml[0], trim($definition->documentElement->tagName));
         try {
             $installer->validate();
             $msg = $installer->install();
             return $this->ajaxResponse($ajax, $msg, true, SPC::SUCCESS_MSG);
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
     } else {
         return $this->ajaxResponse($ajax, SPLang::e('NO_FILE_HAS_BEEN_UPLOADED'), false, SPC::ERROR_MSG);
     }
 }
Ejemplo n.º 16
0
 protected function installLanguage($def, $dir)
 {
     $this->checkRequirements($def);
     $this->definition = new DOMDocument();
     $this->definition->formatOutput = true;
     $this->definition->preserveWhiteSpace = false;
     $this->definition->appendChild($this->definition->createElement('SobiProApp'));
     $Install = $this->definition->createElement('installLog');
     $Files = $this->definition->createElement('files');
     $filesLog = array();
     $this->id = $def->getElementsByTagName('tag')->item(0)->nodeValue;
     if ($def->getElementsByTagName('administration')->length) {
         $this->langFiles('administration', $def, $dir, $filesLog);
     }
     if ($def->getElementsByTagName('site')->length) {
         $this->langFiles('site', $def, $dir, $filesLog);
     }
     $this->storeData('language', $def);
     $dir = SPLoader::dirPath('etc.installed.languages', 'front', false);
     if (!SPFs::exists($dir)) {
         SPFs::mkdir($dir);
     }
     foreach ($filesLog as $file) {
         $Files->appendChild($this->definition->createElement('file', $file));
     }
     $Install->appendChild($Files);
     $root = $this->definition->getElementsByTagName('SobiProApp')->item(0);
     $root->appendChild($this->definition->createElement('id', $this->id));
     $root->appendChild($this->definition->createElement('type', 'language'));
     $root->appendChild($this->definition->createElement('name', $def->getElementsByTagName('name')->item(0)->nodeValue));
     $root->appendChild($Install);
     $this->definition->appendChild($root);
     $path = "{$dir}/{$this->id}.xml";
     $file = SPFactory::Instance('base.fs.file', $path);
     $this->definition->normalizeDocument();
     $file->content($this->definition->saveXML());
     $file->save();
     if (!$this->error) {
         return array('msg' => Sobi::Txt('LANG_INSTALLED', $def->getElementsByTagName('name')->item(0)->nodeValue), 'msgtype' => SPC::SUCCESS_MSG);
     } else {
         return array('msg' => Sobi::Txt('LANG_INSTALLED', $def->getElementsByTagName('name')->item(0)->nodeValue) . "\n" . $this->error, 'msgtype' => $this->errorType);
     }
 }
Ejemplo n.º 17
0
 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;
 }
Ejemplo n.º 18
0
 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'))));
 }
Ejemplo n.º 19
0
 private function store($key, $value, $msg = null)
 {
     // let's try to create kinda mutex here
     $file = SPLoader::path('tmp.info', 'front', false, 'txt');
     while (SPFs::exists($file)) {
         usleep(100000);
     }
     $c = date(DATE_RFC822);
     SPFs::write($file, $c);
     $store = Sobi::GetUserData('requirements', array());
     $store[$key] = array('value' => $value, 'message' => $msg);
     Sobi::SetUserData('requirements', $store);
     SPFs::delete($file);
     //		$msg = $msg ? $msg[ 'org' ][ 'label' ] : null;
     //		$file = SPLoader::path( 'tmp.info', 'front', false, 'txt' );
     //		$cont = null;
     //		if ( SPFs::exists( $file ) ) {
     //			$cont = SPFs::read( $file );
     //		}
     //		$txt = "{$cont}\n{$key}={$msg};{$value}";
     //		SPFs::write( $file, $txt );
 }
Ejemplo n.º 20
0
 private function payment()
 {
     $sid = SPRequest::sid();
     $data = SPFactory::cache()->getObj('payment', $sid, Sobi::Section(), true);
     if (!$data) {
         $tsId = SPRequest::string('tsid');
         $tfile = SPLoader::path('tmp.edit.' . $tsId . '.payment', 'front', false, 'var');
         if (SPFs::exists($tfile)) {
             $data = SPConfig::unserialize(SPFs::read($tfile));
         }
     }
     if (!$data) {
         Sobi::Error('payment', SPLang::e('Session expired'), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     /*
      * It doesn't make sense because this has been already checked for the edit function. Right?
      * Or do I miss something?
      */
     //		if( Sobi::My( 'id' ) && Sobi::My( 'id' ) == $this->_model->get( 'owner' ) ) {
     //			$this->authorise( 'edit', 'own' );
     //		}
     //		else {
     //			$this->authorise( 'edit', '*' );
     //		}
     if ($data['ident'] != SPRequest::string('payment_' . $sid, null, false, 'cookie')) {
         Sobi::Error('payment', SPLang::e('UNAUTHORIZED_ACCESS'), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $this->paymentView(null, $data['data']);
 }
Ejemplo n.º 21
0
 /**
  * init tree
  * @param int $sid - sobi id / section id
  * @param int $current - actually displayed category
  * @return string $tree
  */
 public function init($sid, $current = 0)
 {
     $head =& SPFactory::header();
     if (defined('SOBIPRO_ADM')) {
         $head->addCssFile('tree', true);
     } else {
         if (Sobi::Reg('current_template_path', null) && SPFs::exists(Sobi::Reg('current_template_path') . 'css/tree.css')) {
             $head->addCssFile('absolute.' . Sobi::Reg('current_template_path') . 'css/tree.css');
         } else {
             $head->addCssFile('tree');
         }
     }
     $tree = null;
     $matrix = null;
     $this->_sid = $sid;
     if ($current) {
         $this->startScript($current);
     }
     $section = $this->getSection($sid);
     $sectionLink = $this->parseLink($section);
     $sectionName = $section->get('name');
     $childs = $this->getChilds($sid);
     //		if( count( $cats ) ) {
     //			foreach ( $cats as $i => $cat ) {
     //				$childs[ $cat->get( 'name' ).$i ] = $cat;
     //			}
     //		}
     //		ksort( $childs );
     $countNodes = count($childs, 0);
     $lastNode = 0;
     $tree .= "\n\t<{$this->_tag} class=\"sigsiuTree {$this->_id}SigsiuTree\">";
     $tree .= "\n\t\t<{$this->_tag} class=\"sigsiuTreeNode\" id=\"{$this->_id}stNode0\">";
     if (!in_array($sid, $this->_disabled)) {
         $tree .= "<a href=\"{$sectionLink}\" id=\"{$this->_id}_imgFolderUrl0\"><img id=\"{$this->_id}0\" src=\"{$this->_images['root']}\" alt=\"{$sectionName}\"/></a>";
     } else {
         $tree .= "<img id=\"{$this->_id}0\" src=\"{$this->_images['root']}\" alt=\"{$sectionName}\"/>";
     }
     if (!in_array($sid, $this->_disabled)) {
         $tree .= "<a href=\"{$sectionLink}\"  rel=\"{$sid}\" data-sid=\"{$sid}\" class=\"treeNode\" id=\"{$this->_id}_CatUrl0\">{$sectionName}</a>";
     } else {
         $tree .= $sectionName;
     }
     $tree .= "</{$this->_tag}>";
     $tree .= "\n\t\t<{$this->_tag} id=\"{$this->_id}\" class=\"clip\" style=\"display: block;\">";
     if (count($childs)) {
         foreach ($childs as $cat) {
             $countNodes--;
             // clean string produces htmlents and these are invalid in XML
             $catName = $cat->get('name');
             $hasChilds = count($cat->getChilds('category'));
             $cid = $cat->get('id');
             $url = $this->parseLink($cat);
             $disabled = in_array($cid, $this->_disabled) ? true : false;
             $tree .= "\n\t\t\t<{$this->_tag} class=\"sigsiuTreeNode\" id=\"{$this->_id}stNode{$cid}\">";
             if ($hasChilds) {
                 if ($countNodes == 0 && !$disabled) {
                     $lastNode = $cid;
                     $tree .= "\n\t\t\t\t\t<a href=\"javascript:{$this->_id}_stmExpand( {$cid}, 0, {$this->_pid} );\" id=\"{$this->_id}_imgUrlExpand{$cid}\">\n\t\t\t\t\t\t<img src=\"{$this->_images['plusBottom']}\" id=\"{$this->_id}_imgExpand{$cid}\"  style=\"border-style:none;\" alt=\"expand\"/>\n\t\t\t\t\t</a>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'plusBottom' );";
                 } elseif (!$disabled) {
                     $tree .= "\n\t\t\t\t\t<a href=\"javascript:{$this->_id}_stmExpand( {$cid}, 0, {$this->_pid} );\" id=\"{$this->_id}_imgUrlExpand{$cid}\">\n\t\t\t\t\t\t<img src=\"{$this->_images['plus']}\" id=\"{$this->_id}_imgExpand{$cid}\"  style=\"border-style:none;\" alt=\"expand\"/>\n\t\t\t\t\t</a>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'plus' );";
                 } else {
                     $tree .= "\n\t\t\t\t\t<img src=\"{$this->_images['join']}\" id=\"{$this->_id}_imgExpand{$cid}\" style=\"border-style:none;\" alt=\"expand\"/>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'plus' );";
                 }
             } else {
                 if ($countNodes == 0 && !$disabled) {
                     $lastNode = $cid;
                     $tree .= "\n\t\t\t\t\t<img src=\"{$this->_images['joinBottom']}\" style=\"border-style:none;\" id=\"{$this->_id}_imgJoin{$cid}\" alt=\"\"/>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'join' );";
                 } elseif (!$disabled) {
                     $tree .= "\n\t\t\t\t\t<img src=\"{$this->_images['join']}\" style=\"border-style:none;\" id=\"{$this->_id}_imgJoin{$cid}\" alt=\"\"/>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'joinBottom' );";
                 } else {
                     $tree .= "\n\t\t\t\t\t<img src=\"{$this->_images['joinBottom']}\" id=\"{$this->_id}_imgExpand{$cid}\" style=\"border-style:none;\" alt=\"expand\"/>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'plus' );";
                 }
             }
             if (!$disabled) {
                 $tree .= "\n\t\t\t\t\t<a href=\"{$url}\" id=\"{$this->_id}_imgFolderUrl{$cid}\">\n\t\t\t\t\t\t<img src=\"{$this->_images['folder']}\" style=\"border-style:none;\" id=\"{$this->_id}_imgFolder{$cid}\" alt=\"\"/>\n\t\t\t\t\t</a>\n\t\t\t\t\t<a href=\"{$url}\" rel=\"{$cid}\" data-sid=\"{$cid}\" class=\"treeNode\" id=\"{$this->_id}_CatUrl{$cid}\">\n\t\t\t\t\t\t{$catName}\n\t\t\t\t\t</a>";
             } else {
                 $tree .= "\n\t\t\t\t\t<img src=\"{$this->_images['disabled']}\" style=\"border-style:none;\" id=\"{$this->_id}_imgFolder{$cid}\" alt=\"\"/>\n\t\t\t\t\t{$catName}\n\t\t\t\t\t</a>";
             }
             $tree .= "\n\t\t\t</{$this->_tag}>";
             if ($hasChilds && !$disabled) {
                 $tree .= "\n\t\t\t<{$this->_tag} id=\"{$this->_id}_childsContainer{$cid}\" class=\"clip\" style=\"display: block; display:none;\"></{$this->_tag}>";
             }
         }
     }
     $tree .= "\n\t\t</{$this->_tag}>";
     $tree .= "\n\t</{$this->_tag}>\n\n";
     $this->createScript($lastNode, $childs, $matrix, $head);
     $this->tree = $tree;
 }
Ejemplo n.º 22
0
 /**
  * Moves file to new location
  * @param string $target - destination path
  * @return bool
  */
 public function move($target)
 {
     $f = explode(DS, $target);
     $path = str_replace($f[count($f) - 1], null, $target);
     if (!SPFs::exists($path)) {
         SPFs::mkdir($path);
     }
     if (SPFs::move($this->_filename, $target)) {
         $this->_filename = $target;
     }
     return $this;
 }
Ejemplo n.º 23
0
 /**
  * @param $file
  * @param $output
  * @param $u
  */
 protected function compileLessFile($file, $output, $u, $compress = false)
 {
     include_once 'phar://' . SOBI_PATH . '/lib/services/third-party/less/less.phar.tar.gz/Autoloader.php';
     try {
         Less_Autoloader::register();
         if ($compress) {
             $options = array('compress' => true, 'strictMath' => true);
         } else {
             $options = array();
         }
         $parser = new Less_Parser($options);
         $parser->parseFile($file);
         $css = $parser->getCss();
         if (SPFs::exists($output)) {
             SPFs::delete($output);
         }
         SPFs::write($output, $css);
     } catch (Exception $x) {
         $this->response(Sobi::Url($u), SPLang::e('TP.LESS_FILE_NOT_COMPILED', $x->getMessage()), false, SPC::ERROR_MSG);
     }
 }
Ejemplo n.º 24
0
 private function info()
 {
     $templateName = SPRequest::cmd('template');
     if (!strlen($templateName)) {
         $templateName = SPC::DEFAULT_TEMPLATE;
     }
     $dir = $this->dir($templateName);
     /** @var $view SPAdmTemplateView */
     $view = SPFactory::View('template', true);
     if (Sobi::Section() && Sobi::Cfg('section.template') == SPC::DEFAULT_TEMPLATE) {
         SPFactory::message()->warning(Sobi::Txt('TP.DEFAULT_WARN', 'https://www.sigsiu.net/help_screen/template.info'), false)->setSystemMessage();
     }
     if (SPFs::exists($dir . '/template.xml')) {
         $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');
     } else {
         SPFactory::message()->warning(Sobi::Txt('TP.MISSING_DEFINITION_FILE'), false)->setSystemMessage();
     }
     $menu = $this->createMenu();
     if (Sobi::Section()) {
         $menu->setOpen('AMN.APPS_SECTION_TPL');
     } else {
         $menu->setOpen('GB.CFG.GLOBAL_TEMPLATES');
     }
     $view->assign($menu, 'menu')->assign($this->_task, 'task')->assign(Sobi::Section(), 'sid')->addHidden($templateName, 'templateName')->determineTemplate('template', 'info');
     Sobi::Trigger('Info', $this->name(), array(&$file, &$view));
     $view->display();
 }
Ejemplo n.º 25
0
 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));
 }
Ejemplo n.º 26
0
 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);
             }
         }
     }
 }
Ejemplo n.º 27
0
 protected function initIcons()
 {
     if (!count($this->_icons)) {
         if (Sobi::Reg('current_template') && SPFs::exists(Sobi::Reg('current_template') . '/js/icons.json')) {
             $this->_icons = json_decode(Sobi::Reg('current_template') . '/js/icons.json', true);
         } else {
             $this->_icons = json_decode(SPFs::read(SOBI_PATH . '/etc/icons.json'), true);
         }
     }
 }