示例#1
0
function bxpress_block_topics_show($options)
{
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $mc = RMSettings::module_settings('bxpress');
    $tbl1 = $db->prefix('mod_bxpress_posts');
    $tbl2 = $db->prefix('mod_bxpress_topics');
    $tbl3 = $db->prefix('mod_bxpress_likes');
    $tbl4 = $db->prefix('mod_bxpress_forums');
    // Calculate period of time
    if (0 < $options['days']) {
        $period = time() - $options['days'] * 86400;
    }
    $order = 'DESC' == $options['order'] ? 'DESC' : 'ASC';
    $sql = "SELECT topics.*, forums.name,\n                (SELECT SUM(likes) FROM {$tbl1} WHERE id_topic=topics.id_topic) as likes,\n                (SELECT post_time FROm {$tbl1} WHERE id_topic=topics.id_topic ORDER BY post_time DESC LIMIT 0, 1) as updated\n                FROM {$tbl2} as topics, {$tbl4} as forums WHERE ";
    if (0 < $options['days']) {
        $sql .= " topics.date > {$period} AND ";
    }
    $sql .= "forums.id_forum=topics.id_forum";
    if ('recent' == $options['type']) {
        $sql .= " ORDER BY topics.id_topic {$order} LIMIT 0, {$options['limit']}";
    } elseif ('hot' == $options['type']) {
        $sql .= " ORDER BY topics.replies {$order} LIMIT 0, {$options['limit']}";
    } elseif ('hits' == $options['type']) {
        $sql .= " ORDER BY topics.views {$order} LIMIT 0, {$options['limit']}";
    }
    $result = $db->queryF($sql);
    $topics = array();
    $block = array();
    include_once XOOPS_ROOT_PATH . '/modules/bxpress/class/bxforum.class.php';
    include_once XOOPS_ROOT_PATH . '/modules/bxpress/class/bxpost.class.php';
    include_once XOOPS_ROOT_PATH . '/modules/bxpress/class/bxtopic.class.php';
    include_once XOOPS_ROOT_PATH . '/modules/bxpress/class/bxfunctions.class.php';
    $topic = new bXTopic();
    $forum = new bXForum();
    $tf = new RMTimeFormatter(0, '%T% %d%, %Y%');
    while ($row = $db->fetchArray($result)) {
        $topic->assignVars($row);
        $forum->assignVars(array('id_forum' => $topic->forum()));
        $ret = array('id' => $topic->id(), 'title' => $topic->title, 'link' => $topic->permalink(), 'likes' => $topic->likes, 'replies' => $topic->replies, 'hits' => $topic->views, 'forum' => array('name' => $row['name'], 'id' => $row['id_forum'], 'link' => $forum->permalink()), 'time' => $topic->date, 'date' => $tf->ago($topic->date), 'likes' => $row['likes'], 'updated' => 'full' == $options['format'] ? sprintf(__('Updated on %s', 'bxpress'), $tf->format($row['updated'])) : $tf->ago($row['updated']));
        $topics[] = $ret;
    }
    $block['topics'] = $topics;
    $block['format'] = $options['format'];
    // Add css styles
    RMTemplate::get()->add_style('bxpress-blocks.min.css', 'bxpress');
    return $block;
}
示例#2
0
    $tf = new RMTimeFormatter(0, __('%T% %d%, %Y%', 'bxpress'));
    // Likes parsing
    if (!is_null($row['liked'])) {
        $likes_ids = explode(",", $row['liked'], 3);
    } else {
        $likes_ids = array();
    }
    $likes = array();
    foreach ($likes_ids as $like) {
        if (!isset($users[$like])) {
            $users[$like] = new XoopsUser($like);
        }
        $like_user = $users[$like];
        $likes[] = array('uid' => $like, 'uname' => $like_user->getVar('uname'), 'name' => $like_user->getVar('name') != '' ? $like_user->getVar('name') : $like_user->getVar('uname'), 'avatar' => RMEvents::get()->run_event("rmcommon.get.avatar", $like_user->getVar('email'), 40));
    }
    $posts[$post->id()] = array('id' => $post->id(), 'text' => $post->text(), 'edit' => $post->editText(), 'approved' => $post->approved(), 'date' => $tf->ago($post->date()), 'canedit' => $canedit, 'candelete' => $candelete, 'canshow' => $canshow, 'canreport' => $report, 'poster' => $userData, 'attachs' => $attachs, 'attachscount' => count($attachs), 'parent' => $post->parent, 'replies' => $row['replies'], 'likes_count' => $row['likes'], 'likes' => $likes);
    $posts_ids[] = $post->id();
}
$tpl->assign('posts', $posts);
unset($userData, $bbUser, $users);
// Common Utilities Notifications
$notifications = RMNotifications::get();
$events = Bxpress_Notifications::get();
$permissions = $forum->permissions();
// New topics notifications
$event = $events->event('reply')->parameters($topic->id())->permissions(array('groups' => in_array(0, $permissions['view']) ? array() : $permissions['view']));
$notifications->add_item($event);
unset($event, $permissions);
$tpl->assign('notifications', $notifications->render());
$tpl->assign('lang_edit', __('Edit', 'bxpress'));
$tpl->assign('lang_delete', __('Delete', 'bxpress'));