/**
 * Smarty {math} function plugin
 *
 * Type:     function<br>
 * Name:     math<br>
 * Purpose:  handle math computations in template<br>
 *
 * @link http://smarty.php.net/manual/en/language.function.math.php {math}
 *          (Smarty online manual)
 * @param array
 * @param Smarty
 * @param unknown $params
 * @param unknown $smarty (reference)
 * @return string
 */
function smarty_function_math($params, &$smarty)
{
    // be sure equation parameter is present
    if (empty($params['equation'])) {
        $smarty->trigger_error("math: missing equation parameter");
        return;
    }
    $equation = $params['equation'];
    // make sure parenthesis are balanced
    if (substr_count($equation, "(") != substr_count($equation, ")")) {
        $smarty->trigger_error("math: unbalanced parenthesis");
        return;
    }
    // match all vars in equation, make sure all are passed
    preg_match_all("!\\!(0x)([a-zA-Z][a-zA-Z0-9_]*)!", $equation, $match);
    $allowed_funcs = array('int', 'abs', 'ceil', 'cos', 'exp', 'floor', 'log', 'log10', 'max', 'min', 'pi', 'pow', 'rand', 'round', 'sin', 'sqrt', 'srand', 'tan');
    foreach ($match[2] as $curr_var) {
        if (!in_array($curr_var, array_keys($params)) && !in_array($curr_var, $allowed_funcs)) {
            $smarty->trigger_error("math: parameter {$curr_var} not passed as argument");
            return;
        }
    }
    foreach ($params as $key => $val) {
        if ($key != "equation" && $key != "format" && $key != "assign") {
            // make sure value is not empty
            if (strlen($val) == 0) {
                $smarty->trigger_error("math: parameter {$key} is empty");
                return;
            }
            if (!is_numeric($val)) {
                $smarty->trigger_error("math: parameter {$key}: is not numeric");
                return;
            }
            $equation = preg_replace("/\\b{$key}\\b/", $val, $equation);
        }
    }
    eval("\$smarty_math_result = " . $equation . ";");
    if (empty($params['format'])) {
        if (empty($params['assign'])) {
            return $smarty_math_result;
        } else {
            $smarty->assign($params['assign'], $smarty_math_result);
        }
    } else {
        if (empty($params['assign'])) {
            printf($params['format'], $smarty_math_result);
        } else {
            $smarty->assign($params['assign'], sprintf($params['format'], $smarty_math_result));
        }
    }
}
/**
 * Smarty {assign_debug_info} function plugin
 *
 * Type:     function<br>
 * Name:     assign_debug_info<br>
 * Purpose:  assign debug info to the template<br>
 *              {@link Smarty::$_tpl_vars} and {@link Smarty::$_smarty_debug_info}
 *
 * @param Smarty
 * @param unknown $params
 * @param unknown $smarty (reference)
 */
function smarty_function_assign_debug_info($params, &$smarty)
{
    $assigned_vars = $smarty->_tpl_vars;
    ksort($assigned_vars);
    if (@is_array($smarty->_config[0])) {
        $config_vars = $smarty->_config[0];
        ksort($config_vars);
        $smarty->assign("_debug_config_keys", array_keys($config_vars));
        $smarty->assign("_debug_config_vals", array_values($config_vars));
    }
    $included_templates = $smarty->_smarty_debug_info;
    $smarty->assign("_debug_keys", array_keys($assigned_vars));
    $smarty->assign("_debug_vals", array_values($assigned_vars));
    $smarty->assign("_debug_tpls", $included_templates);
}
Exemple #3
0
/**
 *
 *
 * @param unknown $bBlog (reference)
 */
function admin_plugin_rss_run(&$bBlog)
{
    $pole = "";
    for ($i = 1; $i < 10; $i++) {
        if (isset($_POST['sending']) && $_POST['sending'] == "true") {
            $id = $_POST[id . $i];
            $ch = $_POST[ch . $i];
            $update_query = "UPDATE " . T_RSS . " SET `url` = '" . $id . "',`input_charset` = '" . $ch . "' WHERE `id` = '" . $i . "' LIMIT 1 ;";
            $bBlog->query($update_query);
        }
        $query = "select * from " . T_RSS . " where id=" . $i . ";";
        $row = $bBlog->get_row($query);
        $rssurl = $row->url;
        $w1250 = "";
        if ($row->input_charset == "W1250") {
            $w1250 = " selected";
        }
        $utf8 = "";
        if ($row->input_charset == "UTF8") {
            $utf8 = " selected";
        }
        if ($i / 2 == floor($i / 2)) {
            $class = 'high';
        } else {
            $class = 'low';
        }
        $pole .= '<tr class="' . $class . '"><td>' . $i . '</td><td><input type="text" name="id' . $i . '" size="20" value="' . $rssurl . '" class="text" /></td><td><select name="ch' . $i . '">';
        $pole .= '<option>I88592</option>';
        $pole .= '<option' . $w1250 . '>W1250</option>';
        $pole .= '<option' . $utf8 . '>UTF8</option>';
        $pole .= '</select></td></tr>';
    }
    $bBlog->assign('pole', $pole);
}
/**
 * Smarty {debug} function plugin
 *
 * Type:     function<br>
 * Name:     debug<br>
 * Date:     July 1, 2002<br>
 * Purpose:  popup debug window
 *
 * @link http://smarty.php.net/manual/en/language.function.debug.php {debug}
 *       (Smarty online manual)
 * @author   Monte Ohrt <*****@*****.**>
 * @version  1.0
 * @param array
 * @param Smarty
 * @param unknown $params
 * @param unknown $smarty (reference)
 * @return string output from {@link Smarty::_generate_debug_output()}
 */
