Exemple #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;
 }
Exemple #2
0
 protected function crawlSobiSection($sid)
 {
     $done = false;
     $task = $this->cleanCache ? 'crawler.restart' : 'crawler.init';
     $connection = SPFactory::Instance('services.remote');
     while (!$done && time() - $this->start < $this->timeLimit) {
         $url = $this->liveURL . "/index.php?option=com_sobipro&task={$task}&sid={$sid}&format=raw&tmpl=component&timeLimit={$this->loopTimeLimit}&fullFormat=1";
         list($content, $response) = $this->SpConnect($connection, $url);
         $task = 'crawler';
         if ($response['http_code'] == 303) {
             preg_match('/Location: (http.*)/', $content, $newUrl);
             list($content, $response) = $this->SpConnect($connection, $newUrl[1]);
         }
         if ($response['http_code'] == 200) {
             $content = substr($content, $response['header_size']);
             $data = json_decode($content);
             $done = $data->status == 'done';
             $this->SpOut('');
             $this->SpOut('============');
             $this->SpOut("[ " . date(DATE_RFC2822) . " ] {$data->message}");
             $this->SpOut('============');
             foreach ($data->data as $row) {
                 $u = strip_tags($row->url);
                 $this->SpOut("{$u}\t{$row->count}\t{$row->code}\t{$row->time}");
             }
         } else {
             $done = true;
             $this->out('[ERROR] Invalid return code: ' . $response['http_code']);
         }
     }
 }
Exemple #3
0
 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;
 }
Exemple #4
0
 protected function getFunctionsLabel()
 {
     if (isset($this->params->interpreter)) {
         $interpreter = explode('.', $this->params->interpreter);
         $function = array_pop($interpreter);
         $obj = SPFactory::Instance(implode('.', $interpreter));
         self::$functionsLabel = $obj->{$function}(self::$sid, self::$section);
     } elseif (isset($this->params->text)) {
         if (isset($this->params->loadTextFile)) {
             SPLang::load($this->params->loadTextFile);
         }
         self::$functionsLabel = Sobi::Txt($this->params->text);
     }
 }
Exemple #5
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));
     }
 }
Exemple #6
0
 private function screen()
 {
     $view =& SPFactory::View('view', true);
     $view->setTemplate('config.help');
     if (SPLoader::path('etc.repos.sobipro_core.repository', 'front', true, 'xml')) {
         $repository = SPFactory::Instance('services.installers.repository');
         $repository->loadDefinition(SPLoader::path("etc.repos.sobipro_core.repository", 'front', true, 'xml'));
         try {
             $repository->connect();
         } catch (SPException $x) {
             $view->assign(SPLang::e('REPO_ERR', $x->getMessage()), 'message');
         }
         try {
             $response = $repository->help($repository->get('token'), SPRequest::cmd('mid'));
             $view->assign($response, 'message');
         } catch (SPException $x) {
             $view->assign(SPLang::e('REPO_ERR', $x->getMessage()), 'message');
         }
     } else {
         $view->assign(Sobi::Txt('MSG.HELP_ADD_CORE_REPO'), 'message');
     }
     $view->display();
 }
Exemple #7
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;
 }
Exemple #8
0
 protected function view()
 {
     /* determine template package */
     $tplPckg = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     Sobi::ReturnPoint();
     $this->_task = 'alpha';
     if (!$this->_model) {
         $this->setModel('section');
         $this->_model->init(Sobi::Section());
     }
     $this->visible();
     /* load template config */
     $this->template();
     $this->tplCfg($tplPckg);
     /* get limits - if defined in template config - otherwise from the section config */
     $eLimit = $this->tKey($this->template, 'entries_limit', Sobi::Cfg('list.entries_limit', 2));
     $eInLine = $this->tKey($this->template, 'entries_in_line', Sobi::Cfg('list.entries_in_line', 2));
     /* get the site to display */
     $site = SPRequest::int('site', 1);
     $eLimStart = ($site - 1) * $eLimit;
     $eCount = count($this->getEntries(0, 0, true));
     $entries = $this->getEntries($eLimit, $site);
     $compare = $this->_field ? $this->_field : $this->_nid;
     if (strlen($compare) && $compare != Sobi::Cfg('alphamenu.primary_field')) {
         $t = 'list.alpha.' . strtolower($this->_letter) . '.' . $this->_nid;
     } else {
         $t = 'list.alpha.' . strtolower($this->_letter);
     }
     $pn = SPFactory::Instance('helpers.pagenav_' . $this->tKey($this->template, 'template_type', 'xslt'), $eLimit, $eCount, $site, array('sid' => SPRequest::sid(), 'task' => $t));
     $cUrl = array('sid' => SPRequest::sid(), 'task' => $t);
     if (SPRequest::int('site', 0)) {
         $cUrl['site'] = SPRequest::int('site', 0);
     }
     SPFactory::header()->addCanonical(Sobi::Url($cUrl, true, true, true));
     /* handle meta data */
     SPFactory::header()->objMeta($this->_model);
     $letter = urldecode(SPRequest::cmd('letter'));
     /* add pathway */
     if (!$this->_fieldType) {
         SPFactory::mainframe()->addToPathway(Sobi::Txt('AL.PATH_TITLE', array('letter' => $letter)), Sobi::Url('current'));
         SPFactory::header()->addTitle(Sobi::Txt('AL.TITLE', array('letter' => $letter, 'section' => $this->_model->get('name'))), array(ceil($eCount / $eLimit), $site));
     } else {
         $field = SPFactory::Model('field');
         $field->init($this->_field);
         SPFactory::mainframe()->addToPathway(Sobi::Txt('AL.PATH_TITLE_FIELD', array('letter' => $letter, 'field' => $field->get('name'))), Sobi::Url('current'));
         SPFactory::header()->addTitle(Sobi::Txt('AL.TITLE_FIELD', array('letter' => $letter, 'section' => $this->_model->get('name'), 'field' => $field->get('name'))), array(ceil($eCount / $eLimit), $site));
     }
     /* get view class */
     $view = SPFactory::View('listing');
     $view->assign($eLimit, '$eLimit');
     $view->assign($eLimStart, '$eLimStart');
     $view->assign($eCount, '$eCount');
     $view->assign($eInLine, '$eInLine');
     $view->assign($this->_task, 'task');
     $view->assign($this->_model, 'section');
     $view->assign(Sobi::Txt('AL.PATH_TITLE', array('letter' => $this->_letter)), 'listing_name');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPckg . '.' . $this->templateType . '.' . $this->template);
     $view->assign($pn->get(), 'navigation');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($entries, 'entries');
     Sobi::Trigger('AlphaListing', 'View', array(&$view));
     $view->display();
 }
