From c4f991bb7d7e90f8c55897f89888d9196c7e438f Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 28 Jun 2009 19:45:11 -0700 Subject: Clean up the combined javascript change and refactor out the Gallery_View base class from Theme_View and Admin_View. 1) Move all the theme specific jquery stuff from gallery_theme::head() and admin_head() into the theme files. Use $theme->script() as appropriate. 2) Get rid of the extra boolean on $theme->url() that we were using so that we could call $theme->script($theme->url(...)) -- add $theme->theme_script() instead (poorly named, but still clearer than what we had before) 3) Fix the bug that combined scripts didn't work at all in the admin theme. 4) Get rid of $theme->display() in favor of new View(...) --- modules/gallery/libraries/Admin_View.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'modules/gallery/libraries/Admin_View.php') diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index 7a7396eb..01496c0d 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -17,9 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Admin_View_Core extends View { - private $theme_name = null; - +class Admin_View_Core extends Gallery_View { /** * Attempts to load a view and pre-load view data. * @@ -46,15 +44,6 @@ class Admin_View_Core extends View { $this->set_global("user", user::active()); } - public function url($path, $absolute_url=false) { - $arg = "themes/{$this->theme_name}/$path"; - return $absolute_url ? url::abs_file($arg) : url::file($arg); - } - - public function display($page_name, $view_class="View") { - return new $view_class($page_name); - } - public function admin_menu() { $menu = Menu::factory("root"); gallery_menu::admin($menu, $this); @@ -109,6 +98,10 @@ class Admin_View_Core extends View { } } + if ($function == "admin_head") { + array_unshift($blocks, $this->combine_script()); + } + if (Session::instance()->get("debug")) { if ($function != "admin_head") { array_unshift( -- cgit v1.2.3 From 34c76c0906a639321dedfe0e77d9fd123ed7c792 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 29 Jun 2009 12:32:11 -0700 Subject: A Combined javascript seems to work. 1) CSS files are added to the combined version by use of $theme->css() or $theme->css_theme() methods 2) url references in the css are converted to full paths as opposed to relative 3) @import statements in the css are resolved as well. 4) need to move the [if IE] statements into the css files so the will be honored in the browser. currently the ie fix css are always included. --- modules/gallery/controllers/combined.php | 5 --- modules/gallery/libraries/Admin_View.php | 1 + modules/gallery/libraries/Gallery_View.php | 54 ++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 23 deletions(-) (limited to 'modules/gallery/libraries/Admin_View.php') diff --git a/modules/gallery/controllers/combined.php b/modules/gallery/controllers/combined.php index 50fe77c4..399a60f4 100644 --- a/modules/gallery/controllers/combined.php +++ b/modules/gallery/controllers/combined.php @@ -99,10 +99,5 @@ class Combined_Controller extends Controller { Kohana::close_buffers(false); print $content; } - - public function __call($function, $args) { - array_unshift($args, $function); - print ""; - } } diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index 01496c0d..5e0d5feb 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -99,6 +99,7 @@ class Admin_View_Core extends Gallery_View { } if ($function == "admin_head") { + array_unshift($blocks, $this->combine_css()); array_unshift($blocks, $this->combine_script()); } diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php index 1c1dec38..b4cfde46 100644 --- a/modules/gallery/libraries/Gallery_View.php +++ b/modules/gallery/libraries/Gallery_View.php @@ -113,7 +113,6 @@ class Gallery_View_Core extends View { protected function combine_css() { $links = array(); $key = ""; - static $PATTERN = "#url\(\s*['|\"]{0,1}(.*?)['|\"]{0,1}\s*\)#"; foreach (array_keys($this->css) as $file) { $path = DOCROOT . $file; @@ -130,27 +129,12 @@ class Gallery_View_Core extends View { $key = md5($key); $cache = Cache::instance(); $contents = $cache->get($key); - $docroot_length = strlen(DOCROOT); + $contents = ""; if (empty($contents)) { $contents = ""; foreach ($links as $link) { - $css = file_get_contents($link); - if (preg_match_all($PATTERN, $css, $matches, PREG_SET_ORDER)) { - $search = $replace = array(); - foreach ($matches as $match) { - $relative = substr(realpath(dirname($link) . "/$match[1]"), $docroot_length); - if (!empty($relative)) { - $search[] = $match[1]; - $replace[] = url::abs_file($relative); - } else { - Kohana::log("alert", sprintf("Missing URL reference '%s' in CSS file '%s' ", - $match[1], $link)); - } - } - $css = str_replace($search, $replace, $css); - } - $contents .= $css; + $contents .= $this->process_css($link); } $cache->set($key, $contents, array("css"), 30 * 84600); if (function_exists("gzencode")) { @@ -162,4 +146,38 @@ class Gallery_View_Core extends View { url::site("combined/css/$key") . "\" />"; } + private function process_css($css_file) { + static $PATTERN = "#url\(\s*['|\"]{0,1}(.*?)['|\"]{0,1}\s*\)#"; + $docroot_length = strlen(DOCROOT); + + $css = file_get_contents($css_file); + if (preg_match_all($PATTERN, $css, $matches, PREG_SET_ORDER)) { + $search = $replace = array(); + foreach ($matches as $match) { + $relative = substr(realpath(dirname($css_file) . "/$match[1]"), $docroot_length); + if (!empty($relative)) { + $search[] = $match[0]; + $replace[] = "url('" . url::abs_file($relative) . "')"; + } else { + Kohana::log("alert", sprintf("Missing URL reference '%s' in CSS file '%s' ", + $match[1], $css_file)); + } + } + $css = str_replace($search, $replace, $css); + } + $imports = preg_match_all("#@import\s*['|\"]{0,1}(.*?)['|\"]{0,1};#", + $css, $matches, PREG_SET_ORDER); + + if ($imports) { + $search = $replace = array(); + foreach ($matches as $match) { + Kohana::log("error", dirname($css_file) . "/$match[1]"); + $search[] = $match[0]; + $replace[] = $this->process_css(dirname($css_file) . "/$match[1]"); + } + $css = str_replace($search, $replace, $css); + } + + return $css; + } } \ No newline at end of file -- cgit v1.2.3 From fa8ca2f7ad21980f0b45e7acc67be4be296f9f87 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 29 Jun 2009 18:12:53 -0700 Subject: Refactor combine_xxx() functions together into combine_files() and use html functions to generate the resulting elements. Add phpdoc. --- modules/gallery/controllers/combined.php | 2 + modules/gallery/libraries/Admin_View.php | 6 +-- modules/gallery/libraries/Gallery_View.php | 81 ++++++++++-------------------- modules/gallery/libraries/Theme_View.php | 4 +- 4 files changed, 34 insertions(+), 59 deletions(-) (limited to 'modules/gallery/libraries/Admin_View.php') diff --git a/modules/gallery/controllers/combined.php b/modules/gallery/controllers/combined.php index f6c6d60b..9df74638 100644 --- a/modules/gallery/controllers/combined.php +++ b/modules/gallery/controllers/combined.php @@ -22,6 +22,7 @@ class Combined_Controller extends Controller { * Return the combined Javascript bundle associated with the given key. */ public function javascript($key) { + $key = substr($key, 0, strlen($key) - 3); // strip off the trailing .js return $this->_emit("javascript", $key); } @@ -29,6 +30,7 @@ class Combined_Controller extends Controller { * Return the combined CSS bundle associated with the given key. */ public function css($key) { + $key = substr($key, 0, strlen($key) - 4); // strip off the trailing .css return $this->_emit("css", $key); } diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index 5e0d5feb..f7de96bf 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -98,9 +98,9 @@ class Admin_View_Core extends Gallery_View { } } - if ($function == "admin_head") { - array_unshift($blocks, $this->combine_css()); - array_unshift($blocks, $this->combine_script()); + if ($function == "head") { + array_unshift($blocks, $this->combine_files($this->css, "css")); + array_unshift($blocks, $this->combine_files($this->css, "javascript")); } if (Session::instance()->get("debug")) { diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php index 9d4fe5c0..48cf8089 100644 --- a/modules/gallery/libraries/Gallery_View.php +++ b/modules/gallery/libraries/Gallery_View.php @@ -49,45 +49,6 @@ class Gallery_View_Core extends View { return $absolute_url ? url::abs_file($arg) : url::file($arg); } - /** - * Combine a series of Javascript files into a single one and cache it in the database, then - * return a single "; - } - /** * Add a css file to the combined css list. * @param $file the relative path to a script from the gallery3 directory @@ -107,12 +68,11 @@ class Gallery_View_Core extends View { } /** - * Combine a series of Javascript files into a single one and cache it in the database, then - * return a single