Replace self::func() with <helper_name>::func() for all public APIs

and constants to make overloading easier.  Fixes #1510.
This commit is contained in:
Bharat Mediratta
2010-11-28 11:27:25 -08:00
parent 76b6daefaa
commit eb010554ff
15 changed files with 92 additions and 92 deletions

View File

@@ -26,7 +26,7 @@ class html extends html_Core {
* unescaped HTML which is assumed to be safe.
*
* Example:<pre>
* <div><?= html::clean($php_var) ?>
* <div><?= html::clean($php_var) ?>
* </pre>
*/
static function clean($html) {
@@ -39,7 +39,7 @@ class html extends html_Core {
* only non-malicious HTML.
*
* Example:<pre>
* <div><?= html::purify($item->title) ?>
* <div><?= html::purify($item->title) ?>
* </pre>
*/
static function purify($html) {
@@ -86,6 +86,6 @@ class html extends html_Core {
* @return the string escaped for use in HTML attributes.
*/
static function clean_attribute($string) {
return self::clean($string)->for_html_attr();
return html::clean($string)->for_html_attr();
}
}

View File

@@ -24,7 +24,7 @@ class remote extends remote_Core {
/* Read the web page into a buffer */
list ($response_status, $response_headers, $response_body) =
self::do_request($url, 'POST', $extra_headers, $post_data_raw);
remote::do_request($url, 'POST', $extra_headers, $post_data_raw);
return array($response_body, $response_status, $response_headers);
}

View File

@@ -79,7 +79,7 @@ class access_Core {
* @return boolean
*/
static function can($perm_name, $item) {
return self::user_can(identity::active_user(), $perm_name, $item);
return access::user_can(identity::active_user(), $perm_name, $item);
}
/**
@@ -102,7 +102,7 @@ class access_Core {
$resource = $perm_name == "view" ?
$item : model_cache::get("access_cache", $item->id, "item_id");
foreach ($user->groups() as $group) {
if ($resource->__get("{$perm_name}_{$group->id}") === self::ALLOW) {
if ($resource->__get("{$perm_name}_{$group->id}") === access::ALLOW) {
return true;
}
}
@@ -117,12 +117,12 @@ class access_Core {
* @return boolean
*/
static function required($perm_name, $item) {
if (!self::can($perm_name, $item)) {
if (!access::can($perm_name, $item)) {
if ($perm_name == "view") {
// Treat as if the item didn't exist, don't leak any information.
throw new Kohana_404_Exception();
} else {
self::forbidden();
access::forbidden();
}
}
}
@@ -138,7 +138,7 @@ class access_Core {
static function group_can($group, $perm_name, $item) {
$resource = $perm_name == "view" ?
$item : model_cache::get("access_cache", $item->id, "item_id");
return $resource->__get("{$perm_name}_{$group->id}") === self::ALLOW;
return $resource->__get("{$perm_name}_{$group->id}") === access::ALLOW;
}
/**
@@ -168,14 +168,14 @@ class access_Core {
return null;
}
// For view permissions, if any parent is self::DENY, then those parents lock this one.
// For view permissions, if any parent is access::DENY, then those parents lock this one.
// Return
$lock = ORM::factory("item")
->where("left_ptr", "<=", $item->left_ptr)
->where("right_ptr", ">=", $item->right_ptr)
->where("items.id", "<>", $item->id)
->join("access_intents", "items.id", "access_intents.item_id")
->where("access_intents.view_$group->id", "=", self::DENY)
->where("access_intents.view_$group->id", "=", access::DENY)
->order_by("level", "DESC")
->limit(1)
->find();
@@ -222,7 +222,7 @@ class access_Core {
self::_update_access_non_view_cache($group, $perm_name, $album);
}
self::update_htaccess_files($album, $group, $perm_name, $value);
access::update_htaccess_files($album, $group, $perm_name, $value);
model_cache::clear();
}
@@ -414,7 +414,7 @@ class access_Core {
static function verify_csrf() {
$input = Input::instance();
if ($input->post("csrf", $input->get("csrf", null)) !== Session::instance()->get("csrf")) {
self::forbidden();
access::forbidden();
}
}
@@ -437,7 +437,7 @@ class access_Core {
* @return string
*/
static function csrf_form_field() {
return "<input type=\"hidden\" name=\"csrf\" value=\"" . self::csrf_token() . "\"/>";
return "<input type=\"hidden\" name=\"csrf\" value=\"" . access::csrf_token() . "\"/>";
}
/**
@@ -488,7 +488,7 @@ class access_Core {
"ALTER TABLE {access_intents} ADD `$field` BINARY DEFAULT NULL");
db::build()
->update("access_intents")
->set($field, self::DENY)
->set($field, access::DENY)
->where("item_id", "=", 1)
->execute();
model_cache::clear();
@@ -517,12 +517,12 @@ class access_Core {
// DENY and this ALLOW cannot be obeyed. So in that case, back up the tree and find any
// non-DEFAULT and non-ALLOW parent and propagate from there. If we can't find a matching
// item, then its safe to propagate from here.
if ($access->$field !== self::DENY) {
if ($access->$field !== access::DENY) {
$tmp_item = ORM::factory("item")
->where("left_ptr", "<", $item->left_ptr)
->where("right_ptr", ">", $item->right_ptr)
->join("access_intents", "access_intents.item_id", "items.id")
->where("access_intents.$field", "=", self::DENY)
->where("access_intents.$field", "=", access::DENY)
->order_by("left_ptr", "DESC")
->limit(1)
->find();
@@ -537,7 +537,7 @@ class access_Core {
// that we can tell which permissions have been changed, and which ones need to be updated.
db::build()
->update("items")
->set($field, self::UNKNOWN)
->set($field, access::UNKNOWN)
->where("left_ptr", ">=", $item->left_ptr)
->where("right_ptr", "<=", $item->right_ptr)
->execute();
@@ -548,20 +548,20 @@ class access_Core {
->where("left_ptr", ">=", $item->left_ptr)
->where("right_ptr", "<=", $item->right_ptr)
->where("type", "=", "album")
->where("access_intents.$field", "IS NOT", self::INHERIT)
->where("access_intents.$field", "IS NOT", access::INHERIT)
->order_by("level", "DESC")
->find_all();
foreach ($query as $row) {
if ($row->$field == self::ALLOW) {
if ($row->$field == access::ALLOW) {
// Propagate ALLOW for any row that is still UNKNOWN.
db::build()
->update("items")
->set($field, $row->$field)
->where($field, "IS", self::UNKNOWN) // UNKNOWN is NULL so we have to use IS
->where($field, "IS", access::UNKNOWN) // UNKNOWN is NULL so we have to use IS
->where("left_ptr", ">=", $row->left_ptr)
->where("right_ptr", "<=", $row->right_ptr)
->execute();
} else if ($row->$field == self::DENY) {
} else if ($row->$field == access::DENY) {
// DENY overwrites everything below it
db::build()
->update("items")
@@ -577,8 +577,8 @@ class access_Core {
// the hierarchy, and all of those are safe to change to ALLOW.
db::build()
->update("items")
->set($field, self::ALLOW)
->where($field, "IS", self::UNKNOWN) // UNKNOWN is NULL so we have to use IS
->set($field, access::ALLOW)
->where($field, "IS", access::UNKNOWN) // UNKNOWN is NULL so we have to use IS
->where("left_ptr", ">=", $item->left_ptr)
->where("right_ptr", "<=", $item->right_ptr)
->execute();
@@ -605,12 +605,12 @@ class access_Core {
//
// @todo To optimize this, we wouldn't need to propagate from the parent, we could just
// propagate from here with the parent's intent.
if ($access->$field === self::INHERIT) {
if ($access->$field === access::INHERIT) {
$tmp_item = ORM::factory("item")
->join("access_intents", "items.id", "access_intents.item_id")
->where("left_ptr", "<", $item->left_ptr)
->where("right_ptr", ">", $item->right_ptr)
->where($field, "IS NOT", self::UNKNOWN) // UNKNOWN is NULL so we have to use IS NOT
->where($field, "IS NOT", access::UNKNOWN) // UNKNOWN is NULL so we have to use IS NOT
->order_by("left_ptr", "DESC")
->limit(1)
->find();
@@ -626,11 +626,11 @@ class access_Core {
->join("items", "items.id", "access_intents.item_id")
->where("left_ptr", ">=", $item->left_ptr)
->where("right_ptr", "<=", $item->right_ptr)
->where($field, "IS NOT", self::INHERIT)
->where($field, "IS NOT", access::INHERIT)
->order_by("level", "ASC")
->find_all();
foreach ($query as $row) {
$value = ($row->$field === self::ALLOW) ? true : false;
$value = ($row->$field === access::ALLOW) ? true : false;
db::build()
->update("access_caches")
->set($field, $value)
@@ -683,7 +683,7 @@ class access_Core {
}
foreach ($dirs as $dir) {
if ($value === self::DENY) {
if ($value === access::DENY) {
$fp = fopen("$dir/.htaccess", "w+");
fwrite($fp, "<IfModule mod_rewrite.c>\n");
fwrite($fp, " RewriteEngine On\n");

View File

@@ -74,13 +74,13 @@ class auth_Core {
}
static function validate_too_many_failed_logins($name_input) {
if (self::too_many_failures($name_input->value)) {
if (auth::too_many_failures($name_input->value)) {
$name_input->add_error("too_many_failed_logins", 1);
}
}
static function validate_too_many_failed_auth_attempts($form_input) {
if (self::too_many_failures(identity::active_user()->name)) {
if (auth::too_many_failures(identity::active_user()->name)) {
$form_input->add_error("too_many_failed_auth_attempts", 1);
}
}

View File

@@ -27,10 +27,10 @@ class block_manager_Core {
}
static function add($location, $module_name, $block_id) {
$blocks = self::get_active($location);
$blocks = block_manager::get_active($location);
$blocks[rand()] = array($module_name, $block_id);
self::set_active($location, $blocks);
block_manager::set_active($location, $blocks);
}
static function activate_blocks($module_name) {
@@ -38,25 +38,25 @@ class block_manager_Core {
if (method_exists($block_class, "get_site_list")) {
$blocks = call_user_func(array($block_class, "get_site_list"));
foreach (array_keys($blocks) as $block_id) {
self::add("site_sidebar", $module_name, $block_id);
block_manager::add("site_sidebar", $module_name, $block_id);
}
}
}
static function remove($location, $block_id) {
$blocks = self::get_active($location);
$blocks = block_manager::get_active($location);
unset($blocks[$block_id]);
self::set_active($location, $blocks);
block_manager::set_active($location, $blocks);
}
static function remove_blocks_for_module($location, $module_name) {
$blocks = self::get_active($location);
$blocks = block_manager::get_active($location);
foreach ($blocks as $key => $block) {
if ($block[0] == $module_name) {
unset($blocks[$key]);
}
}
self::set_active($location, $blocks);
block_manager::set_active($location, $blocks);
}
static function deactivate_blocks($module_name) {
@@ -64,14 +64,14 @@ class block_manager_Core {
if (method_exists($block_class, "get_site_list")) {
$blocks = call_user_func(array($block_class, "get_site_list"));
foreach (array_keys($blocks) as $block_id) {
self::remove_blocks_for_module("site_sidebar", $module_name);
block_manager::remove_blocks_for_module("site_sidebar", $module_name);
}
}
if (method_exists($block_class, "get_admin_list")) {
$blocks = call_user_func(array($block_class, "get_admin_list"));
foreach (array("dashboard_sidebar", "dashboard_center") as $location) {
self::remove_blocks_for_module($location, $module_name);
block_manager::remove_blocks_for_module($location, $module_name);
}
}
}
@@ -99,7 +99,7 @@ class block_manager_Core {
}
static function get_html($location, $theme=null) {
$active = self::get_active($location);
$active = block_manager::get_active($location);
$result = "";
foreach ($active as $id => $desc) {
if (method_exists("$desc[0]_block", "get")) {

View File

@@ -82,7 +82,7 @@ class gallery_block_Core {
case "block_adder":
$block->css_id = "g-block-adder";
$block->title = t("Dashboard content");
$block->content = self::get_add_block_form();
$block->content = gallery_block::get_add_block_form();
break;
case "language":

View File

@@ -50,7 +50,7 @@ class graphics_Core {
$rule->active = true;
$rule->save();
self::mark_dirty($target == "thumb", $target == "resize");
graphics::mark_dirty($target == "thumb", $target == "resize");
}
/**
@@ -67,7 +67,7 @@ class graphics_Core {
->where("operation", "=", $operation)
->execute();
self::mark_dirty($target == "thumb", $target == "resize");
graphics::mark_dirty($target == "thumb", $target == "resize");
}
/**
@@ -80,7 +80,7 @@ class graphics_Core {
->where("module_name", "=", $module_name)
->execute();
if (count($status)) {
self::mark_dirty(true, true);
graphics::mark_dirty(true, true);
}
}
@@ -252,7 +252,7 @@ class graphics_Core {
$db->execute();
}
$count = self::find_dirty_images_query()->count_records();
$count = graphics::find_dirty_images_query()->count_records();
if ($count) {
site_status::warning(
t2("One of your photos is out of date. <a %attrs>Click here to fix it</a>",

View File

@@ -61,7 +61,7 @@ class identity_Core {
$session = Session::instance();
if (!($user = $session->get("user"))) {
self::set_active_user($user = self::guest());
identity::set_active_user($user = self::guest());
}
// The installer cannot set a user into the session, so it just sets an id which we should
@@ -127,7 +127,7 @@ class identity_Core {
$session = Session::instance();
$session->set("user", $user);
$session->delete("group_ids");
self::load_user();
identity::load_user();
}
/**

View File

@@ -40,14 +40,14 @@ class l10n_client_Core {
}
static function server_uid($api_key=null) {
$api_key = $api_key == null ? self::api_key() : $api_key;
$api_key = $api_key == null ? l10n_client::api_key() : $api_key;
$parts = explode(":", $api_key);
return empty($parts) ? 0 : $parts[0];
}
private static function _sign($payload, $api_key=null) {
$api_key = $api_key == null ? self::api_key() : $api_key;
return md5($api_key . $payload . self::client_token());
$api_key = $api_key == null ? l10n_client::api_key() : $api_key;
return md5($api_key . $payload . l10n_client::client_token());
}
static function validate_api_key($api_key) {
@@ -57,9 +57,9 @@ class l10n_client_Core {
list ($response_data, $response_status) = remote::post(
$url, array("version" => $version,
"client_token" => self::client_token(),
"client_token" => l10n_client::client_token(),
"signature" => $signature,
"uid" => self::server_uid($api_key)));
"uid" => l10n_client::server_uid($api_key)));
if (!remote::success($response_status)) {
return false;
}
@@ -215,9 +215,9 @@ class l10n_client_Core {
list ($response_data, $response_status) = remote::post(
$url, array("data" => $request_data,
"client_token" => self::client_token(),
"client_token" => l10n_client::client_token(),
"signature" => $signature,
"uid" => self::server_uid()));
"uid" => l10n_client::server_uid()));
if (!remote::success($response_status)) {
throw new Exception("@todo TRANSLATIONS_SUBMISSION_FAILED " . $response_status);

View File

@@ -212,7 +212,7 @@ class locales_Core {
}
private static function _locale_match_score($requested_locale, $qvalue, $adjustment_factor) {
$installed = self::installed();
$installed = locales::installed();
if (isset($installed[$requested_locale])) {
return array($requested_locale, $qvalue);
}
@@ -227,14 +227,14 @@ class locales_Core {
static function set_request_locale() {
// 1. Check the session specific preference (cookie)
$locale = self::cookie_locale();
$locale = locales::cookie_locale();
// 2. Check the user's preference
if (!$locale) {
$locale = identity::active_user()->locale;
}
// 3. Check the browser's / OS' preference
if (!$locale) {
$locale = self::locale_from_http_request();
$locale = locales::locale_from_http_request();
}
// If we have any preference, override the site's default locale
if ($locale) {

View File

@@ -30,7 +30,7 @@ class log_Core {
* @param string $html an html snippet presented alongside the log message to aid the admin
*/
static function success($category, $message, $html="") {
self::_add($category, $message, $html, self::SUCCESS);
self::_add($category, $message, $html, log::SUCCESS);
}
/**
@@ -40,7 +40,7 @@ class log_Core {
* @param string $html an html snippet presented alongside the log message to aid the admin
*/
static function info($category, $message, $html="") {
self::_add($category, $message, $html, self::INFO);
self::_add($category, $message, $html, log::INFO);
}
/**
@@ -50,7 +50,7 @@ class log_Core {
* @param string $html an html snippet presented alongside the log message to aid the admin
*/
static function warning($category, $message, $html="") {
self::_add($category, $message, $html, self::WARNING);
self::_add($category, $message, $html, log::WARNING);
}
/**
@@ -60,7 +60,7 @@ class log_Core {
* @param string $html an html snippet presented alongside the log message to aid the admin
*/
static function error($category, $message, $html="") {
self::_add($category, $message, $html, self::ERROR);
self::_add($category, $message, $html, log::ERROR);
}
/**
@@ -92,16 +92,16 @@ class log_Core {
*/
static function severity_class($severity) {
switch($severity) {
case self::SUCCESS:
case log::SUCCESS:
return "g-success";
case self::INFO:
case log::INFO:
return "g-info";
case self::WARNING:
case log::WARNING:
return "g-warning";
case self::ERROR:
case log::ERROR:
return "g-error";
}
}

View File

@@ -28,7 +28,7 @@ class message_Core {
* @param string $msg a detailed message
*/
static function success($msg) {
self::_add($msg, self::SUCCESS);
self::_add($msg, message::SUCCESS);
}
/**
@@ -36,7 +36,7 @@ class message_Core {
* @param string $msg a detailed message
*/
static function info($msg) {
self::_add($msg, self::INFO);
self::_add($msg, message::INFO);
}
/**
@@ -44,7 +44,7 @@ class message_Core {
* @param string $msg a detailed message
*/
static function warning($msg) {
self::_add($msg, self::WARNING);
self::_add($msg, message::WARNING);
}
/**
@@ -52,7 +52,7 @@ class message_Core {
* @param string $msg a detailed message
*/
static function error($msg) {
self::_add($msg, self::ERROR);
self::_add($msg, message::ERROR);
}
/**
@@ -79,7 +79,7 @@ class message_Core {
$messages = Session::instance()->get_once("messages", array());
foreach ($messages as $msg) {
$msg[0] = str_replace("__CSRF__", access::csrf_token(), $msg[0]);
$buf[] = "<li class=\"" . self::severity_class($msg[1]) . "\">$msg[0]</li>";
$buf[] = "<li class=\"" . message::severity_class($msg[1]) . "\">$msg[0]</li>";
}
if ($buf) {
return "<ul id=\"g-action-status\" class=\"g-message-block\">" . implode("", $buf) . "</ul>";
@@ -93,16 +93,16 @@ class message_Core {
*/
static function severity_class($severity) {
switch($severity) {
case self::SUCCESS:
case message::SUCCESS:
return "g-success";
case self::INFO:
case message::INFO:
return "g-info";
case self::WARNING:
case message::WARNING:
return "g-warning";
case self::ERROR:
case message::ERROR:
return "g-error";
}
}

View File

@@ -35,7 +35,7 @@ class module_Core {
* @param integer $version
*/
static function set_version($module_name, $version) {
$module = self::get($module_name);
$module = module::get($module_name);
if (!$module->loaded()) {
$module->name = $module_name;
$module->active = $module_name == "gallery"; // only gallery is active by default
@@ -62,7 +62,7 @@ class module_Core {
* not found
*/
static function info($module_name) {
$module_list = self::available();
$module_list = module::available();
return isset($module_list->$module_name) ? $module_list->$module_name : false;
}
@@ -94,10 +94,10 @@ class module_Core {
$modules->$module_name =
new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS);
$m =& $modules->$module_name;
$m->installed = self::is_installed($module_name);
$m->active = self::is_active($module_name);
$m->installed = module::is_installed($module_name);
$m->active = module::is_active($module_name);
$m->code_version = $m->version;
$m->version = self::get_version($module_name);
$m->version = module::get_version($module_name);
$m->locked = false;
if ($m->active && $m->version != $m->code_version) {
@@ -107,7 +107,7 @@ class module_Core {
// Lock certain modules
$modules->gallery->locked = true;
$identity_module = self::get_var("gallery", "identity_provider", "user");
$identity_module = module::get_var("gallery", "identity_provider", "user");
$modules->$identity_module->locked = true;
$modules->ksort();
self::$available = $modules;
@@ -258,7 +258,7 @@ class module_Core {
call_user_func_array(array($installer_class, "activate"), array());
}
$module = self::get($module_name);
$module = module::get($module_name);
if ($module->loaded()) {
$module->active = true;
$module->save();
@@ -285,7 +285,7 @@ class module_Core {
call_user_func_array(array($installer_class, "deactivate"), array());
}
$module = self::get($module_name);
$module = module::get($module_name);
if ($module->loaded()) {
$module->active = false;
$module->save();
@@ -312,7 +312,7 @@ class module_Core {
}
graphics::remove_rules($module_name);
$module = self::get($module_name);
$module = module::get($module_name);
if ($module->loaded()) {
$module->delete();
}
@@ -532,6 +532,6 @@ class module_Core {
* @param string $module_name
*/
static function get_version($module_name) {
return self::get($module_name)->version;
return module::get($module_name)->version;
}
}

View File

@@ -58,7 +58,7 @@ class movie_Core {
}
static function extract_frame($input_file, $output_file) {
$ffmpeg = self::find_ffmpeg();
$ffmpeg = movie::find_ffmpeg();
if (empty($ffmpeg)) {
throw new Exception("@todo MISSING_FFMPEG");
}
@@ -103,7 +103,7 @@ class movie_Core {
* Return the width, height, mime_type and extension of the given movie file.
*/
static function get_file_metadata($file_path) {
$ffmpeg = self::find_ffmpeg();
$ffmpeg = movie::find_ffmpeg();
if (empty($ffmpeg)) {
throw new Exception("@todo MISSING_FFMPEG");
}

View File

@@ -101,7 +101,7 @@ class site_status_Core {
$buf = array();
foreach (ORM::factory("message")->find_all() as $msg) {
$value = str_replace("__CSRF__", access::csrf_token(), $msg->value);
$buf[] = "<li class=\"" . self::severity_class($msg->severity) . "\">$value</li>";
$buf[] = "<li class=\"" . site_status::severity_class($msg->severity) . "\">$value</li>";
}
if ($buf) {
@@ -116,16 +116,16 @@ class site_status_Core {
*/
static function severity_class($severity) {
switch($severity) {
case self::SUCCESS:
case site_status::SUCCESS:
return "g-success";
case self::INFO:
case site_status::INFO:
return "g-info";
case self::WARNING:
case site_status::WARNING:
return "g-warning";
case self::ERROR:
case site_status::ERROR:
return "g-error";
}
}