PageRenderTime 26ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_zoo/controllers/configuration.php

https://github.com/foxbei/joomla15
PHP | 367 lines | 210 code | 105 blank | 52 comment | 20 complexity | ab59118f1758f2b35bb4bf4275a79b59 MD5 | raw file
  1. <?php
  2. /**
  3. * @package ZOO Component
  4. * @file configuration.php
  5. * @version 2.3.7 March 2011
  6. * @author YOOtheme http://www.yootheme.com
  7. * @copyright Copyright (C) 2007 - 2011 YOOtheme GmbH
  8. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  9. */
  10. /*
  11. Class: ConfigurationController
  12. The controller class for application configuration
  13. */
  14. class ConfigurationController extends YController {
  15. public $application;
  16. public function __construct($default = array()) {
  17. parent::__construct($default);
  18. // get application
  19. $this->application = Zoo::getApplication();
  20. // register tasks
  21. $this->registerTask('applyassignelements', 'saveassignelements');
  22. }
  23. public function display() {
  24. // set toolbar items
  25. $this->joomla->set('JComponentTitle', $this->application->getToolbarTitle(JText::_('Config')));
  26. JToolBarHelper::save();
  27. ZooHelper::toolbarHelp();
  28. // get params
  29. $this->params = $this->application->getParams();
  30. // template select
  31. $options = array(JHTML::_('select.option', '', '- '.JText::_('Select Template').' -'));
  32. foreach ($this->application->getTemplates() as $template) {
  33. $metadata = $template->getMetaData();
  34. $options[] = JHTML::_('select.option', $template->name, $metadata['name']);
  35. }
  36. $this->lists['select_template'] = JHTML::_('select.genericlist', $options, 'template', '', 'value', 'text', $this->params->get('template'));
  37. // display view
  38. $this->getView()->setLayout('application')->display();
  39. }
  40. public function save() {
  41. // check for request forgeries
  42. YRequest::checkToken() or jexit('Invalid Token');
  43. // init vars
  44. $post = YRequest::get('post');
  45. try {
  46. // bind post
  47. $this->application->bind($post, array('params'));
  48. // set params
  49. $params = $this->application
  50. ->getParams()
  51. ->remove('global.')
  52. ->set('template', @$post['template'])
  53. ->set('global.config.', @$post['params']['config'])
  54. ->set('global.template.', @$post['params']['template']);
  55. if (isset($post['addons']) && is_array($post['addons'])) {
  56. foreach ($post['addons'] as $addon => $value) {
  57. $params->set("global.$addon.", $value);
  58. }
  59. }
  60. $this->application->params = $params->toString();
  61. // save application
  62. YTable::getInstance('application')->save($this->application);
  63. // set redirect message
  64. $msg = JText::_('Application Saved');
  65. } catch (YException $e) {
  66. // raise notice on exception
  67. JError::raiseNotice(0, JText::_('Error Saving Application').' ('.$e.')');
  68. $msg = null;
  69. }
  70. $this->setRedirect($this->baseurl, $msg);
  71. }
  72. public function getApplicationParams() {
  73. // init vars
  74. $template = YRequest::getCmd('template');
  75. // get params
  76. $this->params = $this->application->getParams();
  77. // set template
  78. $this->params->set('template', $template);
  79. // display view
  80. $this->getView()->setLayout('_applicationparams')->display();
  81. }
  82. public function importExport() {
  83. // set toolbar items
  84. $this->joomla->set('JComponentTitle', $this->application->getToolbarTitle(JText::_('Import / Export')));
  85. ZooHelper::toolbarHelp();
  86. $files = YFile::readDirectoryFiles(ZOO_ADMIN_PATH . '/helpers/exporter/', ZOO_ADMIN_PATH . '/helpers/exporter/', '/.*\.php$/', false);
  87. $this->exporter = array();
  88. foreach ($files as $file) {
  89. if ($instance = ExportHelper::getInstance(basename($file, '.php'))) {
  90. if ($instance->getName() != 'Zoo v2') {
  91. $this->exporter[] = $instance;
  92. }
  93. }
  94. }
  95. // display view
  96. $this->getView()->setLayout('importexport')->display();
  97. }
  98. public function importFrom() {
  99. // check for request forgeries
  100. YRequest::checkToken() or jexit('Invalid Token');
  101. $exporter = YRequest::getString('exporter');
  102. try {
  103. $xml = ExportHelper::getInstance($exporter)->export();
  104. $file = rtrim($this->joomla->getCfg('tmp_path'), '\/') . '/' . YUtility::generateUUID() . '.tmp';
  105. if (JFile::exists($file)) {
  106. JFile::delete($file);
  107. }
  108. JFile::write($file, $xml);
  109. } catch (Exception $e) {
  110. // raise error on exception
  111. JError::raiseNotice(0, JText::_('Error During Export').' ('.$e.')');
  112. $this->setRedirect($this->baseurl.'&task=importexport', $msg);
  113. }
  114. $this->_import($file);
  115. }
  116. public function import() {
  117. // check for request forgeries
  118. YRequest::checkToken() or jexit('Invalid Token');
  119. $userfile = null;
  120. $xmlfile = JRequest::getVar('import-xml', array(), 'files', 'array');
  121. try {
  122. // validate
  123. $validator = new YValidatorFile(array('extensions' => array('xml')));
  124. $userfile = $validator->clean($xmlfile);
  125. $type = 'xml';
  126. } catch (YValidatorException $e) {}
  127. $csvfile = JRequest::getVar('import-csv', array(), 'files', 'array');
  128. try {
  129. // validate
  130. $validator = new YValidatorFile(array('extensions' => array('csv')));
  131. $userfile = $validator->clean($csvfile);
  132. $type = 'csv';
  133. } catch (YValidatorException $e) {}
  134. if (!empty($userfile)) {
  135. $file = rtrim($this->joomla->getCfg('tmp_path'), '\/') . '/' . basename($userfile['tmp_name']);
  136. if (JFile::upload($userfile['tmp_name'], $file)) {
  137. $this->_import($file, $type);
  138. } else {
  139. // raise error on exception
  140. JError::raiseNotice(0, JText::_('Error Importing (Unable to upload file.)'));
  141. $this->setRedirect($this->baseurl.'&task=importexport', $msg);
  142. }
  143. } else {
  144. // raise error on exception
  145. JError::raiseNotice(0, JText::_('Error Importing (Unable to upload file.)'));
  146. $this->setRedirect($this->baseurl.'&task=importexport', $msg);
  147. }
  148. }
  149. public function importCSV() {
  150. $file = YRequest::getCmd('file', '');
  151. $file = rtrim($this->joomla->getCfg('tmp_path'), '\/') . '/' . $file;
  152. $this->_import($file, 'importcsv');
  153. }
  154. protected function _import($file, $type = 'xml') {
  155. // disable menu
  156. YRequest::setVar('hidemainmenu', 1);
  157. // set toolbar items
  158. $this->joomla->set('JComponentTitle', $this->application->getToolbarTitle(JText::_('Import').': '.$this->application->name));
  159. JToolBarHelper::cancel('importexport', 'Cancel');
  160. ZooHelper::toolbarHelp();
  161. // set_time_limit doesn't work in safe mode
  162. if (!ini_get('safe_mode')) {
  163. @set_time_limit(0);
  164. }
  165. $layout = '';
  166. switch ($type) {
  167. case 'xml':
  168. if ($document = YXML::loadFile($file)) {
  169. $this->info = ImportHelper::getImportInfo($document);
  170. $this->file = basename($file);
  171. } else {
  172. // raise error on exception
  173. JError::raiseNotice(0, JText::_('Error Importing (Not a valid XML file)'));
  174. $this->setRedirect($this->baseurl.'&task=importexport', $msg);
  175. }
  176. $layout = 'importxml';
  177. break;
  178. case 'csv':
  179. $this->file = basename($file);
  180. $layout = 'configcsv';
  181. break;
  182. case 'importcsv':
  183. $this->contains_headers = YRequest::getBool('contains-headers', false);
  184. $this->field_separator = YRequest::getString('field-separator', ',');
  185. $this->field_separator = empty($this->field_separator) ? ',' : substr($this->field_separator, 0, 1);
  186. $this->field_enclosure = YRequest::getString('field-enclosure', '"');
  187. $this->field_enclosure = empty($this->field_enclosure) ? '"' : substr($this->field_enclosure, 0, 1);
  188. $this->info = ImportHelper::getImportInfoCSV($file, $this->contains_headers, $this->field_separator, $this->field_enclosure);
  189. $this->file = basename($file);
  190. $layout = 'importcsv';
  191. break;
  192. }
  193. // display view
  194. $this->getView()->setLayout($layout)->display();
  195. }
  196. public function doImport() {
  197. // init vars
  198. $import_frontpage = YRequest::getBool('import-frontpage', false);
  199. $frontpage_params = YRequest::getArray('frontpage-params', array());
  200. $import_categories = YRequest::getBool('import-categories', false);
  201. $category_params = YRequest::getArray('category-params', array());
  202. $element_assignment = YRequest::getArray('element-assign', array());
  203. $types = YRequest::getArray('types', array());
  204. $file = YRequest::getCmd('file', '');
  205. $file = rtrim($this->joomla->getCfg('tmp_path'), '\/') . '/' . $file;
  206. if (JFile::exists($file)) {
  207. // set_time_limit doesn't work in safe mode
  208. if (!ini_get('safe_mode')) {
  209. @set_time_limit(0);
  210. }
  211. ImportHelper::import($file, $import_frontpage, $frontpage_params, $import_categories, $category_params, $element_assignment, $types);
  212. }
  213. $this->setRedirect($this->baseurl.'&task=importexport', JText::_('Import successfull'));
  214. }
  215. public function doImportCSV() {
  216. // init vars
  217. $contains_headers = YRequest::getBool('contains-headers', false);
  218. $field_separator = YRequest::getString('field-separator', ',');
  219. $field_enclosure = YRequest::getString('field-enclosure', '"');
  220. $element_assignment = YRequest::getArray('element-assign', array());
  221. $type = YRequest::getCmd('type', '');
  222. $file = YRequest::getCmd('file', '');
  223. $file = rtrim($this->joomla->getCfg('tmp_path'), '\/') . '/' . $file;
  224. if (JFile::exists($file)) {
  225. // set_time_limit doesn't work in safe mode
  226. if (!ini_get('safe_mode')) {
  227. @set_time_limit(0);
  228. }
  229. ImportHelper::importCSV($file, $type, $contains_headers, $field_separator, $field_enclosure, $element_assignment);
  230. }
  231. $this->setRedirect($this->baseurl.'&task=importexport', JText::_('Import successfull'));
  232. }
  233. public function doExport() {
  234. $exporter = YRequest::getString('exporter');
  235. if ($exporter) {
  236. try {
  237. // set_time_limit doesn't work in safe mode
  238. if (!ini_get('safe_mode')) {
  239. @set_time_limit(0);
  240. }
  241. $xml = ExportHelper::getInstance($exporter)->export();
  242. header("Pragma: public");
  243. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  244. header("Expires: 0");
  245. header("Content-Transfer-Encoding: binary");
  246. header ("Content-Type: text/xml");
  247. header('Content-Disposition: attachment;'
  248. .' filename="'.JFilterOutput::stringURLSafe($this->application->name).'.xml";'
  249. );
  250. echo $xml;
  251. } catch (ExportHelperException $e) {
  252. // raise error on exception
  253. JError::raiseNotice(0, JText::_('Error Exporting').' ('.$e.')');
  254. $this->setRedirect($this->baseurl.'&task=importexport', $msg);
  255. }
  256. }
  257. }
  258. }
  259. /*
  260. Class: ConfigurationControllerException
  261. */
  262. class ConfigurationControllerException extends YException {}