PHP Classes

File: bt-include/admin.functions.php

Recommend this page to a friend!
  Packages of Michael Dale   Bluetrait   bt-include/admin.functions.php   Download  
File: bt-include/admin.functions.php
Role: Auxiliary script
Content type: text/plain
Description: Admin Functions File
Class: Bluetrait
A multi-user blog system
Author: By
Last change:
Date: 18 years ago
Size: 3,968 bytes
 

Contents

Class file image Download
<?php

function bt_current_file() {

    return substr($_SERVER['PHP_SELF'], strlen(bt_get_config('script_path') . BT_ADMIN . '/'));

}

function bt_admin_message($message) {
    
    $output = '<div class="tablecontain">' . $message . '</div>';
    
    return $output;
}

function bt_total_comment_count() {
    global $bt_db, $bt_tb;

    $query = "SELECT count(*) FROM $bt_tb->comments WHERE comment_approved = 1";
    $stmt = $bt_db->prepare($query);

    try {
        $stmt->execute();
    }
    catch (Exception $e) {
        bt_die($e->getMessage());
    }
    
    $count = $stmt->fetch(PDO::FETCH_ASSOC);
    
    return (int) $count['count(*)'];

}

function bt_total_post_count() {
    global $bt_db, $bt_tb;

    $query = "SELECT count(*) FROM $bt_tb->posts WHERE post_type = 'published'";
    $stmt = $bt_db->prepare($query);

    try {
        $stmt->execute();
    }
    catch (Exception $e) {
        bt_die($e->getMessage());
    }
    
    $count = $stmt->fetch(PDO::FETCH_ASSOC);
    
    return (int) $count['count(*)'];

}

function bt_total_mod_comment_count() {
    global $bt_db, $bt_tb;

    $query = "SELECT count(*) FROM $bt_tb->comments WHERE comment_approved = 0";
    $stmt = $bt_db->prepare($query);

    try {
        $stmt->execute();
    }
    catch (Exception $e) {
        bt_die($e->getMessage());
    }
    
    $count = $stmt->fetch(PDO::FETCH_ASSOC);
    
    return (int) $count['count(*)'];

}

function bt_last_10_events() {
    global $bt_db, $bt_tb;
        
    //move this elsewhere
    $query = "SELECT event_date, description, type, event_id FROM $bt_tb->events ORDER BY event_id DESC LIMIT 10";
    $stmt = $bt_db->prepare($query);
    try {
        $stmt->execute();
    }
    catch (Exception $e) {
        bt_die($e->getMessage());
    }
    $events = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    return $events;

}

function admin_upgrade_message() {
    global $bt_database_version;

    try {
        if (bt_get_config('database_version') == $bt_database_version) {
            $xml = new SimpleXMLElement(bt_get_config('last_update_response'));
            $version = bt_get_config('program_version');
            $version = explode('-', $version);
            if (version_compare($version[0], $xml->version, '<')) {
                $message = 'There is a new version of Bluetrait available, ' . bt_htmlentities($xml->version) . '.';
                if ($xml->download) {
                    $message .= ' It can be downloaded from <strong><a href="'.bt_htmlentities($xml->download).'">here</a></strong>.';
                    $message .= ' Please make sure you read upgrade.txt contained within the package before you upgrade.';
                }
                return $message;
            }
        }
        else {
            $message = 'Your database needs updating click <a href="upgrade.php">here</a> to upgrade.';
            return $message;
        }
    }
    catch (Exception $e) {
        //echo($e->getMessage());
    }
    return false;

}

function bt_return_site() {

    $site_length = strlen(bt_get_config('address'));
    if (isset($_SERVER['HTTP_REFERER']) && !strncmp($_SERVER['HTTP_REFERER'], bt_get_config('address'), $site_length)) {
        $return = bt_htmlentities($_SERVER['HTTP_REFERER']);
    }
    else {
        $return = false;
    }
    
    return $return;
}

//displays a back link. If HTTP_REFERER is disabled then redirect to $url,
//otherwise back to admin index
function bt_admin_url_back($url = '') {
    $return_site = bt_return_site();
    if ($return_site) {
        $url_array = parse_url($return_site);
        if (!array_key_exists('query', $url_array)) $url_array['query'] = '';
        if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']) && $url_array['query'] == $_SERVER['QUERY_STRING']) {
            if (!empty($url)) {
                return '<a href="'. $url .'">&laquo; Back</a>';
            }
            else {
                return '<a href="'. bt_get_config('address'). BT_ADMIN . '/">&laquo; Back</a>';
            }
        }
        else {
            return '<a href="'. $return_site .'">&laquo; Back</a>';
        }
    }
    elseif (!empty($url)) {
        return '<a href="'. $url .'">&laquo; Back</a>';
    }
    else {
        return '<a href="'. bt_get_config('address'). BT_ADMIN . '/">&laquo; Back</a>';
    }
}

?>