예제 #1
1
 /**
  * @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;
 }
예제 #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));
 }
예제 #3
0
파일: file.php 프로젝트: pelloq1/SobiPro
 protected function check($file)
 {
     $allowed = SPLoader::loadIniFile('etc.files');
     $mType = SPFactory::Instance('services.fileinfo', $file)->mimeType();
     if (strlen($mType) && !in_array($mType, $allowed)) {
         SPFs::delete($file);
         $this->message(array('type' => 'error', 'text' => SPLang::e('FILE_WRONG_TYPE', $mType), 'id' => ''));
     }
     return $mType;
 }
예제 #4
0
 /**
  * @param DOMDocument $def
  * @param string $dir
  * @return array | string
  */
 protected function installExt($def, $dir)
 {
     if ($def->firstChild->nodeName == 'install') {
         $content = $def->saveXML();
         // I know, I know ....
         $content = str_replace(array('<install', '</install>'), array('<extension', '</extension>'), $content);
         SPFs::write($dir . '/temp.xml', $content);
         $def = new DOMDocument();
         $def->load($dir . '/temp.xml');
     }
     return parent::installExt($def, $dir);
 }
예제 #5
0
 private function status($message, $progress = 0, $interval = 0, $type = SPC::INFO_MSG)
 {
     if (!strlen($message)) {
         $message = Sobi::Txt('PROGRESS_WORKING');
     }
     $progress = $progress ? $progress : $this->progress;
     $interval = $interval ? $interval : $this->interval;
     $type = $type ? $type : $this->type;
     $this->progress = $progress;
     $this->message = $message;
     $this->interval = $interval;
     $this->type = $type;
     $typeText = Sobi::Txt('STATUS_' . $type);
     SPFs::write($this->file, json_encode(array('progress' => $progress, 'message' => $message, 'interval' => $interval, 'type' => $type, 'typeText' => $typeText)));
 }
예제 #6
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));
 }
예제 #7
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');
 }
예제 #8
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));
     }
 }
