PageRenderTime 28ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/system/cms/themes/pyrocms/theme.php

https://gitlab.com/sheldonels/pyrocms
PHP | 221 lines | 145 code | 35 blank | 41 comment | 25 complexity | 624fe5b707a909ba0b5ec6739fe3823f MD5 | raw file
  1. <?php
  2. use Pyro\Module\Addons\AbstractTheme;
  3. use Pyro\Module\Comments\Model\Comment;
  4. class Theme_Pyrocms extends AbstractTheme
  5. {
  6. public $name = 'PyroCMS - Admin Theme';
  7. public $author = 'PyroCMS Dev Team';
  8. public $author_website = 'http://pyrocms.com/';
  9. public $website = 'http://pyrocms.com/';
  10. public $description = 'PyroCMS admin theme. HTML5 and CSS3 styling.';
  11. public $version = '1.0.0';
  12. public $type = 'admin';
  13. public $options = array(
  14. 'pyrocms_recent_comments' => array(
  15. 'title' => 'Recent Comments',
  16. 'description' => 'Would you like to display recent comments on the dashboard?',
  17. 'default' => 'yes',
  18. 'type' => 'radio',
  19. 'options' => 'yes=Yes|no=No',
  20. 'is_required' => true
  21. ),
  22. 'pyrocms_news_feed' => array(
  23. 'title' => 'News Feed',
  24. 'description' => 'Would you like to display the news feed on the dashboard?',
  25. 'default' => 'yes',
  26. 'type' => 'radio',
  27. 'options' => 'yes=Yes|no=No',
  28. 'is_required' => true
  29. ),
  30. 'pyrocms_quick_links' => array(
  31. 'title' => 'Quick Links',
  32. 'description' => 'Would you like to display quick links on the dashboard?',
  33. 'default' => 'yes',
  34. 'type' => 'radio',
  35. 'options' => 'yes=Yes|no=No',
  36. 'is_required' => true
  37. ),
  38. 'pyrocms_analytics_graph' => array(
  39. 'title' => 'Analytics Graph',
  40. 'description' => 'Would you like to display the graph on the dashboard?',
  41. 'default' => 'yes',
  42. 'type' => 'radio',
  43. 'options' => 'yes=Yes|no=No',
  44. 'is_required' => true
  45. ),
  46. );
  47. /**
  48. * Run() is triggered when the theme is loaded for use
  49. *
  50. * This should contain the main logic for the theme.
  51. *
  52. * @return void
  53. */
  54. public function run()
  55. {
  56. // only load these items on the dashboard
  57. if ($this->module && $this->method !== 'login' && $this->method !== 'help') {
  58. // don't bother fetching the data if it's turned off in the theme
  59. if (( ! $opt = $this->theme->model->getOptionValues())) {
  60. if (isset($opt->pyrocms_analytics_graph) and $opt->pyrocms_analytics_graph == 'yes') {
  61. self::getAnalytics();
  62. }
  63. if (isset($opt->pyrocms_news_feed) and $opt->pyrocms_news_feed == 'yes') {
  64. self::getRssFeed();
  65. }
  66. if (isset($opt->pyrocms_recent_comments) and $opt->pyrocms_recent_comments == 'yes') {
  67. self::getRecentComments();
  68. }
  69. }
  70. }
  71. }
  72. /**
  73. * Generate Menu
  74. *
  75. * Get a list of all modules available to this user/group
  76. *
  77. * @return void
  78. */
  79. private function generate_menu()
  80. {
  81. if (! $this->current_user) {
  82. return;
  83. }
  84. $modules = $this->module_m->get_all(array(
  85. 'is_backend' => true,
  86. 'group' => $this->current_user->group,
  87. 'lang' => CURRENT_LANGUAGE
  88. ));
  89. $grouped_modules = array();
  90. $grouped_menu[] = 'content';
  91. foreach ($modules as $module) {
  92. if ($module['menu'] != 'content' && $module['menu'] != 'design' && $module['menu'] != 'users' && $module['menu'] != 'utilities' && $module['menu'] != '0') {
  93. $grouped_menu[] = $module['menu'];
  94. }
  95. }
  96. array_push($grouped_menu, 'design', 'users', 'utilities');
  97. $grouped_menu = array_unique($grouped_menu);
  98. foreach ($modules as $module) {
  99. $grouped_modules[$module['menu']][$module['name']] = $module;
  100. }
  101. // pass them on as template variables
  102. $this->template->menu_items = $grouped_menu;
  103. $this->template->modules = $grouped_modules;
  104. }
  105. /**
  106. * Get Analytics
  107. *
  108. * Fetch Google Analytics information for the dashboard graph
  109. *
  110. * @return void
  111. */
  112. public function getAnalytics()
  113. {
  114. if ( ! (Settings::get('ga_email') and Settings::get('ga_password') and Settings::get('ga_profile'))) {
  115. return;
  116. }
  117. // Not false? Return it
  118. if ($cached_response = $this->cache->get('analytics')) {
  119. $data['analytic_visits'] = $cached_response['analytic_visits'];
  120. $data['analytic_views'] = $cached_response['analytic_views'];
  121. } else {
  122. try {
  123. $this->load->library('analytics', array(
  124. 'username' => Settings::get('ga_email'),
  125. 'password' => Settings::get('ga_password'),
  126. ));
  127. // Set by GA Profile ID if provided, else try and use the current domain
  128. $this->analytics->setProfileById('ga:'.Settings::get('ga_profile'));
  129. $end_date = date('Y-m-d');
  130. $start_date = date('Y-m-d', strtotime('-1 month'));
  131. $this->analytics->setDateRange($start_date, $end_date);
  132. $visits = $this->analytics->getVisitors();
  133. $views = $this->analytics->getPageviews();
  134. /* build tables */
  135. if (count($visits)) {
  136. foreach ($visits as $date => $visit) {
  137. $year = substr($date, 0, 4);
  138. $month = substr($date, 4, 2);
  139. $day = substr($date, 6, 2);
  140. $utc = mktime(date('h') + 1, null, null, $month, $day, $year) * 1000;
  141. $flot_datas_visits[] = '[' . $utc . ',' . $visit . ']';
  142. $flot_datas_views[] = '[' . $utc . ',' . $views[$date] . ']';
  143. }
  144. $flot_data_visits = '[' . implode(',', $flot_datas_visits) . ']';
  145. $flot_data_views = '[' . implode(',', $flot_datas_views) . ']';
  146. }
  147. $data['analytic_visits'] = $flot_data_visits;
  148. $data['analytic_views'] = $flot_data_views;
  149. // Call the model or library with the method provided and the same arguments
  150. $this->cache->set('analytics', array('analytic_visits' => $flot_data_visits, 'analytic_views' => $flot_data_views), 60 * 60 * 6); // 6 hours
  151. } catch (Exception $e) {
  152. $data['messages']['notice'] = sprintf(lang('cp_google_analytics_no_connect'), anchor('admin/settings', lang('cp_nav_settings')));
  153. }
  154. }
  155. // make it available in the theme
  156. $this->template->set($data);
  157. }
  158. /**
  159. * Get RSS Feed
  160. *
  161. * Fetch articles for whatever RSS feed is in settings
  162. */
  163. public function getRssFeed()
  164. {
  165. // Dashboard RSS feed (using SimplePie)
  166. $pie = new SimplePie;
  167. $pie->set_cache_location($this->config->item('simplepie_cache_dir'));
  168. $pie->set_feed_url(Settings::get('dashboard_rss'));
  169. $pie->init();
  170. $pie->handle_content_type();
  171. $this->template->rss_items = $pie->get_items(0, Settings::get('dashboard_rss_count'));
  172. }
  173. /**
  174. * Get Recent Comments
  175. *
  176. * Fetch recent comments and work out what they attach to.
  177. */
  178. public function getRecentComments()
  179. {
  180. $this->load->library('comments/comments');
  181. $this->lang->load('comments/comments');
  182. $recent_comments = Comment::findRecent(5);
  183. $this->template->recent_comments = $this->comments->process($recent_comments);
  184. }
  185. }
  186. /* End of file theme.php */