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)); }
public function entryFormLabel($sid, $section) { return Sobi::Txt('MENU_LINK_TO_ADD_ENTRY_FORM_SELECTED', $section == $sid ? SPFactory::Section($sid)->get('name') : SPFactory::Category($sid)->get('name')); }
protected function category($category) { $cat = array(); if (is_numeric($category)) { $cat = $this->cachedCategory($category); } if (!is_array($cat) || !count($cat)) { if (is_numeric($category)) { $category = SPFactory::Category($category); } $cat['id'] = $category->get('id'); $cat['nid'] = $category->get('nid'); $cat['name'] = array('_complex' => 1, '_data' => $category->get('name'), '_attributes' => array('lang' => Sobi::Lang(false))); if (Sobi::Cfg('list.cat_desc', false)) { $cat['description'] = array('_complex' => 1, '_cdata' => 1, '_data' => $category->get('description'), '_attributes' => array('lang' => Sobi::Lang(false))); } $showIntro = $category->get('showIntrotext'); if ($showIntro == SPC::GLOBAL_SETTING) { $showIntro = Sobi::Cfg('category.show_intro', true); } if ($showIntro) { $cat['introtext'] = array('_complex' => 1, '_cdata' => 1, '_data' => $category->get('introtext'), '_attributes' => array('lang' => Sobi::Lang(false))); } $showIcon = $category->get('showIcon'); if ($showIcon == SPC::GLOBAL_SETTING) { $showIcon = Sobi::Cfg('category.show_icon', true); } if ($showIcon && $category->get('icon')) { if (SPFs::exists(Sobi::Cfg('images.category_icons') . DS . $category->get('icon'))) { $cat['icon'] = Sobi::FixPath(Sobi::Cfg('images.category_icons_live') . $category->get('icon')); } } $cat['url'] = Sobi::Url(array('title' => Sobi::Cfg('sef.alias', true) ? $category->get('nid') : $category->get('name'), 'sid' => $category->get('id'))); $cat['position'] = $category->get('position'); $cat['author'] = $category->get('owner'); if ($category->get('state') == 0) { $cat['state'] = 'unpublished'; } else { if (strtotime($category->get('validUntil')) != 0 && strtotime($category->get('validUntil')) < time()) { $cat['state'] = 'expired'; } elseif (strtotime($category->get('validSince')) != 0 && strtotime($category->get('validSince')) > time()) { $cat['state'] = 'pending'; } else { $cat['state'] = 'published'; } } if (Sobi::Cfg('list.cat_meta', false)) { $cat['meta'] = array('description' => $category->get('metaDesc'), 'keys' => $this->metaKeys($category), 'author' => $category->get('metaAuthor'), 'robots' => $category->get('metaRobots')); } if (Sobi::Cfg('list.subcats', true)) { /* @todo we have to change this method in this way that it can be sorted and limited */ $subcats = $category->getChilds('category', false, 1, true, Sobi::Cfg('list.subcats_ordering', 'name')); $sc = array(); if (count($subcats)) { foreach ($subcats as $id => $name) { $sc[] = array('_complex' => 1, '_data' => SPLang::clean($name['name']), '_attributes' => array('lang' => Sobi::Lang(false), 'id' => $id, 'url' => Sobi::Url(array('title' => Sobi::Cfg('sef.alias', true) ? $name['alias'] : $name['name'], 'sid' => $id)))); } } $cat['subcategories'] = $sc; } SPFactory::cache()->addObj($cat, 'category_struct', $category->get('id')); unset($category); } $cat['counter'] = $this->getNonStaticData($cat['id'], 'counter'); Sobi::Trigger('List', ucfirst(__FUNCTION__), array(&$cat)); return $cat; }
/** */ protected function view($allEntries, $term = null) { if ($allEntries) { SPRequest::set('task', 'section.entries'); } else { SPRequest::set('task', 'section.view'); } /* @var SPdb $db */ $db = SPFactory::db(); $c = array(); $e = array(); if (!Sobi::Section()) { Sobi::Error('Section', SPLang::e('Missing section identifier'), SPC::ERROR, 500, __LINE__, __FILE__); } $this->_model->init(Sobi::Section()); /* get the lists ordering and limits */ $eLimit = Sobi::GetUserState('entries.limit', 'elimit', Sobi::Cfg('admin.entries-limit', 25)); $cLimit = Sobi::GetUserState('categories.limit', 'climit', Sobi::Cfg('admin.categories-limit', 15)); $eLimStart = SPRequest::int('eSite', 0); $cLimStart = SPRequest::int('cSite', 0); /* get child categories and entries */ /* @todo: need better method - the query can be very large with lot of entries */ if (!$allEntries) { $e = $this->_model->getChilds(); $c = $this->_model->getChilds('category'); } elseif (!($term && $allEntries)) { $c = $this->_model->getChilds('category', true); $c[] = Sobi::Section(); if (count($c)) { try { $e1 = $db->dselect('id', 'spdb_relations', array('pid' => $c, 'oType' => 'entry'))->loadResultArray(); $e2 = $db->dselect('sid', 'spdb_field_data', array('section' => Sobi::Section(), 'fid' => Sobi::Cfg('entry.name_field')))->loadResultArray(); $e = array_merge($e1, $e2); $e = array_unique($e); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } } else { try { $e = $db->dselect('sid', 'spdb_field_data', array('section' => Sobi::Section(), 'fid' => Sobi::Cfg('entry.name_field'), 'baseData' => "%{$term}%"))->loadResultArray(); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } // just in case the given site is grater than all existing sites $cCount = count($c); $cPages = ceil($cCount / $cLimit); if ($cLimStart > $cPages) { $cLimStart = $cPages; SPRequest::set('cSite', $cPages); } $eCount = count($e); $ePages = ceil($eCount / $eLimit); if ($eLimStart > $ePages) { $eLimStart = $ePages; SPRequest::set('eSite', $ePages); } $entries = array(); $categories = array(); /* if there are entries in the root */ if (count($e)) { try { $Limit = $eLimit > 0 ? $eLimit : 0; $LimStart = $eLimStart ? ($eLimStart - 1) * $eLimit : $eLimStart; $eOrder = $this->parseOrdering('entries', 'eorder', 'position.asc', $Limit, $LimStart, $e); $results = $db->select('id', 'spdb_object', array('id' => $e, 'oType' => 'entry'), $eOrder, $Limit, $LimStart)->loadResultArray(); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } foreach ($results as $i => $entry) { $entries[$i] = $entry; } } /* if there are categories in the root */ if (count($c)) { try { $LimStart = $cLimStart ? ($cLimStart - 1) * $cLimit : $cLimStart; $Limit = $cLimit > 0 ? $cLimit : 0; $cOrder = $this->parseOrdering('categories', 'corder', 'order.asc', $Limit, $LimStart, $c); $results = $db->select('id', 'spdb_object', array('id' => $c, 'oType' => 'category'), $cOrder, $Limit, $LimStart)->loadResultArray(); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } foreach ($results as $i => $category) { $categories[$i] = SPFactory::Category($category); } } /* create menu */ $mClass = SPLoader::loadClass('views.adm.menu'); $menu = new $mClass('section.' . $this->_task, Sobi::Section()); /* load the menu definition */ $cfg = SPLoader::loadIniFile('etc.adm.section_menu'); Sobi::Trigger('Create', 'AdmMenu', array(&$cfg)); if (count($cfg)) { foreach ($cfg as $section => $keys) { $menu->addSection($section, $keys); } } Sobi::Trigger('AfterCreate', 'AdmMenu', array(&$menu)); /* create new SigsiuTree */ $tree = SPLoader::loadClass('mlo.tree'); $tree = new $tree(Sobi::GetUserState('categories.order', 'corder', 'order.asc')); /* set link */ $tree->setHref(Sobi::Url(array('sid' => '{sid}'))); $tree->setId('menuTree'); /* set the task to expand the tree */ $tree->setTask('category.expand'); $tree->init(Sobi::Reg('current_section')); /* add the tree into the menu */ $menu->addCustom('AMN.ENT_CAT', $tree->getTree()); $entriesName = SPFactory::config()->nameField()->get('name'); $entriesField = SPFactory::config()->nameField()->get('nid'); $view = SPFactory::View('section', true); $view->assign($entriesName, 'entries_name')->assign($entriesField, 'entries_field')->assign($eLimit, 'entries-limit')->assign($cLimit, 'categories-limit')->assign(SPRequest::int('eSite', 1), 'entries-site')->assign(SPRequest::int('cSite', 1), 'categories-site')->assign($cCount, 'categories-count')->assign($eCount, 'entries-count')->assign($this->_task, 'task')->assign($term, 'filter')->assign($this->customCols(), 'fields')->assign($this->_model, 'section')->assign($categories, 'categories')->assign($entries, 'entries')->assign(SPFactory::config()->nameField()->get('name'), 'entries_name')->assign($menu, 'menu')->assign(Sobi::GetUserState('entries.eorder', 'eorder', 'order.asc'), 'ordering')->assign(Sobi::GetUserState('categories.corder', 'corder', 'order.asc'), 'corder')->assign(Sobi::Section(true), 'category')->addHidden(Sobi::Section(), 'pid')->addHidden(SPRequest::sid(), 'sid'); Sobi::Trigger('Section', 'View', array(&$view)); $view->display(); }
/** * @param int $sid * @return SPSection */ private function getChilds($sid, $count = false) { $childs = array(); /* @var SPdb $db */ try { $ids = SPFactory::db()->select('id', 'spdb_relations', array('pid' => $sid, 'oType' => 'category'))->loadResultArray(); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_GET_CHILDS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } if ($count) { return count($ids); } if (count($ids)) { foreach ($ids as $id) { $child = SPFactory::Category($id); if ($child->get('state') || defined('SOBIPRO_ADM')) { $childs[] = $child; } } } uasort($childs, array($this, 'sortChilds')); return $childs; }
/** */ protected function view() { /* @var SPdb $db */ $db = SPFactory::db(); SPRequest::set('task', 'category.view'); /* get the lists ordering and limits */ $eLimit = Sobi::GetUserState('entries.limit', 'elimit', Sobi::Cfg('admin.entries-limit', 25)); $cLimit = Sobi::GetUserState('categories.limit', 'climit', Sobi::Cfg('admin.categories-limit', 15)); $eLimStart = SPRequest::int('eSite', 0); $cLimStart = SPRequest::int('cSite', 0); /* get child categories and entries */ $e = $this->_model->getChilds(); $c = $this->_model->getChilds('category'); // just in case the given site is grater than all existing sites $cCount = count($c); $cPages = ceil($cCount / $cLimit); if ($cLimStart > $cPages) { $cLimStart = $cPages; SPRequest::set('cSite', $cPages); } $eCount = count($e); $ePages = ceil($eCount / $eLimit); if ($eLimStart > $ePages) { $eLimStart = $ePages; SPRequest::set('eSite', $ePages); } $entries = array(); $categories = array(); SPLoader::loadClass('models.dbobject'); /* if there are categories in the root */ if (count($c)) { try { $LimStart = $cLimStart ? ($cLimStart - 1) * $cLimit : $cLimStart; $Limit = $cLimit > 0 ? $cLimit : 0; $cOrder = $this->parseOrdering('categories', 'corder', 'position.asc', $Limit, $LimStart, $c); $db->select('*', 'spdb_object', array('id' => $c, 'oType' => 'category'), $cOrder, $Limit, $LimStart); $results = $db->loadResultArray(); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } foreach ($results as $i => $category) { $categories[$i] = SPFactory::Category($category); // new $cClass(); //$categories[ $i ]->extend( $category ); } } /* if there are entries in the root */ if (count($e)) { try { $LimStart = $eLimStart ? ($eLimStart - 1) * $eLimit : $eLimStart; $Limit = $eLimit > 0 ? $eLimit : 0; $eOrder = $this->parseOrdering('entries', 'eorder', 'position.asc', $Limit, $LimStart, $e); $entries = $db->select('*', 'spdb_object', array('id' => $e, 'oType' => 'entry'), $eOrder, $Limit, $LimStart)->loadResultArray(); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } $entriesName = SPFactory::config()->nameField()->get('name'); $entriesField = SPFactory::config()->nameField()->get('nid'); /* create menu */ SPLoader::loadClass('views.adm.menu'); $menu = new SPAdmSiteMenu('section.' . $this->_task, SPRequest::sid()); /* load the menu definition */ $cfg = SPLoader::loadIniFile('etc.adm.section_menu'); Sobi::Trigger('Create', 'AdmMenu', array(&$cfg)); if (count($cfg)) { foreach ($cfg as $section => $keys) { $menu->addSection($section, $keys); } } /* create new SigsiuTree */ $tree = SPLoader::loadClass('mlo.tree'); $tree = new $tree(Sobi::GetUserState('categories.order', 'corder', 'position.asc')); /* set link */ $tree->setHref(Sobi::Url(array('sid' => '{sid}'))); $tree->setId('menuTree'); /* set the task to expand the tree */ $tree->setTask('category.expand'); $tree->init(Sobi::Reg('current_section'), SPRequest::sid()); /* add the tree into the menu */ $menu->addCustom('AMN.ENT_CAT', $tree->getTree()); /* get view class */ $view = SPFactory::View('category', true); $view->assign($eLimit, '$eLimit')->assign($eLimit, 'entries-limit')->assign($cLimit, 'categories-limit')->assign(SPRequest::int('eSite', 1), 'entries-site')->assign(SPRequest::int('cSite', 1), 'categories-site')->assign($cCount, 'categories-count')->assign($eCount, 'entries-count')->assign($this->_task, 'task')->assign($this->_model, 'category')->assign($categories, 'categories')->assign($entries, 'entries')->assign($this->customCols(), 'fields')->assign($entriesName, 'entries_name')->assign($entriesField, 'entries_field')->assign($menu, 'menu')->assign(Sobi::GetUserState('entries.eorder', 'eorder', 'position.asc'), 'eorder')->assign(Sobi::GetUserState('categories.corder', 'corder', 'position.asc'), 'corder')->assign($this->_model->get('name'), 'category_name')->addHidden(Sobi::Section(), 'pid')->addHidden(SPRequest::sid(), 'sid'); Sobi::Trigger('Category', 'View', array(&$view)); $view->display(); }
/** * @param $params * @param bool $count * @return array */ protected function entries($params, $count = false) { if ($params->get('fieldOrder')) { $eOrder = $params->get('fieldOrder'); } else { $eOrder = $params->get('spOrder'); } $entriesRecursive = true; $conditions = array(); $db = SPFactory::db(); $limits = $params->get('spLimit'); if ($limits) { $limits = explode('::', $limits); $fid = $limits[0]; $value = $limits[1] == 'group' ? $limits[2] : $limits[1]; $condition = array('fid' => $fid, 'optValue' => $value); if ($limits[1] == 'group') { $condition['optValue'] = $db->select('optValue', 'spdb_field_option', array('optParent' => $value, 'fid' => $fid))->loadResultArray(); } $conditions['spo.id'] = $db->select('sid', 'spdb_field_option_selected', $condition)->loadResultArray(); if (!count($conditions['spo.id'])) { return array(); } } $eDir = $params->get('spOrderDir'); $oPrefix = null; /* get the site to display */ if ($params->get('engine') != 'static') { $site = SPRequest::int('site', 1); } else { $site = 1; } $eLimit = $params->get('entriesLimit'); $eLimStart = ($site - 1) * $eLimit; /* get the ordering and the direction */ if (strstr($eOrder, '.')) { $eOrder = explode('.', $eOrder); $eDir = $eOrder[1]; $eOrder = $eOrder[0]; } $sid = $params->get('sid'); $section = $params->get('section'); $this->setModel($sid == $section ? 'section' : 'category'); $this->_model->init($sid); $catId = SPRequest::int('pid'); $catId = $catId ? $catId : SPRequest::sid(); if ($params->get('autoListing', false) && $catId && $catId != Sobi::Section()) { $entries = Sobi::GetUserData('currently-displayed-entries', array()); if (!count($entries) && $catId) { $entries = SPFactory::Category($catId)->getChilds('entry', true, 1); $entries = array_unique($entries); } if (count($entries)) { $conditions['spo.id'] = $entries; } } else { if ($entriesRecursive) { $pids = $this->_model->getChilds('category', true); // getChilds doesn't includes the category id itself $pids[$this->_model->get('id')] = $this->_model->get('id'); if (is_array($pids)) { $pids = array_keys($pids); } $conditions['sprl.pid'] = $pids; } else { $conditions['sprl.pid'] = $sid; } if ($sid == -1) { unset($conditions['sprl.pid']); } } if (count($conditions)) { /* sort by field */ if (is_numeric($eOrder)) { static $fields = array(); $specificMethod = false; $field = isset($fields[$sid]) ? $fields[$sid] : null; if (!$field) { try { $fType = $db->select('fieldType', 'spdb_field', array('fid' => $eOrder))->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); } $fields[$sid] = $field; } if ($field && method_exists($field, 'sortBy')) { $table = null; $oPrefix = null; $specificMethod = call_user_func_array(array($field, 'sortBy'), array(&$table, &$conditions, &$oPrefix, &$eOrder, &$eDir)); } if (!$specificMethod) { $table = $db->join(array(array('table' => 'spdb_field', 'as' => 'fdef', 'key' => 'fid'), array('table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => array('fdata.sid', 'spo.id')), array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => array('fdata.sid', 'sprl.id')))); $oPrefix = 'spo.'; $conditions['spo.oType'] = 'entry'; $conditions['fdef.fid'] = $eOrder; $eOrder = 'baseData.' . $eDir; } } else { $table = $db->join(array(array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => 'id'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => 'id'))); $conditions['spo.oType'] = 'entry'; if ($eOrder == 'validUntil') { $eOrder = 'spo.validUntil'; } $eOrder = $eOrder . '.' . $eDir; $oPrefix = 'spo.'; } /* check user permissions for the visibility */ if (Sobi::My('id')) { $this->userPermissionsQuery($conditions, $oPrefix); } else { $conditions = array_merge($conditions, array($oPrefix . 'state' => '1', '@VALID' => $db->valid($oPrefix . 'validUntil', $oPrefix . 'validSince'))); } $conditions['sprl.copy'] = '0'; try { if (!$count) { $results = $db->select($oPrefix . 'id', $table, $conditions, $eOrder, $eLimit, $eLimStart, true)->loadResultArray(); } else { $results = $db->select("COUNT( DISTINCT {$oPrefix}id )", $table, $conditions, $eOrder)->loadResult(); } } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } if ($count) { return $results; } $entries = array(); if (count($results)) { foreach ($results as $i => $sid) { $entries[$i] = $sid; } } return $entries; } else { return array(); } }
/** * @return void */ private function parents() { // sleep( 5 ); $sid = SPRequest::sid(); $out = SPRequest::cmd('out', 'json'); $path = SPFactory::config()->getParentPath($sid, true, false, true); $cats = array(); if (count($path)) { $childs = 0; foreach ($path as $category) { if ($category['id'] == $sid) { $childs = count(SPFactory::Category($sid)->getChilds('category', false, 1)); } $cats[] = array('id' => $category['id'], 'name' => $category['name'], 'childsCount' => $childs); } } switch ($out) { case 'json': SPFactory::mainframe()->cleanBuffer()->customHeader(); echo json_encode(array('id' => $sid, 'categories' => $cats)); exit; } }
protected function determineObjectType($sid) { if ($this->task) { $this->oTypeName = Sobi::Txt('TASK_' . strtoupper($this->task)); $this->oType = $this->task; } elseif ($sid) { $this->oType = SPFactory::db()->select('oType', 'spdb_object', array('id' => $sid))->loadResult(); $this->oTypeName = Sobi::Txt('OTYPE_' . strtoupper($this->oType)); } switch ($this->oType) { case 'entry': $this->oName = SPFactory::Entry($sid)->get('name'); break; case 'section': $this->oName = SPFactory::Section($sid)->get('name'); break; case 'category': $this->oName = SPFactory::Category($sid)->get('name'); break; default: $this->oName = null; break; } }