/** * Get an existing story * * @param array args Contains all the data provided by the client * @param string &output OUTPUT parameter containing the returned text * @return int Response code as defined in lib-plugins.php */ function service_get_story($args, &$output, &$svc_msg) { global $_CONF, $_TABLES, $_USER; $output = array(); $retval = ''; if (!isset($_CONF['atom_max_stories'])) { $_CONF['atom_max_stories'] = 10; // set a resonable default } $svc_msg['output_fields'] = array('draft_flag', 'hits', 'numemails', 'comments', 'trackbacks', 'featured', 'commentcode', 'statuscode', 'expire_date', 'postmode', 'advanced_editor_mode', 'frontpage', 'owner_id', 'group_id', 'perm_owner', 'perm_group', 'perm_members', 'perm_anon'); if (empty($args['sid']) && !empty($args['id'])) { $args['sid'] = $args['id']; } if ($args['gl_svc']) { if (isset($args['mode'])) { $args['mode'] = COM_applyBasicFilter($args['mode']); } if (isset($args['sid'])) { $args['sid'] = COM_applyBasicFilter($args['sid']); } if (empty($args['sid'])) { $svc_msg['gl_feed'] = true; } else { $svc_msg['gl_feed'] = false; } } else { $svc_msg['gl_feed'] = false; } if (empty($args['mode'])) { $args['mode'] = 'view'; } if (!$svc_msg['gl_feed']) { $sid = $args['sid']; $mode = $args['mode']; $story = new Story(); $retval = $story->loadFromDatabase($sid, $mode); if ($retval != STORY_LOADED_OK) { $output = $retval; return PLG_RET_ERROR; } reset($story->_dbFields); while (list($fieldname, $save) = each($story->_dbFields)) { $varname = '_' . $fieldname; $output[$fieldname] = $story->{$varname}; } $output['username'] = $story->_username; $output['fullname'] = $story->_fullname; if ($args['gl_svc']) { if ($output['statuscode'] == STORY_ARCHIVE_ON_EXPIRE || $output['statuscode'] == STORY_DELETE_ON_EXPIRE) { // This date format is PHP 5 only, // but only the web-service uses the value $output['expire_date'] = date('c', $output['expire']); } $output['id'] = $output['sid']; $output['category'] = array($output['tid']); $output['published'] = date('c', $output['date']); $output['updated'] = date('c', $output['date']); if (empty($output['bodytext'])) { $output['content'] = $output['introtext']; } else { $output['content'] = $output['introtext'] . LB . '[page_break]' . LB . $output['bodytext']; } $output['content_type'] = $output['postmode'] == 'html' ? 'html' : 'text'; $owner_data = SESS_getUserDataFromId($output['owner_id']); $output['author_name'] = $owner_data['username']; $output['link_edit'] = $sid; } } else { $output = array(); $mode = $args['mode']; $sql = array(); if (isset($args['offset'])) { $offset = COM_applyBasicFilter($args['offset'], true); } else { $offset = 0; } $max_items = $_CONF['atom_max_stories'] + 1; $limit = " LIMIT {$offset}, {$max_items}"; $limit_pgsql = " LIMIT {$max_items} OFFSET {$offset}"; $order = " ORDER BY unixdate DESC"; $sql['mysql'] = "SELECT s.*, UNIX_TIMESTAMP(s.date) AS unixdate, UNIX_TIMESTAMP(s.expire) as expireunix, " . "u.username, u.fullname, u.photo, u.email, t.topic, t.imageurl " . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, {$_TABLES['topics']} AS t " . "WHERE (s.uid = u.uid) AND (s.tid = t.tid)" . COM_getPermSQL('AND', $_USER['uid'], 2, 's') . $order . $limit; $sql['pgsql'] = "SELECT s.*, UNIX_TIMESTAMP(s.date) AS unixdate, UNIX_TIMESTAMP(s.expire) as expireunix, u.username, u.fullname, u.photo, u.email, t.topic, t.imageurl FROM stories s, users u, topics t WHERE (s.uid = u.uid) AND (s.tid = t.tid) FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, {$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid)" . COM_getPermSQL('AND', $_USER['uid'], 2, 's') . $order . $limit_pgsql; $result = DB_query($sql); $count = 0; while (($story_array = DB_fetchArray($result, false)) !== false) { $count += 1; if ($count == $max_items) { $svc_msg['offset'] = $offset + $_CONF['atom_max_stories']; break; } $story = new Story(); $story->loadFromArray($story_array); // This access check is not strictly necessary $access = SEC_hasAccess($story_array['owner_id'], $story_array['group_id'], $story_array['perm_owner'], $story_array['perm_group'], $story_array['perm_members'], $story_array['perm_anon']); $story->_access = min($access, SEC_hasTopicAccess($story->_tid)); if ($story->_access == 0) { continue; } $story->sanitizeData(); reset($story->_dbFields); $output_item = array(); while (list($fieldname, $save) = each($story->_dbFields)) { $varname = '_' . $fieldname; $output_item[$fieldname] = $story->{$varname}; } if ($args['gl_svc']) { if ($output_item['statuscode'] == STORY_ARCHIVE_ON_EXPIRE || $output_item['statuscode'] == STORY_DELETE_ON_EXPIRE) { // This date format is PHP 5 only, // but only the web-service uses the value $output_item['expire_date'] = date('c', $output_item['expire']); } $output_item['id'] = $output_item['sid']; $output_item['category'] = array($output_item['tid']); $output_item['published'] = date('c', $output_item['date']); $output_item['updated'] = date('c', $output_item['date']); if (empty($output_item['bodytext'])) { $output_item['content'] = $output_item['introtext']; } else { $output_item['content'] = $output_item['introtext'] . LB . '[page_break]' . LB . $output_item['bodytext']; } $output_item['content_type'] = $output_item['postmode'] == 'html' ? 'html' : 'text'; $owner_data = SESS_getUserDataFromId($output_item['owner_id']); $output_item['author_name'] = $owner_data['username']; } $output[] = $output_item; } } return PLG_RET_OK; }