wishcraft wishcraft
  • Module Developer
  • Module Developer
  • Joined: 2007/5/18 16:56
  • From Marrickville South, NSW, Australia
  • Group: Registered Users
  • Posts: 3652
  • Posted on: 2011/4/9 16:04
#Comments #RSS #Feed for XOOPS #1
Put the following code in a file called something like comments.php in your XOOPS_ROOT_PATH where backend.php is featured and it will add a feed to your site for comments to import into twitter etc.

<?php
/**
 * XOOPS feed creator
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @since           2.0.0
 * @version         $Id: backend.php 4941 2010-07-22 17:13:36Z beckmi $
 */
 
include dirname(__FILE__) . DIRECTORY_SEPARATOR 'mainfile.php';

$GLOBALS['xoopsLogger']->activated false;
if (
function_exists('mb_http_output')) {
    
mb_http_output('pass');
}
header('Content-Type:text/xml; charset=utf-8');

include_once 
$GLOBALS['xoops']->path('class/template.php');
$tpl = new XoopsTpl();
$tpl->xoops_setCaching(2);
$tpl->xoops_setCacheTime(3600);
if (!
$tpl->is_cached('db:system_rss.html')) {
    
xoops_load('XoopsLocal');
    
$tpl->assign('channel_title'XoopsLocal::convert_encoding(htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)));
    
$tpl->assign('channel_link'XOOPS_URL '/');
    
$tpl->assign('channel_desc'XoopsLocal::convert_encoding(htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES)));
    
$tpl->assign('channel_lastbuild'formatTimestamp(time(), 'rss'));
    
$tpl->assign('channel_webmaster'checkEmail($xoopsConfig['adminmail'], true));
    
$tpl->assign('channel_editor'checkEmail($xoopsConfig['adminmail'], true));
    
$tpl->assign('channel_category''News');
    
$tpl->assign('channel_generator''XOOPS');
    
$tpl->assign('channel_language'_LANGCODE);
    
$tpl->assign('image_url'XOOPS_URL '/images/logo.png');
    
$dimention getimagesize(XOOPS_ROOT_PATH '/images/logo.png');
    if (empty(
$dimention[0])) {
        
$width 88;
    } else {
        
$width = ($dimention[0] > 144) ? 144 $dimention[0];
    }
    if (empty(
$dimention[1])) {
        
$height 31;
    } else {
        
$height = ($dimention[1] > 400) ? 400 $dimention[1];
    }
    
$tpl->assign('image_width'$width);
    
$tpl->assign('image_height'$height);
    
    
$comments_handler xoops_gethandler('comment');
    
$criteria = new CriteriaCompo(new Criteria('com_status'2));
    if (isset(
$_REQUEST['modid'])&&is_numeric($_REQUEST['modid']))
        
$criteria->add(new Criteria('`com_modid`'intval($_REQUEST['modid'])));
    if (isset(
$_REQUEST['uid'])&&is_numeric($_REQUEST['uid']))
        
$criteria->add(new Criteria('`com_uid`'intval($_REQUEST['uid'])));
    
$criteria->setLimit(((isset($_REQUEST['num'])&&is_numeric($_REQUEST['num'])&&intval($_REQUEST['num'])>0)?intval($_REQUEST['num']):10));
    
$criteria->setSort('`com_created`');
    
$criteria->setOrder('DESC');
    
    
$module_handler xoops_gethandler('module');
    
