Exemplo n.º 1
1
 protected function menu(&$data)
 {
     if (Sobi::Cfg('general.top_menu', true)) {
         $data['menu'] = array('front' => array('_complex' => 1, '_data' => Sobi::Reg('current_section_name'), '_attributes' => array('lang' => Sobi::Lang(false), 'url' => Sobi::Url(array('sid' => Sobi::Section())))));
         if (Sobi::Can('section.search')) {
             $data['menu']['search'] = array('_complex' => 1, '_data' => Sobi::Txt('MN.SEARCH'), '_attributes' => array('lang' => Sobi::Lang(false), 'url' => Sobi::Url(array('task' => 'search', 'sid' => Sobi::Section()))));
         }
         if (Sobi::Can('entry', 'add', 'own', Sobi::Section())) {
             $data['menu']['add'] = array('_complex' => 1, '_data' => Sobi::Txt('MN.ADD_ENTRY'), '_attributes' => array('lang' => Sobi::Lang(false), 'url' => Sobi::Url(array('task' => 'entry.add', 'sid' => SPRequest::sid()))));
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @param $action
  * @param int $sid
  * @param array $changes
  * @param $message
  * @return SPMessage
  */
 public function &logAction($action, $sid = 0, $changes = array(), $message = null)
 {
     if (Sobi::Cfg('entry.versioning', true)) {
         $log = array('revision' => microtime(true) . '.' . $sid . '.' . Sobi::My('id'), 'changedAt' => 'FUNCTION:NOW()', 'uid' => Sobi::My('id'), 'userName' => Sobi::My('name'), 'userEmail' => Sobi::My('mail'), 'change' => $action, 'site' => defined('SOBIPRO_ADM') ? 'adm' : 'site', 'sid' => $sid, 'changes' => SPConfig::serialize($changes), 'params' => null, 'reason' => $message, 'language' => Sobi::Lang());
         SPFactory::db()->insert('spdb_history', $log);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Get field specific values if these are in an other table
  * @param $sid - id of the entry
  * @param $fullData - the database row form the spdb_field_data table
  * @param $rawData - raw data of the field content
  * @param $fData - full formated data of the field content
  * @return void
  */
 public function loadData($sid, &$fullData, &$rawData, &$fData)
 {
     /* @var SPdb $db */
     $db =& SPFactory::db();
     static $lang = null;
     if (!$lang) {
         $lang = Sobi::Lang(false);
     }
     $table = $db->join(array(array('table' => 'spdb_field_option_selected', 'as' => 'sdata', 'key' => 'fid'), array('table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid'), array('table' => 'spdb_language', 'as' => 'ldata', 'key' => array('sdata.optValue', 'ldata.sKey'))));
     try {
         $db->select('*, sdata.copy as scopy', $table, array('sdata.fid' => $this->id, 'sdata.sid' => $sid, 'fdata.sid' => $sid, 'ldata.oType' => 'field_option', 'ldata.fid' => $this->id), 'scopy', 0, 0, true);
         $data = $db->loadObjectList();
         $order = SPFactory::cache()->getVar('order_' . $this->nid);
         if (!$order) {
             $db->select('optValue', 'spdb_field_option', array('fid' => $this->id), 'optPos');
             $order = $db->loadResultArray();
             SPFactory::cache()->addVar($order, 'order_' . $this->nid);
         }
         // check which version the user may see
         $copy = $this->checkCopy();
         if ($data && count($data)) {
             $rawData = array();
             $sRawData = array();
             $copied = false;
             foreach ($data as $selected) {
                 // if there was at least once copy
                 if ($selected->scopy) {
                     $copied = true;
                 }
             }
             // check what we should show
             $remove = (int) $copied && $copy;
             foreach ($data as $selected) {
                 if ($selected->scopy == $remove) {
                     // if not already set or the language fits better
                     if (!isset($rawData[$selected->optValue]) || $selected->language == $lang) {
                         $rawData[$selected->optValue] = $selected->sValue;
                     }
                 }
             }
             foreach ($order as $id => $opt) {
                 if (isset($rawData[$opt])) {
                     $sRawData[] = $rawData[$opt];
                     $this->_selected[$id] = $opt;
                 }
             }
             $fData = implode("</li>\n\t<li>", $sRawData);
             $fData = "<ul id=\"{$this->nid}\" class=\"{$this->cssClass}\">\n\t<li>{$fData}</li>\n</ul>\n";
             $fullData->baseData = $fData;
         }
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_GET_SELECTED_OPTIONS', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
 }
Exemplo n.º 4
0
 private function view()
 {
     $type = $this->key('template_type', 'xslt');
     if ($type != 'php' && Sobi::Cfg('global.disable_xslt', false)) {
         $type = 'php';
     }
     if ($type == 'xslt') {
         $visitor = $this->get('visitor');
         $current = $this->get('section');
         $categories = $this->get('categories');
         $entries = $this->get('entries');
         $data = array();
         $data['id'] = $current->get('id');
         $data['section'] = array('_complex' => 1, '_data' => Sobi::Section(true), '_attributes' => array('id' => Sobi::Section(), 'lang' => Sobi::Lang(false)));
         $data['name'] = array('_complex' => 1, '_data' => $this->get('listing_name'), '_attributes' => array('lang' => Sobi::Lang(false)));
         if (Sobi::Cfg('category.show_desc')) {
             $desc = $current->get('description');
             if (Sobi::Cfg('category.parse_desc')) {
                 Sobi::Trigger('prepare', 'Content', array(&$desc, $current));
             }
             $data['description'] = array('_complex' => 1, '_cdata' => 1, '_data' => $desc, '_attributes' => array('lang' => Sobi::Lang(false)));
         }
         $data['meta'] = array('description' => $current->get('metaDesc'), 'keys' => $this->metaKeys($current), 'author' => $current->get('metaAuthor'), 'robots' => $current->get('metaRobots'));
         $data['entries_in_line'] = $this->get('$eInLine');
         $data['categories_in_line'] = $this->get('$cInLine');
         $this->menu($data);
         $this->alphaMenu($data);
         $data['visitor'] = $this->visitorArray($visitor);
         if (count($categories)) {
             foreach ($categories as $category) {
                 if (is_numeric($category)) {
                     $category = SPFactory::Category($category);
                 }
                 $data['categories'][] = array('_complex' => 1, '_attributes' => array('id' => $category->get('id'), 'nid' => $category->get('nid')), '_data' => $this->category($category));
                 unset($category);
             }
         }
         if (count($entries)) {
             $this->loadNonStaticData($entries);
             $manager = Sobi::Can('entry', 'edit', '*', Sobi::Section()) ? true : false;
             foreach ($entries as $eid) {
                 $en = $this->entry($eid, $manager);
                 $data['entries'][] = array('_complex' => 1, '_attributes' => array('id' => $en['id']), '_data' => $en);
             }
             $this->navigation($data);
         }
         $this->_attr = $data;
     }
     // general listing trigger
     Sobi::Trigger('Listing', ucfirst(__FUNCTION__), array(&$this->_attr));
     // specific lisitng trigger
     Sobi::Trigger($this->_type, ucfirst(__FUNCTION__), array(&$this->_attr));
 }
Exemplo n.º 5
0
 /**
  * @return array
  * Ausgabe des Feldes in DV and vCard
  */
 public function struct()
 {
     $data = SPLang::getValue($this->nid . '-viewInfo', 'field_information', Sobi::Section());
     $attributes = array();
     if (strlen($data)) {
         $this->cssClass = strlen($this->cssClass) ? $this->cssClass : 'spFieldsData';
         $this->cssClass = $this->cssClass . ' ' . $this->nid;
         $this->cleanCss();
         $attributes = array('lang' => Sobi::Lang(), 'class' => $this->cssClass);
     } else {
         $this->cssClass = strlen($this->cssClass) ? $this->cssClass : 'spField';
     }
     return array('_complex' => 1, '_data' => $data, '_attributes' => $attributes);
 }
Exemplo n.º 6
0
 /**
  *
  */
 public function display()
 {
     $this->_type = 'frontpage';
     $type = $this->key('template_type', 'xslt');
     if ($type != 'php' && Sobi::Cfg('global.disable_xslt', false)) {
         $type = 'php';
     }
     if ($type == 'xslt') {
         $sections = $this->get('sections');
         $data = array();
         if (count($sections)) {
             foreach ($sections as $section) {
                 $s = array('name' => array('_complex' => 1, '_data' => $section->get('name'), '_attributes' => array('lang' => Sobi::Lang(false))), 'description' => array('_complex' => 1, '_cdata' => 1, '_data' => $section->get('description'), '_attributes' => array('lang' => Sobi::Lang(false))), 'createdTime' => $section->get('createdTime'), 'meta' => array('description' => $section->get('metaDesc'), 'keys' => $this->metaKeys($section), 'author' => $section->get('metaAuthor'), 'robots' => $section->get('metaRobots')), 'owner' => $section->get('owner'), 'version' => $section->get('version'), 'validSince' => $section->get('validSince'), 'validUntil' => $section->get('validUntil'), 'url' => Sobi::Url(array('sid' => $section->get('id'))));
                 $data[] = array('_complex' => 1, '_data' => $s, '_attributes' => array('id' => $section->get('id'), 'nid' => $section->get('nid')));
             }
         }
         $this->assign($data, 'sections');
         Sobi::Trigger($this->_type, ucfirst(__FUNCTION__), array(&$this->_attr));
     }
     parent::display();
 }
Exemplo n.º 7
0
 /**
  */
 protected function parseOrdering()
 {
     $order = Sobi::GetUserState('sections.order', 'order', 'name.asc');
     $ord = $order;
     $dir = 'asc';
     if (strstr($order, '.')) {
         $ord = explode('.', $ord);
         $dir = $ord[1];
         $ord = $ord[0];
     }
     if ($ord == 'position') {
         $ord = 'name';
     }
     if ($ord == 'name') {
         /* @var SPdb $db */
         $db =& SPFactory::db();
         try {
             $db->select('id', 'spdb_language', array('oType' => 'section', 'sKey' => 'name', 'language' => Sobi::Lang()), 'sValue.' . $dir);
             $fields = $db->loadResultArray();
             if (!count($fields) && Sobi::Lang() != Sobi::DefLang()) {
                 $db->select('id', 'spdb_language', array('oType' => 'section', 'sKey' => 'name', 'language' => Sobi::DefLang()), 'sValue.' . $dir);
                 $fields = $db->loadResultArray();
             }
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 500, __LINE__, __FILE__);
             return false;
         }
         if (count($fields)) {
             $fields = implode(',', $fields);
             $ord = "field( id, {$fields} )";
         } else {
             $ord = 'id.' . $dir;
         }
     } else {
         $ord = isset($dir) && strlen($dir) ? $ord . '.' . $dir : $ord;
     }
     SPFactory::user()->setUserState('sections.order', $ord);
     return $ord;
 }
Exemplo n.º 8
0
 /**
  * Gets the data for a field and save it in the database
  * @param SPEntry $entry
  * @param string $request
  * @throws SPException
  * @return bool
  */
 public function saveData(&$entry, $request = 'POST')
 {
     if (!$this->enabled) {
         return false;
     }
     if ($this->method == 'fixed') {
         $fixed = $this->fixedCid;
         $fixed = explode(',', $fixed);
         $data = array();
         if (count($fixed)) {
             foreach ($fixed as $cid) {
                 $data[] = trim($cid);
             }
         }
         if (!count($data)) {
             throw new SPException(SPLang::e('FIELD_CC_FIXED_CID_NOT_SELECTED', $this->name));
         }
     } else {
         $data = $this->verify($entry, $request);
     }
     $time = SPRequest::now();
     $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $uid = Sobi::My('id');
     /* if we are here, we can save these data */
     /* @var SPdb $db */
     $db = SPFactory::db();
     /* collect the needed params */
     $params = array();
     $params['publishUp'] = $entry->get('publishUp');
     $params['publishDown'] = $entry->get('publishDown');
     $params['fid'] = $this->fid;
     $params['sid'] = $entry->get('id');
     $params['section'] = Sobi::Reg('current_section');
     $params['lang'] = Sobi::Lang();
     $params['enabled'] = $entry->get('state');
     $params['params'] = null;
     $params['options'] = null;
     $params['baseData'] = SPConfig::serialize($data);
     $params['approved'] = $entry->get('approved');
     $params['confirmed'] = $entry->get('confirmed');
     /* if it is the first version, it is new entry */
     if ($entry->get('version') == 1) {
         $params['createdTime'] = $time;
         $params['createdBy'] = $uid;
         $params['createdIP'] = $IP;
     }
     $params['updatedTime'] = $time;
     $params['updatedBy'] = $uid;
     $params['updatedIP'] = $IP;
     $params['copy'] = !$entry->get('approved');
     if (Sobi::My('id') == $entry->get('owner')) {
         --$this->editLimit;
     }
     $params['editLimit'] = $this->editLimit;
     /* save it */
     try {
         /* Notices:
          * If it was new entry - insert
          * If it was an edit and the field wasn't filled before - insert
          * If it was an edit and the field was filled before - update
          *     " ... " and changes are not autopublish it should be insert of the copy .... but
          * " ... " if a copy already exist it is update again
          * */
         $db->insertUpdate('spdb_field_data', $params);
     } catch (SPException $x) {
         Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     /* if it wasn't edited in the default language, we have to try to insert it also for def lang */
     if (Sobi::Lang() != Sobi::DefLang()) {
         $params['lang'] = Sobi::DefLang();
         try {
             $db->insert('spdb_field_data', $params, true, true);
         } catch (SPException $x) {
             Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     /** Last important thing - join selected categories  */
     $cats = SPFactory::registry()->get('request_categories', array());
     $cats = array_unique(array_merge($cats, $data));
     SPFactory::registry()->set('request_categories', $cats);
     if ($this->method == 'select' && $this->isPrimary) {
         $db->update('spdb_object', array('parent' => $data[0]), array('id' => $params['sid']));
     }
 }
Exemplo n.º 9
0
 private static function createLangFile()
 {
     static $loaded = false;
     if (!$loaded) {
         $lang = array('months' => Sobi::Txt('JS_CALENDAR_MONTHS'), 'monthsShort' => Sobi::Txt('JS_CALENDAR_MONTHS_SHORT'), 'days' => Sobi::Txt('JS_CALENDAR_DAYS'), 'daysShort' => Sobi::Txt('JS_CALENDAR_DAYS_SHORT'), 'daysMin' => Sobi::Txt('JS_CALENDAR_DAYS_MINI'), 'today' => Sobi::Txt('JS_CALENDAR_TODAY'));
         $check = md5(serialize($lang));
         if (!SPLoader::JsFile('locale.' . Sobi::Lang(false) . '_date_picker', false, true, false) || !stripos(SPFs::read(SPLoader::JsFile('locale.' . Sobi::Lang(false) . '_date_picker', false, false, false)), $check)) {
             foreach ($lang as $k => $v) {
                 $lang[$k] = explode(',', $v);
             }
             $lang = json_encode($lang);
             $c = "\nvar spDatePickerLang={$lang}";
             $c .= "\n//{$check}";
             SPFs::write(SPLoader::JsFile('locale.' . Sobi::Lang(false) . '_date_picker', false, false, false), $c);
         }
     }
     $loaded = true;
 }
Exemplo n.º 10
0
 /**
  * Shows the field in the search form
  * @param bool $return return or display directly
  * @return string
  */
 public function searchForm($return = false)
 {
     if ($this->searchMethod == 'general') {
         return false;
     }
     if ($this->searchMethod == 'range') {
         return $this->rangeSearch($this->searchRangeValues, $this->freeRange);
     }
     $fdata = array();
     try {
         $data = SPFactory::db()->dselect(array('baseData', 'sid', 'lang'), 'spdb_field_data', array('fid' => $this->fid, 'copy' => '0', 'enabled' => 1), 'field( lang, \'' . Sobi::Lang() . '\'), baseData', 0, 0, 'baseData')->loadAssocList();
         $languages = array();
         $output = array();
         $lang = Sobi::Lang(false);
         $defLang = Sobi::DefLang();
         if (count($data)) {
             foreach ($data as $row) {
                 $languages[$row['lang']][$row['sid']] = $row['baseData'];
             }
         }
         if (isset($languages[$lang])) {
             foreach ($languages[$lang] as $sid => $fieldData) {
                 $output[$sid] = $fieldData;
             }
             unset($languages[$lang]);
         }
         if (isset($languages[$defLang])) {
             foreach ($languages[$defLang] as $sid => $fieldData) {
                 if (!isset($output[$sid])) {
                     $output[$sid] = $fieldData;
                 }
             }
             unset($languages[$defLang]);
         }
         if (count($languages)) {
             foreach ($languages as $language => $langData) {
                 foreach ($langData as $sid => $fieldData) {
                     if (!isset($output[$sid])) {
                         $output[$sid] = $fieldData;
                     }
                 }
                 unset($languages[$language]);
             }
         }
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_GET_FIELDS_DATA_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     $data = (array) $output;
     if (count($data)) {
         $fdata[''] = Sobi::Txt('FD.INBOX_SEARCH_SELECT', array('name' => $this->name));
         foreach ($data as $i => $d) {
             if (strlen($d)) {
                 $fdata[strip_tags($d)] = strip_tags($d);
             }
         }
     }
     return SPHtml_Input::select($this->nid, $fdata, $this->_selected, false, array('class' => $this->cssClass . ' ' . Sobi::Cfg('search.form_list_def_css', 'SPSearchSelect'), 'size' => '1', 'id' => $this->nid));
 }
Exemplo n.º 11
0
 /**
  * Static function to create the right SQL-Query if a entries list should be sorted by this field
  * @param string $tables - table or tables join
  * @param array $conditions - array with conditions
  * @param string $oPrefix
  * @param string $eOrder
  * @param string $eDir
  * @return void
  */
 public static function sortBy(&$tables, &$conditions, &$oPrefix, &$eOrder, $eDir)
 {
     /* @var SPdb $db */
     $db =& SPFactory::db();
     $tables = $db->join(array(array('table' => 'spdb_field_option_selected', 'as' => 'sdata', 'key' => 'fid'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => array('sdata.sid', 'spo.id')), array('table' => 'spdb_field_data', 'as' => 'fdata', 'key' => array('fdata.fid', 'sdata.fid')), array('table' => 'spdb_field', 'as' => 'fdef', 'key' => array('fdef.fid', 'sdata.fid')), array('table' => 'spdb_language', 'as' => 'ldata', 'key' => array('sdata.optValue', 'ldata.sKey')), array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => array('spo.id', 'sprl.id'))));
     $oPrefix = 'spo.';
     $conditions['spo.oType'] = 'entry';
     if (!isset($conditions['sprl.pid'])) {
         $conditions['sprl.pid'] = SPRequest::sid();
     }
     $conditions['ldata.oType'] = 'field_option';
     $conditions['fdef.nid'] = $eOrder;
     $eOrder = 'sValue.' . $eDir . ", field( language, '" . Sobi::Lang(false) . "', '" . Sobi::DefLang() . "' )";
     return true;
 }
Exemplo n.º 12
0
 private function view()
 {
     $type = $this->key('template_type', 'xslt');
     if ($type != 'php' && Sobi::Cfg('global.disable_xslt', false)) {
         $type = 'php';
     }
     if ($type == 'xslt') {
         $visitor = $this->get('visitor');
         $current = $this->get($this->_type);
         $orderings = $this->get('orderings');
         $categories = $this->get('categories');
         $entries = $this->get('entries');
         $cUrl = array('title' => Sobi::Cfg('sef.alias', true) ? $current->get('nid') : $current->get('name'), 'sid' => $current->get('id'));
         if (SPRequest::int('site', 0)) {
             $cUrl['site'] = SPRequest::int('site', 0);
         }
         SPFactory::header()->addCanonical(Sobi::Url($cUrl, true, true, true));
         $data = array();
         $data['id'] = $current->get('id');
         $data['counter'] = $current->get('counter');
         $data['section'] = array('_complex' => 1, '_data' => Sobi::Section(true), '_attributes' => array('id' => Sobi::Section(), 'lang' => Sobi::Lang(false)));
         $data['name'] = array('_complex' => 1, '_data' => $current->get('name'), '_attributes' => array('lang' => Sobi::Lang(false)));
         if (Sobi::Cfg('category.show_desc') || $current->get('oType') == 'section') {
             $desc = $current->get('description');
             if (Sobi::Cfg('category.parse_desc')) {
                 Sobi::Trigger('prepare', 'Content', array(&$desc, $current));
             }
             $data['description'] = array('_complex' => 1, '_cdata' => 1, '_data' => $desc, '_attributes' => array('lang' => Sobi::Lang(false)));
         }
         $showIcon = $current->get('showIcon');
         if ($showIcon == SPC::GLOBAL_SETTING) {
             $showIcon = Sobi::Cfg('category.show_icon', true);
         }
         if ($showIcon && $current->get('icon')) {
             if (SPFs::exists(Sobi::Cfg('images.category_icons') . '/' . $current->get('icon'))) {
                 $data['icon'] = Sobi::FixPath(Sobi::Cfg('images.category_icons_live') . $current->get('icon'));
             }
         }
         $data['meta'] = array('description' => $current->get('metaDesc'), 'keys' => $this->metaKeys($current), 'author' => $current->get('metaAuthor'), 'robots' => $current->get('metaRobots'));
         $data['entries_in_line'] = $this->get('$eInLine');
         $data['categories_in_line'] = $this->get('$cInLine');
         $data['number_of_subcats'] = Sobi::Cfg('list.num_subcats');
         $this->menu($data);
         $this->alphaMenu($data);
         $data['visitor'] = $this->visitorArray($visitor);
         if (count($categories)) {
             $this->loadNonStaticData($categories);
             foreach ($categories as $category) {
                 $cat = $this->category($category);
                 $data['categories'][] = array('_complex' => 1, '_attributes' => array('id' => $cat['id'], 'nid' => $cat['nid']), '_data' => $cat);
             }
             if (strstr($orderings['categories'], 'name') && Sobi::Cfg('lang.multimode', false)) {
                 usort($data['categories'], 'self::orderByName');
                 if ($orderings['categories'] == 'name.desc') {
                     $data['categories'] = array_reverse($data['categories']);
                 }
             }
         }
         if (count($entries)) {
             $this->loadNonStaticData($entries);
             $manager = Sobi::Can('entry', 'edit', '*', Sobi::Section()) ? true : false;
             foreach ($entries as $eid) {
                 $en = $this->entry($eid, $manager);
                 $data['entries'][] = array('_complex' => 1, '_attributes' => array('id' => $en['id'], 'nid' => $en['nid']), '_data' => $en);
             }
             if (strstr($orderings['entries'], 'name') && Sobi::Cfg('lang.multimode', false)) {
                 usort($data['entries'], 'self::orderByName');
                 if ($orderings['entries'] == 'name.desc') {
                     $data['entries'] = array_reverse($data['entries']);
                 }
             }
             $this->navigation($data);
         }
         $this->fixTimes($data);
         $this->_attr = $data;
     }
     Sobi::Trigger($this->_type, ucfirst(__FUNCTION__), array(&$this->_attr));
 }
Exemplo n.º 13
0
 /**
  * @param int $sid
  * @param bool $enabled
  * @return void
  */
 public function loadFields($sid = 0, $enabled = false)
 {
     $sid = $sid ? $sid : $this->section;
     /* @var SPdb $db */
     $db = SPFactory::db();
     static $fields = array();
     static $lang = null;
     $lang = $lang ? $lang : Sobi::Lang(false);
     if (!isset($fields[$sid])) {
         /* get fields */
         try {
             if ($enabled) {
                 $db->select('*', 'spdb_field', array('section' => $sid, 'enabled' => 1), 'position');
             } else {
                 $db->select('*', 'spdb_field', array('section' => $sid), 'position');
             }
             $fields[$sid] = $db->loadObjectList();
             Sobi::Trigger($this->name(), ucfirst(__FUNCTION__), array(&$fields));
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_GET_FIELDS_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     $nameField = $this->nameField();
     if (!$this->_loaded || !count($fields[$sid])) {
         if (count($fields[$sid])) {
             /* if it is an entry - prefetch the basic fields data */
             if ($this->id) {
                 $noCopy = $this->checkCopy();
                 /* in case the entry is approved, or we are editing an entry, or the user can see unapproved changes */
                 if ($this->approved || $noCopy) {
                     $ordering = 'copy.desc';
                 } else {
                     $ordering = 'copy.asc';
                 }
                 try {
                     $fdata = $db->select('*', 'spdb_field_data', array('sid' => $this->id), $ordering)->loadObjectList();
                     $db->getQuery();
                     $fieldsdata = array();
                     if (count($fdata)) {
                         foreach ($fdata as $data) {
                             /* if it has been already set - check if it is not better language choose */
                             if (isset($fieldsdata[$data->fid])) {
                                 /*
                                  * I know - the whole thing could be shorter
                                  * but it is better to understand and debug this way
                                  */
                                 if ($data->lang == $lang) {
                                     if ($noCopy) {
                                         if (!$data->copy) {
                                             $fieldsdata[$data->fid] = $data;
                                         }
                                     } else {
                                         $fieldsdata[$data->fid] = $data;
                                     }
                                 } else {
                                     $fieldsdata['langs'][$data->lang][$data->fid] = $data;
                                 }
                             } else {
                                 if ($noCopy) {
                                     if (!$data->copy) {
                                         $fieldsdata[$data->fid] = $data;
                                     }
                                 } else {
                                     $fieldsdata[$data->fid] = $data;
                                 }
                             }
                         }
                     }
                     unset($fdata);
                     SPFactory::registry()->set('fields_data_' . $this->id, $fieldsdata);
                 } catch (SPException $x) {
                     Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
                 }
             }
             foreach ($fields[$sid] as $f) {
                 /* @var SPField $field */
                 $field = SPFactory::Model('field', defined('SOBIPRO_ADM'));
                 $field->extend($f);
                 if (isset($fieldsdata[$f->fid])) {
                     $field->loadData($this->id);
                 }
                 $this->fields[] = $field;
                 $this->fieldsNids[$field->get('nid')] = $this->fields[count($this->fields) - 1];
                 $this->fieldsIds[$field->get('fid')] = $this->fields[count($this->fields) - 1];
                 /* case it was the name field */
                 if ($field->get('fid') == $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');
                 }
             }
             $this->_loaded = true;
         }
     }
 }
Exemplo n.º 14
0
 /**
  * @param $entry
  * @param $request
  * @param $files
  * @return SPdb
  * @throws SPException
  */
 protected function storeData(&$entry, $request, $files)
 {
     /* @var SPdb $db */
     $db =& SPFactory::db();
     $this->verify($entry, $request);
     $time = SPRequest::now();
     $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $uid = Sobi::My('id');
     /* if we are here, we can save these data */
     /* collect the needed params */
     $save = count($files) ? SPConfig::serialize($files) : null;
     $params = array();
     $params['publishUp'] = $entry->get('publishUp');
     $params['publishDown'] = $entry->get('publishDown');
     $params['fid'] = $this->fid;
     $params['sid'] = $entry->get('id');
     $params['section'] = Sobi::Reg('current_section');
     $params['lang'] = Sobi::Lang();
     $params['enabled'] = $entry->get('state');
     $params['baseData'] = $db->escape($save);
     $params['approved'] = $entry->get('approved');
     $params['confirmed'] = $entry->get('confirmed');
     /* if it is the first version, it is new entry */
     if ($entry->get('version') == 1) {
         $params['createdTime'] = $time;
         $params['createdBy'] = $uid;
         $params['createdIP'] = $IP;
     }
     $params['updatedTime'] = $time;
     $params['updatedBy'] = $uid;
     $params['updatedIP'] = $IP;
     $params['copy'] = !$entry->get('approved');
     if (Sobi::My('id') == $entry->get('owner')) {
         --$this->editLimit;
     }
     $params['editLimit'] = $this->editLimit;
     /* save it */
     try {
         $db->insertUpdate('spdb_field_data', $params);
         return $db;
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELDS_DATA_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         return $db;
     }
     return $db;
 }
Exemplo n.º 15
0
 public function display()
 {
     $this->_type = 'search';
     $type = $this->key('template_type', 'xslt');
     if ($type != 'php' && Sobi::Cfg('global.disable_xslt', false)) {
         $type = 'php';
     }
     if ($type == 'xslt') {
         $searchData = array();
         $fields = $this->get('fields');
         $visitor = $this->get('visitor');
         $p = $this->get('priorities');
         $priorities = array();
         if (is_array($p) && count($p)) {
             foreach ($p as $priority => $eids) {
                 if (is_array($eids) && count($eids)) {
                     foreach ($eids as $sid) {
                         $priorities[$sid] = $priority;
                     }
                 }
             }
         }
         $entries = $this->get('entries');
         $searchData['section'] = array('_complex' => 1, '_data' => Sobi::Section(true), '_attributes' => array('id' => Sobi::Section(), 'lang' => Sobi::Lang(false)));
         $searchPhrase = $this->get('search_for');
         $phrase = $this->get('search_phrase');
         $searchPhrase = strlen($searchPhrase) ? $searchPhrase : Sobi::Txt('SH.SEARCH_FOR_BOX');
         SPFactory::header()->addJsCode('var spSearchDefStr = "' . Sobi::Txt('SH.SEARCH_FOR_BOX') . '"');
         if ($this->get('$eInLine')) {
             $searchData['entries_in_line'] = $this->get('$eInLine');
         }
         if ($this->get('$eCount') >= 0) {
             $searchData['message'] = Sobi::Txt('SH.SEARCH_FOUND_RESULTS', array('count' => $this->get('$eCount')));
         }
         $this->menu($searchData);
         $this->alphaMenu($searchData);
         $fData = array();
         if (Sobi::Cfg('search.show_searchbox', true)) {
             $fData['searchbox'] = array('_complex' => 1, '_data' => array('label' => array('_complex' => 1, '_data' => Sobi::Txt('SH.SEARCH_FOR'), '_attributes' => array('lang' => Sobi::Lang(false))), 'data' => array('_complex' => 1, '_xml' => 1, '_data' => SPHtml_Input::text('sp_search_for', $searchPhrase, array('class' => Sobi::Cfg('search.form_box_def_css', 'SPSearchBox'), 'id' => 'SPSearchBox')))), '_attributes' => array('position' => 1, 'css_class' => 'SPSearchBox'));
         }
         if (Sobi::Cfg('search.top_button', true)) {
             $fData['top_button'] = array('_complex' => 1, '_data' => array('label' => array('_complex' => 1, '_data' => Sobi::Txt('SH.SEARCH_START'), '_attributes' => array('lang' => Sobi::Lang())), 'data' => array('_complex' => 1, '_xml' => 1, '_data' => SPHtml_Input::submit('search', Sobi::Txt('SH.START'), array('id' => 'top_button')))), '_attributes' => array('position' => 1, 'css_class' => 'SPSearchButton'));
         }
         if (Sobi::Cfg('search.show_phrase', true)) {
             $fData['phrase'] = array('_complex' => 1, '_data' => array('label' => array('_complex' => 1, '_data' => Sobi::Txt('SH.FIND_ENTRIES_THAT_HAVE'), '_attributes' => array('lang' => Sobi::Lang(false))), 'data' => array('_complex' => 1, '_xml' => 1, '_data' => SPHtml_Input::radioList('spsearchphrase', array('all' => Sobi::Txt('SH.FIND_ENTRIES_THAT_HAVE_ALL_WORDS'), 'any' => Sobi::Txt('SH.FIND_ENTRIES_THAT_HAVE_ANY_WORDS'), 'exact' => Sobi::Txt('SH.FIND_ENTRIES_THAT_HAVE_EXACT_PHRASE')), 'spsearchphrase', strlen($phrase) ? $phrase : Sobi::Cfg('search.form_searchphrase_def', 'all'), null, 'right'))), '_attributes' => array('position' => 1, 'css_class' => 'SPSearchPhrase'));
         }
         if (count($fields)) {
             foreach ($fields as $field) {
                 $data = $field->searchForm();
                 $suffix = $field->get('searchMethod') != 'range' ? $field->get('suffix') : null;
                 if (strlen($data)) {
                     $fData[$field->get('nid')] = array('_complex' => 1, '_data' => array('label' => array('_complex' => 1, '_data' => $field->get('name'), '_attributes' => array('lang' => Sobi::Lang())), 'data' => array('_complex' => 1, '_xml' => 1, '_data' => $data)), '_attributes' => array('id' => $field->get('id'), 'type' => $field->get('type'), 'suffix' => $suffix, 'position' => $field->get('position'), 'css_class' => strlen($field->get('cssClass')) ? $field->get('cssClass') : 'spField'));
                 }
             }
         }
         if (Sobi::Cfg('search.bottom_button', false)) {
             $fData['bottom_button'] = array('_complex' => 1, '_data' => array('label' => array('_complex' => 1, '_data' => Sobi::Txt('SH.SEARCH_START'), '_attributes' => array('lang' => Sobi::Lang(false))), 'data' => array('_complex' => 1, '_xml' => 1, '_data' => SPHtml_Input::submit('search', Sobi::Txt('SH.START')))), '_attributes' => array('position' => 1, 'css_class' => 'SPSearchButton'));
         }
         $searchData['fields'] = $fData;
         if (count($entries)) {
             $this->loadNonStaticData($entries);
             $manager = Sobi::Can('entry', 'edit', '*', Sobi::Section()) ? true : false;
             foreach ($entries as $entry) {
                 $en = $this->entry($entry, $manager);
                 $searchData['entries'][] = array('_complex' => 1, '_attributes' => array('id' => $en['id'], 'search-priority' => isset($priorities[$en['id']]) ? $priorities[$en['id']] : 'undefined'), '_data' => $en);
             }
             $this->navigation($searchData);
         }
         $searchData['visitor'] = $this->visitorArray($visitor);
         $this->_attr = $searchData;
     }
     Sobi::Trigger($this->_type, ucfirst(__FUNCTION__), array(&$this->_attr));
     parent::display($this->_type);
 }
Exemplo n.º 16
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;
 }
Exemplo n.º 17
0
 protected function xmlFile($node, &$element)
 {
     $type = $node->attributes->getNamedItem('type')->nodeValue;
     $translatable = $node->attributes->getNamedItem('translatable') ? $node->attributes->getNamedItem('translatable')->nodeValue : false;
     $admin = $node->attributes->getNamedItem('start-path') ? $node->attributes->getNamedItem('start-path')->nodeValue : 'front';
     $filename = $node->attributes->getNamedItem('filename')->nodeValue;
     $path = explode('.', $filename);
     $filename = array_pop($path);
     $dirPath = implode('.', $path);
     $element['type'] = 'text';
     if ($translatable) {
         $file = SPLoader::path($dirPath . '.' . Sobi::Lang() . '.' . $filename, $admin, true, $type);
         if (!$file) {
             $file = SPLoader::path($dirPath . '.en-GB.' . $filename, $admin, true, $type);
         }
         if ($file) {
             $element['content'] = SPFs::read($file);
         } else {
             $element['content'] = SPLoader::path($dirPath . '.' . Sobi::Lang() . '.' . $filename, $admin, false, $type);
         }
     }
 }
Exemplo n.º 18
0
 /**
  * @param int $sid
  * @return void
  */
 public function loadData($sid)
 {
     if ($this->_off) {
         return null;
     }
     $this->sid = $sid;
     $fdata = Sobi::Reg('fields_data_' . $sid, array());
     $this->suffix = SPLang::clean($this->suffix);
     if ($sid && count($fdata) && isset($fdata[$this->id])) {
         $this->_fData = $fdata[$this->id];
         $this->lang = $this->_fData->lang;
         $this->_rawData = $this->_fData->baseData;
         $this->_data = $this->_fData->baseData;
         // if the field has own method we have to re-init
         $this->checkMethod('loadData');
         if ($this->_type && method_exists($this->_type, 'loadData')) {
             $this->_type->loadData($sid, $this->_fData, $this->_rawData, $this->_data);
         }
         if ($this->editLimit > 0 && is_numeric($this->_fData->editLimit)) {
             $this->editLimit = $this->_fData->editLimit;
         } elseif ($this->editLimit < 0) {
             $this->editLimit = 2;
         } else {
             $this->editLimit = 2;
         }
         // if the limit has been reached - this field cannot be required
         if (!Sobi::Can('entry.manage.*') && $this->editLimit < 1 && in_array(SPRequest::task(), array('entry.save', 'entry.edit', 'entry.submit'))) {
             $this->required = false;
             $this->enabled = false;
             $this->_off = true;
         }
     } else {
         $fdata = Sobi::Reg('editcache');
         if (is_array($fdata) && isset($fdata[$this->nid])) {
             $this->_data = $fdata[$this->nid];
             $this->_rawData = $fdata[$this->nid];
         } else {
             $this->checkMethod('loadData');
             if ($this->_type && method_exists($this->_type, 'loadData')) {
                 $this->_type->loadData($sid, $this->_fData, $this->_rawData, $this->_data);
             } else {
                 $this->_rawData = SPFactory::db()->select('baseData', 'spdb_field_data', array('sid' => $this->sid, 'fid' => $this->fid, 'lang' => Sobi::Lang(false)))->loadResult();
             }
         }
     }
     if (!$this->isFree && SPRequest::task() == 'entry.edit') {
         /* in case we are editing - check if this field wasn't paid already */
         SPLoader::loadClass('services.payment');
         if (SPPayment::check($sid, $this->id)) {
             $this->fee = 0;
             $this->isFree = true;
         }
     }
 }
Exemplo n.º 19
0
 /**
  * @param string $subject
  * @param string $col
  * @param string $def
  * @param int $lim
  * @param int $lStart
  * @param $sids
  * @return string
  */
 protected function parseOrdering($subject, $col, $def, &$lim, &$lStart, &$sids)
 {
     $ord = Sobi::GetUserState($subject . '.order', $col, Sobi::Cfg('admin.' . $subject . '-order', $def));
     $ord = str_replace(array('e_s', 'c_s'), null, $ord);
     if (strstr($ord, '.')) {
         $ord = explode('.', $ord);
         $dir = $ord[1];
         $ord = $ord[0];
     } else {
         $dir = 'asc';
     }
     if ($ord == 'order' || $ord == 'position') {
         $subject = $subject == 'categories' ? 'category' : 'entry';
         /* @var SPdb $db */
         $db = SPFactory::db();
         $db->select('id', 'spdb_relations', array('oType' => $subject, 'pid' => $this->_model->get('id')), 'position.' . $dir, $lim, $lStart);
         $fields = $db->loadResultArray();
         if (count($fields)) {
             $sids = $fields;
             $fields = implode(',', $fields);
             $ord = "field( id, {$fields} )";
             $lStart = 0;
             $lim = 0;
         } else {
             $ord = 'id.' . $dir;
         }
     } elseif ($ord == 'name') {
         $subject = $subject == 'categories' ? 'category' : 'entry';
         /* @var SPdb $db */
         $db =& SPFactory::db();
         $db->select('id', 'spdb_language', array('oType' => $subject, 'sKey' => 'name', 'language' => Sobi::Lang()), 'sValue.' . $dir);
         $fields = $db->loadResultArray();
         if (!count($fields) && Sobi::Lang() != Sobi::DefLang()) {
             $db->select('id', 'spdb_language', array('oType' => $subject, 'sKey' => 'name', 'language' => Sobi::DefLang()), 'sValue.' . $dir);
             $fields = $db->loadResultArray();
         }
         if (count($fields)) {
             $fields = implode(',', $fields);
             $ord = "field( id, {$fields} )";
         } else {
             $ord = 'id.' . $dir;
         }
     } elseif (strstr($ord, 'field_')) {
         $db = SPFactory::db();
         static $field = null;
         if (!$field) {
             try {
                 $db->select('fieldType', 'spdb_field', array('nid' => $ord, 'section' => Sobi::Section()));
                 $fType = $db->loadResult();
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('CANNOT_DETERMINE_FIELD_TYPE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
             }
             if ($fType) {
                 $field = SPLoader::loadClass('opt.fields.' . $fType);
             }
         }
         /* *
          * @TODO The whole sort by custom field method in admin panel has to be re-implemented -
          * We could use the same field 'sortBy' method for backend and frontend.
          * The current method could be very inefficient !!!
          */
         if ($field && method_exists($field, 'sortByAdm')) {
             $fields = call_user_func_array(array($field, 'sortByAdm'), array(&$ord, &$dir));
         } else {
             $join = array(array('table' => 'spdb_field', 'as' => 'def', 'key' => 'fid'), array('table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid'));
             $db->select('sid', $db->join($join), array('def.nid' => $ord, 'lang' => Sobi::Lang()), 'baseData.' . $dir);
             $fields = $db->loadResultArray();
         }
         if (count($fields)) {
             $fields = implode(',', $fields);
             $ord = "field( id, {$fields} )";
         } else {
             $ord = 'id.' . $dir;
         }
     } elseif ($ord == 'state') {
         $ord = $ord . '.' . $dir . ', validSince.' . $dir . ', validUntil.' . $dir;
     } else {
         $ord = $ord . '.' . $dir;
     }
     return $ord;
 }
Exemplo n.º 20
0
 /**
  * @param $cOrder
  * @param int $cLim
  * @internal param string $eOrder
  * @internal param int $eLimit
  * @internal param int $eLimStart
  * @return array
  */
 public function getCats($cOrder, $cLim = 0)
 {
     $categories = array();
     $cOrder = trim($cOrder);
     $cLim = $cLim > 0 ? $cLim : 0;
     if ($this->_model->getChilds('category')) {
         /* var SPDb $db */
         $db = SPFactory::db();
         $oPrefix = null;
         /* load needed definitions */
         SPLoader::loadClass('models.dbobject');
         $conditions = array();
         switch ($cOrder) {
             case 'name.asc':
             case 'name.desc':
                 $table = $db->join(array(array('table' => 'spdb_language', 'as' => 'splang', 'key' => 'id'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => 'id')));
                 $oPrefix = 'spo.';
                 $conditions['spo.oType'] = 'category';
                 $conditions['splang.sKey'] = 'name';
                 $conditions['splang.language'] = array(Sobi::Lang(false), Sobi::DefLang(), 'en-GB');
                 if (strstr($cOrder, '.')) {
                     $cOrder = explode('.', $cOrder);
                     $cOrder = 'sValue.' . $cOrder[1];
                 }
                 break;
             case 'position.asc':
             case 'position.desc':
                 $table = $db->join(array(array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => 'id'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => 'id')));
                 $conditions['spo.oType'] = 'category';
                 $oPrefix = 'spo.';
                 break;
             case 'counter.asc':
             case 'counter.desc':
                 $table = $db->join(array(array('table' => 'spdb_counter', 'as' => 'spcounter', 'key' => 'sid'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => 'id')));
                 $oPrefix = 'spo.';
                 $conditions['spo.oType'] = 'category';
                 if (strstr($cOrder, '.')) {
                     $cOrder = explode('.', $cOrder);
                     $cOrder = 'spcounter.counter.' . $cOrder[1];
                 }
                 break;
             default:
                 $table = 'spdb_object';
                 break;
         }
         /* check user permissions for the visibility */
         if (Sobi::My('id')) {
             if (!Sobi::Can('category.access.*')) {
                 if (Sobi::Can('category.access.unapproved_own')) {
                     $conditions[] = $db->argsOr(array('approved' => '1', 'owner' => Sobi::My('id')));
                 } else {
                     $conditions[$oPrefix . 'approved'] = '1';
                 }
             }
             if (!Sobi::Can('category.access.unpublished')) {
                 if (Sobi::Can('category.access.unpublished_own')) {
                     $conditions[] = $db->argsOr(array('state' => '1', 'owner' => Sobi::My('id')));
                 } else {
                     $conditions[$oPrefix . 'state'] = '1';
                 }
             }
             if (!Sobi::Can('category.access.*')) {
                 if (Sobi::Can('category.access.expired_own')) {
                     $conditions[] = $db->argsOr(array('@VALID' => $db->valid($oPrefix . 'validUntil', $oPrefix . 'validSince'), 'owner' => Sobi::My('id')));
                 } else {
                     $conditions['state'] = '1';
                     $conditions['@VALID'] = $db->valid($oPrefix . 'validUntil', $oPrefix . 'validSince');
                 }
             }
         } else {
             $conditions = array_merge($conditions, array($oPrefix . 'state' => '1', $oPrefix . 'approved' => '1', '@VALID' => $db->valid($oPrefix . 'validUntil', $oPrefix . 'validSince')));
         }
         $conditions[$oPrefix . 'id'] = $this->_model->getChilds('category');
         try {
             $results = $db->select($oPrefix . 'id', $table, $conditions, $cOrder, $cLim, 0, true)->loadResultArray();
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
         Sobi::Trigger($this->name(), 'AfterGetCategories', array(&$results));
         if ($results && count($results)) {
             foreach ($results as $i => $cid) {
                 $categories[$i] = $cid;
                 // new $cClass();
                 //$categories[ $i ]->init( $cid );
             }
         }
     }
     return $categories;
 }
Exemplo n.º 21
0
 private function prepareStoredData(&$settings)
 {
     $store = Sobi::GetUserData('requirements', array());
     if (Sobi::Lang() != 'en-GB' && file_exists(JPATH_ADMINISTRATOR . self::langFile)) {
         $file = parse_ini_file(JPATH_ADMINISTRATOR . self::langFile);
     }
     if (count($store)) {
         foreach ($store as $key => $data) {
             if (Sobi::Lang() != 'en-GB') {
                 $translate = $file['SP.' . $data['message']['org']['label']];
                 if (count($data['message']['org']['params'])) {
                     foreach ($data['message']['org']['params'] as $param => $value) {
                         $translate = str_replace("var:[{$param}]", $value, $translate);
                     }
                 }
                 $settings[$key] = array('key' => $key, 'response' => array('en-GB' => $translate, Sobi::Lang() => $data['message']['current']), 'status' => $data['value']);
             } else {
                 $settings[$key] = array('key' => $key, 'response' => array('en-GB' => $data['message']['current']), 'status' => $data['value']);
             }
         }
     }
 }
Exemplo n.º 22
0
 /**
  * @param string $col
  * @param string $def
  * @return string
  */
 protected function parseOrdering($col, $def)
 {
     $order = Sobi::GetUserState('fields.order', $col, Sobi::Cfg('admin.fields-order', $def));
     $ord = $order;
     $dir = 'asc';
     /** legacy - why the hell I called it order?! */
     $ord = str_replace('order', 'position', $ord);
     if (strstr($ord, '.')) {
         $ord = explode('.', $ord);
         $dir = $ord[1];
         $ord = $ord[0];
     }
     $ord = $ord == 'state' ? 'enabled' : $ord;
     //		$ord = ( $ord == 'position' ) ? 'position' : $ord;
     if ($ord == 'name') {
         /* @var SPdb $db */
         $db = SPFactory::db();
         $fields = $db->select('fid', 'spdb_language', array('oType' => 'field', 'sKey' => 'name', 'language' => Sobi::Lang()), 'sValue.' . $dir)->loadResultArray();
         if (!count($fields) && Sobi::Lang() != Sobi::DefLang()) {
             $fields = $db->select('id', 'spdb_language', array('oType' => 'field', 'sKey' => 'name', 'language' => Sobi::DefLang()), 'sValue.' . $dir)->loadResultArray();
         }
         if (count($fields)) {
             $fields = implode(',', $fields);
             $ord = "field( fid, {$fields} )";
         } else {
             $ord = 'fid.' . $dir;
         }
     } else {
         $ord = $ord . '.' . $dir;
     }
     Sobi::setUserState('fields.order', $order);
     return $ord;
 }
Exemplo n.º 23
0
 /**
  * @param string $task
  */
 function __construct($task)
 {
     SPLoader::loadClass('base.exception');
     set_error_handler('SPExceptionHandler');
     $this->_err = ini_set('display_errors', 'on');
     $this->_mem = memory_get_usage();
     $this->_time = microtime();
     $this->_task = $task;
     /* load all needed classes */
     SPLoader::loadClass('base.factory');
     SPLoader::loadClass('base.object');
     SPLoader::loadClass('base.const');
     SPLoader::loadClass('base.filter');
     SPLoader::loadClass('base.request');
     SPLoader::loadClass('sobi');
     SPLoader::loadClass('base.config');
     /* authorise access */
     $this->checkAccess();
     /* initialise mainframe interface to CMS */
     $this->_mainframe =& SPFactory::mainframe();
     /* get sid if any */
     $this->_sid = SPRequest::sid();
     /* determine section */
     $this->getSection();
     /* initialise config */
     $this->createConfig();
     ini_set('display_errors', Sobi::Cfg('debug.display_errors', false));
     $this->_deb = error_reporting(Sobi::Cfg('debug.level', 0));
     /* trigger plugin */
     Sobi::Trigger('AdminStart');
     /* initialise translator and load language files */
     SPLoader::loadClass('cms.base.lang');
     SPLang::setLang(Sobi::Lang());
     try {
         SPLang::registerDomain('admin');
     } catch (SPException $x) {
         Sobi::Error('CoreCtrl', SPLang::e('Cannot register language domain: %s.', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     /* load admin html files */
     SPFactory::header()->initBase(true);
     /** @noinspection PhpParamsInspection */
     if ($this->_section) {
         $sectionName = SPLang::translateObject($this->_section, 'name', 'section');
         SPFactory::registry()->set('current_section_name', SPLang::clean($sectionName[$this->_section]['value']));
     }
     if ($this->_section && !Sobi::Cfg('section.template')) {
         SPFactory::config()->set('template', SPC::DEFAULT_TEMPLATE, 'section');
     }
     /* check if it wasn't plugin custom task */
     if (!Sobi::Trigger('custom', 'task', array($this, SPRequest::task()))) {
         /* if not, start to route */
         try {
             $this->route();
         } catch (SPException $x) {
             Sobi::Error('CoreCtrl', SPLang::e('Cannot route: %s.', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     return true;
 }
Exemplo n.º 24
0
 /**
  * Gets the data for a field and save it in the database
  * @param SPEntry $entry
  * @param string $request
  * @return bool
  */
 public function saveData(&$entry, $request = 'POST')
 {
     if (!$this->enabled) {
         return false;
     }
     $data = $this->verify($entry, $request);
     $time = SPRequest::now();
     $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $uid = Sobi::My('id');
     /* if we are here, we can save these data */
     /* @var SPdb $db */
     $db =& SPFactory::db();
     if ($this->allowHtml) {
         /* filter data */
         if (count($this->allowedAttributes)) {
             SPRequest::setAttributesAllowed($this->allowedAttributes);
         }
         if (count($this->allowedTags)) {
             SPRequest::setTagsAllowed($this->allowedTags);
         }
         $data = SPRequest::string($this->nid, null, $this->allowHtml, $request);
         SPRequest::resetFilter();
         if (!$this->editor && $this->maxLength && strlen($data) > $this->maxLength) {
             $data = substr($data, 0, $this->maxLength);
         }
     } else {
         $data = strip_tags($data);
     }
     /* collect the needed params */
     $params = array();
     $params['publishUp'] = $entry->get('publishUp');
     $params['publishDown'] = $entry->get('publishDown');
     $params['fid'] = $this->fid;
     $params['sid'] = $entry->get('id');
     $params['section'] = Sobi::Reg('current_section');
     $params['lang'] = Sobi::Lang();
     $params['enabled'] = $entry->get('state');
     $params['params'] = null;
     $params['options'] = null;
     $params['baseData'] = $data;
     $params['approved'] = $entry->get('approved');
     $params['confirmed'] = $entry->get('confirmed');
     /* if it is the first version, it is new entry */
     if ($entry->get('version') == 1) {
         $params['createdTime'] = $time;
         $params['createdBy'] = $uid;
         $params['createdIP'] = $IP;
     }
     $params['updatedTime'] = $time;
     $params['updatedBy'] = $uid;
     $params['updatedIP'] = $IP;
     $params['copy'] = !$entry->get('approved');
     if (Sobi::My('id') == $entry->get('owner')) {
         --$this->editLimit;
     }
     $params['editLimit'] = $this->editLimit;
     /* save it */
     try {
         $db->insertUpdate('spdb_field_data', $params);
     } catch (SPException $x) {
         Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     /* if it wasn't edited in the default language, we have to try to insert it also for def lang */
     if (Sobi::Lang() != Sobi::DefLang()) {
         $params['lang'] = Sobi::DefLang();
         try {
             $db->insert('spdb_field_data', $params, true, true);
         } catch (SPException $x) {
             Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
 }
Exemplo n.º 25
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);
 }
Exemplo n.º 26
0
 /**
  * Translating language depend attributes of objects
  *
  * @param array $sids - array with ids of objects to translate
  * @param array $fields - (optional) array (or string) with properties names to translate. If not given, translates all
  * @param string $type - (optional) type of object (section, category, entry). If not given, translates all
  * @param string $lang - (optional) specific language. If not given, use currently set language
  * @param string $ident
  * @return array
  */
 public static function translateObject($sids, $fields = array(), $type = null, $lang = null, $ident = 'id')
 {
     /** @todo multiple attr does not work because the id is the object id */
     $fields = is_array($fields) ? $fields : (strlen($fields) ? array($fields) : null);
     $lang = $lang ? $lang : Sobi::Lang(false);
     // we don't need to specify the language as we want to have all of them and then order it right
     // when an object name has been entered in a particular language but this language isn't used later
     // we won't have any label for this certain object
     // Wed, Dec 18, 2013 09:57:04
     //$params = array( 'id' => $sids, 'language' => array( $lang, Sobi::DefLang(), 'en-GB' ) );
     $params = array($ident => $sids);
     $result = array();
     if ($type) {
         $params['oType'] = $type;
     }
     if (in_array('alias', $fields)) {
         $fields[] = 'nid';
     }
     if ($fields && count($fields)) {
         $params['sKey'] = $fields;
     }
     try {
         $labels = SPFactory::db()->select($ident . ' AS id, sKey AS label, sValue AS value, language', 'spdb_language', $params, "FIELD( language, '{$lang}', '" . Sobi::DefLang() . "' )")->loadAssocList();
         if (count($labels)) {
             $aliases = array();
             if (in_array('alias', $fields)) {
                 $aliases = SPFactory::db()->select(array('nid', 'id'), 'spdb_object', array('id' => $sids))->loadAssocList('id');
             }
             foreach ($labels as $label) {
                 if ($label['label'] == 'nid') {
                     $result[$label['id']]['alias'] = $label['value'];
                 } else {
                     if (!isset($result[$label['id']]) || $label['language'] == Sobi::Lang()) {
                         $result[$label['id']] = $label;
                     }
                 }
                 if (in_array('nid', $fields)) {
                     if (!isset($result[$label['id']]['alias'])) {
                         $result[$label['id']]['alias'] = isset($aliases[$label['id']]) ? $aliases[$label['id']]['nid'] : null;
                     }
                 }
             }
         }
     } catch (SPError $x) {
         Sobi::Error('language', SPLang::e('CANNOT_TRANSLATE_OBJECT', $x->getMessage()), SPC::WARNING, 500, __LINE__, __CLASS__);
     }
     return $result;
 }
Exemplo n.º 27
0
 /**
  * Gets the data for a field and save it in the database
  * @param SPEntry $entry
  * @param string $request
  * @return bool
  */
 public function saveData(&$entry, $request = 'POST')
 {
     if (!$this->enabled) {
         return false;
     }
     /* @var SPdb $db */
     $db = SPFactory::db();
     $save = $this->verify($entry, $request);
     $time = SPRequest::now();
     $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $uid = Sobi::My('id');
     /* collect the needed params */
     $params = array();
     $params['publishUp'] = $entry->get('publishUp');
     $params['publishDown'] = $entry->get('publishDown');
     $params['fid'] = $this->fid;
     $params['sid'] = $entry->get('id');
     $params['section'] = Sobi::Reg('current_section');
     $params['lang'] = Sobi::Lang();
     $params['enabled'] = $entry->get('state');
     $params['baseData'] = $db->escape(SPConfig::serialize($save));
     $params['approved'] = $entry->get('approved');
     $params['confirmed'] = $entry->get('confirmed');
     /* if it is the first version, it is new entry */
     if ($entry->get('version') == 1) {
         $params['createdTime'] = $time;
         $params['createdBy'] = $uid;
         $params['createdIP'] = $IP;
     }
     $params['updatedTime'] = $time;
     $params['updatedBy'] = $uid;
     $params['updatedIP'] = $IP;
     $params['copy'] = !$entry->get('approved');
     if (Sobi::My('id') == $entry->get('owner')) {
         --$this->editLimit;
     }
     $params['editLimit'] = $this->editLimit;
     /* save it */
     try {
         /* Notices:
          * If it was new entry - insert
          * If it was an edit and the field wasn't filled before - insert
          * If it was an edit and the field was filled before - update
          *     " ... " and changes are not autopublish it should be insert of the copy .... but
          * " ... " if a copy already exist it is update again
          * */
         $db->insertUpdate('spdb_field_data', $params);
     } catch (SPException $x) {
         Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     /* if it wasn't edited in the default language, we have to try to insert it also for def lang */
     if (Sobi::Lang() != Sobi::DefLang()) {
         $params['lang'] = Sobi::DefLang();
         try {
             $db->insert('spdb_field_data', $params, true, true);
         } catch (SPException $x) {
             Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
 }
Exemplo n.º 28
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;
 }
Exemplo n.º 29
0
 public function __call($fn, $args)
 {
     $return = array('error' => 500);
     array_unshift($args, Sobi::Lang(false));
     array_unshift($args, Sobi::Cfg('live_site'));
     if ($this->_server instanceof SPSoapClient) {
         try {
             $return = $this->_server->__soapCall($fn, $args);
         } catch (SoapFault $x) {
             throw new SPException($x->getMessage());
         }
         /* what the hell ???!!!!!*/
         if ($return instanceof SoapFault) {
             throw new SPException($return->getMessage());
         }
     }
     return $return;
 }
Exemplo n.º 30
0
 protected function entryData($getFields = true)
 {
     /** @var SPEntry $entry */
     $entry = $this->get('entry');
     $visitor = $this->get('visitor');
     $data = array();
     $data['section'] = array('_complex' => 1, '_data' => Sobi::Section(true), '_attributes' => array('id' => Sobi::Section(), 'lang' => Sobi::Lang(false)));
     $en = array();
     $en['name'] = array('_complex' => 1, '_data' => $entry->get('name'), '_attributes' => array('lang' => Sobi::Lang(false)));
     $en['created_time'] = $entry->get('createdTime');
     $en['updated_time'] = $entry->get('updatedTime');
     $en['valid_since'] = $entry->get('validSince');
     $en['valid_until'] = $entry->get('validUntil');
     $en['author'] = $entry->get('owner');
     $en['counter'] = $entry->get('counter');
     $en['approved'] = $entry->get('approved');
     $this->fixTimes($en);
     //       $mytime = date( 'Y-m-d H:i:s', time());
     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['url'] = Sobi::Url(array('pid' => $entry->get('parent'), 'sid' => $entry->get('id'), 'title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name')), true, true, true);
     if (Sobi::Can('entry', 'edit', '*') || Sobi::My('id') == $entry->get('owner') && Sobi::Can('entry', 'edit', 'own')) {
         $en['edit_url'] = Sobi::Url(array('task' => 'entry.edit', 'sid' => $entry->get('id')));
     }
     if (Sobi::Can('entry', 'manage', '*')) {
         $en['approve_url'] = Sobi::Url(array('task' => $entry->get('approved') ? 'entry.unapprove' : 'entry.approve', 'sid' => $entry->get('id')));
     }
     if ($entry->get('owner') == Sobi::My('id') && Sobi::Can('entry', 'delete', 'own') || Sobi::Can('entry', 'delete', '*')) {
         $en['delete_url'] = Sobi::Url(array('task' => 'entry.delete', 'sid' => $entry->get('id')));
     }
     if (Sobi::Can('entry', 'publish', '*') || Sobi::My('id') == $entry->get('owner') && Sobi::Can('entry', 'publish', 'own')) {
         $en['publish_url'] = Sobi::Url(array('task' => $entry->get('state') ? 'entry.unpublish' : 'entry.publish', 'sid' => $entry->get('id')));
     }
     $cats = $entry->get('categories');
     $categories = array();
     if (count($cats)) {
         $cn = SPLang::translateObject(array_keys($cats), array('name', 'alias'), 'category');
     }
     $primaryCat = $entry->get('parent');
     foreach ($cats as $cid => $cat) {
         $cAttr = array('lang' => Sobi::Lang(false), 'id' => $cat['pid'], 'alias' => $cat['alias'], 'position' => $cat['position'], 'url' => Sobi::Url(array('sid' => $cat['pid'], 'title' => Sobi::Cfg('sef.alias', true) ? $cat['alias'] : $cat['name'])));
         if ($cat['pid'] == $primaryCat) {
             $cAttr['primary'] = 'true';
         }
         $categories[] = array('_complex' => 1, '_data' => SPLang::clean($cn[$cid]['value']), '_attributes' => $cAttr);
     }
     $en['categories'] = $categories;
     $en['meta'] = array('description' => $entry->get('metaDesc'), 'keys' => $this->metaKeys($entry), 'author' => $entry->get('metaAuthor'), 'robots' => $entry->get('metaRobots'));
     if ($getFields) {
         $fields = $entry->getFields();
         if (count($fields)) {
             $en['fields'] = $this->fieldStruct($fields, 'details');
         }
     }
     $this->menu($data);
     $this->alphaMenu($data);
     $data['entry'] = array('_complex' => 1, '_data' => $en, '_attributes' => array('id' => $entry->get('id'), 'nid' => $entry->get('nid'), 'version' => $entry->get('version')));
     $data['visitor'] = $this->visitorArray($visitor);
     return $data;
 }