PageRenderTime 27ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_easyblog/tables/profile.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 539 lines | 391 code | 90 blank | 58 comment | 43 complexity | b2b917364d5519c6bb49ef7d09991b99 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. * EasyBlog is free software. This version may have been modified pursuant
  7. * to the GNU General Public License, and as distributed it includes or
  8. * is derivative of works licensed under the GNU General Public License or
  9. * other free or open source software licenses.
  10. * See COPYRIGHT.php for copyright notices and details.
  11. */
  12. defined('_JEXEC') or die('Restricted access');
  13. require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'table.php' );
  14. require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'image.php' );
  15. require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'string.php' );
  16. class EasyBlogTableProfile extends EasyBlogTable
  17. {
  18. var $id = null;
  19. var $title = null;
  20. var $nickname = null;
  21. var $avatar = null;
  22. var $description = null;
  23. var $biography = null;
  24. var $url = null;
  25. var $params = null;
  26. var $user = null;
  27. var $permalink = null;
  28. /**
  29. * Constructor for this class.
  30. *
  31. * @return
  32. * @param object $db
  33. */
  34. function __construct(& $db )
  35. {
  36. parent::__construct( '#__easyblog_users' , 'id' , $db );
  37. }
  38. function bind( $data, $ignore = array() )
  39. {
  40. parent::bind( $data, $ignore );
  41. $this->url = $this->_appendHTTP( $this->url );
  42. //default to username for blogger permalink if empty
  43. if(empty($this->permalink))
  44. {
  45. $user = JFactory::getUser($this->id);
  46. $this->permalink = ( isset($user->username) ) ? $user->username : $this->id;
  47. }
  48. else
  49. {
  50. $this->permalink = JFilterOutput::stringURLSafe($this->permalink);
  51. }
  52. return true;
  53. }
  54. public function store($updateNulls = false)
  55. {
  56. $isNew = ( empty( $this->id ) ) ? true : false;
  57. $state = parent::store($updateNulls);
  58. $my = JFactory::getUser();
  59. if( $my->id == $this->id )
  60. {
  61. JFactory::getLanguage()->load( 'com_easyblog' , JPATH_ROOT );
  62. // @rule: Integrations with EasyDiscuss
  63. EasyBlogHelper::getHelper( 'EasyDiscuss' )->log( 'easyblog.update.profile' , $this->id , JText::_( 'COM_EASYBLOG_EASYDISCUSS_HISTORY_UPDATE_PROFILE' ) );
  64. EasyBlogHelper::getHelper( 'EasyDiscuss' )->addPoint( 'easyblog.update.profile' , $this->id );
  65. EasyBlogHelper::getHelper( 'EasyDiscuss' )->addBadge( 'easyblog.update.profile' , $this->id );
  66. }
  67. if( ! $isNew )
  68. {
  69. $activity = new stdClass();
  70. $activity->actor_id = $my->id;
  71. $activity->target_id = ( $my->id == $this->id ) ? '0' : $this->id;
  72. $activity->context_type = 'profile';
  73. $activity->context_id = $this->id;
  74. $activity->verb = 'update';
  75. EasyBlogHelper::activityLog( $activity );
  76. }
  77. return $state;
  78. }
  79. function _createDefault( $id )
  80. {
  81. $db = $this->getDBO();
  82. $user = JFactory::getUser($id);
  83. $obj = new stdClass();
  84. $obj->id = $user->id;
  85. $obj->nickname = $user->name;
  86. $obj->avatar = 'default_blogger.png';
  87. $obj->description = '';
  88. $obj->url = '';
  89. $obj->params = '';
  90. //default to username for blogger permalink
  91. $obj->permalink = $user->username;
  92. $db->insertObject('#__easyblog_users', $obj);
  93. return $obj;
  94. }
  95. /**
  96. * override load method.
  97. * if user record not found in eblog_profile, create one record.
  98. *
  99. */
  100. function load($id = null, $reset = true)
  101. {
  102. static $users = null;
  103. $id = ( $id == '0' ) ? null : $id;
  104. if( is_null($id) )
  105. {
  106. $this->bind( JFactory::getUser(0) );
  107. return $this;
  108. }
  109. if (empty($id))
  110. {
  111. // When the id is null or 0
  112. $this->bind( JFactory::getUser() );
  113. return $this;
  114. }
  115. if( !isset( $users[ $id ] ) )
  116. {
  117. if((! parent::load($id)) && ($id != 0))
  118. {
  119. $obj = $this->_createDefault($id);
  120. $this->bind( $obj );
  121. }
  122. $users[ $id ] = clone $this;
  123. }
  124. $this->user = JFactory::getUser( $id );
  125. $this->bind( $users[ $id ] );
  126. return $users[ $id ];
  127. }
  128. function setUser( $my )
  129. {
  130. $this->load( $my->id );
  131. $this->user = $my;
  132. }
  133. function getLink()
  134. {
  135. return EasyBlogRouter::_('index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $this->id);
  136. }
  137. function getName(){
  138. if($this->id == 0)
  139. {
  140. return JText::_('COM_EASYBLOG_GUEST');
  141. }
  142. $config = EasyBlogHelper::getConfig();
  143. $displayname = $config->get('layout_nameformat');
  144. if( !$this->user )
  145. {
  146. $this->user = JFactory::getUser( $this->id );
  147. }
  148. switch($displayname)
  149. {
  150. case "name" :
  151. $name = $this->user->name;
  152. break;
  153. case "username" :
  154. $name = $this->user->username;
  155. break;
  156. case "nickname" :
  157. default :
  158. $name = (empty($this->nickname)) ? $this->user->name : $this->nickname;
  159. break;
  160. }
  161. return EasyBlogStringHelper::escape( $name );
  162. }
  163. function getId(){
  164. return $this->id;
  165. }
  166. /**
  167. * Retrieves the user's avatar
  168. *
  169. **/
  170. function getAvatar()
  171. {
  172. return EasyBlogHelper::getHelper( 'avatar' )->getAvatarURL( $this );
  173. }
  174. function getDescription($raw = false)
  175. {
  176. $description = $raw ? $this->description : nl2br($this->description);
  177. return $description;
  178. }
  179. /**
  180. * Retrieves the user's twitter link
  181. **/
  182. function getTwitterLink()
  183. {
  184. return EasyBlogHelper::getHelper( 'SocialShare' )->getLink( 'twitter' , $this->id );
  185. }
  186. /**
  187. * Determines whether the blogger is a featured blogger
  188. **/
  189. function isFeatured()
  190. {
  191. return EasyBlogHelper::isFeatured( 'blogger', $this->id );
  192. }
  193. /**
  194. * Retrieves the biography from the specific blogger
  195. **/
  196. function getBiography($raw = false)
  197. {
  198. static $loaded = array();
  199. if( !isset( $loaded[ $this->id ] ) )
  200. {
  201. $status = '';
  202. $config = EasyBlogHelper::getConfig();
  203. if( $config->get( 'integrations_jomsocial_blogger_status' ) )
  204. {
  205. $path = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'core.php';
  206. if( JFile::exists( $path ) )
  207. {
  208. require_once( $path );
  209. require_once( JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'string.php' );
  210. $user = CFactory::getUser( $this->id );
  211. $status = $user->getStatus();
  212. }
  213. }
  214. if( !empty( $this->biography ) && empty( $status ) )
  215. {
  216. $status = $raw ? $this->biography : nl2br( $this->biography );
  217. }
  218. if( empty( $status ) )
  219. {
  220. $lang = JFactory::getLanguage();
  221. $lang->load( 'com_easyblog' , JPATH_ROOT );
  222. $status = JText::sprintf( 'COM_EASYBLOG_BIOGRAPHY_NOT_SET' , $this->getName() );
  223. }
  224. $loaded[ $this->id ] = $status;
  225. }
  226. return $loaded[ $this->id ];
  227. }
  228. function getWebsite()
  229. {
  230. $url = $this->url == 'http://' ? '' : $this->url;
  231. return $url;
  232. }
  233. /*
  234. * Generates profile links for the author.
  235. *
  236. * @param null
  237. * @return string The link to their profile
  238. */
  239. public function getProfileLink( $defaultItemId = '' )
  240. {
  241. static $instance = array();
  242. static $phpbbDB = null;
  243. static $phpbbpath = null;
  244. static $isBlogger = array();
  245. // since it's for avatar, we'll follow the avatar's integration
  246. $config = EasyBlogHelper::getConfig();
  247. $source = $config->get( 'layout_avatarIntegration' );
  248. if(! $config->get('main_nonblogger_profile') )
  249. {
  250. // 1st check if this user a blogger or not.
  251. $showLink = false;
  252. if( isset($isBlogger[$this->id]) )
  253. {
  254. $showLink = $isBlogger[$this->id];
  255. }
  256. else
  257. {
  258. $showLink = EasyBlogHelper::isBlogger( $this->id );
  259. $isBlogger[$this->id] = $showLink;
  260. }
  261. if( !$showLink )
  262. {
  263. return 'javascript: void(0);';
  264. }
  265. }
  266. // phpbb case
  267. if($source == 'phpbb' && $phpbbDB === null)
  268. {
  269. $phpbbpath = $config->get( 'layout_phpbb_path' );
  270. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . $phpbbpath . DIRECTORY_SEPARATOR . 'config.php';
  271. if (JFile::exists($file))
  272. {
  273. require($file);
  274. $host = $dbhost;
  275. $user = $dbuser;
  276. $password = $dbpasswd;
  277. $database = $dbname;
  278. $prefix = $table_prefix;
  279. $driver = $dbms;
  280. $debug = 0;
  281. $options = array ( 'driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix );
  282. $phpbbDB = JDatabase::getInstance( $options );
  283. } else {
  284. $phpbbDB = false;
  285. }
  286. }
  287. if ($phpbbDB === false)
  288. {
  289. // can't get phpbb's config file, fallback to default profile link
  290. $source = 'default';
  291. }
  292. // Always use the core linking if user does not wants this.
  293. if( !$config->get( 'layout_avatar_link_name') )
  294. {
  295. $source = 'default';
  296. }
  297. // to ensure the passed in value is only a number
  298. $defaultItemId = str_replace( '&Itemid=', '', $defaultItemId);
  299. // to ensure the uniqueness of the key
  300. $key = $source . '-' . $defaultItemId;
  301. // this is where the magic starts
  302. if (!isset($instance[$this->id][$key]))
  303. {
  304. $defaultItemId = ( !empty( $defaultItemId ) ) ? '&Itemid=' . $defaultItemId : '';
  305. $defaultLink = EasyBlogRouter::_( 'index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $this->id . $defaultItemId );
  306. switch ($source)
  307. {
  308. case 'k2':
  309. $file1 = JPATH_ROOT . '/components/com_k2/helpers/route.php';
  310. $file2 = JPATH_ROOT . '/components/com_k2/helpers/utilities.php';
  311. jimport( 'joomla.filesystem.file' );
  312. if( JFile::exists( $file1 ) && JFile::exists( $file2 ) )
  313. {
  314. require_once($file1);
  315. require_once($file2);
  316. $ret = K2HelperRoute::getUserRoute( $this->id );
  317. }
  318. else
  319. {
  320. $ret = $defaultLink;
  321. }
  322. break;
  323. case 'mightyregistration':
  324. $ret = JRoute::_( 'index.php?option=com_community&view=profile&user_id=' . $this->id , false );
  325. break;
  326. case 'communitybuilder':
  327. $ret = JRoute::_('index.php?option=com_comprofiler&task=userProfile&user=' . $this->id, false);
  328. break;
  329. case 'jomsocial':
  330. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'core.php';
  331. $ret = ( JFile::exists($file) && require_once($file) )? CRoute::_( 'index.php?option=com_community&view=profile&userid=' . $this->id ) : '';
  332. break;
  333. case 'kunena':
  334. $ret = JRoute::_('index.php?option=com_kunena&func=fbprofile&userid=' . $this->id, false);
  335. break;
  336. case 'phpbb':
  337. $juser = JFactory::getUser( $this->id );
  338. $query = 'SELECT ' . $phpbbDB->nameQuote('user_id') . ' '
  339. . 'FROM ' . $phpbbDB->nameQuote('#__users') . ' WHERE LOWER('.$phpbbDB->nameQuote('username') . ') = LOWER(' . $phpbbDB->quote($juser->username) . ') ';
  340. $phpbbDB->setQuery($query, 0, 1);
  341. $phpbbuserid = $phpbbDB->loadResult();
  342. $ret = $phpbbuserid ? JURI::root() . rtrim( $phpbbpath , '/' ) . '/memberlist.php?mode=viewprofile&u=' . $phpbbuserid : '';
  343. break;
  344. case 'anahita':
  345. $person = KFactory::get( 'lib.anahita.se.person.helper' )->getPerson( $this->id );
  346. $ret = $person->getURL();
  347. break;
  348. case 'easydiscuss':
  349. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easydiscuss' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'router.php';
  350. $ret = ( JFile::exists($file) && require_once($file) ) ? DiscussRouter::_( 'index.php?option=com_easydiscuss&view=profile&id='.$this->id, false ) : '';
  351. break;
  352. case 'gravatar':
  353. case 'default':
  354. default:
  355. $ret = '';
  356. break;
  357. }
  358. $instance[$this->id][$key] = $ret ? $ret : $defaultLink;
  359. }
  360. return $instance[$this->id][$key];
  361. }
  362. public function getPermalink()
  363. {
  364. $url = EasyBlogRouter::_( 'index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $this->id );
  365. return $url;
  366. }
  367. function getParams(){
  368. return $this->params;
  369. }
  370. function getUserType(){
  371. return $this->user->usertype;
  372. }
  373. function _appendHTTP($url)
  374. {
  375. $returnStr = '';
  376. $regex = '/^(http|https|ftp):\/\/*?/i';
  377. if (preg_match($regex, trim($url), $matches)) {
  378. $returnStr = $url;
  379. } else {
  380. $returnStr = 'http://' . $url;
  381. }
  382. return $returnStr;
  383. }
  384. function getRSS()
  385. {
  386. $config = EasyBlogHelper::getConfig();
  387. if( $config->get( 'main_feedburnerblogger' ) )
  388. {
  389. $feedburner = EasyBlogHelper::getTable( 'Feedburner', 'Table' );
  390. $feedburner->load($this->id);
  391. if(! empty($feedburner->url))
  392. {
  393. $rssLink = $feedburner->url;
  394. return $rssLink;
  395. }
  396. }
  397. return EasyBlogHelper::getHelper( 'Feeds' )->getFeedURL( 'index.php?option=com_easyblog&view=blogger&id=' . $this->id );
  398. }
  399. function getAtom()
  400. {
  401. return EasyBlogHelper::getHelper( 'Feeds' )->getFeedURL( 'index.php?option=com_easyblog&view=blogger&id=' . $this->id, true );
  402. }
  403. function isOnline()
  404. {
  405. static $loaded = array();
  406. if( !isset( $loaded[ $this->id ] ) )
  407. {
  408. $db = EasyBlogHelper::db();
  409. $query = 'SELECT COUNT(1) FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__session' ) . ' '
  410. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'userid' ) . '=' . $db->Quote( $this->id ) . ' '
  411. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'client_id') . '<>' . $db->Quote( 1 );
  412. $db->setQuery( $query );
  413. $loaded[ $this->id ] = $db->loadResult() > 0 ? true : false;
  414. }
  415. return $loaded[ $this->id ];
  416. }
  417. /**
  418. * Retrieve a list of tags created by this user
  419. **/
  420. public function getTags()
  421. {
  422. $db = EasyBlogHelper::db();
  423. $query = 'SELECT * FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__easyblog_tag' ) . ' '
  424. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'created_by' ) .'=' . $db->Quote( $this->id ) . ' '
  425. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( 1 );
  426. $db->setQuery( $query );
  427. $rows = $db->loadObjectList();
  428. $tags = array();
  429. foreach( $rows as $row )
  430. {
  431. $tag = EasyBlogHelper::getTable( 'Tag' , 'Table' );
  432. $tag->bind( $row );
  433. $tags[] = $tag;
  434. }
  435. return $tags;
  436. }
  437. /**
  438. * Retrieve a list of tags created by this user
  439. **/
  440. public function getCommentsCount()
  441. {
  442. $db = EasyBlogHelper::db();
  443. $query = 'SELECT COUNT(1) FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__easyblog_comment' ) . ' '
  444. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'created_by' ) .'=' . $db->Quote( $this->id ) . ' '
  445. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( 1 );
  446. $db->setQuery( $query );
  447. return $db->loadResult();
  448. }
  449. }