예제 #1
0
 public function __construct()
 {
     $this->_db =& SPFactory::db();
     parent::__construct();
     /** because we have always the same URL - disable Joomla! cache */
     SPFactory::cache()->setJoomlaCaching(false);
 }
예제 #2
0
 public function execute()
 {
     SPLang::load('com_sobipro.check');
     $task = $this->_task = strlen($this->_task) ? $this->_task : $this->_defTask;
     // this is need to delete all old cache after installation
     if (SPRequest::int('init')) {
         SPFactory::cache()->cleanAll();
     }
     switch ($this->_task) {
         case 'view':
             $this->view();
             break;
         case 'download':
             $this->download();
             break;
         default:
             if (method_exists($this, $this->_task)) {
                 SPFactory::mainframe()->cleanBuffer()->customHeader();
                 $this->{$task}();
                 exit;
             } else {
                 Sobi::Error('requirements', 'Task not found', SPC::WARNING, 404, __LINE__, __FILE__);
                 exit;
             }
             break;
     }
 }
예제 #3
0
파일: crawler.php 프로젝트: pelloq1/SobiPro
 public function execute()
 {
     $this->start = microtime(true);
     $sites = $this->getSites();
     $responses = array();
     $status = 'working';
     $message = null;
     $this->format = SPRequest::bool('fullFormat') ? self::FORMAT_FULL : self::FORMAT;
     //		$this->format = SPRequest::bool( 'fullFormat' ) ? self::FORMAT_FULL : self::FORMAT_FULL;
     $task = SPRequest::task();
     if (in_array($task, array('crawler.init', 'crawler.restart'))) {
         if ($task == 'crawler.restart') {
             SPFactory::cache()->cleanSection(Sobi::Section());
         }
         SPFactory::db()->truncate(self::DB_TABLE);
         $multiLang = Sobi::Cfg('lang.multimode', false);
         if ($multiLang) {
             $langs = SPFactory::CmsHelper()->getLanguages();
             if ($multiLang && $langs) {
                 foreach ($langs as $lang) {
                     $responses[] = $this->getResponse(Sobi::Cfg('live_site') . 'index.php?option=com_sobipro&sid=' . Sobi::Section() . '&lang=' . $lang);
                 }
             }
         }
         $responses[] = $this->getResponse(Sobi::Cfg('live_site') . 'index.php?option=com_sobipro&sid=' . Sobi::Section());
         $sites = $this->getSites();
     }
     if (!count($sites) && !in_array($task, array('crawler.init', 'crawler.restart'))) {
         $message = Sobi::Txt('CRAWL_URL_PARSED_DONE', SPFactory::db()->select('count(*)', self::DB_TABLE)->loadResult());
         SPFactory::db()->truncate(self::DB_TABLE);
         $this->response(array('status' => 'done', 'data' => array(), 'message' => $message));
     }
     if (count($sites)) {
         $i = 0;
         $timeLimit = SPRequest::int('timeLimit', self::TIME_LIMIT, 'get', true);
         foreach ($sites as $site) {
             if (!strlen($site)) {
                 continue;
             }
             $responses[] = $this->getResponse($site);
             $i++;
             if (microtime(true) - $this->start > $timeLimit) {
                 break;
             }
         }
         $message = Sobi::Txt('CRAWL_URL_PARSED_WORKING', $i, count($sites));
     }
     $this->response(array('status' => $status, 'data' => $responses, 'message' => $message));
 }