예제 #9
0
 protected function iconChooser()
 {
     if (!Sobi::Can('category.edit')) {
         Sobi::Error('category', 'You have no permission to access this site', SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $folder = SPRequest::cmd('iconFolder', null);
     $callback = SPRequest::cmd('callback', 'SPSelectIcon');
     $dir = $folder ? Sobi::Cfg('images.category_icons') . str_replace('.', '/', $folder) . '/' : Sobi::Cfg('images.category_icons');
     $files = array();
     $dirs = array();
     if ($folder) {
         $up = explode('.', $folder);
         unset($up[count($up) - 1]);
         $dirs[] = array('name' => Sobi::Txt('FOLEDR_UP'), 'count' => count(scandir($dir . '..')) - 2, 'url' => Sobi::Url(array('task' => 'category.icon', 'out' => 'html', 'iconFolder' => count($up) ? implode('.', $up) : null)));
     }
     $ext = array('png', 'jpg', 'jpeg', 'gif');
     if (is_dir($dir) && ($dh = opendir($dir))) {
         while (($file = readdir($dh)) !== false) {
             if (filetype($dir . $file) == 'file' && in_array(strtolower(SPFs::getExt($file)), $ext)) {
                 $files[] = array('name' => $folder ? str_replace('.', '/', $folder) . '/' . $file : $file, 'path' => str_replace('\\', '/', str_replace(SOBI_ROOT, Sobi::Cfg('live_site'), str_replace('//', '/', $dir . $file))));
             } elseif (filetype($dir . $file) == 'dir' && !($file == '.' || $file == '..')) {
                 $dirs[] = array('name' => $file, 'count' => count(scandir($dir . $file)) - 2, 'path' => str_replace('\\', '/', str_replace(SOBI_ROOT, Sobi::Cfg('live_site'), str_replace('//', '/', $dir . $file))), 'url' => Sobi::Url(array('task' => 'category.icon', 'out' => 'html', 'iconFolder' => $folder ? $folder . '.' . $file : $file)));
             }
         }
         closedir($dh);
     }
     sort($files);
     sort($dirs);
     $view = SPFactory::View('category');
     $view->setTemplate('category.icon');
     $view->assign($this->_task, 'task');
     $view->assign($callback, 'callback');
     $view->assign($files, 'files');
     $view->assign(Sobi::Cfg('images.folder_ico'), 'folder');
     $view->assign($dirs, 'directories');
     $view->icon();
 }
예제 #10
0
 private static function createLangFile()
 {
     static $loaded = false;
     if (!$loaded) {
         $lang = array('months' => Sobi::Txt('JS_CALENDAR_MONTHS'), 'monthsShort' => Sobi::Txt('JS_CALENDAR_MONTHS_SHORT'), 'days' => Sobi::Txt('JS_CALENDAR_DAYS'), 'daysShort' => Sobi::Txt('JS_CALENDAR_DAYS_SHORT'), 'daysMin' => Sobi::Txt('JS_CALENDAR_DAYS_MINI'), 'today' => Sobi::Txt('JS_CALENDAR_TODAY'));
         $check = md5(serialize($lang));
         if (!SPLoader::JsFile('locale.' . Sobi::Lang(false) . '_date_picker', false, true, false) || !stripos(SPFs::read(SPLoader::JsFile('locale.' . Sobi::Lang(false) . '_date_picker', false, false, false)), $check)) {
             foreach ($lang as $k => $v) {
                 $lang[$k] = explode(',', $v);
             }
             $lang = json_encode($lang);
             $c = "\nvar spDatePickerLang={$lang}";
             $c .= "\n//{$check}";
             SPFs::write(SPLoader::JsFile('locale.' . Sobi::Lang(false) . '_date_picker', false, false, false), $c);
         }
     }
     $loaded = true;
 }
예제 #11
0
 public function loadFile($file)
 {
     $sql = SPFs::read($file);
     $sql = explode("\n", $sql);
     $log = array();
     if (count($sql)) {
         foreach ($sql as $query) {
             if (strlen($query)) {
                 $this->exec(str_replace('spdb_', $this->prefix . 'sobipro_', $query));
                 $log[] = $query;
             }
         }
     }
     return $log;
 }
예제 #12
0
 /**
  * @return array
  */
 public function struct()
 {
     if (!$this->dependency) {
         return parent::struct(true);
     }
     $selected = $this->getRaw();
     if (isset($this->_fData->options)) {
         $path = SPConfig::unserialize($this->_fData->options);
     } else {
         return null;
     }
     $selectedPath = array();
     $options = json_decode(SPFs::read(SOBI_PATH . '/etc/fields/select-list/definitions/' . str_replace('.xml', '.json', $this->dependencyDefinition)), true);
     if (isset($options['translation'])) {
         SPLang::load($options['translation']);
         $selected = Sobi::Txt(strtoupper($options['prefix']) . '.' . strtoupper($selected));
     }
     if (count($path) && isset($options['translation'])) {
         foreach ($path as $step) {
             $selectedPath[$step] = $selected = Sobi::Txt(strtoupper($options['prefix']) . '.' . strtoupper($step));
         }
     }
     $this->cleanCss();
     return array('_complex' => 1, '_data' => $selected, '_attributes' => array('class' => $this->cssClass), '_options' => array('path' => count($selectedPath) ? $selectedPath : $path));
 }
예제 #13
0
파일: front.php 프로젝트: pelloq1/SobiPro
 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;
 }
예제 #14
0
 /**
  * Small work-around
  * The imageTYPE function is not very suitable for OO code
  * @return void
  */
 private function storeImage()
 {
     $st = preg_replace('/[^0-9]/', null, microtime(true) * 10000);
     $this->temp = SPLoader::path('tmp.img.' . $st, 'front', false, 'var', false);
     if (!SPLoader::dirPath('tmp.img', 'front', true)) {
         SPFs::mkdir(SPLoader::dirPath('tmp.img', 'front', false));
     }
     switch ($this->type) {
         case IMAGETYPE_GIF:
             imagegif($this->image, $this->temp);
             break;
         case IMAGETYPE_JPEG:
         case IMAGETYPE_JPEG2000:
             imagejpeg($this->image, $this->temp, Sobi::Cfg('image.jpeg_quality', 75));
             break;
         case IMAGETYPE_PNG:
             imagepng($this->image, $this->temp, Sobi::Cfg('image.png_compression', 0));
             break;
     }
     $this->_content = file_get_contents($this->temp);
     if ($this->image) {
         imagedestroy($this->image);
     }
 }
예제 #15
0
 private function editFile()
 {
     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();
     }
     $file = SPRequest::cmd('file');
     $file = $this->file($file);
     $ext = SPFs::getExt($file);
     $fileContent = SPFs::read($file);
     $path = str_replace('\\', '/', SOBI_PATH);
     if (strstr($file, $path)) {
         $filename = str_replace($path . '/usr/templates/', null, $file);
     } else {
         $filename = str_replace(SOBI_ROOT, null, $file);
     }
     $menu = $this->createMenu();
     if (Sobi::Section()) {
         $menu->setOpen('AMN.APPS_SECTION_TPL');
     } else {
         $menu->setOpen('GB.CFG.GLOBAL_TEMPLATES');
     }
     /** @var $view SPAdmTemplateView */
     $view = SPFactory::View('template', true)->assign($fileContent, 'file_content')->assign($filename, 'file_name')->assign($ext, 'file_ext')->assign($menu, 'menu')->assign($this->_task, 'task')->assign(Sobi::Section(), 'sid')->addHidden(SPRequest::cmd('file'), 'fileName')->addHidden($filename, 'filePath')->determineTemplate('template', 'edit');
     Sobi::Trigger('Edit', $this->name(), array(&$file, &$view));
     $view->display();
 }
