protected function upload() { $ident = SPRequest::cmd('ident', null, 'post'); $data = SPRequest::file($ident, 'tmp_name'); $secret = md5(Sobi::Cfg('secret')); if ($data) { $properties = SPRequest::file($ident); $fileName = md5(SPRequest::file($ident, 'name') . time() . $secret); $path = SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $fileName; /** @var $file SPFile */ $file = SPFactory::Instance('base.fs.file'); if (!$file->upload($data, $path)) { $this->message(array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE'), 'id' => '')); } $path = $file->getPathname(); $type = $this->check($path); $properties['tmp_name'] = $path; SPFs::write($path . '.var', SPConfig::serialize($properties)); $response = array('type' => 'success', 'text' => Sobi::Txt('FILE_UPLOADED', $properties['name'], $type), 'id' => 'file://' . $fileName, 'data' => array('name' => $properties['name'], 'type' => $properties['type'], 'size' => $properties['size'])); } else { $response = array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE_NO_DATA'), 'id' => ''); } // $field = SPRequest::cmd( 'field', null ); $this->message($response); }
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)); }
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)); }
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); } }
private function dir($file) { $file = explode('.', $file); if (strstr($file[0], 'cms:')) { $file[0] = str_replace('cms:', null, $file[0]); $file = SPFactory::mainframe()->path(implode('.', $file)); $file = SPLoader::dirPath($file, 'root', true); } else { $file = SPLoader::dirPath('usr.templates.' . implode('.', $file), 'front', true); } if (!$file) { $file = SPLoader::path('usr.templates.' . implode('.', $file), 'front', false); Sobi::Error($this->name(), SPLang::e('FILE_NOT_FOUND', $file), SPC::WARNING, 404, __LINE__, __FILE__); } return $file; }
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; }
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; }
protected function listTemplates($tpl = null, $cmsOv = true) { SPFactory::header()->addJsFile('dtree')->addCssFile('dtree', true); SPLoader::loadClass('base.fs.directory_iterator'); $ls = Sobi::Cfg('live_site') . 'media/sobipro/tree'; $nodes = null; $count = 0; $tpl = Sobi::FixPath($tpl ? $tpl : SPLoader::dirPath('usr.templates')); if (Sobi::Section()) { $realName = Sobi::Txt('TP.INFO'); $iTask = Sobi::Url(array('task' => 'template.info', 'template' => basename($tpl), 'sid' => Sobi::Section())); $nodes .= "spTpl.add( -123, 0,'{$realName}','{$iTask}', '', '', '{$ls}/info.png' );\n"; if (file_exists("{$tpl}/config.xml")) { $realName = Sobi::Txt('TP.SETTINGS'); $iTask = Sobi::Url(array('task' => 'template.settings', 'template' => basename($tpl), 'sid' => Sobi::Section())); $nodes .= "spTpl.add( -120, 0,'{$realName}','{$iTask}', '', '', '{$ls}/settings.png' );\n"; } } $this->travelTpl(new SPDirectoryIterator($tpl), $nodes, 0, $count); if ($cmsOv) { $cms = SPFactory::CmsHelper()->templatesPath(); if (is_array($cms) && isset($cms['name']) && isset($cms['data']) && is_array($cms['data']) && count($cms['data'])) { $count++; if (isset($cms['icon'])) { $nodes .= "spTpl.add( {$count}, 0, '{$cms['name']}', '', '', '', '{$cms['icon']}', '{$cms['icon']}' );\n"; } else { $nodes .= "spTpl.add( {$count}, 0, '{$cms['name']}' );\n"; } $current = $count; foreach ($cms['data'] as $name => $path) { $count++; $nodes .= "spTpl.add( {$count}, {$current},'{$name}' );\n"; $this->travelTpl(new SPDirectoryIterator($path), $nodes, $count, $count, true); } } } if (Sobi::Section()) { $file = SPLoader::path('usr.templates.' . Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE) . '.template', 'front', true, 'xml'); $def = new DOMDocument(); $def->load($file); $xdef = new DOMXPath($def); $t = $xdef->query('/template/name')->item(0)->nodeValue; } else { $t = Sobi::Txt('GB.TEMPLATES'); } SPFactory::header()->addJsCode("\n\t\t\ticons = {\n\t\t\t\t\t\troot : '{$ls}/base.gif',\n\t\t\t\t\t\tfolder : '{$ls}/folder.gif',\n\t\t\t\t\t\tfolderOpen : '{$ls}/folderopen.gif',\n\t\t\t\t\t\tnode : '{$ls}/page.gif',\n\t\t\t\t\t\tempty : '{$ls}/empty.gif',\n\t\t\t\t\t\tline : '{$ls}/line.gif',\n\t\t\t\t\t\tjoin : '{$ls}/join.gif',\n\t\t\t\t\t\tjoinBottom : '{$ls}/joinbottom.gif',\n\t\t\t\t\t\tplus : '{$ls}/plus.gif',\n\t\t\t\t\t\tplusBottom : '{$ls}/plusbottom.gif',\n\t\t\t\t\t\tminus : '{$ls}/minus.gif',\n\t\t\t\t\t\tminusBottom\t: '{$ls}/minusbottom.gif',\n\t\t\t\t\t\tnlPlus : '{$ls}/nolines_plus.gif',\n\t\t\t\t\t\tnlMinus : '{$ls}/nolines_minus.gif'\n\t\t\t};\n\t\t\tvar spTpl = new dTree( 'spTpl', icons );\t\n\n\t\t\tSobiPro.jQuery( document ).ready( function ()\n\t\t\t{\n\t\t\t\tspTpl.add(0, -1, '{$t}' );\n\n\t\t\t\t{$nodes} \n\n\t\t\t\ttry { document.getElementById( 'spTpl' ).innerHTML = spTpl } catch( e ) {}\n\t\t\t} );\n\t\t"); /** for some reason jQuery is not able to add the tree */ return "<div id=\"spTpl\"></div>"; }
protected function listFunctions() { /** @var SPDirectory $directory */ $directory = SPFactory::Instance('base.fs.directory', SPLoader::dirPath('menu', 'adm.templates')); $files = $directory->searchFile('.xml', false); $functions = array(); if (count($files)) { foreach ($files as $file) { $path = $file->getPathInfo(); $functions[$path['filename']] = $this->functionDetails($file); } } /** Mon, Aug 24, 2015 10:24:24 - put the section ink on the top */ $section = $functions['section']; unset($functions['section']); $functions = array_merge(array('section' => $section), $functions); $functions = array_merge(array('null' => Sobi::Txt('SOBI_SELECT_FUNCTIONALITY')), $functions); SPFactory::View('joomla-menu', true)->assign($functions, 'functions')->functions(); }
/** * @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; }
/** */ protected function tplCfg($path, $task = null) { $file = explode('.', $path); $files = array(); if (strstr($file[0], 'cms:')) { $file[0] = str_replace('cms:', null, $file[0]); $file = SPFactory::mainframe()->path(implode('.', $file)); $path = SPLoader::dirPath($file, 'root', true); $this->_tCfg = SPLoader::loadIniFile("{$path}.config", true, false, false, true); $files[] = SPLoader::iniStorage(); } else { $this->_tCfg = SPLoader::loadIniFile("usr.templates.{$path}.config"); $files[] = SPLoader::iniStorage(); $path = SPLoader::dirPath('usr.templates.' . $path, 'front', true); } if (!$task) { $task = $this->_task == 'add' || $this->_task == 'submit' ? 'edit' : $this->template; } if (SPLoader::translatePath("{$path}.{$this->templateType}.{$task}", 'absolute', true, 'ini')) { $taskCfg = SPLoader::loadIniFile("{$path}.{$this->templateType}.{$task}", true, false, false, true); $files[] = SPLoader::iniStorage(); foreach ($taskCfg as $section => $keys) { if (isset($this->_tCfg[$section])) { $this->_tCfg[$section] = array_merge($this->_tCfg[$section], $keys); } else { $this->_tCfg[$section] = $keys; } } } if (count($files)) { foreach ($files as $i => $file) { $files[$i] = array('file' => str_replace(SPLoader::translateDirPath(Sobi::Cfg('section.template'), 'templates'), null, $file), 'checksum' => md5_file($file)); } SPFactory::registry()->set('template_config', $files); } if (SPLoader::translatePath("{$path}.config", 'absolute', true, 'json')) { $config = json_decode(SPFs::read(SPLoader::translatePath("{$path}.config", 'absolute', true, 'json')), true); $settings = array(); foreach ($config as $section => $setting) { $settings[str_replace('-', '.', $section)] = $setting; } if (SPLoader::translatePath("{$path}.{$this->templateType}.{$task}", 'absolute', true, 'json')) { $subConfig = json_decode(SPFs::read(SPLoader::translatePath("{$path}.{$this->templateType}.{$task}", 'absolute', true, 'json')), true); if (count($subConfig)) { foreach ($subConfig as $section => $subSettings) { foreach ($subSettings as $k => $v) { $settings[str_replace('-', '.', $section)][$k] = $v; } } } } if (isset($settings['general'])) { foreach ($settings['general'] as $k => $v) { $this->_tCfg['general'][$k] = $v; } } $task = SPRequest::task() == 'entry.add' ? 'entry.edit' : SPRequest::task(); if (isset($settings[$task])) { foreach ($settings[$task] as $k => $v) { $this->_tCfg['general'][$k] = $v; } } } Sobi::Trigger($this->name(), __FUNCTION__, array(&$this->_tCfg)); SPFactory::registry()->set('current_template', $path); }
protected function tplPath() { if (!$this->_templatePath) { $tpl = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE); $file = explode('.', $tpl); if (strstr($file[0], 'cms:')) { $file[0] = str_replace('cms:', null, $file[0]); $file = SPFactory::mainframe()->path(implode('.', $file)); $this->_templatePath = SPLoader::dirPath($file, 'root', false, null); } else { $this->_templatePath = SPLoader::dirPath('usr.templates.' . $tpl, 'front', false, null); } } SPFactory::registry()->set('current_template_path', $this->_templatePath); return $this->_templatePath; }
/** * 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); } }
/** * Save an entry * * @param bool $apply */ protected function save($apply) { $new = true; if (!$this->_model) { $this->setModel(SPLoader::loadModel($this->_type)); } if ($this->_model->get('oType') != 'entry') { Sobi::Error('Entry', sprintf('Serious security violation. Trying to save an object which claims to be an entry but it is a %s. Task was %s', $this->_model->get('oType'), SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); exit; } /* check if we have stored last edit in cache */ $tsId = SPRequest::string('editentry', null, false, 'cookie'); if (!$tsId) { $tsId = SPRequest::cmd('ssid'); } $request = $this->getCache($tsId); $this->_model->init(SPRequest::sid($request)); $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE); $this->tplCfg($tplPackage); $customClass = null; if (isset($this->_tCfg['general']['functions']) && $this->_tCfg['general']['functions']) { $customClass = SPLoader::loadClass('/' . str_replace('.php', null, $this->_tCfg['general']['functions']), false, 'templates'); if (method_exists($customClass, 'BeforeStoreEntry')) { $customClass::BeforeStoreEntry($this->_model, $this->store['post']); SPFactory::registry()->set('requestcache_stored', $this->store); SPFactory::registry()->set('requestcache', $this->store['post']); } } $preState = array('approved' => $this->_model->get('approved'), 'state' => $this->_model->get('state'), 'new' => !$this->_model->get('id')); SPFactory::registry()->set('object_previous_state', $preState); $this->_model->getRequest($this->_type, $request); Sobi::Trigger($this->name(), __FUNCTION__, array(&$this->_model)); if ($this->_model->get('id') && $this->_model->get('id') == SPRequest::sid()) { $new = false; if (Sobi::My('id') && Sobi::My('id') == $this->_model->get('owner')) { $this->authorise('edit', 'own'); } else { $this->authorise('edit', '*'); } } else { $this->authorise('add', 'own'); } $this->_model->save($request); /* if there is something pay */ $pCount = SPFactory::payment()->count($this->_model->get('id')); if ($pCount && !Sobi::Can('entry.payment.free')) { // $this->paymentView( $tsid ); if ($customClass && method_exists($customClass, 'BeforeStoreEntryPayment')) { $customClass::BeforeStoreEntryPayment($this->_model->get('id')); } SPFactory::payment()->store($this->_model->get('id')); } /* delete cache files on after */ $file = str_replace('.', '-', $tsId); if (SPLoader::dirPath('tmp.edit.' . $file)) { SPFs::delete(SPLoader::dirPath('tmp.edit.' . $file)); } else { SPFactory::cache()->deleteVar('request_cache_' . $tsId); } SPLoader::loadClass('env.cookie'); SPCookie::delete('editentry'); $sid = $this->_model->get('id'); $pid = SPRequest::int('pid') ? SPRequest::int('pid') : Sobi::Section(); if ($new) { if ($this->_model->get('state') || Sobi::Can('entry.see_unpublished.own')) { $msg = $this->_model->get('state') ? Sobi::Txt('EN.ENTRY_SAVED') : Sobi::Txt('EN.ENTRY_SAVED_NP'); $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid)); } else { // determine if there is a custom redirect if (Sobi::Cfg('redirects.entry_save_enabled') && !($pCount && !Sobi::Can('entry.payment.free'))) { $redirect = Sobi::Cfg('redirects.entry_save_url', null); if (!preg_match('/http[s]?:\\/\\/.*/', $redirect) && $redirect != 'index.php') { $redirect = Sobi::Url($redirect); } $this->response($redirect, Sobi::Txt(Sobi::Cfg('redirects.entry_save_msg', 'EN.ENTRY_SAVED_NP')), true, Sobi::Cfg('redirects.entry_save_msgtype', SPC::SUCCESS_MSG)); } else { $msg = Sobi::Txt('EN.ENTRY_SAVED_NP'); $url = Sobi::Url(array('sid' => $pid)); } } } elseif ($this->_model->get('approved') || Sobi::Can('entry.see_unapproved.own')) { $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid)); $msg = $this->_model->get('approved') ? Sobi::Txt('EN.ENTRY_SAVED') : Sobi::Txt('EN.ENTRY_SAVED_NA'); } else { if ($this->_model->get('approved')) { $msg = Sobi::Txt('EN.ENTRY_SAVED'); } else { $msg = Sobi::Txt('EN.ENTRY_SAVED_NA'); } $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid)); } if ($pCount && !Sobi::Can('entry.payment.free')) { $ident = md5(microtime() . $tsId . $sid . time()); $data = array('data' => SPFactory::payment()->summary($sid), 'ident' => $ident); $url = Sobi::Url(array('sid' => $sid, 'task' => 'entry.payment'), false, false); if (Sobi::Cfg('cache.l3_enabled', true)) { SPFactory::cache()->addObj($data, 'payment', $sid, Sobi::Section(), true); } else { SPFs::write(SPLoader::path('tmp.edit.' . $ident . '.payment', 'front', false, 'var'), SPConfig::serialize($data)); $url = Sobi::Url(array('sid' => $sid, 'task' => 'entry.payment', 'tsid' => $ident), false, false); } SPLoader::loadClass('env.cookie'); SPCookie::set('payment_' . $sid, $ident, SPCookie::days(1)); } if ($customClass && method_exists($customClass, 'AfterStoreEntry')) { $customClass::AfterStoreEntry($this->_model); } $this->logChanges('save', SPRequest::string('history-note')); $this->response($url, $msg, true, SPC::SUCCESS_MSG); }
public function install() { $log = array(); $type = strlen($this->xGetString('type')) ? $this->xGetString('type') : ($this->xGetString('fieldType') ? 'field' : null); $id = $this->xGetString('id'); if ($this->installed($id, $type)) { SPFactory::db()->delete('spdb_plugins', array('pid' => $id, 'type' => $type)); } Sobi::Trigger('Before', 'InstallPlugin', array($id)); $requirements = $this->xGetChilds('requirements/*'); if ($requirements && $requirements instanceof DOMNodeList) { $reqCheck =& SPFactory::Instance('services.installers.requirements'); $reqCheck->check($requirements); } $permissions = $this->xGetChilds('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->addPermission($perm[0], $perm[1], $perm[2]); $log['permissions'][] = $permissions->item($i)->nodeValue; } } $actions = $this->xGetChilds('actions/*'); if ($actions && $actions instanceof DOMNodeList) { $log['actions'] = $this->actions($actions, $id); } $dir = SPLoader::dirPath('etc.installed.' . $type . 's', 'front', false); if (!SPFs::exists($dir)) { SPFs::mkdir($dir); SPFs::mkdir("{$dir}/{$id}/backup"); } $files = $this->xGetChilds('files'); $date = str_replace(array(':', ' '), array('-', '_'), SPFactory::config()->date(time())); if ($files && $files instanceof DOMNodeList && $files->length) { $log['files'] = $this->files($files, $id, "{$dir}/{$id}/backup/{$date}"); if (count($log['files'])) { foreach ($log['files'] as $i => $f) { $log['files'][$i] = str_replace(SOBI_ROOT, null, $f); } } } $languages = $this->xGetChilds('language'); if ($languages->length) { $langFiles = array(); foreach ($languages as $language) { $folder = $language->attributes->getNamedItem('folder')->nodeValue; foreach ($language->childNodes as $file) { $adm = false; if (strstr($file->nodeName, '#')) { continue; } 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); } } $log['files']['created'] = array_merge($log['files']['created'], SPFactory::CmsHelper()->installLang($langFiles, false)); } $sql = $this->xGetString('sql'); if ($sql && SPFs::exists("{$this->root}/{$sql}")) { try { $log['sql'] = SPFactory::db()->loadFile("{$this->root}/{$sql}"); } catch (SPException $x) { Sobi::Error('installer', SPLang::e('CANNOT_EXECUTE_QUERIES', $x->getMessage()), SPC::WARNING, 500, __LINE__, __FILE__); return false; } } if (!strlen($this->xGetString('type')) && strlen($this->xGetString('fieldType'))) { $log['field'] = $this->field(); } $exec = $this->xGetString('exec'); if ($exec && SPFs::exists("{$this->root}/{$exec}")) { include_once "{$this->root}/{$exec}"; } $this->plugin($id, $type); $this->log($log); $this->definition->formatOutput = true; $this->definition->preserveWhiteSpace = false; $this->definition->normalizeDocument(); $path = "{$dir}/{$id}.xml"; $file = SPFactory::Instance('base.fs.file', $path); // $file->content( $this->definition->saveXML() ); // why the hell DOM cannot format it right. Try this $outXML = $this->definition->saveXML(); $xml = new DOMDocument(); $xml->preserveWhiteSpace = false; $xml->formatOutput = true; $xml->loadXML($outXML); $file->content($xml->saveXML()); $file->save(); switch ($type) { case 'SobiProApp': $type = 'plugin'; default: case 'update': case 'plugin': case 'field': $t = Sobi::Txt('EX.' . strtoupper($type) . '_TYPE'); break; case 'payment': $t = Sobi::Txt('EX.PAYMENT_METHOD_TYPE'); break; } Sobi::Trigger('After', 'InstallPlugin', array($id)); $dir =& SPFactory::Instance('base.fs.directory', SPLoader::dirPath('tmp.install')); $dir->deleteFiles(); return Sobi::Txt('EX.EXTENSION_HAS_BEEN_INSTALLED', array('type' => $t, 'name' => $this->xGetString('name'))); }
/** * This method is adding new tasks to the XML files used for Joomla! menu definition * @param $tasks - list of tasks to add * @param $controlString - a single string to check for if it has not been already added * @param $languageFile - language file where the translation for tasks can be found * @param array $additionalStrings - optional list of additional strings to add to the sys ini files * @param bool $force - force even if it has been already done - forcing only language files redefinition * @return void */ public function updateXMLDefinition($tasks, $controlString, $languageFile, $additionalStrings = array(), $force = false) { $file = SPLoader::translatePath('metadata', 'front', true, 'xml'); $run = false; $strings = array(); foreach ($tasks as $label) { $strings[] = $label; $strings[] = $label . '_EXPL'; } if (count($additionalStrings)) { foreach ($additionalStrings as $additionalString) { $strings[] = $additionalString; } } /** check if it hasn't been already added */ if (!strstr(SPFs::read($file), $controlString)) { $run = true; $doc = new DOMDocument(); $doc->load($file); $options = $doc->getElementsByTagName('options')->item(0); foreach ($tasks as $task => $label) { $node = $doc->createElement('option'); $attribute = $doc->createAttribute('value'); $attribute->value = $task; $node->appendChild($attribute); $attribute = $doc->createAttribute('name'); $attribute->value = 'SP.' . $label; $node->appendChild($attribute); $attribute = $doc->createAttribute('msg'); $attribute->value = 'SP.' . $label . '_EXPL'; $node->appendChild($attribute); $options->appendChild($node); } $doc->save($file); } if ($run || $force) { $dirPath = SPLoader::dirPath('administrator.language', 'root'); /** @var SPDirectory $dir */ $dir = SPFactory::Instance('base.fs.directory', $dirPath); $files = $dir->searchFile('com_sobipro.sys.ini', false, 2); $default = array(); $defaultLangDir = SPLoader::dirPath("language.en-GB", 'root', true); $defaultLang = parse_ini_file($defaultLangDir . 'en-GB.' . $languageFile . '.ini'); foreach ($strings as $string) { $default['SP.' . $string] = $defaultLang['SP.' . $string]; } /** @var SPFile $file */ $file = null; foreach ($files as $file) { $fileName = $file->getFileName(); list($language) = explode('.', $fileName); $nativeLangDir = SPLoader::dirPath("language.{$language}", 'root', true); $nativeStrings = array(); if ($nativeLangDir) { $nativeLangFile = $nativeLangDir . $language . '.' . $languageFile . '.ini'; if (file_exists($nativeLangFile)) { $nativeLang = @parse_ini_file($nativeLangFile); foreach ($strings as $string) { if (isset($nativeLang['SP.' . $string])) { $nativeStrings['SP.' . $string] = $nativeLang['SP.' . $string]; } } } } $add = null; foreach ($strings as $string) { if (isset($nativeStrings['SP.' . $string])) { $add .= "\nSP.{$string}=\"{$nativeStrings['SP.' . $string]}\""; } else { $add .= "\nSP.{$string}=\"{$default['SP.' . $string]}\""; } } $add .= "\n"; $content = SPFs::read($file->getPathname()); $add = $content . $add; SPFs::write($file->getPathname(), $add); } } }
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); } }
/** * @param $directory * @return array */ private function getAjaxFiles($directory) { $secret = md5(Sobi::Cfg('secret')); $coordinates = null; $dirNameHash = str_replace('directory://', null, $directory); if (strstr($dirNameHash, '::coordinates://')) { $struct = explode('::coordinates://', $dirNameHash); $dirNameHash = $struct[0]; $coordinates = $struct[1]; } $data = $dirNameHash; $dirName = SPLoader::dirPath("tmp.files.{$secret}.{$dirNameHash}", 'front', false); $files = scandir($dirName); return array($data, $dirName, $files, $coordinates); }
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); } }