Ejemplo n.º 1
0
function smarty_modifier_dirify($text, $attr = '1')
{
    if ($attr == "0") {
        return $text;
    }
    require_once "MTUtil.php";
    return dirify($text, $attr);
}
function smarty_function_mtinclude($args, &$ctx)
{
    // status: partial
    // parameters: module, file
    // notes: file case needs work -- search through blog site archive path, etc...
    // push to ctx->vars
    $ext_args = array();
    while (list($key, $val) = each($args)) {
        if (!preg_match('/(^file$|^module$|^widget$|^blog_id$|^identifier$|^type$)/', $key)) {
            require_once "function.mtsetvar.php";
            smarty_function_mtsetvar(array('name' => $key, 'value' => $val), $ctx);
            $ext_args[] = $key;
        }
    }
    $blog_id = $args['blog_id'];
    $blog_id or $blog_id = $ctx->stash('blog_id');
    if ($args['local']) {
        $blog_id = $ctx->stash('local_blog_id');
    }
    $blog = $ctx->mt->db()->fetch_blog($blog_id);
    // When the module name starts by 'Widget', it converts to 'Widget' from 'Module'.
    if (isset($args['module']) && $args['module']) {
        $module = $args['module'];
        if (preg_match('/^Widget:/', $module)) {
            $args['widget'] = preg_replace('/^Widget: ?/', '', $module);
            unset($args['module']);
        }
    }
    // Fetch template meta data
    $load_type = null;
    $load_name = null;
    if (isset($args['module'])) {
        $load_type = 'custom';
        $load_name = $args['module'];
    } elseif (isset($args['widget'])) {
        $load_type = 'widget';
        $load_name = $args['widget'];
    } elseif (isset($args['identifier'])) {
        $load_type = 'identifier';
        $load_name = $args['identifier'];
    }
    $tmpl_meta = null;
    if (!empty($load_type)) {
        $is_global = isset($args['global']) && $args['global'] ? 1 : 0;
        if (isset($args['parent']) && $args['parent']) {
            if (isset($args['global']) && $args['global']) {
                return $ctx->error($ctx->mt->translate("'parent' modifier cannot be used with '[_1]'", 'global'));
            }
            if (isset($args['local']) && $args['local']) {
                return $ctx->error($ctx->mt->translate("'parent' modifier cannot be used with '[_1]'", 'global'));
            }
            $local_blog = $ctx->mt->db()->fetch_blog($ctx->stash('local_blog_id'));
            if ($local_blog->is_blog()) {
                $website = $local_blog->website();
                $blog_id = $website->id;
            } else {
                $blog_id = $local_blog->id;
            }
        }
        $tmpl_meta = $ctx->mt->db()->fetch_template_meta($load_type, $load_name, $blog_id, $is_global);
    }
    # Convert to phrase of PHP Include
    require_once 'MTUtil.php';
    $ssi_enable = false;
    $include_file = '';
    if (!empty($load_type) && isset($blog) && $blog->blog_include_system == 'php' && (isset($args['ssi']) && $args['ssi'] || $tmpl_meta->include_with_ssi)) {
        $ssi_enable = true;
        // Generates include path using Key
        $base_path = '';
        if (isset($args['key'])) {
            $base_path = $args['key'];
        } elseif (isset($args['cache_key'])) {
            $base_path or $base_path = $args['cache_key'];
        }
        $include_path_array = _include_path($base_path);
        $filename = dirify($tmpl_meta->template_name);
        $filename or $filename = 'template_' . $tmpl_meta->template_id;
        $filename .= '.' . $blog->blog_file_extension;
        $include_path = $blog->site_path();
        if (substr($include_path, strlen($include_path) - 1, 1) != DIRECTORY_SEPARATOR) {
            $include_path .= DIRECTORY_SEPARATOR;
        }
        foreach ($include_path_array as $p) {
            $include_path .= $p . DIRECTORY_SEPARATOR;
        }
        $include_file = $include_path . $filename;
    }
    # Try to read from cache
    $cache_enable = false;
    $cache_id = '';
    $cache_key = '';
    $cache_ttl = 0;
    $cache_expire_type = $tmpl_meta->cache_expire_type;
    if (!empty($load_type) && isset($blog) && $blog->blog_include_cache == 1 && ($cache_expire_type == '1' || $cache_expire_type == '2') || (isset($args['cache']) && $args['cache'] == '1' || isset($args['key']) || isset($args['cache_key']) || isset($args['ttl']))) {
        $cache_blog_id = isset($args['global']) && $args['global'] == 1 ? 0 : $blog_id;
        $mt = MT::get_instance();
        $cache_enable = true;
        $cache_key = isset($args['key']) ? $args['key'] : (isset($args['cache_key']) ? $args['cache_key'] : md5('blog::' . $cache_blog_id . '::template_' . $load_type . '::' . $load_name));
        if (isset($args['ttl'])) {
            $cache_ttl = $args['ttl'];
        } elseif (isset($cache_expire_type) && $cache_expire_type == '1') {
            $cache_ttl = $tmpl_meta->cache_expire_interval;
        } else {
            $cache_ttl = 60 * 60;
        }
        # default 60 min.
        if (isset($cache_expire_type) && $cache_expire_type == '2') {
            $expire_types = preg_split('/,/', $tmpl_meta->cache_expire_event, -1, PREG_SPLIT_NO_EMPTY);
            if (!empty($expire_types)) {
                $latest = $ctx->mt->db()->get_latest_touch($blog_id, $expire_types);
                if ($latest) {
                    $latest_touch = $latest->modified_on;
                    if ($ssi_enable) {
                        $file_stat = stat($include_file);
                        if ($file_stat) {
                            $file_stamp = gmdate("Y-m-d H:i:s", $file_stat[9]);
                            if (datetime_to_timestamp($latest_touch) > datetime_to_timestamp($file_stamp)) {
                                $cache_ttl = 1;
                            }
                        }
                    } else {
                        $cache_ttl = time() - datetime_to_timestamp($latest_touch, 'gmt');
                    }
                }
            }
        }
        $elapsed_time = time() - offset_time(datetime_to_timestamp($tmpl_meta->template_modified_on, 'gmt'), $blog, '-');
        if ($cache_ttl == 0 || $elapsed_time < $cache_ttl) {
            $cache_ttl = $elapsed_time;
        }
        $cache_driver = $mt->cache_driver($cache_ttl);
        $cached_val = $cache_driver->get($cache_key, $cache_ttl);
        if (!empty($cached_val)) {
            _clear_vars($ctx, $ext_args);
            if ($ssi_enable) {
                if (file_exists($include_file) && is_readable($include_file)) {
                    $content = file_get_contents($include_file);
                    if ($content) {
                        return $content;
                    }
                }
            } else {
                return $cached_val;
            }
        }
    }
    if ($ssi_enable && !$cache_enable) {
        if (file_exists($include_file) && is_readable($include_file)) {
            $content = file_get_contents($include_file);
            if ($content) {
                return $content;
            }
        }
    }
    # Compile template
    static $_include_cache = array();
    $_var_compiled = '';
    if (!empty($load_type)) {
        $cache_blog_id = isset($args['global']) && $args['global'] == 1 ? 0 : $blog_id;
        $cache_id = $load_type . '::' . $cache_blog_id . '::' . $load_name;
        if (isset($_include_cache[$cache_id])) {
            $_var_compiled = $_include_cache[$cache_id];
        } else {
            $tmpl = $ctx->mt->db()->get_template_text($ctx, $load_name, $blog_id, $load_type, $args['global']);
            if (!$ctx->_compile_source('evaluated template', $tmpl, $_var_compiled)) {
                _clear_vars($ctx, $ext_args);
                return $ctx->error("Error compiling template module '{$module}'");
            }
            $_include_cache[$cache_id] = $_var_compiled;
        }
    } elseif (isset($args['file']) && $args['file']) {
        $mt = MT::get_instance();
        if (!$mt->config('AllowFileInclude')) {
            return $ctx->error('File include is disabled by "AllowFileInclude" config directive.');
        }
        $file = $args['file'];
        $cache_id = 'file::' . $blog_id . '::' . $file;
        if (isset($_include_cache[$cache_id])) {
            $_var_compiled = $_include_cache[$cache_id];
        } else {
            $tmpl = _get_template_from_file($ctx, $file, $blog_id);
            if (!$ctx->_compile_source('evaluated template', $tmpl, $_var_compiled)) {
                _clear_vars($ctx, $ext_args);
                return $ctx->error("Error compiling template file '{$file}'");
            }
            $_include_cache[$cache_id] = $_var_compiled;
        }
    } elseif (isset($args['type']) && $args['type']) {
        $type = $args['type'];
        $cache_id = 'type::' . $blog_id . '::' . $type;
        if (isset($_include_cache[$cache_id])) {
            $_var_compiled = $_include_cache[$cache_id];
        } else {
            $tmpl = $ctx->mt->db()->load_special_template($ctx, null, $type, $blog_id);
            if ($tmpl) {
                if ($ctx->_compile_source('evaluated template', $tmpl->template_text, $_var_compiled)) {
                    $_include_cache[$cache_id] = $_var_compiled;
                } else {
                    if ($type != 'dynamic_error') {
                        _clear_vars($ctx, $ext_args);
                        return $ctx->error("Error compiling template module '{$module}'");
                    } else {
                        _clear_vars($ctx, $ext_args);
                        return null;
                    }
                }
            } else {
                _clear_vars($ctx, $ext_args);
                return null;
            }
        }
    }
    ob_start();
    $ctx->_eval('?>' . $_var_compiled);
    $_contents = ob_get_contents();
    ob_end_clean();
    _clear_vars($ctx, $ext_args);
    if ($cache_enable) {
        $cache_driver = $mt->cache_driver($cache_ttl);
        $cache_driver->set($cache_key, $_contents, $cache_ttl);
    }
    if ($ssi_enable) {
        $include_dir = dirname($include_file);
        if (!file_exists($include_dir) && !is_dir($include_dir)) {
            mkpath($include_dir, 0777);
        }
        if (is_writable($include_dir)) {
            if ($h_file = fopen($include_file, 'w')) {
                fwrite($h_file, $_contents);
                fclose($h_file);
            }
        }
    }
    return $_contents;
}
Ejemplo n.º 3
0
					</div>
				</div>
				<div id="content">
