PageRenderTime 21ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/app/modules/kitchensink/KitchensinkWebModule.php

http://github.com/modolabs/Kurogo-Mobile-Web
PHP | 262 lines | 219 code | 30 blank | 13 comment | 16 complexity | be1256999c857b0077b2f79a77f54510 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. * Copyright © 2010 - 2013 Modo Labs Inc. All rights reserved.
  4. *
  5. * The license governing the contents of this file is located in the LICENSE
  6. * file located at the root directory of this distribution. If the LICENSE file
  7. * is missing, please contact sales@modolabs.com.
  8. *
  9. */
  10. includePackage('DateTime');
  11. class KitchensinkWebModule extends WebModule {
  12. protected $id = 'kitchensink';
  13. protected $shouldGenerateNativeWebTemplates = true;
  14. protected function getListsForPage($page) {
  15. $lists = array();
  16. $supportedFields = array(
  17. 'titles' => 'title',
  18. 'subtitles' => 'subtitle',
  19. 'urls' => 'url',
  20. 'imgs' => 'img',
  21. 'classes' => 'class',
  22. );
  23. $configs = $this->loadPageConfigArea($page, false);
  24. foreach ($configs as $config) {
  25. if (!isset($config['titles'])) { continue; }
  26. $list = array(
  27. 'description' => self::argVal($config, 'description', 'list'),
  28. 'items' => array(),
  29. );
  30. foreach ($config['titles'] as $i => $title) {
  31. $item = array();
  32. foreach ($supportedFields as $fieldArray => $supportedField) {
  33. if (isset($config[$fieldArray], $config[$fieldArray][$i])) {
  34. $item[$supportedField] = $config[$fieldArray][$i];
  35. }
  36. }
  37. if (!isset($item['url'])) {
  38. $args = $this->args;
  39. if (isset($item['title'])) {
  40. $args['title'] = $item['title'];
  41. }
  42. $item['url'] = $this->buildBreadcrumbURL($this->page, $args);
  43. }
  44. $list['items'][] = $item;
  45. }
  46. $lists[] = $list;
  47. }
  48. return $lists;
  49. }
  50. protected function initializeForPage() {
  51. switch ($this->page) {
  52. case 'index':
  53. $links = array(
  54. array(
  55. 'title' => 'Text',
  56. 'url' => $this->buildBreadcrumbURL('text', array()),
  57. ),
  58. array(
  59. 'title' => 'Navigation Lists',
  60. 'url' => $this->buildBreadcrumbURL('nav', array()),
  61. ),
  62. array(
  63. 'title' => 'Results Lists',
  64. 'url' => $this->buildBreadcrumbURL('results', array()),
  65. ),
  66. array(
  67. 'title' => 'Search',
  68. 'url' => $this->buildBreadcrumbURL('search', array()),
  69. ),
  70. array(
  71. 'title' => 'Detail',
  72. 'url' => $this->buildBreadcrumbURL('detail', array()),
  73. ),
  74. array(
  75. 'title' => 'Geolocation',
  76. 'url' => $this->buildBreadcrumbURL('location', array()),
  77. ),
  78. array(
  79. 'title' => 'HTML Truncation Form',
  80. 'url' => $this->buildBreadcrumbURL('truncate', array()),
  81. ),
  82. array(
  83. 'title' => 'Javascript API Call Test',
  84. 'url' => $this->buildBreadcrumbURL('apicall', array()),
  85. ),
  86. );
  87. if ($this->browser == 'native') {
  88. $appQLinks = array(
  89. array(
  90. 'title' => 'Dialogs',
  91. 'url' => $this->buildBreadcrumbURL('dialogs', array()),
  92. ),
  93. array(
  94. 'title' => 'Refresh Button',
  95. 'url' => $this->buildBreadcrumbURL('refresh', array()),
  96. ),
  97. array(
  98. 'title' => 'Auto Refresh',
  99. 'url' => $this->buildBreadcrumbURL('autorefresh', array()),
  100. ),
  101. );
  102. $this->assign('appQLinks', $appQLinks);
  103. }
  104. $this->assign('links', $links);
  105. break;
  106. case 'text':
  107. break;
  108. case 'apicall':
  109. break;
  110. case 'search':
  111. $formFields = $this->loadPageConfigArea($this->page, false);
  112. foreach ($formFields as $i => $formField) {
  113. if (isset($formField['option_keys'])) {
  114. $options = array();
  115. foreach ($formField['option_keys'] as $j => $optionKey) {
  116. $options[$optionKey] = $formField['option_values'][$j];
  117. }
  118. $formFields[$i]['options'] = $options;
  119. unset($formFields[$i]['option_keys']);
  120. unset($formFields[$i]['option_values']);
  121. }
  122. }
  123. $this->assign('formFields', $formFields);
  124. break;
  125. case 'results':
  126. if ($title = $this->getArg('title')) {
  127. $this->setPageTitles($title);
  128. }
  129. $this->assign('next', 'Next');
  130. $this->assign('prev', 'Prev');
  131. $this->assign('nextURL', $this->buildBreadcrumbURL($this->page, $this->args, false));
  132. $this->assign('prevURL', $this->buildBreadcrumbURL($this->page, $this->args, false));
  133. $this->assign('lists', $this->getListsForPage($this->page));
  134. break;
  135. case 'nav':
  136. if ($title = $this->getArg('title')) {
  137. $this->setPageTitles($title);
  138. }
  139. $this->assign('lists', $this->getListsForPage($this->page));
  140. break;
  141. case 'pane':
  142. $this->assign('lists', $this->getListsForPage($this->page));
  143. break;
  144. case 'articles':
  145. $this->setWebBridgePageRefresh(true);
  146. $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
  147. $this->addOnLoad('setupListing();');
  148. $this->assign('articles', $this->getListsForPage($this->page));
  149. break;
  150. case 'detail':
  151. $detailConfig = $this->loadPageConfigArea('detail', 'detailConfig');
  152. if ($this->getOptionalModuleVar('SHARING_ENABLED', 1)) {
  153. $this->assign('shareTitle', $this->getLocalizedString('SHARE_THIS_ITEM'));
  154. $this->assign('shareEmailURL', 'john.smith@gmail.com');
  155. $this->assign('shareRemark', 'This is a share remark');
  156. $this->assign('shareURL', 'This is a share URL');
  157. }
  158. if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
  159. $this->generateBookmarkOptions('fakeid');
  160. }
  161. $this->enableTabs(array_keys($detailConfig['tabs']));
  162. break;
  163. case 'dialogs':
  164. $buttons = array();
  165. $configs = $this->loadPageConfigArea($this->page, false);
  166. foreach ($configs as $config) {
  167. if (!isset($config['title'],
  168. $config['description'],
  169. $config['api'],
  170. $config['arguments'])) {
  171. continue;
  172. }
  173. $buttons[] = array(
  174. 'title' => $config['title'],
  175. 'description' => $config['description'],
  176. 'javascript' => "kgoBridge.{$config['api']}(".implode(', ', $config['arguments']).
  177. ", null, function (error, params) { alert('You clicked button type \''+params['button']+'\''); }); return false;",
  178. );
  179. }
  180. $this->assign('buttons', $buttons);
  181. break;
  182. case 'location':
  183. $links = array(
  184. array(
  185. 'title' => 'Watch Position Map Test',
  186. 'url' => $this->buildBreadcrumbURL('location_full', array()),
  187. ),
  188. );
  189. $this->assign('links', $links);
  190. break;
  191. case 'location_full':
  192. $this->addExternalJavascript('http://maps.googleapis.com/maps/api/js?sensor=true');
  193. $this->addOnLoad('initMap();');
  194. $this->addInlineJavascript('var locationMarkerURL = "'.FULL_URL_PREFIX.'common/images/map-location.png";');
  195. break;
  196. case 'truncate':
  197. $this->assign('action', $this->buildBreadcrumbURL('truncated', array()));
  198. break;
  199. case 'truncated':
  200. $length = $this->getArg('length', 0);
  201. $margin = $this->getArg('margin', 0);
  202. $minLineLength = $this->getArg('minLineLength', 40);
  203. $html = $this->getArg('html', '');
  204. if ($length && $margin && $html) {
  205. $html = Sanitizer::sanitizeAndTruncateHTML($html, $truncated, $length, $margin, $minLineLength);
  206. }
  207. $this->assign('html', $html);
  208. break;
  209. case 'autorefresh':
  210. $links = array(
  211. array(
  212. 'title' => 'Detail',
  213. 'url' => $this->buildBreadcrumbURL('detail', array()),
  214. ),
  215. );
  216. $this->assign('links', $links);
  217. // fallthrough
  218. case 'refresh':
  219. $now = new DateTime();
  220. $this->assign('lastUpdated',
  221. DateFormatter::formatDate($now, DateFormatter::MEDIUM_STYLE, DateFormatter::MEDIUM_STYLE));
  222. break;
  223. }
  224. }
  225. protected function initializeForNativeTemplatePage() {
  226. // Native template support
  227. // specify anything that goes into the header or footer here
  228. // and force the appearance of assets so they get loaded into the template
  229. // All the data in this module is static!
  230. $this->initializeForPage();
  231. }
  232. }