Exemple #9
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;
 }
Exemple #10
0
 protected function &createMenu($task = null)
 {
     if (!$task) {
         $task = 'config.' . $this->_task;
     }
     /* load the menu definition */
     if (Sobi::Section()) {
         /* create menu */
         $menu =& SPFactory::Instance('views.adm.menu', $task, Sobi::Section());
         $cfg = SPLoader::loadIniFile('etc.adm.section_menu');
         /* create new SigsiuTree */
         $tree = SPFactory::Instance('mlo.tree');
         /* set link */
         $tree->setHref(Sobi::Url(array('sid' => '{sid}')));
         $tree->setId('menuTree');
         /* set the task to expand the tree */
         $tree->setTask('category.expand');
         $tree->init(Sobi::Section());
         /* add the tree into the menu */
         $menu->addCustom('AMN.ENT_CAT', $tree->getTree());
         $seClass = SPLoader::loadModel('section');
         $cSec = new $seClass();
         $cSec->init(Sobi::Section());
     } else {
         $cfg = SPLoader::loadIniFile('etc.adm.config_menu');
         /* create menu */
         $menu =& SPFactory::Instance('views.adm.menu', $task);
     }
     Sobi::Trigger('Create', 'AdmMenu', array(&$cfg));
     if (count($cfg)) {
         foreach ($cfg as $section => $keys) {
             $menu->addSection($section, $keys);
         }
     }
     if (!Sobi::Section()) {
         $menu->addCustom('GB.CFG.GLOBAL_TEMPLATES', $this->listTemplates());
     }
     Sobi::Trigger('AfterCreate', 'AdmMenu', array(&$menu));
     return $menu;
 }
Exemple #11
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'))));
 }
Exemple #12
0
 protected function tree()
 {
     $selector = null;
     $selectedCategories = array();
     $tree = SPFactory::Instance('mlo.tree', Sobi::Cfg('list.categories_ordering'), array('preventParents' => !$this->catsWithChilds));
     $tree->setHref('#');
     $tree->setTask('category.chooser');
     $tree->setId($this->nid);
     $tree->disable(Sobi::Section());
     $tree->init(Sobi::Section());
     $params = array();
     $params['maxcats'] = $this->catsMaxLimit;
     $params['field'] = $this->nid;
     $params['preventParents'] = !$this->catsWithChilds;
     $setheight = '';
     if ($this->height > 0) {
         $setheight = " style=\"height: {$this->height}px;\"";
     }
     $addBtParams = array('class' => 'btn');
     $delBtParams = array('class' => 'btn');
     $selectParams = array();
     SPFactory::header()->addJsFile('opt.field_category_tree')->addJsCode('SobiPro.jQuery( document ).ready( function () { new SigsiuTreeEdit( ' . json_encode($params) . '); } );');
     $selector = $selector . '<div class="tree"' . $setheight . '>' . $tree->display(true) . '</div>';
     if (count($this->_selectedCats)) {
         $selected = SPLang::translateObject($this->_selectedCats, 'name', 'category');
         if (count($selected)) {
             $count = 0;
             foreach ($selected as $category) {
                 if ($category['id'] == $this->sid && SPRequest::task() != 'entry.add') {
                     continue;
                 }
                 $selectedCategories[$category['id']] = $category['value'];
                 $count++;
                 if ($count == $this->catsMaxLimit) {
                     break;
                 }
             }
         }
     }
     if (count($selectedCategories) >= $this->catsMaxLimit) {
         $addBtParams['disabled'] = 'disabled';
         $selectParams['readonly'] = 'readonly';
     } elseif (!count($selectedCategories)) {
         $delBtParams['disabled'] = 'disabled';
     }
     $selector .= '<div class="selected">';
     $selector .= SPHtml_Input::select($this->nid . '_list', $selectedCategories, null, true, $selectParams);
     $selector .= SPHtml_Input::hidden($this->nid, 'json://' . json_encode(array_keys($selectedCategories)));
     $selector .= '</div>';
     $selector .= '<div class="buttons">';
     $selector .= SPHtml_Input::button('addCategory', Sobi::Txt('CC.ADD_BT'), $addBtParams);
     $selector .= SPHtml_Input::button('removeCategory', Sobi::Txt('CC.DEL_BT'), $delBtParams);
     $selector .= '</div>';
     $selector = '<div class="SigsiuTree" id="' . $this->nid . '_canvas">' . $selector . '</div>';
     if ($this->modal) {
         $selector = SPHtml_Input::modalWindow(Sobi::Txt('EN.SELECT_CAT_PATH'), $this->nid . '_modal', $selector, 'modaltree modal hide', 'CLOSE', null);
         $field = SPHtml_Input::button('select-category', Sobi::Txt('EN.SELECT_CAT_PATH'), array('class' => 'btn btn-primary', 'href' => '#' . $this->nid . '_modal', 'data-toggle' => 'modal', 'id' => $this->nid . '_modal_fire'));
         return $field . $selector;
     } else {
         return $selector;
     }
 }
