diff --git a/code/AssetAdmin.php b/code/AssetAdmin.php index ad60ce40..f84a6021 100755 --- a/code/AssetAdmin.php +++ b/code/AssetAdmin.php @@ -255,58 +255,14 @@ HTML; return singleton('File'); } } - - /** - * Return the entire site tree as a nested UL. - * @return string HTML for site tree - */ + public function SiteTreeAsUL() { - $obj = singleton('Folder'); - $obj->setMarkingFilter('ClassName', ClassInfo::subclassesFor('Folder')); - $obj->markPartialTree(30, null, "ChildFolders"); - - if($p = $this->currentPage()) $obj->markToExpose($p); - - // getChildrenAsUL is a flexible and complex way of traversing the tree - $siteTreeList = $obj->getChildrenAsUL( - '', - '"
  • ID\" class=\"$child->class" . $child->markingClasses() . ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' . - '"Link(),0,-1), "show", $child->ID) . "\" class=\"" . ($child->hasChildFolders() ? " contents" : "") . "\" >" . $child->TreeTitle . "" ', - $this, - true, - "ChildFolders" - ); - - // Wrap the root if needs be - $rootLink = $this->Link() . 'show/root'; - $baseUrl = Director::absoluteBaseURL() . "assets"; - if(!isset($rootID)) { - $siteTree = ""; - } - - return $siteTree; - } - - /** - * Returns a subtree of items underneat the given folder. - */ - public function getsubtree() { - $obj = DataObject::get_by_id('Folder', $_REQUEST['ID']); - $obj->setMarkingFilter('ClassName', ClassInfo::subclassesFor('Folder')); - $obj->markPartialTree(); - - $results = $obj->getChildrenAsUL( - '', - '"
  • ID\" class=\"$child->class" . $child->markingClasses() . ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' . - '"Link(),0,-1), "show", $child->ID) . "\" >" . $child->TreeTitle . "" ', - $this, - true - ); - - return substr(trim($results), 4, -5); + return $this->getSiteTreeFor($this->stat('tree_class'), null, 'ChildFolders'); } + public function getCMSTreeTitle() { + return Director::absoluteBaseURL() . "assets"; + } //------------------------------------------------------------------------------------------// @@ -319,7 +275,8 @@ HTML; $form = new Form( $this, 'SyncForm', - new FieldSet(), + new FieldSet( + ), new FieldSet( $btn = new FormAction('doSync', _t('FILESYSTEMSYNC','Look for new files')) ) diff --git a/code/CMSMain.php b/code/CMSMain.php index 2db5b60d..64217f86 100755 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -50,7 +50,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr 'AddForm', 'SiteTreeAsUL', 'getshowdeletedsubtree', - 'getfilteredsubtree', 'SearchTreeForm', 'ReportForm', 'LangForm', @@ -132,30 +131,11 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr Versioned::prepopulate_versionnumber_cache("SiteTree", "Stage"); Versioned::prepopulate_versionnumber_cache("SiteTree", "Live"); - return $this->getSiteTreeFor("SiteTree"); + return $this->getSiteTreeFor($this->stat('tree_class')); } - /** - * Use a CMSSiteTreeFilter to only get certain nodes - * - * @return string - */ - public function getfilteredsubtree($data, $form) { - $params = $form->getData(); - - // Get the tree - $tree = $this->getSiteTreeFor( - $this->stat('tree_class'), - $data['ID'], - null, - array(new CMSMainMarkingFilter($params), 'mark') - ); - - // Trim off the outer tag - $tree = ereg_replace('^[ \t\r\n]*]*>','', $tree); - $tree = ereg_replace(']*>[ \t\r\n]*$','', $tree); - - return $tree; + protected function getMarkingFilter($params) { + return new CMSMainMarkingFilter($params); } public function generateDataTreeHints() { @@ -186,7 +166,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr } public function generateTreeStylingJS() { - $classes = ClassInfo::subclassesFor('SiteTree'); + $classes = ClassInfo::subclassesFor($this->stat('tree_class')); foreach($classes as $class) { $obj = singleton($class); if($obj instanceof HiddenClass) continue; @@ -1114,7 +1094,7 @@ JS; _t('CMSMain_left.ss.CLEAR', 'Clear') ), new FormAction( - 'getfilteredsubtree', + 'doSearchTree', _t('CMSMain_left.ss.SEARCH', 'Search') ) ) @@ -1123,6 +1103,10 @@ JS; return $form; } + + function doSearchTree($data, $form) { + return $this->getsubtree($this->request); + } function publishall() { ini_set("memory_limit", -1); @@ -1357,24 +1341,12 @@ JS; } } -class CMSMainMarkingFilter { - - /** - * @var array Request params (unsanitized) - */ - protected $params = array(); - - /** - * @param array $params Request params (unsanitized) - */ - function __construct($params = null) { - $this->ids = array(); - $this->expanded = array(); - $this->params = $params; - +class CMSMainMarkingFilter extends LeftAndMainMarkingFilter{ + + protected function getQuery($params) { $where = array(); - $SQL_params = Convert::raw2sql($this->params); + $SQL_params = Convert::raw2sql($params); foreach($SQL_params as $name => $val) { switch($name) { // Match against URLSegment, Title, MenuTitle & Content @@ -1402,38 +1374,13 @@ class CMSMainMarkingFilter { } } - $where = empty($where) ? '' : 'WHERE (' . implode(') AND (',$where) . ')'; - - $parents = array(); - - /* Do the actual search */ - $res = DB::query('SELECT "ParentID", "ID" FROM "SiteTree" '.$where); - if (!$res) return; - - /* And keep a record of parents we don't need to get parents of themselves, as well as IDs to mark */ - foreach($res as $row) { - if ($row['ParentID']) $parents[$row['ParentID']] = true; - $this->ids[$row['ID']] = true; - } - - /* We need to recurse up the tree, finding ParentIDs for each ID until we run out of parents */ - while (!empty($parents)) { - $res = DB::query('SELECT "ParentID", "ID" FROM "SiteTree" WHERE "ID" in ('.implode(',',array_keys($parents)).')'); - $parents = array(); - - foreach($res as $row) { - if ($row['ParentID']) $parents[$row['ParentID']] = true; - $this->ids[$row['ID']] = true; - $this->expanded[$row['ID']] = true; - } - } - } - - function mark($node) { - $id = $node->ID; - if(array_key_exists((int) $id, $this->expanded)) $node->markOpened(); - return array_key_exists((int) $id, $this->ids) ? $this->ids[$id] : false; + return new SQLQuery( + array("ParentID", "ID"), + 'SiteTree', + $where + ); } + } ?> diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 58d8ee3f..eafd8e94 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -451,6 +451,10 @@ class LeftAndMain extends Controller { return DataObject::get_by_id($className, $id); } } + + public function SiteTreeAsUL() { + return $this->getSiteTreeFor($this->stat('tree_class')); + } /** * Get a site tree displaying the nodes under the given objects. @@ -498,7 +502,6 @@ class LeftAndMain extends Controller { ); // Wrap the root if needs be. - if(!$rootID) { $rootLink = '#'; @@ -518,14 +521,12 @@ class LeftAndMain extends Controller { * If ID = 0, then get the whole tree. */ public function getsubtree($request) { - // Get the tree - $minNodeCount = (is_numeric($request->getVar('minNodeCount'))) ? $request->getVar('minNodeCount') : NULL; $tree = $this->getSiteTreeFor( $this->stat('tree_class'), $request->getVar('ID'), null, - null, - $minNodeCount + array($this->getMarkingFilter($request->requestVars()), 'mark'), + $request->getVar('minNodeCount') ); // Trim off the outer tag @@ -535,6 +536,14 @@ class LeftAndMain extends Controller { return $tree; } + /** + * @param array $params + * @return LeftAndMainMarkingFilter + */ + protected function getMarkingFilter($params) { + return new LeftAndMainMarkingFilter($params); + } + /** * Save handler */ @@ -1217,4 +1226,72 @@ JS; } +class LeftAndMainMarkingFilter { + + /** + * @var array Request params (unsanitized) + */ + protected $params = array(); + + /** + * @param array $params Request params (unsanitized) + */ + function __construct($params = null) { + $this->ids = array(); + $this->expanded = array(); + $parents = array(); + + $q = $this->getQuery($params); + $res = $q->execute(); + if (!$res) return; + + // And keep a record of parents we don't need to get parents + // of themselves, as well as IDs to mark + foreach($res as $row) { + if ($row['ParentID']) $parents[$row['ParentID']] = true; + $this->ids[$row['ID']] = true; + } + + // We need to recurse up the tree, + // finding ParentIDs for each ID until we run out of parents + while (!empty($parents)) { + $res = DB::query('SELECT "ParentID", "ID" FROM "SiteTree" WHERE "ID" in ('.implode(',',array_keys($parents)).')'); + $parents = array(); + + foreach($res as $row) { + if ($row['ParentID']) $parents[$row['ParentID']] = true; + $this->ids[$row['ID']] = true; + $this->expanded[$row['ID']] = true; + } + } + } + + protected function getQuery($params) { + $where = array(); + + $SQL_params = Convert::raw2sql($params); + if(isset($SQL_params['ID'])) unset($SQL_params['ID']); + foreach($SQL_params as $name => $val) { + switch($name) { + default: + // Partial string match against a variety of fields + if(!empty($val) && singleton("SiteTree")->hasDatabaseField($name)) { + $where[] = "\"$name\" LIKE '%$val%'"; + } + } + } + + return new SQLQuery( + array("ParentID", "ID"), + 'SiteTree', + $where + ); + } + + function mark($node) { + $id = $node->ID; + if(array_key_exists((int) $id, $this->expanded)) $node->markOpened(); + return array_key_exists((int) $id, $this->ids) ? $this->ids[$id] : false; + } +} ?> \ No newline at end of file diff --git a/code/SecurityAdmin.php b/code/SecurityAdmin.php index c4d8367f..6da54d76 100644 --- a/code/SecurityAdmin.php +++ b/code/SecurityAdmin.php @@ -183,34 +183,8 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { return FormResponse::respond(); } - /** - * Return the entire site tree as a nested set of ULs. - * @return string Unordered list