?php /* error_reporting(E_ALL); ini_set('display_errors', 1); */ class Website_Tool_Nikonians_Forum { var $forum_db; var $nikoniansconfig; // Next fields have corresponding in dcp.dcsetup table var $forum_setup_array = array(); public function __construct() { $this->forum_db = Website_Tool_Nikonians::getForumDB(); $nikonianstool = new Website_Tool_Nikonians(); $this->nikoniansconfig = $nikonianstool->getNikoniansConfig(); $this->initDcpDcsetupArray(); /* $locale = Zend_Registry::get("Zend_Locale"); $t = Zend_Registry::get("Zend_Translate"); $t->setLocale($locale); */ } public function __destruct() { Website_Tool_Nikonians::closeDBConnection($this->forum_db); } function initDcpDcsetupArray() { $q = "SELECT var_key, var_value FROM dcsetup"; $this->forum_setup_array = array(); $result = $this->forum_db->fetchAll($q); foreach ($result as $row) { $var_key = $row['var_key']; $this->forum_setup_array[$var_key] = $row['var_value']; } return; } function getUserAvatarArray($username) { $q = "SELECT id, username, pc, pd FROM dcuser2 WHERE username = " . $this->forum_db->quote($username); $avatarArray = array(); $row = $this->forum_db->fetchRow($q); if ($row['id']) { $avatarArray['id'] = $row['id']; $avatarArray['username'] = $row['username']; $avatarArray['src'] = $row['pc']; $avatarArray['gender'] = $row['pd']; } return $avatarArray; } function getUsertimeZone($userid) { $default_ut_id = $this->forum_setup_array['time_zone']; $time_zone = $this->get_time_zone_id_from_ut_id($default_ut_id); $q = "SELECT id, ut, username FROM dcuser2 WHERE id = " . $this->forum_db->quote($userid); $row = $this->forum_db->fetchRow($q); if ($row['id'] == $userid and !$this->isGuestUser($row['username'])) { $time_zone= $this->get_time_zone_id_from_ut_id($row['ut']); return $time_zone; } return $time_zone; } function get_ut_id_for_time_zone($timezone_id) { $ut_id = 0; $q = "SELECT ut_id , timezone_id FROM nik_time_zones WHERE timezone_id = " . $this->forum_db->quote($timezone_id) . " ORDER BY display_it DESC LIMIT 1"; $row = $this->forum_db->fetchRow($q); if ($row['timezone_id'] == $timezone_id) { $ut_id = $row['ut_id']; } return $ut_id; } function get_time_zone_id_from_ut_id($ut_id) { $timezone_id = ''; $q = "SELECT timezone_id, ut_id FROM nik_time_zones WHERE ut_id = " . $this->forum_db->quote($ut_id) . " ORDER BY display_it DESC LIMIT 1"; $row = $this->forum_db->fetchRow($q); if ( $row['ut_id'] == $ut_id) { $timezone_id = $row['timezone_id']; } return $timezone_id; } // Used for sidebar function getRegisteredUserLastDays($days = 7) { $days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-$days, date("Y"))); $q = "SELECT count(id) AS count FROM dcuser2 WHERE delete_flag = 'no' AND reg_date > '$days'"; $nrusers = 0; $row = $this->forum_db->fetchRow($q); if ($row['count']) { $nrusers = $row['count']; } return $nrusers; } function getLastRegisteredUser() { $q = "SELECT id, username FROM dcuser2 WHERE status='on' ORDER BY reg_date DESC LIMIT 1 "; $user = array(); $row = $this->forum_db->fetchRow($q); if ($row['id']) { $user['id'] = $row['id']; $user['username'] = $row['username']; } return $user; } function getLatestForumAnnouncements($language = 'english') { $announcement = array(); $q = "SELECT id, subject FROM dcannouncement WHERE TO_DAYS(e_date) > TO_DAYS(NOW()) AND language = ". $this->forum_db->quote($language) ." ORDER BY a_date DESC "; $result = $this->forum_db->fetchAll($q); foreach ($result as $row) { $id = $row['id']; $announcement[$id] = $row['subject']; } return $announcement; } // Used for comments on articles public function getResourcesCommentedByUserInfo($user_id) { $userdata = array(); $row = $this->forum_db->fetchRow("SELECT username, name, pd, pc FROM dcuser2 WHERE id=" . $this->forum_db->quote($user_id)); if ($row['username']) { $userdata['username'] = $row['username']; $userdata['name'] = $row['name']; $userdata['gender'] = $row['pd']; $userdata['avatarimg'] = $row['pc']; } return $userdata; } // Used for article owner data in future public function getResourcesAuthorUserInfo($user_id) { $userdata = array(); $row = $this->forum_db->fetchRow("SELECT username, name, pg, pe, pf, pc FROM dcuser2 WHERE id=" . $this->forum_db->quote($user_id)); if ($row['username']) { $userdata['username'] = $row['username']; $userdata['name'] = $row['name']; $userdata['groupid'] = $row['groupid']; $userdata['gender'] = $row['pd']; $userdata['city'] = $row['pe']; $userdata['avatarimg'] = $row['pc']; } return $userdata; } public function getNikoniansUsernameById($user_id, $ann_if_deleted = false) { $out = ''; $row = $this->forum_db->fetchRow("SELECT username, delete_flag FROM dcuser2 WHERE id=" . $this->forum_db->quote($user_id)); if ($row['username']) { if ($ann_if_deleted and $row['delete_flag'] == 'yes') { return $out; } $out = $row['username']; } return $out; } // We try this keep minimalistic public function getUserViewsDetailsById($user_id) { $row = $this->forum_db->fetchRow("SELECT id, username, name, pc, status, delete_flag FROM dcuser2 WHERE id=" . $this->forum_db->quote($user_id)); return $row; } public function getNikoniansNameById($user_id) { $out = ''; $row = $this->forum_db->fetchRow("SELECT name FROM dcuser2 WHERE id=" . $this->forum_db->quote($user_id)); if ($row['name']) { $out = $row['name']; } return $out; } public function getNikoniansUserIdByUserName($user_name) { $out = ''; $row = $this->forum_db->fetchRow("SELECT id FROM dcuser2 WHERE username = " . $this->forum_db->quote($user_name)); if ($row['id']) { $out = $row['id']; } return $out; } // fields must be dcuser2 fields public function getNikoniansUsersArray($fields = 'id, username, name', $order_by = "username") { $result = array(); try { $result = $this->forum_db->fetchAll("SELECT " . $fields . " FROM dcuser2 ORDER BY " . $order_by); } catch (Exception $e) { // We may here silently die } return $result; } public function getNikoniansActiveUsersArray($limit = '', $fields = 'id, username, name', $order_by = "username") { $result = array(); if ($limit != '') $limit = " LIMIT " . $limit; try { $result = $this->forum_db->fetchAll("SELECT " . $fields . " FROM dcuser2 WHERE status = 'on' ORDER BY " . $order_by . $limit); } catch (Exception $e) { // We may here silently die } return $result; } public function getAvatarURL($avatarImg, $gender, $useDefaultAvatar = false) { $nikoniansconfig = $this->nikoniansconfig; $ret_url = ''; if(empty($avatarImg)) { if ($useDefaultAvatar) { //$ret_url = $nikoniansconfig->root_url->en . 'website/static/images/default_avatar.png'; $ret_url = $nikoniansconfig->static->images_url . 'default_avatar.png'; } else if (empty($gender) or $gender == 'male') { $ret_url = $nikoniansconfig->server->root_url->en . '/sn/images/avatarAnonymus.gif'; } else { $ret_url = $nikoniansconfig->server->root_url->en . '/sn/images/sillueteFemale.gif'; } } else { $ret_url = $nikoniansconfig->forum->avatar_url . '/' . $avatarImg; } $ret_url = str_replace('http://', 'https://', $ret_url); return $ret_url; } // This function return the Team Users Array with only usernames and user ids public function getTeamUsersKeys() { $result = array(); try { $sql = "SELECT u.id as userId , u.username FROM dcuser2 as u WHERE u.g_id > 9 and u.status = 'on' and u.delete_flag = 'no' and u.teampage = 'yes' and u.ua != 'yes' ORDER BY u.username"; $result = $this->forum_db->fetchAll($sql); } catch (Exception $e) { return $result; } return $result; } // This function return the Team Users Array public function generateNikoniansTeamUsersArray() { $result = array(); try { // get team users array $usersArray = $this->getTeamUsersKeys(); // Build array with data needed by team page foreach ($usersArray as $user) { $userId = $user['userId']; $sql = "SELECT u.id as userId , u.username, u.name, u.g_id as groupId , u.pc as avatar, u.pd as gender, u.num_posts as numPosts , u.reg_date as regDate, u.WishList, u.FavouriteGadget , u.pj as userComment, u.user_title as userTitle , u.last_login, u.last_date FROM dcuser2 as u WHERE u.id = '$userId'"; $user_result = $this->forum_db->fetchRow($sql); $result[] = $user_result; } } catch (Exception $e) { return $result; } return $result; } public function cacheNikoniansTeamUsersArray() { try { $cacheEngine = new Nikonians_TeampageCache_TeampageUsersArray(); $cacheKey = $cacheEngine->createKey(); $ret_array = self::generateNikoniansTeamUsersArray(); $cacheEngine->save($ret_array); Logger::info('CACHE REFRESHED: ' . $cacheKey); } catch (Exception $e) { Logger::warning($e->getMessage()); $ret_array = self::generateNikoniansTeamUsersArray(); } return $ret_array; } public function getNikoniansTeamUsersArray() { $ret_array = array(); try { $cacheEngine = new Nikonians_TeampageCache_TeampageUsersArray(); $cacheKey = $cacheEngine->createKey(); // Get data from cache $ret_array = $cacheEngine->load(); if (!$ret_array or $ret_array == null) { $ret_array = self::generateNikoniansTeamUsersArray(); } } catch (Exception $e) { Logger::warning($e->getMessage()); $ret_array = self::generateNikoniansTeamUsersArray(); } return $ret_array; } // This function return the forums moderated by the user public function generateUserModeratedForumsArray($u_id) { $whereBlacklisted = ''; /* $blacklisted = Pimcore_Tool_Frontend::getWebsiteConfig("blacklisted_forums"); if (sizeof($blacklisted) > 0) { foreach ($blacklisted as $blacklistedForumID) { $whereBlacklisted .= " AND f.id != '" .$blacklistedForumID ."'"; } } */ // We avoid blacklisted as our condition in query is much restrictive $result = array(); try { $sql = "SELECT m.forum_id as forum_id , f.name as forum_name , f.language as forum_lang FROM dcmoderator m join dcforum f on m.forum_id = f.id WHERE m.u_id = " . $this->forum_db->quote($u_id) . " and f.status = 'on' and (f.type = '10' OR f.type = '20' OR f.type = '35' OR f.type = '50' OR f.type = '60' OR f.type = '70' OR f.type = '65') $whereBlacklisted order by f.name "; $result = $this->forum_db->fetchAll($sql); } catch (Exception $e) { return $result; // We may here silently die } return $result; } public function cacheUserModeratedForums($user_id) { $ret_array = array(); // start cache try { $cacheEngine = new Nikonians_TeampageCache_UserModeratedForums(); $cacheKey = $cacheEngine->createKey(array('user_id' => $user_id)); $ret_array = self::generateUserModeratedForumsArray($user_id); $cacheEngine->save($ret_array); Logger::info('CACHE REFRESHED: ' . $cacheKey); } catch (Exception $e) { Logger::warning($e->getMessage()); $ret_array = self::generateUserModeratedForumsArray($user_id); } return $ret_array; } // This function return forums which we use to select data from public function getUserModeratedForums($user_id) { $ret_array = array(); // start cache try { $cacheEngine = new Nikonians_TeampageCache_UserModeratedForums(); $cacheKey = $cacheEngine->createKey(array('user_id' => $user_id)); // Test if data cache exists $ret_array = $cacheEngine->load(); // Test conditions are different as we may have also empty array if ($ret_array == null) { $ret_array = self::generateUserModeratedForumsArray($user_id); } } catch (Exception $e) { Logger::warning($e->getMessage()); $ret_array = self::generateUserModeratedForumsArray($user_id); } return $ret_array; } // This function return user rating data public function getUserRatingData($u_id) { $nikoniansconfig = $this->nikoniansconfig; $language = 'en'; $result = array(); $result['totalRecommended'] = 0; $result['viewRatingsURL'] = ''; try { $sql = "SELECT count(score) as totalRecommended FROM dcuserrating WHERE u_id = " . $this->forum_db->quote($u_id); $sql_result = $this->forum_db->fetchRow($sql); $totalRecommended = $sql_result['totalRecommended']; if (empty($totalRecommended)) { $totalRecommended = 0; } $result['totalRecommended'] = $totalRecommended; $result['viewRatingsURL'] = $nikoniansconfig->forum->root_url->$language . '?az=user_ratings_new&u_id=' . $u_id; } catch (Exception $e) { return $result; // We may here silently die } return $result; } function getUserRibbonsArray($u_id) { $ribbons = array(); // Get all ribbons of this user $sql = "SELECT * FROM nik_ribbon_asigment WHERE user_id = " . $this->forum_db->quote($u_id); $sql_result = $this->forum_db->fetchAll($sql); foreach ($sql_result as $row) { $ribbon_id = $row['ribbon_id']; $sql_image = "SELECT * FROM nik_ribbon WHERE id = " . $this->forum_db->quote($ribbon_id); $sql_image_result = $this->forum_db->fetchAll($sql_image); foreach ($sql_image_result as $image_row) { $image = $image_row['img']; $description = $row['description']; if ($image != '') { $ribbons[] = array( 'image' => '/forums/images/ribbons/' . $image , 'description' => $description ); } } } return $ribbons; } public function cacheWhiteListedForumsArray($forumLanguage = '') { $ret_data = array(); // start cache try { $cacheEngine = new Nikonians_TeampageCache_WhiteListedForumsArray(); $cacheKey = $cacheEngine->createKey(); $ret_array = self::generateWhiteListedForumsArray($forumLanguage); $cacheEngine->save($ret_array); Logger::info('CACHE REFRESHED: ' . $cacheKey); } catch (Exception $e) { Logger::warning($e->getMessage()); $ret_data = self::generateWhiteListedForumsArray($forumLanguage); } return $ret_data; } // This function return forums which we use to select data from public function getWhiteListedForumsArray($forumLanguage = '') { $ret_data = array(); // start cache try { $cacheEngine = new Nikonians_TeampageCache_WhiteListedForumsArray(); $cacheKey = $cacheEngine->createKey(); // Test if data cache exists $ret_data = $cacheEngine->load(); // We check not against null as we must have at least one if (!$ret_data) { $ret_data = self::generateWhiteListedForumsArray($forumLanguage); } } catch (Exception $e) { Logger::warning($e->getMessage()); $ret_data = self::generateWhiteListedForumsArray($forumLanguage); } return $ret_data; } // This function return forums which we use to select data from public function generateWhiteListedForumsArray($forumLanguage = '') { $forumid_array = array(); try { // WE do not list blacklisted forums $whereBlacklisted = ''; $blacklisted = Pimcore_Tool_Frontend::getWebsiteConfig("blacklisted_forums"); if (sizeof($blacklisted) > 0 ) { foreach ($blacklisted as $blacklistedForumID) { $whereBlacklisted .= " AND f.id != '" .$blacklistedForumID ."'"; } } // We add language criteria $whereLanguage = ''; if (!empty($forumLanguage)) { $whereLanguage = ' AND language = ' . $this->forum_db->quote($forumLanguage); } // We select the forums details $sql = "SELECT f.id, f.name, f.language FROM dcforum AS f WHERE f.status = 'on' AND (f.type = '35' or f.type = '50' or f.type = '20') $whereBlacklisted $whereLanguage ORDER BY f.last_date desc "; $result = $this->forum_db->fetchAll($sql); foreach($result as $row) { $key = $row['id']; $val = array('forum_name'=>$row['name'],'forum_lang'=>$row['language'],'forum_id'=>$row['id'],); $forumid_array[$key] = $val; } return $forumid_array; } catch (Exception $e) { // We may here silently die } return $forumid_array; } // This function checks if user has any posts based on dcuser2.last_date and num_posts public function hasUserForumPosts($user_id) { $has_posts = false; try { // We test if user had any posts based on last_date from dcuser2 $sql = "SELECT num_posts FROM dcuser2 WHERE id = " . $this->forum_db->quote($user_id); $row = $this->forum_db->fetchRow($sql); // or $row['last_date'] != '0000-00-00 00:00:00' if ($row['num_posts'] > 0) { $has_posts = true; } } catch (Exception $e) { // It can be some forum tables are missing //echo $e->getMessage(); } return $has_posts; } public function cacheUserLatestForumPost($user_id, $forumid_array = array()) { $ret_array = array(); if (!self::hasUserForumPosts($user_id)) { return $ret_array; } // start cache try { $cacheEngine = new Nikonians_TeampageCache_UserLatestForumPost(); $cacheKey = $cacheEngine->createKey(array('user_id' => $user_id)); $ret_array = self::generateUserLatestForumPost($user_id, $forumid_array); $cacheEngine->save($ret_array); Logger::info('CACHE REFRESHED: ' . $cacheKey); } catch (Exception $e) { Logger::warning($e->getMessage()); $ret_array = self::generateUserLatestForumPost($user_id, $forumid_array); } return $ret_array; } // This function return a user latest forum post public function getUserLatestForumPost($user_id, $forumid_array = array()) { $ret_array = array(); if (!self::hasUserForumPosts($user_id)) { return $ret_array; } // start cache try { $cacheEngine = new Nikonians_TeampageCache_UserLatestForumPost(); $cacheKey = $cacheEngine->createKey(array('user_id' => $user_id)); // Test if data cache exists $ret_array = $cacheEngine->load(); if ($ret_array == null) { $ret_array = self::generateUserLatestForumPost($user_id, $forumid_array); } } catch (Exception $e) { Logger::warning($e->getMessage()); $ret_array = self::generateUserLatestForumPost($user_id, $forumid_array); } return $ret_array; } // This function return the user latest forum post public function generateUserLatestForumPost($user_id, $forumid_array = array() ) { $user_posted_array = array(); if (!self::hasUserForumPosts($user_id)) { return $user_posted_array; } try { if (empty($forumid_array)) { $forumid_array = self::getWhiteListedForumsArray(); } $messages = array(); $prevMessageTimestamp = 0; $latestMessageRow = array(); foreach($forumid_array as $for_id=>$for_values) { try { $table_name = $for_id . '_mesg'; $sql = "SELECT tbl.last_date as post_date, tbl.id as id, tbl.subject as subject , tbl.top_id as top_id, tbl.parent_id as parent_id FROM $table_name as tbl WHERE tbl.author_id = " . $user_id . " AND tbl.topic_hidden != 'on' AND tbl.topic_queue != 'on' AND tbl.type != '98' AND tbl.subject != 'Deleted message' ORDER BY tbl.last_date DESC LIMIT 1"; $result = $this->forum_db->fetchAll($sql); foreach($result as $row) { $row['forum_id'] = $for_id; $row['forum_name'] = $for_values['forum_name']; $row['forum_lang'] = $for_values['forum_lang']; $currMessageTimestamp = strtotime($row['post_date']); $row['post_date_timestamp'] = $currMessageTimestamp; if ($currMessageTimestamp > $prevMessageTimestamp) { $latestMessageRow = $row; $prevMessageTimestamp = $currMessageTimestamp; } } } catch (Exception $e) { // It can be some forum tables are missing //echo $e->getMessage(); } } if (!empty($latestMessageRow)) { $show_it_url = self::getForumMessageURL($latestMessageRow); $latestMessageRow['url'] = $show_it_url; $user_posted_array = $latestMessageRow; } return $user_posted_array; } catch (Exception $e) { // We may here silently die } return $user_posted_array; } // This function return the users latest forum posts same as in profile page public function getUserPostsInForum($user_id, $for_id, $for_max_posts = 8) { $user_posted_array = array(); try { $messages = array(); try { $table_name = $for_id . '_mesg'; $sql = "SELECT tbl.last_date as post_date, tbl.id as id, tbl.subject as subject , tbl.top_id as top_id, tbl.parent_id as parent_id FROM $table_name as tbl WHERE tbl.author_id = " . $user_id . " AND tbl.topic_hidden != 'on' AND tbl.topic_queue != 'on' ORDER BY tbl.last_date DESC LIMIT $for_max_posts"; $result = $this->forum_db->fetchAll($sql); foreach($result as $row) { $row['forum_id'] = $for_id; $row['post_date_timestamp'] = strtotime($row['post_date']); array_push($messages, $row); } } catch (Exception $e) { // It can be some forum tables are missing //echo $e->getMessage(); } return $messages; } catch (Exception $e) { // We may here silently die } return $messages; } // This function return the users latest forum posts same as in profile page public function getUserForumPostsActivity($user_id, $for_max_posts = 8, $forumid_array = array()) { $user_posted_array = array(); if (!self::hasUserForumPosts($user_id)) { return $user_posted_array; } try { // We select the forums which we may use to extract forum posts if (empty($forumid_array)) { $forumid_array = self::getWhiteListedForumsArray(); } // We go thru forums array and extract users posts $messages = array(); foreach($forumid_array as $for_id=>$for_values) { $forum_messages = self::getUserPostsInForum($user_id, $for_id, $for_max_posts); foreach($forum_messages as $row) { $row['forum_name'] = $for_values['forum_name']; $row['forum_lang'] = $for_values['forum_lang']; $row['forum_id'] = $for_id; $show_it_url = self::getForumMessageURL($row); $row['url'] = $show_it_url; array_push($messages, $row); } } //order by date $posts_arr = Website_Tool_NikoniansText::subvalSort($messages, 'post_date_timestamp'); $posts_arr = array_reverse($posts_arr, true); foreach ($posts_arr as $k=>$arr_val) { array_push($user_posted_array,$arr_val); } $user_posted_array = array_slice($user_posted_array, 0, $for_max_posts); return $user_posted_array; } catch (Exception $e) { //echo $e->getMessage(); return $user_posted_array; // We may here silently die } return $user_posted_array; } // This function return the topic url public function getForumMessageURL($row) { if ($row['top_id'] > 0) { $topic_id = $row['top_id']; } else { $topic_id = $row['id']; } $the_lang = ''; if ($row['forum_lang'] != 'english') { $the_lang = substr(strtolower($row['forum_lang']),0,2); } if ($the_lang == 'en') { $forumBaseURL = $this->nikoniansconfig->forum->root_url->en; } else if ($the_lang == 'de') { $forumBaseURL = $this->nikoniansconfig->forum->root_url->de; } else if ($the_lang == 'fr') { $forumBaseURL = $this->nikoniansconfig->forum->root_url->fr; } else { $forumBaseURL = $this->nikoniansconfig->forum->root_url->en; } $show_it_url = $forumBaseURL . "?az=show_mesg&forum=".$row['forum_id']."&topic_id=".$topic_id."&mesg_id=".$row['id']; return $show_it_url; } // This function return the friends activity Array public function getUserLastActivity($username) { $row = array(); try { $sql = "SELECT activity_type, activity_date, activity_url, activity_image, activity_varchar, activity_varchar2, activity_int FROM sn_activities WHERE activity_username = " . $this->forum_db->quote($username) . " ORDER BY activity_id DESC LIMIT 1"; $row = $this->forum_db->fetchRow($sql); /* activity_type = 3 - means comment on gallery photo activity_url - show photo URL activity_varchar - photo title activity_type = 4 - means uploaded a photo activity_url - show photo URL activity_image - phito thumbnail activity_varchar - photo id activity_varchar2 - photo title activity_type = 6 - blog post activity_url - blog url activity_varchar - blog title activity_varchar2 - piece of text activity_type = 7 - became friend with activity_varchar - the friend username function checkBlogUrl($urlPar, $user) { $url = $urlPar; $occur = $this->strposOffset("//", $url, 2)+1; $firstPart = substr($url, 0, $occur); $secondPart = substr($url, $occur); $blogUser = $user; $blogUser = str_replace(' ', "_", $blogUser); $blogUser = strtolower($blogUser); $newUrl = $firstPart.$blogUser.$secondPart; return $newUrl; } */ } catch (Exception $e) { // We may here silently die } return $row; } public function getPaymentCountriesArray() { $result = array(); $ret_array = array(); try { $sql = "SELECT c.country_name, c.country_code FROM dccountries AS c WHERE c.lang='english' ORDER BY c.country_order, c.country_name"; $result = $this->forum_db->fetchAll($sql); foreach($result as $row) { $code = $row['country_code']; $name = $row['country_name']; $ret_array[$code] = $name; } } catch (Exception $e) { return $ret_array; } return $ret_array; } // $nikoniansUser is a nikoniansUser object // It is the object of the logged in or not user, the user which view the page public function getForumLobbyArray($nikoniansUser, $language = 'en') { $visitorUserId = $nikoniansUser->userid; $visitorUsername = $nikoniansUser->username; $visitorGroupId = $nikoniansUser->groupid; $forumReturnArray = array(); $userAccess = array(); $forumAccessList = array(); if (isset($visitorGroupId) and $visitorGroupId > 1) { $q = "SELECT forum_id FROM dcpflist WHERE u_id = '" . $visitorUserId . "' "; $result = $this->forum_db->fetchAll($q); foreach($result as $row) { $userAccess[$row['forum_id']] = 1; } // private forums $q = "SELECT forum_id FROM dcmoderator WHERE u_id = '" . $visitorUserId . "' "; $result = $this->forum_db->fetchAll($q); foreach($result as $row) { $userAccess[$row['forum_id']] = 1; } } $forumLanguage = Website_Tool_NikoniansText::getForumLanguageFromShortLang($language); $q = "SELECT f.*,UNIX_TIMESTAMP(f.last_date) AS last_date,t.name as forum_type FROM dcforum AS f, dcforumtype AS t WHERE f.type = t.id AND f.status = 'on' AND f.language = " .$this->forum_db->quote($forumLanguage) ." ORDER BY f.parent_id, f.forum_order, f.type, name ASC"; $result = $this->forum_db->fetchAll($q); foreach($result as $row) { // another backward compatible fix $row['l_date'] = $row['last_date']; // admin has full access if ($visitorGroupId == 99) { $forumAccessList[$row['id']] = 'RW'; } elseif ($row['type'] == '40') { if ($userAccess[$row['id']] > 0) { $forumAccessList[$row['id']] = 'RW'; } } elseif ($row['type'] == '30') { if ($visitorGroupId > 1) { $forumAccessList[$row['id']] = 'RW'; } } elseif ($row['type'] == '20' or $row['type'] == '35') { if (!$this->isGuestUser($visitorUsername) and $visitorGroupId > 0) { $forumAccessList[$row['id']] = 'RW'; } else { $forumAccessList[$row['id']] = 'R'; } } elseif ($row['type'] == '50') { if ($visitorGroupId >= 6 and $visitorGroupId != 9) { $forumAccessList[$row['id']] = 'RW'; } else { $forumAccessList[$row['id']] = 'R'; } } elseif ($row['type'] == '60') { if ($this->isGuestUser($visitorUsername) or $visitorGroupId < 6 ) { $forumAccessList[$row['id']] = 'R'; } else { $forumAccessList[$row['id']] = 'RW'; } } elseif ($row['type'] == '65') { if ($userAccess[$row['id']] > 0) { $forumAccessList[$row['id']] = 'RW'; } else { if ($this->isGuestUser($visitorUsername) or ($visitorGroupId < 7 /*$visitorGroupId != 8 and $visitorGroupId != 7 and $visitorGroupId != 20 */)) { $forumAccessList[$row['id']] = 'R'; } else { $forumAccessList[$row['id']] = 'RW'; } } } elseif ($row['type'] == '70') { if ($userAccess[$row['id']] > 0) { $forumAccessList[$row['id']] = 'RW'; } else { if ($this->isGuestUser($visitorUsername) or ($visitorGroupId < 8 /*$visitorGroupId != 8 and $visitorGroupId != 20*/ )) { $forumAccessList[$row['id']] = 'R'; } else { $forumAccessList[$row['id']] = 'RW'; } } } else { $forumAccessList[$row['id']] = 'RW'; } if ($forumAccessList[$row['id']] == 'R' or $forumAccessList[$row['id']] == 'RW') { $forumReturnArray[$row['id']] = $row; } } return $forumReturnArray; } public function getSortedForumLobbyArray($nikoniansUser, $language = 'en') { $forum_list = $this->getForumLobbyArray($nikoniansUser, $language); $sorted_forum_list = $this->sortForumList($forum_list); return $sorted_forum_list; } public function getForumFlagsForView($sorted_forum_list) { // Go thru the array and mark last level forums // This is used to determine the type of "branch" a folder needs $last_folder = array(); $last_flag = array(); // $sorted_forum_list returns $id and $level in array foreach ($sorted_forum_list as $this_array) { // $key and $level - $key is really the forum ID $key = $this_array['0']; $level = $this_array['1']; // If top level, re-initialize if ($level == 0) { $prev_level = $level; $last_folder[$level] = $key; } else { if ($level > $prev_level) { $last_folder[$level] = $key; $last_flag[$key] = 1; } else { $prev_last_key = $last_folder[$level]; $last_folder[$level] = $key; $last_flag[$prev_last_key] = 0; $last_flag[$key] = 1; } $prev_key = $key; $prev_level = $level; } } return array( 'last_folder_array' => $last_folder , 'last_flag_array' => $last_flag ); } public function sortForumList($forum_list) { // setup sorted forum list we're sending back $sorted_forum_list = array(); // initialize level value $level = 0; while(list($key,$val) = each ($forum_list) ) { // Check to see if this is the first level forum // If so, go get child folders if ($val['parent_id'] == 0 and $val['status'] == 'on') { // Ok, we have a parent forum...add it to the array array_push($sorted_forum_list,array($key,$level)); // get children forums $count_child = $this->getForumChild($sorted_forum_list,$forum_list,$key,$level); // if the number of accessible folders are 0, // then we remove this top level forum if ($count_child < 1 and $val['type'] == 99) array_pop($sorted_forum_list); } } reset($sorted_forum_list); return $sorted_forum_list; } ////////////////////////////////////////////////////////////////////////// // function get_child // recursive function to sort stuff // ////////////////////////////////////////////////////////////////////////// public function getForumChild(&$sorted_forum_list,$forum_list,$parent_id,&$level) { $level++; $count_child = 0; // sort thru $forum_list and pick off parents while(list($key,$val) = each($forum_list)) { if ($val['parent_id'] == $parent_id and $val['status'] === 'on') { // ok we have a child, now add one $count_child++; // add this child to the sorted forum list array_push($sorted_forum_list,array($key,$level)); $this_num = $this->getForumChild($sorted_forum_list,$forum_list,$key,$level); if ($this_num < 1 and $val['type'] == 99) { array_pop($sorted_forum_list); $count_child--; } } } $level--; return $count_child; } public function isGuestUser($username) { if (empty($username)) { return true; } elseif ($username == $this->nikoniansconfig->forum->guestuser) { return true; } else { return false; } } public function getForumReadNewStatus($userUseMarkTimestamp, $userCurrentBrowseTime, $markedForumTimeStamp, $date) { if (!$userCurrentBrowseTime) { $userCurrentBrowseTime = 0; } if (!$markedForumTimeStamp) { $markedForumTimeStamp = 0; } // Check time difference if ($userUseMarkTimestamp == 'yes') { $time_diff = $date - $markedForumTimeStamp; } else { // User is using last visited time to keep track of the time... $time_diff = $date - $userCurrentBrowseTime; } if ($time_diff > 0) { $status = true; } else { $status = false; } return $status; } public function getForumShowTopicsUrl($forum_id, $forum_lang, $az = 'show_topics', $forum_alias='') { if (empty($forum_lang)) { $forum_url = $this->nikoniansconfig->forum->root_url->en; } else { $forum_lang = substr($forum_lang, 0, 2); if ($az == 'show_topics' and $forum_alias !='') { $forum_url = $this->nikoniansconfig->forum->root_url_new->$forum_lang . $forum_id . '/' . $forum_alias ; } else { $forum_url = $this->nikoniansconfig->forum->root_url->$forum_lang . '?az=' . $az. '&forum=' . $forum_id ; } } return $forum_url; } // For the time being only used at the box friends public function getFriendsActivity($username, $limit = 4) { // User friends activity array $activityArray = array(); // Activity counter when needed $total_cnt = 0; try { // We build an array with user friends $friendsArray = $this->getFriends($username); if (count($friendsArray) == 0) { return $activityArray; } // Find which friend has tomorrow birthday $g_id = 1; $sql = "SELECT g_id FROM dcuser2 WHERE username = " . $this->forum_db->quote($username); $row = $this->forum_db->fetchRow($sql); if (isset($row['g_id'])) { $g_id = $row['g_id']; } if ($g_id > 9) { foreach ($friendsArray as $friend) { $sql = "select username , birthdate , substr(birthdate, 6, 2) as bmonth , substr(birthdate, 9, 2) as bday from dcuser2 where username = " . $this->forum_db->quote($friend) . " and date_format( birthdate, '%m%d' ) = date_format( now() + interval 1 day , '%m%d' ) AND birthdate_visibility = 1 AND status='on' AND delete_flag='no' "; $row = $this->forum_db->fetchRow($sql); if (isset($row['username'])) { $activityArray[] = array(activity_id => -1, activity_username => $friend, activity_type => 'birthday', activity_date => date('Y-m-d H:i:s'), activity_url => '', activity_image => '', activity_varchar => $row['bmonth'], activity_varchar2 => $row['bday'], activity_int => ''); $total_cnt++; } } } // Fill in activities $sql = "SELECT * FROM sn_activities WHERE activity_id = 0"; foreach ($friendsArray as $friend) { $sql .= " OR activity_username = " . $this->forum_db->quote($friend); } $sql .= " ORDER BY activity_date DESC LIMIT " . $limit; $result = $this->forum_db->fetchAll($sql); foreach ($result as $row) { $activityArray[] = $row; } } catch (Exception $e) { return $activityArray; } return $activityArray; } public function getOnlyFriends($username) { $friends = array(); $sql = "SELECT requestor_username, friend_username, friendship_status FROM sn_friends WHERE requestor_username = " . $this->forum_db->quote($username) . " OR friend_username = " . $this->forum_db->quote($username); $result = $this->forum_db->fetchAll($sql); foreach($result as $row) { if($row['friendship_status'] == 1) { $friend = $row['friend_username']; $requestor = $row['requestor_username']; if($friend == $username) $name = $requestor; else $name = $friend; $friends[] = $name; } } return $friends; } public function getFriends($username, $filter = 'onlyAccepted', $rettype = 'onlyUsernames') { $retfriendsarr = array(); $mayUserFollow = $this->mayUserFollow($username); if ($mayUserFollow) { if ($filter == 'onlyAccepted') { $sql = "SELECT 'friends' as type, friend_username, requestor_username, friendship_status, friendship_date, id FROM sn_friends WHERE ((requestor_username = " . $this->forum_db->quote($username) . " OR friend_username = " . $this->forum_db->quote($username) . ") AND friendship_status= 1) UNION (SELECT 'follow' as type, followed_username as friend_username, follower_username as requestor_username, follow_status as friendship_status , follows_since as friendship_date, id FROM sn_followers WHERE (follower_username = " . $this->forum_db->quote($username) . " AND follow_status = 1 AND block_follow != 1) ) "; } else { $sql = "SELECT 'friends' as type, friend_username, requestor_username, friendship_status, friendship_date, id FROM sn_friends WHERE ( (requestor_username = " . $this->forum_db->quote($username) . " OR friend_username = " . $this->forum_db->quote($username) . ") UNION (SELECT 'follow' as type, followed_username as friend_username, follower_username as requestor_username, follow_status as friendship_status , follows_since as friendship_date, id FROM sn_followers WHERE (follower_username = " . $this->forum_db->quote($username) . " OR followed_username = " . $this->forum_db->quote($username) . ") ) "; } } else { $sql = "SELECT 'friends' as type, friend_username, requestor_username, friendship_status, friendship_date, id FROM sn_friends WHERE ((requestor_username = " . $this->forum_db->quote($username) . " OR friend_username = " . $this->forum_db->quote($username) . ") AND friendship_status= 1) "; } $result = $this->forum_db->fetchAll($sql); foreach($result as $row) { if ($rettype == 'onlyUsernames' or $rettype == 'idAndUsername') { if($row['type'] == 'friends') { $friend = $row['friend_username']; $requestor = $row['requestor_username']; if($friend == $username) $name = $requestor; else $name = $friend; $retfriendsarr[] = $name; } elseif ($row['type'] == 'follow') { $name = $row['friend_username']; $retfriendsarr[] = $name; } } else { $retfriendsarr[] = $row; } } if (($rettype == 'onlyUsernames' or $rettype == 'idAndUsername') and !empty($retfriendsarr)) { $tmp_array = array_unique($retfriendsarr); $retfriendsarr = array(); foreach($tmp_array as $name) { $retfriendsarr[] = $name; } } // We fill in with user ids if ($rettype == 'idAndUsername') { $tmp_array = $retfriendsarr; foreach($tmp_array as $friend_username) { $q_friend_id = "select id from dcuser2 where username = " . $this->forum_db->quote($friend_username); $row = $this->forum_db->fetchRow($q_friend_id); $friend_id = $row['id']; $retfriendsarr[$friend_id] = $friend_username; } } return $retfriendsarr; } public function getFavoriteForums($user_id, $language = 'en') { $forum_language = Website_Tool_NikoniansText::getForumLanguageFromShortLang($language); $sql = "SELECT fav.forum_id , fav.forum_order FROM favorite_forums fav join dcforum df on fav.forum_id = df.id WHERE fav.u_id = " . $this->forum_db->quote($user_id) . " AND df.language = '" . $forum_language . "' and df.status = 'on' ORDER BY fav.forum_order"; $result = $this->forum_db->fetchAll($sql); $ret_array = array(); foreach($result as $row) { $forum_id = $row['forum_id']; $ret_array[] = $forum_id; } return $ret_array; } function userHasNewInboxEntry($u_id) { if ($this->isGuestUser($u_id)) return 0; $sql = "SELECT UNIX_TIMESTAMP(date) AS date FROM dcinboxlog WHERE u_id = '$u_id' ORDER BY date DESC LIMIT 1 "; $row = $this->forum_db->fetchRow($sql); // $row['date'] has the last timestamp $lastdate = $row['date']; // Next get the latest inbox message date $sql = "SELECT UNIX_TIMESTAMP(date) AS date FROM dcinbox WHERE to_id = '$u_id' ORDER BY date DESC LIMIT 1 "; $row = $this->forum_db->fetchRow($sql); if ($lastdate < $row['date']) { return 1; } else { return 0; } } public function getImageStream($forum_lang = 'en', $user_id = 0, $limit = 15, $pageIndex = 0, $visitorUsername = '', $visitorGroupId = 1, $include_gallery = true, $use_favorite_forums = true) { $tmpImagesArray = array(); if ($pageIndex>0) { $pageIndex = $pageIndex * $limit; } try { $config = Pimcore_Tool_Frontend::getWebsiteConfig(); $except_forum_ids = $config->img_stream_except_forum_id; $add_sql = ''; if (!empty($except_forum_ids)) { $arr_except_forum_ids = explode(',', $except_forum_ids); $arr_sql_cond = array(); foreach ($arr_except_forum_ids as $forum_id) { $arr_sql_cond[] = "l.id<>'" . $forum_id . "'"; $arr_sql_cond[] = "l.parent_id<>'" . $forum_id . "'"; } $add_sql = ' and ' . implode(' and ', $arr_sql_cond); } $userAccess = Array(); if (isset($visitorGroupId) and $visitorGroupId > 1) { $result = $this->forum_db->fetchAll("SELECT forum_id FROM dcpflist WHERE u_id = '" . $user_id . "' "); foreach($result as $row) { $userAccess[$row['forum_id']] = 1; } // private forums $result = $this->forum_db->fetchAll("SELECT forum_id FROM dcmoderator WHERE u_id = '" . $user_id . "' "); foreach($result as $row) { $userAccess[$row['forum_id']] = 1; } } $requested_forum_lang = 'english'; if (empty($forum_lang)) { $requested_forum_lang = ''; } else if (strlen($forum_lang) == 2) { if ($forum_lang == 'de') { $requested_forum_lang = 'deutsch'; } else if ($forum_lang == 'fr') { $requested_forum_lang = 'french'; } } if (!$user_id) { $use_favorite_forums = false; } if ($use_favorite_forums) { // We check if user has any favorite forums $sql = "SELECT count(f.id) AS cnt FROM favorite_forums f JOIN dcforum l ON f.forum_id = l.id WHERE l.language = '" . $requested_forum_lang . "' and l.whitelisted = 'yes' and f.u_id = '" . $user_id . "'"; $row = $this->forum_db->fetchRow($sql); $fav_for_cnt = $row['cnt']; if (!$fav_for_cnt) { $use_favorite_forums = false; } } // Select uploaded images for the stream if ($use_favorite_forums) { $sql = "select u.id as img_photo_id, u.u_id, u.forum_id, u.mesg_id, u.file_type, u.date as img_date, l.language as forum_lang, l.type from favorite_forums f join dcupload u on f.forum_id = u.forum_id join dcforum l on l.id = f.forum_id where f.u_id = '" . $user_id . "' and l.status='on' and l.language = '$requested_forum_lang' $add_sql and u.mesg_id<>'' and u.file_type in ('jpg', 'png') and l.whitelisted = 'yes' order by u.id desc limit $pageIndex,$limit"; } elseif ($requested_forum_lang == '') { $sql = "select u.id as img_photo_id, u.u_id, u.forum_id, u.mesg_id, u.file_type, u.date as img_date, l.language as forum_lang, l.type from dcupload u join dcforum l on l.id = u.forum_id where u.mesg_id<>'' and l.status='on' and l.type<>'70' and l.type<>'65' $add_sql and u.file_type in ('jpg', 'png') and l.whitelisted = 'yes' order by u.id desc limit $pageIndex,$limit"; } else { $sql = "select u.id as img_photo_id, u.u_id, u.forum_id, u.mesg_id, u.file_type, u.date as img_date, l.language as forum_lang, l.type from dcupload u join dcforum l on l.id = u.forum_id where l.language = '$requested_forum_lang' and l.status='on' and l.type<>'70' and l.type<>'65' $add_sql and u.mesg_id<>'' and u.file_type in ('jpg', 'png') and l.whitelisted = 'yes' order by u.id desc limit $pageIndex,$limit"; } $result = $this->forum_db->fetchAll($sql); foreach($result as $row) { $tmpImagesArray[] = $row; } if ($tmpImagesArray) { // Fill in needed fields $imagesArray = array(); $forumAccessList = array(); foreach ($tmpImagesArray as $img_row) { // username of the uploader $sql = "SELECT id, username FROM dcuser2 WHERE id = '" . $img_row['u_id'] . "'"; $row = $this->forum_db->fetchRow($sql); $img_username = $row['username']; $img_userid = $row['id']; // topic subject $sql = "SELECT subject, top_id FROM " . $img_row['forum_id'] . "_mesg WHERE id = '" . $img_row['mesg_id'] . "'"; $row = $this->forum_db->fetchRow($sql); $img_title = $row['subject']; $img_top_id = $row['top_id']; $img_mesg_id = $img_row['mesg_id']; // build the image link $forum_lang = $img_row['language']; $img_src_url = self::buildAttachmentSrc($img_row['img_photo_id'], $img_row['forum_lang'], $img_row['file_type']); $topicDataArray = array( 'forum_id' => $img_row['forum_id'], 'mesg_id' => $img_mesg_id, 'top_id' => $img_top_id, 'forum_lang' => $img_row['forum_lang'], 'subject' => $row['subject'] ); $img_url = self::buildTopicUrl($topicDataArray); if (!isset($forumAccessList[$img_row['id']])) { if ($visitorGroupId == 99) { $forumAccessList[$img_row['id']] = 'RW'; } elseif ($img_row['type'] == '40') { if ($userAccess[$img_row['id']] > 0) { $forumAccessList[$img_row['id']] = 'RW'; } } elseif ($img_row['type'] == '30') { if ($visitorGroupId > 1) { $forumAccessList[$img_row['id']] = 'RW'; } } elseif ($img_row['type'] == '20' or $img_row['type'] == '35') { if (!$this->isGuestUser($visitorUsername) and $visitorGroupId > 0) { $forumAccessList[$img_row['id']] = 'RW'; } else { $forumAccessList[$img_row['id']] = 'R'; } } elseif ($img_row['type'] == '50') { if ($visitorGroupId >= 6 and $visitorGroupId != 9) { $forumAccessList[$img_row['id']] = 'RW'; } else { $forumAccessList[$img_row['id']] = 'R'; } } elseif ($img_row['type'] == '60') { if ($this->isGuestUser($visitorUsername) or $visitorGroupId < 6) { $forumAccessList[$img_row['id']] = 'R'; } else { $forumAccessList[$img_row['id']] = 'RW'; } } elseif ($img_row['type'] == '65') { if ($userAccess[$img_row['id']] > 0) { $forumAccessList[$img_row['id']] = 'RW'; } else { if ($this->isGuestUser($visitorUsername) or ($visitorGroupId < 7)) { $forumAccessList[$img_row['id']] = 'R'; } else { $forumAccessList[$img_row['id']] = 'RW'; } } } elseif ($img_row['type'] == '70') { if ($userAccess[$img_row['id']] > 0) { $forumAccessList[$img_row['id']] = 'RW'; } else { if ($this->isGuestUser($visitorUsername) or ($visitorGroupId < 8)) { $forumAccessList[$img_row['id']] = 'R'; } else { $forumAccessList[$img_row['id']] = 'RW'; } } } else { $forumAccessList[$img_row['id']] = 'RW'; } } if ($forumAccessList[$img_row['id']] == 'R' or $forumAccessList[$img_row['id']] == 'RW') { $photo_row = array( 'img_photo_id' => $img_row['img_photo_id'], 'img_date' => $img_row['img_date'], 'img_src_url' => $img_src_url, 'img_url' => $img_url, 'img_title' => $img_title, 'img_username' => $img_username, 'img_userid' => $img_userid, 'img_view_area' => 'forums', 'forum' => $img_row['forum_id'], 'post' => $img_row['top_id'] > 0 ? $img_row['top_id'] : $img_row['mesg_id'] ); $imagesArray[] = $photo_row; } } } /*------------------------------ gallery -------*/ if ($include_gallery) { $gallery_db = Website_Tool_Nikonians::getGalleryDB(); $sql = "SELECT p.id as img_photo_id, p.cat, p.bigimage as imagename, p.date as img_date, p.title, p.user FROM photos p JOIN categories c ON c.id=p.cat WHERE c.private='no' AND c.agecheck = 'no' AND p.approved = 1 GROUP BY p.user ORDER BY p.date DESC LIMIT $pageIndex,$limit"; $row = $gallery_db->fetchAll($sql); foreach ($row as $img_row) { $photo_row = array( 'img_photo_id' => $img_row['img_photo_id'], 'img_date' => date('Y-m-d h:m:s', $img_row['img_date']), 'img_src_url' => $this->nikoniansconfig->gallery->imgurl . $img_row['cat'] . '/' . $img_row['imagename'], 'img_url' => $this->nikoniansconfig->gallery->showphoto . $img_row['img_photo_id'] . '/', 'img_title' => $img_row['title'], 'img_username' => $img_row['user'], 'img_view_area' => 'gallery' ); $imagesArray[] = $photo_row; } } function sorta($a, $b) { if ($a['img_date'] < $b['img_date']) return 1; } usort($imagesArray, 'sorta'); } catch (Exception $e) { return $imagesArray; } return $imagesArray; } /* $topicDataArray need next keys: forum_id, top_id, mesg_id, subject, forum_lang */ public function buildTopicUrl_old($topicDataArray) { if ($topicDataArray['top_id'] > 0) { $topic_id = $topicDataArray['top_id']; } else { $topic_id = $topicDataArray['mesg_id']; } $the_lang = ''; if ($topicDataArray['forum_lang'] != 'english') { $the_lang = substr(strtolower($topicDataArray['forum_lang']),0,2); } $forumBaseURL = $this->nikoniansconfig->forum->root_url->en; if ($the_lang == 'de') { $forumBaseURL = $this->nikoniansconfig->forum->root_url->de; } else if ($the_lang == 'fr') { $forumBaseURL = $this->nikoniansconfig->forum->root_url->fr; } $text_tool = new Website_Tool_Text(); $seo_subject = $text_tool->nik_get_seo_string($topicDataArray['subject']); if (empty($seo_subject)) { $seo_subject = 'az=show_topic'; } // TODO decide if topic url or what exactly //$show_it_url = $forumBaseURL . "?az=show_mesg&forum=".$topicDataArray['forum_id']."&topic_id=".$topic_id."&mesg_id=".$topicDataArray['id']; $show_it_url = $forumBaseURL . "?" . $seo_subject . "&forum=".$topicDataArray['forum_id']."&topic_id=".$topic_id."&mesg_id=".$topicDataArray['mesg_id']; return $show_it_url; } public function buildTopicUrl($topicDataArray) { if ($topicDataArray['top_id'] > 0) { $topic_id = $topicDataArray['top_id']; } else { $topic_id = $topicDataArray['mesg_id']; } $the_lang = ''; if ($topicDataArray['forum_lang'] != 'english') { $the_lang = substr(strtolower($topicDataArray['forum_lang']),0,2); } $forumBaseURL = $this->nikoniansconfig->forum->root_url_new->en; if ($the_lang == 'de') { $forumBaseURL = $this->nikoniansconfig->forum->root_url_new->de; } else if ($the_lang == 'fr') { $forumBaseURL = $this->nikoniansconfig->forum->root_url_new->fr; } $text_tool = new Website_Tool_Text(); $seo_subject = $text_tool->nik_get_seo_string($topicDataArray['subject']); if (empty($seo_subject)) { $seo_subject = 'az=show_topic'; } // TODO decide if topic url or what exactly //$show_it_url = $forumBaseURL . "?az=show_mesg&forum=".$topicDataArray['forum_id']."&topic_id=".$topic_id."&mesg_id=".$topicDataArray['id']; $show_it_url = $forumBaseURL . "topic/" . $topicDataArray['forum_id']. "-" . $topic_id . "-" . $topicDataArray['mesg_id'] . "/" . $seo_subject . "#" . $topicDataArray['mesg_id']; return $show_it_url; } public function buildAttachmentSrc($photo_id, $language, $filetype) { $the_lang = substr(strtolower($language),0,2); $img_src_base = $this->nikoniansconfig->forum->attachment_url->en; if ($the_lang == 'de') { $img_src_base = $this->nikoniansconfig->forum->attachment_url->de; } else if ($the_lang == 'fr') { $img_src_base = $this->nikoniansconfig->forum->attachment_url->fr; } $img_src = $img_src_base . '/' . $photo_id . '.' . $filetype; return $img_src; } // @TODO need change that also accepts and filter language public function getAllImagesStream($forum_lang = 'english', $limit = 6) { // User friends activity array $imagesArray = array(); try { $sql = "SELECT * FROM nikonians_img_stream ORDER BY img_id DESC LIMIT $limit"; $result = $this->forum_db->fetchAll($sql); $text_tool = new Website_Tool_Text(); foreach($result as $row) { $imagesArray[] = $row; //error_log($text_tool->nik_get_seo_string($row['img_title'])); } } catch (Exception $e) { return $imagesArray; } return $imagesArray; } // It returns the number of days in the past we get forum latest posts public function getForumLatency($language) { $conf_key_prefix = 'forum_latency_'; $forumLatency = ''; $website_config = Pimcore_Tool_Frontend::getWebsiteConfig(); if ($language == 'en' || $language == 'de' || $language == 'fr') { $conf_key = $conf_key_prefix . $language; $forumLatency = $website_config->$conf_key; } else { $forumLatency = $website_config->forum_default_latency; } if (empty($forumLatency)) { $forumLatency = 90; } return $forumLatency; } /** * Get frontpage forum posts * * @param int $forumPostsLimit How many the most recent posts to return * @return array */ public function getForumLatestPosts($forumPostsLimit, $forumLatency, $blacklisted, $short_language = 'en') { $language = 'english'; $forumBaseURL = $this->nikoniansconfig->forum->root_url->en; if ($short_language == 'de') { $language = 'deutsch'; $forumBaseURL = $this->nikoniansconfig->forum->root_url->de; } else if ($short_language == 'fr') { $language = 'french'; $forumBaseURL = $this->nikoniansconfig->forum->root_url->fr; } $blacklisted = explode(',', $blacklisted); if (sizeof($blacklisted) > 0) { $whereBlacklisted = ''; foreach ($blacklisted as $blacklistedForumID) { $whereBlacklisted .= " AND forum_id != '" . $blacklistedForumID . "'"; } } $timeLimit = Zend_Date::now()->subHour($forumLatency)->toString('Y-MM-dd H:m:s'); $sql = "SELECT *, dcforum.language, dcforum.type FROM latest_forum_posts, dcforum WHERE dcforum.language = '" . $language . "' AND latest_forum_posts.mesg_date >= '" . $timeLimit . "' AND dcforum.status='on' AND (dcforum.type = '10' OR dcforum.type = '20' OR dcforum.type = '35' OR dcforum.type = '50') " . $whereBlacklisted . " AND latest_forum_posts.forum_id=dcforum.id ORDER BY latest_forum_posts.mesg_date DESC LIMIT 0," . $forumPostsLimit; $forums = $this->forum_db->fetchAll($sql); $postsCounter = 0; $posts = array(); foreach ($forums as $forum) { $posts[$postsCounter]['original_subject'] = $forum['top_subject']; $posts[$postsCounter]['original_author'] = $forum['top_author']; $posts[$postsCounter]['forum_id'] = $forum['forum_id']; $posts[$postsCounter]['subject'] = $forum['mesg_subject']; $posts[$postsCounter]['topic_replies'] = $forum['replies']; $posts[$postsCounter]['message_author'] = $forum['mesg_author']; $posts[$postsCounter]['mesg_date'] = $forum['mesg_date']; $posts[$postsCounter]['mesg_date_sec'] = strtotime($forum['mesg_date']); $posts[$postsCounter]['mesg_id'] = $forum['mesg_id']; $posts[$postsCounter]['parent_id'] = $forum['parent_id']; if ($forum['top_id'] != 0) { $posts[$postsCounter]['top_id'] = $forum['top_id']; } else { $posts[$postsCounter]['top_id'] = $forum['mesg_id']; } $posts[$postsCounter]['post_url'] = $forumBaseURL . "?az=show_topic&forum=" . $forum['forum_id'] . "&topic_id=" . $posts[$postsCounter]['top_id'] . "&mode=full"; $postsCounter++; } return $posts; } // This function returns value of a setup field from dcp.dcsetup table public function getSetupValue($var_key) { $q = "SELECT var_value FROM dcsetup WHERE var_key = " . $this->forum_db->quote($var_key) ; $var_value = ''; $result = $this->forum_db->fetchAll($q); foreach($result as $row) { $var_value = $row['var_value']; } return $var_value; } // This function array with ALL details of an attachment public function getForumAttMainDetails($imgId) { $q = "SELECT * FROM dcupload WHERE id = " . $this->forum_db->quote($imgId); $row = $this->forum_db->fetchRow($q); if (empty($row['id'])) { return $row; } // We select forum language $sql = "SELECT language , whitelisted FROM dcforum WHERE id = " . $this->forum_db->quote($row['forum_id']); $frow = $this->forum_db->fetchRow($sql); $row['att_lang'] = $frow['language']; // We select topic subject $sql = "SELECT subject FROM " . $row['forum_id'] . "_mesg WHERE id = " . $this->forum_db->quote($row['mesg_id']); $trow = $this->forum_db->fetchRow($sql); $row['att_whitelisted'] = $frow['whitelisted']; $row['att_subject'] = $trow['subject']; $row['att_lang'] = $frow['language']; $row['img_url'] = $this->buildAttachmentSrc($row['id'], $row['att_lang'], $row['file_type']); $row['img_link_url'] = $this->buildTopicUrl(array('forum_id'=>$row['forum_id'] , 'top_id'=>$row['mesg_id'] , 'mesg_id'=>$row['mesg_id'] , 'forum_lang'=>$row['att_lang'] , 'subject'=>$row['att_subject'] )); return $row; } // This function array with details from dcupload table for an image id public function getForumUploadAtttDetails($imgId) { $q = "SELECT * FROM dcupload WHERE id = " . $this->forum_db->quote($imgId); $row = $this->forum_db->fetchRow($q); return $row; } // This function has as parameter a forum attachment url or image id public function getForumAttUsername($img) { $username = ''; if (strpos($img, '.' ) === false and strpos($img, '/' ) === false) { $imgId = $img; } else if (strpos($img, '/' ) === false) { $imgId = substr($img, 0, strpos($img, '.' )); } else { $imgId = $img; $imgId = substr($imgId, 0, strrpos($img, '.' )); $imgId = substr($img, strrpos($img, '/' ) + 1); } $attRow = self::getForumUploadAtttDetails($imgId); if (!$attRow['u_id']) { return $username; } $q = "SELECT username FROM dcuser2 WHERE id = " . $this->forum_db->quote($attRow['u_id']); $row = $this->forum_db->fetchRow($q); if (!$row['username']) { return $username; } return $row['username']; } public function isShowLobbySlider($u_id) { $q = "SELECT show_lobby_slider FROM dcuser2 WHERE id = " . $this->forum_db->quote($u_id); $row = $this->forum_db->fetchRow($q); if ($row['show_lobby_slider']) { return $row['show_lobby_slider']; } else { return 'yes'; } } function get_forum_alias($str, $max_length = 0) { $seo_str = trim($str); $seo_str = str_replace(array('RE: '), '', $seo_str); // replace one or multiple spaces into single dash (-) $seo_str = preg_replace('!\s+!', '-', $seo_str); $validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_"; $encoding = 'UTF-8'; $seo_str = htmlentities($seo_str, ENT_COMPAT, $encoding); $seo_str = preg_replace('/&([a-zA-Z])(uml);/','$1e',$seo_str); $seo_str = preg_replace('/&([s|S])(zlig);/','$1s',$seo_str); $seo_str = preg_replace('/&([a-zA-Z])(acute|grave|circ|tilde);/','$1',$seo_str); $seo_str = html_entity_decode($seo_str); $seo_parts = array(); for ($i = 0; $i < strlen($seo_str); $i++) { if (strpos($validChars, $seo_str[$i]) !== false) { $seo_parts[] = $seo_str[$i]; } else { $seo_parts[] = '-'; } } $seo_str = strtolower(implode("", $seo_parts)); // replace many dashes with one dash $seo_str = preg_replace('/-+/', '-', $seo_str); // Truncate it if ($max_length == 0) { $max_length = 55; } if ($max_length > 0 and strlen($seo_str) > $max_length) { $seo_str = substr($seo_str,0,$max_length); } $seo_str = str_replace(array(" ", ",", "&", "'", ":", "/", "(", ")", "!"), "-", $seo_str); $seo_str = str_replace("--", "-", $seo_str); $seo_str = urlencode($seo_str); return $seo_str; } public function getGroupIcon ($group_id, $show_text='yes', $show_link = 'yes') { $nikoniansconfig = $this->nikoniansconfig; $group_icon = ""; $extra_text = ''; // localize the images based on language // logo_silver_trial_small_fr.gif // all icons have extension .gif $explhtml = "server->root_url->en . "/html/about/member_icon_explanation.html\">%1%"; // This is the link to explanation page of icons $imggif=''; if ($group_id > 5 and $group_id < 10) { $imggif = 'group_icon_' . $group_id; } elseif ($group_id == 10) { $imggif = 'team_icon'; } elseif ($group_id == 20) { $imggif = 'moderator_icon'; } elseif ($group_id == 99) { $imggif = 'admin_icon'; } if ($imggif) { $imggif = $this->getSetupValue($imggif); /*$imglanggif = get_this_lang_image($imggif); if (does_image_exists($imglanggif, $nikoniansconfig->forum->root_dir->en.'images')) { $imggif = $imglanggif; } $imghtml = get_image_with_tooltip($imggif); */ $imghtml = ''; // Force not show of extra text if ($show_link == 'yes') { $group_icon = str_replace('%1%',$imghtml, $explhtml); } else { $group_icon = $imghtml; } } return $group_icon; } // Fields needed when we want check icons we show for a user public function getUserIconsRelatedFields($user_id) { $row = array(); try { if (preg_match ("/^([0-9]+)$/", $user_id)) { $query_cond = "id = " . $this->forum_db->quote($user_id); } else { $query_cond = "username = " . $this->forum_db->quote($user_id); } $sql = "SELECT id, username, name, g_id, pg, pf, uc, pb, ua, ub, ug, status, delete_flag, allow_friends, up from dcuser2 WHERE $query_cond"; $row = $this->forum_db->fetchRow($sql); } catch (Exception $e) { return $row; } return $row; } // Check if user follow the other user public function doesUserFollows($follower_username,$followed_username) { $row = array(); try { $sql = "SELECT follower_username, followed_username, follow_status from sn_followers WHERE follower_username = " . $this->forum_db->quote($follower_username) . " AND followed_username = " . $this->forum_db->quote($followed_username); $row = $this->forum_db->fetchRow($sql); if (isset($row['follow_status']) and $row['follow_status'] == 1) { return true; } } catch (Exception $e) { return false; } return false; } // Check if user may use follow functionality public function mayUserFollow($user_id) { $row = array(); try { if (preg_match ("/^([0-9]+)$/", $user_id)) { $query_cond = "id = " . $this->forum_db->quote($user_id); } else { $query_cond = "username = " . $this->forum_db->quote($user_id); } $sql = "SELECT g_id , delete_flag, status from dcuser2 WHERE " . $query_cond; $row = $this->forum_db->fetchRow($sql); if (isset($row['g_id']) and $row['g_id'] > 9 and $row['delete_flag'] == 'no' and $row['status'] == 'on') { return true; } else { return false; } } catch (Exception $e) { return false; } return false; } // Check if user may use follow functionality public function mayUserBeFollowed($user_id) { $row = array(); try { $query_cond = ''; if (preg_match ("/^([0-9]+)$/", $user_id)) { $query_cond = "id = " . $this->forum_db->quote($user_id); } else { $query_cond = "username = " . $this->forum_db->quote($user_id); } $sql = "SELECT id, delete_flag, status, up from dcuser2 WHERE " . $query_cond; $row = $this->forum_db->fetchRow($sql); if ($row['up'] == "yes" and $row['delete_flag'] == 'no' and $row['status'] == 'on') { return true; } } catch (Exception $e) { return false; } return false; } /* This function returns true if the user u_id may recommend user recommend_user_id is_guest refers to u_id - is 'yes' if the user u_id is not logged in */ function showRecommendIcon($u_id, $is_guest = 'yes', $recommend_user_id) { if ( $this->forum_setup_array['user_rating'] == 'yes' and $this->userMayRecommend($u_id, $is_guest) and $this->userCanBeRecommended($recommend_user_id) and $u_id != $recommend_user_id and !$this->userAlreadyRecommended($u_id, $recommend_user_id) ) { return true; } else { return false; } } ///////////////////////////////////////////////////////////////// // // function returns 1 if this user may recommend other users // ///////////////////////////////////////////////////////////////// function userMayRecommend($u_id, $is_guest = 'yes') { $user_row = $this->getUserIconsRelatedFields($u_id); $status = $user_row['status']; $delete_flag = $user_row['delete_flag']; $ug = $user_row['ug']; if ($this->forum_setup_array['allow_disable_user_rating'] == 'yes') { if ($is_guest != 'yes' and $ug == 'yes' and $status == 'on' and $delete_flag == 'no') { return 1; } else { return 0; } } else { if ($is_guest != 'yes' and $status == 'on' and $delete_flag == 'no') { return 1; } else { return 0; } } } /* It returns true if this user can be recommended by any other user */ function userCanBeRecommended($u_id) { $user_row = $this->getUserIconsRelatedFields($u_id); $status = $user_row['status']; $delete_flag = $user_row['delete_flag']; $ug = $user_row['ug']; if ($this->forum_setup_array['allow_disable_user_rating'] == 'yes') { if ($ug == 'yes' and $status == 'on' and $delete_flag == 'no') { return 1; } else { return 0; } } else { if ($status == 'on' and $delete_flag == 'no') { return 1; } else { return 0; } } } /* * * alreadyRated($u_id, $r_id) - returns TRUE if user $r_id rated user $u_id * */ function userAlreadyRecommended($r_id,$u_id) { // Check and make sure this user didn't already rated this user $q = "SELECT count(*) as cnt FROM dcuserrating WHERE r_id = '$r_id' AND u_id = '$u_id' "; $row = $this->forum_db->fetchRow($q); if ($row['cnt'] > 0) { return true; } else { return false; } } //var $friendshipStatuses = array($lang['friend_pending'], $lang['friend_approved'], $lang['friend_denied'], $lang['friend_deleted']); // Returns true if the users are already friends public function usersAlreadyFriends($username, $friend_username) { $sql = "SELECT count(*) as cnt from sn_friends WHERE friendship_status != 3 AND ((requestor_username = " . $this->forum_db->quote($username) . " AND friend_username = " . $this->forum_db->quote($friend_username) . ") OR (requestor_username = " . $this->forum_db->quote($friend_username) . " AND friend_username = " . $this->forum_db->quote($username) . ") ) "; $row = $this->forum_db->fetchRow($sql); if ($row['cnt'] > 0) { return true; } else { return false; } } // Returns true if we show add friend public function showAddFriend($username, $friend_username) { $ret = $this->usersAlreadyFriends($username, $friend_username); $ret = !$ret; return $ret; } public function getIntroMessage($message, $limit = 100) { $message = htmlspecialchars($message); $message = preg_replace("/\r/","",$message); $tags_array = Array("[b]", "[/b]", "[i]", "[/i]", "[u]", "[/u]", "[h1]", "[/h1]", "[h2]", "[/h2]", "[h4]", "[/h4]", "[/font]", "[ul]", "[li]", "[/li]", "[/ul]", "[ol]", "[li]", "[/li]", "[/ol]", "[tr]", "[td]", "[/td]", "[td]", "[/td]", "[/tr]", "[/table]", "[code]", "[/code]"); $message = str_replace($tags_array, "", $message); if (preg_match_all('~\[link:(.+?)\]~isU', $message, $tags_array)) { $message = str_replace($tags_array[0], "", $message); } if (preg_match_all('~\[wiki:(.+?)\]~isU', $message, $tags_array)) { $message = str_replace($tags_array[0], "", $message); } if (preg_match_all('~\[imglink:(.+?)\]~isU', $message, $tags_array)) { $message = str_replace($tags_array[0], "", $message); } if (preg_match_all('~\[font(.+?)\]~isU', $message, $tags_array)) { $message = str_replace($tags_array[0], "", $message); } if (preg_match_all('~\[table(.+?)\]~isU', $message, $tags_array)) { $message = str_replace($tags_array[0], "", $message); } if ( (strlen($message) > $limit) and ($limit > 0) ) { $message = substr($message, 0, $limit-3) . '...'; } return $message; } function seoGetForumUrl($forum_id) { $forum_url = ''; try { $q = "SELECT id, name, language, short_name FROM dcforum WHERE id = " . $this->forum_db->quote($forum_id); $row = $this->forum_db->fetchRow($q); if ($row['id']) { $website_text_tool = new Website_Tool_Text(); $seo_name = $website_text_tool->nik_get_seo_string($row['short_name']); $nikonians_tool_text = new Website_Tool_NikoniansText(); $short_language = $nikonians_tool_text->getShortLangFromForumLanguage($row['language']); $nikoniansconfig = $this->nikoniansconfig; $forum_url = $nikoniansconfig->server->root_url->$short_language . '/forum/' . $forum_id . '/' . $seo_name; } } catch (Exception $e) { echo $e->getException(); } return $forum_url; } public function get_announcements_new( $user_id, $language ) { $lang = Website_Tool_NikoniansText::getForumLanguageFromShortLang($language); $announcements = array(); $sql = "SELECT id, subject, message, image, buttonlink, UNIX_TIMESTAMP(a_date) as a_date FROM dcannouncement WHERE TO_DAYS(e_date) > TO_DAYS(NOW()) AND language = ". $this->forum_db->quote($lang) ." ORDER BY a_date ASC "; $result = $this->forum_db->fetchAll($sql); $i = 0; $cookie_arr = array(); if (isset($_COOKIE['notifications'])) { $cookie_arr = json_decode($_COOKIE['notifications'], true); } foreach ($result as $row) { $guest_user_show = false; if ($user_id=='') { if (in_array($row['id'], $cookie_arr)) { $guest_user_show = false; } else { $guest_user_show = true; } } if ($guest_user_show or $this->check_new_announcement($user_id, $row['id'], 'yes')) { if ($row['buttonlink']=='') { $button_link = '#'; $button_label = 'Close'; $onclick = 'onclick="$(this).parents(\'.notification\').find(\'.close-notifications\').click();"'; } else { $button_link = $row['buttonlink']; $button_label = 'Download'; $onclick = ''; } $hidden = ''; if ($i > 0) { $hidden = 'style="display:none;"'; } $announcement = '

'.$row['message'].'

X
'; $announcements[] = $announcement; $i++; } } return $announcements; } function check_new_announcement($user_id, $ann_id, $showed) { if ($user_id=='') { return false; } $sql = "SELECT id FROM users_announcements WHERE announcement_id = ".$ann_id." AND user_id =".$user_id." AND showed = 'yes'"; $result = $this->forum_db->fetchAll($sql); $row = $result[0]['id']; if ($row) { return false; } else { return true; } } function get_like_status($forum_id, $post_id, $user_id) { $sql = "SELECT status FROM likes WHERE forum_id = ". $forum_id. " AND post_id = ". $post_id. " AND user_id = '". $user_id. "'"; $row = $this->forum_db->fetchRow($sql); if ($row) { if ($row['status']=='1') { return '1'; } else { return '-1'; } } else { return '0'; } } function get_likes_count($forum_id, $post_id) { $sql = "SELECT count(*) as count_likes FROM likes WHERE forum_id = '". $forum_id. "' AND post_id = '". $post_id. "' AND status = '1'"; $row = $this->forum_db->fetchRow($sql); return $row['count_likes']; } function get_forum_url ($type, $lang, $forum_id, $topic_id, $mess_id, $subject) { $url = ''; $flang = $lang; if (empty($flang)) { // We select forum language $sql = "SELECT f.language FROM dcforum AS f WHERE f.id = " . $this->forum_db->quote($forum_id); $row = $this->forum_db->fetchRow($sql); $flang = $row['language']; $flang = substr($flang,0,2); } $base_url = $this->nikoniansconfig->forum->root_url_new->$flang; if ( $type == 'topic' ) { $url = $base_url . 'topic/' . $forum_id . '-' . $topic_id . '-' . $mess_id . '/' . self::get_forum_alias($subject) . '#' . $mess_id; } return $url; } function get_user_data($username) { $q = "SELECT id, username, name, g_id, pj, portfolio, portfolio_text, portfolio_title, email , ph, uw, status, delete_flag , contact_option FROM dcuser2 WHERE username = " . $this->forum_db->quote($username); $userArray = array(); $row = $this->forum_db->fetchRow($q); if (isset($row['id']) and $row['id'] > 0) { $userArray['id'] = $row['id']; $userArray['username'] = $row['username']; $userArray['name'] = $row['name']; $userArray['g_id'] = $row['g_id']; $userArray['comment'] = $row['pj']; $userArray['portfolio'] = $row['portfolio']; $userArray['portfolio_text'] = $row['portfolio_text']; $userArray['portfolio_title'] = $row['portfolio_title']; $userArray['email'] = $row['email']; $userArray['ph'] = $row['ph']; $userArray['uw'] = $row['uw']; $userArray['status'] = $row['status']; $userArray['delete_flag'] = $row['delete_flag']; $userArray['contact_option'] = $row['contact_option']; } return $userArray; } function update_portfolio_title($userid,$title) { $q = "update dcuser2 set portfolio_title = ". $this->forum_db->quote($title) . " WHERE id = " . $this->forum_db->quote($userid); $this->forum_db->query($q); return 'success'; } function update_portfolio_comment($userid,$descr) { $q = "update dcuser2 set portfolio_text = ". $this->forum_db->quote($descr) . " WHERE id = " . $this->forum_db->quote($userid); $this->forum_db->query($q); return 'success'; } function enable_portfolio($userid) { if (!$this->may_have_portfolio($userid)) { return 'deny'; } $q = 'update dcuser2 set portfolio = "yes" WHERE id = ' . $this->forum_db->quote($userid); $this->forum_db->query($q); return 'success'; } public function may_have_portfolio($userid) { $sql = "SELECT g_id, status, delete_flag FROM dcuser2 WHERE id=" . $this->forum_db->quote($userid); $row = $this->forum_db->fetchRow($sql); if ($row['status'] == 'on' and $row['delete_flag'] == 'no' and $row['g_id'] > 6) { return 1; } return 0; } public function does_has_portfolio($userid) { $sql = "SELECT portfolio FROM dcuser2 WHERE id=" . $this->forum_db->quote($userid); $row = $this->forum_db->fetchRow($sql); if ($row['portfolio'] == 'yes') { return 1; } return 0; } function get_follow_users($user) { $escuser = $this->forum_db->quote($user); $q = "SELECT f.friend_username AS username FROM sn_activities a, sn_friends f WHERE f.friend_username = a.activity_username AND f.requestor_username=$escuser AND f.friendship_status = 1 AND a.activity_url <> '' AND a.activity_type IN (3,4) AND a.activity_username != $escuser UNION SELECT f.requestor_username AS username FROM sn_activities a, sn_friends f WHERE f.requestor_username = a.activity_username AND f.friend_username=$escuser AND f.friendship_status = 1 AND a.activity_url <> '' AND a.activity_type IN (3,4) AND a.activity_username != $escuser UNION DISTINCT SELECT f.followed_username AS username FROM sn_activities a, sn_followers f WHERE f.followed_username = a.activity_username AND f.follower_username=$escuser AND a.activity_url <> '' AND a.activity_type IN (3,4) AND a.activity_username != $escuser AND f.follow_status = 1 AND f.block_follow != 1 ORDER BY username ASC"; return $this->forum_db->fetchAll($q); } function send_message($message_type, $user_to, $user_from, $message, $subject = 'New message', $ecq_id = 0) { $ret = false; try { $user_to = $this->get_user_data($user_to); $user_from = $this->get_user_data($user_from); if (empty($user_to) or empty($user_from)) { return $ret; } if ($message_type == 'pm') { $message = $this->forum_db->quote($message); $subject = $this->forum_db->quote($subject); $ecq_id = $this->forum_db->quote($ecq_id); $q = "INSERT INTO dcinbox (to_id, from_id, subject, message, date, ecq_id) VALUES(" . $user_to['id'] . ", " . $user_from['id'] . ", " . $subject . ", " . $message . ", NOW(), $ecq_id) "; $this->forum_db->query($q); $ret = true; } elseif ($message_type == 'mail') { $locale = Zend_Registry::get("Zend_Locale"); $t = Zend_Registry::get("Zend_Translate"); $t->setLocale($locale); $subject = htmlspecialchars($subject); $message .= "\r\n\n" . str_replace('%1%', $user_from['username'], $t->translate('mess_from_user_footer')); if ($user_from['g_id'] < 10 ) { $message .= "\r\n" . $t->translate('mess_from_user_disclaimer'); } $message = htmlspecialchars($message); $header = "From: " . $user_from['email'] . "\r\n"; $header .= "Reply-TO: " . $user_from['email'] . "\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: text/plain; charset=utf8\r\n"; $header .= "X-Priority: 3\r\n"; $header .= "X-Mailer: PHP / " . phpversion() . "\r\n"; $ret = mail($user_to['email'], $subject, $message, $header); } } catch (Exception $e) { } return $ret; } function get_user_pref_language($username) { $u_q = "SELECT uw FROM dcuser2 where username = " . $this->forum_db->quote($username); $u_row = $this->forum_db->fetchRow($u_q); $pref_lang = $u_row['uw']; if (empty($pref_lang) or $pref_lang == 'french') { $pref_lang = 'english'; } elseif ($pref_lang != 'english' and $pref_lang != 'deutsch') { $pref_lang = 'english'; } return $pref_lang; } function send_mail_using_template($notice_key, $username, $email_from='', $params='') { $q = "SELECT id, username, name, email FROM dcuser2 WHERE username = " . $this->forum_db->quote($username); $row = $this->forum_db->fetchRow($q); $name = $row['name']; $to = $row['email']; if (empty($from_email)) { $from = $this->forum_setup_array['auth_admin_email_address']; } else { $from = $email_from; } if (empty($from_email)) { return false; } $row = $this->get_message_notice($notice_key, '', $username); if (empty($row)) { return false; } $subject = $row['var_subject']; $message = $row['var_message']; $message = $this->replace_place_holders_in_mess($message, $username, $name); $header = "From: $from\r\n"; $header .= "Reply-To: $from\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: text/plain; charset=utf8\r\n"; $header .= "X-Priority: 3\r\n"; $header .= "X-Mailer: PHP / " . phpversion() . "\r\n"; $extra = ''; if (isset($row['mail_envelope_address']) and !empty($row['mail_envelope_address'])) { $envelopeEmailFrom = $row['mail_envelope_address']; $extra = "-f" . $envelopeEmailFrom; } $is_sent = $this->nik_mail($to, $subject, $message, $header, $extra, $notice_key); return $is_sent; } // start This functions must behave and be same as under forums and scripts function get_message_notice($type, $pref_lang = '', $username = '') { if (empty($pref_lang) and !empty($username)) { $pref_lang = $this->get_user_pref_language($username); } if (empty($pref_lang)) $pref_lang = 'english'; $q = "SELECT * FROM dcnotice WHERE var_key = " . $this->forum_db->quote($type) . " AND var_lang = " . $this->forum_db->quote($pref_lang); $row = $this->forum_db->fetchRow($q); if (isset($row['mail_envelope_key']) and !empty($row['mail_envelope_key'])) { $a_q = "SELECT var_value FROM dcsetup WHERE var_key = " . $this->forum_db->quote($row['mail_envelope_key']); $a_row = $this->forum_db->fetchRow($a_q); if (isset($a_row['var_value']) and !empty($a_row['var_value'])) { $row['mail_envelope_address'] = $a_row['var_value']; } } return $row; } function replace_place_holders_in_mess($message, $username, $name = '') { $message = preg_replace("/#USERNAME#/",$username,$message); $enc_username = urlencode($username); $message = preg_replace("/#ENCUSERNAME#/",$enc_username,$message); $message = preg_replace("/#ENCODEDUNAME#/",$enc_username,$message); if (empty($name) and (strpos($message, '#NAME#') !== false or strpos($message, '#NAMEUSERNAME#') !== false)) { $q = "SELECT name FROM dcuser2 WHERE username = " . $this->forum_db->quote($username); $row = $this->forum_db->fetchRow($q); $name = $row['name']; } $message = preg_replace("/#NAME#/",$name,$message); $message = preg_replace("/#NAMEUSERNAME#/",$name. ' (' . $username . ')',$message); if (strpos($message, '#UNSUBSCRIBEURL#') !== false) { $unsubscribe_url = $this->get_unsubscribe_url_for_user($username); $message = preg_replace("/#UNSUBSCRIBEURL#/", $unsubscribe_url, $message); } return $message; } function build_unsubscribe_url_w_hash($unsubscribe_hash) { $unsubscribe_url = $this->nikoniansconfig->server->root_url->en ."/forums/?az=nik_user_mails_unsubscribe&for=" . urlencode($unsubscribe_hash); return $unsubscribe_url; } function get_unsubscribe_url_for_user($username) { $unsubscribe_hash = $this->get_unsubscribe_mails_hash($username); $unsubscribe_url = $this->build_unsubscribe_url_w_hash($unsubscribe_hash); return $unsubscribe_url; } // Function get hash key based on username if any function get_unsubscribe_mails_hash($username) { $q = "SELECT id, unsubscribe_mails_hash FROM dcuser2 WHERE username=" . $this->forum_db->quote($username); $row = $this->forum_db->fetchRow($q); $unsubscribe_mails_hash = ''; $userid = 0; if ($row['id']) { $userid = $row['id']; $unsubscribe_mails_hash = $row['unsubscribe_mails_hash']; } if (empty($unsubscribe_mails_hash)) { $hash = $this->generate_unsubscribe_mails_hash($userid); } else { $hash = $unsubscribe_mails_hash; } return $hash; } // Function to generate a hash key based on user id function generate_unsubscribe_mails_hash($userid) { $encrypted = ''; $data = ''; $listAlpha = 'abcdefghijklmnpqrstuvwxyz0123456789'; // eliminated the letter o $add_hash = str_shuffle(substr(str_shuffle($listAlpha),0,10)); $data .= $add_hash; $add_hash = $userid + 5643; $data .= $add_hash; $encrypted = base64_encode(convert_uuencode($data)); $update_sql = "UPDATE dcuser2 SET unsubscribe_mails_hash = ". $this->forum_db->quote($encrypted) . " WHERE id='$userid'"; $this->forum_db->query($update_sql); return $encrypted; } function nik_mail($to,$subject,$message,$header='',$extra='',$emailtype='',$params= array()) { $is_sent = mail($to,$subject,$message,$header,$extra); return $is_sent; } // stop // This function returns fist image from a forum post f any image public function getFirstImageFromForumPost($forum_id, $mesg_id, $gallRel = '') { $img = ''; $result = array(); try { $tbl_forum = $forum_id . '_mesg'; $sql = "SELECT message FROM $tbl_forum WHERE id = " . $this->forum_db->quote($mesg_id); $row = $this->forum_db->fetchRow($sql); if ($row) { $message = $row['message']; $searchimglink = strpos($message, '[imglink:'); if ($searchimglink !== false) { $endimglink = strpos($message, ']', $searchimglink); if ($endimglink !== false) { $tagimglink = substr($message, $searchimglink, ($endimglink - $searchimglink + 1)); $idimg = str_replace(array('[imglink:', ']'), '', $tagimglink); if (empty($gallRel)) { $gallRel = new Website_Tool_Nikonians_Gallery(); } $img = $gallRel->getImageDetails($idimg); } } } } catch (Exception $e) { return $img; // We may here silently die } return $img; } public function getWorksafeStatus($user) { $sql = "SELECT work_safe_mode FROM dcuser2 WHERE id=" . $user; $row = $this->forum_db->fetchRow($sql); if ($row['work_safe_mode'] == 'yes') { return 1; } return 0; } public function toggleWorksafeStatus($user) { $sql = "SELECT work_safe_mode FROM dcuser2 WHERE id=" . $user; $row = $this->forum_db->fetchRow($sql); $new_work_safe_mode = 'yes'; if ($row['work_safe_mode'] == 'yes') { $new_work_safe_mode = 'no'; } $sql = "UPDATE dcuser2 SET work_safe_mode='" . $new_work_safe_mode . "' WHERE id=" . $user; $row = $this->forum_db->query($sql); echo $new_work_safe_mode; } public function get_topbuttons_status($user_id) { $sql = "SELECT home_buttons_status FROM dcuser2 WHERE id=" . $user_id; $row = $this->forum_db->fetchRow($sql); return $row['home_buttons_status']; } public function getLatestForumImages($forum_lang = 'en', $VisitorUserId = 0, $limit = 15, $pageIndex = 0, $visitorUsername = '', $visitorGroupId = 1, $include_gallery = true, $use_favorite_forums = false) { $tmpImagesArray = array(); if ($pageIndex>0) { $pageIndex = $pageIndex * $limit; } try { $config = Pimcore_Tool_Frontend::getWebsiteConfig(); $except_forum_ids = $config->img_stream_except_forum_id; $add_sql = ''; if (!empty($except_forum_ids)) { $arr_except_forum_ids = explode(',', $except_forum_ids); $arr_sql_cond = array(); foreach ($arr_except_forum_ids as $forum_id) { $arr_sql_cond[] = "l.id<>'" . $forum_id . "'"; $arr_sql_cond[] = "l.parent_id<>'" . $forum_id . "'"; } $add_sql = ' and ( ' . implode(' and ', $arr_sql_cond) . ') '; } $userAccess = Array(); if (!$this->isGuestUser($visitorUsername) and $visitorGroupId > 1 ) { $result = $this->forum_db->fetchAll("SELECT forum_id FROM dcpflist WHERE u_id = '" . $VisitorUserId . "' "); foreach($result as $row) { $userAccess[$row['forum_id']] = 1; } // private forums $result = $this->forum_db->fetchAll("SELECT forum_id FROM dcmoderator WHERE u_id = '" . $VisitorUserId . "' "); foreach($result as $row) { $userAccess[$row['forum_id']] = 1; } } $requested_forum_lang = 'english'; if (empty($forum_lang)) { $requested_forum_lang = ''; } else if (strlen($forum_lang) == 2) { if ($forum_lang == 'de') { $requested_forum_lang = 'deutsch'; } else if ($forum_lang == 'fr') { $requested_forum_lang = 'french'; } } if (!$VisitorUserId or $this->isGuestUser($visitorUsername)) { $use_favorite_forums = false; } if ($use_favorite_forums) { // We check if user has any favorite forums $sql = "SELECT count(f.id) AS cnt FROM favorite_forums f JOIN dcforum l ON f.forum_id = l.id WHERE l.language = '" . $requested_forum_lang . "' and l.whitelisted = 'yes' and f.u_id = '" . $VisitorUserId . "'"; $row = $this->forum_db->fetchRow($sql); $fav_for_cnt = $row['cnt']; if (!$fav_for_cnt) { $use_favorite_forums = false; } } // Select uploaded images for the stream if ($use_favorite_forums) { $sql = "select u.id as img_photo_id, u.u_id, u.forum_id, u.mesg_id, u.file_type, u.date as img_date, l.language as forum_lang, l.type from favorite_forums f join dcupload u on f.forum_id = u.forum_id join dcforum l on l.id = f.forum_id where f.u_id = '" . $VisitorUserId . "' and l.status='on' and l.language = '$requested_forum_lang' $add_sql and u.mesg_id<>'' and u.file_type in ('jpg', 'png') and l.whitelisted = 'yes' order by u.id desc limit $pageIndex,$limit"; } elseif ($requested_forum_lang == '') { $sql = "select u.id as img_photo_id, u.u_id, u.forum_id, u.mesg_id, u.file_type, u.date as img_date, l.language as forum_lang, l.type from dcupload u join dcforum l on l.id = u.forum_id where u.mesg_id<>'' and l.status='on' and l.type<>'70' and l.type<>'65' $add_sql and u.file_type in ('jpg', 'png') and l.whitelisted = 'yes' order by u.id desc limit $pageIndex,$limit"; } else { $sql = "select u.id as img_photo_id, u.u_id, u.forum_id, u.mesg_id, u.file_type, u.date as img_date, l.language as forum_lang, l.type from dcupload u join dcforum l on l.id = u.forum_id where l.language = '$requested_forum_lang' and l.status='on' and l.type<>'70' and l.type<>'65' $add_sql and u.mesg_id<>'' and u.file_type in ('jpg', 'png') and l.whitelisted = 'yes' order by u.id desc limit $pageIndex,$limit"; } $result = $this->forum_db->fetchAll($sql); foreach($result as $row) { $tmpImagesArray[] = $row; } if ($tmpImagesArray) { // Fill in needed fields $imagesArray = array(); $forumAccessList = array(); foreach ($tmpImagesArray as $img_row) { // username of the uploader $sql = "SELECT id, username FROM dcuser2 WHERE id = '" . $img_row['u_id'] . "'"; $row = $this->forum_db->fetchRow($sql); $img_username = $row['username']; $img_userid = $row['id']; // topic subject $sql = "SELECT subject, top_id FROM " . $img_row['forum_id'] . "_mesg WHERE id = '" . $img_row['mesg_id'] . "'"; $row = $this->forum_db->fetchRow($sql); $img_title = $row['subject']; $img_top_id = $row['top_id']; $img_mesg_id = $img_row['mesg_id']; // build the image link $forum_lang = $img_row['language']; $img_src_url = self::buildAttachmentSrc($img_row['img_photo_id'], $img_row['forum_lang'], $img_row['file_type']); $topicDataArray = array( 'forum_id' => $img_row['forum_id'], 'mesg_id' => $img_mesg_id, 'top_id' => $img_top_id, 'forum_lang' => $img_row['forum_lang'], 'subject' => $row['subject'] ); $img_url = self::buildTopicUrl($topicDataArray); if (!isset($forumAccessList[$img_row['id']])) { if ($visitorGroupId == 99) { $forumAccessList[$img_row['id']] = 'RW'; } elseif ($img_row['type'] == '40') { if ($userAccess[$img_row['id']] > 0) { $forumAccessList[$img_row['id']] = 'RW'; } } elseif ($img_row['type'] == '30') { if ($visitorGroupId > 1) { $forumAccessList[$img_row['id']] = 'RW'; } } elseif ($img_row['type'] == '20' or $img_row['type'] == '35') { if (!$this->isGuestUser($visitorUsername) and $visitorGroupId > 0) { $forumAccessList[$img_row['id']] = 'RW'; } else { $forumAccessList[$img_row['id']] = 'R'; } } elseif ($img_row['type'] == '50') { if ($visitorGroupId >= 6 and $visitorGroupId != 9) { $forumAccessList[$img_row['id']] = 'RW'; } else { $forumAccessList[$img_row['id']] = 'R'; } } elseif ($img_row['type'] == '60') { if ($this->isGuestUser($visitorUsername) or $visitorGroupId < 6) { $forumAccessList[$img_row['id']] = 'R'; } else { $forumAccessList[$img_row['id']] = 'RW'; } } elseif ($img_row['type'] == '65') { if ($userAccess[$img_row['id']] > 0) { $forumAccessList[$img_row['id']] = 'RW'; } else { if ($this->isGuestUser($visitorUsername) or ($visitorGroupId < 7)) { $forumAccessList[$img_row['id']] = 'R'; } else { $forumAccessList[$img_row['id']] = 'RW'; } } } elseif ($img_row['type'] == '70') { if ($userAccess[$img_row['id']] > 0) { $forumAccessList[$img_row['id']] = 'RW'; } else { if ($this->isGuestUser($visitorUsername) or ($visitorGroupId < 8)) { $forumAccessList[$img_row['id']] = 'R'; } else { $forumAccessList[$img_row['id']] = 'RW'; } } } else { $forumAccessList[$img_row['id']] = 'RW'; } } if ($forumAccessList[$img_row['id']] == 'R' or $forumAccessList[$img_row['id']] == 'RW') { $photo_row = array( 'img_photo_id' => $img_row['img_photo_id'], 'img_date' => $img_row['img_date'], 'img_date' => $img_row['img_date'], 'img_src_url' => $img_src_url, 'img_url' => $img_url, 'img_title' => $img_title, 'img_username' => $img_username, 'img_userid' => $img_userid, 'img_view_area' => 'forums', 'forum' => $img_row['forum_id'], 'post' => $img_row['top_id'] > 0 ? $img_row['top_id'] : $img_row['mesg_id'] ); $imagesArray[] = $photo_row; } } } /*------------------------------ gallery -------*/ if ($include_gallery) { $gallery_db = Website_Tool_Nikonians::getGalleryDB(); $sql = "SELECT p.id as img_photo_id, p.cat, p.bigimage as imagename, p.date as img_date, p.title, p.user FROM photos p JOIN categories c ON c.id=p.cat WHERE c.private='no' AND c.agecheck = 'no' AND p.approved = 1 GROUP BY p.user ORDER BY p.date DESC LIMIT $pageIndex,$limit"; $row = $gallery_db->fetchAll($sql); foreach ($row as $img_row) { $photo_row = array( 'img_photo_id' => $img_row['img_photo_id'], 'img_date' => date('Y-m-d h:m:s', $img_row['img_date']), 'img_src_url' => $this->nikoniansconfig->gallery->imgurl . $img_row['cat'] . '/' . $img_row['imagename'], 'img_url' => $this->nikoniansconfig->gallery->showphoto . $img_row['img_photo_id'] . '/', 'img_title' => $img_row['title'], 'img_username' => $img_row['user'], 'img_view_area' => 'gallery' ); $imagesArray[] = $photo_row; } } function sorta($a, $b) { if ($a['img_date'] < $b['img_date']) return 1; } usort($imagesArray, 'sorta'); } catch (Exception $e) { return $imagesArray; } return $imagesArray; } function isEditorTeamUser($user_id) { $sql = "SELECT id, g_id, status, delete_flag, ec_team FROM dcuser2 WHERE id =" . $this->forum_db->quote($user_id); $row = $this->forum_db->fetchRow($sql); $id = $row['id']; $g_id = $row['g_id']; $status = $row['status']; $delete_flag = $row['delete_flag']; $ec_team = $row['ec_team']; if ($id != $user_id) { return false; } if ($delete_flag == 'no' and $status == 'on' and $ec_team == 'yes' and $g_id > 9) { return true; } return false; } function buildForImageArrForView($img_id) { $tmp_arr = array(); $img_details = $this->getForumAttMainDetails($img_id); if (empty($img_details)) { return $tmp_arr; } // not sure if we shall test again /* if ($img_details['att_whitelisted'] != 'yes') { return $tmp_arr; } */ $img_src_url = $img_details['img_url']; $img_link_url = $img_details['img_link_url']; $title = $img_details['att_subject']; $sql = "SELECT username FROM dcuser2 WHERE id = " . $img_details['u_id']; $trow = $this->forum_db->fetchRow($sql); $tmp_username = $trow['username']; $tmp_arr = array(); $tmp_arr['where'] = 'forum'; $tmp_arr['title'] = $title; $tmp_arr['description'] = ''; $tmp_arr['img_url_big'] = Website_Tool_NikoniansImage::getPixImg($img_src_url, 'pix_portfolio_big'); $tmp_arr['img_url'] = Website_Tool_NikoniansImage::getPixImg($img_src_url, 'pix_home_gall_latest'); $tmp_arr['url'] = $img_link_url; $tmp_arr['user'] = $tmp_username; $tmp_arr['author_id'] = $img_details['u_id']; $tmp_arr['forum'] = $img_details['forum_id']; $tmp_arr['post'] = $img_details['mesg_id']; return $tmp_arr; } function getMembershipGroupName($g_id, $language = 'english') { $fieldName = 'en_view_name'; if ($language == 'deutsch') { $fieldName = 'de_view_name'; } $result = $this->forum_db->fetchRow("SELECT name, $fieldName as view_name FROM dcgroup WHERE id = " . $this->forum_db->quote($g_id)); if ($result['view_name']) { $groupname = $result['view_name']; $groupname = strtolower($groupname); } elseif ($result['name']) { $groupname = $result['name']; $groupname = strtolower($groupname); $groupname = str_replace('donator_', '', $groupname); } return $groupname; } function getCountryStateName($country_code, $state_code = '', $language = 'english') { $ret_array = array( 'country_name' => '', 'state_name' => '' ); if (empty($country_code)) { return $ret_array; } $this_lang = $language; if ($language != 'english' and $language != 'deutsch') { $this_lang = 'english'; } // country name $result = $this->forum_db->fetchRow("SELECT country_name FROM dccountries WHERE country_code = " . $this->forum_db->quote($country_code) . " and lang = '" . $this_lang . "' "); if ($result['country_name']) { $ret_array['country_name'] = $result['country_name']; } if (empty($state_code)) { return $ret_array; } // state name $result = $this->forum_db->fetchRow("SELECT state_name FROM dccountriesstates WHERE state_code = " . $this->forum_db->quote($state_code) . " AND country_code = " . $this->forum_db->quote($country_code) . " AND lang = '" . $this_lang . "' "); if ($result['state_name']) { $ret_array['state_name'] = $result['state_name']; } return $ret_array; } // Same as under /forums/include/dcflib.php // this we call indeed when adm does actions only function log_adm_action($action, $action_info = '', $target_u_id = 0, $actby_u_id = 0, $view_area = '', $view_section = '') { if (empty($actby_u_id)) { return; } if (empty($actby_u_id)) { $actby_u_id = 0; } $action = trim($action); $arr_event_info_rel = array( "Decreased SGP Validity" => "change", "Newsletter Subscription" => "change", "Registration Ok" => "change", "Upgrade User" => "change", "Downgrade User" => "change", "User Cancel Renewal" => "change", "User Cancel Trial" => "change", "Profile Update" => "change", "Del User" => "del", "login" => "login", "logout" => "logout" ); if (isset($arr_event_info_rel[$action]) and !empty($arr_event_info_rel[$action])) { $action = $arr_event_info_rel[$action]; } if (empty($action)) { $action = 'unknown'; } if (empty($action_info)) { if (!empty($target_u_id)) { $action_info = json_encode(array('u_id' => $target_u_id)); } } elseif (!empty($action_info) and substr($action_info,0,1) != '{') { $action_info = json_encode($action_info); } $arr_section = array(); if (isset($view_area) and !empty($view_area)) { $arr_section['area'] = 'area=' . $view_area; } if (isset($view_section) and !empty($view_section)) { $arr_section['section'] = 'section=' . $view_section; } $section = implode(';', $arr_section); $q = "INSERT INTO adm_actions (id, date, area, section, actby_u_id, action, action_info, target_u_id) VALUES ('', now(), 'main', " . $this->forum_db->quote($section) . ", '$actby_u_id', " . $this->forum_db->quote($action) . ", " . $this->forum_db->quote($action_info) . " , '$target_u_id' ) "; $this->forum_db->query($q); return; } }