当前位置: 首页>>代码示例>>PHP>>正文


PHP Element函数代码示例

本文整理汇总了PHP中Element函数的典型用法代码示例。如果您正苦于以下问题:PHP Element函数的具体用法?PHP Element怎么用?PHP Element使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Element函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ukko_install

 function ukko_install($settings)
 {
     if (!file_exists($settings['uri'])) {
         @mkdir($settings['uri'], 0777) or error("Couldn't create " . $settings['uri'] . ". Check permissions.", true);
     }
     file_write($settings['uri'] . '/ukko.js', Element('themes/ukko/ukko.js', array()));
 }
开发者ID:odilitime,项目名称:vichan,代码行数:7,代码来源:info.php

示例2: build

 public function build($settings, $board_name)
 {
     global $config, $board;
     openBoard($board_name);
     $recent_images = array();
     $recent_posts = array();
     $stats = array();
     $query = query(sprintf("SELECT *, `id` AS `thread_id`,\n\t\t\t\t(SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`,\n\t\t\t\t(SELECT SUM(`num_files`) FROM ``posts_%s`` WHERE `thread` = `thread_id` AND `num_files` IS NOT NULL) AS `image_count`,\n\t\t\t\t'%s' AS `board` FROM ``posts_%s`` WHERE `thread`  IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name, $board_name, $board_name)) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $post['id']);
         $post['board_name'] = $board['name'];
         if ($post['embed'] && preg_match('/^https?:\\/\\/(\\w+\\.)?(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/)([a-zA-Z0-9\\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) {
             $post['youtube'] = $matches[2];
         }
         if (isset($post['files'])) {
             $files = json_decode($post['files']);
             if ($files[0]->file == 'deleted') {
                 continue;
             }
             $post['file'] = $config['uri_thumb'] . $files[0]->thumb;
         }
         $recent_posts[] = $post;
     }
     $required_scripts = array('js/jquery.min.js', 'js/jquery.mixitup.min.js', 'js/catalog.js');
     foreach ($required_scripts as $i => $s) {
         if (!in_array($s, $config['additional_javascript'])) {
             $config['additional_javascript'][] = $s;
         }
     }
     file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, 'stats' => $stats, 'board' => $board_name, 'link' => $config['root'] . $board['dir'])));
 }
开发者ID:vicentil,项目名称:vichan,代码行数:31,代码来源:theme.php

示例3: sitemap_build

function sitemap_build($action, $settings, $board)
{
    global $config;
    // Possible values for $action:
    //	- all (rebuild everything, initialization)
    //	- news (news has been updated)
    //	- boards (board list changed)
    //	- post (a post has been made)
    //	- thread (a thread has been made)
    if ($action != 'post-thread' && $action != 'post-delete') {
        return;
    }
    if ($settings['regen_time'] > 0) {
        if ($last_gen = @filemtime($settings['path'])) {
            if (time() - $last_gen < (int) $settings['regen_time']) {
                return;
            }
            // Too soon
        }
    }
    $boards = explode(' ', $settings['boards']);
    $threads = array();
    foreach ($boards as $board) {
        $query = query(sprintf("SELECT `id` AS `thread_id`, (SELECT `time` FROM ``posts_%s`` WHERE `thread` = `thread_id` OR `id` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `lastmod` FROM ``posts_%s`` WHERE `thread` IS NULL", $board, $board)) or error(db_error());
        $threads[$board] = $query->fetchAll(PDO::FETCH_ASSOC);
    }
    file_write($settings['path'], Element('themes/sitemap/sitemap.xml', array('settings' => $settings, 'config' => $config, 'threads' => $threads, 'boards' => $boards)));
}
开发者ID:2Rainbow,项目名称:fukuro,代码行数:28,代码来源:theme.php

