[geeklog-hg] geeklog: Renamed CTL_plugin_themebaseURL to CTL_plugin_themeFind...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sun May 24 12:41:32 EDT 2015


changeset 9601:595a1a779ea6
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/595a1a779ea6
user: Tom
date: Sun May 24 12:40:47 2015 -0400
description:
Renamed CTL_plugin_themebaseURL to CTL_plugin_themeFindFile for a more general description of function.
CTL_plugin_themeFindFile now can return url path or physical path to file.
Plugin Templates that are theme specfic can now have a functions.php file which is similar to theme functions.php. This allows plugin templates to set additional javascript files, javascript librarys and css files.

diffstat:

 plugins/calendar/functions.inc |    2 +-
 plugins/polls/functions.inc    |    2 +-
 system/lib-template.php        |  104 +++++++++++++++++++++++++++++++++++++---
 3 files changed, 98 insertions(+), 10 deletions(-)

diffs (166 lines):

diff -r a7ab804dc464 -r 595a1a779ea6 plugins/calendar/functions.inc
--- a/plugins/calendar/functions.inc	Mon May 11 22:51:24 2015 +0900
+++ b/plugins/calendar/functions.inc	Sun May 24 12:40:47 2015 -0400
@@ -671,7 +671,7 @@
 
     // use the CSS only if we are on the plugin's pages
     if (substr_count ($_SERVER['PHP_SELF'], '/calendar/') > 0) {
-        $_SCRIPTS->setCSSFile('calendar', CTL_plugin_themebaseURL('calendar', 'css', 'style.css'), false);
+        $_SCRIPTS->setCSSFile('calendar', CTL_plugin_themeFindFile('calendar', 'css', 'style.css'), false);
     }
 }
 
diff -r a7ab804dc464 -r 595a1a779ea6 plugins/polls/functions.inc
--- a/plugins/polls/functions.inc	Mon May 11 22:51:24 2015 +0900
+++ b/plugins/polls/functions.inc	Sun May 24 12:40:47 2015 -0400
@@ -1090,7 +1090,7 @@
     // You normally only set the css file when needed but with the possibility of
     // the poll block or autotag being displayed after COM_SiteHeader being called
     // we need to set it just in case
-    $_SCRIPTS->setCSSFile('polls', CTL_plugin_themebaseURL('polls', 'css', 'style.css'));
+    $_SCRIPTS->setCSSFile('polls', CTL_plugin_themeFindFile('polls', 'css', 'style.css'));
 }
 
 
diff -r a7ab804dc464 -r 595a1a779ea6 system/lib-template.php
--- a/system/lib-template.php	Mon May 11 22:51:24 2015 +0900
+++ b/system/lib-template.php	Sun May 24 12:40:47 2015 -0400
@@ -171,35 +171,72 @@
 
 
 /**
-* Get HTML path for a plugin file.
+* Get HTML path for a plugin file (url or physical file location).
+* Order of checking is:
+* - theme path/plugin/file
+* - html path/plugin/directory/file
+* - html path/plugin/directory/theme/file
+* - html path/plugin/directory/default/file
+* - html path/plugin/file (url path only)
+* - plugin path/plugin/directory/theme/file (physical path only)
+* - plugin path/plugin/directory/default/file (physical path only)
 *
 * @param    string  $plugin     name of plugin
 * @param    string  $directory  name of directory
 * @param    string  $filename   name of file
+* @param    boolean $return_url return url path or file path
 * @return   string              full HTML path to file
 *
 */