Exemple #13
0
 protected function view()
 {
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     Sobi::ReturnPoint();
     $this->_task = 'date';
     if (!$this->_model) {
         $this->setModel('section');
         $this->_model->init(Sobi::Section());
     }
     $this->visible();
     /* load template config */
     $this->template();
     $this->tplCfg($tplPackage);
     /* get limits - if defined in template config - otherwise from the section config */
     $eLimit = $this->tKey($this->template, 'entries_limit', Sobi::Cfg('list.entries_limit', 2));
     $eInLine = $this->tKey($this->template, 'entries_in_line', Sobi::Cfg('list.entries_in_line', 2));
     $date = explode('.', SPRequest::cmd('date'));
     $this->date['year'] = isset($date[0]) && $date[0] ? $date[0] : null;
     $this->date['month'] = isset($date[1]) && $date[1] ? $date[1] : null;
     $this->date['day'] = isset($date[2]) && $date[2] ? $date[2] : null;
     if (!$this->date['year'] || !(int) $this->date['year']) {
         throw new SPException(SPLang::e('INVALID_DATE_GIVEN'));
     }
     /* get the site to display */
     $site = SPRequest::int('site', 1);
     $eLimStart = ($site - 1) * $eLimit;
     $conditions = array('spo.oType' => 'entry', 'year(createdTime)' => $this->date['year']);
     $listing = 'year';
     if ($this->date['month'] && $this->date['month'] < 13 && $this->date['month'] > 0) {
         $conditions['month(createdTime)'] = $this->date['month'];
         $listing = 'month';
     }
     if ($this->date['day'] && $this->date['day'] < 13 && $this->date['day'] > 0) {
         $conditions['day(createdTime)'] = $this->date['day'];
         $listing = 'date';
     }
     $eOrder = 'createdTime';
     $eCount = count($this->getEntries($eOrder, 0, 0, true, $conditions, true, Sobi::Section()));
     $entries = $this->getEntries($eOrder, $eLimit, $eLimStart, true, $conditions, true, Sobi::Section());
     $url = array('sid' => SPRequest::sid(), 'task' => 'list.date', 'date' => SPRequest::cmd('date'));
     $pn = SPFactory::Instance('helpers.pagenav_' . $this->tKey($this->template, 'template_type', 'xslt'), $eLimit, $eCount, $site, $url);
     if (SPRequest::int('site', 0)) {
         $url['site'] = SPRequest::int('site', 0);
     }
     SPFactory::header()->addCanonical(Sobi::Url($url, true, true, true));
     /* handle meta data */
     SPFactory::header()->objMeta($this->_model);
     $date = $this->date;
     $monthsNames = explode(',', Sobi::Txt('JS_CALENDAR_MONTHS'));
     $date['month'] = isset($monthsNames[$date['month'] - 1]) ? trim($monthsNames[$date['month'] - 1]) : null;
     SPFactory::mainframe()->addToPathway(Sobi::Txt('DL.PATH_TITLE_' . strtoupper($listing), $date), Sobi::Url('current'));
     SPFactory::header()->addTitle(Sobi::Txt('DL.TITLE_' . strtoupper($listing), $date), array(ceil($eCount / $eLimit), $site));
     /* get view class */
     $view = SPFactory::View('listing');
     $view->assign($eLimit, '$eLimit');
     $view->assign($eLimStart, '$eLimStart');
     $view->assign($eCount, '$eCount');
     $view->assign($eInLine, '$eInLine');
     $view->assign($this->_task, 'task');
     $view->assign($this->_model, 'section');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . $this->template);
     $view->assign($pn->get(), 'navigation');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($entries, 'entries');
     Sobi::Trigger('UserListing', 'View', array(&$view));
     $view->display();
 }
