Permalink
Browse files

[IMP] Plugin get overridable layout

  • Loading branch information...
1 parent b9106e1 commit 505c2aed3f821faa46ed59bfaec783c38fe4722f @phproberto phproberto committed Jul 24, 2012
Showing with 54 additions and 0 deletions.
  1. +54 −0 libraries/joomla/plugin/helper.php
@@ -27,6 +27,60 @@
protected static $plugins = null;
/**
+ * Get the path to a layout from a Plugin
+ *
+ * @param string $type Plugin type
+ * @param string $name Plugin name
+ * @param string $layout Layout name
+ *
+ * @return string Layout path
+ */
+ public static function getLayoutPath($type, $name, $layout = 'default')
+ {
+ $template = JFactory::getApplication()->getTemplate();
+ $defaultLayout = $layout;
+
+ if (strpos($layout, ':') !== false)
+ {
+ // Get the template and file name from the string
+ $temp = explode(':', $layout);
+ $template = ($temp[0] == '_') ? $template : $temp[0];
+ $layout = $temp[1];
+ $defaultLayout = ($temp[1]) ? $temp[1] : 'default';
+ }
+
+ // Build the template and base path for the layout
+ $tPath = JPATH_THEMES . DIRECTORY_SEPARATOR . $template
+ . DIRECTORY_SEPARATOR . 'html'
+ . DIRECTORY_SEPARATOR . 'plg_' . $type . '_' . $name
+ . DIRECTORY_SEPARATOR . $layout . '.php';
+ $bPath = JPATH_BASE . DIRECTORY_SEPARATOR . 'plugins'
+ . DIRECTORY_SEPARATOR . $type
+ . DIRECTORY_SEPARATOR . $name
+ . DIRECTORY_SEPARATOR . 'tmpl'
+ . DIRECTORY_SEPARATOR . $defaultLayout . '.php';
+ $dPath = JPATH_BASE . DIRECTORY_SEPARATOR . 'plugins'
+ . DIRECTORY_SEPARATOR . $type
+ . DIRECTORY_SEPARATOR . $name
+ . DIRECTORY_SEPARATOR . 'tmpl'
+ . DIRECTORY_SEPARATOR . 'default.php';
+
+ // If the template has a layout override use it
+ if (file_exists($tPath))
+ {
+ return $tPath;
+ }
+ elseif (file_exists($bPath))
+ {
+ return $bPath;
+ }
+ else
+ {
+ return $dPath;
+ }
+ }
+
+ /**
* Get the plugin data of a specific type if no specific plugin is specified
* otherwise only the specific plugin data is returned.
*

0 comments on commit 505c2ae

Please sign in to comment.