PageRenderTime 69ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
  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. * @param int $points
  1882. * @return string
  1883. */
  1884. function getUserParticipationLevel ($points)
  1885. {
  1886. $level = '';
  1887. if ($points > 12800) {
  1888. $level = '<div title="'.T_('Level 10').' ('.$points.')" class="level10"></div>';
  1889. } elseif ($points > 6400) {
  1890. $level = '<div title="'.T_('Level 9').' ('.$points.')" class="level9"></div>';
  1891. } elseif ($points > 3200) {
  1892. $level = '<div title="'.T_('Level 8').' ('.$points.')" class="level8"></div>';
  1893. } elseif ($points > 1600) {
  1894. $level = '<div title="'.T_('Level 7').' ('.$points.')" class="level7"></div>';
  1895. } elseif ($points > 800) {
  1896. $level = '<div title="'.T_('Level 6').' ('.$points.')" class="level6"></div>';
  1897. } elseif ($points > 400) {
  1898. $level = '<div title="'.T_('Level 5').' ('.$points.')" class="level5"></div>';
  1899. } elseif ($points > 200) {
  1900. $level = '<div title="'.T_('Level 4').' ('.$points.')" class="level4"></div>';
  1901. } elseif ($points > 100) {
  1902. $level = '<div title="'.T_('Level 3').' ('.$points.')" class="level3"></div>';
  1903. } elseif ($points > 50) {
  1904. $level = '<div title="'.T_('Level 2').' ('.$points.')" class="level2"></div>';
  1905. } elseif ($points > 25) {
  1906. $level = '<div title="'.T_('Level 1').' ('.$points.')" class="level1"></div>';
  1907. } else {
  1908. $level = '<div title="'.T_('Level 0').' ('.$points.')" class="level0"></div>';
  1909. }
  1910. return $level;
  1911. }
  1912. /**
  1913. * getContactEmail
  1914. *
  1915. * @return string
  1916. */
  1917. function getContactEmail ()
  1918. {
  1919. $sql = "SELECT `value`
  1920. FROM `fcms_config`
  1921. WHERE `name` = 'contact'";
  1922. $result = mysql_query($sql);
  1923. if (!$result)
  1924. {
  1925. return 'ERROR-contact';
  1926. }
  1927. $r = mysql_fetch_array($result);
  1928. return $r['value'];
  1929. }
  1930. /**
  1931. * getSiteName
  1932. *
  1933. * @return string
  1934. */
  1935. function getSiteName()
  1936. {
  1937. $sql = "SELECT `value`
  1938. FROM `fcms_config`
  1939. WHERE `name` = 'sitename'";
  1940. $result = mysql_query($sql);
  1941. if (!$result)
  1942. {
  1943. return 'ERROR-sitename';
  1944. }
  1945. $r = mysql_fetch_array($result);
  1946. return cleanOutput($r['value']);
  1947. }
  1948. /**
  1949. * getCurrentVersion
  1950. *
  1951. * @return void
  1952. */
  1953. function getCurrentVersion()
  1954. {
  1955. $sql = "SELECT `value`
  1956. FROM `fcms_config`
  1957. WHERE `name` = 'current_version'";
  1958. $result = mysql_query($sql);
  1959. if (!$result)
  1960. {
  1961. return 'ERROR-current_version';
  1962. }
  1963. $r = mysql_fetch_array($result);
  1964. return $r['value'];
  1965. }
  1966. /**
  1967. * displayBBCodeToolbar
  1968. *
  1969. * @return void
  1970. */
  1971. function displayBBCodeToolbar ()
  1972. {
  1973. echo '
  1974. <div id="toolbar" class="toolbar hideme">
  1975. <input type="button" class="bold button" onclick="bb.insertCode(\'B\', \'bold\');" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Bold').'" />
  1976. <input type="button" class="italic button" onclick="bb.insertCode(\'I\', \'italic\');" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Italic').'"/>
  1977. <input type="button" class="underline button" onclick="bb.insertCode(\'U\', \'underline\');" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Underline').'"/>
  1978. <input type="button" class="left_align button" onclick="bb.insertCode(\'ALIGN=LEFT\', \'left right\', \'ALIGN\');" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Left Align').'"/>
  1979. <input type="button" class="center_align button" onclick="bb.insertCode(\'ALIGN=CENTER\', \'center\', \'ALIGN\');" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Center').'"/>
  1980. <input type="button" class="right_align button" onclick="bb.insertCode(\'ALIGN=RIGHT\', \'align right\', \'ALIGN\');" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Right Align').'"/>
  1981. <input type="button" class="h1 button" onclick="bb.insertCode(\'H1\', \'heading 1\');" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Heading 1').'"/>
  1982. <input type="button" class="h2 button" onclick="bb.insertCode(\'H2\', \'heading 2\');" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Heading 2').'"/>
  1983. <input type="button" class="h3 button" onclick="bb.insertCode(\'H3\', \'heading 3\');" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Heading 3').'"/>
  1984. <input type="button" class="board_quote button" onclick="bb.insertCode(\'QUOTE\', \'quote\');" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Quote').'"/>
  1985. <input type="button" class="board_images button" onclick="window.open(\'inc/upimages.php\',\'name\',\'width=700,height=500,scrollbars=yes,resizable=no,location=no,menubar=no,status=no\'); return false;" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Insert Image').'"/>
  1986. <input type="button" class="links button" onclick="bb.insertLink();" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Insert URL').'"/>
  1987. <input type="button" class="smileys button" onclick="window.open(\'inc/smileys.php\',\'name\',\'width=500,height=200,scrollbars=no,resizable=no,location=no,menubar=no,status=no\'); return false;" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('Insert Smiley').'"/>
  1988. <input type="button" class="help button" onclick="window.open(\'inc/bbcode.php\',\'name\',\'width=400,height=300,scrollbars=yes,resizable=no,location=no,menubar=no,status=no\'); return false;" onmouseout="style.border=\'1px solid #f6f6f6\';" onmouseover="style.border=\'1px solid #c1c1c1\';" title="'.T_('BBCode Help').'"/>
  1989. </div>';
  1990. }
  1991. /**
  1992. * displayWysiwygJs
  1993. *
  1994. * @param mixed $id
  1995. *
  1996. * @return void
  1997. */
  1998. function displayWysiwygJs ($id)
  1999. {
  2000. $elements = $id;
  2001. if (is_array($id))
  2002. {
  2003. $elements = implode(",", $id);
  2004. }
  2005. echo '
  2006. <script type="text/javascript">
  2007. tinyMCE.init({
  2008. // General options
  2009. mode : "exact",
  2010. elements : "'.$elements.'",
  2011. theme : "advanced",
  2012. // Theme options
  2013. theme_advanced_buttons1 : "myimage,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,|,link,unlink,|,blockquote,|,forecolor,removeformat",
  2014. theme_advanced_buttons2 : "",
  2015. theme_advanced_buttons3 : "",
  2016. theme_advanced_buttons4 : "",
  2017. theme_advanced_toolbar_location : "top",
  2018. theme_advanced_toolbar_align : "left",
  2019. theme_advanced_statusbar_location : "bottom",
  2020. theme_advanced_resizing : true,
  2021. setup : function(ed) {
  2022. ed.addButton("myimage", {
  2023. title : "'.T_('Images').'",
  2024. image : "img/example.gif",
  2025. onclick : function() {
  2026. window.open("inc/upimages.php","name","width=700,height=500,scrollbars=yes,resizable=no,location=no,menubar=no,status=no");
  2027. return false;
  2028. }
  2029. });
  2030. }
  2031. });
  2032. </script>';
  2033. }
  2034. /**
  2035. * displayOkMessage
  2036. *
  2037. * Displays a success/ok message that closes automatically through js.
  2038. *
  2039. * @param string $msg defaults to 'Changes Updated Successfully.'
  2040. * @param int $timeout defaults to 4000 ms
  2041. *
  2042. * @return void
  2043. */
  2044. function displayOkMessage ($msg = '', $timeout = 0)
  2045. {
  2046. $id = 'msg-'.time();
  2047. if (empty($msg))
  2048. {
  2049. $msg = T_('Changes Updated Successfully.');
  2050. }
  2051. if ($timeout <= 0)
  2052. {
  2053. $timeout = '4000';
  2054. }
  2055. echo '
  2056. <script type="text/javascript" src="'.URL_PREFIX.'ui/js/scriptaculous.js"></script>
  2057. <div id="'.$id.'" class="ok-msg-container" style="display:none">
  2058. <div class="ok-msg">
  2059. <a class="close-msg" href="#" onclick="Effect.Fade(\''.$id.'\')" title="'.T_('Close Message').'">x</a>
  2060. '.$msg.'
  2061. </div>
  2062. </div>
  2063. <noscript>
  2064. <style type="text/css">
  2065. .ok-msg-container { display: block !important; margin: 0 0 30px 0 !important; position: relative; }
  2066. .ok-msg { width: auto !important; padding: 10px 45px !important; }
  2067. .close-msg { display: none; }
  2068. </style>
  2069. </noscript>
  2070. <script type="text/javascript">
  2071. Event.observe(window, \'load\', function() {
  2072. Effect.BlindDown(\''.$id.'\');
  2073. var t=setTimeout("Effect.Fade(\''.$id.'\')",'.$timeout.');
  2074. });
  2075. </script>';
  2076. }
  2077. /**
  2078. * uploadImages
  2079. *
  2080. * @param string $filetype
  2081. * @param string $filename
  2082. * @param string $filetmpname
  2083. * @param string $destination
  2084. * @param int $max_h
  2085. * @param int $max_w
  2086. * @param boolean $unique
  2087. * @param boolean $show
  2088. * @param boolean $square
  2089. *
  2090. * @return string
  2091. */
  2092. function uploadImages ($filetype, $filename, $filetmpname, $destination, $max_h, $max_w, $unique = false, $show = true, $square = false)
  2093. {
  2094. global $cfg_mysql_host, $cfg_mysql_db, $cfg_mysql_user, $cfg_mysql_pass;
  2095. include_once('gallery_class.php');
  2096. include_once('database_class.php');
  2097. $currentUserId = (int)$_SESSION['login_id'];
  2098. $database = new database('mysql', $cfg_mysql_host, $cfg_mysql_db, $cfg_mysql_user, $cfg_mysql_pass);
  2099. $gallery = new PhotoGallery($currentUserId, $database);
  2100. $known_photo_types = array(
  2101. 'image/pjpeg' => 'jpeg',
  2102. 'image/jpeg' => 'jpg',
  2103. 'image/gif' => 'gif',
  2104. 'image/bmp' => 'bmp',
  2105. 'image/x-png' => 'png',
  2106. 'image/png' => 'png'
  2107. );
  2108. $gd_function_suffix = array(
  2109. 'image/pjpeg' => 'JPEG',
  2110. 'image/jpeg' => 'JPEG',
  2111. 'image/gif' => 'GIF',
  2112. 'image/bmp' => 'WBMP',
  2113. 'image/x-png' => 'PNG',
  2114. 'image/png' => 'PNG'
  2115. );
  2116. // Get extension of photo
  2117. $ext = explode('.', $filename);
  2118. $ext = end($ext);
  2119. $ext = strtolower($ext);
  2120. // Check mime type
  2121. if (!array_key_exists($filetype, $known_photo_types)) {
  2122. echo '
  2123. <p class="error-alert">
  2124. '.sprintf(T_('Error: File %s is not a photo. Photos must be of type (.JPG, .JPEG, .GIF, .BMP or .PNG).'), $filetype).'
  2125. </p>';
  2126. // Check file extension
  2127. } elseif (!in_array($ext, $known_photo_types)) {
  2128. echo '
  2129. <p class="error-alert">
  2130. '.sprintf(T_('Error: File %s is not a photo. Photos must be of type (.JPG, .JPEG, .GIF, .BMP or .PNG).'), $filetype).'
  2131. </p>';
  2132. } else {
  2133. // Make filename unique
  2134. if ($unique) {
  2135. $new_id = uniqid("");
  2136. $extention = $known_photo_types[$filetype];
  2137. $filename = $new_id . "." . $extention;
  2138. }
  2139. copy($filetmpname, $destination . $filename);
  2140. $size = GetImageSize($destination . $filename);
  2141. if ($square) {
  2142. $thumbnail = $gallery->getResizeSizeSquare(
  2143. $size[0],
  2144. $size[1],
  2145. $max_w
  2146. );
  2147. $temp_width = $thumbnail[0];
  2148. $temp_height = $thumbnail[1];
  2149. $width = $thumbnail[2];
  2150. $height = $thumbnail[3];
  2151. } else {
  2152. $thumbnail = $gallery->getResizeSize(
  2153. $size[0],
  2154. $size[1],
  2155. $max_w,
  2156. $max_h
  2157. );
  2158. $temp_width = $thumbnail[0];
  2159. $temp_height = $thumbnail[1];
  2160. $width = $thumbnail[0];
  2161. $height = $thumbnail[1];
  2162. }
  2163. if ($size[0] > $max_w && $size[1] > $max_h) {
  2164. $function_suffix = $gd_function_suffix[$filetype];
  2165. $function_to_read = "ImageCreateFrom".$function_suffix;
  2166. $function_to_write = "Image".$function_suffix;
  2167. $source_handle = $function_to_read($destination . $filename);
  2168. if ($source_handle) {
  2169. $destination_handle = ImageCreateTrueColor($width, $height);
  2170. ImageCopyResampled($destination_handle, $source_handle, 0, 0, 0, 0, $temp_width, $temp_height, $size[0], $size[1]);
  2171. }
  2172. $function_to_write($destination_handle, $destination . $filename);
  2173. ImageDestroy($destination_handle );
  2174. }
  2175. }
  2176. // Show thumbnail?
  2177. if ($show) {
  2178. echo "<img src=\"" . $destination . $filename . "\" alt=\"\"/>";
  2179. }
  2180. return $filename;
  2181. }
  2182. /**
  2183. * displayPages
  2184. *
  2185. * Function renamed in 2.0, needs to stay until old calls are updated.
  2186. *
  2187. * @deprecated deprecated since version 2.0
  2188. */
  2189. function displayPages ($url, $cur_page, $total_pages)
  2190. {
  2191. displayPagination($url, $cur_page, $total_pages);
  2192. }
  2193. /**
  2194. * displayPagination
  2195. *
  2196. * Displays the pagination links.
  2197. *
  2198. * @param url the url of the page (index.php?uid=0)
  2199. * @param cur_page the current page #
  2200. * @param total_pages The total # of pages needed
  2201. * @return nothing
  2202. */
  2203. function displayPagination ($url, $cur_page, $total_pages)
  2204. {
  2205. // Check if we have a index.php url or a index.php?uid=0 url
  2206. $end = substr($url, strlen($url) - 4);
  2207. if ($end == '.php') {
  2208. $divider = '?';
  2209. } else {
  2210. $divider = '&amp;';
  2211. }
  2212. if ($total_pages > 1)
  2213. {
  2214. echo '
  2215. <div class="pagination pages">
  2216. <ul>';
  2217. // First / Previous
  2218. if ($cur_page > 1)
  2219. {
  2220. $prev = ($cur_page - 1);
  2221. echo '
  2222. <li><a title="'.T_('First Page').'" class="first" href="'.$url.$divider.'page=1">'.T_('First').'</a></li>
  2223. <li><a title="'.T_('Previous Page').'" class="previous" href="'.$url.$divider.'page='.$prev.'">'.T_('Previous').'</a></li>';
  2224. }
  2225. else
  2226. {
  2227. echo '
  2228. <li><a title="'.T_('First Page').'" class="first" href="'.$url.$divider.'page=1">'.T_('First').'</a></li>
  2229. <li><a title="'.T_('Previous Page').'" class="previous" href="'.$url.$divider.'page=1">'.T_('Previous').'</a></li>';
  2230. }
  2231. // Numbers
  2232. if ($total_pages > 8)
  2233. {
  2234. if ($cur_page > 2)
  2235. {
  2236. for ($i = ($cur_page-2); $i <= ($cur_page+5); $i++)
  2237. {
  2238. if ($i <= $total_pages)
  2239. {
  2240. $aClass = $cur_page == $i ? ' class="current"' : '';
  2241. $lClass = $cur_page == $i ? ' class="active"' : '';
  2242. echo '
  2243. <li'.$lClass.'><a href="'.$url.$divider.'page='.$i.'"'.$aClass.'>'.$i.'</a></li>';
  2244. }
  2245. }
  2246. }
  2247. else
  2248. {
  2249. for ($i = 1; $i <= 8; $i++)
  2250. {
  2251. $aClass = $cur_page == $i ? ' class="current"' : '';
  2252. $lClass = $cur_page == $i ? ' class="active"' : '';
  2253. echo '
  2254. <li'.$lClass.'><a href="'.$url.$divider.'page='.$i.'"'.$aClass.'>'.$i.'</a></li>';
  2255. }
  2256. }
  2257. }
  2258. else
  2259. {
  2260. for ($i = 1; $i <= $total_pages; $i++)
  2261. {
  2262. $aClass = $cur_page == $i ? ' class="current"' : '';
  2263. $lClass = $cur_page == $i ? ' class="active"' : '';
  2264. echo '
  2265. <li'.$lClass.'><a href="'.$url.$divider.'page='.$i.'"'.$aClass.'>'.$i.'</a></li>';
  2266. }
  2267. }
  2268. // Next / Last
  2269. if ($cur_page < $total_pages)
  2270. {
  2271. $next = ($cur_page + 1);
  2272. echo '
  2273. <li><a title="'.T_('Next Page').'" class="next" href="'.$url.$divider.'page='.$next.'">'.T_('Next').'</a></li>
  2274. <li><a title="'.T_('Last page').'" class="last" href="'.$url.$divider.'page='.$total_pages.'">'.T_('Last').'</a></li>';
  2275. }
  2276. else
  2277. {
  2278. echo '
  2279. <li><a title="'.T_('Next Page').'" class="next" href="'.$url.$divider.'page='.$total_pages.'">'.T_('Next').'</a></li>
  2280. <li><a title="'.T_('Last page').'" class="last" href="'.$url.$divider.'page='.$total_pages.'">'.T_('Last').'</a></li>';
  2281. }
  2282. echo '
  2283. </ul>
  2284. </div>';
  2285. }
  2286. }
  2287. /**
  2288. * formatSize
  2289. *
  2290. * @param int $file_size
  2291. * @return string
  2292. */
  2293. function formatSize($file_size)
  2294. {
  2295. if ($file_size >= 1073741824) {
  2296. $file_size = round($file_size / 1073741824 * 100) / 100 . "Gb";
  2297. } elseif ($file_size >= 1048576) {
  2298. $file_size = round($file_size / 1048576 * 100) / 100 . "Mb";
  2299. } elseif ($file_size >= 1024) {
  2300. $file_size = round($file_size / 1024 * 100) / 100 . "Kb";
  2301. } else {
  2302. $file_size = $file_size . "b";
  2303. }
  2304. return $file_size;
  2305. }
  2306. /**
  2307. * displayMembersOnline
  2308. *
  2309. * @return void
  2310. */
  2311. function displayMembersOnline ()
  2312. {
  2313. $last24hours = time() - (60 * 60 * 24);
  2314. $sql = "SELECT *
  2315. FROM fcms_users
  2316. WHERE UNIX_TIMESTAMP(`activity`) >= $last24hours
  2317. ORDER BY `activity` DESC";
  2318. $result = mysql_query($sql);
  2319. if (!$result)
  2320. {
  2321. displaySqlError('Online Error', __FILE__.' ['.__LINE__.']', $sql, mysql_error());
  2322. return;
  2323. }
  2324. echo '
  2325. <h3>'.T_('Last Seen').':</h3>
  2326. <ul class="avatar-member-list">';
  2327. while ($r = mysql_fetch_assoc($result))
  2328. {
  2329. $displayname = getUserDisplayName($r['id']);
  2330. $tz_offset = getTimezone($r['id']);
  2331. $activity = fixDate('F d, h:i a', $tz_offset, $r['activity']);
  2332. $since = getHumanTimeSince(strtotime($r['activity']));
  2333. echo '
  2334. <li>
  2335. <a href="profile.php?member='.$r['id'].'" class="tooltip" title="['.$displayname.'] - '.$activity.'" onmouseover="showTooltip(this)" onmouseout="hideTooltip(this)">
  2336. <img alt="avatar" src="'.getCurrentAvatar($r['id']).'" alt="'.$displayname.'"/>
  2337. </a>
  2338. <div class="tooltip" style="display:none;">
  2339. <h5>'.$displayname.'</h5>
  2340. <span>'.$since.'</span>
  2341. </div>
  2342. </li>';
  2343. }
  2344. echo '
  2345. </ul><br/><br/>';
  2346. }
  2347. /**
  2348. * checkLoginInfo
  2349. *
  2350. * Checks the user's username/pw combo
  2351. *
  2352. * @param $userid the id of the user you want to check
  2353. * @param $username the username of the user
  2354. * @param $password the password of the user
  2355. * returns boolean
  2356. */
  2357. function checkLoginInfo ($userid, $username, $password)
  2358. {
  2359. $userid = (int)$userid;
  2360. $sql = "SELECT `username`, `password`
  2361. FROM `fcms_users`
  2362. WHERE `id` = '$userid'
  2363. LIMIT 1";
  2364. $result = mysql_query($sql);
  2365. if (!$result)
  2366. {
  2367. displaySqlError($sql, mysql_error());
  2368. return false;
  2369. }
  2370. if (mysql_num_rows($result) <= 0)
  2371. {
  2372. return false;
  2373. }
  2374. $r = mysql_fetch_array($result);
  2375. if ($r['username'] !== $username)
  2376. {
  2377. return false;
  2378. }
  2379. elseif ($r['password'] !== $password)
  2380. {
  2381. return false;
  2382. }
  2383. else
  2384. {
  2385. return true;
  2386. }
  2387. }
  2388. /**
  2389. * buildHtmlSelectOptions
  2390. *
  2391. * Builds a list of select options, given an array of values and selected values.
  2392. *
  2393. * @param $options array of available options, key is the value of the option
  2394. * @param $selected array or string of selected options, key is the value of the option
  2395. * returns a string of options
  2396. *
  2397. */
  2398. function buildHtmlSelectOptions ($options, $selected_options)
  2399. {
  2400. $return = '';
  2401. foreach ($options as $key => $value)
  2402. {
  2403. $selected = '';
  2404. if (is_array($selected))
  2405. {
  2406. if (array_key_exists($key, $selected_options))
  2407. {
  2408. $selected = ' selected="selected"';
  2409. }
  2410. }
  2411. else
  2412. {
  2413. if ($key == $selected_options)
  2414. {
  2415. $selected = ' selected="selected"';
  2416. }
  2417. }
  2418. $return .= '<option value="'.cleanOutput($key).'"'.$selected.'>'.cleanOutput($value).'</option>';
  2419. }
  2420. return $return;
  2421. }
  2422. /**
  2423. * usingFamilyNews
  2424. *
  2425. * Wrapper function for usingPlugin.
  2426. *
  2427. * @return boolean
  2428. */
  2429. function usingFamilyNews()
  2430. {
  2431. return usingPlugin('familynews');
  2432. }
  2433. /**
  2434. * usingPrayers
  2435. *
  2436. * Wrapper function for usingPlugin.
  2437. *
  2438. * @return boolean
  2439. */
  2440. function usingPrayers()
  2441. {
  2442. return usingPlugin('prayers');
  2443. }
  2444. /**
  2445. * usingRecipes
  2446. *
  2447. * Wrapper function for usingPlugin.
  2448. *
  2449. * @return boolean
  2450. */
  2451. function usingRecipes()
  2452. {
  2453. return usingPlugin('recipes');
  2454. }
  2455. /**
  2456. * usingDocuments
  2457. *
  2458. * Wrapper function for usingPlugin.
  2459. *
  2460. * @return boolean
  2461. */
  2462. function usingDocuments()
  2463. {
  2464. return usingPlugin('documents');
  2465. }
  2466. /**
  2467. * usingWhereIsEveryone
  2468. *
  2469. * Wrapper function for usingPlugin.
  2470. *
  2471. * @return boolean
  2472. */
  2473. function usingWhereIsEveryone()
  2474. {
  2475. return usingPlugin('whereiseveryone');
  2476. }
  2477. /**
  2478. * usingFacebook
  2479. *
  2480. * Wrapper function for usingPlugin.
  2481. *
  2482. * @return boolean
  2483. */
  2484. function usingFacebook()
  2485. {
  2486. return usingPlugin('admin_facebook');
  2487. }
  2488. /**
  2489. * usingPlugin
  2490. *
  2491. * Checks whether the given section is currently being used.
  2492. *
  2493. * @param string $section
  2494. * @return boolean
  2495. */
  2496. function usingPlugin ($section)
  2497. {
  2498. $sql = "SELECT `id`, `link`, `order`
  2499. FROM `fcms_navigation`
  2500. WHERE `link` = '".escape_string($section)."'
  2501. LIMIT 1";
  2502. $result = mysql_query($sql);
  2503. if (!$result)
  2504. {
  2505. displaySqlError($sql, mysql_error());
  2506. return false;
  2507. }
  2508. if (mysql_num_rows($result) > 0)
  2509. {
  2510. $r = mysql_fetch_assoc($result);
  2511. if ($r['order'] > 0)
  2512. {
  2513. return true;
  2514. }
  2515. }
  2516. return false;
  2517. }
  2518. /**
  2519. * tableExists
  2520. *
  2521. * @param string $tbl
  2522. * @return boolean
  2523. */
  2524. function tableExists ($tbl)
  2525. {
  2526. global $cfg_mysql_db;
  2527. $tbl = escape_string($tbl);
  2528. $table = mysql_query("SHOW TABLES FROM `$cfg_mysql_db` LIKE '$tbl'");
  2529. if (mysql_fetch_row($table) === false) {
  2530. return false;
  2531. } else {
  2532. return true ;
  2533. }
  2534. }
  2535. /**
  2536. * getDomainAndDir
  2537. *
  2538. * @return string
  2539. */
  2540. function getDomainAndDir ()
  2541. {
  2542. $pageURL = 'http';
  2543. if (isset($_SERVER["HTTPS"]))
  2544. {
  2545. if ($_SERVER["HTTPS"] == "on")
  2546. {
  2547. $pageURL .= 's';
  2548. }
  2549. }
  2550. $pageURL .= '://';
  2551. if (isset($_SERVER["SERVER_PORT"]))
  2552. {
  2553. if ($_SERVER["SERVER_PORT"] != "80")
  2554. {
  2555. $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  2556. }
  2557. else
  2558. {
  2559. $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  2560. }
  2561. }
  2562. // Return the domain and any directories, but exlude the filename from the end
  2563. return substr($pageURL, 0, strripos($pageURL, '/')+1);
  2564. }
  2565. /**
  2566. * displaySqlError
  2567. *
  2568. * Logs sql errors and prints a generic error message.
  2569. * If debugging is turned on, will also print debug info.
  2570. *
  2571. * @param string $sql
  2572. * @param string $error
  2573. *
  2574. * @return void
  2575. */
  2576. function displaySqlError ($sql, $error)
  2577. {
  2578. $backtrace = debug_backtrace(false);
  2579. $last = $backtrace[1];
  2580. $file = $last['file'];
  2581. $line = $last['line'];
  2582. $debugInfo = '';
  2583. if (debugOn())
  2584. {
  2585. $debugInfo = '
  2586. <p><b>File:</b> '.$file.'</p>
  2587. <p><b>Statement:</b> '.$sql.'</p>
  2588. <p><b>Error:</b> '.$error.'</p>
  2589. <p><b>MySQL Version:</b> '.mysql_get_server_info().'</p>
  2590. <p><b>PHP Version:</b> '.phpversion().'</p>';
  2591. }
  2592. echo '
  2593. <div class="error-alert">
  2594. <p><b>'.T_('There was a problem communicating with the database.').'</b></p>
  2595. '.$debugInfo.'
  2596. </div>';
  2597. // Remove newlines, tabs, spaces from sql
  2598. $sql = str_replace(array("\n", "\r", " ", "\t"), '', $sql);
  2599. logError($file.' ['.$line.'] - '.$error.' - '.$sql);
  2600. }
  2601. /**
  2602. * displayError
  2603. *
  2604. * @param string $error
  2605. *
  2606. * @return void
  2607. */
  2608. function displayError ($error)
  2609. {
  2610. // Get file and line
  2611. $backtrace = debug_backtrace(false);
  2612. $last = $backtrace[1];
  2613. $file = $last['file'];
  2614. $line = $last['line'];
  2615. $debugInfo = '';
  2616. if (debugOn())
  2617. {
  2618. $debugInfo = '
  2619. <p><b>File:</b> '.$file.'</p>
  2620. <p><b>Line:</b> '.$line.'</p>
  2621. <p><b>MySQL Version:</b> '.mysql_get_server_info().'</p>
  2622. <p><b>PHP Version:</b> '.phpversion().'</p>';
  2623. }
  2624. echo '
  2625. <div class="error-alert">
  2626. '.$error.'
  2627. '.$debugInfo.'
  2628. </div>';
  2629. logError($file.' ['.$line.'] - '.$error);
  2630. }
  2631. /**
  2632. * logError
  2633. *
  2634. * @param string $string The full error string
  2635. *
  2636. * @return void
  2637. */
  2638. function logError ($string)
  2639. {
  2640. require_once THIRDPARTY.'KLogger.php';
  2641. $log = new KLogger(ROOT.'logs/', KLogger::ERR );
  2642. $log->logError($string);
  2643. }
  2644. /**
  2645. * debugOn
  2646. *
  2647. * @return void
  2648. */
  2649. function debugOn ()
  2650. {
  2651. $sql = "SELECT `value`
  2652. FROM `fcms_config`
  2653. WHERE `name` = 'debug'
  2654. LIMIT 1";
  2655. $result = mysql_query($sql);
  2656. if (!$result)
  2657. {
  2658. displaySqlError($sql, mysql_error());
  2659. return false;
  2660. }
  2661. if (mysql_num_rows($result) <= 0)
  2662. {
  2663. return false;
  2664. }
  2665. $r = mysql_fetch_assoc($result);
  2666. $on = $r['value'] == 1 ? true : false;
  2667. return $on;
  2668. }
  2669. /**
  2670. * displayWhatsNewAll
  2671. *
  2672. * Displays the following types of new data from the site:
  2673. *
  2674. * ADDRESSADD Add address of non-member
  2675. * ADDRESSEDIT Edit own address
  2676. * AVATAR Change avatar
  2677. * BOARD Message board post
  2678. * CALENDAR Add date to calendar
  2679. * DOCS Added document
  2680. * GALCATCOM Commented on category of photos
  2681. * GALCOM Commented on photo
  2682. * GALLERY Added photo
  2683. * JOINED Joined the site (became active)
  2684. * NEWS Added family news
  2685. * NEWSCOM Commented on family news
  2686. * POLL Added poll
  2687. * POLLCOM Commented on poll
  2688. * PRAYERS Added prayer concern
  2689. * RECIPES Added recipe
  2690. * RECIPECOM Commented on recipe
  2691. * STATUS Added status update
  2692. * VIDEO Added video
  2693. * VIDEOCOM Commented on video
  2694. * WHEREISEVERYONE Checked in on foursquare
  2695. *
  2696. * @param int $userid
  2697. *
  2698. * @return void
  2699. */
  2700. function displayWhatsNewAll ($userid)
  2701. {
  2702. global $cfg_mysql_host, $cfg_use_news, $cfg_use_prayers;
  2703. load('gallery');
  2704. $userid = (int)$userid;
  2705. $tz_offset = getTimezone($userid);
  2706. $galleryObj = new PhotoGallery($userid);
  2707. $lastday = '0-0';
  2708. $today_start = fixDate('Ymd', $tz_offset, date('Y-m-d H:i:s')) . '000000';
  2709. $today_end = fixDate('Ymd', $tz_offset, date('Y-m-d H:i:s')) . '235959';
  2710. $time = mktime(0, 0, 0, date('m') , date('d')-1, date('Y'));
  2711. $yesterday_start = fixDate('Ymd', $tz_offset, date('Y-m-d H:i:s', $time)) . '000000';
  2712. $yesterday_end = fixDate('Ymd', $tz_offset, date('Y-m-d H:i:s', $time)) . '235959';
  2713. // Get data
  2714. $whatsNewData = getWhatsNewData($userid, 30);
  2715. if ($whatsNewData === false)
  2716. {
  2717. return;
  2718. }
  2719. $cachedUserData = array();
  2720. $position = 1;
  2721. // Loop through data
  2722. foreach ($whatsNewData as $r)
  2723. {
  2724. $updated = fixDate('Ymd', $tz_offset, $r['date']);
  2725. $updatedFull = fixDate('YmdHis', $tz_offset, $r['date']);
  2726. // Print date header
  2727. if ($updated != $lastday)
  2728. {
  2729. // Today
  2730. if ($updatedFull >= $today_start && $updatedFull <= $today_end)
  2731. {
  2732. echo '
  2733. <p><b>'.T_('Today').'</b></p>';
  2734. }
  2735. // Yesterday
  2736. if ($updatedFull >= $yesterday_start && $updatedFull <= $yesterday_end)
  2737. {
  2738. echo '
  2739. <p><b>'.T_('Yesterday').'</b></p>';
  2740. }
  2741. }
  2742. $rtime = strtotime($r['date']);
  2743. // Use cached data
  2744. if (isset($cachedUserData[$r['userid']]))
  2745. {
  2746. $displayname = $cachedUserData[$r['userid']]['displayname'];
  2747. $avatar = $cachedUserData[$r['userid']]['avatar'];
  2748. }
  2749. // Get new data
  2750. else
  2751. {
  2752. $displayname = getUserDisplayName($r['userid']);
  2753. $displayname = '<a class="u" href="profile.php?member='.$r['userid'].'">'.$displayname.'</a>';
  2754. $avatar = '<img src="'.getCurrentAvatar($r['userid']).'" alt="'.cleanOutput($displayname).'"/>';
  2755. // Save this for later
  2756. $cachedUserData[$r['userid']]['avatar'] = $avatar;
  2757. $cachedUserData[$r['userid']]['displayname'] = $displayname;
  2758. }
  2759. if ($r['type'] == 'ADDRESSADD')
  2760. {
  2761. $displayname = getUserDisplayName($r['id2']);
  2762. $displayname = '<a class="u" href="profile.php?member='.$r['id2'].'">'.$displayname.'</a>';
  2763. $avatar = '<img src="'.getCurrentAvatar($r['id2']).'" alt="'.cleanOutput($displayname).'"/>';
  2764. $for = '<a href="addressbook.php?address='.$r['id'].'">'.getUserDisplayName($r['userid'], 2, false).'</a>';
  2765. echo '
  2766. <div id="'.$position.'" class="new newaddress">
  2767. <div class="avatar">'.$avatar.'</div>
  2768. <div class="info">
  2769. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  2770. <p>
  2771. '.sprintf(T_('Added address information for %s.'), $for).'
  2772. </p>
  2773. </div>
  2774. </div>';
  2775. }
  2776. elseif ($r['type'] == 'ADDRESSEDIT')
  2777. {
  2778. if ($r['title'] == 'address')
  2779. {
  2780. $titleType = T_('address');
  2781. }
  2782. elseif ($r['title'] == 'email')
  2783. {
  2784. $titleType = T_('email address');
  2785. }
  2786. elseif ($r['title'] == 'home')
  2787. {
  2788. $titleType = T_('home phone number');
  2789. }
  2790. elseif ($r['title'] == 'work')
  2791. {
  2792. $titleType = T_('work phone number');
  2793. }
  2794. elseif ($r['title'] == 'cell')
  2795. {
  2796. $titleType = T_('cell phone number');
  2797. }
  2798. // this shouldn't happen
  2799. else
  2800. {
  2801. $titleType = T_('address');
  2802. }
  2803. $editor = getUserDisplayName($r['id2']);
  2804. $editor = '<a class="u" href="profile.php?member='.$r['id2'].'">'.$editor.'</a>';
  2805. $avatar = '<img src="'.getCurrentAvatar($r['id2']).'" alt="'.cleanOutput($editor).'"/>';
  2806. $address = '<a href="addressbook.php?address='.$r['id'].'">'.$titleType.'</a>';
  2807. if ($r['id2'] != $r['userid'])
  2808. {
  2809. $user = getUserDisplayName($r['userid']);
  2810. $text = sprintf(T_pgettext('Example: "Updated the <address/phone/email> for <name>."', 'Updated the %s for %s.'), $address, $user);
  2811. }
  2812. else
  2813. {
  2814. if ($r['id3'] == 'F')
  2815. {
  2816. $text = sprintf(T_pgettext('Example: "Updated her <address/phone/email>."', 'Updated her %s.'), $address);
  2817. }
  2818. else
  2819. {
  2820. $text = sprintf(T_pgettext('Example: "Updated his <address/phone/email>."', 'Updated his %s.'), $address);
  2821. }
  2822. }
  2823. echo '
  2824. <div id="'.$position.'" class="new newaddress">
  2825. <div class="avatar">'.$avatar.'</div>
  2826. <div class="info">
  2827. '.$editor.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  2828. <p>
  2829. '.$text.'
  2830. </p>
  2831. </div>
  2832. </div>';
  2833. }
  2834. elseif ($r['type'] == 'AVATAR')
  2835. {
  2836. $text = T_('Changed his profile picture.');
  2837. if ($r['id3'] == 'F')
  2838. {
  2839. $text = T_('Changed her profile picture.');
  2840. }
  2841. echo '
  2842. <div id="'.$position.'" class="new newavatar">
  2843. <div class="avatar">'.$avatar.'</div>
  2844. <div class="info">
  2845. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  2846. <p>'.$text.'</p>
  2847. </div>
  2848. </div>';
  2849. }
  2850. elseif ($r['type'] == 'BOARD')
  2851. {
  2852. $sql = "SELECT MIN(`id`) AS 'id'
  2853. FROM `fcms_board_posts`
  2854. WHERE `thread` = '".$r['id2']."'";
  2855. $result = mysql_query($sql);
  2856. if (!$result)
  2857. {
  2858. displaySqlError($sql, mysql_error());
  2859. return;
  2860. }
  2861. $minpost = mysql_fetch_array($result);
  2862. $subject = $r['title'];
  2863. $pos = strpos($subject, '#ANOUNCE#');
  2864. if ($pos !== false)
  2865. {
  2866. $subject = substr($subject, 9, strlen($subject)-9);
  2867. }
  2868. $title = cleanOutput($subject);
  2869. $subject = cleanOutput($subject);
  2870. $subject = '<a href="messageboard.php?thread='.$r['id2'].'" title="'.$title.'">'.$subject.'</a>';
  2871. if ($r['id'] == $minpost['id'])
  2872. {
  2873. $class = 'newthread';
  2874. $text = sprintf(T_('Started the new thread %s.'), $subject);
  2875. }
  2876. else
  2877. {
  2878. $class = 'newpost';
  2879. $text = sprintf(T_('Replied to %s.'), $subject);
  2880. }
  2881. echo '
  2882. <div id="'.$position.'" class="new '.$class.'">
  2883. <div class="avatar">'.$avatar.'</div>
  2884. <div class="info">
  2885. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  2886. <p>
  2887. '.$text.'
  2888. </p>
  2889. </div>
  2890. </div>';
  2891. }
  2892. elseif ($r['type'] == 'CALENDAR')
  2893. {
  2894. $date_date = date('F j, Y', strtotime($r['id2']));
  2895. $for = '<a href="calendar.php?event='.$r['id'].'">'.cleanOutput($r['title']).'</a>';
  2896. echo '
  2897. <div id="'.$position.'" class="new newcal">
  2898. <div class="avatar">'.$avatar.'</div>
  2899. <div class="info">
  2900. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  2901. <p>
  2902. '.$for.' - '.$date_date.'
  2903. </p>
  2904. </div>
  2905. </div>';
  2906. }
  2907. elseif ($r['type'] == 'DOCS')
  2908. {
  2909. $doc = '<a href="documents.php">'.cleanOutput($r['title']).'</a>';
  2910. echo '
  2911. <div id="'.$position.'" class="new newdocument">
  2912. <div class="avatar">'.$avatar.'</div>
  2913. <div class="info">
  2914. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  2915. <p>
  2916. '.sprintf(T_('Added a new Document (%s).'), $doc).'
  2917. </p>
  2918. </div>
  2919. </div>';
  2920. }
  2921. elseif ($r['type'] == 'GALCATCOM')
  2922. {
  2923. $category = '<a href="gallery/index.php?uid='.$r['id2'].'&amp;cid='.$r['id3'].'">'.cleanOutput($r['title']).'</a>';
  2924. echo '
  2925. <div id="'.$position.'" class="new newcom">
  2926. <div class="avatar">'.$avatar.'</div>
  2927. <div class="info">
  2928. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  2929. <p>
  2930. '.sprintf(T_('Commented on %s.'), $category).'
  2931. </p>
  2932. </div>
  2933. </div>';
  2934. }
  2935. elseif ($r['type'] == 'GALCOM')
  2936. {
  2937. $data = array(
  2938. 'id' => $r['id'],
  2939. 'user' => $r['id2'],
  2940. 'filename' => $r['id3'],
  2941. 'external_id' => null,
  2942. 'thumbnail' => null
  2943. );
  2944. if ($r['id3'] == 'noimage.gif')
  2945. {
  2946. $sql = "SELECT p.`id`, p.`filename`, p.`external_id`, e.`thumbnail`
  2947. FROM `fcms_gallery_photos` AS p
  2948. LEFT JOIN `fcms_gallery_external_photo` AS e ON p.`external_id` = e.`id`
  2949. WHERE p.`id` = '".(int)$r['id']."'";
  2950. $result = mysql_query($sql);
  2951. if (!$result)
  2952. {
  2953. displaySqlError($sql, mysql_error());
  2954. return;
  2955. }
  2956. $p = mysql_fetch_assoc($result);
  2957. $data['external_id'] = $p['external_id'];
  2958. $data['thumbnail'] = $p['thumbnail'];
  2959. }
  2960. $photoSrc = $galleryObj->getPhotoSource($data);
  2961. echo '
  2962. <div id="'.$position.'" class="new newcom">
  2963. <div class="avatar">'.$avatar.'</div>
  2964. <div class="info">
  2965. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  2966. <p>
  2967. '.T_('Commented on the following photo:').'<br/>
  2968. <a href="gallery/index.php?uid=0&amp;cid=comments&amp;pid='.$r['id'].'">
  2969. <img src="'.$photoSrc.'"/>
  2970. </a>
  2971. </p>
  2972. </div>
  2973. </div>';
  2974. }
  2975. elseif ($r['type'] == 'GALLERY')
  2976. {
  2977. $cat = '<a href="gallery/index.php?uid='.$r['userid'].'&amp;cid='.$r['id'].'">'.cleanOutput($r['title']).'</a>';
  2978. $photos = '';
  2979. $limit = 4;
  2980. if ($r['id2'] < $limit)
  2981. {
  2982. $limit = $r['id2'];
  2983. }
  2984. $sql = "SELECT p.`id`, p.`user`, p.`category`, p.`filename`, p.`caption`,
  2985. p.`external_id`, e.`thumbnail`, e.`medium`, e.`full`
  2986. FROM `fcms_gallery_photos` AS p
  2987. LEFT JOIN `fcms_gallery_external_photo` AS e ON p.`external_id` = e.`id`
  2988. WHERE p.`category` = '".(int)$r['id']."'
  2989. AND DAYOFYEAR(p.`date`) = '".(int)$r['id3']."'
  2990. ORDER BY p.`date`
  2991. DESC LIMIT $limit";
  2992. $result = mysql_query($sql);
  2993. if (!$result)
  2994. {
  2995. displaySqlError($sql, mysql_error());
  2996. return;
  2997. }
  2998. while ($p = mysql_fetch_assoc($result))
  2999. {
  3000. $photoSrc = $galleryObj->getPhotoSource($p);
  3001. $photos .= '
  3002. <a href="gallery/index.php?uid='.$r['userid'].'&amp;cid='.$r['id'].'&amp;pid='.$p['id'].'">
  3003. <img src="'.$photoSrc.'" alt="'.cleanOutput($p['caption']).'"/>
  3004. </a> &nbsp;';
  3005. }
  3006. echo '
  3007. <div id="'.$position.'" class="new newphoto">
  3008. <div class="avatar">'.$avatar.'</div>
  3009. <div class="info">
  3010. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  3011. <p>
  3012. '.sprintf(T_('Added %d new photos to the %s category.'), $r['id2'], $cat).'<br/>
  3013. '.$photos.'
  3014. </p>
  3015. </div>
  3016. </div>';
  3017. }
  3018. elseif ($r['type'] == 'JOINED')
  3019. {
  3020. echo '
  3021. <div id="'.$position.'" class="new newmember">
  3022. <div class="avatar">'.$avatar.'</div>
  3023. <div class="info">
  3024. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  3025. <p>'.T_('Joined the website.').'</p>
  3026. </div>
  3027. </div>';
  3028. }
  3029. elseif ($r['type'] == 'NEWS')
  3030. {
  3031. $title = !empty($r['title']) ? cleanOutput($r['title']) : T_('untitled');
  3032. $news = '<a href="familynews.php?getnews='.$r['userid'].'&amp;newsid='.$r['id'].'">'.$title.'</a>';
  3033. echo '
  3034. <div id="'.$position.'" class="new newnews">
  3035. <div class="avatar">'.$avatar.'</div>
  3036. <div class="info">
  3037. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  3038. <p>
  3039. '.sprintf(T_('Added %s to his/her Family News.'), $news).'
  3040. </p>
  3041. </div>
  3042. </div>';
  3043. }
  3044. elseif ($r['type'] == 'NEWSCOM')
  3045. {
  3046. $news = '<a href="familynews.php?getnews='.$r['userid'].'&amp;newsid='.$r['id'].'">'.cleanOutput($r['title']).'</a>';
  3047. echo '
  3048. <div id="'.$position.'" class="new newcom">
  3049. <div class="avatar">'.$avatar.'</div>
  3050. <div class="info">
  3051. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  3052. <p>
  3053. '.sprintf(T_('Commented on Family News %s.'), $news).'
  3054. </p>
  3055. </div>
  3056. </div>';
  3057. }
  3058. elseif ($r['type'] == 'POLL')
  3059. {
  3060. $poll = '<a href="polls.php?id='.$r['id'].'">'.cleanOutput($r['title']).'</a>';
  3061. echo '
  3062. <p class="new newpoll">'.sprintf(T_('A new Poll (%s) has been added.'), $poll).' <small><i>'.getHumanTimeSince($rtime).'</i></small></p>';
  3063. }
  3064. elseif ($r['type'] == 'POLLCOM')
  3065. {
  3066. $poll = '<a href="polls.php?id='.$r['id'].'"#comments>'.cleanOutput($r['title']).'</a>';
  3067. echo '
  3068. <div id="'.$position.'" class="new pollcom">
  3069. <div class="avatar">'.$avatar.'</div>
  3070. <div class="info">
  3071. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  3072. <p>
  3073. '.sprintf(T_('Commented on Poll %s.'), $poll).'
  3074. </p>
  3075. </div>
  3076. </div>';
  3077. }
  3078. elseif ($r['type'] == 'PRAYERS')
  3079. {
  3080. $for = '<a href="prayers.php">'.cleanOutput($r['title']).'</a>';
  3081. echo '
  3082. <div id="'.$position.'" class="new newprayer">
  3083. <div class="avatar">'.$avatar.'</div>
  3084. <div class="info">
  3085. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  3086. <p>
  3087. '.sprintf(T_('Added a Prayer Concern for %s.'), $for).'
  3088. </p>
  3089. </div>
  3090. </div>';
  3091. }
  3092. elseif ($r['type'] == 'RECIPES')
  3093. {
  3094. $rec = '<a href="recipes.php?category='.$r['id2'].'&amp;id='.$r['id'].'">'.cleanOutput($r['title']).'</a>';
  3095. echo '
  3096. <div id="'.$position.'" class="new newrecipe">
  3097. <div class="avatar">'.$avatar.'</div>
  3098. <div class="info">
  3099. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  3100. <p>
  3101. '.sprintf(T_('Added the %s recipe.'), $rec).'
  3102. </p>
  3103. </div>
  3104. </div>';
  3105. }
  3106. elseif ($r['type'] == 'RECIPECOM')
  3107. {
  3108. $rec = '<a href="recipes.php?category='.$r['id2'].'&amp;id='.$r['id'].'">'.cleanOutput($r['title']).'</a>';
  3109. echo '
  3110. <div id="'.$position.'" class="new newcom">
  3111. <div class="avatar">'.$avatar.'</div>
  3112. <div class="info">
  3113. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  3114. <p>
  3115. '.sprintf(T_('Commented on Recipe %s.'), $rec).'
  3116. </p>
  3117. </div>
  3118. </div>';
  3119. }
  3120. elseif ($r['type'] == 'STATUS')
  3121. {
  3122. $title = cleanOutput($r['title']);
  3123. $title = nl2br_nospaces($title);
  3124. // Get any replies to this status update
  3125. $sql = "SELECT `id`, `user`, `status`, `parent`, `updated`, `created`
  3126. FROM `fcms_status`
  3127. WHERE `parent` = '".(int)$r['id']."'
  3128. ORDER BY `id`";
  3129. $result = mysql_query($sql);
  3130. if (!$result)
  3131. {
  3132. displaySqlError($sql, mysql_error());
  3133. return;
  3134. }
  3135. $statuses = '';
  3136. if (mysql_num_rows($result) > 0)
  3137. {
  3138. while ($s = mysql_fetch_assoc($result))
  3139. {
  3140. $name = getUserDisplayName($s['user']);
  3141. $name = '<a class="u" href="profile.php?member='.$s['user'].'">'.$name.'</a>';
  3142. $avatar2 = '<img src="'.getCurrentAvatar($s['user']).'" alt="'.cleanOutput($name).'"/>';
  3143. $status = cleanOutput($s['status']);
  3144. $status = nl2br_nospaces($status);
  3145. $statuses .= '
  3146. <div class="newstatus">
  3147. <div class="avatar">'.$avatar2.'</div>
  3148. <div class="info">
  3149. '.$name.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince(strtotime($s['created'])).'</i></small>
  3150. <p>
  3151. '.$status.'
  3152. </p>
  3153. </div>
  3154. </div>';
  3155. }
  3156. }
  3157. echo '
  3158. <div id="'.$position.'" class="new newstatus">
  3159. <div class="avatar">'.$avatar.'</div>
  3160. <div class="info">
  3161. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince(strtotime($r['id3'])).'</i></small>
  3162. <p>
  3163. '.$title.'
  3164. </p>
  3165. '.$statuses;
  3166. displayStatusUpdateForm($r['id']);
  3167. echo '
  3168. </div>
  3169. </div>';
  3170. }
  3171. elseif ($r['type'] == 'VIDEO')
  3172. {
  3173. echo '
  3174. <div id="'.$position.'" class="new newvideo">
  3175. <div class="avatar">'.$avatar.'</div>
  3176. <div class="info">
  3177. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  3178. <p>
  3179. '.T_('Added a new Video.').'<br/>
  3180. <a href="video.php?u='.$r['userid'].'&amp;id='.$r['id'].'"><img src="http://i.ytimg.com/vi/'.$r['id2'].'/default.jpg"/></a>
  3181. </p>
  3182. </div>
  3183. </div>';
  3184. }
  3185. elseif ($r['type'] == 'VIDEOCOM')
  3186. {
  3187. echo '
  3188. <div id="'.$position.'" class="new newcom">
  3189. <div class="avatar">'.$avatar.'</div>
  3190. <div class="info">
  3191. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  3192. <p>
  3193. '.T_('Commented on the following Video:').'<br/>
  3194. <a href="video.php?u='.$r['userid'].'&amp;id='.$r['id'].'#comments"><img src="http://i.ytimg.com/vi/'.$r['id2'].'/default.jpg"/></a>
  3195. </p>
  3196. </div>
  3197. </div>';
  3198. }
  3199. elseif ($r['type'] == 'WHEREISEVERYONE')
  3200. {
  3201. echo '
  3202. <div id="'.$position.'" class="new newwhere">
  3203. <div class="avatar">'.$avatar.'</div>
  3204. <div class="info">
  3205. '.$displayname.' &nbsp;- &nbsp;<small><i>'.getHumanTimeSince($rtime).'</i></small>
  3206. <p>
  3207. '.sprintf(T_('Visited %s.'), $r['title']).'
  3208. </p>
  3209. '.(!empty($r['id2']) ? '<blockquote>'.cleanOutput($r['id2']).'</blockquote>' : '').'
  3210. </div>
  3211. </div>';
  3212. }
  3213. $position++;
  3214. $lastday = $updated;
  3215. }
  3216. }
  3217. /**
  3218. * getWhatsNewData
  3219. *
  3220. * Get the latest information in the site, including any external data.
  3221. * Defaults to the last 30 days.
  3222. *
  3223. * Types of data:
  3224. *
  3225. * ADDRESSADD Add address of non-member
  3226. * ADDRESSEDIT Edit own address
  3227. * AVATAR Change avatar
  3228. * BOARD Message board post
  3229. * CALENDAR Add date to calendar
  3230. * DOCS Added document
  3231. * GALCATCOM Commented on category of photos
  3232. * GALCOM Commented on photo
  3233. * GALLERY Added photo
  3234. * JOINED Joined the site (became active)
  3235. * NEWS Added family news
  3236. * NEWSCOM Commented on family news
  3237. * POLL Added poll
  3238. * POLLCOM Commented on poll
  3239. * PRAYERS Added prayer concern
  3240. * RECIPES Added recipe
  3241. * RECIPECOM Commented on recipe
  3242. * STATUS Added status update
  3243. * VIDEO Added video
  3244. * VIDEOCOM Commented on video
  3245. * WHEREISEVERYONE Checked in on foursquare
  3246. *
  3247. * @param int $userid
  3248. * @param int $days
  3249. * @param string $groupByType
  3250. *
  3251. * @return void
  3252. */
  3253. function getWhatsNewData ($userid, $days = 30, $groupByType = false)
  3254. {
  3255. $currentUserId = (int)$userid;
  3256. $sql = "SELECT p.`id`, `date`, `subject` AS title, u.`id` AS userid, `thread` AS id2, 0 AS id3, 'BOARD' AS type
  3257. FROM `fcms_board_posts` AS p, `fcms_board_threads` AS t, fcms_users AS u
  3258. WHERE p.`thread` = t.`id`
  3259. AND p.`user` = u.`id`
  3260. AND `date` >= DATE_SUB(CURDATE(),INTERVAL $days DAY)
  3261. UNION SELECT a.`id`, c.`created` AS date, c.`column` AS title, a.`user` AS userid, a.`updated_id` AS id2, u.`sex` AS id3, 'ADDRESSEDIT' AS type
  3262. FROM `fcms_changelog` AS c
  3263. LEFT JOIN `fcms_users` AS u ON c.`user` = u.`id`
  3264. LEFT JOIN `fcms_address` AS a ON u.`id` = a.`user`
  3265. WHERE c.`created` >= DATE_SUB(CURDATE(),INTERVAL $days DAY)
  3266. AND c.`column` != 'avatar'
  3267. UNION SELECT a.id, a.updated AS date, 0 AS title, a.user AS userid, a.`created_id` AS id2, u.joindate AS id3, 'ADDRESSADD' AS type
  3268. FROM fcms_address AS a, fcms_users AS u
  3269. WHERE a.user = u.id
  3270. AND u.`password` = 'NONMEMBER'
  3271. AND u.`activated` < 1
  3272. AND a.updated >= DATE_SUB(CURDATE(),INTERVAL $days DAY)
  3273. UNION SELECT `id`, `joindate` AS date, 0 AS title, `id` AS userid, 0 AS id2, 0 AS id3, 'JOINED' AS type
  3274. FROM `fcms_users`
  3275. WHERE `password` != 'NONMEMBER'
  3276. AND `activated` > 0
  3277. AND `joindate` >= DATE_SUB(CURDATE(), INTERVAL $days DAY) ";
  3278. if (usingFamilyNews())
  3279. {
  3280. $sql .= "UNION SELECT n.`id` AS id, n.`updated` AS date, `title`, u.`id` AS userid, 0 AS id2, 0 AS id3, 'NEWS' AS type
  3281. FROM `fcms_users` AS u, `fcms_news` AS n
  3282. WHERE u.`id` = n.`user`
  3283. AND n.`updated` >= DATE_SUB(CURDATE(),INTERVAL $days DAY)
  3284. AND `username` != 'SITENEWS'
  3285. AND `password` != 'SITENEWS'
  3286. UNION SELECT n.`id` AS 'id', nc.`date`, `title`, nc.`user` AS userid, 0 AS id2, 0 AS id3, 'NEWSCOM' AS type
  3287. FROM `fcms_news_comments` AS nc, `fcms_news` AS n, `fcms_users` AS u
  3288. WHERE nc.`date` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)
  3289. AND nc.`user` = u.`id`
  3290. AND n.`id` = nc.`news` ";
  3291. }
  3292. if (usingPrayers())
  3293. {
  3294. $sql .= "UNION SELECT 0 AS id, `date`, `for` AS title, `user` AS userid, 0 AS id2, 0 AS id3, 'PRAYERS' AS type
  3295. FROM `fcms_prayers`
  3296. WHERE `date` >= DATE_SUB(CURDATE(), INTERVAL $days DAY) ";
  3297. }
  3298. if (usingRecipes())
  3299. {
  3300. $sql .= "UNION SELECT `id` AS id, `date`, `name` AS title, `user` AS userid, `category` AS id2, 0 AS id3, 'RECIPES' AS type
  3301. FROM `fcms_recipes`
  3302. WHERE `date` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)
  3303. UNION SELECT r.`id`, rc.`date`, r.`name` AS title, rc.`user` AS userid, r.`category` AS id2, 0 AS id3, 'RECIPECOM' AS type
  3304. FROM `fcms_recipe_comment` AS rc, `fcms_recipes` AS r
  3305. WHERE rc.`date` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)
  3306. AND rc.`recipe` = r.`id` ";
  3307. }
  3308. if (usingdocuments())
  3309. {
  3310. $sql .= "UNION SELECT d.`id` AS 'id', d.`date`, `name` AS title, d.`user` AS userid, 0 AS id2, 0 AS id3, 'DOCS' AS type
  3311. FROM `fcms_documents` AS d, `fcms_users` AS u
  3312. WHERE d.`date` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)
  3313. AND d.`user` = u.`id` ";
  3314. }
  3315. $sql .= "UNION SELECT DISTINCT p.`category` AS id, p.`date`, `name` AS title, p.`user` AS userid, COUNT(*) AS id2, DAYOFYEAR(p.`date`) AS id3, 'GALLERY' AS type
  3316. FROM `fcms_gallery_photos` AS p, `fcms_users` AS u, `fcms_category` AS c
  3317. WHERE p.`user` = u.`id`
  3318. AND p.`category` = c.`id`
  3319. AND p.`date` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)
  3320. GROUP BY userid, title, id3
  3321. UNION SELECT p.`id`, gc.`date`, `comment` AS title, gc.`user` AS userid, p.`user` AS id2, `filename` AS id3, 'GALCOM' AS type
  3322. FROM `fcms_gallery_photo_comment` AS gc, `fcms_users` AS u, `fcms_gallery_photos` AS p
  3323. WHERE gc.`date` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)
  3324. AND gc.`user` = u.`id`
  3325. AND gc.`photo` = p.`id`
  3326. UNION SELECT g.`id`, g.`created`, c.`name` AS title, g.`created_id` AS userid, c.`user` AS id2, c.`id` AS id3, 'GALCATCOM' AS type
  3327. FROM `fcms_gallery_category_comment` AS g
  3328. LEFT JOIN `fcms_users` AS u ON g.`created_id` = u.`id`
  3329. LEFT JOIN `fcms_category` AS c ON g.`category_id` = c.`id`
  3330. WHERE g.`created` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)
  3331. UNION SELECT c.`id`, c.`date_added` AS date, `title`, `created_by` AS userid, `date` AS id2, `category` AS id3, 'CALENDAR' AS type
  3332. FROM `fcms_calendar` AS c, `fcms_users` AS u
  3333. WHERE c.`date_added` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)
  3334. AND c.`created_by` = u.`id` AND `private` < 1
  3335. UNION SELECT `id`, `started` AS date, `question`, '0' AS userid, 'na' AS id2, 'na' AS id3, 'POLL' AS type
  3336. FROM `fcms_polls`
  3337. WHERE `started` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)
  3338. UNION SELECT p.`id`, c.`created` AS date, p.`question` AS title, c.`created_id` AS userid, 'na' AS id2, 'na' AS id3, 'POLLCOM' AS type
  3339. FROM `fcms_poll_comment` AS c
  3340. LEFT JOIN `fcms_polls` AS p ON c.`poll_id` = p.`id`
  3341. WHERE `created` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)
  3342. UNION SELECT `id`, `updated` AS date, `status` AS title, `user` AS userid, `parent` AS id2, `created` AS id3, 'STATUS' AS type
  3343. FROM `fcms_status`
  3344. WHERE `updated` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)
  3345. AND `parent` = 0
  3346. UNION SELECT 0 as id, c.`created` AS date, 0 AS title, c.`user` AS userid, 0 AS id2, u.`sex` AS id3, 'AVATAR' AS type
  3347. FROM `fcms_changelog` AS c
  3348. LEFT JOIN `fcms_users` AS u ON c.`user` = u.`id`
  3349. WHERE `created` >= DATE_SUB(CURDATE(),INTERVAL $days DAY)
  3350. AND `column` = 'avatar'
  3351. UNION SELECT `id`, `created` AS date, `title`, `created_id` AS userid, `source_id` AS id2, `source` AS id3, 'VIDEO' AS type
  3352. FROM `fcms_video`
  3353. WHERE `created` >= DATE_SUB(CURDATE(),INTERVAL $days DAY)
  3354. AND `active` = '1'
  3355. UNION SELECT `video_id` AS 'id', c.`created` AS date, `comment`, c.`created_id` AS userid, `source_id` AS id2, `source` AS id3, 'VIDEOCOM' AS type
  3356. FROM `fcms_video_comment` AS c
  3357. LEFT JOIN `fcms_video` AS v ON c.`video_id` = v.`id`
  3358. WHERE c.`created` >= DATE_SUB(CURDATE(),INTERVAL $days DAY)
  3359. AND v.`active` = '1'
  3360. ORDER BY date DESC LIMIT 0, 35";
  3361. $result = mysql_query($sql);
  3362. if (!$result)
  3363. {
  3364. displaySqlError($sql, mysql_error());
  3365. return false;
  3366. }
  3367. // Save data
  3368. while ($r = mysql_fetch_assoc($result))
  3369. {
  3370. if ($groupByType)
  3371. {
  3372. $whatsNewData[$r['type']][] = $r;
  3373. }
  3374. else
  3375. {
  3376. $whatsNewData[] = $r;
  3377. }
  3378. }
  3379. // Add external foursquare data
  3380. if (usingWhereIsEveryone())
  3381. {
  3382. include_once('socialmedia.php');
  3383. include_once('thirdparty/foursquare/EpiFoursquare.php');
  3384. include_once('thirdparty/foursquare/EpiCurl.php');
  3385. $users = getFoursquareUsersData();
  3386. $config = getFoursquareConfigData();
  3387. // TODO
  3388. // Move this check inside the getFoursquareConfigData and have it return false on failure.
  3389. // Foursquare hasn't been setup or is invalid
  3390. if (empty($config['fs_client_id']) or empty($config['fs_client_secret']))
  3391. {
  3392. // If admin is viewing, alert them that the config is missing/messed up
  3393. if (checkAccess($currentUserId) < 2)
  3394. {
  3395. echo '
  3396. <div class="info-alert">
  3397. <h2>'.T_('Foursquare is not configured correctly.').'</h2>
  3398. <p>'.T_('The "Where Is Everyone" feature cannot work without Foursquare. Please configure Foursquare or turn off "Where Is Everyone".').'</p>
  3399. </div>';
  3400. }
  3401. return $whatsNewData;
  3402. }
  3403. $foursquareData = array();
  3404. if (count($users[0]) > 0)
  3405. {
  3406. $timeago = gmmktime(0, 0, 0, gmdate('m'), gmdate('d')-$days, gmdate('Y'));
  3407. $i = 0;
  3408. foreach ($users as $k => $data)
  3409. {
  3410. // Skip users who don't have foursquare setup
  3411. if (empty($data['access_token']))
  3412. {
  3413. continue;
  3414. }
  3415. $fsObj = new EpiFoursquare($config['fs_client_id'], $config['fs_client_secret'], $data['access_token']);
  3416. try
  3417. {
  3418. $params = array(
  3419. 'afterTimestamp' => $timeago
  3420. );
  3421. $creds = $fsObj->get('/users/'.$data['user_id'].'/checkins', $params);
  3422. }
  3423. catch(EpiFoursquareException $e)
  3424. {
  3425. echo 'We caught an EpiOAuthException';
  3426. echo $e->getMessage();
  3427. return false;
  3428. }
  3429. catch(Exception $e)
  3430. {
  3431. echo 'We caught an unexpected Exception';
  3432. echo $e->getMessage();
  3433. return false;
  3434. }
  3435. foreach ($creds->response->checkins->items as $checkin)
  3436. {
  3437. // Skip shouts, etc
  3438. if ($checkin->type != 'checkin')
  3439. {
  3440. continue;
  3441. }
  3442. $date = date('Y-m-d H:i:s', $checkin->createdAt);
  3443. $sort = $checkin->createdAt;
  3444. $shout = isset($checkin->shout) ? $checkin->shout : '';
  3445. // Save data
  3446. if ($groupByType)
  3447. {
  3448. $whatsNewData['WHEREISEVERYONE'][] = array(
  3449. 'id' => '',
  3450. 'date' => $date,
  3451. 'title' => $checkin->venue->name,
  3452. 'userid' => $data['fcms_user_id'],
  3453. 'id2' => $shout,
  3454. 'id3' => '',
  3455. 'type' => 'WHEREISEVERYONE'
  3456. );
  3457. }
  3458. else
  3459. {
  3460. $whatsNewData[] = array(
  3461. 'id' => '',
  3462. 'date' => $date,
  3463. 'title' => $checkin->venue->name,
  3464. 'userid' => $data['fcms_user_id'],
  3465. 'id2' => $shout,
  3466. 'id3' => '',
  3467. 'type' => 'WHEREISEVERYONE'
  3468. );
  3469. }
  3470. }
  3471. }
  3472. }
  3473. // Order is messed up now, so fix it
  3474. if ($groupByType)
  3475. {
  3476. $sorted = array();
  3477. foreach ($whatsNewData as $type => $data)
  3478. {
  3479. $tmp = subval_sort($whatsNewData[$type], 'date');
  3480. $tmp = array_reverse($tmp);
  3481. $sorted[$type] = $tmp;
  3482. }
  3483. $whatsNewData = $sorted;
  3484. }
  3485. else
  3486. {
  3487. $whatsNewData = subval_sort($whatsNewData, 'date');
  3488. $whatsNewData = array_reverse($whatsNewData);
  3489. }
  3490. }
  3491. return $whatsNewData;
  3492. }
  3493. /**
  3494. * ImageCreateFromBMP
  3495. *
  3496. * @author DHKold
  3497. * @contact admin@dhkold.com
  3498. * @date The 15th of June 2005
  3499. * @version 2.0B
  3500. *
  3501. * @param string $filename
  3502. * @return void
  3503. */
  3504. function ImageCreateFromBMP ($filename)
  3505. {
  3506. if (! $f1 = fopen($filename,"rb")) return FALSE;
  3507. $FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1,14));
  3508. if ($FILE['file_type'] != 19778) return FALSE;
  3509. $BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel/Vcompression/Vsize_bitmap/Vhoriz_resolution/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1,40));
  3510. $BMP['colors'] = pow(2,$BMP['bits_per_pixel']);
  3511. if ($BMP['size_bitmap'] == 0) $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
  3512. $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8;
  3513. $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
  3514. $BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4);
  3515. $BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4);
  3516. $BMP['decal'] = 4-(4*$BMP['decal']);
  3517. if ($BMP['decal'] == 4) $BMP['decal'] = 0;
  3518. $PALETTE = array();
  3519. if ($BMP['colors'] < 16777216) {
  3520. $PALETTE = unpack('V'.$BMP['colors'], fread($f1,$BMP['colors']*4));
  3521. }
  3522. $IMG = fread($f1,$BMP['size_bitmap']);
  3523. $VIDE = chr(0);
  3524. $res = imagecreatetruecolor($BMP['width'],$BMP['height']);
  3525. $P = 0;
  3526. $Y = $BMP['height']-1;
  3527. while ($Y >= 0) {
  3528. $X=0;
  3529. while ($X < $BMP['width']) {
  3530. if ($BMP['bits_per_pixel'] == 24) {
  3531. $COLOR = unpack("V",substr($IMG,$P,3).$VIDE);
  3532. } elseif ($BMP['bits_per_pixel'] == 16) {
  3533. $COLOR = unpack("n",substr($IMG,$P,2));
  3534. $COLOR[1] = $PALETTE[$COLOR[1]+1];
  3535. } elseif ($BMP['bits_per_pixel'] == 8) {
  3536. $COLOR = unpack("n",$VIDE.substr($IMG,$P,1));
  3537. $COLOR[1] = $PALETTE[$COLOR[1]+1];
  3538. } elseif ($BMP['bits_per_pixel'] == 4) {
  3539. $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
  3540. if (($P*2)%2 == 0) $COLOR[1] = ($COLOR[1] >> 4) ; else $COLOR[1] = ($COLOR[1] & 0x0F);
  3541. $COLOR[1] = $PALETTE[$COLOR[1]+1];
  3542. } elseif ($BMP['bits_per_pixel'] == 1) {
  3543. $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
  3544. if (($P*8)%8 == 0) $COLOR[1] = $COLOR[1] >>7;
  3545. elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6;
  3546. elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5;
  3547. elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4;
  3548. elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3;
  3549. elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2;
  3550. elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1;
  3551. elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1);
  3552. $COLOR[1] = $PALETTE[$COLOR[1]+1];
  3553. } else {
  3554. return FALSE;
  3555. }
  3556. imagesetpixel($res,$X,$Y,$COLOR[1]);
  3557. $X++;
  3558. $P += $BMP['bytes_per_pixel'];
  3559. }
  3560. $Y--;
  3561. $P+=$BMP['decal'];
  3562. }
  3563. //Fermeture du fichier
  3564. fclose($f1);
  3565. return $res;
  3566. }
  3567. /**
  3568. * usingAdvancedUploader
  3569. *
  3570. * @param int $userid
  3571. * @return boolean
  3572. */
  3573. function usingAdvancedUploader ($userid)
  3574. {
  3575. $userid = (int)$userid;
  3576. $sql = "SELECT `advanced_upload`
  3577. FROM `fcms_user_settings`
  3578. WHERE `user` = '$userid'";
  3579. $result = mysql_query($sql);
  3580. if (!$result)
  3581. {
  3582. displaySqlError($sql, mysql_error());
  3583. return true;
  3584. }
  3585. $r = mysql_fetch_array($result);
  3586. if ($r['advanced_upload'] != 1)
  3587. {
  3588. return false;
  3589. }
  3590. return true;
  3591. }
  3592. /**
  3593. * usingAdvancedTagging
  3594. *
  3595. * @param int $userid
  3596. * @return boolean
  3597. */
  3598. function usingAdvancedTagging ($userid)
  3599. {
  3600. $userid = (int)$userid;
  3601. $sql = "SELECT `advanced_tagging`
  3602. FROM `fcms_user_settings`
  3603. WHERE `user` = '$userid'";
  3604. $result = mysql_query($sql);
  3605. if (!$result)
  3606. {
  3607. displaySqlError($sql, mysql_error());
  3608. return true;
  3609. }
  3610. $r = mysql_fetch_array($result);
  3611. if ($r['advanced_tagging'] == 1)
  3612. {
  3613. return true;
  3614. }
  3615. else
  3616. {
  3617. return false;
  3618. }
  3619. }
  3620. /**
  3621. * multi_array_key_exists
  3622. *
  3623. * @param $needle The key you want to check for
  3624. * @param $haystack The array you want to search
  3625. * @return boolean
  3626. */
  3627. function multi_array_key_exists ($needle, $haystack)
  3628. {
  3629. foreach ($haystack as $key => $value) {
  3630. if ($needle == $key) {
  3631. return true;
  3632. }
  3633. if (is_array($value)) {
  3634. if (multi_array_key_exists($needle, $value) == true) {
  3635. return true;
  3636. } else {
  3637. continue;
  3638. }
  3639. }
  3640. }
  3641. return false;
  3642. }
  3643. /**
  3644. * getLangName
  3645. *
  3646. * Given a gettext language code, it returns the translated
  3647. * language full name
  3648. *
  3649. * @param string $code
  3650. * @return string
  3651. */
  3652. function getLangName ($code)
  3653. {
  3654. switch($code) {
  3655. case 'cs_CZ':
  3656. return T_('Czech (Czech Republic)');
  3657. break;
  3658. case 'da_DK':
  3659. return T_('Danish (Denmark)');
  3660. break;
  3661. case 'de_DE':
  3662. return T_('German (Germany)');
  3663. break;
  3664. case 'en_US':
  3665. return T_('English (United States)');
  3666. break;
  3667. case 'es_ES':
  3668. return T_('Spanish (Spain)');
  3669. break;
  3670. case 'et':
  3671. return T_('Estonian');
  3672. break;
  3673. case 'fr_FR':
  3674. return T_('French (France)');
  3675. break;
  3676. case 'lv':
  3677. return T_('Latvian');
  3678. break;
  3679. case 'nl':
  3680. return T_('Dutch');
  3681. break;
  3682. case 'pt_BR':
  3683. return T_('Portuguese (Brazil)');
  3684. break;
  3685. case 'sk_SK':
  3686. return T_('Slovak');
  3687. break;
  3688. case 'zh_CN':
  3689. return T_('Chinese (China)');
  3690. break;
  3691. case 'x-wrap':
  3692. return T_('X Wrapped');
  3693. break;
  3694. default:
  3695. return $code;
  3696. break;
  3697. }
  3698. }
  3699. /**
  3700. * recursive_array_search
  3701. *
  3702. * @param string $needle
  3703. * @param string $haystack
  3704. * @return void
  3705. */
  3706. function recursive_array_search ($needle, $haystack)
  3707. {
  3708. foreach($haystack as $key=>$value) {
  3709. $current_key = $key;
  3710. if (
  3711. $needle === $value OR
  3712. (is_array($value) && recursive_array_search($needle,$value) !== false)
  3713. ) {
  3714. return $current_key;
  3715. }
  3716. }
  3717. return false;
  3718. }
  3719. /**
  3720. * printr
  3721. *
  3722. * Development only, wraps pre tags around print_r output.
  3723. *
  3724. * @param string $var
  3725. * @return void
  3726. */
  3727. function printr ($var)
  3728. {
  3729. echo '<pre>';
  3730. print_r($var);
  3731. echo '</pre>';
  3732. }
  3733. /**
  3734. * getBirthdayCategory
  3735. *
  3736. * returns the id of the category for bithday, if available
  3737. *
  3738. * @return int
  3739. */
  3740. function getBirthdayCategory ()
  3741. {
  3742. $sql = "SELECT `id`
  3743. FROM `fcms_category`
  3744. WHERE `type` = 'calendar'
  3745. AND `name` like 'Birthday'";
  3746. $result = mysql_query($sql);
  3747. if (!$result)
  3748. {
  3749. displaySqlError($sql, mysql_error());
  3750. return 1;
  3751. }
  3752. if (mysql_num_rows($result) > 0)
  3753. {
  3754. $r = mysql_fetch_array($result);
  3755. return $r['id'];
  3756. }
  3757. else
  3758. {
  3759. return 1;
  3760. }
  3761. }
  3762. /**
  3763. * getCalendarCategory
  3764. *
  3765. * Searches the db for a category that matches the given string
  3766. *
  3767. * @param string $cat
  3768. * @param boolean $caseSensitive
  3769. * @return int
  3770. */
  3771. function getCalendarCategory ($cat, $caseSensitive = false)
  3772. {
  3773. if ($caseSensitive)
  3774. {
  3775. $sql = "SELECT `id`
  3776. FROM `fcms_category`
  3777. WHERE `type` = 'calendar'
  3778. AND `name` like '$cat'";
  3779. }
  3780. else
  3781. {
  3782. $sql = "SELECT `id`
  3783. FROM `fcms_category`
  3784. WHERE `type` = 'calendar'
  3785. AND (
  3786. `name` like '".ucfirst($cat)."' OR
  3787. `name` like '".strtoupper($cat)."' OR
  3788. `name` like '".strtolower($cat)."' OR
  3789. `name` like '$cat'
  3790. )";
  3791. }
  3792. $result = mysql_query($sql);
  3793. if (!$result)
  3794. {
  3795. displaySqlError($sql, mysql_error());
  3796. return;
  3797. }
  3798. if (mysql_num_rows($result) > 0)
  3799. {
  3800. $r = mysql_fetch_assoc($result);
  3801. return $r['id'];
  3802. }
  3803. else
  3804. {
  3805. return 1;
  3806. }
  3807. }
  3808. /**
  3809. * getCurrentAvatar
  3810. *
  3811. * @param int $id User id
  3812. *
  3813. * @return string
  3814. */
  3815. function getCurrentAvatar ($id)
  3816. {
  3817. $id = (int)$id;
  3818. $sql = "SELECT `avatar`, `gravatar`
  3819. FROM `fcms_users`
  3820. WHERE `id` = '$id'";
  3821. $result = mysql_query($sql);
  3822. if (!$result)
  3823. {
  3824. displaySqlError($sql, mysql_error());
  3825. return getAvatarPath('no_avatar.jpg', NULL);
  3826. }
  3827. // No Avatar set
  3828. if (mysql_num_rows($result) <= 0)
  3829. {
  3830. return getAvatarPath('no_avatar.jpg', NULL);
  3831. }
  3832. $r = mysql_fetch_array($result);
  3833. return getAvatarPath($r['avatar'], $r['gravatar']);
  3834. }
  3835. /**
  3836. * getAvatarPath
  3837. *
  3838. * @param string $avatar no_avatar.jpg | gravatar | <filename>
  3839. * @param string $gravatar email address for gravatar or ''
  3840. *
  3841. * @return string
  3842. */
  3843. function getAvatarPath ($avatar, $gravatar)
  3844. {
  3845. // Protected uploads
  3846. if (defined('UPLOADS'))
  3847. {
  3848. switch ($avatar)
  3849. {
  3850. case 'no_avatar.jpg':
  3851. return URL_PREFIX.'file.php?a=no_avatar.jpg';
  3852. break;
  3853. case 'gravatar':
  3854. return 'http://www.gravatar.com/avatar.php?gravatar_id='.md5(strtolower($gravatar)).'&amp;s=80';
  3855. break;
  3856. default:
  3857. return URL_PREFIX.'file.php?a='.basename($avatar);
  3858. break;
  3859. }
  3860. }
  3861. // Unprotected uploads
  3862. switch ($avatar)
  3863. {
  3864. case 'no_avatar.jpg':
  3865. return URL_PREFIX.'uploads/avatar/no_avatar.jpg';
  3866. break;
  3867. case 'gravatar':
  3868. return 'http://www.gravatar.com/avatar.php?gravatar_id='.md5(strtolower($gravatar)).'&amp;s=80';
  3869. break;
  3870. default:
  3871. return URL_PREFIX.'uploads/avatar/'.basename($avatar);
  3872. break;
  3873. }
  3874. }
  3875. /**
  3876. * getTimezone
  3877. *
  3878. * @param int $user_id
  3879. *
  3880. * @return string
  3881. */
  3882. function getTimezone ($user_id)
  3883. {
  3884. $sql = "SELECT `timezone`
  3885. FROM `fcms_user_settings`
  3886. WHERE `user` = '$user_id'";
  3887. $result = mysql_query($sql);
  3888. if (!$result)
  3889. {
  3890. displaySqlError($sql, mysql_error());
  3891. die();
  3892. }
  3893. if (mysql_num_rows($result) <= 0)
  3894. {
  3895. displaySqlError($sql, mysql_error());
  3896. die();
  3897. }
  3898. $r = mysql_fetch_array($result);
  3899. return $r['timezone'];
  3900. }
  3901. /**
  3902. * subval_sort
  3903. *
  3904. * Sorts a multidimensional array by a key in the sub array.
  3905. *
  3906. * @param array $a
  3907. * @param string $subkey
  3908. *
  3909. * @return void
  3910. */
  3911. function subval_sort ($a, $subkey)
  3912. {
  3913. foreach($a as $k => $v)
  3914. {
  3915. $b[$k] = strtolower($v[$subkey]);
  3916. }
  3917. asort($b);
  3918. foreach($b as $key => $val)
  3919. {
  3920. $c[] = $a[$key];
  3921. }
  3922. return $c;
  3923. }
  3924. /**
  3925. * isRegistrationOn
  3926. *
  3927. * Checks the admin configuration to see if the site is allowing registration of new users.
  3928. *
  3929. * @return void
  3930. */
  3931. function isRegistrationOn ()
  3932. {
  3933. $sql = "SELECT `value` AS 'registration'
  3934. FROM `fcms_config`
  3935. WHERE `name` = 'registration'
  3936. LIMIT 1";
  3937. $result = mysql_query($sql);
  3938. if (!$result)
  3939. {
  3940. displaySqlError($sql, mysql_error());
  3941. return false;
  3942. }
  3943. $r = mysql_fetch_array($result);
  3944. $on = $r['registration'] == 1 ? true : false;
  3945. return $on;
  3946. }
  3947. /**
  3948. * getNextShareNavigationOrder
  3949. *
  3950. * Wrapper for getNextNavigationOrder.
  3951. * Returns the next order number for the Share navigation.
  3952. *
  3953. * @return void
  3954. */
  3955. function getNextShareNavigationOrder ()
  3956. {
  3957. return getNextNavigationOrder(4);
  3958. }
  3959. /**
  3960. * getNextAdminNavigationOrder
  3961. *
  3962. * Wrapper for getNextNavigationOrder.
  3963. * Returns the next order number for the Admininstration navigation.
  3964. *
  3965. * @return void
  3966. */
  3967. function getNextAdminNavigationOrder ()
  3968. {
  3969. return getNextNavigationOrder(6);
  3970. }
  3971. /**
  3972. * getNextNavigationOrder
  3973. *
  3974. * Returns the next order number for the given navigation column.
  3975. *
  3976. * @return void
  3977. */
  3978. function getNextNavigationOrder ($col)
  3979. {
  3980. $sql = "SELECT MAX(`order`) AS 'order'
  3981. FROM `fcms_navigation`
  3982. WHERE `col` = $col";
  3983. $result = mysql_query($sql);
  3984. if (!$result)
  3985. {
  3986. displaySqlError($sql, mysql_error());
  3987. return false;
  3988. }
  3989. if (mysql_num_rows($result) <= 0)
  3990. {
  3991. trigger_error('Navigation Order Missing or Corrupt');
  3992. die();
  3993. }
  3994. $r = mysql_fetch_assoc($result);
  3995. $next = $r['order'] + 1;
  3996. return $next;
  3997. }
  3998. /**
  3999. * getNumberOfPosts
  4000. *
  4001. * @param int $thread_id
  4002. * @return int
  4003. */
  4004. function getNumberOfPosts ($thread_id)
  4005. {
  4006. $sql = "SELECT count(*) AS c
  4007. FROM `fcms_board_posts`
  4008. WHERE `thread` = '".(int)$thread_id."'";
  4009. $result = mysql_query($sql);
  4010. if (!$result)
  4011. {
  4012. displaySqlError($sql, mysql_error());
  4013. return;
  4014. }
  4015. $row = mysql_fetch_assoc($result);
  4016. return (int)$row['c'];
  4017. }
  4018. /**
  4019. * postAsync
  4020. *
  4021. * Sends an asynchronous post without waiting for a response.
  4022. * Used to start "cron-like" jobs in the background.
  4023. *
  4024. * @param string $url
  4025. * @param array $params
  4026. *
  4027. * @return void
  4028. */
  4029. function postAsync ($url, $params)
  4030. {
  4031. foreach ($params as $key => &$val)
  4032. {
  4033. if (is_array($val))
  4034. {
  4035. $val = implode(',', $val);
  4036. }
  4037. $post_params[] = $key.'='.urlencode($val);
  4038. }
  4039. $post_string = implode('&', $post_params);
  4040. $parts = parse_url($url);
  4041. $fp = fsockopen($parts['host'], isset($parts['port'])?$parts['port']:80, $errno, $errstr, 30);
  4042. $out = "POST ".$parts['path']." HTTP/1.1\r\n";
  4043. $out .= "Host: ".$parts['host']."\r\n";
  4044. $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
  4045. $out .= "Content-Length: ".strlen($post_string)."\r\n";
  4046. $out .= "Connection: Close\r\n\r\n";
  4047. if (isset($post_string))
  4048. {
  4049. $out .= $post_string;
  4050. }
  4051. fwrite($fp, $out);
  4052. fclose($fp);
  4053. }
  4054. /**
  4055. * runningJob
  4056. *
  4057. * Is a cron job currently being run? If any errors occur, we say cron is running
  4058. * just to be safe.
  4059. *
  4060. * @return boolean
  4061. */
  4062. function runningJob ()
  4063. {
  4064. $sql = "SELECT `value`
  4065. FROM `fcms_config`
  4066. WHERE `name` = 'running_job'
  4067. AND `value` = '1'";
  4068. $result = mysql_query($sql);
  4069. if (!$result)
  4070. {
  4071. // Lets be safe and say a job is being run
  4072. return true;
  4073. }
  4074. if (mysql_num_rows($result) <= 0)
  4075. {
  4076. return false;
  4077. }
  4078. return true;
  4079. }
  4080. /**
  4081. * runJob
  4082. *
  4083. * Sets the db flag that a job has started. Returns true if worked, else false.
  4084. *
  4085. * @return boolean
  4086. */
  4087. function runJob ()
  4088. {
  4089. $sql = "UPDATE `fcms_config`
  4090. SET `value` = '1'
  4091. WHERE `name` = 'running_job'";
  4092. if (!mysql_query($sql))
  4093. {
  4094. return false;
  4095. }
  4096. // running_job config was missing, add it
  4097. if (mysql_affected_rows() <= 0)
  4098. {
  4099. $sql = "INSERT INTO `fcms_config` (`name`, `value`)
  4100. VALUES ('running_job', '1')";
  4101. if (!mysql_query($sql))
  4102. {
  4103. return false;
  4104. }
  4105. }
  4106. return true;
  4107. }
  4108. /**
  4109. * stopJob
  4110. *
  4111. * Turns off the job flag. Returns true if worked, else false.
  4112. *
  4113. * @return boolean
  4114. */
  4115. function stopJob ()
  4116. {
  4117. $sql = "UPDATE `fcms_config`
  4118. SET `value` = '0'
  4119. WHERE `name` = 'running_job'";
  4120. if (!mysql_query($sql))
  4121. {
  4122. return false;
  4123. }
  4124. if (mysql_affected_rows() <= 0)
  4125. {
  4126. return false;
  4127. }
  4128. return true;
  4129. }
  4130. /**
  4131. * getExistingYouTubeIds
  4132. *
  4133. * @return array
  4134. */
  4135. function getExistingYouTubeIds ()
  4136. {
  4137. $ids = array();
  4138. $sql = "SELECT `source_id`
  4139. FROM `fcms_video`
  4140. WHERE `source` = 'youtube'";
  4141. $result = mysql_query($sql);
  4142. if (!$result)
  4143. {
  4144. displaySqlError($sql, mysql_error());
  4145. return $ids;
  4146. }
  4147. while ($row = mysql_fetch_assoc($result))
  4148. {
  4149. $ids[$row['source_id']] = 1;
  4150. }
  4151. return $ids;
  4152. }
  4153. /**
  4154. * getExistingInstagramIds
  4155. *
  4156. * @return array
  4157. */
  4158. function getExistingInstagramIds ()
  4159. {
  4160. $ids = array();
  4161. $sql = "SELECT `source_id`
  4162. FROM `fcms_gallery_external_photo`";
  4163. $result = mysql_query($sql);
  4164. if (!$result)
  4165. {
  4166. displaySqlError($sql, mysql_error());
  4167. return $ids;
  4168. }
  4169. while ($row = mysql_fetch_assoc($result))
  4170. {
  4171. $ids[$row['source_id']] = 1;
  4172. }
  4173. return $ids;
  4174. }
  4175. /**
  4176. * userConnectedSocialMedia
  4177. *
  4178. * @param int $userId
  4179. *
  4180. * @return boolean
  4181. */
  4182. function userConnectedSocialMedia ($userId)
  4183. {
  4184. // Get Social Media data
  4185. $facebook = getUserFacebookAccessToken($userId);
  4186. $foursquare = getFoursquareUserData($userId);
  4187. $youtube = getYouTubeUserData($userId);
  4188. // Facebook
  4189. if (!empty($facebook))
  4190. {
  4191. return true;
  4192. }
  4193. // Foursquare
  4194. if (!empty($foursquare['fs_user_id']) && !empty($foursquare['fs_access_token']))
  4195. {
  4196. return true;
  4197. }
  4198. // YouTube
  4199. if (!empty($youtube['youtube_session_token']))
  4200. {
  4201. return true;
  4202. }
  4203. return false;
  4204. }
  4205. /**
  4206. * delete_dir
  4207. *
  4208. * Deletes a directory and everything in it.
  4209. *
  4210. * @param string $directory
  4211. *
  4212. * @return void
  4213. */
  4214. function delete_dir ($directory)
  4215. {
  4216. // removes trailing slash
  4217. if (substr($directory, -1) == '/')
  4218. {
  4219. $directory = substr($directory, 0, -1);
  4220. }
  4221. if (!file_exists($directory) || !is_dir($directory))
  4222. {
  4223. return false;
  4224. }
  4225. elseif (!is_readable($directory))
  4226. {
  4227. return false;
  4228. }
  4229. $handle = opendir($directory);
  4230. while (false !== ($item = readdir($handle)))
  4231. {
  4232. // skip . and ..
  4233. if ($item != '.' && $item != '..')
  4234. {
  4235. $path = $directory.'/'.$item;
  4236. // dirctory
  4237. if (is_dir($path))
  4238. {
  4239. delete_dir($path);
  4240. }
  4241. else
  4242. {
  4243. unlink($path);
  4244. }
  4245. }
  4246. }
  4247. closedir($handle);
  4248. // this dir is empty, delete it
  4249. if (!rmdir($directory))
  4250. {
  4251. return false;
  4252. }
  4253. return true;
  4254. }
  4255. /**
  4256. * buildCountryList
  4257. *
  4258. * Builds an array of country ISO 3166 names keyed by alpha-2 codes from the country.txt file.
  4259. * This text file is from http://www.iso.org/iso/country_codes/iso_3166_code_lists.htm.
  4260. *
  4261. * @return array
  4262. */
  4263. function buildCountryList ()
  4264. {
  4265. $countries = array();
  4266. $lines = @file('inc/country.txt');
  4267. if ($lines === false)
  4268. {
  4269. echo '<div class="error-alert">'.T_('Could not read inc/country.txt file.').'</div>';
  4270. return $countries;
  4271. }
  4272. foreach($lines as $line)
  4273. {
  4274. $country = explode(";", $line);
  4275. $country[0] = trim($country[0]);
  4276. $country[1] = trim($country[1]);
  4277. $countries[$country[1]] = $country[0];
  4278. }
  4279. return $countries;
  4280. }
  4281. /**
  4282. * getDefaultCountry
  4283. *
  4284. * @return void
  4285. */
  4286. function getDefaultCountry ()
  4287. {
  4288. $sql = "SELECT `value`
  4289. FROM `fcms_config`
  4290. WHERE `name` = 'country'";
  4291. $result = mysql_query($sql);
  4292. if (!$result)
  4293. {
  4294. return 'US';
  4295. }
  4296. $r = mysql_fetch_array($result);
  4297. return $r['value'];
  4298. }
  4299. /**
  4300. * getAddRemoveTaggedMembers
  4301. *
  4302. * @param array $tagged
  4303. * @param array $prev
  4304. *
  4305. * @return array
  4306. */
  4307. function getAddRemoveTaggedMembers ($tagged = null, $prev = null)
  4308. {
  4309. // Nothing to add or remove
  4310. if (is_null($tagged) && is_null($prev))
  4311. {
  4312. return true;
  4313. }
  4314. if (!is_array($tagged) && !is_array($prev))
  4315. {
  4316. return false;
  4317. }
  4318. $add = array();
  4319. $remove = array();
  4320. // Tagging new users on photo with already tagged users
  4321. if (is_array($tagged) && is_array($prev))
  4322. {
  4323. // Find all additions
  4324. foreach ($tagged as $id)
  4325. {
  4326. if (!in_array($id, $prev))
  4327. {
  4328. $add[] = $id;
  4329. }
  4330. }
  4331. // Find all removals
  4332. foreach ($prev as $id)
  4333. {
  4334. if (!in_array($id, $tagged))
  4335. {
  4336. $remove[] = $id;
  4337. }
  4338. }
  4339. }
  4340. // No tagged members now, but did have some previously
  4341. elseif (!is_array($tagged) && is_array($prev))
  4342. {
  4343. $remove = $prev;
  4344. }
  4345. // Tagging new users, didn't have any previously
  4346. elseif (is_array($tagged) && !is_array($prev))
  4347. {
  4348. $add = $tagged;
  4349. }
  4350. return array('add' => $add, 'remove' => $remove);
  4351. }
  4352. /**
  4353. * getMembersNeedingActivation
  4354. *
  4355. * @return void
  4356. */
  4357. function getMembersNeedingActivation ()
  4358. {
  4359. $members = array();
  4360. $sql = "SELECT `id`, `fname`, `lname`
  4361. FROM `fcms_users`
  4362. WHERE `activated` != 1
  4363. AND `password` != 'NONMEMBER'
  4364. ORDER BY `joindate` DESC";
  4365. $result = mysql_query($sql);
  4366. if (!$result)
  4367. {
  4368. displaySqlError($sql, mysql_error());
  4369. return false;
  4370. }
  4371. while ($r = mysql_fetch_assoc($result))
  4372. {
  4373. $members[$r['id']] = $r['fname'].' '.$r['lname'];
  4374. }
  4375. return $members;
  4376. }
  4377. /**
  4378. * getCalendarWeekStart
  4379. *
  4380. * Returns the day, the calendar is set to start on.
  4381. *
  4382. * 0 - 6, with 0 being Sunday and 6 being Saturday.
  4383. *
  4384. * @return int
  4385. */
  4386. function getCalendarWeekStart ()
  4387. {
  4388. $sql = "SELECT `value`
  4389. FROM `fcms_config`
  4390. WHERE `name` = 'start_week'";
  4391. $result = mysql_query($sql);
  4392. if (!$result)
  4393. {
  4394. return '0';
  4395. }
  4396. if (mysql_num_rows($result) <= 0)
  4397. {
  4398. return '0';
  4399. }
  4400. $r = mysql_fetch_array($result);
  4401. return (int)$r['value'];
  4402. }
  4403. /**
  4404. * getPage
  4405. *
  4406. * Returns the page number that was requested, defaults to 1.
  4407. *
  4408. * @return int
  4409. */
  4410. function getPage ()
  4411. {
  4412. $page = 1;
  4413. if (isset($_GET['page']))
  4414. {
  4415. $page = (int)$_GET['page'];
  4416. }
  4417. return $page;
  4418. }
  4419. /**
  4420. * shortenString
  4421. *
  4422. * @param string $string
  4423. * @param int $maxLength
  4424. * @param string $end
  4425. *
  4426. * @return string
  4427. */
  4428. function shortenString ($string, $maxLength = 100, $end = '')
  4429. {
  4430. $endLength = 0;
  4431. if ($end != '')
  4432. {
  4433. $endLength = strlen($end);
  4434. }
  4435. if (strlen($string) > $maxLength)
  4436. {
  4437. $string = substr($string, 0, $maxLength - $endLength) . $end;
  4438. }
  4439. return $string;
  4440. }
  4441. /**
  4442. * getUserInstagramCategory
  4443. *
  4444. * Will return the category id for the instagram category.
  4445. * If one doesn't exist yet, will create it and return the id.
  4446. *
  4447. * @param int $userId
  4448. *
  4449. * @return void
  4450. */
  4451. function getUserInstagramCategory ($userId)
  4452. {
  4453. $userId = (int)$userId;
  4454. $sql = "SELECT `id`
  4455. FROM `fcms_category`
  4456. WHERE `name` = 'Instagram'
  4457. AND `user` = '$userId'";
  4458. $result = mysql_query($sql);
  4459. if (!$result)
  4460. {
  4461. // TODO
  4462. return;
  4463. }
  4464. if (mysql_num_rows($result) <= 0)
  4465. {
  4466. // Create a new one
  4467. $sql = "INSERT INTO `fcms_category`
  4468. (`name`, `type`, `user`, `date`)
  4469. VALUES
  4470. ('Instagram', 'gallery', '$userId', NOW())";
  4471. $result = mysql_query($sql);
  4472. if (!$result)
  4473. {
  4474. // TODO
  4475. return;
  4476. }
  4477. return mysql_insert_id();
  4478. }
  4479. $r = mysql_fetch_array($result);
  4480. return $r['id'];
  4481. }
  4482. /**
  4483. * getUploadsAbsolutePath
  4484. *
  4485. * Returns the absolute path to the uploads directory.
  4486. *
  4487. * @return string
  4488. */
  4489. function getUploadsAbsolutePath ()
  4490. {
  4491. if (defined('UPLOADS'))
  4492. {
  4493. return UPLOADS;
  4494. }
  4495. return ROOT.'uploads/';
  4496. }