Exemplo n.º 1
0
function do_rss_blog($formatter, $options)
{
    global $DBInfo;
    #  if (!$options['date'] or !preg_match('/^\d+$/',$date)) $date=date('Ym');
    #  else $date=$options['date'];
    $date = $options['date'];
    $category_pages = array();
    if ($options['category'] and $DBInfo->blog_category) {
        $categories = Blog_cache::get_categories();
        if ($categories[$options['category']]) {
            $category_pages = $categories[$options['category']];
        }
        $title = $options['category'];
    } else {
        $title = _("Blog Changes");
    }
    if ($options['all'] or $options['category']) {
        # check error and set default value
        $blog_rss = new Cache_text('blogrss');
        #    $blog_mtime=filemtime($DBInfo->cache_dir."/blog");
        #    if ($blog_rss->exists($date'.xml') and ($blog_rss->mtime($date.'.xml') > $blog_mtime)) {
        #      print $blog_rss->fetch($date.'.xml');
        #      return;
        #    }
        $blogs = Blog_cache::get_rc_blogs($date, $category_pages);
        $logs = Blog_cache::get_summary($blogs, $date);
        $rss_name = $DBInfo->sitename . ': ' . $title;
    } else {
        $blogs = array($DBInfo->pageToKeyname($formatter->page->name));
        $logs = Blog_cache::get_summary($blogs, $date);
        $rss_name = $formatter->page->name;
    }
    usort($logs, 'BlogCompare');
    /* generate <rss> ... </rss> */
    $rss = generate_rss($formatter, $rss_name, $logs);
    /* output encoding */
    if ($options['oe'] and strtolower($options['oe']) != $DBInfo->charset) {
        $charset = $options['oe'];
        if (function_exists('iconv')) {
            $out = iconv($DBInfo->charset, $charset, $rss);
            if (!$out) {
                $out =& $rss;
                $charset = $DBInfo->charset;
            }
        }
    } else {
        $charset = $DBInfo->charset;
    }
    /* emit output rss as text/xml */
    header("Content-Type: text/xml");
    print <<<XML
<?xml version="1.0" encoding="{$charset}"?>
<!--
    Add "oe=utf-8" to convert the charset of this rss to UTF-8.
-->
{$rss}
XML;
}
Exemplo n.º 2
0
             }
             // Create the post ("topic post")
             $db->query('INSERT INTO ' . $db->prefix . 'posts (poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id) VALUES(\'' . $db->escape($username) . '\', ' . $pun_user['id'] . ', \'' . get_remote_address() . '\', \'' . $db->escape($message) . '\', \'' . $hide_smilies . '\', ' . $_SERVER['REQUEST_TIME'] . ', ' . $new_tid . ')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
         } else {
             // Create the post ("topic post")
             $email_sql = $pun_config['p_force_guest_email'] == 1 || $email ? '\'' . $db->escape($email) . '\'' : 'NULL';
             $db->query('INSERT INTO ' . $db->prefix . 'posts (poster, poster_ip, poster_email, message, hide_smilies, posted, topic_id) VALUES(\'' . $db->escape($username) . '\', \'' . get_remote_address() . '\', ' . $email_sql . ', \'' . $db->escape($message) . '\', \'' . $hide_smilies . '\', ' . $_SERVER['REQUEST_TIME'] . ', ' . $new_tid . ')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
         }
         $new_pid = $db->insert_id();
         // Update the topic with last_post_id
         $db->query('UPDATE ' . $db->prefix . 'topics SET last_post_id=' . $new_pid . ' WHERE id=' . $new_tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
         update_search_index('post', $new_pid, $message, $subject);
         update_forum($fid);
     }
 }
 generate_rss();
 $uploaded = 0;
 $upload_result = process_uploaded_files($fid ? $new_tid : $tid, $new_pid, $uploaded);
 // If the posting user is logged in, increment his/her post count
 // MERGE POSTS BEGIN
 if (!$pun_user['is_guest']) {
     if ($uploaded) {
         $add_files = 'num_files=num_files+' . $uploaded . ', ';
     } else {
         $add_files = '';
     }
     if ($merged) {
         $db->query('UPDATE ' . $db->prefix . 'users SET ' . $add_files . 'last_post=' . $_SERVER['REQUEST_TIME'] . ' WHERE id=' . $pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
     } else {
         $db->query('UPDATE ' . $db->prefix . 'users SET ' . $add_files . 'num_posts=num_posts+1, last_post=' . $_SERVER['REQUEST_TIME'] . ' WHERE id=' . $pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
     }
Exemplo n.º 3
0
    $total = keyword_count($keyword);
    render('main', array('title' => 'Search results for: ' . tag_i18n($keyword) . ' - ' . blog_title(), 'description' => 'Search results for: ' . tag_i18n($keyword) . ' on ' . blog_title() . '.', 'canonical' => site_url() . 'search/' . strtolower($keyword), 'page' => $page, 'posts' => $posts, 'search' => $tsearch, 'bodyclass' => 'insearch', 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Search results for: ' . tag_i18n($keyword), 'pagination' => has_pagination($total, $perpage, $page), 'is_search' => true));
});
// The JSON API
get('/api/json', function () {
    header('Content-type: application/json');
    $page = from($_GET, 'page');
    $page = $page ? (int) $page : 1;
    $perpage = config('json.count');
    echo generate_json(get_posts(null, $page, $perpage));
});
// Show the RSS feed
get('/feed/rss', function () {
    header('Content-Type: application/rss+xml');
    // Show an RSS feed with the 30 latest posts
    echo generate_rss(get_posts(null, 1, config('rss.count')));
});
// Generate OPML file
get('/feed/opml', function () {
    header('Content-Type: text/xml');
    // Generate OPML file for the RSS
    echo generate_opml();
});
// Show blog post without year-month
get('/post/:name', function ($name) {
    if (config('permalink.type') != 'post') {
        $post = find_post(null, null, $name);
        $current = $post['current'];
        $redir = site_url() . date('Y/m', $current->date) . '/' . $name;
        header("location: {$redir}", TRUE, 301);
    }
Exemplo n.º 4
0
 /**
  * setMessage
  *
  * @param array $args
  * @return array
  * @throws Exception
  */
 public function setMessage($args)
 {
     $message = $args['message'];
     $topicId = $args['topicId'];
     $hideSmiles = $args['hideSmiles'];
     $topicId = intval($topicId);
     if ($topicId <= 0) {
         throw new Exception($this->_lang['Bad request']);
     }
     if ($this->_pun_user['is_guest']) {
         throw new Exception($this->_lang['Bad request']);
     }
     if ($this->_pun_user['last_post'] && $_SERVER['REQUEST_TIME'] - $this->_pun_user['last_post'] < $this->_pun_user['g_post_flood']) {
         throw new Exception($this->_lang['Bad request']);
     }
     // Clean up message
     $message = pun_linebreaks(pun_trim($message));
     if (!$message) {
         throw new Exception($this->_lang['Bad request']);
     } else {
         if (mb_strlen($message) > 65535) {
             throw new Exception($this->_lang['Bad request']);
         } else {
             if (!$this->_pun_config['p_message_all_caps'] && mb_strtoupper($message) == $message && $this->_pun_user['g_id'] > PUN_MOD) {
                 $message = ucwords(mb_strtolower($message));
             }
         }
     }
     convert_forum_url($message);
     // Insert the new post
     $r = $this->_db->query('
         INSERT INTO ' . $this->_db->prefix . 'posts (
             poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id
         ) VALUES (
             \'' . $this->_db->escape($this->_pun_user['username']) . '\',
             ' . $this->_pun_user['id'] . ',
             \'' . get_remote_address() . '\',
             \'' . $this->_db->escape($message) . '\',
             \'' . intval($hideSmiles) . '\',
             ' . $_SERVER['REQUEST_TIME'] . ',
             ' . $topicId . '
         )
     ');
     if (!$r) {
         throw new Exception($this->_db->error());
     }
     if (!$this->_db->affected_rows()) {
         throw new Exception($this->_lang['Bad request']);
     }
     $id = $this->_db->insert_id();
     // Count number of replies in the topic
     $result = $this->_db->query('
         SELECT COUNT(1)
         FROM ' . $this->_db->prefix . 'posts
         WHERE topic_id=' . $topicId);
     $num_replies = $this->_db->result($result, 0) - 1;
     // Update topic
     $this->_db->query('
         UPDATE ' . $this->_db->prefix . 'topics
         SET num_replies=' . $num_replies . ',
         last_post=' . $_SERVER['REQUEST_TIME'] . ',
         last_post_id=' . $id . ',
         last_poster=\'' . $this->_db->escape($this->_pun_user['username']) . '\'
         WHERE id=' . $topicId);
     //update_search_index('post', $id, $message);
     $result = $this->_db->query('
         SELECT f.id
         FROM ' . $this->_db->prefix . 'topics AS t
         INNER JOIN ' . $this->_db->prefix . 'forums AS f ON f.id=t.forum_id
         LEFT JOIN ' . $this->_db->prefix . 'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=' . $this->_pun_user['g_id'] . ')
         WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id=' . $topicId);
     $forumId = $this->_db->result($result, 0);
     update_forum($forumId);
     generate_rss();
     return array('message' => $this->_parseMessage($message, $hideSmiles), 'poster' => $this->_pun_user['username'], 'posted' => $_SERVER['REQUEST_TIME']);
 }
Exemplo n.º 5
0
        not_found();
    }
    render('main', array('page' => $page, 'posts' => $posts, 'has_pagination' => has_pagination($page)));
});
// The post page
get('/:year/:month/:name', function ($year, $month, $name) {
    $post = find_post($year, $month, $name);
    if (!$post) {
        not_found();
    }
    render('post', array('title' => $post->title . ' ⋅ ' . config('blog.title'), 'p' => $post));
});
// The JSON API
get('/api/json', function () {
    header('Content-type: application/json');
    // Print the 10 latest posts as JSON
    echo generate_json(get_posts(1, 10));
});
// Show the RSS feed
get('/rss', function () {
    header('Content-Type: application/rss+xml');
    // Show an RSS feed with the 30 latest posts
    echo generate_rss(get_posts(1, 30));
});
// If we get here, it means that
// nothing has been matched above
get('.*', function () {
    not_found();
});
// Serve the blog
dispatch();
Exemplo n.º 6
0
 function output_rss($channel, $items)
 {
     header("Content-Type: text/xml; charset=" . RSS_ENCODING);
     echo generate_rss($channel, $items);
 }