Exemple #14
0
 /**
  * List all fields in this section
  */
 private function listFields()
 {
     /* @var SPdb $db */
     $ord = $this->parseOrdering('forder', 'position.asc');
     SPLoader::loadClass('html.input');
     Sobi::ReturnPoint();
     /* create menu */
     $sid = Sobi::Reg('current_section');
     $menu = SPFactory::Instance('views.adm.menu', 'field.list', $sid);
     $cfg = SPLoader::loadIniFile('etc.adm.section_menu');
     Sobi::Trigger('Create', 'AdmMenu', array(&$cfg));
     if (count($cfg)) {
         foreach ($cfg as $section => $keys) {
             $menu->addSection($section, $keys);
         }
     }
     Sobi::Trigger('AfterCreate', 'AdmMenu', array(&$menu));
     /* create new SigsiuTree */
     $tree = SPLoader::loadClass('mlo.tree');
     $tree = new $tree(Sobi::GetUserState('categories.order', 'corder', 'position.asc'));
     /* set link */
     $tree->setHref(Sobi::Url(array('sid' => '{sid}')));
     $tree->setId('menuTree');
     /* set the task to expand the tree */
     $tree->setTask('category.expand');
     $tree->init($sid);
     /* add the tree into the menu */
     $menu->addCustom('AMN.ENT_CAT', $tree->getTree());
     try {
         $results = SPFactory::db()->select('*', 'spdb_field', array('section' => $sid), $ord)->loadObjectList();
     } catch (SPException $x) {
         //			SPConfig::debOut(SPFactory::db()->getQuery());
         Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     $fields = array();
     if (count($results)) {
         foreach ($results as $result) {
             $field = SPFactory::Model('field', true);
             $field->extend($result);
             $fields[] = $field;
         }
     }
     $fieldTypes = $this->getFieldTypes();
     $subMenu = array();
     foreach ($fieldTypes as $type => $group) {
         asort($group);
         $subMenu[] = array('label' => $type, 'element' => 'nav-header');
         foreach ($group as $t => $l) {
             $subMenu[] = array('type' => null, 'task' => 'field.add.' . $t, 'label' => $l, 'icon' => 'tasks', 'element' => 'button');
         }
     }
     SPFactory::View('field', true)->addHidden($sid, 'sid')->assign($fields, 'fields')->assign($subMenu, 'fieldTypes')->assign(Sobi::Section(true), 'section')->assign($menu, 'menu')->assign(Sobi::GetUserState('fields.order', 'forder', 'position.asc'), 'ordering')->assign($this->_task, 'task')->determineTemplate('field', 'list')->display();
 }
 private function download()
 {
     //		$file = SPLoader::path( 'tmp.info', 'front', false, 'txt' );
     $cont = null;
     $settings = array();
     $settings['SobiPro'] = array('Version' => SPFactory::CmsHelper()->myVersion(true), 'Version_Num' => implode('.', SPFactory::CmsHelper()->myVersion()));
     $file = SPLoader::path('tmp.info', 'front', false, 'txt');
     //		if ( SPFs::exists( $file ) ) {
     //			$cont = SPFs::read( $file );
     //		}
     //		$cont = explode( "\n", $cont );
     //		if ( count( $cont ) ) {
     //			foreach ( $cont as $line ) {
     //				if ( strstr( $line, '=' ) ) {
     //					$line = explode( "=", $line );
     //					$line[ 1 ] = explode( ';', $line[ 1 ] );
     //					$settings[ $line[ 0 ] ] = array( 'key' => $line[ 0 ], 'response' => $line[ 1 ][ 0 ], 'status' => $line[ 1 ][ 1 ] );
     //				}
     //			}
     //		}
     $this->prepareStoredData($settings);
     $settings['env'] = array('PHP_OS' => PHP_OS, 'php_uname' => php_uname(), 'PHP_VERSION_ID' => PHP_VERSION_ID);
     $settings['ftp'] = $this->ftp();
     $settings['curl'] = $this->curlFull();
     $settings['exec']['response'] = $this->execResp();
     $settings['SOBI_SETTINGS'] = SPFactory::config()->getSettings();
     $c = SPFactory::db()->select('*', 'spdb_config')->loadObjectList();
     $sections = SPFactory::db()->select(array('nid', 'id'), 'spdb_object', array('oType' => 'section'))->loadAssocList('id');
     $as = array();
     foreach ($c as $key) {
         if ($key->section == 0 || !isset($sections[$key->section])) {
             continue;
         }
         $key->section = $sections[$key->section]['nid'];
         if (!isset($as[$key->section])) {
             $as[$key->section] = array();
         }
         if (!isset($as[$key->section][$key->cSection])) {
             $as[$key->section][$key->cSection] = array();
         }
         $_c = explode('_', $key->sKey);
         if ($_c[count($_c) - 1] == 'array') {
             $key->sValue = SPConfig::unserialize($key->sValue);
         }
         $as[$key->section][$key->cSection][$key->sKey] = $key->sValue;
     }
     $settings['SOBI_SETTINGS']['sections'] = $as;
     $apps = SPFactory::db()->select('*', 'spdb_plugins')->loadObjectList();
     foreach ($apps as $app) {
         $settings['Apps'][$app->pid] = get_object_vars($app);
     }
     $settings['SOBI_SETTINGS']['mail']['smtphost'] = $settings['SOBI_SETTINGS']['mail']['smtphost'] ? 'SET' : 0;
     $settings['SOBI_SETTINGS']['mail']['smtpuser'] = $settings['SOBI_SETTINGS']['mail']['smtpuser'] ? 'SET' : 0;
     $settings['SOBI_SETTINGS']['mail']['smtppass'] = $settings['SOBI_SETTINGS']['mail']['smtppass'] ? 'SET' : 0;
     $php = ini_get_all();
     unset($php['extension_dir']);
     unset($php['include_path']);
     unset($php['mysql.default_user']);
     unset($php['mysql.default_password']);
     unset($php['mysqli.default_pw']);
     unset($php['mysqli.default_user']);
     unset($php['open_basedir']);
     unset($php['pdo_mysql.default_socket']);
     unset($php['sendmail_path']);
     unset($php['session.name']);
     unset($php['session.save_path']);
     unset($php['soap.wsdl_cache_dir']);
     unset($php['upload_tmp_dir']);
     unset($php['doc_root']);
     unset($php['docref_ext']);
     unset($php['docref_root']);
     unset($php['mysql.default_socket']);
     $settings['PHP_SETTINGS'] = $php;
     $php = get_loaded_extensions();
     $settings['PHP_EXT'] = $php;
     $out = SPFactory::Instance('types.array');
     $data = $out->toXML($settings, 'settings');
     $data = str_replace(array(SOBI_ROOT, '></'), array('REMOVED', '>0</'), $data);
     $f = SPLang::nid($settings['SOBI_SETTINGS']['general']['site_name'] . '-' . date(DATE_RFC822));
     SPFactory::mainframe()->cleanBuffer();
     header('Cache-Control: no-cache, must-revalidate');
     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
     header("Content-type: application/xml");
     header("Content-Disposition: attachment; filename=\"sobipro_system_{$f}.xml\"");
     header('Content-Length: ' . strlen($data));
     ob_clean();
     flush();
     echo $data;
     exit;
 }
Exemple #16
0
 /**
  * @param $def
  */
 protected function checkRequirements($def)
 {
     $xp = new DOMXPath($def);
     $requirements = $xp->query('//SobiPro/requirements/*');
     if ($requirements && $requirements instanceof DOMNodeList) {
         $reqCheck =& SPFactory::Instance('services.installers.requirements');
         $reqCheck->check($requirements);
     }
 }
Exemple #17
0
 protected function xmlPagination($node, &$element)
 {
     $args = array();
     /** @var DOMElement $attribute */
     foreach ($node->attributes as $attribute) {
         $args[$attribute->nodeName] = $attribute->nodeValue;
     }
     foreach ($node->childNodes as $param) {
         if (strstr($param->nodeName, '#')) {
             continue;
         }
         $args[$param->attributes->getNamedItem('name')->nodeValue] = $this->xmlParams($param);
     }
     /** @var $pagination SPPagination */
     $pagination = SPFactory::Instance('views.adm.pagination');
     foreach ($args as $var => $val) {
         $pagination->set($var, $val);
     }
     $element['content'] = $pagination->display(true);
 }
Exemple #18
0
 private function menu()
 {
     /* create menu */
     $menu = SPFactory::Instance('views.adm.menu', 'extensions.' . $this->_task);
     $cfg = SPLoader::loadIniFile('etc.adm.config_menu');
     Sobi::Trigger('Create', 'AdmMenu', array(&$cfg));
     if (count($cfg)) {
         foreach ($cfg as $section => $keys) {
             $menu->addSection($section, $keys);
         }
     }
     $menu->addCustom('GB.CFG.GLOBAL_TEMPLATES', $this->listTemplates());
     Sobi::Trigger('AfterCreate', 'AdmMenu', array(&$menu));
     return $menu;
 }
Exemple #19
0
 public function onFieldEdit(&$view)
 {
     $dependencyDefinitions = scandir(SOBI_PATH . '/etc/fields/select-list/');
     if (count($dependencyDefinitions)) {
         $set = array();
         foreach ($dependencyDefinitions as $file) {
             if (!is_dir(SOBI_PATH . '/etc/fields/select-list/' . $file)) {
                 $set[$file] = $file;
             }
         }
         $view->assign($set, 'dependencyDefinition');
     }
     /** @var $arr SPData_Array */
     $arr = SPFactory::Instance('types.array');
     $options = array();
     $this->_parseOptions($this->options, $options);
     $options = $arr->toINIString($options);
     $view->assign($options, 'options');
 }
Exemple #20
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();
         $defLabelsArr = array();
         $optsIds = array();
         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);
                     SPFactory::message()->warning('FIELD_WARN_DUPLICATE_OPT_ID');
                 }
             }
             $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'];
         }
         /* @var SPdb $db */
         $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_DELETE_SELECTED_OPTIONS', $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_STORE_FIELD_OPTIONS_DB_ERR', $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;
         }
     }
     $attr['params'] = $properties;
     $this->sets['field.options'] = SPFactory::Instance('types.array')->toINIString($data);
 }
Exemple #21
0
 protected function reject()
 {
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     if ($this->authorise('manage')) {
         $changes = array();
         $objects = array('entry' => $this->_model, 'user' => SPFactory::user(), 'author' => SPFactory::Instance('cms.base.user', $this->_model->get('owner')));
         $messages =& SPFactory::registry()->get('messages');
         $reason = SPLang::replacePlaceHolders(SPRequest::string('reason', null, true, 'post'), $objects);
         $objects['reason'] = nl2br($reason);
         $messages['rejection'] = $objects;
         SPFactory::registry()->set('messages', $messages);
         $this->_model->setMessage($reason, 'reason');
         if (SPRequest::bool('unpublish', false, 'post')) {
             $this->_model->changeState(0, $reason, false);
             $changes[] = 'unpublish';
         }
         if (SPRequest::bool('trigger_unpublish', false, 'post')) {
             Sobi::Trigger('Entry', 'AfterChangeState', array($this->_model, 0, 'messages' => $this->_model->get('messages')));
         }
         if (SPRequest::bool('discard', false, 'post')) {
             $changes[] = 'discard';
             $data = $this->_model->discard(false);
         }
         if (SPRequest::bool('trigger_unapprove', false, 'post')) {
             Sobi::Trigger('Entry', 'AfterUnapprove', array($this->_model, 0));
         }
         Sobi::Trigger('Entry', 'AfterReject', array($this->_model, 0));
         SPFactory::message()->logAction('reject', $this->_model->get('id'), $data, $reason);
         $this->response(Sobi::Back(), Sobi::Txt('ENTRY_REJECTED', $this->_model->get('name')), true, SPC::SUCCESS_MSG);
     }
 }
 /**
  * @param $dir
  * @param $string
  * @param $exact
  * @param $recLevel
  * @param $results
  * @param $level
  * @return array
  */
 private function searchRecursive($dir, $string, $exact, $recLevel, &$results, $level = 0)
 {
     $level++;
     if ($level > $recLevel) {
         return true;
     }
     $r = $dir->searchFile($string, $exact);
     $results = array_merge($results, $r);
     foreach ($dir as $file) {
         if ($file->isDir() && !$file->isDot()) {
             $this->searchRecursive(SPFactory::Instance('base.fs.directory_iterator', $file->getPathname()), $string, $exact, $recLevel, $results, $level);
         }
     }
 }
