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

/ww_view/assembler.php

https://github.com/justincawthorne/Wicked-Words
PHP | 294 lines | 132 code | 95 blank | 67 comment | 29 complexity | 67980f7693b52bf08ce7642225878937 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?php
  2. /*
  3. Copyright (C) 2010 Justin Cawthorne
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>
  14. */
  15. /*
  16. error_reporting(E_ALL | E_STRICT);
  17. ini_set('display_errors', 1);
  18. */
  19. if(!file_exists('../ww_config/model_functions.php')) {
  20. echo 'did you forget to set up your model_functions.php file? I think so...';
  21. exit();
  22. }
  23. // set page loading start time
  24. $start = time() + microtime();
  25. // load functions
  26. include_once('../ww_config/model_functions.php');
  27. include_once('../ww_config/combined_functions.php');
  28. include_once('../ww_config/controller_functions.php');
  29. include_once('../ww_config/view_functions.php');
  30. if (!session_id()) session_start();
  31. // set theme and check for includes
  32. if(empty($config)) {
  33. echo '
  34. <div style="margin:0 auto;width:440px;margin-top: 120px;text-align:center;">
  35. <p>it appears this is a new installation of Wicked Words</p>
  36. <h4>Well done you!</h4>
  37. <p>now go to the <a href="create.php">create page</a> to create your database tables...</p>
  38. </div>';
  39. exit();
  40. }
  41. if(!empty($config['admin']['shutdown'])) {
  42. header('HTTP/1.1 503 Service Temporarily Unavailable',true,503);
  43. header('Status: 503 Service Temporarily Unavailable');
  44. header('Retry-After: 172800');
  45. echo "
  46. ".$config['site']['title']." is temporarily closed for maintenance...";
  47. exit();
  48. }
  49. // start caching
  50. if(!empty($config['cache']['caching_on'])) {
  51. $cache_fp = (!isset($_POST['submit_comment'])) ? start_caching($config['cache'], $start) : 0 ;
  52. }
  53. // process url
  54. $request = process_request();
  55. $config['site']['theme'] = (isset($_SESSION['theme'])) ? $_SESSION['theme'] : $config['site']['theme'] ;
  56. // check for includes
  57. $includes = get_includes($config['site']['theme']);
  58. if(!empty($includes)) {
  59. foreach($includes as $inc){
  60. include_once($inc);
  61. }
  62. }
  63. // create a 'meta title' from the main site title (used for browser titlebar and <title> tag
  64. // redirect as needed
  65. if(isset($_GET['page_name'])) {
  66. // rss feed - redirect to xml page
  67. if($_GET['page_name'] == 'feed') {
  68. include(WW_ROOT.'/ww_view/rss-xml.php');
  69. exit();
  70. }
  71. // front page
  72. if($_GET['page_name'] == 'front') {
  73. if(!empty($config['front']['article_id'])) {
  74. // this is a specific article, selected in the edit room
  75. $article = get_article($config['front']['article_id']);
  76. } else {
  77. // determine what content goes on front page, and which list style
  78. switch($config['front']['page_style']) {
  79. case 'custom':
  80. break;
  81. case 'latest_post':
  82. $article = get_article();
  83. break;
  84. case 'latest_month':
  85. // get list of valid months
  86. $months_list = get_months();
  87. $current_page = (empty($_GET['page'])) ? '1' : (int)$_GET['page'] ;
  88. $_GET['month'] = $months_list[$current_page-1]['month'];
  89. $_GET['year'] = $months_list[$current_page-1]['year'];
  90. // use front list style setting
  91. $config['layout']['per_page'] = 0; // override per page value in this case
  92. $config['layout']['list_style'] = $config['front']['front_list_style'];
  93. $articles = get_articles($config['layout']);
  94. break;
  95. case 'per_page':
  96. default:
  97. $config['layout']['list_style'] = $config['front']['front_list_style'];
  98. $articles = get_articles($config['layout']);
  99. break;
  100. }
  101. }
  102. }
  103. // 404 error
  104. if($_GET['page_name'] == '404') {
  105. // no content
  106. // we set up the meta tags and parse the request string on the partial page
  107. }
  108. // single article
  109. if($_GET['page_name'] == 'article') {
  110. $article = get_article($_GET['article_id']);
  111. }
  112. // multiple articles - either a search or listings request
  113. if($_GET['page_name'] == 'listing') {
  114. if(isset($_GET['feed_listing'])) {
  115. // for a list of all available feeds we'll borrow the listing page
  116. $feeds = get_feeds($config['admin']['show_all_feeds']);
  117. $articles = format_feeds_list($feeds);
  118. } elseif(!empty($_GET['search'])) {
  119. // run a search
  120. $articles = search_articles($_GET['search'],$config['layout']);
  121. } else {
  122. // standard article listing
  123. $articles = get_articles($config['layout']);
  124. }
  125. }
  126. // allowed pages array - redirect to 404 if any other page name is attempted
  127. $allowed_pages = array('feed','front','404','article','listing');
  128. $_GET['page_name'] = (in_array($_GET['page_name'],$allowed_pages)) ? $_GET['page_name'] : '404' ;
  129. // get content partial - checking for theme versions as well
  130. $theme_content_folder = WW_ROOT.'/ww_view/themes'.$config['site']['theme'].'/_content';
  131. $content_partial = (file_exists($theme_content_folder.'/_'.$_GET['page_name'].'.php'))
  132. ? $theme_content_folder.'/_'.$_GET['page_name'].'.php'
  133. : WW_ROOT.'/ww_view/_content/_'.$_GET['page_name'].'.php';
  134. // at this point we could look for a custom 'builder' file in the theme folder
  135. /* reference:
  136. $body_content['header'] = '';
  137. $body_content['nav'] = '';
  138. $body_content['main'] = '';
  139. $body_content['aside'] = '';
  140. $body_content['footer'] = '';
  141. */
  142. // header content - below is just for example
  143. /* $body_content['header'] = '<div id="header">yeah, header</div>'; */
  144. if(file_exists($theme_content_folder.'/_header.php')) {
  145. ob_start();
  146. include($theme_content_folder.'/_header.php');
  147. $body_content['header'] = ob_get_contents();
  148. ob_end_clean();
  149. }
  150. // nav content - below is just for example
  151. /* $body_content['nav'] = '<div id="nav">yeah, nav content</div>'; */
  152. if(file_exists($theme_content_folder.'/_nav.php')) {
  153. ob_start();
  154. include($theme_content_folder.'/_nav.php');
  155. $body_content['nav'] = ob_get_contents();
  156. ob_end_clean();
  157. }
  158. // footer content - below is just for example
  159. /* $body_content['footer'] = '<div id="footer">test footer</div>'; */
  160. if(file_exists($theme_content_folder.'/_footer.php')) {
  161. ob_start();
  162. include($theme_content_folder.'/_footer.php');
  163. $body_content['footer'] = ob_get_contents();
  164. ob_end_clean();
  165. }
  166. // get aside content
  167. /* $body_content['aside'] = insert_aside($aside_content); */
  168. if(file_exists($theme_content_folder.'/_aside.php')) {
  169. ob_start();
  170. include($theme_content_folder.'/_aside.php');
  171. $body_content['aside'] = ob_get_contents();
  172. ob_end_clean();
  173. }
  174. // buffer main content and insert into a variable
  175. ob_start();
  176. include $content_partial;
  177. $body_content['main'] = ob_get_contents();
  178. ob_end_clean();
  179. /*
  180. with a builder file we can use a different html structure
  181. */
  182. if(file_exists($theme_content_folder.'/builder.php')) {
  183. include($theme_content_folder.'/builder.php');
  184. } else {
  185. // output default head section
  186. $head_content = '';
  187. show_head($head_content, $config);
  188. // output default body section
  189. show_body($body_content, $config);
  190. }
  191. } // end checking for $_GET['page_name']
  192. // close caching routine - create file
  193. if(!empty($config['cache']['caching_on'])) {
  194. end_caching($cache_fp, $start);
  195. }
  196. ?>