function smarty_function_debug($params, &$smarty)
{
    if ($params['output']) {
        $smarty->assign('_smarty_debug_output', $params['output']);
    }
    require_once SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.display_debug_console.php';
    return smarty_core_display_debug_console(null, $smarty);
}
/**
 * Smarty {assign} function plugin
 *
 * Type:     function<br>
 * Name:     assign<br>
 * Purpose:  assign a value to a template variable
 *
 * @link http://smarty.php.net/manual/en/language.custom.functions.php#LANGUAGE.FUNCTION.ASSIGN {assign}
 *       (Smarty online manual)
 * @param array   Format: array('var' => variable name, 'value' => value to assign)
 * @param Smarty
 * @param unknown $params
 * @param unknown $smarty (reference)
 */
function smarty_function_assign($params, &$smarty)
{
    extract($params);
    if (empty($var)) {
        $smarty->trigger_error("assign: missing 'var' parameter");
        return;
    }
    if (!in_array('value', array_keys($params))) {
        $smarty->trigger_error("assign: missing 'value' parameter");
        return;
    }
    $smarty->assign($var, $value);
}
/**
 *
 *
 * @param unknown $params
 * @param unknown $bBlog  (reference)
 */
function smarty_function_getcontent($params, &$bBlog)
{
    // Retrieving data
    $bBlog->get_sections();
    $sections = $bBlog->sections;
    foreach ($sections as $object) {
        $new[$object->sectionid] = $object;
    }
    $sections = $new;
    $current_section = $bBlog->get_template_vars("sectionid");
    // Return
    $bBlog->assign("content", $sections[$current_section]->content);
}
/**
 *
 *
 * @param unknown $params
 * @param unknown $bBlog  (reference)
 */
function smarty_function_getcomments($params, &$bBlog)
{
    $assign = "comments";
    $postid = $bBlog->show_post;
    $replyto = $_REQUEST['replyto'];
    extract($params);
    // first, assign the hidden fields
    $commentformhiddenfields = '<input type="hidden" name="do" value="submitcomment" />';
    $commentformhiddenfields .= '<input type="hidden" name="comment_postid" value="' . $postid . '" />';
    if (is_numeric($replyto)) {
        $commentformhiddenfields .= '<a name="commentform"></a><input type="hidden" name="replytos" value="' . $replyto . '" />';
    }
    $bBlog->assign("commentformhiddenfields", $commentformhiddenfields);
    $bBlog->assign("commentformaction", $bBlog->_get_entry_permalink($postid));
    // are we posting a comment ?
    if ($_POST['do'] == 'submitcomment' && is_numeric($_POST['comment_postid'])) {
        // we are indeed!
        if (is_numeric($_POST['replytos'])) {
            $rt = $_POST['replytos'];
        } else {
            $rt = false;
        }
        $bBlog->new_comment($_POST['comment_postid'], $rt);
    }
    // get the comments.
    /* start loop and get posts*/
    $rt = false;
    if (is_numeric($_GET['replyto'])) {
        $rt = $_GET['replyto'];
        $cs = $bBlog->get_comment($postid, $rt);
    } else {
        $cs = $bBlog->get_comments($postid, FALSE);
    }
    /* assign loop variable */
    $bBlog->assign($assign, $cs);
}
/**
 *
 *
 * @param unknown $bBlog (reference)
 */
function admin_plugin_rssfeedmaker_run(&$bBlog)
{
    if (isset($_POST['sub']) && $_POST['sub'] == 'y') {
        $url = BLOGURL . 'rss.php?';
        if ($_POST['version'] == 2) {
            $url .= 'ver=2';
        } elseif ($_POST['version'] == 'atom03') {
            $url .= 'ver=atom03';
        } else {
            $url .= 'ver=0.92';
        }
        if (is_numeric($_POST['num'])) {
            $url .= '&amp;num=' . $_POST['num'];
        }
        if ($_POST['sectionid'] > 0) {
            $url .= '&amp;sectionid=' . $_POST['sectionid'];
        }
        if (is_numeric($_POST['year'])) {
            $url .= '&amp;year=' . $_POST['year'];
        }
        if (is_numeric($_POST['month'])) {
            $url .= '&amp;year=' . $_POST['day'];
        }
        if (is_numeric($_POST['day'])) {
            $url .= '&amp;year=' . $_POST['day'];
        }
        $bBlog->assign('results', TRUE);
        $bBlog->assign('feedurl', $url);
    }
    $sections = $bBlog->get_sections();
    $sectionlist = '';
    foreach ($sections as $section) {
        $sectionlist .= "<option value='{$section->sectionid}'>{$section->nicename}</option>";
    }
    $bBlog->assign('sectionlist', $sectionlist);
}
/**
 * Smarty {counter} function plugin
 *
 * Type:     function<br>
 * Name:     counter<br>
 * Purpose:  print out a counter value
 *
 * @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
 *       (Smarty online manual)
 * @param array   parameters
 * @param Smarty
 * @param unknown $params
 * @param unknown $smarty (reference)
 * @return string|null
 */
