This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 
<?php
defined('C5_EXECUTE') or die("Access Denied.");
class Concrete5_Controller_Dashboard_Sitemap_Search extends Controller {
    
    public $helpers = array('form');
    
    public function view() {
        $html = Loader::helper('html');
        
        $pageList = $this->getRequestedSearchResults();
        if (is_object($pageList)) {
            $searchInstance = 'page' . time();

            $this->addHeaderItem('<script type="text/javascript">$(function() { ccm_sitemapSetupSearch(\'' . $searchInstance . '\'); });</script>');
            $pages = $pageList->getPage();
                    
            $this->set('pageList', $pageList);      
            $this->set('pages', $pages);        
            $this->set('searchInstance', $searchInstance);
            $this->set('pagination', $pageList->getPagination());
            
        }
    }
    
    public function getRequestedSearchResults() {
    
        $dh = Loader::helper('concrete/dashboard/sitemap');
        if (!$dh->canRead()) {
            return false;
        }
        
        $pageList = new PageList();
        $pageList->ignoreAliases();
        $pageList->enableStickySearchRequest();
        
        if ($_REQUEST['submit_search']) {
            $pageList->resetSearchRequest();
        }

        $req = $pageList->getSearchRequest();
        $pageList->displayUnapprovedPages();

        $columns = PageSearchColumnSet::getCurrent();
        $this->set('columns', $columns);
        
        $cvName = h($req['cvName']);
        
        if ($cvName != '') {
            $pageList->filterByName($cvName);
        }

        if ($req['numResults'] && Loader::helper('validation/numbers')->integer($req['numResults'])) {
            $pageList->setItemsPerPage($req['numResults']);
        }

        if ($req['ctID']) {
            $pageList->filterByCollectionTypeID($req['ctID']);
        }

        if (is_array($req['selectedSearchField'])) {
            foreach($req['selectedSearchField'] as $i => $item) {
                // due to the way the form is setup, index will always be one more than the arrays
                if ($item != '') {
                    switch($item) {
                        case 'keywords':
                            $keywords = htmlentities($req['keywords'], ENT_QUOTES, APP_CHARSET);
                            $pageList->filterByKeywords($keywords);
                            break;
                        case 'num_children':
                            $symbol = '=';
                            if ($req['cChildrenSelect'] == 'gt') {
                                $symbol = '>';
                            } else if ($req['cChildrenSelect'] == 'lt') {
                                $symbol = '<';
                            }
                            $pageList->filterByNumberOfChildren($req['cChildren'], $symbol);                        
                            break;
                        case 'owner':
                            $ui = UserInfo::getByUserName($req['owner']);
                            if (is_object($ui)) {
                                $pageList->filterByUserID($ui->getUserID());
                            } else {
                                $pageList->filterByUserID(-1);
                            }
                            break;
                        case 'theme':
                            $pageList->filter('ptID', $_REQUEST['ptID']);
                            break;
                        case 'parent':
                            if (isset($req['_cParentAll'])) {
                                $req['cParentAll'] = $req['_cParentAll'];
                            }
                            if ($req['cParentIDSearchField'] > 0) {
                                if ($req['cParentAll'] == 1) {
                                    $pc = Page::getByID($req['cParentIDSearchField']);
                                    $cPath = $pc->getCollectionPath();
                                    $pageList->filterByPath($cPath);
                                } else {
                                    $pageList->filterByParentID($req['cParentIDSearchField']);
                                }
                            }
                            break;
                        case 'version_status':
                            if (isset($req['_cvIsApproved'])) {
                                $req['cvIsApproved'] = $req['_cvIsApproved'];
                            }
                            $pageList->filterByIsApproved($req['cvIsApproved']);
                            break;
                        case 'permissions_inheritance':
                            $pageList->filter('cInheritPermissionsFrom', $req['cInheritPermissionsFrom']);
                            break;
                        case "date_public":
                            $dateFrom = $req['date_public_from'];
                            $dateTo = $req['date_public_to'];
                            if ($dateFrom != '') {
                                $dateFrom = date('Y-m-d', strtotime($dateFrom));
                                $pageList->filterByPublicDate($dateFrom, '>=');
                                $dateFrom .= ' 00:00:00';
                            }
                            if ($dateTo != '') {
                                $dateTo = date('Y-m-d', strtotime($dateTo));
                                $dateTo .= ' 23:59:59';                             
                                $pageList->filterByPublicDate($dateTo, '<=');
                            }
                            break;
                        case "last_modified":
                            $dateFrom = $req['last_modified_from'];
                            $dateTo = $req['last_modified_to'];
                            if ($dateFrom != '') {
                                $dateFrom = date('Y-m-d', strtotime($dateFrom));
                                $pageList->filterByDateLastModified($dateFrom, '>=');
                                $dateFrom .= ' 00:00:00';
                            }
                            if ($dateTo != '') {
                                $dateTo = date('Y-m-d', strtotime($dateTo));
                                $dateTo .= ' 23:59:59';                             
                                $pageList->filterByDateLastModified($dateTo, '<=');
                            }
                            break;
                        case "date_added":
                            $dateFrom = $req['date_added_from'];
                            $dateTo = $req['date_added_to'];
                            if ($dateFrom != '') {
                                $dateFrom = date('Y-m-d', strtotime($dateFrom));
                                $pageList->filterByDateAdded($dateFrom, '>=');
                                $dateFrom .= ' 00:00:00';
                            }
                            if ($dateTo != '') {
                                $dateTo = date('Y-m-d', strtotime($dateTo));
                                $dateTo .= ' 23:59:59';                             
                                $pageList->filterByDateAdded($dateTo, '<=');
                            }
                            break;

                        default:
                            Loader::model('attribute/categories/collection');
                            $akID = $item;
                            $fak = CollectionAttributeKey::get($akID);
                            if (!is_object($fak) || (!($fak instanceof CollectionAttributeKey))) {
                                break;
                            }
                            
                            $type = $fak->getAttributeType();
                            $cnt = $type->getController();
                            $cnt->setRequestArray($req);
                            $cnt->setAttributeKey($fak);
                            $cnt->searchForm($pageList);
                            break;
                    }
                }
            }
        }

        $this->set('searchRequest', $req);
        return $pageList;
    }
}