Simple status box for the sidebar.
[elgg_plugins.git] / suggest / config.php
blobd798db8331cdb987c37cb387a6604aa8e49e157c
1 <?php
2 /*
3 * Created on Aug 1, 2007
5 * @author Diego Andrés Ramírez Aragón <diego@somosmas.org>
6 * @copyright Corporación Somos más - 2007
7 */
9 ########################################## Suggestion Constants Config ####################################
10 /**
11 * Define the cache timeout in seconds
12 * Default value: 3600
14 define('SUGGEST_CACHE_TIME',3600);
16 /**
17 * Define the default number of suggestions
18 * Default value: 3
20 define('SUGGEST_SUGGESTIONS',3);
22 /**
23 * Define the icon size for widgets and keyword
24 * Default value: 40
26 define('SUGGEST_WIDGET_ICON_SIZE',40);
28 /**
29 * Define if you want to use the suggest tracking feature
30 * Default value: true
32 define('SUGGEST_FILTER',true);
34 /**
35 * Defines if you want to add submenu buttons
36 * Default value: true
38 define('SUGGEST_SUBMENU_CONTRIBUTIONS',true);
40 /**
41 * Define the default number of suggestions on page listings
42 * Default value: 10
44 define('SUGGEST_SUGGESTIONS_CONTRIB',10);
46 /**
47 * Define the icon size for contributed pages
48 * Default value: 70
50 define('SUGGEST_CONTRIB_ICON_SIZE',100);
52 ########################################## Suggestion Query Config ########################################
53 # You can extend/change the way the suggestions are done
54 # For add a new type of suggestions you only needs to add an entry in the $queries array.
55 # Where the first key match with the third param from the {{suggest}} keyword.
56 # A shor description about the mean of each key follow:
58 # $suggest_queries[<type>]['title'] Is the section title header
59 # $suggest_queries[<type>]['schema'] Is the URL schema of the content.
60 # In this schema you can use the following keywords:
61 # - {{username}}
62 # - {{type}}
63 # - {{ident}}
64 # $suggest_queries[<type>]['query'] The SQL query to be executed to get the suggested content
65 # Here you MUST to use the {{limit}} keyword to limit the number
66 # of contents to be retrieved.
67 # $suggest_queries[<type>]['menu_contrib'] The context where the contributions would be placed
70 ###########################################################################################################
71 global $db,$CFG,$suggest_queries;
73 # Suggested users and communities
74 ##################################
76 $suggest_queries['user']['title'] = __gettext("Users and Communities");
77 $suggest_queries['user']['menu_contrib'] = 'network';
78 $suggest_queries['user']['query'] = "SELECT u.ident,u.username,u.name, u.icon, count(t.tag) as metric FROM {$CFG->prefix}tags t";
79 $suggest_queries['user']['query'] .= " JOIN {$CFG->prefix}users u on u.ident = t.owner";
80 $suggest_queries['user']['query'] .= " WHERE t.tagtype = \"interests\" AND t.owner <> {$_SESSION['userid']}";
81 $suggest_queries['user']['query'] .= " AND tag in ( SELECT tag FROM {$CFG->prefix}tags WHERE tagtype = \"interests\"";
82 $suggest_queries['user']['query'] .= " AND owner = {$_SESSION['userid']} ) ";
83 $suggest_queries['user']['query'] .= " AND u.ident NOT IN (SELECT friend FROM {$CFG->prefix}friends WHERE owner = {$_SESSION['userid']})";
84 $suggest_queries['user']['query'] .= " GROUP BY u.ident ORDER BY metric DESC LIMIT {{limit}}";
87 # Suggested weblog related posts (included extra context)
88 ##############################################################
89 if (is_array($CFG->weblog_extensions)) {
90 foreach ($CFG->weblog_extensions as $key => $value) {
91 $suggest_queries[$key]['schema'] = "{{username}}/$key/{{ident}}.html";
93 $suggest_queries[$key]['title'] = ucfirst($key);
94 if (array_key_exists('name', $value)) {
95 $suggest_queries[$key]['title'] = $value['name'];
98 $suggest_queries[$key]['menu_contrib'] = $key;
100 $filter = array ();
101 if ($key != 'weblog' && array_key_exists('type', $value)) {
102 $nofilter[] = $value['type'];
103 $filter[] = $value['type'];
105 if ($key != 'weblog' && array_key_exists('values', $value)) {
106 if (is_array($value['values'])) {
107 $nofilter = array_merge($value['values'], $nofilter);
110 if ($key != 'weblog' && array_key_exists('extra_type', $value)) {
111 if (is_array($value['extra_type'])) {
112 $nofilter = array_merge($value['extra_type'], $nofilter);
113 $filter = array_merge($value['extra_type'], $filter);
117 $where = run("users:access_level_sql_where", $_SESSION['userid']);
118 $where = str_replace("access", "w.access", $where);
119 $where = str_replace("owner", "w.owner", $where);
120 $filter = implode(',', array_map(array ($db,'qstr'), $filter));
122 $suggest_queries[$key]['query'] = "SELECT w.ident,u.username,w.title as name, w.icon,w.body as description,w.weblog as owner ";
123 $suggest_queries[$key]['query'] .= " FROM {$CFG->prefix}users u, {$CFG->prefix}weblog_posts w";
124 $suggest_queries[$key]['query'] .= " WHERE ($where) AND u.ident = w.owner";
125 $suggest_queries[$key]['query'] .= " AND w.ident IN (SELECT ref FROM {$CFG->prefix}tags";
126 $suggest_queries[$key]['query'] .= " WHERE tagtype='weblog' ";
127 $suggest_queries[$key]['query'] .= " AND tag IN (SELECT tag FROM {$CFG->prefix}tags WHERE tagtype = 'interests' AND owner={$_SESSION['userid']})";
128 $suggest_queries[$key]['query'] .= " AND owner <> {$_SESSION['userid']})";
130 if ($key != "weblog" && !empty ($filter)) {
131 $suggest_queries[$key]['query'] .= " AND w.ident IN (SELECT ref FROM {$CFG->prefix}tags WHERE tagtype='weblog' AND tag IN ($filter)";
132 $suggest_queries[$key]['query'] .= " AND owner <> {$_SESSION['userid']})";
133 } else {
134 $suggest_queries[$key]['query'] .= " {{nofilter}}";
136 if(SUGGEST_FILTER){
137 $suggest_queries[$key]['query'] .= " AND w.ident NOT IN (SELECT contentid FROM {$CFG->prefix}suggest_tracking";
138 $suggest_queries[$key]['query'] .= " WHERE userid = {$_SESSION['userid']} AND type='$key')";
140 $suggest_queries[$key]['query'] .= " ORDER BY rand() DESC LIMIT {{limit}}";
143 if(is_array($nofilter)){
144 $nofilter = implode(',', array_map(array ($db,'qstr'), $nofilter));
145 $nofilter = " AND w.ident NOT IN (SELECT ref FROM {$CFG->prefix}tags WHERE tagtype='weblog' AND tag IN ($nofilter)";
146 $nofilter .= " AND owner <> {$_SESSION['userid']})";
149 $suggest_queries['weblog']['query'] = str_replace('{{nofilter}}', $nofilter, $suggest_queries['weblog']['query']);