function smarty_function_counter($params, &$smarty)
{
    static $counters = array();
    extract($params);
    if (!isset($name)) {
        if (isset($id)) {
            $name = $id;
        } else {
            $name = "default";
        }
    }
    if (!isset($counters[$name])) {
        $counters[$name] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1);
    }
    $counter =& $counters[$name];
    if (isset($start)) {
        $counter['start'] = $counter['count'] = $start;
    }
    if (!empty($assign)) {
        $counter['assign'] = $assign;
    }
    if (isset($counter['assign'])) {
        $smarty->assign($counter['assign'], $counter['count']);
    }
    if (isset($print)) {
        $print = (bool) $print;
    } else {
        $print = empty($counter['assign']);
    }
    if ($print) {
        $retval = $counter['count'];
    } else {
        $retval = null;
    }
    if (isset($skip)) {
        $counter['skip'] = $skip;
    }
    if (isset($direction)) {
        $counter['direction'] = $direction;
    }
    if ($counter['direction'] == "down") {
        $counter['count'] -= $counter['skip'];
    } else {
        $counter['count'] += $counter['skip'];
    }
    return $retval;
}
/**
 *
 *
 * @param unknown $params
 * @param unknown $bBlog  (reference)
 * @return unknown
 */
function smarty_function_getarchives($params, &$bBlog)
{
    $ar = array();
    $opt = $params;
    unset($opt['assign']);
    // If "assign" is not set... we'll establish a default.
    if ($params['assign'] == '') {
        $params['assign'] = 'archives';
    }
    $ar = $bBlog->get_archives($opt);
    // No posts.
    if (!is_array($ar)) {
        return '';
    }
    $bBlog->assign($params['assign'], $ar);
    return '';
}
/**
 * Smarty {textformat}{/textformat} block plugin
 *
 * Type:     block function<br>
 * Name:     textformat<br>
 * Purpose:  format text a certain way with preset styles
 *           or custom wrap/indent settings<br>
 *
 * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat}
 *       (Smarty online manual)
 * @param array
 * <pre>
 * Params:   style: string (email)
 *           indent: integer (0)
 *           wrap: integer (80)
 *           wrap_char string ("\n")
 *           indent_char: string (" ")
 *           wrap_boundary: boolean (true)
 * </pre>
 * @param string  contents of the block
 * @param Smarty  clever simulation of a method
 * @param unknown $params
 * @param unknown $content
 * @param unknown $smarty  (reference)
 * @return string string $content re-formatted
 */
function smarty_block_textformat($params, $content, &$smarty)
{
    $style = null;
    $indent = 0;
    $indent_first = 0;
    $indent_char = ' ';
    $wrap = 80;
    $wrap_char = "\n";
    $wrap_cut = false;
    $assign = null;
    if ($content == null) {
        return true;
    }
    extract($params);
    if ($style == 'email') {
        $wrap = 72;
    }
    // split into paragraphs
    $paragraphs = preg_split('![\\r\\n][\\r\\n]!', $content);
    $output = '';
    foreach ($paragraphs as $paragraph) {
        if ($paragraph == '') {
            continue;
        }
        // convert mult. spaces & special chars to single space
        $paragraph = preg_replace(array('!\\s+!', '!(^\\s+)|(\\s+$)!'), array(' ', ''), $paragraph);
        // indent first line
        if ($indent_first > 0) {
            $paragraph = str_repeat($indent_char, $indent_first) . $paragraph;
        }
        // wordwrap sentences
        $paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
        // indent lines
        if ($indent > 0) {
            $paragraph = preg_replace('!^!m', str_repeat($indent_char, $indent), $paragraph);
        }
        $output .= $paragraph . $wrap_char . $wrap_char;
    }
    if ($assign != null) {
        $smarty->assign($assign, $output);
    } else {
        return $output;
    }
}
Exemple #12
0
/**
 * Smarty {eval} function plugin
 *
 * Type:     function<br>
 * Name:     eval<br>
 * Purpose:  evaluate a template variable as a template<br>
 *
 * @link http://smarty.php.net/manual/en/language.function.eval.php {eval}
 *       (Smarty online manual)
 * @param array
 * @param Smarty
 * @param unknown $params
 * @param unknown $smarty (reference)
 * @return unknown
 */
function smarty_function_eval($params, &$smarty)
{
    if (!isset($params['var'])) {
        $smarty->trigger_error("eval: missing 'var' parameter");
        return;
    }
    if ($params['var'] == '') {
        return;
    }
    $smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
    ob_start();
    $smarty->_eval('?>' . $_var_compiled);
    $_contents = ob_get_contents();
    ob_end_clean();
    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $_contents);
    } else {
        return $_contents;
    }
}
/**
 *
 *
 * @param unknown $params
 * @param unknown $bBlog  (reference)
 * @return unknown
 */
function smarty_function_getpost($params, &$bBlog)
{
    $ar = array();
    // If "assign" is not set... we'll establish a default.
    if ($params['assign'] == '') {
        $params['assign'] = 'post';
    }
    if ($params['postid'] == '') {
        $bBlog->trigger_error('postid is a required parameter');
        return '';
    }
    $q = $bBlog->make_post_query(array("postid" => $params['postid']));
    $ar['posts'] = $bBlog->get_posts($q);
    // No posts.
    if (!is_array($ar['posts'])) {
        return false;
    }
    $ar['posts'][0]['newday'] = 'yes';
    $ar['posts'][0]['newmonth'] = 'yes';
    $bBlog->assign($params['assign'], $ar['posts'][0]);
    return '';
}
/**
 *
 *
 * @param unknown $params
 * @param unknown $bBlog  (reference)
 * @return unknown
 */