示例4: homepage

 public static function homepage($settings)
 {
     global $config;
     $settings['no_recent'] = (int) $settings['no_recent'];
     $query = query("SELECT * FROM `news` ORDER BY `time` DESC" . ($settings['no_recent'] ? ' LIMIT ' . $settings['no_recent'] : '')) or error(db_error());
     $news = $query->fetchAll(PDO::FETCH_ASSOC);
     return Element('themes/basic/index.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'news' => $news));
 }
开发者ID:npfriday,项目名称:Tinyboard,代码行数:8,代码来源:theme.php

示例5: sidebar

 public static function sidebar($settings)
 {
     global $config, $board;
     $categories = $config['categories'];
     foreach ($categories as &$boards) {
         foreach ($boards as &$board) {
             $title = boardTitle($board);
             if (!$title) {
                 $title = $board;
             }
             // board doesn't exist, but for some reason you want to display it anyway
             $board = array('title' => $title, 'uri' => sprintf($config['board_path'], $board));
         }
     }
     return Element('themes/categories/sidebar.html', array('settings' => $settings, 'config' => $config, 'categories' => $categories));
 }
开发者ID:npfriday,项目名称:Tinyboard,代码行数:16,代码来源:theme.php

示例6: build

 public function build($settings, $board_name)
 {
     global $config, $board;
     openBoard($board_name);
     $recent_images = array();
     $recent_posts = array();
     $stats = array();
     $query = query(sprintf("SELECT *, `id` AS `thread_id`, (SELECT COUNT(*) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name)) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $post['id']);
         $post['board_name'] = $board['name'];
         $post['file'] = $config['uri_thumb'] . $post['thumb'];
         $recent_posts[] = $post;
     }
     file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, 'stats' => $stats, 'board' => $board_name, 'link' => $config['root'] . $board['dir'])));
 }
开发者ID:carriercomm,项目名称:Tinyboard,代码行数:16,代码来源:theme.php

示例7: build

 public function build($settings, $board_name)
 {
     global $config, $board;
     openBoard($board_name);
     $recent_images = array();
     $recent_posts = array();
     $stats = array();
     $query = query(sprintf("SELECT *, `id` AS `thread_id`, (SELECT COUNT(*) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name)) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $post['id']);
         $post['board_name'] = $board['name'];
         $post['file'] = $config['uri_thumb'] . $post['thumb'];
         if ($post['embed'] && preg_match('/^https?:\\/\\/(\\w+\\.)?(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/)([a-zA-Z0-9\\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) {
             $post['youtube'] = $matches[2];
         }
         $recent_posts[] = $post;
     }
     file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, 'stats' => $stats, 'board' => $board_name, 'link' => $config['root'] . $board['dir'])));
 }
开发者ID:2Rainbow,项目名称:fukuro,代码行数:19,代码来源:theme.php

示例8: build

 public function build($index = false)
 {
     global $board, $config, $debug;
     $built = Element('post_thread.html', array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index));
     if (!$this->mod && $index && $config['cache']['enabled']) {
         cache::set($this->cache_key($index), $built);
     }
     return $built;
 }
开发者ID:npfriday,项目名称:Tinyboard,代码行数:9,代码来源:display.php

示例9: prepare

    $query = prepare('INSERT INTO ``mods`` VALUES (NULL, :username, :password, :salt, :type, :boards, :email)');
    $query->bindValue(':username', $username);
    $query->bindValue(':password', $password);
    $query->bindValue(':salt', $salt);
    $query->bindValue(':type', 20);
    $query->bindValue(':boards', $uri);
    $query->bindValue(':email', $email);
    $query->execute() or error(db_error($query));
    $query = prepare('INSERT INTO ``boards`` (`uri`, `title`, `subtitle`) VALUES (:uri, :title, :subtitle)');
    $query->bindValue(':uri', $_POST['uri']);
    $query->bindValue(':title', $_POST['title']);
    $query->bindValue(':subtitle', $_POST['subtitle']);
    $query->execute() or error(db_error($query));
    $query = Element('posts.sql', array('board' => $uri));
    query($query) or error(db_error());
    if (!openBoard($_POST['uri'])) {
        error(_("Couldn't open board after creation."));
    }
    if ($config['cache']['enabled']) {
        cache::delete('all_boards');
    }
    // Build the board
    buildIndex();
    rebuildThemes('boards');
    $query = prepare("INSERT INTO ``board_create``(uri) VALUES(:uri)");
    $query->bindValue(':uri', $uri);
    $query->execute() or error(db_error());
    _syslog(LOG_NOTICE, "New board: {$uri}");
    $body = Element("8chan/create_success.html", array("config" => $config, "password" => $_POST['password'], "uri" => $uri));
    echo Element("page.html", array("config" => $config, "body" => $body, "title" => _("Success"), "subtitle" => _("This was a triumph")));
}
开发者ID:odilitime,项目名称:infinity,代码行数:31,代码来源:create.php