예제 #16
0
 /**
  *
  */
 private function mimeFromExt()
 {
     $ext = SPFs::getExt($this->_path);
     if (!count(self::$_exts)) {
         self::$_exts = SPLoader::loadIniFile('etc.mime', false);
     }
     if (!isset(self::$_exts[$ext])) {
         Sobi::Error('FileInfo', SPLang::e('Cannot determine the right file type from extension'), SPC::WARNING, 0);
     } else {
         $this->_mime = self::$_exts[$ext];
     }
 }
예제 #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;
 }
예제 #18
0
파일: error.php 프로젝트: pelloq1/SobiPro
 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);
 }
예제 #19
0
 /**
  * @param string $name variable name
  * @param string $property
  * @param string $request request method
  * @return string
  */
 public static function file($name, $property = null, $request = 'files')
 {
     if ($request == 'files') {
         /** check for Ajax uploaded files */
         $check = self::string($name);
         if ($check) {
             $secret = md5(Sobi::Cfg('secret'));
             $fileName = str_replace('file://', null, $check);
             $path = SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $fileName;
             if (file_exists("{$path}.var")) {
                 $cfg = SPFs::read("{$path}.var");
                 $data = SPConfig::unserialize($cfg);
                 $_FILES[$name] = $data;
             }
         }
     }
     self::init($name, $request);
     self::$val = isset(self::$request[self::$name]) ? self::$request[self::$name] : null;
     return $property && isset(self::$val[$property]) ? self::$val[$property] : self::$val;
 }