function smarty_function_getposts($params, &$bBlog)
{
    $ar = array();
    $opt = array();
    if (is_numeric($params['postid']) && $params['postid'] > 0) {
        $postid = $params['postid'];
    } else {
        $postid = FALSE;
    }
    // If "assign" is not set... we'll establish a default.
    if ($params['assign'] == '') {
        if ($postid) {
            $params['assign'] = 'post';
        } else {
            $params['assign'] = 'posts';
        }
    }
    if ($postid) {
        //we've been given a post id so we'll just get it and get outta here.
        $q = $bBlog->make_post_query(array("postid" => $params['postid']));
        $ar['posts'] = $bBlog->get_posts($q);
        // No post.
        if (!is_array($ar['posts'])) {
            return false;
        }
        $ar['posts'][0]['newday'] = 'yes';
        $ar['posts'][0]['newmonth'] = 'yes';
        $bBlog->assign($params['assign'], $ar['posts'][0]);
        return '';
        // so if postid is given this is the last line processed
    }
    // If "archive" is set, order them ASCENDING by posttime.
    if ($params['archive']) {
        $opt['order'] = " ORDER BY posttime ";
    }
    // If num is set, we'll only get that many results in return
    if (is_numeric($params['num'])) {
        $opt['num'] = $params['num'];
    }
    // If skip is set, we'll skip that many results
    if (is_numeric($params['skip'])) {
        $opt['skip'] = $params['skip'];
    }
    if ($params['section'] != '') {
        $opt['sectionid'] = $bBlog->sect_by_name[$params['section']];
    }
    if ($bBlog->show_section) {
        $opt['sectionid'] = $bBlog->show_section;
    }
    if (is_numeric($params['year'])) {
        if (strlen($params['year']) != 4) {
            $bBlog->trigger_error('getposts: year parameter requires a 4 digit month');
            return '';
        }
        $opt['year'] = $params['year'];
    }
    if (is_numeric($params['month'])) {
        if (strlen($params['month']) != 2) {
            $bBlog->trigger_error('getposts: month parameter requires a 2 digit month');
            return '';
        }
        $opt['month'] = $params['month'];
    }
    if (is_numeric($params['day'])) {
        if (strlen($params['day']) != 2) {
            $bBlog->trigger_error('getposts: day parameter requires a 2 digit day');
            return '';
        }
        $opt['day'] = $params['day'];
    }
    if (is_numeric($params['hour'])) {
        if (strlen($params['hour']) != 2) {
            $bBlog->trigger_error('getposts: hour parameter requires a 2 digit hour');
            return '';
        }
        $opt['hour'] = $params['hour'];
    }
    if (is_numeric($params['minute'])) {
        if (strlen($params['minute']) != 2) {
            $bBlog->trigger_error('getposts: minute parameter requires a 2 digit minute');
            return '';
        }
        $opt['minute'] = $params['minute'];
    }
    if (is_numeric($params['second'])) {
        if (strlen($params['second']) != 2) {
            $bBlog->trigger_error('getposts: second parameter requires a 2 digit second');
            return '';
        }
        $opt['second'] = $params['second'];
    }
    $opt['home'] = $params['home'];
    $q = $bBlog->make_post_query($opt);
    $ar['posts'] = $bBlog->get_posts($q);
    // No posts.
    if (!is_array($ar['posts'])) {
        return '';
    }
    $lastmonth = 0;
    $lastdate = 0;
    foreach ($ar['posts'] as $key => $value) {
        /* check if new day  - used by block.newday.php */
        if (date('Ymd', $ar['posts'][$key]['posttime']) != $lastdate) {
            $ar['posts'][$key]['newday'] = TRUE;
        }
        $lastdate = date('Ymd', $ar['posts'][$key]['posttime']);
        /* check if new month - use by block.newmonth.php */
        if (date('Fy', $ar['posts'][$key]['posttime']) != $lastmonth) {
            $ar['posts'][$key]['newmonth'] = TRUE;
        }
        $lastmonth = date('Fy', $ar['posts'][$key]['posttime']);
    }
    $bBlog->assign($params['assign'], $ar['posts']);
    return '';
}
Exemple #15
0
/**
 *
 *
 * @param unknown $bBlog (reference)
 */
function admin_plugin_links_run(&$bBlog)
{
    if (isset($_GET['linkdo'])) {
        $linkdo = $_GET['linkdo'];
    } elseif (isset($_POST['linkdo'])) {
        $linkdo = $_POST['linkdo'];
    } else {
        $linkdo = '';
    }
    switch ($linkdo) {
        case "New":
            // add new link
            $maxposition = $bBlog->get_var("select position from " . T_LINKS . " order by position desc limit 0,1");
            $position = $maxposition + 10;
            $bBlog->query("insert into " . T_LINKS . "\n            set nicename='" . my_addslashes($_POST['nicename']) . "',\n            url='" . my_addslashes($_POST['url']) . "',\n            category='" . my_addslashes($_POST['category']) . "',\n\t    position='{$position}'");
            break;
        case "Delete":
            // delete link
            $bBlog->query("delete from " . T_LINKS . " where linkid=" . $_POST['linkid']);
            break;
        case "Save":
            // update an existing link
            $bBlog->query("update " . T_LINKS . "\n            set nicename='" . my_addslashes($_POST['nicename']) . "',\n            url='" . my_addslashes($_POST['url']) . "',\n            category='" . my_addslashes($_POST['category']) . "'\n            where linkid=" . $_POST['linkid']);
            break;
        case "Up":
            $bBlog->query("update " . T_LINKS . " set position=position-15 where linkid=" . $_POST['linkid']);
            reorder_links();
            break;
        case "Down":
            $bBlog->query("update " . T_LINKS . " set position=position+15 where linkid=" . $_POST['linkid']);
            reorder_links();
            break;
        default:
            // show form
            break;
    }
    if (isset($_GET['catdo'])) {
        $catdo = $_GET['catdo'];
    } elseif (isset($_POST['catdo'])) {
        $catdo = $_POST['catdo'];
    } else {
        $catdo = '';
    }
    switch ($catdo) {
        case "New":
            // add new category
            $bBlog->query("insert into " . T_CATEGORIES . "\n            set name='" . my_addslashes($_POST['name']) . "'");
            break;
        case "Delete":
            // delete category
            // have to remove all references to the category in the links
            $bBlog->query("update " . T_LINKS . "\n            set linkid=0 where linkid=" . $_POST['categoryid']);
            // delete the category
            $bBlog->query("delete from " . T_CATEGORIES . " where categoryid=" . $_POST['categoryid']);
            break;
        case "Save":
            // update an existing category
            $bBlog->query("update " . T_CATEGORIES . "\n            set name='" . my_addslashes($_POST['name']) . "'\n            where categoryid=" . $_POST['categoryid']);
            break;
        default:
            // show form
            break;
    }
    $bBlog->assign('ecategories', $bBlog->get_results("select * from " . T_CATEGORIES));
    $bBlog->assign('elinks', $bBlog->get_results("select * from " . T_LINKS . " order by position"));
}
/**
 *
 *
 * @param unknown $params
 * @param unknown $bBlog  (reference)
 */
