/** * Get virtual path. Relative path without root folder parent path. * * @param string $path relative path to convert * @return string virtual relative path, if virtual path is turn off in menu item config return the same path as given */ public static function getVirtualPath($path) { static $virtualRootPath, $virtualRootAlias, $virtualRootPathLength, $virtualRootAliasLength; /* @var $virtualRootDepth depth of virtual folder parent */ if (is_null($virtualRootPath) && is_null($virtualRootAlias) || isset($GLOBALS['joomDOCPath'])) { $config = JoomDOCConfig::getInstance(isset($GLOBALS['joomDOCPath']) ? $GLOBALS['joomDOCPath'] : null); if ($config->virtualFolder) { $model = JModelLegacy::getInstance(JOOMDOC_DOCUMENT, JOOMDOC_MODEL_PREFIX); /* @var $model JoomDOCModelDocument */ $virtualRootPath = JoomDOCFileSystem::getRelativePath($config->path); $virtualRootAlias = $model->searchFullAliasByPath($virtualRootPath); if (is_null($virtualRootAlias)) { $virtualRootAlias = JoomDOCString::stringURLSafe($virtualRootPath); } $virtualRootPathLength = JString::strlen($virtualRootPath) + 1; $virtualRootAliasLength = JString::strlen($virtualRootAlias) + 1; } else { $virtualRootPath = $virtualRootAlias = false; } } if ($path) { if ($virtualRootPath && JString::strpos($path, $virtualRootPath) === 0) { $path = JString::substr($path, $virtualRootPathLength); } elseif ($virtualRootAlias && JString::strpos($path, $virtualRootAlias) === 0) { $path = JString::substr($path, $virtualRootAliasLength); } } return $path; }
/** * Overload the store method for the documents table. * * @param boolean Toggle whether null values should be updated. * @return boolean True on success, false on failure. * @since 1.6 */ public function store($updateNulls = false, $reindex = true) { $date = JFactory::getDate(); /* @var $date JDate current date */ $currentDate = $date->toSql(); /* @var $currentDate string current date as MySQL datetime in GMT0 */ $user = JFactory::getUser(); /* @var $user JUser current logged user */ $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ $app = JFactory::getApplication(); /* @var $app JApplication */ if ($this->id) { // for exists document store modifier $this->modified = $currentDate; $this->modified_by = $user->get('id'); } else { if (!intval($this->created)) { $this->created = $currentDate; } if (empty($this->created_by)) { $this->created_by = $user->get('id'); } // add on end in list $this->_db->setQuery('SELECT MAX(`ordering`) FROM `#__joomdoc` WHERE `parent_path` = ' . $this->_db->quote($this->parent_path)); $this->ordering = (int) $this->_db->loadResult() + 1; } // if user doesn't set alias use title if (!JString::trim($this->alias)) { $this->alias = $this->title; } // convert alias to safe string if ($app->getCfg('unicodeslugs') == 1) { $this->alias = JFilterOutput::stringURLUnicodeSlug($this->alias); } else { $this->alias = JFilterOutput::stringURLSafe($this->alias); } $this->full_alias = $this->alias; if ($this->parent_path) { // search alias of parent document $this->_db->setQuery('SELECT `full_alias` FROM `#__joomdoc` WHERE `path` = ' . $this->_db->Quote($this->parent_path) . ' ORDER BY `version` DESC', 0, 1); $parentAlias = $this->_db->loadResult(); // create full alias with parent path if (!JString::trim($parentAlias)) { // if parent alias not available use parent path $parentAlias = JoomDOCString::stringURLSafe($this->parent_path); } if (JString::trim($parentAlias)) { $this->full_alias = $parentAlias . '/' . $this->alias; } } $this->_db->setQuery('SELECT MIN(`id`) FROM `#__joomdoc` WHERE `parent_path` = ' . $this->_db->Quote($this->path) . ' GROUP BY `path`'); $cid = $this->_db->loadColumn(); if ($cid) { // update alias in child documents $query = 'SELECT `id`, `alias`, `full_alias` FROM `#__joomdoc` WHERE `id` IN (' . implode(', ', $cid) . ')'; $this->_db->setQuery($query); $childs = $this->_db->loadObjectList(); foreach ($childs as $child) { $fullAlias = $this->full_alias . '/' . $child->alias; if ($child->full_alias != $fullAlias) { $query = 'UPDATE `#__joomdoc` SET `full_alias` = ' . $this->_db->Quote($fullAlias) . ' WHERE `id` = ' . (int) $child->id; $this->_db->setQuery($query); $this->_db->query(); } } } foreach (get_object_vars($this) as $var => $val) { if ($var[0] != '_' && (is_array($val) || is_object($val))) { $registry = new JRegistry($val); $this->{$var} = $registry->toString(); } } $success = parent::store($updateNulls); if ($success && $reindex) { JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_PREFIX)->flat($this->path); } return $success; }