PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/core/functions.php

https://github.com/allanfreitas/CandyCMS
PHP | 207 lines | 136 code | 63 blank | 8 comment | 16 complexity | f0b3920ade5d0491de6718f5949d7a97 MD5 | raw file
  1. <?php
  2. /**
  3. * @package CandyCMS
  4. * @version 1.0
  5. * @since 0.1
  6. * @copyright Copyright 2012 (C) Cocoon Design Ltd. - All Rights Reserved
  7. *
  8. * The main functions file, contains the biggies!
  9. */
  10. function candytitle($separator = '|'){
  11. $title = Candy::Options('site_title');
  12. $page = (isset($_GET['page'])) ? $_GET['page'] : Candy::Options('homepage');
  13. $page_title = Candy::Pages()->getInfo('page_title', $page);
  14. if (isset($_GET['post']) && $_GET['post'] != '') {
  15. $postTitle = Blog::getPostTitle($_GET['post']);
  16. echo $title, ' ', $separator, ' ', $page_title, ' ', $separator, ' ', $postTitle;
  17. } else {
  18. echo $title, ' ', $separator, ' ', $page_title;
  19. }
  20. }
  21. function candyHead(){
  22. $plugins = Plugins::enabledPlugins();
  23. $return = '';
  24. foreach ($plugins as $plugin) {
  25. if (method_exists($plugin, 'candyHead')) {
  26. $return .= $plugin::candyHead()."\n";
  27. }
  28. }
  29. $return .= '<meta name="generator" content="Candy '.CANDYVERSION.'" />'."\n";
  30. echo $return;
  31. }
  32. function theContent(){
  33. $page = (isset($_GET['page'])) ? $_GET['page'] : Candy::Options('homepage');
  34. $content = Candy::Pages()->getInfo('page_body', $page);
  35. $plugins = Plugins::enabledPlugins();
  36. foreach ($plugins as $plugin) {
  37. if (method_exists($plugin, 'addShorttag')) {
  38. $replace = $plugin::addShorttag();
  39. foreach ($replace as $key => $value) {
  40. $content = str_replace($key, $value, $content);
  41. }
  42. }
  43. }
  44. echo $content;
  45. }
  46. function theField($field){
  47. $page = (isset($_GET['page'])) ? $_GET['page'] : Candy::Options('homepage');
  48. $id = Candy::Pages()->getInfo('page_id', $page);
  49. $dbh = new CandyDB();
  50. $sth = $dbh->prepare("SELECT field_value FROM ".DB_PREFIX."fields WHERE field_name='$field' AND post_id=$id");
  51. $sth->execute();
  52. $content = $sth->fetchColumn();
  53. $plugins = Plugins::enabledPlugins();
  54. foreach ($plugins as $plugin) {
  55. if (method_exists($plugin, 'addShorttag')) {
  56. $replace = $plugin::addShorttag();
  57. foreach ($replace as $key => $value) {
  58. $content = str_replace($key, $value, $content);
  59. }
  60. }
  61. }
  62. echo $content;
  63. }
  64. function getField($field){
  65. ;
  66. $page = (isset($_GET['page'])) ? $_GET['page'] : Candy::Options('homepage');
  67. $id = $Candy['pages']->getInfo('page_id', $page);
  68. $dbh = new CandyDB();
  69. $sth = $dbh->prepare("SELECT field_value FROM ".DB_PREFIX."fields WHERE field_name='$field' AND post_id=$id");
  70. $sth->execute();
  71. $content = $sth->fetchColumn();
  72. $plugins = Plugins::enabledPlugins();
  73. foreach ($plugins as $plugin) {
  74. if (method_exists($plugin, 'addShorttag')) {
  75. $replace = $plugin::addShorttag();
  76. foreach ($replace as $key => $value) {
  77. $content = str_replace($key, $value, $content);
  78. }
  79. }
  80. }
  81. return $content;
  82. }
  83. function theTitle(){
  84. ;
  85. $page = (isset($_GET['page'])) ? $_GET['page'] : Candy::Options('homepage');
  86. echo Candy::Pages()->getInfo('page_title', $page);
  87. }
  88. function theNav($class = 'nav', $active = 'active-page'){
  89. ;
  90. $html = '<ul class="'. $class .'">';
  91. $pages = Candy::Options('nav');
  92. $pages = json_decode($pages);
  93. $path = URL_PATH;
  94. $curpage = (isset($_GET['page'])) ? $_GET['page'] : Candy::Options('homepage');
  95. $info = Candy::Pages()->loadPage($curpage);
  96. $homepage = Candy::Options('homepage');
  97. foreach ($pages as $page) {
  98. $dbh = new CandyDB();
  99. $sth = $dbh->prepare('SELECT page_title, rewrite FROM '. DB_PREFIX .'pages WHERE page_id = '.$page->id);
  100. $sth->execute();
  101. $pages_info = $sth->fetchAll(PDO::FETCH_CLASS);
  102. if (!empty($info)) {
  103. $html .= ($page->id == $info[0]->page_id) ? '<li class="'.$active.'">' : '<li>';
  104. } else {
  105. $html .= '<li>';
  106. }
  107. $html .= ($homepage == $pages_info[0]->rewrite) ? '<a href="'. $path .'" title="'.$pages_info[0]->page_title.'">'. $pages_info[0]->page_title .'</a>' : '<a href="'. $path . $pages_info[0]->rewrite .'">'. $pages_info[0]->page_title .'</a>';
  108. if (isset($page->children)) {
  109. $html .= '<ul class="candy-dropdown">';
  110. foreach ($page->children as $child) {
  111. $sth = $dbh->prepare('SELECT page_title, rewrite FROM '. DB_PREFIX .'pages WHERE page_id = '.$child->id);
  112. $sth->execute();
  113. $child_info = $sth->fetchAll(PDO::FETCH_CLASS);
  114. $html .= '<li>';
  115. $html .= '<a href="'. $path . $child_info[0]->rewrite .'">'. $child_info[0]->page_title .'</a>';
  116. $html .= '</li>';
  117. }
  118. $html .= '</ul>';
  119. }
  120. $html .= '</li>';
  121. }
  122. $html .= '</ul>';
  123. echo $html;
  124. }
  125. function cmsPage($title, $page, $class=false){
  126. $path = URL_PATH;
  127. if ($class == false) {
  128. echo '<a href="'.$path. $page .'" title="'. $title .'">'. $title .'</a>';
  129. } else {
  130. echo '<a href="'.$path. $page .'" title="'. $title .'" class="'.$class.'">'. $title .'</a>';
  131. }
  132. }
  133. function candyCss($filename){
  134. $theme = Candy::Options('theme');
  135. echo '<link rel="stylesheet" href="'.THEME_URL.$theme.'/css/'.$filename.'" type="text/css" />';
  136. }
  137. function candyScript($filename){
  138. $theme = Candy::Options('theme');
  139. echo '<script type="text/javascript" src="'.THEME_URL.$theme.'/js/'.$filename.'"></script>';
  140. }
  141. function candyImg($filename, $alt){
  142. $theme = Candy::Options('theme');
  143. echo '<img src="'.THEME_URL.$theme.'/images/'.$filename.'" alt="'.$alt.'" />';
  144. }