/**
     * @return array
     * @param int $id
     * @param string
     * @param string
     * @param object nlb_user
     * @param string
     * @desc Grabs and formats all the comments to blog $id and sets them up for ETS
     * @date 02-10-04
     */
    function getComments($id, $date_format, $lang_anon, &$user, $lang_edit)
    {
        // get ones posted by real users
        $real = $this->sql->getAllArray('# Grab real comments
		SELECT c.comment_id, c.author_id, c.date, c.body, u.username
		FROM ' . db_comments . ' AS c, ' . db_users . ' AS u
		WHERE c.parent_id = ' . $id . ' AND c.author_id = u.user_id
		ORDER BY c.date ASC;');
        // get guest posts
        $guest = $this->sql->getAllArray('# Grab guest comments
		SELECT comment_id, author_id, date, body
		FROM ' . db_comments . '
		WHERE author_id = -1 AND parent_id = ' . $id . '
		ORDER BY date ASC;');
        /*
        	Because I'm using two querys to grab the comments, I have the problem of sorting
        	the results. I'm throwing all the results together in $grab. Then I go throuh them
        	and build a new array, with the date of the post as the key. Now I can use ksort()
        	to sort by key (asc) and the comments will be in the propper order. The key doesn't
        	matter in the templates, as ETS will just loop through them in order. Probally 
        	costs more memory this way, but the job gets done.
        	
        	We won't have to bulid $grab if there are only one type of comments, so im trying
        	to detect if ksort is needed or not below.
        */
        if (empty($real) && empty($guest)) {
            $all = array();
            // no comments
        } elseif (empty($real)) {
            $all = $guest;
            // only guest comments
        } elseif (empty($guest)) {
            $all = $real;
            // only real comments
        } else {
            // a mix of real and guest comments.
            $grab = array_merge($real, $guest);
            foreach ($grab as $val) {
                $all[$val['date']] = $val;
            }
            ksort($all);
        }
        // loop through real, get id nubers to check for avatars
        $av_ins = false;
        $avatars = array();
        if (count($real) != 0) {
            $av_ins = '(';
            foreach ($real as $r) {
                $av_ins .= $r['author_id'] . ', ';
            }
            $av_ins = substr($av_ins, 0, -2);
            $av_ins .= ')';
            $r = $this->sql->query('SELECT owner_id, isCustom, file, type
			FROM ' . db_avatars . '
			WHERE owner_id IN' . $av_ins . ' AND type != 2;');
            while ($row = mysql_fetch_assoc($r)) {
                if (isset($avatars[$row['owner_id']]) && $avatars[$row['owner_id']]['type'] != 3) {
                    $avatars[$row['owner_id']] = $row;
                }
                if (!isset($avatars[$row['owner_id']])) {
                    $avatars[$row['owner_id']] = $row;
                }
            }
        }
        $c = array();
        $i = 0;
        foreach ($all as $comment) {
            $c[$i]->date = date($date_format, $comment['date']);
            //$body = stripslashes( $comment['body'] );
            $body = $comment['body'];
            $body = htmlspecialchars($body);
            $body = nl2br($body);
            $body = $this->addSmiles($body);
            $body = insertBBCode($body);
            $c[$i]->body = $body;
            if ($comment['author_id'] == -1) {
                // a guest post!
                $c[$i]->author = $lang_anon;
                $c[$i]->guest = true;
            } else {
                // comment by normal user!
                $c[$i]->author = $comment['username'];
                $c[$i]->author_url_blog = build_link('blog.php', array('user' => $comment['author_id']));
                $c[$i]->author_url_profile = build_link('profile.php', array('user' => $comment['author_id']));
                // avatar check
                if (isset($avatars[$comment['author_id']])) {
                    if ($avatars[$comment['author_id']]['isCustom'] == 1) {
                        $c[$i]->avatar_url = script_path . 'avatars/' . $avatars[$comment['author_id']]['file'];
                    } else {
                        $c[$i]->avatar_url = script_path . 'avatars/default/' . $avatars[$comment['author_id']]['file'];
                    }
                    $c[$i]->avatar = '<img src="' . $c[$i]->avatar_url . '" />';
                }
            }
            // admin-only link to edit comment?
            if ($user->isAllowed('admin')) {
                $admin_url = script_path . 'admincp.php?action=edit_comment&id=' . $comment['comment_id'];
                $c[$i]->body .= ' [<a href="' . $admin_url . '">' . $lang_edit . '</a>]';
            }
            $i++;
        }
        return $c;
    }
Example #2
0
echo '<rss version="2.0">
<channel>
<title>Public blogs posted by ' . $USER . '</title>
<link>' . $home_url . '</link>
<description>The 10 most recent public blogs by ' . $USER . '</description>
<pubDate>' . date('r', time()) . '</pubDate>
<generator>NewLife Blogger v' . nlb_version . '</generator>';
// now print blog items
while ($blog = mysql_fetch_assoc($blogs)) {
    foreach ($blog as $key => $val) {
        $val = stripslashes($val);
        $val = htmlspecialchars($val);
        $blog[$key] = $val;
        $body = $blog['body'];
        if ($blog['bb'] == 1) {
            $body = insertBBCode($body);
            $body = htmlSpecialChars($body);
            // we can not have HTML inside of a RSS feed.
        }
    }
    $url = build_link('blog.php', array('id' => $blog['blog_id']));
    echo '
	<item>
	<title>' . $blog['subject'] . '</title>
	<link>' . full_url . $url . '</link>
	<description>' . $body . '</description>
	<comments>' . full_url . $url . '</comments>
	<pubDate>' . date('r', $blog['date']) . '</pubDate>
	</item>
	';
}
Example #3
0
    $ets->matches = $_SESSION['results'];
    $q = $_SESSION['query'];
    $q .= " \nORDER BY b.date DESC \nLIMIT {$start}, {$end};";
    $page = $db->getAllArray($q);
    $i = 0;
    foreach ($page as $b) {
        stripslashes_array($b);
        $ets->entries[$i]->author = $b['username'];
        $ets->entries[$i]->url = build_link('blog.php', array('id' => $b['blog_id']));
        $ets->entries[$i]->subject = $b['subject'];
        $ets->entries[$i]->comments = $b['comments'];
        if ($b['html'] == 0) {
            $b['body'] = htmlspecialchars($b['body']);
        }
        if ($b['bb'] == 1) {
            $b['body'] = insertBBCode($b['body']);
        }
        $b['body'] = nl2br($b['body']);
        $ets->entries[$i]->body = truncate($b['body'], 800);
        $ets->entries[$i]->date = date($config->get('recent_blog_date', $b['date']));
        $i++;
    }
    //  	debug($q,"THE QUERY");
    //  	debug($ets,'ETS Data');
    //  	debug($_SESSION,'_SESSION');
    //  	die();
} else {
    if (isset($_POST['q'])) {
        //------------------------
        //		BUILD QUERY AND OTHER PRE-QUERY TASKS
        //------------------------