Exemple #23
0
 protected function save($new = false)
 {
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $content = SPRequest::raw('file_content', null, 'post');
     $file = $this->file(SPRequest::cmd('fileName'), !$new);
     Sobi::Trigger('Save', $this->name(), array(&$content, &$file));
     if (!$file) {
         throw new SPException(SPLang::e('Missing  file to save %s', SPRequest::cmd('fileName')));
     }
     $File = SPFactory::Instance('base.fs.file', $file);
     $File->content(stripslashes($content));
     try {
         $File->save();
         $u = array('task' => 'template.edit', 'file' => SPRequest::cmd('fileName'));
         if (Sobi::Section()) {
             $u['sid'] = Sobi::Section();
         }
         $this->response(Sobi::Url($u), Sobi::Txt('TP.FILE_SAVED'), $new, 'success');
     } catch (SPException $x) {
         $this->response(Sobi::Back(), $x->getMessage(), false, 'error');
     }
 }
Exemple #24
0
 /**
  * @return SigsiuTree
  */
 protected function initialiseTree()
 {
     /** @var SigsiuTree $tree */
     $tree = SPFactory::Instance('mlo.tree', Sobi::GetUserState('categories.order', 'corder', 'position.asc'));
     $tree->setHref("javascript:SP_selectCat( '{sid}' )");
     $tree->setTask('category.chooser');
     return $tree;
 }
Exemple #25
0
 protected function alphaMenu(&$data)
 {
     if ($this->key('alphamenu.show', Sobi::Cfg('alphamenu.show'))) {
         $letters = explode(',', $this->key('alphamenu.letters', Sobi::Cfg('alphamenu.letters')));
         $entry = SPFactory::Model('entry');
         $entry->loadFields(Sobi::Section());
         $fs = $entry->getFields('id');
         $defField = true;
         if (count($letters)) {
             foreach ($letters as $i => $letter) {
                 $letters[$i] = trim($letter);
             }
         }
         $field = explode('.', SPRequest::task('get'));
         if (strstr(SPRequest::task('get'), 'field') && isset($field[3])) {
             $field = $field[3];
             $defField = false;
         } else {
             $field = Sobi::Cfg('alphamenu.primary_field', SPFactory::config()->nameField()->get('id'));
             if (isset($fs[$field]) && $fs[$field] instanceof SPObject) {
                 $field = $fs[$field]->get('nid');
             } else {
                 $field = $fs[SPFactory::config()->nameField()->get('id')]->get('nid');
             }
         }
         if ($this->key('alphamenu.verify', Sobi::Cfg('alphamenu.verify'))) {
             $entries = SPFactory::cache()->getVar('alpha_entries_' . $field);
             if (!$entries) {
                 $alphCtrl = SPFactory::Instance('opt.listing.alpha');
                 $entries = array();
                 foreach ($letters as $letter) {
                     $params = array('letter' => $letter);
                     if ($field) {
                         $params['field'] = $field;
                     }
                     $alphCtrl->setParams($params);
                     $entries[$letter] = $alphCtrl->entries($field);
                 }
                 SPFactory::cache()->addVar($entries, 'alpha_entries_' . $field);
             }
             foreach ($letters as $letter) {
                 $le = array('_complex' => 1, '_data' => trim($letter));
                 $urlLetter = SPFactory::Instance('types.string', $letter)->toLower()->trim()->get();
                 if (count($entries[$letter])) {
                     if (!$defField) {
                         $task = 'list.alpha.' . $urlLetter . '.' . $field;
                     } else {
                         $task = 'list.alpha.' . $urlLetter;
                     }
                     $le['_attributes'] = array('url' => Sobi::Url(array('sid' => Sobi::Section(), 'task' => $task)));
                 }
                 $l[] = $le;
             }
         } else {
             foreach ($letters as $i => $letter) {
                 $urlLetter = SPFactory::Instance('types.string', $letter)->toLower()->trim()->get();
                 $l[] = array('_complex' => 1, '_data' => trim($letter), '_attributes' => array('url' => Sobi::Url(array('sid' => Sobi::Section(), 'task' => 'list.alpha.' . $urlLetter))));
             }
         }
         $fields = Sobi::Cfg('alphamenu.extra_fields_array');
         $extraFields = array();
         if (count($fields)) {
             array_unshift($fields, Sobi::Cfg('alphamenu.primary_field'));
             foreach ($fields as $fid) {
                 if (isset($fs[$fid]) && method_exists($fs[$fid], 'get')) {
                     if ($fs[$fid]->get('enabled')) {
                         $extraFields[$fs[$fid]->get('nid')] = $fs[$fid]->get('name');
                     }
                 }
             }
             if (count($extraFields) < 2) {
                 $extraFields = array();
             }
             $extraFields = array('_complex' => 1, '_data' => $extraFields, '_attributes' => array('current' => $field));
         }
         $data['alphaMenu'] = array('_complex' => 1, '_data' => array('letters' => $l, 'fields' => $extraFields));
     }
 }
