Example #1
0
 public static function distinct_post_terms(array $posts, $fields = '')
 {
     $ids = array();
     foreach ($posts as $post) {
         if (is_numeric($post)) {
             $ids[] = absint($post);
         } elseif (is_a($post, 'WP_Post')) {
             $ids[] = $post->ID;
         } elseif (is_a($post, 'PostController')) {
             $ids[] = $post->id;
         }
     }
     if (empty($ids)) {
         return array();
     }
     global $wpdb;
     $ids = implode(',', $ids);
     $query = "\n      SELECT DISTINCT t.term_id, t.name, t.slug, t.term_group\n\n      FROM `wp_terms` as t\n      JOIN `wp_term_taxonomy` as tax ON t.term_id = tax.term_id\n      JOIN `wp_term_relationships` as rel ON tax.term_taxonomy_id = rel.term_taxonomy_id\n\n      WHERE rel.object_id IN ({$ids});\n    ";
     switch ($fields) {
         case 'raw':
             return get_results($query, OBJECT_K);
         case 'ids':
             return get_col($query);
         default:
             $results = get_results($query);
             foreach ($results as &$result) {
                 $result = self::get_controller($result);
             }
             return $results;
     }
 }
Example #2
0
foreach ($hosts as $index => $host) {
    $filename = $conf['rrds'] . "/{$clustername}/{$host}/{$metricname}.rrd";
    if (file_exists($filename)) {
        $c++;
        $command .= " DEF:'a{$c}'='{$filename}':'sum':AVERAGE";
        $total_cmd .= ",a{$c},+";
    }
}
$mean_cmd = " CDEF:'mean'=total,{$c},/";
$first = array_shift($hosts);
$color = get_col(0);
$command .= " AREA:'a1'#{$color}:'{$first}'";
$c = 1;
foreach ($hosts as $host) {
    $cx = $c / (1 + count($hosts));
    $color = get_col($cx);
    $c++;
    $command .= " STACK:'a{$c}'#{$color}:'{$host}'";
}
$command .= " LINE1:'a1'#333";
$c = 1;
foreach ($hosts as $host) {
    $c++;
    $command .= " STACK:'a{$c}'#000000";
}
$command .= $total_cmd . $mean_cmd;
$command .= " COMMENT:'\\j'";
$command .= " GPRINT:'total':AVERAGE:'Avg Total\\: %5.2lf'";
$command .= " GPRINT:'total':LAST:'Current Total\\: %5.2lf\\c'";
$command .= " GPRINT:'mean':AVERAGE:'Avg Average\\: %5.2lf'";
$command .= " GPRINT:'mean':LAST:'Current Average\\: %5.2lf\\c'";
Example #3
0
File: tit.php Project: schwebke/tit
    if (trim($description) != '') {
        $query = "INSERT INTO comments (issue_id, description, user, entrytime) values('{$issue_id}','{$description}','{$user}','{$now}')";
        // create
        $db->exec($query);
    }
    if ($NOTIFY["COMMENT_CREATE"]) {
        notify($id, "[{$TITLE}] New Comment Posted", "New comment posted by {$user}\r\nTitle: " . get_col($id, "issues", "title") . "\r\nURL: http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?id={$issue_id}");
    }
    header("Location: {$_SERVER['PHP_SELF']}?id={$issue_id}");
}
// Delete Comment
if (isset($_GET["deletecomment"])) {
    $id = pdo_escape_string($_GET['id']);
    $cid = pdo_escape_string($_GET['cid']);
    // only comment poster or admin can delete comment
    if ($_SESSION['tit']['admin'] || $_SESSION['tit']['username'] == get_col($cid, "comments", "user")) {
        $db->exec("DELETE FROM comments WHERE id='{$cid}'");
    }
    header("Location: {$_SERVER['PHP_SELF']}?id={$id}");
}
//
//      FUNCTIONS
//
// PDO quote, but without enclosing single-quote
function pdo_escape_string($str)
{
    global $db;
    $quoted = $db->quote($str);
    return $db->quote("") == "''" ? substr($quoted, 1, strlen($quoted) - 2) : $quoted;
}
// check credentials, returns -1 if not okay