plugins/staticpages/services.inc.php
author Dirk Haun <dirk@haun-online.de>
Sat, 03 Oct 2009 21:15:34 +0200
branchHEAD
changeset 7354 82e167a0e3a4
parent 7228 5524c9cdb063
child 7496 59e9aa23b118
permissions -rw-r--r--
Made the meta tag handling somewhat more consistent
     1 <?php
     2 
     3 // Reminder: always indent with 4 spaces (no tabs). 
     4 // +---------------------------------------------------------------------------+
     5 // | Static Pages Plugin 1.6                                                   |
     6 // +---------------------------------------------------------------------------+
     7 // | services.inc.php                                                          |
     8 // |                                                                           |
     9 // | This file implements the services provided by the 'Static Pages' plugin.  |
    10 // +---------------------------------------------------------------------------+
    11 // | Copyright (C) 2000-2009 by the following authors:                         |
    12 // |                                                                           |
    13 // | Authors: Tony Bibbs       - tony AT tonybibbs DOT com                     |
    14 // |          Tom Willett      - twillett AT users DOT sourceforge DOT net     |
    15 // |          Blaine Lang      - langmail AT sympatico DOT ca                  |
    16 // |          Dirk Haun        - dirk AT haun-online DOT de                    |
    17 // |          Ramnath R Iyer   - rri AT silentyak DOT com                      |
    18 // +---------------------------------------------------------------------------+
    19 // |                                                                           |
    20 // | This program is free software; you can redistribute it and/or             |
    21 // | modify it under the terms of the GNU General Public License               |
    22 // | as published by the Free Software Foundation; either version 2            |
    23 // | of the License, or (at your option) any later version.                    |
    24 // |                                                                           |
    25 // | This program is distributed in the hope that it will be useful,           |
    26 // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
    27 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
    28 // | GNU General Public License for more details.                              |
    29 // |                                                                           |
    30 // | You should have received a copy of the GNU General Public License         |
    31 // | along with this program; if not, write to the Free Software Foundation,   |
    32 // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
    33 // |                                                                           |
    34 // +---------------------------------------------------------------------------+
    35 
    36 /**
    37 * Functions related to the webservices and the internal plugin API
    38 *
    39 * @package StaticPages
    40 */
    41 
    42 if (strpos(strtolower($_SERVER['PHP_SELF']), 'services.inc.php') !== false) {
    43     die('This file can not be used on its own.');
    44 }
    45 
    46 /**
    47 * Max. length of the ID for a static page.
    48 * This must be kept in sync with the actual size of 'sp_id' in the db.
    49 */
    50 define('STATICPAGE_MAX_ID_LENGTH', 40);
    51 
    52 /**
    53  * Submit static page. The page is updated if it exists, or a new one is created
    54  *
    55  * @param   array   args     Contains all the data provided by the client
    56  * @param   string  &output  OUTPUT parameter containing the returned text
    57  * @param   string  &svc_msg OUTPUT parameter containing any service messages
    58  * @return  int		     Response code as defined in lib-plugins.php
    59  */
    60 function service_submit_staticpages($args, &$output, &$svc_msg)
    61 {
    62     global $_CONF, $_TABLES, $_USER, $LANG_ACCESS, $LANG12, $LANG_STATIC,
    63            $LANG_LOGIN, $_GROUPS, $_SP_CONF;
    64 
    65     if (version_compare(PHP_VERSION, '5.0.0', '>=') &&
    66             (! $_CONF['disable_webservices'])) {
    67         require_once $_CONF['path_system'] . '/lib-webservices.php';
    68     }
    69 
    70     $output = '';
    71 
    72     if (!SEC_hasRights('staticpages.edit')) {
    73         $output = COM_siteHeader('menu', $LANG_STATIC['access_denied']);
    74         $output .= COM_startBlock($LANG_STATIC['access_denied'], '',
    75                                   COM_getBlockTemplate('_msg_block', 'header'));
    76         $output .= $LANG_STATIC['access_denied_msg'];
    77         $output .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer'));
    78         $output .= COM_siteFooter();
    79 
    80         return PLG_RET_AUTH_FAILED;
    81     }
    82 
    83     // TEST CODE
    84     /*
    85     foreach ($args as $k => $v) {
    86         if (!is_array($v)) {
    87             echo "$k => $v\r\n";
    88         } else {
    89             echo "$k => $v\r\n";
    90             foreach ($v as $k1 => $v1) {
    91                 echo "        $k1 => $v1\r\n";
    92             }
    93         }
    94     }
    95     exit ();
    96     */
    97     $gl_edit = false;
    98     if (isset($args['gl_edit'])) {
    99         $gl_edit = $args['gl_edit'];
   100     }
   101     if ($gl_edit) {
   102         // This is EDIT mode, so there should be an sp_old_id 
   103         if (empty($args['sp_old_id'])) {
   104             if (!empty($args['id'])) {
   105                 $args['sp_old_id'] = $args['id'];
   106             } else {
   107                 return PLG_RET_ERROR;
   108             }
   109 
   110             if (empty($args['sp_id'])) {
   111                 $args['sp_id'] = $args['sp_old_id'];
   112             }
   113         }
   114     } else {
   115         if (empty($args['sp_id']) && !empty($args['id'])) {
   116             $args['sp_id'] = $args['id'];
   117         }
   118     }
   119 
   120     if (!isset($args['sp_uid'])) {
   121         $args['sp_uid'] = $_USER['uid'];
   122     }
   123 
   124     if (empty($args['sp_title']) && !empty($args['title'])) {
   125         $args['sp_title'] = $args['title'];
   126     }
   127 
   128     if (empty($args['sp_content']) && !empty($args['content'])) {
   129         $args['sp_content'] = $args['content'];
   130     }
   131 
   132     if (isset($args['category']) && is_array($args['category']) &&
   133             !empty($args['category'][0])) {
   134         $args['sp_tid'] = $args['category'][0];
   135     }
   136 
   137     if (!isset($args['owner_id'])) {
   138         $args['owner_id'] = $_USER['uid'];
   139     }
   140 
   141     if (empty($args['group_id'])) {
   142         $args['group_id'] = SEC_getFeatureGroup('staticpages.edit', $_USER['uid']);
   143     }
   144 
   145     $args['sp_id'] = COM_sanitizeID($args['sp_id']);
   146     if (!$gl_edit) {
   147         if (strlen($args['sp_id']) > STATICPAGE_MAX_ID_LENGTH) {
   148             $slug = '';
   149             if (isset($args['slug'])) {
   150                 $slug = $args['slug'];
   151             }
   152             if (function_exists('WS_makeId')) {
   153                 $args['sp_id'] = WS_makeId($slug, STATICPAGE_MAX_ID_LENGTH);
   154             } else {
   155                 $args['sp_id'] = COM_makeSid();
   156             }
   157         }
   158     }
   159 
   160     // Apply filters to the parameters passed by the webservice 
   161     if ($args['gl_svc']) {
   162         $par_str = array('mode', 'sp_id', 'sp_old_id', 'sp_tid', 'sp_format',
   163                          'postmode');
   164         $par_num = array('sp_uid', 'sp_hits', 'owner_id', 'group_id',
   165                          'sp_where', 'sp_php', 'commentcode');
   166 
   167         foreach ($par_str as $str) {
   168             if (isset($args[$str])) {
   169                 $args[$str] = COM_applyBasicFilter($args[$str]);
   170             } else {
   171                 $args[$str] = '';
   172             }
   173         }
   174 
   175         foreach ($par_num as $num) {
   176             if (isset($args[$num])) {
   177                 $args[$num] = COM_applyBasicFilter($args[$num], true);
   178             } else {
   179                 $args[$num] = 0;
   180             }
   181         }
   182     }
   183 
   184     // START: Staticpages defaults 
   185 
   186     if(empty($args['sp_format'])) {
   187         $args['sp_format'] = 'allblocks';
   188     }
   189 
   190     if (empty($args['sp_tid'])) {
   191         $args['sp_tid'] = 'all';
   192     }
   193 
   194     if (($args['sp_where'] < 0) || ($args['sp_where'] > 3)) {
   195         $args['sp_where'] = 0;
   196     }
   197 
   198     if (($args['sp_php'] < 0) || ($args['sp_php'] > 2)) {
   199         $args['sp_php'] = 0;
   200     }
   201 
   202     if (($args['commentcode'] < -1) || ($args['commentcode'] > 1)) {
   203         $args['commentcode'] = $_CONF['comment_code'];
   204     }
   205 
   206     if ($args['gl_svc']) {
   207         // Permissions 
   208         if (!isset($args['perm_owner'])) {
   209             $args['perm_owner'] = $_SP_CONF['default_permissions'][0];
   210         } else {
   211             $args['perm_owner'] = COM_applyBasicFilter($args['perm_owner'], true);
   212         }
   213         if (!isset($args['perm_group'])) {
   214             $args['perm_group'] = $_SP_CONF['default_permissions'][1];
   215         } else {
   216             $args['perm_group'] = COM_applyBasicFilter($args['perm_group'], true);
   217         }
   218         if (!isset($args['perm_members'])) {
   219             $args['perm_members'] = $_SP_CONF['default_permissions'][2];
   220         } else {
   221             $args['perm_members'] = COM_applyBasicFilter($args['perm_members'], true);
   222         }
   223         if (!isset($args['perm_anon'])) {
   224             $args['perm_anon'] = $_SP_CONF['default_permissions'][3];
   225         } else {
   226             $args['perm_anon'] = COM_applyBasicFilter($args['perm_anon'], true);
   227         }
   228 
   229         if (!isset($args['sp_onmenu'])) {
   230             $args['sp_onmenu'] = '';
   231         } else if (($args['sp_onmenu'] == 'on') && empty($args['sp_label'])) {
   232             $svc_msg['error_desc'] = 'Menu label missing';
   233             return PLG_RET_ERROR;
   234         }
   235 
   236         if (empty($args['sp_content'])) {
   237             $svc_msg['error_desc'] = 'No content';
   238             return PLG_RET_ERROR;
   239         }
   240 
   241         if (empty($args['sp_inblock']) && ($_SP_CONF['in_block'] == '1')) {
   242             $args['sp_inblock'] = 'on';
   243         }
   244 
   245         if (empty($args['sp_centerblock'])) {
   246             $args['sp_centerblock'] = '';
   247         }
   248     }
   249 
   250     // END: Staticpages defaults 
   251 
   252     $sp_id = $args['sp_id'];
   253     $sp_uid = $args['sp_uid'];
   254     $sp_title = $args['sp_title'];
   255     $sp_content = $args['sp_content'];
   256     $sp_hits = $args['sp_hits'];
   257     $sp_format = $args['sp_format'];
   258     $sp_onmenu = $args['sp_onmenu'];
   259     $sp_label = '';
   260     if (!empty($args['sp_label'])) {
   261         $sp_label = $args['sp_label'];
   262     }
   263     $meta_description = $args['meta_description'];
   264     $meta_keywords = $args['meta_keywords'];    
   265     $commentcode = $args['commentcode'];
   266     $owner_id = $args['owner_id'];
   267     $group_id = $args['group_id'];
   268     $perm_owner = $args['perm_owner'];
   269     $perm_group = $args['perm_group'];
   270     $perm_members = $args['perm_members'];
   271     $perm_anon = $args['perm_anon'];
   272     $sp_php = $args['sp_php'];
   273     $sp_nf = '';
   274     if (!empty($args['sp_nf'])) {
   275         $sp_nf = $args['sp_nf'];
   276     }
   277     $sp_old_id = $args['sp_old_id'];
   278     $sp_centerblock = $args['sp_centerblock'];
   279     $sp_help = '';
   280     if (!empty($args['sp_help'])) {
   281         $sp_help = $args['sp_help'];
   282     }
   283     $sp_tid = $args['sp_tid'];
   284     $sp_where = $args['sp_where'];
   285     $sp_inblock = $args['sp_inblock'];
   286     $postmode = $args['postmode'];
   287 
   288     if ($gl_edit && !empty($args['gl_etag'])) {
   289         // First load the original staticpage to check if it has been modified 
   290         $o = array();
   291         $s = array();
   292         $r = service_get_staticpages(array('sp_id' => $sp_old_id, 'gl_svc' => true), $o, $s);
   293 
   294         if ($r == PLG_RET_OK) {
   295             if ($args['gl_etag'] != $o['updated']) {
   296                 $svc_msg['error_desc'] = 'A more recent version of the staticpage is available';
   297                 return PLG_RET_PRECONDITION_FAILED;
   298             }
   299         } else {
   300             $svc_msg['error_desc'] = 'The requested staticpage no longer exists';
   301             return PLG_RET_ERROR;
   302         }
   303     }
   304 
   305     // Check for unique page ID
   306     $duplicate_id = false;
   307     $delete_old_page = false;
   308     if (DB_count ($_TABLES['staticpage'], 'sp_id', $sp_id) > 0) {
   309         if ($sp_id != $sp_old_id) {
   310             $duplicate_id = true;
   311         }
   312     } elseif (!empty ($sp_old_id)) {
   313         if ($sp_id != $sp_old_id) {
   314             $delete_old_page = true;
   315         }
   316     }
   317 
   318     if ($duplicate_id) {
   319         $output .= COM_siteHeader ('menu', $LANG_STATIC['staticpageeditor']);
   320         $output .= COM_errorLog ($LANG_STATIC['duplicate_id'], 2);
   321         if (!$args['gl_svc']) {
   322             $output .= staticpageeditor ($sp_id);
   323         }
   324         $output .= COM_siteFooter ();
   325         $svc_msg['error_desc'] = 'Duplicate ID';
   326         return PLG_RET_ERROR;
   327     } elseif (!empty ($sp_title) && !empty ($sp_content)) {
   328         if (empty ($sp_hits)) {
   329             $sp_hits = 0;
   330         }
   331 
   332         if ($sp_onmenu == 'on') {
   333             $sp_onmenu = 1;
   334         } else {
   335             $sp_onmenu = 0;
   336         }
   337         if ($sp_nf == 'on') {
   338             $sp_nf = 1;
   339         } else {
   340             $sp_nf = 0;
   341         }
   342         if ($sp_centerblock == 'on') {
   343             $sp_centerblock = 1;
   344         } else {
   345             $sp_centerblock = 0;
   346         }
   347         if ($sp_inblock == 'on') {
   348             $sp_inblock = 1;
   349         } else {
   350             $sp_inblock = 0;
   351         }
   352 
   353         // Clean up the text
   354         if ($_SP_CONF['censor'] == 1) {
   355             $sp_content = COM_checkWords ($sp_content);
   356             $sp_title = COM_checkWords ($sp_title);
   357         }
   358         if ($_SP_CONF['filter_html'] == 1) {
   359             $sp_content = COM_checkHTML($sp_content, 'staticpages.edit');
   360         }
   361         $sp_title = strip_tags ($sp_title);
   362         $sp_label = strip_tags ($sp_label);
   363 
   364         $meta_description = strip_tags ($meta_description);
   365         $meta_keywords = strip_tags ($meta_keywords);
   366 
   367         $sp_content = addslashes ($sp_content);
   368         $sp_title = addslashes ($sp_title);
   369         $sp_label = addslashes ($sp_label);
   370         $meta_description = addslashes ($meta_description);
   371         $meta_keywords = addslashes ($meta_keywords);        
   372 
   373         // If user does not have php edit perms, then set php flag to 0.
   374         if (($_SP_CONF['allow_php'] != 1) || !SEC_hasRights ('staticpages.PHP')) {
   375             $sp_php = 0;
   376         }
   377 
   378         // make sure there's only one "entire page" static page per topic
   379         if (($sp_centerblock == 1) && ($sp_where == 0)) {
   380             $sql = "UPDATE {$_TABLES['staticpage']} SET sp_centerblock = 0 WHERE sp_centerblock = 1 AND sp_where = 0 AND sp_tid = '$sp_tid'";
   381 
   382             // if we're in a multi-language setup, we need to allow one "entire
   383             // page" centerblock for 'all' or 'none' per language
   384             if ((!empty($_CONF['languages']) &&
   385                     !empty($_CONF['language_files'])) &&
   386                     (($sp_tid == 'all') || ($sp_tid == 'none'))) {
   387                 $ids = explode('_', $sp_id);
   388                 if (count($ids) > 1) {
   389                     $lang_id = array_pop($ids);
   390 
   391                     $sql .= " AND sp_id LIKE '%\\_$lang_id'";
   392                 }
   393             }
   394 
   395             DB_query($sql);
   396         }
   397 
   398         $formats = array ('allblocks', 'blankpage', 'leftblocks', 'noblocks');
   399         if (!in_array ($sp_format, $formats)) {
   400             $sp_format = 'allblocks';
   401         }
   402 
   403         if (!$args['gl_svc']) {
   404             list($perm_owner,$perm_group,$perm_members,$perm_anon) = SEC_getPermissionValues($perm_owner,$perm_group,$perm_members,$perm_anon);
   405         }
   406 
   407         DB_save ($_TABLES['staticpage'], 'sp_id,sp_uid,sp_title,sp_content,sp_date,sp_hits,sp_format,sp_onmenu,sp_label,commentcode,meta_description,meta_keywords,owner_id,group_id,'
   408                 .'perm_owner,perm_group,perm_members,perm_anon,sp_php,sp_nf,sp_centerblock,sp_help,sp_tid,sp_where,sp_inblock,postmode',
   409                 "'$sp_id',$sp_uid,'$sp_title','$sp_content',NOW(),$sp_hits,'$sp_format',$sp_onmenu,'$sp_label','$commentcode','$meta_description','$meta_keywords',$owner_id,$group_id,"
   410                         ."$perm_owner,$perm_group,$perm_members,$perm_anon,'$sp_php','$sp_nf',$sp_centerblock,'$sp_help','$sp_tid',$sp_where,"
   411                         ."'$sp_inblock','$postmode'");
   412 
   413         if ($delete_old_page && !empty ($sp_old_id)) {
   414             DB_delete ($_TABLES['staticpage'], 'sp_id', $sp_old_id);
   415         }
   416 
   417         if (empty($sp_old_id) || ($sp_id == $sp_old_id)) {
   418             PLG_itemSaved($sp_id, 'staticpages');
   419         } else {
   420             DB_change($_TABLES['comments'], 'sid', addslashes($sp_id),
   421                       array('sid', 'type'),
   422                       array(addslashes($sp_old_id), 'staticpages'));
   423             PLG_itemSaved($sp_id, 'staticpages', $sp_old_id);
   424         }
   425 
   426         $url = COM_buildURL($_CONF['site_url'] . '/staticpages/index.php?page='
   427                             . $sp_id);
   428         $output .= PLG_afterSaveSwitch($_SP_CONF['aftersave'], $url,
   429                                        'staticpages', 19);
   430 
   431         $svc_msg['id'] = $sp_id;
   432         return PLG_RET_OK;
   433     } else {
   434         $output .= COM_siteHeader ('menu', $LANG_STATIC['staticpageeditor']);
   435         $output .= COM_errorLog ($LANG_STATIC['no_title_or_content'], 2);
   436         if (!$args['gl_svc']) {
   437             $output .= staticpageeditor ($sp_id);
   438         }
   439         $output .= COM_siteFooter ();
   440         return PLG_RET_ERROR;
   441     }
   442 }
   443 
   444 /**
   445  * Delete an existing static page
   446  *
   447  * @param   array   args    Contains all the data provided by the client
   448  * @param   string  &output OUTPUT parameter containing the returned text
   449  * @param   string  &svc_msg OUTPUT parameter containing any service messages
   450  * @return  int		    Response code as defined in lib-plugins.php
   451  */
   452 function service_delete_staticpages($args, &$output, &$svc_msg)
   453 {
   454     global $_CONF, $_TABLES, $_USER, $LANG_ACCESS, $LANG12, $LANG_STATIC,
   455            $LANG_LOGIN;
   456 
   457     $output = COM_refresh($_CONF['site_admin_url']
   458                           . '/plugins/staticpages/index.php?msg=20');
   459 
   460     if (empty($args['sp_id']) && !empty($args['id']))
   461         $args['sp_id'] = $args['id'];
   462 
   463     // Apply filters to the parameters passed by the webservice 
   464 
   465     if ($args['gl_svc']) {
   466         $args['sp_id'] = COM_applyBasicFilter($args['sp_id']);
   467         $args['mode'] = COM_applyBasicFilter($args['mode']);
   468     }
   469 
   470     $sp_id = $args['sp_id'];
   471 
   472     if (!SEC_hasRights ('staticpages.delete')) {
   473         $output = COM_siteHeader ('menu', $LANG_STATIC['access_denied']);
   474         $output .= COM_startBlock ($LANG_STATIC['access_denied'], '',
   475                                     COM_getBlockTemplate ('_msg_block', 'header'));
   476         $output .= $LANG_STATIC['access_denied_msg'];
   477         $output .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
   478         $output .= COM_siteFooter ();
   479         if ($_USER['uid'] > 1) {
   480             return PLG_RET_PERMISSION_DENIED;
   481         } else {
   482             return PLG_RET_AUTH_FAILED;
   483         }
   484     }
   485 
   486     DB_delete($_TABLES['staticpage'], 'sp_id', $sp_id);
   487     DB_delete($_TABLES['comments'], array('sid',  'type'),
   488                                     array($sp_id, 'staticpages'));
   489 
   490     PLG_itemDeleted($sp_id, 'staticpages');
   491 
   492     return PLG_RET_OK;
   493 }
   494 
   495 /**
   496  * Get an existing static page
   497  *
   498  * @param   array   args    Contains all the data provided by the client
   499  * @param   string  &output OUTPUT parameter containing the returned text
   500  * @param   string  &svc_msg OUTPUT parameter containing any service messages
   501  * @return  int		    Response code as defined in lib-plugins.php
   502  */
   503 function service_get_staticpages($args, &$output, &$svc_msg)
   504 {
   505     global $_CONF, $_TABLES, $LANG_ACCESS, $LANG12, $LANG_STATIC, $LANG_LOGIN, $_SP_CONF;
   506 
   507     $output = '';
   508 
   509     $svc_msg['output_fields'] = array(
   510                                     'sp_hits',
   511                                     'sp_format',
   512                                     'owner_id',
   513                                     'group_id',
   514                                     'perm_owner',
   515                                     'perm_group',
   516                                     'perm_members',
   517                                     'perm_anon',
   518                                     'sp_help',
   519                                     'sp_php',
   520                                     'sp_inblock',
   521                                     'commentcode'
   522                                      );
   523 
   524     if (empty($args['sp_id']) && !empty($args['id'])) {
   525         $args['sp_id'] = $args['id'];
   526     }
   527 
   528     if ($args['gl_svc']) {
   529         if (isset($args['sp_id'])) {
   530             $args['sp_id'] = COM_applyBasicFilter($args['sp_id']);
   531         }
   532         if (isset($args['mode'])) {
   533             $args['mode'] = COM_applyBasicFilter($args['mode']);
   534         }
   535 
   536         if (empty($args['sp_id'])) {
   537             $svc_msg['gl_feed'] = true;
   538         } else {
   539             $svc_msg['gl_feed'] = false;
   540         }
   541     } else {
   542         $svc_msg['gl_feed'] = false;
   543     }
   544 
   545     if (!$svc_msg['gl_feed']) {
   546         $page = '';
   547         if (isset($args['sp_id'])) {
   548             $page = $args['sp_id'];
   549         }
   550         $mode = '';
   551         if (isset($args['mode'])) {
   552             $mode = $args['mode'];
   553         }
   554 
   555         $error = 0;
   556 
   557         if ($page == '') {
   558             $error = 1;
   559         }
   560         $perms = SP_getPerms ();
   561         if (!empty ($perms)) {
   562             $perms = ' AND ' . $perms;
   563         }
   564         $sql = array();
   565         $sql['mysql'] = "SELECT sp_title,sp_content,sp_hits,sp_date,sp_format,"
   566                       . "commentcode,meta_description,meta_keywords,owner_id,"
   567                       . "group_id,perm_owner,perm_group,"
   568                       . "perm_members,perm_anon,sp_tid,sp_help,sp_php,"
   569                       . "sp_inblock FROM {$_TABLES['staticpage']} "
   570                       . "WHERE (sp_id = '$page')" . $perms;
   571         $sql['mssql'] = "SELECT sp_title,"
   572                       . "CAST(sp_content AS text) AS sp_content,sp_hits,"
   573                       . "sp_date,sp_format,commentcode,"
   574                       . "CAST(meta_description AS text) AS meta_description,"
   575                       . "CAST(meta_keywords AS text) AS meta_keywords,"
   576                       . "owner_id,group_id,perm_owner,perm_group,perm_members,"
   577                       . "perm_anon,sp_tid,sp_help,sp_php,sp_inblock "
   578                       . "FROM {$_TABLES['staticpage']} WHERE (sp_id = '$page')"
   579                       . $perms;
   580         $result = DB_query ($sql);
   581         $count = DB_numRows ($result);
   582 
   583         if ($count == 0 || $count > 1) {
   584             $error = 1;
   585         }
   586 
   587         if (!($error)) {
   588             $output = DB_fetchArray ($result, false);
   589 
   590             // WE ASSUME $output doesn't have any confidential fields 
   591 
   592         } else { // an error occured (page not found, access denied, ...)
   593             if (empty ($page)) {
   594                 $failflg = 0;
   595             } else {
   596                 $failflg = DB_getItem ($_TABLES['staticpage'], 'sp_nf', "sp_id='$page'");
   597             }
   598             if ($failflg) {
   599                 if ($mode !== 'autotag') {
   600                     $output = COM_siteHeader ('menu');
   601                 }
   602                 $output .= COM_startBlock ($LANG_LOGIN[1], '',
   603                                         COM_getBlockTemplate ('_msg_block', 'header'));
   604                 $login = new Template ($_CONF['path_layout'] . 'submit');
   605                 $login->set_file (array ('login' => 'submitloginrequired.thtml'));
   606                 $login->set_var ('login_message', $LANG_LOGIN[2]);
   607                 $login->set_var ('site_url', $_CONF['site_url']);
   608                 $login->set_var ('lang_login', $LANG_LOGIN[3]);
   609                 $login->set_var ('lang_newuser', $LANG_LOGIN[4]);
   610                 $login->parse ('output', 'login');
   611                 $output .= $login->finish ($login->get_var ('output'));
   612                 $output .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
   613                 if ($mode !== 'autotag') {
   614                     $output .= COM_siteFooter (true);
   615                 }
   616             } else {
   617                 if ($mode !== 'autotag') {
   618                     $output = COM_siteHeader ('menu');
   619                 }
   620                 $output .= COM_startBlock ($LANG_ACCESS['accessdenied'], '',
   621                                         COM_getBlockTemplate ('_msg_block', 'header'));
   622                 $output .= $LANG_STATIC['deny_msg'];
   623                 $output .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
   624                 if ($mode !== 'autotag') {
   625                     $output .= COM_siteFooter (true);
   626                 }
   627             }
   628 
   629             return PLG_RET_ERROR;
   630         }
   631 
   632         if ($args['gl_svc']) {
   633             // This date format is PHP 5 only,
   634             // but only the web-service uses the value
   635             $output['published']    = date('c', strtotime($output['sp_date']));
   636             $output['updated']      = date('c', strtotime($output['sp_date']));
   637             $output['id']           = $page;
   638             $output['title']        = $output['sp_title'];
   639             $output['category']     = array($output['sp_tid']);
   640             $output['content']      = $output['sp_content'];
   641             $output['content_type'] = 'html';
   642 
   643             $owner_data = SESS_getUserDataFromId($output['owner_id']);
   644 
   645             $output['author_name']  = $owner_data['username'];
   646 
   647             $output['link_edit'] = $page;
   648         }
   649     } else {
   650         $output = array();
   651 
   652         $mode = '';
   653         if (isset($args['mode'])) {
   654             $mode = $args['mode'];
   655         }
   656 
   657         $perms = SP_getPerms();
   658         if (!empty ($perms)) {
   659             $perms = ' WHERE ' . $perms;
   660         }
   661 
   662         $offset = 0;
   663         if (isset($args['offset'])) {
   664             $offset = COM_applyBasicFilter($args['offset'], true);
   665         }
   666         $max_items = $_SP_CONF['atom_max_items'] + 1;
   667 
   668         $limit = " LIMIT $offset, $max_items";
   669         $order = " ORDER BY sp_date DESC";
   670         $sql = array();
   671         $sql['mysql'] = "SELECT sp_id,sp_title,sp_content,sp_hits,sp_date,sp_format,meta_description,meta_keywords,owner_id,"
   672                 ."group_id,perm_owner,perm_group,perm_members,perm_anon,sp_tid,sp_help,sp_php,"
   673                 ."sp_inblock FROM {$_TABLES['staticpage']}" . $perms . $order . $limit;
   674         $sql['mssql'] = "SELECT sp_id,sp_title,CAST(sp_content AS text) AS sp_content,sp_hits,"
   675                 ."sp_date,sp_format,CAST(meta_description AS text) AS meta_description,CAST(meta_keywords AS text) AS meta_keywords,owner_id,group_id,perm_owner,perm_group,perm_members,"
   676                 ."perm_anon,sp_tid,sp_help,sp_php,sp_inblock FROM {$_TABLES['staticpage']}"
   677                 . $perms . $order . $limit;
   678         $result = DB_query ($sql);
   679 
   680         $count = 0;
   681         while (($output_item = DB_fetchArray ($result, false)) !== false) {
   682             // WE ASSUME $output doesn't have any confidential fields 
   683 
   684             $count += 1;
   685             if ($count == $max_items) {
   686                 $svc_msg['offset'] = $offset + $_SP_CONF['atom_max_items'];
   687                 break;
   688             }
   689 
   690             if($args['gl_svc']) {
   691                 // This date format is PHP 5 only, but only the web-service uses the value 
   692                 $output_item['published']    = date('c', strtotime($output_item['sp_date']));
   693                 $output_item['updated']      = date('c', strtotime($output_item['sp_date']));
   694                 $output_item['id']           = $output_item['sp_id'];
   695                 $output_item['title']        = $output_item['sp_title'];
   696                 $output_item['category']     = array($output_item['sp_tid']);
   697                 $output_item['content']      = $output_item['sp_content'];
   698                 $output_item['content_type'] = 'html';
   699 
   700                 $owner_data = SESS_getUserDataFromId($output_item['owner_id']);
   701 
   702                 $output_item['author_name']  = $owner_data['username'];
   703             }
   704             $output[] = $output_item;
   705         }
   706     }
   707 
   708     return PLG_RET_OK;
   709 }
   710 
   711 /**
   712  * Get all the topics available
   713  *
   714  * @param   array   args    Contains all the data provided by the client
   715  * @param   string  &output OUTPUT parameter containing the returned text
   716  * @return  int         Response code as defined in lib-plugins.php
   717  */
   718 function service_getTopicList_staticpages($args, &$output, &$svc_msg)
   719 {
   720     //$output = COM_topicArray('tid');
   721     $output[] = 'all';
   722     $output[] = 'none';
   723 
   724     return PLG_RET_OK;
   725 }
   726 
   727 ?>