-
Notifications
You must be signed in to change notification settings - Fork 1
/
completed_project.php
421 lines (373 loc) · 15.3 KB
/
completed_project.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<?php
/**
* Project index page - displays details of a single project, a list of project summary descriptions or a compact table of projects
*
* @copyright Copyright Madfish (Simon Wilkinson) 2012
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
* @since 1.0
* @author Madfish (Simon Wilkinson) <simon@isengard.biz>
* @package projects
* @version $Id$
*/
include_once "header.php";
$xoopsOption["template_main"] = "projects_project.html";
include_once ICMS_ROOT_PATH . "/header.php";
// Sanitise input parameters
$untagged_content = FALSE;
if (isset($_GET['tag_id'])) {
if ($_GET['tag_id'] == 'untagged') {
$untagged_content = TRUE;
}
}
$clean_project_id = isset($_GET["project_id"]) ? (int)$_GET["project_id"] : 0 ;
$clean_tag_id = isset($_GET["tag_id"]) ? (int)$_GET["tag_id"] : 0 ;
$clean_start = isset($_GET["start"]) ? (int)($_GET["start"]) : 0;
// Get the requested project, or retrieve the index page. Only show online projects
$projects_project_handler = icms_getModuleHandler("project", basename(dirname(__FILE__)), "projects");
$criteria = icms_buildCriteria(array('online_status' => '1'));
$projectObj = $projects_project_handler->get($clean_project_id, TRUE, FALSE, $criteria);
// Get relative path to document root for this ICMS install. This is required to call the logos correctly if ICMS is installed in a subdirectory
$directory_name = basename(dirname(__FILE__));
$script_name = getenv("SCRIPT_NAME");
$document_root = str_replace('modules/' . $directory_name . '/completed_project.php', '', $script_name);
// Optional tagging support (only if Sprockets module installed)
$sprocketsModule = icms::handler("icms_module")->getByDirname("sprockets");
$projects_tag_name = '';
if (icms_get_module_status("sprockets"))
{
icms_loadLanguageFile("sprockets", "common");
$sprockets_tag_handler = icms_getModuleHandler('tag', $sprocketsModule->getVar('dirname'), 'sprockets');
$sprockets_taglink_handler = icms_getModuleHandler('taglink', $sprocketsModule->getVar('dirname'), 'sprockets');
$criteria = icms_buildCriteria(array('label_type' => '0'));
$sprockets_tag_buffer = $sprockets_tag_handler->getList($criteria, TRUE, TRUE);
}
// Assign common logo preferences to template
$icmsTpl->assign('display_project_logos', icms::$module->config['display_project_logos']);
$icmsTpl->assign('projects_freestyle_logo_dimensions', icms::$module->config['projects_freestyle_logo_dimensions']);
$icmsTpl->assign('projects_logo_display_width', icms::$module->config['projects_logo_index_display_width']);
if (icms::$module->config['project_logo_position'] == 1) // Align right
{
$icmsTpl->assign('project_logo_position', 'projects_float_right');
}
else // Align left
{
$icmsTpl->assign('project_logo_position', 'projects_float_left');
}
/////////////////////////////////////////
////////// VIEW SINGLE PROJECT //////////
/////////////////////////////////////////
if($projectObj && !$projectObj->isNew())
{
// Update hit counter
if (!icms_userIsAdmin(icms::$module->getVar('dirname')))
{
$projects_project_handler->updateCounter($projectObj);
}
// Convert object to array for easy insertion into templates
$project = $projectObj->toArray();
// Add SEO friendly string to URL
if (!empty($project['short_url']))
{
$project['itemUrl'] .= "&title=" . $project['short_url'];
}
// Check if the hit counter should be displayed or not
if (icms::$module->config['projects_show_view_counter'] == FALSE)
{
unset($project['counter']);
}
// Adjust logo path for template
if (!empty($project['logo']))
{
$project['logo'] = $document_root . 'uploads/' . $directory_name . '/project/' . $project['logo'];
}
// Prepare tags for display
if (icms_get_module_status("sprockets"))
{
$project['tag'] = array();
$project_tag_array = $sprockets_taglink_handler->getTagsForObject($projectObj->getVar('project_id'), $projects_project_handler, 0);
foreach ($project_tag_array as $key => $value)
{
if ($value == 0) {
$project['tag'][$value] = '<a href="' . PROJECTS_URL
. 'completed_project.php?tag_id=untagged">' . _CO_PROJECTS_UNTAGGED . '</a>';
} else {
$project['tag'][$value] = '<a href="' . PROJECTS_URL
. 'completed_project.php?tag_id=' . $value . '">'
. $sprockets_tag_buffer[$value] . '</a>';
}
}
$project['tag'] = implode(', ', $project['tags']);
}
// If the project is completed, add the completed flag to the breadcrumb title
if ($projectObj->getVar('complete', 'e') == 1)
{
$icmsTpl->assign("projects_completed_path", _CO_PROJECTS_PROJECT_COMPLETE);
}
$icmsTpl->assign("projects_project", $project);
$icms_metagen = new icms_ipf_Metagen($projectObj->getVar("title"),
$projectObj->getVar("meta_keywords", "n"), $projectObj->getVar("meta_description", "n"));
$icms_metagen->createMetaTags();
}
////////////////////////////////////////
////////// VIEW PROJECT INDEX //////////
////////////////////////////////////////
else
{
// Get a select box (if preferences allow, and only if Sprockets module installed)
if (icms_get_module_status("sprockets") && icms::$module->config['projects_show_tag_select_box'] == TRUE)
{
// Initialise
$projects_tag_name = '';
$tagList = array();
$sprockets_tag_handler = icms_getModuleHandler('tag', $sprocketsModule->getVar('dirname'),
'sprockets');
$sprockets_taglink_handler = icms_getModuleHandler('taglink',
$sprocketsModule->getVar('dirname'), 'sprockets');
// Append the tag to the breadcrumb title
if (array_key_exists($clean_tag_id, $sprockets_tag_buffer) && ($clean_tag_id !== 0))
{
$projects_tag_name = $sprockets_tag_buffer[$clean_tag_id];
$icmsTpl->assign('projects_tag_name', $projects_tag_name);
$icmsTpl->assign('projects_category_path', $sprockets_tag_buffer[$clean_tag_id]);
}
// Load the tag navigation select box
// $action, $selected = null, $zero_option_message = '---',
// $navigation_elements_only = TRUE, $module_id = null, $item = null,
if ($untagged_content) {
$tag_select_box = $sprockets_tag_handler->getTagSelectBox('completed_project.php',
'untagged', _CO_PROJECTS_PROJECT_ALL_TAGS, TRUE, icms::$module->getVar('mid'),
'project', TRUE);
} else {
$tag_select_box = $sprockets_tag_handler->getTagSelectBox('completed_project.php',
$clean_tag_id, _CO_PROJECTS_PROJECT_ALL_TAGS, TRUE, icms::$module->getVar('mid'),
'project', TRUE);
}
$icmsTpl->assign('projects_tag_select_box', $tag_select_box);
}
///////////////////////////////////////////////////////////////////
////////// View projects as list of summary descriptions //////////
///////////////////////////////////////////////////////////////////
if (icms::$module->config['projects_index_display_mode'] == TRUE)
{
$project_summaries = $linked_project_ids = array();
// Append the tag name to the module title (if preferences allow, and only if Sprockets module installed)
if (icms_get_module_status("sprockets") && icms::$module->config['projects_show_breadcrumb'] == FALSE)
{
if (array_key_exists($clean_tag_id, $sprockets_tag_buffer) && ($clean_tag_id !== 0))
{
$projects_tag_name = $sprockets_tag_buffer[$clean_tag_id];
$icmsTpl->assign('projects_tag_name', $projects_tag_name);
} elseif ($untagged_content) {
$icmsTpl->assign('projects_tag_name', _CO_PROJECTS_UNTAGGED);
}
} else {
if ($untagged_content) {
$icmsTpl->assign('projects_category_path', _CO_PROJECTS_UNTAGGED);
} else {
$icmsTpl->assign('projects_category_path', $sprockets_tag_buffer[$clean_tag_id]);
}
}
// Retrieve projects for a given tag
if (($clean_tag_id || $untagged_content) && icms_get_module_status("sprockets"))
{
/**
* Retrieve a list of projects JOINED to taglinks by project_id/tag_id/module_id/item
*/
$query = $rows = $project_count = '';
$linked_project_ids = array();
// First, count the number of projects for the pagination control
$project_count = '';
$group_query = "SELECT count(*) FROM " . $projects_project_handler->table . ", "
. $sprockets_taglink_handler->table
. " WHERE `project_id` = `iid`"
. " AND `online_status` = '1'"
. " AND `complete` = '1'"
. " AND `tid` = '" . $clean_tag_id . "'"
. " AND `mid` = '" . icms::$module->getVar('mid') . "'"
. " AND `item` = 'project'";
$result = icms::$xoopsDB->query($group_query);
if (!$result)
{
echo 'Error';
exit;
}
else
{
while ($row = icms::$xoopsDB->fetchArray($result))
{
foreach ($row as $key => $count)
{
$project_count = $count;
}
}
}
// Secondly, get the projects
$query = "SELECT * FROM " . $projects_project_handler->table . ", "
. $sprockets_taglink_handler->table
. " WHERE `project_id` = `iid`"
. " AND `online_status` = '1'"
. " AND `complete` = '1'"
. " AND `tid` = '" . $clean_tag_id . "'"
. " AND `mid` = '" . icms::$module->getVar('mid') . "'"
. " AND `item` = 'project'"
. " ORDER BY `weight` ASC"
. " LIMIT " . $clean_start . ", " . icms::$module->config['number_of_projects_per_page'];
$result = icms::$xoopsDB->query($query);
if (!$result)
{
echo 'Error';
exit;
}
else
{
$rows = $projects_project_handler->convertResultSet($result, TRUE, FALSE);
foreach ($rows as $key => $row)
{
$project_summaries[$row['project_id']] = $row;
}
}
}
// Retrieve projects without filtering by tag
else
{
$criteria = new icms_db_criteria_Compo();
$criteria->add(new icms_db_criteria_Item('complete', '1'));
$criteria->add(new icms_db_criteria_Item('online_status', '1'));
// Count the number of online projects for the pagination control
$project_count = $projects_project_handler->getCount($criteria);
// Continue to retrieve projects for this page view
$criteria->setStart($clean_start);
$criteria->setLimit(icms::$module->config['number_of_projects_per_page']);
$criteria->setSort('weight');
$criteria->setOrder('ASC');
$project_summaries = $projects_project_handler->getObjects($criteria, TRUE, FALSE);
}
// Prepare tags. A list of project IDs is used to retrieve relevant taglinks. The taglinks
// are sorted into a multidimensional array, using the project ID as the key to each subarray.
// Then its just a case of assigning each subarray to the matching project.
// Prepare a list of project_id, this will be used to create a taglink buffer, which is used
// to create tag links for each project
$linked_project_ids = array();
foreach ($project_summaries as $key => $value) {
$linked_project_ids[] = $value['project_id'];
}
if (icms_get_module_status("sprockets") && !empty($linked_project_ids))
{
$tagList = $sprockets_tag_handler->getTagBuffer(TRUE);
$taglink_buffer = $sprockets_taglink_handler->getTagsForObjects($linked_project_ids, 'project');
foreach ($project_summaries as &$project) {
$tagLinks = $icons = array();
if ($taglink_buffer[$project['project_id']]) {
foreach ($taglink_buffer[$project['project_id']] as $tag) {
if ($tag == '0') {
$tagLinks[] = '<a href="' . PROJECTS_URL
. 'completed_project.php?tag_id=untagged">'
. $tagList[$tag]->getVar('title') . '</a>';
} else {
$tagLinks[] = '<a href="' . PROJECTS_URL
. 'completed_project.php?tag_id=' . $tag . '">'
. $tagList[$tag]->getVar('title') . '</a>';
$icons[] = '<a href="' . PROJECTS_URL
. 'completed_project.php?tag_id=' . $tag . '">'
. $tagList[$tag]->getVar('icon') . '</a>';
}
}
$project['tag'] = implode(", ", $tagLinks);
unset($tagLinks);
}
$tag_icons[$project['project_id']] = $icons;
unset($icons);
}
}
// Prepare project for display
foreach ($project_summaries as &$project)
{
// Ajust logo paths to allow dynamic image resizing
if (!empty($project['logo']))
$project['logo'] = $document_root . 'uploads/' . $directory_name . '/project/'
. $project['logo'];
// Add SEO friendly string to URL
if (!empty($project['short_url']))
{
$project['itemUrl'] .= "&title=" . $project['short_url'];
}
// Alter the itemUrl to point at the completed projects page, rather than the projects page
$project['itemUrl'] = str_replace('project.php', 'completed_project.php', $project['itemUrl']);
}
$icmsTpl->assign('project_summaries', $project_summaries);
// Adjust pagination for tag, if present
if (!empty($clean_tag_id))
{
$extra_arg = 'tag_id=' . $clean_tag_id;
}
else
{
$extra_arg = TRUE;
}
// Pagination control
$pagenav = new icms_view_PageNav($project_count, icms::$module->config['number_of_projects_per_page'],
$clean_start, 'start', $extra_arg);
$icmsTpl->assign('projects_navbar', $pagenav->renderNav());
}
else
{
//////////////////////////////////////////////////////////////////////////////
////////// View projects in compact table, optionally filter by tag //////////
//////////////////////////////////////////////////////////////////////////////
$tagged_project_list = '';
if (($clean_tag_id || $untagged_content) && icms_get_module_status("sprockets"))
{
// get a list of project IDs belonging to this tag
$criteria = new icms_db_criteria_Compo();
if ($untagged_content) {
$criteria->add(new icms_db_criteria_Item('tid', 0));
} else {
$criteria->add(new icms_db_criteria_Item('tid', $clean_tag_id));
}
$criteria->add(new icms_db_criteria_Item('mid', icms::$module->getVar('mid')));
$criteria->add(new icms_db_criteria_Item('item', 'project'));
$taglink_array = $sprockets_taglink_handler->getObjects($criteria);
foreach ($taglink_array as $taglink) {
$tagged_project_list[] = $taglink->getVar('iid');
}
$tagged_project_list = "('" . implode("','", $tagged_project_list) . "')";
}
$criteria = new icms_db_criteria_Compo();
if (!empty($tagged_project_list))
{
$criteria->add(new icms_db_criteria_Item('project_id', $tagged_project_list, 'IN'));
}
$criteria->add(new icms_db_criteria_Item('complete', '1'));
$criteria->add(new icms_db_criteria_Item('online_status', '1'));
$criteria->setSort('weight');
$criteria->setOrder('ASC');
// Retrieve the table
$objectTable = new icms_ipf_view_Table($projects_project_handler, $criteria, array());
$objectTable->isForUserSide();
$objectTable->addQuickSearch('title');
$objectTable->addColumn(new icms_ipf_view_Column("title", _GLOBAL_LEFT, FALSE, addSEOStringToItemUrl));
$objectTable->addColumn(new icms_ipf_view_Column("date"));
$objectTable->addColumn(new icms_ipf_view_Column("last_update"));
$icmsTpl->assign("projects_project_table", $objectTable->fetch());
}
}
// Breadcrumb
if (icms::$module->config['projects_show_breadcrumb'])
{
$icmsTpl->assign("projects_show_breadcrumb", icms::$module->config['projects_show_breadcrumb']);
$icmsTpl->assign("projects_module_home", '<a href="' . ICMS_URL . "/modules/"
. icms::$module->getVar("dirname") . '/">' . icms::$module->getVar("name") . "</a>");
if ($projects_tag_name)
{
$icmsTpl->assign("projects_completed_path", '<a href="' . ICMS_URL . "/modules/"
. icms::$module->getVar("dirname") . '/completed_project.php">'
. _CO_PROJECTS_PROJECT_COMPLETE . "</a>");
}
else
{
$icmsTpl->assign("projects_completed_path", _CO_PROJECTS_PROJECT_COMPLETE);
}
}
// Page title
$icmsTpl->assign("projects_page_title", _CO_PROJECTS_COMPLETE_PROJECTS);
include_once "footer.php";