Example #1
0
 if (isset($_REQUEST['moderate']) && $_REQUEST['moderate'] == 1) {
     $approved = 0;
     $moderate = 1;
 } else {
     $approved = 1;
     $moderate = 0;
 }
 $output .= "\n\t" . '<form id="contentList" action="' . $_SERVER['PHP_SELF'] . '?moderate=' . $moderate . '" method="post">';
 if ($approved) {
     $pagination_menu = generate_pagination('admin', 'feedback', $plog_page, $num_comments, $_SESSION['entries_per_page']);
 } else {
     $pagination_menu = generate_pagination('admin', 'feedback', $plog_page, $num_comments_im, $_SESSION['entries_per_page'], array('moderate' => 1));
 }
 $pagination_menu = "\n\t\t" . '<div class="pagination">' . $pagination_menu . '</div>';
 // Generate javascript init function for ajax editing
 $timefn = getTimeFn();
 $query = "SELECT *, {$timefn}\"date\") AS \"date\" from " . PLOGGER_TABLE_PREFIX . "comments WHERE \"approved\" = " . $approved . " ORDER BY \"id\" DESC " . $limit;
 $result = run_query($query);
 if ($result->rowCount() > 0) {
     $output .= "\n\t\t" . '<script type="text/javascript">';
     $output .= "\n\t\t\t" . 'Event.observe(window, \'load\', init, false);';
     $output .= "\n\t\t\t" . 'function init() {' . "\n";
     while ($row = $result->fetch()) {
         $output .= "\t\t\t\tmakeEditable('comment-comment-" . $row['id'] . "');\n\t\t\t\tmakeEditable('comment-author-" . $row['id'] . "');\n\t\t\t\tmakeEditable('comment-url-" . $row['id'] . "');\n\t\t\t\tmakeEditable('comment-email-" . $row['id'] . "');\n";
     }
     $output .= "\t\t\t" . '}';
     $output .= "\n\t\t" . '</script>' . "\n";
 }
 $query = "SELECT *, {$timefn}\"date\") AS \"date\" from " . PLOGGER_TABLE_PREFIX . "comments WHERE \"approved\" = " . $approved . " ORDER BY \"id\" DESC " . $limit;
 $result = run_query($query);
 $empty = 0;
function plogger_init_search($arr)
{
    global $PLOGGER_DBH;
    $timefn = getTimeFn();
    $terms = explode(' ', $arr['searchterms']);
    $from = 0;
    $limit = 20;
    if (isset($arr['from']) && $arr['from'] > 0) {
        $from = $arr['from'];
    }
    // Enforce hard-coded max limit
    if (isset($arr['limit']) && $arr['limit'] > 0 && $arr['limit'] <= 100) {
        $limit = $arr['limit'];
    }
    $query = " FROM \"" . PLOGGER_TABLE_PREFIX . "pictures\" p LEFT JOIN \"" . PLOGGER_TABLE_PREFIX . "comments\" c\n\tON p.\"id\" = c.\"parent_id\" ";
    if (count($terms) != 1 || $terms[0] != '') {
        $query .= " WHERE ( ";
        foreach ($terms as $term) {
            $term = $PLOGGER_DBH->quote('%' . $term . '%');
            $multi_term = explode('+', $term);
            if (count($multi_term) > 1) {
                $path = implode("%' AND \"path\" LIKE '%", $multi_term);
                $description = implode("%' AND \"description\" LIKE '%", $multi_term);
                $comment = implode("%' AND \"comment\" LIKE '%", $multi_term);
                $caption = implode("%' AND \"caption\" LIKE '%", $multi_term);
            } else {
                $path = $description = $comment = $caption = $term;
            }
            $query .= "\n\t\t\t\"path\" LIKE {$path} OR\n\t\t\t\"description\" LIKE {$description} OR\n\t\t\t\"comment\" LIKE {$comment} OR\n\t\t\t\"caption\" LIKE {$caption} OR ";
        }
        $query = substr($query, 0, strlen($query) - 3) . ") ";
    } else {
        // No search terms? No results either
        $query .= " WHERE 1 = 0";
    }
    $sort_fields = array('date_submitted', 'id');
    $sortby = 'date_submitted';
    if (isset($arr['sortby']) && in_array($arr['sortby'], $sort_fields)) {
        $sortby = $arr['sortby'];
    }
    $sortdir = ' DESC';
    if (isset($arr['sortdir']) && 'asc' == $arr['sortdir']) {
        $sortdir = ' ASC';
    }
    $result = run_query("SELECT COUNT(DISTINCT p.\"id\") AS cnt " . $query);
    $row = $result->fetch();
    $GLOBALS['total_pictures'] = $row['cnt'];
    // And I need sort order here as well
    // from and limit too
    $result = run_query("SELECT \"caption\",\"path\",p.\"id\",c.\"comment\",\n\t{$timefn}\"date_submitted\") AS \"unix_date_submitted\" " . $query . "\n\tGROUP BY p.\"id\", c.\"comment\"  ORDER BY \"{$sortby}\" {$sortdir} LIMIT {$limit} OFFSET {$from}");
    $GLOBALS['available_pictures'] = $result->rowCount();
    $GLOBALS['picture_counter'] = 0;
    $GLOBALS['picture_dbh'] = $result;
}