function smarty_function_nextprev($params, &$bBlog)
{
    // Initialize default values...
    $skip = 0;
    $num = 20;
    $max_pages = 0;
    $pages_before = 0;
    // Set the num parameter
    if (is_numeric($params['num'])) {
        $num = $params['num'];
    }
    // Set the max_pages parameter
    if (is_numeric($params['max_pages'])) {
        $max_pages = $params['max_pages'];
        $pages_before = (int) ($max_pages / 2);
    }
    // Acquire the page skip count; if set, snag it.
    $newSkip = $_GET["pageskip"];
    if ($newSkip) {
        $skip = $newSkip;
    }
    $sectionid = $_GET["sectionid"];
    $QuerySection = '';
    $ExtraParams = '';
    if ($sectionid) {
        $QuerySection .= " AND sections like '%:{$sectionid}:%'";
        $ExtraParams .= "&sectionid={$sectionid}";
    } else {
        // This is for the case of Clean URLS
        $sectionid = $bBlog->get_template_vars("sectionid");
        if ($sectionid) {
            $QuerySection .= " AND sections like '%:{$sectionid}:%'";
        }
    }
    $query_params = $params['query'];
    if ($query_params) {
        $QuerySection .= " AND {$query_params}";
    }
    $link_params = $params['link'];
    if ($link_params) {
        $ExtraParams .= $link_params;
    }
    $posts = $params['posts'];
    // Calculate the new offset
    $offset = $skip * $num;
    $nextoffset = $offset + $num;
    $bBlog->assign("current_offset", $offset);
    // Get number of entries...
    if ($posts) {
        $entryCount = count($posts);
        if ($params['adjust']) {
            $bBlog->assign('posts', array_slice($posts, $offset, $num));
        }
    } else {
        // invariant: Need to query the database and count
        $countArray = $bBlog->get_results("select count(*) as nElements from " . T_POSTS . " where status = 'live' {$QuerySection};");
        if ($bBlog->num_rows <= 0) {
            $entryCount = 0;
        } else {
            foreach ($countArray as $cnt) {
                $entryCount = $cnt->nElements;
            }
        }
    }
    // Create the previous pages...
    $i = 0;
    $current_page = $skip;
    if ($max_pages != 0) {
        $i = $current_page - $pages_before;
        if ($i < 0) {
            $i = 0;
        }
    }
    $bBlog->assign("current_page", $current_page + 1);
    $bBlog->assign("gofirstpage", $i + 1);
    while ($i < $current_page) {
        $cp = $i + 1;
        $prevpages[] = array('page' => $cp, 'url' => $_SERVER["PHP_SELF"] . "?pageskip={$i}{$ExtraParams}");
        ++$i;
    }
    $bBlog->assign("goprevpages", $prevpages);
    // Create the next pages
    $i = $current_page + 1;
    $numberOfPages = (int) ($entryCount / $num);
    $pages = $numberOfPages;
    if ($pages * $num < $entryCount) {
        $pages++;
        $numberOfPages++;
    }
    if ($max_pages != 0) {
        $pages = $i + $pages_before;
        if ($pages > $numberOfPages) {
            $pages = $numberOfPages;
        }
    }
    $bBlog->assign("golastpage", $pages);
    $bBlog->assign("gonum_pages", $numberOfPages);
    while ($i < $pages) {
        $nextpages[] = array('page' => $i + 1, 'url' => $_SERVER["PHP_SELF"] . "?pageskip={$i}{$ExtraParams}");
        ++$i;
    }
    $bBlog->assign("gonextpages", $nextpages);
    // Get the previous count...
    if ($offset == 0) {
        $previous = 0;
        $bBlog->assign("goprev", "");
    } else {
        $previous = $skip - 1;
        $bBlog->assign("goprev", $_SERVER["PHP_SELF"] . "?pageskip={$previous}{$ExtraParams}");
    }
    // Get the next count...
    if ($nextoffset < $entryCount) {
        $next = $skip + 1;
        $bBlog->assign("gonext", $_SERVER["PHP_SELF"] . "?pageskip={$next}{$ExtraParams}");
    } else {
        $next = 0;
        $bBlog->assign("gonext", "");
    }
}
/**
 *
 *
 * @param unknown $params
 * @param unknown $bBlog  (reference)
 * @return unknown
 */
