Esempio n. 1
0
/**
 * function plugin_lastcomments_cache
 * 
 * comment cache is a reverse queue; we put
 * element on the top, and we delete elements
 * from bottom; this is because the output
 * string is created reading queuing from top to bottom.
 * All this headache stuff just to say that
 * in the end the widget will show up elements ordered
 * from newer to older :P
 * 
 * @param $entryid string entry id i.e. entryNNNNNN-NNNNNN
 * @param $comment array where $comment[0] is $commentid i.e. commentNNNNNN-NNNNNN
 *			 and $comment[1] is the actual content array 
 */
function plugin_lastcomments_cache($entryid, $comment)
{
    // max num of chars per comment
    $CHOP_AT = 30;
    list($id, $content) = $comment;
    comment_clean($content);
    if (false === ($f = io_load_file(LASTCOMMENTS_CACHE_FILE))) {
        // no comments in cache
        $list = array();
    } else {
        // if file exists and its correctly read, we get the stored list
        // (it is stored in encoded form)
        $list = unserialize($f);
        if (count($list) + 1 > LASTCOMMENTS_MAX) {
            // comments are more than allowed maximum:
            // we delete the last in queue.
            array_shift($list);
        }
    }
    if (strlen($content['content']) > $CHOP_AT) {
        $string = substr($content['content'], 0, $CHOP_AT) . '...';
    } else {
        $string = $content['content'];
    }
    array_push($list, array('name' => $content['name'], 'content' => $string, 'id' => $id, 'entry' => $entryid));
    return io_write_file(LASTCOMMENTS_CACHE_FILE, serialize($list));
}
Esempio n. 2
0
/**
 * function bdb_save_comment
 *
 * <p>Saves the content of the $comment array, associating it to the entry-ID $id.</p>
 * <p>$comment must be formatted as the one returned by {@link bdb_parse_entry()}.</p>
 * <p>Returns true on success, or false on failure</p>
 *
 * @param string $id string formatted like "prefixYYMMDD-HHMMSS"
 * @param array $comment array formatted as the one returned by {@link bdb_parse_entry()}
 * @return bool
 * 
 * @see bdb_parse_entry()
 */
function comment_save($id, $comment)
{
    comment_clean($comment);
    $comment = array_change_key_case($comment, CASE_UPPER);
    $comment_dir = bdb_idtofile($id, BDB_COMMENT);
    if (!isset($comment['DATE'])) {
        $comment['DATE'] = date_time();
    }
    $id = bdb_idfromtime(BDB_COMMENT, $comment['DATE']);
    $f = $comment_dir . $id . EXT;
    $str = utils_kimplode($comment);
    if (io_write_file($f, $str)) {
        return $id;
    }
    return false;
}