PageRenderTime 76ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 1ms

/inc/utils.php

https://bitbucket.org/ryanhowdy/family-connections
PHP | 5099 lines | 3552 code | 596 blank | 951 comment | 356 complexity | c32ed7a3493c61d70538d47095b28625 MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0

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

  1. <?php
  2. // Smileys
  3. $smiley_array = array(':smile:', ':none:', ':)', '=)', ':wink:', ';)', ':tongue:', ':biggrin:', ':sad:', ':(', ':sick:', ':cry:', ':shocked:', ':cool:', ':sleep:', 'zzz', ':angry:', ':mad:', ':embarrassed:', ':shy:',
  4. ':rolleyes:', ':nervous:', ':doh:', ':love:', ':please:', ':1please:', ':hrmm:', ':quiet:', ':clap:', ':twitch:', ':blah:', ':bored:', ':crazy:', ':excited:', ':noidea:', ':disappointed:', ':banghead:',
  5. ':dance:', ':laughat:', ':ninja:', ':pirate:', ':thumbup:', ':thumbdown:', ':twocents:'
  6. );
  7. $smiley_file_array = array('smile.gif', 'smile.gif', 'smile.gif', 'smile.gif', 'wink.gif', 'wink.gif', 'tongue.gif', 'biggrin.gif', 'sad.gif', 'sad.gif', 'sick.gif', 'cry.gif', 'shocked.gif', 'cool.gif',
  8. 'sleep.gif', 'sleep.gif', 'angry.gif', 'angry.gif', 'embarrassed.gif', 'embarrassed.gif', 'rolleyes.gif', 'nervous.gif', 'doh.gif', 'love.gif', 'please.gif', 'please.gif', 'hrmm.gif', 'quiet.gif',
  9. 'clap.gif', 'twitch.gif', 'blah.gif', 'bored.gif', 'crazy.gif', 'excited.gif', 'noidea.gif', 'disappointed.gif', 'banghead.gif', 'dance.gif', 'laughat.gif', 'ninja.gif', 'pirate.gif', 'thumbup.gif',
  10. 'thumbdown.gif', 'twocents.gif'
  11. );
  12. /**
  13. * getEmailHeaders
  14. *
  15. * @param string $name
  16. * @param string $email
  17. *
  18. * @return string
  19. */
  20. function getEmailHeaders ($name = '', $email = '')
  21. {
  22. if (empty($name)) {
  23. $name = getSiteName();
  24. }
  25. if (empty($email)) {
  26. $email = getContactEmail();
  27. }
  28. return "From: $name <$email>\r\n" .
  29. "Reply-To: $email\r\n" .
  30. "Content-Type: text/plain; charset=UTF-8;\r\n" .
  31. "MIME-Version: 1.0\r\n" .
  32. "X-Mailer: PHP/" . phpversion();
  33. }
  34. /**
  35. * getTheme
  36. *
  37. * @param int $userid
  38. *
  39. * @return void
  40. */
  41. function getTheme ($userid = 0)
  42. {
  43. if (empty($userid))
  44. {
  45. return UI."themes/default/";
  46. }
  47. else
  48. {
  49. $userid = (int)$userid;
  50. $sql = "SELECT `theme`
  51. FROM `fcms_user_settings`
  52. WHERE `user` = '$userid'";
  53. $result = mysql_query($sql);
  54. if (!$result)
  55. {
  56. displaySqlError($sql, mysql_error());
  57. return UI."themes/default/";
  58. }
  59. $r = mysql_fetch_array($result);
  60. // old versions of fcms may still list .css in theme name
  61. $pos = strpos($r['theme'], '.css');
  62. if ($pos === false)
  63. {
  64. return UI."themes/".basename($r['theme'])."/";
  65. }
  66. else
  67. {
  68. return UI."themes/".substr($r['theme'], 0, $pos)."/";
  69. }
  70. }
  71. }
  72. /**
  73. * getThemeList
  74. *
  75. * Returns an array of available themes.
  76. *
  77. * @return array
  78. */
  79. function getThemeList ()
  80. {
  81. $dir = THEMES;
  82. $themes = array();
  83. if (is_dir($dir))
  84. {
  85. if ($dh = opendir($dir))
  86. {
  87. while (($file = readdir($dh)) !== false)
  88. {
  89. // Skip files
  90. if (filetype($dir.$file) !== "dir")
  91. {
  92. continue;
  93. }
  94. // Skip directories that start with a period
  95. if ($file[0] === '.')
  96. {
  97. continue;
  98. }
  99. $themes[] = $file;
  100. }
  101. closedir($dh);
  102. sort($themes);
  103. }
  104. }
  105. return $themes;
  106. }
  107. /*
  108. * getUserDisplayName
  109. *
  110. * Gets the user's name, displayed how they set in there settings, unless display option is set
  111. * which will overwrite the user's settings.
  112. *
  113. * @param int $userid
  114. * @param int $display
  115. * @param boolean $isMember
  116. * @return string
  117. */
  118. function getUserDisplayName ($userid, $display = 0, $isMember = true)
  119. {
  120. $userid = (int)$userid;
  121. if ($isMember)
  122. {
  123. $sql = "SELECT u.`fname`, u.`lname`, u.`username`, s.`displayname`
  124. FROM `fcms_users` AS u, `fcms_user_settings` AS s
  125. WHERE u.`id` = '$userid'
  126. AND u.`id` = s.`user`";
  127. }
  128. else
  129. {
  130. $sql = "SELECT `fname`, `lname`, `username`
  131. FROM `fcms_users`
  132. WHERE `id` = '$userid' ";
  133. }
  134. $result = mysql_query($sql);
  135. if (!$result)
  136. {
  137. displaySqlError($sql, mysql_error());
  138. return '';
  139. }
  140. $r = mysql_fetch_assoc($result);
  141. // Do we want user's settings or overriding it?
  142. if ($display < 1)
  143. {
  144. $displayname = $r['displayname'];
  145. }
  146. else
  147. {
  148. $displayname = $display;
  149. }
  150. $ret = '';
  151. switch($displayname)
  152. {
  153. case '1':
  154. $ret = cleanOutput($r['fname']);
  155. break;
  156. case '2':
  157. $ret = cleanOutput($r['fname']).' '.cleanOutput($r['lname']);
  158. break;
  159. case '3':
  160. $ret = cleanOutput($r['username']);
  161. break;
  162. default:
  163. $ret = cleanOutput($r['username']);
  164. break;
  165. }
  166. return $ret;
  167. }
  168. /**
  169. * getPMCount
  170. *
  171. * Returns a string consisting of the user's new pm count in ()'s
  172. *
  173. * @return string
  174. */
  175. function getPMCount ()
  176. {
  177. // Count was calculated during getUserNotifications()
  178. if (isset($_SESSION['private_messages']))
  179. {
  180. $count = $_SESSION['private_messages'];
  181. }
  182. else
  183. {
  184. $sql = "SELECT * FROM `fcms_privatemsg`
  185. WHERE `read` < 1
  186. AND `to` = '".(int)$_SESSION['login_id']."'";
  187. $result = mysql_query($sql);
  188. if (!$result)
  189. {
  190. displaySqlError($sql, mysql_error());
  191. return '';
  192. }
  193. $count = mysql_num_rows($result);
  194. }
  195. if ($count > 0)
  196. {
  197. return " ($count)";
  198. }
  199. return '';
  200. }
  201. /**
  202. * getNotificationCount
  203. *
  204. * Returns a string consisting of the user's unread notification count in ()'s
  205. *
  206. * @return string
  207. */
  208. function getNotificationCount ()
  209. {
  210. // Count was calculated during getUserNotifications()
  211. if (isset($_SESSION['notifications']))
  212. {
  213. $count = $_SESSION['notifications'];
  214. }
  215. else
  216. {
  217. $sql = "SELECT `id` FROM `fcms_notification`
  218. WHERE `read` < 1
  219. AND `user` = '".(int)$_SESSION['login_id']."'
  220. AND `created_id` != '".(int)$_SESSION['login_id']."'";
  221. $result = mysql_query($sql);
  222. if (!$result)
  223. {
  224. displaySqlError($sql, mysql_error());
  225. return '';
  226. }
  227. $count = mysql_num_rows($result);
  228. }
  229. if ($count > 0)
  230. {
  231. return " ($count)";
  232. }
  233. return '';
  234. }
  235. /**
  236. * getUserEmail
  237. *
  238. * @param string $userid
  239. * @return string
  240. */
  241. function getUserEmail ($userid)
  242. {
  243. $userid = (int)$userid;
  244. $sql = "SELECT `email`
  245. FROM `fcms_users`
  246. WHERE `id` = '$userid'";
  247. $result = mysql_query($sql);
  248. if (!$result)
  249. {
  250. displaySqlError($sql, mysql_error());
  251. return 'nothing@mail.com';
  252. }
  253. $r = mysql_fetch_assoc($result);
  254. return $r['email'];
  255. }
  256. /**
  257. * getDefaultNavUrl
  258. *
  259. * Gets the url for the 'Share' default link
  260. *
  261. * @return string
  262. */
  263. function getDefaultNavUrl ()
  264. {
  265. $sql = "SELECT `link`
  266. FROM `fcms_navigation`
  267. WHERE `col` = 4
  268. AND `order` = 1";
  269. $result = mysql_query($sql);
  270. if (!$result)
  271. {
  272. displaySqlError($sql, mysql_error());
  273. return 'gallery/index.php';
  274. }
  275. $r = mysql_fetch_assoc($result);
  276. return getPluginUrl($r['link']);
  277. }
  278. /**
  279. * getNavLinks
  280. *
  281. * Gets the links and order for all the navigation.
  282. * Creates a multi-dimensional array of the nav, where
  283. * the first array is the navigation tabs and the second
  284. * is the links in those tabs.
  285. *
  286. * Home
  287. * My Stuff
  288. * - Profile
  289. * - Settings
  290. * - Private Messages
  291. * - Notifications
  292. * Communicate
  293. * - Message Board
  294. * - Family News
  295. * - Prayer Concerns
  296. * Share
  297. * - Photo Gallery
  298. * - Video Gallery
  299. * - Address Book
  300. * - Calendar
  301. * - Recipes
  302. * - Family Tree
  303. * - Documents
  304. * - Where Is Everyone
  305. * Misc.
  306. * - Members
  307. * - Contact Webmaster
  308. * - Help
  309. * Administration
  310. *
  311. * @return array
  312. */
  313. function getNavLinks ()
  314. {
  315. $ret = array();
  316. $sql = "SELECT `link`, `col`
  317. FROM `fcms_navigation`
  318. WHERE `order` != 0
  319. AND `col` != 6
  320. ORDER BY `col`, `order`";
  321. $result = mysql_query($sql);
  322. if (!$result)
  323. {
  324. displaySqlError($sql, mysql_error());
  325. return $ret;
  326. }
  327. $currentUserId = (int)$_SESSION['login_id'];
  328. // Add links
  329. while ($r = mysql_fetch_array($result))
  330. {
  331. $ret['my-stuff'] = T_('My Stuff');
  332. // Notifications
  333. $notifications = getUserNotifications($currentUserId);
  334. if ($notifications > 0)
  335. {
  336. $ret['my-stuff'] = '<b>'.$notifications.'</b>'.$ret['my-stuff'];
  337. }
  338. $ret[$r['col']][] = array(
  339. 'url' => getPluginUrl($r['link']),
  340. 'text' => getPluginName($r['link']),
  341. );
  342. }
  343. // Add admin
  344. if (checkAccess($currentUserId) <= 2)
  345. {
  346. $ret[6][] = array(
  347. 'url' => 'index.php',
  348. 'text' => T_('Administration')
  349. );
  350. }
  351. return $ret;
  352. }
  353. /**
  354. * getAdminNavLinks
  355. *
  356. * @return void
  357. */
  358. function getAdminNavLinks ()
  359. {
  360. $ret = array();
  361. $sql = "SELECT `link`, `col`
  362. FROM `fcms_navigation`
  363. WHERE `col` = 6
  364. ORDER BY `order`";
  365. $result = mysql_query($sql);
  366. if (!$result)
  367. {
  368. displaySqlError($sql, mysql_error());
  369. return $ret;
  370. }
  371. while ($r = mysql_fetch_array($result))
  372. {
  373. $ret[$r['link']] = array(
  374. 'url' => getPluginUrl($r['link']),
  375. 'text' => getPluginName($r['link']),
  376. );
  377. }
  378. return $ret;
  379. }
  380. /**
  381. * getPluginName
  382. *
  383. * Given the name of the section from the db, returns the translated text
  384. *
  385. * @param string $section
  386. * @return string
  387. */
  388. function getPluginName ($section)
  389. {
  390. switch ($section) {
  391. case 'admin_awards':
  392. return T_('Awards');
  393. break;
  394. case 'admin_configuration':
  395. return T_('Configuration');
  396. break;
  397. case 'admin_facebook':
  398. return 'Facebook';
  399. break;
  400. case 'admin_foursquare':
  401. return 'Foursquare';
  402. break;
  403. case 'admin_instagram':
  404. return 'Instagram';
  405. break;
  406. case 'admin_members':
  407. return T_('Members');
  408. break;
  409. case 'admin_photogallery':
  410. return T_('Photo Gallery');
  411. break;
  412. case 'admin_polls':
  413. return T_('Polls');
  414. break;
  415. case 'admin_scheduler':
  416. return T_('Scheduler');
  417. break;
  418. case 'admin_upgrade':
  419. return T_('Upgrade');
  420. break;
  421. case 'admin_vimeo':
  422. return 'Vimeo';
  423. break;
  424. case 'admin_whereiseveryone':
  425. return 'Foursquare';
  426. break;
  427. case 'admin_youtube':
  428. return 'YouTube';
  429. break;
  430. case 'addressbook':
  431. return T_('Address Book');
  432. break;
  433. case 'calendar':
  434. return T_('Calendar');
  435. break;
  436. case 'chat':
  437. return T_('Chat');
  438. break;
  439. case 'contact':
  440. return T_('Contact Webmaster');
  441. break;
  442. case 'documents':
  443. return T_('Documents');
  444. break;
  445. case 'familynews':
  446. return T_('Family News');
  447. break;
  448. case 'help':
  449. return T_('Help');
  450. break;
  451. case 'messageboard':
  452. return T_('Message Board');
  453. break;
  454. case 'members':
  455. return T_('Members');
  456. break;
  457. case 'notification':
  458. return T_('Notifications').getNotificationCount();
  459. break;
  460. case 'photogallery':
  461. return T_('Photo Gallery');
  462. break;
  463. case 'prayers':
  464. return T_('Prayers');
  465. break;
  466. case 'profile':
  467. return T_('Profile');
  468. break;
  469. case 'pm':
  470. return T_('Private Messages').getPMCount();
  471. break;
  472. case 'recipes':
  473. return T_('Recipes');
  474. break;
  475. case 'settings':
  476. return T_('Settings');
  477. break;
  478. case 'tree':
  479. return T_('Family Tree');
  480. break;
  481. case 'videogallery':
  482. return T_('Video Gallery');
  483. break;
  484. case 'whereiseveryone':
  485. return T_('Where Is Everyone');
  486. break;
  487. default:
  488. return 'error';
  489. break;
  490. }
  491. }
  492. /**
  493. * getPluginUrl
  494. *
  495. * Given the name of the section from the db, returns the url for that section
  496. *
  497. * @param string $section
  498. * @return string
  499. */
  500. function getPluginUrl ($section)
  501. {
  502. switch ($section) {
  503. case 'admin_awards':
  504. return 'admin/awards.php';
  505. break;
  506. case 'admin_configuration':
  507. return 'admin/config.php';
  508. break;
  509. case 'admin_facebook':
  510. return 'admin/facebook.php';
  511. break;
  512. case 'admin_foursquare':
  513. return 'admin/foursquare.php';
  514. break;
  515. case 'admin_instagram':
  516. return 'admin/instagram.php';
  517. break;
  518. case 'admin_members':
  519. return 'admin/members.php';
  520. break;
  521. case 'admin_photogallery':
  522. return 'admin/gallery.php';
  523. break;
  524. case 'admin_polls':
  525. return 'admin/polls.php';
  526. break;
  527. case 'admin_scheduler':
  528. return 'admin/scheduler.php';
  529. break;
  530. case 'admin_upgrade':
  531. return 'admin/upgrade.php';
  532. break;
  533. case 'admin_vimeo':
  534. return 'admin/vimeo.php';
  535. break;
  536. case 'admin_whereiseveryone':
  537. return 'admin/foursquare.php';
  538. break;
  539. case 'admin_youtube':
  540. return 'admin/youtube.php';
  541. break;
  542. case 'addressbook':
  543. return 'addressbook.php';
  544. break;
  545. case 'calendar':
  546. return 'calendar.php';
  547. break;
  548. case 'chat':
  549. return 'inc/chat/index.php';
  550. break;
  551. case 'contact':
  552. return 'contact.php';
  553. break;
  554. case 'documents':
  555. return 'documents.php';
  556. break;
  557. case 'familynews':
  558. return 'familynews.php';
  559. break;
  560. case 'help':
  561. return 'help.php';
  562. break;
  563. case 'messageboard':
  564. return 'messageboard.php';
  565. break;
  566. case 'members':
  567. return 'members.php';
  568. break;
  569. case 'notification':
  570. return 'notifications.php';
  571. break;
  572. case 'photogallery':
  573. return 'gallery/index.php';
  574. break;
  575. case 'prayers':
  576. return 'prayers.php';
  577. break;
  578. case 'profile':
  579. return 'profile.php';
  580. break;
  581. case 'pm':
  582. return 'privatemsg.php';
  583. break;
  584. case 'recipes':
  585. return 'recipes.php';
  586. break;
  587. case 'settings':
  588. return 'settings.php';
  589. break;
  590. case 'tree':
  591. return 'familytree.php';
  592. break;
  593. case 'videogallery':
  594. return 'video.php';
  595. break;
  596. case 'whereiseveryone':
  597. return 'whereiseveryone.php';
  598. break;
  599. default:
  600. return 'home.php';
  601. break;
  602. }
  603. }
  604. /**
  605. * getPluginDescription
  606. *
  607. * Given the name of the plugin from the db, returns the description.
  608. *
  609. * @param string$plugin
  610. *
  611. * @return string
  612. */
  613. function getPluginDescription ($plugin)
  614. {
  615. switch ($plugin) {
  616. case 'admin_awards':
  617. return T_('Awards');
  618. break;
  619. case 'admin_configuration':
  620. return T_('Configuration');
  621. break;
  622. case 'admin_facebook':
  623. return T_('Facebook');
  624. break;
  625. case 'admin_foursquare':
  626. return T_('Foursquare');
  627. break;
  628. case 'admin_members':
  629. return T_('Members');
  630. break;
  631. case 'admin_photogallery':
  632. return T_('Photo Gallery');
  633. break;
  634. case 'admin_polls':
  635. return T_('Polls');
  636. break;
  637. case 'admin_scheduler':
  638. return T_('Scheduler');
  639. break;
  640. case 'admin_upgrade':
  641. return T_('Upgrade');
  642. break;
  643. case 'admin_vimeo':
  644. return T_('Vimeo');
  645. break;
  646. case 'admin_whereiseveryone':
  647. return T_('Foursquare');
  648. break;
  649. case 'admin_youtube':
  650. return T_('YouTube');
  651. break;
  652. case 'addressbook':
  653. return T_('Allows members to share Address information.');
  654. break;
  655. case 'calendar':
  656. return T_('Allows members to share events and send invitations.');
  657. break;
  658. case 'chat':
  659. return T_('Chat');
  660. break;
  661. case 'contact':
  662. return T_('Contact Webmaster');
  663. break;
  664. case 'documents':
  665. return T_('Allows members to share files.');
  666. break;
  667. case 'familynews':
  668. return T_('Allows members to create a family blog.');
  669. break;
  670. case 'help':
  671. return T_('Help');
  672. break;
  673. case 'messageboard':
  674. return T_('Allows members to communicate with each other.');
  675. break;
  676. case 'members':
  677. return T_('Members');
  678. break;
  679. case 'photogallery':
  680. return T_('Allows members to share photos.');
  681. break;
  682. case 'prayers':
  683. return T_('Allows members to share prayer concerns.');
  684. break;
  685. case 'profile':
  686. return T_('Profile');
  687. break;
  688. case 'pm':
  689. return T_('Private Messages');
  690. break;
  691. case 'recipes':
  692. return T_('Allows members to share recipes.');
  693. break;
  694. case 'settings':
  695. return T_('Settings');
  696. break;
  697. case 'tree':
  698. return T_('Allows members to create a family tree.');
  699. break;
  700. case 'videogallery':
  701. return T_('Allows members to share videos.');
  702. break;
  703. case 'whereiseveryone':
  704. return T_('Allows members to share Foursquare checkins.');
  705. break;
  706. default:
  707. return 'error';
  708. break;
  709. }
  710. }
  711. /**
  712. * getUserNotifications
  713. *
  714. * @param int $userId
  715. *
  716. * @return mixed Returns # of notifications or false.
  717. */
  718. function getUserNotifications ($userId)
  719. {
  720. $notifications = 0;
  721. $_SESSION['private_messages'] = $notifications;
  722. // Private Messages
  723. $sql = "SELECT `id` FROM `fcms_privatemsg`
  724. WHERE `read` < 1
  725. AND `to` = '$userId'";
  726. $result = mysql_query($sql);
  727. if (!$result)
  728. {
  729. logError(__FILE__.' ['.__LINE__.'] Could not get pm notifications.');
  730. return false;
  731. }
  732. if (mysql_num_rows($result) > 0)
  733. {
  734. $notifications += mysql_num_rows($result);
  735. $_SESSION['private_messages'] = $notifications;
  736. }
  737. // Tagged notifications
  738. $sql = "SELECT `id` FROM `fcms_notification`
  739. WHERE `read` < 1
  740. AND `user` = '$userId'
  741. AND `created_id` != '$userId'";
  742. $result = mysql_query($sql);
  743. if (!$result)
  744. {
  745. logError(__FILE__.' ['.__LINE__.'] Could not get tagged notifications.');
  746. return false;
  747. }
  748. if (mysql_num_rows($result) > 0)
  749. {
  750. $tagged = mysql_num_rows($result);
  751. $notifications += $tagged;
  752. $_SESSION['notifications'] = $tagged;
  753. }
  754. return $notifications;
  755. }
  756. /**
  757. * displayNewPM
  758. *
  759. * @param int $userid
  760. *
  761. * @return void
  762. */
  763. function displayNewPM ($userid)
  764. {
  765. $userid = (int)$userid;
  766. $sql = "SELECT `id`
  767. FROM `fcms_privatemsg`
  768. WHERE `to` = '$userid' AND `read` < 1";
  769. $result = mysql_query($sql);
  770. if (!$result)
  771. {
  772. displaySqlError($sql, mysql_error());
  773. return ' ';
  774. }
  775. if (mysql_num_rows($result) > 0)
  776. {
  777. echo '<a href="'.URL_PREFIX.'privatemsg.php" class="new_pm">'.T_('New PM').'</a> ';
  778. }
  779. else
  780. {
  781. echo ' ';
  782. }
  783. }
  784. /**
  785. * checkAccess
  786. *
  787. * Returns the access level as a number for the given user.
  788. *
  789. * @param int $userid
  790. * @return int
  791. */
  792. function checkAccess ($userid)
  793. {
  794. $userid = (int)$userid;
  795. $sql = "SELECT `access`
  796. FROM `fcms_users`
  797. WHERE `id` = '$userid'";
  798. $result = mysql_query($sql);
  799. if (!$result)
  800. {
  801. displaySqlError($sql, mysql_error());
  802. return '10';
  803. }
  804. if (mysql_num_rows($result) <= 0)
  805. {
  806. return '10'; // guest
  807. }
  808. $r = mysql_fetch_array($result);
  809. return $r['access'];
  810. }
  811. /**
  812. * getAccessLevel
  813. *
  814. * Returns the access level name for the given user.
  815. *
  816. * @param int $userid
  817. * @return string
  818. */
  819. function getAccessLevel ($userid)
  820. {
  821. $access = checkAccess($userid);
  822. $accessLevel = T_('Member');
  823. switch ($access) {
  824. case 1:
  825. $accessLevel = T_('Admin');
  826. break;
  827. case 2:
  828. $accessLevel = T_('Helper');
  829. break;
  830. case 3:
  831. $accessLevel = T_('Member');
  832. break;
  833. case 4:
  834. $accessLevel = T_('Non-Photographer');
  835. break;
  836. case 5:
  837. $accessLevel = T_('Non-Poster');
  838. break;
  839. case 6:
  840. $accessLevel = T_('Commenter');
  841. break;
  842. case 7:
  843. $accessLevel = T_('Poster');
  844. break;
  845. case 8:
  846. $accessLevel = T_('Photographer');
  847. break;
  848. case 9:
  849. $accessLevel = T_('Blogger');
  850. break;
  851. case 10:
  852. $accessLevel = T_('Guest');
  853. break;
  854. case 11:
  855. $accessLevel = T_('Non-editable Member');
  856. break;
  857. }
  858. return $accessLevel;
  859. }
  860. /**
  861. * parse
  862. *
  863. * @param string $data
  864. *
  865. * @return void
  866. */
  867. function parse ($data)
  868. {
  869. $data = htmlentities($data, ENT_COMPAT, 'UTF-8');
  870. $data = parse_smilies($data);
  871. $data = parse_bbcodes($data);
  872. $data = nl2br_nospaces($data);
  873. return $data;
  874. }
  875. /**
  876. * parse_bbcodes
  877. *
  878. * @param string $data
  879. * @return void
  880. */
  881. function parse_bbcodes ($data)
  882. {
  883. $search = getBBCodeList();
  884. $replace = array(
  885. '<ins>$1</ins>',
  886. '<del>$1</del>',
  887. '<h1>$1</h1>',
  888. '<h2>$1</h2>',
  889. '<h3>$1</h3>',
  890. '<h4>$1</h4>',
  891. '<h5>$1</h5>',
  892. '<h6>$1</h6>',
  893. '<b>$1</b>',
  894. '<i>$1</i>',
  895. '<u>$1</u>',
  896. '<a href="$1">$2</a>',
  897. '<a href="$1">$1</a>',
  898. '<div style="text-align: $1;">$2</div>',
  899. '<img src="$1"/>',
  900. '<img src="$1"/>',
  901. '<a href="mailto:$1">$2</a>',
  902. '<a href="mailto:$1">$1</a>',
  903. '<span style="font-family: $1;">$2</span>',
  904. '<span style="font-size: $1;">$2</span>',
  905. '<span style="color: $1;">$2</span>',
  906. '<span>$1</span>',
  907. '<span class="$1">$2</span>',
  908. '<blockquote>$1</blockquote>',
  909. 'unhtmlentities("\\1")'
  910. );
  911. $data = preg_replace ($search, $replace, $data);
  912. return $data;
  913. }
  914. /**
  915. * removeBBCode
  916. *
  917. * @param string $str
  918. * @return string
  919. */
  920. function removeBBCode ($str)
  921. {
  922. $search = getBBCodeList();
  923. $replace = array(
  924. '$1', // ins
  925. '$1', // del
  926. '$1', // h1
  927. '$1', // h2
  928. '$1', // h3
  929. '$1', // h4
  930. '$1', // h5
  931. '$1', // h6
  932. '$1', // b
  933. '$1', // i
  934. '$1', // u
  935. '$2', // url
  936. '$1', // url
  937. '$2', // align
  938. '', // img
  939. '', // img
  940. '$2', // mail
  941. '$1', // mail
  942. '$2', // font
  943. '$2', // size
  944. '$2', // color
  945. '$1', // span
  946. '$2', // span
  947. '$1', // quote
  948. '', // video
  949. );
  950. return preg_replace($search, $replace, stripslashes($str));
  951. }
  952. /**
  953. * getBBCodeList
  954. *
  955. * Returns an array of regex for the current list of BBCodes that FCMS supports.
  956. *
  957. * @return array
  958. */
  959. function getBBCodeList ()
  960. {
  961. return array(
  962. '/\[ins\](.*?)\[\/ins\]/is',
  963. '/\[del\](.*?)\[\/del\]/is',
  964. '/\[h1\](.*?)\[\/h1\]/is',
  965. '/\[h2\](.*?)\[\/h2\]/is',
  966. '/\[h3\](.*?)\[\/h3\]/is',
  967. '/\[h4\](.*?)\[\/h4\]/is',
  968. '/\[h5\](.*?)\[\/h5\]/is',
  969. '/\[h6\](.*?)\[\/h6\]/is',
  970. '/\[b\](.*?)\[\/b\]/is',
  971. '/\[i\](.*?)\[\/i\]/is',
  972. '/\[u\](.*?)\[\/u\]/is',
  973. '/\[url\=(.*?)\](.*?)\[\/url\]/is',
  974. '/\[url\](.*?)\[\/url\]/is',
  975. '/\[align\=(left|center|right)\](.*?)\[\/align\]/is',
  976. '/\[img\=(.*?)\]/is',
  977. '/\[img\](.*?)\[\/img\]/is',
  978. '/\[mail\=(.*?)\](.*?)\[\/mail\]/is',
  979. '/\[mail\](.*?)\[\/mail\]/is',
  980. '/\[font\=(.*?)\](.*?)\[\/font\]/is',
  981. '/\[size\=(.*?)\](.*?)\[\/size\]/is',
  982. '/\[color\=(.*?)\](.*?)\[\/color\]/is',
  983. '/\[span\](.*?)\[\/span\]/is',
  984. '/\[span\=(.*?)\](.*?)\[\/span\]/is',
  985. '/\[quote\](.*?)\[\/quote\]/is',
  986. '/\[video\](.*?)\[\/video\]/ise'
  987. );
  988. }
  989. /**
  990. * parse_smilies
  991. *
  992. * @param string $data
  993. *
  994. * @return void
  995. */
  996. function parse_smilies ($data)
  997. {
  998. global $smiley_array, $smiley_file_array;
  999. $i = 0;
  1000. while($i < count($smiley_array))
  1001. {
  1002. $data = str_replace(
  1003. $smiley_array[$i],
  1004. '<img src="'.URL_PREFIX.'ui/smileys/'.$smiley_file_array[$i].'" alt="'.$smiley_array[$i].'"/>',
  1005. $data
  1006. );
  1007. $i++;
  1008. }
  1009. return $data;
  1010. }
  1011. /**
  1012. * nl2br_nospaces
  1013. *
  1014. * @param string $string
  1015. * @return void
  1016. */
  1017. function nl2br_nospaces ($string)
  1018. {
  1019. $string = str_replace(array("\r\n", "\r", "\n"), "<br/>", $string);
  1020. return $string;
  1021. }
  1022. // Used for PHP 4 and less
  1023. if (!function_exists('stripos')) {
  1024. function stripos($haystack, $needle, $offset = 0) {
  1025. return strpos(strtolower($haystack), strtolower($needle), $offset);
  1026. }
  1027. }
  1028. // If php is compiled without mbstring support
  1029. if (!function_exists('mb_detect_encoding')) {
  1030. function mb_detect_encoding($text) {
  1031. return 'UTF-8';
  1032. }
  1033. function mb_convert_encoding($text,$target_encoding,$source_encoding) {
  1034. return $text;
  1035. }
  1036. }
  1037. /**
  1038. * displaySmileys
  1039. *
  1040. * @return void
  1041. */
  1042. function displaySmileys ()
  1043. {
  1044. global $smiley_array, $smiley_file_array;
  1045. $i=0;
  1046. $previous_smiley_file = '';
  1047. foreach ($smiley_array as $smiley) {
  1048. if ($smiley_file_array[$i] != $previous_smiley_file) {
  1049. echo '<div class="smiley"><img src="../ui/smileys/' . $smiley_file_array[$i] . '" alt="' . $smiley . '" onclick="return addSmiley(\''.str_replace("'", "\'", $smiley).'\')" /></div>';
  1050. $previous_smiley_file = $smiley_file_array[$i];
  1051. }
  1052. $i++;
  1053. }
  1054. }
  1055. /**
  1056. * escape_string
  1057. *
  1058. * @param string $string
  1059. * @return string
  1060. */
  1061. function escape_string ($string)
  1062. {
  1063. if (version_compare(phpversion(), "4.3.0") == "-1") {
  1064. return mysql_escape_string($string);
  1065. } else {
  1066. return mysql_real_escape_string($string);
  1067. }
  1068. }
  1069. /**
  1070. * cleanOutput
  1071. *
  1072. * Cleans output from the db or from the user so it can be displayed.
  1073. *
  1074. * @param mixed $output
  1075. * @param string $type
  1076. * @return mixed
  1077. */
  1078. function cleanOutput ($output, $type = 'string')
  1079. {
  1080. // Strings that may contain HTML
  1081. if ($type == 'html') {
  1082. return htmlentities($output, ENT_COMPAT, 'UTF-8');
  1083. }
  1084. // Strings without HTML
  1085. $output = strip_tags($output);
  1086. return htmlentities($output, ENT_COMPAT, 'UTF-8');
  1087. }
  1088. /**
  1089. * cleanFilename
  1090. *
  1091. * Removes unwanted characters from a filename.
  1092. *
  1093. * @param string $filename
  1094. *
  1095. * @return void
  1096. */
  1097. function cleanFilename ($filename)
  1098. {
  1099. // convert spaces to underscores
  1100. $filename = str_replace(" ", "_", $filename);
  1101. // remove everything else but numbers and letters _ -
  1102. $filename = preg_replace('/[^.A-Za-z0-9_-]/', '', $filename);
  1103. return $filename;
  1104. }
  1105. /**
  1106. * unhtmlentities
  1107. *
  1108. * html_entity_decode for PHP 4.3.0 and earlier:
  1109. *
  1110. * @param string $string
  1111. * @return string
  1112. */
  1113. function unhtmlentities($string)
  1114. {
  1115. // replace numeric entities
  1116. $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
  1117. $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string);
  1118. // replace literal entities
  1119. $trans_tbl = get_html_translation_table(HTML_ENTITIES);
  1120. $trans_tbl = array_flip($trans_tbl);
  1121. return strtr($string, $trans_tbl);
  1122. }
  1123. /**
  1124. * getPostsById
  1125. *
  1126. * Gets the post count and percentage of total posts for the givin user
  1127. * @param user_id the id of the desired user
  1128. * @param option how you want the data returned
  1129. * count - returns just the count
  1130. * percent - returns just the percent
  1131. * array - returns both, but in an array
  1132. * both - returns both in "X (X%)" format
  1133. * @return a string or array of strings
  1134. */
  1135. function getPostsById ($user_id, $option = 'both')
  1136. {
  1137. $user_id = (int)$user_id;
  1138. $sql = "SELECT COUNT(`id`) AS c
  1139. FROM `fcms_board_posts`";
  1140. $result = mysql_query($sql);
  1141. if (!$result)
  1142. {
  1143. displaySqlError($sql, mysql_error());
  1144. return '0';
  1145. }
  1146. $found = mysql_fetch_array($result);
  1147. $total = $found['c'];
  1148. $sql = "SELECT COUNT(`user`) AS c
  1149. FROM `fcms_board_posts`
  1150. WHERE `user` = '$user_id'";
  1151. $result = mysql_query($sql);
  1152. if (!$result)
  1153. {
  1154. displaySqlError($sql, mysql_error());
  1155. return '0';
  1156. }
  1157. $found = mysql_fetch_array($result);
  1158. $count = $found['c'];
  1159. if ($total < 1 || $count < 1)
  1160. {
  1161. $count = '0';
  1162. $percent = '0%';
  1163. }
  1164. else
  1165. {
  1166. $percent = round((($count/$total)*100), 1) . '%';
  1167. }
  1168. switch($option)
  1169. {
  1170. case 'count':
  1171. return $count;
  1172. break;
  1173. case 'percent':
  1174. return $percent;
  1175. break;
  1176. case 'array':
  1177. return array('count' => $count, 'percent' => $percent);
  1178. break;
  1179. case 'both':
  1180. default:
  1181. return "$count ($percent)";
  1182. break;
  1183. }
  1184. }
  1185. /**
  1186. * getPhotosById
  1187. *
  1188. * Gets the photo count and percentage of total posts for the givin user
  1189. * @param user_id the id of the desired user
  1190. * @param option how you want the data returned
  1191. * count - returns just the count
  1192. * percent - returns just the percent
  1193. * array - returns both, but in an array
  1194. * both - returns both in "X (X%)" format
  1195. * @return a string or array of strings
  1196. */
  1197. function getPhotosById ($user_id, $option = 'both')
  1198. {
  1199. $user_id = (int)$user_id;
  1200. $sql = "SELECT COUNT(`id`) AS c
  1201. FROM `fcms_gallery_photos`";
  1202. $result = mysql_query($sql);
  1203. if (!$result)
  1204. {
  1205. displaySqlError($sql, mysql_error());
  1206. return '0';
  1207. }
  1208. $found = mysql_fetch_assoc($result);
  1209. $total = $found['c'];
  1210. $sql = "SELECT COUNT(`user`) AS c
  1211. FROM `fcms_gallery_photos`
  1212. WHERE `user` = '$user_id'";
  1213. $result = mysql_query($sql);
  1214. if (!$result)
  1215. {
  1216. displaySqlError($sql, mysql_error());
  1217. return '0';
  1218. }
  1219. $found = mysql_fetch_assoc($result);
  1220. $count = $found['c'];
  1221. if ($total < 1 || $count < 1)
  1222. {
  1223. $count = '0';
  1224. $percent = '0%';
  1225. }
  1226. else
  1227. {
  1228. $percent = round((($count/$total)*100), 1) . '%';
  1229. }
  1230. switch($option)
  1231. {
  1232. case 'count':
  1233. return $count;
  1234. break;
  1235. case 'percent':
  1236. return $percent;
  1237. break;
  1238. case 'array':
  1239. return array('count' => $count, 'percent' => $percent);
  1240. break;
  1241. case 'both':
  1242. default:
  1243. return "$count ($percent)";
  1244. break;
  1245. }
  1246. }
  1247. /**
  1248. * getCommentsById
  1249. *
  1250. * Gets the news/gallery comment count and percentage of total news/gallery for the givin user
  1251. * @param user_id the id of the desired user
  1252. * @param option how you want the data returned
  1253. * count - returns just the count
  1254. * percent - returns just the percent
  1255. * array - returns both, but in an array
  1256. * both - returns both in "X (X%)" format
  1257. * @return a string or array of strings
  1258. */
  1259. function getCommentsById ($user_id, $option = 'both')
  1260. {
  1261. $user_id = (int)$user_id;
  1262. $sql = "SELECT COUNT(`id`) AS c
  1263. FROM `fcms_gallery_photo_comment`";
  1264. $result = mysql_query($sql);
  1265. if (!$result)
  1266. {
  1267. displaySqlError($sql, mysql_error());
  1268. return '0';
  1269. }
  1270. $found = mysql_fetch_assoc($result);
  1271. $total = $found['c'];
  1272. $sql = "SELECT COUNT(`user`) AS c
  1273. FROM `fcms_gallery_photo_comment`
  1274. WHERE `user` = '$user_id'";
  1275. $result = mysql_query($sql);
  1276. if (!$result)
  1277. {
  1278. displaySqlError($sql, mysql_error());
  1279. return '0';
  1280. }
  1281. $found = mysql_fetch_assoc($result);
  1282. $count = $found['c'];
  1283. // Check Family News if applicable
  1284. if (usingFamilyNews())
  1285. {
  1286. $sql = "SELECT COUNT(`id`) AS c
  1287. FROM `fcms_news_comments`";
  1288. $result = mysql_query($sql);
  1289. if (!$result)
  1290. {
  1291. displaySqlError($sql, mysql_error());
  1292. return '0';
  1293. }
  1294. $found = mysql_fetch_assoc($result);
  1295. $total = $total + $found['c'];
  1296. $sql = "SELECT COUNT(`user`) AS c
  1297. FROM `fcms_news_comments`
  1298. WHERE `user` = '$user_id'";
  1299. $result = mysql_query($sql);
  1300. if (!$result)
  1301. {
  1302. displaySqlError($sql, mysql_error());
  1303. return '0';
  1304. }
  1305. $found = mysql_fetch_assoc($result);
  1306. $count = $count + $found['c'];
  1307. }
  1308. if ($total < 1 || $count < 1)
  1309. {
  1310. $count = '0';
  1311. $percent = '0%';
  1312. }
  1313. else
  1314. {
  1315. $percent = round((($count/$total)*100), 1) . '%';
  1316. }
  1317. switch($option)
  1318. {
  1319. case 'count':
  1320. return $count;
  1321. break;
  1322. case 'percent':
  1323. return $percent;
  1324. break;
  1325. case 'array':
  1326. return array('count' => $count, 'percent' => $percent);
  1327. break;
  1328. case 'both':
  1329. default:
  1330. return "$count ($percent)";
  1331. break;
  1332. }
  1333. }
  1334. /**
  1335. * getCalendarEntriesById
  1336. *
  1337. * Gets the calendar entries count and percentage of total for the givin user
  1338. * @param user_id the id of the desired user
  1339. * @param option how you want the data returned
  1340. * count - returns just the count
  1341. * percent - returns just the percent
  1342. * array - returns both, but in an array
  1343. * both - returns both in "X (X%)" format
  1344. * @return a string or array of strings
  1345. */
  1346. function getCalendarEntriesById ($user_id, $option = 'both')
  1347. {
  1348. $user_id = (int)$user_id;
  1349. $sql = "SELECT COUNT(`id`) AS c
  1350. FROM `fcms_calendar`";
  1351. $result = mysql_query($sql);
  1352. if (!$result)
  1353. {
  1354. displaySqlError($sql, mysql_error());
  1355. return '0';
  1356. }
  1357. $found = mysql_fetch_assoc($result);
  1358. $total = $found['c'];
  1359. $sql = "SELECT COUNT(`id`) AS c
  1360. FROM `fcms_calendar`
  1361. WHERE `created_by` = '$user_id'";
  1362. $result = mysql_query($sql);
  1363. if (!$result)
  1364. {
  1365. displaySqlError($sql, mysql_error());
  1366. return '0';
  1367. }
  1368. $found = mysql_fetch_assoc($result);
  1369. $count = $found['c'];
  1370. if ($total < 1 || $count < 1)
  1371. {
  1372. $count = '0';
  1373. $percent = '0%';
  1374. }
  1375. else
  1376. {
  1377. $percent = round((($count/$total)*100), 1) . '%';
  1378. }
  1379. switch ($option)
  1380. {
  1381. case 'count':
  1382. return $count;
  1383. break;
  1384. case 'percent':
  1385. return $percent;
  1386. break;
  1387. case 'array':
  1388. return array('count' => $count, 'percent' => $percent);
  1389. break;
  1390. case 'both':
  1391. default:
  1392. return "$count ($percent)";
  1393. break;
  1394. }
  1395. }
  1396. /**
  1397. * getFamilyNewsById
  1398. *
  1399. * Gets the news count and percentage of total news for the givin user
  1400. * @param user_id the id of the desired user
  1401. * @param option how you want the data returned
  1402. * count - returns just the count
  1403. * percent - returns just the percent
  1404. * array - returns both, but in an array
  1405. * both - returns both in "X (X%)" format
  1406. * @return a string or array of strings
  1407. */
  1408. function getFamilyNewsById ($user_id, $option = 'both')
  1409. {
  1410. $user_id = (int)$user_id;
  1411. $sql = "SELECT COUNT(`id`) AS c
  1412. FROM `fcms_news`";
  1413. $result = mysql_query($sql);
  1414. if (!$result)
  1415. {
  1416. displaySqlError($sql, mysql_error());
  1417. return '0';
  1418. }
  1419. $found = mysql_fetch_assoc($result);
  1420. $total = $found['c'];
  1421. $sql = "SELECT COUNT(`id`) AS c
  1422. FROM `fcms_news`
  1423. WHERE `user` = '$user_id'
  1424. GROUP BY `user`";
  1425. $result = mysql_query($sql);
  1426. if (!$result)
  1427. {
  1428. displaySqlError($sql, mysql_error());
  1429. return '0';
  1430. }
  1431. $found = mysql_fetch_array($result);
  1432. $count = $found['c'];
  1433. if ($total < 1 || $count < 1)
  1434. {
  1435. $count = '0';
  1436. $percent = '0%';
  1437. }
  1438. else
  1439. {
  1440. $percent = round((($count/$total)*100), 1) . '%';
  1441. }
  1442. switch($option)
  1443. {
  1444. case 'count':
  1445. return $count;
  1446. break;
  1447. case 'percent':
  1448. return $percent;
  1449. break;
  1450. case 'array':
  1451. return array('count' => $count, 'percent' => $percent);
  1452. break;
  1453. case 'both':
  1454. default:
  1455. return "$count ($percent)";
  1456. break;
  1457. }
  1458. }
  1459. /**
  1460. * getRecipesById
  1461. *
  1462. * Gets the recipes count and percentage of total for the givin user
  1463. * @param user_id the id of the desired user
  1464. * @param option how you want the data returned
  1465. * count - returns just the count
  1466. * percent - returns just the percent
  1467. * array - returns both, but in an array
  1468. * both - returns both in "X (X%)" format
  1469. * @return a string or array of strings
  1470. */
  1471. function getRecipesById ($user_id, $option = 'both')
  1472. {
  1473. $user_id = (int)$user_id;
  1474. $sql = "SELECT COUNT(`id`) AS c
  1475. FROM `fcms_recipes`";
  1476. $result = mysql_query($sql);
  1477. if (!$result)
  1478. {
  1479. displaySqlError($sql, mysql_error());
  1480. return '0';
  1481. }
  1482. $found = mysql_fetch_assoc($result);
  1483. $total = $found['c'];
  1484. $sql = "SELECT COUNT(`id`) AS c
  1485. FROM `fcms_recipes`
  1486. WHERE `user` = '$user_id'
  1487. GROUP BY `user`";
  1488. $result = mysql_query($sql);
  1489. if (!$result)
  1490. {
  1491. displaySqlError($sql, mysql_error());
  1492. return '0';
  1493. }
  1494. $found = mysql_fetch_assoc($result);
  1495. $count = $found['c'];
  1496. if ($total < 1 || $count < 1)
  1497. {
  1498. $count = '0';
  1499. $percent = '0%';
  1500. }
  1501. else
  1502. {
  1503. $percent = round((($count/$total)*100), 1) . '%';
  1504. }
  1505. switch($option)
  1506. {
  1507. case 'count':
  1508. return $count;
  1509. break;
  1510. case 'percent':
  1511. return $percent;
  1512. break;
  1513. case 'array':
  1514. return array('count' => $count, 'percent' => $percent);
  1515. break;
  1516. case 'both':
  1517. default:
  1518. return "$count ($percent)";
  1519. break;
  1520. }
  1521. }
  1522. /**
  1523. * getDocumentsById
  1524. *
  1525. * Gets the documents count and percentage of total for the givin user
  1526. * @param user_id the id of the desired user
  1527. * @param option how you want the data returned
  1528. * count - returns just the count
  1529. * percent - returns just the percent
  1530. * array - returns both, but in an array
  1531. * both - returns both in "X (X%)" format
  1532. * @return a string or array of strings
  1533. */
  1534. function getDocumentsById ($user_id, $option = 'both')
  1535. {
  1536. $user_id = (int)$user_id;
  1537. $sql = "SELECT COUNT(`id`) AS c
  1538. FROM `fcms_documents`";
  1539. $result = mysql_query($sql);
  1540. if (!$result)
  1541. {
  1542. displaySqlError($sql, mysql_error());
  1543. return '0';
  1544. }
  1545. $found = mysql_fetch_assoc($result);
  1546. $total = $found['c'];
  1547. $sql = "SELECT COUNT(`id`) AS c
  1548. FROM `fcms_documents`
  1549. WHERE `user` = '$user_id'
  1550. GROUP BY `user`";
  1551. $result = mysql_query($sql);
  1552. if (!$result)
  1553. {
  1554. displaySqlError($sql, mysql_error());
  1555. return '0';
  1556. }
  1557. $found = mysql_fetch_assoc($result);
  1558. $count = $found['c'];
  1559. if ($total < 1 || $count < 1)
  1560. {
  1561. $count = '0';
  1562. $percent = '0%';
  1563. }
  1564. else
  1565. {
  1566. $percent = round((($count/$total)*100), 1) . '%';
  1567. }
  1568. switch($option)
  1569. {
  1570. case 'count':
  1571. return $count;
  1572. break;
  1573. case 'percent':
  1574. return $percent;
  1575. break;
  1576. case 'array':
  1577. return array('count' => $count, 'percent' => $percent);
  1578. break;
  1579. case 'both':
  1580. default:
  1581. return "$count ($percent)";
  1582. break;
  1583. }
  1584. }
  1585. /**
  1586. * getPrayersById
  1587. *
  1588. * Gets the prayers count and percentage of total for the givin user
  1589. * @param user_id the id of the desired user
  1590. * @param option how you want the data returned
  1591. * count - returns just the count
  1592. * percent - returns just the percent
  1593. * array - returns both, but in an array
  1594. * both - returns both in "X (X%)" format
  1595. * @return a string or array of strings
  1596. */
  1597. function getPrayersById ($user_id, $option = 'both')
  1598. {
  1599. $user_id = (int)$user_id;
  1600. $sql = "SELECT COUNT(`id`) AS c
  1601. FROM `fcms_prayers`";
  1602. $result = mysql_query($sql);
  1603. if (!$result)
  1604. {
  1605. displaySqlError($sql, mysql_error());
  1606. return '0';
  1607. }
  1608. $found = mysql_fetch_array($result);
  1609. $total = $found['c'];
  1610. $sql = "SELECT COUNT(`id`) AS c
  1611. FROM `fcms_prayers`
  1612. WHERE `user` = '$user_id'
  1613. GROUP BY `user`";
  1614. $result = mysql_query($sql);
  1615. if (!$result)
  1616. {
  1617. displaySqlError($sql, mysql_error());
  1618. return '0';
  1619. }
  1620. $found = mysql_fetch_array($result);
  1621. $count = $found['c'];
  1622. if ($total < 1 || $count < 1)
  1623. {
  1624. $count = '0';
  1625. $percent = '0%';
  1626. }
  1627. else
  1628. {
  1629. $percent = round((($count/$total)*100), 1) . '%';
  1630. }
  1631. switch($option)
  1632. {
  1633. case 'count':
  1634. return $count;
  1635. break;
  1636. case 'percent':
  1637. return $percent;
  1638. break;
  1639. case 'array':
  1640. return array('count' => $count, 'percent' => $percent);
  1641. break;
  1642. case 'both':
  1643. default:
  1644. return "$count ($percent)";
  1645. break;
  1646. }
  1647. }
  1648. /**
  1649. * getNewsComments
  1650. *
  1651. * @param int $news_id
  1652. * @return void
  1653. */
  1654. function getNewsComments ($news_id)
  1655. {
  1656. $news_id = (int)$news_id;
  1657. $sql = "SELECT COUNT(`id`) AS c
  1658. FROM `fcms_news_comments`
  1659. WHERE `news` = '$news_id'";
  1660. $result = mysql_query($sql);
  1661. if (!$result)
  1662. {
  1663. displaySqlError($sql, mysql_error());
  1664. return 0;
  1665. }
  1666. $found = mysql_fetch_array($result);
  1667. return $found['c'] ? $found['c'] : 0;
  1668. }
  1669. /**
  1670. * getUserParticipationPoints
  1671. *
  1672. * Get the participation points for the given member.
  1673. *
  1674. * Action Points
  1675. * -------------------
  1676. * thread 5
  1677. * photo 3
  1678. * news 3
  1679. * recipe 2
  1680. * document 2
  1681. * prayer 2
  1682. * post 2
  1683. * comment 2
  1684. * address 1
  1685. * phone # 1
  1686. * date/event 1
  1687. * vote 1
  1688. *
  1689. * @param int $id
  1690. * @return int
  1691. */
  1692. function getUserParticipationPoints ($id)
  1693. {
  1694. $id = (int)$id;
  1695. $points = 0;
  1696. $commentTables = array('fcms_gallery_photo_comment');
  1697. // Thread (5)
  1698. $sql = "SELECT COUNT(`id`) AS thread
  1699. FROM `fcms_board_threads`
  1700. WHERE `started_by` = '$id'";
  1701. $result = mysql_query($sql);
  1702. if (!$result)
  1703. {
  1704. displaySqlError($sql, mysql_error());
  1705. return 0;
  1706. }
  1707. $r = mysql_fetch_array($result);
  1708. $points += $r['thread'] * 5;
  1709. // Photo (3)
  1710. $sql = "SELECT COUNT(`id`) AS photo
  1711. FROM `fcms_gallery_photos`
  1712. WHERE `user` = '$id'";
  1713. $result = mysql_query($sql);
  1714. if (!$result)
  1715. {
  1716. displaySqlError($sql, mysql_error());
  1717. return 0;
  1718. }
  1719. $r = mysql_fetch_array($result);
  1720. $points += $r['photo'] * 3;
  1721. // News (3)
  1722. if (usingFamilyNews())
  1723. {
  1724. array_push($commentTables, 'fcms_news_comments');
  1725. $sql = "SELECT COUNT(`id`) AS news
  1726. FROM `fcms_news`
  1727. WHERE `user` = '$id'";
  1728. $result = mysql_query($sql);
  1729. if (!$result)
  1730. {
  1731. displaySqlError($sql, mysql_error());
  1732. return 0;
  1733. }
  1734. $r = mysql_fetch_array($result);
  1735. $points += $r['news'] * 3;
  1736. }
  1737. // Recipe (2)
  1738. if (usingRecipes())
  1739. {
  1740. array_push($commentTables, 'fcms_recipe_comment');
  1741. $sql = "SELECT COUNT(`id`) AS recipe
  1742. FROM `fcms_recipes`
  1743. WHERE `user` = '$id'";
  1744. $result = mysql_query($sql);
  1745. if (!$result)
  1746. {
  1747. displaySqlError($sql, mysql_error());
  1748. return 0;
  1749. }
  1750. $r = mysql_fetch_array($result);
  1751. $points += $r['recipe'] * 2;
  1752. }
  1753. // Document (2)
  1754. if (usingDocuments())
  1755. {
  1756. $sql = "SELECT COUNT(`id`) AS doc
  1757. FROM `fcms_documents`
  1758. WHERE `user` = '$id'";
  1759. $result = mysql_query($sql);
  1760. if (!$result)
  1761. {
  1762. displaySqlError($sql, mysql_error());
  1763. return 0;
  1764. }
  1765. $r = mysql_fetch_array($result);
  1766. $points += $r['doc'] * 2;
  1767. }
  1768. // Prayer (2)
  1769. if (usingPrayers())
  1770. {
  1771. $sql = "SELECT COUNT(`id`) AS prayer
  1772. FROM `fcms_prayers`
  1773. WHERE `user` = '$id'";
  1774. $result = mysql_query($sql);
  1775. if (!$result)
  1776. {
  1777. displaySqlError($sql, mysql_error());
  1778. return 0;
  1779. }
  1780. $r = mysql_fetch_array($result);
  1781. $points += $r['prayer'] * 2;
  1782. }
  1783. // Post (2)
  1784. $sql = "SELECT COUNT(`id`) AS post
  1785. FROM `fcms_board_posts`
  1786. WHERE `user` = '$id'";
  1787. $result = mysql_query($sql);
  1788. if (!$result)
  1789. {
  1790. displaySqlError($sql, mysql_error());
  1791. return 0;
  1792. }
  1793. $r = mysql_fetch_array($result);
  1794. $points += $r['post'] * 2;
  1795. // Comment (2)
  1796. $from = implode('`, `', $commentTables);
  1797. $where = implode("`.`user` = '$id' AND `", $commentTables);
  1798. $sql = "SELECT COUNT(*) AS comment
  1799. FROM `$from`
  1800. WHERE `$where`.`user` = '$id'";
  1801. $result = mysql_query($sql);
  1802. if (!$result)
  1803. {
  1804. displaySqlError($sql, mysql_error());
  1805. return 0;
  1806. }
  1807. $r = mysql_fetch_array($result);
  1808. $points += $r['comment'] * 2;
  1809. // Address/Phone (1)
  1810. $sql = "SELECT `address`, `city`, `state`, `home`, `work`, `cell`
  1811. FROM `fcms_address`
  1812. WHERE `user` = '$id'";
  1813. $result = mysql_query($sql);
  1814. if (!$result)
  1815. {
  1816. displaySqlError($sql, mysql_error());
  1817. return 0;
  1818. }
  1819. $r = mysql_fetch_array($result);
  1820. if (!empty($r['address']) && !empty($r['city']) && !empty($r['state']))
  1821. {
  1822. $points++;
  1823. }
  1824. if (!empty($r['home']))
  1825. {
  1826. $points++;
  1827. }
  1828. if (!empty($r['work']))
  1829. {
  1830. $points++;
  1831. }
  1832. if (!empty($r['cell']))
  1833. {
  1834. $points++;
  1835. }
  1836. // Date/Event
  1837. $sql = "SELECT COUNT(`id`) AS event
  1838. FROM `fcms_calendar`
  1839. WHERE `created_by` = '$id'";
  1840. $result = mysql_query($sql);
  1841. if (!$result)
  1842. {
  1843. displaySqlError($sql, mysql_error());
  1844. return 0;
  1845. }
  1846. $r = mysql_fetch_array($result);
  1847. $points += $r['event'];
  1848. // Vote
  1849. $sql = "SELECT COUNT(`id`) AS vote
  1850. FROM `fcms_poll_votes`
  1851. WHERE `user` = '$id'";
  1852. $result = mysql_query($sql);
  1853. if (!$result)
  1854. {
  1855. displaySqlError($sql, mysql_error());
  1856. return 0;
  1857. }
  1858. $r = mysql_fetch_array($result);
  1859. $points += $r['vote'];
  1860. return $points;
  1861. }
  1862. /**
  1863. * getUserParticipationLevel
  1864. *
  1865. * Get the participation level for the given points.
  1866. *
  1867. * Level Points
  1868. * ---------------
  1869. * 1 25
  1870. * 2 50
  1871. * 3 100
  1872. * 4 200
  1873. * 5 400
  1874. * 6 800
  1875. * 7 1,600
  1876. * 8 3,200
  1877. * 9 6,400
  1878. * 10 12,800
  1879. *
  1880. *
  1881. * …

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