Retrofitted $_SP_CONF['includesearch'] option (had to take it out to get Tom's patch integrated)
3 /* Reminder: always indent with 4 spaces (no tabs). */
4 // +---------------------------------------------------------------------------+
5 // | Static Pages Plugin 1.6 |
6 // +---------------------------------------------------------------------------+
9 // | This file does two things: 1) it implements the necessary Geeklog Plugin |
10 // | API method and 2) implements all the common code needed by the Static |
11 // | Pages' PHP files. |
12 // +---------------------------------------------------------------------------+
13 // | Copyright (C) 2000-2009 by the following authors: |
15 // | Authors: Tony Bibbs - tony AT tonybibbs DOT com |
16 // | Tom Willett - twillett AT users DOT sourceforge DOT net |
17 // | Blaine Lang - blaine AT portalparts DOT com |
18 // | Dirk Haun - dirk AT haun-online DOT de |
19 // +---------------------------------------------------------------------------+
21 // | This program is free software; you can redistribute it and/or |
22 // | modify it under the terms of the GNU General Public License |
23 // | as published by the Free Software Foundation; either version 2 |
24 // | of the License, or (at your option) any later version. |
26 // | This program is distributed in the hope that it will be useful, |
27 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
28 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
29 // | GNU General Public License for more details. |
31 // | You should have received a copy of the GNU General Public License |
32 // | along with this program; if not, write to the Free Software Foundation, |
33 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
35 // +---------------------------------------------------------------------------+
38 * Implementation of the Plugin API for the Static Pages plugin
40 * @package StaticPages
43 if (strpos(strtolower($_SERVER['PHP_SELF']), 'functions.inc') !== false) {
44 die('This file can not be used on its own.');
47 $plugin_path = $_CONF['path'] . 'plugins/staticpages/';
50 * Language file include
52 $langfile = $plugin_path . 'language/' . $_CONF['language'] . '.php';
53 if (file_exists($langfile)) {
54 require_once $langfile;
56 require_once $plugin_path . 'language/english.php';
60 * Check and see if we need to load the plugin configuration
62 if (!isset($_SP_CONF['allow_php'])) {
63 require_once $_CONF['path_system'] . 'classes/config.class.php';
65 $sp_config = config::get_instance();
66 $_SP_CONF = $sp_config->get_config('staticpages');
70 // +---------------------------------------------------------------------------+
71 // | Plugin API - Services |
72 // +---------------------------------------------------------------------------+
74 include_once $plugin_path . 'services.inc.php';
76 // +---------------------------------------------------------------------------+
77 // | Geeklog Plugin API Implementations |
78 // +---------------------------------------------------------------------------+
81 * Returns the items for this plugin that should appear on the main menu
83 * NOTE: this MUST return the url/value pairs in the following format
84 * $<arrayname>[<label>] = <url>
87 function plugin_getmenuitems_staticpages()
89 global $_CONF, $_TABLES, $_SP_CONF;
92 if (!empty ($_SP_CONF['sort_menu_by'])) {
93 $order = ' ORDER BY ';
94 if ($_SP_CONF['sort_menu_by'] == 'date') {
95 $order .= 'sp_date DESC';
96 } else if ($_SP_CONF['sort_menu_by'] == 'label') {
98 } else if ($_SP_CONF['sort_menu_by'] == 'title') {
100 } else { // default to "sort by id"
105 $result = DB_query('SELECT sp_id, sp_label FROM ' . $_TABLES['staticpage'] . ' WHERE sp_onmenu = 1' . COM_getPermSql('AND') . COM_getLangSql('sp_id', 'AND') . $order);
106 $nrows = DB_numRows ($result);
107 $menuitems = array ();
108 for ($i = 0; $i < $nrows; $i++) {
109 $A = DB_fetchArray ($result);
110 $menuitems[$A['sp_label']] = COM_buildURL ($_CONF['site_url'] . '/staticpages/index.php?page=' . $A['sp_id']);
117 * Plugin should display [a] comment[s]
119 * @param string $id Unique idenifier for item comment belongs to
120 * @param int $cid Comment id to display (possibly including sub-comments)
121 * @param string $title Page/comment title
122 * @param string $order 'ASC' or 'DSC' or blank
123 * @param string $format 'threaded', 'nested', or 'flat'
124 * @param int $page Page number of comments to display
125 * @param boolean $view True to view comment (by cid), false to display (by $pid)
126 * @return mixed results of calling the plugin_displaycomment_ function
128 function plugin_displaycomment_staticpages ($id, $cid, $title, $order, $format, $page, $view)
130 global $_TABLES, $LANG_ACCESS;
134 $sql = "SELECT COUNT(*) AS count, commentcode, owner_id, group_id, perm_owner, "
135 . "perm_group, perm_members, perm_anon "
136 . "FROM {$_TABLES['staticpage']} "
137 . "WHERE (sp_id = '$id')" . COM_getPermSQL('AND')
139 $result = DB_query ($sql);
140 $A = DB_fetchArray ($result);
141 $allowed = $A['count'];
144 $delete_option = (SEC_hasRights ('staticpages.edit') &&
145 (SEC_hasAccess ($A['owner_id'], $A['group_id'],
146 $A['perm_owner'], $A['perm_group'], $A['perm_members'],
147 $A['perm_anon']) == 3));
148 $retval .= CMT_userComments ($id, $title, 'staticpages', $order, $format,
149 $cid, $page, $view, $delete_option,
152 $retval .= COM_startBlock ($LANG_ACCESS['accessdenied'], '',
153 COM_getBlockTemplate ('_msg_block', 'header'))
154 . $LANG_ACCESS['storydenialmsg']
155 . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
162 * Static Page saves a comment
164 * @param string $title comment title
165 * @param string $comment comment text
166 * @param string $id Item id to which $cid belongs
167 * @param int $pid comment parent
168 * @param string $postmode 'html' or 'text'
169 * @return mixed false for failure, HTML string (redirect?) for success
171 function plugin_savecomment_staticpages($title, $comment, $id, $pid, $postmode)
173 global $_CONF, $_TABLES, $LANG03, $_USER;
177 $commentcode = DB_getItem($_TABLES['staticpage'], 'commentcode',
179 if ($commentcode != 0) {
180 return COM_refresh($_CONF['site_url'] . '/index.php');
183 $ret = CMT_saveComment($title, $comment, $id, $pid, 'staticpages', $postmode);
184 if ($ret > 0) { // failure //FIXME: some failures should not return to comment form
185 $retval .= COM_siteHeader('menu', $LANG03[1])
186 . CMT_commentForm($title, $comment, $id, $pid, 'staticpages',
187 $LANG03[14], $postmode)
191 if (($_CONF['commentsubmission'] == 1) &&
192 !SEC_hasRights('comment.submit')) {
195 $retval = COM_refresh ($_CONF['site_url']
196 . "/staticpages/index.php?page=$id$msg");
203 * staticpages: delete a comment
205 * @param int $cid Comment to be deleted
206 * @param string $id Item id to which $cid belongs
207 * @return mixed false for failure, HTML string (redirect?) for success
209 function plugin_deletecomment_staticpages($cid, $id)
211 global $_CONF, $_TABLES, $_USER;
215 $has_editPermissions = SEC_hasRights ('staticpages.edit');
216 $result = DB_query ("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon "
217 . "FROM {$_TABLES['staticpage']} WHERE sp_id = '{$id}'");
218 $A = DB_fetchArray ($result);
220 if ($has_editPermissions && SEC_hasAccess ($A['owner_id'],
221 $A['group_id'], $A['perm_owner'], $A['perm_group'],
222 $A['perm_members'], $A['perm_anon']) == 3) {
223 CMT_deleteComment($cid, $id, 'staticpages');
224 $retval .= COM_refresh ($_CONF['site_url']
225 . "/staticpages/index.php?page=$id");
227 COM_errorLog ("User {$_USER['username']} (IP: {$_SERVER['REMOTE_ADDR']}) "
228 . "tried to illegally delete comment $cid from staticpage $id");
229 $retval .= COM_refresh ($_CONF['site_url'] . '/index.php');
236 * Helper function: Count static pages visible to the current user
238 * @return int number of pages
241 function SP_countVisiblePages ()
245 $perms = SP_getPerms ();
246 if (!empty ($perms)) {
247 $perms = ' WHERE ' . $perms;
249 $result = DB_query ("SELECT COUNT(*) AS cnt FROM {$_TABLES['staticpage']}" . $perms);
250 $A = DB_fetchArray ($result);
256 * Prepare static page for display.
258 * @param string $page static page id
259 * @param array $A static page data
260 * @param string $comment_order sorting of comments
261 * @param string $comment_mode comment mode (nested, flat, etc.)
262 * @param int $msg optional message number
263 * @return string HTML for the static page
266 function SP_displayPage ($page, $A, $comment_order = 'ASC', $comment_mode = 'nested', $msg = 0)
268 global $_CONF, $_TABLES, $_USER,
269 $LANG01, $LANG11, $LANG_STATIC, $_IMAGE_TYPE, $_SP_CONF;
273 $sp_url = COM_buildUrl($_CONF['site_url'] . '/staticpages/index.php?page='
275 $headercode = '<link rel="canonical" href="' . $sp_url . '"' . XHTML . '>';
278 If ($_SP_CONF['meta_tags'] > 0) {
279 $meta_description = $A['meta_description'];
280 $meta_keywords = $A['meta_keywords'];
281 $headercode .= COM_createMetaTags($meta_description, $meta_keywords);
284 if ($A['sp_format'] == 'allblocks' OR $A['sp_format'] == 'leftblocks') {
285 $retval .= COM_siteHeader('menu', $A['sp_title'], $headercode);
287 if ($A['sp_format'] <> 'blankpage') {
288 $retval .= COM_siteHeader('none', $A['sp_title'], $headercode);
292 $retval .= COM_showMessage($msg, 'staticpages');
294 if (($A['sp_inblock'] == 1) && ($A['sp_format'] != 'blankpage')) {
295 $retval .= COM_startBlock (stripslashes ($A['sp_title']), $A['sp_help'],
296 COM_getBlockTemplate ('_staticpages_block', 'header'));
299 $spage = new Template( $_CONF['path'] . 'plugins/staticpages/templates/' );
300 $spage->set_var('xhtml', XHTML);
302 $spage->set_var('xmlns', ' xmlns="http://www.w3.org/1999/xhtml"');
304 $spage->set_var('site_url', $_CONF['site_url']);
305 $spage->set_var('layout_url', $_CONF['layout_url']);
306 $spage->set_var('site_admin_url', $_CONF['site_admin_url']);
307 $spage -> set_file( array('page'=>'staticpage.thtml',
308 'comments' => 'spcomments.thtml'));
310 if ($A['sp_format'] <> 'blankpage') {
311 if ($_CONF['hideprintericon'] == 0) {
312 $icon_url = $_CONF['layout_url'] . '/images/print.' . $_IMAGE_TYPE;
313 $attr = array('title' => $LANG_STATIC['printable_format']);
314 $printicon = COM_createImage($icon_url, $LANG01[65], $attr);
315 $print_url = COM_buildURL ($_CONF['site_url']
316 . '/staticpages/index.php?page=' . $page . '&disp_mode=print');
317 $icon = COM_createLink($printicon, $print_url);
318 $spage->set_var('print_icon', $icon);
320 if ((SEC_hasAccess ($A['owner_id'], $A['group_id'], $A['perm_owner'],
321 $A['perm_group'], $A['perm_members'], $A['perm_anon']) == 3) &&
322 SEC_hasRights ('staticpages.edit')) {
323 $icon_url = $_CONF['layout_url'] . '/images/edit.' . $_IMAGE_TYPE;
324 $attr = array('title' => $LANG_STATIC['edit']);
325 $editiconhtml = COM_createImage($icon_url, $LANG_STATIC['edit'], $attr);
326 $attr = array('class' => 'editlink','title' => $LANG_STATIC['edit']);
327 $url = $_CONF['site_admin_url']
328 . '/plugins/staticpages/index.php?mode=edit&sp_id=' . $page;
330 ' ' . COM_createLink(
331 $editiconhtml, //display
333 $attr //other attributes
335 $spage->set_var('edit_icon', $icon);
339 if($A['commentcode'] >= 0 ) {
340 $delete_option = (SEC_hasRights('staticpages.edit') &&
341 SEC_hasAccess($A['owner_id'], $A['group_id'],
342 $A['perm_owner'], $A['perm_group'], $A['perm_members'],
343 $A['perm_anon']) == 3 ? true : false);
344 require_once $_CONF['path_system'] . 'lib-comment.php';
345 $spage->set_var ('commentbar', CMT_userComments($page, $A['sp_title'], 'staticpages',
346 $comment_order, $comment_mode, 0, 1, false,
347 $delete_option, $A['commentcode']));
351 $content = SP_render_content (stripslashes ($A['sp_content']), $A['sp_php']);
352 $spage->set_var('content', $content );
354 $spage->set_var('info_separator', 'hidden');
355 if ($A['sp_format'] <> 'blankpage') {
356 $curtime = COM_getUserDateTimeFormat ($A['sp_date']);
357 if ($_SP_CONF['show_date'] == 1) {
358 $lastupdate = $LANG_STATIC['lastupdated']. ' ' . $curtime[0];
359 $spage->set_var('lastupdate', $lastupdate);
362 if ($_SP_CONF['show_hits'] == 1) {
363 if ($_SP_CONF['show_date'] == 1) {
364 $spage->set_var('info_separator','visible');
366 $hits = COM_numberFormat ($A['sp_hits']) . ' ' . $LANG_STATIC['hits'];
367 $spage->set_var('hits', $hits);
371 $retval .= $spage->finish($spage->parse('output', 'page'));
372 if (($A['sp_inblock'] == 1) && ($A['sp_format'] != 'blankpage')) {
373 $retval .= COM_endBlock (COM_getBlockTemplate ('_staticpages_block',
377 if ($A['sp_format'] <> 'blankpage') {
378 if (!isset($_USER['noboxes'])) {
379 if (empty($_USER['uid']) || ($_USER['uid'] == 1)) {
380 $_USER['noboxes'] = 0;
382 $_USER['noboxes'] = DB_getItem($_TABLES['userindex'],
383 'noboxes', "uid = '{$_USER['uid']}'");
387 if (($A['sp_format'] == 'allblocks') && ($_USER['noboxes'] != 1)) {
388 $retval .= COM_siteFooter(true);
389 } else if (($A['sp_format'] == 'leftblocks') || ($A['sp_format'] == 'noblocks')) {
390 $retval .= COM_siteFooter(false);
392 $retval .= COM_siteFooter();
400 * Prepare static page for print (i.e. display as "printable version").
402 * @param string $page static page id
403 * @param array $A static page data
404 * @return string HTML for the static page
407 function SP_printPage($page, $A)
409 global $_CONF, $_TABLES, $LANG01, $LANG_DIRECTION;
411 $template_path = staticpages_templatePath();
412 $print = new Template($template_path);
413 $print->set_file(array('print' => 'printable.thtml'));
414 $print->set_var('site_url', $_CONF['site_url']);
415 $print->set_var('site_admin_url', $_CONF['site_admin_url']);
416 $print->set_var('layout_url', $_CONF['layout_url']);
417 $print->set_var('site_name', $_CONF['site_name']);
418 $print->set_var('site_slogan', $_CONF['site_slogan']);
420 $print->set_var('direction', $LANG_DIRECTION);
421 COM_setLangIdAndAttribute($print);
422 $print->set_var('xhtml', XHTML);
423 $print->set_var('page_title', $_CONF['site_name'] . ' - '
424 . stripslashes($A['sp_title']));
425 $sp_url = COM_buildUrl($_CONF['site_url']
426 . '/staticpages/index.php?page=' . $page);
427 $print->set_var('sp_url', $sp_url);
428 $print->set_var('sp_title', stripslashes($A['sp_title']));
429 $print->set_var('sp_content',
430 SP_render_content(stripslashes($A['sp_content']), $A['sp_php']));
431 $print->set_var('sp_hits', COM_numberFormat($A['sp_hits']));
432 $printable = COM_buildURL($_CONF['site_url']
433 . '/staticpages/index.php?page=' . $page . '&mode=print');
434 $print->set_var('printable_url', $printable);
435 if ($A['commentcode'] >= 0) {
436 $commentsUrl = $sp_url . '#comments';
437 $comments = DB_count($_TABLES['comments'],
438 array('sid', 'type'), array($page, 'staticpages'));
439 $numComments = COM_numberFormat($comments);
440 $print->set_var('story_comments', $numComments);
441 $print->set_var('comments_url', $commentsUrl);
442 $print->set_var('comments_text', $numComments . ' ' . $LANG01[3]);
443 $print->set_var('comments_count', $numComments);
444 $print->set_var('lang_comments', $LANG01[3]);
445 $comments_with_count = sprintf($LANG01[121], $numComments);
448 $comments_with_count = COM_createLink($comments_with_count,
451 $print->set_var('comments_with_count', $comments_with_count);
453 $print->parse('output', 'print');
455 return $print->finish($print->get_var('output'));
459 * Prepare static page for display
461 * @param string $page static page id
462 * @param string $mode type of display to return ('', 'print', 'autotag'
463 * @param string $comment_order sorting of comments
464 * @param string $comment_mode comment mode (nested, flat, etc.)
465 * @param int $msg optional message number
466 * @return string HTML for the static page
469 function SP_returnStaticpage($page='', $mode='', $comment_order = 'ASC', $comment_mode = 'nested', $msg = 0)
471 global $_CONF, $_TABLES, $LANG_ACCESS, $LANG_STATIC, $LANG_LOGIN;
481 if (PLG_invokeService('staticpages', 'get', $args, $retval, $svc_msg) == PLG_RET_OK) {
483 if ($mode == 'print') {
484 $retval = SP_printPage($page, $retval);
485 } else if ($mode =='autotag') {
486 $retval = SP_render_content(stripslashes($retval['sp_content']), $retval['sp_php']);
488 $retval = SP_displayPage($page, $retval, $comment_order, $comment_mode, $msg);
491 // increment hit counter for page
492 DB_query("UPDATE {$_TABLES['staticpage']} SET sp_hits = sp_hits + 1 WHERE sp_id = '$page'");
500 * Shows the statistics for the Static Pages plugin on stats.php.
501 * If $showsitestats is 1 then we are to only print the overall stats in the
502 * 'site statistics box' otherwise we show the detailed stats
504 * @param int showsitestate Flag to let us know which stats to get
506 function plugin_showstats_staticpages($showsitestats)
508 global $_CONF, $_TABLES, $LANG_STATIC;
512 $perms = SP_getPerms();
513 if (!empty($perms)) {
514 $perms = ' AND ' . $perms;
516 $result = DB_query("SELECT sp_id,sp_title,sp_hits FROM {$_TABLES['staticpage']} WHERE sp_hits > 0" . $perms . ' ORDER BY sp_hits DESC LIMIT 10');
517 $nrows = DB_numRows($result);
519 require_once $_CONF['path_system'] . 'lib-admin.php';
522 array('text' => $LANG_STATIC['stats_page_title'],
524 'header_class' => 'stats-header-title'),
525 array('text' => $LANG_STATIC['stats_hits'],
526 'field' => 'sp_hits',
527 'header_class' => 'stats-header-count',
528 'field_class' => 'stats-list-count'),
531 $text_arr = array('has_menu' => false,
532 'title' => $LANG_STATIC['stats_headline']
534 for ($i = 0; $i < $nrows; $i++) {
535 $A = DB_fetchArray($result);
536 $A['sp_title'] = stripslashes($A['sp_title']);
537 $A['sid'] = COM_createLink($A['sp_title'],
538 COM_buildUrl($_CONF['site_url']
539 . "/staticpages/index.php?page={$A['sp_id']}"));
540 $A['sp_hits'] = COM_NumberFormat($A['sp_hits']);
543 $retval .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr);
545 $retval .= COM_startBlock($LANG_STATIC['stats_headline']);
546 $retval .= $LANG_STATIC['stats_no_hits'];
547 $retval .= COM_endBlock();
554 * New stats plugin API function for proper integration with the site stats
556 * @return array(item text, item count);
559 function plugin_statssummary_staticpages()
563 $total_pages = SP_countVisiblePages();
565 return array($LANG_STATIC['staticpages'], COM_numberFormat($total_pages));
569 * Geeklog is asking us to provide any new items that show up in the type
570 * drop-down on search.php. Let's let users search static pages!
573 function plugin_searchtypes_staticpages()
575 global $LANG_STATIC, $_SP_CONF;
577 if ($_SP_CONF['includesearch'] == 1) {
578 $tmp['staticpages'] = $LANG_STATIC['staticpages'];
586 * this searches for static pages matching the user query and returns an array of
587 * for the header and table rows back to search.php where it will be formated and
590 * @param string $query Keywords user is looking for
591 * @param date $datestart Start date to get results for
592 * @param date $dateend End date to get results for
593 * @param string $topic The topic they were searching in
594 * @param string $type Type of items they are searching, or 'all' (deprecated)
595 * @param int $author Get all results by this author
596 * @param string $keyType search key type: 'all', 'phrase', 'any'
597 * @param int $page page number of current search (deprecated)
598 * @param int $perpage number of results per page (deprecated)
601 function plugin_dopluginsearch_staticpages($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
603 global $_TABLES, $_DB_dbms, $LANG_STATIC, $LANG09, $_SP_CONF;
605 if ($_SP_CONF['includesearch'] != 1) {
609 // Make sure the query is SQL safe
610 $query = trim(addslashes($query));
612 $sql = "SELECT sp.sp_id AS id, sp.sp_title AS title, sp.sp_content AS description, ";
613 $sql .= "UNIX_TIMESTAMP(sp.sp_date) AS date, sp.sp_uid AS uid, sp.sp_hits AS hits, ";
614 $sql .= "CONCAT('/staticpages/index.php?page=', sp.sp_id) AS url ";
615 $sql .= "FROM {$_TABLES['staticpage']} AS sp,{$_TABLES['users']} AS u ";
616 $sql .= "WHERE (sp.sp_uid = u.uid) AND (sp_php <> 1) ";
617 $sql .= COM_getPermSQL('AND') . COM_getLangSQL('sp_id', 'AND', 'sp') . ' ';
619 if (!empty ($author)) {
620 $sql .= "AND (sp_uid = '$author') ";
623 $search_p = new SearchCriteria('staticpages', $LANG_STATIC['staticpages']);
625 $columns = array('title' => 'sp_title', 'sp_content');
626 $sql .= $search_p->getDateRangeSQL('AND', 'sp_date', $datestart, $dateend);
627 list($sql,$ftsql) = $search_p->buildSearchSQL($keyType, $query, $columns, $sql);
629 $search_p->setSQL($sql);
630 $search_p->setFTSQL($ftsql);
631 $search_p->setRank(3);
632 $search_p->setURLRewrite(true);
634 // Search static page comments
635 $sql = "SELECT c.cid AS id, c.title AS title, c.comment AS description, ";
636 $sql .= "UNIX_TIMESTAMP(c.date) AS date, c.uid AS uid, ";
638 // MSSQL has a problem when concatenating numeric values
639 if ($_DB_dbms == 'mssql') {
640 $sql .= "'/comment.php?mode=view&cid=' + CAST(c.cid AS varchar(10)) AS url ";
642 $sql .= "CONCAT('/comment.php?mode=view&cid=',c.cid) AS url ";
645 $sql .= "FROM {$_TABLES['users']} AS u, {$_TABLES['comments']} AS c ";
646 $sql .= "LEFT JOIN {$_TABLES['staticpage']} AS s ON ((s.sp_id = c.sid) ";
647 $sql .= COM_getPermSQL('AND',0,2,'s') . COM_getLangSQL('sid','AND','s') . ") ";
648 $sql .= "WHERE (u.uid = c.uid) AND (s.commentcode >= 0) AND (s.sp_date <= NOW()) ";
650 if (!empty($author)) {
651 $sql .= "AND (c.uid = '$author') ";
654 $search_c = new SearchCriteria('comments', array($LANG_STATIC['staticpages'],$LANG09[66]));
656 $columns = array('title' => 'c.title', 'comment');
657 $sql .= $search_c->getDateRangeSQL('AND', 'c_date', $datestart, $dateend);
658 list($sql, $ftsql) = $search_c->buildSearchSQL($keyType, $query, $columns, $sql);
660 $search_c->setSQL($sql);
661 $search_c->setFTSQL($ftsql);
662 $search_c->setRank(2);
664 return array($search_p, $search_c);
669 * This will put an option for static pages in the command and control block on
673 function plugin_cclabel_staticpages()
675 global $LANG_STATIC, $_CONF;
677 if (SEC_hasRights ('staticpages.edit,staticpages.delete', 'OR')) {
678 return array ($LANG_STATIC['staticpages'],
679 $_CONF['site_admin_url'] . '/plugins/staticpages/index.php',
680 plugin_geticon_staticpages ());
687 * returns the administrative option for this plugin
690 function plugin_getadminoption_staticpages()
692 global $_CONF, $_TABLES, $LANG_STATIC;
694 if (SEC_hasRights ('staticpages.edit,staticpages.delete', 'OR')) {
695 $result = DB_query ("SELECT COUNT(*) AS cnt FROM {$_TABLES['staticpage']}" . COM_getPermSQL ('WHERE', 0, 3));
696 $A = DB_fetchArray ($result);
697 $total_pages = $A['cnt'];
698 return array ($LANG_STATIC['staticpages'], $_CONF['site_admin_url'] . '/plugins/staticpages/index.php', $total_pages);
703 * Return SQL where statement with appropriate permissions
705 * Takes User id and permission and returns SQL where clause which will return
706 * the appropriate objects.
707 * This assumes that the table has the following security structure:
708 * owner_id | mediumint(8)
709 * group_id | mediumint(8)
710 * perm_owner | tinyint(1) unsigned
711 * perm_group | tinyint(1) unsigned
712 * perm_members | tinyint(1) unsigned
713 * perm_anon | tinyint(1) unsigned
714 * This will work with the standard GL tables
716 * @param string $table Table name (used in joins)
717 * @param int $access Access if blank read access 2 = read 3 = read/edit
718 * @param int $u_id User ID if blank current user
719 * @return string Where clause of sql statement
722 function SP_getPerms ($table = '', $access = '2', $u_id = '')
724 global $_USER, $_GROUPS;
726 if ($table != '') { $table .= '.'; }
729 if (isset ($_USER['uid'])) {
730 $uid = $_USER['uid'];
737 $GROUPS = SEC_getUserGroups ($uid);
743 $sql .= "((owner_id = '{$uid}') AND (perm_owner >= $access)) OR ";
745 $sql .= "((group_id IN (" . implode (',', $GROUPS) . ")) "
746 . "AND (perm_group >= $access)) OR (perm_members >= $access)";
748 $sql .= "perm_anon >= $access";
757 * Display static pages in the center block.
759 * @param where int where the static page will be displayed (0..3)
760 * @param page int page number
761 * @param topic string topic ID
762 * @return string HTML for the static page (can be empty)
764 function plugin_centerblock_staticpages ($where = 1, $page = 1, $topic ='')
766 global $_CONF, $_TABLES, $_SP_CONF, $LANG_STATIC, $_IMAGE_TYPE, $LANG01;
771 return $retval; // we only support page 1 at the moment ...
774 $moresql = "(sp_where = $where) AND ";
775 $displayFeatured = false;
777 // If there are no featured stories, we won't be called with $where == 2.
778 // So, if asked to display pages for the top of the page, check if we
779 // have pages to be displayed after the featured story and if there is
780 // no featured story, display those pages as well.
781 if (($where == 1) && ($_CONF['showfirstasfeatured'] == 0)) {
782 if (DB_count ($_TABLES['stories'], 'featured', 1) == 0) {
783 // no featured story found - redefine $moresql
784 $moresql = "(sp_where = 1 OR sp_where = 2) AND ";
785 $displayFeatured = true;
789 if (empty ($topic)) {
790 $moresql .= "((sp_tid = 'none') OR (sp_tid = 'all'))";
792 $moresql .= "((sp_tid = '{$topic}') OR (sp_tid = 'all'))";
795 if ($_SP_CONF['sort_by'] == 'date') {
796 $sort = 'sp_date DESC';
797 } else if ($_SP_CONF['sort_by'] == 'title') {
799 } else { // default to "sort by id"
802 if ($displayFeatured) {
803 $sort = 'sp_where,' . $sort;
806 $perms = SP_getPerms ();
807 if (!empty ($perms)) {
808 $perms = ' AND ' . $perms;
810 $spsql = "SELECT sp_id,sp_title,sp_content,sp_format,sp_date,sp_hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon,sp_php,sp_inblock,sp_help FROM {$_TABLES['staticpage']} WHERE (sp_centerblock = 1)" . COM_getLangSql ('sp_id', 'AND') . ' AND ' . $moresql . $perms . " ORDER BY " . $sort;
811 $result = DB_query ($spsql);
813 $pages = DB_numRows ($result);
815 for ($i = 0; $i < $pages; $i++) {
816 $S = DB_fetchArray ($result);
819 switch ($S['sp_format']) {
821 $retval .= COM_siteHeader ('none');
825 $retval .= COM_siteHeader ('menu');
828 if (isset($_GET['msg'])) {
829 $msg = COM_applyFilter($_GET['msg'], true);
831 $retval .= COM_showMessage($msg);
836 if (($S['sp_inblock'] == 1) && !empty ($S['sp_title'])
837 && (($where != 0) || ($S['sp_format'] != 'blankpage'))) {
838 $retval .= COM_startBlock ($S['sp_title'], $S['sp_help'],
839 COM_getBlockTemplate ('_staticpages_centerblock', 'header'));
842 $spage = new Template( $_CONF['path'] . 'plugins/staticpages/templates/' );
843 $spage->set_file( array('page'=>'centerblock.thtml'));
844 $spage->set_var('xhtml', XHTML);
845 $spage->set_var('site_url', $_CONF['site_url']);
846 $spage->set_var('layout_url', $_CONF['layout_url']);
847 $spage->set_var('site_admin_url', $_CONF['site_admin_url']);
849 if ($_CONF['hideprintericon'] == 0) {
850 $icon_url = $_CONF['layout_url'] . '/images/print.' . $_IMAGE_TYPE;
851 $attr = array('title' => $LANG_STATIC['printable_format']);
852 $printicon = COM_createImage($icon_url, $LANG01[65], $attr);
853 $print_url = COM_buildURL ($_CONF['site_url']
854 . '/staticpages/index.php?page=' . $S['sp_id'] . '&mode=print');
855 $icon = COM_createLink($printicon, $print_url);
856 $spage->set_var('print_icon', $icon);
858 if ((SEC_hasAccess ($S['owner_id'], $S['group_id'], $S['perm_owner'],
859 $S['perm_group'], $S['perm_members'], $S['perm_anon']) == 3) &&
860 SEC_hasRights ('staticpages.edit')) {
861 $icon_url = $_CONF['layout_url'] . '/images/edit.' . $_IMAGE_TYPE;
862 $attr = array('title' => $LANG_STATIC['edit']);
863 $editiconhtml = COM_createImage($icon_url, $LANG_STATIC['edit'], $attr);
864 $url = $_CONF['site_admin_url']
865 . '/plugins/staticpages/index.php?mode=edit&sp_id=' . $S['sp_id'];
866 $attr = array('class' => 'editlink','title' => $LANG_STATIC['edit']);
868 ' ' . COM_createLink(
869 $editiconhtml, //display
871 $attr //other attributes
873 $spage->set_var('edit_icon', $icon);
876 $spage->set_var('info_separator', 'hidden');
877 if ($_SP_CONF['show_date'] == 1) {
878 $curtime = COM_getUserDateTimeFormat($S['sp_date']);
879 $lastupdate = $LANG_STATIC['lastupdated']. ' ' . $curtime[0];
880 $spage->set_var('lastupdate', $lastupdate);
883 if ($_SP_CONF['show_hits'] == 1) {
884 if ($_SP_CONF['show_date'] == 1) {
885 $spage->set_var('info_separator', 'visible');
887 $hits = COM_numberFormat($S['sp_hits']) . ' '
888 . $LANG_STATIC['hits'];
889 $spage->set_var('hits', $hits);
892 $content = SP_render_content (stripslashes ($S['sp_content']), $S['sp_php']);
893 $spage->set_var('content', $content );
894 $retval .= $spage->finish($spage->parse('output', 'page'));
895 if (($S['sp_inblock'] == 1) && !empty ($S['sp_title'])
896 && (($where != 0) || ($S['sp_format'] != 'blankpage'))) {
897 $retval .= COM_endBlock (COM_getBlockTemplate ('_staticpages_centerblock', 'footer'));
901 if ($S['sp_format'] == 'allblocks') {
902 $retval .= COM_siteFooter (true);
903 } else if ($S['sp_format'] != 'blankpage') {
904 $retval .= COM_siteFooter ();
908 // increment hit counter for page
909 DB_query ("UPDATE {$_TABLES['staticpage']} SET sp_hits = sp_hits + 1 WHERE sp_id = '{$S['sp_id']}'");
917 * A user is about to be deleted. Update ownership of any static pages owned
918 * by that user or delete them.
920 * @param uid int User id of deleted user
923 function plugin_user_delete_staticpages($uid)
925 global $_TABLES, $_SP_CONF;
927 if (DB_count ($_TABLES['staticpage'], 'sp_uid', $uid) +
928 DB_count ($_TABLES['staticpage'], 'owner_id', $uid) == 0) {
932 if ($_SP_CONF['delete_pages'] == 1) {
934 DB_query ("DELETE FROM {$_TABLES['staticpage']} WHERE (sp_uid = $uid) OR (owner_id = $uid)");
936 // assign ownership to a user from the Root group
937 $rootgroup = DB_getItem ($_TABLES['groups'], 'grp_id',
938 "grp_name = 'Root'");
939 $result = DB_query ("SELECT DISTINCT ug_uid FROM {$_TABLES['group_assignments']} WHERE ug_main_grp_id = $rootgroup ORDER BY ug_uid LIMIT 1");
940 $A = DB_fetchArray ($result);
941 $rootuser = $A['ug_uid'];
943 DB_query ("UPDATE {$_TABLES['staticpage']} SET sp_uid = $rootuser WHERE sp_uid = $uid");
944 DB_query ("UPDATE {$_TABLES['staticpage']} SET owner_id = $rootuser WHERE owner_id = $uid");
950 * Return the current version of code.
951 * Used in the Plugin Editor to show the registered version and code version
953 function plugin_chkVersion_staticpages()
957 require_once $_CONF['path'] . 'plugins/staticpages/autoinstall.php';
959 $inst_parms = plugin_autoinstall_staticpages('staticpages');
961 return $inst_parms['info']['pi_version'];
965 * Implements the [staticpage:] autotag.
968 function plugin_autotags_staticpages($op, $content = '', $autotag = '')
970 global $_CONF, $_TABLES;
972 static $recursive = array();
974 if ($op == 'tagname' ) {
975 return array('staticpage', 'staticpage_content');
976 } else if ($op == 'parse') {
977 if ($autotag['tag'] == 'staticpage' ) {
978 $sp_id = COM_applyFilter($autotag['parm1']);
979 if (! empty($sp_id)) {
980 $url = COM_buildUrl($_CONF['site_url']
981 . '/staticpages/index.php?page=' . $sp_id);
982 if (empty($autotag['parm2'])) {
983 $linktext = stripslashes(DB_getItem($_TABLES['staticpage'],
984 'sp_title', "sp_id = '$sp_id'"));
986 $linktext = $autotag['parm2'];
988 $link = COM_createLink($linktext, $url);
989 $content = str_replace($autotag['tagstr'], $link, $content);
991 } else if ($autotag['tag'] == 'staticpage_content') {
992 $sp_id = COM_applyFilter($autotag['parm1']);
993 if (! empty($sp_id)) {
994 if (isset($recursive[$sp_id])) {
997 $recursive[$sp_id] = true;
998 $sp_content = SP_returnStaticpage($sp_id, 'autotag');
999 $content = str_replace($autotag['tagstr'], $sp_content,
1010 * Returns the URL of the plugin's icon
1012 * @return string URL of the icon
1015 function plugin_geticon_staticpages ()
1019 return $_CONF['site_url'] . '/staticpages/images/staticpages.png';
1023 * Update the Static Pages plugin
1025 * @return int Number of message to display (true = generic success msg)
1028 function plugin_upgrade_staticpages()
1030 global $_CONF, $_TABLES, $_DB_dbms;
1032 $installed_version = DB_getItem($_TABLES['plugins'], 'pi_version',
1033 "pi_name = 'staticpages'");
1034 $code_version = plugin_chkVersion_staticpages();
1035 if ($installed_version == $code_version) {
1040 require_once $_CONF['path'] . 'plugins/staticpages/autoinstall.php';
1042 if (! plugin_compatible_with_this_version_staticpages('staticpages')) {
1046 $inst_parms = plugin_autoinstall_staticpages('staticpages');
1047 $pi_gl_version = $inst_parms['info']['pi_gl_version'];
1049 require_once $_CONF['path'] . 'plugins/staticpages/sql/'
1050 . $_DB_dbms . '_updates.php';
1052 $current_version = $installed_version;
1055 switch ($current_version) {
1058 $current_version = '1.6.0';
1062 if (isset($_UPDATES[$current_version])) {
1063 $_SQL = $_UPDATES[$current_version];
1064 foreach ($_SQL as $sql) {
1069 update_ConfValues_1_6_0();
1071 $current_version = '1.6.1';
1079 DB_query("UPDATE {$_TABLES['plugins']} SET pi_version = '$code_version', pi_gl_version = '$pi_gl_version' WHERE pi_name = 'staticpages'");
1085 * Called during site migration - handle changed URLs or paths
1087 * @param array $old_conf contents of the $_CONF array on the old site
1088 * @param boolean true on success, otherwise false
1091 function plugin_migrate_staticpages($old_conf)
1096 'staticpage' => 'sp_id, sp_content'
1099 if ($old_conf['site_url'] != $_CONF['site_url']) {
1100 INST_updateSiteUrl($old_conf['site_url'], $_CONF['site_url'], $tables);
1107 * Automatic uninstall function for plugins
1111 * This code is automatically uninstalling the plugin.
1112 * It passes an array to the core code function that removes
1113 * tables, groups, features and php blocks from the tables.
1114 * Additionally, this code can perform special actions that cannot be
1115 * foreseen by the core code (interactions with other plugins for example)
1118 function plugin_autouninstall_staticpages ()
1121 /* give the name of the tables, without $_TABLES[] */
1122 'tables' => array('staticpage'),
1123 /* give the full name of the group, as in the db */
1124 'groups' => array('Static Page Admin', // correct Admin group name
1125 'Static Pages Admin' // typo in Geeklog 1.6.0
1127 /* give the full name of the feature, as in the db */
1128 'features' => array('staticpages.edit', 'staticpages.delete', 'staticpages.PHP'),
1129 /* give the full name of the block, including 'phpblock_', etc */
1130 'php_blocks' => array('phpblock_calendar'),
1131 /* give all vars with their name */
1139 * Get path for the template files.
1141 * @param string $path subdirectory within the base template path
1142 * @return string full path to template directory
1145 function staticpages_templatePath ($path = '')
1149 if (empty ($path)) {
1150 $layout_path = $_CONF['path_layout'] . 'staticpages';
1152 $layout_path = $_CONF['path_layout'] . 'staticpages/' . $path;
1155 if (is_dir ($layout_path)) {
1156 $retval = $layout_path;
1158 $retval = $_CONF['path'] . 'plugins/staticpages/templates';
1159 if (!empty ($path)) {
1160 $retval .= '/' . $path;
1167 function plugin_getListField_staticpages($fieldname, $fieldvalue, $A, $icon_arr)
1169 global $_CONF, $LANG_ADMIN, $LANG_STATIC, $_TABLES;
1171 switch($fieldname) {
1173 $retval = COM_createLink($icon_arr['edit'],
1174 "{$_CONF['site_admin_url']}/plugins/staticpages/index.php?mode=edit&sp_id={$A['sp_id']}");
1177 $retval = COM_createLink($icon_arr['copy'],
1178 "{$_CONF['site_admin_url']}/plugins/staticpages/index.php?mode=clone&sp_id={$A['sp_id']}");
1181 $sp_title = stripslashes ($A['sp_title']);
1182 $url = COM_buildUrl ($_CONF['site_url'] .
1183 '/staticpages/index.php?page=' . $A['sp_id']);
1184 $retval = COM_createLink($sp_title, $url, array('title'=>$LANG_STATIC['title_display']));
1187 $retval = COM_getDisplayName ($A['sp_uid']);
1189 case "sp_centerblock":
1190 if ($A['sp_centerblock']) {
1191 switch ($A['sp_where']) {
1192 case '1': $where = $LANG_STATIC['centerblock_top']; break;
1193 case '2': $where = $LANG_STATIC['centerblock_feat']; break;
1194 case '3': $where = $LANG_STATIC['centerblock_bottom']; break;
1195 default: $where = $LANG_STATIC['centerblock_entire']; break;
1199 $retval = $LANG_STATIC['centerblock_no'];
1203 $retval = strftime ($_CONF['daytime'], $A['unixdate']);
1206 $retval = $fieldvalue;
1213 * Render the actual content of a static page (without any surrounding blocks)
1215 * @param string $sp_content the content (HTML or PHP source)
1216 * @param int $sp_php flag: 1 = content is PHP source, 0 = is HTML
1217 * @return string rendered content (HTML)
1220 function SP_render_content ($sp_content, $sp_php)
1222 global $_SP_CONF, $LANG_STATIC;
1226 if ($_SP_CONF['allow_php'] == 1) {
1227 // Check for type (ie html or php)
1229 $retval = eval ($sp_content);
1230 } else if ($sp_php == 2) {
1233 $retval = ob_get_contents ();
1236 $retval = $sp_content;
1238 $retval = PLG_replacetags ($retval);
1241 COM_errorLog ("PHP in static pages is disabled. Can not display page '$page'.", 1);
1242 $retval .= $LANG_STATIC['deny_msg'];
1244 $retval .= PLG_replacetags ($sp_content);
1252 * Return true since this plugin supports webservices
1254 * @return bool True, if webservices are supported
1256 function plugin_wsEnabled_staticpages()
1262 * Return headlines for New Static Pages section in the What's New block, if enabled
1264 * @return mixed array(headline, byline), or boolean false if disabled
1267 function plugin_whatsnewsupported_staticpages()
1269 global $_SP_CONF, $LANG_STATIC, $LANG_WHATSNEW;
1271 if ($_SP_CONF['hidenewstaticpages'] == 0) {
1272 $retval = array($LANG_STATIC['pages'],
1273 COM_formatTimeString($LANG_WHATSNEW['new_last'],
1274 $_SP_CONF['newstaticpagesinterval'])
1284 * Return new Static Pages for the What's New block
1286 * @return string HTML list of new staticpages
1289 function plugin_getwhatsnew_staticpages()
1291 global $_CONF, $_TABLES, $_SP_CONF, $LANG_STATIC;
1296 if ($_SP_CONF['includecenterblocks'] == 0) {
1297 $extra_sql =' AND sp_centerblock = 0';
1299 if ($_SP_CONF['includephp'] == 0) {
1300 $extra_sql .=' AND sp_php = 0';
1303 $sql = "SELECT sp_id, sp_title
1304 FROM {$_TABLES['staticpage']}
1305 WHERE NOT ISNULL(sp_content) AND (sp_date >= (DATE_SUB(NOW(), INTERVAL {$_SP_CONF['newstaticpagesinterval']} SECOND)))
1307 " . COM_getPermSQL( 'AND' ) . "
1308 ORDER BY sp_date DESC LIMIT 15";
1310 $result = DB_query( $sql );
1312 $nrows = DB_numRows( $result );
1316 $newstaticpages = array();
1318 for( $x = 0; $x < $nrows; $x++ )
1320 $A = DB_fetchArray( $result );
1322 $url = COM_buildUrl( $_CONF['site_url']
1323 . '/staticpages/index.php?page=' . $A['sp_id'] );
1325 $title = COM_undoSpecialChars( stripslashes( $A['sp_title'] ));
1326 $titletouse = COM_truncate( $title, $_SP_CONF['title_trim_length'],
1328 if( $title != $titletouse )
1330 $attr = array('title' => htmlspecialchars($title));
1336 $astaticpage = str_replace( '$', '$', $titletouse );
1337 $astaticpage = str_replace( ' ', ' ', $astaticpage );
1339 $newstaticpages[] = COM_createLink($astaticpage, $url, $attr);
1342 $retval .= COM_makeList( $newstaticpages, 'list-new-comments' );
1346 $retval .= $LANG_STATIC['no_new_pages'] . '<br' . XHTML . '>' . LB;
1353 * Return information for a static page
1355 * @param string $sp_id static page ID or '*'
1356 * @param string $what comma-separated list of properties
1357 * @param int $uid user ID or 0 = current user
1358 * @param array $options (reserved for future extensions)
1359 * @return mixed string or array of strings with the information
1362 function plugin_getiteminfo_staticpages($sp_id, $what, $uid = 0, $options = array())
1364 global $_CONF, $_TABLES;
1366 // parse $what to see what we need to pull from the database
1367 $properties = explode(',', $what);
1369 foreach ($properties as $p) {
1371 case 'date-modified':
1372 $fields[] = 'UNIX_TIMESTAMP(sp_date) AS unixdate';
1376 $fields[] = 'sp_content';
1377 $fields[] = 'sp_php';
1380 $fields[] = 'sp_id';
1383 $fields[] = 'sp_title';
1386 // needed for $sp_id == '*', but also in case we're only requesting
1387 // the URL (so that $fields isn't emtpy)
1388 $fields[] = 'sp_id';
1396 $fields = array_unique($fields);
1398 if (count($fields) == 0) {
1404 // prepare SQL request
1405 if ($sp_id == '*') {
1409 $where = " WHERE sp_id = '" . addslashes($sp_id) . "'";
1413 $permSql = COM_getPermSql($permOp, $uid);
1415 $permSql = COM_getPermSql($permOp);
1417 $sql = "SELECT " . implode(',', $fields)
1418 . " FROM {$_TABLES['staticpage']}" . $where . $permSql;
1419 if ($sp_id != '*') {
1423 $result = DB_query($sql);
1424 $numRows = DB_numRows($result);
1427 for ($i = 0; $i < $numRows; $i++) {
1428 $A = DB_fetchArray($result);
1431 foreach ($properties as $p) {
1433 case 'date-modified':
1434 $props['date-modified'] = $A['unixdate'];
1438 $props[$p] = SP_render_content(stripslashes($A['sp_content']),
1442 $props['id'] = $A['sp_id'];
1445 $props['title'] = stripslashes($A['sp_title']);
1448 if (empty($A['sp_id'])) {
1449 $props['url'] = COM_buildUrl($_CONF['site_url']
1450 . '/staticpages/index.php?page=' . $sp_id);
1452 $props['url'] = COM_buildUrl($_CONF['site_url']
1453 . '/staticpages/index.php?page=' . $A['sp_id']);
1457 // return empty string for unknown properties
1464 foreach ($props as $key => $value) {
1465 if ($sp_id == '*') {
1467 $mapped[$key] = $value;
1474 if ($sp_id == '*') {
1475 $retval[] = $mapped;
1482 if (($sp_id != '*') && (count($retval) == 1)) {
1483 $retval = $retval[0];
1490 * Provide URL of a documentation file
1492 * @param string $file documentation file being requested, e.g. 'config'
1493 * @return mixed URL or false when not available
1496 function plugin_getdocumentationurl_staticpages($file)
1505 if (isset($docurl)) {
1508 $doclang = COM_getLanguageName();
1509 $docs = 'docs/' . $doclang . '/staticpages.html';
1510 if (file_exists($_CONF['path_html'] . $docs)) {
1511 $retval = $_CONF['site_url'] . '/' . $docs;
1513 $retval = $_CONF['site_url'] . '/docs/english/staticpages.html';
1528 * Provide URL and ID for the link to a comment's parent
1530 * NOTE: The Plugin API does not support $_CONF['url_rewrite'] here,
1531 * so we'll end up with a non-rewritten URL ...
1533 * @return array array consisting of the base URL and the ID name
1536 function plugin_getcommenturlid_staticpages()
1541 $_CONF['site_url'] . '/staticpages/index.php',