<div class="entry" style="padding-bottom: 250px;">
<?php 
    print '<h1>Resultat af søgning</h1>';
    print '<p>Du søgte efter <span style="color: #900; font-weight: bold">\'' . urldecode($q) . '\'</span>, og der blev fundet <b>' . $numrows . '</b> indlæg der matchede din søgning.</p><p>Resultaterne er sorteret efter relevans. Hvis søgeordet forekommer indenfor de første 200 bogstaver i indlægget er det fremhævet med <span style="background-color: #ddf">denne farve</span></p>';
    $i = 1;
    while ($row = @mysql_fetch_array($result)) {
        extract($row);
        $linkdate = date('dmy', $date);
        $date = date("G:i || d.m || Y", $date);
        print "<div class='seperator'>\n";
        print "<div class='head'>";
        #			print '<p>#'.$i.'</p>';
        print "<h1>#{$i} <a href=\"/{$linkdate}/" . dirify($title) . "\">{$title}</a></h1>\n";
        print "</div>";
        print "<p class=\"date\">{$date}</p>\n";
        $text = strip_tags($text);
        $text = stripslashes($text);
        $text = substr($text, 0, 200);
        $text = preg_replace("/({$q})/i", '<span style="background-color: #ddf">\\1</span>', $text);
        print "<p>{$text}...</p>\n</div>";
        $i++;
    }
}
?>
</div>

				</div>
				<div id="footer">
