/inc/utils.php
PHP | 5099 lines | 3552 code | 596 blank | 951 comment | 356 complexity | c32ed7a3493c61d70538d47095b28625 MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- // Smileys
- $smiley_array = array(':smile:', ':none:', ':)', '=)', ':wink:', ';)', ':tongue:', ':biggrin:', ':sad:', ':(', ':sick:', ':cry:', ':shocked:', ':cool:', ':sleep:', 'zzz', ':angry:', ':mad:', ':embarrassed:', ':shy:',
- ':rolleyes:', ':nervous:', ':doh:', ':love:', ':please:', ':1please:', ':hrmm:', ':quiet:', ':clap:', ':twitch:', ':blah:', ':bored:', ':crazy:', ':excited:', ':noidea:', ':disappointed:', ':banghead:',
- ':dance:', ':laughat:', ':ninja:', ':pirate:', ':thumbup:', ':thumbdown:', ':twocents:'
- );
- $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',
- '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',
- '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',
- 'thumbdown.gif', 'twocents.gif'
- );
- /**
- * getEmailHeaders
- *
- * @param string $name
- * @param string $email
- *
- * @return string
- */
- function getEmailHeaders ($name = '', $email = '')
- {
- if (empty($name)) {
- $name = getSiteName();
- }
- if (empty($email)) {
- $email = getContactEmail();
- }
- return "From: $name <$email>\r\n" .
- "Reply-To: $email\r\n" .
- "Content-Type: text/plain; charset=UTF-8;\r\n" .
- "MIME-Version: 1.0\r\n" .
- "X-Mailer: PHP/" . phpversion();
- }
- /**
- * getTheme
- *
- * @param int $userid
- *
- * @return void
- */
- function getTheme ($userid = 0)
- {
- if (empty($userid))
- {
- return UI."themes/default/";
- }
- else
- {
- $userid = (int)$userid;
- $sql = "SELECT `theme`
- FROM `fcms_user_settings`
- WHERE `user` = '$userid'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return UI."themes/default/";
- }
- $r = mysql_fetch_array($result);
- // old versions of fcms may still list .css in theme name
- $pos = strpos($r['theme'], '.css');
- if ($pos === false)
- {
- return UI."themes/".basename($r['theme'])."/";
- }
- else
- {
- return UI."themes/".substr($r['theme'], 0, $pos)."/";
- }
- }
- }
- /**
- * getThemeList
- *
- * Returns an array of available themes.
- *
- * @return array
- */
- function getThemeList ()
- {
- $dir = THEMES;
- $themes = array();
- if (is_dir($dir))
- {
- if ($dh = opendir($dir))
- {
- while (($file = readdir($dh)) !== false)
- {
- // Skip files
- if (filetype($dir.$file) !== "dir")
- {
- continue;
- }
- // Skip directories that start with a period
- if ($file[0] === '.')
- {
- continue;
- }
- $themes[] = $file;
- }
- closedir($dh);
- sort($themes);
- }
- }
- return $themes;
- }
- /*
- * getUserDisplayName
- *
- * Gets the user's name, displayed how they set in there settings, unless display option is set
- * which will overwrite the user's settings.
- *
- * @param int $userid
- * @param int $display
- * @param boolean $isMember
- * @return string
- */
- function getUserDisplayName ($userid, $display = 0, $isMember = true)
- {
- $userid = (int)$userid;
- if ($isMember)
- {
- $sql = "SELECT u.`fname`, u.`lname`, u.`username`, s.`displayname`
- FROM `fcms_users` AS u, `fcms_user_settings` AS s
- WHERE u.`id` = '$userid'
- AND u.`id` = s.`user`";
- }
- else
- {
- $sql = "SELECT `fname`, `lname`, `username`
- FROM `fcms_users`
- WHERE `id` = '$userid' ";
- }
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '';
- }
- $r = mysql_fetch_assoc($result);
- // Do we want user's settings or overriding it?
- if ($display < 1)
- {
- $displayname = $r['displayname'];
- }
- else
- {
- $displayname = $display;
- }
- $ret = '';
- switch($displayname)
- {
- case '1':
- $ret = cleanOutput($r['fname']);
- break;
- case '2':
- $ret = cleanOutput($r['fname']).' '.cleanOutput($r['lname']);
- break;
- case '3':
- $ret = cleanOutput($r['username']);
- break;
- default:
- $ret = cleanOutput($r['username']);
- break;
- }
- return $ret;
- }
- /**
- * getPMCount
- *
- * Returns a string consisting of the user's new pm count in ()'s
- *
- * @return string
- */
- function getPMCount ()
- {
- // Count was calculated during getUserNotifications()
- if (isset($_SESSION['private_messages']))
- {
- $count = $_SESSION['private_messages'];
- }
- else
- {
- $sql = "SELECT * FROM `fcms_privatemsg`
- WHERE `read` < 1
- AND `to` = '".(int)$_SESSION['login_id']."'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '';
- }
- $count = mysql_num_rows($result);
- }
- if ($count > 0)
- {
- return " ($count)";
- }
- return '';
- }
- /**
- * getNotificationCount
- *
- * Returns a string consisting of the user's unread notification count in ()'s
- *
- * @return string
- */
- function getNotificationCount ()
- {
- // Count was calculated during getUserNotifications()
- if (isset($_SESSION['notifications']))
- {
- $count = $_SESSION['notifications'];
- }
- else
- {
- $sql = "SELECT `id` FROM `fcms_notification`
- WHERE `read` < 1
- AND `user` = '".(int)$_SESSION['login_id']."'
- AND `created_id` != '".(int)$_SESSION['login_id']."'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '';
- }
- $count = mysql_num_rows($result);
- }
- if ($count > 0)
- {
- return " ($count)";
- }
- return '';
- }
- /**
- * getUserEmail
- *
- * @param string $userid
- * @return string
- */
- function getUserEmail ($userid)
- {
- $userid = (int)$userid;
- $sql = "SELECT `email`
- FROM `fcms_users`
- WHERE `id` = '$userid'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 'nothing@mail.com';
- }
- $r = mysql_fetch_assoc($result);
- return $r['email'];
- }
- /**
- * getDefaultNavUrl
- *
- * Gets the url for the 'Share' default link
- *
- * @return string
- */
- function getDefaultNavUrl ()
- {
- $sql = "SELECT `link`
- FROM `fcms_navigation`
- WHERE `col` = 4
- AND `order` = 1";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 'gallery/index.php';
- }
- $r = mysql_fetch_assoc($result);
- return getPluginUrl($r['link']);
- }
- /**
- * getNavLinks
- *
- * Gets the links and order for all the navigation.
- * Creates a multi-dimensional array of the nav, where
- * the first array is the navigation tabs and the second
- * is the links in those tabs.
- *
- * Home
- * My Stuff
- * - Profile
- * - Settings
- * - Private Messages
- * - Notifications
- * Communicate
- * - Message Board
- * - Family News
- * - Prayer Concerns
- * Share
- * - Photo Gallery
- * - Video Gallery
- * - Address Book
- * - Calendar
- * - Recipes
- * - Family Tree
- * - Documents
- * - Where Is Everyone
- * Misc.
- * - Members
- * - Contact Webmaster
- * - Help
- * Administration
- *
- * @return array
- */
- function getNavLinks ()
- {
- $ret = array();
- $sql = "SELECT `link`, `col`
- FROM `fcms_navigation`
- WHERE `order` != 0
- AND `col` != 6
- ORDER BY `col`, `order`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return $ret;
- }
- $currentUserId = (int)$_SESSION['login_id'];
- // Add links
- while ($r = mysql_fetch_array($result))
- {
- $ret['my-stuff'] = T_('My Stuff');
- // Notifications
- $notifications = getUserNotifications($currentUserId);
- if ($notifications > 0)
- {
- $ret['my-stuff'] = '<b>'.$notifications.'</b>'.$ret['my-stuff'];
- }
- $ret[$r['col']][] = array(
- 'url' => getPluginUrl($r['link']),
- 'text' => getPluginName($r['link']),
- );
- }
- // Add admin
- if (checkAccess($currentUserId) <= 2)
- {
- $ret[6][] = array(
- 'url' => 'index.php',
- 'text' => T_('Administration')
- );
- }
- return $ret;
- }
- /**
- * getAdminNavLinks
- *
- * @return void
- */
- function getAdminNavLinks ()
- {
- $ret = array();
- $sql = "SELECT `link`, `col`
- FROM `fcms_navigation`
- WHERE `col` = 6
- ORDER BY `order`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return $ret;
- }
- while ($r = mysql_fetch_array($result))
- {
- $ret[$r['link']] = array(
- 'url' => getPluginUrl($r['link']),
- 'text' => getPluginName($r['link']),
- );
- }
- return $ret;
- }
- /**
- * getPluginName
- *
- * Given the name of the section from the db, returns the translated text
- *
- * @param string $section
- * @return string
- */
- function getPluginName ($section)
- {
- switch ($section) {
- case 'admin_awards':
- return T_('Awards');
- break;
- case 'admin_configuration':
- return T_('Configuration');
- break;
- case 'admin_facebook':
- return 'Facebook';
- break;
- case 'admin_foursquare':
- return 'Foursquare';
- break;
- case 'admin_instagram':
- return 'Instagram';
- break;
- case 'admin_members':
- return T_('Members');
- break;
- case 'admin_photogallery':
- return T_('Photo Gallery');
- break;
- case 'admin_polls':
- return T_('Polls');
- break;
- case 'admin_scheduler':
- return T_('Scheduler');
- break;
- case 'admin_upgrade':
- return T_('Upgrade');
- break;
- case 'admin_vimeo':
- return 'Vimeo';
- break;
- case 'admin_whereiseveryone':
- return 'Foursquare';
- break;
- case 'admin_youtube':
- return 'YouTube';
- break;
- case 'addressbook':
- return T_('Address Book');
- break;
- case 'calendar':
- return T_('Calendar');
- break;
- case 'chat':
- return T_('Chat');
- break;
- case 'contact':
- return T_('Contact Webmaster');
- break;
- case 'documents':
- return T_('Documents');
- break;
- case 'familynews':
- return T_('Family News');
- break;
- case 'help':
- return T_('Help');
- break;
- case 'messageboard':
- return T_('Message Board');
- break;
- case 'members':
- return T_('Members');
- break;
- case 'notification':
- return T_('Notifications').getNotificationCount();
- break;
- case 'photogallery':
- return T_('Photo Gallery');
- break;
- case 'prayers':
- return T_('Prayers');
- break;
- case 'profile':
- return T_('Profile');
- break;
- case 'pm':
- return T_('Private Messages').getPMCount();
- break;
- case 'recipes':
- return T_('Recipes');
- break;
- case 'settings':
- return T_('Settings');
- break;
- case 'tree':
- return T_('Family Tree');
- break;
- case 'videogallery':
- return T_('Video Gallery');
- break;
- case 'whereiseveryone':
- return T_('Where Is Everyone');
- break;
- default:
- return 'error';
- break;
- }
- }
- /**
- * getPluginUrl
- *
- * Given the name of the section from the db, returns the url for that section
- *
- * @param string $section
- * @return string
- */
- function getPluginUrl ($section)
- {
- switch ($section) {
- case 'admin_awards':
- return 'admin/awards.php';
- break;
- case 'admin_configuration':
- return 'admin/config.php';
- break;
- case 'admin_facebook':
- return 'admin/facebook.php';
- break;
- case 'admin_foursquare':
- return 'admin/foursquare.php';
- break;
- case 'admin_instagram':
- return 'admin/instagram.php';
- break;
- case 'admin_members':
- return 'admin/members.php';
- break;
- case 'admin_photogallery':
- return 'admin/gallery.php';
- break;
- case 'admin_polls':
- return 'admin/polls.php';
- break;
- case 'admin_scheduler':
- return 'admin/scheduler.php';
- break;
- case 'admin_upgrade':
- return 'admin/upgrade.php';
- break;
- case 'admin_vimeo':
- return 'admin/vimeo.php';
- break;
- case 'admin_whereiseveryone':
- return 'admin/foursquare.php';
- break;
- case 'admin_youtube':
- return 'admin/youtube.php';
- break;
- case 'addressbook':
- return 'addressbook.php';
- break;
- case 'calendar':
- return 'calendar.php';
- break;
- case 'chat':
- return 'inc/chat/index.php';
- break;
- case 'contact':
- return 'contact.php';
- break;
- case 'documents':
- return 'documents.php';
- break;
- case 'familynews':
- return 'familynews.php';
- break;
- case 'help':
- return 'help.php';
- break;
- case 'messageboard':
- return 'messageboard.php';
- break;
- case 'members':
- return 'members.php';
- break;
- case 'notification':
- return 'notifications.php';
- break;
- case 'photogallery':
- return 'gallery/index.php';
- break;
- case 'prayers':
- return 'prayers.php';
- break;
- case 'profile':
- return 'profile.php';
- break;
- case 'pm':
- return 'privatemsg.php';
- break;
- case 'recipes':
- return 'recipes.php';
- break;
- case 'settings':
- return 'settings.php';
- break;
- case 'tree':
- return 'familytree.php';
- break;
- case 'videogallery':
- return 'video.php';
- break;
- case 'whereiseveryone':
- return 'whereiseveryone.php';
- break;
- default:
- return 'home.php';
- break;
- }
- }
- /**
- * getPluginDescription
- *
- * Given the name of the plugin from the db, returns the description.
- *
- * @param string$plugin
- *
- * @return string
- */
- function getPluginDescription ($plugin)
- {
- switch ($plugin) {
- case 'admin_awards':
- return T_('Awards');
- break;
- case 'admin_configuration':
- return T_('Configuration');
- break;
- case 'admin_facebook':
- return T_('Facebook');
- break;
- case 'admin_foursquare':
- return T_('Foursquare');
- break;
- case 'admin_members':
- return T_('Members');
- break;
- case 'admin_photogallery':
- return T_('Photo Gallery');
- break;
- case 'admin_polls':
- return T_('Polls');
- break;
- case 'admin_scheduler':
- return T_('Scheduler');
- break;
- case 'admin_upgrade':
- return T_('Upgrade');
- break;
- case 'admin_vimeo':
- return T_('Vimeo');
- break;
- case 'admin_whereiseveryone':
- return T_('Foursquare');
- break;
- case 'admin_youtube':
- return T_('YouTube');
- break;
- case 'addressbook':
- return T_('Allows members to share Address information.');
- break;
- case 'calendar':
- return T_('Allows members to share events and send invitations.');
- break;
- case 'chat':
- return T_('Chat');
- break;
- case 'contact':
- return T_('Contact Webmaster');
- break;
- case 'documents':
- return T_('Allows members to share files.');
- break;
- case 'familynews':
- return T_('Allows members to create a family blog.');
- break;
- case 'help':
- return T_('Help');
- break;
- case 'messageboard':
- return T_('Allows members to communicate with each other.');
- break;
- case 'members':
- return T_('Members');
- break;
- case 'photogallery':
- return T_('Allows members to share photos.');
- break;
- case 'prayers':
- return T_('Allows members to share prayer concerns.');
- break;
- case 'profile':
- return T_('Profile');
- break;
- case 'pm':
- return T_('Private Messages');
- break;
- case 'recipes':
- return T_('Allows members to share recipes.');
- break;
- case 'settings':
- return T_('Settings');
- break;
- case 'tree':
- return T_('Allows members to create a family tree.');
- break;
- case 'videogallery':
- return T_('Allows members to share videos.');
- break;
- case 'whereiseveryone':
- return T_('Allows members to share Foursquare checkins.');
- break;
- default:
- return 'error';
- break;
- }
- }
- /**
- * getUserNotifications
- *
- * @param int $userId
- *
- * @return mixed Returns # of notifications or false.
- */
- function getUserNotifications ($userId)
- {
- $notifications = 0;
- $_SESSION['private_messages'] = $notifications;
- // Private Messages
- $sql = "SELECT `id` FROM `fcms_privatemsg`
- WHERE `read` < 1
- AND `to` = '$userId'";
- $result = mysql_query($sql);
- if (!$result)
- {
- logError(__FILE__.' ['.__LINE__.'] Could not get pm notifications.');
- return false;
- }
- if (mysql_num_rows($result) > 0)
- {
- $notifications += mysql_num_rows($result);
- $_SESSION['private_messages'] = $notifications;
- }
- // Tagged notifications
- $sql = "SELECT `id` FROM `fcms_notification`
- WHERE `read` < 1
- AND `user` = '$userId'
- AND `created_id` != '$userId'";
- $result = mysql_query($sql);
- if (!$result)
- {
- logError(__FILE__.' ['.__LINE__.'] Could not get tagged notifications.');
- return false;
- }
- if (mysql_num_rows($result) > 0)
- {
- $tagged = mysql_num_rows($result);
- $notifications += $tagged;
- $_SESSION['notifications'] = $tagged;
- }
- return $notifications;
- }
- /**
- * displayNewPM
- *
- * @param int $userid
- *
- * @return void
- */
- function displayNewPM ($userid)
- {
- $userid = (int)$userid;
- $sql = "SELECT `id`
- FROM `fcms_privatemsg`
- WHERE `to` = '$userid' AND `read` < 1";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return ' ';
- }
- if (mysql_num_rows($result) > 0)
- {
- echo '<a href="'.URL_PREFIX.'privatemsg.php" class="new_pm">'.T_('New PM').'</a> ';
- }
- else
- {
- echo ' ';
- }
- }
- /**
- * checkAccess
- *
- * Returns the access level as a number for the given user.
- *
- * @param int $userid
- * @return int
- */
- function checkAccess ($userid)
- {
- $userid = (int)$userid;
- $sql = "SELECT `access`
- FROM `fcms_users`
- WHERE `id` = '$userid'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '10';
- }
- if (mysql_num_rows($result) <= 0)
- {
- return '10'; // guest
- }
- $r = mysql_fetch_array($result);
- return $r['access'];
- }
- /**
- * getAccessLevel
- *
- * Returns the access level name for the given user.
- *
- * @param int $userid
- * @return string
- */
- function getAccessLevel ($userid)
- {
- $access = checkAccess($userid);
- $accessLevel = T_('Member');
- switch ($access) {
- case 1:
- $accessLevel = T_('Admin');
- break;
- case 2:
- $accessLevel = T_('Helper');
- break;
- case 3:
- $accessLevel = T_('Member');
- break;
- case 4:
- $accessLevel = T_('Non-Photographer');
- break;
- case 5:
- $accessLevel = T_('Non-Poster');
- break;
- case 6:
- $accessLevel = T_('Commenter');
- break;
- case 7:
- $accessLevel = T_('Poster');
- break;
- case 8:
- $accessLevel = T_('Photographer');
- break;
- case 9:
- $accessLevel = T_('Blogger');
- break;
- case 10:
- $accessLevel = T_('Guest');
- break;
- case 11:
- $accessLevel = T_('Non-editable Member');
- break;
- }
- return $accessLevel;
- }
- /**
- * parse
- *
- * @param string $data
- *
- * @return void
- */
- function parse ($data)
- {
- $data = htmlentities($data, ENT_COMPAT, 'UTF-8');
- $data = parse_smilies($data);
- $data = parse_bbcodes($data);
- $data = nl2br_nospaces($data);
- return $data;
- }
- /**
- * parse_bbcodes
- *
- * @param string $data
- * @return void
- */
- function parse_bbcodes ($data)
- {
- $search = getBBCodeList();
- $replace = array(
- '<ins>$1</ins>',
- '<del>$1</del>',
- '<h1>$1</h1>',
- '<h2>$1</h2>',
- '<h3>$1</h3>',
- '<h4>$1</h4>',
- '<h5>$1</h5>',
- '<h6>$1</h6>',
- '<b>$1</b>',
- '<i>$1</i>',
- '<u>$1</u>',
- '<a href="$1">$2</a>',
- '<a href="$1">$1</a>',
- '<div style="text-align: $1;">$2</div>',
- '<img src="$1"/>',
- '<img src="$1"/>',
- '<a href="mailto:$1">$2</a>',
- '<a href="mailto:$1">$1</a>',
- '<span style="font-family: $1;">$2</span>',
- '<span style="font-size: $1;">$2</span>',
- '<span style="color: $1;">$2</span>',
- '<span>$1</span>',
- '<span class="$1">$2</span>',
- '<blockquote>$1</blockquote>',
- 'unhtmlentities("\\1")'
- );
- $data = preg_replace ($search, $replace, $data);
- return $data;
- }
- /**
- * removeBBCode
- *
- * @param string $str
- * @return string
- */
- function removeBBCode ($str)
- {
- $search = getBBCodeList();
- $replace = array(
- '$1', // ins
- '$1', // del
- '$1', // h1
- '$1', // h2
- '$1', // h3
- '$1', // h4
- '$1', // h5
- '$1', // h6
- '$1', // b
- '$1', // i
- '$1', // u
- '$2', // url
- '$1', // url
- '$2', // align
- '', // img
- '', // img
- '$2', // mail
- '$1', // mail
- '$2', // font
- '$2', // size
- '$2', // color
- '$1', // span
- '$2', // span
- '$1', // quote
- '', // video
- );
- return preg_replace($search, $replace, stripslashes($str));
- }
- /**
- * getBBCodeList
- *
- * Returns an array of regex for the current list of BBCodes that FCMS supports.
- *
- * @return array
- */
- function getBBCodeList ()
- {
- return array(
- '/\[ins\](.*?)\[\/ins\]/is',
- '/\[del\](.*?)\[\/del\]/is',
- '/\[h1\](.*?)\[\/h1\]/is',
- '/\[h2\](.*?)\[\/h2\]/is',
- '/\[h3\](.*?)\[\/h3\]/is',
- '/\[h4\](.*?)\[\/h4\]/is',
- '/\[h5\](.*?)\[\/h5\]/is',
- '/\[h6\](.*?)\[\/h6\]/is',
- '/\[b\](.*?)\[\/b\]/is',
- '/\[i\](.*?)\[\/i\]/is',
- '/\[u\](.*?)\[\/u\]/is',
- '/\[url\=(.*?)\](.*?)\[\/url\]/is',
- '/\[url\](.*?)\[\/url\]/is',
- '/\[align\=(left|center|right)\](.*?)\[\/align\]/is',
- '/\[img\=(.*?)\]/is',
- '/\[img\](.*?)\[\/img\]/is',
- '/\[mail\=(.*?)\](.*?)\[\/mail\]/is',
- '/\[mail\](.*?)\[\/mail\]/is',
- '/\[font\=(.*?)\](.*?)\[\/font\]/is',
- '/\[size\=(.*?)\](.*?)\[\/size\]/is',
- '/\[color\=(.*?)\](.*?)\[\/color\]/is',
- '/\[span\](.*?)\[\/span\]/is',
- '/\[span\=(.*?)\](.*?)\[\/span\]/is',
- '/\[quote\](.*?)\[\/quote\]/is',
- '/\[video\](.*?)\[\/video\]/ise'
- );
- }
- /**
- * parse_smilies
- *
- * @param string $data
- *
- * @return void
- */
- function parse_smilies ($data)
- {
- global $smiley_array, $smiley_file_array;
- $i = 0;
- while($i < count($smiley_array))
- {
- $data = str_replace(
- $smiley_array[$i],
- '<img src="'.URL_PREFIX.'ui/smileys/'.$smiley_file_array[$i].'" alt="'.$smiley_array[$i].'"/>',
- $data
- );
- $i++;
- }
- return $data;
- }
- /**
- * nl2br_nospaces
- *
- * @param string $string
- * @return void
- */
- function nl2br_nospaces ($string)
- {
- $string = str_replace(array("\r\n", "\r", "\n"), "<br/>", $string);
- return $string;
- }
- // Used for PHP 4 and less
- if (!function_exists('stripos')) {
- function stripos($haystack, $needle, $offset = 0) {
- return strpos(strtolower($haystack), strtolower($needle), $offset);
- }
- }
- // If php is compiled without mbstring support
- if (!function_exists('mb_detect_encoding')) {
- function mb_detect_encoding($text) {
- return 'UTF-8';
- }
- function mb_convert_encoding($text,$target_encoding,$source_encoding) {
- return $text;
- }
- }
- /**
- * displaySmileys
- *
- * @return void
- */
- function displaySmileys ()
- {
- global $smiley_array, $smiley_file_array;
- $i=0;
- $previous_smiley_file = '';
- foreach ($smiley_array as $smiley) {
- if ($smiley_file_array[$i] != $previous_smiley_file) {
- echo '<div class="smiley"><img src="../ui/smileys/' . $smiley_file_array[$i] . '" alt="' . $smiley . '" onclick="return addSmiley(\''.str_replace("'", "\'", $smiley).'\')" /></div>';
- $previous_smiley_file = $smiley_file_array[$i];
- }
- $i++;
- }
- }
- /**
- * escape_string
- *
- * @param string $string
- * @return string
- */
- function escape_string ($string)
- {
- if (version_compare(phpversion(), "4.3.0") == "-1") {
- return mysql_escape_string($string);
- } else {
- return mysql_real_escape_string($string);
- }
- }
- /**
- * cleanOutput
- *
- * Cleans output from the db or from the user so it can be displayed.
- *
- * @param mixed $output
- * @param string $type
- * @return mixed
- */
- function cleanOutput ($output, $type = 'string')
- {
- // Strings that may contain HTML
- if ($type == 'html') {
- return htmlentities($output, ENT_COMPAT, 'UTF-8');
- }
- // Strings without HTML
- $output = strip_tags($output);
- return htmlentities($output, ENT_COMPAT, 'UTF-8');
- }
- /**
- * cleanFilename
- *
- * Removes unwanted characters from a filename.
- *
- * @param string $filename
- *
- * @return void
- */
- function cleanFilename ($filename)
- {
- // convert spaces to underscores
- $filename = str_replace(" ", "_", $filename);
- // remove everything else but numbers and letters _ -
- $filename = preg_replace('/[^.A-Za-z0-9_-]/', '', $filename);
- return $filename;
- }
- /**
- * unhtmlentities
- *
- * html_entity_decode for PHP 4.3.0 and earlier:
- *
- * @param string $string
- * @return string
- */
- function unhtmlentities($string)
- {
- // replace numeric entities
- $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
- $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string);
- // replace literal entities
- $trans_tbl = get_html_translation_table(HTML_ENTITIES);
- $trans_tbl = array_flip($trans_tbl);
- return strtr($string, $trans_tbl);
- }
- /**
- * getPostsById
- *
- * Gets the post count and percentage of total posts for the givin user
- * @param user_id the id of the desired user
- * @param option how you want the data returned
- * count - returns just the count
- * percent - returns just the percent
- * array - returns both, but in an array
- * both - returns both in "X (X%)" format
- * @return a string or array of strings
- */
- function getPostsById ($user_id, $option = 'both')
- {
- $user_id = (int)$user_id;
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_board_posts`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_array($result);
- $total = $found['c'];
- $sql = "SELECT COUNT(`user`) AS c
- FROM `fcms_board_posts`
- WHERE `user` = '$user_id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_array($result);
- $count = $found['c'];
- if ($total < 1 || $count < 1)
- {
- $count = '0';
- $percent = '0%';
- }
- else
- {
- $percent = round((($count/$total)*100), 1) . '%';
- }
- switch($option)
- {
- case 'count':
- return $count;
- break;
- case 'percent':
- return $percent;
- break;
- case 'array':
- return array('count' => $count, 'percent' => $percent);
- break;
- case 'both':
- default:
- return "$count ($percent)";
- break;
- }
- }
- /**
- * getPhotosById
- *
- * Gets the photo count and percentage of total posts for the givin user
- * @param user_id the id of the desired user
- * @param option how you want the data returned
- * count - returns just the count
- * percent - returns just the percent
- * array - returns both, but in an array
- * both - returns both in "X (X%)" format
- * @return a string or array of strings
- */
- function getPhotosById ($user_id, $option = 'both')
- {
- $user_id = (int)$user_id;
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_gallery_photos`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $total = $found['c'];
- $sql = "SELECT COUNT(`user`) AS c
- FROM `fcms_gallery_photos`
- WHERE `user` = '$user_id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $count = $found['c'];
- if ($total < 1 || $count < 1)
- {
- $count = '0';
- $percent = '0%';
- }
- else
- {
- $percent = round((($count/$total)*100), 1) . '%';
- }
- switch($option)
- {
- case 'count':
- return $count;
- break;
- case 'percent':
- return $percent;
- break;
- case 'array':
- return array('count' => $count, 'percent' => $percent);
- break;
- case 'both':
- default:
- return "$count ($percent)";
- break;
- }
- }
- /**
- * getCommentsById
- *
- * Gets the news/gallery comment count and percentage of total news/gallery for the givin user
- * @param user_id the id of the desired user
- * @param option how you want the data returned
- * count - returns just the count
- * percent - returns just the percent
- * array - returns both, but in an array
- * both - returns both in "X (X%)" format
- * @return a string or array of strings
- */
- function getCommentsById ($user_id, $option = 'both')
- {
- $user_id = (int)$user_id;
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_gallery_photo_comment`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $total = $found['c'];
- $sql = "SELECT COUNT(`user`) AS c
- FROM `fcms_gallery_photo_comment`
- WHERE `user` = '$user_id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $count = $found['c'];
- // Check Family News if applicable
- if (usingFamilyNews())
- {
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_news_comments`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $total = $total + $found['c'];
- $sql = "SELECT COUNT(`user`) AS c
- FROM `fcms_news_comments`
- WHERE `user` = '$user_id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $count = $count + $found['c'];
- }
- if ($total < 1 || $count < 1)
- {
- $count = '0';
- $percent = '0%';
- }
- else
- {
- $percent = round((($count/$total)*100), 1) . '%';
- }
- switch($option)
- {
- case 'count':
- return $count;
- break;
- case 'percent':
- return $percent;
- break;
- case 'array':
- return array('count' => $count, 'percent' => $percent);
- break;
- case 'both':
- default:
- return "$count ($percent)";
- break;
- }
- }
- /**
- * getCalendarEntriesById
- *
- * Gets the calendar entries count and percentage of total for the givin user
- * @param user_id the id of the desired user
- * @param option how you want the data returned
- * count - returns just the count
- * percent - returns just the percent
- * array - returns both, but in an array
- * both - returns both in "X (X%)" format
- * @return a string or array of strings
- */
- function getCalendarEntriesById ($user_id, $option = 'both')
- {
- $user_id = (int)$user_id;
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_calendar`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $total = $found['c'];
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_calendar`
- WHERE `created_by` = '$user_id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $count = $found['c'];
- if ($total < 1 || $count < 1)
- {
- $count = '0';
- $percent = '0%';
- }
- else
- {
- $percent = round((($count/$total)*100), 1) . '%';
- }
- switch ($option)
- {
- case 'count':
- return $count;
- break;
- case 'percent':
- return $percent;
- break;
- case 'array':
- return array('count' => $count, 'percent' => $percent);
- break;
- case 'both':
- default:
- return "$count ($percent)";
- break;
- }
- }
- /**
- * getFamilyNewsById
- *
- * Gets the news count and percentage of total news for the givin user
- * @param user_id the id of the desired user
- * @param option how you want the data returned
- * count - returns just the count
- * percent - returns just the percent
- * array - returns both, but in an array
- * both - returns both in "X (X%)" format
- * @return a string or array of strings
- */
- function getFamilyNewsById ($user_id, $option = 'both')
- {
- $user_id = (int)$user_id;
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_news`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $total = $found['c'];
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_news`
- WHERE `user` = '$user_id'
- GROUP BY `user`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_array($result);
- $count = $found['c'];
- if ($total < 1 || $count < 1)
- {
- $count = '0';
- $percent = '0%';
- }
- else
- {
- $percent = round((($count/$total)*100), 1) . '%';
- }
- switch($option)
- {
- case 'count':
- return $count;
- break;
- case 'percent':
- return $percent;
- break;
- case 'array':
- return array('count' => $count, 'percent' => $percent);
- break;
- case 'both':
- default:
- return "$count ($percent)";
- break;
- }
- }
- /**
- * getRecipesById
- *
- * Gets the recipes count and percentage of total for the givin user
- * @param user_id the id of the desired user
- * @param option how you want the data returned
- * count - returns just the count
- * percent - returns just the percent
- * array - returns both, but in an array
- * both - returns both in "X (X%)" format
- * @return a string or array of strings
- */
- function getRecipesById ($user_id, $option = 'both')
- {
- $user_id = (int)$user_id;
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_recipes`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $total = $found['c'];
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_recipes`
- WHERE `user` = '$user_id'
- GROUP BY `user`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $count = $found['c'];
- if ($total < 1 || $count < 1)
- {
- $count = '0';
- $percent = '0%';
- }
- else
- {
- $percent = round((($count/$total)*100), 1) . '%';
- }
- switch($option)
- {
- case 'count':
- return $count;
- break;
- case 'percent':
- return $percent;
- break;
- case 'array':
- return array('count' => $count, 'percent' => $percent);
- break;
- case 'both':
- default:
- return "$count ($percent)";
- break;
- }
- }
- /**
- * getDocumentsById
- *
- * Gets the documents count and percentage of total for the givin user
- * @param user_id the id of the desired user
- * @param option how you want the data returned
- * count - returns just the count
- * percent - returns just the percent
- * array - returns both, but in an array
- * both - returns both in "X (X%)" format
- * @return a string or array of strings
- */
- function getDocumentsById ($user_id, $option = 'both')
- {
- $user_id = (int)$user_id;
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_documents`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $total = $found['c'];
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_documents`
- WHERE `user` = '$user_id'
- GROUP BY `user`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_assoc($result);
- $count = $found['c'];
- if ($total < 1 || $count < 1)
- {
- $count = '0';
- $percent = '0%';
- }
- else
- {
- $percent = round((($count/$total)*100), 1) . '%';
- }
- switch($option)
- {
- case 'count':
- return $count;
- break;
- case 'percent':
- return $percent;
- break;
- case 'array':
- return array('count' => $count, 'percent' => $percent);
- break;
- case 'both':
- default:
- return "$count ($percent)";
- break;
- }
- }
- /**
- * getPrayersById
- *
- * Gets the prayers count and percentage of total for the givin user
- * @param user_id the id of the desired user
- * @param option how you want the data returned
- * count - returns just the count
- * percent - returns just the percent
- * array - returns both, but in an array
- * both - returns both in "X (X%)" format
- * @return a string or array of strings
- */
- function getPrayersById ($user_id, $option = 'both')
- {
- $user_id = (int)$user_id;
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_prayers`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_array($result);
- $total = $found['c'];
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_prayers`
- WHERE `user` = '$user_id'
- GROUP BY `user`";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return '0';
- }
- $found = mysql_fetch_array($result);
- $count = $found['c'];
- if ($total < 1 || $count < 1)
- {
- $count = '0';
- $percent = '0%';
- }
- else
- {
- $percent = round((($count/$total)*100), 1) . '%';
- }
- switch($option)
- {
- case 'count':
- return $count;
- break;
- case 'percent':
- return $percent;
- break;
- case 'array':
- return array('count' => $count, 'percent' => $percent);
- break;
- case 'both':
- default:
- return "$count ($percent)";
- break;
- }
- }
- /**
- * getNewsComments
- *
- * @param int $news_id
- * @return void
- */
- function getNewsComments ($news_id)
- {
- $news_id = (int)$news_id;
- $sql = "SELECT COUNT(`id`) AS c
- FROM `fcms_news_comments`
- WHERE `news` = '$news_id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $found = mysql_fetch_array($result);
- return $found['c'] ? $found['c'] : 0;
- }
- /**
- * getUserParticipationPoints
- *
- * Get the participation points for the given member.
- *
- * Action Points
- * -------------------
- * thread 5
- * photo 3
- * news 3
- * recipe 2
- * document 2
- * prayer 2
- * post 2
- * comment 2
- * address 1
- * phone # 1
- * date/event 1
- * vote 1
- *
- * @param int $id
- * @return int
- */
- function getUserParticipationPoints ($id)
- {
- $id = (int)$id;
- $points = 0;
- $commentTables = array('fcms_gallery_photo_comment');
- // Thread (5)
- $sql = "SELECT COUNT(`id`) AS thread
- FROM `fcms_board_threads`
- WHERE `started_by` = '$id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $r = mysql_fetch_array($result);
- $points += $r['thread'] * 5;
- // Photo (3)
- $sql = "SELECT COUNT(`id`) AS photo
- FROM `fcms_gallery_photos`
- WHERE `user` = '$id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $r = mysql_fetch_array($result);
- $points += $r['photo'] * 3;
- // News (3)
- if (usingFamilyNews())
- {
- array_push($commentTables, 'fcms_news_comments');
- $sql = "SELECT COUNT(`id`) AS news
- FROM `fcms_news`
- WHERE `user` = '$id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $r = mysql_fetch_array($result);
- $points += $r['news'] * 3;
- }
- // Recipe (2)
- if (usingRecipes())
- {
- array_push($commentTables, 'fcms_recipe_comment');
- $sql = "SELECT COUNT(`id`) AS recipe
- FROM `fcms_recipes`
- WHERE `user` = '$id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $r = mysql_fetch_array($result);
- $points += $r['recipe'] * 2;
- }
- // Document (2)
- if (usingDocuments())
- {
- $sql = "SELECT COUNT(`id`) AS doc
- FROM `fcms_documents`
- WHERE `user` = '$id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $r = mysql_fetch_array($result);
- $points += $r['doc'] * 2;
- }
- // Prayer (2)
- if (usingPrayers())
- {
- $sql = "SELECT COUNT(`id`) AS prayer
- FROM `fcms_prayers`
- WHERE `user` = '$id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $r = mysql_fetch_array($result);
- $points += $r['prayer'] * 2;
- }
- // Post (2)
- $sql = "SELECT COUNT(`id`) AS post
- FROM `fcms_board_posts`
- WHERE `user` = '$id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $r = mysql_fetch_array($result);
- $points += $r['post'] * 2;
- // Comment (2)
- $from = implode('`, `', $commentTables);
- $where = implode("`.`user` = '$id' AND `", $commentTables);
- $sql = "SELECT COUNT(*) AS comment
- FROM `$from`
- WHERE `$where`.`user` = '$id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $r = mysql_fetch_array($result);
- $points += $r['comment'] * 2;
- // Address/Phone (1)
- $sql = "SELECT `address`, `city`, `state`, `home`, `work`, `cell`
- FROM `fcms_address`
- WHERE `user` = '$id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $r = mysql_fetch_array($result);
- if (!empty($r['address']) && !empty($r['city']) && !empty($r['state']))
- {
- $points++;
- }
- if (!empty($r['home']))
- {
- $points++;
- }
- if (!empty($r['work']))
- {
- $points++;
- }
- if (!empty($r['cell']))
- {
- $points++;
- }
- // Date/Event
- $sql = "SELECT COUNT(`id`) AS event
- FROM `fcms_calendar`
- WHERE `created_by` = '$id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $r = mysql_fetch_array($result);
- $points += $r['event'];
- // Vote
- $sql = "SELECT COUNT(`id`) AS vote
- FROM `fcms_poll_votes`
- WHERE `user` = '$id'";
- $result = mysql_query($sql);
- if (!$result)
- {
- displaySqlError($sql, mysql_error());
- return 0;
- }
- $r = mysql_fetch_array($result);
- $points += $r['vote'];
- return $points;
- }
- /**
- * getUserParticipationLevel
- *
- * Get the participation level for the given points.
- *
- * Level Points
- * ---------------
- * 1 25
- * 2 50
- * 3 100
- * 4 200
- * 5 400
- * 6 800
- * 7 1,600
- * 8 3,200
- * 9 6,400
- * 10 12,800
- *
- *
- * …
Large files files are truncated, but you can click here to view the full file