forked from Moc/cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e_search.php
93 lines (74 loc) · 2.09 KB
/
e_search.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
<?php
/*
* CookBook - an e107 plugin by Tijn Kuyper (http://www.tijnkuyper.nl)
*
* Released under the terms and conditions of the
* Apache License 2.0 (see LICENSE file or http://www.apache.org/licenses/LICENSE-2.0)
*
*/
if (!defined('e107_INIT')) { exit; }
class cookbook_search extends e_search
{
function config()
{
$search = array(
'name' => LAN_CB_NAME,
'table' => 'cookbook_recipes',
'advanced' => array(
'date' => array('type' => 'date', 'text' => LAN_DATE_POSTED),
'author'=> array('type' => 'author', 'text' => LAN_SEARCH_61)
),
'return_fields' => array(
'r_id',
'r_author',
'r_name',
'r_name_sef',
'r_summary',
'r_datestamp'
),
'search_fields' => array(
'r_name' => '1',
'r_summary' => '0.8',
'r_ingredients' => '0.6',
'r_instructions' => '1'
),
'order' => array('r_datestamp' => 'DESC'),
'refpage' => e107::url('cookbook', 'index'),
);
return $search;
}
/* Compile Database data for output */
function compile($row)
{
$tp = e107::getParser();
$username = e107::user($row['r_author']);
$username = $username['user_name'];
$res = array();
$res['link'] = e107::url('cookbook', 'id', $row);
//$res['pre_title'] = LAN_SEARCH_7;
$res['title'] = $row['r_name'];
$res['summary'] = $row['r_summary'];
$res['detail'] = LAN_SEARCH_15." ".$username." | ".LAN_SEARCH_66.": ".$tp->toDate($row['r_datestamp'], "long");
return $res;
}
/**
* Advanced Where
* @param $parm - data returned from $_GET (ie. advanced fields included. in this case 'date' and 'author' )
*/
function where($parm=null)
{
$tp = e107::getParser();
$user_name = $tp->toDB($parm['author']);
$user_id = e107::getDb()->retrieve("user", "user_id", "user_name = '".$username);
$qry = "";
if (vartrue($parm['time']) && is_numeric($parm['time']))
{
$qry .= " r_datestamp ".($parm['on'] == 'new' ? '>=' : '<=')." '".(time() - $parm['time'])."' AND";
}
if(vartrue($parm['author']))
{
$qry .= " r_author = ".$user_id;
}
return $qry;
}
}