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

/Extensions/Controller/ExtensionsThemesController.php

https://github.com/kareypowell/croogo
PHP | 162 lines | 80 code | 22 blank | 60 comment | 10 complexity | 7d742c637ccaac1e43426040bd80cfce MD5 | raw file
  1. <?php
  2. App::uses('File', 'Utility');
  3. App::uses('Folder', 'Utility');
  4. App::uses('ExtensionsAppController', 'Extensions.Controller');
  5. App::uses('ExtensionsInstaller', 'Extensions.Lib');
  6. App::uses('CroogoTheme', 'Extensions.Lib');
  7. App::uses('Sanitize', 'Utility');
  8. /**
  9. * Extensions Themes Controller
  10. *
  11. * @category Controller
  12. * @package Croogo.Extensions.Controller
  13. * @version 1.0
  14. * @author Fahad Ibnay Heylaal <contact@fahad19.com>
  15. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  16. * @link http://www.croogo.org
  17. */
  18. class ExtensionsThemesController extends ExtensionsAppController {
  19. /**
  20. * Controller name
  21. *
  22. * @var string
  23. * @access public
  24. */
  25. public $name = 'ExtensionsThemes';
  26. /**
  27. * Models used by the Controller
  28. *
  29. * @var array
  30. * @access public
  31. */
  32. public $uses = array(
  33. 'Settings.Setting',
  34. 'Users.User',
  35. );
  36. /**
  37. * CroogoTheme instance
  38. */
  39. protected $_CroogoTheme = false;
  40. /**
  41. * Constructor
  42. */
  43. public function __construct($request = null, $response = null) {
  44. $this->_CroogoTheme = new CroogoTheme();
  45. parent::__construct($request, $response);
  46. }
  47. /**
  48. * admin_index
  49. *
  50. * @return void
  51. */
  52. public function admin_index() {
  53. $this->set('title_for_layout', __d('croogo', 'Themes'));
  54. $themes = $this->_CroogoTheme->getThemes();
  55. $themesData = array();
  56. $themesData[] = $this->_CroogoTheme->getData();
  57. foreach ($themes as $theme) {
  58. $themesData[$theme] = $this->_CroogoTheme->getData($theme);
  59. }
  60. $currentTheme = $this->_CroogoTheme->getData(Configure::read('Site.theme'));
  61. $this->set(compact('themes', 'themesData', 'currentTheme'));
  62. }
  63. /**
  64. * admin_activate
  65. *
  66. * @param string $alias
  67. * @return void
  68. */
  69. public function admin_activate($alias = null) {
  70. if ($this->_CroogoTheme->activate($alias)) {
  71. $this->Session->setFlash(__d('croogo', 'Theme activated.'), 'default', array('class' => 'success'));
  72. } else {
  73. $this->Session->setFlash(__d('croogo', 'Theme activation failed.'), 'default', array('class' => 'success'));
  74. }
  75. return $this->redirect(array('action' => 'index'));
  76. }
  77. /**
  78. * admin_add
  79. *
  80. * @return void
  81. */
  82. public function admin_add() {
  83. $this->set('title_for_layout', __d('croogo', 'Upload a new theme'));
  84. if (!empty($this->request->data)) {
  85. $file = $this->request->data['Theme']['file'];
  86. unset($this->request->data['Theme']['file']);
  87. $Installer = new ExtensionsInstaller;
  88. try {
  89. $Installer->extractTheme($file['tmp_name']);
  90. $this->Session->setFlash(__d('croogo', 'Theme uploaded successfully.'), 'default', array('class' => 'success'));
  91. } catch (CakeException $e) {
  92. $this->Session->setFlash($e->getMessage(), 'default', array('class' => 'error'));
  93. }
  94. return $this->redirect(array('action' => 'index'));
  95. }
  96. }
  97. /**
  98. * admin_editor
  99. *
  100. * @return void
  101. */
  102. public function admin_editor() {
  103. $this->set('title_for_layout', __d('croogo', 'Theme Editor'));
  104. }
  105. /**
  106. * admin_save
  107. *
  108. * @return void
  109. */
  110. public function admin_save() {
  111. }
  112. /**
  113. * admin_delete
  114. *
  115. * @param string $alias
  116. * @return void
  117. */
  118. public function admin_delete($alias = null) {
  119. if ($alias == null) {
  120. $this->Session->setFlash(__d('croogo', 'Invalid Theme.'), 'default', array('class' => 'error'));
  121. return $this->redirect(array('action' => 'index'));
  122. }
  123. if ($alias == 'default') {
  124. $this->Session->setFlash(__d('croogo', 'Default theme cannot be deleted.'), 'default', array('class' => 'error'));
  125. return $this->redirect(array('action' => 'index'));
  126. } elseif ($alias == Configure::read('Site.theme')) {
  127. $this->Session->setFlash(__d('croogo', 'You cannot delete a theme that is currently active.'), 'default', array('class' => 'error'));
  128. return $this->redirect(array('action' => 'index'));
  129. }
  130. $result = $this->_CroogoTheme->delete($alias);
  131. if ($result === true) {
  132. $this->Session->setFlash(__d('croogo', 'Theme deleted successfully.'), 'default', array('class' => 'success'));
  133. } elseif (!empty($result[0])) {
  134. $this->Session->setFlash($result[0], 'default', array('class' => 'error'));
  135. } else {
  136. $this->Session->setFlash(__d('croogo', 'An error occurred.'), 'default', array('class' => 'error'));
  137. }
  138. return $this->redirect(array('action' => 'index'));
  139. }
  140. }