function showListview() { global $_DOCMAN; $assets = JURI::root() . "components/com_docman/assets"; // add styles and scripts $doc =& JFactory::getDocument(); JHTML::_('behavior.mootools'); $doc->addStyleSheet($assets . '/css/doclink.css'); $doc->addScript($assets . '/js/sortabletable.js'); $doc->addScript($assets . '/js/listview.js'); if (isset($_REQUEST['catid'])) { $cid = intval($_REQUEST['catid']); } else { $cid = 0; } //get folders $cats = DOCMAN_Cats::getChildsByUserAccess($cid); //get items if ($cid) { $docs = DOCMAN_Docs::getDocsByUserAccess($cid, 'name', 'ASC', 999, 0); } else { $docs = array(); } //if ($entries_cnt) HTML_DMDoclink::createHeader(); HTML_DMDoclink::createFolders($cats, $cid); HTML_DMDoclink::createItems($docs, $cid); HTML_DMDoclink::createFooter(); }
function DocmanBuildRoute(&$query) { jimport('joomla.filter.output'); $segments = array(); // check for task=... if (!isset($query['task'])) { return $segments; } $segments[] = $query['task']; // check for gid=... $gid = isset($query['gid']) ? $query['gid'] : 0; if (in_array($query['task'], array('cat_view', 'upload'))) { // create the category slugs $cats =& DOCMAN_Cats::getCategoryList(); $cat_slugs = array(); while ($gid and isset($cats[$gid])) { $cat_slugs[] = $gid . ':' . JFilterOutput::stringURLSafe($cats[$gid]->name); $gid = $cats[$gid]->parent_id; } $segments = array_merge($segments, array_reverse($cat_slugs)); } else { // create the document slug $doc = DocmanRouterHelper::getDoc($gid); if ($doc->id) { $segments[] = $gid . ':' . JFilterOutput::stringURLSafe($doc->dmname); } } unset($query['gid']); unset($query['task']); return $segments; }
function fetchCategoryList($id) { global $_DOCMAN, $_DMUSER; $children = DOCMAN_Cats::getChildsByUserAccess($id); $items = array(); foreach ($children as $child) { $cat = new DOCMAN_Category($child->id); // process content mambots DOCMAN_Utils::processContentBots($cat, 'description'); $item = new StdClass(); $item->links =& $cat->getLinkObject(); $item->paths =& $cat->getPathObject(); $item->data =& $cat->getDataObject(); $items[] = $item; } // display the entries return HTML_DMCategories::displayCategoryList($items); }
function getLinks($args) { global $_DOCMAN, $mainframe; $wf = WFEditorPlugin::getInstance(); jimport('joomla.filesystem.file'); require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_docman' . DS . 'docman.class.php'; //DOCMan core interaction API $_DOCMAN = new dmMainFrame(_DM_TYPE_DOCLINK); // Load classes and language require_once $_DOCMAN->getPath('classes', 'utils'); $cid = isset($args->gid) ? $args->gid : 0; //get folders $categories = DOCMAN_Cats::getChildsByUserAccess($cid); $items = array(); $view = isset($args->view) ? $args->view : ''; switch ($view) { default: foreach ($categories as $category) { $items[] = array('id' => 'index.php?option=com_docman&view=category&gid=' . $category->id . WFLinkBrowser::getItemId('com_docman'), 'name' => $category->name, 'class' => 'folder docmanlinks'); } break; case 'category': //get items if ($cid) { $categories = DOCMAN_Cats::getChildsByUserAccess($cid); $documents = DOCMAN_Docs::getDocsByUserAccess($cid, 'name', 'ASC', 999, 0); } else { $categories = array(); $documents = array(); } foreach ($categories as $category) { $items[] = array('id' => 'index.php?option=com_docman&view=category&gid=' . $category->id . WFLinkBrowser::getItemId('com_docman'), 'name' => $category->name, 'class' => 'folder docmanlinks'); } foreach ($documents as $document) { $items[] = array('id' => 'index.php?option=com_docman&task=doc_' . $wf->getParam('docmanlinks_link', 'download') . '&gid=' . $document->id . WFLinkBrowser::getItemId('com_docman'), 'name' => $document->dmname, 'class' => 'file docmanlinks ' . JFile::getExt($document->dmfilename)); } break; } return $items; }
function getAncestorsRecurse($id, &$cats, &$ancestors) { $cat = new StdClass(); $cat->name = $cats[$id]->name; $cat->title = $cats[$id]->title; $sef = defined('_DM_J15') ? false : true; $cat->link = DOCMAN_Utils::taskLink('cat_view', $id, null, $sef); $ancestors[] =& $cat; $id = $cats[$id]->parent; if ($id != 0) { DOCMAN_Cats::getAncestorsRecurse($id, $cats, $ancestors); } }
function _format(&$objDBCat) { global $_DOCMAN; $user = $_DOCMAN->getUser(); // format category data $this->objFormatData = DOCMAN_Utils::get_object_vars($objDBCat); $this->objFormatData->files = DOCMAN_Cats::countDocsInCatByUser($objDBCat->id, $user, true); // format category links $this->objFormatLink->view = $this->_formatLink('cat_view'); // format category paths $this->objFormatPath->thumb = DOCMAN_Utils::pathThumb($objDBCat->image); $this->objFormatPath->icon = DOCMAN_Utils::pathIcon('folder.png', 1); }
function fetchPageTitle($id) { if (!$id > 0) { return; } // get the category ancestors $ancestors =& DOCMAN_Cats::getAncestors($id); // reverse the array $ancestors = array_reverse($ancestors); // display the pathway return HTML_docman::fetchPageTitle($ancestors); }
/** * * @desc This function performs a generic search * against the database. Originaly from the mambot * but enhanced for wider searches * @param array $ of arrays $searchArray The lists of what to search for * i.e.: array( array( 'phrase'=>'search phrases', mode=>'exact'), * array( 'phrase=>'..... * Currently only uses the FIRST array request. (FUTURE: multiples) * @param string $ The ordering of the results (newest...etc). * Prefix with a '-' to reverse the ordering. * @param int $ the categories to search for (0=all) * @param mixed $ Either an array of terms to return or '*' * (Array is 'column-name' => 'return name'.) * @param array $ List of options for searching * * NOTE: We are NOT assured that we have $_DOCMAN and all the other goodies. * (we may be just from mambot) */ function search(&$searchArray, $ordering = '', $cats = '', array $columns = array(), $options = array()) { global $_DOCMAN; $my = JFactory::getUser(); $database = JFactory::getDBO(); $_DMUSER = $_DOCMAN->getUser(); $searchterms = array_pop($searchArray); // Only do one (for now) if (empty($options)) { $options = array('search_name', 'search_description'); } if ($ordering == '') { $ordering = 'newest'; } $registered = $_DOCMAN->getCfg('registered'); $perpage = $_DOCMAN->getCfg('perpage'); $authorCan = $_DOCMAN->getCfg('author_can', '9999'); $userid = intval($my->id); $isAdmin = $_DMUSER->isAdmin; // ------------------------------------- // Fetch the search options. Passed in options array // ------------------------------------- $search_col = array(); if (is_array($options)) { if (in_array('search_name', $options)) { $search_col[] = 'DM.dmname '; } if (in_array('search_description', $options) || in_array('search_desc', $options)) { $search_col[] = 'DM.dmdescription '; } if (in_array('search_cat', $options)) { $search_col[] = "CAT.title "; $search_col[] = "CAT.name "; $search_col[] = "SUB.title "; $search_col[] = "SUB.name "; } } if (count($search_col) == 0) { return array(); // Have to search SOMETHING! } // BUILD QUERY PARTS $search_mode = $searchterms['search_mode']; $text = trim($searchterms['search_phrase']); if (!$text) { return array(); } // (1) Format search 'phrase' into SQL $invert = false; if (substr($search_mode, 0, 1) == '-') { $invert = true; $search_mode = substr($search_mode, 1); } $wheres = array(); switch ($search_mode) { case 'exact': foreach ($search_col as $col) { $wheres[] = $col . "LIKE '%" . $database->getEscaped($text, true) . "%'"; } $where = '(' . implode(') OR (', $wheres) . ')'; break; case 'any': // Fall through for regex $text = implode('|', explode(' ', $text)); case 'regex': foreach ($search_col as $col) { $wheres[] = $col . "RLIKE '" . $database->getEscaped($text, true) . "'"; } $where = '(' . implode(' OR ', $wheres) . ')'; break; case 'all': default: $words = explode(' ', $text); foreach ($search_col as $col) { $wheres2 = array(); foreach ($words as $word) { $wheres2[] = $col . "LIKE '%" . $database->getEscaped($word, true) . "%'"; } $wheres[] = implode(' AND ', $wheres2); } $where = '(' . implode(') OR (', $wheres) . ')'; break; } if ($invert) { $where = 'NOT ( ' . $where . ')'; } // DEBUG: // echo "<pre>WHERE is: $where</pre>"; // (2) Create the 'ORDER BY' section based on user request $_DM_SEARCH_SORT_ORDER = array('newest' => 'DM.dmlastupdateon DDD', 'oldest' => 'DM.dmlastupdateon AAA', 'popular' => 'DM.dmcounter DDD', 'alpha' => 'DM.dmname AAA', 'category' => 'CAT.title AAA, SUB.title AAA, DM.dmname AAA'); $_DM_SEARCH_PATTERN = array('/DDD/', '/AAA/'); $invert = false; if (substr($ordering, 0, 1) == '-') { $ordering = substr($ordering, 1); $invert = true; } $order = $_DM_SEARCH_SORT_ORDER[$ordering]; if ($invert) { $order = preg_replace($_DM_SEARCH_PATTERN, array('ASC', 'DESC'), $order); } else { $order = preg_replace($_DM_SEARCH_PATTERN, array('DESC', 'ASC'), $order); } // (3) SQL WHERE portion based on user access priviledges if ($isAdmin) { $user_filter = " (SUB.access=" . _DM_ACCESS_PUBLIC . " OR SUB.access=" . _DM_ACCESS_REGISTERED . " OR SUB.access=" . _DM_ACCESS_SPECIAL . ")"; } else { if ($userid > 0) { // Logged IN $user_groups = $_DMUSER->getGroupsIn(); $user_filter = "(" . "\n DM.dmowner=" . _DM_PERMIT_EVERYONE . "\n OR DM.dmowner=" . _DM_PERMIT_REGISTERED . "\n OR DM.dmowner=" . $userid . "\n OR DM.dmowner IN ({$user_groups}) " . "\n OR DM.dmmantainedby=" . $userid . "\n OR DM.dmmantainedby IN ({$user_groups}) "; if ($authorCan > 0) { $user_filter .= "\n OR DM.dmsubmitedby = {$userid}"; } $user_filter .= ")" . "\n AND (SUB.access=" . _DM_ACCESS_PUBLIC . "\n OR SUB.access=" . _DM_ACCESS_REGISTERED; if ($_DMUSER->isSpecial) { $user_filter .= "\n OR SUB.access=" . _DM_ACCESS_SPECIAL; } $user_filter .= ")"; } else { // NOT logged in $user_filter = " DM.dmowner=" . _DM_PERMIT_EVERYONE . "\n AND SUB.access=" . _DM_ACCESS_PUBLIC; } // endif $userid } // endif isAdmin // (4)Build up the category list (if they selected it) if ($cats != '' && $cats != 0) { // check to see if category has `child categories` $cat_list = DOCMAN_Cats::getChilds($cats); // if category has `child categories` then add ids of `child categories` to category list if (count($cat_list) != 0) { $cats = $cat_list; } $user_filter .= "\n AND DM.catid "; if (is_array($cats)) { $user_filter .= 'IN (' . implode(',', $cats) . ')'; } else { $user_filter .= "= {$cats}"; } } // (5) Build up list of columns to return $list = array(); foreach ($columns as $key => $value) { $list[] = "\n\t{$key} AS {$value}"; } if (!count($list)) { $list[] = "\n\t*"; } $list_terms = implode(',', $list); $list_terms .= strlen($list_terms) ? ', ' : ''; $list_terms .= 'DM.* , DM.catid AS docman_catid'; // (*) Build final query for SQL lookup $query = "SELECT {$list_terms} " . "\nFROM #__docman AS DM " . "\nLEFT JOIN #__categories AS SUB ON SUB.id = DM.catid" . "\nLEFT JOIN #__categories AS CAT ON CAT.id = SUB.parent_id" . "\nWHERE {$user_filter} " . "\n AND DM.published=1 AND DM.approved=1" . "\n AND ({$where}) " . "\nORDER BY {$order}"; // TODO: add proper pagination instead of hardcoded limit? $database->setQuery($query, 0, 50); $rows = $database->loadObjectList(); $cache = array(); // Fill in the correct sections for ($r = 0; $r < count($rows); $r++) { $rows[$r]->section = @$options['section_prefix'] . DOCMAN_Docs::_dmSearchSection($rows[$r]->catid, $cache, '/') . @$options['section_suffix']; } // FINAL SORT: // We couldn't sort by category until now (we didn't HAVE a category) if ($order == 'category') { if ($invert) { usort($rows, create_function("{$a},{$b}", "return strcasecmp({$a->section} . {$a->dmname} , {$b->section} . {$b->dmname});")); } else { usort($rows, create_function("{$a},{$b}", "return strcasecmp({$b->section} . {$b->dmname} , {$a->section} . {$a->dmname});")); } } return $rows; }
function &getInstance($id = 0) { global $database; static $instances = array(); if (!$id) { $new = new mosDMCategory($database); return $new; } if (!isset($instances[$id])) { $instances[$id] = new mosDMCategory($database); //$instances[$id]->load( $id ); // instead of loading, we'll use the the following method to improve performance $list =& DOCMAN_Cats::getCategoryList(); // get a list of categories, $list[$id] is our current category $instances[$id]->bind((array) $list[$id]); // assign each property of the category to the category object } return $instances[$id]; }