$comments $comments_handler->getObjects($criteria);
    if (!empty(
$comments) && is_array($comments)) {
        
$myts =& MyTextSanitizer::getInstance();
        foreach (
$comments as $comment) {
            
$xoModule $module_handler->get($comment->getVar('com_modid'));
            
$comment_config $xoModule->getInfo('comments'); 
            
$tpl->append('items', array(
                
'title' => XoopsLocal::convert_encoding(htmlspecialchars($comment->getVar('com_title'), ENT_QUOTES)) ,
                
'link' => htmlspecialchars(XOOPS_URL '/modules/'.$xoModule->getVar('dirname').'/'.$comment_config['pageName'].'?'.$comment_config['itemName'].'='.$comment->getVar('com_itemid').'&com_id='.$comment->getVar('com_id').'&com_rootid='.$comment->getVar('com_rootid').'&com_mode='.$GLOBALS['xoopsConfig']['com_mode'].'&com_order=0'.(strlen($comment->getVar('com_exparams'))>0?'&'.$comment->getVar('com_exparams'):'').'#comment'.$comment->getVar('com_id')),
                
'guid' => htmlspecialchars(XOOPS_URL '/modules/'.$xoModule->getVar('dirname').'/'.$comment_config['pageName'].'?'.$comment_config['itemName'].'='.$comment->getVar('com_itemid').'&com_id='.$comment->getVar('com_id').'&com_rootid='.$comment->getVar('com_rootid').'&com_mode='.$GLOBALS['xoopsConfig']['com_mode'].'&com_order=0'.(strlen($comment->getVar('com_exparams'))>0?'&'.$comment->getVar('com_exparams'):'').'#comment'.$comment->getVar('com_id')),
                
'category' => XoopsLocal::convert_encoding(htmlspecialchars($xoModule->getVar('name'))) ,
                
'pubdate' => formatTimestamp($comment->getVar('com_created'), 'rss') ,
                
'description' => XoopsLocal::convert_encoding(htmlspecialchars($myts->displayTarea($comment->getVar('com_text'), $comment->getVar('dohtml'), $comment->getVar('dosmiley'), $comment->getVar('doxcode'), $comment->getVar('doimage'), $comment->getVar('dobr')), ENT_QUOTES))));
        }
    }
}
$tpl->display('db:system_rss.html');
?>

* Code Final Edited 10/04/2011 6:25:20 AEST
wishcraft wishcraft
  • Module Developer
  • Module Developer
  • Joined: 2007/5/18 16:56
  • From Marrickville South, NSW, Australia
  • Group: Registered Users
  • Posts: 3652
  • Posted on: 2011/4/9 16:44
Re: #Comments #RSS #Feed for XOOPS #2
By including the following function, you can customise the code for sending a twitter explicit RSS Feed Title so the words longer than xxx are and have a hash placed in front of them for twitters RSS Aggregation

