Esempio n. 1
0
 /**
  * Get all parents. List is filtered only for trashed items.
  * 
  * @since 3.3.1
  * @return array relative paths of non trashed parents
  */
 public static function getNonTrashedParents($parent = '', $recurse = true, $exploded = null)
 {
     $config = JoomDOCConfig::getInstance();
     $model = JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_PREFIX);
     /* @var $model JoomDOCModelDocuments */
     $docroot = $parent === '' ? $config->docroot : JoomDOCFileSystem::getFullPath($parent);
     if ($exploded) {
         $paths = JoomDOCFileSystem::getExplodedFolders($docroot, '', $recurse, $exploded);
     } else {
         $paths = JFolder::folders($docroot, '.', $recurse, true);
     }
     // absolute paths of all folders into deep
     $paths = array_map('JPath::clean', $paths);
     foreach ($paths as &$path) {
         // add slash at the end to fix problem with asort
         $path .= DIRECTORY_SEPARATOR;
     }
     // Sort the folders again with asort like JFolder::folders
     asort($paths);
     foreach ($paths as &$path) {
         // remove slash at the end after asort
         $path = JString::substr($path, 0, JString::strlen($path) - 1);
     }
     $paths = array_map('JoomDOCFileSystem::getRelativePath', $paths);
     // convert to relative paths
     if (DIRECTORY_SEPARATOR == "\\") {
         foreach ($paths as $i => $pth) {
             $paths[$i] = str_replace($config->docroot . DIRECTORY_SEPARATOR, '', $pth);
         }
     }
     $nonTrashed = $model->getNonTrashedFiles($paths);
     // filter for trashed
     if ($parent) {
         $nonTrashed[] = $parent;
     }
     foreach ($paths as $i => $path) {
         $parent = JoomDOCFileSystem::getParentPath($path);
         if (!in_array($path, $nonTrashed) || $parent && !in_array($parent, $nonTrashed)) {
             unset($paths[$i]);
         }
         // item or parent are trashed
     }
     $paths = array_merge($paths);
     // reindexing
     natcasesort($paths);
     return $paths;
 }