예제 #1
0
function cmsMainMarkingFilterFunction($node)
{
    // Expand all nodes
    // $node->markingFinished();
    $failed_filter = false;
    // First check for the generic search term in the URLSegment, Title, MenuTitle, & Content
    if (!empty($_REQUEST['SiteTreeSearchTerm'])) {
        // For childless nodes, show only those matching the filter
        $filter = strtolower($_REQUEST['SiteTreeSearchTerm']);
        if (strpos(strtolower($node->URLSegment), $filter) === false && strpos(strtolower($node->Title), $filter) === false && strpos(strtolower($node->MenuTitle), $filter) === false && strpos(strtolower($node->Content), $filter) === false) {
            $failed_filter = true;
        }
    }
    // Check the 'Edited Since' date
    if (!empty($_REQUEST['SiteTreeFilterDate'])) {
        $edited_since = mktime(0, 0, 0, substr($_REQUEST['SiteTreeFilterDate'], 3, 2), substr($_REQUEST['SiteTreeFilterDate'], 0, 2), substr($_REQUEST['SiteTreeFilterDate'], 6, 4));
        if (strtotime($node->LastEdited) < $edited_since) {
            $failed_filter = true;
        }
    }
    // Now check if a specified Criteria attribute matches
    foreach (CMSMain::T_SiteTreeFilterOptions() as $key => $value) {
        if (!empty($_REQUEST[$key])) {
            $parameterName = $key;
            $filter = strtolower($_REQUEST[$key]);
            // Show node only if the filter string exists anywere in the filter paramater (ignoring case)
            if (strpos(strtolower($node->{$parameterName}), $filter) === false) {
                $failed_filter = true;
            }
        }
    }
    // Each filter must match or it fails
    if (true == $failed_filter) {
        // Don't ever hide nodes with children, because otherwise if one of their children matches the search, it wouldn't be shown.
        if ($node->AllChildrenIncludingDeleted()->count() > 0) {
            // Open all nodes with children so it is easy to see any children that match the search.
            foreach ($node->AllChildrenIncludingDeleted() as $childNode) {
                if (cmsMainMarkingFilterFunction($childNode)) {
                    $node->markOpened();
                    $filterCache[$node->ID] = true;
                    return true;
                }
            }
        }
        $filterCache[$node->ID] = false;
        return false;
    } else {
        if ($node->AllChildrenIncludingDeleted()->count() > 0) {
            $node->markOpened();
        }
        $filterCache[$node->ID] = true;
        return true;
    }
}
 function __construct()
 {
     $this->ids = array();
     $this->expanded = array();
     $where = array();
     // Match against URLSegment, Title, MenuTitle & Content
     if (isset($_REQUEST['SiteTreeSearchTerm'])) {
         $term = Convert::raw2sql($_REQUEST['SiteTreeSearchTerm']);
         $where[] = "\"URLSegment\" LIKE '%{$term}%' OR \"Title\" LIKE '%{$term}%' OR \"MenuTitle\" LIKE '%{$term}%' OR \"Content\" LIKE '%{$term}%'";
     }
     // Match against date
     if (isset($_REQUEST['SiteTreeFilterDate'])) {
         $date = $_REQUEST['SiteTreeFilterDate'];
         $date = (int) substr($date, 6, 4) . '-' . (int) substr($date, 3, 2) . '-' . (int) substr($date, 0, 2);
         $where[] = "\"LastEdited\" > '{$date}'";
     }
     // Match against exact ClassName
     if (isset($_REQUEST['ClassName']) && $_REQUEST['ClassName'] != 'All') {
         $klass = Convert::raw2sql($_REQUEST['ClassName']);
         $where[] = "\"ClassName\" = '{$klass}'";
     }
     // Partial string match against a variety of fields
     foreach (CMSMain::T_SiteTreeFilterOptions() as $key => $value) {
         if (!empty($_REQUEST[$key])) {
             $match = Convert::raw2sql($_REQUEST[$key]);
             $where[] = "\"{$key}\" LIKE '%{$match}%'";
         }
     }
     $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;
         }
     }
 }
 /**
  * Retun an array of maps containing the keys, 'ID' and 'ParentID' for each page to be displayed
  * in the search.
  */
 function pagesIncluded()
 {
     $data = $this->data;
     $this->ids = array();
     $this->expanded = array();
     $where = array();
     // Match against URLSegment, Title, MenuTitle & Content
     if (isset($data['SiteTreeSearchTerm'])) {
         $term = Convert::raw2sql($data['SiteTreeSearchTerm']);
         $where[] = "\"URLSegment\" LIKE '%{$term}%' OR \"Title\" LIKE '%{$term}%' OR \"MenuTitle\" LIKE '%{$term}%' OR \"Content\" LIKE '%{$term}%'";
     }
     // Match against date
     if (isset($data['SiteTreeFilterDate'])) {
         $date = $data['SiteTreeFilterDate'];
         $date = (int) substr($date, 6, 4) . '-' . (int) substr($date, 3, 2) . '-' . (int) substr($date, 0, 2);
         $where[] = "\"LastEdited\" > '{$date}'";
     }
     // Match against exact ClassName
     if (isset($data['ClassName']) && $data['ClassName'] != 'All') {
         $klass = Convert::raw2sql($data['ClassName']);
         $where[] = "\"ClassName\" = '{$klass}'";
     }
     // Partial string match against a variety of fields
     foreach (CMSMain::T_SiteTreeFilterOptions() as $key => $value) {
         if (!empty($data[$key])) {
             $match = Convert::raw2sql($data[$key]);
             $where[] = "\"{$key}\" LIKE '%{$match}%'";
         }
     }
     $where = empty($where) ? '' : 'WHERE (' . implode(') AND (', $where) . ')';
     $parents = array();
     /* Do the actual search */
     $res = DB::query('SELECT "ParentID", "ID" FROM "SiteTree" ' . $where);
     return $res;
 }