/** * Get path paremeter from request. Test if parameter is relative path or document alias. * Test if path is virtual path. * * @param string $path path to control, if null use param path from request * @return string */ public static function getPath($path = null) { static $model; /* @var $model JoomDOCModelDocument */ $mainframe = JFactory::getApplication(); /* @var $mainframe JApplication (JSite or JAdministrator) */ if ($mainframe->isSite() && is_null($model)) { $model = JModelLegacy::getInstance(JOOMDOC_DOCUMENT, JOOMDOC_MODEL_PREFIX); } // get root path from request or config if (!$path) { $path = JString::trim(JRequest::getString('path')); } $path = JoomDOCString::urldecode($path); // frontend if ($mainframe->isSite()) { // path from request can be document full alias - search for path in document table $candidate = $model->searchRelativePathByFullAlias($path); if ($candidate) { $path = $candidate; } else { // if request param is path convert from virtual to full relative path $path = JoomDOCFileSystem::getNonVirtualPath($path); } } else { // backend $path = $mainframe->getUserStateFromRequest(JoomDOCRequest::getSessionPrefix() . 'path', 'path', '', 'string'); if ($path == JText::_('JOOMDOC_ROOT')) { return ''; } } $path = str_replace('/', DIRECTORY_SEPARATOR, $path); //windows if ($path) { $path = JPath::clean($path); } return $path; }
$url = JoomDOCRoute::viewDocuments($access->relativePath, $access->alias); } elseif ($moduleConfig->link_type == 'download' && $access->canDownload) { // download link is displayed only if file can be download in ACL setting $url = JoomDOCRoute::download($access->relativePath, $access->alias); } else { $url = null; } if ($url) { echo '<a href="' . JRoute::_($url) . '" title="">' . ($access->docid ? $item->document->title : $item->getFileName()) . '</a>'; } else { // Name is displayed as document title or file path. echo $access->docid ? $item->document->title : $item->getFileName(); } if ($moduleConfig->show_filesize) { echo '<strong>' . JText::sprintf('JOOMDOC_MODULE_FILESIZE', JoomDOCFileSystem::getFileSize($access->absolutePath)) . '</strong>'; } if ($moduleConfig->show_listfields) { echo '<table class="fields"><tbody>'; foreach ($listFields as $field) { if ($value = JHtml::_('joomdoc.showfield', $field, $item->document)) { echo '<tr><th>' . $field->title . ':</th><td>' . $value . '</td></tr>'; } } echo '</tbody></table>'; } if ($moduleConfig->show_text && $access->docid && ($description = JString::trim($item->document->description))) { echo '<p>' . JoomDOCString::crop($description, $moduleConfig->crop_length) . '</p>'; } echo '</li>'; } echo '</ul></div>';
/** * 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; }
/** * Get URL to untrash file. * * @param string $path * @return string */ public static function untrash($path) { return 'index.php?option=' . JOOMDOC_OPTION . '&task=' . JoomDOCHelper::getTask(JOOMDOC_FILE, JOOMDOC_TASK_UNTRASH) . '&path=' . JoomDOCString::urlencode($path); }
$prefixLength = JString::strlen($prefix); $this->root->initIteration(); $i = 0; while ($this->root->hasNext()) { $item = $this->root->getNext(); $access = new JoomDOCAccessHelper($item); echo '<tr class="row' . $i % 2 . '">'; echo '<td>'; // backspashes doing bad in js pass $id = str_replace(DIRECTORY_SEPARATOR, '/', $this->escape($access->relativePath)); $title = $this->escape($access->docid ? $item->document->title : str_replace(DIRECTORY_SEPARATOR, '/', $access->relativePath)); $url = JRoute::_($linkType == JOOMDOC_LINK_TYPE_DOWNLOAD && $access->isFile ? JoomDOCRoute::download(str_replace(DIRECTORY_SEPARATOR, '/', $access->relativePath), $access->alias) : JoomDOCRoute::viewDocuments(str_replace(DIRECTORY_SEPARATOR, '/', $access->relativePath), $access->alias)); if (JString::strpos($url, $prefix) === 0) { $url = JString::substr($url, $prefixLength); } echo '<a href="javascript:window.parent.jSelectJoomdocDocument(\'' . addslashes(JoomDOCString::dsEncode($id)) . '\', \'' . addslashes($title) . '\', \'' . addslashes($url) . '\')" class="hasTip addDocument" title="' . $this->getTooltip('JOOMDOC_SET_DOCUMENT') . '"></a>'; if ($access->isFolder) { echo '<a class="hasTip folder" href="' . JRoute::_(JoomDOCRoute::modalDocuments($access->relativePath, $useLinkType, $addSymLink, $symLinkSource)) . '" title="' . $this->getTooltip($access->relativePath, 'JOOMDOC_DOCUMENTS_OPEN_FOLDER') . '">' . $this->escape($access->name) . '</a>'; } else { echo '<span class="file">' . $this->escape($access->name) . '</span>'; } echo '</td>'; echo '<td>' . ($access->docid ? $this->escape($item->document->title) : '-') . '</td>'; echo '</tr>'; $i++; } if ($i === 0) { echo '<tr><td>This folder contains no items.</td></tr>'; } else { echo ''; }
echo '<span class="modified">' . JText::sprintf('JOOMDOC_MODIFIED', JHtml::date($item->document->modified, JText::_('JOOMDOC_UPLOADED_DATE_J16'))) . '</span>'; } } if ($config->showHits && !$access->isFolder) { echo '<span class="hits">' . JText::sprintf('JOOMDOC_HITS_INFO', JoomDOCHelper::number($item->hits)) . '</span>'; } foreach ($this->listfields as $field) { if ($value = JHtml::_('joomdoc.showfield', $field, $item->document)) { echo '<span class="field">' . $field->title . ': ' . $value . '</span>'; } } echo '<div class="clr"></div>'; echo '</div>'; } if ($access->docid && ($description = JString::trim($item->document->description)) && ($this->access->canShowAllDesc || $access->isFolder && $config->showFolderDesc || $access->isFile && $config->showFileDesc)) { echo '<p>' . JoomDOCString::crop($description, 200) . '</p>'; } if ($config->showLicense && $access->licenseID && $access->isFile) { echo '<a class="modal license" rel="{handler: \'iframe\', size: {x: 800, y: 600}, onClose: function() {}}" href="' . JoomDOCRoute::viewLicense($access->licenseID, $access->licenseAlias) . '">' . JText::sprintf('JOOMDOC_ITEM_LICENSE', $access->licenseTitle) . '</a>'; } if ($access->canOpenFolder || $access->canOpenFile || $access->canDeleteDoc || $access->canEdit || $access->canCreate || $access->canDeleteFile || $access->canDownload) { echo '<div class="toolbar">'; if ($config->showOpenFolder && $access->isFolder) { echo '<a class="open" href="' . $viewDocuments . '" title="">' . JText::_('JOOMDOC_DISPLAY_FOLDER') . '</a>'; } if ($config->showOpenFile && $access->isFile) { echo '<a class="open" href="' . $viewDocuments . '" title="">' . JText::_('JOOMDOC_DISPLAY_FILE') . '</a>'; } if ($config->showDownloadFile && $access->canDownload) { if ($access->licenseID) { echo '<a class="modal download" rel="{handler: \'iframe\', size: {x: ' . JOOMDOC_LIGHTBOX_WIDTH . ', y: ' . JOOMDOC_LIGHTBOX_HEIGHT . '}, onClose: function() {}}" href="' . JoomDOCRoute::viewLicense($access->licenseID, $access->licenseAlias, $access->relativePath, $access->alias) . '">' . JText::_('JOOMDOC_DOWNLOAD_FILE') . '</a>';
/** * 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; }