function mosReadDirectory($path, $filter = '.', $recurse = false, $fullpath = false) { $arr = array(); if (!@is_dir($path)) { return $arr; } $handle = opendir($path); while ($file = readdir($handle)) { $dir = DOCMAN_Compat::mosPathName($path . '/' . $file, false); $isDir = is_dir($dir); if ($file != "." && $file != "..") { if (preg_match("/{$filter}/", $file)) { if ($fullpath) { $arr[] = trim(DOCMAN_Compat::mosPathName($path . '/' . $file, false)); } else { $arr[] = trim($file); } } if ($recurse && $isDir) { $arr2 = DOCMAN_Compat::mosReadDirectory($dir, $filter, $recurse, $fullpath); $arr = array_merge($arr, $arr2); } } } closedir($handle); asort($arr); return $arr; }
/** * Compiles a list of installed, version 4.5+ templates * * Based on xml files found. If no xml file found the template * is ignored */ function showThemes() { global $_DOCMAN; $database = JFactory::getDBO(); $mainframe = JFactory::getApplication(); $limit = $mainframe->getCfg('list_limit'); $limit = $mainframe->getUserStateFromRequest('viewlistlimit', 'limit', $limit); $limitstart = $mainframe->getUserStateFromRequest("view{com_docman}limitstart", 'limitstart', 0); $themesBaseDir = DOCMAN_Compat::mosPathName($_DOCMAN->getPath('themes')); $rows = array(); // Read the template dir to find templates $themesDirs = DOCMAN_Compat::mosReadDirectory($themesBaseDir); $rowid = 0; // Check that the directory contains an xml file foreach ($themesDirs as $themeDir) { $path = DOCMAN_Compat::mosPathName($themesBaseDir . $themeDir); $xmlFilesInDir = DOCMAN_Compat::mosReadDirectory($path, '.xml'); foreach ($xmlFilesInDir as $xmlFile) { $rows[] =& parseXMLFile($rowid, $path . $xmlFile); $rowid++; } } $pageNav = new DOCMAN_Pagination(count($rows), $limitstart, $limit); $rows = array_slice($rows, $pageNav->limitstart, $pageNav->limit); HTML_DMThemes::showThemes($rows, $pageNav); }
/** * Compiles a list of installed, version 4.5+ templates * * Based on xml files found. If no xml file found the template * is ignored */ function showThemes() { global $database, $mainframe, $_DOCMAN; global $mosConfig_absolute_path, $mosConfig_list_limit; $limit = $mainframe->getUserStateFromRequest('viewlistlimit', 'limit', $mosConfig_list_limit); $limitstart = $mainframe->getUserStateFromRequest("view{com_docman}limitstart", 'limitstart', 0); $themesBaseDir = mosPathName($_DOCMAN->getPath('themes')); $rows = array(); // Read the template dir to find templates $themesDirs = DOCMAN_Compat::mosReadDirectory($themesBaseDir); $rowid = 0; // Check that the directory contains an xml file foreach ($themesDirs as $themeDir) { $path = mosPathName($themesBaseDir . $themeDir); $xmlFilesInDir = DOCMAN_Compat::mosReadDirectory($path, '.xml'); foreach ($xmlFilesInDir as $xmlFile) { $rows[] =& parseXMLFile($rowid, $path . $xmlFile); $rowid++; } } require_once $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php'; $pageNav = new mosPageNav(count($rows), $limitstart, $limit); $rows = array_slice($rows, $pageNav->limitstart, $pageNav->limit); HTML_DMThemes::showThemes($rows, $pageNav); }
function imageList($name, &$active, $javascript = null, $directory = null) { if (!$javascript) { $javascript = "onchange=\"javascript:if (document.adminForm." . $name . ".options[selectedIndex].value!='') {document.imagelib.src='../images/stories/' + document.adminForm." . $name . ".options[selectedIndex].value} else {document.imagelib.src='../images/blank.png'}\""; } if (!$directory) { $directory = '/images/stories'; } $imageFiles = DOCMAN_Compat::mosReadDirectory(JPATH_ROOT . $directory); $images = array(JHTML::_('select.option', '', _DML_SELECTIMAGE)); foreach ($imageFiles as $file) { if (eregi("bmp|gif|jpg|png", $file)) { $images[] = JHTML::_('select.option', $file); } } $images = JHTML::_('select.genericlist', $images, $name, 'id="' . $name . '" class="inputbox" size="1" ' . $javascript, 'value', 'text', $active); return $images; }
/** * Count the number of files in the data folder */ function cntFiles() { global $_DOCMAN; $files = DMInstallHelper::getDefaultFiles(); $dir = DOCMAN_Compat::mosReadDirectory($_DOCMAN->getCfg('dmpath')); return count(array_diff($dir, $files)); }
function editDocument($uid) { require_once JPATH_ADMINISTRATOR . "/components/com_docman/classes/DOCMAN_utils.class.php"; require_once JPATH_ADMINISTRATOR . "/components/com_docman/classes/DOCMAN_params.class.php"; global $_DOCMAN, $_DMUSER; $database = JFactory::getDBO(); $my = JFactory::getUser(); $mainframe = JFactory::getApplication(); // disable the main menu to force user to use buttons $_REQUEST['hidemainmenu'] = 1; //@TODO :: Needs to be tested //$uploaded_file = mosGetParam(DOCMAN_Utils::stripslashes($_REQUEST), "uploaded_file", ""); $uploaded_file = JRequest::getString('uploaded_file', ''); $doc = new mosDMDocument($database); if ($uid) { $doc->load($uid); if ($doc->checked_out) { if ($doc->checked_out != $my->id) { $mainframe->redirect("index.php?option={$option}", _DML_THE_MODULE . " {$row->title} " . _DML_IS_BEING); } } else { // check out document... $doc->checkout($my->id); } } else { $doc->init_record(); } // Begin building interface information... $lists = array(); $lists['document_url'] = ''; //make sure $lists['original_dmfilename'] = $doc->dmfilename; if (strcasecmp(substr($doc->dmfilename, 0, _DM_DOCUMENT_LINK_LNG), _DM_DOCUMENT_LINK) == 0) { $lists['document_url'] = substr($doc->dmfilename, _DM_DOCUMENT_LINK_LNG); $doc->dmfilename = _DM_DOCUMENT_LINK; } // category select list $options = array(JHTML::_('select.option', '0', _DML_SELECT_CAT)); $lists['catid'] = dmHTML::categoryList($doc->catid, "", $options); // check if we have at least one category defined $database->setQuery("SELECT id " . "\n FROM #__categories " . "\n WHERE section='com_docman'", 0, 1); if (!($checkcats = $database->loadObjectList())) { $mainframe->redirect("index.php?option=com_docman§ion=categories", _DML_PLEASE_SEL_CAT); } // select lists $lists['approved'] = JHTML::_('select.booleanlist', 'approved', 'class="inputbox"', $doc->approved); $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $doc->published); // licenses list $database->setQuery("SELECT id, name " . "\n FROM #__docman_licenses " . "\n ORDER BY name ASC"); $licensesTemp = $database->loadObjectList(); $licenses[] = JHTML::_('select.option', '0', _DML_NO_LICENSE); foreach ($licensesTemp as $licensesTemp) { $licenses[] = JHTML::_('select.option', $licensesTemp->id, $licensesTemp->name); } $lists['licenses'] = JHTML::_('select.genericlist', $licenses, 'dmlicense_id', 'class="inputbox" size="1"', 'value', 'text', $doc->dmlicense_id); // licenses display list $licenses_display[] = JHTML::_('select.option', '0', _DML_NO); $licenses_display[] = JHTML::_('select.option', '1', _DML_YES); $lists['licenses_display'] = JHTML::_('select.genericlist', $licenses_display, 'dmlicense_display', 'class="inputbox" size="1"', 'value', 'text', $doc->dmlicense_display); if ($uploaded_file == '') { // Create docs List $dm_path = $_DOCMAN->getCfg('dmpath'); $fname_reject = $_DOCMAN->getCfg('fname_reject'); $docFiles = DOCMAN_Compat::mosReadDirectory($dm_path); $docs = array(JHTML::_('select.option', '', _DML_SELECT_FILE)); $docs[] = JHTML::_('select.option', _DM_DOCUMENT_LINK, _DML_LINKED); if (count($docFiles) > 0) { foreach ($docFiles as $file) { if (substr($file, 0, 1) == '.') { continue; } //ignore files starting with . if (@is_dir($dm_path . '/' . $file)) { continue; } //ignore directories if ($fname_reject && preg_match("/^(" . $fname_reject . ")\$/i", $file)) { continue; } //ignore certain filenames if (preg_match("/^(" . _DM_FNAME_REJECT . ")\$/i", $file)) { continue; } //ignore certain filenames //$query = "SELECT * FROM #__docman WHERE dmfilename='" . $database->getEscaped($file) . "'"; //$database->setQuery($query); //if (!($result = $database->query())) { // echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n"; //} //if ($database->getNumRows($result) == 0 || $doc->dmfilename == $file) { $docs[] = JHTML::_('select.option', $file); //} } //end foreach $docsFiles } if (count($docs) < 1) { $mainframe->redirect("index.php?option={$option}&task=upload", _DML_YOU_MUST_UPLOAD); } $lists['dmfilename'] = JHTML::_('select.genericlist', $docs, 'dmfilename', 'class="inputbox" size="1"', 'value', 'text', $doc->dmfilename); } else { // uploaded_file isn't blank $filename = split("\\.", $uploaded_file); $row->dmname = $filename[0]; $docs = array(JHTML::_('select.option', $uploaded_file)); $lists['dmfilename'] = JHTML::_('select.genericlist', $docs, 'dmfilename', 'class="inputbox" size="1"', 'value', 'text', $doc->dmfilename); } // endif uploaded_file // permissions lists $lists['viewer'] = dmHTML::viewerList($doc, 'dmowner'); $lists['maintainer'] = dmHTML::maintainerList($doc, 'dmmantainedby'); // updater user information $last = array(); if ($doc->dmlastupdateby > '0' && $doc->dmlastupdateby != $my->id) { $database->setQuery("SELECT id, name FROM #__users WHERE id=" . (int) $doc->dmlastupdateby); $last = $database->loadObjectList(); } else { $last[0]->name = $my->name ? $my->name : $my->username; } // "Super Administrator" // creator user information $created = array(); if ($doc->dmsubmitedby > '0' && $doc->dmsubmitedby != $my->id) { $database->setQuery("SELECT id, name FROM #__users WHERE id=" . (int) $doc->dmsubmitedby); $created = $database->loadObjectList(); } else { $created[0]->name = $my->name ? $my->name : $my->username; } // "Super Administrator" // Imagelist $lists['image'] = dmHTML::imageList('dmthumbnail', $doc->dmthumbnail); // Params definitions $params_path = JPATH_ADMINISTRATOR . '/components/com_docman/docman.params.xml'; if (file_exists($params_path)) { $params =& new dmParameters($doc->attribs, $params_path, 'params'); } /* ------------------------------ * * MAMBOT - Setup All Mambots * * ------------------------------ */ $prebot = new DOCMAN_mambot('onBeforeEditDocument'); $prebot->setParm('document', $doc); $prebot->setParm('filename', $filename); $prebot->setParm('user', $_DMUSER); if (!$uid) { $prebot->copyParm('process', 'new document'); } else { $prebot->copyParm('process', 'edit document'); } $prebot->trigger(); if ($prebot->getError()) { $mainframe->redirect("index.php?option=com_docman§ion=documents", $prebot->getErrorMsg()); } HTML_DMDocuments::editDocument($doc, $lists, $last, $created, $params); }
/** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_filelist($name, $value, &$node, $control_name) { // path to images directory $path = JPATH_ROOT . DS . $node->getAttribute('directory'); $filter = $node->getAttribute('filter'); $files = DOCMAN_Compat::mosReadDirectory($path, $filter); $options = array(); foreach ($files as $file) { $options[] = JHTML::_('select.option', $file, $file); } if (!$node->getAttribute('hide_none')) { array_unshift($options, JHTML::_('select.option', '-1', '- ' . 'Do Not Use' . ' -')); } if (!$node->getAttribute('hide_default')) { array_unshift($options, JHTML::_('select.option', '', '- ' . 'Use Default' . ' -')); } return JHTML::_('select.genericlist', $options, '' . $control_name . '[' . $name . ']', 'class="inputbox"', 'value', 'text', $value, "param{$name}"); }
/** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_filelist($name, $value, &$node, $control_name) { global $mosConfig_absolute_path; // path to images directory $path = $mosConfig_absolute_path . $node->getAttribute('directory'); $filter = $node->getAttribute('filter'); $files = DOCMAN_Compat::mosReadDirectory($path, $filter); $options = array(); foreach ($files as $file) { $options[] = mosHTML::makeOption($file, $file); } if (!$node->getAttribute('hide_none')) { array_unshift($options, mosHTML::makeOption('-1', '- ' . 'Do Not Use' . ' -')); } if (!$node->getAttribute('hide_default')) { array_unshift($options, mosHTML::makeOption('', '- ' . 'Use Default' . ' -')); } return mosHTML::selectList($options, '' . $control_name . '[' . $name . ']', 'class="inputbox"', 'value', 'text', $value, "param{$name}"); }
/** * Tries to find the package XML file * @return boolean True on success, False on error */ function findInstallFile() { $found = false; // Search the install dir for an xml file $files = DOCMAN_Compat::mosReadDirectory($this->installDir(), '.xml$', true, true); if (count($files) > 0) { foreach ($files as $file) { $packagefile = $this->isPackageFile($file); if (!is_null($packagefile) && !$found) { $this->xmlDoc($packagefile); return true; } } $this->setError(1, 'ERROR: Could not find a Joomla! XML setup file in the package.'); return false; } else { $this->setError(1, 'ERROR: Could not find a Joomla! XML setup file in the package.'); return false; } }