/** @todo combine with Admin_Users_Controller::_add_locale_dropdown */ private function _add_locale_dropdown(&$form, $user = null) { $locales = locales::installed(); foreach ($locales as $locale => $display_name) { $locales[$locale] = SafeString::of_safe_html($display_name); } if (count($locales) > 1) { // Put "none" at the first position in the array $locales = array_merge(array("" => t("« none »")), $locales); $selected_locale = $user && $user->locale ? $user->locale : ""; $form->dropdown("locale")->label(t("Language Preference"))->options($locales)->selected($selected_locale); } }
static function sidebar_blocks($theme) { $locales = locales::installed(); foreach ($locales as $locale => $display_name) { $locales[$locale] = SafeString::of_safe_html($display_name); } if (count($locales) > 1) { $block = new Block(); $block->css_id = "gUserLanguageBlock"; $block->title = t("Select Language Preference"); $block->content = new View("user_languages_block.html"); $block->content->installed_locales = array_merge(array("" => t("« none »")), $locales); $block->content->selected = (string) user::cookie_locale(); return $block; } }
static function get($block_id, $theme) { $block = ""; switch ($block_id) { case "language": $locales = locales::installed(); foreach ($locales as $locale => $display_name) { $locales[$locale] = SafeString::of_safe_html($display_name); } if (count($locales) > 1) { $block = new Block(); $block->css_id = "g-user-language-block"; $block->title = t("Language Preference"); $block->content = new View("user_languages_block.html"); $block->content->installed_locales = array_merge(array("" => t("« none »")), $locales); $block->content->selected = (string) user::cookie_locale(); } break; } return $block; }
/** * Flags the given string as safe to be used in HTML (free of malicious HTML/JS). * * Example:<pre> * // Parameters to t() are automatically escaped by default. * // If the parameter is marked as clean, it won't get escaped. * t('Go <a href="%url">there</a>', * array("url" => html::mark_clean(url::current()))) * </pre> */ static function mark_clean($html) { return SafeString::of_safe_html($html); }
static function credits() { $version_string = SafeString::of_safe_html('<bdo dir="ltr">Gallery ' . gallery::version_string() . '</bdo>'); return "<li class=\"g-first\">" . t(module::get_var("gallery", "credits"), array("url" => "http://gallery.menalto.com", "gallery_version" => $version_string)) . "</li>"; }
public function safestring_of_safestring_safe_status_override_test() { $safe_string = new SafeString("hello <p>world</p>"); $safe_string_2 = SafeString::of_safe_html($safe_string); $this->assert_equal("hello <p>world</p>", $safe_string_2); }
/** * Translates a localizable message. * * Security: * The returned string is safe for use in HTML (it contains a safe subset of HTML and * interpolation parameters are converted to HTML entities). * For use in JavaScript, please call ->for_js() on it. * * @param $message String|array The message to be translated. E.g. "Hello world" * or array("one" => "One album", "other" => "%count albums") * @param $options array (optional) Options array for key value pairs which are used * for pluralization and interpolation. Special keys are "count" and "locale", * the latter to override the currently configured locale. * @return String The translated message string. */ public function translate($message, $options = array()) { $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; $count = isset($options['count']) ? $options['count'] : null; $values = $options; unset($values['locale']); $this->log($message, $options); $entry = $this->lookup($locale, $message); if (null === $entry) { // Default to the root locale. $entry = $message; $locale = $this->_config['root_locale']; } $entry = $this->pluralize($locale, $entry, $count); $entry = $this->interpolate($locale, $entry, $values); return SafeString::of_safe_html($entry); }
static function get($block_id) { $block = new Block(); switch ($block_id) { case "welcome": $block->css_id = "g-welcome"; $block->title = t("Welcome to Gallery 3"); $block->content = new View("admin_block_welcome.html"); break; case "photo_stream": $block->css_id = "g-photo-stream"; $block->title = t("Photo Stream"); $block->content = new View("admin_block_photo_stream.html"); $block->content->photos = ORM::factory("item")->where("type", "photo")->orderby("created", "DESC")->find_all(10); break; case "log_entries": $block->css_id = "g-log-entries"; $block->title = t("Log Entries"); $block->content = new View("admin_block_log_entries.html"); $block->content->entries = ORM::factory("log")->orderby(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5); break; case "stats": $block->css_id = "g-stats"; $block->title = t("Gallery Stats"); $block->content = new View("admin_block_stats.html"); $block->content->album_count = ORM::factory("item")->where("type", "album")->where("id <>", 1)->count_all(); $block->content->photo_count = ORM::factory("item")->where("type", "photo")->count_all(); break; case "platform_info": $block->css_id = "g-platform"; $block->title = t("Platform Information"); $block->content = new View("admin_block_platform.html"); if (is_readable("/proc/loadavg")) { $block->content->load_average = join(" ", array_slice(split(" ", array_shift(file("/proc/loadavg"))), 0, 3)); } else { $block->content->load_average = t("Unavailable"); } break; case "project_news": $block->css_id = "g-project-news"; $block->title = t("Gallery Project News"); $block->content = new View("admin_block_news.html"); $block->content->feed = feed::parse("http://gallery.menalto.com/node/feed", 3); break; case "block_adder": $block->css_id = "g-block-adder"; $block->title = t("Dashboard Content"); $block->content = self::get_add_block_form(); break; case "language": $locales = locales::installed(); if (count($locales)) { foreach ($locales as $locale => $display_name) { $locales[$locale] = SafeString::of_safe_html($display_name); } $block = new Block(); $block->css_id = "g-user-language-block"; $block->title = t("Language Preference"); $block->content = new View("user_languages_block.html"); $block->content->installed_locales = array_merge(array("" => t("« none »")), $locales); $block->content->selected = (string) locales::cookie_locale(); } else { $block = ""; } break; } return $block; }
public function clean_attribute_test() { $safe_string = SafeString::of_safe_html("hello's <p >world</p>"); $safe_string = html::clean_attribute($safe_string); $this->assert_equal("hello's <p >world</p>", $safe_string); }
static function get($block_id) { $block = new Block(); switch ($block_id) { case "welcome": $block->css_id = "g-welcome"; $block->title = t("Welcome to Gallery 3"); $block->content = new View("admin_block_welcome.html"); break; case "photo_stream": $block->css_id = "g-photo-stream"; $block->title = t("Photo stream"); $block->content = new View("admin_block_photo_stream.html"); $block->content->photos = ORM::factory("item")->where("type", "=", "photo")->order_by("created", "DESC")->find_all(10); break; case "log_entries": $block->css_id = "g-log-entries"; $block->title = t("Log entries"); $block->content = new View("admin_block_log_entries.html"); $block->content->entries = ORM::factory("log")->order_by(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5); break; case "stats": $block->css_id = "g-stats"; $block->title = t("Gallery stats"); $block->content = new View("admin_block_stats.html"); $block->content->album_count = ORM::factory("item")->where("type", "=", "album")->where("id", "<>", 1)->count_all(); $block->content->photo_count = ORM::factory("item")->where("type", "=", "photo")->count_all(); break; case "platform_info": $block->css_id = "g-platform"; $block->title = t("Platform information"); $block->content = new View("admin_block_platform.html"); break; case "project_news": $block->css_id = "g-project-news"; $block->title = t("Gallery project news"); $block->content = new View("admin_block_news.html"); $block->content->feed = feed::parse("http://gallery.menalto.com/node/feed", 3); break; case "block_adder": $block->css_id = "g-block-adder"; $block->title = t("Dashboard content"); $block->content = gallery_block::get_add_block_form(); break; case "language": $locales = locales::installed(); if (count($locales) > 1) { foreach ($locales as $locale => $display_name) { $locales[$locale] = SafeString::of_safe_html($display_name); } $block = new Block(); $block->css_id = "g-user-language-block"; $block->title = t("Language preference"); $block->content = new View("user_languages_block.html"); $block->content->installed_locales = array_merge(array("" => t("« none »")), $locales); $block->content->selected = (string) locales::cookie_locale(); } else { $block = ""; } break; case "upgrade_checker": $block = new Block(); $block->css_id = "g-upgrade-available-block"; $block->title = t("Check for Gallery upgrades"); $block->content = new View("upgrade_checker_block.html"); $block->content->version_info = upgrade_checker::version_info(); $block->content->auto_check_enabled = upgrade_checker::auto_check_enabled(); $block->content->new_version = upgrade_checker::get_upgrade_message(); } return $block; }
public function credits() { if (module::get_var("gallery", "show_credits")) { $version_string = SafeString::of_safe_html('Gallery ' . gallery::VERSION); return '<ul id="g-credits">' . '<li class="g-branding"><a id="g-gallery-logo" href="http://gallery.menalto.com" title="' . $version_string . '"></a>' . '<a id="g-theme-logo" href="http://codex.gallery2.org/Gallery3:Themes:greydragon" target="_blank" title="' . $this->themename . ' ' . $this->themeversion . ' (' . $this->colorpack . ')"></a></li>' . gallery_theme::credits() . '</ul>'; } else { return ''; } }