【问题标题】:Hoping to create Joomla plugin to allow for custom admin templates in K2希望创建 Joomla 插件以允许在 K2 中自定义管理模板
【发布时间】:2011-12-22 08:27:08
【问题描述】:

所以我想出了如何破解 k2 以允许基于项目类别的多个后端模板。它实际上非常简单,但需要对 k2 核心进行 hack。

在管理员/组件/com_k2/views/item/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。

所以我想做的是创建一个可安装的插件,基本上在呈现管理模板之前插入此代码。不知道该怎么做……有什么想法吗?

谢谢!

【问题讨论】:

    标签: php joomla


    【解决方案1】:

    这应该很简单:

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

    另外,Joomla 在/plugins/user/example.php 中有一个示例插件(这不是您想要的插件,而是一个很好的起点)。 您应该创建在onAfterDispatch 或onAfterRender 上触发的System 插件,您可能需要使用事件才能使其正确...

    这是草稿:

    <?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); 
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-02-06
      • 1970-01-01
      • 2020-04-21
      • 2015-07-25
      • 2014-11-27
      • 2020-06-17
      • 2012-12-23
      • 2014-04-21
      • 2012-09-13
      相关资源
      最近更新 更多