Example #1
0
/**
 * Get an existing static page
 *
 * @param   array   args    Contains all the data provided by the client
 * @param   string  &output OUTPUT parameter containing the returned text
 * @param   string  &svc_msg OUTPUT parameter containing any service messages
 * @return  int		    Response code as defined in lib-plugins.php
 */
function service_get_staticpages($args, &$output, &$svc_msg)
{
    global $_CONF, $_TABLES, $LANG_ACCESS, $LANG12, $LANG_STATIC, $_SP_CONF;
    $output = '';
    $svc_msg['output_fields'] = array('sp_hits', 'sp_format', 'draft_flag', 'owner_id', 'group_id', 'perm_owner', 'perm_group', 'perm_members', 'perm_anon', 'sp_help', 'sp_php', 'sp_inblock', 'commentcode');
    if (empty($args['sp_id']) && !empty($args['id'])) {
        $args['sp_id'] = $args['id'];
    }
    if ($args['gl_svc']) {
        if (isset($args['sp_id'])) {
            $args['sp_id'] = COM_applyBasicFilter($args['sp_id']);
        }
        if (isset($args['mode'])) {
            $args['mode'] = COM_applyBasicFilter($args['mode']);
        }
        if (empty($args['sp_id'])) {
            $svc_msg['gl_feed'] = true;
        } else {
            $svc_msg['gl_feed'] = false;
        }
    } else {
        $svc_msg['gl_feed'] = false;
    }
    if (!$svc_msg['gl_feed']) {
        $page = '';
        if (isset($args['sp_id'])) {
            $page = $args['sp_id'];
        }
        $mode = '';
        if (isset($args['mode'])) {
            $mode = $args['mode'];
        }
        $error = 0;
        if ($page == '') {
            $error = 1;
        }
        $perms = SP_getPerms();
        if (!SEC_hasRights('staticpages.edit')) {
            if (!empty($perms)) {
                $perms .= ' AND';
            }
            $perms .= '(draft_flag = 0)';
        }
        if (!empty($perms)) {
            $perms = ' AND ' . $perms;
        }
        $sql = array();
        $sql['mysql'] = "SELECT sp_title,sp_page_title,sp_content,sp_hits,created,modified,sp_format," . "commentcode,meta_description,meta_keywords,template_flag,template_id,draft_flag," . "owner_id,group_id,perm_owner,perm_group," . "perm_members,perm_anon,sp_tid,sp_help,sp_php," . "sp_inblock FROM {$_TABLES['staticpage']} " . "WHERE (sp_id = '{$page}')" . $perms;
        $sql['mssql'] = "SELECT sp_title,sp_page_title," . "CAST(sp_content AS text) AS sp_content,sp_hits," . "created,modified,sp_format,commentcode," . "CAST(meta_description AS text) AS meta_description," . "CAST(meta_keywords AS text) AS meta_keywords,template_flag,template_id,draft_flag," . "owner_id,group_id,perm_owner,perm_group,perm_members," . "perm_anon,sp_tid,sp_help,sp_php,sp_inblock " . "FROM {$_TABLES['staticpage']} WHERE (sp_id = '{$page}')" . $perms;
        $sql['pgsql'] = "SELECT sp_title,sp_page_title,sp_content,sp_hits," . "created,modified,sp_format," . "commentcode,meta_description,meta_keywords,template_flag,template_id,draft_flag," . "owner_id,group_id,perm_owner,perm_group," . "perm_members,perm_anon,sp_tid,sp_help,sp_php," . "sp_inblock FROM {$_TABLES['staticpage']} " . "WHERE (sp_id = '{$page}')" . $perms;
        $result = DB_query($sql);
        $count = DB_numRows($result);
        if ($count == 0 || $count > 1) {
            $error = 1;
        }
        if (!$error) {
            $output = DB_fetchArray($result, false);
            // WE ASSUME $output doesn't have any confidential fields
            if ($output['template_id'] != '') {
                $retval = '';
                $mode = '';
                $xmlObject = simplexml_load_string($output['sp_content']);
                // create array of XML data
                $tag = array();
                foreach ($xmlObject->variable as $variable) {
                    $key = $variable["name"] . '';
                    $value = $variable->data;
                    $tag[$key] = $value;
                }
                // Loop through variables to replace any autotags first
                foreach ($tag as &$value) {
                    $value = PLG_replaceTags($value);
                }
                $args = array('sp_id' => $output['template_id'], 'mode' => $mode, 'gl_svc' => '');
                $svc_msg = array();
                if (PLG_invokeService('staticpages', 'get', $args, $retval, $svc_msg) == PLG_RET_OK) {
                    $retval['sp_content'] = str_replace(array_keys($tag), array_values($tag), $retval['sp_content']);
                    $output['sp_content'] = $retval['sp_content'];
                }
            }
        } else {
            // an error occured (page not found, access denied, ...)
            /**
             * if the user has edit permissions and the page does not exist,
             * send them to the editor so they can create it "wiki style"
             */
            $create_page = false;
            if ($mode !== 'autotag' && $count == 0 && SEC_hasRights('staticpages.edit')) {
                // check again without permissions
                if (DB_count($_TABLES['staticpage'], 'sp_id', $page) == 0) {
                    $url = $_CONF['site_admin_url'] . '/plugins/staticpages/index.php?mode=edit&sp_new_id=' . $page . '&msg=21';
                    $output = COM_refresh($url);
                    $create_page = true;
                }
            }
            if (!$create_page) {
                if (empty($page)) {
                    $failflg = 0;
                } else {
                    $failflg = DB_getItem($_TABLES['staticpage'], 'sp_nf', "sp_id = '{$page}'");
                }
                if ($failflg) {
                    if ($mode !== 'autotag') {
                        $output = COM_siteHeader('menu');
                    }
                    $output .= SEC_loginRequiredForm();
                    if ($mode !== 'autotag') {
                        $output .= COM_siteFooter(true);
                    }
                } else {
                    if ($mode !== 'autotag') {
                        $output = COM_siteHeader('menu');
                    }
                    $output .= COM_startBlock($LANG_ACCESS['accessdenied'], '', COM_getBlockTemplate('_msg_block', 'header'));
                    $output .= $LANG_STATIC['deny_msg'];
                    $output .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer'));
                    if ($mode !== 'autotag') {
                        $output .= COM_siteFooter(true);
                    }
                }
            }
            return PLG_RET_ERROR;
        }
        if ($args['gl_svc']) {
            // This date format is PHP 5 only,
            // but only the web-service uses the value
            $output['published'] = date('c', strtotime($output['created']));
            $output['updated'] = date('c', strtotime($output['modified']));
            $output['id'] = $page;
            $output['title'] = $output['sp_title'];
            $output['page_title'] = $output['sp_page_title'];
            $output['category'] = array($output['sp_tid']);
            $output['content'] = $output['sp_content'];
            $output['content_type'] = 'html';
            $owner_data = SESS_getUserDataFromId($output['owner_id']);
            $output['author_name'] = $owner_data['username'];
            $output['link_edit'] = $page;
        }
    } else {
        $output = array();
        $mode = '';
        if (isset($args['mode'])) {
            $mode = $args['mode'];
        }
        $perms = SP_getPerms();
        if (!empty($perms)) {
            $perms = ' WHERE ' . $perms;
        }
        $offset = 0;
        if (isset($args['offset'])) {
            $offset = COM_applyBasicFilter($args['offset'], true);
        }
        $max_items = $_SP_CONF['atom_max_items'] + 1;
        $limit = " LIMIT {$offset}, {$max_items}";
        $order = " ORDER BY modified DESC";
        $sql = array();
        $sql['mysql'] = "SELECT sp_id,sp_title,sp_page_title,sp_content,sp_hits,created,modified,sp_format,meta_description,meta_keywords,template_flag,template_id,draft_flag,owner_id," . "group_id,perm_owner,perm_group,perm_members,perm_anon,sp_tid,sp_help,sp_php," . "sp_inblock FROM {$_TABLES['staticpage']}" . $perms . $order . $limit;
        $sql['mssql'] = "SELECT sp_id,sp_title,sp_page_title,CAST(sp_content AS text) AS sp_content,sp_hits," . "created,modified,sp_format,CAST(meta_description AS text) AS meta_description,CAST(meta_keywords AS text) AS meta_keywords,template_flag,template_id,draft_flag,owner_id,group_id,perm_owner,perm_group,perm_members," . "perm_anon,sp_tid,sp_help,sp_php,sp_inblock FROM {$_TABLES['staticpage']}" . $perms . $order . $limit;
        $sql['pgsql'] = "SELECT sp_id,sp_title,sp_page_title,sp_content,sp_hits,created,modified,sp_format,meta_description,meta_keywords,template_flag,template_id,draft_flag,owner_id," . "group_id,perm_owner,perm_group,perm_members,perm_anon,sp_tid,sp_help,sp_php," . "sp_inblock FROM {$_TABLES['staticpage']}" . $perms . $order . $limit;
        $result = DB_query($sql);
        $count = 0;
        while (($output_item = DB_fetchArray($result, false)) !== false) {
            // WE ASSUME $output doesn't have any confidential fields
            $count += 1;
            if ($count == $max_items) {
                $svc_msg['offset'] = $offset + $_SP_CONF['atom_max_items'];
                break;
            }
            if ($args['gl_svc']) {
                // This date format is PHP 5 only, but only the web-service uses the value
                $output_item['published'] = date('c', strtotime($output_item['created']));
                $output_item['updated'] = date('c', strtotime($output_item['modified']));
                $output_item['id'] = $output_item['sp_id'];
                $output_item['title'] = $output_item['sp_title'];
                $output_item['page_title'] = $output_item['sp_page_title'];
                $output_item['category'] = array($output_item['sp_tid']);
                $output_item['content'] = $output_item['sp_content'];
                $output_item['content_type'] = 'html';
                $owner_data = SESS_getUserDataFromId($output_item['owner_id']);
                $output_item['author_name'] = $owner_data['username'];
            }
            $output[] = $output_item;
        }
    }
    return PLG_RET_OK;
}
Example #2
0
/**
* Saves story to database
*
* @param    string      $type           story submission or (new) story
* @param    string      $sid            ID of story to save
* @param    int         $uid            ID of user that wrote the story
* @param    string      $tid            Topic ID story belongs to
* @param    string      $title          Title of story
* @param    string      $page_title     Title of the page
* @param    string      $introtext      Introduction text
* @param    string      $bodytext       Text of body
* @param    int         $hits           Number of times story has been viewed
* @param    string      $unixdate       Date story was originally saved
* @param    int         $featured       Flag on whether or not this is a featured article
* @param    string      $commentcode    Indicates if comments are allowed to be made to article
* @param    string      $trackbackcode  Indicates if trackbacks are allowed to be made to article
* @param    string      $statuscode     Status of the story
* @param    string      $postmode       Is this HTML or plain text?
* @param    string      $frontpage      Flag indicates if story will appear on front page and topic or just topic
* @param    int         $draft_flag     Flag indicates if story is a draft or not
* @param    int         $numemails      Number of times this story has been emailed to someone
* @param    int         $owner_id       ID of owner (not necessarily the author)
* @param    int         $group_id       ID of group story belongs to
* @param    int         $perm_owner     Permissions the owner has on story
* @param    int         $perm_group     Permissions the group has on story
* @param    int         $perm_member    Permissions members have on story
* @param    int         $perm_anon      Permissions anonymous users have on story
* @param    int         $delete         String array of attached images to delete from article
*
*/
function submitstory($type = '')
{
    $output = '';
    $args =& $_POST;
    // Handle Magic GPC Garbage:
    while (list($key, $value) = each($args)) {
        if (!is_array($value)) {
            $args[$key] = COM_stripslashes($value);
        } else {
            while (list($subkey, $subvalue) = each($value)) {
                $value[$subkey] = COM_stripslashes($subvalue);
            }
        }
    }
    /* ANY FURTHER PROCESSING on POST variables - COM_stripslashes etc.
     * Do it HERE on $args */
    PLG_invokeService('story', 'submit', $args, $output, $svc_msg);
    echo $output;
}
Example #3
0
/**
 * Handles the DELETE request
 */
