/** * Adds object to the pathway * @param SPDBObject $obj * @param array $site * @return void */ public function &addObjToPathway($obj, $site = array()) { if (defined('SOBI_ADM_PATH')) { return true; } $menu = JSite::getMenu()->getActive()->query; $sid = isset($menu['sid']) ? $menu['sid'] : 0; $resetPathway = false; if ($obj->get('oType') == 'entry') { $id = SPRequest::int('pid'); /** if the entry isn't linked directly in the menu */ if (!($obj->get('id') == $sid)) { /* if we didn't entered this entry via category */ if (!$id || $id == Sobi::Section() || Sobi::Cfg('entry.primary_path_always')) { $id = $obj->get('parent'); $resetPathway = true; } } else { /** ok - here is the weird thing: * When it is accessed via menu we have to force cache to create another version * because the pathway is stored in the cache * @todo find better solution for it */ $mid = true; SPFactory::registry()->set('cache_view_recreate_request', $mid)->set('cache_view_add_itemid', JSite::getMenu()->getActive()->id); return $this; } } else { $id = $obj->get('id'); } $path = SPFactory::cache()->getVar('parent_path', $id); if (!$path) { $path = SPFactory::config()->getParentPath($id, true, false, true); SPFactory::cache()->addVar($path, 'parent_path', $id); } if (count($path)) { /* skip everything above the linked sid */ $rpath = array_reverse($path); $path = array(); foreach ($rpath as $part) { if ($part['id'] == $sid) { break; } $path[] = $part; } $path = array_reverse($path); /* ^^ skip everything above the linked sid */ } $title = array(); // if there was an active menu - add its title to the browser title as well if ($sid) { $title[] = JFactory::getDocument()->getTitle(); } /** * Mon, Jul 16, 2012 * I would relay like to know why I've added the "htmlentities" call here. * The second param of the 'addItem' method is URL so there should be definitely no such thing * Related to Bug #692 */ if (count($path)) { if ($resetPathway) { /** we have to reset the J! pathway in case: * - we are entering an entry and we want to show the pathway corresponding to the main parent if of the entry * but we have also an Itemid and Joomla! set already the pathway partialy so we need to override it * It wouldn't be normally a problem but when SEF is enabled we do not have the pid so we don't know how it has been enetered */ JFactory::getApplication()->getPathway()->setPathway(array()); } foreach ($path as $data) { if (!(isset($data['name']) || isset($data['id'])) || !$data['id']) { continue; } $title[] = $data['name']; $this->addToPathway($data['name'], self::url(array('title' => Sobi::Cfg('sef.alias', true) ? $data['alias'] : $data['name'], 'sid' => $data['id']))); } } if ($obj->get('oType') == 'entry') { $this->addToPathway($obj->get('name'), self::url(array('task' => 'entry.details', 'title' => Sobi::Cfg('sef.alias', true) ? $obj->get('nid') : $obj->get('name'), 'sid' => $obj->get('id')))); $title[] = $obj->get('name'); } // if ( count( $site ) && $site[ 0 ] ) { // $title[ ] = Sobi::Txt( 'SITES_COUNTER', $site[ 1 ], $site[ 0 ] ); // } SPFactory::header()->addTitle($title, $site); return $this; }
/** * (non-PHPdoc) * @see Site/lib/models/SPDBObject#save() */ public function save($request = 'post') { $this->loadFields(Sobi::Section(), true); // Thu, Feb 19, 2015 12:12:47 - it should be actually "beforeSave" Sobi::Trigger($this->name(), 'Before' . ucfirst(__FUNCTION__), array($this->id)); /* save the base object data */ /* @var SPdb $db */ $db = SPFactory::db(); $db->transaction(); if (!$this->nid || SPRequest::task() == 'entry.clone') { $this->nid = SPRequest::string($this->nameField, null, false, $request); $this->nid = $this->createAlias(); $this->name = $this->nid; } if (Sobi::Cfg('entry.publish_limit', 0) && !defined('SOBI_ADM_PATH')) { SPRequest::set('entry_createdTime', 0, $request); SPRequest::set('entry_validSince', 0, $request); SPRequest::set('entry_validUntil', 0, $request); $this->validUntil = gmdate('Y-m-d H:i:s', time() + Sobi::Cfg('entry.publish_limit', 0) * 24 * 3600); } $preState = Sobi::Reg('object_previous_state'); parent::save($request); $nameField = $this->nameField(); /* get the fields for this section */ foreach ($this->fields as $field) { /* @var $field SPField */ try { if ($field->enabled('form', $preState['new'])) { $field->saveData($this, $request); } else { $field->finaliseSave($this, $request); } if ($field->get('id') == $nameField) { /* get the entry name */ $this->name = $field->getRaw(); /* save the nid (name id) of the field where the entry name is saved */ $this->nameField = $field->get('nid'); } } catch (SPException $x) { if (SPRequest::task() != 'entry.clone') { $db->rollback(); throw new SPException(SPLang::e('CANNOT_SAVE_FIELS_DATA', $x->getMessage())); } else { Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } } $values = array(); /* get categories */ $cats = Sobi::Reg('request_categories'); if (!count($cats)) { $cats = SPRequest::arr('entry_parent', SPFactory::registry()->get('request_categories', array()), $request); } /* by default it should be comma separated string */ if (!count($cats)) { $cats = SPRequest::string('entry_parent', null, $request); if (strlen($cats) && strpos($cats, ',')) { $cats = explode(',', $cats); foreach ($cats as $i => $cat) { $c = (int) trim($cat); if ($c) { $cats[$i] = $c; } else { unset($cats[$i]); } } } elseif (strlen($cats)) { $cats = array((int) $cats); } } if (is_array($cats) && count($cats)) { foreach ($cats as $i => $v) { if (!$v) { unset($cats[$i]); } } } if (is_array($cats) && count($cats)) { /* get the ordering in these categories */ try { $db->select('pid, MAX(position)', 'spdb_relations', array('pid' => $cats, 'oType' => 'entry'), null, 0, 0, false, 'pid'); $cPos = $db->loadAssocList('pid'); $currPos = $db->select(array('pid', 'position'), 'spdb_relations', array('id' => $this->id, 'oType' => 'entry'))->loadAssocList('pid'); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } /* set the right position */ foreach ($cats as $i => $cat) { $copy = 0; if (!$this->approved) { $copy = isset($this->categories[$cats[$i]]) ? 0 : 1; } else { $db->delete('spdb_relations', array('id' => $this->id, 'oType' => 'entry')); } if (isset($currPos[$cat])) { $pos = $currPos[$cat]['position']; } else { $pos = isset($cPos[$cat]) ? $cPos[$cat]['MAX(position)'] : 0; $pos++; } $values[] = array('id' => $this->id, 'pid' => $cats[$i], 'oType' => 'entry', 'position' => $pos, 'validSince' => $this->validSince, 'validUntil' => $this->validUntil, 'copy' => $copy); } try { $db->insertArray('spdb_relations', $values, true); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } } elseif (!count($this->categories)) { throw new SPException(SPLang::e('MISSING_CAT')); } /* trigger possible state changes */ if ($preState['approved'] != $this->approved) { if ($this->approved) { $this->approveFields(true); // it's being done by the method above - removing //Sobi::Trigger( $this->name(), 'AfterApprove', array( $this->id, $this->approved ) ); } } if ($preState['state'] != $this->state) { Sobi::Trigger($this->name(), 'AfterChangeState', array($this->id, $this->state)); } SPFactory::cache()->purgeSectionVars(); SPFactory::cache()->deleteObj('entry', $this->id); if (count($cats)) { foreach ($cats as $cat) { SPFactory::cache()->deleteObj('category', $cat); } } Sobi::Trigger($this->name(), 'After' . ucfirst($preState['new'] ? __FUNCTION__ : 'Update'), array(&$this)); }
/** * (non-PHPdoc) * @see Site/lib/models/SPDBObject#delete() * @param bool $childs - update child entries parent */ public function delete($childs = true) { parent::delete(); SPFactory::cache()->cleanSection(); SPFactory::cache()->deleteObj('category', $this->id); try { /* get all child cats and delete these too */ $childs = $this->getChilds('category', true); if (count($childs)) { foreach ($childs as $child) { $cat = new self(); $cat->init($child); $cat->delete(false); } } $childs[$this->id] = $this->id; SPFactory::db()->delete('spdb_category', array('id' => $this->id)); if ($childs) { SPFactory::db()->update('spdb_object', array('parent' => Sobi::Section()), array('parent' => $childs)); } } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_DELETE_CATEGORY_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } }
/** * Gets meta keys and met description from the given object * and adds to the site header * @param SPDBObject $obj * @return SPHeader */ public function &objMeta($obj) { if ($obj->get('metaDesc')) { $this->addDescription($obj->get('metaDesc')); } if ($obj->get('metaKeys')) { $this->addKeyword($obj->get('metaKeys')); } if ($obj->get('metaAuthor')) { $this->addAuthor($obj->get('metaAuthor')); } if ($obj->get('metaRobots')) { $this->addRobots($obj->get('metaRobots')); } if ($obj->get('oType') != 'section' && Sobi::Cfg('meta.always_add_section')) { $this->objMeta(SPFactory::currentSection()); } if ($obj->get('oType') == 'entry') { $fields = $obj->getFields(); if (count($fields)) { foreach ($fields as $field) { $this->addDescription($field->metaDesc()); $this->addKeyword($field->metaKeys()); } } } return $this; }
/** */ public function save($update = false, $init = true) { /* @var SPdb $db */ $db =& SPFactory::db(); /* check nid */ if (!$update) { $c = 1; while ($c) { /* section name id has to be unique */ try { $db->select('COUNT(nid)', 'spdb_object', array('oType' => 'section', 'nid' => $this->nid)); $c = $db->loadResult(); if ($c > 0) { $this->nid = $this->nid . '_' . rand(0, 1000); } } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } } } SPFactory::registry()->set('current_section', $this->id); $db->transaction(); parent::save(); /* case adding new section, define the default title field */ if (!$update && $init) { $field = SPFactory::Model('field', true); $fid = $field->saveNew(array('name' => 'Name', 'nid' => 'field_name', 'showIn' => 'both', 'fieldType' => 'inbox', 'enabled' => 1, 'required' => 1, 'editable' => 1, 'section' => $this->id, 'inSearch' => 1, 'searchMethod' => 'general', 'isFree' => 1, 'editLimit' => -1, 'withLabel' => 1)); $field = SPFactory::Model('field', true); $field->saveNew(array('name' => 'Category', 'nid' => 'field_category', 'showIn' => 'hidden', 'fieldType' => 'category', 'enabled' => 1, 'required' => 1, 'editable' => 1, 'section' => $this->id, 'inSearch' => 1, 'searchMethod' => 'select', 'isFree' => 1, 'editLimit' => -1, 'withLabel' => 1, 'method' => 'select', 'isPrimary' => true)); SPFactory::config()->saveCfg('entry.name_field', $fid)->saveCfg('list.entries_ordering', 'field_name')->saveCfg('template.icon_fonts_arr', array('font-awesome-3-local')); SPFactory::Controller('acl', true)->addNewRule($this->get('name'), array($this->id), array('section.access.valid', 'category.access.valid', 'entry.access.valid', 'entry.add.own', 'section.search.*'), array('visitor', 'registered'), 'Default permissions for the section "' . $this->get('name') . '"'); } /* insert relation */ try { $db->insertUpdate('spdb_relations', array('id' => $this->id, 'pid' => 0, 'oType' => 'section', 'position' => 1, 'validSince' => $this->validSince, 'validUntil' => $this->validUntil)); } catch (SPException $x) { $db->rollback(); Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } /* if there was no errors, commit the database changes */ $db->commit(); // if( !$update ) { // SPFactory::mainframe()->msg( Sobi::Txt( 'SEC.CREATED' ) ); // } SPFactory::cache()->cleanSection(); /* trigger plugins */ Sobi::Trigger('afterSave', $this->name(), array(&$this)); }