Skip to content

Instantly share code, notes, and snippets.

@klaftertief
Forked from nickdunn/gist:257872
Created January 28, 2010 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klaftertief/288592 to your computer and use it in GitHub Desktop.
Save klaftertief/288592 to your computer and use it in GitHub Desktop.
<?php
require_once(TOOLKIT . '/class.datasource.php');
Class datasourceblog_post_moderated_comment_count extends Datasource{
var $dsParamROOTELEMENT = 'blog-post-moderated-comment-count';
var $dsParamORDER = 'desc';
var $dsParamLIMIT = '9999';
var $dsParamREDIRECTONEMPTY = 'no';
var $dsParamSORT = 'system:id';
var $dsParamSTARTPAGE = '1';
function __construct(&$parent, $env=NULL, $process_params=true){
parent::__construct($parent, $env, $process_params);
$this->dsParamFILTERS = array(
'posts' => '{$ds-blog-posts}',
'posts-by-tag' => '{$ds-blog-posts-by-tag}',
'post' => '{$ds-blog-post}',
'posts-search' => '{$ds-blog-posts-search}'
);
$this->_dependencies = array('$ds-blog-posts', '$ds-blog-posts-by-tag', '$ds-blog-post', '$ds-blog-posts-search');
}
function about(){
return array(
'name' => 'Blog Post Moderated Comment Count',
'author' => array(
'name' => 'Nick Dunn',
'website' => 'http://dev.ema.mtv.co.uk',
'email' => 'nick.dunn@airlock.com'),
'version' => '1.0',
'release-date' => '2008-09-30T14:40:58+00:00');
}
function grab(&$param_pool){
$result = new XMLElement("post-comments");
$posts = array();
if (is_array($this->dsParamFILTERS['posts'])) {
foreach($this->dsParamFILTERS['posts'] as $post) {
array_push($posts, $post);
}
}
if (is_array($this->dsParamFILTERS['posts-by-tag'])) {
foreach($this->dsParamFILTERS['posts-by-tag'] as $post) {
array_push($posts, $post);
}
}
if (is_array($this->dsParamFILTERS['post'])) {
foreach($this->dsParamFILTERS['post'] as $post) {
array_push($posts, $post);
}
}
if (is_array($this->dsParamFILTERS['posts-search'])) {
foreach($this->dsParamFILTERS['posts-search'] as $post) {
array_push($posts, $post);
}
}
foreach($posts as $post) {
$post_xml = new XMLElement("post");
$section_link_id = 32;
$moderation_id = 34;
$comments = $this->_Parent->Database->fetchRow(0, "SELECT COUNT(sym_entries_data_$section_link_id.relation_id) FROM sym_entries_data_$moderation_id INNER JOIN sym_entries_data_$section_link_id ON sym_entries_data_$moderation_id.entry_id = sym_entries_data_$section_link_id.entry_id WHERE (sym_entries_data_$moderation_id.handle = 'approved' OR sym_entries_data_$moderation_id.value = 'Approved') AND sym_entries_data_$section_link_id.relation_id = " . $post);
$post_xml->setAttributeArray(array("id" => $post, "approved-comments" => $comments["COUNT(sym_entries_data_$section_link_id.relation_id)"]));
$result->appendChild($post_xml);
}
return $result;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment