Вход Регистрация
Файл: WoWonder 1.2.1/Update Guide/v1.1/Script/assets/includes/core.php
Строк: 4653
<?php
// +------------------------------------------------------------------------+
// | @author Deen Doughouz (WoWnder)
// | @author_url 1: http://www.wowonder.com
// | @author_url 2: http://codecanyon.net/user/wowondersocial
// | @author_email: deendoughouz@gmail.com   
// +------------------------------------------------------------------------+
// | WoWonder - A Social Networking Platform
// | Copyright (c) 2015 WoWonder. All rights reserved.
// +------------------------------------------------------------------------+
require_once('connect.php');
// user login function
function Wo_Login($username$password) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$username) || empty($username)) {
            return 
false;
      }
      
$username Wo_Secure($username);
      
$password Wo_Secure(md5($password));
      
$query    mysqli_query($sqlConnect"SELECT COUNT(`user_id`) FROM " T_USERS " WHERE `username` = '{$username}' AND `password` = '{$password}'");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// set (login with) session
function Wo_SetLoginWithSession($user_email) {
      if (empty(
$user_email)) {
            return 
false;
      }
      
$user_email          Wo_Secure($user_email);
      
$_SESSION['user_id'] = Wo_UserIdFromEmail($user_email);
}
// check if username is active
function Wo_UserActive($username) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$username)) {
            return 
false;
      }
      
$username Wo_Secure($username);
      
$query    mysqli_query($sqlConnect"SELECT COUNT(`user_id`) FROM " T_USERS "  WHERE `username`= '{$username}' AND `active` = '1'");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// check account if it's disabled
function Wo_UserInactive($username) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$username)) {
            return 
false;
      }
      
$username Wo_Secure($username);
      
$query    mysqli_query($sqlConnect"SELECT COUNT(`user_id`) FROM " T_USERS "  WHERE `username`= '{$username}' AND `active` = '2' ");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// check if user exists
function Wo_UserExists($username) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$username)) {
            return 
false;
      }
      
$username Wo_Secure($username);
      
$query    mysqli_query($sqlConnect"SELECT COUNT(`user_id`) FROM " T_USERS " WHERE `username` = '{$username}'");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// get user ID from username
function Wo_UserIdFromUsername($username) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$username)) {
            return 
false;
      }
      
$username Wo_Secure($username);
      
$query    mysqli_query($sqlConnect"SELECT `user_id` FROM " T_USERS " WHERE `username` = '{$username}'");
      return 
Wo_Sql_Result($query0'user_id');
}
// get user ID from e-mail
function Wo_UserIdFromEmail($email) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$email)) {
            return 
false;
      }
      
$email Wo_Secure($email);
      
$query mysqli_query($sqlConnect"SELECT `user_id` FROM " T_USERS " WHERE `email` = '{$email}'");
      return 
Wo_Sql_Result($query0'user_id');
}
// check if user is blocked
function Wo_IsBlocked($user_id) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            return 
false;
      }
      
$logged_user_id Wo_Secure($wo['user']['user_id']);
      
$user_id        Wo_Secure($user_id);
      
$query          mysqli_query($sqlConnect"SELECT COUNT(`id`) FROM " T_BLOCKS " WHERE (`block_from` = {$user_id} AND `block_to` = {$logged_user_id})");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// check if email exists
function Wo_EmailExists($email) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$email)) {
            return 
false;
      }
      
$email Wo_Secure($email);
      
$query mysqli_query($sqlConnect"SELECT COUNT(`user_id`) FROM " T_USERS " WHERE `email` = '{$email}'");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// check if user is onwer
function Wo_IsOnwer($user_id) {
      
// Global required variables
      
global $wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            return 
false;
      }
      
$user_id        Wo_Secure($user_id);
      
$logged_user_id Wo_Secure($wo['user']['user_id']);
      if (
Wo_IsAdmin($logged_user_id) === false) {
            if (
$user_id == $logged_user_id) {
                  return 
true;
            } else {
                  return 
false;
            }
      } else {
            return 
true;
      }
}
// get user data
function Wo_UserData($user_id) {
      
// Global required variables
      
global $wo$sqlConnect$cache;
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            return 
false;
      }
      
$data           = array();
      
$user_id        Wo_Secure($user_id);
      
$query_one      "SELECT * FROM " T_USERS " WHERE `user_id` = {$user_id}";
      
$hashed_user_Id md5($user_id);
      if (
$wo['config']['cacheSystem'] == 1) {
            
$fetched_data $cache->read($hashed_user_Id '_U_Data.tmp');
            if (empty(
$fetched_data)) {
                  
$sql          mysqli_query($sqlConnect$query_one);
                  
$fetched_data mysqli_fetch_assoc($sql);
                  
$cache->write($hashed_user_Id '_U_Data.tmp'$fetched_data);
            }
      } else {
            
//Wo_ClearCache();
            
$sql          mysqli_query($sqlConnect$query_one);
            
$fetched_data mysqli_fetch_assoc($sql);
      }
      if (empty(
$fetched_data)) {
            return array();
      }
      
$fetched_data['avatar'] = Wo_GetMedia($fetched_data['avatar']);
      
$fetched_data['cover']  = Wo_GetMedia($fetched_data['cover']);
      
//$fetched_data['about']  = Wo_Emo($fetched_data['about']);
      
$fetched_data['url']    = Wo_SeoLink('index.php?tab1=timeline&u=' $fetched_data['username']);
      
$fetched_data['name']   = '';
      if (!empty(
$fetched_data['first_name'])) {
            if (!empty(
$fetched_data['last_name'])) {
                  
$fetched_data['name'] = $fetched_data['first_name'] . ' ' $fetched_data['last_name'];
            } else {
                  
$fetched_data['name'] = $fetched_data['first_name'];
            }
      } else {
            
$fetched_data['name'] = $fetched_data['username'];
      }
      return 
$fetched_data;
}
// get user status (online | lastseen)
function Wo_UserStatus($user_id$lastseen) {
      global 
$wo;
      if (
Wo_IsLogged() === false) {
            
//return false;
      
}
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            return 
false;
      }
      if (empty(
$lastseen) || !is_numeric($lastseen) || $lastseen 0) {
            return 
false;
      }
      
$status   '';
      
$user_id  Wo_Secure($user_id);
      
$lastseen Wo_Secure($lastseen);
      
$time     time() - 60;
      if (
$lastseen $time) {
            if (
$wo['config']['message_typing'] == 1) {
                  if (
Wo_IsTyping($user_id)) {
                        
Wo_DeleteAllTyping($user_id);
                  }
            }
            
$status '<span class="small-last-seen">' $wo['lang']['last_seen'] . ' ' Wo_Time_Elapsed_String($lastseen) . '</span>';
      } else {
            
$status '<span class="online-text"> ' $wo['lang']['online'] . ' </span>';
      }
      return 
$status;
}
// update user lastseen
function Wo_LastSeen($user_id$type '') {
      
// Global required variables
      
global $wo$sqlConnect$cache;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            return 
false;
      }
      if (
$type == 'first') {
            
$user Wo_UserData($user_id);
            if (
$user['status'] == 1) {
                  return 
false;
            }
      } else {
            if (
$wo['user']['status'] == 1) {
                  return 
false;
            }
      }
      
$user_id Wo_Secure($user_id);
      
$query   mysqli_query($sqlConnect" UPDATE " T_USERS " SET `lastseen` = " time() . " WHERE `user_id` = {$user_id} AND `active` = '1'");
      if (
$query) {
            if (
$wo['config']['cacheSystem'] == 1) {
                  
$cache->delete(md5($user_id) . '_U_Data.tmp');
            }
            return 
true;
      } else {
            return 
false;
      }
}
// register user
function Wo_RegisterUser($registration_data) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (empty(
$registration_data)) {
            return 
false;
      }
      
$registration_data['password'] = md5($registration_data['password']);
      
$fields                        '`' implode('`, `'array_keys($registration_data)) . '`';
      
$data                          ''' . implode('', '', $registration_data) . ''';
      
$query                         mysqli_query($sqlConnect"INSERT INTO " T_USERS " ({$fields}) VALUES ({$data})");
      if (
$query) {
            return 
true;
      } else {
            return 
false;
      }
}
// activate user
function Wo_ActivateUser($email$code) {
      
// Global required variables
      
global $sqlConnect;
      
$email  Wo_Secure($email);
      
$code   Wo_Secure($code);
      
$query  mysqli_query($sqlConnect" SELECT COUNT(`user_id`)  FROM " T_USERS "  WHERE `email` = '{$email}' AND `email_code` = '{$code}' AND `active` = '0'");
      
$result Wo_Sql_Result($query0);
      if (
$result == 1) {
            
$query_two mysqli_query($sqlConnect" UPDATE " T_USERS "  SET `active` = '1' WHERE `email` = '{$email}' ");
            if (
$query_two) {
                  return 
true;
            }
      } else {
            return 
false;
      }
}
// reset password
function Wo_ResetPassword($user_id$password) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            return 
false;
      }
      if (empty(
$password)) {
            return 
false;
      }
      
$user_id  Wo_Secure($user_id);
      
$password md5($password);
      
$query    mysqli_query($sqlConnect" UPDATE " T_USERS " SET `password` = '{$password}' WHERE `user_id` = {$user_id} ");
      if (
$query) {
            return 
true;
      } else {
            return 
false;
      }
}
// get languages
function Wo_GetLanguages() {
      
$data           = array();
      
$dir            scandir('assets/languages');
      
$languages_name array_diff($dir, array(
            
".",
            
"..",
            
"error_log",
            
"index.html",
            
".htaccess",
            
"_notes"
      
));
      return 
$languages_name;
}
// creat post slug
function Wo_SlugPost($string) {
      
$slug url_slug($string, array(
            
'delimiter' => '-',
            
'limit' => 80,
            
'lowercase' => true,
            
'replacements' => array(
                  
'/b(an)b/i' => 'a',
                  
'/b(example)b/i' => 'Test'
            
)
      ));
      return 
$slug '.html';
}
// get post id from slug url
function Wo_GetPostIdFromUrl($string) {
      
$slug_string '';
      
$string      Wo_Secure($string);
      if (
preg_match('/[^a-zs-]/i'$string)) {
            
$string_exp  = @explode('_'$string);
            
$slug_string $string_exp[0];
      } else {
            
$slug_string $string;
      }
      return 
Wo_Secure($slug_string);
}
// check if is valid password code
function Wo_isValidPasswordResetToken($string) {
      
// Global required variables
      
global $sqlConnect;
      
$string_exp explode('_'$string);
      
$user_id    Wo_Secure($string_exp[0]);
      
$password   Wo_Secure($string_exp[1]);
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      if (empty(
$password)) {
            return 
false;
      }
      
$query mysqli_query($sqlConnect" SELECT COUNT(`user_id`) FROM " T_USERS " WHERE `user_id` = {$user_id} AND `password` = '{$password}' AND `active` = '1' ");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// delete user
function Wo_DeleteUser($user_id) {
      
// Global required variables
      
global $wo$sqlConnect$cache;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 1) {
            return 
false;
      }
      
$user_id Wo_Secure($user_id);
      if (
Wo_IsAdmin($wo['user']['user_id']) === false) {
            if (
$wo['user']['user_id'] != $user_id) {
                  return 
false;
            }
      }
      
$query_one_delete_photos mysqli_query($sqlConnect" SELECT `avatar`,`cover` FROM " T_USERS " WHERE `user_id` = {$user_id}");
      
$fetched_data            mysqli_fetch_assoc($query_one_delete_photos);
      if (isset(
$fetched_data['avatar']) && !empty($fetched_data['avatar']) && $fetched_data['avatar'] != $wo['userDefaultAvatar']) {
            @
unlink($fetched_data['avatar']);
      }
      if (isset(
$fetched_data['cover']) && !empty($fetched_data['cover']) && $fetched_data['cover'] != $wo['userDefaultCover']) {
            @
unlink($fetched_data['cover']);
      }
      
$query_one_delete_media mysqli_query($sqlConnect" SELECT `media` FROM " T_MESSAGES " WHERE `from_id` = {$user_id} OR `to_id` = {$user_id}");
      if (
mysqli_num_rows($query_one_delete_media) > 0) {
            while (
$fetched_data mysqli_fetch_assoc($query_one_delete_media)) {
                  if (isset(
$fetched_data['media']) && !empty($fetched_data['media'])) {
                        @
unlink($fetched_data['media']);
                  }
            }
      }
      
$query_two_delete_media mysqli_query($sqlConnect" SELECT `postFile`,`id`,`post_id` FROM " T_POSTS " WHERE `user_id` = {$user_id}");
      if (
mysqli_num_rows($query_two_delete_media) > 0) {
            while (
$fetched_data mysqli_fetch_assoc($query_two_delete_media)) {
                  
$query_one_reports mysqli_query($sqlConnect"DELETE FROM " T_REPORTS " WHERE `post_id` = " $fetched_data['id']);
                  
$query_one_reports .= mysqli_query($sqlConnect"DELETE FROM " T_REPORTS " WHERE `post_id` = " $fetched_data['post_id']);
                  if (isset(
$fetched_data['postFile']) && !empty($fetched_data['postFile'])) {
                        @
unlink($fetched_data['postFile']);
                  }
            }
      }
      if (
$wo['config']['cacheSystem'] == 1) {
            
$cache->delete(md5($user_id) . '_U_Data.tmp');
            
$query_two mysqli_query($sqlConnect"SELECT `id`,`post_id` FROM " T_POSTS " WHERE `user_id` = {$user_id} OR `recipient_id` = {$user_id}");
            if (
mysqli_num_rows($query_two) > 0) {
                  while (
$fetched_data_two mysqli_fetch_assoc($query_two)) {
                        
$cache->delete(md5($fetched_data_two['id']) . '_P_Data.tmp');
                        
$cache->delete(md5($fetched_data_two['post_id']) . '_P_Data.tmp');
                  }
            }
      }
      
$query_four_delete_media mysqli_query($sqlConnect"SELECT `page_id` FROM " T_PAGES " WHERE `user_id` = {$user_id}");
      if (
mysqli_num_rows($query_four_delete_media) > 0) {
            while (
$fetched_data mysqli_fetch_assoc($query_four_delete_media)) {
                  
$delete_posts Wo_DeletePage($fetched_data['page_id']);
            }
      }
      
$query_one mysqli_query($sqlConnect"DELETE FROM " T_USERS " WHERE `user_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_FOLLOWERS " WHERE `follower_id` = {$user_id} OR `following_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_MESSAGES " WHERE `from_id` = {$user_id} OR `to_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_POSTS " WHERE  `user_id` = {$user_id} OR `recipient_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_NOTIFICATION " WHERE `notifier_id` = {$user_id} OR `recipient_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_COMMENTS " WHERE `user_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_COMMENT_WONDERS " WHERE  `user_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_COMMENT_LIKES " WHERE  `user_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_LIKES " WHERE  `user_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_WONDERS " WHERE  `user_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_SAVED_POSTS " WHERE `user_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_REPORTS " WHERE `user_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_ACTIVITIES " WHERE `user_id` = {$user_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_BLOCKS " WHERE `block_to` = {$user_id} OR `block_from` = {$user_id}");
      if (
$query_one) {
            return 
true;
      }
}
// update user data
function Wo_UpdateUserData($user_id$update_data) {
      
// Global required variables
      
global $wo$sqlConnect$cache;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            return 
false;
      }
      if (empty(
$update_data)) {
            return 
false;
      }
      
$user_id Wo_Secure($user_id);
      if (
Wo_IsAdmin($wo['user']['user_id']) === false) {
            if (
$wo['user']['user_id'] != $user_id) {
                  return 
false;
            }
      }
      if (!empty(
$update_data['relationship'])) {
            if (!
array_key_exists($update_data['relationship'], $wo['relationship'])) {
                  
$update_data['relationship'] = 1;
            }
      }
      if (!empty(
$update_data['country_id'])) {
            if (!
array_key_exists($update_data['country_id'], $wo['countries_name'])) {
                  
$update_data['country_id'] = 1;
            }
      }
      
$update = array();
      foreach (
$update_data as $field => $data) {
            
$update[] = '`' $field '` = '' . Wo_Secure($data) . ''';
      }
      
$impload   implode(', '$update);
      
$query_one " UPDATE " T_USERS " SET {$impload} WHERE `user_id` = {$user_id} ";
      
$query     mysqli_query($sqlConnect$query_one);
      if (
$wo['config']['cacheSystem'] == 1) {
            
$cache->delete(md5($user_id) . '_U_Data.tmp');
      }
      if (
$query) {
            return 
true;
      } else {
            return 
false;
      }
}
// replace media file with full media url
function Wo_GetMedia($media) {
      
// Global required variables
      
global $wo;
      if (empty(
$media)) {
            return 
'';
      }
      return 
$wo['config']['site_url'] . '/' $media;
}
// upload images
function Wo_UploadImage($file$name$type$user_id 0$placement '') {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$file) || empty($name) || empty($type) || empty($user_id)) {
            return 
false;
      }
      
$ext pathinfo($namePATHINFO_EXTENSION);
      if (!
file_exists('upload/photos/' date('Y'))) {
            
mkdir('upload/photos/' date('Y'), 0777true);
      }
      if (!
file_exists('upload/photos/' date('Y') . '/' date('m'))) {
            
mkdir('upload/photos/' date('Y') . '/' date('m'), 0777true);
      }
      
$allowed           'jpg,png,jpeg,gif';
      
$new_string        pathinfo($namePATHINFO_FILENAME) . '.' strtolower(pathinfo($namePATHINFO_EXTENSION));
      
$extension_allowed explode(','$allowed);
      
$file_extension    pathinfo($new_stringPATHINFO_EXTENSION);
      if (!
in_array($file_extension$extension_allowed)) {
            return 
false;
      }
      
$dir 'upload/photos/' date('Y') . '/' date('m');
      if (
$placement == 'page') {
            
$image_data['page_id'] = Wo_Secure($user_id);
      } else {
            
$image_data['user_id'] = Wo_Secure($user_id);
      }
      if (
$type == 'cover') {
            if (
$placement == 'page') {
                  
$query_one_delete_cover mysqli_query($sqlConnect" SELECT `cover` FROM " T_PAGES " WHERE `page_id` = " $image_data['page_id'] . " AND `active` = '1' ");
            } else {
                  
$query_one_delete_cover mysqli_query($sqlConnect" SELECT `cover` FROM " T_USERS " WHERE `user_id` = " $image_data['user_id'] . " AND `active` = '1' ");
            }
            
$fetched_data        mysqli_fetch_assoc($query_one_delete_cover);
            
$filename            $dir '/' Wo_GenerateKey() . '_' date('d') . '_' md5(time()) . '_cover.' $ext;
            
$image_data['cover'] = $filename;
            if (
move_uploaded_file($file$filename)) {
                  if (isset(
$fetched_data['cover']) && !empty($fetched_data['cover']) && $fetched_data['cover'] != $wo['userDefaultCover']) {
                        @
unlink($fetched_data['cover']);
                  }
                  
$update_data false;
                  if (
$placement == 'page') {
                        
$update_data Wo_UpdatePageData($image_data['page_id'], $image_data);
                  } else {
                        
$update_data Wo_UpdateUserData($image_data['user_id'], $image_data);
                  }
                  if (
$update_data == true) {
                        
Wo_Resize_Crop_Image(1000400$filename$filename80);
                        return 
true;
                  }
            }
      } else if (
$type == 'avatar') {
            
$filename             $dir '/' Wo_GenerateKey() . '_' date('d') . '_' md5(time()) . '_avatar.' $ext;
            
$image_data['avatar'] = $filename;
            if (
move_uploaded_file($file$filename)) {
                  if (
$placement == 'page') {
                        
$update_data Wo_UpdatePageData($image_data['page_id'], $image_data);
                        
Wo_Resize_Crop_Image(400400$filename$filename60);
                        return 
true;
                  } else {
                        if (
Wo_UpdateUserData($image_data['user_id'], $image_data)) {
                              
Wo_RegisterPost(array(
                                    
'user_id' => Wo_Secure($image_data['user_id']),
                                    
'postFile' => Wo_Secure($image_data['avatar']),
                                    
'time' => time(),
                                    
'postType' => Wo_Secure('profile_picture'),
                                    
'postPrivacy' => '0'
                              
));
                              
Wo_Resize_Crop_Image(400400$filename$filename60);
                              return 
true;
                        }
                  }
            }
      } else if (
$type == 'background_image') {
            
$query_one_delete_background_image mysqli_query($sqlConnect" SELECT `background_image` FROM " T_USERS " WHERE `user_id` = " $image_data['user_id'] . " AND `active` = '1' ");
            
$fetched_data                      mysqli_fetch_assoc($query_one_delete_background_image);
            
$filename                          $dir '/' Wo_GenerateKey() . '_' date('d') . '_' md5(time()) . '_background_image.' $ext;
            
$image_data['background_image']    = $filename;
            if (
move_uploaded_file($file$filename)) {
                  if (isset(
$fetched_data['background_image']) && !empty($fetched_data['background_image'])) {
                        @
unlink($fetched_data['background_image']);
                  }
                  if (
Wo_UpdateUserData($image_data['user_id'], $image_data)) {
                        return 
true;
                  }
            }
      }
      
/* ----- API / Developers (will be available on future updates) ------ */
      /* else if ($type == 'app') {
      
      $filename = $dir . '/' . Wo_GenerateKey() . '_' . date('d') . '_' . md5(time()) . '_app.' . $ext;
      
      $image_data['app_avatar'] = $filename;
      
      if (move_uploaded_file($file, $filename)) {
      
      if (Wo_UpdateAppImage($image_data['user_id'], $image_data['app_avatar'])) {
      
      Wo_Resize_Crop_Image(400, 400, $filename, $filename, 60);
      
      return true;
      
      }
      }
      }*/
}
// get user birthday
function Wo_UserBirthday($birthday) {
      
// Global required variables
      
global $wo;
      if (empty(
$birthday)) {
            return 
false;
      }
      
$birthday Wo_Secure($birthday);
      
$age      '';
      if (
$wo['config']['age'] == 0) {
            
$age date_diff(date_create($birthday), date_create('today'))->y;
      } else {
            
$age_style explode('-'$birthday);
            
$age       $age_style[1] . '/' $age_style[2] . '/' $age_style[0];
      }
      return 
$age;
}
// get all users from database
function Wo_GetAllUsers($limit ''$type ''$filter = array(), $after '') {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data      = array();
      
$query_one " SELECT `user_id` FROM " T_USERS " WHERE `type` = 'user'";
      if (isset(
$filter) AND !empty($filter)) {
            if (!empty(
$filter['query'])) {
                  
$query_one .= " AND ((`email` LIKE '%" Wo_Secure($filter['query']) . "%') OR (`username` LIKE '%" Wo_Secure($filter['query']) . "%') OR CONCAT( `first_name`,  ' ', `last_name` ) LIKE  '%" Wo_Secure($filter['query']) . "%')";
            }
            if (isset(
$filter['source']) && $filter['source'] != 'all') {
                  
$query_one .= " AND `src` = '" Wo_Secure($filter['source']) . "'";
            }
            if (isset(
$filter['status']) && $filter['status'] != 'all') {
                  
$query_one .= " AND `active` = '" Wo_Secure($filter['status']) . "'";
            }
      }
      if (!empty(
$after) && is_numeric($after) && $after 0) {
            
$query_one .= " AND `user_id` < " Wo_Secure($after);
      }
      if (
$type == 'sidebar') {
            
$query_one .= " ORDER BY RAND()";
      } else {
            
$query_one .= " ORDER BY `user_id` DESC";
      }
      if (isset(
$limit) and !empty($limit)) {
            
$query_one .= " LIMIT {$limit}";
      }
      
$sql mysqli_query($sqlConnect$query_one);
      while (
$fetched_data mysqli_fetch_assoc($sql)) {
            
$user_data        Wo_UserData($fetched_data['user_id']);
            
$user_data['src'] = ($user_data['src'] == 'site') ? $wo['config']['siteName'] : $user_data['src'];
            ;
            
$data[] = $user_data;
      }
      return 
$data;
}
// get users for welcome page
function Wo_WelcomeUsers($limit ''$type '') {
      
// Global required variables
      
global $wo$sqlConnect;
      
$limit     12;
      
$data      = array();
      
$query_one " SELECT `user_id` FROM " T_USERS " WHERE `active` = '1' AND `avatar` <> '" Wo_Secure($wo['userDefaultAvatar']) . "' ORDER BY RAND() LIMIT {$limit}";
      
$sql       mysqli_query($sqlConnect$query_one);
      while (
$fetched_data mysqli_fetch_assoc($sql)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      return 
$data;
}
// get (people you may know) user list 
function Wo_UserSug($limit 20) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (!
is_numeric($limit)) {
            return 
false;
      }
      
$data      = array();
      
$user_id   Wo_Secure($wo['user']['user_id']);
      
$query_one " SELECT `user_id` FROM " T_USERS " WHERE `active` = '1' AND `user_id` NOT IN (SELECT `following_id` FROM " T_FOLLOWERS " WHERE `follower_id` = {$user_id}) AND `user_id` <> {$user_id}";
      if (isset(
$limit)) {
            
$query_one .= " ORDER BY RAND() LIMIT {$limit}";
      }
      
$sql mysqli_query($sqlConnect$query_one);
      while (
$fetched_data mysqli_fetch_assoc($sql)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      return 
$data;
}
// import user photos from (login with) 
function Wo_ImportImageFromLogin($media) {
      if (!
file_exists('upload/photos/' date('Y'))) {
            
mkdir('upload/photos/' date('Y'), 0777true);
      }
      if (!
file_exists('upload/photos/' date('Y') . '/' date('m'))) {
            
mkdir('upload/photos/' date('Y') . '/' date('m'), 0777true);
      }
      
$dir         'upload/photos/' date('Y') . '/' date('m');
      
$file_dir    $dir '/' Wo_GenerateKey() . '_avatar.jpg';
      
$importImage = @file_put_contents($file_dirfile_get_contents($media));
      if (
$importImage) {
            
Wo_Resize_Crop_Image(400400$file_dir$file_dir80);
      }
      if (
file_exists($file_dir)) {
            return 
$file_dir;
      } else {
            return 
$wo['userDefaultAvatar'];
      }
}
// import user photos from (login with) 
function Wo_ImportImageFromUrl($media) {
      if (empty(
$media)) {
            return 
$wo['userDefaultAvatar'];
      }
      if (!
file_exists('upload/photos/' date('Y'))) {
            
mkdir('upload/photos/' date('Y'), 0777true);
      }
      if (!
file_exists('upload/photos/' date('Y') . '/' date('m'))) {
            
mkdir('upload/photos/' date('Y') . '/' date('m'), 0777true);
      }
      
$size      getimagesize($media);
      
$extension image_type_to_extension($size[2]);
      if (empty(
$extension)) {
            
$extension '.jpg';
      }
      
$dir         'upload/photos/' date('Y') . '/' date('m');
      
$file_dir    $dir '/' Wo_GenerateKey() . '_url_image' $extension;
      
$importImage = @file_put_contents($file_dirfile_get_contents($media));
      if (
$importImage) {
            
Wo_Resize_Crop_Image(400400$file_dir$file_dir80);
      }
      if (
file_exists($file_dir)) {
            return 
$file_dir;
      } else {
            return 
$wo['userDefaultAvatar'];
      }
}
// check user if he is following 
function Wo_IsFollowing($following_id$user_id 0) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$following_id) || !is_numeric($following_id) || $following_id 0) {
            return 
false;
      }
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            
$user_id $wo['user']['user_id'];
      }
      
$following_id Wo_Secure($following_id);
      
$user_id      Wo_Secure($user_id);
      
$query        mysqli_query($sqlConnect" SELECT COUNT(`id`) FROM " T_FOLLOWERS " WHERE `following_id` = {$following_id} AND `follower_id` = {$user_id} AND `active` = '1' ");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// register follow 
function Wo_RegisterFollow($following_id 0$follower_id 0) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!isset(
$following_id) or empty($following_id) or !is_numeric($following_id) or $following_id 1) {
            return 
false;
      }
      if (!isset(
$follower_id) or empty($follower_id) or !is_numeric($follower_id) or $follower_id 1) {
            return 
false;
      }
      
$following_id Wo_Secure($following_id);
      
$follower_id  Wo_Secure($follower_id);
      
$active       1;
      if (
Wo_IsFollowing($following_id$follower_id) === true) {
            return 
false;
      }
      
$follower_data  Wo_UserData($follower_id);
      
$following_data Wo_UserData($following_id);
      if (
$following_data['confirm_followers'] == 1) {
            
$active 0;
      }
      if (
$wo['config']['connectivitySystem'] == 1) {
            
$active 0;
      }
      
$query mysqli_query($sqlConnect" INSERT INTO " T_FOLLOWERS " (`following_id`,`follower_id`,`active`) VALUES ({$following_id},{$follower_id},'{$active}')");
      if (
$query) {
            if (
$active == 1) {
                  
$notification_data = array(
                        
'recipient_id' => $following_id,
                        
'type' => 'following',
                        
'url' => 'index.php?tab1=timeline&u=' $follower_data['username']
                  );
                  
Wo_RegisterNotification($notification_data);
            }
            return 
true;
      }
}
// count users follow requets
function Wo_CountFollowRequests($data = array()) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$get     = array();
      
$user_id Wo_Secure($wo['user']['user_id']);
      if (empty(
$data['account_id']) || $data['account_id'] == 0) {
            
$data['account_id'] = $user_id;
            
$account            $wo['user'];
      }
      if (!
is_numeric($data['account_id']) || $data['account_id'] < 1) {
            return 
false;
      }
      if (
$data['account_id'] != $user_id) {
            
$data['account_id'] = Wo_Secure($data['account_id']);
            
$account            Wo_UserData($data['account_id']);
      }
      
$query_one " SELECT COUNT(`id`) AS `FollowRequests` FROM " T_FOLLOWERS " WHERE `active` = '0' AND following_id =  " $account['user_id'];
      if (isset(
$data['unread']) && $data['unread'] == true) {
            
$query_one .= " AND `seen` = 0";
      }
      
$query_one .= " ORDER BY `id` DESC";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      
$sql_fetch_one mysqli_fetch_assoc($sql_query_one);
      return 
$sql_fetch_one['FollowRequests'];
}
// check if follow requested
function Wo_IsFollowRequested($following_id 0$follower_id 0) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!isset(
$following_id) or empty($following_id) or !is_numeric($following_id) or $following_id 1) {
            return 
false;
      }
      if (!isset(
$follower_id) or empty($follower_id) or !is_numeric($follower_id) or $follower_id 1) {
            
$follower_id $wo['user']['user_id'];
      }
      if (!
is_numeric($follower_id) or $follower_id 1) {
            return 
false;
      }
      
$following_id Wo_Secure($following_id);
      
$follower_id  Wo_Secure($follower_id);
      
$query        "SELECT `id` FROM " T_FOLLOWERS " WHERE `follower_id` = {$follower_id} AND `following_id` = {$following_id} AND `active` = '0'";
      
$sql_query    mysqli_query($sqlConnect$query);
      if (
mysqli_num_rows($sql_query) > 0) {
            return 
true;
      }
}
// delete follow (unfollow)
function Wo_DeleteFollow($following_id 0$follower_id 0) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!isset(
$following_id) or empty($following_id) or !is_numeric($following_id) or $following_id 1) {
            return 
false;
      }
      if (!isset(
$follower_id) or empty($follower_id) or !is_numeric($follower_id) or $follower_id 1) {
            return 
false;
      }
      
$following_id Wo_Secure($following_id);
      
$follower_id  Wo_Secure($follower_id);
      if (
Wo_IsFollowing($following_id$follower_id) === false && Wo_IsFollowRequested($following_id$follower_id) === false) {
            return 
false;
      } else {
            
$query mysqli_query($sqlConnect" DELETE FROM " T_FOLLOWERS " WHERE `following_id` = {$following_id} AND `follower_id` = {$follower_id}");
            if (
$wo['config']['connectivitySystem'] == 1) {
                  
$query_two     "DELETE FROM " T_FOLLOWERS " WHERE `follower_id` = {$following_id} AND `following_id` = {$follower_id}";
                  
$sql_query_two mysqli_query($sqlConnect$query_two);
            }
            if (
$query) {
                  return 
true;
            }
      }
}
// count users following
function Wo_CountFollowing($user_id) {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data = array();
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      
$user_id      Wo_Secure($user_id);
      
$query        mysqli_query($sqlConnect"SELECT COUNT(`user_id`) AS count FROM " T_USERS " WHERE `user_id` IN (SELECT `following_id` FROM " T_FOLLOWERS " WHERE `follower_id` = {$user_id} AND `following_id` <> {$user_id} AND `active` = '1') AND `active` = '1' ");
      
$fetched_data mysqli_fetch_assoc($query);
      return 
$fetched_data['count'];
}
// accept follow request
function Wo_AcceptFollowRequest($following_id 0$follower_id 0) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!isset(
$following_id) or empty($following_id) or !is_numeric($following_id) or $following_id 1) {
            return 
false;
      }
      if (!isset(
$follower_id) or empty($follower_id) or !is_numeric($follower_id) or $follower_id 1) {
            return 
false;
      }
      
$following_id Wo_Secure($following_id);
      
$follower_id  Wo_Secure($follower_id);
      if (
Wo_IsFollowRequested($following_id$follower_id) === false) {
            return 
false;
      }
      
$follower_data Wo_UserData($follower_id);
      
$query         mysqli_query($sqlConnect"UPDATE " T_FOLLOWERS " SET `active` = '1' WHERE `following_id` = {$follower_id} AND `follower_id` = {$following_id} AND `active` = '0'");
      if (
$wo['config']['connectivitySystem'] == 1) {
            
$query_two mysqli_query($sqlConnect"INSERT INTO " T_FOLLOWERS " (`following_id`,`follower_id`,`active`) VALUES ({$following_id},{$follower_id},'1') ");
      }
      if (
$query) {
            
$notification_data = array(
                  
'recipient_id' => $following_id,
                  
'type' => 'accepted_request',
                  
'url' => 'index.php?tab1=timeline&u=' $follower_data['username']
            );
            if (
Wo_RegisterNotification($notification_data) === true) {
                  return 
true;
            } else {
                  return 
false;
            }
      }
}
// delete follow request
function Wo_DeleteFollowRequest($following_id$follower_id) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!isset(
$following_id) or empty($following_id) or !is_numeric($following_id) or $following_id 1) {
            return 
false;
      }
      if (!isset(
$follower_id) or empty($follower_id) or !is_numeric($follower_id) or $follower_id 1) {
            return 
false;
      }
      
$following_id Wo_Secure($following_id);
      
$follower_id  Wo_Secure($follower_id);
      if (
Wo_IsFollowRequested($following_id$follower_id) === false) {
            return 
false;
      } else {
            
$query mysqli_query($sqlConnect" DELETE FROM " T_FOLLOWERS " WHERE `following_id` = {$follower_id} AND `follower_id` = {$following_id} ");
            if (
$query) {
                  return 
true;
            }
      }
}
// get follow requests
function Wo_GetFollowRequests($user_id 0$search_query '') {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$data = array();
      if (empty(
$user_id) or $user_id == 0) {
            
$user_id $wo['user']['user_id'];
      }
      if (!
is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      
$user_id Wo_Secure($user_id);
      
$query   "SELECT `user_id` FROM " T_USERS " WHERE `user_id` IN (SELECT `follower_id` FROM " T_FOLLOWERS " WHERE `follower_id` <> {$user_id} AND `following_id` = {$user_id} AND `active` = '0') AND `active` = '1' ";
      if (!empty(
$search_query)) {
            
$search_query Wo_Secure($search_query);
            
$query .= " AND `name` LIKE '%$search_query%'";
      }
      
$query .= " ORDER BY `user_id` DESC";
      
$sql_query mysqli_query($sqlConnect$query);
      while (
$sql_fetch mysqli_fetch_assoc($sql_query)) {
            
$data[] = Wo_UserData($sql_fetch['user_id']);
      }
      return 
$data;
}
// count followers
function Wo_CountFollowers($user_id) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      
$data         = array();
      
$user_id      Wo_Secure($user_id);
      
$query        mysqli_query($sqlConnect" SELECT COUNT(`user_id`) AS count FROM " T_USERS " WHERE `user_id` IN (SELECT `follower_id` FROM " T_FOLLOWERS " WHERE `follower_id` <> {$user_id} AND `following_id` = {$user_id} AND `active` = '1') AND `active` = '1' ");
      
$fetched_data mysqli_fetch_assoc($query);
      return 
$fetched_data['count'];
}
// get users following
function Wo_GetFollowing($user_id$type ''$limit ''$after_user_id '') {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data = array();
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      
$user_id       Wo_Secure($user_id);
      
$after_user_id Wo_Secure($after_user_id);
      
$query         "SELECT `user_id` FROM " T_USERS " WHERE `user_id` IN (SELECT `following_id` FROM " T_FOLLOWERS " WHERE `follower_id` = {$user_id} AND `following_id` <> {$user_id} AND `active` = '1') AND `active` = '1' ";
      if (!empty(
$after_user_id) && is_numeric($after_user_id)) {
            
$query .= " AND `user_id` < {$after_user_id}";
      }
      if (
$type == 'sidebar' && !empty($limit) && is_numeric($limit)) {
            
$query .= " ORDER BY RAND() LIMIT {$limit}";
      }
      if (
$type == 'profile' && !empty($limit) && is_numeric($limit)) {
            
$query .= " ORDER BY `user_id` DESC LIMIT {$limit}";
      }
      
$sql_query mysqli_query($sqlConnect$query);
      while (
$fetched_data mysqli_fetch_assoc($sql_query)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      return 
$data;
}
// get users followers
function Wo_GetFollowers($user_id$type ''$limit ''$after_user_id '') {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data = array();
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      
$user_id       Wo_Secure($user_id);
      
$after_user_id Wo_Secure($after_user_id);
      
$query         " SELECT `user_id` FROM " T_USERS " WHERE `user_id` IN (SELECT `follower_id` FROM " T_FOLLOWERS " WHERE `follower_id` <> {$user_id} AND `following_id` = {$user_id} AND `active` = '1') AND `active` = '1'";
      if (!empty(
$after_user_id) && is_numeric($after_user_id)) {
            
$query .= " AND `user_id` < {$after_user_id}";
      }
      if (
$type == 'sidebar' && !empty($limit) && is_numeric($limit)) {
            
$query .= " ORDER BY RAND()";
      }
      if (
$type == 'profile' && !empty($limit) && is_numeric($limit)) {
            
$query .= " ORDER BY `user_id` DESC";
      }
      
$query .= " LIMIT {$limit} ";
      
$sql_query mysqli_query($sqlConnect$query);
      while (
$fetched_data mysqli_fetch_assoc($sql_query)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      return 
$data;
}
// get follow button
function Wo_GetFollowButton($user_id 0) {
      
// Global required variables
      
global $wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!
is_numeric($user_id) or $user_id 0) {
            return 
false;
      }
      if (
$user_id == $wo['user']['user_id']) {
            return 
false;
      }
      
$account $wo['follow'] = Wo_UserData($user_id);
      if (!isset(
$wo['follow']['user_id'])) {
            return 
false;
      }
      
$user_id           Wo_Secure($user_id);
      
$logged_user_id    Wo_Secure($wo['user']['user_id']);
      
$follow_button     'buttons/follow';
      
$unfollow_button   'buttons/unfollow';
      
$add_frined_button 'buttons/add-friend';
      
$unfrined_button   'buttons/unfriend';
      
$accept_button     'buttons/accept-request';
      
$request_button    'buttons/requested';
      if (
Wo_IsFollowing($user_id$logged_user_id)) {
            if (
$wo['config']['connectivitySystem'] == 1) {
                  return 
Wo_LoadPage($unfrined_button);
            } else {
                  return 
Wo_LoadPage($unfollow_button);
            }
      } else {
            if (
Wo_IsFollowRequested($user_id$logged_user_id)) {
                  return 
Wo_LoadPage($request_button);
            } else if (
Wo_IsFollowRequested($logged_user_id$user_id)) {
                  return 
Wo_LoadPage($accept_button);
            } else {
                  if (
$account['follow_privacy'] == 1) {
                        if (
Wo_IsFollowing($logged_user_id$user_id)) {
                              if (
$wo['config']['connectivitySystem'] == 1) {
                                    return 
Wo_LoadPage($add_frined_button);
                              } else {
                                    return 
Wo_LoadPage($follow_button);
                              }
                        }
                  } else if (
$account['follow_privacy'] == 0) {
                        if (
$wo['config']['connectivitySystem'] == 1) {
                              return 
Wo_LoadPage($add_frined_button);
                        } else {
                              return 
Wo_LoadPage($follow_button);
                        }
                  }
            }
      }
}
// register notification
function Wo_RegisterNotification($data = array()) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!isset(
$data['recipient_id']) or empty($data['recipient_id']) or !is_numeric($data['recipient_id']) or $data['recipient_id'] < 1) {
            return 
false;
      }
      if (!isset(
$data['post_id']) or empty($data['post_id'])) {
            
$data['post_id'] = 0;
      }
      if (!
is_numeric($data['post_id']) or $data['recipient_id'] < 0) {
            return 
false;
      }
      if (empty(
$data['notifier_id']) or $data['notifier_id'] == 0) {
            
$data['notifier_id'] = Wo_Secure($wo['user']['user_id']);
      }
      if (!
is_numeric($data['notifier_id']) or $data['notifier_id'] < 1) {
            return 
false;
      }
      if (
$data['notifier_id'] == $wo['user']['user_id']) {
            
$notifier $wo['user'];
      } else {
            
$data['notifier_id'] = Wo_Secure($data['notifier_id']);
            
$notifier            Wo_UserData($data['notifier_id']);
            if (!isset(
$notifier['user_id'])) {
                  return 
false;
            }
      }
      if (
$notifier['user_id'] != $wo['user']['user_id']) {
            return 
false;
      }
      if (
$data['recipient_id'] == $data['notifier_id']) {
            return 
false;
      }
      if (!isset(
$data['text'])) {
            
$data['text'] = '';
      }
      if (!isset(
$data['type']) or empty($data['type'])) {
            return 
false;
      }
      if (!isset(
$data['url']) or empty($data['url'])) {
            return 
false;
      }
      
$recipient Wo_UserData($data['recipient_id']);
      if (!isset(
$recipient['user_id'])) {
            return 
false;
      }
      
$url                  $data['url'];
      
$recipient['user_id'] = Wo_Secure($recipient['user_id']);
      
$data['post_id']      = Wo_Secure($data['post_id']);
      
$data['type']         = Wo_Secure($data['type']);
      if (!empty(
$data['type2'])) {
            
$data['type2'] = Wo_Secure($data['type2']);
      } else {
            
$data['type2'] = '';
      }
      if (
$data['text'] != strip_tags($data['text'])) {
            
$data['text'] = '';
      }
      
$data['text']            = Wo_Secure($data['text']);
      
$notifier['user_id']     = Wo_Secure($notifier['user_id']);
      
$page_notifcation_query  '';
      
$page_notifcation_query2 '';
      if (!empty(
$data['page_id']) && $data['page_id'] > 0) {
            
$page Wo_PageData($data['page_id']);
            if (!isset(
$page['page_id'])) {
                  return 
false;
            }
            
$page_id Wo_Secure($page['page_id']);
            if (isset(
$data['page_enable'])) {
                  if (
$data['page_enable'] !== false) {
                        
$notifier['user_id'] = 0;
                  }
            } else {
                  
$notifier['user_id'] = 0;
            }
            
$page_notifcation_query  '`page_id`,';
            
$page_notifcation_query2 "{$page_id}, ";
      }
      
$query_one     " SELECT `id` FROM " T_NOTIFICATION " WHERE `recipient_id` = " $recipient['user_id'] . " AND `post_id` = " $data['post_id'] . " AND `type` = '" $data['type'] . "'";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) > 0) {
            if (
$data['type'] != "following") {
                  
$query_two     " DELETE FROM " T_NOTIFICATION " WHERE `recipient_id` = " $recipient['user_id'] . " AND `post_id` = " $data['post_id'] . " AND `type` = '" $data['type'] . "'";
                  
$sql_query_two mysqli_query($sqlConnect$query_two);
            }
      }
      if (!isset(
$data['undo']) or $data['undo'] != true) {
            
$query_three     "INSERT INTO " T_NOTIFICATION " (`recipient_id`, `notifier_id`, {$page_notifcation_query} `post_id`, `type`, `type2`, `text`, `url`, `time`) VALUES (" $recipient['user_id'] . "," $notifier['user_id'] . ",{$page_notifcation_query2} " $data['post_id'] . ",'" $data['type'] . "','" $data['type2'] . "','" $data['text'] . "','{$url}'," time() . ")";
            
$sql_query_three mysqli_query($sqlConnect$query_three);
            if (
$sql_query_three) {
                  if (
$wo['config']['emailNotification'] == && $recipient['emailNotification'] == 1) {
                        
$post_data_id      Wo_PostData($data['post_id']);
                        
$post_data['text'] = '';
                        if (!empty(
$post_data_id['postText'])) {
                              
$post_data['text'] = substr($post_data_id['postText'], 020);
                        }
                        
$data['notifier']        = $notifier;
                        
$data['url']             = Wo_SeoLink($url);
                        
$data['post_data']       = $post_data;
                        
$wo['emailNotification'] = $data;
                        
$body                    Wo_LoadPage('emails/notifiction-email');
                        
$headers                 "From: " $wo['config']['siteName'] . " <" $wo['config']['siteEmail'] . ">rn";
                        
$headers .= "Content-Type: text/html; charset=UTF-8rn";
                        @
mail($recipient['email'], 'New notification'$body$headers);
                  }
                  return 
true;
            }
      }
}
// get notifications
function Wo_GetNotifications($data = array()) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$get = array();
      if (!isset(
$data['account_id']) or empty($data['account_id'])) {
            
$data['account_id'] = $wo['user']['user_id'];
      }
      if (!
is_numeric($data['account_id']) or $data['account_id'] < 1) {
            return 
false;
      }
      if (
$data['account_id'] == $wo['user']['user_id']) {
            
$account $wo['user'];
      } else {
            
$data['account_id'] = $data['account_id'];
            
$account            Wo_UserData($data['account_id']);
      }
      if (
$account['user_id'] != $wo['user']['user_id']) {
            return 
false;
      }
      
$new_notif Wo_CountNotifications(array(
            
'unread' => true
      
));
      if (
$new_notif 0) {
            
$query_one " SELECT * FROM " T_NOTIFICATION " WHERE `recipient_id` = " $account['user_id'] . " AND `seen` = 0 ORDER BY `id` DESC";
      } else {
            
$query_one " SELECT * FROM " T_NOTIFICATION " WHERE `recipient_id` = " $account['user_id'];
            if (isset(
$data['unread']) && $data['unread'] == true) {
                  
$query_one .= " AND `seen` = 0";
            }
            
$query_one .= " ORDER BY `id` DESC LIMIT 15";
      }
      if (isset(
$data['all']) && $data['all'] == true) {
            
$query_one "SELECT * FROM " T_NOTIFICATION " WHERE `recipient_id` = " $account['user_id'] . " AND `seen` = 0 ORDER BY `id` DESC LIMIT 20";
      }
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) > 0) {
            while (
$sql_fetch_one mysqli_fetch_assoc($sql_query_one)) {
                  if (!empty(
$sql_fetch_one['page_id']) && empty($sql_fetch_one['notifier_id'])) {
                        
$sql_fetch_one['notifier']        = Wo_PageData($sql_fetch_one['page_id']);
                        
$sql_fetch_one['notifier']['url'] = Wo_SeoLink('index.php?tab1=page&p=' $sql_fetch_one['notifier']['page_name']);
                  } else {
                        
$sql_fetch_one['notifier']        = Wo_UserData($sql_fetch_one['notifier_id']);
                        
$sql_fetch_one['notifier']['url'] = Wo_SeoLink('index.php?tab1=timeline&u=' $sql_fetch_one['notifier']['username']);
                  }
                  
$sql_fetch_one['url'] = Wo_SeoLink($sql_fetch_one['url']);
                  
$get[]                = $sql_fetch_one;
            }
      }
      
mysqli_query($sqlConnect" DELETE FROM " T_NOTIFICATION " WHERE `time` < " . (time() - (60 60 24 5)) . " AND `seen` > 0");
      return 
$get;
}
// count notifications
function Wo_CountNotifications($data = array()) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$get = array();
      if (empty(
$data['account_id']) or $data['account_id'] == 0) {
            
$data['account_id'] = Wo_Secure($wo['user']['user_id']);
            
$account            $wo['user'];
      }
      if (!
is_numeric($data['account_id']) or $data['account_id'] < 1) {
            return 
false;
      }
      if (
$data['account_id'] != $wo['user']['user_id']) {
            
$data['account_id'] = Wo_Secure($data['account_id']);
            
$account            Wo_UserData($data['account_id']);
      }
      
$query_one " SELECT COUNT(`id`) AS `notifications` FROM " T_NOTIFICATION " WHERE `recipient_id` = " $account['user_id'];
      if (isset(
$data['unread']) && $data['unread'] == true) {
            
$query_one .= " AND `seen` = 0";
      }
      
$query_one .= " ORDER BY `id` DESC";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      
$sql_fetch_one mysqli_fetch_assoc($sql_query_one);
      return 
$sql_fetch_one['notifications'];
}
// search for users 
function Wo_GetSearch($search_qeury) {
      
// Global required variables
      
global $sqlConnect;
      
$search_qeury Wo_Secure($search_qeury);
      
$data         = array();
      
$query        mysqli_query($sqlConnect" SELECT `user_id` FROM " T_USERS " WHERE ((`username` LIKE '%$search_qeury%') OR CONCAT( `first_name`,  ' ', `last_name` ) LIKE '%$search_qeury%') AND `active` = '1' LIMIT 10");
      while (
$fetched_data mysqli_fetch_assoc($query)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      if (empty(
$data)) {
            
$query mysqli_query($sqlConnect" SELECT `page_id` FROM " T_PAGES " WHERE ((`page_name` LIKE '%$search_qeury%') OR `page_title` LIKE '%$search_qeury%') AND `active` = '1' LIMIT 10");
            while (
$fetched_data mysqli_fetch_assoc($query)) {
                  
$data[] = Wo_PageData($fetched_data['page_id']);
            }
      }
      return 
$data;
}
// search for users by filter
function Wo_GetSearchFilter($result$limit 30) {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data = array();
      
$time time() - 60;
      if (empty(
$result)) {
            return array();
      }
      if (!empty(
$result['query'])) {
            
$result['query'] = Wo_Secure($result['query']);
      }
      if (!empty(
$result['country'])) {
            
$result['country'] = Wo_Secure($result['country']);
      }
      if (!empty(
$result['gender'])) {
            
$result['gender'] = Wo_Secure($result['gender']);
      }
      if (!empty(
$result['status'])) {
            
$result['status'] = Wo_Secure($result['status']);
      }
      if (!empty(
$result['image'])) {
            
$result['image'] = Wo_Secure($result['image']);
      }
      
$query " SELECT `user_id` FROM " T_USERS " WHERE (`username` LIKE '%" $result['query'] . "%' OR CONCAT( `first_name`,  ' ', `last_name` ) LIKE  '%" $result['query'] . "%')";
      if (isset(
$result['gender'])) {
            
$result['gender'] = Wo_Secure($result['gender']);
            if (
$result['gender'] == 'male') {
                  
$query .= " AND (`gender` = 'male') ";
            } else if (
$result['gender'] == 'female') {
                  
$query .= " AND (`gender` = 'female') ";
            }
      }
      if (isset(
$result['country'])) {
            
$result['country'] = Wo_Secure($result['country']);
            if (
$result['country'] != 'all') {
                  
$query .= " AND (`country_id` = " $result['country'] . ') ';
            }
      }
      if (isset(
$result['status'])) {
            
$result['status'] = Wo_Secure($result['status']);
            if (
$result['status'] == 'on') {
                  
$query .= " AND (`lastseen` >= {$time}) ";
            } else if (
$result['status'] == 'off') {
                  
$query .= " AND (`lastseen` <= {$time}) ";
            }
      }
      if (isset(
$result['image'])) {
            
$result['image'] = Wo_Secure($result['image']);
            
$d_image         Wo_Secure($wo['userDefaultAvatar']);
            if (
$result['image'] == 'yes') {
                  
$query .= " AND (`avatar` <> '{$d_image}') ";
            } else if (
$result['image'] == 'no') {
                  
$query .= " AND (`avatar` = '{$d_image}') ";
            }
      }
      if (
Wo_IsLogged() === true) {
            
$user_id Wo_Secure($wo['user']['user_id']);
            
$query .= " AND `user_id` <> {$user_id}";
      }
      
$query .= " AND `active` = '1' ";
      if (!empty(
$limit)) {
            
$limit Wo_Secure($limit);
            
$query .= " ORDER BY `first_name` LIMIT {$limit}";
      }
      
$sql_query_one mysqli_query($sqlConnect$query);
      while (
$fetched_data mysqli_fetch_assoc($sql_query_one)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      if (empty(
$data)) {
            
$query mysqli_query($sqlConnect" SELECT `page_id` FROM " T_PAGES " WHERE ((`page_name` LIKE '%" $result['query'] . "') OR `page_title` LIKE '%" $result['query'] . "%') AND `active` = '1' LIMIT 10");
            while (
$fetched_data mysqli_fetch_assoc($query)) {
                  
$data[] = Wo_PageData($fetched_data['page_id']);
            }
      }
      return 
$data;
}
// get message user list
function Wo_GetMessagesUsers($user_id$searchQuery ''$limit 50$new false$update 0) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!
is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      if (!isset(
$user_id)) {
            
$user_id $wo['user']['user_id'];
      }
      
$data     = array();
      
$excludes = array();
      if (isset(
$searchQuery) AND !empty($searchQuery)) {
            
$query_one " SELECT `user_id` FROM " T_USERS " WHERE (`user_id` IN (SELECT `from_id` FROM " T_MESSAGES " WHERE `to_id` = {$user_id} AND `active` = '1' ";
            if (isset(
$new) && $new == true) {
                  
$query_one .= " AND `seen` = 0";
            }
            
$query_one .= " ORDER BY `user_id` DESC)";
            if (!isset(
$new) or $new == false) {
                  
$query_one .= " OR `user_id` IN (SELECT `to_id` FROM " T_MESSAGES " WHERE `from_id` = {$user_id} ORDER BY `id` DESC)";
            }
            
$query_one .= ") AND ((`username` LIKE '%{$searchQuery}%') OR CONCAT( `first_name`,  ' ', `last_name` ) LIKE  '%{$searchQuery}%')";
      } else {
            
$query_one "SELECT `user_id` FROM " T_USERS " WHERE (`user_id` IN (SELECT `from_id` FROM " T_MESSAGES " WHERE `to_id` = {$user_id} AND `active` = '1'";
            if (isset(
$new) && $new == true) {
                  
$query_one .= " AND `seen` = 0";
            }
            
$query_one .= " ORDER BY `user_id` DESC)";
            if (!isset(
$new) or $new == false) {
                  
$query_one .= " OR `user_id` IN (SELECT `to_id` FROM " T_MESSAGES " WHERE `from_id` = {$user_id} ORDER BY `id` DESC)";
            }
            
$query_one .= ")";
      }
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) > 0) {
            while (
$sql_fetch_one mysqli_fetch_assoc($sql_query_one)) {
                  
$data[]     = Wo_UserData($sql_fetch_one['user_id']);
                  
$excludes[] = $sql_fetch_one['user_id'];
            }
      }
      
$exclude_query_string 0;
      
$exclude_i            0;
      
$excludes_num         count($excludes);
      if (
$excludes_num 0) {
            
$exclude_query_string '';
            foreach (
$excludes as $exclude) {
                  
$exclude_i++;
                  
$exclude_query_string .= $exclude;
                  if (
$exclude_i != $excludes_num) {
                        
$exclude_query_string .= ',';
                  }
            }
      }
      
$query_two "SELECT `user_id` FROM " T_USERS " WHERE `user_id` IN (SELECT `following_id` FROM " T_FOLLOWERS " WHERE `follower_id` = {$user_id} AND `following_id` NOT IN ({$user_id}{$exclude_query_string})) AND `active` = '1'";
      if (!empty(
$searchQuery)) {
            
$query_two .= " AND ((`username` LIKE '%$searchQuery%') OR CONCAT( first_name,  ' ', last_name ) LIKE  '%{$searchQuery}%')";
      }
      
$query_two .= " ORDER BY `lastseen` DESC LIMIT {$limit}";
      
$sql_query_two mysqli_query($sqlConnect$query_two);
      while (
$sql_fetch_two mysqli_fetch_assoc($sql_query_two)) {
            
$data[] = Wo_UserData($sql_fetch_two['user_id']);
      }
      return 
$data;
}
// get messages
function Wo_GetMessages($data = array(), $limit 50) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$message_data   = array();
      
$user_id        Wo_Secure($data['user_id']);
      
$logged_user_id Wo_Secure($wo['user']['user_id']);
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            return 
false;
      }
      
$query_one " SELECT * FROM " T_MESSAGES;
      if (isset(
$data['new']) && $data['new'] == true) {
            
$query_one .= " WHERE `seen` = 0 AND `from_id` = {$user_id} AND `to_id` = {$logged_user_id}";
      } else {
            
$query_one .= " WHERE ((`from_id` = {$user_id} AND `to_id` = {$logged_user_id}) OR (`from_id` = {$logged_user_id} AND `to_id` = {$user_id}))";
      }
      if (!empty(
$data['message_id'])) {
            
$data['message_id'] = Wo_Secure($data['message_id']);
            
$query_one .= " AND `id` = " $data['message_id'];
      } else if (!empty(
$data['before_message_id']) && is_numeric($data['before_message_id']) && $data['before_message_id'] > 0) {
            
$data['before_message_id'] = Wo_Secure($data['before_message_id']);
            
$query_one .= " AND `id` < " $data['before_message_id'] . " AND `id` <> " $data['before_message_id'];
      } else if (!empty(
$data['after_message_id']) && is_numeric($data['after_message_id']) && $data['after_message_id'] > 0) {
            
$data['after_message_id'] = Wo_Secure($data['after_message_id']);
            
$query_one .= " AND `id` > " $data['after_message_id'] . " AND `id` <> " $data['after_message_id'];
      }
      
$sql_query_one    mysqli_query($sqlConnect$query_one);
      
$query_limit_from mysqli_num_rows($sql_query_one) - 50;
      if (
$query_limit_from 1) {
            
$query_limit_from 0;
      }
      if (isset(
$limit)) {
            
$query_one .= " ORDER BY `id` ASC LIMIT {$query_limit_from}, 50";
      }
      
$query mysqli_query($sqlConnect$query_one);
      while (
$fetched_data mysqli_fetch_assoc($query)) {
            
$fetched_data['messageUser'] = Wo_UserData($fetched_data['from_id']);
            
$fetched_data['text']        = Wo_Markup($fetched_data['text']);
            
$fetched_data['text']        = Wo_Emo($fetched_data['text']);
            
$fetched_data['onwer']       = ($fetched_data['messageUser']['user_id'] == $wo['user']['user_id']) ? 0;
            
$message_data[]              = $fetched_data;
            if (
$fetched_data['messageUser']['user_id'] == $user_id && $fetched_data['seen'] == 0) {
                  
mysqli_query($sqlConnect" UPDATE " T_MESSAGES " SET `seen` = " time() . " WHERE `id` = " $fetched_data['id']);
            }
      }
      return 
$message_data;
}
// register message
function Wo_RegisterMessage($ms_data = array()) {
      
// Global required variables
      
global $sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$ms_data)) {
            return 
false;
      }
      if (empty(
$ms_data['to_id']) || !is_numeric($ms_data['to_id']) || $ms_data['to_id'] < 0) {
            return 
false;
      }
      if (empty(
$ms_data['from_id']) || !is_numeric($ms_data['from_id']) || $ms_data['from_id'] < 0) {
            return 
false;
      }
      if (empty(
$ms_data['text']) || !isset($ms_data['text']) || strlen($ms_data['text']) < 0) {
            if (empty(
$ms_data['media']) || !isset($ms_data['media']) || strlen($ms_data['media']) < 0) {
                  return 
false;
            }
      }
      
$link_regex '/(http://|https://|www.)([^ ]+)/i';
      
$i          0;
      
preg_match_all($link_regex$ms_data['text'], $matches);
      foreach (
$matches[0] as $match) {
            
$match_url       strip_tags($match);
            
$syntax          '[a]' urlencode($match_url) . '[/a]';
            
$ms_data['text'] = str_replace($match$syntax$ms_data['text']);
      }
      
$mention_regex '/@([A-Za-z0-9_]+)/i';
      
preg_match_all($mention_regex$ms_data['text'], $matches);
      foreach (
$matches[1] as $match) {
            
$match         Wo_Secure($match);
            
$match_user    Wo_UserData(Wo_UserIdFromUsername($match));
            
$match_search  '@' $match;
            
$match_replace '@[' $match_user['user_id'] . ']';
            if (isset(
$match_user['user_id'])) {
                  
$ms_data['text'] = str_replace($match_search$match_replace$ms_data['text']);
                  
$mentions[]      = $match_user['user_id'];
            }
      }
      
$hashtag_regex '/#([^`~!@$%^&*#()-+=\|/.,<>?'":;{}[]* ]+)/i';
      preg_match_all(
$hashtag_regex$ms_data['text'], $matches);
      foreach (
$matches[1] as $match) {
            if (!is_numeric(
$match)) {
                  
$hashdata = Wo_GetHashtag($match);
                  if (is_array(
$hashdata)) {
                        
$match_search      = '#' . $match;
                        
$match_replace     = '#[' . $hashdata['id'] . ']';
                        
$ms_data['text']   = str_replace($match_search$match_replace$ms_data['text']);
                        
$hashtag_query     = " UPDATE " . T_HASHTAGS . " SET `last_trend_time` = " . time() . ", `trend_use_num` = " . ($hashdata['trend_use_num'] + 1) . " WHERE `id` = " . $hashdata['id'];
                        
$hashtag_sql_query = mysqli_query($sqlConnect$hashtag_query);
                  }
            }
      }
      
$fields = '`' . implode('`, `', array_keys($ms_data)) . '`';
      
$data   = ''' . implode('', '', $ms_data) . ''';
      
$query  = mysqli_query($sqlConnect, " INSERT INTO " . T_MESSAGES . " ({$fields}) VALUES ({$data})");
      if (
$query) {
            
$message_id = mysqli_insert_id($sqlConnect);
            return 
$message_id;
      } else {
            return false;
      }
}
// delete message
function Wo_DeleteMessage(
$message_id$media = '') {
      // Global required variables
      global 
$wo$sqlConnect;
      if (Wo_IsLogged() === false) {
            return false;
      }
      if (empty(
$message_id) || !is_numeric($message_id) || $message_id < 0) {
            return false;
      }
      
$message_id    = Wo_Secure($message_id);
      
$query_one     = " SELECT `id`, `from_id`, `mediaFROM " . T_MESSAGES . " WHERE `id` = {$message_id}";
      
$sql_query_one = mysqli_query($sqlConnect$query_one);
      if (mysqli_num_rows(
$sql_query_one) == 1) {
            
$sql_fetch_one = mysqli_fetch_assoc($sql_query_one);
            
$user_fetch    = Wo_UserData($sql_fetch_one['from_id']);
            
$continue      = false;
            if (
$user_fetch['user_id'] == $wo['user']['user_id']) {
                  
$continue = true;
            }
            if (
$continue == true) {
                  
$query = mysqli_query($sqlConnect, " DELETE FROM " . T_MESSAGES . " WHERE `id` = {$message_id}");
                  if (
$query) {
                        if (isset(
$sql_fetch_one['media']) AND !empty($sql_fetch_one['media'])) {
                              @unlink(
$sql_fetch_one['media']);
                        }
                        return true;
                  } else {
                        return false;
                  }
            } else {
                  return false;
            }
      }
}
// count messages
function Wo_CountMessages(
$data = array(), $type = '') {
      // Global required variables
      global 
$wo$sqlConnect;
      if (Wo_IsLogged() === false) {
            return false;
      }
      if (empty(
$data['user_id']) or $data['user_id'] == 0) {
            
$data['user_id'] = $wo['user']['user_id'];
      }
      if (!is_numeric(
$data['user_id']) or $data['user_id'] < 1) {
            return false;
      }
      
$data['user_id'] = Wo_Secure($data['user_id']);
      if (
$type == 'interval') {
            
$account = $wo['user'];
      } else {
            
$account = Wo_UserData($data['user_id']);
      }
      if (empty(
$account['user_id'])) {
            return false;
      }
      
$logged_user_id = Wo_Secure($wo['user']['user_id']);
      if (isset(
$data['user_id']) && is_numeric($data['user_id']) && $data['user_id'] > 0) {
            
$user_id = Wo_Secure($data['user_id']);
            if (isset(
$data['new']) && $data['new'] == true) {
                  
$query = " SELECT COUNT(`id`) AS `messagesFROM " . T_MESSAGES . " WHERE `to_id` = {$logged_user_id}";
                  if (
$wo['user']['user_id'] != $user_id) {
                        
$query .= " AND `from_id` = {$user_id}";
                  }
            } else {
                  
$query = " SELECT COUNT(`id`) AS `messagesFROM " . T_MESSAGES . " WHERE ((`from_id` = {$user_id} AND `to_id` = {$logged_user_id}) OR (`from_id` = {$logged_user_id} AND `to_id` = {$user_id}))";
            }
      } else {
            
$query = " SELECT COUNT(`from_id`) AS `messagesFROM " . T_MESSAGES . " WHERE `to_id` = {$logged_user_id}";
      }
      if (isset(
$data['new']) && $data['new'] == true) {
            
$query .= " AND `seen` = 0";
      }
      
$sql_query = mysqli_query($sqlConnect$query);
      
$sql_fetch = mysqli_fetch_assoc($sql_query);
      return 
$sql_fetch['messages'];
}
// check if message seen
function Wo_SeenMessage(
$message_id) {
      // Global required variables
      global 
$sqlConnect;
      
$message_id   = Wo_Secure($message_id);
      
$query        = mysqli_query($sqlConnect, " SELECT `seenFROM " . T_MESSAGES . " WHERE `id` = {$message_id}");
      
$fetched_data = mysqli_fetch_assoc($query);
      if (
$fetched_data['seen'] > 0) {
            
$data         = array();
            
$data['time'] = date('c', $fetched_data['seen']);
            
$data['seen'] = Wo_Time_Elapsed_String($fetched_data['seen']);
            return 
$data;
      } else {
            return false;
      }
}
// get message button
function Wo_GetMessageButton(
$user_id = 0) {
      // Global required variables
      global 
$wo$sqlConnect;
      if (Wo_IsLogged() === false) {
            return false;
      }
      if (!is_numeric(
$user_id) or $user_id < 0) {
            return false;
      }
      if (
$user_id == $wo['user']['user_id']) {
            return false;
      }
      
$user_id        = Wo_Secure($user_id);
      
$logged_user_id = Wo_Secure($wo['user']['user_id']);
      
$message_button = 'buttons/message';
      
$account        = $wo['message'] = Wo_UserData($user_id);
      if (!isset(
$account['user_id'])) {
            return false;
      }
      if (
$account['message_privacy'] == 1) {
            if (Wo_IsFollowing(
$logged_user_id$user_id) === true) {
                  return Wo_LoadPage(
$message_button);
            }
      } else if (
$account['message_privacy'] == 0) {
            return Wo_LoadPage(
$message_button);
      }
}
// create text markup (hashtags | links | mentions)
function Wo_Markup(
$text$link = true, $hashtag = true, $mention = true) {
      if (
$link == true) {
            
$link_search = '/[a](.*?)[/a]/i';
            if (preg_match_all(
$link_search$text$matches)) {
                  foreach (
$matches[1] as $match) {
                        
$match_decode = urldecode($match);
                        
$match_url    = $match_decode;
                        if (!preg_match("
/http(|s):///", $match_decode)) {
                              
$match_url 'http://' $match_url;
                        }
                        
$text str_replace('[a]' $match '[/a]''<a href="' strip_tags($match_url) . '" target="_blank" class="hash" rel="nofollow">' $match_decode '</a>'$text);
                  }
            }
      }
      if (
$hashtag == true) {
            
// Hashtags
            
$hashtag_regex '/(#[([0-9]+)])/i';
            
preg_match_all($hashtag_regex$text$matches);
            
$match_i 0;
            foreach (
$matches[1] as $match) {
                  
$hashtag  $matches[1][$match_i];
                  
$hashkey  $matches[2][$match_i];
                  
$hashdata Wo_GetHashtag($hashkey);
                  if (
is_array($hashdata)) {
                        
$hashlink '<a href="' Wo_SeoLink('index.php?tab1=hashtag&hash=' $hashdata['tag']) . '" class="hash">#' $hashdata['tag'] . '</a>';
                        
$text     str_replace($hashtag$hashlink$text);
                  }
                  
$match_i++;
            }
      }
      if (
$mention == true) {
            
// @Mentions
            
$mention_regex '/@[([0-9]+)]/i';
            if (
preg_match_all($mention_regex$text$matches)) {
                  foreach (
$matches[1] as $match) {
                        
$match         Wo_Secure($match);
                        
$match_user    Wo_UserData($match);
                        
$match_search  '@[' $match ']';
                        
$match_replace '<a href="' Wo_SeoLink('index.php?tab1=timeline&u=' $match_user['username']) . '" class="hash">' $match_user['name'] . '</a>';
                        if (isset(
$match_user['user_id'])) {
                              
$text str_replace($match_search$match_replace$text);
                        }
                  }
            }
      }
      return 
$text;
}
// create text markup (hashtags | links | mentions) for post editing
function Wo_EditMarkup($text$link true$hashtag true$mention true) {
      if (
$link == true) {
            
$link_search '/[a](.*?)[/a]/i';
            if (
preg_match_all($link_search$text$matches)) {
                  foreach (
$matches[1] as $match) {
                        
$match_decode urldecode($match);
                        
$match_url    $match_decode;
                        if (!
preg_match("/http(|s):///"$match_decode)) {
                              
$match_url 'http://' $match_url;
                        }
                        
$text str_replace('[a]' $match '[/a]'$match_decode$text);
                  }
            }
      }
      if (
$hashtag == true) {
            
// Hashtags
            
$hashtag_regex '/(#[([0-9]+)])/i';
            
preg_match_all($hashtag_regex$text$matches);
            
$match_i 0;
            foreach (
$matches[1] as $match) {
                  
$hashtag  $matches[1][$match_i];
                  
$hashkey  $matches[2][$match_i];
                  
$hashdata Wo_GetHashtag($hashkey);
                  if (
is_array($hashdata)) {
                        
$hashlink '#' $hashdata['tag'];
                        
$text     str_replace($hashtag$hashlink$text);
                  }
                  
$match_i++;
            }
      }
      if (
$mention == true) {
            
// @Mentions
            
$mention_regex '/@[([0-9]+)]/i';
            if (
preg_match_all($mention_regex$text$matches)) {
                  foreach (
$matches[1] as $match) {
                        
$match         Wo_Secure($match);
                        
$match_user    Wo_UserData($match);
                        
$match_search  '@[' $match ']';
                        
$match_replace '@' $match_user['username'];
                        if (isset(
$match_user['user_id'])) {
                              
$text str_replace($match_search$match_replace$text);
                        }
                  }
            }
      }
      return 
$text;
}
// get emoticons
function Wo_Emo($string '') {
      
// Global required variables
      
global $emo;
      foreach (
$emo as $code => $name) {
            
$code   $code;
            
$name   '<i class="twa-lg twa twa-' $name '"></i>';
            
$string str_replace($code$name$string);
      }
      return 
$string;
}
// upload & share files 
function Wo_ShareFile($data = array()) {
      
// Global required variables
      
global $wo$sqlConnect;
      
$allowed '';
      if (!
file_exists('upload/files/' date('Y'))) {
            @
mkdir('upload/files/' date('Y'), 0777true);
      }
      if (!
file_exists('upload/files/' date('Y') . '/' date('m'))) {
            @
mkdir('upload/files/' date('Y') . '/' date('m'), 0777true);
      }
      if (!
file_exists('upload/photos/' date('Y'))) {
            @
mkdir('upload/photos/' date('Y'), 0777true);
      }
      if (!
file_exists('upload/photos/' date('Y') . '/' date('m'))) {
            @
mkdir('upload/photos/' date('Y') . '/' date('m'), 0777true);
      }
      if (!
file_exists('upload/videos/' date('Y'))) {
            @
mkdir('upload/videos/' date('Y'), 0777true);
      }
      if (!
file_exists('upload/videos/' date('Y') . '/' date('m'))) {
            @
mkdir('upload/videos/' date('Y') . '/' date('m'), 0777true);
      }
      if (!
file_exists('upload/sounds/' date('Y'))) {
            @
mkdir('upload/sounds/' date('Y'), 0777true);
      }
      if (!
file_exists('upload/sounds/' date('Y') . '/' date('m'))) {
            @
mkdir('upload/sounds/' date('Y') . '/' date('m'), 0777true);
      }
      if (isset(
$data['file']) && !empty($data['file'])) {
            
$data['file'] = Wo_Secure($data['file']);
      }
      if (isset(
$data['name']) && !empty($data['name'])) {
            
$data['name'] = Wo_Secure($data['name']);
      }
      if (isset(
$data['name']) && !empty($data['name'])) {
            
$data['name'] = Wo_Secure($data['name']);
      }
      if (empty(
$data)) {
            return 
false;
      }
      if (
$wo['config']['fileSharing'] == 1) {
            
$allowed $wo['config']['allowedExtenstion'];
      } else {
            
$allowed 'jpg,png,jpeg,gif';
      }
      
$new_string        pathinfo($data['name'], PATHINFO_FILENAME) . '.' strtolower(pathinfo($data['name'], PATHINFO_EXTENSION));
      
$extension_allowed explode(','$allowed);
      
$file_extension    pathinfo($new_stringPATHINFO_EXTENSION);
      if (!
in_array($file_extension$extension_allowed)) {
            return 
false;
      }
      if (
$data['size'] > $wo['config']['maxUpload']) {
            return 
false;
      }
      if (
$file_extension == 'jpg' || $file_extension == 'jpeg' || $file_extension == 'png' || $file_extension == 'gif') {
            
$folder   'photos';
            
$fileType 'image';
      } else if (
$file_extension == 'mp4' || $file_extension == 'webm' || $file_extension == 'flv') {
            
$folder   'videos';
            
$fileType 'video';
      } else if (
$file_extension == 'mp3' || $file_extension == 'wav') {
            
$folder   'sounds';
            
$fileType 'soundFile';
      } else {
            
$folder   'files';
            
$fileType 'file';
      }
      if (empty(
$folder) || empty($fileType)) {
            return 
false;
      }
      
$dir         "upload/{$folder}/" date('Y') . '/' date('m');
      
$filename    $dir '/' Wo_GenerateKey() . '_' date('d') . '_' md5(time()) . "_{$fileType}.{$file_extension}";
      
$second_file pathinfo($filenamePATHINFO_EXTENSION);
      if (
move_uploaded_file($data['file'], $filename)) {
            if (
$second_file == 'jpg' || $second_file == 'jpeg' || $second_file == 'png') {
                  @
Wo_CompressImage($filename$filename60);
            }
            
$last_data             = array();
            
$last_data['filename'] = $filename;
            
$last_data['name']     = $data['name'];
            return 
$last_data;
      }
}
// display shared file
function Wo_DisplaySharedFile($media$placement '') {
      
// Global required variables
      
global $wo$sqlConnect;
      
$wo['media']['filename'] = Wo_GetMedia($media['filename']);
      
$wo['media']['name']     = Wo_Secure($media['name']);
      
$wo['media']['type']     = $media['type'];
      
$icon_size               'fa-2x';
      if (
$placement == 'chat') {
            
$icon_size '';
      }
      if (!empty(
$wo['media']['filename'])) {
            
$file_extension pathinfo($wo['media']['filename'], PATHINFO_EXTENSION);
            
$file           '';
            
$media_file     '';
            
$start_link     "<a href=" $wo['media']['filename'] . ">";
            
$end_link       '</a>';
            
$file_extension strtolower($file_extension);
            if (
$file_extension == 'jpg' || $file_extension == 'jpeg' || $file_extension == 'png' || $file_extension == 'gif') {
                  if (
$placement != 'chat') {
                        
$media_file .= "<img src='" $wo['media']['filename'] . "' alt='Image' class='image-file pointer' data-toggle='modal' data-target='#ImageModal-" $media['storyId'] . "'>";
                  } else {
                        
$media_file .= "<a href='" $wo['media']['filename'] . "' target='_blank'><img src='" $wo['media']['filename'] . "' alt='Image' class='image-file pointer'></a>";
                  }
                  if (
$media['type'] == 'post') {
                        
$media_file .= Wo_LoadPage('modals/post-image');
                  } else if (
$media['type'] == 'message') {
                        
$media_file .= Wo_LoadPage('modals/message-image');
                  }
            }
            if (
$file_extension == 'pdf') {
                  
$file .= '<i class="fa ' $icon_size ' fa-file-pdf-o"></i> ' $wo['media']['name'];
            }
            if (
$file_extension == 'txt') {
                  
$file .= '<i class="fa ' $icon_size ' fa-file-text-o"></i> ' $wo['media']['name'];
            }
            if (
$file_extension == 'zip' || $file_extension == 'rar' || $file_extension == 'tar') {
                  
$file .= '<i class="fa ' $icon_size ' fa-file-archive-o"></i> ' $wo['media']['name'];
            }
            if (
$file_extension == 'doc' || $file_extension == 'docx') {
                  
$file .= '<i class="fa ' $icon_size ' fa-file-word-o"></i> ' $wo['media']['name'];
            }
            if (
$file_extension == 'mp3' || $file_extension == 'wav') {
                  if (
$placement == 'chat') {
                        
$file .= '<i class="fa ' $icon_size ' fa-music"></i> ' $wo['media']['name'];
                  } else {
                        
$media_file .= Wo_LoadPage('players/audio');
                  }
            }
            if (empty(
$file)) {
                  
$file .= '<i class="fa ' $icon_size ' fa-file-o"></i> ' $wo['media']['name'];
            }
            if (
$file_extension == 'mp4' || $file_extension == 'mkv') {
                  
$media_file .= Wo_LoadPage('players/video');
            }
            
$last_file_view '';
            if (isset(
$media_file) && !empty($media_file)) {
                  
$last_file_view $media_file;
            } else {
                  
$last_file_view $start_link $file $end_link;
            }
            return 
$last_file_view;
      }
}
// check if logged in user has access to admin panel
function Wo_IsAdmin($user_id) {
      
// Global required variables
      
global $sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            
$user_id $wo['user']['user_id'];
      }
      
$query mysqli_query($sqlConnect" SELECT COUNT(`user_id`) FROM " T_USERS " WHERE `admin` = '1' AND `user_id` = {$user_id} AND `active` = '1'");
      return (
Wo_Sql_Result($query'0') == 1) ? true false;
}
// register post
function Wo_RegisterPost($re_data = array('recipient_id' => 0), $post_video '') {
      
// Global required variables
      
global $wo$sqlConnect;
      if (empty(
$re_data['user_id']) or $re_data['user_id'] == 0) {
            
$re_data['user_id'] = $wo['user']['user_id'];
      }
      if (!
is_numeric($re_data['user_id']) or $re_data['user_id'] < 0) {
            return 
false;
      }
      if (
$re_data['user_id'] == $wo['user']['user_id']) {
            
$timeline $wo['user'];
      } else {
            
$re_data['user_id'] = Wo_Secure($re_data['user_id']);
            
$timeline           Wo_UserData($re_data['user_id']);
      }
      if (
$timeline['user_id'] != $wo['user']['user_id']) {
            return 
false;
      }
      if (!empty(
$re_data['page_id'])) {
            if (
Wo_IsPageOnwer($re_data['page_id']) === false) {
                  return 
false;
            }
      }
      if (!empty(
$re_data['postText'])) {
            if (
$wo['config']['maxCharacters'] > 0) {
                  if (
mb_strlen($re_data['postText']) > $wo['config']['maxCharacters']) {
                        
//return false;
                  
}
            }
            
// Links
            
$link_regex '/(http://|https://|www.)([^ ]+)/i';
            
$i          0;
            
preg_match_all($link_regex$re_data['postText'], $matches);
            foreach (
$matches[0] as $match) {
                  
$match_url           strip_tags($match);
                  
$syntax              '[a]' urlencode($match_url) . '[/a]';
                  
$re_data['postText'] = str_replace($match$syntax$re_data['postText']);
            }
            
// @Mentions
            
$mention_regex '/@([A-Za-z0-9_]+)/i';
            
preg_match_all($mention_regex$re_data['postText'], $matches);
            foreach (
$matches[1] as $match) {
                  
$match         Wo_Secure($match);
                  
$match_user    Wo_UserData(Wo_UserIdFromUsername($match));
                  
$match_search  '@' $match;
                  
$match_replace '@[' $match_user['user_id'] . ']';
                  if (isset(
$match_user['user_id'])) {
                        
$re_data['postText'] = str_replace($match_search$match_replace$re_data['postText']);
                        
$mentions[]          = $match_user['user_id'];
                  }
            }
            
$hashtag_regex '/#([^`~!@$%^&*#()-+=\|/.,<>?'":;{}[]* ]+)/i';
            preg_match_all(
$hashtag_regex$re_data['postText'], $matches);
            foreach (
$matches[1] as $match) {
                  if (!is_numeric(
$match)) {
                        
$hashdata = Wo_GetHashtag($match);
                        if (is_array(
$hashdata)) {
                              
$match_search        = '#' . $match;
                              
$match_replace       = '#[' . $hashdata['id'] . ']';
                              
$re_data['postText'] = str_replace($match_search$match_replace$re_data['postText']);
                              
$hashtag_query       = "UPDATE " . T_HASHTAGS . " SET `last_trend_time` = " . time() . ", `trend_use_num` = " . ($hashdata['trend_use_num'] + 1) . " WHERE `id` = " . $hashdata['id'];
                              
$hashtag_sql_query   = mysqli_query($sqlConnect$hashtag_query);
                        }
                  }
            }
      }
      
$re_data['postVine']        = '';
      
$re_data['postYoutube']     = '';
      
$re_data['postVimeo']       = '';
      
$re_data['postDailymotion'] = '';
      
$re_data['postFacebook']    = '';
      
$is_there_video             = false;
      if (!empty(
$post_video)) {
            if (preg_match('%(?:youtube(?:-nocookie)?.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu.be/)([^"
&?/ ]{11})%i', $post_video, $match)) {
                  $re_data['
postYoutube'] = Wo_Secure($match[1]);
                  $is_there_video         = true;
            } else if (preg_match("#(?<=vine.co/v/)[0-9A-Za-z]+#", $post_video, $match)) {
                  $re_data['
postVine'] = Wo_Secure($match[0]);
                  $is_there_video      = true;
            } else if (preg_match("#https?://vimeo.com/([0-9]+)#i", $post_video, $match)) {
                  $re_data['
postVimeo'] = Wo_Secure($match[1]);
                  $is_there_video       = true;
            } else if (preg_match('
#http://www.dailymotion.com/video/([A-Za-z0-9]+)#s', $post_video, $match)) {
                  
$re_data['postDailymotion'] = Wo_Secure($match[1]);
                  
$is_there_video             true;
            } else if (
preg_match('~/videos/(?:t.d+/)?(d+)~i'$post_video$match)) {
                  
$re_data['postFacebook'] = Wo_Secure($match[1]);
                  
$is_there_video          true;
            }
      }
      if (!empty(
$re_data['postSoundCloud'])) {
            if (
preg_match('%(?:https?://)(?:www.)?soundcloud.com/([-a-z0-9_]+/[-a-z0-9_]+)%im'$re_data['postSoundCloud'])) {
                  
$arrContextOptions         = array(
                        
"ssl" => array(
                              
"verify_peer" => false,
                              
"verify_peer_name" => false
                        
)
                  );
                  
$url                       "https://api.soundcloud.com/resolve.json?url=" $re_data['postSoundCloud'] . "&client_id=d4f8636b1b1d07e4461dcdc1db226a53";
                  
$track_json                = @file_get_contents($urlfalsestream_context_create($arrContextOptions));
                  
$track                     json_decode($track_json);
                  
$re_data['postSoundCloud'] = $track->id;
            } else {
                  
$re_data['postSoundCloud'] = '';
            }
      }
      if (
$is_there_video == true) {
            
$re_data['postFile']       = '';
            
$re_data['postSoundCloud'] = '';
      } else if (!empty(
$re_data['postSoundCloud']) && empty($re_data['postFile'])) {
            
$re_data['postSoundCloud'] = $re_data['postSoundCloud'];
      } else if (!empty(
$re_data['postFile']) && empty($re_data['postSoundCloud'])) {
            
$re_data['postFile'] = $re_data['postFile'];
      } else if (!empty(
$re_data['postFile']) && !empty($re_data['postSoundCloud'])) {
            
$re_data['postFile']       = $re_data['postFile'];
            
$re_data['postSoundCloud'] = '';
      }
      if (empty(
$re_data['postText']) && empty($re_data['postFacebook']) && empty($re_data['postVimeo']) && empty($re_data['postDailymotion']) && empty($re_data['postVine']) && empty($re_data['postYoutube']) && empty($re_data['postFile']) && empty($re_data['postSoundCloud']) && empty($re_data['postMap'])) {
            return 
false;
      }
      if (!empty(
$re_data['recipient_id']) && is_numeric($re_data['recipient_id']) && $re_data['recipient_id'] > 0) {
            if (
$re_data['recipient_id'] == $re_data['user_id']) {
                  return 
false;
            }
            
$recipient Wo_UserData($re_data['recipient_id']);
            if (empty(
$recipient['user_id'])) {
                  return 
false;
            }
            if (!empty(
$recipient['user_id'])) {
                  if (
$recipient['post_privacy'] == 'ifollow') {
                        if (
Wo_IsFollowing($recipient['user_id'], $wo['user']['user_id']) === false) {
                              return 
false;
                        }
                  } else if (
$recipient['post_privacy'] == 'nobody') {
                        return 
false;
                  }
            }
      }
      if (!isset(
$re_data['postType'])) {
            
$re_data['postType'] = 'post';
      }
      if (!empty(
$re_data['page_id'])) {
            
$re_data['user_id'] = 0;
      }
      
$fields  '`' implode('`, `'array_keys($re_data)) . '`';
      
$data    ''' . implode('', '', $re_data) . ''';
      
$query   mysqli_query($sqlConnect"INSERT INTO " T_POSTS " ({$fields}) VALUES ({$data})");
      
$post_id mysqli_insert_id($sqlConnect);
      if (
$query) {
            
mysqli_query($sqlConnect"UPDATE " T_POSTS " SET `post_id` = {$post_id} WHERE `id` = {$post_id}");
            if (isset(
$recipient['user_id'])) {
                  
$notification_data_array = array(
                        
'recipient_id' => $recipient['user_id'],
                        
'post_id' => $post_id,
                        
'type' => 'profile_wall_post',
                        
'url' => 'index.php?tab1=post&id=' $post_id
                  
);
                  
Wo_RegisterNotification($notification_data_array);
            }
            if (isset(
$mentions) && is_array($mentions)) {
                  foreach (
$mentions as $mention) {
                        
$notification_data_array = array(
                              
'recipient_id' => $mention,
                              
'page_id' => $re_data['page_id'],
                              
'type' => 'post_mention',
                              
'url' => 'index.php?tab1=post&id=' $post_id
                        
);
                        
Wo_RegisterNotification($notification_data_array);
                  }
            }
            return 
$post_id;
      }
}
// get hashtags
function Wo_GetHashtag($tag '') {
      
// Global required variables
      
global $sqlConnect;
      
$create false;
      if (empty(
$tag)) {
            return 
false;
      }
      
$tag Wo_Secure($tag);
      if (
is_numeric($tag)) {
            
$query " SELECT * FROM " T_HASHTAGS " WHERE `id` = {$tag}";
      } else {
            
$query  " SELECT * FROM " T_HASHTAGS " WHERE `tag` = '{$tag}' ";
            
$create true;
      }
      
$sql_query   mysqli_query($sqlConnect$query);
      
$sql_numrows mysqli_num_rows($sql_query);
      if (
$sql_numrows == 1) {
            
$sql_fetch mysqli_fetch_assoc($sql_query);
            return 
$sql_fetch;
      } elseif (
$sql_numrows == 0) {
            if (
$create == true) {
                  
$hash          md5($tag);
                  
$query_two     " INSERT INTO " T_HASHTAGS " (`hash`, `tag`, `last_trend_time`) VALUES ('{$hash}', '{$tag}', " time() . ")";
                  
$sql_query_two mysqli_query($sqlConnect$query_two);
                  if (
$sql_query_two) {
                        
$sql_id mysqli_insert_id($sqlConnect);
                        
$get    = array(
                              
'id' => $sql_id,
                              
'hash' => $hash,
                              
'tag' => $tag,
                              
'last_trend_time' => time(),
                              
'trend_use_num' => 0
                        
);
                        return 
$get;
                  }
            }
      }
}
// get post data
function Wo_PostData($post_id$placement '') {
      
// Global required variables
      
global $wo$sqlConnect$cache;
      if (empty(
$post_id) || !is_numeric($post_id) || $post_id 0) {
            return 
false;
      }
      
$data           = array();
      
$post_id        Wo_Secure($post_id);
      
$query_one      "SELECT * FROM " T_POSTS " WHERE `id` = {$post_id}";
      
$hashed_post_Id md5($post_id);
      if (
$wo['config']['cacheSystem'] == 1) {
            
$fetched_data $cache->read($hashed_post_Id '_P_Data.tmp');
            if (empty(
$fetched_data)) {
                  
$sql_query_one mysqli_query($sqlConnect$query_one);
                  
$fetched_data  mysqli_fetch_assoc($sql_query_one);
                  
$cache->write($hashed_post_Id '_P_Data.tmp'$fetched_data);
            }
      } else {
            
//Wo_ClearCache();
            
$sql_query_one mysqli_query($sqlConnect$query_one);
            
$fetched_data  mysqli_fetch_assoc($sql_query_one);
      }
      if (!empty(
$fetched_data['page_id'])) {
            
$fetched_data['publisher'] = Wo_PageData($fetched_data['page_id']);
      } else {
            
$fetched_data['publisher'] = Wo_UserData($fetched_data['user_id']);
      }
      if (
$fetched_data['id'] == $fetched_data['post_id']) {
            
$story $fetched_data;
      } else {
            
$query_two     "SELECT * FROM " T_POSTS " WHERE `id` = " $fetched_data['post_id'];
            
$sql_query_two mysqli_query($sqlConnect$query_two);
            if (
mysqli_num_rows($sql_query_two) != 1) {
                  return 
false;
            }
            
$sql_fetch_two mysqli_fetch_assoc($sql_query_two);
            
$story         $sql_fetch_two;
            if (!empty(
$story['page_id'])) {
                  
$story['publisher'] = Wo_PageData($story['page_id']);
            } else {
                  
$story['publisher'] = Wo_UserData($story['user_id']);
            }
      }
      if (
$placement != 'admin') {
            if (
$story['postPrivacy'] == 1) {
                  if (
Wo_IsLogged() === true) {
                        if (!empty(
$story['publisher']['page_id'])) {
                        } else {
                              if (
$story['publisher']['user_id'] != $wo['user']['user_id']) {
                                    if (
Wo_IsFollowing($wo['user']['user_id'], $story['publisher']['user_id']) === false) {
                                          return 
false;
                                    }
                              }
                        }
                  } else {
                        return 
false;
                  }
            }
            if (
$story['postPrivacy'] == 2) {
                  if (
Wo_IsLogged() === true) {
                        if (!empty(
$story['publisher']['page_id'])) {
                              if (
$story['publisher']['user_id'] != $wo['user']['user_id']) {
                                    if (
Wo_IsPageLiked($story['publisher']['page_id'], $wo['user']['user_id']) === false) {
                                          return 
false;
                                    }
                              }
                        } else {
                              if (
$story['publisher']['user_id'] != $wo['user']['user_id']) {
                                    if (
Wo_IsFollowing($story['publisher']['user_id'], $wo['user']['user_id']) === false) {
                                          return 
false;
                                    }
                              }
                        }
                  } else {
                        return 
false;
                  }
            }
            if (
$story['postPrivacy'] == 3) {
                  if (
Wo_IsLogged() === true) {
                        if (!empty(
$story['publisher']['page_id'])) {
                        } else {
                              if (
$wo['user']['user_id'] != $story['publisher']['user_id']) {
                                    return 
false;
                              }
                        }
                  } else {
                        return 
false;
                  }
            }
      }
      
$story['Orginaltext'] = Wo_EditMarkup($story['postText']);
      
$story['Orginaltext'] = str_replace('<br>'"n"$story['Orginaltext']);
      
$story['postText']    = Wo_Emo($story['postText']);
      
$story['postText']    = Wo_Markup($story['postText']);
      
$story['page']        = 0;
      if (isset(
$story['Orginaltext']) && !empty($story['Orginaltext']) && $wo['config']['useSeoFrindly'] == 1) {
            
$story['url'] = Wo_SeoLink('index.php?tab1=post&id=' $story['id']) . '_' Wo_SlugPost($story['Orginaltext']);
      } else {
            
$story['url'] = Wo_SeoLink('index.php?tab1=post&id=' $story['id']);
      }
      
$story['via_type'] = '';
      if (
$story['id'] != $fetched_data['id'] && $story['user_id'] != $fetched_data['user_id']) {
            
$story['via_type'] = 'share';
            
$story['via']      = $fetched_data['publisher'];
      }
      
$story['recipient_exists'] = false;
      
$story['recipient']        = '';
      if (
$story['recipient_id'] > 0) {
            
$story['recipient_exists'] = true;
            
$story['recipient']        = Wo_UserData($story['recipient_id']);
      }
      
$story['admin'] = false;
      if (
Wo_IsLogged() === true) {
            if (!empty(
$story['page_id'])) {
                  if (
Wo_IsPageOnwer($story['page_id'])) {
                        
$story['admin'] = true;
                  }
            } else {
                  if (
$story['publisher']['user_id'] == $wo['user']['user_id']) {
                        
$story['admin'] = true;
                  }
            }
            if (
$story['recipient_exists'] == true) {
                  if (
$story['recipient']['user_id'] == $wo['user']['user_id']) {
                        
$story['admin'] = true;
                  }
            }
      }
      
$story['is_post_saved']     = false;
      
$story['is_post_reported']  = false;
      
$story['is_liked']          = false;
      
$story['is_wondered']       = false;
      
$story['post_comments']     = 0;
      
$story['post_shares']       = 0;
      
$story['post_likes']        = 0;
      
$story['post_wonders']      = 0;
      
$story['postLinkImage']     = Wo_GetMedia($story['postLinkImage']);
      
$story['is_post_pinned']    = (Wo_IsPostPinned($story['id']) === true) ? true false;
      
$story['get_post_comments'] = Wo_GetPostComments($story['id']);
      if (
Wo_IsLogged() === true) {
            
$story['post_comments']    = Wo_CountPostComment($story['id']);
            
$story['post_shares']      = Wo_CountShares($story['id']);
            
$story['post_likes']       = Wo_CountLikes($story['id']);
            
$story['post_wonders']     = Wo_CountWonders($story['id']);
            
$story['is_liked']         = (Wo_IsLiked($story['id'], $wo['user']['user_id']) === true) ? true false;
            
$story['is_wondered']      = (Wo_IsWondered($story['id'], $wo['user']['user_id']) === true) ? true false;
            
$story['is_post_saved']    = (Wo_IsPostSaved($story['id'], $wo['user']['user_id']) === true) ? true false;
            
$story['is_post_reported'] = (Wo_IsPostRepotred($story['id'], $wo['user']['user_id']) === true) ? true false;
      }
      return 
$story;
}
// count user posts
function Wo_CountUserPosts($user_id) {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data = array();
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      
$user_id      Wo_Secure($user_id);
      
$query        mysqli_query($sqlConnect"SELECT COUNT(`id`) AS count FROM " T_POSTS " WHERE `user_id` = {$user_id}");
      
$fetched_data mysqli_fetch_assoc($query);
      return 
$fetched_data['count'];
}
// check if post exists
function Wo_PostExists($post_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) || !is_numeric($post_id) || $post_id 0) {
            return 
false;
      }
      
$post_id Wo_Secure($post_id);
      
$query   mysqli_query($sqlConnect"SELECT COUNT(`id`) FROM " T_POSTS " WHERE `id` = {$post_id}");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// check if user is the post onwer
function Wo_IsPostOnwer($post_id$user_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) || !is_numeric($post_id) || $post_id 0) {
            return 
false;
      }
      
$post_id Wo_Secure($post_id);
      
$user_id Wo_Secure($user_id);
      
$query   mysqli_query($sqlConnect"SELECT COUNT(`id`) FROM " T_POSTS " WHERE `id` = {$post_id} AND (`user_id` = {$user_id} OR `page_id` IN (SELECT `page_id` FROM " T_PAGES " WHERE `user_id` = {$user_id}))");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// get publisher box
function Wo_GetPostPublisherBox($user_id 0$recipient_id 0) {
      
// Global required variables
      
global $wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$continue true;
      if (empty(
$user_id) or $user_id == 0) {
            
$user_id $wo['user']['user_id'];
      }
      if (!
is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      if (
$user_id == $wo['user']['user_id']) {
            
$user_timline $wo['user'];
      } else {
            
$user_id      Wo_Secure($user_id);
            
$user_timline Wo_UserData($user_id);
      }
      if (!isset(
$recipient_id) or empty($recipient_id)) {
            
$recipient_id 0;
      }
      if (!
is_numeric($recipient_id) or $recipient_id 0) {
            return 
false;
      }
      
$recipient_id Wo_Secure($recipient_id);
      if (
$user_id == $recipient_id) {
            
$recipient_id 0;
      }
      if (
$recipient_id 0) {
            
$recipient Wo_UserData($recipient_id);
            if (!isset(
$recipient['user_id'])) {
                  return 
false;
            }
            if (
$recipient['post_privacy'] == "ifollow") {
                  if (
Wo_IsFollowing($wo['user']['user_id'], $recipient_id) === false) {
                        
$continue false;
                  }
            } elseif (
$recipient['post_privacy'] == "nobody") {
                  
$continue false;
            } elseif (
$recipient['post_privacy'] == "everyone") {
                  
$continue true;
            }
            
$wo['input']['recipient'] = $recipient;
      }
      if (
$continue == true) {
            
$wo['input']['user_timline'] = $user_timline;
            return 
Wo_LoadPage('story/publisher-box');
      }
}
// get posts from database
function Wo_GetPosts($data = array('filter_by' => 'all''after_post_id' => 0'page_id' => 0'publisher_id' => 0'limit' => 5)) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (empty(
$data['filter_by'])) {
            
$data['filter_by'] = 'all';
      }
      
$subquery_one " `id` > 0 ";
      if (!empty(
$data['after_post_id']) && is_numeric($data['after_post_id']) && $data['after_post_id'] > 0) {
            
$data['after_post_id'] = Wo_Secure($data['after_post_id']);
            
$subquery_one          " `id` < " $data['after_post_id'] . " AND `id` <> " $data['after_post_id'];
      } else if (!empty(
$data['before_post_id']) && is_numeric($data['before_post_id']) && $data['before_post_id'] > 0) {
            
$data['before_post_id'] = Wo_Secure($data['before_post_id']);
            
$subquery_one           " `id` > " $data['before_post_id'] . " AND `id` <> " $data['before_post_id'];
      }
      if (!empty(
$data['publisher_id']) && is_numeric($data['publisher_id']) && $data['publisher_id'] > 0) {
            
$data['publisher_id'] = Wo_Secure($data['publisher_id']);
            
$Wo_publisher         Wo_UserData($data['publisher_id']);
      }
      if (!empty(
$data['page_id']) && is_numeric($data['page_id']) && $data['page_id'] > 0) {
            
$data['page_id']   = Wo_Secure($data['page_id']);
            
$Wo_page_publisher Wo_PageData($data['page_id']);
      }
      
$query_text "SELECT `id` FROM " T_POSTS " WHERE {$subquery_one}";
      if (isset(
$Wo_publisher['user_id'])) {
            
$user_id Wo_Secure($Wo_publisher['user_id']);
            
$query_text .= " AND (`user_id` = {$user_id} OR `recipient_id` = {$user_id}) AND postShare IN (0,1) AND `id` NOT IN (SELECT `post_id` from " T_PINNED_POSTS " WHERE `user_id` = {$user_id})  AND `page_id` NOT IN (SELECT `page_id` from " T_PAGES " WHERE user_id = {$user_id})";
            switch (
$data['filter_by']) {
                  case 
'text':
                        
$query_text .= " AND `postText` <> '' AND `postFile` = '' AND `postYoutube` = '' AND `postFacebook` = ''  AND `postVimeo` = ''  AND `postDailymotion` = '' AND `postSoundCloud` = '' ";
                        break;
                  case 
'files':
                        
$query_text .= " AND (`postFile` LIKE '%_file%' AND `postFile` NOT LIKE '%_video%' AND `postFile` NOT LIKE '%_avatar%' AND `postFile` NOT LIKE '%_soundFile%' AND `postFile` NOT LIKE '%_image%')";
                        break;
                  case 
'photos':
                        
$query_text .= " AND (`postFile` LIKE '%_image%' OR `postFile` LIKE '%_avatar%')";
                        break;
                  case 
'music':
                        
$query_text .= " AND (`postSoundCloud` <> '' OR `postFile` LIKE '%_soundFile%')";
                        break;
                  case 
'video':
                        
$query_text .= " AND (`postYoutube` <> '' OR `postVine` <> '' OR `postFacebook` <> '' OR `postDailymotion` <> '' OR `postVimeo` <> '' OR `postFile` LIKE '%_video%')";
                        break;
                  case 
'maps':
                        
$query_text .= " AND `postMap` <> ''";
                        break;
            }
      } else if (isset(
$Wo_page_publisher['page_id'])) {
            
$page_id Wo_Secure($Wo_page_publisher['page_id']);
            
$query_text .= " AND (`page_id` = {$page_id}) AND `id` NOT IN (SELECT `post_id` from " T_PINNED_POSTS " WHERE `page_id` = {$page_id})";
            switch (
$data['filter_by']) {
                  case 
'text':
                        
$query_text .= " AND `postText` <> '' AND `postFile` = '' AND `postYoutube` = '' AND `postFacebook` = ''  AND `postVimeo` = ''  AND `postDailymotion` = '' AND `postSoundCloud` = '' ";
                        break;
                  case 
'files':
                        
$query_text .= " AND (`postFile` LIKE '%_file%' AND `postFile` NOT LIKE '%_video%' AND `postFile` NOT LIKE '%_avatar%' AND `postFile` NOT LIKE '%_soundFile%' AND `postFile` NOT LIKE '%_image%')";
                        break;
                  case 
'photos':
                        
$query_text .= " AND (`postFile` LIKE '%_image%' OR `postFile` LIKE '%_avatar%')";
                        break;
                  case 
'music':
                        
$query_text .= " AND (`postSoundCloud` <> '' OR `postFile` LIKE '%_soundFile%')";
                        break;
                  case 
'video':
                        
$query_text .= " AND (`postYoutube` <> '' OR `postVine` <> '' OR `postFacebook` <> '' OR `postDailymotion` <> '' OR `postVimeo` <> '' OR `postFile` LIKE '%_video%')";
                        break;
                  case 
'maps':
                        
$query_text .= " AND `postMap` <> ''";
                        break;
            }
      } else {
            
$query_text .= " AND (`user_id` IN (SELECT `following_id` FROM " T_FOLLOWERS " WHERE `follower_id` = " $wo['user']['user_id'] . " AND `active` = '1') OR `recipient_id` IN (SELECT `following_id` FROM " T_FOLLOWERS " WHERE `follower_id` = " Wo_Secure($wo['user']['user_id']) . " AND `active` = '1' ) OR `user_id` IN (" Wo_Secure($wo['user']['user_id']) . ") OR `page_id` IN (SELECT `page_id` FROM " T_PAGES " WHERE `user_id` = " $wo['user']['user_id'] . " AND `active` = '1') OR `page_id` IN (SELECT `page_id` FROM " T_PAGES_LIKES " WHERE `user_id` = " $wo['user']['user_id'] . " AND `active` = '1')) AND `postShare` NOT IN (1)";
            switch (
$data['filter_by']) {
                  case 
'text':
                        
$query_text .= " AND `postText` <> '' AND `postFile` = '' AND `postYoutube` = '' AND `postFacebook` = ''  AND `postVimeo` = ''  AND `postDailymotion` = '' AND `postSoundCloud` = '' ";
                        break;
                  case 
'files':
                        
$query_text .= " AND (`postFile` LIKE '%_file%' AND `postFile` NOT LIKE '%_video%' AND `postFile` NOT LIKE '%_avatar%' AND `postFile` NOT LIKE '%_soundFile%' AND `postFile` NOT LIKE '%_image%')";
                        break;
                  case 
'photos':
                        
$query_text .= " AND (`postFile` LIKE '%_image%' OR `postFile` LIKE '%_avatar%')";
                        break;
                  case 
'music':
                        
$query_text .= " AND (`postSoundCloud` <> '' OR `postFile` LIKE '%_soundFile%')";
                        break;
                  case 
'video':
                        
$query_text .= " AND (`postYoutube` <> '' OR `postVine` <> '' OR `postFacebook` <> '' OR `postDailymotion` <> '' OR `postVimeo` <> '' OR `postFile` LIKE '%_video%')";
                        break;
                  case 
'maps':
                        
$query_text .= " AND `postMap` <> ''";
                        break;
            }
      }
      if (empty(
$data['limit']) or !is_numeric($data['limit']) or $data['limit'] < 1) {
            
$data['limit'] = 5;
      }
      
$limit Wo_Secure($data['limit']);
      
$query_text .= " ORDER BY `id` DESC LIMIT {$limit}";
      
$data = array();
      
$sql  mysqli_query($sqlConnect$query_text);
      while (
$fetched_data mysqli_fetch_assoc($sql)) {
            
$post Wo_PostData($fetched_data['id']);
            if (
is_array($post)) {
                  
$data[] = $post;
            }
      }
      return 
$data;
}
// delete post
function Wo_DeletePost($post_id 0) {
      
// Global required variables
      
global $wo$sqlConnect$cache;
      if (
$post_id || empty($post_id) || !is_numeric($post_id)) {
            return 
false;
      }
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id Wo_Secure($wo['user']['user_id']);
      
$post_id Wo_Secure($post_id);
      
$query   mysqli_query($sqlConnect"SELECT `id`, `user_id`, `recipient_id`, `page_id` `postFile`, `postType`, `postLinkImage` FROM " T_POSTS " WHERE `id` = {$post_id} AND (`user_id` = {$user_id} OR `recipient_id` = {$user_id} OR `page_id` IN (SELECT `page_id` FROM " T_PAGES " WHERE `user_id` = {$user_id}))");
      if (
mysqli_num_rows($query) > || Wo_IsAdmin($wo['user']['user_id']) === true) {
            
$fetched_data mysqli_fetch_assoc($query);
            if (isset(
$fetched_data['postFile']) && !empty($fetched_data['postFile'])) {
                  if (
$fetched_data['postType'] != 'profile_picture') {
                        @
unlink($fetched_data['postFile']);
                  }
            }
            if (isset(
$fetched_data['postLinkImage']) && !empty($fetched_data['postLinkImage'])) {
                  @
unlink($fetched_data['postLinkImage']);
            }
            if (
$wo['config']['cacheSystem'] == 1) {
                  
$cache->delete(md5($post_id) . '_P_Data.tmp');
            }
            
$query_delete mysqli_query($sqlConnect"DELETE FROM " T_POSTS " WHERE `id` = {$post_id}");
            
$query_delete .= mysqli_query($sqlConnect"DELETE FROM " T_POSTS " WHERE `post_id` = {$post_id}");
            
$query_delete .= mysqli_query($sqlConnect"DELETE FROM " T_COMMENTS " WHERE `post_id` = {$post_id}");
            
$query_delete .= mysqli_query($sqlConnect"DELETE FROM " T_COMMENT_LIKES " WHERE `post_id` = {$post_id}");
            
$query_delete .= mysqli_query($sqlConnect"DELETE FROM " T_COMMENT_WONDERS " WHERE `post_id` = {$post_id}");
            
$query_delete .= mysqli_query($sqlConnect"DELETE FROM " T_WONDERS " WHERE `post_id` = {$post_id}");
            
$query_delete .= mysqli_query($sqlConnect"DELETE FROM " T_LIKES " WHERE `post_id` = {$post_id}");
            
$query_delete .= mysqli_query($sqlConnect"DELETE FROM " T_NOTIFICATION " WHERE `post_id` = {$post_id}");
            
$query_delete .= mysqli_query($sqlConnect"DELETE FROM " T_SAVED_POSTS " WHERE `post_id` = {$post_id}");
            
$query_delete .= mysqli_query($sqlConnect"DELETE FROM " T_PINNED_POSTS " WHERE `post_id` = {$post_id}");
            
$query_delete .= mysqli_query($sqlConnect"DELETE FROM " T_ACTIVITIES " WHERE `post_id` = {$post_id}");
            return 
true;
      } else {
            return 
false;
      }
}
// get user ID from post 
function Wo_GetUserIdFromPostId($post_id 0) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      
$post_id       Wo_Secure($post_id);
      
$query_one     "SELECT `user_id` FROM " T_POSTS " WHERE `id` = {$post_id}";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) == 1) {
            
$sql_fetch_one mysqli_fetch_assoc($sql_query_one);
            return 
$sql_fetch_one['user_id'];
      }
}
// get pinned post
function Wo_GetPinnedPost($user_id$type '') {
      
// Global required variables
      
global $sqlConnect$wo;
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 1) {
            return 
false;
      }
      
$query_type = ($type == 'page') ? 'page_id' 'user_id';
      
$data       = array();
      
$query_one  mysqli_query($sqlConnect"SELECT `post_id` FROM " T_PINNED_POSTS " WHERE `{$query_type}` = {$user_id} AND `active` = '1'");
      while (
$fetched_data mysqli_fetch_assoc($query_one)) {
            
$post Wo_PostData($fetched_data['post_id']);
            if (
is_array($post)) {
                  
$data[] = $post;
            }
      }
      return 
$data;
}
// check if post is pinned
function Wo_IsPostPinned($post_id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$post_id) || !is_numeric($post_id) || $post_id 1) {
            return 
false;
      }
      
$post_id       Wo_Secure($post_id);
      
$query_one     mysqli_query($sqlConnect"SELECT COUNT(`id`) as `pinned` FROM " T_PINNED_POSTS " WHERE `post_id` = {$post_id} AND `active` = '1'");
      
$sql_query_one mysqli_fetch_assoc($query_one);
      return (
$sql_query_one['pinned'] == 1) ? true false;
}
// is user pinned a post 
function Wo_IsUserPinned($user_id$type '') {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id       Wo_Secure($user_id);
      
$query_type    = ($type == 'page') ? 'page_id' 'user_id';
      
$query_one     mysqli_query($sqlConnect"SELECT COUNT(`id`) as `pinned` FROM " T_PINNED_POSTS " WHERE `{$query_type}` = {$user_id} AND `active` = '1'");
      
$sql_query_one mysqli_fetch_assoc($query_one);
      return (
$sql_query_one['pinned'] == 1) ? true false;
}
// pin a post
function Wo_PinPost($post_id$type ''$page 0) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id Wo_Secure($wo['user']['user_id']);
      
$post_id Wo_Secure($post_id);
      
$page_id 0;
      if (!empty(
$page)) {
            
$page_id Wo_Secure($page);
      }
      
$continue false;
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 1) {
            return 
false;
      }
      if (empty(
$post_id) || !is_numeric($post_id) || $post_id 1) {
            return 
false;
      }
      if (
Wo_PostExists($post_id) === false) {
            return 
false;
      }
      if (
Wo_IsPostOnwer($post_id$user_id) === false) {
            return 
false;
      }
      
$delete_query_text  "DELETE FROM " T_PINNED_POSTS;
      
$where_delete_query = ($type == 'page') ? " WHERE `page_id` = {$page_id} AND `active` = '1'" " WHERE `user_id` = {$user_id} AND `active` = '1'";
      
$query_text         $delete_query_text $where_delete_query;
      
$insert_query_text  "INSERT INTO " T_PINNED_POSTS;
      
$where_insert_query = ($type == 'page') ? " (`page_id`, `post_id`, `active`) VALUES ({$page_id}{$post_id}, '1')" "  (`user_id`, `post_id`, `active`) VALUES ({$user_id}{$post_id}, '1')";
      
$insert_text        $insert_query_text $where_insert_query;
      if (
Wo_IsPostPinned($post_id)) {
            
$query_two mysqli_query($sqlConnect$query_text);
            return 
'unpin';
      } else {
            
$type2 = (!empty($page_id)) ? $page_id $user_id;
            
$type3 = (!empty($page_id)) ? 'page' '';
            if (
Wo_IsUserPinned($type2$type3)) {
                  
$query_two mysqli_query($sqlConnect$query_text);
                  
$continue  true;
            } else {
                  
$continue true;
            }
            if (
$continue === true) {
                  
$query_three mysqli_query($sqlConnect$insert_text);
                  if (
$query_three) {
                        return 
'pin';
                  }
            }
      }
}
// register new activity
function Wo_RegisterActivity($data = array()) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (
$wo['user']['show_activities_privacy'] == 0) {
            return 
false;
      }
      if (empty(
$data['post_id']) || !is_numeric($data['post_id']) || $data['post_id'] < 1) {
            return 
false;
      }
      if (empty(
$data['user_id']) || !is_numeric($data['user_id']) || $data['user_id'] < 1) {
            return 
false;
      }
      if (empty(
$data['activity_type'])) {
            return 
false;
      }
      
$post_id       Wo_Secure($data['post_id']);
      
$user_id       Wo_Secure($data['user_id']);
      
$post_user_id  Wo_Secure($data['post_user_id']);
      
$activity_type Wo_Secure($data['activity_type']);
      
$time          time();
      if (
$user_id == $post_user_id) {
            return 
false;
      }
      
$query_insert "INSERT INTO " T_ACTIVITIES " (`user_id`, `post_id`, `activity_type`, `time`) VALUES ('{$user_id}', '{$post_id}', '{$activity_type}', '{$time}')";
      if (
Wo_IsActivity($post_id$user_id$activity_type) === true) {
            
$query_delete mysqli_query($sqlConnect"DELETE FROM " T_ACTIVITIES " WHERE `user_id` = '{$user_id}' AND `post_id` = '{$post_id}'");
            if (
$query_delete) {
                  
$query_one mysqli_query($sqlConnect$query_insert);
            }
      } else {
            
$query_one mysqli_query($sqlConnect$query_insert);
      }
      if (
$query_one) {
            return 
true;
      }
}
// check if it's real activity
function Wo_IsActivity($post_id$user_id$activity_type) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$query mysqli_query($sqlConnect"SELECT `id` FROM " T_ACTIVITIES " WHERE `user_id` = '{$user_id}' AND `post_id` = '{$post_id}' AND `activity_type` = '{$activity_type}'");
      return (
mysqli_num_rows($query) > 0) ? true false;
}
// delete activity
function Wo_DeleteActivity($post_id$user_id$activity_type) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$post_id) || !is_numeric($post_id) || $post_id 1) {
            return 
false;
      }
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 1) {
            return 
false;
      }
      
$query mysqli_query($sqlConnect"DELETE FROM " T_ACTIVITIES " WHERE `user_id` = '{$user_id}' AND `post_id` = '{$post_id}' AND `activity_type` = '{$activity_type}'");
      return (
$query) ? true false;
}
// get one activity
function Wo_GetActivity($id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id Wo_Secure($wo['user']['user_id']);
      if (empty(
$id) || !is_numeric($id) || $id 1) {
            return 
false;
      }
      
$query mysqli_query($sqlConnect"SELECT * FROM " T_ACTIVITIES " WHERE `id` = {$id}");
      if (
mysqli_num_rows($query) == 1) {
            
$finel_fetched_data              mysqli_fetch_assoc($query);
            
$finel_fetched_data['postData']  = Wo_PostData($finel_fetched_data['post_id']);
            
$finel_fetched_data['activator'] = Wo_UserData($finel_fetched_data['user_id']);
            return 
$finel_fetched_data;
      }
}
// get activities
function Wo_GetActivities($data = array('after_activity_id' => 0'before_activity_id' => 0'limit' => 5)) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id Wo_Secure($wo['user']['user_id']);
      
$get     = array();
      if (empty(
$data['limit'])) {
            
$data['limit'] = 5;
      }
      
$limit        Wo_Secure($data['limit']);
      
$subquery_one " `id` > 0 ";
      if (!empty(
$data['after_activity_id']) && is_numeric($data['after_activity_id']) && $data['after_activity_id'] > 0) {
            
$data['after_activity_id'] = Wo_Secure($data['after_activity_id']);
            
$subquery_one              " `id` < " $data['after_activity_id'] . " AND `id` <> " $data['after_activity_id'];
      } else if (!empty(
$data['before_activity_id']) && is_numeric($data['before_activity_id']) && $data['before_activity_id'] > 0) {
            
$data['before_activity_id'] = Wo_Secure($data['before_activity_id']);
            
$subquery_one               " `id` > " $data['before_activity_id'] . " AND `id` <> " $data['before_activity_id'];
      }
      
$query_text "SELECT `id` FROM " T_ACTIVITIES " WHERE {$subquery_one}";
      
$query_text .= " AND `user_id` IN (SELECT `following_id` FROM " T_FOLLOWERS " WHERE `follower_id` = {$user_id} AND `active` = '1') AND `user_id` NOT IN ($user_id) ORDER BY `id` DESC LIMIT {$limit}";
      
$sql_query_one mysqli_query($sqlConnect$query_text);
      while (
$fetched_data mysqli_fetch_assoc($sql_query_one)) {
            if (
is_array($fetched_data)) {
                  
$get[] = Wo_GetActivity($fetched_data['id']);
            }
      }
      return 
$get;
}
// register like
function Wo_AddLikes($post_id) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$post_id) || !is_numeric($post_id) || $post_id 1) {
            return 
false;
      }
      
$post_id        Wo_Secure($post_id);
      
$user_id        Wo_GetUserIdFromPostId($post_id);
      
$page_id        0;
      
$logged_user_id Wo_Secure($wo['user']['user_id']);
      
$post           Wo_PostData($post_id);
      
$text           '';
      
$type2          '';
      if (empty(
$user_id)) {
            
$user_id Wo_GetUserIdFromPageId($post['page_id']);
            if (empty(
$user_id)) {
                  return 
false;
            }
      }
      if (isset(
$post['postText']) && !empty($post['postText'])) {
            
$text substr($post['postText'], 010) . '..';
      }
      if (isset(
$post['postYoutube']) && !empty($post['postYoutube'])) {
            
$type2 'post_youtube';
      } elseif (isset(
$post['postSoundCloud']) && !empty($post['postSoundCloud'])) {
            
$type2 'post_soundcloud';
      } elseif (isset(
$post['postVine']) && !empty($post['postVine'])) {
            
$type2 'post_vine';
      } elseif (isset(
$post['postFile']) && !empty($post['postFile'])) {
            if (
strpos($post['postFile'], '_image') !== false) {
                  
$type2 'post_image';
            } else if (
strpos($post['postFile'], '_video') !== false) {
                  
$type2 'post_video';
            } else if (
strpos($post['postFile'], '_avatar') !== false) {
                  
$type2 'post_avatar';
            } else if (
strpos($post['postFile'], '_sound') !== false) {
                  
$type2 'post_soundFile';
            } else {
                  
$type2 'post_file';
            }
      }
      if (
Wo_IsLiked($post_id$wo['user']['user_id']) === true) {
            
$query_one        "DELETE FROM " T_LIKES " WHERE `post_id` = {$post_id} AND `user_id` = {$logged_user_id}";
            
$query_delete_one mysqli_query($sqlConnect"DELETE FROM " T_NOTIFICATION " WHERE `post_id` = {$post_id} AND `recipient_id` = {$user_id} AND `type` = 'liked_post'");
            
$delete_activity  Wo_DeleteActivity($post_id$logged_user_id'liked_post');
            
$sql_query_one    mysqli_query($sqlConnect$query_one);
            if (
$sql_query_one) {
                  return 
'unliked';
            }
      } else {
            
$query_two     "INSERT INTO " T_LIKES " (`user_id`, `post_id`) VALUES ({$logged_user_id}{$post_id})";
            
$sql_query_two mysqli_query($sqlConnect$query_two);
            if (
$sql_query_two) {
                  if (
$type2 != 'post_avatar') {
                        
$activity_data = array(
                              
'post_id' => $post_id,
                              
'user_id' => $logged_user_id,
                              
'post_user_id' => $user_id,
                              
'activity_type' => 'liked_post'
                        
);
                        
$add_activity  Wo_RegisterActivity($activity_data);
                  }
                  
$notification_data_array = array(
                        
'recipient_id' => $user_id,
                        
'post_id' => $post_id,
                        
'type' => 'liked_post',
                        
'text' => $text,
                        
'type2' => $type2,
                        
'url' => 'index.php?tab1=post&id=' $post_id
                  
);
                  
Wo_RegisterNotification($notification_data_array);
                  return 
'liked';
            }
      }
}
// count post likes
function Wo_CountLikes($post_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      
$post_id       Wo_Secure($post_id);
      
$query_one     "SELECT COUNT(`id`) AS `likes` FROM " T_LIKES " WHERE `post_id` = {$post_id}";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) == 1) {
            
$sql_fetch_one mysqli_fetch_assoc($sql_query_one);
            return 
$sql_fetch_one['likes'];
      }
}
// check if user is liked
function Wo_IsLiked($post_id$user_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      
$post_id       Wo_Secure($post_id);
      
$query_one     "SELECT `id` FROM " T_LIKES " WHERE `post_id` = {$post_id} AND `user_id` = {$user_id}";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) >= 1) {
            return 
true;
      }
}
// register wonder
function Wo_AddWonders($post_id) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!isset(
$post_id) or empty($post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      
$post_id        Wo_Secure($post_id);
      
$user_id        Wo_GetUserIdFromPostId($post_id);
      
$logged_user_id Wo_Secure($wo['user']['user_id']);
      
$post           Wo_PostData($post_id);
      if (empty(
$user_id)) {
            
$user_id Wo_GetUserIdFromPageId($post['page_id']);
            if (empty(
$user_id)) {
                  return 
false;
            }
      }
      
$text  '';
      
$type2 '';
      if (isset(
$post['postText']) && !empty($post['postText'])) {
            
$text substr($post['postText'], 010) . '..';
      }
      if (isset(
$post['postYoutube']) && !empty($post['postYoutube'])) {
            
$type2 'post_youtube';
      } elseif (isset(
$post['postSoundCloud']) && !empty($post['postSoundCloud'])) {
            
$type2 'post_soundcloud';
      } elseif (isset(
$post['postVine']) && !empty($post['postVine'])) {
            
$type2 'post_vine';
      } elseif (isset(
$post['postFile']) && !empty($post['postFile'])) {
            if (
strpos($post['postFile'], '_image') !== false) {
                  
$type2 'post_image';
            } else if (
strpos($post['postFile'], '_video') !== false) {
                  
$type2 'post_video';
            } else if (
strpos($post['postFile'], '_avatar') !== false) {
                  
$type2 'post_avatar';
            } else if (
strpos($post['postFile'], '_sound') !== false) {
                  
$type2 'post_soundFile';
            } else {
                  
$type2 'post_file';
            }
      }
      if (
Wo_IsWondered($post_id$logged_user_id) === true) {
            
$query_one        "DELETE FROM " T_WONDERS " WHERE `post_id` = {$post_id} AND `user_id` = {$logged_user_id}";
            
$query_delete_one mysqli_query($sqlConnect"DELETE FROM " T_NOTIFICATION " WHERE `post_id` = {$post_id} AND `recipient_id` = {$user_id} AND `type` = 'wondered_post' ");
            
$delete_activity  Wo_DeleteActivity($post_id$logged_user_id'wondered_post');
            
$sql_query_one    mysqli_query($sqlConnect$query_one);
            if (
$sql_query_one) {
                  return 
'unwonder';
            }
      } else {
            
$query_two     "INSERT INTO " T_WONDERS " (`user_id`, `post_id`) VALUES ({$logged_user_id}{$post_id})";
            
$sql_query_two mysqli_query($sqlConnect$query_two);
            if (
$sql_query_two) {
                  if (
$type2 != 'post_avatar') {
                        
$activity_data = array(
                              
'post_id' => $post_id,
                              
'user_id' => $logged_user_id,
                              
'post_user_id' => $user_id,
                              
'activity_type' => 'wondered_post'
                        
);
                        
$add_activity  Wo_RegisterActivity($activity_data);
                  }
                  
$notification_data_array = array(
                        
'recipient_id' => $user_id,
                        
'post_id' => $post_id,
                        
'type' => 'wondered_post',
                        
'text' => $text,
                        
'type2' => $type2,
                        
'url' => 'index.php?tab1=post&id=' $post_id
                  
);
                  
Wo_RegisterNotification($notification_data_array);
                  return 
'wonder';
            }
      }
}
// count wonders
function Wo_CountWonders($post_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      
$post_id       Wo_Secure($post_id);
      
$query_one     "SELECT COUNT(`id`) AS `wonders` FROM " T_WONDERS " WHERE `post_id` = {$post_id}";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) == 1) {
            
$sql_fetch_one mysqli_fetch_assoc($sql_query_one);
            return 
$sql_fetch_one['wonders'];
      }
}
// check if user wondered the post
function Wo_IsWondered($post_id$user_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      
$post_id       Wo_Secure($post_id);
      
$query_one     "SELECT `id` FROM " T_WONDERS " WHERE `post_id` = {$post_id} AND `user_id` = {$user_id}";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) >= 1) {
            return 
true;
      }
}
// get post likes
function Wo_GetPostLikes($post_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      
$post_id       Wo_Secure($post_id);
      
$data          = array();
      
$query_one     "SELECT `user_id` FROM " T_LIKES " WHERE `post_id` = {$post_id}";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      while (
$fetched_data mysqli_fetch_assoc($sql_query_one)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      return 
$data;
}
// get post wonders
function Wo_GetPostWonders($post_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      
$post_id       Wo_Secure($post_id);
      
$data          = array();
      
$query_one     "SELECT `user_id` FROM " T_WONDERS " WHERE `post_id` = {$post_id}";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      while (
$fetched_data mysqli_fetch_assoc($sql_query_one)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      return 
$data;
}
// register share
function Wo_AddShare($post_id 0) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() !== true) {
            return 
false;
      }
      if (!isset(
$post_id) or empty($post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      
$post_id        Wo_Secure($post_id);
      
$user_id        Wo_GetUserIdFromPostId($post_id);
      
$logged_user_id Wo_Secure($wo['user']['user_id']);
      
$post           Wo_PostData($post_id);
      if (empty(
$user_id)) {
            
$user_id Wo_GetUserIdFromPageId($post['page_id']);
            if (empty(
$user_id)) {
                  return 
false;
            }
      }
      
$text  '';
      
$type2 '';
      if (isset(
$post['postText']) && !empty($post['postText'])) {
            
$text substr($post['postText'], 010) . '..';
      }
      if (isset(
$post['postYoutube']) && !empty($post['postYoutube'])) {
            
$type2 'post_youtube';
      } elseif (isset(
$post['postSoundCloud']) && !empty($post['postSoundCloud'])) {
            
$type2 'post_soundcloud';
      } elseif (isset(
$post['postVine']) && !empty($post['postVine'])) {
            
$type2 'post_vine';
      } elseif (isset(
$post['postFile']) && !empty($post['postFile'])) {
            if (
strpos($post['postFile'], '_image') !== false) {
                  
$type2 'post_image';
            } else if (
strpos($post['postFile'], '_video') !== false) {
                  
$type2 'post_video';
            } else if (
strpos($post['postFile'], '_avatar') !== false) {
                  
$type2 'post_avatar';
            } else if (
strpos($post['postFile'], '_sound') !== false) {
                  
$type2 'post_soundFile';
            } else {
                  
$type2 'post_file';
            }
      }
      if (
Wo_IsShared($post_id$logged_user_id)) {
            
$query_one        "DELETE FROM " T_POSTS " WHERE `post_id` = {$post_id} AND `user_id` = {$logged_user_id} AND `postShare` = 1";
            
$query_delete_one mysqli_query($sqlConnect"DELETE FROM " T_NOTIFICATION " WHERE `post_id` = {$post_id} AND `recipient_id` = {$user_id} AND `type` = 'share_post'");
            
$delete_activity  Wo_DeleteActivity($post_id$logged_user_id'shared_post');
            
$sql_query_one    mysqli_query($sqlConnect$query_one);
            if (
$sql_query_one) {
                  return 
'unshare';
            }
      } else {
            
$query_two        "INSERT INTO " T_POSTS " (`user_id`, `post_id`, `time`, `postShare`) VALUES ({$logged_user_id}{$post_id}, " time() . ", 1)";
            
$sql_query_two    mysqli_query($sqlConnect$query_two);
            
$inserted_post_id mysqli_insert_id($sqlConnect);
            if (
$sql_query_two) {
                  if (
$type2 != 'post_avatar') {
                        
$activity_data = array(
                              
'post_id' => $post_id,
                              
'user_id' => $logged_user_id,
                              
'post_user_id' => $user_id,
                              
'activity_type' => 'shared_post'
                        
);
                        
$add_activity  Wo_RegisterActivity($activity_data);
                  }
                  
$notification_data_array = array(
                        
'recipient_id' => $user_id,
                        
'post_id' => $post_id,
                        
'type' => 'share_post',
                        
'text' => $text,
                        
'type2' => $type2,
                        
'url' => 'index.php?tab1=post&id=' $inserted_post_id
                  
);
                  
Wo_RegisterNotification($notification_data_array);
                  return 
'share';
            }
      }
}
// count shares
function Wo_CountShares($post_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      
$post_id       Wo_Secure($post_id);
      
$query_one     "SELECT COUNT(`id`) AS `shares` FROM " T_POSTS " WHERE `post_id` = {$post_id} AND `postShare` = 1";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) == 1) {
            
$sql_fetch_one mysqli_fetch_assoc($sql_query_one);
            return 
$sql_fetch_one['shares'];
      }
}
// check if user shared the post
function Wo_IsShared($post_id$user_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      
$post_id       Wo_Secure($post_id);
      
$query_one     "SELECT `id` FROM " T_POSTS " WHERE `post_id`= {$post_id} AND `postShare` = 1 AND `user_id` = {$user_id}";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) >= 1) {
            return 
true;
      }
}
// register comment
function Wo_RegisterPostComment($data = array()) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (empty(
$data['post_id']) || !is_numeric($data['post_id']) || $data['post_id'] < 0) {
            return 
false;
      }
      if (empty(
$data['text'])) {
            return 
false;
      }
      if (empty(
$data['user_id']) || !is_numeric($data['user_id']) || $data['user_id'] < 0) {
            return 
false;
      }
      if (!empty(
$data['page_id'])) {
            if (
Wo_IsPageOnwer($data['page_id']) === false) {
                  
$data['page_id'] = 0;
            }
      }
      if (!empty(
$data['text'])) {
            if (
$wo['config']['maxCharacters'] > 0) {
                  if (
strlen($data['text']) > $wo['config']['maxCharacters']) {
                        return 
false;
                  }
            }
            
// Links
            
$link_regex '/(http://|https://|www.)([^ ]+)/i';
            
$i          0;
            
preg_match_all($link_regex$data['text'], $matches);
            foreach (
$matches[0] as $match) {
                  
$match_url    strip_tags($match);
                  
$syntax       '[a]' urlencode($match_url) . '[/a]';
                  
$data['text'] = str_replace($match$syntax$data['text']);
            }
            
// @Mentions
            
$mention_regex '/@([A-Za-z0-9_]+)/i';
            
preg_match_all($mention_regex$data['text'], $matches);
            foreach (
$matches[1] as $match) {
                  
$match         Wo_Secure($match);
                  
$match_user    Wo_UserData(Wo_UserIdFromUsername($match));
                  
$match_search  '@' $match;
                  
$match_replace '@[' $match_user['user_id'] . ']';
                  if (isset(
$match_user['user_id'])) {
                        
$data['text'] = str_replace($match_search$match_replace$data['text']);
                        
$mentions[]   = $match_user['user_id'];
                  }
            }
      }
      
$hashtag_regex '/#([^`~!@$%^&*#()-+=\|/.,<>?'":;{}[]* ]+)/i';
      preg_match_all(
$hashtag_regex$data['text'], $matches);
      foreach (
$matches[1] as $match) {
            if (!is_numeric(
$match)) {
                  
$hashdata = Wo_GetHashtag($match);
                  if (is_array(
$hashdata)) {
                        
$match_search      = '#' . $match;
                        
$match_replace     = '#[' . $hashdata['id'] . ']';
                        
$data['text']      = str_replace($match_search$match_replace$data['text']);
                        
$hashtag_query     = "UPDATE " . T_HASHTAGS . " SET `last_trend_time` = " . time() . ", `trend_use_num` = " . ($hashdata['trend_use_num'] + 1) . " WHERE `id` = " . $hashdata['id'];
                        
$hashtag_sql_query = mysqli_query($sqlConnect$hashtag_query);
                  }
            }
      }
      
$post    = Wo_PostData($data['post_id']);
      
$text    = '';
      
$type2   = '';
      
$page_id = '';
      if (!empty(
$post['page_id']) && $post['page_id'] > 0) {
            
$page_id = $post['page_id'];
      }
      if (isset(
$post['postText']) && !empty($post['postText'])) {
            
$text = substr($post['postText'], 0, 10) . '..';
      }
      if (isset(
$post['postYoutube']) && !empty($post['postYoutube'])) {
            
$type2 = 'post_youtube';
      } elseif (isset(
$post['postSoundCloud']) && !empty($post['postSoundCloud'])) {
            
$type2 = 'post_soundcloud';
      } elseif (isset(
$post['postVine']) && !empty($post['postVine'])) {
            
$type2 = 'post_vine';
      } elseif (isset(
$post['postFile']) && !empty($post['postFile'])) {
            if (strpos(
$post['postFile'], '_image') !== false) {
                  
$type2 = 'post_image';
            } else if (strpos(
$post['postFile'], '_video') !== false) {
                  
$type2 = 'post_video';
            } else if (strpos(
$post['postFile'], '_avatar') !== false) {
                  
$type2 = 'post_avatar';
            } else if (strpos(
$post['postFile'], '_sound') !== false) {
                  
$type2 = 'post_soundFile';
            } else {
                  
$type2 = 'post_file';
            }
      }
      
$user_id = Wo_GetUserIdFromPostId($data['post_id']);
      if (empty(
$user_id)) {
            
$user_id = Wo_GetUserIdFromPageId($post['page_id']);
            if (empty(
$user_id)) {
                  return false;
            }
      }
      
$fields       = '`' . implode('`, `', array_keys($data)) . '`';
      
$comment_data = ''' . implode('', '', $data) . ''';
      
$query        = mysqli_query($sqlConnect, "INSERT INTO  " . T_COMMENTS . " ({$fields}) VALUES ({$comment_data})");
      if (
$query) {
            
$inserted_comment_id     = mysqli_insert_id($sqlConnect);
            
$activity_data           = array(
                  'post_id' => 
$data['post_id'],
                  'user_id' => 
$data['user_id'],
                  'post_user_id' => 
$user_id,
                  'activity_type' => 'commented_post'
            );
            
$add_activity            = Wo_RegisterActivity($activity_data);
            
$notification_data_array = array(
                  'recipient_id' => 
$user_id,
                  'post_id' => 
$data['post_id'],
                  'type' => 'comment',
                  'text' => 
$text,
                  'type2' => 
$type2,
                  'url' => 'index.php?tab1=post&id=' . 
$data['post_id']
            );
            Wo_RegisterNotification(
$notification_data_array);
            if (isset(
$mentions) && is_array($mentions)) {
                  foreach (
$mentions as $mention) {
                        
$notification_data_array = array(
                              'recipient_id' => 
$mention,
                              'type' => 'comment_mention',
                              'page_id' => 
$page_id,
                              'url' => 'index.php?tab1=post&id=' . 
$data['post_id']
                        );
                        Wo_RegisterNotification(
$notification_data_array);
                  }
            }
            return 
$inserted_comment_id;
      }
}
// get post comments
function Wo_GetPostComments(
$post_id$limit = 5) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$post_id) || !is_numeric($post_id) || $post_id < 0) {
            return false;
      }
      
$post_id = Wo_Secure($post_id);
      
$data    = array();
      
$query   = "SELECT `idFROM " . T_COMMENTS . " WHERE `post_id` = {$post_idORDER BY `idASC";
      if ((
$comments_num = Wo_CountPostComment($post_id)) > $limit) {
            
$query .= " LIMIT " . ($comments_num - $limit) . ", {$limit";
      }
      
$query_one = mysqli_query($sqlConnect$query);
      while (
$fetched_data = mysqli_fetch_assoc($query_one)) {
            
$data[] = Wo_GetPostComment($fetched_data['id']);
      }
      return 
$data;
}
// get post comment
function Wo_GetPostComment(
$comment_id) {
      // Global required variables
      global 
$wo$sqlConnect;
      if (empty(
$comment_id) || !is_numeric($comment_id) || $comment_id < 0) {
            return false;
      }
      
$query_one    = mysqli_query($sqlConnect, "SELECT FROM " . T_COMMENTS . " WHERE `id` = {$comment_id");
      
$fetched_data = mysqli_fetch_assoc($query_one);
      if (!empty(
$fetched_data['page_id'])) {
            
$fetched_data['publisher'] = Wo_PageData($fetched_data['page_id']);
            
$fetched_data['url']       = Wo_SeoLink('index.php?tab1=page&p=' . $fetched_data['publisher']['page_name']);
      } else {
            
$fetched_data['publisher'] = Wo_UserData($fetched_data['user_id']);
            
$fetched_data['url']       = Wo_SeoLink('index.php?tab1=timeline&u=' . $fetched_data['publisher']['username']);
      }
      
$fetched_data['Orginaltext']         = Wo_EditMarkup($fetched_data['text']);
      
$fetched_data['Orginaltext']         = str_replace('<br>', "n", $fetched_data['Orginaltext']);
      
$fetched_data['text']                = Wo_Markup($fetched_data['text']);
      
$fetched_data['text']                = Wo_Emo($fetched_data['text']);
      
$fetched_data['onwer']               = false;
      
$fetched_data['post_onwer']          = false;
      
$fetched_data['comment_likes']       = Wo_CountCommentLikes($fetched_data['id']);
      
$fetched_data['comment_wonders']     = Wo_CountCommentWonders($fetched_data['id']);
      
$fetched_data['is_comment_wondered'] = false;
      
$fetched_data['is_comment_liked']    = false;
      if (Wo_IsLogged() === true) {
            
$fetched_data['onwer']               = ($fetched_data['publisher']['user_id'] == $wo['user']['user_id']) ? true : false;
            
$fetched_data['post_onwer']          = (Wo_IsPostOnwer($fetched_data['post_id'], $wo['user']['user_id'])) ? true : false;
            
$fetched_data['is_comment_wondered'] = (Wo_IsCommentWondered($fetched_data['id'], $wo['user']['user_id'])) ? true : false;
            
$fetched_data['is_comment_liked']    = (Wo_IsCommentLiked($fetched_data['id'], $wo['user']['user_id'])) ? true : false;
      }
      return 
$fetched_data;
}
// count post comments
function Wo_CountPostComment(
$post_id) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$post_id) || !is_numeric($post_id) || $post_id < 0) {
            return false;
      }
      
$query        = mysqli_query($sqlConnect, "SELECT COUNT(`id`) AS `commentsFROM " . T_COMMENTS . " WHERE `post_id` = {$post_id");
      
$fetched_data = mysqli_fetch_assoc($query);
      return 
$fetched_data['comments'];
}
// delete post comment
function Wo_DeletePostComment(
$comment_id) {
      // Global required variables
      global 
$wo$sqlConnect;
      if (
$comment_id < 0 || empty($comment_id) || !is_numeric($comment_id)) {
            return false;
      }
      if (Wo_IsLogged() === false) {
            return false;
      }
      
$logged_user_id = Wo_Secure($wo['user']['user_id']);
      
$post_id        = Wo_GetPostIdFromCommentId($comment_id);
      
$query_one      = mysqli_query($sqlConnect, "SELECT `id`, `user_idFROM " . T_COMMENTS . " WHERE `id` = {$comment_id} AND `user_id` = {$logged_user_id}");
      if (mysqli_num_rows(
$query_one) > 0 || Wo_IsPostOnwer($post_id$logged_user_id) === true) {
            
$query_delete = mysqli_query($sqlConnect, "DELETE FROM " . T_COMMENTS . " WHERE `id` = {$comment_id}");
            if (
$query_delete) {
                  
$delete_activity = Wo_DeleteActivity($post_id$logged_user_id, 'commented_post');
                  return true;
            }
      } else {
            return false;
      }
}
// update comment
function Wo_UpdateComment(
$data = array()) {
      // Global required variables
      global 
$wo$sqlConnect;
      if (
$data['comment_id'] < 0 || empty($data['comment_id']) || !is_numeric($data['comment_id'])) {
            return false;
      }
      if (empty(
$data['text'])) {
            return false;
      }
      if (Wo_IsLogged() === false) {
            return false;
      }
      
$page_id = 0;
      if (!empty(
$data['page_id'])) {
            
$page_id = Wo_Secure($data['page_id']);
      }
      
$user_id      = Wo_Secure($wo['user']['user_id']);
      
$comment_id   = Wo_Secure($data['comment_id']);
      
$comment_text = Wo_Secure($data['text']);
      
$query        = mysqli_query($sqlConnect, "SELECT `id`, `user_idFROM " . T_COMMENTS . " WHERE `id` = {$comment_id} AND `user_id` = {$user_id}");
      if (mysqli_num_rows(
$query) > 0) {
            if (!empty(
$comment_text)) {
                  if (
$wo['config']['maxCharacters'] > 0) {
                        if (strlen(
$data['text']) > $wo['config']['maxCharacters']) {
                              return false;
                        }
                  }
                  // Links
                  
$link_regex = '/(http://|https://|www.)([^ ]+)/i';
                  
$i          = 0;
                  preg_match_all(
$link_regex$comment_text$matches);
                  foreach (
$matches[0] as $match) {
                        
$match_url    = strip_tags($match);
                        
$syntax       = '[a]' . urlencode($match_url) . '[/a]';
                        
$comment_text = str_replace($match$syntax$comment_text);
                  }
                  // @Mentions
                  
$mention_regex = '/@([A-Za-z0-9_]+)/i';
                  preg_match_all(
$mention_regex$comment_text$matches);
                  foreach (
$matches[1] as $match) {
                        
$match         = Wo_Secure($match);
                        
$match_user    = Wo_UserData(Wo_UserIdFromUsername($match));
                        
$match_search  = '@' . $match;
                        
$match_replace = '@[' . $match_user['user_id'] . ']';
                        if (isset(
$match_user['user_id'])) {
                              
$comment_text = str_replace($match_search$match_replace$comment_text);
                              
$mentions[]   = $match_user['user_id'];
                        }
                  }
            }
            
$hashtag_regex = '/#([^`~!@$%^&*#()-+=\|/.,<>?'":;{}[]* ]+)/i';
            preg_match_all($hashtag_regex, $comment_text, $matches);
            foreach ($matches[1] as $match) {
                  if (!is_numeric($match)) {
                        $hashdata = Wo_GetHashtag($match);
                        if (is_array($hashdata)) {
                              $match_search      = '
#' . $match;
                              
$match_replace     '#[' $hashdata['id'] . ']';
                              
$comment_text      str_replace($match_search$match_replace$comment_text);
                              
$hashtag_query     "UPDATE " T_HASHTAGS " SET `last_trend_time` = " time() . ", `trend_use_num` = " . ($hashdata['trend_use_num'] + 1) . " WHERE `id` = " $hashdata['id'];
                              
$hashtag_sql_query mysqli_query($sqlConnect$hashtag_query);
                        }
                  }
            }
            
$query_one mysqli_query($sqlConnect"UPDATE " T_COMMENTS " SET `text` = '{$comment_text}' WHERE `id` = {$comment_id}");
            if (
$query_one) {
                  if (isset(
$mentions) && is_array($mentions)) {
                        foreach (
$mentions as $mention) {
                              
$notification_data_array = array(
                                    
'recipient_id' => $mention,
                                    
'type' => 'comment_mention',
                                    
'page_id' => $page_id,
                                    
'url' => 'index.php?tab1=post&id=' Wo_GetPostIdFromCommentId($data['comment_id'])
                              );
                              
Wo_RegisterNotification($notification_data_array);
                        }
                  }
                  
$query                mysqli_query($sqlConnect"SELECT `text` FROM " T_COMMENTS " WHERE `id` = {$comment_id}");
                  
$fetched_data         mysqli_fetch_assoc($query);
                  
$fetched_data['text'] = Wo_Markup($fetched_data['text']);
                  
$fetched_data['text'] = Wo_Emo($fetched_data['text']);
                  return 
$fetched_data['text'];
            }
      } else {
            return 
false;
      }
}
// update post privacy
function Wo_UpdatePostPrivacy($data = array()) {
      
// Global required variables
      
global $wo$sqlConnect$cache;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (
$data['post_id'] < || empty($data['post_id']) || !is_numeric($data['post_id'])) {
            return 
false;
      }
      if (!
is_numeric($data['privacy_type'])) {
            return 
false;
      }
      
$privacy_type Wo_Secure($data['privacy_type']);
      
$user_id      Wo_Secure($wo['user']['user_id']);
      
$post_id      Wo_Secure($data['post_id']);
      
$query        mysqli_query($sqlConnect"SELECT `id`, `user_id` FROM " T_POSTS " WHERE `id` = {$post_id} OR `post_id` = {$post_id}  AND `user_id` = {$user_id}");
      if (
mysqli_num_rows($query) == 1) {
            
$query_one mysqli_query($sqlConnect"UPDATE " T_POSTS " SET `postPrivacy` = '{$privacy_type}' WHERE `id` = {$post_id}");
            if (
$query_one) {
                  if (
$wo['config']['cacheSystem'] == 1) {
                        
$cache->delete(md5($data['post_id']) . '_P_Data.tmp');
                  }
                  return 
$privacy_type;
            }
      } else {
            return 
false;
      }
}
// update post data
function Wo_UpdatePost($data = array()) {
      
// Global required variables
      
global $wo$sqlConnect$cache;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (
$data['post_id'] < || empty($data['post_id']) || !is_numeric($data['post_id'])) {
            return 
false;
      }
      if (empty(
$data['text'])) {
            return 
false;
      }
      
$page_id 0;
      if (!empty(
$data['page_id'])) {
            
$page_id Wo_Secure($data['page_id']);
      }
      
$post_text Wo_Secure($data['text']);
      
$user_id   Wo_Secure($wo['user']['user_id']);
      
$post_id   Wo_Secure($data['post_id']);
      
$query     mysqli_query($sqlConnect"SELECT `id`, `user_id` FROM " T_POSTS " WHERE `id` = {$post_id} OR `post_id` = {$post_id} AND `user_id` = {$user_id} OR `page_id` IN (SELECT `page_id` FROM " T_PAGES " WHERE `user_id` = {$user_id})");
      if (
mysqli_num_rows($query) > 0) {
            if (!empty(
$post_text)) {
                  if (
$wo['config']['maxCharacters'] > 0) {
                        if (
strlen($post_text) > $wo['config']['maxCharacters']) {
                              return 
false;
                        }
                  }
                  
// Links
                  
$link_regex '/(http://|https://|www.)([^ ]+)/i';
                  
$i          0;
                  
preg_match_all($link_regex$post_text$matches);
                  foreach (
$matches[0] as $match) {
                        
$match_url strip_tags($match);
                        
$syntax    '[a]' urlencode($match_url) . '[/a]';
                        
$post_text str_replace($match$syntax$post_text);
                  }
                  
// @Mentions
                  
$mention_regex '/@([A-Za-z0-9_]+)/i';
                  
preg_match_all($mention_regex$post_text$matches);
                  foreach (
$matches[1] as $match) {
                        
$match         Wo_Secure($match);
                        
$match_user    Wo_UserData(Wo_UserIdFromUsername($match));
                        
$match_search  '@' $match;
                        
$match_replace '@[' $match_user['user_id'] . ']';
                        if (isset(
$match_user['user_id'])) {
                              
$post_text  str_replace($match_search$match_replace$post_text);
                              
$mentions[] = $match_user['user_id'];
                        }
                  }
            }
            
$hashtag_regex '/#([^`~!@$%^&*#()-+=\|/.,<>?'":;{}[]* ]+)/i';
            preg_match_all(
$hashtag_regex$post_text$matches);
            foreach (
$matches[1] as $match) {
                  if (!is_numeric(
$match)) {
                        
$hashdata = Wo_GetHashtag($match);
                        if (is_array(
$hashdata)) {
                              
$match_search      = '#' . $match;
                              
$match_replace     = '#[' . $hashdata['id'] . ']';
                              
$post_text         = str_replace($match_search$match_replace$post_text);
                              
$hashtag_query     = "UPDATE " . T_HASHTAGS . " SET `last_trend_time` = " . time() . ", `trend_use_num` = " . ($hashdata['trend_use_num'] + 1) . " WHERE `id` = " . $hashdata['id'];
                              
$hashtag_sql_query = mysqli_query($sqlConnect$hashtag_query);
                        }
                  }
            }
            
$query_one = mysqli_query($sqlConnect, "UPDATE " . T_POSTS . " SET `postText` = '{$post_text}' WHERE `id` = {$post_id}");
            if (
$query_one) {
                  if (
$wo['config']['cacheSystem'] == 1) {
                        
$cache->delete(md5($data['post_id']) . '_P_Data.tmp');
                  }
                  if (isset(
$mentions) && is_array($mentions)) {
                        foreach (
$mentions as $mention) {
                              
$notification_data_array = array(
                                    'recipient_id' => 
$mention,
                                    'type' => 'post_mention',
                                    'page_id' => 
$page_id,
                                    'url' => 'index.php?tab1=post&id=' . 
$post_id
                              );
                              Wo_RegisterNotification(
$notification_data_array);
                        }
                  }
                  
$query                    = mysqli_query($sqlConnect, "SELECT `postTextFROM " . T_POSTS . " WHERE `id` = {$post_id}");
                  
$fetched_data             = mysqli_fetch_assoc($query);
                  
$fetched_data['postText'] = Wo_Markup($fetched_data['postText']);
                  
$fetched_data['postText'] = Wo_Emo($fetched_data['postText']);
                  return 
$fetched_data['postText'];
            }
      } else {
            return false;
      }
}
// save new post
function Wo_SavePosts(
$post_data) {
      // Global required variables
      global 
$wo$sqlConnect;
      if (empty(
$post_data)) {
            return false;
      }
      
$user_id = Wo_Secure($wo['user']['user_id']);
      
$post_id = Wo_Secure($post_data['post_id']);
      if (Wo_IsPostSaved(
$post_id$user_id)) {
            
$query_one     = "DELETE FROM " . T_SAVED_POSTS . " WHERE `post_id` = {$post_id} AND `user_id` = {$user_id}";
            
$sql_query_one = mysqli_query($sqlConnect$query_one);
            if (
$sql_query_one) {
                  return 'unsaved';
            }
      } else {
            
$query_two     = "INSERT INTO " . T_SAVED_POSTS . " (`user_id`, `post_id`) VALUES ({$user_id}, {$post_id})";
            
$sql_query_two = mysqli_query($sqlConnect$query_two);
            if (
$sql_query_two) {
                  return 'saved';
            }
      }
}
// report a post
function Wo_ReportPost(
$post_data) {
      // Global required variables
      global 
$wo$sqlConnect;
      if (Wo_IsLogged() === false) {
            return false;
      }
      if (empty(
$post_data)) {
            return false;
      }
      if (Wo_PostExists(
$post_data['post_id']) === false) {
            return false;
      }
      
$user_id = Wo_Secure($wo['user']['user_id']);
      
$post_id = Wo_Secure($post_data['post_id']);
      if (Wo_IsPostRepotred(
$post_id$user_id)) {
            
$query_one     = "DELETE FROM " . T_REPORTS . " WHERE `post_id` = {$post_id} AND `user_id` = {$user_id}";
            
$sql_query_one = mysqli_query($sqlConnect$query_one);
            if (
$sql_query_one) {
                  return 'unreport';
            }
      } else {
            
$query_two     = "INSERT INTO " . T_REPORTS . " (`user_id`, `post_id`, `time`) VALUES ({$user_id}, {$post_id}, " . time() . ")";
            
$sql_query_two = mysqli_query($sqlConnect$query_two);
            if (
$sql_query_two) {
                  return 'report';
            }
      }
}
// count not seen reports
function Wo_CountUnseenReports() {
      // Global required variables
      global 
$wo$sqlConnect;
      
$query_one    = "SELECT COUNT(`id`) AS `reportsFROM " . T_REPORTS . " WHERE `seen` = ";
      
$sql          = mysqli_query($sqlConnect$query_one);
      
$fetched_data = mysqli_fetch_assoc($sql);
      return 
$fetched_data['reports'];
}
// update report seen
function Wo_UpdateSeenReports() {
      // Global required variables
      global 
$wo$sqlConnect;
      
$query_one = " UPDATE " . T_REPORTS . " SET `seen` = 1 WHERE `seen` = 0";
      
$sql       = mysqli_query($sqlConnect$query_one);
      if (
$sql) {
            return true;
      }
}
// delete report
function Wo_DeleteReport(
$report_id) {
      // Global required variables
      global 
$sqlConnect;
      
$report_id = Wo_Secure($report_id);
      
$query     = mysqli_query($sqlConnect, "DELETE FROM " . T_REPORTS . " WHERE `id` = {$report_id}");
      if (
$query) {
            return true;
      }
}
// get reports
function Wo_GetReports() {
      // Global required variables
      global 
$wo$sqlConnect;
      
$data      = array();
      
$query_one = " SELECT FROM " . T_REPORTS . " ORDER BY `idDESC";
      
$sql       = mysqli_query($sqlConnect$query_one);
      while (
$fetched_data = mysqli_fetch_assoc($sql)) {
            
$fetched_data['reporter'] = Wo_UserData($fetched_data['user_id']);
            
$fetched_data['story']    = Wo_PostData($fetched_data['post_id']);
            
$data[]                   = $fetched_data;
      }
      return 
$data;
}
// check if post is reported
function Wo_IsPostRepotred(
$post_id$user_id) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id < 1) {
            return false;
      }
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id < 1) {
            return false;
      }
      
$post_id       = Wo_Secure($post_id);
      
$user_id       = Wo_Secure($user_id);
      
$query_one     = "SELECT `idFROM " . T_REPORTS . " WHERE `post_id` = {$post_id} AND `user_id` = {$user_id}";
      
$sql_query_one = mysqli_query($sqlConnect$query_one);
      if (mysqli_num_rows(
$sql_query_one) >= 1) {
            return true;
      }
}
// get all posts
function Wo_GetAllPosts(
$posts = array('limit' => 10, 'after_user_id' => 0)) {
      // Global required variables
      global 
$wo$sqlConnect;
      
$data     = array();
      
$subquery = '';
      
$limit    = Wo_Secure($posts['limit']);
      if (isset(
$posts['after_post_id']) && !empty($posts['after_post_id']) && $posts['after_post_id'] > 0) {
            
$after_post_id = Wo_Secure($posts['after_post_id']);
            
$subquery      = " WHERE `id` < {$after_post_id}";
      }
      
$query_one = " SELECT `idFROM " . T_POSTS . " {$subqueryORDER BY `idDESC LIMIT {$limit}";
      
$sql       = mysqli_query($sqlConnect$query_one);
      while (
$fetched_data = mysqli_fetch_assoc($sql)) {
            
$data[] = Wo_PostData($fetched_data['id'], 'admin');
      }
      return 
$data;
}
// check if post is saved
function Wo_IsPostSaved(
$post_id$user_id) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id < 1) {
            return false;
      }
      
$post_id       = Wo_Secure($post_id);
      
$user_id       = Wo_Secure($user_id);
      
$query_one     = "SELECT `idFROM " . T_SAVED_POSTS . " WHERE `post_id` = {$post_id} AND `user_id` = {$user_id}";
      
$sql_query_one = mysqli_query($sqlConnect$query_one);
      if (mysqli_num_rows(
$sql_query_one) >= 1) {
            return true;
      }
}
// get saved posts
function Wo_GetSavedPosts(
$user_id) {
      // Global required variables
      global 
$wo$sqlConnect;
      
$data  = array();
      
$query = mysqli_query($sqlConnect, "SELECT FROM " . T_SAVED_POSTS . " WHERE `user_id` = {$user_idORDER BY id DESC");
      while (
$fetched_data = mysqli_fetch_assoc($query)) {
            
$data[] = Wo_PostData($fetched_data['post_id']);
      }
      return 
$data;
}
// get post id from comment
function Wo_GetPostIdFromCommentId(
$comment_id = 0) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$comment_id) or !is_numeric($comment_id) or $comment_id < 1) {
            return false;
      }
      
$comment_id    = Wo_Secure($comment_id);
      
$query_one     = "SELECT `post_idFROM " . T_COMMENTS . " WHERE `id` = {$comment_id}";
      
$sql_query_one = mysqli_query($sqlConnect$query_one);
      if (mysqli_num_rows(
$sql_query_one) == 1) {
            
$sql_fetch_one = mysqli_fetch_assoc($sql_query_one);
            return 
$sql_fetch_one['post_id'];
      }
}
// get user id from comment
function Wo_GetUserIdFromCommentId(
$comment_id = 0) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$comment_id) or !is_numeric($comment_id) or $comment_id < 1) {
            return false;
      }
      
$comment_id    = Wo_Secure($comment_id);
      
$query_one     = "SELECT `user_idFROM " . T_COMMENTS . " WHERE `id` = {$comment_id}";
      
$sql_query_one = mysqli_query($sqlConnect$query_one);
      if (mysqli_num_rows(
$sql_query_one) == 1) {
            
$sql_fetch_one = mysqli_fetch_assoc($sql_query_one);
            return 
$sql_fetch_one['user_id'];
      }
}
// add likes to comment
function Wo_AddCommentLikes(
$comment_id$text = '') {
      // Global required variables
      global 
$wo$sqlConnect;
      if (Wo_IsLogged() === false) {
            return false;
      }
      if (!isset(
$comment_id) or empty($comment_id) or !is_numeric($comment_id) or $comment_id < 1) {
            return false;
      }
      
$comment_id          = Wo_Secure($comment_id);
      
$user_id             = Wo_Secure($wo['user']['user_id']);
      
$comment_timeline_id = Wo_GetUserIdFromCommentId($comment_id);
      
$post_id             = Wo_GetPostIdFromCommentId($comment_id);
      
$page_id             = '';
      
$post_data           = Wo_PostData($post_id);
      if (!empty(
$post_data['page_id'])) {
            
$page_id = $post_data['page_id'];
      }
      if (Wo_IsPageOnwer(
$post_data['page_id']) === false) {
            
$page_id = 0;
      }
      if (empty(
$comment_timeline_id)) {
            return false;
      }
      if (isset(
$text) && !empty($text)) {
            
$text = substr($text, 0, 10) . '..';
      }
      if (Wo_IsCommentLiked(
$comment_id$user_id) === true) {
            
$query_one = "DELETE FROM " . T_COMMENT_LIKES . " WHERE `comment_id` = {$comment_id} AND `user_id` = {$user_id}";
            mysqli_query(
$sqlConnect, "DELETE FROM " . T_NOTIFICATION . " WHERE `post_id` = {$post_id} AND `recipient_id` = {$comment_timeline_id} AND `type` = 'liked_comment'");
            
$sql_query_one = mysqli_query($sqlConnect$query_one);
            if (
$sql_query_one) {
                  return 'unliked';
            }
      } else {
            
$query_two     = "INSERT INTO " . T_COMMENT_LIKES . " (`user_id`, `post_id`, `comment_id`) VALUES ({$user_id},{$post_id},{$comment_id})";
            
$sql_query_two = mysqli_query($sqlConnect$query_two);
            if (
$sql_query_two) {
                  
$notification_data_array = array(
                        'recipient_id' => 
$comment_timeline_id,
                        'post_id' => 
$post_id,
                        'type' => 'liked_comment',
                        'text' => 
$text,
                        'page_id' => 
$page_id,
                        'url' => 'index.php?tab1=post&id=' . 
$post_id
                  );
                  Wo_RegisterNotification(
$notification_data_array);
                  return 'liked';
            }
      }
}
// count comment likes
function Wo_CountCommentLikes(
$comment_id) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$comment_id) or !is_numeric($comment_id) or $comment_id < 1) {
            return false;
      }
      
$comment_id    = Wo_Secure($comment_id);
      
$query_one     = "SELECT COUNT(`id`) AS `likesFROM " . T_COMMENT_LIKES . " WHERE `comment_id` = {$comment_id}";
      
$sql_query_one = mysqli_query($sqlConnect$query_one);
      if (mysqli_num_rows(
$sql_query_one) == 1) {
            
$sql_fetch_one = mysqli_fetch_assoc($sql_query_one);
            return 
$sql_fetch_one['likes'];
      }
}
// check if comment is liked
function Wo_IsCommentLiked(
$comment_id$user_id) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$comment_id) or !is_numeric($comment_id) or $comment_id < 1) {
            return false;
      }
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id < 1) {
            return false;
      }
      
$comment_id    = Wo_Secure($comment_id);
      
$user_id       = Wo_Secure($user_id);
      
$query_one     = "SELECT `idFROM " . T_COMMENT_LIKES . " WHERE `comment_id` = {$comment_id} AND `user_id` = {$user_id}";
      
$sql_query_one = mysqli_query($sqlConnect$query_one);
      if (mysqli_num_rows(
$sql_query_one) >= 1) {
            return true;
      }
}
// add comment wonders
function Wo_AddCommentWonders(
$comment_id$text = '') {
      // Global required variables
      global 
$wo$sqlConnect;
      if (Wo_IsLogged() === false) {
            return false;
      }
      if (!isset(
$comment_id) or empty($comment_id) or !is_numeric($comment_id) or $comment_id < 1) {
            return false;
      }
      
$comment_id      = Wo_Secure($comment_id);
      
$user_id         = Wo_Secure($wo['user']['user_id']);
      
$comment_user_id = Wo_GetUserIdFromCommentId($comment_id);
      
$post_id         = Wo_GetPostIdFromCommentId($comment_id);
      
$page_id         = '';
      
$post_data       = Wo_PostData($post_id);
      if (!empty(
$post_data['page_id'])) {
            
$page_id = $post_data['page_id'];
      }
      if (Wo_IsPageOnwer(
$post_data['page_id']) === false) {
            
$page_id = 0;
      }
      if (empty(
$comment_user_id)) {
            return false;
      }
      if (isset(
$text) && !empty($text)) {
            
$text = substr($text, 0, 10) . '..';
      }
      if (Wo_IsCommentWondered(
$comment_id$wo['user']['user_id']) === true) {
            
$query_one = "DELETE FROM " . T_COMMENT_WONDERS . " WHERE `comment_id` = {$comment_id} AND `user_id` = {$user_id}";
            mysqli_query(
$sqlConnect, "DELETE FROM " . T_NOTIFICATION . " WHERE `post_id` = {$post_id} AND `recipient_id` = {$comment_user_id} AND `type` = 'wondered_comment'");
            
$sql_query_one = mysqli_query($sqlConnect$query_one);
            if (
$sql_query_one) {
                  return 'unwonder';
            }
      } else {
            
$query_two     = "INSERT INTO " . T_COMMENT_WONDERS . " (`user_id`, `post_id`, `comment_id`) VALUES ({$user_id}, {$post_id}, {$comment_id})";
            
$sql_query_two = mysqli_query($sqlConnect$query_two);
            if (
$sql_query_two) {
                  
$notification_data_array = array(
                        'recipient_id' => 
$comment_user_id,
                        'post_id' => 
$post_id,
                        'type' => 'wondered_comment',
                        'text' => 
$text,
                        'page_id' => 
$page_id,
                        'url' => 'index.php?tab1=post&id=' . 
$post_id
                  );
                  Wo_RegisterNotification(
$notification_data_array);
                  return 'wonder';
            }
      }
}
// count comment wonders
function Wo_CountCommentWonders(
$comment_id) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$comment_id) or !is_numeric($comment_id) or $comment_id < 1) {
            return false;
      }
      
$comment_id    = Wo_Secure($comment_id);
      
$query_one     = "SELECT COUNT(`id`) AS `likesFROM " . T_COMMENT_WONDERS . " WHERE `comment_id` = {$comment_id}";
      
$sql_query_one = mysqli_query($sqlConnect$query_one);
      if (mysqli_num_rows(
$sql_query_one) == 1) {
            
$sql_fetch_one = mysqli_fetch_assoc($sql_query_one);
            return 
$sql_fetch_one['likes'];
      }
}
// check is comment wondered
function Wo_IsCommentWondered(
$comment_id$user_id) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$comment_id) or !is_numeric($comment_id) or $comment_id < 1) {
            return false;
      }
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id < 1) {
            return false;
      }
      
$comment_id    = Wo_Secure($comment_id);
      
$user_id       = Wo_Secure($user_id);
      
$query_one     = "SELECT `idFROM " . T_COMMENT_WONDERS . " WHERE `comment_id` = {$comment_id} AND `user_id` = {$user_id}";
      
$sql_query_one = mysqli_query($sqlConnect$query_one);
      if (mysqli_num_rows(
$sql_query_one) >= 1) {
            return true;
      }
}
// get comment likes
function Wo_GetCommentLikes(
$comment_id) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$comment_id) or !is_numeric($comment_id) or $comment_id < 1) {
            return false;
      }
      
$comment_id    = Wo_Secure($comment_id);
      
$data          = array();
      
$query_one     = "SELECT `user_idFROM " . T_COMMENT_LIKES . " WHERE `comment_id` = {$comment_id}";
      
$sql_query_one = mysqli_query($sqlConnect$query_one);
      while (
$fetched_data = mysqli_fetch_assoc($sql_query_one)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      return 
$data;
}
// get comment wonders
function Wo_GetCommentWonders(
$comment_id) {
      // Global required variables
      global 
$sqlConnect;
      if (empty(
$comment_id) or !is_numeric($comment_id) or $comment_id < 1) {
            return false;
      }
      
$comment_id    = Wo_Secure($comment_id);
      
$data          = array();
      
$query_one     = "SELECT `user_idFROM " . T_COMMENT_WONDERS . " WHERE `comment_id` = {$comment_id}";
      
$sql_query_one = mysqli_query($sqlConnect$query_one);
      while (
$fetched_data = mysqli_fetch_assoc($sql_query_one)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      return 
$data;
}
// get trending hashtags
function Wa_GetTrendingHashs(
$type = 'latest', $limit = 5) {
      // Global required variables
      global 
$sqlConnect;
      
$data = array();
      if (empty(
$type)) {
            return false;
      }
      if (empty(
$limit) or !is_numeric($limit) or $limit < 1) {
            
$limit = 5;
      }
      if (
$type == "latest") {
            
$query = "SELECT FROM " . T_HASHTAGS . " ORDER BY `last_trend_timeDESC LIMIT {$limit}";
      } elseif (
$type == "popular") {
            
$query = "SELECT FROM " . T_HASHTAGS . " ORDER BY `trend_use_numDESC LIMIT {$limit}";
      }
      
$sql_query   = mysqli_query($sqlConnect$query);
      
$sql_numrows = mysqli_num_rows($sql_query);
      if (
$sql_numrows > 0) {
            while (
$sql_fetch = mysqli_fetch_assoc($sql_query)) {
                  
$sql_fetch['url'] = Wo_SeoLink('index.php?tab1=hashtag&hash=' . $sql_fetch['tag']);
                  
$data[]           = $sql_fetch;
            }
            return 
$data;
      }
}
// get hashtag posts
function Wo_GetHashtagPosts(
$s_query$after_post_id = 0, $limit = 5) {
      // Global required variables
      global 
$sqlConnect;
      
$data         = array();
      
$search_query = str_replace('#', '', Wo_Secure($s_query));
      
$hashdata     = Wo_GetHashtag($search_query);
      if (is_array(
$hashdata) && count($hashdata) > 0) {
            
$search_string = "#[" . $hashdata['id'] . "]";
            
$query_one     "SELECT id FROM " T_POSTS " WHERE `postText` LIKE '%{$search_string}%'";
            if (isset(
$after_post_id) && !empty($after_post_id) && is_numeric($after_post_id)) {
                  
$after_post_id Wo_Secure($after_post_id);
                  
$query_one .= " AND id < {$after_post_id}";
            }
            
$query_one .= " ORDER BY `id` DESC LIMIT {$limit}";
            
$sql_query_one mysqli_query($sqlConnect$query_one);
            while (
$sql_fetch_one mysqli_fetch_assoc($sql_query_one)) {
                  
$posts Wo_PostData($sql_fetch_one['id']);
                  if (
is_array($posts)) {
                        
$data[] = $posts;
                  }
            }
      }
      return 
$data;
}
// get hashtag posts
function Wo_SearchForPosts($id 0$s_query ''$limit 5$type '') {
      
// Global required variables
      
global $sqlConnect;
      
$data = array();
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$id) || !is_numeric($id) || $id 1) {
            return 
false;
      }
      if (
$type == 'page') {
            
$query_type "AND `page_id` = {$id}";
      } else if (
$type == 'user') {
            
$query_type "AND `user_id` = {$id}";
      } else {
            return 
false;
      }
      
$search_query Wo_Secure($s_query);
      
$query_one    "SELECT id FROM " T_POSTS " WHERE `postText` LIKE '%{$search_query}%' {$query_type}";
      
$query_one .= " ORDER BY `id` DESC LIMIT {$limit}";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      while (
$sql_fetch_one mysqli_fetch_assoc($sql_query_one)) {
            
$posts Wo_PostData($sql_fetch_one['id']);
            if (
is_array($posts)) {
                  
$data[] = $posts;
            }
      }
      return 
$data;
}
// search for tag
function Wo_GetSerachHash($s_query) {
      
// Global required variables
      
global $sqlConnect;
      
$search_query str_replace('#'''Wo_Secure($s_query));
      
$data         = array();
      
$query        mysqli_query($sqlConnect"SELECT * FROM " T_HASHTAGS " WHERE `tag` LIKE '%{$search_query}%' ORDER BY `trend_use_num` DESC LIMIT 10");
      while (
$fetched_data mysqli_fetch_assoc($query)) {
            
$fetched_data['url'] = Wo_SeoLink('index.php?tab1=hashtag&hash=' $fetched_data['tag']);
            
$data[]              = $fetched_data;
      }
      return 
$data;
}
// count online users
function Wo_CountOnlineUsers() {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$time         time() - 60;
      
$user_id      Wo_Secure($wo['user']['user_id']);
      
$query        mysqli_query($sqlConnect"SELECT COUNT(`user_id`) AS `online` FROM " T_USERS " WHERE `user_id` IN (SELECT `following_id` FROM " T_FOLLOWERS " WHERE `follower_id`= {$user_id} AND `following_id` <> {$user_id} AND `active` = '1') AND `lastseen` > {$time} AND `active` = '1' ORDER BY `lastseen` DESC");
      
$fetched_data mysqli_fetch_assoc($query);
      return 
$fetched_data['online'];
}
function 
Wo_GetChatUsers($type) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$data       = array();
      
$time       time() - 60;
      
$user_id    Wo_Secure($wo['user']['user_id']);
      
$query_text "SELECT `user_id` FROM " T_USERS " WHERE `user_id` IN (SELECT `following_id` FROM " T_FOLLOWERS " WHERE `follower_id` = {$user_id} AND `following_id` <> {$user_id} AND `active` = '1')";
      if (
$type == 'online') {
            
$query_text .= " AND `lastseen` > {$time}";
      } else if (
$type == 'offline') {
            
$query_text .= " AND `lastseen` < {$time}";
      }
      
$query_text .= " AND `active` = '1' ORDER BY `lastseen` DESC LIMIT 5";
      
$query mysqli_query($sqlConnect$query_text);
      while (
$fetched_data mysqli_fetch_assoc($query)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      return 
$data;
}
// search for users in chat
function Wo_ChatSearchUsers($search_query '') {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$data         = array();
      
$time         time() - 60;
      
$search_query Wo_Secure($search_query);
      
$user_id      Wo_Secure($wo['user']['user_id']);
      
$query_one    "SELECT `user_id` FROM " T_USERS " WHERE (`user_id` IN (SELECT `following_id` FROM " T_FOLLOWERS " WHERE `follower_id` = {$user_id} AND `following_id` <> {$user_id} AND `active` = '1') AND `active` = '1'";
      if (isset(
$search_query) && !empty($search_query)) {
            
$query_one .= " AND ((`username` LIKE '%$search_query%') OR CONCAT(`first_name`,  ' ', `last_name`) LIKE  '%{$search_query}%'))";
      }
      
$query_one .= " ORDER BY `first_name` LIMIT 10";
      
$query mysqli_query($sqlConnect$query_one);
      while (
$fetched_data mysqli_fetch_assoc($query)) {
            
$data[] = Wo_UserData($fetched_data['user_id']);
      }
      return 
$data;
}
// update chat status
function Wo_UpdateStatus($status 'online') {
      
// Global required variables
      
global $sqlConnect$wo$cache;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$status)) {
            return 
false;
      }
      
$finel_status '';
      
$user_id      Wo_Secure($wo['user']['user_id']);
      if (
$status == 'online') {
            
$finel_status 0;
      } else if (
$status == 'offline') {
            
$finel_status 1;
      }
      if (!
is_numeric($finel_status)) {
            return 
false;
      }
      
$query mysqli_query($sqlConnect"UPDATE " T_USERS " SET `status` = {$finel_status} WHERE `user_id` = {$user_id}");
      if (
$query) {
            if (
$wo['config']['cacheSystem'] == 1) {
                  
$cache->delete(md5($wo['user']['user_id']) . '_U_Data.tmp');
            }
            return 
$finel_status;
      }
}
// check if users is online
function Wo_IsOnline($user_id) {
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 1) {
            return 
false;
      }
      
$user_id  Wo_Secure($user_id);
      
$lastseen Wo_UserData($user_id);
      
$time     time() - 60;
      if (
$lastseen['lastseen'] < $time) {
            return 
false;
      } else {
            return 
true;
      }
}
function 
Wo_RightToLeft($type '') {
      
// Global required variables
      
global $wo;
      
$type Wo_Secure($type);
      if (
$wo['language_type'] == 'rtl') {
            if (
$type == 'pull-right') {
                  return 
'pull-left';
            }
            if (
$type == 'pull-left') {
                  return 
'pull-right';
            }
            if (
$type == 'left-addon') {
                  return 
'right-addon';
            }
            if (
$type == 'text-right') {
                  return 
'text-left';
            }
            if (
$type == 'text-left') {
                  return 
'text-right';
            }
            if (
$type == 'right') {
                  return 
'left';
            }
      } else {
            return 
$type;
      }
}
function 
Wo_IsTyping($recipient_id) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$recipient_id) || !is_numeric($recipient_id) || $recipient_id 0) {
            return 
false;
      }
      
$user_id      Wo_Secure($wo['user']['user_id']);
      
$recipient_id Wo_Secure($recipient_id);
      
$query        "SELECT `is_typing` FROM " T_FOLLOWERS " WHERE follower_id = {$user_id} AND following_id = {$recipient_id} AND `is_typing` = 1";
      
$query_one    mysqli_query($sqlConnect$query);
      return (
Wo_Sql_Result($query_one0) == 1) ? true false;
}
function 
Wo_RegisterTyping($recipient_id$isTyping 1) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$recipient_id) || !is_numeric($recipient_id) || $recipient_id 0) {
            return 
false;
      }
      
$user_id      $wo['user']['user_id'];
      
$recipient_id Wo_Secure($recipient_id);
      
$typing       1;
      if (
$isTyping == 0) {
            
$typing 0;
      }
      if (
Wo_IsFollowing($user_id$recipient_id) === false) {
            return 
false;
      }
      
$query mysqli_query($sqlConnect"UPDATE " T_FOLLOWERS " SET `is_typing`  = " $typing " WHERE following_id = " $wo['user']['user_id'] . "  AND follower_id = {$recipient_id}");
      if (
$query) {
            return 
true;
      }
}
function 
Wo_DeleteAllTyping($user_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            return 
false;
      }
      
$user_id Wo_Secure($user_id);
      
$query   mysqli_query($sqlConnect"UPDATE " T_FOLLOWERS " SET `is_typing` = 0 WHERE `following_id` = {$user_id}");
      if (
$query) {
            return 
true;
      }
}
// update ad code
function Wo_UpdateAdsCode($update_data = array()) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (
Wo_IsAdmin($wo['user']['user_id']) === false) {
            return 
false;
      }
      if (empty(
$update_data)) {
            return 
false;
      }
      if (empty(
$update_data['type'])) {
            return 
false;
      }
      
$type   Wo_Secure($update_data['type']);
      
$update = array();
      foreach (
$update_data as $field => $data) {
            
$update[] = '`' $field '` = '' . mysqli_real_escape_string($sqlConnect, $data) . ''';
      }
      
$query_text    implode(', '$update);
      
$query_one     " UPDATE " T_ADS " SET {$query_text} WHERE `type` = '{$type}'";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
$sql_query_one) {
            return 
true;
      }
}
// get an ad
function Wo_GetAd($type$admin true) {
      
// Global required variables
      
global $sqlConnect;
      
$type      Wo_Secure($type);
      
$query_one "SELECT `code` FROM " T_ADS " WHERE `type` = '{$type}'";
      if (
$admin === false) {
            
$query_one .= " AND `active` = '1'";
      }
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      
$fetched_data  mysqli_fetch_assoc($sql_query_one);
      return 
$fetched_data['code'];
}
//check if ad is active
function Wo_IsAdActive($type) {
      
// Global required variables
      
global $sqlConnect;
      
$query_one     "SELECT COUNT(`id`) AS `count` FROM " T_ADS " WHERE `type` = '{$type}' AND `active` = '1' ";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      
$fetched_data  mysqli_fetch_assoc($sql_query_one);
      return 
$fetched_data['count'];
}
// update ad activation
function Wo_UpdateAdActivation($type) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (
Wo_IsAdmin($wo['user']['user_id']) === false) {
            return 
false;
      }
      if (
Wo_IsAdActive($type)) {
            
$query_one mysqli_query($sqlConnect"UPDATE " T_ADS " SET `active` = '0' WHERE `type` = '{$type}'");
            return 
'inactive';
      } else {
            
$query_one mysqli_query($sqlConnect"UPDATE " T_ADS " SET `active` = '1' WHERE `type` = '{$type}'");
            return 
'active';
      }
}
// Add new announcement
function Wo_AddNewAnnouncement($text) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id Wo_Secure($wo['user']['user_id']);
      
$text    mysqli_real_escape_string($sqlConnect$text);
      if (
Wo_IsAdmin($user_id) === false) {
            return 
false;
      }
      if (empty(
$text)) {
            return 
false;
      }
      
$query mysqli_query($sqlConnect"INSERT INTO " T_ANNOUNCEMENT " (`text`, `time`, `active`) VALUES ('{$text}', " time() . ", '1')");
      if (
$query) {
            return 
mysqli_insert_id($sqlConnect);
      }
}
// get announcement data
function Wo_GetAnnouncement($id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id Wo_Secure($wo['user']['user_id']);
      
$data    = array();
      if (empty(
$id) || !is_numeric($id) || $id 1) {
            return 
false;
      }
      
$query mysqli_query($sqlConnect"SELECT * FROM " T_ANNOUNCEMENT " WHERE `id` = {$id} ORDER BY `id` DESC");
      if (
mysqli_num_rows($query) == 1) {
            
$fetched_data         mysqli_fetch_assoc($query);
            
$fetched_data['text'] = Wo_Markup($fetched_data['text']);
            
$fetched_data['text'] = Wo_Emo($fetched_data['text']);
            return 
$fetched_data;
      }
}
//get announcement views
function Wo_GetAnnouncementViews($id) {
      
// Global required variables
      
global $sqlConnect$wo;
      
$id            Wo_Secure($id);
      
$query_one     mysqli_query($sqlConnect"SELECT COUNT(`id`) as `count` FROM " T_ANNOUNCEMENT_VIEWS " WHERE `announcement_id` = {$id}");
      
$sql_query_one mysqli_fetch_assoc($query_one);
      return 
$sql_query_one['count'];
}
// get all active announcements for admin
function Wo_GetActiveAnnouncements() {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id Wo_Secure($wo['user']['user_id']);
      
$data    = array();
      if (
Wo_IsAdmin($user_id) === false) {
            return 
false;
      }
      
$query mysqli_query($sqlConnect"SELECT `id` FROM " T_ANNOUNCEMENT " WHERE `active` = '1' ORDER BY `id` DESC");
      while (
$row mysqli_fetch_assoc($query)) {
            
$data[] = Wo_GetAnnouncement($row['id']);
      }
      return 
$data;
}
// get home page announcements
function Wo_GetHomeAnnouncements() {
      global 
$sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id      Wo_Secure($wo['user']['user_id']);
      
$query        mysqli_query($sqlConnect"SELECT `id` FROM " T_ANNOUNCEMENT " WHERE `active` = '1' AND `id` NOT IN (SELECT `announcement_id` FROM " T_ANNOUNCEMENT_VIEWS " WHERE `user_id` = {$user_id}) ORDER BY RAND() LIMIT 1");
      
$fetched_data mysqli_fetch_assoc($query);
      
$data         Wo_GetAnnouncement($fetched_data['id']);
      return 
$data;
}
// get all inactive announcements for admin
function Wo_GetInactiveAnnouncements() {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id Wo_Secure($wo['user']['user_id']);
      
$data    = array();
      if (
Wo_IsAdmin($user_id) === false) {
            return 
false;
      }
      
$query mysqli_query($sqlConnect"SELECT `id` FROM " T_ANNOUNCEMENT " WHERE `active` = '0' ORDER BY `id` DESC");
      while (
$row mysqli_fetch_assoc($query)) {
            
$data[] = Wo_GetAnnouncement($row['id']);
      }
      return 
$data;
}
// delete announcement
function Wo_DeleteAnnouncement($id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$id      Wo_Secure($id);
      
$user_id Wo_Secure($wo['user']['user_id']);
      if (
Wo_IsAdmin($user_id) === false) {
            return 
false;
      }
      
$query_one mysqli_query($sqlConnect"DELETE FROM " T_ANNOUNCEMENT " WHERE `id` = {$id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_ANNOUNCEMENT_VIEWS " WHERE `announcement_id` = {$id}");
      if (
$query_one) {
            return 
true;
      }
}
// check if announcement is active
function Wo_IsActiveAnnouncement($id) {
      
// Global required variables
      
global $sqlConnect;
      
$id    Wo_Secure($id);
      
$query mysqli_query($sqlConnect"SELECT COUNT(`id`) FROM " T_ANNOUNCEMENT " WHERE `id` = '{$id}' AND `active` = '1'");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// check if announcement is viewed
function Wo_IsViewedAnnouncement($id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$id      Wo_Secure($id);
      
$user_id Wo_Secure($wo['user']['user_id']);
      
$query   mysqli_query($sqlConnect"SELECT COUNT(`id`) FROM " T_ANNOUNCEMENT_VIEWS " WHERE `announcement_id` = '{$id}' AND `user_id` = '{$user_id}'");
      return (
Wo_Sql_Result($query0) > 0) ? true false;
}
// check if is there an announcement
function Wo_IsThereAnnouncement() {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id Wo_Secure($wo['user']['user_id']);
      
$query   mysqli_query($sqlConnect"SELECT COUNT(`id`) as count FROM " T_ANNOUNCEMENT " WHERE `active` = '1' AND `id` NOT IN (SELECT `announcement_id` FROM " T_ANNOUNCEMENT_VIEWS " WHERE `user_id` = {$user_id})");
      
$sql     mysqli_fetch_assoc($query);
      return (
$sql['count'] > 0) ? true false;
}
// disable announcement
function Wo_DisableAnnouncement($id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$id      Wo_Secure($id);
      
$user_id Wo_Secure($wo['user']['user_id']);
      if (
Wo_IsAdmin($user_id) === false) {
            return 
false;
      }
      if (
Wo_IsActiveAnnouncement($id) === false) {
            return 
false;
      }
      
$query_one mysqli_query($sqlConnect"UPDATE " T_ANNOUNCEMENT " SET `active` = '0' WHERE `id` = {$id}");
      if (
$query_one) {
            return 
true;
      }
}
// activate announcement
function Wo_ActivateAnnouncement($id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$id      Wo_Secure($id);
      
$user_id Wo_Secure($wo['user']['user_id']);
      if (
Wo_IsAdmin($user_id) === false) {
            return 
false;
      }
      if (
Wo_IsActiveAnnouncement($id) === true) {
            return 
false;
      }
      
$query_one mysqli_query($sqlConnect"UPDATE " T_ANNOUNCEMENT " SET `active` = '1' WHERE `id` = {$id}");
      if (
$query_one) {
            return 
true;
      }
}
// update announcement views
function Wo_UpdateAnnouncementViews($id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$id      Wo_Secure($id);
      
$user_id Wo_Secure($wo['user']['user_id']);
      if (
Wo_IsActiveAnnouncement($id) === false) {
            return 
false;
      }
      if (
Wo_IsViewedAnnouncement($id) === true) {
            return 
false;
      }
      
$query_one mysqli_query($sqlConnect"INSERT INTO " T_ANNOUNCEMENT_VIEWS " (`user_id`, `announcement_id`) VALUES ('{$user_id}', '{$id}')");
      if (
$query_one) {
            return 
true;
      }
}
function 
Wo_RegisterApp($registration_data) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$registration_data)) {
            return 
false;
      }
      if (empty(
$registration_data['app_user_id']) || !is_numeric($registration_data['app_user_id']) || $registration_data['app_user_id'] < 1) {
            return 
false;
      }
      
