/webroot/rss/functions.php

https://github.com/iconifyit/SkyBlue-CMS · PHP · 106 lines · 84 code · 8 blank · 14 comment · 27 complexity · 1734c207785ab7ba4237788602490d77 MD5 · raw file

  1. <?php defined('SKYBLUE') or die('Bad File Request');
  2. /**
  3. * @version v 1.2 2009-06-15 23:55:00 $
  4. * @package SkyBlueCanvas
  5. * @copyright Copyright (C) 2005 - 2010 Scott Edwin Lewis. All rights reserved.
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * SkyBlueCanvas is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYING.txt for copyright notices and details.
  12. */
  13. function rss_syndicated($item) {
  14. if (!isset($item->syndicate)) return true;
  15. return $item->syndicate;
  16. }
  17. function rss_date($date) {
  18. return date("D, j M Y H:i:s T", strtotime(str_replace('T', null, $date)));
  19. }
  20. function rss_site_description() {
  21. Loader::load("managers.meta.helpers.*", true, _SBC_SYS_);
  22. $description = RSS_NO_DESCRIPTION;
  23. $meta = MetaHelper::getMetaData();
  24. foreach ($meta as $m) {
  25. if ($m->name == 'description') {
  26. $description = $m->content;
  27. break;
  28. }
  29. }
  30. return $description;
  31. }
  32. function rss_end_of_sentence($shred) {
  33. if ($shred{strlen($shred)-1} == '.' ||
  34. strlen($shred) < 1 ||
  35. strpos($shred, '.') === false)
  36. {
  37. return $shred;
  38. }
  39. else {
  40. $words = explode(' ', $shred);
  41. for ($i=count($words); $i>0; $i--) {
  42. $word = $words[$i];
  43. if ($word == '.' || $word{strlen($word)-1} == '.') {
  44. $shred = implode(' ', array_slice($words, 0, $i+1));
  45. }
  46. }
  47. return $shred;
  48. }
  49. }
  50. function rss_filter_tokens($text) {
  51. // Filter out snippet calls
  52. $regex = "/({snippet\(([^}]*)\)})/i";
  53. if (preg_match_all($regex, $text, $matches)) {
  54. $tokens = $matches[0];
  55. for ($i=0; $i<count($tokens); $i++) {
  56. $text = str_replace($tokens[$i], "", $text);
  57. }
  58. }
  59. // Filter out fragment calls
  60. $regex = "/({fragment\(([^}]*)\)})/i";
  61. if (preg_match_all($regex, $text, $matches)) {
  62. $tokens = $matches[0];
  63. for ($i=0; $i<count($tokens); $i++) {
  64. $text = str_replace($tokens[$i], "", $text);
  65. }
  66. }
  67. // Filter out skyblue vars
  68. $regex = "/\[\[(.*)\]\]/i";
  69. if (preg_match_all($regex, $text, $matches)) {
  70. $tokens = $matches[0];
  71. for ($i=0; $i<count($tokens); $i++) {
  72. $text = str_replace($tokens[$i], "", $text);
  73. }
  74. }
  75. return $text;
  76. }
  77. function rss_text_blob($shred, $length=RSS_TEXT_LENGTH) {
  78. if (strlen($shred) <= $length) return rss_filter_tokens($shred);
  79. $text = null;
  80. $n=0;
  81. while (strlen($text) < $length || $n==$length) {
  82. $text .= $shred{$n};
  83. $n++;
  84. }
  85. return rss_filter_tokens($text);
  86. }
  87. function rss_story_text($content) {
  88. global $Core;
  89. if (trim($content) != "") {
  90. $content = base64_decode($content);
  91. $shred = str_replace(">", "> ", $content);
  92. if (trim($shred) != "") {
  93. $shred = rss_text_blob(strip_tags($shred), RSS_TEXT_LENGTH);
  94. }
  95. return ( trim($shred) == "" ? RSS_NO_DESCRIPTION : $shred );
  96. }
  97. return RSS_NO_DESCRIPTION;
  98. }