2011-11-04 52 views
0

因此,我找到了如何破解k2以允许基于项目类别的多个后端模板。它其实很简单,但需要在k2核心中进行破解。希望创建Joomla插件以允许K2中的自定义管理模板

在管理员/组件/ com_k2 /视图/项目/ view.html.php在行305,只是下面:

$this->assignRef('form', $form); 

我说:

jimport('joomla.filesystem.folder'); 
$componentPath = JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'templates'; 
$componentFolders = JFolder::folders($componentPath); 
$db =& JFactory::getDBO(); 
$query = "SELECT template FROM #__templates_menu WHERE client_id = 0 AND menuid = 0"; 
$db->setQuery($query); 
$defaultemplate = $db->loadResult(); 

if (JFolder::exists(JPATH_SITE.DS.'templates'.DS.$defaultemplate.DS.'html'.DS.'com_k2'.DS.'templates'.DS.'admin'.DS.$item->catid)) { 
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$defaultemplate.DS.'html'.DS.'com_k2'.DS.'templates'.DS.'admin'.DS.$item->catid); 
    } 

这使我能够复制/ administrator/components/com_k2/views/item/tmpl的文件夹和内容,将它移动到templates/MY_TEMPLATE/html/com_k2/admin,并用我想覆盖的类别id重命名新文件夹。

这很好,我可以完全自定义我的后端K2模板按类别,使一切都更容易为客户端,使K2更像一个完整的CCK。

所以我想要做的是创建一个可安装的插件,基本上插入此代码之前管理模板呈现。不知道如何去做这个,但...有什么想法?

谢谢!

回答

0

这应该是非常简单的:

  1. 研究如何创建的Joomla插件。这里是Joomla create plug-in tutorial
  2. 了解更多关于插件的行为,这里是plug-in documentation and events
  3. 编写代码:-)

此外,的Joomla在/plugins/user/example.php一个样本插件(这不是插件,你想,但是一个好的起点)。 您应该创建系统插件被解雇或者在onAfterDispatchonAfterRender,则可能是活动中发挥得到它的权利......

这里是草稿:

<?php 
// no direct access 
defined('_JEXEC') or die('Restricted access'); 

jimport('joomla.plugin.plugin'); 
jimport('joomla.filesystem.folder'); 

/** 
* K2 Template Overload Plug-in 
* 
* @package  Joomla 
* @subpackage System 
*/ 
class plgSystemK2template extends JPlugin 
{ 

    function plgSystemCache(& $subject, $config) 
    { 
     parent::__construct($subject, $config); 
    } 

    public function onAfterDispatch() 
    { 
     // WHAT IS THE PURPOSE OF THESE 2 VARS?? 
     $componentPath = JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'templates'; 
     $componentFolders = JFolder::folders($componentPath); 

     // 
     $db =& JFactory::getDBO(); 
     $query = "SELECT template FROM #__templates_menu WHERE client_id = 0 AND menuid = 0"; 
     $db->setQuery($query); 
     $defaultemplate = $db->loadResult(); 

     if (JFolder::exists(JPATH_SITE.DS.'templates'.DS.$defaultemplate.DS.'html'.DS.'com_k2'.DS.'templates'.DS.'admin'.DS.$item->catid)) { 
      $this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$defaultemplate.DS.'html'.DS.'com_k2'.DS.'templates'.DS.'admin'.DS.$item->catid); 
     } 
    } 
}