PageRenderTime 61ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/perch/core/apps/content/runtime.php

https://bitbucket.org/pauver/dirty-bastards
PHP | 241 lines | 164 code | 65 blank | 12 comment | 36 complexity | 98be6135be08d35fe922b3ba75cc1293 MD5 | raw file
  1. <?php
  2. include(PERCH_CORE.'/apps/content/PerchContent_Regions.class.php');
  3. include(PERCH_CORE.'/apps/content/PerchContent_Region.class.php');
  4. include(PERCH_CORE.'/apps/content/PerchContent_Items.class.php');
  5. include(PERCH_CORE.'/apps/content/PerchContent_Item.class.php');
  6. include(PERCH_CORE.'/apps/content/PerchContent_Pages.class.php');
  7. include(PERCH_CORE.'/apps/content/PerchContent_Page.class.php');
  8. include(PERCH_CORE.'/apps/content/PerchContent.class.php');
  9. perch_content_check_preview();
  10. function perch_content($key=false, $return=false)
  11. {
  12. if ($key === false) {
  13. echo 'You must pass in a <em>name</em> for the content. e.g. <code style="color: navy;background: white;">&lt;' . '?php perch_content(\'Phone number\'); ?' . '&gt;</code>';
  14. }
  15. $Content = PerchContent::fetch();
  16. $out = $Content->get($key);
  17. // Post processing - if there are still <perch:x /> tags
  18. if (strpos($out, '<perch:')!==false) {
  19. $Template = new PerchTemplate();
  20. $out = $Template->apply_runtime_post_processing($out);
  21. }
  22. if ($return) return $out;
  23. echo $out;
  24. }
  25. function perch_content_custom($key=false, $opts=false, $return=false)
  26. {
  27. if ($key === false) return ' ';
  28. if (isset($opts['skip-template']) && $opts['skip-template']==true) {
  29. $return = true;
  30. $postpro = false;
  31. }else{
  32. $postpro = true;
  33. }
  34. $Content = PerchContent::fetch();
  35. $out = $Content->get_custom($key, $opts);
  36. // Post processing - if there are still <perch:x /> tags
  37. if ($postpro && !is_array($out) && strpos($out, '<perch:')!==false) {
  38. $Template = new PerchTemplate();
  39. $out = $Template->apply_runtime_post_processing($out);
  40. }
  41. if ($return) return $out;
  42. echo $out;
  43. }
  44. function perch_content_check_preview()
  45. {
  46. if (!defined('PERCH_PREVIEW_ARG')) define('PERCH_PREVIEW_ARG', 'preview');
  47. if (isset($_GET[PERCH_PREVIEW_ARG])) {
  48. if ($_GET[PERCH_PREVIEW_ARG] == 'all') {
  49. $contentID = 'all';
  50. }else{
  51. $contentID = (int)$_GET[PERCH_PREVIEW_ARG];
  52. }
  53. $rev = false;
  54. $Users = new PerchUsers;
  55. $CurrentUser = $Users->get_current_user();
  56. if (is_object($CurrentUser) && $CurrentUser->logged_in()) {
  57. $Content = PerchContent::fetch();
  58. $Content->set_preview($contentID, $rev);
  59. }
  60. }
  61. }
  62. function perch_content_search($key=false, $opts=false, $return=false)
  63. {
  64. $key = trim(stripslashes($key));
  65. $Content = PerchContent::fetch();
  66. $defaults = array();
  67. $defaults['template'] = 'search-result.html';
  68. $defaults['count'] = 10;
  69. $defaults['excerpt-chars'] = 250;
  70. $defaults['from-path'] = '/';
  71. $defaults['hide-extensions'] = false;
  72. if (is_array($opts)) {
  73. $opts = array_merge($defaults, $opts);
  74. }else{
  75. $opts = $defaults;
  76. }
  77. if (isset($opts['hide_extensions'])) $opts['hide-extensions'] = $opts['hide_extensions'];
  78. if (isset($opts['from_path'])) $opts['from-path'] = $opts['from_path'];
  79. if (isset($opts['excerpt_chars'])) $opts['excerpt-chars'] = $opts['excerpt_chars'];
  80. $out = $Content->search_content($key, $opts);
  81. // Post processing - if there are still <perch:x /> tags
  82. if (strpos($out, '<perch:')!==false) {
  83. $Template = new PerchTemplate();
  84. $out = $Template->apply_runtime_post_processing($out);
  85. }
  86. if ($return) return $out;
  87. echo $out;
  88. }
  89. function perch_page_title($return=false)
  90. {
  91. if ($return) return perch_pages_title(true);
  92. perch_pages_title();
  93. }
  94. function perch_pages_title($return=false)
  95. {
  96. $Pages = new PerchContent_Pages;
  97. $Perch = Perch::fetch();
  98. $Page = $Pages->find_by_path($Perch->get_page());
  99. $r = '';
  100. if (is_object($Page)) {
  101. $r = $Page->pageTitle();
  102. }
  103. if ($return) return $r;
  104. echo $r;
  105. }
  106. function perch_pages_navigation($opts=array(), $return=false)
  107. {
  108. $Pages = new PerchContent_Pages;
  109. $Perch = Perch::fetch();
  110. // translate renamed options from Perch v1
  111. if (isset($opts['from_path'])) $opts['from-path'] = $opts['from_path'];
  112. if (isset($opts['hide_extensions'])) $opts['hide-extensions'] = $opts['hide_extensions'];
  113. $default_opts = array(
  114. 'from-path'=>'/',
  115. 'levels'=>0,
  116. 'hide-extensions'=>false,
  117. 'hide-default-doc'=>true,
  118. 'flat'=>false,
  119. 'template'=>array('item.html'),
  120. 'include-parent'=>false,
  121. 'skip-template'=>false,
  122. 'siblings'=>false,
  123. 'only-expand-selected'=>false
  124. );
  125. if (is_array($opts)) {
  126. $opts = array_merge($default_opts, $opts);
  127. }else{
  128. $opts = $default_opts;
  129. }
  130. if ($opts['skip-template']) $return = true;
  131. $current_page = $Perch->get_page();
  132. if ($opts['from-path']=='*') {
  133. $opts['from-path'] = $current_page;
  134. }
  135. $r = $Pages->get_navigation($opts, $current_page);
  136. if ($return) return $r;
  137. echo $r;
  138. }
  139. function perch_pages_breadcrumbs($opts=array(), $return=false)
  140. {
  141. $Pages = new PerchContent_Pages;
  142. $Perch = Perch::fetch();
  143. $default_opts = array(
  144. 'hide-extensions'=>false,
  145. 'hide-default-doc'=>true,
  146. 'template'=>'breadcrumbs.html',
  147. 'skip-template'=>false
  148. );
  149. if (is_array($opts)) {
  150. $opts = array_merge($default_opts, $opts);
  151. }else{
  152. $opts = $default_opts;
  153. }
  154. if ($opts['skip-template']) $return = true;
  155. $current_page = $Perch->get_page();
  156. $opts['from-path'] = $current_page;
  157. $r = $Pages->get_breadcrumbs($opts);
  158. if ($return) return $r;
  159. echo $r;
  160. }
  161. /**
  162. * Get an item from the querystring, or return the default if not found. Defaults to false.
  163. *
  164. * @param string $var
  165. * @param string $default
  166. * @return void
  167. * @author Drew McLellan
  168. */
  169. function perch_get($var, $default=false)
  170. {
  171. if (isset($_GET[$var]) && $_GET[$var]!='') {
  172. return $_GET[$var];
  173. }
  174. return $default;
  175. }
  176. ?>