Exemple #26
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;
 }
Exemple #27
0
 protected function view()
 {
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     Sobi::ReturnPoint();
     $this->_task = 'user';
     if (!$this->_model) {
         $this->setModel('section');
         $this->_model->init(Sobi::Section());
     }
     $this->visible();
     /* load template config */
     $this->template();
     $this->tplCfg($tplPackage);
     /* get limits - if defined in template config - otherwise from the section config */
     $eLimit = $this->tKey($this->template, 'entries_limit', Sobi::Cfg('list.entries_limit', 2));
     $eInLine = $this->tKey($this->template, 'entries_in_line', Sobi::Cfg('list.entries_in_line', 2));
     $url = array('sid' => SPRequest::sid(), 'task' => 'list.user');
     if (SPRequest::int('uid')) {
         $url['uid'] = SPRequest::int('uid');
         $this->uid = (int) SPRequest::int('uid');
     } else {
         $this->uid = (int) Sobi::My('id');
     }
     $this->user = SPJoomlaUser::getBaseData((int) $this->uid);
     if (!$this->user) {
         throw new SPException(SPLang::e('UNAUTHORIZED_ACCESS'));
     }
     /* get the site to display */
     $site = SPRequest::int('site', 1);
     $eLimStart = ($site - 1) * $eLimit;
     $eOrder = $this->parseOrdering('entries', 'eorder', $this->tKey($this->template, 'entries_ordering', Sobi::Cfg('list.entries_ordering', 'name.asc')));
     $eCount = count($this->getEntries($eOrder, 0, 0, true, array('spo.owner' => $this->uid), true, Sobi::Section()));
     $entries = $this->getEntries($eOrder, $eLimit, $eLimStart, true, array('spo.owner' => $this->uid), true, Sobi::Section());
     //		$eCount = count( $this->_getEntries( 0, 0, true ) );
     //		$entries = $this->_getEntries( $eLimit, $site );
     $pn = SPFactory::Instance('helpers.pagenav_' . $this->tKey($this->template, 'template_type', 'xslt'), $eLimit, $eCount, $site, $url);
     if (SPRequest::int('site', 0)) {
         $url['site'] = SPRequest::int('site', 0);
     }
     SPFactory::header()->addCanonical(Sobi::Url($url, true, true, true));
     /* handle meta data */
     SPFactory::header()->objMeta($this->_model);
     SPFactory::mainframe()->addToPathway(Sobi::Txt('UL.PATH_TITLE', array('username' => $this->user->username, 'user' => $this->user->name)), Sobi::Url('current'));
     SPFactory::header()->addTitle(Sobi::Txt('UL.TITLE', array('username' => $this->user->username, 'user' => $this->user->name, 'section' => $this->_model->get('name'))), array(ceil($eCount / $eLimit), $site));
     /* add pathway */
     /* get view class */
     $view = SPFactory::View('listing');
     $view->assign($eLimit, '$eLimit');
     $view->assign($eLimStart, '$eLimStart');
     $view->assign($eCount, '$eCount');
     $view->assign($eInLine, '$eInLine');
     $view->assign($this->_task, 'task');
     $view->assign($this->_model, 'section');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . $this->template);
     $view->assign($pn->get(), 'navigation');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($entries, 'entries');
     Sobi::Trigger('UserListing', 'View', array(&$view));
     $view->display();
 }
Exemple #28
0
 protected function getResponse($url)
 {
     $request = str_replace('amp;', null, $url);
     //		$request = parse_url( $url );
     //		$request[ 'query' ] =  urlencode( $request[ 'query' ] );
     //		$request = $request[ 'scheme' ].'://'.$request[ 'host' ].$request[ 'path' ].'?'.$request[ 'query' ];
     if (!strstr($request, '?')) {
         $request .= '?';
     } else {
         $request .= '&';
     }
     $request .= $this->format;
     /** @var $connection SPRemote */
     $connection = SPFactory::Instance('services.remote');
     $connection->setOptions(array('url' => $request, 'connecttimeout' => 10, 'returntransfer' => true, 'useragent' => self::USER_AGENT, 'header' => true, 'verbose' => true));
     $content = $connection->exec();
     $response = $connection->info();
     $urls = array();
     if ($response['http_code'] == 200) {
         $urls = $this->parseResponse($content);
         if (!is_array($urls) && is_numeric($urls)) {
             $response['http_code'] = $urls;
         }
     }
     if ($response['http_code'] == 303) {
         preg_match('/Location: (http.*)/', $content, $newUrl);
         $urls[] = str_replace(array('?' . $this->format, '&' . $this->format), null, trim($newUrl[1]));
     }
     if (count($urls)) {
         $this->insertUrls($urls);
     }
     $this->removeUrl($url);
     return array('url' => "<a href=\"{$url}\" target=\"_blank\">{$url}</a>", 'count' => count($urls), 'code' => $response['http_code'], 'time' => $response['total_time']);
 }
