function smarty_modifier_sp($str, $args) { if ($args != 1) { return $str; } $mt = MT::get_instance(); $ctx =& $mt->context(); $websiteId = $ctx->__stash['blog']->blog_parent_id || 0; if ($websiteId) { $website = $mt->db()->fetch_blog($websiteId); $websiteUrl = $website->site_url; $cfg = $mt->db()->fetch_plugin_data('ModifyURL', 'configuration:blog:' . $websiteId); $path = $cfg['path_setting']; } else { $websiteUrl = $ctx->__stash['blog']->site_url; $cfg = $mt->db()->fetch_plugin_data('ModifyURL', 'configuration:blog:' . $ctx->__stash['blog_id']); $path = $cfg['path_setting']; } if (strpos($str, 'http') === FALSE) { $blog_path = preg_replace('/https?:\\/\\/[^\\/]+/', '', $websiteUrl); if ($blog_path === '/') { $str = $blog_path . $path . $str; } else { if (preg_match('/\\/$/', $blog_path)) { $str = $blog_path . $path . '/' . str_replace($blog_path, '', $str); } else { $str = '/' . $path . $str; } } } else { $str = str_replace($websiteUrl, $websiteUrl . $path . '/', $str); } return $str; }
function smarty_function_mtcommenteruserpic($args, &$ctx) { $comment = $ctx->stash('comment'); if (!$comment) { return $ctx->error("No comments available"); } $cmntr = $ctx->stash('commenter'); if (!$cmntr) { return ''; } $asset_id = isset($cmntr->author_userpic_asset_id) ? $cmntr->author_userpic_asset_id : 0; $asset = $ctx->mt->db()->fetch_assets(array('id' => $asset_id)); if (!$asset) { return ''; } $blog =& $ctx->stash('blog'); require_once "MTUtil.php"; $userpic_url = userpic_url($asset[0], $blog, $cmntr); if (empty($userpic_url)) { return ''; } $mt = MT::get_instance(); $dimensions = sprintf('width="%s" height="%s"', $mt->config('UserpicThumbnailSize'), $mt->config('UserpicThumbnailSize')); $link = sprintf('<img src="%s?%d" %s alt="%s" />', encode_html($userpic_url), $asset_id, $dimensions, encode_html($asset->label)); return $link; }
function smarty_modifier_nofollowfy($str, $arg = 1) { # manipulate hyperlinks in $str... if (!isset($str)) { return $str; } if (!$arg) { return $str; } $mt = MT::get_instance(); $ctx =& $mt->context(); $blog = $ctx->stash('blog'); $curr_tag = $ctx->_tag_stack[count($ctx->_tag_stack) - 1]; $enable = false; if (isset($curr_tag[1]['nofollowfy'])) { $enable = $curr_tag[1]['nofollowfy'] ? true : false; } if (!$enable && !$blog->blog_nofollow_urls) { return $str; } $arg = strtolower($arg); if ($arg == 'mtcommentbody' || $arg == 'mtcommentauthorlink' || $arg == 'mtcommenturl') { $comment = $ctx->stash('comment'); if ($comment->comment_commenter_id) { // is an authenticated comment $auth = $comment->commenter(); if ($auth && $blog->blog_follow_auth_links) { return $str; } } } return preg_replace_callback('#<a\\s([^>]*\\s*href\\s*=[^>]*)>#i', 'nofollowfy_cb', $str); }
public function testIssetWithOverloading() { include_once "php/mt.php"; include_once "php/lib/MTUtil.php"; $cfg_file = realpath("t/mysql-test.cfg"); $mt = MT::get_instance(1, $cfg_file); $ctx =& $mt->context(); // Test some objects inheriting ObjectBase class. require_once "php/lib/class.mt_config.php"; $config = new Config(); $config->Load(); $this->assertTrue(isset($config->id)); require_once "php/lib/class.mt_author.php"; $author = new Author(); $author->Load(); $this->assertTrue(isset($author->id)); // protected variable call (bugid:113105) require_once "php/lib/class.mt_entry.php"; $entry = new Entry(); $entry->id = 1; $this->assertTrue(isset($entry->id)); $this->assertNull($entry->_prefix); $this->assertFalse(isset($entry->_prefix)); // fixed Dynamic publishing error occurred with memcached environment. bugid: 113546 $mt->config('MemcachedServers', '127.0.0.1:11211'); $obj_names = array('asset' => 'Asset', 'author' => 'Author', 'blog' => 'Blog', 'category' => 'Category', 'comment' => 'Comment', 'entry' => 'Entry', 'folder' => 'Folder', 'page' => 'Page', 'tbping' => 'TBPing', 'template' => 'Template', 'website' => 'Website'); foreach ($obj_names as $table => $name) { require_once "php/lib/class.mt_{$table}.php"; $obj = new $name(); $obj->Load(); $this->cache("{$table}:" . $obj->id, $obj); $obj_cache = $this->load_cache("{$table}:" . $obj->id); $this->assertInstanceOf("{$name}", $obj_cache); } }
function smarty_modifier_ts_format($text, $arg) { $mt = MT::get_instance(); $ctx =& $mt->context(); $text = $mt->db()->db2ts($text); $args = array('ts' => $text, 'format' => $arg); return $ctx->_hdlr_date($args, $ctx); }
function smarty_function_mttagsearchlink($args, &$ctx) { $mt = MT::get_instance(); $blog = $ctx->stash('blog'); $tag = $ctx->stash('Tag'); if (!$tag) { return ''; } if (is_object($tag)) { $name = $tag->tag_name; } else { $name = $tag; } $param = ''; $include_blogs = $args['include_blogs'] ? $args['include_blogs'] : $ctx->stash('include_blogs'); $include_blogs or $include_blogs = $args['blog_ids'] ? $args['blog_ids'] : $ctx->stash('blog_ids'); if ($include_blogs) { if ($include_blogs != 'all') { $incl = $mt->db()->parse_blog_ids($include_blogs, $include_with_website); if (!$blog->is_blog) { array_unshift($incl, $blog->id); } $param = 'IncludeBlogs=' . implode(',', $incl); } } else { $blog_id = $ctx->stash('blog_id'); $param = 'IncludeBlogs=' . $blog_id; } if ($exclude_blogs = $args['exclude_blogs'] ? $args['exclude_blogs'] : $ctx->stash('exclude_blogs')) { $excl = $mt->db()->parse_blog_ids($exclude_blogs); $param = 'ExcludeBlogs=' . implode(',', $excl); } $tmpl_blog_id = null; if (isset($args['tmpl_blog_id'])) { $tmpl_blog_id = $args['tmpl_blog_id']; if ('parent' == strtolower($tmpl_blog_id)) { if ($blog->is_blog) { $blog = $blog->website(); } $tmpl_blog_id = $blog->id; } else { if (!preg_match('/^\\d+$/', $tmpl_blog_id) || $tmpl_blog_id < 1) { $mt = MT::get_instance(); $ctx->error($mt->translate('Invalid [_1] parameter.', 'tmpl_blog_id')); } } } require_once "function.mtcgipath.php"; $search = smarty_function_mtcgipath($args, $ctx); $search .= $ctx->mt->config('SearchScript'); $link = $search . '?' . $param . ($param ? '&' : '') . 'tag=' . urlencode($name); $link .= '&limit=' . $ctx->mt->config('MaxResults'); if ($tmpl_blog_id) { $link .= '&blog_id=' . $tmpl_blog_id; } return $link; }
function smarty_function_mtassettype($args, &$ctx) { $asset = $ctx->stash('asset'); if (!$asset) { return ''; } $mt = MT::get_instance(); return $mt->translate($asset->asset_class); }
function smarty_modifier_filters($text, $filters) { // status: complete $mt = MT::get_instance(); $ctx =& $mt->context(); require_once 'MTUtil.php'; $text = apply_text_filter($ctx, $text, $filters); return $text; }
function smarty_function_mtcommentauthorlink($args, &$ctx) { $mt = MT::get_instance(); $comment = $ctx->stash('comment'); $name = $comment->comment_author; if (!$name && isset($args['default_name'])) { $name = $args['default_name']; } $name or $name = $mt->translate("Anonymous"); require_once "MTUtil.php"; $name = encode_html($name); $email = $comment->comment_email; $url = $comment->comment_url; if (isset($args['show_email'])) { $show_email = $args['show_email']; } else { $show_email = 0; } if (isset($args['show_url'])) { $show_url = $args['show_url']; } else { $show_url = 1; } $target = isset($args['new_window']) && $args['new_window'] ? ' target="_blank"' : ''; _comment_follow($args, $ctx); $cmntr = $ctx->stash('commenter'); if (!isset($cmntr) && isset($comment->comment_commenter_id)) { $cmntr = $comment->commenter(); } if ($cmntr) { $name = isset($cmntr->author_nickname) ? encode_html($cmntr->author_nickname) : $name; if ($cmntr->author_url) { return sprintf('<a title="%s" href="%s"%s>%s</a>', encode_html($cmntr->author_url), encode_html($cmntr->author_url), $target, $name); } return $name; } elseif ($show_url && $url) { require_once "function.mtcgipath.php"; $cgi_path = smarty_function_mtcgipath($args, $ctx); $comment_script = $ctx->mt->config('CommentScript'); $name = strip_tags($name); $url = encode_html(strip_tags($url)); if ($comment->comment_id && (!isset($args['no_redirect']) || isset($args['no_redirect']) && !$args['no_redirect']) && (!isset($args['nofollowfy']) || isset($args['nofollowfy']) && !$args['nofollowfy'])) { return sprintf('<a title="%s" href="%s%s?__mode=red;id=%d"%s>%s</a>', $url, $cgi_path, $comment_script, $comment->comment_id, $target, $name); } else { return sprintf('<a title="%s" href="%s"%s>%s</a>', $url, $url, $target, $name); } } elseif ($show_email && $email && is_valid_email($email)) { $email = encode_html(strip_tags($email)); $str = 'mailto:' . $email; if ($args['spam_protect']) { $str = spam_protect($str); } return sprintf('<a href="%s">%s</a>', $str, $name); } return $name; }
public function Save() { $val = $this->data; $this->data = null; $ret = parent::Save(); if ($ret) { $mt = MT::get_instance(); $mt->db()->db()->UpdateBlob('mt_session', 'session_data', $val, "session_id='" . $this->id . "'", 'BLOB'); } }
function smarty_function_mtcategorycommentcount($args, &$ctx) { $mt = MT::get_instance(); $db = $mt->db(); $category = $ctx->stash('category'); $cat_id = (int) $category->category_id; $count = 0; if ($cat_id) { $count = $db->category_comment_count(array('category_id' => $cat_id, 'top' => $args['top'])); } return $ctx->count_format($count, $args); }
function smarty_modifier_setvar($text, $name) { $mt = MT::get_instance(); $ctx =& $mt->context(); if (array_key_exists('__inside_set_hashvar', $ctx->__stash)) { $vars =& $ctx->__stash['__inside_set_hashvar']; } else { $vars =& $ctx->__stash['vars']; } $vars[$name] = $text; return ''; }
function smarty_block_mtentrynext($args, $content, &$ctx, &$repeat) { static $_next_cache = array(); if (!isset($content)) { # save all values, to be restored when we're done... $ctx->localize(array('entry', 'conditional', 'else_content')); $entry = $ctx->stash('entry'); if ($entry) { $label = $entry->entry_id; if (isset($args['by_author'])) { $label .= ':author=' . $entry->entry_author_id; } if (isset($args['by_category']) || isset($args['by_folder'])) { $cat = $entry->category(); $cat_id = $cat ? $cat->category_id : 0; $label .= ':category=' . $cat_id; } if (isset($_next_cache[$label])) { $next_entry = $_next_cache[$label]; } else { $mt = MT::get_instance(); $blog_id = $entry->entry_blog_id; if (isset($args['class'])) { $class = $args['class']; } else { $class = 'entry'; } $ts = $mt->db()->db2ts($class == 'entry' ? $entry->entry_authored_on : $entry->entry_modified_on); $eargs = array('not_entry_id' => $entry->entry_id, 'blog_id' => $blog_id, 'lastn' => 1, 'base_sort_order' => 'ascend', 'current_timestamp' => $ts, 'class' => $class); if (isset($args['by_author'])) { $eargs['author_id'] = $entry->entry_author_id; } if (isset($args['by_category']) || isset($args['by_folder'])) { $eargs['category_id'] = $cat_id; } list($next_entry) = $ctx->mt->db()->fetch_entries($eargs); if ($next_entry) { $_next_cache[$label] = $next_entry; } } $ctx->stash('entry', $next_entry); } $ctx->stash('conditional', isset($next_entry)); $ctx->stash('else_content', null); } else { if (!$ctx->stash('conditional')) { $content = $ctx->stash('else_content'); } $ctx->restore(array('entry', 'conditional', 'else_content')); } return $content; }
function smarty_block_mtifcommentertrusted($args, $content, &$ctx, &$repeat) { if (!isset($content)) { $is_trust = NULL; $a = $ctx->stash('commenter'); if (empty($a)) { $is_trust = 0; } else { $perm = $a->permissions(0); $perm = is_array($perm) ? array_shift($perm) : $perm; if (!empty($perm)) { if (preg_match("/'administer'/", $perm->permission_permissions)) { $is_trust = 1; } } if (is_null($is_trust)) { $mt = MT::get_instance(); $blog_id = 0; if (!$mt->config('SingleCommunity')) { $blog = $ctx->stash('blog'); if (!empty($blog)) { $blog_id = $blog->id; } } $perm = $a->permissions($blog_id); $perm = is_array($perm) ? array_shift($perm) : $perm; if (!empty($perm)) { if (preg_match("/'comment'/", $perm->permission_restrictions)) { $is_trust = 0; } elseif (preg_match("/'(comment|administer_blog|manage_feedback)'/", $perm->permission_permissions)) { $is_trust = 1; } } else { if (!$mt->config('SingleCommunity')) { $is_trust = 0; } } if (is_null($is_trust)) { if ($mt->config('SingleCommunity') && $a->type == 1 && $a->status == 1) { $is_trust = 1; } else { $is_trust = 0; } } } } return $ctx->_hdlr_if($args, $content, $ctx, $repeat, $is_trust); } else { return $ctx->_hdlr_if($args, $content, $ctx, $repeat); } }
public function form_fields($blog_id) { $mt = MT::get_instance(); $token = ''; $token = sha1(rand(0, 65535)); if (strlen($token) == 0) { return ''; } $cgipath = $mt->config('CGIPath'); $commentscript = $mt->config('CommentScript'); $caption = $mt->translate('Captcha'); $description = $mt->translate('Type the characters shown in the picture above.'); $form = "\n<div class=\"label\"><label for=\"captcha_code\">{$caption}:</label></div>\n<div class=\"field\">\n<input type=\"hidden\" name=\"token\" value=\"{$token}\" />\n<img src=\"{$cgipath}{$commentscript}/captcha/{$blog_id}/{$token}\" width=\"150\" height=\"35\" /><br />\n<input type=\"text\" name=\"captcha_code\" id=\"captcha-code\" class=\"text\" value=\"\" autocomplete=\"off\" />\n<p>{$description}</p>\n</div>"; return $form; }
function smarty_modifier_sanitize($text, $spec = '1') { if (!$spec) { return $text; } else { if ($spec == '1') { $mt = MT::get_instance(); $ctx =& $mt->context(); $blog = $ctx->stash('blog'); $spec = $blog->blog_sanitize_spec; $spec or $spec = $mt->config('GlobalSanitizeSpec'); } } require_once "sanitize_lib.php"; return sanitize($text, $spec); }
public function data($name = null) { if (empty($this->_data)) { $mt = MT::get_instance(); $this->_data = $mt->db()->unserialize($this->data); } if (!empty($name)) { if (isset($this->_data[$name])) { return $this->_data[$name]; } else { return null; } } else { return $this->_data; } }
function smarty_function_mtarchivelabel($args, &$ctx) { $at = $ctx->stash('current_archive_type'); if (isset($args['type'])) { $at = $args['type']; } elseif (isset($args['archive_type'])) { $at = $args['archive_type']; } $ar = ArchiverFactory::get_archiver($at); if (isset($ar)) { return $ar->get_label($args); } else { $mt = MT::get_instance(); return $mt->translate($at); } }
function smarty_modifier_mteval($text, $arg) { if (!$arg) { return $text; } $mt = MT::get_instance(); $ctx =& $mt->context(); $_var_compiled = ''; if (!$ctx->_compile_source('evaluated template', $text, $_var_compiled)) { return $ctx->error("Error compiling text '{$text}'"); } ob_start(); $ctx->_eval('?>' . $_var_compiled); $_contents = ob_get_contents(); ob_end_clean(); return $_contents; }
public static function _find_current_plugindata($blog) { $keys = array('configuration:blog:' . $blog->id); if ($blog->parent_id) { array_push($keys, 'configuration:blog:' . $blog->parent_id); } array_push($keys, 'configuration'); require_once 'class.mt_plugindata.php'; $class = new PluginData(); $where = "plugindata_plugin = 'GoogleAnalytics' AND " . "plugindata_key IN ('" . join("','", $keys) . "')"; $tmp_objs = $class->Find($where); if (empty($tmp_objs)) { return null; } $objs = array(); foreach ($keys as $k) { foreach ($tmp_objs as $o) { if ($o->key == $k) { array_push($objs, $o); } } } $mt = MT::get_instance(); $db = $mt->db(); for ($i = 0; $i < sizeof($objs); $i++) { $o = $objs[$i]; $data = $o->data(); if ($data && $data['profile_id']) { if ($data['client_id'] && $data['client_secret']) { return $o; } else { if ($data['parent_client_id']) { for ($j = 0; $j < sizeof($objs); $j++) { $parent_data = $objs[$j]->data(); if ($parent_data && $parent_data['client_id'] && $parent_data['client_id'] == $data['parent_client_id'] && $parent_data['client_secret']) { return $o; } } } } } } }
public function __construct($ttl = 0) { parent::__construct($ttl); if (empty(self::$_server)) { $mt = MT::get_instance(); $servers = $mt->config('MemcachedServers'); if (!empty($servers)) { if (extension_loaded('memcache')) { self::$_server = new Memcache(); $this->connect($servers); } else { require_once 'class.exception.php'; throw new MTException("Cannot load memcached extension."); } } else { require_once 'class.exception.php'; throw new MTException("Cannot load memcached extension."); } } }
function smarty_function_mtcommentauthor($args, &$ctx) { $c = $ctx->stash('comment'); if (!$c) { return $ctx->error("No comments available"); } $a = isset($c->comment_author) ? $c->comment_author : ''; if ($c->comment_commenter_id) { $commenter = $ctx->stash('commenter'); if ($commenter) { $a = $commenter->nickname; } } if (isset($args['default'])) { $a or $a = $args['default']; } else { $mt = MT::get_instance(); $a or $a = $mt->translate("Anonymous"); } $a or $a = ''; return strip_tags($a); }
function smarty_function_mtcommentreplytolink($args, &$ctx) { $comment = $ctx->stash('comment'); if (!$comment) { return ''; } $mt = MT::get_instance(); $label = $args['label']; $label or $label = $args['text']; $label or $label = $mt->translate("Reply"); $onclick = $args['onclick']; $onclick or $onclick = "mtReplyCommentOnClick(%d, '%s')"; $comment_author = $comment->comment_author; if ($comment->comment_commenter_id) { $cmtr = $comment->commenter(); if (!empty($cmtr)) { $comment_author = $cmtr->nickname; } } require_once "MTUtil.php"; $comment_author = encode_html(encode_js($comment_author)); $onclick = sprintf($onclick, $comment->comment_id, $comment_author); return sprintf("<a title=\"%s\" href=\"javascript:void(0);\" onclick=\"{$onclick}\">%s</a>", $label, $label); }
public function testIssetWithOverloading() { include_once "php/mt.php"; include_once "php/lib/MTUtil.php"; $cfg_file = realpath("t/mysql-test.cfg"); $mt = MT::get_instance(1, $cfg_file); $ctx =& $mt->context(); // Test some objects inheriting ObjectBase class. require_once "php/lib/class.mt_config.php"; $config = new Config(); $config->Load(); $this->assertTrue(isset($config->id)); require_once "php/lib/class.mt_author.php"; $author = new Author(); $author->Load(); $this->assertTrue(isset($author->id)); // protected variable call (bugid:113105) require_once "php/lib/class.mt_entry.php"; $entry = new Entry(); $entry->Load(); $this->assertTrue(isset($entry->id)); $this->assertNull($entry->_prefix); $this->assertFalse(isset($entry->_prefix)); }
function flush_all() { $mt = MT::get_instance(); return $mt->db()->flush_session(); }
public static function bulk_load_meta(&$objs) { if (empty($objs)) { return; } $obj = $objs[0]; $extras = array(); $table = $obj->TableInfo(); $meta_table = $obj->_table . '_meta'; if (empty($table->_hasMany[$meta_table])) { return; } $child_class = $table->_hasMany[$meta_table]; $foreign_key = $child_class->foreignKey; $key = reset($table->keys); $hash = array(); foreach ($objs as &$obj) { $id = @$obj->{$key}; if (!is_numeric($id)) { $db = $obj->DB(); $id = $db->qstr($id); } $obj_hash[$id] =& $obj; } $mt = MT::get_instance(); $limit = $mt->config('BulkLoadMetaObjectsLimit'); $length = sizeof($obj_hash); for ($from = 0; $from < $length; $from += $limit) { $children = $child_class->Find($foreign_key . ' IN (' . join(',', array_slice(array_keys($obj_hash), $from, $limit)) . ')', false, false); $meta_hash = array(); if ($children) { foreach ($children as &$child) { $k = $child->{$foreign_key}; if (!$meta_hash[$k]) { $meta_hash[$k] = array(); } $meta_hash[$k][] = $child; } } foreach ($meta_hash as $k => &$v) { $obj_hash[$k]->{$meta_table} = $v; } unset($meta_hash); } unset($obj_hash); foreach ($objs as &$obj) { if (!$obj_type) { $obj_type = $obj->object_type(); } $meta_info = $obj->{$meta_table}; if (!$meta_info) { continue; } foreach ($meta_info as &$meta) { $col_name = $obj->_prefix . 'meta_type'; $meta_name = $meta->{$col_name}; $value = null; $is_blob = false; foreach ($obj->_meta_fields as $f) { $col_name = $obj->_prefix . 'meta_' . $f; $value = $meta->{$col_name}; if (!is_null($value)) { break; } if (preg_match("/^BIN:SERG/", $value)) { $mt = MT::get_instance(); $value = preg_replace("/^BIN:/", "", $value); $value = $mt->db()->unserialize($value); } } if (!self::$_meta_info[$obj_type][$meta_name]) { self::$_meta_info[$obj_type][$meta_name] = $col_name; } $obj->{$meta_name} = $value; $obj->_original[] = $value; } } }
function _include_path($path) { $path_array = array(); if (preg_match('/^\\//', $path)) { $path_array = preg_split('/\\//', $path, -1, PREG_SPLIT_NO_EMPTY); } else { $path_array = preg_split('/\\//', $path, -1, PREG_SPLIT_NO_EMPTY); $mt = MT::get_instance(); array_unshift($path_array, $mt->config('IncludesDir')); } return $path_array; }
function _parse_modifier($str) { if (!preg_match('/,/', $str)) { return $str; } $mt = MT::get_instance(); $result = ''; if (preg_match_all('/(?:[,:]((["\'])((?:<[^>]*?>|.)*?)?\\2)+)/', $str, $matches, PREG_SET_ORDER)) { for ($a = 0; $a < count($matches); $a++) { $val = $matches[$a][1]; if (strlen($val)) { if (preg_match('/^([\'"])\\$([A-Za-z_](\\w|\\.)*)\\1$/', $val, $second_matches)) { $quote = $second_matches[1]; if (preg_match('/^(config|request)\\.(.+)$/i', $second_matches[2], $m)) { if (strtolower($m[1]) == 'config' && !preg_match('/(password|secret)/i', $m[2])) { $val = $quote . $mt->config(strtolower($m[2])) . $quote; } elseif (strtolower($m[1]) == 'request') { $val = '$smarty.request.' . $m[2]; } } else { $val = '$vars.' . $second_matches[2]; } } $result .= ':' . $val; } } return $result; } else { return $str; } }
function multiblog_filter_blogs(&$ctx, $is_include, $blogs) { # Set flag to indicate whether @blogs are to be included or excluded $is_include = $is_include == 'include_blogs' ? 1 : 0; # Set local blog $this_blog = $ctx->stash('blog_id'); $multiblog_system_config = multiblog_fetch_system_config(); # Get the MultiBlog system config for default access and overrides if (isset($multiblog_system_config['default_access_allowed'])) { $default_access_allowed = $multiblog_system_config['default_access_allowed']; } else { $default_access_allowed = 1; } $access_overrides = $multiblog_system_config['access_overrides']; if (!$access_overrides) { $access_overrides = array(); } # System setting allows access by default if ($default_access_allowed) { # include_blogs="all" if ($is_include && $blogs[0] == "all") { # Check for any deny overrides. # If found, switch to exclude_blogs="..." $deny = array(); foreach (array_keys($access_overrides) as $o) { if ($o != $this_blog && (isset($access_overrides[$o]) && $access_overrides[$o] == MULTIBLOG_ACCESS_DENIED)) { $deny[] = $o; } } return count($deny) ? array('exclude_blogs', $deny) : array('include_blogs', array('all')); } elseif ($blogs[0] == 'site' || $blogs[0] == 'children' || $blogs[0] == 'siblings') { $mt = MT::get_instance(); $ctx = $mt->context(); $blog = $ctx->stash('blog'); if (!empty($blog)) { $website = $blog->class == 'blog' ? $blog->website() : $blog; $blogs = $website->blogs(); if (empty($blogs)) { $blogs = array(); } $allow = array(); foreach ($blogs as $b) { if ($b->id == $this_blog || !isset($access_overrides[$b->id]) || $access_overrides[$b->id] == MULTIBLOG_ACCESS_ALLOWED) { array_push($allow, $b->id); } } } return count($allow) ? array('include_blogs', $allow) : null; } elseif ($is_include && count($blogs)) { # Remove any included blogs that are specifically deny override # Return undef is all specified blogs are deny override $allow = array(); foreach ($blogs as $b) { if ($b == $this_blog || !isset($access_overrides[$b]) || $access_overrides[$b] == MULTIBLOG_ACCESS_ALLOWED) { $allow[] = $b; } } return count($allow) ? array('include_blogs', $allow) : null; } else { # Add any deny overrides blogs to the list and de-dupe foreach (array_keys($access_overrides) as $o) { if ($o != $this_blog && (isset($access_overrides[$o]) && $access_overrides[$o] == MULTIBLOG_ACCESS_DENIED)) { $blogs[] = $o; } } $seen = array(); foreach ($blogs as $b) { $seen[$b] = 1; } $blogs = array_keys($seen); return array('exclude_blogs', $blogs); } } else { # include_blogs="all" if ($is_include && $blogs[0] == "all") { # Enumerate blogs from allow override # Hopefully this is significantly smaller than @all_blogs $allow = array(); foreach (array_keys($access_overrides) as $o) { if ($o == $this_blog || isset($access_overrides[$o]) && $access_overrides[$o] == MULTIBLOG_ACCESS_ALLOWED) { $allow[] = $o; } } if (!isset($access_overrides[$this_blog])) { $allow[] = $this_blog; } return count($allow) ? array('include_blogs', $allow) : null; } elseif ($blogs[0] == 'site' || $blogs[0] == 'children' || $blogs[0] == 'siblings') { $mt = MT::get_instance(); $ctx = $mt->context(); $blog = $ctx->stash('blog'); if (!empty($blog) && $blog->class == 'blog') { require_once 'class.mt_blog.php'; $blog_class = new Blog(); $blogs = $blog_class->Find("blog_parent_id = " . $blog->parent_id); $allow = array(); foreach ($blogs as $b) { if ($b->id == $this_blog || isset($access_overrides[$b->id]) && $access_overrides[$b->id] == MULTIBLOG_ACCESS_ALLOWED) { array_push($allow, $b->id); } } } return count($allow) ? array('include_blogs', $allow) : null; } elseif ($is_include && count($blogs)) { # Filter @blogs returning only those with allow override $allow = array(); foreach ($blogs as $b) { if ($b == $this_blog || isset($access_overrides[$b]) && $access_overrides[$b] == MULTIBLOG_ACCESS_ALLOWED) { $allow[] = $b; } } return count($allow) ? array('include_blogs', $allow) : null; } else { # Get allow override blogs and then omit # the specified excluded blogs. $allow = array(); foreach (array_keys($access_overrides) as $o) { if ($o == $this_blog || isset($access_overrides[$o]) && $access_overrides[$o] == MULTIBLOG_ACCESS_ALLOWED) { $allow[] = $o; } } if (!isset($access_overrides[$this_blog])) { $allow[] = $this_blog; } $seen = array(); foreach ($blogs as $b) { $seen[$b] = 1; } $blogs = array(); foreach ($allow as $a) { if (!isset($seen[$a])) { $blogs[] = $a; } } return count($blogs) ? array('include_blogs', $blogs) : null; } } }
public function update_archive_link_cache($args) { $blog_id = $args['blog_id']; $at = $args['archive_type']; $where = isset($args['where']) ? $args['where'] : ''; if (isset($args['hi']) && isset($args['low'])) { $hi = $args['hi']; $low = $args['low']; $range = " and fileinfo_startdate between '{$low}' and '{$hi}'"; } $sql = "\n fileinfo_archive_type = '{$at}'\n and fileinfo_blog_id = {$blog_id}\n and templatemap_is_preferred = 1\n {$range}\n {$where}"; $extras['join']['mt_templatemap'] = array('condition' => "templatemap_id = fileinfo_templatemap_id"); require_once 'class.mt_fileinfo.php'; $fileinfo = new FileInfo(); $finfos = $fileinfo->Find($sql, false, false, $extras); if (!empty($finfos)) { $mt = MT::get_instance(); foreach ($finfos as $finfo) { $date = $this->db2ts($finfo->fileinfo_startdate); if ($at == 'Page') { $blog_url = $finfo->blog()->site_url(); } else { $blog_url = $finfo->blog()->archive_url(); $blog_url or $blog_url = $finfo->blog()->site_url(); } $blog_url = preg_replace('!(https?://(?:[^/]+))/.*!', '$1', $blog_url); $url = $blog_url . $finfo->url; $url = _strip_index($url, array('blog_file_extension' => $finfo->blog()->blog_file_extension)); $this->_archive_link_cache[$date . ';' . $at] = $url; } } return true; }