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

/administrator/components/com_easyblog/models/blogger.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 323 lines | 215 code | 66 blank | 42 comment | 31 complexity | ae1a57c942e5d4299e388dea9db959d9 MD5 | raw file
  1. <?php
  2. /**
  3. * @package EasyBlog
  4. * @copyright Copyright (C) 2010 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. require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'parent.php' );
  15. class EasyBlogModelBlogger extends EasyBlogModelParent
  16. {
  17. /**
  18. * Category total
  19. *
  20. * @var integer
  21. */
  22. var $_total = null;
  23. /**
  24. * Pagination object
  25. *
  26. * @var object
  27. */
  28. var $_pagination = null;
  29. /**
  30. * Category data array
  31. *
  32. * @var array
  33. */
  34. var $_data = null;
  35. function __construct()
  36. {
  37. parent::__construct();
  38. $mainframe = JFactory::getApplication();
  39. $limit = ($mainframe->getCfg('list_limit') == 0) ? 5 : $mainframe->getCfg('list_limit');
  40. $limitstart = JRequest::getVar('limitstart', 0, 'REQUEST');
  41. // In case limit has been changed, adjust it
  42. $limitstart = (int) ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
  43. $this->setState('limit', $limit);
  44. $this->setState('limitstart', $limitstart);
  45. }
  46. /**
  47. * Method to get a pagination object for the categories
  48. *
  49. * @access public
  50. * @return integer
  51. */
  52. function getPagination()
  53. {
  54. return $this->_pagination;
  55. }
  56. function getBloggers($sort = 'latest', $limit = 0, $filter='showallblogger')
  57. {
  58. $db = EasyBlogHelper::db();
  59. require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'helper.php' );
  60. $config = EasyBlogHelper::getConfig();
  61. $nameDisplayFormat = $config->get('layout_nameformat');
  62. $limitSQL = '';
  63. if( !is_null( $limit ) )
  64. {
  65. $limit = ($limit == 0) ? $this->getState('limit') : $limit;
  66. $limitstart = $this->getState('limitstart');
  67. $limitSQL = ' LIMIT ' . $limitstart . ',' . $limit;
  68. }
  69. $query = 'SELECT COUNT(1) FROM (';
  70. $query .= ' (SELECT a.`id`';
  71. $query .= ' FROM `#__users` AS `a`';
  72. $query .= ' INNER JOIN `#__easyblog_users` AS `b` ON a.`id` = b.`id`';
  73. if( EasyBlogHelper::getJoomlaVersion() >= '1.6' )
  74. {
  75. $query .= ' INNER JOIN `#__user_usergroup_map` AS `d` ON d.`user_id` = a.`id`';
  76. }
  77. else
  78. {
  79. $query .= ' INNER JOIN `#__core_acl_aro` AS `c` ON a.`id` = c.`value`';
  80. $query .= ' AND c.`section_value` = ' . $db->Quote('users');
  81. $query .= ' INNER JOIN `#__core_acl_groups_aro_map` AS `d` ON c.`id` = d.`aro_id`';
  82. }
  83. $query .= ' INNER JOIN `#__easyblog_acl_group` AS `e` ON d.`group_id` = e.`content_id`';
  84. $query .= ' AND e.`type` = ' . $db->Quote('group') . ' AND e.`status` = 1';
  85. $query .= ' INNER JOIN `#__easyblog_acl` as `f` ON e.`acl_id` = f.`id`';
  86. $query .= ' AND f.`action` = ' . $db->Quote('add_entry');
  87. $query .= ' LEFT JOIN `#__easyblog_post` AS `p` ON a.`id` = p.`created_by`';
  88. $query .= ' GROUP BY a.`id`';
  89. if($filter == 'showbloggerwithpost')
  90. $query .= ' HAVING (COUNT(p.`id`) > 0)';
  91. $query .= ' )';
  92. $query .= ' UNION ';
  93. $query .= ' (SELECT a1.`id`';
  94. $query .= ' FROM `#__users` AS `a1`';
  95. $query .= ' INNER JOIN `#__easyblog_users` AS `b1` ON a1.`id` = b1.`id`';
  96. $query .= ' INNER JOIN `#__easyblog_acl_group` AS `c1` ON a1.`id` = c1.`content_id`';
  97. $query .= ' AND c1.`type` = ' . $db->Quote('assigned') . ' AND c1.`status` = 1';
  98. $query .= ' INNER JOIN `#__easyblog_acl` as `d1` ON c1.`acl_id` = d1.`id`';
  99. $query .= ' AND d1.`action` = ' . $db->Quote('add_entry');
  100. $query .= ' LEFT JOIN `#__easyblog_post` AS `p1` ON a1.`id` = p1.`created_by`';
  101. $query .= ' GROUP BY a1.`id`';
  102. if($filter == 'showbloggerwithpost')
  103. $query .= ' HAVING (COUNT(p1.`id`) > 0)';
  104. $query .= ' )';
  105. $query .= ' ) as x';
  106. //echo $query;
  107. //exit;
  108. $db->setQuery( $query );
  109. $this->_total = $db->loadResult();
  110. if($db->getErrorNum())
  111. {
  112. JError::raiseError( 500, $db->stderr());
  113. }
  114. if( empty($this->_pagination) && !empty( $limitSQL ) )
  115. {
  116. jimport('joomla.html.pagination');
  117. $this->_pagination = new JPagination( $this->_total , $limitstart , $limit);
  118. }
  119. // $query = 'SELECT a.`id`, b.`nickname`, b.`avatar`, b.`description`,';
  120. // $query .= ' a.`name`, a.`username`, a.`registerDate`, a.`lastvisitDate`';
  121. // $query .= ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__users' ) . ' AS `a`';
  122. // $query .= ' INNER JOIN '.EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__easyblog_users' ) . ' AS `b`';
  123. // $query .= ' ON a.`id` = b.`id`';
  124. $query = 'SELECT x.* FROM (';
  125. $query .= ' (SELECT a.`id`, b.`nickname`, b.`avatar`, b.`description`,';
  126. $query .= ' a.`name`, a.`username`, a.`registerDate`, a.`lastvisitDate`,';
  127. $query .= ' COUNT(p.`id`) as `totalPost`, MAX(p.`created`) as `latestPostDate`';
  128. $query .= ' FROM `#__users` AS `a`';
  129. $query .= ' INNER JOIN `#__easyblog_users` AS `b` ON a.`id` = b.`id`';
  130. if( EasyBlogHelper::getJoomlaVersion() >= '1.6' )
  131. {
  132. $query .= ' INNER JOIN `#__user_usergroup_map` AS `d` ON d.`user_id` = a.`id`';
  133. }
  134. else
  135. {
  136. $query .= ' INNER JOIN `#__core_acl_aro` AS `c` ON a.`id` = c.`value`';
  137. $query .= ' AND c.`section_value` = ' . $db->Quote('users');
  138. $query .= ' INNER JOIN `#__core_acl_groups_aro_map` AS `d` ON c.`id` = d.`aro_id`';
  139. }
  140. $query .= ' INNER JOIN `#__easyblog_acl_group` AS `e` ON d.`group_id` = e.`content_id`';
  141. $query .= ' AND e.`type` = ' . $db->Quote('group') . ' AND e.`status` = 1';
  142. $query .= ' INNER JOIN `#__easyblog_acl` as `f` ON e.`acl_id` = f.`id`';
  143. $query .= ' AND f.`action` = ' . $db->Quote('add_entry');
  144. $query .= ' LEFT JOIN `#__easyblog_post` AS `p` ON a.`id` = p.`created_by`';
  145. $query .= ' GROUP BY a.`id`';
  146. if($filter == 'showbloggerwithpost')
  147. $query .= ' HAVING (COUNT(p.`id`) > 0)';
  148. $query .= ' )';
  149. $query .= ' UNION ';
  150. $query .= ' (SELECT a1.`id`, b1.`nickname`, b1.`avatar`, b1.`description`,';
  151. $query .= ' a1.`name`, a1.`username`, a1.`registerDate`, a1.`lastvisitDate`,';
  152. $query .= ' COUNT(p1.`id`) as `totalPost`, MAX(p1.`created`) as `latestPostDate`';
  153. $query .= ' FROM `#__users` AS `a1`';
  154. $query .= ' INNER JOIN `#__easyblog_users` AS `b1` ON a1.`id` = b1.`id`';
  155. $query .= ' INNER JOIN `#__easyblog_acl_group` AS `c1` ON a1.`id` = c1.`content_id`';
  156. $query .= ' AND c1.`type` = ' . $db->Quote('assigned') . ' AND c1.`status` = 1';
  157. $query .= ' INNER JOIN `#__easyblog_acl` as `d1` ON c1.`acl_id` = d1.`id`';
  158. $query .= ' AND d1.`action` = ' . $db->Quote('add_entry');
  159. $query .= ' LEFT JOIN `#__easyblog_post` AS `p1` ON a1.`id` = p1.`created_by`';
  160. $query .= ' GROUP BY a1.`id`';
  161. if($filter == 'showbloggerwithpost')
  162. $query .= ' HAVING (COUNT(p1.`id`) > 0)';
  163. $query .= ' )';
  164. $query .= ' ) as x';
  165. switch($sort)
  166. {
  167. case 'latestpost' :
  168. $query .= ' ORDER BY x.`latestPostDate` DESC';
  169. break;
  170. case 'latest' :
  171. $query .= ' ORDER BY x.`registerDate` DESC';
  172. break;
  173. case 'active' :
  174. $query .= ' ORDER BY x.`lastvisitDate` DESC';
  175. break;
  176. case 'alphabet' :
  177. if($nameDisplayFormat == 'name')
  178. $query .= ' ORDER BY x.`name` ASC';
  179. else if($nameDisplayFormat == 'username')
  180. $query .= ' ORDER BY x.`username` ASC';
  181. else
  182. $query .= ' ORDER BY x.`nickname` ASC';
  183. break;
  184. default :
  185. break;
  186. }
  187. $query .= $limitSQL;
  188. //echo $query;
  189. $db->setQuery( $query );
  190. $result = $db->loadObjectList();
  191. if($db->getErrorNum())
  192. {
  193. JError::raiseError( 500, $db->stderr());
  194. }
  195. return $result;
  196. }
  197. function isBloggerSubscribedUser($bloggerId, $userId)
  198. {
  199. $db = EasyBlogHelper::db();
  200. $query = 'SELECT `id` FROM `#__easyblog_blogger_subscription`';
  201. $query .= ' WHERE `blogger_id` = ' . $db->Quote($bloggerId);
  202. $query .= ' AND `user_id` = ' . $db->Quote($userId);
  203. $db->setQuery($query);
  204. $result = $db->loadResult();
  205. return $result;
  206. }
  207. function isBloggerSubscribedEmail($bloggerId, $email)
  208. {
  209. $db = EasyBlogHelper::db();
  210. $query = 'SELECT `id` FROM `#__easyblog_blogger_subscription`';
  211. $query .= ' WHERE `blogger_id` = ' . $db->Quote($bloggerId);
  212. $query .= ' AND `email` = ' . $db->Quote($email);
  213. $db->setQuery($query);
  214. $result = $db->loadResult();
  215. return $result;
  216. }
  217. function addBloggerSubscription($bloggerId, $email, $userId = '0')
  218. {
  219. $config = EasyBlogHelper::getConfig();
  220. $acl = EasyBlogACLHelper::getRuleSet();
  221. $my = JFactory::getUser();
  222. if($acl->rules->allow_subscription || (empty($my->id) && $config->get('main_allowguestsubscribe')))
  223. {
  224. $date = EasyBlogHelper::getDate();
  225. $subscriber = EasyBlogHelper::getTable( 'BloggerSubscription', 'Table' );
  226. $subscriber->blogger_id = $bloggerId;
  227. $subscriber->email = $email;
  228. if($userId != '0')
  229. $subscriber->user_id = $userId;
  230. $subscriber->created = $date->toMySQL();
  231. $subscriber->store();
  232. }
  233. }
  234. function updateBloggerSubscriptionEmail($sid, $email)
  235. {
  236. $config = EasyBlogHelper::getConfig();
  237. $acl = EasyBlogACLHelper::getRuleSet();
  238. $my = JFactory::getUser();
  239. if($acl->rules->allow_subscription || (empty($my->id) && $config->get('main_allowguestsubscribe')))
  240. {
  241. $subscriber = EasyBlogHelper::getTable( 'BloggerSubscription', 'Table' );
  242. $subscriber->load($sid);
  243. $subscriber->email = $email;
  244. $subscriber->store();
  245. }
  246. }
  247. function getBlogggerSubscribers($bloggerId)
  248. {
  249. $db = EasyBlogHelper::db();
  250. $query = "SELECT *. 'bloggersubscription' as `type` FROM `#__easyblog_blogger_subscription`";
  251. $query .= " WHERE `blogger_id` = " . $db->Quote($bloggerId);
  252. //echo $query . '<br/><br/>';
  253. $db->setQuery($query);
  254. $result = $db->loadObjectList();
  255. return $result;
  256. }
  257. }