PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_myblog/functions.myblog.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 1902 lines | 1296 code | 376 blank | 230 comment | 242 complexity | 9f9c2272f42b92d7d382c05b326c9cdf MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. (defined('_VALID_MOS') OR defined('_JEXEC')) or die('Direct Access to this location is not allowed.');
  3. // Add 3rd party compatibilities
  4. if(!defined('CMSLIB_DEFINED'))
  5. include_once(dirname(dirname(dirname(__FILE__))) . '/components/libraries/cmslib/spframework.php');
  6. /**
  7. * Info: To reset the ordering for older entries and set the new ordering for a content
  8. * @params: $entry (blogContent)
  9. **/
  10. function mySortOrder(&$entry){
  11. $cms =& cmsInstance('CMSCore');
  12. $strSQL = "SELECT * FROM #__content WHERE `catid`='{$entry->catid}'";
  13. $cms->db->query($strSQL);
  14. $result = $cms->db->get_object_list();
  15. // If there is already an ordering, dont perform anything since My Blog doesn't allow user to change the ordering.
  16. // User may be editing the content, we dont want to update the ordering.
  17. if(!$entry->ordering)
  18. {
  19. // We give ourself a new ordering id for this specific content it.
  20. if(count($result) == 0)
  21. {
  22. $entry->ordering = 1;
  23. }
  24. else
  25. {
  26. $entry->ordering = count($result) + 1;
  27. }
  28. //$entry->store();
  29. $strSQL = "UPDATE #__content SET `ordering`='{$entry->ordering}' WHERE `id`='{$entry->id}'";
  30. $cms->db->query($strSQL);
  31. }
  32. }
  33. /**
  34. * Retrieves pagination object
  35. **/
  36. function myPagination($total, $limitstart, $limit)
  37. {
  38. $pagination = new stdClass();
  39. if(cmsVersion() == _CMS_JOOMLA15){
  40. jimport('joomla.html.pagination');
  41. $pageNav = new JPagination($total, $limitstart, $limit);
  42. $pagination->limitstart = $limitstart;
  43. $pagination->limit = $limit;
  44. $pagination->total = $total;
  45. $pagination->footer = $pageNav->getListFooter();
  46. $pagination->links = $pageNav->getPagesLinks();
  47. }
  48. else{
  49. $cms =& cmsInstance('CMSCore');
  50. include_once($cms->get_path('root') . '/administrator/includes/pageNavigation.php');
  51. // We assume that this is a joomla 1.0 or mambo.
  52. $pageNav = new mosPageNav($total, $limitstart, $limit);
  53. $pagination->limitstart = $limitstart;
  54. $pagination->limit = $limit;
  55. $pagination->total = $total;
  56. $pagination->footer = $pageNav->getListFooter();
  57. $pagination->links = $pageNav->getPagesLinks();
  58. }
  59. return $pagination;
  60. }
  61. function mySendTrackbacks($contentId, $trackbacks){
  62. global $mainframe, $_MY_CONFIG;
  63. $cms =& cmsInstance('CMSCore');
  64. $sections = $_MY_CONFIG->get('managedSections');
  65. if(!class_exists('Trackback'))
  66. include_once ($cms->get_path('root').'/components/com_myblog/libraries/trackback/trackback_cls.php');
  67. $strSQL = "SELECT a.*, b.permalink, c.name "
  68. . "FROM #__content AS a, "
  69. . "#__myblog_permalinks AS b, "
  70. . "#__users AS c "
  71. . "WHERE a.id=b.contentid "
  72. . "AND a.id='{$contentId}' "
  73. . "AND a.created_by=c.id "
  74. . "AND a.sectionid IN ($sections)";
  75. $cms->db->query($strSQL);
  76. $row = $cms->db->first_row();
  77. $Itemid = myGetItemId();
  78. if($trackbacks && $trackbacks != '' && $row){
  79. $trackbacks = explode(',', $trackbacks);
  80. foreach($trackbacks as $url){
  81. // Check if we have already sent a trackback request.
  82. $strSQL = "SELECT COUNT(*) FROM `#__myblog_tb_sent` "
  83. . "WHERE `url`='{$url}' AND "
  84. . "`contentid`='{$row->id}'";
  85. $cms->db->query($strSQL);
  86. // Since we never send a request before, send it.
  87. if($cms->db->get_value() <= 0){
  88. $trackback = new Trackback($mainframe->getCfg('sitename'), $row->name, 'UTF-8');
  89. $url = trim(strip_tags($url));
  90. $cms->load('helper','url');
  91. $content = new stdClass();
  92. $content->id = $row->id;
  93. $content->url = myGetPermalinkUrl($row->id);
  94. $content->title = $trackback->cut_short($row->title);
  95. $content->excerpt = $trackback->cut_short($row->introtext . $row->fulltext);
  96. if($trackback->ping($url, $content->url, $content->title, $content->excerpt)){
  97. // Add into the database that we actually sent a trackback
  98. $strSQL = "INSERT INTO `#__myblog_tb_sent` SET `url`='{$url}',`contentid`='{$content->id}'";
  99. $cms->db->query($strSQL);
  100. }
  101. }
  102. }
  103. } else {
  104. return false;
  105. }
  106. }
  107. function myAllowedGuestView($context){
  108. global $_MY_CONFIG;
  109. $cms =& cmsInstance('CMSCore');
  110. $cms->load('libraries','user');
  111. $allowed = true;
  112. if($context == 'intro'){
  113. if($_MY_CONFIG->get('viewIntro') == '2' && $cms->user->id == '0')
  114. $allowed = false;
  115. } else if($context == 'entry'){
  116. if($_MY_CONFIG->get('viewEntry') == '2' && $cms->user->id == '0')
  117. $allowed = false;
  118. }
  119. return $allowed;
  120. }
  121. // Add a list of new and existing tags based on the array
  122. function myAddTags($contentId, $tagArray){
  123. global $_MY_CONFIG, $my;
  124. $cms =& cmsInstance('CMSCore');
  125. $cms->load('libraries', 'user');
  126. include_once(MY_LIBRARY_PATH.'/tags.class.php');
  127. $tagObj = new MYTags();
  128. // delete old tags used by this current content id.
  129. $strSQL = "DELETE FROM #__myblog_content_categories WHERE `contentid`='{$contentId}'";
  130. // var_dump($tagArray);
  131. // echo $strSQL;exit;
  132. $cms->db->query($strSQL);
  133. if($tagArray != ''){
  134. // Add tags
  135. foreach($tagArray as $tag){
  136. $tagObj->add(trim($tag));
  137. // Update the blog entry with this tag's id.
  138. $strSQL = "INSERT INTO #__myblog_content_categories "
  139. . "(`contentid`,`category`) VALUES ($contentId, $tagObj->insertId)";
  140. $cms->db->query($strSQL);
  141. }
  142. }
  143. }
  144. /**
  145. * Get the tag name since we have a slug now, we need to map it to the correct tag.
  146. **/
  147. function myGetTagName($tag){
  148. $cms =& cmsInstance('CMSCore');
  149. $strSQL = "SELECT name FROM #__myblog_categories WHERE `name` LIKE '{$tag}' OR `slug` LIKE '{$tag}'";
  150. $cms->db->query($strSQL);
  151. return $cms->db->get_value();
  152. }
  153. function myGetUsedTags($userId){
  154. $db =& cmsInstance('CMSDb');
  155. $strSQL = "SELECT DISTINCT c.name, c.slug FROM #__content AS a, "
  156. . "#__myblog_content_categories AS b, "
  157. . "#__myblog_categories AS c "
  158. . "WHERE a.id=b.contentid "
  159. . "AND c.id=b.category "
  160. . "AND a.created_by='{$userId}'";
  161. $db->query($strSQL);
  162. return $db->get_object_list();
  163. }
  164. /**
  165. * Get list of tags for a given content
  166. */
  167. function myGetTags($contentid) {
  168. $db = &cmsInstance('CMSDb');
  169. $query = "SELECT b.id,b.name, b.slug FROM #__myblog_content_categories as a,#__myblog_categories as b WHERE b.id=a.category AND a.contentid='$contentid' ORDER BY b.name DESC";
  170. $db->query($query);
  171. $result = $db->get_object_list();
  172. // Check for slug if it exists, use it as name
  173. for($i = 0; $i < count($result); $i++){
  174. $tag = $result[$i];
  175. if($tag->slug == '')
  176. $tag->slug = $tag->name;
  177. }
  178. return $result;
  179. }
  180. function myGetSid($length = 12){
  181. $token = md5(uniqid('a'));
  182. $sid = md5(uniqid(rand(), true));
  183. $return = '';
  184. for($i = 0; $i < $length; $i++){
  185. $return .= substr($sid, rand(1, ($length-1)), 1 );
  186. }
  187. return $return;
  188. }
  189. function myNotifyAdmin($contentId, $author = '', $title = '', $text = '', $isNew){
  190. global $_MY_CONFIG, $mainframe, $MYBLOG_LANG;
  191. $status = false;
  192. $cms =& cmsInstance('CMSCore');
  193. // Notify administrators.
  194. if($_MY_CONFIG->get('allowNotification')){
  195. $emails = $_MY_CONFIG->get('adminEmail');
  196. $recipients = split(',', $_MY_CONFIG->get('adminEmail'));
  197. if(!class_exists('MYMailer'))
  198. include_once(MY_LIBRARY_PATH . '/mail.class.php');
  199. if(!class_exists('AzrulJXTemplate'))
  200. include_once($cms->get_path('plugins') . '/system/pc_includes/template.php');
  201. $sid = myGetSid();
  202. $date = strftime("%Y-%m-%d %H:%M:%S", time() + ($mainframe->getCfg('offset') * 60 * 60));
  203. // Maintenance mode, clear existing 'sid'
  204. $strSQL = "DELETE FROM #__myblog_admin WHERE `sid`='{$sid}'";
  205. $cms->db->query($strSQL);
  206. // Re-insert new sid
  207. $strSQL = "INSERT INTO #__myblog_admin SET `sid`='{$sid}', `cid`='{$contentId}', `date`='{$date}'";
  208. $cms->db->query($strSQL);
  209. // Publish link
  210. $publish = 'index.php?option=com_myblog&task=admin&do=publish&sid=' . $sid;
  211. // Unpublish link
  212. $unpublish = 'index.php?option=com_myblog&task=admin&do=unpublish&sid=' . $sid;
  213. // Delete link
  214. $delete = 'index.php?option=com_myblog&task=admin&do=remove&sid=' . $sid;
  215. $template = new AzrulJXTemplate();
  216. $text = strip_tags($text);
  217. if($isNew){
  218. $content = $template->fetch(MY_TEMPLATE_PATH . "/_default/new.notify.tmpl.html");
  219. $content = str_replace('%PUBLISH%', cmsSefAmpReplace($publish), $content);
  220. $content = str_replace('%UNPUBLISH%', cmsSefAmpReplace($unpublish), $content);
  221. $content = str_replace('%DELETE%', cmsSefAmpReplace($delete), $content);
  222. $content = str_replace('%AUTHOR%', $author, $content);
  223. $content = str_replace('%TITLE%', $title, $content);
  224. $content = str_replace('%ENTRY%', $text, $content);
  225. $title = $MYBLOG_LANG['TPL_NOTIFY_MAILTITLE'];
  226. } else {
  227. // Entry is updated.
  228. $content = $template->fetch(MY_TEMPLATE_PATH . "/_default/update.notify.tmpl.html");
  229. $content = str_replace('%UNPUBLISH%', cmsSefAmpReplace($unpublish), $content);
  230. $content = str_replace('%DELETE%', cmsSefAmpReplace($delete), $content);
  231. $content = str_replace('%AUTHOR%', $author, $content);
  232. $content = str_replace('%TITLE%', $title, $content);
  233. $content = str_replace('%ENTRY%', $text, $content);
  234. $title = $MYBLOG_LANG['TPL_NOTIFY_UPDATEMAILTITLE'];
  235. }
  236. $mail = new MYMailer();
  237. $status = $mail->send($mainframe->getCfg('mailfrom'), $recipients, $title, $content);
  238. }
  239. return $status;
  240. }
  241. function myClearCache(){
  242. global $mainframe;
  243. $cms =& cmsInstance('CMSCore');
  244. $cms->load('helper','directory');
  245. $list = cmsGetFiles(MY_CACHE_PATH, '');
  246. foreach($list as $file){
  247. // Only remove files that contains the naming convention for cache_
  248. if(strstr($file, 'cache_')){
  249. @unlink(MY_CACHE_PATH . '/' . $file);
  250. }
  251. }
  252. // For Joomla 1.0 we would still need to clear the cached files
  253. // located in $mosConfig_cachepath
  254. if(cmsVersion() == _CMS_JOOMLA10 || cmsVersion() == _CMS_MAMBO){
  255. $list = cmsGetFiles($mainframe->getCfg('cachepath'), '');
  256. foreach($list as $file){
  257. if(strstr($file, 'cache_'))
  258. @unlink($mainframe->getCfg('cachepath') . '/' . $file);
  259. }
  260. }
  261. }
  262. function myGetUser($session)
  263. {
  264. $cms =& cmsInstance('CMSCore');
  265. $cms->load('libraries' , 'user');
  266. if($session)
  267. {
  268. // $vars[0] : userid
  269. // $vars[1] : sessionid
  270. $vars = explode(':' , $session);
  271. $strSQL = "SELECT userid, username, usertype FROM #__session WHERE `userid`='{$vars[0]}' "
  272. . "AND `session_id`='{$vars[1]}'";
  273. $cms->db->query( $strSQL );
  274. $data = $cms->db->first_row( $strSQL );
  275. if($data)
  276. {
  277. $my = new stdclass();
  278. $my->id = $data->userid;
  279. $my->username = $data->username;
  280. $my->usertype = $data->usertype;
  281. return $my;
  282. }
  283. }
  284. return false;
  285. }
  286. /**
  287. * Get the status if user is allowed to post
  288. * Return: boolean
  289. **/
  290. function myGetUserCanPost(){
  291. global $_MY_CONFIG;
  292. // Check posting permissions
  293. $posterIds = explode(',', $_MY_CONFIG->get('allowedPosters'));
  294. $postGroups = explode(',', $_MY_CONFIG->get('postGroup'));
  295. $extraPostGroups = explode(',', $_MY_CONFIG->get('extraPostGroups'));
  296. $adminPostGroups = explode(',', $_MY_CONFIG->get('adminPostGroup'));
  297. $disallowedUsers = explode(',', $_MY_CONFIG->get('disallowedPosters'));
  298. $cms =& cmsInstance('CMSCore');
  299. $cms->load('libraries', 'user');
  300. $userId = $cms->user->id;
  301. $userType = $cms->user->usertype;
  302. $userName = $cms->user->username;
  303. if(!$userId){
  304. return false;
  305. }
  306. array_walk($postGroups, 'myTrim');
  307. array_walk($extraPostGroups, 'myTrim');
  308. array_walk($adminPostGroups, 'myTrim');
  309. # If user is not allowed to post
  310. if (!in_array($userType, $adminPostGroups)) {
  311. if (!in_array($userType, $extraPostGroups) and !in_array($userType, $postGroups) AND !(in_array($userId, $posterIds) OR in_array(myUserGetName($userId),$posterIds))) {
  312. return false;
  313. }
  314. }
  315. // Check if users is specifically blocked from posting.
  316. if(in_array($userId, $disallowedUsers) || in_array($userName, $disallowedUsers))
  317. return false;
  318. return true;
  319. }
  320. /**
  321. * Get the status if user is allowed to publish or unpublish
  322. * Return: boolean
  323. **/
  324. function myGetUserCanPublish(){
  325. global $_MY_CONFIG, $my;
  326. $publishRights = false;
  327. if(cmsVersion() == _CMS_JOOMLA10 || cmsVersion() == _CMS_MAMBO){
  328. $userId = $my->id;
  329. $userType = $my->usertype;
  330. }elseif(cmsVersion() == _CMS_JOOMLA15){
  331. $user = & JFactory::getUser();
  332. $userId = $user->id;
  333. $userType = $user->usertype;
  334. }
  335. // Check publishing permissions
  336. $posterIds = explode(',', $_MY_CONFIG->get('allowedPublishers'));
  337. $publishers = explode(',', $_MY_CONFIG->get('publishControlGroup'));
  338. $extraPublishGroups = explode(',', $_MY_CONFIG->get('extraPublishGroups'));
  339. $adminPublishGroup = explode(',', $_MY_CONFIG->get('adminPublishControlGroup'));
  340. array_walk($extraPublishGroups, 'myTrim');
  341. if (in_array($userType, $extraPublishGroups) or (in_array($userId, $posterIds) or in_array(myUserGetName($userId),$posterIds)) or in_array($userType, $publishers) or in_array($userType, $adminPublishGroup))
  342. return true;
  343. return false;
  344. }
  345. /**
  346. * Get the username of the specific userid
  347. **/
  348. /**
  349. * Get the status of the azrul video mambot
  350. * Return: boolean
  351. **/
  352. function myGetAzVideoBot(){
  353. $cms =& cmsInstance('CMSCore');
  354. $db =& cmsInstance('CMSDb');
  355. $azVideoId = '';
  356. // Get the azrul video mambot's id
  357. $strSQL = "SELECT `id` FROM #__mambots WHERE `element`='azvideobot' AND `folder`='content'";
  358. $db->query($strSQL);
  359. // Check if azrulvideomambot file even exists
  360. if(file_exists($cms->get_path('plugins') . '/content/azvideobot.php') && ($azVideoId = $db->get_value())){
  361. $strSQL = "SELECT `my_published` FROM #__myblog_mambots WHERE `mambot_id`='{$azVideoId}'";
  362. $db->query($strSQL);
  363. if($db->get_value() == "1"){
  364. return true;
  365. } else{
  366. return false;
  367. }
  368. } else {
  369. return false;
  370. }
  371. }
  372. /**
  373. * Get the status of Jom Comment installation and integrated on the site.
  374. * Return: boolean
  375. **/
  376. function myGetJomComment(){
  377. global $_MY_CONFIG;
  378. $cms =& cmsInstance('CMSCore');
  379. if($_MY_CONFIG->get('useComment') && file_exists($cms->get_path('root') . '/administrator/components/com_jomcomment/config.jomcomment.php'))
  380. return true;
  381. return false;
  382. }
  383. /**
  384. * Get list of tags for a given user
  385. */
  386. function myGetUserTags($uid) {
  387. global $sections;
  388. $db = &cmsInstance('CMSDb');
  389. $db->query("SELECT distinct(b.name) from #__content as c,#__myblog_content_categories as a,#__myblog_categories as b WHERE c.id=a.contentid and b.id=a.category and c.created_by=$uid and c.state='1' and c.sectionid in ($sections) and c.publish_up < now() ORDER BY b.name DESC");
  390. return $db->get_object_list();
  391. }
  392. /**
  393. * Replace newlines with <br/> tags
  394. */
  395. function my_strict_nl2br($text, $replac = " <br />") {
  396. return preg_replace("/\r\n|\n|\r/", $replac, $text);
  397. }
  398. /**
  399. * Retrieve number of entries for a given user
  400. */
  401. function myCountUserEntry($uid, $exclude_drafts = "") {
  402. global $_MY_CONFIG;
  403. $db = &cmsInstance('CMSDb');
  404. $sections = $_MY_CONFIG->get('managedSections');
  405. $extra = "";
  406. if ($exclude_drafts == "1") {
  407. $extra = "and state='1' and publish_up < '" . date( 'Y-m-d H:i:s' ) . "'";
  408. }
  409. $db->query("SELECT COUNT(*) FROM #__content WHERE created_by='$uid' and sectionid IN ($sections) $extra");
  410. $result = $db->get_value();
  411. if ($result == "")
  412. return 0;
  413. return $result;
  414. }
  415. /**
  416. * Retrieve number of comments for a given user
  417. */
  418. function myCountUserComment($uid) {
  419. global $_MY_CONFIG;
  420. $db = &cmsInstance('CMSDb');
  421. $sections = $_MY_CONFIG->get('managedSections');
  422. $strSQL = "SELECT COUNT(*) FROM #__jomcomment AS a "
  423. . "INNER JOIN #__content AS b "
  424. . "WHERE b.id=a.contentid "
  425. . "AND a.option='com_myblog' "
  426. . "AND b.created_by='{$uid}'";
  427. $db->query($strSQL);
  428. $result = $db->get_value();
  429. if ($result == "")
  430. return 0;
  431. return $result;
  432. }
  433. /**
  434. * Retrieve number of hits for a given user
  435. */
  436. function myCountUserHits($uid) {
  437. global $_MY_CONFIG;
  438. $db = &cmsInstance('CMSDb');
  439. $sections = $_MY_CONFIG->get('managedSections');
  440. $db->query("SELECT SUM(hits) FROM #__content WHERE created_by='$uid' and sectionid in ($sections) and state='1' and publish_up < NOW()");
  441. $result = $db->get_value();
  442. if ($result == "")
  443. return 0;
  444. return $result;
  445. }
  446. /**
  447. * Retrieves a list of links to the unpublsihed entries for a user
  448. */
  449. function myGetUserDraft($uid) {
  450. global $MYBLOG_LANG, $Itemid, $sectionid, $sections;
  451. $cms =& cmsInstance('CMSCore');
  452. $cms->load('helper', 'url');
  453. $db = & cmsInstance('CMSDb');
  454. $db->query("SELECT title,created,id FROM #__content WHERE created_by='$uid' AND state=0 and sectionid in ($sections) ORDER BY created");
  455. $result = $db->get_object_list();
  456. $drafts = "<em>";
  457. if ($result) {
  458. foreach ($result as $row) {
  459. $draftlink = cmsSefAmpReplace("index2.php?option=com_myblog&no_html=1&task=edit&id=$row->id&Itemid=$Itemid&admin=1");
  460. if ($drafts != "<em>")
  461. $drafts .= ", ";
  462. $drafts .= "<a class=\"draftLink\" href=\"$draftlink\">".$row->title."</a>";
  463. }
  464. } else {
  465. $drafts = $MYBLOG_LANG['_MB_NO_DRAFTS'];
  466. }
  467. $drafts .= "</em>";
  468. return $drafts;
  469. }
  470. /**
  471. * Retrieves number of Jom comments for an article.
  472. */
  473. function myCountJomcomment($article_Id, $com = "com_myblog") {
  474. $db = &cmsInstance('CMSDb');
  475. $db->query("SELECT COUNT(*) FROM #__jomcomment WHERE contentid='$article_Id' AND (`option`='$com' OR `option`='com_content') AND published='1'");
  476. $result = $db->get_value();
  477. return $result;
  478. }
  479. /**
  480. * Retrieves number of articles in a selected category.
  481. **/
  482. function myGetCategoryCount($categoryId){
  483. $db =& cmsInstance('CMSDb');
  484. $strSQL = "SELECT COUNT(*) FROM #__content "
  485. . "WHERE `catid`='{$categoryId}' AND `state`='1' AND created <= NOW()";
  486. $db->query($strSQL);
  487. return $db->get_value();
  488. }
  489. /**
  490. * Get a list of categories for a content.
  491. */
  492. function myCategoriesURLGet($contentid, $linkCats = true, $task="") {
  493. global $Itemid, $MYBLOG_LANG;
  494. $cms =& cmsInstance('CMSCore');
  495. $cms->load('helper','url');
  496. $result = myGetTags($contentid);
  497. $catCount = count($result);
  498. $link = "";
  499. $task = empty($task) ? '&task=tag' : "&task=$task" ;
  500. if ($result) {
  501. $count = 0;
  502. foreach ($result as $row) {
  503. if ($link != "")
  504. $link .= ",&nbsp;";
  505. if ($linkCats) {
  506. $url = cmsSefAmpReplace('index.php?option=com_myblog' . $task . '&category=' . urlencode($row->slug) . '&Itemid=' . $Itemid);
  507. // if(cmsVersion() == _CMS_JOOMLA10 || cmsVersion() == _CMS_MAMBO){
  508. // $url = ampReplace(sefRelToAbs("index.php?option=com_myblog$task&category=" . urlencode($row->name) . "&Itemid=$Itemid"));
  509. // }elseif(cmsVersion() == _CMS_JOOMLA15){
  510. // $url = JFilterOutput::ampReplace(JRoute::_("index.php?option=com_myblog$task&category=" . urlencode($row->name) . "&Itemid=$Itemid"));
  511. // }
  512. $link .= "<a href=\"$url\">$row->name</a>";
  513. } else
  514. $link .= $row->name;
  515. $count++;
  516. }
  517. } else {
  518. $link .= "<i>".$MYBLOG_LANG['_MB_UNTAGGED']."</i>&nbsp;";
  519. }
  520. return $link;
  521. }
  522. /**
  523. * Retrieves the comment link for a content
  524. */
  525. function myCommentsURLGet($contentid, $addCommentCount = true, $task="") {
  526. global $Itemid, $MYBLOG_LANG;
  527. $link = "";
  528. if ($task!="")
  529. $task = "&task=$task";
  530. if ($addCommentCount) {
  531. //$commentlink = myGetPermalinkUrl($contentid, $task);
  532. $numcomment = intval(myCountJomcomment($contentid));
  533. //$link .= "<a href=\"$commentlink#comments\">".$MYBLOG_LANG['_MB_COMMENT']." ($numcomment)</a>";
  534. }
  535. return $MYBLOG_LANG['_MB_COMMENT']." ($numcomment) "; //$link;
  536. }
  537. /**
  538. * Gets the author username/fullname
  539. */
  540. function myGetAuthorName($uid, $useFullName="") {
  541. $db = &cmsInstance('CMSDb');
  542. $select = "username";
  543. if ($useFullName == "1")
  544. $select = "name";
  545. $db->query("SELECT $select FROM #__users WHERE id='$uid'");
  546. $result = $db->get_value();
  547. return $result;
  548. }
  549. function myGetAuthorEmail($uid){
  550. $db = &cmsInstance('CMSDb');
  551. $db->query("SELECT `email` FROM #__users WHERE id='$uid'");
  552. $result = $db->get_value();
  553. return $result;
  554. }
  555. /** %UserName%
  556. * Gets the author's id
  557. */
  558. function myGetAuthorId($name, $useFullName="") {
  559. $db = &cmsInstance('CMSDb');
  560. $name = urldecode($name);
  561. // If name is empty, just return 0 since some site somehow has username's ''
  562. if(!$name)
  563. return '0';
  564. // If display full name instead of username, need to check both fullname nad username,
  565. // just in case the blogger url param contains the username.
  566. if ($useFullName=="1")
  567. {
  568. $db->query("SELECT id FROM #__users WHERE name RLIKE '[[:<:]]$name"."[[:>:]]' or username RLIKE '[[:<:]]$name"."[[:>:]]' ");
  569. $result = $db->get_value();
  570. return ($result ? $result : "0");
  571. }
  572. // get exact username match
  573. $name = $db->_escape($name);
  574. $db->query("SELECT id FROM #__users WHERE username='$name'");
  575. $result = $db->get_value();
  576. // if not found, try get similar match
  577. if (!$result)
  578. {
  579. $db->query("SELECT id FROM #__users WHERE username RLIKE '[[:<:]]$name"."[[:>:]]'");
  580. $result = $db->get_value();
  581. }
  582. // if still not found, check name and see if contains username.
  583. if (!$result)
  584. {
  585. $db->query("SELECT id FROM #__users WHERE name RLIKE '[[:<:]]$name"."[[:>:]]'");
  586. $result = $db->get_value();
  587. }
  588. return ($result ? $result : "0");
  589. }
  590. /**
  591. * Gets the author username/fullname
  592. */
  593. function myUserGetName($uid, $useFullName="") {
  594. $db = &cmsInstance('CMSDb');
  595. $uid = intval($uid);
  596. $select = "username";
  597. if ($useFullName == "1")
  598. $select = "name";
  599. $db->query("SELECT $select FROM #__users WHERE id=$uid");
  600. $username = $db->get_value();
  601. return $username;
  602. }
  603. function myEncodeString($contents) {
  604. $ascii = '';
  605. $strlen_var = strlen($contents);
  606. for ($c = 0; $c < $strlen_var; ++ $c) {
  607. $ord_var_c = ord($contents {
  608. $c });
  609. switch ($ord_var_c) {
  610. case 0x08 :
  611. $ascii .= '\b';
  612. break;
  613. case 0x09 :
  614. $ascii .= '\t';
  615. break;
  616. case 0x0A :
  617. $ascii .= '\n';
  618. break;
  619. case 0x0C :
  620. $ascii .= '\f';
  621. break;
  622. case 0x0D :
  623. $ascii .= '\r';
  624. break;
  625. default :
  626. $ascii .= $contents {
  627. $c };
  628. }
  629. }
  630. return $ascii;
  631. }
  632. // Return the complete & valid permalink-URL for the given content
  633. function myGetPermalinkUrl($uid, $task="", $blogger = '') {
  634. $db = &cmsInstance('CMSDb');
  635. $cms = &cmsInstance('CMSCore');
  636. $cms->load('helper', 'url');
  637. $Itemid = myGetItemId();
  638. $db->query("SELECT permalink from #__myblog_permalinks WHERE contentid='$uid'");
  639. $link = $db->get_value();
  640. if (!$link OR empty($link)) {
  641. // The permalink might be empty. We need to delete it
  642. $db->query("DELETE FROM #__myblog_permalinks WHERE contentid='$uid'");
  643. $db->query("SELECT title from #__content WHERE id='$uid'");
  644. $title = $db->get_value();
  645. // remove unwatned chars from permalink
  646. $link = myTitleToLink(trim($title . ".html"));;
  647. $db->query("SELECT count(*) from #__myblog_permalinks WHERE permalink='$link' and contentid!='$uid'");
  648. $linkExists = $db->get_value();
  649. if ($linkExists) {
  650. $link = myTitleToLink(trim($title));
  651. $plink = "$link-$uid.html";
  652. $db->query("SELECT contentid from #__myblog_permalinks WHERE permalink='$plink' and contentid!='$uid'");
  653. $count = 0;
  654. while ($db->get_value()) {
  655. $count++;
  656. $plink = "$link-$uid-$count.html";
  657. $db->query("SELECT contentid from #__myblog_permalinks WHERE permalink='$plink' and contentid!='$uid'");
  658. }
  659. //$plink = urlencode($plink);
  660. $db->query("INSERT INTO #__myblog_permalinks SET permalink='$plink',contentid='$uid'");
  661. } else
  662. {
  663. $db->query("INSERT INTO #__myblog_permalinks SET permalink='$link',contentid='$uid' ");
  664. }
  665. }
  666. $link = urlencode($link);
  667. if ($task!=""){
  668. $task = "&task=$task";
  669. }
  670. if ($blogger!=""){
  671. $blogger = "&blogger=$blogger";
  672. }
  673. $url = "index.php?option=com_myblog&show={$link}{$task}{$blogger}&Itemid={$Itemid}";
  674. $sefUrl = cmsSefAmpReplace($url);
  675. // If $sefUrl does not start with http, we will have to make the url absolute,
  676. // this ensure that this link works with RSS Feed
  677. // if(substr($sefUrl,0, 4) != 'http'){
  678. // $sefUrl = $cms->get_path('live') .'/'. $sefUrl;
  679. // }
  680. return $sefUrl;
  681. }
  682. // Return the complete & valid permalink-URL for the given content
  683. function myGetPermalink($uid, $task="") {
  684. $db = &cmsInstance('CMSDb');
  685. $cms = &cmsInstance('CMSCore');
  686. $Itemid = myGetItemId();
  687. $db->query("SELECT permalink from #__myblog_permalinks WHERE contentid='$uid'");
  688. $link = $db->get_value();
  689. if (!$link OR empty($link)) {
  690. // The permalink might be empty. We need to delete it
  691. $db->query("DELETE FROM #__myblog_permalinks WHERE contentid='$uid'");
  692. $db->query("SELECT title from #__content WHERE id='$uid'");
  693. $title = $db->get_value();
  694. // remove unwatned chars from permalink
  695. $link = myTitleToLink(trim($title . ".html"));;
  696. $db->query("SELECT count(*) from #__myblog_permalinks WHERE permalink='$link' and contentid!='$uid'");
  697. $linkExists = $db->get_value();
  698. if ($linkExists) {
  699. $link = myTitleToLink(trim($title));
  700. $plink = "$link-$uid.html";
  701. $db->query("SELECT contentid from #__myblog_permalinks WHERE permalink='$plink' and contentid!='$uid'");
  702. $count = 0;
  703. while ($db->get_value()) {
  704. $count++;
  705. $plink = "$link-$uid-$count.html";
  706. $db->query("SELECT contentid from #__myblog_permalinks WHERE permalink='$plink' and contentid!='$uid'");
  707. }
  708. //$plink = urlencode($plink);
  709. $db->query("INSERT INTO #__myblog_permalinks SET permalink='$plink',contentid='$uid'");
  710. return $plink;
  711. } else{
  712. $db->query("INSERT INTO #__myblog_permalinks SET permalink='$link',contentid='$uid' ");
  713. return $link;
  714. }
  715. }
  716. return $link;
  717. }
  718. /**
  719. * Get bookmarking links to be displayed when viewing blogs.
  720. **/
  721. function myGetBookmarks(& $row){
  722. $link = $row->permalink;
  723. $title = $row->title;
  724. $text = '';
  725. if(cmsVersion() == _CMS_JOOMLA10 || cmsVersion() == _CMS_MAMBO){
  726. $bookmarks = array(
  727. 'digg' => ampReplace(_getBookmarkLink('digg', $link, $title)),
  728. 'delicious' => ampReplace(_getBookmarkLink('delicious', $link, $title)),
  729. 'spurl' => ampReplace(_getBookmarkLink('spurl', $link, $title)),
  730. 'reddit' => ampReplace(_getBookmarkLink('reddit', $link, $title)),
  731. 'furl' => ampReplace(_getBookmarkLink('furl', $link, $title))
  732. );
  733. }elseif(cmsVersion() == _CMS_JOOMLA15){
  734. $bookmarks = array(
  735. 'digg' => JFilterOutput::ampReplace(_getBookmarkLink('digg', $link, $title)),
  736. 'delicious' => JFilterOutput::ampReplace(_getBookmarkLink('delicious', $link, $title)),
  737. 'spurl' => JFilterOutput::ampReplace(_getBookmarkLink('spurl', $link, $title)),
  738. 'reddit' => JFilterOutput::ampReplace(_getBookmarkLink('reddit', $link, $title)),
  739. 'furl' => JFilterOutput::ampReplace(_getBookmarkLink('furl', $link, $title))
  740. );
  741. }
  742. $row->text .= "<div class=\"clear\">"
  743. . "<div>"
  744. . "<p>"
  745. . "<a href=\"" . $bookmarks['delicious'] . "\">del.icio.us</a>&#183;"
  746. . "<a href=\"" . $bookmarks['digg'] . "\">digg this</a>&#183;"
  747. . "<a href=\"" . $bookmarks['spurl'] . "\">spurl</a>&#183;"
  748. . "<a href=\"" . $bookmarks['reddit'] . "\">reddit</a>&#183;"
  749. . "<a href=\"" . $bookmarks['furl'] . "\">furl this</a>"
  750. . "</p>"
  751. . "</div>"
  752. . "</div>";
  753. return true;
  754. }
  755. function _getBookmarkLink($type, $link, $title)
  756. {
  757. switch ($type)
  758. {
  759. case 'digg':
  760. return 'http://www.digg.com/submit?phase=2&url='.$link."&title=".$title;
  761. case 'delicious':
  762. return "javascript:void(window.open('http://del.icio.us/post?url='+encodeURIComponent('".$link."')+'&title='+encodeURIComponent('".str_replace("%26amp%3B", "%26", urlencode(addslashes($title)))."')+'&noui&jump=close&v=4','_blank','width=700,height=280,status=no,resizable=yes,scrollbars=auto'))";
  763. case 'spurl':
  764. return "javascript:d=document;void(window.open('http://www.spurl.net/spurl.php?v=3
  765. &title='+encodeURIComponent('".str_replace("%26amp%3Bamp%3B", "%26amp%3B", urlencode(htmlentities(addslashes($title))))."')+
  766. '&url='+escape('".$link."')+
  767. '&blocked='+encodeURIComponent(d.selection?d.selection.createRange().text:d.getSelection()),
  768. '_blank','width=450,height=550,status=no,resizable=yes,scrollbars=auto'))";
  769. case 'reddit':
  770. return 'http://reddit.com/submit?url='.$link.'&title='.$title;
  771. case'furl':
  772. return "javascript:(function(){
  773. var%20d=document;
  774. var%20c=window.getSelection?window.getSelection():'';
  775. var%20f=window.open('http://www.furl.net/storeIt.jsp?t='
  776. +encodeURIComponent('".str_replace(array("%26amp%3Bamp%3B", "%25") , array("%26amp%3B", "%2525"), htmlentities(addslashes($title)))
  777. ."')+'&u=
  778. '+escape(escape('".$link."'))+'&c=
  779. '+encodeURIComponent(c),'myfurlwindow','width=475,height=540,left=75,top=20,resizable=yes');
  780. f.focus();return;
  781. })();";
  782. }
  783. }
  784. /**
  785. * Displays images on image browser, resized while maintaining aspect ratio
  786. */
  787. function displayAndResizeImages($img_array) {
  788. $uploadedImages = "";
  789. if ($img_array) {
  790. foreach ($img_array as $img) {
  791. if (!empty ($img)) {
  792. $img['filename'] = trim($img['filename']);
  793. $imageMaxSize = 80;
  794. $imageWidth = $img['width'];
  795. $imageHeight = $img['height'];
  796. if ($imageHeight > $imageMaxSize or $imageWidth > $imageMaxSize) {
  797. if ($imageHeight > $imageWidth) {
  798. $imageWidth = ($imageMaxSize / $imageHeight) * $imageWidth;
  799. $imageHeight = $imageMaxSize;
  800. } else {
  801. $imageHeight = ($imageMaxSize / $imageWidth) * $imageHeight;
  802. $imageWidth = $imageMaxSize;
  803. }
  804. }
  805. $basename = basename($img['filename']);
  806. $imgtag = "<img src='{$img['filename']}' hspace='4' vspace='4' align='left' alt='$basename' border='0' />";
  807. $imgtag = addslashes($imgtag);
  808. $onDblCick ="tinyMCE.execCommand('mceFocus',false, 'mce_editor_0');";
  809. $onDblCick .="tinyMCE.execCommand('mceInsertContent',false, '$imgtag');";
  810. $uploadedImages .= "<div title=\"$basename\" class=\"imgContainerOut\" ondblclick=\"$onDblCick\">
  811. <span class=\"imgContainer\" onmouseover=\"this.className='imgContainerHover';\" onmouseout=\"this.className='imgContainer';\">
  812. <center>
  813. <img src=\"" . $img['filename'] . "\" width=\"$imageWidth\" height=\"$imageHeight\" />
  814. </center>
  815. </span>
  816. </div>";
  817. }
  818. }
  819. } else {
  820. $uploadedImages = " ";
  821. }
  822. return $uploadedImages;
  823. }
  824. /**
  825. * Retrieves AJAX page navigation links
  826. */
  827. function writeAjaxPageNav($comp, $func, $limit, $limitstart, $total, $loadingDivName, $loadingImgURL = "") {
  828. $txt = '';
  829. $displayed_pages = 10;
  830. $total_pages = $limit ? ceil($total / $limit) : 0;
  831. $this_page = $limit ? ceil(($limitstart +1) / $limit) : 1;
  832. $start_loop = (floor(($this_page -1) / $displayed_pages)) * $displayed_pages +1;
  833. if ($start_loop + $displayed_pages -1 < $total_pages) {
  834. $stop_loop = $start_loop + $displayed_pages -1;
  835. } else {
  836. $stop_loop = $total_pages;
  837. }
  838. $link = "javascript:loading('$loadingDivName','$loadingImgURL');jax.icall('$comp','" . $func . "','" . $limit . "',";
  839. $pnSpace = '';
  840. if (_PN_LT || _PN_RT)
  841. $pnSpace = "&nbsp;";
  842. if ($this_page > 1) {
  843. $page = ($this_page -2) * $limit;
  844. $txt .= '<a href="' . "$link '0');" . '" class="pagenav" ><img border=0 src="components/com_myblog/images/Backward_16x16.png" alt=""/>' . $pnSpace . _PN_START . '</a> ';
  845. $txt .= '<a href="' . "$link '$page');" . '" class="pagenav" ><img border=0 src="components/com_myblog/images/Play2_16x16.png" alt=""/>' . $pnSpace . _PN_PREVIOUS . '</a> ';
  846. } else {
  847. }
  848. for ($i = $start_loop; $i <= $stop_loop; $i++) {
  849. $page = ($i -1) * $limit;
  850. if ($i == $this_page) {
  851. $txt .= '<span class="pagenav">' . $i . '</span> ';
  852. } else {
  853. $txt .= '<a href="' . "$link '$page');" . '" class="pagenav"><strong>' . $i . '</strong></a> ';
  854. }
  855. }
  856. if ($this_page < $total_pages) {
  857. $page = $this_page * $limit;
  858. $end_page = ($total_pages -1) * $limit;
  859. $txt .= '<a href="' . "$link '$page');" . '" class="pagenav">' . _PN_NEXT . $pnSpace . '<img border=0 src="components/com_myblog/images/Play_16x16.png" alt=""/></a> ';
  860. $txt .= '<a href="' . "$link '$end_page');" . '" class="pagenav">' . _PN_END . $pnSpace . '<img border=0 src="components/com_myblog/images/Forward_16x16.png" alt=""/></a>';
  861. } else {
  862. }
  863. return $txt;
  864. }
  865. /**
  866. * Gets the tag clouds given a query and number of cloud variations
  867. */
  868. function myGetTagClouds($query, $clouds = 8) {
  869. $db = &cmsInstance('CMSDb');
  870. $db->query($query);
  871. $rows = $db->get_object_list();
  872. /* Test Data
  873. $rows = array();
  874. for($i = 0; $i < 10; $i++){
  875. $a = new StdClass();
  876. $a->name = $i.'-myblog';
  877. $a->frequency = 100*$i;
  878. $rows[] = $a;
  879. }
  880. */
  881. if (!$rows)
  882. return "";
  883. $vals = array();
  884. foreach ($rows as $row) {
  885. $vals["{$row->frequency}"] = $row->frequency;
  886. }
  887. $maxFreq = max($vals);
  888. $minFreq = min($vals);
  889. $freqSize = $maxFreq - $minFreq;
  890. $freqSpacing = $freqSize / $clouds;
  891. if($freqSpacing < 1){
  892. $freqSpacing = 1;
  893. }
  894. foreach ($rows as $row) {
  895. $tagClass = round($row->frequency / $freqSpacing);
  896. $result[] = array (
  897. 'name' => $row->name,
  898. 'cloud' => $tagClass,
  899. 'slug' => $row->slug
  900. );
  901. }
  902. usort($result, 'mySortTags');
  903. return $result;
  904. }
  905. /**
  906. * sort tags alphabetically
  907. */
  908. function mySortTags($a, $b) {
  909. return (strtoupper($a['name']) < strtoupper($b['name'])) ? -1 : 1;
  910. }
  911. /**
  912. * Display page navigation, non ajaxed
  913. */
  914. function myWritePagesLinks($link, $total, $limitstart, $limit) {
  915. $total = (int) $total;
  916. $limitstart = (int) max($limitstart, 0);
  917. $limit = (int) max($limit, 0);
  918. $txt = '';
  919. $displayed_pages = 10;
  920. $total_pages = $limit ? ceil($total / $limit) : 0;
  921. $this_page = $limit ? ceil(($limitstart +1) / $limit) : 1;
  922. $start_loop = (floor(($this_page -1) / $displayed_pages)) * $displayed_pages +1;
  923. if ($start_loop + $displayed_pages -1 < $total_pages) {
  924. $stop_loop = $start_loop + $displayed_pages -1;
  925. } else {
  926. $stop_loop = $total_pages;
  927. }
  928. $link .= '&amp;limit=' . $limit;
  929. if (!defined('_PN_LT') || !defined('_PN_RT')) {
  930. DEFINE('_PN_LT', '&lt;');
  931. DEFINE('_PN_RT', '&gt;');
  932. }
  933. if (!defined('_PN_START'))
  934. define('_PN_START', 'Start');
  935. if (!defined('_PN_PREVIOUS'))
  936. define('_PN_PREVIOUS', 'Previous');
  937. if (!defined('_PN_END'))
  938. define('_PN_END', 'End');
  939. if (!defined('_PN_NEXT'))
  940. define('_PN_NEXT', 'Next');
  941. $pnSpace = '';
  942. if (_PN_LT || _PN_RT)
  943. $pnSpace = "&nbsp;";
  944. if ($this_page > 1) {
  945. $page = ($this_page -2) * $limit;
  946. $txt .= '<a href="' . sefRelToAbs("$link&amp;limitstart=0") . '" class="pagenav" title="' . _PN_START . '"><img border=0 src="components/com_myblog/images/Backward_16x16.png" alt=""/>' . $pnSpace . _PN_START . '</a> ';
  947. $txt .= '<a href="' . sefRelToAbs("$link&amp;limitstart=$page") . '" class="pagenav" title="' . _PN_PREVIOUS . '"><img border=0 src="components/com_myblog/images/Play2_16x16.png" alt=""/>' . $pnSpace . _PN_PREVIOUS . '</a> ';
  948. } else {
  949. $txt .= '';
  950. $txt .= '';
  951. }
  952. for ($i = $start_loop; $i <= $stop_loop; $i++) {
  953. $page = ($i -1) * $limit;
  954. if ($i == $this_page) {
  955. $txt .= '<span class="pagenav">' . $i . '</span> ';
  956. } else {
  957. $txt .= '<a href="' . sefRelToAbs($link . '&amp;limitstart=' . $page) . '" class="pagenav"><strong>' . $i . '</strong></a> ';
  958. }
  959. }
  960. if ($this_page < $total_pages) {
  961. $page = $this_page * $limit;
  962. $end_page = ($total_pages -1) * $limit;
  963. $txt .= '<a href="' . sefRelToAbs($link . '&amp;limitstart=' . $page) . ' " class="pagenav" title="' . _PN_NEXT . '">' . _PN_NEXT . $pnSpace . '<img border=0 src="components/com_myblog/images/Play_16x16.png" alt=""/></a> ';
  964. $txt .= '<a href="' . sefRelToAbs($link . '&amp;limitstart=' . $end_page) . ' " class="pagenav" title="' . _PN_END . '">' . _PN_END . $pnSpace . '<img border=0 src="components/com_myblog/images/Forward_16x16.png" alt=""/></a>';
  965. } else {
  966. $txt .= '';
  967. $txt .= '';
  968. }
  969. return $txt;
  970. }
  971. /**
  972. * Retrieves avatar image url for a user
  973. */
  974. function getAvatarImg($user_id) {
  975. global $_MY_CONFIG, $mainframe;
  976. $cms =& cmsInstance('CMSCore');
  977. $db = &cmsInstance('CMSDb');
  978. $db->query("SELECT email from #__users WHERE id='$user_id'");
  979. $email = $db->get_value();
  980. $grav_url = $cms->get_path('live') . "/components/com_myblog/images/guest.gif"; #get_url() doesnt work
  981. $avatarWidth = ($_MY_CONFIG->get('avatarWidth')) ? intval($_MY_CONFIG->get('avatarWidth')) : "";
  982. $avatarHeight = ($_MY_CONFIG->get('avatarHeight')) ? intval($_MY_CONFIG->get('avatarHeight')) : "";
  983. switch ($_MY_CONFIG->get('avatar')) {
  984. case "gravatar" :
  985. $avatarWidth = ($avatarWidth) ? $avatarWidth : "40";
  986. $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=" . md5($email) . "&default=" . urlencode($cms->get_path('live') . "/components/com_myblog/images/guest.gif") . "&size=$avatarWidth";
  987. break;
  988. case "fireboard":
  989. $fb_config_file = $cms->get_path('root') . "/administrator/components/com_fireboard/fireboard_config.php";
  990. if (file_exists($fb_config_file))
  991. include($fb_config_file);
  992. else
  993. break;
  994. if ($fbConfig['avatar_src']=='fb')
  995. {
  996. // get the fireboard avatar path if fireboard config has avatar source set to fireboard
  997. $db->query("SELECT avatar from #__fb_users WHERE userid='$user_id'");
  998. $avatar_relative_path = $db->get_value();
  999. if ($avatar_relative_path)
  1000. {
  1001. $fb_avatar = '';
  1002. #Check version
  1003. if($fbConfig['version'] == '1.0.2' || $fbConfig['version'] == '1.0.3'){
  1004. $fb_avatar = "/components/com_fireboard/avatars/" . $avatar_relative_path;
  1005. }
  1006. else{
  1007. // need to get the abs path since avatar path stored is relative to avatars directory for fireboard
  1008. $fb_avatar = '/images/fbfiles/avatars/' . $avatar_relative_path;
  1009. }
  1010. $avatar_abs_path = $cms->get_path('root') . $fb_avatar;
  1011. if (file_exists($avatar_abs_path))
  1012. $grav_url = $cms->get_path('live') . $fb_avatar;
  1013. }
  1014. break;
  1015. } else if ($fbConfig['avatar_src']!="cb")
  1016. {
  1017. // this is for handling case where fireboard avatar source is clexus PM
  1018. break;
  1019. }
  1020. // if is CB, go to CB avatar
  1021. case "cb" :
  1022. $db->query("SELECT avatar FROM #__comprofiler WHERE user_id=" . $user_id . " AND avatarapproved=1");
  1023. $result = $db->get_value();
  1024. if ($result) {
  1025. if (file_exists($cms->get_path('root') . "/components/com_comprofiler/images/" . $result))
  1026. $grav_url = $cms->get_path('live') . "/components/com_comprofiler/images/" . $result;
  1027. else
  1028. if (file_exists($cms->get_path('root') . "/images/comprofiler/" . $result))
  1029. $grav_url = $cms->get_path('live') . "/images/comprofiler/" . $result;
  1030. }
  1031. break;
  1032. case "smf" :
  1033. $smfPath = $_MY_CONFIG->get('smfPath');
  1034. $smfPath = trim($smfPath);
  1035. $smfPath = rtrim($smfPath, '/');
  1036. if (!$smfPath or $smfPath == "" or !file_exists("$smfPath/Settings.php"))
  1037. $smfPath = $cms->get_path() . "/forum";
  1038. // check for SMF bridge, then use SMF bridge settings if SMF bridge installed
  1039. if (!$smfPath or $smfPath == "" or !file_exists("$smfPath/Settings.php")) {
  1040. $db->query("select id from #__components WHERE `option`='com_smf'");
  1041. if ($db->get_value()) {
  1042. $db->query("select value1 from #__smf_config WHERE variable='smf_path'");
  1043. $smfPath = $db->get_value();
  1044. $smfPath = str_replace("\\", "/", $smfPath);
  1045. $smfPath = rtrim($smfPath, "/");
  1046. }
  1047. }
  1048. // need to get the settings as SMF db / tables can be in different location
  1049. if (file_exists("$smfPath/Settings.php")) {
  1050. include("$smfPath/Settings.php");
  1051. mysql_select_db($mainframe->getCfg('db'));
  1052. $useremail = $email;
  1053. mysql_select_db($db_name);
  1054. // query for user avatar, id using email address
  1055. $q = sprintf("SELECT avatar,ID_MEMBER FROM $db_prefix" . "members WHERE emailAddress='$useremail'");
  1056. $result = mysql_query($q);
  1057. if ($result)
  1058. {
  1059. $result_row = mysql_fetch_array($result);
  1060. mysql_select_db($mainframe->getCfg('db'));
  1061. if ($result_row) {
  1062. $id_member = $result_row[1];
  1063. if (trim($result_row[0]) != "") {
  1064. if (substr($result_row[0], 0, 7) != "http://")
  1065. $grav_url = $boardurl . "/avatars/$result_row[0]";
  1066. else
  1067. $grav_url = $result_row[0];
  1068. } else {
  1069. mysql_select_db($db_name);
  1070. $q = sprintf("SELECT ID_ATTACH FROM $db_prefix" . "attachments WHERE ID_MEMBER='$id_member' and ID_MSG=0 and attachmentType=0");
  1071. $result = mysql_query($q);
  1072. if ($result)
  1073. {
  1074. $result_avatar = mysql_fetch_array($result);
  1075. mysql_select_db($mainframe->getCfg('db'));
  1076. if ($result_avatar[0])
  1077. $grav_url = "$boardurl/index.php?action=dlattach;attach=" . $result_avatar[0] . ";type=avatar";
  1078. }
  1079. }
  1080. }
  1081. }
  1082. }
  1083. break;
  1084. default :
  1085. break;
  1086. }
  1087. return $grav_url;
  1088. }
  1089. /**
  1090. * Retrieves avatar link for a user
  1091. */
  1092. function getAvatarLink($user_id) {
  1093. global $_MY_CONFIG, $Itemid, $mainframe;
  1094. $cms =& cmsInstance('CMSCore');
  1095. $cms->load('helper', 'url');
  1096. $db = &cmsInstance('CMSDb');
  1097. $db->query("SELECT email from #__users WHERE id='$user_id'");
  1098. $email = $db->get_value();
  1099. $link = "";
  1100. switch ($_MY_CONFIG->get('avatar')) {
  1101. case "fireboard":
  1102. // Find the correct itemid
  1103. $link = cmsSefAmpReplace("index.php?option=com_fireboard&Itemid=$Itemid&func=fbprofile&task=showprf&userid=$user_id");
  1104. break;
  1105. case "cb" :
  1106. if ($user_id) {
  1107. $link = cmsSefAmpReplace("index.php?option=com_comprofiler&task=userProfile&user=$user_id");
  1108. }
  1109. break;
  1110. case "smf" :
  1111. $smfPath = $_MY_CONFIG->get('smfPath');
  1112. if (substr($smfPath, strlen($smfPath) - 1, 1) == "/")
  1113. $smfPath = substr($smfPath, 0, strlen($smfPath) - 1);
  1114. if (!$smfPath or $smfPath == "" or !file_exists("$smfPath/Settings.php")) {
  1115. $db->query("select id from #__components WHERE `option`='com_smf'");
  1116. if ($db->get_value()) {
  1117. $db->query("select value1 from #__smf_config WHERE variable='smf_path'");
  1118. $smfPath = $db->get_value();
  1119. $smfPath = str_replace("\\", "/", $smfPath);
  1120. $smfPath = rtrim($smfPath, "/");
  1121. }
  1122. }
  1123. if (!$smfPath or $smfPath == "" or !file_exists("$smfPath/Settings.php"))
  1124. $smfPath = $cms->get_path() . "/forum";
  1125. if (file_exists("$smfPath/Settings.php")) {
  1126. include("$smfPath/Settings.php");
  1127. mysql_select_db($db_name);
  1128. $useremail = $email;
  1129. $q = sprintf("SELECT ID_MEMBER FROM $db_prefix" . "members WHERE emailAddress='%s'", mysql_real_escape_string($useremail));
  1130. $result = mysql_query($q);
  1131. $result_row = @mysql_fetch_array($result);
  1132. mysql_select_db($mainframe->getCfg('db'));
  1133. if ($result_row) {
  1134. $db->query("select id from #__components WHERE `option`='com_smf'");
  1135. $smfWrap = "";
  1136. if ($db->get_value()) {
  1137. $db->query("SELECT value1 from #__smf_config WHERE variable='wrapped'");
  1138. $smfWrap = $db->get_value();
  1139. if ($smfWrap == "true") {
  1140. $smfWrap = "1";
  1141. } else
  1142. $smfWrap = "";
  1143. }
  1144. if ($smfWrap and $smfWrap != "") {
  1145. $link = cmsSefAmpReplace("index.php?option=com_smf&action=profile&u=" . $result_row[0] . "&Itemid=$Itemid");
  1146. } else
  1147. $link = cmsSefAmpReplace($boardurl . "/index.php?action=profile&u=" . $result_row[0]);
  1148. }
  1149. }
  1150. break;
  1151. default :
  1152. break;
  1153. }
  1154. return $link;
  1155. }
  1156. /**
  1157. * Gets the blog description for a user's blog
  1158. */
  1159. function myGetAuthorDescription($userid) {
  1160. $db = &cmsInstance('CMSDb');
  1161. $db->query("SELECT description FROM #__myblog_user WHERE user_id='$userid'");
  1162. $desc = $db->get_value();
  1163. if (!$desc) {
  1164. $desc = "<p>No desc available</p>";
  1165. }
  1166. return $desc;
  1167. }
  1168. function myGetAuthorTitle($userid) {
  1169. $db = &cmsInstance('CMSDb');
  1170. $db->query("SELECT `title` FROM #__myblog_user WHERE user_id='$userid'");
  1171. $title = $db->get_value();
  1172. return $title;
  1173. }
  1174. /**
  1175. * close all open HTML tags. works as HTML cleanup function
  1176. */
  1177. function myCloseTags($html){
  1178. #put all opened tags into an array
  1179. preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU",$html,$result);
  1180. $openedtags=$result[1];
  1181. #put all closed tags into an array
  1182. preg_match_all("#</([a-z]+)>#iU",$html,$result);
  1183. $closedtags=$result[1];
  1184. $len_opened = count($openedtags);
  1185. // all tags are closed
  1186. if(count($closedtags) == $len_opened){
  1187. return $html;
  1188. }
  1189. $openedtags = array_reverse($openedtags);
  1190. // close tags
  1191. for($i=0;$i < $len_opened;$i++) {
  1192. if (!in_array($openedtags[$i],$closedtags) && $openedtags[$i] != 'img'){
  1193. $html .= '</'.$openedtags[$i].'>';
  1194. } else {
  1195. unset($closedtags[array_search($openedtags[$i],$closedtags)]);
  1196. }
  1197. }
  1198. return $html;
  1199. }
  1200. // Create a suitable link from a given title
  1201. function myTitleToLink($link)
  1202. {
  1203. global $_MY_CONFIG;
  1204. // Replace non-ASCII characters.
  1205. $link = strtr($link,
  1206. "\xe1\xc1\xe0\xc0\xe2\xc2\xe4\xc4\xe3\xc3\xe5\xc5".
  1207. "\xaa\xe7\xc7\xe9\xc9\xe8\xc8\xea\xca\xeb\xcb\xed".
  1208. "\xcd\xec\xcc\xee\xce\xef\xcf\xf1\xd1\xf3\xd3\xf2".
  1209. "\xd2\xf4\xd4\xf6\xd6\xf5\xd5\x8\xd8\xba\xf0\xfa\xda".
  1210. "\xf9\xd9\xfb\xdb\xfc\xdc\xfd\xdd\xff\xe6\xc6\xdf\xf8",
  1211. "aAaAaAaAaAaAacCeEeEeEeEiIiIiIiInNo".
  1212. "OoOoOoOoOoOoouUuUuUuUyYyaAso");
  1213. $link = strtr($link, $_MY_CONFIG->replacements_array);
  1214. // remove quotes, spaces, and other illegal characters
  1215. $link = preg_replace(array('/\'/', '/[^a-zA-Z0-9\-.+]+/', '/(^_|_$)/'), array('', '-', ''), $link);
  1216. // Replace multiple '-' with a single '-'
  1217. $link = ereg_replace('-(-)*', '-', $link);
  1218. // Remove first occurence of '-'
  1219. $link = ereg_replace('^-','', $link);
  1220. return $link;
  1221. }
  1222. // Similar to trim, but with reference
  1223. function myTrim(&$string)
  1224. {
  1225. $string = trim($string);
  1226. }
  1227. function i8n_date($date)
  1228. {
  1229. global $MYBLOG_LANG;
  1230. if($MYBLOG_LANG){
  1231. foreach($MYBLOG_LANG as $key => $val)
  1232. {
  1233. $date = str_replace($key, $val, $date);
  1234. }
  1235. }
  1236. return $date;
  1237. }
  1238. /**
  1239. * Return the pdf link for specific content
  1240. **/
  1241. function myGetPDFLink($contentId, $ItemId){
  1242. $cms =& cmsInstance('CMSCore');
  1243. $cms->load('helper', 'url');
  1244. if(cmsVersion() == _CMS_JOOMLA10 || cmsVersion() == _CMS_MAMBO){
  1245. $link = cmsSefAmpReplace('index2.php?option=com_content&do_pdf=1&id=' . $contentId);
  1246. //$link = cmsSefAmpReplace('index2.php?option=com_content&format=pdf&id=' . $contentId . '&Itemid=' . $ItemId);
  1247. }else{
  1248. $link = cmsSefAmpReplace('index.php?view=article&id=' . $contentId . '&format=pdf');
  1249. }
  1250. $str = '<a title="PDF" onClick="window.open(\'' . $link . '\',\'win2\',\'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no\'); return false;" ';
  1251. $str .= 'target="_blank" href="' . $link . '">';
  1252. $str .= '<img border="0" name="PDF" alt="PDF" src="' . $cms->get_path('live') . '/images/M_images/pdf_button.png"></a>';
  1253. return $str;
  1254. }
  1255. /**
  1256. * Return the Print link for specific content
  1257. **/
  1258. function myGetPrintLink($contentId, $ItemId){
  1259. $cms =& cmsInstance('CMSCore');
  1260. $cms->load('helper', 'url');
  1261. if(cmsVersion() == _CMS_JOOMLA10 || cmsVersion() == _CMS_MAMBO){
  1262. $link = cmsSefAmpReplace('index2.php?option=com_content&task=view&id=' . $contentId . '&pop=1&page=0&Itemid=' . $ItemId);
  1263. } else {
  1264. $link = cmsSefAmpReplace('index.php?index.php?view=article&id=' . $contentId . '&tmpl=component&print=1&task=printblog');
  1265. }
  1266. $str = '<a title="Print" onClick="window.open(\'' . $link . '\',\'win2\',\'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no\'); return false;" ';
  1267. $str .= 'target="_blank" href="' . $link . '">';
  1268. $str .= '<img border="0" name="Print" alt="Print" src="' . $cms->get_path('live') . '/images/M_images/printButton.png"></a>';
  1269. return $str;
  1270. }
  1271. /**
  1272. * Return the Back link for specific content
  1273. **/
  1274. function myGetBackLink(){
  1275. global $MYBLOG_LANG;
  1276. if(cmsVersion() == _CMS_JOOMLA10 || cmsVersion() == _CMS_MAMBO){
  1277. $str = '<div class="back_button"><a href="javascript:void(0);" onClick="javascript:history.go(-1);">' . _BACK . '</a></div>';
  1278. }elseif(cmsVersion() == _CMS_JOOMLA15){
  1279. $str = '<div class="back_button"><a href="javascript:void(0);" onClick="javascript:history.go(-1);">' . JText::_( 'BACK' ) . '</a></div>';
  1280. }
  1281. return $str;
  1282. }
  1283. /**
  1284. * Returns the Itemid for the main menu item so that
  1285. * it doesn't conflict with the "dashboard" menu's item id
  1286. **/
  1287. function myGetBlogItemId(){
  1288. static $mbItemid = -1;
  1289. if($mbItemid == -1){
  1290. global $Itemid;
  1291. $db = &cmsInstance('CMSDb');
  1292. $mbItemid = $Itemid;
  1293. $strSQL = "SELECT `id` FROM #__menu WHERE "
  1294. . "`link` LIKE '%option=com_myblog%' "
  1295. . "AND `link` NOT LIKE '%option=com_myblog&task=adminhome%' "
  1296. . "AND `published`='1' "
  1297. . "AND `id`='{$Itemid}'";
  1298. $db->query($strSQL);
  1299. if(!$db->get_value()){
  1300. // The current itemId is not myblog related, ignore it, and find a valid one
  1301. // Menu type is 'component' for Joomla 1.0 and 'components' for Jooma 1.5
  1302. $strSQL = "SELECT `id` FROM #__menu WHERE "
  1303. . "(type='component' OR type='components') "
  1304. . "AND `link`='index.php?option=com_myblog' "
  1305. . "AND `published`='1'";
  1306. $db->query($strSQL);
  1307. $mbItemid = $db->get_value();
  1308. }
  1309. }
  1310. return $mbItemid;
  1311. }
  1312. /**
  1313. * Return valid Itemid for my blog links
  1314. * If 'option' are currently on myblog, then use current ItemId
  1315. */
  1316. function myGetItemId(){
  1317. static $mbItemid = -1;
  1318. if($mbItemid == -1){
  1319. global $Itemid;
  1320. $db = &cmsInstance('CMSDb');
  1321. $mbItemid = $Itemid;
  1322. $db->query("select id from #__menu where link LIKE '%option=com_myblog%' and published='1' AND `id`='$Itemid'");
  1323. if(!$db->get_value()){
  1324. // The current itemId is not myblog related, ignore it, and find a valid one
  1325. // Menu type is 'component' for Joomla 1.0 and 'components' for Jooma 1.5
  1326. $db->query("select id from #__menu where (type='component' or type='components') and link='index.php?option=com_myblog' and published='1'");
  1327. $mbItemid = $db->get_value();
  1328. }
  1329. }
  1330. return $mbItemid;
  1331. }
  1332. // Return the adminhome itemid
  1333. function myGetAdminItemId(){
  1334. static $mbItemid = -1;
  1335. if($mbItemid == -1){
  1336. global $Itemid;
  1337. $db = &cmsInstance('CMSDb');
  1338. $mbItemid

Large files files are truncated, but you can click here to view the full file