Example #1
0
 /** @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);
     }
 }
 public function create()
 {
     access::verify_csrf();
     $form = $this->_get_theme_form();
     if ($form->validate()) {
         $session = Session::instance();
         $extract_path = $session->get_once("theme_extract_path");
         $v = new View("admin_themeroller_progress.html");
         $task_def = Task_Definition::factory()->callback("themeroller_task::create_theme")->description(t("Generate theme from a themeroller archive"))->name(t("Generate theme"));
         $v->task = task::create($task_def, array("path" => $extract_path, "user_name" => SafeString::purify(identity::active_user()->name), "original_name" => SafeString::purify($form->theme->original->value), "theme_name" => SafeString::purify($form->theme->theme_name->value), "display_name" => SafeString::purify($form->theme->display_name->value), "description" => SafeString::purify($form->theme->description->value), "author_url" => SafeString::purify($form->theme->author_url->value), "info_url" => SafeString::purify($form->theme->info_url->value), "discuss_url" => SafeString::purify($form->theme->discuss_url->value), "is_admin" => $session->get("themeroller_is_admin")));
         json::reply(array("html" => (string) $v));
     } else {
         json::reply(array("result" => "error", "html" => (string) $form));
     }
 }
Example #3
0
 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;
     }
 }
Example #4
0
 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;
 }
Example #5
0
 /**
  * Escapes the given string for use in JavaScript.
  *
  * Example:<pre>
  *   <script type="text/javascript>"
  *     var some_js_string = <?= html::js_string($php_string) ?>;
  *   </script>
  * </pre>
  */
 static function js_string($string)
 {
     return SafeString::of($string)->for_js();
 }
Example #6
0
 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>";
 }
Example #7
0
 public static function test()
 {
     parent::registerClass('SafeStringTestUnwrap');
 }
 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);
 }
Example #9
0
 /**
  * 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);
 }
 public static function test()
 {
     parent::registerClass('Wrapper');
 }
Example #11
0
 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;
 }
Example #12
0
 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&#039;s <p  >world</p>", $safe_string);
 }
Example #13
0
 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 '';
     }
 }