Exemple #29
0
 public function connect()
 {
     if ($this->definition instanceof DOMDocument && $this->xGetString('url')) {
         $connection = SPFactory::Instance('services.remote');
         $ssl = $connection->certificate($this->xGetString('url'));
         if (isset($ssl['err'])) {
             throw new SPException($ssl['msg']);
         }
         if ($ssl['serialNumber'] != $this->xGetString('certificate/serialnumber')) {
             throw new SPException(SPLang::e('SSL validation error: stored serial number is %s but the serial number for the repository at %s has the number %s.', $this->xGetString('certificate/serialnumber'), $this->xGetString('url'), $ssl['serialNumber']));
         }
         // for some reason on some servers the hash is being indeed modified
         // although it has been correctly transferred
         // it seems that it is depend on the protocol used (TSL/SSL)
         //			if ( $ssl[ 'hash' ] != $this->xGetString( 'certificate/hash' ) ) {
         //				throw new SPException(
         //					SPLang::e(
         //						'SSL validation error: stored hash does not accords the hash for the repository at %s. %s != %s',
         //						$this->xGetString( 'url' ), $ssl[ 'hash' ], $this->xGetString( 'certificate/hash' )
         //					)
         //				);
         //			}
         if ($ssl['validTo'] < time()) {
             throw new SPException(SPLang::e('SSL validation error: SSL certificate for %s is expired.', $this->xGetString('url')));
         }
         $this->_server = SPFactory::Instance('services.soap', null, array('location' => $this->xGetString('url')));
     } else {
         throw new SPException(SPLang::e('No repository definition file at %s or the definition is invalid.', $this->xmlFile));
     }
 }
Exemple #30
0
 /**
  * @param DOMNodeList $fields
  * @param int $sid
  * @return array
  */
 private function fields($fields, $sid)
 {
     $c = 0;
     $fids = array();
     foreach ($fields as $field) {
         if ($field->nodeName == 'field') {
             $c++;
             $attr = array();
             $attr['adminField'] = false;
             $attr['editLimit'] = -1;
             $ftype = $this->txt($field, 'type');
             $options = $field->getElementsByTagName('option');
             if ($options instanceof DOMNodeList && $options->length) {
                 foreach ($options as $option) {
                     $v = $option->nodeValue;
                     if (in_array($option->nodeValue, array('true', 'false'))) {
                         $v = $option->nodeValue == 'true' ? true : false;
                     }
                     $attr[$option->getAttribute('attribute')] = $v;
                 }
             }
             /** @var $options DOMNodeList */
             $options = $field->getElementsByTagName('value');
             // handles std options in select/checkbox group etc
             $addOptions = array();
             if ($options instanceof DOMNodeList && $options->length && $options->item(0)->parentNode->getAttribute('attribute') == 'fieldOptions') {
                 $values = array();
                 foreach ($options as $option) {
                     $id = strlen($option->getAttribute('name')) ? $option->getAttribute('name') : 0;
                     if (strlen($option->getAttribute('group')) && $option->getAttribute('group') != 'root') {
                         if (!isset($values[$option->getAttribute('group')])) {
                             $values[$option->getAttribute('group')] = array('gid' => $option->getAttribute('group'), 'name' => $option->getAttribute('group'));
                         }
                         $values[$option->getAttribute('group')][] = array('id' => $id, 'name' => $option->nodeValue);
                     } elseif ($id) {
                         $values[] = array('id' => $id, 'name' => $option->nodeValue);
                     } else {
                         $addOptions[$option->parentNode->getAttribute('attribute')][] = $option->nodeValue;
                     }
                 }
                 if (count($addOptions)) {
                     foreach ($addOptions as $name => $options) {
                         $values[$name] = $options;
                     }
                 }
                 /* we need the exact array format as the field expects, so we have to have numeric index */
                 if (count($values)) {
                     foreach ($values as $v) {
                         $attr['options'][] = $v;
                     }
                 }
             } elseif ($options instanceof DOMNodeList && $options->length) {
                 foreach ($options as $option) {
                     if (strlen($option->getAttribute('name'))) {
                         $attr[$option->parentNode->getAttribute('attribute')][$option->getAttribute('name')] = $option->nodeValue;
                     } else {
                         $attr[$option->parentNode->getAttribute('attribute')][] = $option->nodeValue;
                     }
                 }
             }
             $attr['nid'] = $this->txt($field, 'name');
             $attr['name'] = $this->txt($field, 'label');
             $attr['required'] = $this->txt($field, 'required') == 'true' ? true : false;
             $attr['showIn'] = $this->txt($field, 'showIn');
             $attr['type'] = $ftype;
             $attr['section'] = $sid;
             $attr['position'] = isset($attr['position']) ? $attr['position'] : $c;
             $attr['enabled'] = isset($attr['enabled']) ? $attr['enabled'] : true;
             $attr['editable'] = isset($attr['editable']) ? $attr['editable'] : true;
             /* let's create the field */
             $f =& SPFactory::Instance('models.adm.field');
             $f->saveNew($attr);
             $f->loadType($ftype);
             $f->save($attr);
             $fids[$attr['nid']] = $f->get('id');
         }
     }
     return $fids;
 }