function smarty_function_getarchiveposts($params, &$bBlog)
{
    $ar = array();
    $opt = array();
    // If "assign" is not set... we'll establish a default.
    if ($params['assign'] == '') {
        $params['assign'] = 'posts';
    }
    // If "archive" is set, order them ASCENDING by posttime.
    if ($params['archive']) {
        $opt['order'] = " ORDER BY posttime ";
    }
    if (is_numeric($params['num'])) {
        $opt['num'] = $params['num'];
    }
    if (is_numeric($params['year'])) {
        if (strlen($params['year']) != 4) {
            $bBlog->trigger_error('getarchiveposts: year parameter requires a 4 digit year');
            return '';
        }
        $opt['year'] = $params['year'];
    }
    if (is_numeric($params['month'])) {
        if (strlen($params['month']) != 2) {
            $bBlog->trigger_error('getarchiveposts: month parameter requires a 2 digit month');
            return '';
        }
        $opt['month'] = $params['month'];
    }
    if (is_numeric($params['day'])) {
        if (strlen($params['day']) != 2) {
            $bBlog->trigger_error('getarchiveposts: day parameter requires a 2 digit day');
            return '';
        }
        $opt['day'] = $params['day'];
    }
    if (is_numeric($params['hour'])) {
        if (strlen($params['hour']) != 2) {
            $bBlog->trigger_error('getarchiveposts: hour parameter requires a 2 digit hour');
            return '';
        }
        $opt['hour'] = $params['hour'];
    }
    if (is_numeric($params['minute'])) {
        if (strlen($params['minute']) != 2) {
            $bBlog->trigger_error('getarchiveposts: minute parameter requires a 2 digit minute');
            return '';
        }
        $opt['minute'] = $params['minute'];
    }
    if (is_numeric($params['second'])) {
        if (strlen($params['second']) != 2) {
            $bBlog->trigger_error('getarchiveposts: second parameter requires a 2 digit second');
            return '';
        }
        $opt['second'] = $params['second'];
    }
    if ($params['section'] != '') {
        $opt['sectionid'] = $bBlog->sect_by_name[$params['section']];
    }
    $q = $bBlog->make_post_query($opt);
    $ar['posts'] = $bBlog->get_posts($q);
    // No posts.
    if (!is_array($ar['posts'])) {
        return '';
    }
    $lastmonth = '';
    $lastdate = '';
    foreach ($ar['posts'] as $key => $value) {
        // It seems silly to do this. Especially since,
        // this kind of check can be done in Smarty template.
        // Additionally, since {newday} and {newmonth} require
        // the data to be in a variable named "post" it may not
        // function at all.
        //
        // We'll leave it here for now.
        if (date('Fy', $ar['posts'][$key]['posttime']) != $lastmonth) {
            $ar['posts'][$key]['newmonth'] = 'yes';
        }
        $lastmonth = date('Fy', $ar['posts'][$key]['posttime']);
        if (date('Ymd', $ar['posts'][$key]['posttime']) != $lastdate) {
            $ar['posts'][$key]['newday'] = 'yes';
        }
        $lastdate = date('Ymd', $ar['posts'][$key]['posttime']);
    }
    $bBlog->assign($params['assign'], $ar['posts']);
    return '';
}
/**
 *
 *
 * @param unknown $bBlog (reference)
 */
function populateSelectList(&$bBlog)
{
    $posts_with_comments_q = "SELECT " . T_POSTS . ".postid, " . T_POSTS . ".title, count(*) c FROM " . T_COMMENTS . ",  " . T_POSTS . " \tWHERE " . T_POSTS . ".postid = " . T_COMMENTS . ".postid GROUP BY " . T_POSTS . ".postid ORDER BY " . T_POSTS . ".posttime DESC ";
    // previously function populateSelectList(&$bBlog){
    //  $posts_with_comments_q = "SELECT ".T_POSTS.".postid, ".T_POSTS.".title, count(*) c FROM ".T_COMMENTS.",  ".T_POSTS."  WHERE ".T_POSTS.".postid = ".T_COMMENTS.".postid GROUP BY ".T_POSTS.".postid ORDER BY ".T_POSTS.".posttime DESC  LIMIT 0 , 30 ";
    //removed the LIMIT parameter as it was unnecessary
    $posts_with_comments = $bBlog->get_results($posts_with_comments_q, ARRAY_A);
    $bBlog->assign("postselect", $posts_with_comments);
}
/**
 * Smarty {cycle} function plugin
 *
 * Type:     function<br>
 * Name:     cycle<br>
 * Date:     May 3, 2002<br>
 * Purpose:  cycle through given values<br>
 * Input:
 *         - name = name of cycle (optional)
 *         - values = comma separated list of values to cycle,
 *                    or an array of values to cycle
 *                    (this can be left out for subsequent calls)
 *         - reset = boolean - resets given var to true
 *         - print = boolean - print var or not. default is true
 *         - advance = boolean - whether or not to advance the cycle
 *         - delimiter = the value delimiter, default is ","
 *         - assign = boolean, assigns to template var instead of
 *                    printed.
 *
 * Examples:<br>
 * <pre>
 * {cycle values="#eeeeee,#d0d0d0d"}
 * {cycle name=row values="one,two,three" reset=true}
 * {cycle name=row}
 * </pre>
 *
 * @link http://smarty.php.net/manual/en/language.function.cycle.php {cycle}
 *       (Smarty online manual)
 * @author Monte Ohrt <*****@*****.**>
 * @author credit to Mark Priatel <*****@*****.**>
 * @author credit to Gerard <*****@*****.**>
 * @author credit to Jason Sweat <*****@*****.**>
 * @version  1.3
 * @param array
 * @param Smarty
 * @param unknown $params
 * @param unknown $smarty (reference)
 * @return string|null
 */