Ejemplo n.º 4
0
function display_archive_entry()
{
    $url_expl = explode("/", $_SERVER['REQUEST_URI']);
    list($month, $year) = explode(".", $url_expl[2]);
    $sql = "\n\tSELECT\n\t\t*\n\tFROM\n\t\tentries\n\tWHERE\n\t\tFROM_UNIXTIME(entries.date, '%M') = '{$month}'\n\tAND\n\t\tFROM_UNIXTIME(entries.date, '%Y') = '{$year}'\n\tAND\n\t\tentries.status = '1'\n\tORDER BY\n\t\tentries.date\n\tDESC";
    $result = @mysql_query($sql);
    if (!$result) {
        print "<p>Error performing query 1: " . mysql_error() . "</p>\n";
    }
    $u_expl[0] = dateify($u_expl[0]);
    print "<h1 class=\"harkiv\">Arkiv for " . dateify($month) . " måned, år {$year}</h1>";
    while ($row = @mysql_fetch_array($result)) {
        extract($row);
        $edate = date("G:i || d.m || Y", $date);
        $post_head = "<div class='entry'>\n";
        $post_head .= '<div class="head">';
        $post_head .= "<h1><a title=\"Permanent link til '{$title}'\"";
        $title_d = dirify($title);
        $date = date('dmy', $date);
        $post_head .= " href=\"/{$date}/{$title_d}\"><img style=\"border: 0; vertical-align:middle;\" src=\"/img/permlink.gif\" alt=\"\" /></a>{$title}</h1>\n";
        $post_head .= '</div>';
        $post_head .= "<p class=\"date\">{$edate}</p>\n";
        $post_head .= stripslashes($text);
        if (!empty($text_more)) {
            $post_head .= "<p><a href=\"/{$date}/{$title_d}#mere\" style=\"font-weight: bold\" title=\"Læs mere af '{$title}' | Read more of '{$title}'\">Læs mere...</a></p>";
        }
        #		$post_head .= "</p>";
        print $post_head;
        $title_slashed = addslashes($title);
        if ($comments == 'on') {
            $sql2 = "SELECT entries.title, comments.eid, entries.id FROM " . $db_name . ".comments, " . $db_name . ".entries WHERE entries.title LIKE ('{$title_slashed}') AND comments.eid = entries.id";
            if (!($result2 = @mysql_query($sql2))) {
                print "<p>Error performing query: " . mysql_error() . "</p>";
                exit;
            } else {
                $count_comments = @mysql_num_rows($result2);
                if (@mysql_num_rows($result2) > 0) {
                    print "<p class=\"komm\"><a href=\"/{$date}/" . dirify($title) . "#c\">Kommentar [ {$count_comments} ]</a></p>\n";
                } else {
                    print "<p class=\"komm\"><a href=\"/{$date}/" . dirify($title) . "#ca\">Kommentarer [ {$count_comments} ]</a></p>\n";
                }
            }
        }
        print "</div>\n";
    }
}
Ejemplo n.º 5
0
} else {
    $id2 = $id + 1;
    $id3 = $id - 1;
    $total = count($thumb_path);
    $caption = "";
    $caption .= "<tr>\n<td>\n<p class=\"byline\"> {$page['header']} &raquo;  #{$id2} // #{$total} </p></td>\n</tr>\n<tr>\n";
    $caption .= "<td>\n<p class=\"byline\">\n";
    if ($id == 0) {
        $caption .= "<a href=\"?id={$id2}\" byline>&gt;&gt;</a></p>";
    } elseif ($id == $total - 1) {
        $caption .= "<a href=\"?id={$id3}\">&lt;&lt;</a></p>  ";
    } else {
        $caption .= "<a href=\"?id={$id3}\">&lt;&lt;</a>    <a href=\"?id={$id2}\">&gt;&gt;</a></p>";
    }
    $caption .= "<p><a href=\".\" title=\"Up\"><img src=\"{$images[$id]}\" alt=\"{$images[$id]}\" />\n</a>\n<br />\n";
    $caption .= dirify($images[$id]) . "\n";
    if ($design['show_size_px'] == true) {
        $caption .= "Størrelse (pixels): {$i_width[$iu]} x {$i_height[$iu]}<br />\n";
    }
    if ($design['show_size_kb'] == true) {
        $caption .= "<br />{$f_size[$id]} Kb.\n";
    }
    $caption .= "<br />\n</p></td>\n</tr>\n";
    $caption .= "<tr>\n<td>\n<p>\n";
    if ($id == 0) {
        $caption .= "<a href=\"?id={$id2}\">&gt;&gt;</a>";
    } elseif ($id == $total - 1) {
        $caption .= "<a href=\"?id={$id3}\">&lt;&lt;</a>  ";
    } else {
        $caption .= "<a href=\"?id={$id3}\">&lt;&lt;</a>    <a href=\"?id={$id2}\">&gt;&gt;</a>";
    }
Ejemplo n.º 6
0
    putenv("TZ=CET");
    $last_build_date = date("r", time());
    # Initiate the content-string that will be added to
    $xml_string = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<rss version=\"2.0\">\n<channel>\n\t<title>. verture.net | her skriver jeg .</title>\n\t<description>Jonas Voss' weblog, Københavner og studerende, som så mange andre.</description>\n\t<link>http://blog.verture.net/</link>\n\t<lastBuildDate>{$last_build_date}</lastBuildDate>\n";
    while ($row = @mysql_fetch_array($result_xml)) {
        extract($row);
        $text = htmlspecialchars($text);
        $pub_date = date("r", $xml_date);
        $date = date("dmy", $xml_date);
        $xml_string .= "<item>\n\t";
        $xml_string .= "<title>{$title}</title>\n\t";
        $xml_string .= "<description>{$text}</description>\n\t";
        $xml_string .= "<link>http://blog.verture.net/" . $date . "/" . dirify($title) . "</link>\n\t";
        $xml_string .= "<pubDate>{$pub_date}</pubDate>\n\t";
        $xml_string .= "<guid>http://blog.verture.net/" . $date . "/" . dirify($title) . "</guid>\n\t";
        $xml_string .= "<author>" . $name . "</author>\n\t";
        $xml_string .= "<comments>http://blog.verture.net/" . $date . "/" . dirify($title) . "#c</comments>\n\t";
        $xml_string .= "</item>\n";
    }
    $xml_string .= "</channel>\n</rss>";
    $xml_file = 'rssfeed.xml';
    if (!($fp = fopen($xml_file, "w+"))) {
        print "<p>Kunne ikke åbne {$xml_file}</p>";
    } else {
        if (!fwrite($fp, $xml_string)) {
            print "<p>Kunne ikke skrive til {$xml_file}.</p>";
        } else {
            print "<p style=\"padding-left: 10px;\">XML-feed opdateret i /{$xml_file}.</p>";
        }
    }
}
Ejemplo n.º 7
0
    $caption .= "<p><a href=\".\" title=\"Thumbnail view\"><img src=\"{$images[$id]}\" alt=\"{$images[$id]}\" />\n</a>\n<br />\n";
    $caption .= "<span style=\"font-size: large\">" . dirify($images[$id]) . "</span>\n";
    if ($design['show_size_px'] == 1) {
        $caption .= "Størrelse (pixels): {$i_width[$iu]} x {$i_height[$iu]}<br />\n";
    }
    if ($design['show_size_kb'] == 1) {
        $caption .= "<br />{$f_size[$id]} Kb.\n";
    }
    $caption .= "<br />\n</p></td>\n</tr>\n";
    $caption .= "<tr>\n<td>\n<p style=\"padding-top: 12px;\">\n";
    if ($id == 0) {
        $caption .= "<a href=\"?id={$id2}\">&gt;&gt;</a> " . dirify($images[$id + 1]) . "";
    } elseif ($id == $total - 1) {
        $caption .= dirify($images[$id - 1]) . " <a href=\"?id={$id3}\">&lt;&lt;</a>  ";
    } else {
        $caption .= dirify($images[$id - 1]) . " <a href=\"?id={$id3}\">&lt;&lt;</a>    <a href=\"?id={$id2}\">&gt;&gt;</a> " . dirify($images[$id + 1]) . "";
    }
    $caption .= "</p>\n</td>\n</tr>\n";
    print $caption;
}
#   If the user defined a footer_file, print it:
if (!empty($page['footer_file'])) {
    print "<tr><td colspan=\"{$design['columns']}\">\n<p style=\"width: 100%; text-align: center; padding-top: 25px;\">\n";
    @(include $_SERVER['DOCUMENT_ROOT'] . $page['footer_file']);
    print "</p></td></tr>";
}
#   Print version number:
#   print "<tr><td colspan=\"{$design['columns']}\"><p style=\"width: 100%; text-align: center; padding-top: 25px;\">Back to <a href=\"http://verture.net/\">verture.net</a></p></td></tr>";
print "</table>\n";
#   Exit PHP and clean up the page:
?>