function WS_delete()
{
    global $_CONF, $WS_PLUGIN, $WS_VERBOSE;
    if ($WS_VERBOSE) {
        COM_errorLog("WS: DELETE request received");
    }
    WS_dissectURI($args);
    // @TODO Store array $args
    // object id has already been stored from the URI
    /* Indicates that the method are being called by the webservice */
    $args['gl_svc'] = true;
    $ret = PLG_invokeService($WS_PLUGIN, 'delete', $args, $out, $svc_msg);
    if ($ret == PLG_RET_OK) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');
        return;
    }
    WS_error($ret, $svc_msg['error_desc']);
}
Example #4
0
/**
 * Delete a story.
 * This is used to delete a story from the list of stories.
 *
 * @param    string $sid ID of the story to delete
 * @return   string          HTML, e.g. a meta redirect
 */
function STORY_deleteStory($sid)
{
    $args = array('sid' => $sid);
    $output = '';
    PLG_invokeService('story', 'delete', $args, $output, $svc_msg);
    return $output;
}
Example #5
0
/**
* Saves a Static Page to the database
*
* @param string sp_id            ID of static page
* @param string sp_title         title of page
* @param string sp_page_title    page title of the staticpage
* @param string sp_content       page content
* @param int    sp_hits          Number of page views
* @param string sp_format        HTML or plain text
* @param string sp_onmenu        Flag to place entry on menu
* @param string sp_label         Menu Entry
* @param int    commentcode      Comment Code
* @param int    owner_id         Permission bits
* @param int    group_id
* @param int    perm_owner
* @param int    perm_members
* @param int    perm_anon
* @param int    sp_php           Flag to indicate PHP usage
* @param string sp_nf            Flag to indicate type of not found message
* @param string sp_old_id        original ID of this static page
* @param string sp_centerblock   Flag to indicate display as a center block
* @param string sp_help          Help URL that displays in the block
* @param int    sp_where         position of center block
* @param string sp_inblock       Flag: wrap page in a block (or not)
* @param string postmode
* @param string meta_description
* @param string meta_keywords
* @param string draft_flag       Flag: save as draft
* @param string cache_time       Cache time of page
*
*/
function submitstaticpage($sp_id, $sp_title, $sp_page_title, $sp_content, $sp_hits, $sp_format, $sp_onmenu, $sp_label, $commentcode, $owner_id, $group_id, $perm_owner, $perm_group, $perm_members, $perm_anon, $sp_php, $sp_nf, $sp_old_id, $sp_centerblock, $sp_help, $sp_where, $sp_inblock, $postmode, $meta_description, $meta_keywords, $draft_flag, $template_flag, $template_id, $cache_time)
{
    $retval = '';
    $args = array('sp_id' => $sp_id, 'sp_title' => $sp_title, 'sp_page_title' => $sp_page_title, 'sp_content' => $sp_content, 'sp_hits' => $sp_hits, 'sp_format' => $sp_format, 'sp_onmenu' => $sp_onmenu, 'sp_label' => $sp_label, 'commentcode' => $commentcode, 'meta_description' => $meta_description, 'meta_keywords' => $meta_keywords, 'template_flag' => $template_flag, 'template_id' => $template_id, 'draft_flag' => $draft_flag, 'cache_time' => $cache_time, 'owner_id' => $owner_id, 'group_id' => $group_id, 'perm_owner' => $perm_owner, 'perm_group' => $perm_group, 'perm_members' => $perm_members, 'perm_anon' => $perm_anon, 'sp_php' => $sp_php, 'sp_nf' => $sp_nf, 'sp_old_id' => $sp_old_id, 'sp_centerblock' => $sp_centerblock, 'sp_help' => $sp_help, 'sp_where' => $sp_where, 'sp_inblock' => $sp_inblock, 'postmode' => $postmode);
    PLG_invokeService('staticpages', 'submit', $args, $retval, $svc_msg);
    return $retval;
}
Example #6
0
/**
* Saves a Static Page to the database
*
* @param sp_id           string  ID of static page
* @param sp_uid          string  ID of user that created page
* @param sp_title        string  title of page
* @param sp_content      string  page content
* @param sp_hits         int     Number of page views
* @param sp_format       string  HTML or plain text
* @param sp_onmenu       string  Flag to place entry on menu
* @param sp_label        string  Menu Entry
* @param commentcode     int     Comment Code
* @param owner_id        int     Permission bits
* @param group_id        int
* @param perm_owner      int
* @param perm_members    int
* @param perm_anon       int
* @param sp_php          int     Flag to indicate PHP usage
* @param sp_nf           string  Flag to indicate type of not found message
* @param sp_old_id       string  original ID of this static page
* @param sp_centerblock  string  Flag to indicate display as a center block
* @param sp_help         string  Help URL that displays in the block
* @param sp_tid          string  topid id (for center block)
* @param sp_where        int     position of center block
* @param sp_inblock      string  Flag: wrap page in a block (or not)
*
*/
function PAGE_submit($sp_id, $sp_status, $sp_uid, $sp_title, $sp_content, $sp_hits, $sp_format, $sp_onmenu, $sp_label, $commentcode, $owner_id, $group_id, $perm_owner, $perm_group, $perm_members, $perm_anon, $sp_php, $sp_nf, $sp_old_id, $sp_centerblock, $sp_help, $sp_tid, $sp_where, $sp_inblock, $postmode, $sp_search)
{
    global $_CONF, $_TABLES, $LANG12, $LANG_STATIC, $_SP_CONF;
    $retval = '';
    $args = array('sp_id' => $sp_id, 'sp_status' => $sp_status, 'sp_uid' => $sp_uid, 'sp_title' => $sp_title, 'sp_content' => $sp_content, 'sp_hits' => $sp_hits, 'sp_format' => $sp_format, 'sp_onmenu' => $sp_onmenu, 'sp_label' => $sp_label, 'commentcode' => $commentcode, 'owner_id' => $owner_id, 'group_id' => $group_id, 'perm_owner' => $perm_owner, 'perm_group' => $perm_group, 'perm_members' => $perm_members, 'perm_anon' => $perm_anon, 'sp_php' => $sp_php, 'sp_nf' => $sp_nf, 'sp_old_id' => $sp_old_id, 'sp_centerblock' => $sp_centerblock, 'sp_help' => $sp_help, 'sp_tid' => $sp_tid, 'sp_where' => $sp_where, 'sp_inblock' => $sp_inblock, 'postmode' => $postmode, 'sp_search' => $sp_search);
    PLG_invokeService('staticpages', 'submit', $args, $retval, $svc_msg);
    CACHE_remove_instance('stmenu');
    return $retval;
}
Example #7
0
    }
}
if (empty($sid)) {
    echo COM_refresh($_CONF['site_url'] . '/index.php');
    exit;
}
if (strcasecmp($order, 'ASC') != 0 && strcasecmp($order, 'DESC') != 0) {
    $order = '';
}
$result = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE sid = '{$sid}'" . COM_getPermSql('AND'));
$A = DB_fetchArray($result);
if ($A['count'] > 0) {
    $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_startBlock($LANG_ACCESS['accessdenied'], '', COM_getBlockTemplate('_msg_block', 'header')) . $LANG_ACCESS['storydenialmsg'] . COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer')) . COM_siteFooter();
    } elseif ($output == STORY_INVALID_SID) {
Example #8
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 #9
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'");
}
Example #10
0
/**
* Saves story to database
*
* @param    string      $type           story submission or (new) story
* @param    string      $sid            ID of story to save
* @param    int         $uid            ID of user that wrote the story
* @param    string      $tid            Topic ID story belongs to
* @param    string      $title          Title of story
* @param    string      $introtext      Introduction text
* @param    string      $bodytext       Text of body
* @param    int         $hits           Number of times story has been viewed
* @param    string      $unixdate       Date story was originally saved
* @param    int         $featured       Flag on whether or not this is a featured article
* @param    string      $commentcode    Indicates if comments are allowed to be made to article
* @param    string      $trackbackcode  Indicates if trackbacks are allowed to be made to article
* @param    string      $statuscode     Status of the story
* @param    string      $postmode       Is this HTML or plain text?
* @param    string      $frontpage      Flag indicates if story will appear on front page and topic or just topic
* @param    int         $draft_flag     Flag indicates if story is a draft or not
* @param    int         $numemails      Number of times this story has been emailed to someone
* @param    int         $owner_id       ID of owner (not necessarily the author)
* @param    int         $group_id       ID of group story belongs to
* @param    int         $perm_owner     Permissions the owner has on story
* @param    int         $perm_group     Permissions the group has on story
* @param    int         $perm_member    Permissions members have on story
* @param    int         $perm_anon      Permissions anonymous users have on story
* @param    int         $delete         String array of attached images to delete from article
*
*/
function STORY_submit($type = '')
{
    $output = '';
    $args =& $_POST;
    while (list($key, $value) = each($args)) {
        if (!is_array($value)) {
            $args[$key] = $value;
        } else {
            while (list($subkey, $subvalue) = each($value)) {
                $value[$subkey] = $subvalue;
            }
        }
    }
    /* ANY FURTHER PROCESSING on POST variables - COM_stripslashes etc.
     * Do it HERE on $args */
    $rc = PLG_invokeService('story', 'submit', $args, $output, $svc_msg);
    switch ($rc) {
        case PLG_RET_ERROR:
            break;
        case PLG_RET_PERMISSION_DENIED:
            break;
        case PLG_RET_PERMISSION_DENIED:
            break;
        case PLG_RET_PRECONDITION_FAILED:
            break;
        case PLG_RET_AUTH_FAILED:
            break;
    }
    return $output;
}
Example #11
0
/**
* Delete a story.
*
* This is used to delete a story from the list of stories.
*
* @param    string  $sid    ID of the story to delete
* @return   string          HTML, e.g. a meta redirect
*
*/
function STORY_deleteStory($sid)
{
    $args = array('sid' => $sid);
    $output = '';
    PLG_invokeService('story', 'delete', $args, $output, $svc_msg);
    CACHE_remove_instance('whatsnew');
    CACHE_remove_instance('story_' . $sid);
    return $output;
}