PageRenderTime 57ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/www/app/AdminModule/presenters/AdminThemesPresenter.php

https://github.com/bazo/Mokuji
PHP | 138 lines | 121 code | 15 blank | 2 comment | 10 complexity | 2fad7cbef0caeb5338a25ba2465a2290 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT
  1. <?php
  2. class Admin_ThemesPresenter extends Admin_SecurePresenter
  3. {
  4. public function actionDefault()
  5. {
  6. $this->view = 'visuals_admin';
  7. }
  8. public function actionSite()
  9. {
  10. $this->view = 'visuals_site';
  11. }
  12. public function createComponentPageAdminThemes($name)
  13. {
  14. $page = new Page($this,$name);
  15. $item = $page->addItem("Tabs");
  16. $item->contentFactory = array($this,'createTabs');
  17. //Tab Admin Themes
  18. $item = $page->addItem("admin_themes");
  19. $item->contentFactory = array($this,'createTabAdminThemes');
  20. }
  21. public function createComponentPageSiteThemes($name)
  22. {
  23. $page = new Page($this,$name);
  24. $item = $page->addItem("Tabs");
  25. $item->contentFactory = array($this,'createTabs');
  26. //Tab Site Themes
  27. $item = $page->addItem("site_themes");
  28. $item->contentFactory = array($this,'createTabSiteThemes');
  29. }
  30. public function createTabs($name, $page)
  31. {
  32. $params = $this->getRequest()->getParams();
  33. $action = $params['action'];
  34. $linkMeta = Html::el('a')->href($this->link('default'))->add(Html::el('span')->add('Admin Themes'));
  35. $linkAdvanced = Html::el('a')->href($this->link('site'))->add(Html::el('span')->add('Site Themes'));
  36. $liMeta = Html::el('li')->class('ui-tabs-panel ui-widget-content ui-state-default ui-corner-top');
  37. $liAdvanced = Html::el('li')->class('ui-tabs-panel ui-widget-content ui-state-default ui-corner-top');
  38. if($action == 'site')
  39. $liAdvanced->class('ui-tabs-panel ui-widget-content ui-state-default ui-corner-top ui-tabs-selected ui-state-active');
  40. else
  41. $liMeta->class('ui-tabs-panel ui-widget-content ui-state-default ui-corner-top ui-tabs-selected ui-state-active');
  42. $tabs = Html::el('div')->class('tabs ui-tabs ui-widget ui-widget-content ui-corner-all')->add(Html::el('ul')->class('ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all')
  43. ->add($liMeta->add($linkMeta))
  44. ->add($liAdvanced->add($linkAdvanced)));
  45. return $tabs;
  46. }
  47. public function createTabAdminThemes($name, item $item)
  48. {
  49. $appDir = Environment::getVariable('appDir');
  50. $moduleDir = Environment::getVariable('moduleDir');
  51. $themesDir = Environment::getVariable('themesDir');
  52. $activeTheme = Environment::getVariable('theme');
  53. $themesPath = $appDir.'/'.$moduleDir.'/'.$themesDir;
  54. $activeThemeInfoFile = $themesPath.'/'.$activeTheme.'/theme.xml';
  55. $activeThemeInfo = simplexml_load_file($activeThemeInfoFile);
  56. $availableThemes = array();
  57. foreach(scandir($themesPath) as $path)
  58. {
  59. if( $path != $activeTheme and $path != '.' and $path != '..' and is_dir($themesPath.'/'.$path) )
  60. {
  61. $themeInfo = simplexml_load_file($themesPath.'/'.$path.'/theme.xml');
  62. $themeInfo->folder = $path;
  63. $availableThemes[] = (array)$themeInfo;
  64. }
  65. }
  66. $template = $this->createTemplate();
  67. $template->activeTheme = $activeThemeInfo;
  68. $template->themes = $availableThemes;
  69. $template->mode = 'admin';
  70. $template->setFile($themesPath.'/'.$activeTheme.'/templates/Themes/themes.phtml');
  71. return $template;
  72. }
  73. public function handleActivateAdminTheme($theme)
  74. {
  75. $data = ConfigAdapterIni::load(APP_DIR.'/config/admin.ini', 'admin');
  76. $data['theme'] = $theme;
  77. $themeConfig = new Config();
  78. $themeConfig->import($data);
  79. $themeConfig->save(APP_DIR.'/config/admin.ini', 'admin');
  80. $this->flash('Admin theme '.$theme.' activated');
  81. $this->redirect('this');
  82. }
  83. public function createTabSiteThemes($name, item $item)
  84. {
  85. $appDir = Environment::getVariable('appDir');
  86. $moduleDir = 'FrontModule';
  87. $adminModuleDir = Environment::getVariable('moduleDir');
  88. $themesDir = Environment::getVariable('themesDir');
  89. $data = ConfigAdapterIni::load(APP_DIR.'/config/site.ini', 'site');
  90. $activeTheme = $data['theme'];
  91. $activeAdminTheme = Environment::getVariable('theme');
  92. $adminThemesPath = $appDir.'/'.$adminModuleDir.'/'.$themesDir;
  93. $themesPath = $appDir.'/'.$moduleDir.'/'.$themesDir;
  94. $activeThemeInfoFile = $themesPath.'/'.$activeTheme.'/theme.xml';
  95. $activeThemeInfo = simplexml_load_file($activeThemeInfoFile);
  96. $availableThemes = array();
  97. foreach(scandir($themesPath) as $path)
  98. {
  99. if( $path != $activeTheme and $path != '.' and $path != '..' and is_dir($themesPath.'/'.$path) )
  100. {
  101. $themeInfo = simplexml_load_file($themesPath.'/'.$path.'/theme.xml');
  102. $themeInfo->folder = $path;
  103. $availableThemes[] = (array)$themeInfo;
  104. }
  105. }
  106. $template = $this->createTemplate();
  107. $template->activeTheme = $activeThemeInfo;
  108. $template->themes = $availableThemes;
  109. $template->mode = 'site';
  110. $template->setFile($adminThemesPath.'/'.$activeAdminTheme.'/templates/Themes/themes.phtml');
  111. return $template;
  112. }
  113. public function handleActivateSiteTheme($theme)
  114. {
  115. $data = ConfigAdapterIni::load(APP_DIR.'/config/site.ini', 'site');
  116. $data['theme'] = $theme;
  117. $themeConfig = new Config();
  118. $themeConfig->import($data);
  119. $themeConfig->save(APP_DIR.'/config/site.ini', 'site');
  120. $this->flash('Site theme '.$theme.' activated');
  121. }
  122. }
  123. ?>