$id_str                          sha1($registration_data['app_user_id'] . microtime() . time());
      
$registration_data['app_id']     = Wo_Secure(substr($id_str020));
      
$secret_str                      sha1($registration_data['app_user_id'] . Wo_GenerateKey(5555) . microtime());
      
$registration_data['app_secret'] = Wo_Secure(substr($secret_str039));
      if (empty(
$registration_data['app_secret']) || empty($registration_data['app_id'])) {
            return 
false;
      }
      
$fields '`' implode('`, `'array_keys($registration_data)) . '`';
      
$data   ''' . implode('', '', $registration_data) . ''';
      
$query  mysqli_query($sqlConnect"INSERT INTO " T_APPS " ({$fields}) VALUES ({$data})");
      if (
$query) {
            return 
mysqli_insert_id($sqlConnect);
      }
}
function 
Wo_IsAppOnwer($app_id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$user_id       Wo_Secure($wo['user']['user_id']);
      
$app_id        Wo_Secure($app_id);
      
$query_one     mysqli_query($sqlConnect"SELECT COUNT(`id`) as `count` FROM " T_APPS " WHERE `app_user_id` = {$user_id} AND `id` = {$app_id} AND `active` = '1'");
      
$sql_query_one mysqli_fetch_assoc($query_one);
      return (
$sql_query_one['count'] == 1) ? true false;
}
function 
Wo_GetAppsData($placement '') {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$data       = array();
      
$user_id    $wo['user']['user_id'];
      
$query_text "SELECT `id` FROM " T_APPS;
      if (
$placement != 'admin') {
            
$query_text .= " WHERE `app_user_id` = {$user_id}";
      }
      
$query_one mysqli_query($sqlConnect$query_text);
      while (
$fetched_data mysqli_fetch_assoc($query_one)) {
            if (
is_array($fetched_data)) {
                  
$data[] = Wo_GetApp($fetched_data['id']);
            }
      }
      return 
$data;
}
function 
Wo_GetApp($app_id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$app_id) || !is_numeric($app_id) || $app_id 1) {
            return 
false;
      }
      
$app_id    Wo_Secure($app_id);
      
$query_one mysqli_query($sqlConnect"SELECT * FROM " T_APPS " WHERE `id` = {$app_id}");
      if (
mysqli_num_rows($query_one) == 1) {
            
$sql_query_one               mysqli_fetch_assoc($query_one);
            
$sql_query_one['app_onwer']  = Wo_UserData($sql_query_one['app_user_id']);
            
$sql_query_one['app_avatar'] = Wo_GetMedia($sql_query_one['app_avatar']);
            return 
$sql_query_one;
      }
}
function 
Wo_UpdateAppImage($app_id$image) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$app_id) || !is_numeric($app_id) || $app_id 0) {
            return 
false;
      }
      if (empty(
$image)) {
            return 
false;
      }
      
$app_id    Wo_Secure($app_id);
      
$query_one " UPDATE " T_APPS " SET `app_avatar` = '{$image}' WHERE `id` = {$app_id} ";
      
$query     mysqli_query($sqlConnect$query_one);
      if (
$query) {
            return 
true;
      }
}
// update app data
function Wo_UpdateAppData($app_id$update_data) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$app_id) || !is_numeric($app_id) || $app_id 0) {
            return 
false;
      }
      if (empty(
$update_data)) {
            return 
false;
      }
      
$app_id Wo_Secure($app_id);
      
$update = array();
      foreach (
$update_data as $field => $data) {
            
$update[] = '`' $field '` = '' . Wo_Secure($data) . ''';
      }
      
$impload   implode(', '$update);
      
$query_one " UPDATE " T_APPS " SET {$impload} WHERE `id` = {$app_id} ";
      
$query     mysqli_query($sqlConnect$query_one);
      if (
$query) {
            return 
true;
      } else {
            return 
false;
      }
}
function 
Wo_GetIdFromAppID($app_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$app_id)) {
            return 
false;
      }
      
$app_id        Wo_Secure($app_id);
      
$query_one     "SELECT `id` FROM " T_APPS " WHERE `app_id` = '{$app_id}'";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) == 1) {
            
$sql_fetch_one mysqli_fetch_assoc($sql_query_one);
            return 
$sql_fetch_one['id'];
      }
}
function 
Wo_AccessToken($app_id$app_secret) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$app_id)) {
            return 
false;
      }
      if (empty(
$app_secret)) {
            return 
false;
      }
      
$app_id        Wo_Secure($app_id);
      
$app_secret    Wo_Secure($app_secret);
      
$query_one     "SELECT `id` FROM " T_APPS " WHERE `app_id` = '{$app_id}' AND `app_secret` = '{$app_secret}'";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) == 1) {
            return 
true;
      } else {
            return 
false;
      }
}
function 
Wo_IsValidApp($app_id) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$app_id)) {
            return 
false;
      }
      
$app_id        Wo_Secure($app_id);
      
$query_one     "SELECT `id` FROM " T_APPS " WHERE `app_id` = '{$app_id}'";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) == 1) {
            return 
true;
      }
}
function 
Wo_AppHasPermission($user_id$app_id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (empty(
$app_id)) {
            return 
false;
      }
      
$app_id        Wo_Secure($app_id);
      
$user_id       Wo_Secure($user_id);
      
$query_one     "SELECT `id` FROM " T_APPS_PERMISSION " WHERE `app_id` = '{$app_id}' AND `user_id` = '{$user_id}'";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) > 0) {
            return 
true;
      } else {
            return 
false;
      }
}
function 
Wo_AcceptPermissions($app_id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$app_id  Wo_Secure($app_id);
      
$user_id Wo_Secure($wo['user']['user_id']);
      if (empty(
$app_id) || empty($user_id)) {
            return 
false;
      }
      
$query_one     "INSERT INTO " T_APPS_PERMISSION " (`user_id`,`app_id`) VALUES ('{$user_id}','{$app_id}')";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
$sql_query_one) {
            return 
true;
      }
}
function 
Wo_GenrateToken($user_id$app_id) {
      
// Global required variables
      
global $sqlConnect$wo;
      
$app_id  Wo_Secure($app_id);
      
$user_id Wo_Secure($user_id);
      if (empty(
$app_id) || empty($user_id)) {
            return 
false;
      }
      
$token     Wo_GenerateKey(100100);
      
$query_two mysqli_query($sqlConnect"SELECT `id` FROM " T_TOKENS " WHERE `app_id` = {$app_id} AND `user_id` = {$user_id}");
      if (
mysqli_num_rows($query_two) > 0) {
            
$query_three mysqli_query($sqlConnect"DELETE FROM " T_TOKENS " WHERE `app_id` = {$app_id} AND `user_id` = {$user_id}");
      }
      
$query_one     "INSERT INTO " T_TOKENS " (`user_id`,`app_id`,`token`,`time`) VALUES ('{$user_id}','{$app_id}','{$token}','" time() . "')";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
$sql_query_one) {
            return 
$token;
      }
}
function 
Wo_UserIdFromToken($token) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (empty(
$token)) {
            return 
false;
      }
      
$query_one     "SELECT `user_id` FROM " T_TOKENS " WHERE `token` = '{$token}'";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) == 1) {
            
$sql_query_two mysqli_fetch_assoc($sql_query_one);
            return 
$sql_query_two['user_id'];
      } else {
            return 
false;
      }
}
function 
Wo_GetIdFromToken($token) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (empty(
$token)) {
            return 
false;
      }
      
$query_one     "SELECT `app_id` FROM " T_TOKENS " WHERE `token` = '{$token}'";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) == 1) {
            
$sql_query_two mysqli_fetch_assoc($sql_query_one);
            return 
$sql_query_two['app_id'];
      } else {
            return 
false;
      }
}
// register page
function Wo_RegisterPage($registration_data) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (empty(
$registration_data)) {
            return 
false;
      }
      
$fields '`' implode('`, `'array_keys($registration_data)) . '`';
      
$data   ''' . implode('', '', $registration_data) . ''';
      
$query  mysqli_query($sqlConnect"INSERT INTO " T_PAGES " ({$fields}) VALUES ({$data})");
      if (
$query) {
            return 
true;
      } else {
            return 
false;
      }
}
function 
Wo_GetMyPages() {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      
$data       = array();
      
$user_id    Wo_Secure($wo['user']['user_id']);
      
$query_text "SELECT `page_id` FROM " T_PAGES " WHERE `user_id` = {$user_id}";
      
$query_one  mysqli_query($sqlConnect$query_text);
      while (
$fetched_data mysqli_fetch_assoc($query_one)) {
            if (
is_array($fetched_data)) {
                  
$data[] = Wo_PageData($fetched_data['page_id']);
            }
      }
      return 
$data;
}
// check if logged in user has access to admin panel
function Wo_IsPageOnwer($page_id) {
      
// Global required variables
      
global $sqlConnect$wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$page_id) || !is_numeric($page_id) || $page_id 0) {
            return 
false;
      }
      
$user_id Wo_Secure($wo['user']['user_id']);
      if (empty(
$user_id) || !is_numeric($user_id) || $user_id 0) {
            return 
false;
      }
      
$query mysqli_query($sqlConnect" SELECT COUNT(`user_id`) FROM " T_PAGES " WHERE `page_id` = {$page_id} AND `user_id` = {$user_id} AND `active` = '1'");
      return (
Wo_Sql_Result($query'0') == 1) ? true false;
}
function 
Wo_PageExists($page_name '') {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$page_name)) {
            return 
false;
      }
      
$page_name Wo_Secure($page_name);
      
$query     mysqli_query($sqlConnect"SELECT COUNT(`page_id`) FROM " T_PAGES " WHERE `page_name`= '{$page_name}' AND `active` = '1'");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
function 
Wo_PageIdFromPagename($page_name '') {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$page_name)) {
            return 
false;
      }
      
$page_name Wo_Secure($page_name);
      
$query     mysqli_query($sqlConnect"SELECT `page_id` FROM " T_PAGES " WHERE `page_name` = '{$page_name}'");
      return 
Wo_Sql_Result($query0'page_id');
}
function 
Wo_PageData($page_id 0) {
      
// Global required variables
      
global $wo$sqlConnect$cache;
      if (empty(
$page_id) || !is_numeric($page_id) || $page_id 0) {
            return 
false;
      }
      
$data           = array();
      
$page_id        Wo_Secure($page_id);
      
$query_one      "SELECT * FROM " T_PAGES " WHERE `page_id` = {$page_id}";
      
$hashed_page_Id md5($page_id);
      if (
$wo['config']['cacheSystem'] == 1) {
            
$fetched_data $cache->read($hashed_page_Id '_PAGE_Data.tmp');
            if (empty(
$fetched_data)) {
                  
$sql          mysqli_query($sqlConnect$query_one);
                  
$fetched_data mysqli_fetch_assoc($sql);
                  
$cache->write($hashed_page_Id '_PAGE_Data.tmp'$fetched_data);
            }
      } else {
            
//Wo_ClearCache();
            
$sql          mysqli_query($sqlConnect$query_one);
            
$fetched_data mysqli_fetch_assoc($sql);
      }
      if (empty(
$fetched_data)) {
            return array();
      }
      
$fetched_data['avatar']   = Wo_GetMedia($fetched_data['avatar']);
      
$fetched_data['cover']    = Wo_GetMedia($fetched_data['cover']);
      
$fetched_data['about']    = $fetched_data['page_description'];
      
$fetched_data['url']      = Wo_SeoLink('index.php?tab1=page&p=' $fetched_data['page_name']);
      
$fetched_data['name']     = $fetched_data['page_title'];
      
$fetched_data['category'] = $wo['page_categories'][$fetched_data['page_category']];
      return 
$fetched_data;
}
function 
Wo_PageActive($page_name) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$page_name)) {
            return 
false;
      }
      
$page_name Wo_Secure($page_name);
      
$query     mysqli_query($sqlConnect"SELECT COUNT(`page_id`) FROM " T_PAGES "  WHERE `page_name`= '{$page_name}' AND `active` = '1'");
      return (
Wo_Sql_Result($query0) == 1) ? true false;
}
// get publisher box
function Wo_GetPagePostPublisherBox($page_id 0) {
      
// Global required variables
      
global $wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!
is_numeric($page_id) or $page_id or !is_numeric($page_id)) {
            return 
false;
      }
      if (
Wo_IsPageOnwer($page_id)) {
            return 
Wo_LoadPage('story/publisher-box');
      }
}
// get follow button
function Wo_GetLikeButton($page_id 0) {
      
// Global required variables
      
global $wo;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$page_id) || !is_numeric($page_id) or $page_id 0) {
            return 
false;
      }
      if (
Wo_IsPageOnwer($page_id)) {
            return 
false;
      }
      
$page $wo['like'] = Wo_PageData($page_id);
      if (!isset(
$wo['like']['page_id'])) {
            return 
false;
      }
      
$page_id        Wo_Secure($page_id);
      
$logged_user_id Wo_Secure($wo['user']['user_id']);
      
$like_button    'buttons/like';
      
$unlike_button  'buttons/unlike';
      if (
Wo_IsPageLiked($page_id$logged_user_id) === true) {
            return 
Wo_LoadPage($unlike_button);
      } else {
            return 
Wo_LoadPage($like_button);
      }
}
function 
Wo_IsPageLiked($page_id 0$user_id 0) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$page_id) || !is_numeric($page_id) || $page_id 0) {
            return 
false;
      }
      if (empty(
$page_id) || !is_numeric($user_id) || $user_id 0) {
            
$user_id Wo_Secure($wo['user']['user_id']);
      }
      
$query_one mysqli_query($sqlConnect"SELECT COUNT(`id`) FROM " T_PAGES_LIKES " WHERE `user_id` = '{$user_id}' AND `page_id` = {$page_id} AND `active` = '1'");
      return (
Wo_Sql_Result($query_one0) == 1) ? true false;
}
// register follow 
function Wo_RegisterPageLike($page_id 0$user_id 0) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!isset(
$page_id) or empty($page_id) or !is_numeric($page_id) or $page_id 1) {
            return 
false;
      }
      if (!isset(
$user_id) or empty($user_id) or !is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      
$page_id    Wo_Secure($page_id);
      
$user_id    Wo_Secure($user_id);
      
$page_onwer Wo_GetUserIdFromPageId($page_id);
      
$active     1;
      if (
Wo_IsPageLiked($page_id$user_id) === true) {
            return 
false;
      }
      
$page_data Wo_PageData($page_id);
      
$query     mysqli_query($sqlConnect" INSERT INTO " T_PAGES_LIKES " (`user_id`,`page_id`,`active`,`time`) VALUES ({$user_id},{$page_id},'1'," time() . ")");
      if (
$query) {
            
$notification_data = array(
                  
'recipient_id' => $page_onwer,
                  
'notifier_id' => $user_id,
                  
'page_enable' => false,
                  
'type' => 'liked_page',
                  
'page_id' => $page_id,
                  
'url' => 'index.php?tab1=page&p=' $page_data['page_name']
            );
            
Wo_RegisterNotification($notification_data);
      }
      return 
true;
}
function 
Wo_DeletePageLike($page_id 0$user_id 0) {
      
// Global required variables
      
global $wo$sqlConnect;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (!isset(
$page_id) or empty($page_id) or !is_numeric($page_id) or $page_id 1) {
            return 
false;
      }
      if (!isset(
$user_id) or empty($user_id) or !is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      
$page_id Wo_Secure($page_id);
      
$user_id Wo_Secure($user_id);
      
$active  1;
      if (
Wo_IsPageLiked($page_id$user_id) === false) {
            return 
false;
      }
      
$user_data Wo_UserData($user_id);
      
$query     mysqli_query($sqlConnect" DELETE FROM " T_PAGES_LIKES " WHERE `user_id` = {$user_id} AND `page_id` = '{$page_id}' AND `active` = '1'");
      if (
$query) {
            return 
true;
      }
}
function 
Wo_UpdatePageData($page_id 0$update_data) {
      
// Global required variables
      
global $wo$sqlConnect$cache;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$page_id) || !is_numeric($page_id) || $page_id 0) {
            return 
false;
      }
      if (empty(
$update_data)) {
            return 
false;
      }
      
$page_id Wo_Secure($page_id);
      if (
Wo_IsAdmin($wo['user']['user_id']) === false) {
            if (
Wo_IsPageOnwer($page_id) === false) {
                  return 
false;
            }
      }
      if (!empty(
$update_data['page_category'])) {
            if (!
array_key_exists($update_data['page_category'], $wo['page_categories'])) {
                  
$update_data['page_category'] = 1;
            }
      }
      
$update = array();
      foreach (
$update_data as $field => $data) {
            
$update[] = '`' $field '` = '' . Wo_Secure($data) . ''';
      }
      
$impload   implode(', '$update);
      
$query_one " UPDATE " T_PAGES " SET {$impload} WHERE `page_id` = {$page_id} ";
      
$query     mysqli_query($sqlConnect$query_one);
      if (
$wo['config']['cacheSystem'] == 1) {
            
$cache->delete(md5($page_id) . '_PAGE_Data.tmp');
      }
      if (
$query) {
            return 
true;
      } else {
            return 
false;
      }
}
// get user ID from post 
function Wo_GetPageIdFromPostId($post_id 0) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$post_id) or !is_numeric($post_id) or $post_id 1) {
            return 
false;
      }
      
$post_id       Wo_Secure($post_id);
      
$query_one     "SELECT `page_id` FROM " T_POSTS " WHERE `id` = {$post_id}";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) == 1) {
            
$sql_fetch_one mysqli_fetch_assoc($sql_query_one);
            return 
$sql_fetch_one['page_id'];
      }
}
// get user ID from post 
function Wo_GetUserIdFromPageId($page_id 0) {
      
// Global required variables
      
global $sqlConnect;
      if (empty(
$page_id) or !is_numeric($page_id) or $page_id 1) {
            return 
false;
      }
      
$page_id       Wo_Secure($page_id);
      
$query_one     "SELECT `user_id` FROM " T_PAGES " WHERE `page_id` = {$page_id}";
      
$sql_query_one mysqli_query($sqlConnect$query_one);
      if (
mysqli_num_rows($sql_query_one) == 1) {
            
$sql_fetch_one mysqli_fetch_assoc($sql_query_one);
            return 
$sql_fetch_one['user_id'];
      }
}
// delete user
function Wo_DeletePage($page_id 0) {
      
// Global required variables
      
global $wo$sqlConnect$cache;
      if (
Wo_IsLogged() === false) {
            return 
false;
      }
      if (empty(
$page_id) || !is_numeric($page_id) || $page_id 1) {
            return 
false;
      }
      
$page_id Wo_Secure($page_id);
      if (
Wo_IsAdmin($wo['user']['user_id']) === false) {
            if (
Wo_IsPageOnwer($page_id) === false) {
                  return 
false;
            }
      }
      
$query_one_delete_photos mysqli_query($sqlConnect" SELECT `avatar`,`cover` FROM " T_PAGES " WHERE `page_id` = {$page_id}");
      
$fetched_data            mysqli_fetch_assoc($query_one_delete_photos);
      if (isset(
$fetched_data['avatar']) && !empty($fetched_data['avatar']) && $fetched_data['avatar'] != $wo['userDefaultAvatar']) {
            @
unlink($fetched_data['avatar']);
      }
      if (isset(
$fetched_data['cover']) && !empty($fetched_data['cover']) && $fetched_data['cover'] != $wo['userDefaultCover']) {
            @
unlink($fetched_data['cover']);
      }
      
$query_two_delete_media mysqli_query($sqlConnect" SELECT `postFile` FROM " T_POSTS " WHERE `page_id` = {$page_id}");
      if (
mysqli_num_rows($query_two_delete_media) > 0) {
            while (
$fetched_data mysqli_fetch_assoc($query_two_delete_media)) {
                  if (isset(
$fetched_data['postFile']) && !empty($fetched_data['postFile'])) {
                        @
unlink($fetched_data['postFile']);
                  }
            }
      }
      
$query_four_delete_media mysqli_query($sqlConnect"SELECT `id`,`post_id` FROM " T_POSTS " WHERE `page_id` = {$page_id}");
      if (
mysqli_num_rows($query_four_delete_media) > 0) {
            while (
$fetched_data mysqli_fetch_assoc($query_four_delete_media)) {
                  
$delete_posts Wo_DeletePost($fetched_data['id']);
            }
      }
      if (
$wo['config']['cacheSystem'] == 1) {
            
$cache->delete(md5($user_id) . '_PAGE_Data.tmp');
            
$query_two mysqli_query($sqlConnect"SELECT `id`,`post_id` FROM " T_POSTS " WHERE `page_id` = {$page_id}");
            if (
mysqli_num_rows($query_two) > 0) {
                  while (
$fetched_data_two mysqli_fetch_assoc($query_two)) {
                        
$cache->delete(md5($fetched_data_two['id']) . '_PAGE_Data.tmp');
                        
$cache->delete(md5($fetched_data_two['post_id']) . '_PAGE_Data.tmp');
                  }
            }
      }
      
$query_one mysqli_query($sqlConnect"DELETE FROM " T_PAGES " WHERE `page_id` = {$page_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_PAGES_LIKES " WHERE `page_id` = {$page_id}");
      
$query_one .= mysqli_query($sqlConnect"DELETE FROM " T_NOTIFICATION " WHERE `page_id` = {$page_id}");
      if (
$query_one) {
            return 
true;
      }
}
// count page likes
function Wo_CountPageLikes($page_id 0) {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data = array();
      if (empty(
$page_id) or !is_numeric($page_id) or $page_id 1) {
            return 
false;
      }
      
$page_id      Wo_Secure($page_id);
      
$query        mysqli_query($sqlConnect"SELECT COUNT(`page_id`) AS count FROM " T_PAGES_LIKES " WHERE `page_id` = {$page_id} AND `active` = '1' ");
      
$fetched_data mysqli_fetch_assoc($query);
      return 
$fetched_data['count'];
}
function 
Wo_CountPagePosts($page_id 0) {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data = array();
      if (empty(
$page_id) or !is_numeric($page_id) or $page_id 1) {
            return 
false;
      }
      
$page_id      Wo_Secure($page_id);
      
$query        mysqli_query($sqlConnect"SELECT COUNT(`id`) AS count FROM " T_POSTS " WHERE `page_id` = {$page_id}");
      
$fetched_data mysqli_fetch_assoc($query);
      return 
$fetched_data['count'];
}
function 
Wo_CountLikesThisWeek($page_id 0) {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data = array();
      
$time strtotime("-1 week");
      if (empty(
$page_id) or !is_numeric($page_id) or $page_id 1) {
            return 
false;
      }
      
$page_id      Wo_Secure($page_id);
      
$query        mysqli_query($sqlConnect"SELECT COUNT(`page_id`) AS count FROM " T_PAGES_LIKES " WHERE `page_id` = {$page_id} AND `active` = '1' AND (`time` between {$time} AND " time() . ")");
      
$fetched_data mysqli_fetch_assoc($query);
      return 
$fetched_data['count'];
}
// get (pages you may like) page list 
function Wo_PageSug($limit 1$page_id 0$type 'next') {
      
// Global required variables
      
global $wo$sqlConnect;
      if (!
is_numeric($limit)) {
            return 
false;
      }
      
$query_not '';
      if (!
is_numeric($page_id) || empty($page_id) || $page_id 1) {
            
$query_not '';
      }
      if (
$type == 'previous') {
            
$query_not "AND `page_id` < $page_id";
      } else {
            
$query_not "AND `page_id` > $page_id";
      }
      
$data      = array();
      
$user_id   Wo_Secure($wo['user']['user_id']);
      
$query_one " SELECT `page_id` FROM " T_PAGES " WHERE `active` = '1' {$query_not} AND `page_id` NOT IN (SELECT `page_id` FROM " T_PAGES_LIKES " WHERE `user_id` = {$user_id} AND `active` = '1') AND `user_id` <> {$user_id}";
      if (isset(
$limit)) {
            
$query_one .= " LIMIT {$limit}";
      }
      
$sql mysqli_query($sqlConnect$query_one);
      while (
$fetched_data mysqli_fetch_assoc($sql)) {
            if (
is_array($fetched_data)) {
                  
$data[] = Wo_PageData($fetched_data['page_id']);
            }
      }
      return 
$data;
}
// get users followers
function Wo_GetLikes($user_id 0$type ''$limit ''$after_user_id '') {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data = array();
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      
$user_id       Wo_Secure($user_id);
      
$after_user_id Wo_Secure($after_user_id);
      
$query         " SELECT `page_id` FROM " T_PAGES_LIKES " WHERE `user_id` = {$user_id} AND `active` = '1'";
      if (!empty(
$after_user_id) && is_numeric($after_user_id)) {
            
$query .= " AND `page_id` < {$after_user_id}";
      }
      if (
$type == 'sidebar' && !empty($limit) && is_numeric($limit)) {
            
$query .= " ORDER BY RAND()";
      }
      if (
$type == 'profile' && !empty($limit) && is_numeric($limit)) {
            
$query .= " ORDER BY `page_id` DESC";
      }
      
$query .= " LIMIT {$limit} ";
      
$sql_query mysqli_query($sqlConnect$query);
      while (
$fetched_data mysqli_fetch_assoc($sql_query)) {
            
$data[] = Wo_PageData($fetched_data['page_id']);
      }
      return 
$data;
}
function 
Wo_CountUserLikes($user_id) {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data = array();
      if (empty(
$user_id) or !is_numeric($user_id) or $user_id 1) {
            return 
false;
      }
      
$user_id      Wo_Secure($user_id);
      
$query        mysqli_query($sqlConnect"SELECT COUNT(`page_id`) AS count FROM " T_PAGES_LIKES " WHERE `user_id` = {$user_id} AND `active` = '1' ");
      
$fetched_data mysqli_fetch_assoc($query);
      return 
$fetched_data['count'];
}
// get all users from database
function Wo_GetAllPages($limit ''$after '') {
      
// Global required variables
      
global $wo$sqlConnect;
      
$data      = array();
      
$query_one " SELECT `page_id` FROM " T_PAGES;
      if (!empty(
$after) && is_numeric($after) && $after 0) {
            
$query_one .= " WHERE `page_id` < " Wo_Secure($after);
      }
      
$query_one .= " ORDER BY `page_id` DESC";
      if (isset(
$limit) and !empty($limit)) {
            
$query_one .= " LIMIT {$limit}";
      }
      
$sql mysqli_query($sqlConnect$query_one);
      while (
$fetched_data mysqli_fetch_assoc($sql)) {
            
$page_data          Wo_PageData($fetched_data['page_id']);
            
$page_data['owner'] = Wo_UserData($page_data['user_id']);
            
$data[]             = $page_data;
      }
      return 
$data;
}
?>
Онлайн: 0
Реклама