function xoopsTweetString($title$doit=false$wordlen=4) {
    if (
$doit==true) {
        
$title_array explode(' '$title);
        
$title '';
        foreach(
$title_array as $item) {
            if (
strlen($item)>$wordlen
                
$title .= ' #'.$item;
            else 
                
$title .= ' '.$item;
        }
    }
    return 
trim($title);
}


The RSS Code with this included would look like:

<?php
/**
 * XOOPS feed creator
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @since           2.0.0
 * @version         $Id: backend.php 4941 2010-07-22 17:13:36Z beckmi $
 */
if (!function_exists('xoopsTweetString')) {
    function 
xoopsTweetString($title$doit=false$wordlen=4) {
        if (
$doit==true) {
            
$title_array explode(' '$title);
            
$title '';
            foreach(
$title_array as $item) {
                if (
strlen($item)>$wordlen
                    
$title .= ' #'.$item;
                else 
                    
$title .= ' '.$item;
            }
        }
        return 
trim($title);
    }
}

include 
dirname(__FILE__) . DIRECTORY_SEPARATOR 'mainfile.php';

$GLOBALS['xoopsLogger']->activated false;
if (
function_exists('mb_http_output')) {
    
mb_http_output('pass');
}
header('Content-Type:text/xml; charset=utf-8');

include_once 
$GLOBALS['xoops']->path('class/template.php');
$tpl = new XoopsTpl();
$tpl->xoops_setCaching(2);
$tpl->xoops_setCacheTime(3600);
if (!
$tpl->is_cached('db:system_rss.html')) {
    
xoops_load('XoopsLocal');
    
$tpl->assign('channel_title'XoopsLocal::convert_encoding(htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)));
    
$tpl->assign('channel_link'XOOPS_URL '/');
    
$tpl->assign('channel_desc'XoopsLocal::convert_encoding(htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES)));
    
$tpl->assign('channel_lastbuild'formatTimestamp(time(), 'rss'));
    
$tpl->assign('channel_webmaster'checkEmail($xoopsConfig['adminmail'], true));
    
$tpl->assign('channel_editor'checkEmail($xoopsConfig['adminmail'], true));
    
$tpl->assign('channel_category''News');
    
$tpl->assign('channel_generator''XOOPS');
    
$tpl->assign('channel_language'_LANGCODE);
    
$tpl->assign('image_url'XOOPS_URL '/images/logo.png');
    
$dimention getimagesize(XOOPS_ROOT_PATH '/images/logo.png');
    if (empty(
$dimention[0])) {
        
$width 88;
    } else {
        
$width = ($dimention[0] > 144) ? 144 $dimention[0];
    }
    if (empty(
$dimention[1])) {
        
$height 31;
    } else {
        
$height = ($dimention[1] > 400) ? 400 $dimention[1];
    }
    
$tpl->assign('image_width'$width);
    
$tpl->assign('image_height'$height);
    
    
$comments_handler xoops_gethandler('comment');
    
$criteria = new CriteriaCompo(new Criteria('com_status'2));
    if (isset(
$_REQUEST['modid'])&&is_numeric($_REQUEST['modid']))
        
$criteria->add(new Criteria('`com_modid`'intval($_REQUEST['modid'])));
    if (isset(
$_REQUEST['uid'])&&is_numeric($_REQUEST['uid']))
        
$criteria->add(new Criteria('`com_uid`'intval($_REQUEST['uid'])));
    
$criteria->setLimit(((isset($_REQUEST['num'])&&is_numeric($_REQUEST['num'])&&intval($_REQUEST['num'])>0)?intval($_REQUEST['num']):10));
    
$criteria->setSort('`com_created`');
    
$criteria->setOrder('DESC');
    
    
$module_handler xoops_gethandler('module');
    
$comments $comments_handler->getObjects($criteria);
    if (!empty(
$comments) && is_array($comments)) {
        
$myts =& MyTextSanitizer::getInstance();
        foreach (
$comments as $comment) {
            
$xoModule $module_handler->get($comment->getVar('com_modid'));
            
$comment_config $xoModule->getInfo('comments'); 
            
$tpl->append('items', array(
                
'title' => XoopsLocal::convert_encoding(htmlspecialchars(xoopsTweetString($comment->getVar('com_title'), isset($_REQUEST['tweet']), ((isset($_REQUEST['tweetlen'])&&is_numeric($_REQUEST['tweetlen'])&&intval($_REQUEST['tweetlen'])>0)?intval($_REQUEST['tweetlen']):4)), ENT_QUOTES)) ,
                
'link' => htmlspecialchars(XOOPS_URL '/modules/'.$xoModule->getVar('dirname').'/'.$comment_config['pageName'].'?'.$comment_config['itemName'].'='.$comment->getVar('com_itemid').'&com_id='.$comment->getVar('com_id').'&com_rootid='.$comment->getVar('com_rootid').'&com_mode='.$GLOBALS['xoopsConfig']['com_mode'].'&com_order=0'.(strlen($comment->getVar('com_exparams'))>0?'&'.$comment->getVar('com_exparams'):'').'#comment'.$comment->getVar('com_id')),
                
'guid' => htmlspecialchars(XOOPS_URL '/modules/'.$xoModule->getVar('dirname').'/'.$comment_config['pageName'].'?'.$comment_config['itemName'].'='.$comment->getVar('com_itemid').'&com_id='.$comment->getVar('com_id').'&com_rootid='.$comment->getVar('com_rootid').'&com_mode='.$GLOBALS['xoopsConfig']['com_mode'].'&com_order=0'.(strlen($comment->getVar('com_exparams'))>0?'&'.$comment->getVar('com_exparams'):'').'#comment'.$comment->getVar('com_id')),
                
'category' => XoopsLocal::convert_encoding(htmlspecialchars($xoModule->getVar('name'))) ,
                
'pubdate' => formatTimestamp($comment->getVar('com_created'), 'rss') ,
                
'description' => XoopsLocal::convert_encoding(htmlspecialchars($myts->displayTarea($comment->getVar('com_text'), $comment->getVar('dohtml'), $comment->getVar('dosmiley'), $comment->getVar('doxcode'), $comment->getVar('doimage'), $comment->getVar('dobr')), ENT_QUOTES))));
        }
    }
}
$tpl->display('db:system_rss.html');
?>


To Turn this on you would do http://yoursite.com/comments.php?tweet=1
wishcraft wishcraft
  • Module Developer
  • Module Developer
  • Joined: 2007/5/18 16:56
  • From Marrickville South, NSW, Australia
  • Group: Registered Users
  • Posts: 3652
  • Posted on: 2011/4/12 13:51
Re: #Comments #RSS #Feed for XOOPS #3
Paul from Stop forum spam was amused by this it is a comments rss feed @ xortify http://xortify.chronolabs.coop/comments.php?tweet=1 in tweet mode
timgno timgno
  • Module Developer
  • Module Developer
  • Joined: 2007/6/21 14:54
  • From Italy
  • Group: Registered Users
  • Posts: 1497
  • Posted on: 2011/4/13 4:38
Re: #Comments #RSS #Feed for XOOPS #4
thanks simon

a suggestion ... would be a better name backcoms.php?
How to effectively post a question in the Xoops forums? - Read here...
Design by: XOOPS UI/UX Team