Example #1
0
/**
* Ask plugin for information about a specific item
*
* Item properties that can be requested:
* - 'date-created'    - creation date, if available
* - 'date-modified'   - date of last modification, if available
* - 'description'     - full description of the item (formatted)
* - 'raw-description' - full raw description (no parsing of tags, etc.)
* - 'excerpt'         - short description of the item
* - 'id'              - ID of the item, e.g. sid for articles
* - 'title'           - title of the item
* - 'url'             - URL of the item
* - 'label'           - Plugin label
*
* 'excerpt' and 'description' may return the same value. Properties that are
* not available should return an empty string.
* Return false for errors (e.g. access denied, item does not exist, etc.).
*
* @param    string  $type       plugin type (incl. 'article' for stories)
* @param    string  $id         ID of an item under the plugin's control or '*'
* @param    string  $what       comma-separated list of item properties
* @param    int     $uid        user ID or 0 = current user
* @param    array   $options    (reserved for future extensions)
* @return   mixed               string or array of strings with the information
*
*/
function PLG_getItemInfo($type, $id, $what, $uid = 0, $options = array())
{
    global $_CONF;
    if ($type == 'article') {
        USES_lib_story();
        return STORY_getItemInfo($id, $what, $uid, $options);
    } else {
        $args[1] = $id;
        $args[2] = $what;
        $args[3] = $uid;
        $args[4] = $options;
        $function = 'plugin_getiteminfo_' . $type;
        return PLG_callFunctionForOnePlugin($function, $args);
    }
}
Example #2
0
function _createMailStory($sid)
{
    global $_CONF, $_TABLES, $LANG_DIRECTION, $LANG01, $LANG08;
    USES_lib_story();
    $story = new Story();
    $args = array('sid' => $sid, 'mode' => 'view');
    $output = STORY_LOADED_OK;
    $result = PLG_invokeService('story', 'get', $args, $output, $svc_msg);
    if ($result == PLG_RET_OK) {
        /* loadFromArray cannot be used, since it overwrites the timestamp */
        reset($story->_dbFields);
        while (list($fieldname, $save) = each($story->_dbFields)) {
            $varname = '_' . $fieldname;
            if (array_key_exists($fieldname, $output)) {
                $story->{$varname} = $output[$fieldname];
            }
        }
        $story->_username = $output['username'];
        $story->_fullname = $output['fullname'];
    }
    if ($output == STORY_PERMISSION_DENIED) {
        $display = COM_siteHeader('menu', $LANG_ACCESS['accessdenied']) . COM_showMessageText($LANG_ACCESS['storydenialmsg'], $LANG_ACCESS['accessdenied'], true, 'error') . COM_siteFooter();
        echo $display;
        exit;
    } elseif ($output == STORY_INVALID_SID) {
        COM_404();
    } else {
        $T = new Template($_CONF['path_layout'] . 'article');
        $T->set_file('article', 'mailable.thtml');
        list($cacheFile, $style_cache_url) = COM_getStyleCacheLocation();
        $T->set_var('direction', $LANG_DIRECTION);
        $T->set_var('css_url', $style_cache_url);
        $T->set_var('page_title', $_CONF['site_name'] . ': ' . $story->displayElements('title'));
        $T->set_var('story_title', $story->DisplayElements('title'));
        $T->set_var('story_subtitle', $story->DisplayElements('subtitle'));
        $story_image = $story->DisplayElements('story_image');
        if ($story_image != '') {
            $T->set_var('story_image', $story_image);
        } else {
            $T->unset_var('story_image');
        }
        if ($_CONF['hidestorydate'] != 1) {
            $T->set_var('story_date', $story->displayElements('date'));
        }
        if ($_CONF['contributedbyline'] == 1) {
            $T->set_var('lang_contributedby', $LANG01[1]);
            $authorname = COM_getDisplayName($story->displayElements('uid'));
            $T->set_var('author', $authorname);
            $T->set_var('story_author', $authorname);
            $T->set_var('story_author_username', $story->DisplayElements('username'));
        }
        $T->set_var('story_introtext', $story->DisplayElements('introtext'));
        $T->set_var('story_bodytext', $story->DisplayElements('bodytext'));
        $T->set_var('site_name', $_CONF['site_name']);
        $T->set_var('site_slogan', $_CONF['site_slogan']);
        $T->set_var('story_id', $story->getSid());
        $articleUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
        if ($story->DisplayElements('commentcode') >= 0) {
            $commentsUrl = $articleUrl . '#comments';
            $comments = $story->DisplayElements('comments');
            $numComments = COM_numberFormat($comments);
            $T->set_var('story_comments', $numComments);
            $T->set_var('comments_url', $commentsUrl);
            $T->set_var('comments_text', $numComments . ' ' . $LANG01[3]);
            $T->set_var('comments_count', $numComments);
            $T->set_var('lang_comments', $LANG01[3]);
            $comments_with_count = sprintf($LANG01[121], $numComments);
            if ($comments > 0) {
                $comments_with_count = COM_createLink($comments_with_count, $commentsUrl);
            }
            $T->set_var('comments_with_count', $comments_with_count);
        }
        $T->set_var('lang_full_article', $LANG08[33]);
        $T->set_var('article_url', $articleUrl);
        COM_setLangIdAndAttribute($T);
        $T->parse('output', 'article');
        $htmlMsg = $T->finish($T->get_var('output'));
        return $htmlMsg;
    }
}
Example #3
0
/**
 * article: display comment(s)
 *
 * @param   string  $id     Unique idenifier for item comment belongs to
 * @param   int     $cid    Comment id to display (possibly including sub-comments)
 * @param   string  $title  Page/comment title
 * @param   string  $order  'ASC' or 'DESC' or blank
 * @param   string  $format 'threaded', 'nested', or 'flat'
 * @param   int     $page   Page number of comments to display
 * @param   boolean $view   True to view comment (by cid), false to display (by $pid)
 * @return  mixed   results of calling the plugin_displaycomment_ function
*/
function plugin_displaycomment_article($id, $cid, $title, $order, $format, $page, $view)
{
    global $_CONF, $_TABLES, $LANG_ACCESS;
    USES_lib_story();
    USES_class_story();
    $retval = '';
    // display story
    $sql = "SELECT s.*, UNIX_TIMESTAMP(s.date) AS unixdate, " . 'UNIX_TIMESTAMP(s.expire) as expireunix, ' . "u.uid, u.username, u.fullname, t.topic, t.imageurl " . "FROM {$_TABLES['stories']} AS s LEFT JOIN {$_TABLES['users']} AS u ON s.uid=u.uid " . "LEFT JOIN {$_TABLES['topics']} AS t on s.tid=t.tid " . "WHERE (sid = '" . DB_escapeString($id) . "') " . 'AND (draft_flag = 0) AND (commentcode >= 0) AND (date <= NOW())' . COM_getPermSQL('AND', 0, 2, 's') . COM_getTopicSQL('AND', 0, 't') . ' GROUP BY sid,owner_id, group_id, perm_owner, s.perm_group,s.perm_members, s.perm_anon ';
    $result = DB_query($sql);
    $nrows = DB_numRows($result);
    if ($A = DB_fetchArray($result)) {
        $story = new Story();
        $story->loadFromArray($A);
        $retval .= STORY_renderArticle($story, 'n');
    }
    // end
    $sql = 'SELECT COUNT(*) AS count, commentcode, uid, owner_id, group_id, perm_owner, perm_group, ' . "perm_members, perm_anon FROM {$_TABLES['stories']} " . "WHERE (sid = '" . DB_escapeString($id) . "') " . 'AND (draft_flag = 0) AND (commentcode >= 0) AND (date <= NOW())' . COM_getPermSQL('AND') . COM_getTopicSQL('AND') . ' GROUP BY sid,owner_id, group_id, perm_owner, perm_group,perm_members, perm_anon ';
    $result = DB_query($sql);
    $B = DB_fetchArray($result);
    $allowed = $B['count'];
    if ($allowed == 1) {
        $delete_option = SEC_hasRights('story.edit') && SEC_hasAccess($B['owner_id'], $B['group_id'], $B['perm_owner'], $B['perm_group'], $B['perm_members'], $B['perm_anon']) == 3;
        $retval .= CMT_userComments($id, $title, 'article', $order, $format, $cid, $page, $view, $delete_option, $B['commentcode'], $B['uid']);
    } else {
        $retval .= COM_showMessageText($LANG_ACCESS['storydenialmsg'], $LANG_ACCESS['accessdenied'], true);
    }
    return $retval;
}
Example #4
0
// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.          |
// |                                                                          |
// +--------------------------------------------------------------------------+
/**
* This page is responsible for showing a single article in different modes which
* may, or may not, include the comments attached
*
* @author   Jason Whittenburg
* @author   Tony Bibbbs <*****@*****.**>
* @author   Vincent Furia <vinny01 AT users DOT sourceforge DOT net>
*/
/**
* glFusion common function library
*/
require_once 'lib-common.php';
USES_lib_story();
if ($_CONF['trackback_enabled']) {
    USES_lib_trackback();
}
// MAIN
$display = '';
$pageBody = '';
$pagetitle = '';
$pingback = false;
$order = '';
$query = '';
$reply = '';
if (isset($_POST['mode'])) {
    $sid = COM_sanitizeID(COM_applyFilter($_POST['story']));
    $mode = COM_applyFilter($_POST['mode']);
    if (isset($_POST['order'])) {
Example #5
0
/**
* This will email new stories in the topics that the user is interested in
*
* In account information the user can specify which topics for which they
* will receive any new article for in a daily digest.
*
* @return   void
*/
function COM_emailUserTopics()
{
    global $_CONF, $_USER, $_VARS, $_TABLES, $LANG04, $LANG08, $LANG24;
    if ($_CONF['emailstories'] == 0) {
        return;
    }
    $storytext = '';
    $storytext_text = '';
    USES_lib_story();
    $subject = strip_tags($_CONF['site_name'] . $LANG08[30] . strftime('%Y-%m-%d', time()));
    $authors = array();
    // Get users who want stories emailed to them
    $usersql = "SELECT username,email,etids,{$_TABLES['users']}.uid AS uuid, status " . "FROM {$_TABLES['users']}, {$_TABLES['userindex']} " . "WHERE {$_TABLES['users']}.uid > 1 AND {$_TABLES['userindex']}.uid = {$_TABLES['users']}.uid AND status=" . USER_ACCOUNT_ACTIVE . " AND (etids <> '-' OR etids IS NULL) ORDER BY {$_TABLES['users']}.uid";
    $users = DB_query($usersql);
    $nrows = DB_numRows($users);
    if (!isset($_VARS['lastemailedstories'])) {
        $_VARS['lastemailedstories'] = 0;
    }
    $lastrun = $_VARS['lastemailedstories'];
    // For each user, pull the stories they want and email it to them
    for ($x = 0; $x < $nrows; $x++) {
        $U = DB_fetchArray($users);
        $storysql = "SELECT sid,uid,date AS day,title,introtext,bodytext";
        $commonsql = " FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW() AND date >= '{$lastrun}'";
        $topicsql = "SELECT tid FROM {$_TABLES['topics']}" . COM_getPermSQL('WHERE', $U['uuid']);
        $tresult = DB_query($topicsql);
        $trows = DB_numRows($tresult);
        if ($trows == 0) {
            // this user doesn't seem to have access to any topics ...
            continue;
        }
        $TIDS = array();
        for ($i = 0; $i < $trows; $i++) {
            $T = DB_fetchArray($tresult);
            $TIDS[] = $T['tid'];
        }
        if (!empty($U['etids'])) {
            $ETIDS = explode(' ', $U['etids']);
            $TIDS = array_intersect($TIDS, $ETIDS);
        }
        if (sizeof($TIDS) > 0) {
            $commonsql .= " AND (tid IN ('" . implode("','", $TIDS) . "'))";
        }
        $commonsql .= COM_getPermSQL('AND', $U['uuid']);
        $commonsql .= ' ORDER BY featured DESC, date DESC';
        $storysql .= $commonsql;
        $stories = DB_query($storysql);
        $nsrows = DB_numRows($stories);
        if ($nsrows == 0) {
            // If no new stories where pulled for this user, continue with next
            continue;
        }
        $T = new Template($_CONF['path_layout']);
        $T->set_file(array('message' => 'digest.thtml', 'story' => 'digest_story.thtml'));
        $TT = new Template($_CONF['path_layout']);
        $TT->set_file(array('message' => 'digest_text.thtml', 'story' => 'digest_story_text.thtml'));
        $T->set_var('week_date', strftime($_CONF['shortdate'], time()));
        $TT->set_var('week_date', strftime($_CONF['shortdate'], time()));
        $T->set_var('site_name', $_CONF['site_name']);
        $TT->set_var('site_name', $_CONF['site_name']);
        $T->set_var('remove_msg', sprintf($LANG08[36], $_CONF['site_name'], $_CONF['site_url']));
        $TT->set_var('remove_msg', sprintf($LANG08[37], $_CONF['site_name'], $_CONF['site_url']));
        for ($y = 0; $y < $nsrows; $y++) {
            // Loop through stories building the requested email message
            $S = DB_fetchArray($stories);
            $story = new Story();
            $args = array('sid' => $S['sid'], 'mode' => 'view');
            $output = STORY_LOADED_OK;
            $result = PLG_invokeService('story', 'get', $args, $output, $svc_msg);
            if ($result == PLG_RET_OK) {
                /* loadFromArray cannot be used, since it overwrites the timestamp */
                reset($story->_dbFields);
                while (list($fieldname, $save) = each($story->_dbFields)) {
                    $varname = '_' . $fieldname;
                    if (array_key_exists($fieldname, $output)) {
                        $story->{$varname} = $output[$fieldname];
                    }
                }
                $story->_username = $output['username'];
                $story->_fullname = $output['fullname'];
            }
            $story_url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $S['sid']);
            $title = COM_undoSpecialChars($S['title']);
            if ($_CONF['contributedbyline'] == 1) {
                if (empty($authors[$S['uid']])) {
                    $storyauthor = COM_getDisplayName($S['uid']);
                    $authors[$S['uid']] = $storyauthor;
                } else {
                    $storyauthor = $authors[$S['uid']];
                }
            }
            $dt = new Date($S['day'], $_USER['tzid']);
            $story_date = $dt->format($_CONF['date'], true);
            if ($_CONF['emailstorieslength'] > 0) {
                $storytext = COM_undoSpecialChars(strip_tags(PLG_replaceTags($S['introtext'], 'glfusion', 'story')));
                $storytext_text = COM_undoSpecialChars(strip_tags(PLG_replaceTags($S['introtext'], 'glfusion', 'story')));
                if ($_CONF['emailstorieslength'] > 1) {
                    $storytext = COM_truncate($storytext, $_CONF['emailstorieslength'], '...');
                    $storytext_text = COM_truncate($storytext_text, $_CONF['emailstorieslength'], '...');
                }
            } else {
                $storytext = '';
                $storytext_text = '';
            }
            $T->set_var('story_introtext', $storytext);
            $TT->set_var('story_introtext', $storytext_text);
            $T->set_var(array('story_url' => $story_url, 'story_title' => $title, 'story_author' => $storyauthor, 'story_date' => $story_date, 'story_text' => $storytext));
            $T->parse('digest_stories', 'story', true);
            $TT->set_var(array('story_url' => $story_url, 'story_title' => $title, 'story_author' => $storyauthor, 'story_date' => $story_date, 'story_text' => $storytext_text));
            $TT->parse('digest_stories', 'story', true);
        }
        $T->parse('digest', 'message', true);
        $TT->parse('digest', 'message', true);
        $mailtext = $T->finish($T->get_var('digest'));
        $mailtext_text = $TT->finish($TT->get_var('digest'));
        $mailfrom = $_CONF['noreply_mail'];
        $mailtext .= LB . LB . $LANG04[159];
        $mailtext_text .= LB . LB . $LANG04[159];
        $to = array();
        $from = array();
        $from = COM_formatEmailAddress('', $mailfrom);
        $to = COM_formatEmailAddress($U['username'], $U['email']);
        COM_mail($to, $subject, $mailtext, $from, 1, 0, '', $mailtext_text);
    }
    DB_query("UPDATE {$_TABLES['vars']} SET value = NOW() WHERE name = 'lastemailedstories'");
}