コード例 #1
0
function render_comments($table, $id)
{
    /* This function will not use memcache for the MySQL queries, as 
     * the data returned would be stale - which would obviously be a bad
     * idea in a function that's going to either be used to force-update
     * the render cache (in which case stale data defeats the point) or
     * as first generation (in which case there is no data in memcache
     * anyway). */
    global $render_dir;
    if ($table == "ext") {
        $section = "external-news";
    } elseif ($table == "sites") {
        $section = "related-sites";
    } else {
        $section = "press";
    }
    $query = "SELECT * FROM {$table} WHERE `Id`='{$id}'";
    $res = mysql_query($query);
    if (mysql_num_rows($res) > 0) {
        $output = "";
        $res = mysql_query("SELECT * FROM comments WHERE `ItemId` = '{$id}' AND `Section` = '{$table}' AND `Visible` = '1' ORDER BY `Posted` ASC");
        if (mysql_num_rows($res) > 0) {
            while ($row = mysql_fetch_array($res)) {
                $obj->id = $row['Id'];
                $obj->itemid = $row['ItemId'];
                $obj->name = $row['Name'];
                $obj->body = $row['Body'];
                $obj->parentid = $row['ParentId'];
                $obj->postdate = $row['Posted'];
                $obj->linecount = $row['LineCount'];
                $obj->children = array();
                $dataset[$obj->id] = clone $obj;
            }
            foreach ($dataset as $element) {
                if ($element->parentid == 0) {
                    $top[] = $element;
                } else {
                    if (isset($dataset[$element->parentid])) {
                        $dataset[$element->parentid]->children[] = $element;
                    }
                }
            }
            foreach ($top as $comment) {
                $output .= print_comment($comment, $table);
                $output .= "<div class=\"c-spacer\"></div>";
            }
        } else {
            $output = "No comments have been posted on this entry yet.";
        }
        $output .= "\n\t\t\t<hr>\n\t\t\t<div class=\"c-comment\">\n\t\t\t<div class=\"c-reply-header\">\n\t\t\tPost a new comment\n\t\t\t</div>\n\t\t\t<form method=\"post\" action=\"/{$section}/item/{$id}/comments/post/\">\n\t\t\t<input type=\"text\" name=\"name\" value=\"Anonymous\" class=\"c-inline\">\n\t\t\t<textarea name=\"body\" class=\"c-inline\"></textarea>\n\t\t\t<div class=\"button\">\n\t\t\t<button type=\"submit\" name=\"submit\">Post comment</button>\n\t\t\t</div>\n\t\t\t</form>\n\t\t\t</div>\n\t\t";
        $path = "{$render_dir}/c-{$table}-{$id}.render";
        file_put_contents($path, $output);
        mc_delete(md5($path) . md5($path . "x"));
        return $output;
    } else {
        return false;
    }
}
コード例 #2
0
ファイル: class.databaserecord.php プロジェクト: deanet/Neon
 public function PurgeCache()
 {
     $parameters = array(":Id" => (string) $this->sId);
     $query_hash = md5($this->fill_query);
     $parameter_hash = md5(serialize($parameters));
     $cache_hash = $query_hash . $parameter_hash;
     mc_delete($cache_hash);
 }