-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
139 lines (114 loc) · 3.68 KB
/
index.php
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
<?php
/**
* Advanced Find Plugin for Frog CMS (original)
* Copyright (C) 2008 Tyler Beckett <[email protected]>
* Adopted by Dejan Andjelkovic 2010 for Wolf CMS as maintainer
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Plugin::setInfos(array(
'id' => 'adv-find',
'title' => 'Advanced Find',
'description' => 'Allows you to search many different archives and sort them by date.',
'version' => '1.0.1',
'license' => 'AGPL',
'author' => 'Tyler Beckett',
'website' => 'http://project79.net/',
'update_url' => 'http://project79.net/plugin-versions.xml',
'require_wolf_version' => '0.5.5'
));
error_reporting(E_ALL^E_NOTICE);
class adv_find extends Page
{
private $search;
private $vars;
private $sortAttribute;
public $children;
private function sorty($attribute)
{
$this->sortAttribute = $attribute;
usort($this->children, array($this, 'cmpVals'));
}
private function cmpVals($val1, $val2)
{
$search = $this->sortAttribute['0'];
$order = $this->sortAttribute['1'];
if (strtoupper($order) == 'DESC')
{
return (strcasecmp($val1->$search, $val2->$search)*-1);
}
return strcasecmp($val1->$search, $val2->$search);
}
private function trimc($limit)
{
$this->children = array_slice($this->children, 0, $limit);
}
public function adv_where($search, $vars)
{
// Use Wolf's built in find function to search for each of the arguments provided
foreach ($search as $sought)
{
$results[] = parent::find($sought);
}
// Use Wolf's built in children function to get all children of the above searched for archives
foreach ($results as $parent)
{
$children[] = $parent->children($vars);
}
// Count the number of archive variables in the array
$total = count($children);
// Count the number of children variables to each of the archive variables above
for ($x = 0; $x <= $total; $x++)
{
$ctotal[$x] = count($children[$x]);
}
// Combine all the search results into one $combine variable
$combine = array();
for ($x = 0; $x < $total; $x++)
{
for ($y = 0; $y < $ctotal[$x]; $y++)
{
array_unshift($combine,$children[$x][$y]);
}
}
unset($children);
$this->children = $combine;
unset($combine);
// If the user has chosen an order that they'd like the results in, order like so
if (isset($this->vars['order']))
{
$sve = explode(' ', $this->vars['order']);
adv_find::sorty($sve);
}
// If the user wants to limit their results, trim the remaining off
if (isset($this->vars['limit']))
{
adv_find::trimc($this->vars['limit']);
}
return $this->children;
}
public function __construct($search,$vars)
{
// Instantiate all the variables necessary to do the search
$this->search = $search;
$this->vars = $vars;
// Do the search and then save the results to $this->results
$this->results = $this->adv_where($this->search,$this->vars);
}
}
function adv_find($query, $args = '')
{
// Begin the process
$found = new adv_find($query, $args);
// Pass the results back to the user!
return $found->children;
}
?>