PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_easyblog/helpers/weever.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 274 lines | 203 code | 51 blank | 20 comment | 10 complexity | bd859f64e4ff40940c3856730dacb05f MD5 | raw file
  1. <?php
  2. /**
  3. * @package EasyBlog
  4. * @copyright Copyright (C) 2011 Stack Ideas Private Limited. All rights reserved.
  5. * @license GNU/GPL, see LICENSE.php
  6. *
  7. * EasyBlog 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 COPYRIGHT.php for copyright notices and details.
  12. */
  13. defined('_JEXEC') or die('Restricted access');
  14. class EasyBlogWeeverHelper
  15. {
  16. public function getMainFeed()
  17. {
  18. $obj = new EasyBlogWeeverMain();
  19. return $obj;
  20. }
  21. public function getDetailsFeed()
  22. {
  23. $obj = new EasyBlogWeeverItemDetails();
  24. return $obj;
  25. }
  26. }
  27. class EasyBlogWeeverItem
  28. {
  29. public $r3sVersion = '0.8.1';
  30. public $tags = array();
  31. public $geo = array();
  32. public $url = null;
  33. public $uuid = null;
  34. public $author = null;
  35. public $publisher = null;
  36. public $relationships = null;
  37. public $name = null;
  38. public $datetime = array( 'published' => '' ,
  39. 'modified' => '',
  40. 'start' => '',
  41. 'end' => ''
  42. );
  43. public function toJSON( $exit = false , $callback = '' )
  44. {
  45. require_once( EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'json.php' );
  46. $json = new Services_JSON();
  47. $data = !empty( $callback ) ? $callback . '(' : '';
  48. $data .= $json->encode( $this );
  49. $data .= !empty( $callback ) ? ')' : '';
  50. if( $exit )
  51. {
  52. header('Content-type: application/json');
  53. echo $data;
  54. exit;
  55. }
  56. return $data;
  57. }
  58. public function setImage( $blog )
  59. {
  60. if( $blog->getImage() )
  61. {
  62. $this->image['mobile' ] = $blog->getImage()->getSource( 'mobile' );
  63. $this->image['full'] = $blog->getImage()->getSource( 'original' );
  64. }
  65. }
  66. public function setDateTime( $obj )
  67. {
  68. if( is_object( $obj ) )
  69. {
  70. foreach( $obj as $key => $value )
  71. {
  72. if( isset( $this->datetime[ $key ] ) )
  73. {
  74. $this->datetime[ $key ] = $value;
  75. }
  76. }
  77. }
  78. if( is_string( $obj ) )
  79. {
  80. $this->datetime[ 'published' ] = $obj;
  81. }
  82. }
  83. public function setGeo( $lat , $lng )
  84. {
  85. return;
  86. $this->geo[ 'latitude' ] = $lat;
  87. $this->geo[ 'longitude' ] = $lng;
  88. }
  89. public function set( $key , $value = '' )
  90. {
  91. $this->$key = $value;
  92. }
  93. public function setAuthor( $userId )
  94. {
  95. $user = EasyBlogHelper::getTable( 'Profile' );
  96. $user->load( $userId );
  97. $this->author = $user->getName();
  98. $this->publisher = $user->getName();
  99. }
  100. public function setTags( &$item )
  101. {
  102. if( !( $item instanceof TableBlog ) )
  103. {
  104. $blog = EasyBlogHelper::getTable( 'Blog' );
  105. $blog->load( $item->id );
  106. }
  107. else
  108. {
  109. $blog = $item;
  110. }
  111. $tags = $blog->getTags();
  112. if( $tags )
  113. {
  114. foreach( $tags as $tag )
  115. {
  116. $data = array();
  117. $data[ 'name' ] = $tag->title;
  118. $data[ 'link' ] = EasyBlogRouter::getRoutedUrl( 'index.php?option=com_easyblog&view=tag&layout=listings&format=weever&id=' . $tag->id , false , true );
  119. $this->tags[] = $data;
  120. }
  121. }
  122. }
  123. public function map( &$blog )
  124. {
  125. $ignore = array( 'image' , 'datetime' , 'tags' , 'geo' );
  126. foreach( $blog as $key => $value )
  127. {
  128. if( isset( $this->$key ) && !in_array( $key , $ignore ) )
  129. {
  130. $this->$key = $value;
  131. }
  132. }
  133. $this->name = $blog->title;
  134. $dateTimeObject = new stdClass();
  135. $dateTimeObject->published = $blog->created;
  136. $dateTimeObject->modified = $blog->created;
  137. $dateTimeObject->start = '';
  138. $dateTimeObject->end = '';
  139. // @task: Set the author
  140. $this->setAuthor( $blog->created_by );
  141. // @task: Set the datetime of the blog post
  142. $this->setDateTime( $dateTimeObject );
  143. // @task: Set the URL
  144. $this->url = EasyBlogRouter::getRoutedUrl( 'index.php?option=com_easyblog&view=entry&id=' . $blog->id . '&format=weever' , false , true );
  145. // @task: Set the geolocation
  146. $this->setGeo( $blog->latitude , $blog->longitude );
  147. // @task: Set the blog image
  148. $this->setImage( $blog );
  149. // @task: Set the tags
  150. $this->setTags( $blog );
  151. return $this;
  152. }
  153. }
  154. class EasyBlogWeeverMain extends EasyBlogWeeverItem
  155. {
  156. public $thisPage = null;
  157. public $lastPage = null;
  158. public $count = 15;
  159. public $type = 'htmlContent';
  160. public $sort = 'rdate';
  161. public $language = 'en-GB';
  162. public $copyright = null;
  163. public $license = null;
  164. public $generator = 'EasyBlog R3S Template for Weever App';
  165. public $image = array('mobile' => '' , 'full' => '');
  166. public $publisher = null;
  167. public $rating = null;
  168. public $url = null;
  169. public $description = null;
  170. public function __construct()
  171. {
  172. }
  173. public function addChild( &$blog )
  174. {
  175. $summary = new EasyBlogWeeverItemSummary();
  176. $this->items[] = $summary->map( $blog );
  177. }
  178. }
  179. class EasyBlogWeeverItemDetails extends EasyBlogWeeverItem
  180. {
  181. public $html = null;
  182. public $url = null;
  183. public $geo = array();
  184. public function toJSON( $exit = false , $callback = '' )
  185. {
  186. require_once( EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'json.php' );
  187. $json = new Services_JSON();
  188. $data = !empty( $callback ) ? $callback . '(' : '';
  189. $data .= $json->encode( array( 'results' => array( $this ) ) );
  190. $data .= !empty( $callback ) ? ')' : '';
  191. if( $exit )
  192. {
  193. header('Content-type: application/json');
  194. echo $data;
  195. exit;
  196. }
  197. return $data;
  198. }
  199. public function map( &$blog )
  200. {
  201. parent::map( $blog );
  202. // @task: Process blog triggers here.
  203. // @rule: Process videos
  204. $blog->intro = EasyBlogHelper::getHelper( 'Videos' )->processVideos( $blog->intro );
  205. $blog->content = EasyBlogHelper::getHelper( 'Videos' )->processVideos( $blog->content );
  206. $blogger = EasyBlogHelper::getTable( 'Profile' );
  207. $blogger->load( $blog->created_by );
  208. // Assign custom variables
  209. $blog->author = $blogger;
  210. $themes = new CodeThemes();
  211. $themes->set( 'blog' , $blog );
  212. $themes->set( 'blogger' , $blogger );
  213. $content = $themes->fetch( 'read.weever.php' );
  214. $this->set( 'html' , $content );
  215. return $this;
  216. }
  217. }
  218. class EasyBlogWeeverItemSummary extends EasyBlogWeeverItem
  219. {
  220. public $type = 'htmlContent';
  221. public $description = '';
  222. public $image = array('mobile' => '' , 'full' => '');
  223. }