function smarty_function_cycle($params, &$smarty)
{
    static $cycle_vars;
    extract($params);
    if (empty($name)) {
        $name = 'default';
    }
    if (!isset($print)) {
        $print = true;
    }
    if (!isset($advance)) {
        $advance = true;
    }
    if (!isset($reset)) {
        $reset = false;
    }
    if (!in_array('values', array_keys($params))) {
        if (!isset($cycle_vars[$name]['values'])) {
            $smarty->trigger_error("cycle: missing 'values' parameter");
            return;
        }
    } else {
        if (isset($cycle_vars[$name]['values']) && $cycle_vars[$name]['values'] != $values) {
            $cycle_vars[$name]['index'] = 0;
        }
        $cycle_vars[$name]['values'] = $values;
    }
    if (isset($delimiter)) {
        $cycle_vars[$name]['delimiter'] = $delimiter;
    } elseif (!isset($cycle_vars[$name]['delimiter'])) {
        $cycle_vars[$name]['delimiter'] = ',';
    }
    if (!is_array($cycle_vars[$name]['values'])) {
        $cycle_array = explode($cycle_vars[$name]['delimiter'], $cycle_vars[$name]['values']);
    } else {
        $cycle_array = $cycle_vars[$name]['values'];
    }
    if (!isset($cycle_vars[$name]['index']) || $reset) {
        $cycle_vars[$name]['index'] = 0;
    }
    if (isset($assign)) {
        $print = false;
        $smarty->assign($assign, $cycle_array[$cycle_vars[$name]['index']]);
    }
    if ($print) {
        $retval = $cycle_array[$cycle_vars[$name]['index']];
    } else {
        $retval = null;
    }
    if ($advance) {
        if ($cycle_vars[$name]['index'] >= count($cycle_array) - 1) {
            $cycle_vars[$name]['index'] = 0;
        } else {
            $cycle_vars[$name]['index']++;
        }
    }
    return $retval;
}
/**
 *
 *
 * @param unknown $params
 * @param unknown $bBlog  (reference)
 * @return unknown
 */
function smarty_function_getrecentposts($params, &$bBlog)
{
    $ar = array();
    $opt = array();
    // If "assign" is not set... we'll establish a default.
    if ($params['assign'] == '') {
        $params['assign'] = 'posts';
    }
    // If "archive" is set, order them ASCENDING by posttime.
    if ($params['archive'] == 'TRUE') {
        $opt['order'] = " ORDER BY posttime ";
    }
    // If num is set, we'll only get that many results in return
    if (is_numeric($params['num'])) {
        $opt['num'] = $params['num'];
    }
    // If skip is set, we'll skip that many results
    if (is_numeric($params['skip'])) {
        $opt['num'] = $params['skip'];
    }
    if ($params['section'] != '') {
        $opt['sectionid'] = $bBlog->sect_by_name[$params['section']];
    }
    if ($bBlog->show_section) {
        $opt['sectionid'] = $bBlog->show_section;
    }
    $opt['home'] = $params['home'];
    $q = $bBlog->make_post_query($opt);
    $ar['posts'] = $bBlog->get_posts($q);
    // No posts.
    if (!is_array($ar['posts'])) {
        return '';
    }
    $lastmonth = 0;
    $lastdate = 0;
    foreach ($ar['posts'] as $key => $value) {
        // It seems silly to do this. Especially since,
        // this kind of check can be done in Smarty template.
        // Additionally, since {newday} and {newmonth} require
        // the data to be in a variable named "post" it may not
        // function at all.
        //
        // We'll leave it here for now.
        /* check if new day  - used by block.newday.php */
        if (date('Ymd', $ar['posts'][$key]['posttime']) != $lastdate) {
            $ar['posts'][$key]['newday'] = TRUE;
        }
        $lastdate = date('Ymd', $ar['posts'][$key]['posttime']);
        /* check if new month - use by block.newmonth.php */
        if (date('Fy', $ar['posts'][$key]['posttime']) != $lastmonth) {
            $ar['posts'][$key]['newmonth'] = TRUE;
        }
        $lastmonth = date('Fy', $ar['posts'][$key]['posttime']);
    }
    $bBlog->assign($params['assign'], $ar['posts']);
    return '';
}
Exemple #21
0
 /**
  * 解析模版变量
  * 
  * @param unknown $key
  * @param unknown $value
  */
 public function assign($key, $value)
 {
     $this->smarty->assign($key, $value);
 }
/**
 *
 *
 * @param unknown $params
 * @param unknown $bBlog  (reference)
 */