예제 #20
0
 private function langFiles($tag, $def, $dir, &$FilesLog)
 {
     $target = $tag == 'administration' ? implode(DS, array(SOBI_ROOT, 'administrator', 'language', $this->id)) : implode(DS, array(SOBI_ROOT, 'language', $this->id));
     if (!file_exists($target)) {
         $this->error = Sobi::Txt('LANG_INSTALL_NO_CORE', $this->id);
         $this->errorType = SPC::WARN_MSG;
         SPFs::mkdir($target);
     }
     $files = $def->getElementsByTagName($tag)->item(0)->getElementsByTagName('files')->item(0);
     $folder = $files->getAttribute('folder');
     $folder = $dir . $folder . DS;
     foreach ($files->getElementsByTagName('filename') as $file) {
         if (file_exists($folder . $file->nodeValue)) {
             if (!SPFs::copy($folder . $file->nodeValue, $target . DS . $file->nodeValue)) {
                 SPFactory::message()->error(Sobi::Txt('Cannot copy %s to %s', $folder . $file->nodeValue, $target . DS . $file->nodeValue), false);
             } else {
                 $FilesLog[] = str_replace(array(DS . DS, SOBI_ROOT), array(DS, null), $target . DS . $file->nodeValue);
             }
         } else {
             SPFactory::message()->error(Sobi::Txt('File %s does not exist!', $folder . $file->nodeValue), false);
         }
     }
 }
예제 #21
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);
     }
 }
예제 #22
0
 /**
  * Remove all files in directory
  * @return bool
  */
 public function deleteFiles()
 {
     $this->iterator();
     $log = array();
     foreach ($this->_dirIterator as $child) {
         if (!$child->isDot()) {
             SPFs::delete($child->getPathname());
         }
     }
 }
예제 #23
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 );
 }
예제 #24
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;
 }
예제 #25
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;
 }
예제 #26
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));
 }
예제 #27
0
 /**
  * @param $entry
  * @param $request
  * @param $files
  * @param $cloneFiles
  * @return SPdb
  */
 protected function cloneFiles(&$entry, $request, $files, $cloneFiles)
 {
     $orgName = basename($files['original']);
     $sPath = $this->parseName($entry, $orgName, $this->savePath);
     $cloneFiles['original'] = $sPath . $this->parseName($entry, $orgName, '{orgname}', true);
     SPFs::copy(SOBI_ROOT . '/' . $files['original'], SOBI_ROOT . '/' . $cloneFiles['original']);
     $cloneFiles['image'] = $sPath . $this->parseName($entry, $orgName, $this->imageName, true);
     SPFs::copy(SOBI_ROOT . '/' . $files['image'], SOBI_ROOT . '/' . $cloneFiles['image']);
     $cloneFiles['thumb'] = $sPath . $this->parseName($entry, $orgName, $this->thumbName, true);
     SPFs::copy(SOBI_ROOT . '/' . $files['thumb'], SOBI_ROOT . '/' . $cloneFiles['thumb']);
     $cloneFiles['ico'] = $sPath . $this->parseName($entry, strtolower($orgName), 'ico_{orgname}', true);
     SPFs::copy(SOBI_ROOT . '/' . $files['ico'], SOBI_ROOT . '/' . $cloneFiles['ico']);
     return $this->storeData($entry, $request, $cloneFiles);
 }
예제 #28
0
 /**
  * @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";
         }
     }
 }
예제 #29
0
 /**
  * Returns currently used language
  *
  * @param $path
  * @return string
  */
 public static function FixPath($path)
 {
     return SPFs::clean($path);
 }
예제 #30
0
 protected function parseDependencyDefinition($file)
 {
     $dom = new DOMDocument();
     $dom->load(SOBI_PATH . '/etc/fields/select-list/' . $file);
     $xpath = new DOMXPath($dom);
     $definition = array();
     $root = $xpath->query('/definition');
     $definition['prefix'] = $root->item(0)->attributes->getNamedItem('prefix')->nodeValue;
     $definition['translation'] = $root->item(0)->attributes->getNamedItem('translation')->nodeValue;
     $definition['options'] = array();
     $this->_parseXML($xpath->query('/definition/option'), $definition['options']);
     SPFs::write(SOBI_PATH . '/etc/fields/select-list/definitions/' . str_replace('.xml', '.json', $file), json_encode($definition));
 }