示例10: homepage

 public function homepage($settings)
 {
     global $config, $board;
     $recent_images = array();
     $recent_posts = array();
     $stats = array();
     $boards = listBoards();
     $query = '';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `files` IS NOT NULL UNION ALL ", $_board['uri'], $_board['uri']);
     }
     $query = '';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` UNION ALL ", $_board['uri'], $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int) $settings['limit_posts'], $query);
     $query = query($query) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         openBoard($post['board']);
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post) . '#' . $post['id'];
         if ($post['body'] != "") {
             $post['snippet'] = pm_snippet($post['body'], 128);
         } else {
             $post['snippet'] = "<em>" . _("(no comment)") . "</em>";
         }
         $post['board_name'] = $board['name'];
         $recent_posts[] = $post;
     }
     // Total posts
     $query = 'SELECT SUM(`top`) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT MAX(`id`) AS `top` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $stats['total_posts'] = number_format($query->fetchColumn());
     // Unique IPs
     $query = 'SELECT COUNT(DISTINCT(`ip`)) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT `ip` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $stats['unique_posters'] = number_format($query->fetchColumn());
     // Active content
     $query = 'SELECT DISTINCT(`files`) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT `files` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ' WHERE `num_files` > 0) AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $files = $query->fetchAll();
     $stats['active_content'] = 0;
     foreach ($files as &$file) {
         preg_match_all('/"size":([0-9]*)/', $file[0], $matches);
         $stats['active_content'] += array_sum($matches[1]);
     }
     return Element('themes/recent_textonly/recent_textonly.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_posts' => $recent_posts, 'stats' => $stats));
 }
开发者ID:remiscarlet,项目名称:kcad,代码行数:74,代码来源:theme.php

示例11: str_replace

    $like = str_replace('%', '%%', $like);
    $query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE " . $like . " ORDER BY `time` DESC LIMIT :limit", $board['uri']));
    $query->bindValue(':limit', $search_limit, PDO::PARAM_INT);
    $query->execute() or error(db_error($query));
    if ($query->rowCount() == $search_limit) {
        _syslog(LOG_WARNING, 'Query too broad.');
        $body .= '<p class="unimportant" style="text-align:center">(' . _('Query too broad.') . ')</p>';
        echo Element('page.html', array('config' => $config, 'title' => 'Search', 'body' => $body));
        exit;
    }
    $temp = '';
    while ($post = $query->fetch()) {
        if (!$post['thread']) {
            $po = new Thread($post);
        } else {
            $po = new Post($post);
        }
        $temp .= $po->build(true) . '<hr/>';
    }
    if (!empty($temp)) {
        $_body .= '<fieldset><legend>' . sprintf(ngettext('%d result in', '%d results in', $query->rowCount()), $query->rowCount()) . ' <a href="/' . sprintf($config['board_path'], $board['uri']) . $config['file_index'] . '">' . sprintf($config['board_abbreviation'], $board['uri']) . ' - ' . $board['title'] . '</a></legend>' . $temp . '</fieldset>';
    }
    $body .= '<hr/>';
    if (!empty($_body)) {
        $body .= $_body;
    } else {
        $body .= '<p style="text-align:center" class="unimportant">(' . _('No results.') . ')</p>';
    }
}
echo Element('page.html', array('config' => $config, 'title' => _('Search'), 'body' => '' . $body));
开发者ID:0151n,项目名称:vichan,代码行数:30,代码来源:search.php

示例12: mod_edit_page

function mod_edit_page($id)
{
    global $config, $mod, $board;
    $query = prepare('SELECT * FROM ``pages`` WHERE `id` = :id');
    $query->bindValue(':id', $id);
    $query->execute() or error(db_error($query));
    $page = $query->fetch();
    if (!$page) {
        error(_('Could not find the page you are trying to edit.'));
    }
    if (!$page['board'] && $mod['boards'][0] !== '*') {
        error($config['error']['noaccess']);
    }
    if (!hasPermission($config['mod']['edit_pages'], $page['board'])) {
        error($config['error']['noaccess']);
    }
    if ($page['board'] && !openBoard($page['board'])) {
        error($config['error']['noboard']);
    }
    if (isset($_POST['method'], $_POST['content'])) {
        $content = $_POST['content'];
        $method = $_POST['method'];
        $page['type'] = $method;
        if (!in_array($method, array('markdown', 'html', 'infinity'))) {
            error(_('Unrecognized page markup method.'));
        }
        switch ($method) {
            case 'markdown':
                $write = purify_html(markdown($content));
                break;
            case 'html':
                if (hasPermission($config['mod']['rawhtml'])) {
                    $write = $content;
                } else {
                    $write = purify_html($content);
                }
                break;
            case 'infinity':
                $c = $content;
                markup($content);
                $write = $content;
                $content = $c;
        }
        if (!isset($write) or !$write) {
            error(_('Failed to mark up your input for some reason...'));
        }
        $query = prepare('UPDATE ``pages`` SET `type` = :method, `content` = :content WHERE `id` = :id');
        $query->bindValue(':method', $method);
        $query->bindValue(':content', $content);
        $query->bindValue(':id', $id);
        $query->execute() or error(db_error($query));
        $fn = ($board['uri'] ? $board['uri'] . '/' : '') . $page['name'] . '.html';
        $body = "<div class='ban'>{$write}</div>";
        $html = Element('page.html', array('config' => $config, 'body' => $body, 'title' => utf8tohtml($page['title'])));
        file_write($fn, $html);
        modLog("Edited page {$page['name']} <span class='unimportant'>(#{$page['id']})</span>");
    }
    if (!isset($content)) {
        $query = prepare('SELECT `content` FROM ``pages`` WHERE `id` = :id');
        $query->bindValue(':id', $id);
        $query->execute() or error(db_error($query));
        $content = $query->fetchColumn();
    }
    mod_page(sprintf(_('Editing static page: %s'), $page['name']), 'mod/edit_page.html', array('page' => $page, 'token' => make_secure_link_token("edit_page/{$id}"), 'content' => prettify_textarea($content), 'board' => $board));
}
开发者ID:ringtech,项目名称:infinity,代码行数:65,代码来源:pages.php

示例13: saveForBoard

 private function saveForBoard($board_name, $recent_posts, $board_link = null)
 {
     global $board, $config;
     if ($board_link === null) {
         $board_link = $config['root'] . $board['dir'];
     }
     $required_scripts = array('js/jquery.min.js', 'js/jquery.mixitup.min.js', 'js/catalog.js');
     // Include scripts that haven't been yet included
     foreach ($required_scripts as $i => $s) {
         if (!in_array($s, $config['additional_javascript'])) {
             $config['additional_javascript'][] = $s;
         }
     }
     file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', array('settings' => $this->settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => array(), 'recent_posts' => $recent_posts, 'stats' => array(), 'board' => $board_name, 'link' => $board_link)));
 }
开发者ID:anastiel,项目名称:lainchan,代码行数:15,代码来源:theme.php

示例14: mod_config


//.........这里部分代码省略.........
    if ($config['mod']['config_editor_php']) {
        $readonly = !(is_file($config_file) ? is_writable($config_file) : is_writable(dirname($config_file)));
        if (!$readonly && isset($_POST['code'])) {
            $code = $_POST['code'];
            // Save previous instance_config if php_check_syntax fails
            $old_code = file_get_contents($config_file);
            file_put_contents($config_file, $code);
            $resp = shell_exec_error('php -l ' . $config_file);
            if (preg_match('/No syntax errors detected/', $resp)) {
                header('Location: ?/config' . ($board_config ? '/' . $board_config : ''), true, $config['redirect_http']);
                return;
            } else {
                file_put_contents($config_file, $old_code);
                error($config['error']['badsyntax'] . $resp);
            }
        }
        $instance_config = @file_get_contents($config_file);
        if ($instance_config === false) {
            $instance_config = "<?php\n\n// This file does not exist yet. You are creating it.";
        }
        $instance_config = str_replace("\n", '&#010;', utf8tohtml($instance_config));
        mod_page(_('Config editor'), 'mod/config-editor-php.html', array('php' => $instance_config, 'readonly' => $readonly, 'boards' => listBoards(), 'board' => $board_config, 'file' => $config_file, 'token' => make_secure_link_token('config' . ($board_config ? '/' . $board_config : ''))));
        return;
    }
    require_once 'inc/mod/config-editor.php';
    $conf = config_vars();
    foreach ($conf as &$var) {
        if (is_array($var['name'])) {
            $c =& $config;
            foreach ($var['name'] as $n) {
                $c =& $c[$n];
            }
        } else {
            $c = @$config[$var['name']];
        }
        $var['value'] = $c;
    }
    unset($var);
    if (isset($_POST['save'])) {
        $config_append = '';
        foreach ($conf as $var) {
            $field_name = 'cf_' . (is_array($var['name']) ? implode('/', $var['name']) : $var['name']);
            if ($var['type'] == 'boolean') {
                $value = isset($_POST[$field_name]);
            } elseif (isset($_POST[$field_name])) {
                $value = $_POST[$field_name];
            } else {
                continue;
            }
            // ???
            if (!settype($value, $var['type'])) {
                continue;
            }
            // invalid
            if ($value != $var['value']) {
                // This value has been changed.
                $config_append .= '$config';
                if (is_array($var['name'])) {
                    foreach ($var['name'] as $name) {
                        $config_append .= '[' . var_export($name, true) . ']';
                    }
                } else {
                    $config_append .= '[' . var_export($var['name'], true) . ']';
                }
                $config_append .= ' = ';
                if (@$var['permissions'] && isset($config['mod']['groups'][$value])) {
                    $config_append .= $config['mod']['groups'][$value];
                } else {
                    $config_append .= var_export($value, true);
                }
                $config_append .= ";\n";
            }
        }
        if (!empty($config_append)) {
            $config_append = "\n// Changes made via web editor by \"" . $mod['username'] . "\" @ " . date('r') . ":\n" . $config_append . "\n";
            if (!is_file($config_file)) {
                $config_append = "<?php\n\n{$config_append}";
            }
            if (!@file_put_contents($config_file, $config_append, FILE_APPEND)) {
                $config_append = htmlentities($config_append);
                if ($config['minify_html']) {
                    $config_append = str_replace("\n", '&#010;', $config_append);
                }
                $page = array();
                $page['title'] = 'Cannot write to file!';
                $page['config'] = $config;
                $page['body'] = '
					<p style="text-align:center">Tinyboard could not write to <strong>' . $config_file . '</strong> with the ammended configuration, probably due to a permissions error.</p>
					<p style="text-align:center">You may proceed with these changes manually by copying and pasting the following code to the end of <strong>' . $config_file . '</strong>:</p>
					<textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" readonly>' . $config_append . '</textarea>
				';
                echo Element('page.html', $page);
                exit;
            }
        }
        header('Location: ?/config' . ($board_config ? '/' . $board_config : ''), true, $config['redirect_http']);
        exit;
    }
    mod_page(_('Config editor') . ($board_config ? ': ' . sprintf($config['board_abbreviation'], $board_config) : ''), 'mod/config-editor.html', array('boards' => listBoards(), 'board' => $board_config, 'conf' => $conf, 'file' => $config_file, 'token' => make_secure_link_token('config' . ($board_config ? '/' . $board_config : ''))));
}
开发者ID:vicentil,项目名称:vichan,代码行数:101,代码来源:pages.php

示例15: homepage

 public function homepage($settings)
 {
     global $config, $board;
     $recent_images = array();
     $recent_posts = array();
     $stats = array();
     $boards = listBoards();
     $query = '';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `files` IS NOT NULL UNION ALL ", $_board['uri'], $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int) $settings['limit_images'], $query);
     if ($query == '') {
         error(_("Can't build the RecentPosts theme, because there are no boards to be fetched."));
     }
     $query = query($query) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         openBoard($post['board']);
         if (isset($post['files'])) {
             $files = json_decode($post['files']);
         }
         if ($files[0]->file == 'deleted') {
             continue;
         }
         // board settings won't be available in the template file, so generate links now
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post) . '#' . $post['id'];
         if ($files) {
             if ($files[0]->thumb == 'spoiler') {
                 $tn_size = @getimagesize($config['spoiler_image']);
                 $post['src'] = $config['spoiler_image'];
                 $post['thumbwidth'] = $tn_size[0];
                 $post['thumbheight'] = $tn_size[1];
             } else {
                 $post['src'] = $config['uri_thumb'] . $files[0]->thumb;
             }
         }
         $recent_images[] = $post;
     }
     $query = '';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` UNION ALL ", $_board['uri'], $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int) $settings['limit_posts'], $query);
     $query = query($query) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         openBoard($post['board']);
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post) . '#' . $post['id'];
         if ($post['body'] != "") {
             $post['snippet'] = pm_snippet($post['body'], 30);
         } else {
             $post['snippet'] = "<em>" . _("(no comment)") . "</em>";
         }
         $post['board_name'] = $board['name'];
         $recent_posts[] = $post;
     }
     // Total posts
     $query = 'SELECT SUM(`top`) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT MAX(`id`) AS `top` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $stats['total_posts'] = number_format($query->fetchColumn());
     // Unique IPs
     $query = 'SELECT COUNT(DISTINCT(`ip`)) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT `ip` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $stats['unique_posters'] = number_format($query->fetchColumn());
     // Active content
     $query = 'SELECT DISTINCT(`files`) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT `files` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ' WHERE `num_files` > 0) AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $files = $query->fetchAll();
     $stats['active_content'] = 0;
     foreach ($files as &$file) {
         preg_match_all('/"size":([0-9]*)/', $file[0], $matches);
         $stats['active_content'] += array_sum($matches[1]);
     }
     return Element('themes/recent/recent.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, 'stats' => $stats));
//.........这里部分代码省略.........
开发者ID:0151n,项目名称:vichan,代码行数:101,代码来源:theme.php


注:本文中的Element函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。