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

/components/com_myblog/libraries/avatar.class.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 366 lines | 263 code | 85 blank | 18 comment | 50 complexity | 5b29deaf3cb17464e63690905009c4ff MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. (defined('_VALID_MOS') OR defined('_JEXEC')) or die('Direct Access to this location is not allowed.');
  3. class MYAvatarBase{
  4. var $_width = '';
  5. var $_height = '';
  6. var $_user = '';
  7. var $_default = '';
  8. var $_email = '';
  9. var $cms = null;
  10. function MYAvatarBase($userId){
  11. global $_MY_CONFIG;
  12. $this->cms =& cmsInstance('CMSCore');
  13. $this->_user = $userId;
  14. $this->_email = myGetAuthorEmail( $userId );
  15. $this->_width = $_MY_CONFIG->get('avatarWidth');
  16. $this->_height = $_MY_CONFIG->get('avatarHeight');
  17. $this->_default = $this->cms->get_path('live') . '/components/com_myblog/images/guest.gif';
  18. }
  19. // Return the HTML code to be inserted as avatar
  20. function display($url = false){
  21. global $_MY_CONFIG;
  22. $url = !empty($url) ? $url : $this->_default;
  23. $alt = myGetAuthorName($this->_user, $_MY_CONFIG->get('useFullName'));
  24. $content = '';
  25. $link = $this->_link();
  26. if($this->_link() && $_MY_CONFIG->get('linkAvatar')){
  27. $content = '<a href="' . $link . '">'
  28. . '<img src="' . $url . '" border="0" alt="' . $alt . '" width="' . $this->_width . '" height="' . $this->_height . '" />'
  29. . '</a>';
  30. } else{
  31. $content = '<img src="' . $url . '" border="0" alt="' . $alt . '" width="' . $this->_width . '" height="' . $this->_height . '" />';
  32. }
  33. return $content;
  34. }
  35. }
  36. class MYGravatarAvatar extends MYAvatarBase{
  37. // Returns html source
  38. function get(){
  39. global $_MY_CONFIG;
  40. $url = 'http://www.gravatar.com/avatar.php?gravatar_id=' . md5(myGetAuthorEmail($this->_user))
  41. . '&default=' . urlencode($this->_default) . '&size=' . $this->_width;
  42. return $this->display($url);
  43. }
  44. function _link(){
  45. return false;
  46. }
  47. }
  48. class MYFireboardAvatar extends MYAvatarBase{
  49. // Fireboard configuration file
  50. var $_config = '';
  51. // Fireboard configurations
  52. var $_version = '';
  53. var $_src = '';
  54. function _init(){
  55. // Test if this is prior to 1.0.5
  56. if( file_exists( $this->_config ) )
  57. {
  58. // We assume it might be version 1.0.5 and above
  59. require_once( $this->_config );
  60. global $fbConfig;
  61. $this->_config = new fb_config();
  62. $this->_config->load();
  63. }
  64. else
  65. {
  66. $this->_config = $this->cms->get_path('root') . '/administrator/components/com_fireboard/fireboard_config.php';
  67. include($this->_config);
  68. $this->_version = $fbConfig['version'];
  69. $this->_src = $fbConfig['avatar_src'];
  70. }
  71. }
  72. function _loadVars()
  73. {
  74. if( !is_object( $this->_config ) )
  75. {
  76. require( $this->_config );
  77. global $fbConfig;
  78. $obj = new stdclass();
  79. $obj->avatar_src = $fbConfig['avatar_src'];
  80. $obj->version = $fbConfig['version'];
  81. $this->_config = $obj;
  82. }
  83. }
  84. // Returns path to image
  85. function get(){
  86. $this->_config = $this->cms->get_path('root') . '/components/com_fireboard/sources/fb_config.class.php';
  87. //$this->_config = $this->cms->get_path('root') . '/administrator/components/com_fireboard/fireboard_config.php';
  88. $this->_init();
  89. $this->_loadVars();
  90. if($this->_config->avatar_src == 'fb'){
  91. // Get fireboard avatar path
  92. $strSQL = "SELECT `avatar` FROM #__fb_users WHERE `userid`='{$this->_user}'";
  93. $this->cms->db->query($strSQL);
  94. $relativePath = $this->cms->db->get_value();
  95. if($relativePath){
  96. $avatar = '';
  97. if($this->_config->_version == '1.0.2' || $this->_config->_version == '1.0.3'){
  98. // Older versions
  99. $avatar = '/components/com_fireboard/avatars/' . $relativePath;
  100. } else {
  101. // Newer versions
  102. $avatar = '/images/fbfiles/avatars/' . $relativePath;
  103. }
  104. // Check if avatar file really exists.
  105. if(file_exists($this->cms->get_path('root') . $avatar)){
  106. return $this->display($this->cms->get_path('live') . $avatar);
  107. }
  108. }
  109. } else if($this->_config->avatar_src != 'cb'){
  110. // handling cases where fireboard avatar source is from clexus PM
  111. }
  112. return $this->display();
  113. }
  114. function _link(){
  115. global $Itemid;
  116. $link = cmsSefAmpReplace("index.php?option=com_fireboard&func=fbprofile&task=showprf&userid={$this->_user}&Itemid={$Itemid}");
  117. return $link;
  118. }
  119. }
  120. class MYCbAvatar extends MYAvatarBase{
  121. function get(){
  122. $strSQL = "SELECT `avatar` FROM #__comprofiler WHERE `user_id`='{$this->_user}' AND `avatarapproved`='1'";
  123. $this->cms->db->query($strSQL);
  124. $result = $this->cms->db->get_value();
  125. if($result){
  126. if(file_exists($this->cms->get_path('root') . '/components/com_comprofiler/images/' . $result)){
  127. $url = $this->cms->get_path('live') . '/components/com_comprofiler/images/' . $result;
  128. return $this->display($url);
  129. } else if(file_exists($this->cms->get_path('root') . '/images/comprofiler/' . $result)){
  130. $url = $this->cms->get_path('live') . '/images/comprofiler/' . $result;
  131. return $this->display($url);
  132. }
  133. }
  134. return $this->display();
  135. }
  136. function _link(){
  137. $link = cmsSefAmpReplace("index.php?option=com_comprofiler&task=userProfile&user={$this->_user}");
  138. return $link;
  139. }
  140. }
  141. class MYSmfAvatar extends MYAvatarBase{
  142. var $_path = '';
  143. var $_db;
  144. function _selectDB( $server , $user , $password , $db )
  145. {
  146. static $selected;
  147. $selected = false;
  148. if( !$selected )
  149. {
  150. $resource = mysql_connect( $server , $user , $password );
  151. mysql_select_db( $db , $resource );
  152. $selected = true;
  153. }
  154. return true;
  155. }
  156. function get(){
  157. global $_MY_CONFIG, $mainframe;
  158. $this->_path = rtrim(trim($_MY_CONFIG->get('smfPath')), '/');
  159. if(!$this->_path || $this->_path == '' || !file_exists($this->_path . '/Settings.php')){
  160. $this->_path = $this->cms->get_path('root') . '/forum';
  161. }
  162. // check for SMF bridge, then use SMF bridge settings if SMF bridge installed
  163. if(!$this->_path || $this->_path == '' || !file_exists($this->_path . '/Settings.php')){
  164. $strSQL = "SELECT `id` FROM #__components WHERE `option`='com_smf'";
  165. $this->cms->db->query($strSQL);
  166. if($this->cms->db->get_value()){
  167. $strSQL = "SELECT `value1` FROM #__smf_config WHERE variable='smf_path'";
  168. $this->cms->db->query($strSQL);
  169. $this->_path = rtrim(str_replace("\\", "/", $this->cms->db->get_value()) , "/");
  170. }
  171. }
  172. // need to get the settings as SMF db / tables can be in different location
  173. if(file_exists($this->_path . '/Settings.php')){
  174. include($this->_path . '/Settings.php');
  175. mysql_select_db($mainframe->getCfg('db') , $this->cms->db->db);
  176. $this->_selectDB($db_server , $db_user , $db_passwd , $db_name );
  177. // query for user avatar, id using email address
  178. $strSQL = sprintf("SELECT avatar, ID_MEMBER FROM {$db_prefix}members WHERE emailAddress='{$this->_email}'");
  179. $result = mysql_query($strSQL);
  180. if($result){
  181. $result_row = mysql_fetch_array($result);
  182. mysql_select_db($mainframe->getCfg('db'));
  183. if($result_row){
  184. $id_member = $result_row[1];
  185. if(trim($result_row[0]) != ''){
  186. if(substr($result_row[0], 0, 7) != 'http://'){
  187. $url = $boardurl . '/avatars/' . $result_row[0];
  188. return $this->display($url);
  189. }else{
  190. $url = $result_row[0];
  191. return $this->display($url);
  192. }
  193. } else {
  194. mysql_select_db($db_name);
  195. $strSQL = sprintf("SELECT ID_ATTACH FROM {$db_prefix}attachments WHERE ID_MEMBER='{$id_member}' AND ID_MSG=0 AND attachmentType=0");
  196. $result = mysql_query($strSQL);
  197. if($result){
  198. $result_avatar = mysql_fetch_array($result);
  199. mysql_select_db($mainframe->getCfg('db'));
  200. if ($result_avatar[0]){
  201. $url = "$boardurl/index.php?action=dlattach;attach=" . $result_avatar[0] . ";type=avatar";
  202. return $this->display($url);
  203. }
  204. }
  205. }
  206. }
  207. }
  208. }
  209. return $this->display();
  210. }
  211. function _link(){
  212. global $mainframe;
  213. if(file_exists($this->_path . '/Settings.php')){
  214. include($this->_path . '/Settings.php');
  215. $this->_selectDB($db_server , $db_user , $db_passwd , $db_name );
  216. $strSQL = sprintf("SELECT ID_MEMBER FROM {$db_prefix}members WHERE emailAddress='%s'", mysql_real_escape_string($this->_email));
  217. $result = mysql_query($strSQL);
  218. $result_row = @mysql_fetch_array($result);
  219. mysql_select_db($mainframe->getCfg('db'));
  220. if($result_row)
  221. {
  222. $link = $boardurl . "/index.php?action=profile&u=" . $result_row[0];
  223. return $link;
  224. }
  225. }
  226. return false;
  227. }
  228. }
  229. class MYJuserAvar extends MYAvatarBase{
  230. // Returns html source
  231. function get(){
  232. $path = $this->cms->get_path('root') . '/administrator/components/com_juser/avatars';
  233. $path = $path . '/' . myGetAuthorName($this->_user);
  234. $source = $this->cms->get_path('live') . '/administrator/components/com_juser/avatars/' . myGetAuthorName($this->_user);
  235. if(file_exists($path . '.gif')){
  236. $source .= '.gif';
  237. } else if(file_exists($path . '.png')){
  238. $source .= '.png';
  239. } else if(file_exists($path . '.jpg')){
  240. $source .= '.jpg';
  241. } else {
  242. return false;
  243. }
  244. return $this->display($url);
  245. }
  246. function _link(){
  247. return false;
  248. }
  249. }
  250. class MYJomsocialAvatar extends MYAvatarBase
  251. {
  252. // Returns html source
  253. function get()
  254. {
  255. $core = $this->cms->get_path('root') . '/components/com_community/libraries/core.php';
  256. if( file_exists( $core ))
  257. {
  258. require_once( $core );
  259. $user =& CFactory::getUser( $this->_user );
  260. return $this->display( $user->getThumbAvatar() );
  261. }
  262. return $this->display();
  263. }
  264. function _link()
  265. {
  266. $core = $this->cms->get_path('root') . '/components/com_community/libraries/core.php';
  267. if( file_exists( $core ))
  268. {
  269. require_once( $core );
  270. $url = CRoute::_('index.php?option=com_community&view=profile&userid=' . $this->_user );
  271. return $url;
  272. }
  273. return false;
  274. }
  275. }
  276. class MYNoneAvatar extends MYAvatarBase{
  277. function get(){
  278. return "";
  279. }
  280. }
  281. ?>