function smarty_function_calendar($params, &$bBlog)
{
    $date = getdate();
    $today = $date["mday"];
    $month = $date["mon"];
    $year = $date["year"];
    $new_month = $_GET["month"];
    $new_year = $_GET["year"];
    if ($new_month && $new_year) {
        $date = getdate(mktime(0, 0, 0, $new_month, 1, $new_year));
        $show_month = $date["mon"];
        $show_year = $date["year"];
    } else {
        $show_month = $month;
        $show_year = $year;
    }
    $q = $bBlog->make_post_query(array("where" => " AND month(FROM_UNIXTIME(posttime)) = {$show_month} and year(FROM_UNIXTIME(posttime)) = {$show_year} ", "num" => "999"));
    $dayindex = array();
    global $dayindex;
    $posts = $bBlog->get_posts($q);
    if (is_array($posts)) {
        foreach ($posts as $post) {
            $d = date('j', $post['posttime']);
            $dayindex[$d][] = array("id" => $post['post'], "title" => $post['title'], "url" => $bBlog->_get_entry_permalink($post['postid']));
        }
    }
    $left_year = $right_year = $show_year;
    $left_month = $show_month - 1;
    if ($left_month < 1) {
        $left_month = 12;
        $left_year--;
    }
    $right_month = $show_month + 1;
    if ($right_month > 12) {
        $right_month = 1;
        $right_year++;
    }
    $bBlog->assign("left", $_SERVER["PHP_SELF"] . "?month={$left_month}&year={$left_year}");
    $bBlog->assign("right", $_SERVER["PHP_SELF"] . "?month={$right_month}&year={$right_year}");
    $bBlog->assign("header", strftime("%B %Y", mktime(0, 0, 0, $show_month, 1, $show_year)));
    $first_date = mktime(0, 0, 0, $show_month, 1, $show_year);
    $date = getdate($first_date);
    $first_wday = $date["wday"];
    $last_date = mktime(0, 0, 0, $show_month + 1, 0, $show_year);
    $date = getdate($last_date);
    $last_day = $date["mday"];
    $wday = "";
    // echo($params["locale"]);
    if ($params["locale"]) {
        @setlocale(LC_TIME, $params["locale"]);
    }
    $week_start = $params["week_start"];
    if ($week_start < 0 || $week_start > 6) {
        $week_start = 1;
    }
    for ($counter = $week_start; $counter < $week_start + 7; $counter++) {
        if ($counter > 6) {
            $wday[] = strftime("%a", mktime(0, 0, 0, 3, $counter - 7, 2004));
        } else {
            $wday[] = strftime("%a", mktime(0, 0, 0, 3, $counter, 2004));
        }
    }
    $bBlog->assign("wday", $wday);
    $week_array = "";
    $month_array = "";
    $pre_counter = $first_wday - $week_start;
    if ($pre_counter < 0) {
        $pre_counter += 7;
    }
    $day = 1;
    while (true) {
        $week_array = "";
        for ($counter = 0; $counter < 7; $counter++) {
            if ($day > $last_day) {
                $week_array[] = array(0 => false, 1 => "&nbsp;", 2 => false);
            } else {
                if ($pre_counter > 0) {
                    $week_array[] = array(0 => false, 1 => "&nbsp;", 2 => false);
                    $pre_counter--;
                } else {
                    getDateLink($day, &$values);
                    $week_array[] = array(0 => $dayindex["{$day}"] ? true : false, 1 => $day, 2 => $day == $today && $month == $show_month && $year == $show_year ? true : false);
                    $day++;
                }
            }
        }
        $month_array[] = $week_array;
        if ($day > $last_day) {
            break;
        }
    }
    $bBlog->assign("month", $month_array);
    $bBlog->assign("values", $values);
    $bBlog->display("calendar.html", FALSE);
}
Exemple #23
0
 /**
  * 添加模板变量
  * @param unknown $key
  * @param unknown $val
  * @return Smarty_Internal_Data
  */
 function assign($key, $val)
 {
     return $this->_smarty->assign($key, $val);
 }
/**
 *
 *
 * @param unknown $bBlog (reference)
 */
function admin_plugin_sections_run(&$bBlog)
{
    // Again, the plugin API needs work.
    if (isset($_GET['sectdo'])) {
        $sectdo = $_GET['sectdo'];
    } elseif (isset($_POST['sectdo'])) {
        $sectdo = $_POST['sectdo'];
    } else {
        $sectdo = '';
    }
    switch ($sectdo) {
        case 'new':
            // sections are being editied
            $bBlog->query("insert into " . T_SECTIONS . "\n\t\t\tset nicename='" . my_addslashes($_POST['nicename']) . "',\n\t\t\tname='" . my_addslashes($_POST['urlname']) . "'");
            $insid = $bBlog->insert_id;
            $bBlog->get_sections();
            // update the section cache
            break;
        case "Delete":
            // delete section
            // have to remove all references to the section in the posts
            $sect_id = $bBlog->sect_by_name[$_POST['sname']];
            if ($sect_id > 0) {
                //
                $posts_in_section_q = $bBlog->make_post_query(array("sectionid" => $sect_id));
                $posts_in_section = $bBlog->get_posts($posts_in_section_q, TRUE);
                if ($posts_in_section) {
                    foreach ($posts_in_section as $post) {
                        unset($tmpr);
                        $tmpr = array();
                        $tmpsections = explode(":", $post->sections);
                        foreach ($tmpsections as $tmpsection) {
                            if ($tmpsection != $sect_id) {
                                $tmpr[] = $tmpsection;
                            }
                        }
                        $newsects = implode(":", $tmpr);
                        // update the posts to remove the section
                        $bBlog->query("update " . T_POSTS . " set sections='{$newsects}'\n                                \twhere postid='{$post->postid}'");
                    }
                    // end foreach ($post_in_section as $post)
                }
                // end if($posts_in_section)
                // delete the section
                //$bBlog->get_results("delete from ".T_SECTIONS." where sectionid='$sect_id'");
                $bBlog->query("delete from " . T_SECTIONS . " where sectionid='{$sect_id}'");
                //echo "delete from ".T_SECTIONS." where sectionid='$sect_id'";
                $bBlog->get_sections();
                //$bBlog->debugging=TRUE;
            }
            // else show error
        // else show error
        case "Save":
            $sect_id = $bBlog->sect_by_name[$_POST['sname']];
            if ($sect_id < 1) {
                break;
            }
            $bBlog->query("update " . T_SECTIONS . " set nicename='" . my_addslashes($_POST['nicename']) . "'\n                        where sectionid='{$sect_id}'");
            $bBlog->get_sections();
            // update section cache
            break;
        default:
            // show form
            break;
    }
    $bBlog->assign('esections', $bBlog->sections);
}