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

/admin/controller.php

https://github.com/sphilp/com_weever
PHP | 427 lines | 265 code | 141 blank | 21 comment | 51 complexity | daf3492f49631eac66b8c626b5f019ad MD5 | raw file
  1. <?php
  2. /*
  3. * Weever Apps Administrator Component for Joomla
  4. * (c) 2010-2011 Weever Apps Inc. <http://www.weeverapps.com/>
  5. *
  6. * Author: Robert Gerald Porter (rob.porter@weever.ca)
  7. * Version: 1.1.1
  8. * License: GPL v3.0
  9. *
  10. * This extension is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This extension is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. defined('_JEXEC') or die;
  22. jimport('joomla.application.component.controller');
  23. JTable::addIncludePath(JPATH_COMPONENT.DS.'tables');
  24. require_once (JPATH_COMPONENT.DS.'helpers'.DS.'helper'.'.php');
  25. class WeeverController extends JController
  26. {
  27. public function phpinfo()
  28. {
  29. phpinfo();
  30. jexit();
  31. }
  32. public function add()
  33. {
  34. JRequest::setVar('view', 'tab');
  35. $this->display();
  36. }
  37. public function edit()
  38. {
  39. JRequest::setVar('view', 'tab');
  40. $this->display();
  41. }
  42. public function ajaxSaveTabName()
  43. {
  44. $result = comWeeverHelper::pushTabNameToCloud();
  45. echo $result;
  46. jexit();
  47. }
  48. public function ajaxSubtabDelete()
  49. {
  50. $id = JRequest::getVar('id');
  51. $result = comWeeverHelper::pushDeleteToCloud($id);
  52. if($result == "Site key missing or invalid.")
  53. {
  54. JError::raiseError(500, JText::_('WEEVER_SERVER_ERROR').$result);
  55. }
  56. echo $result;
  57. jexit();
  58. }
  59. public function ajaxTabPublish()
  60. {
  61. $status = JRequest::getVar('status');
  62. if($status == 1)
  63. $publish = 0;
  64. else
  65. $publish = 1;
  66. $id = JRequest::getVar('id');
  67. $result = comWeeverHelper::pushPublishToCloud($id, $publish);
  68. if($result == "Site key missing or invalid.")
  69. {
  70. JError::raiseError(500, JText::_('WEEVER_SERVER_ERROR').$result);
  71. }
  72. echo $result;
  73. jexit();
  74. }
  75. public function ajaxSaveTabIcon()
  76. {
  77. $jsonResult = comWeeverHelper::pushTabIconToCloud();
  78. comWeeverHelper::saveThemeJson($jsonResult);
  79. echo "Icon Saved";
  80. jexit();
  81. }
  82. public function ajaxSaveTabOrder()
  83. {
  84. $order = JRequest::getVar("order");
  85. $response = comWeeverHelper::sortTabs($order);
  86. echo $response;
  87. jexit();
  88. }
  89. public function ajaxSaveSubtabOrder()
  90. {
  91. $response = comWeeverHelper::pushSubtabReorderToCloud();
  92. echo $response;
  93. jexit();
  94. }
  95. public function ajaxToggleAppStatus()
  96. {
  97. $response = comWeeverHelper::toggleAppStatus();
  98. echo $response;
  99. jexit();
  100. }
  101. public function ajaxUpdateTabSettings()
  102. {
  103. $response = comWeeverHelper::updateTabSettings();
  104. echo $response;
  105. jexit();
  106. }
  107. public function ajaxSaveNewTab()
  108. {
  109. $rss = null;
  110. $tab_id = null;
  111. $type = JRequest::getWord('type', 'tab');
  112. if( $type == "contact" ||
  113. $type == "blog" || $type == "directory" ||
  114. $type == "page" ||
  115. ( $type == "map" && JRequest::getVar("tag") )
  116. )
  117. {
  118. $type_method = "_build".$type."FeedURL";
  119. // ### check later
  120. if(JRequest::getVar('view' == "contact"))
  121. {
  122. comWeeverHelper::getContactInfo();
  123. }
  124. $rss = comWeeverHelper::$type_method();
  125. if($rss === false)
  126. {
  127. echo "Feed build failed!";
  128. jexit();
  129. }
  130. }
  131. JRequest::setVar('rss', $rss, 'post');
  132. JRequest::setVar('weever_server_response', comWeeverHelper::pushSettingsToCloud(), 'post');
  133. if(JRequest::getVar('weever_server_response') == "Site key missing or invalid.")
  134. {
  135. echo JRequest::getVar('weever_server_response');
  136. jexit();
  137. }
  138. echo JRequest::getVar('weever_server_response');
  139. jexit();
  140. }
  141. public function remove()
  142. {
  143. JRequest::checkToken() or jexit('Invalid Token');
  144. $option = JRequest::getCmd('option');
  145. $cid = JRequest::getVar('cid', array(0));
  146. $result = comWeeverHelper::pushDeleteToCloud($cid);
  147. if($result == "Site key missing or invalid.")
  148. {
  149. JError::raiseError(500, JText::_('WEEVER_SERVER_ERROR').$result);
  150. }
  151. if($result)
  152. $this->setRedirect('index.php?option='.$option.'&view=list', JText::_('WEEVER_SERVER_RESPONSE').$result);
  153. else
  154. $this->setRedirect('index.php?option='.$option.'&view=list',JText::_('WEEVER_ERROR_COULD_NOT_CONNECT_TO_SERVER'), 'error');
  155. }
  156. public function staging()
  157. {
  158. $row =& JTable::getInstance('WeeverConfig', 'Table');
  159. $row->load(7);
  160. $staging = $row->setting;
  161. if($staging)
  162. $msg = comWeeverHelper::disableStagingMode();
  163. else
  164. $msg = comWeeverHelper::enableStagingMode();
  165. $this->setRedirect('index.php?option=com_weever&view=account&task=account',$msg);
  166. return;
  167. }
  168. public function save()
  169. {
  170. $option = JRequest::getCmd('option');
  171. JRequest::checkToken() or jexit('Invalid Token');
  172. if(JRequest::getVar('view') == "config")
  173. {
  174. comWeeverHelper::saveConfig();
  175. $this->setRedirect('index.php?option=com_weever&view=config&task=config',JText::_('WEEVER_CONFIG_SAVED'));
  176. return;
  177. }
  178. if(JRequest::getVar('view') == "theme")
  179. {
  180. $msg = comWeeverHelper::saveTheme();
  181. $this->setRedirect('index.php?option=com_weever&view=theme&task=theme',JText::_('WEEVER_THEME_SAVED').$msg);
  182. return;
  183. }
  184. if(JRequest::getVar('view') == "account")
  185. {
  186. if(JRequest::getVar('staging') == 1)
  187. {
  188. $row =& JTable::getInstance('WeeverConfig', 'Table');
  189. $row->load(7);
  190. $row->setting = 1;
  191. $row->store();
  192. }
  193. comWeeverHelper::saveAccount();
  194. if(JRequest::getVar("install"))
  195. $this->setRedirect('index.php?option=com_weever&view=list',JText::_('WEEVER_ACCOUNT_SAVED'));
  196. else
  197. $this->setRedirect('index.php?option=com_weever&view=account&task=account',JText::_('WEEVER_ACCOUNT_SAVED'));
  198. return;
  199. }
  200. $tab_id = null;
  201. $hash = md5(microtime() . JRequest::getVar('name'));
  202. $type = JRequest::getWord('type', 'tab');
  203. $type_method = "_build".$type."FeedURL";
  204. // ### check later
  205. if(JRequest::getVar('view' == "contact"))
  206. {
  207. comWeeverHelper::getContactInfo();
  208. }
  209. $rss = comWeeverHelper::$type_method();
  210. if($rss === false)
  211. {
  212. $this->setRedirect('index.php?option=com_weever&view=tab&task=add&layout='.JRequest::getVar('layout', 'blog'), JText::_('WEEVER_MUST_CHOOSE_OPTION_FROM_DROPDOWN'), 'error');
  213. return;
  214. }
  215. JRequest::setVar('rss', $rss, 'post');
  216. JRequest::setVar('hash', $hash, 'post');
  217. JRequest::setVar('weever_server_response', comWeeverHelper::pushSettingsToCloud(), 'post');
  218. if(JRequest::getVar('weever_server_response') == "Site key missing or invalid.")
  219. {
  220. $this->setRedirect('index.php?option='.$option.'&view=list', JText::_('WEEVER_SERVER_ERROR').JRequest::getVar('weever_server_response'), 'notice');
  221. return;
  222. }
  223. $row =& JTable::getInstance('weever','Table');
  224. if(!$row->bind(JRequest::get('post')))
  225. {
  226. JError::raiseError(500, $row->getError());
  227. }
  228. $row->ordering = $row->ordering + 0.1; // for later reorder to sort well if it is in collision with another.
  229. if(!$row->store())
  230. {
  231. JError::raiseError(500, $row->getError());
  232. }
  233. comWeeverHelper::reorderTabs($type);
  234. comWeeverHelper::pushLocalIdToCloud($row->id, JRequest::getVar('hash'), JRequest::getVar('site_key'));
  235. if(JRequest::getVar('weever_server_response'))
  236. {
  237. if($this->getTask() == 'apply')
  238. $this->setRedirect('index.php?option='.$option.'&view=tab&task=edit'.'&cid[]='.$row->id,
  239. JText::_('WEEVER_SERVER_RESPONSE').JRequest::getVar('weever_server_response'));
  240. else
  241. $this->setRedirect('index.php?option='.$option.'&view=list',JText::_('WEEVER_SERVER_RESPONSE').JRequest::getVar('weever_server_response'));
  242. return;
  243. }
  244. else
  245. {
  246. $this->setRedirect('index.php?option='.$option.'&view=list',JText::_('WEEVER_ERROR_COULD_NOT_CONNECT_TO_SERVER'), 'error');
  247. return;
  248. }
  249. }
  250. public function display()
  251. {
  252. $view = JRequest::getVar('view');
  253. if(!$view)
  254. {
  255. JRequest::setVar('view','list');
  256. }
  257. parent::display();
  258. }
  259. public function publish()
  260. {
  261. $option = JRequest::getCmd('option');
  262. $cid = JRequest::getVar('cid', array());
  263. if(!$cid)
  264. {
  265. $cid[] = JRequest::getVar('id', array());
  266. }
  267. $publish = 1;
  268. if($this->getTask() == 'unpublish')
  269. $publish = 0;
  270. $result = comWeeverHelper::pushPublishToCloud($cid, $publish);
  271. if($result == "Site key missing or invalid.")
  272. {
  273. JError::raiseError(500, JText::_('WEEVER_SERVER_ERROR').$result);
  274. }
  275. if($result)
  276. {
  277. $this->setRedirect('index.php?option='.$option, JText::_('WEEVER_SERVER_RESPONSE').$result);
  278. return;
  279. }
  280. else
  281. {
  282. $this->setRedirect('index.php?option='.$option, JText::_('WEEVER_ERROR_COULD_NOT_CONNECT_TO_SERVER'), 'error');
  283. return;
  284. }
  285. }
  286. }