예제 #4
0
 /**
  * (non-PHPdoc)
  * @see Site/lib/models/SPDBObject#delete()
  * @param bool $childs - update child entries parent
  */
 public function delete($childs = true)
 {
     parent::delete();
     SPFactory::cache()->cleanSection();
     SPFactory::cache()->deleteObj('category', $this->id);
     try {
         /* get all child cats and delete these too */
         $childs = $this->getChilds('category', true);
         if (count($childs)) {
             foreach ($childs as $child) {
                 $cat = new self();
                 $cat->init($child);
                 $cat->delete(false);
             }
         }
         $childs[$this->id] = $this->id;
         SPFactory::db()->delete('spdb_category', array('id' => $this->id));
         if ($childs) {
             SPFactory::db()->update('spdb_object', array('parent' => Sobi::Section()), array('parent' => $childs));
         }
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_DELETE_CATEGORY_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
 }
예제 #5
0
 /**
  * @param string $type
  * @param bool $recursive
  * @param int $state
  * @param bool $name
  * @return array
  */
 public function getChilds($type = 'entry', $recursive = false, $state = 0, $name = false)
 {
     static $lang = null;
     if (!$lang) {
         $lang = Sobi::Lang(false);
     }
     $childs = SPFactory::cache()->getVar('childs_' . $lang . $type . ($recursive ? '_recursive' : '') . ($name ? '_full' : '') . $state, $this->id);
     if ($childs) {
         return $childs == SPC::NO_VALUE ? array() : $childs;
     }
     $db = SPFactory::db();
     $childs = array();
     try {
         $cond = array('pid' => $this->id);
         if ($state) {
             $cond['so.state'] = $state;
             $cond['so.approved'] = $state;
             $tables = $db->join(array(array('table' => 'spdb_object', 'as' => 'so', 'key' => 'id'), array('table' => 'spdb_relations', 'as' => 'sr', 'key' => 'id')));
             $db->select(array('sr.id', 'sr.oType'), $tables, $cond);
         } else {
             $db->select(array('id', 'oType'), 'spdb_relations', $cond);
         }
         $results = $db->loadAssocList('id');
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_GET_CHILDS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     if ($recursive && count($results)) {
         foreach ($results as $cid) {
             $this->rGetChilds($results, $cid, $type);
         }
     }
     if (count($results)) {
         if ($type == 'all') {
             foreach ($results as $id => $r) {
                 $childs[$id] = $r['id'];
             }
         } else {
             foreach ($results as $id => $r) {
                 if ($r['oType'] == $type) {
                     $childs[$id] = $id;
                 }
             }
         }
     }
     if ($name && count($childs)) {
         $names = SPLang::translateObject($childs, array('name', 'alias'), $type);
         if (is_array($names) && !empty($names)) {
             foreach ($childs as $i => $id) {
                 $childs[$i] = array('name' => $names[$id]['value'], 'alias' => $names[$id]['alias']);
             }
         }
     }
     if (!$state) {
         SPFactory::cache()->addVar($childs, 'childs_' . $lang . $type . ($recursive ? '_recursive' : '') . ($name ? '_full' : '') . $state, $this->id);
     }
     return $childs;
 }
예제 #6
0
 /**
  * Adds object to the pathway
  * @param SPDBObject $obj
  * @param array $site
  * @return void
  */
 public function &addObjToPathway($obj, $site = array())
 {
     if (defined('SOBI_ADM_PATH')) {
         return true;
     }
     $menu = JSite::getMenu()->getActive()->query;
     $sid = isset($menu['sid']) ? $menu['sid'] : 0;
     $resetPathway = false;
     if ($obj->get('oType') == 'entry') {
         $id = SPRequest::int('pid');
         /** if the entry isn't linked directly in the menu */
         if (!($obj->get('id') == $sid)) {
             /* if we didn't entered this entry via category */
             if (!$id || $id == Sobi::Section() || Sobi::Cfg('entry.primary_path_always')) {
                 $id = $obj->get('parent');
                 $resetPathway = true;
             }
         } else {
             /** ok - here is the weird thing:
              * When it is accessed via menu we have to force cache to create another version
              * because the pathway is stored in the cache
              * @todo find better solution for it
              */
             $mid = true;
             SPFactory::registry()->set('cache_view_recreate_request', $mid)->set('cache_view_add_itemid', JSite::getMenu()->getActive()->id);
             return $this;
         }
     } else {
         $id = $obj->get('id');
     }
     $path = SPFactory::cache()->getVar('parent_path', $id);
     if (!$path) {
         $path = SPFactory::config()->getParentPath($id, true, false, true);
         SPFactory::cache()->addVar($path, 'parent_path', $id);
     }
     if (count($path)) {
         /* skip everything above the linked sid */
         $rpath = array_reverse($path);
         $path = array();
         foreach ($rpath as $part) {
             if ($part['id'] == $sid) {
                 break;
             }
             $path[] = $part;
         }
         $path = array_reverse($path);
         /* ^^ skip everything above the linked sid */
     }
     $title = array();
     // if there was an active menu - add its title to the browser title as well
     if ($sid) {
         $title[] = JFactory::getDocument()->getTitle();
     }
     /**
      * Mon, Jul 16, 2012
      * I would relay like to know why I've added the "htmlentities" call here.
      * The second param of the 'addItem' method is URL so there should be definitely no such thing
      * Related to Bug #692
      */
     if (count($path)) {
         if ($resetPathway) {
             /** we have to reset the J! pathway in case:
              *  - we are entering an entry and we want to show the pathway corresponding to the main parent if of the entry
              *    but we have also an Itemid and Joomla! set already the pathway partialy so we need to override it
              *    It wouldn't be normally a problem but when SEF is enabled we do not have the pid so we don't know how it has been enetered
              */
             JFactory::getApplication()->getPathway()->setPathway(array());
         }
         foreach ($path as $data) {
             if (!(isset($data['name']) || isset($data['id'])) || !$data['id']) {
                 continue;
             }
             $title[] = $data['name'];
             $this->addToPathway($data['name'], self::url(array('title' => Sobi::Cfg('sef.alias', true) ? $data['alias'] : $data['name'], 'sid' => $data['id'])));
         }
     }
     if ($obj->get('oType') == 'entry') {
         $this->addToPathway($obj->get('name'), self::url(array('task' => 'entry.details', 'title' => Sobi::Cfg('sef.alias', true) ? $obj->get('nid') : $obj->get('name'), 'sid' => $obj->get('id'))));
         $title[] = $obj->get('name');
     }
     //		if ( count( $site ) && $site[ 0 ] ) {
     //			$title[ ] = Sobi::Txt( 'SITES_COUNTER', $site[ 1 ], $site[ 0 ] );
     //		}
     SPFactory::header()->addTitle($title, $site);
     return $this;
 }
예제 #7
0
파일: front.php 프로젝트: pelloq1/SobiPro
 protected function getState()
 {
     $state = SPFactory::cache()->getVar('system_state');
     if (!$state) {
         SPLang::load('com_sobipro.messages');
         $state = array();
         $state['accelerator'] = array('type' => Sobi::Cfg('cache.l3_enabled', true) ? 'success' : 'error', 'label' => Sobi::Cfg('cache.l3_enabled', true) ? Sobi::Txt('ACCELERATOR_ENABLED') : Sobi::Txt('ACCELERATOR_DISABLED'));
         $state['xml-optimiser'] = array('type' => Sobi::Cfg('cache.xml_enabled', true) ? 'success' : 'error', 'label' => Sobi::Cfg('cache.xml_enabled', true) ? Sobi::Txt('XML_CACHE_ENABLED') : Sobi::Txt('XML_CACHE_DISABLED'));
         $state['javascript-cache'] = array('type' => Sobi::Cfg('cache.include_js_files', false) ? 'success' : 'warning', 'label' => Sobi::Cfg('cache.include_js_files', false) ? Sobi::Txt('JS_CACHE_ENABLED') : Sobi::Txt('JS_CACHE_DISABLED'));
         $state['css-cache'] = array('type' => Sobi::Cfg('cache.include_css_files', false) ? 'success' : 'warning', 'label' => Sobi::Cfg('cache.include_css_files', false) ? Sobi::Txt('CSS_CACHE_ENABLED') : Sobi::Txt('CSS_CACHE_DISABLED'));
         $state['display-errors'] = array('type' => Sobi::Cfg('debug.display_errors', false) ? 'error' : 'success', 'label' => Sobi::Cfg('debug.display_errors', false) ? Sobi::Txt('DISPLAY_ERRORS_ENABLED') : Sobi::Txt('DISPLAY_ERRORS_DISABLED'));
         $state['debug-level'] = array('type' => Sobi::Cfg('debug.level', 0) > 2 ? 'warning' : 'success', 'label' => Sobi::Cfg('debug.level', 0) > 2 ? Sobi::Txt('DEBUG_LEVEL_TOO_HIGH') : Sobi::Txt('DEBUG_LEVEL_OK'));
         $state['debug-xml'] = array('type' => Sobi::Cfg('debug.xml_raw', false) ? 'error' : 'success', 'label' => Sobi::Cfg('debug.xml_raw', false) ? Sobi::Txt('DEBUG_XML_ENABLED') : Sobi::Txt('DEBUG_XML_DISABLED'));
         //			uasort( $state, array( $this, 'sortMessages' ) );
         $messages = SPFactory::message()->getSystemMessages();
         $content = null;
         if (count($messages)) {
             foreach ($messages as $message) {
                 $url = Sobi::Url(array('sid' => $message['section']['id']));
                 $url = "<a href=\"{$url}\">{$message['section']['name']}</a> ";
                 $message['section']['link'] = $url;
                 $message['type-text'] = ucfirst(Sobi::Txt($message['type']));
                 $state['messages'][] = $message;
             }
         }
         SPFactory::cache()->addVar($state, 'system_state');
     }
     return $state;
 }
예제 #8
0
 private function switchIndex($field)
 {
     $tplPckg = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     $letters = explode(',', Sobi::Cfg('alphamenu.letters'));
     if (Sobi::Cfg('alphamenu.verify')) {
         $entries = SPFactory::cache()->getVar('alpha_entries_' . $field);
         if (!$entries) {
             $entries = array();
             foreach ($letters as $letter) {
                 $params = array('letter' => $letter);
                 if ($field) {
                     $params['field'] = $field;
                 }
                 $this->setParams($params);
                 $entries[$letter] = $this->entries($field);
             }
             SPFactory::cache()->addVar($entries, 'alpha_entries_' . $field);
         }
         foreach ($letters as $letter) {
             $le = array('_complex' => 1, '_data' => trim($letter));
             if (count($entries[$letter])) {
                 $task = 'list.alpha.' . trim(strtolower($letter)) . '.' . $field;
                 $le['_attributes'] = array('url' => Sobi::Url(array('sid' => Sobi::Section(), 'task' => $task)));
             }
             $l[] = $le;
         }
     } else {
         foreach ($letters as $letter) {
             $task = 'list.alpha.' . trim(strtolower($letter)) . '.' . $field;
             $l[] = array('_complex' => 1, '_data' => trim($letter), '_attributes' => array('url' => Sobi::Url(array('sid' => Sobi::Section(), 'task' => $task))));
         }
     }
     $data = array('_complex' => 1, '_data' => array('letters' => $l));
     /* get view class */
     $view = SPFactory::View('listing');
     $view->setTemplate($tplPckg . '.common.alphaindex');
     $view->assign($data, 'alphaMenu');
     ob_start();
     $view->display('menu', 'raw');
     $out = ob_get_contents();
     SPFactory::mainframe()->cleanBuffer()->customHeader();
     echo json_encode(array('index' => $out));
     exit;
 }
예제 #9
0
 /**
  * Save the config
  */
 protected function save($apply, $clone = false)
 {
     $sid = Sobi::Section();
     $this->authorise($sid);
     if ($sid) {
         $this->validate('config.general', array('task' => 'config.general', 'sid' => $sid));
     } else {
         $this->validate('config.global', array('task' => 'config.global'));
     }
     $fields = array();
     $section = false;
     $data = SPRequest::arr('spcfg', array());
     // strange thing =8-O
     if (!isset($data['alphamenu.extra_fields_array'])) {
         $data['alphamenu.extra_fields_array'] = array();
     }
     if (!isset($data['template.icon_fonts_arr'])) {
         $data['template.icon_fonts_arr'] = array();
     }
     foreach ($data as $k => $v) {
         if (is_string($v)) {
             $v = htmlspecialchars_decode($v);
         }
         //			$k = str_replace( array( 'spcfg_', '.' ), array( null, '_' ), $k );
         $k = str_replace('spcfg_', null, $k);
         $s = explode('.', $k);
         $s = $s[0];
         if (!isset($fields[$s])) {
             $fields[$s] = array();
         }
         $k = str_replace("{$s}.", null, $k);
         $c = explode('_', $k);
         if ($c[count($c) - 1] == 'array' && !is_array($v)) {
             if (!strstr($v, '|')) {
                 $v = explode(',', $v);
             } else {
                 $v = explode('|', $v);
             }
         }
         $fields[$s][$k] = $v;
         if (preg_match('/^section.*/', $k)) {
             $section = true;
         }
     }
     $values = array();
     if (count($fields)) {
         foreach ($fields as $sec => $keys) {
             if (count($keys)) {
                 foreach ($keys as $k => $v) {
                     $values[] = array('sKey' => $k, 'sValue' => $v, 'section' => Sobi::Section(), 'critical' => 0, 'cSection' => $sec);
                 }
             }
         }
     }
     if ($section) {
         /* @var $sec SPSection */
         $sec = SPFactory::Model('section');
         $sec->init(SPRequest::sid());
         $sec->getRequest('section');
         $sec->save(true);
     }
     Sobi::Trigger('SaveConfig', $this->name(), array(&$values));
     try {
         SPFactory::db()->insertArray('spdb_config', $values, true);
     } catch (SPException $x) {
         $this->response(Sobi::Back(), $x->getMessage(), false, SPC::ERROR_MSG);
     }
     if (!($section && !Sobi::Section())) {
         SPFactory::cache()->cleanAll();
     } else {
         SPFactory::cache()->cleanSection();
     }
     Sobi::Trigger('After', 'SaveConfig', array(&$values));
     $this->response(Sobi::Back(), Sobi::Txt('MSG.CONFIG_SAVED'), false, 'success');
 }
예제 #10
0
 /**
  * @param string $out - output type
  * @param array $functions - array with PHP function to register
  * @throws SPException
  * @return mixed|string
  */
 public function display($out = 'html', $functions = array())
 {
     $class = SPLoader::loadClass('helpers.template');
     $methods = get_class_methods($class);
     if (count($methods)) {
         foreach ($methods as $method) {
             $functions[] = $class . '::' . $method;
         }
     }
     /* standard function registered via the core ini file */
     $stdFunctions = SPLoader::loadIniFile('etc.template_functions');
     if (count($stdFunctions)) {
         foreach ($stdFunctions as $class => $fns) {
             if (strstr($class, '.')) {
                 $class = SPLoader::loadClass($class, false, 'sp-root');
             }
             if (count($fns)) {
                 foreach ($fns as $method => $state) {
                     if ($state) {
                         $functions[] = $class == 'functions' ? $method : $class . '::' . $method;
                     }
                 }
             }
         }
     }
     Sobi::Trigger('TemplateEngine', 'RegisterFunctions', array(&$functions));
     $this->createXML();
     if (SPRequest::cmd('xml') && Sobi::Cfg('debug.xml_raw', false) && (!Sobi::Cfg('debug.xml_ip', null) || Sobi::Cfg('debug.xml_ip') == SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'))) {
         SPFactory::mainframe()->cleanBuffer();
         echo $this->_xml->saveXML();
         exit;
     } elseif (SPRequest::cmd('xml')) {
         Sobi::Error('Debug', 'You have no permission to access this site', SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $template = SPLoader::loadTemplate($this->_tpl, 'xsl');
     if (!$template) {
         $template = SPLoader::loadTemplate($this->_tpl, 'xslt');
     }
     if (Sobi::Cfg('cache.xml_enabled')) {
         SPFactory::cache()->addView($this->_xml, $template, $this->_cacheData);
     }
     if ($template) {
         try {
             if (!($style = DOMDocument::load($template))) {
                 Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template), SPC::ERROR, 500, __LINE__, __FILE__);
             }
         } catch (DOMException $x) {
             Sobi::Error('template', SPLang::e('CANNOT_LOAD_TEMPLATE_FILE', $template, $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         Sobi::Trigger('TemplateEngine', 'LoadStyle', array(&$style));
         $processor = new XSLTProcessor();
         $processor->setParameter('block', 'xmlns', 'http://www.w3.org/1999/xhtml');
         $processor->registerPHPFunctions($functions);
         SPException::catchErrors(SPC::WARNING);
         try {
             $processor->importStylesheet($style);
         } catch (SPException $x) {
             Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template) . $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         SPException::catchErrors(0);
         if ($out == 'html') {
             $doc = $processor->transformToDoc($this->_xml);
             $doc->formatOutput = true;
             return $this->cleanOut($doc->saveXML());
         } else {
             $doc = $processor->transformToDoc($this->_xml);
             $doc->formatOutput = true;
             return $doc->saveXML();
         }
     } else {
         throw new SPException(SPLang::e('CANNOT_LOAD_TEMPLATE_FILE_AT', SPLoader::loadTemplate($this->_tpl, 'xsl', false)));
     }
 }
예제 #11
0
 /**
  * Returns linked lists ( names or ids ) of parent elements to the given id
  *
  * @param int $id - the id of object
  * @param bool $names - names or ids only
  * @param bool $parents
  * @param bool $join
  * @return array
  */
 public function getParentPath($id, $names = false, $parents = false, $join = false)
 {
     $db = SPFactory::db();
     if (!is_numeric($id)) {
         return false;
     }
     $ident = 'relations_path' . ($names ? '_names' : '') . ($parents ? '_parents' : '') . ($join ? '_join' : '');
     $cached = SPFactory::cache()->getVar($ident, $id);
     if ($cached) {
         return $cached;
     } else {
         $cid = $id;
     }
     $path = $parents ? array() : array($id);
     while ($id > 0) {
         try {
             // it doesn't make sense but it happened because of a bug in the SigsiuTree category selector
             $id = $db->select('pid', 'spdb_relations', array('id' => $id, '!pid' => $id))->loadResult();
             if ($id) {
                 $path[] = (int) $id;
             }
         } catch (SPException $x) {
             Sobi::Error(__FUNCTION__, SPLang::e('CANNOT_GET_PARENT_ID', $x->getMessage()), SPC::WARNING, 500, __LINE__, __CLASS__);
         }
     }
     if ($names && count($path)) {
         $names = SPLang::translateObject($path, array('name', 'alias'), array('section', 'category', 'entry'));
         if (is_array($names) && !empty($names)) {
             foreach ($path as $i => $id) {
                 if ($join) {
                     $path[$i] = array('id' => $id, 'name' => $names[$id]['value'], 'alias' => $names[$id]['alias']);
                 } else {
                     $path[$i] = $names[$id]['value'];
                 }
             }
         }
     }
     $path = array_reverse($path);
     SPFactory::cache()->addVar($path, $ident, $cid);
     return $path;
 }
예제 #12
0
파일: entry.php 프로젝트: pelloq1/SobiPro
 /**
  * Details view
  * @return void
  */
 private function details()
 {
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     /* load template config */
     $this->template();
     $this->tplCfg($tplPackage);
     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;
     }
     /* add pathway */
     SPFactory::mainframe()->addObjToPathway($this->_model);
     $this->_model->countVisit();
     $this->_model->loadFields(Sobi::Reg('current_section'));
     $class = SPLoader::loadView('entry');
     $view = new $class($this->template);
     $view->assign($this->_model, 'entry');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($this->_task, 'task');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . $this->template);
     Sobi::Trigger($this->name(), __FUNCTION__, array(&$view));
     SPFactory::header()->objMeta($this->_model);
     $view->display();
     SPFactory::cache()->addObj($this->_model, 'entry', $this->_model->get('id'));
 }
예제 #13
0
 /**
  * Route task
  */
 public function execute()
 {
     /* parent class executes the plugins */
     $r = false;
     $task = $this->_task;
     if (strstr($this->_task, '.')) {
         $task = explode('.', $this->_task);
         $this->_fieldType = $task[1];
         $task = $task[0];
     }
     switch ($task) {
         case 'list':
             $r = true;
             $this->listFields();
             break;
         case 'add':
         case 'edit':
             $r = true;
             $this->edit();
             break;
         case 'cancel':
             $r = true;
             $this->checkIn();
             $this->response(Sobi::Back());
             break;
         case 'addNew':
             $r = true;
             Sobi::Redirect(Sobi::Url(array('task' => 'field.edit', 'fid' => $this->saveNew(), 'sid' => SPRequest::sid())));
             break;
         case 'apply':
         case 'save':
             $r = true;
             $this->save();
             break;
         case 'clone':
             $r = true;
             $this->save(true);
             break;
         case 'delete':
             $r = true;
             SPFactory::cache()->cleanSection();
             $this->response(Sobi::Url(array('task' => 'field.list', 'pid' => Sobi::Section())), $this->delete(), true);
             break;
         case 'reorder':
             $r = true;
             $this->reorder();
             break;
         case 'revisions':
             $r = true;
             $this->revisions();
             break;
         case 'up':
         case 'down':
             $r = true;
             $this->singleReorder($this->_task == 'up');
             break;
         case 'hide':
         case 'publish':
         case 'setRequired':
         case 'setNotRequired':
         case 'setEditable':
         case 'setNotEditable':
         case 'setFee':
         case 'setFree':
         case 'toggle':
             $r = true;
             $this->authorise($this->_task);
             SPFactory::cache()->cleanSection();
             $this->response(Sobi::Back(), $this->changeState($task), true);
             break;
         default:
             /* case plugin didn't registered this task, it was an error */
             if (!Sobi::Trigger('Execute', $this->name(), array(&$this))) {
                 $fid = SPRequest::int('fid');
                 $method = $this->_task;
                 if ($fid) {
                     SPLoader::loadModel('field', true);
                     $fdata = $this->loadField($fid);
                     $field = new SPAdmField();
                     $field->extend($fdata);
                     try {
                         $field->{$method}();
                     } catch (SPException $x) {
                         Sobi::Error($this->name(), SPLang::e('SUCH_TASK_NOT_FOUND', SPRequest::task()), SPC::NOTICE, 404, __LINE__, __FILE__);
                     }
                 } elseif (!parent::execute()) {
                     Sobi::Error($this->name(), SPLang::e('SUCH_TASK_NOT_FOUND', SPRequest::task()), SPC::NOTICE, 404, __LINE__, __FILE__);
                 }
             }
             break;
     }
     return $r;
 }
예제 #14
0
 protected function loadCategories()
 {
     if (!$this->_cats || !count($this->_cats)) {
         $this->_cats = SPFactory::cache()->getVar('categories_tree', Sobi::Section());
         if (!$this->_cats || !count($this->_cats)) {
             $this->travelCats(Sobi::Section(), $this->_cats, true);
             SPFactory::cache()->addVar($this->_cats, 'categories_tree', Sobi::Section());
         }
     }
 }
예제 #15
0
 /**
  */
 private function approval($approve)
 {
     $sids = SPRequest::arr('c_sid', array());
     if (!count($sids)) {
         if ($this->_model->get('id')) {
             $sids = array($this->_model->get('id'));
         } else {
             $sids = array();
         }
     }
     if (!count($sids)) {
         $this->response(Sobi::Back(), Sobi::Txt('CHANGE_NO_ID'), false, SPC::ERROR_MSG);
     } else {
         foreach ($sids as $sid) {
             try {
                 SPFactory::db()->update('spdb_object', array('approved' => $approve ? 1 : 0), array('id' => $sid, 'oType' => 'category'));
                 SPFactory::cache()->deleteObj('category', $sid);
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
             }
         }
         SPFactory::cache()->purgeSectionVars();
         $this->response(Sobi::Back(), Sobi::Txt($approve ? 'CAT.APPROVED' : 'CAT.UNAPPROVED'), false);
     }
 }
예제 #16
0
 /**
  * Send the header via the mainframe interface
  */
 public function sendHeader()
 {
     if (count($this->_store)) {
         if (count($this->js)) {
             $jsCode = null;
             foreach ($this->js as $js) {
                 $jsCode .= "\n\t" . str_replace("\n", "\n\t", $js);
             }
             $this->js = array("\n<script type=\"text/javascript\">\n/*<![CDATA[*/{$jsCode}\n/*]]>*/\n</script>\n");
         }
         if (count($this->css)) {
             $cssCode = null;
             foreach ($this->css as $css) {
                 $cssCode .= "\n\t" . str_replace("\n", "\n\t", $css);
             }
             $this->css = array("<style type=\"text/css\">\n{$cssCode}\n</style>");
         }
         // Thu, May 8, 2014 13:10:19 - changed order of meta keys and meta description
         // See #1231
         $this->head['keywords'] = array_reverse($this->keywords);
         $this->head['author'] = $this->author;
         $this->head['robots'] = $this->robots;
         $this->head['description'] = array_reverse($this->description);
         $this->head['css'] = $this->_cssFiles();
         $this->head['js'] = $this->_jsFiles();
         $this->head['links'] = $this->links;
         $this->head['css'] = array_merge($this->head['css'], $this->css);
         $this->head['js'] = array_merge($this->head['js'], $this->js);
         $this->head['raw'] = $this->raw;
         Sobi::Trigger('Header', 'Send', array(&$this->head));
         SPFactory::mainframe()->addHead($this->head);
         if (count($this->title)) {
             SPFactory::mainframe()->setTitle($this->title);
         }
         SPFactory::cache()->storeView($this->_store);
         $this->reset();
     }
 }
예제 #17
0
 protected function entry($entry, $manager, $noId = false)
 {
     $en = array();
     if (is_numeric($entry)) {
         $en = $this->cachedEntry($entry, $manager, $noId);
     }
     if (!is_array($en) || !count($en)) {
         if (is_numeric($entry)) {
             $entry = SPFactory::Entry($entry);
         }
         $en['id'] = $entry->get('id');
         $en['nid'] = $entry->get('nid');
         $en['name'] = array('_complex' => 1, '_data' => $entry->get('name'), '_attributes' => array('lang' => Sobi::Lang(false)));
         $en['url_array'] = array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => $entry->get('primary'), 'sid' => $entry->get('id'));
         if (strstr(SPRequest::task(), 'search') || $noId || Sobi::Cfg('section.force_category_id', false) && SPRequest::sid() == Sobi::Section()) {
             $en['url'] = Sobi::Url(array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => $entry->get('primary'), 'sid' => $entry->get('id')));
         } else {
             $en['url'] = Sobi::Url(array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => SPRequest::sid(), 'sid' => $entry->get('id')));
         }
         if (Sobi::Cfg('list.entry_meta', true)) {
             $en['meta'] = array('description' => $entry->get('metaDesc'), 'keys' => $this->metaKeys($entry), 'author' => $entry->get('metaAuthor'), 'robots' => $entry->get('metaRobots'));
         }
         if ($manager || Sobi::My('id') && Sobi::My('id') == $entry->get('owner') && Sobi::Can('entry', 'edit', 'own', Sobi::Section())) {
             $en['edit_url'] = Sobi::Url(array('task' => 'entry.edit', 'pid' => SPRequest::sid(), 'sid' => $entry->get('id')));
         } else {
             if (isset($en['edit_url'])) {
                 unset($en['edit_url']);
             }
         }
         $en['edit_url_array'] = array('task' => 'entry.edit', 'pid' => SPRequest::sid(), 'sid' => $entry->get('id'));
         $en['created_time'] = $entry->get('createdTime');
         $en['updated_time'] = $entry->get('updatedTime');
         $en['valid_since'] = $entry->get('validSince');
         $en['valid_until'] = $entry->get('validUntil');
         $this->fixTimes($en);
         if ($entry->get('state') == 0) {
             $en['state'] = 'unpublished';
         } else {
             if (strtotime($entry->get('validUntil')) != 0 && strtotime($entry->get('validUntil')) < time()) {
                 $en['state'] = 'expired';
             } elseif (strtotime($entry->get('validSince')) != 0 && strtotime($entry->get('validSince')) > time()) {
                 $en['state'] = 'pending';
             } else {
                 $en['state'] = 'published';
             }
         }
         $en['author'] = $entry->get('owner');
         $en['counter'] = $entry->get('counter');
         $en['approved'] = $entry->get('approved');
         //		$en[ 'confirmed' ] = $entry->get( 'confirmed' );
         if (Sobi::Cfg('list.entry_cats', true)) {
             $cats = $entry->get('categories');
             $categories = array();
             if (count($cats)) {
                 $cn = SPLang::translateObject(array_keys($cats), array('name', 'alias'));
             }
             foreach ($cats as $cid => $cat) {
                 $categories[] = array('_complex' => 1, '_data' => SPLang::clean($cn[$cid]['value']), '_attributes' => array('lang' => Sobi::Lang(false), 'id' => $cat['pid'], 'position' => $cat['position'], 'url' => Sobi::Url(array('sid' => $cat['pid'], 'title' => Sobi::Cfg('sef.alias', true) ? $cat['alias'] : $cat['name']))));
             }
             $en['categories'] = $categories;
         }
         $fields = $entry->getFields();
         if (count($fields)) {
             //				foreach ( $fields as $field ) {
             //					if ( $field->enabled( 'vcard' ) && $field->get( 'id' ) != Sobi::Cfg( 'entry.name_field' ) ) {
             //						$struct = $field->struct();
             //						$options = null;
             //						if ( isset( $struct[ '_options' ] ) ) {
             //							$options = $struct[ '_options' ];
             //							unset( $struct[ '_options' ] );
             //						}
             //						$f[ $field->get( 'nid' ) ] = array(
             //							'_complex' => 1,
             //							'_data' => array(
             //								'label' => array(
             //									'_complex' => 1,
             //									'_data' => $field->get( 'name' ),
             //									'_attributes' => array( 'lang' => Sobi::Lang( false ), 'show' => $field->get( 'withLabel' ) )
             //								),
             //								'data' => $struct,
             //							),
             //							'_attributes' => array( 'id' => $field->get( 'id' ), 'type' => $field->get( 'type' ), 'suffix' => $field->get( 'suffix' ), 'position' => $field->get( 'position' ), 'css_class' => ( strlen( $field->get( 'cssClass' ) ) ? $field->get( 'cssClass' ) : 'spField' ) )
             //						);
             //						if ( Sobi::Cfg( 'list.field_description', false ) ) {
             //							$f[ $field->get( 'nid' ) ][ '_data' ][ 'description' ] = array( '_complex' => 1, '_xml' => 1, '_data' => $field->get( 'description' ) );
             //						}
             //						if ( $options ) {
             //							$f[ $field->get( 'nid' ) ][ '_data' ][ 'options' ] = $options;
             //						}
             //						if ( isset( $struct[ '_xml_out' ] ) && count( $struct[ '_xml_out' ] ) ) {
             //							foreach ( $struct[ '_xml_out' ] as $k => $v )
             //								$f[ $field->get( 'nid' ) ][ '_data' ][ $k ] = $v;
             //						}
             //					}
             //				}
             $en['fields'] = $this->fieldStruct($fields, 'vcard');
         }
         SPFactory::cache()->addObj($entry, 'entry', $entry->get('id'))->addObj($en, 'entry_struct', $entry->get('id'));
         unset($en['url_array']);
         unset($en['edit_url_array']);
         unset($entry);
     }
     $en['counter'] = $this->getNonStaticData($en['id'], 'counter');
     /*
      * this is te special case:
      * no matter what task we currently have - if someone called this we need the data for the V-Card
      * Soe we have to trigger all these plugins we need and therefore also fake the task
      */
     $task = 'list.custom';
     SPFactory::registry()->set('task', $task);
     Sobi::Trigger('List', ucfirst(__FUNCTION__), array(&$en));
     return $en;
 }
예제 #18
0
 /**
  * Save a rule
  *
  * @param bool $apply
  */
 protected function save($apply)
 {
     Sobi::Trigger('Save', 'Acl', array(&$this));
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $rid = SPRequest::int('rid', 'null');
     $this->validate('acl.edit', array('task' => 'acl.edit', 'rid' => $rid));
     if ($rid) {
         $this->remove($rid);
     }
     $vs = SPRequest::timestamp('set_validSince');
     $vu = SPRequest::timestamp('set_validUntil');
     $vs = $vs ? date(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $vs) : null;
     $vu = $vu ? date(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $vu) : null;
     $name = SPRequest::string('set_name');
     $nid = SPRequest::cmd('set_nid');
     $note = SPRequest::string('set_note');
     $state = SPRequest::int('set_state', 1);
     $gids = SPRequest::arr('set_groups');
     $sids = SPRequest::arr('set_sections');
     $pf = SPRequest::arr('set_permissions', array());
     $pa = SPRequest::arr('set_adm_permissions', array());
     // if can publish any, then can see any unpublished
     if (in_array(20, $pf)) {
         $pf[] = 14;
     }
     // if can publish own, then can see own unpublished
     if (in_array(21, $pf)) {
         $pf[] = 12;
     }
     if (in_array(19, $pf)) {
         $pf[] = 15;
     }
     $perms = array_merge($pf, $pa);
     /* @var SPdb $db */
     $db = SPFactory::db();
     /* update or insert the rule definition */
     try {
         $db->insertUpdate('spdb_permissions_rules', array('rid' => $rid, 'name' => $name, 'nid' => $nid, 'validSince' => $vs, 'validUntil' => $vu, 'note' => $note, 'state' => $state));
     } catch (SPException $x) {
         Sobi::Error('ACL', SPLang::e('CANNOT_CREATE_RULE_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     $rid = (int) $rid ? (int) $rid : $db->insertid();
     /* insert the groups ids */
     if (count($gids)) {
         foreach ($gids as $i => $gid) {
             $gids[$i] = array('rid' => $rid, 'gid' => $gid);
         }
         try {
             $db->insertArray('spdb_permissions_groups', $gids);
         } catch (SPException $x) {
             Sobi::Error('ACL', SPLang::e('CANNOT_INSERT_GROUPS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     try {
         $db->select('*', 'spdb_permissions', array('site' => 'adm', 'value' => 'global'));
         $admPermissions = $db->loadResultArray();
     } catch (SPException $x) {
         Sobi::Error('ACL', SPLang::e('CANNOT_GET_PERMISSIONS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     /* create permission and section map */
     if (count($sids) && count($perms)) {
         $map = array();
         /* travel the sections */
         foreach ($sids as $sid) {
             foreach ($perms as $pid) {
                 if (in_array($pid, $admPermissions)) {
                     $map[] = array('rid' => $rid, 'sid' => 0, 'pid' => $pid);
                 } else {
                     $map[] = array('rid' => $rid, 'sid' => $sid, 'pid' => $pid);
                 }
             }
         }
         try {
             $db->insertArray('spdb_permissions_map', $map, true);
         } catch (SPException $x) {
             Sobi::Error('ACL', SPLang::e('CANNOT_INSERT_GROUPS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     SPFactory::cache()->cleanAll();
     /* trigger plugins */
     Sobi::Trigger('AfterSave', 'Acl', array(&$this));
     /* set redirect */
     $this->response(Sobi::Url($apply ? array('task' => 'acl.edit', 'rid' => $rid) : 'acl'), Sobi::Txt('ACL_RULE_SAVED'), !$apply, SPC::SUCCESS_MSG, array('sets' => array('rid' => $rid)));
 }
예제 #19
0
 /**
  * Factory method for entries models
  * @param id of the entry $sid
  * @return SPEntryAdm
  */
 public static function &EntryRow($sid)
 {
     $cached = SPFactory::cache()->getObj('entry_row', $sid);
     if ($cached && is_object($cached)) {
         //			SPConfig::debOut( "$sid: cached" );
         return $cached;
     } else {
         $entry = self::Model('entry', true);
         $entry->init($sid);
         SPFactory::cache()->addObj($entry, 'entry_row', $sid);
         return $entry;
     }
 }
예제 #20
0
 /**
  * @param DOMDocument $def
  * @param string $dir
  * @return array | string
  */
 protected function installExt($def, $dir)
 {
     $this->checkRequirements($def);
     jimport('joomla.installer.installer');
     jimport('joomla.installer.helper');
     $installer = JInstaller::getInstance();
     $type = JInstallerHelper::detectType($dir);
     $xp = new DOMXPath($def);
     try {
         $installer->install($dir);
         // it was core update - break now
         if ($type == 'component') {
             SPFactory::cache()->cleanAll();
             return array('msg' => Sobi::Txt('CMS_SOBIPRO_UPDATE_INSTALLED', $def->getElementsByTagName('version')->item(0)->nodeValue), 'msgtype' => SPC::SUCCESS_MSG);
         }
         $msg = Sobi::Txt('CMSEX_INSTALLED', $type, $def->getElementsByTagName('name')->item(0)->nodeValue);
         $this->id = SPLang::nid($def->getElementsByTagName('name')->item(0)->nodeValue);
         $id = $xp->query('//filename[@module|@plugin]')->item(0);
         $this->id = strlen($id->getAttribute('module')) ? $id->getAttribute('module') : $id->getAttribute('plugin');
         if (strlen($def->documentElement->getAttribute('group'))) {
             $this->id = $def->documentElement->getAttribute('group') . '_' . $this->id;
         }
         if ($this->id) {
             $this->definition = new DOMDocument();
             $this->definition->formatOutput = true;
             $this->definition->preserveWhiteSpace = false;
             $this->definition->appendChild($this->definition->createElement('SobiProApp'));
             $root = $this->definition->getElementsByTagName('SobiProApp')->item(0);
             $root->appendChild($this->definition->createElement('id', $this->id));
             $root->appendChild($this->definition->createElement('type', $type));
             $root->appendChild($this->definition->createElement('name', $def->getElementsByTagName('name')->item(0)->nodeValue));
             $root->appendChild($this->definition->createElement('uninstall', 'cms.base.installer:remove'));
             $this->definition->appendChild($root);
             $dir = SPLoader::dirPath('etc.installed.' . $type . 's', 'front', false);
             if (!SPFs::exists($dir)) {
                 SPFs::mkdir($dir);
             }
             $path = $dir . '/' . $this->id . '.xml';
             $file = SPFactory::Instance('base.fs.file', $path);
             $this->definition->normalizeDocument();
             $file->content($this->definition->saveXML());
             $file->save();
             $this->storeData($type, $def);
         }
         return array('msg' => $msg, 'msgtype' => SPC::SUCCESS_MSG);
     } catch (Exception $x) {
         $this->error = Sobi::Txt('CMS_EXT_NOT_INSTALLED') . ' ' . $x->getMessage();
         $this->errorType = SPC::ERROR_MSG;
         return array('msg' => $this->error, 'msgtype' => SPC::ERROR_MSG);
     }
 }
예제 #21
0
 /**
  * (non-PHPdoc)
  * @see Site/lib/models/SPDBObject#save()
  */
 public function save($request = 'post')
 {
     $this->loadFields(Sobi::Section(), true);
     // Thu, Feb 19, 2015 12:12:47 - it should be actually "beforeSave"
     Sobi::Trigger($this->name(), 'Before' . ucfirst(__FUNCTION__), array($this->id));
     /* save the base object data */
     /* @var SPdb $db */
     $db = SPFactory::db();
     $db->transaction();
     if (!$this->nid || SPRequest::task() == 'entry.clone') {
         $this->nid = SPRequest::string($this->nameField, null, false, $request);
         $this->nid = $this->createAlias();
         $this->name = $this->nid;
     }
     if (Sobi::Cfg('entry.publish_limit', 0) && !defined('SOBI_ADM_PATH')) {
         SPRequest::set('entry_createdTime', 0, $request);
         SPRequest::set('entry_validSince', 0, $request);
         SPRequest::set('entry_validUntil', 0, $request);
         $this->validUntil = gmdate('Y-m-d H:i:s', time() + Sobi::Cfg('entry.publish_limit', 0) * 24 * 3600);
     }
     $preState = Sobi::Reg('object_previous_state');
     parent::save($request);
     $nameField = $this->nameField();
     /* get the fields for this section */
     foreach ($this->fields as $field) {
         /* @var $field SPField */
         try {
             if ($field->enabled('form', $preState['new'])) {
                 $field->saveData($this, $request);
             } else {
                 $field->finaliseSave($this, $request);
             }
             if ($field->get('id') == $nameField) {
                 /* get the entry name */
                 $this->name = $field->getRaw();
                 /* save the nid (name id) of the field where the entry name is saved */
                 $this->nameField = $field->get('nid');
             }
         } catch (SPException $x) {
             if (SPRequest::task() != 'entry.clone') {
                 $db->rollback();
                 throw new SPException(SPLang::e('CANNOT_SAVE_FIELS_DATA', $x->getMessage()));
             } else {
                 Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
             }
         }
     }
     $values = array();
     /* get categories */
     $cats = Sobi::Reg('request_categories');
     if (!count($cats)) {
         $cats = SPRequest::arr('entry_parent', SPFactory::registry()->get('request_categories', array()), $request);
     }
     /* by default it should be comma separated string */
     if (!count($cats)) {
         $cats = SPRequest::string('entry_parent', null, $request);
         if (strlen($cats) && strpos($cats, ',')) {
             $cats = explode(',', $cats);
             foreach ($cats as $i => $cat) {
                 $c = (int) trim($cat);
                 if ($c) {
                     $cats[$i] = $c;
                 } else {
                     unset($cats[$i]);
                 }
             }
         } elseif (strlen($cats)) {
             $cats = array((int) $cats);
         }
     }
     if (is_array($cats) && count($cats)) {
         foreach ($cats as $i => $v) {
             if (!$v) {
                 unset($cats[$i]);
             }
         }
     }
     if (is_array($cats) && count($cats)) {
         /* get the ordering in these categories */
         try {
             $db->select('pid, MAX(position)', 'spdb_relations', array('pid' => $cats, 'oType' => 'entry'), null, 0, 0, false, 'pid');
             $cPos = $db->loadAssocList('pid');
             $currPos = $db->select(array('pid', 'position'), 'spdb_relations', array('id' => $this->id, 'oType' => 'entry'))->loadAssocList('pid');
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         /* set the right position */
         foreach ($cats as $i => $cat) {
             $copy = 0;
             if (!$this->approved) {
                 $copy = isset($this->categories[$cats[$i]]) ? 0 : 1;
             } else {
                 $db->delete('spdb_relations', array('id' => $this->id, 'oType' => 'entry'));
             }
             if (isset($currPos[$cat])) {
                 $pos = $currPos[$cat]['position'];
             } else {
                 $pos = isset($cPos[$cat]) ? $cPos[$cat]['MAX(position)'] : 0;
                 $pos++;
             }
             $values[] = array('id' => $this->id, 'pid' => $cats[$i], 'oType' => 'entry', 'position' => $pos, 'validSince' => $this->validSince, 'validUntil' => $this->validUntil, 'copy' => $copy);
         }
         try {
             $db->insertArray('spdb_relations', $values, true);
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     } elseif (!count($this->categories)) {
         throw new SPException(SPLang::e('MISSING_CAT'));
     }
     /* trigger possible state changes */
     if ($preState['approved'] != $this->approved) {
         if ($this->approved) {
             $this->approveFields(true);
             // it's being done by the method above - removing
             //Sobi::Trigger( $this->name(), 'AfterApprove', array( $this->id, $this->approved ) );
         }
     }
     if ($preState['state'] != $this->state) {
         Sobi::Trigger($this->name(), 'AfterChangeState', array($this->id, $this->state));
     }
     SPFactory::cache()->purgeSectionVars();
     SPFactory::cache()->deleteObj('entry', $this->id);
     if (count($cats)) {
         foreach ($cats as $cat) {
             SPFactory::cache()->deleteObj('category', $cat);
         }
     }
     Sobi::Trigger($this->name(), 'After' . ucfirst($preState['new'] ? __FUNCTION__ : 'Update'), array(&$this));
 }
예제 #22
0
 /**
  */
 private function reorder()
 {
     /* @var SPdb $db */
     $db =& SPFactory::db();
     $sids = SPRequest::arr('ep_sid', array());
     /* re-order it to the valid ordering */
     $order = array();
     asort($sids);
     $eLimStart = SPRequest::int('eLimStart', 0);
     $eLimit = Sobi::GetUserState('adm.entries.limit', 'elimit', Sobi::Cfg('adm_list.entries_limit', 25));
     $LimStart = $eLimStart ? ($eLimStart - 1) * $eLimit : $eLimStart;
     if (count($sids)) {
         $c = 0;
         foreach ($sids as $sid => $pos) {
             $order[++$c] = $sid;
         }
     }
     $pid = SPRequest::int('sid');
     foreach ($order as $sid) {
         try {
             $db->update('spdb_relations', array('position' => ++$LimStart), array('id' => $sid, 'oType' => 'entry', 'pid' => $pid));
             SPFactory::cache()->deleteObj('entry', $sid);
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     $this->response(Sobi::Back(), Sobi::Txt('EMN.REORDERED'), true, SPC::SUCCESS_MSG);
 }
예제 #23
0
 /**
  * @param $message
  * @param $type -
  * @param $section string
  * @return SPMessage
  */
 public function &setSilentSystemMessage($message, $type = SPC::NOTICE_MSG, $section = 'configuration')
 {
     $this->current = array('message' => $message, 'type' => $type, 'section' => array('id' => Sobi::Section(), 'name' => Sobi::Section(true)));
     $this->current['issue-type'] = $section;
     $this->store[md5(serialize($this->current))] = $this->current;
     if (count($this->store)) {
         $messages = SPConfig::serialize($this->store);
         $store = array('params' => $messages, 'key' => 'queue', 'value' => date(DATE_RFC822), 'description' => null, 'options' => null);
         SPFactory::registry()->saveDBSection(array('messages' => $store), 'messages');
         SPFactory::cache()->cleanSection(-1, false);
     }
     return $this;
 }
예제 #24
0
 /**
  * Adding new field
  * Save base data and redirect to the edit function when the field type has been chosed
  * @return integer
  */
 public function saveNew($attr)
 {
     $db = SPFactory::db();
     /* cast all needed data and clean - it is possible just in admin panel but "strzeżonego pan Bóg strzeże" ;-) */
     $base = array();
     $base['section'] = isset($attr['section']) && $attr['section'] ? $attr['section'] : SPRequest::sid();
     if (isset($attr['name'])) {
         $base['name'] = $db->escape($attr['name']);
     }
     if (isset($attr['description'])) {
         $base['description'] = $db->escape($attr['description']);
     } else {
         $base['description'] = null;
     }
     if (isset($attr['suffix'])) {
         $base['suffix'] = $db->escape($attr['suffix']);
     } else {
         $base['suffix'] = null;
     }
     if (isset($attr['nid'])) {
         $base['nid'] = $this->nid($db->escape(preg_replace('/[^[:alnum:]\\-\\_]/', null, $attr['nid'])), true);
     }
     if (isset($attr['cssClass'])) {
         $base['cssClass'] = $db->escape(preg_replace('/[^[:alnum:]\\-\\_ ]/', null, $attr['cssClass']));
     }
     if (isset($attr['notice'])) {
         $base['notice'] = $db->escape($attr['notice']);
     }
     if (isset($attr['showIn'])) {
         $base['showIn'] = $db->escape(preg_replace('/[^[:alnum:]\\.\\-\\_]/', null, $attr['showIn']));
     }
     if (isset($attr['fieldType'])) {
         $base['fieldType'] = preg_replace('/[^[:alnum:]\\.\\-\\_]/', null, $attr['fieldType']);
     }
     if (isset($attr['type'])) {
         $base['fieldType'] = preg_replace('/[^[:alnum:]\\.\\-\\_]/', null, $attr['type']);
     }
     if (isset($attr['description'])) {
         $base['description'] = $db->escape($attr['description']);
     }
     if (isset($attr['enabled'])) {
         $base['enabled'] = (int) $attr['enabled'];
     }
     if (isset($attr['required'])) {
         $base['required'] = (int) $attr['required'];
     }
     if (isset($attr['adminField'])) {
         $base['adminField'] = (int) $attr['adminField'];
     }
     if (isset($attr['adminField']) && $attr['adminField']) {
         $attr['required'] = false;
     }
     if (isset($attr['editable'])) {
         $base['editable'] = (int) $attr['editable'];
     }
     if (isset($attr['editLimit'])) {
         $base['editLimit'] = (int) $attr['editLimit'];
         $base['editLimit'] = $base['editLimit'] > 0 ? $base['editLimit'] : -1;
     }
     if (isset($attr['isFree'])) {
         $base['isFree'] = (int) $attr['isFree'];
     }
     if (isset($attr['withLabel'])) {
         $base['withLabel'] = (int) $attr['withLabel'];
     }
     if (isset($attr['inSearch'])) {
         $base['inSearch'] = (int) $attr['inSearch'];
     }
     if (isset($attr['admList'])) {
         $base['admList'] = (int) $attr['admList'];
     }
     if (isset($attr['fee'])) {
         $base['fee'] = (double) $attr['fee'];
     }
     if (isset($attr['section'])) {
         $base['section'] = (int) $attr['section'];
     }
     $base['version'] = 1;
     /* determine the right position */
     try {
         $db->select('MAX( position )', 'spdb_field', array('section' => SPRequest::sid()));
         $base['position'] = (int) $db->loadResult() + 1;
         if (!$base['position']) {
             $base['position'] = 1;
         }
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_GET_FIELD_POSITION_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     /* get database columns and their ordering */
     $cols = $db->getColumns('spdb_field');
     $values = array();
     /* and sort the properties in the same order */
     foreach ($cols as $col) {
         $values[$col] = array_key_exists($col, $base) ? $base[$col] : '';
     }
     /* save new field */
     try {
         $db->insert('spdb_field', $values);
         $this->fid = $db->insertid();
     } catch (SPException $x) {
         Sobi::Error($this->name(), $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     /* save language depend properties */
     $labels = array();
     $defLabels = array();
     $labels[] = array('sKey' => 'name', 'sValue' => $base['name'], 'language' => Sobi::Lang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     $labels[] = array('sKey' => 'description', 'sValue' => $base['description'], 'language' => Sobi::Lang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     $labels[] = array('sKey' => 'suffix', 'sValue' => $base['suffix'], 'language' => Sobi::Lang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     if (Sobi::Lang() != Sobi::DefLang()) {
         $defLabels[] = array('sKey' => 'name', 'sValue' => $base['name'], 'language' => Sobi::DefLang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
         $defLabels[] = array('sKey' => 'suffix', 'sValue' => $base['suffix'], 'language' => Sobi::DefLang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
         $defLabels[] = array('sKey' => 'description', 'sValue' => $base['description'], 'language' => Sobi::DefLang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     }
     if (count($labels)) {
         try {
             if (Sobi::Lang() != Sobi::DefLang()) {
                 $db->insertArray('spdb_language', $defLabels, false, true);
             }
             $db->insertArray('spdb_language', $labels, true);
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELD_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     SPFactory::cache()->cleanSection();
     return $this->fid;
 }
예제 #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));
     }
 }
예제 #26
0
파일: section.php 프로젝트: pelloq1/SobiPro
 /**
  */
 public function save($update = false, $init = true)
 {
     /* @var SPdb $db */
     $db =& SPFactory::db();
     /* check nid */
     if (!$update) {
         $c = 1;
         while ($c) {
             /* section name id has to be unique */
             try {
                 $db->select('COUNT(nid)', 'spdb_object', array('oType' => 'section', 'nid' => $this->nid));
                 $c = $db->loadResult();
                 if ($c > 0) {
                     $this->nid = $this->nid . '_' . rand(0, 1000);
                 }
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
             }
         }
     }
     SPFactory::registry()->set('current_section', $this->id);
     $db->transaction();
     parent::save();
     /* case adding new section, define the default title field */
     if (!$update && $init) {
         $field = SPFactory::Model('field', true);
         $fid = $field->saveNew(array('name' => 'Name', 'nid' => 'field_name', 'showIn' => 'both', 'fieldType' => 'inbox', 'enabled' => 1, 'required' => 1, 'editable' => 1, 'section' => $this->id, 'inSearch' => 1, 'searchMethod' => 'general', 'isFree' => 1, 'editLimit' => -1, 'withLabel' => 1));
         $field = SPFactory::Model('field', true);
         $field->saveNew(array('name' => 'Category', 'nid' => 'field_category', 'showIn' => 'hidden', 'fieldType' => 'category', 'enabled' => 1, 'required' => 1, 'editable' => 1, 'section' => $this->id, 'inSearch' => 1, 'searchMethod' => 'select', 'isFree' => 1, 'editLimit' => -1, 'withLabel' => 1, 'method' => 'select', 'isPrimary' => true));
         SPFactory::config()->saveCfg('entry.name_field', $fid)->saveCfg('list.entries_ordering', 'field_name')->saveCfg('template.icon_fonts_arr', array('font-awesome-3-local'));
         SPFactory::Controller('acl', true)->addNewRule($this->get('name'), array($this->id), array('section.access.valid', 'category.access.valid', 'entry.access.valid', 'entry.add.own', 'section.search.*'), array('visitor', 'registered'), 'Default permissions for the section "' . $this->get('name') . '"');
     }
     /* insert relation */
     try {
         $db->insertUpdate('spdb_relations', array('id' => $this->id, 'pid' => 0, 'oType' => 'section', 'position' => 1, 'validSince' => $this->validSince, 'validUntil' => $this->validUntil));
     } catch (SPException $x) {
         $db->rollback();
         Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     /* if there was no errors, commit the database changes */
     $db->commit();
     //		if( !$update ) {
     //			SPFactory::mainframe()->msg( Sobi::Txt( 'SEC.CREATED' ) );
     //		}
     SPFactory::cache()->cleanSection();
     /* trigger plugins */
     Sobi::Trigger('afterSave', $this->name(), array(&$this));
 }
예제 #27
0
 /**
  * @return array
  */
 public function struct()
 {
     $baseData = $this->getRaw();
     $list = array();
     $struct = array();
     $order = SPFactory::cache()->getVar('order_' . $this->nid);
     if (!$order) {
         $order = SPFactory::db()->select('optValue', 'spdb_field_option', array('fid' => $this->id), 'optPos')->loadResultArray();
         SPFactory::cache()->addVar($order, 'order_' . $this->nid);
     }
     if (is_array($baseData) && count($baseData)) {
         $this->cssClass = strlen($this->cssClass) ? $this->cssClass : 'spFieldsData';
         $this->cssClass = $this->cssClass . ' ' . $this->nid;
         $this->cleanCss();
         foreach ($order as $opt) {
             if (isset($baseData[$opt])) {
                 $list[] = array('_tag' => 'li', '_value' => SPLang::clean($baseData[$opt]), '_class' => $opt);
             }
         }
         foreach ($this->options as $opt) {
             $struct[] = array('_complex' => 1, '_data' => $opt['label'], '_attributes' => array('selected' => isset($baseData[$opt['id']]) ? 'true' : 'false', 'id' => $opt['id'], 'position' => $opt['position']));
         }
         $data = array('ul' => array('_complex' => 1, '_data' => $list, '_attributes' => array('class' => $this->cssClass)));
     }
     if (count($list)) {
         return array('_complex' => 1, '_data' => $data, '_attributes' => array('lang' => $this->lang, 'class' => $this->cssClass), '_options' => $struct);
     }
 }
예제 #28
0
 /**
  * Executes the controller task
  * @return void
  */
 public function execute()
 {
     if (!$this->_cache) {
         try {
             if (is_array($this->_ctrl)) {
                 foreach ($this->_ctrl as &$c) {
                     $c->execute();
                 }
             } else {
                 if ($this->_ctrl instanceof SPControl) {
                     $this->_ctrl->execute();
                 } else {
                     Sobi::Error('CoreCtrl', SPLang::e('No controller to execute'), SPC::ERROR, 500, __LINE__, __FILE__);
                 }
             }
         } catch (SPException $x) {
             Sobi::Error('CoreCtrl', SPLang::e('%s', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     } else {
         /** @var $view SPFrontView */
         $view = SPFactory::View('cache');
         $view->cachedView($this->_cache['xml'], $this->_cache['template'], $this->_cache['cid'], $this->_cache['config']);
         $view->display();
     }
     /* send header data etc ...*/
     if (SPRequest::cmd('format') == 'raw' && SPRequest::bool('xmlc')) {
         SPFactory::cache()->storeView(array());
     }
     SPFactory::mainframe()->endOut();
     Sobi::Trigger('End');
     /* redirect if any redirect has been set */
     SPFactory::mainframe()->redirect();
     ini_set('display_errors', $this->_err);
     error_reporting($this->_deb);
     restore_error_handler();
 }