-function CTL_plugin_themebaseURL($plugin, $directory, $filename)
+function CTL_plugin_themeFindFile($plugin, $directory, $filename, $return_url = true)
 {
     global $_CONF;
+    
+    $retval = "";
 
-    // See if plugin css file exist in current theme
+    // See if plugin file exist in current theme
     $file = "{$_CONF['path_layout']}$plugin/$filename";
     if (file_exists($file)) {
-        $retval = "{$_CONF['layout_url']}/$plugin/$filename";
+    	if ($return_url) {
+    		$retval = "{$_CONF['layout_url']}/$plugin/$filename";
+		} else {
+			$retval = $file;
+		}
     } else {
         // See if current theme templates stored with plugin
         $file = "{$_CONF['path_html']}/$plugin/$directory/{$_CONF['theme']}/$filename";
         if (file_exists($file)) {
-            $retval = "/$plugin/$directory/{$_CONF['theme']}/$filename";
+        	if ($return_url) {
+        		$retval = "/$plugin/$directory/{$_CONF['theme']}/$filename";
+			} else {
+				$retval = $file;
+			}
         } else {
             // Use default templates then. This should always exist
             $file = "{$_CONF['path_html']}/$plugin/$directory/default/$filename";
             if (file_exists($file)) {
-                $retval = "/$plugin/$directory/default/$filename";
+            	if ($return_url) {
+            		$retval = "/$plugin/$directory/default/$filename";
+				} else {
+					$retval = $file;
+				}
             } else {
-                // Last guess for file location
-                $retval = "/$plugin/$filename";
+            	if ($return_url) {
+					// Last guess for URL file location
+					$retval = "/$plugin/$filename";
+				} else {
+					// See if current theme templates stored with plugin
+					$file = "{$_CONF['path']}plugins/$plugin/$directory/{$_CONF['theme']}/$filename";
+					if (file_exists($file)) {
+						$retval = $file;
+					} else {
+						// Use default templates then. This should always exist
+						$file = "{$_CONF['path']}plugins/$plugin/$directory/default/$filename";
+						if (file_exists($file)) {
+							$retval = $file;
+						}
+					}
+				}
             }
         }
     }
@@ -241,6 +278,57 @@
     return $retval;
 }
 
+/**
+* Include plugin template functions file which may/may not do anything or exist.
+* This will currently set any additional css and javascript that is theme specific for a plugin templates
+*
+* @param    string  $plugin     name of plugin
+*
+*/
+function CTL_plugin_setTemplatesFunctions($plugin)
+{
+	global $_SCRIPTS, $_CONF;	
+	
+	$templateFuncutionsLocation = CTL_plugin_themeFindFile($plugin, 'templates', 'functions.php', false);
+	if (!empty($templateFuncutionsLocation) AND file_exists($templateFuncutionsLocation)) {
+		require_once $templateFuncutionsLocation;
+		
+		/* Include scripts on behalf of plugin template files that are theme specfic */
+		$func = $plugin . "_css_" . $_CONF['theme'];
+		if (function_exists($func)) {
+			foreach ($func() as $info) {
+				$file = (!empty($info['file'])) ? $info['file'] : '';
+				$name = (!empty($info['name'])) ? $info['name'] : md5(!empty($file) ? $file : strval(time()));
+				$constant   = (!empty($info['constant']))   ? $info['constant']   : true;
+				$attributes = (!empty($info['attributes'])) ? $info['attributes'] : array();
+				$priority = (!empty($info['priority']))   ? $info['priority']   : 100;
+				$_SCRIPTS->setCssFile($name, $file, $constant, $attributes, $priority, 'theme');
+			}
+		}
+		$func = $plugin . "_js_libs_" . $_CONF['theme'];
+		if (function_exists($func)) {
+			foreach ($func() as $info) {
+				$footer = true;
+				if (isset($info['footer']) && !$info['footer']) {
+					$footer = false;
+				}
+				$_SCRIPTS->setJavaScriptLibrary($info['library'], $footer);
+			}
+		}
+		$func = $plugin . "_js_files_" . $_CONF['theme'];
+		if (function_exists($func)) {
+			foreach ($func() as $info) {
+				$footer = true;
+				if (isset($info['footer']) && !$info['footer']) {
+					$footer = false;
+				}
+				$priority = (!empty($info['priority']))   ? $info['priority']   : 100;
+				$_SCRIPTS->setJavaScriptFile(md5($info['file']), $info['file'], $footer, $priority);
+			}
+		}    	
+	}
+}
+
 /*
  * Implement *some* of the Plugin API functions for templates. While templates
  * aren't a plugin (and likely never will be), implementing some of the API



More information about the geeklog-cvs mailing list