<?php
<?php
class network
class network
{
{
public $id;
public $id;
public $info;
public $info;
public $is_private;
public $is_private;
public $is_public;
public $is_public;
public function __construct()
public function __construct()
{
{
$this->id = FALSE;
$this->id = FALSE;
$this->C = new stdClass;
$this->C = new stdClass;
$this->info = new stdClass;
$this->info = new stdClass;
$this->cache = & $GLOBALS['cache'];
$this->cache = & $GLOBALS['cache'];
$this->db1 = & $GLOBALS['db1'];
$this->db1 = & $GLOBALS['db1'];
$this->db2 = & $GLOBALS['db2'];
$this->db2 = & $GLOBALS['db2'];
}
}
public function LOAD()
public function LOAD()
{
{
if( $this->id ) {
if( $this->id ) {
return FALSE;
return FALSE;
}
}
$this->load_network_settings();
$this->load_network_settings();
$this->info = (object) array(
$this->info = (object) array(
'id' => 1,
'id' => 1,
);
);
$this->is_private = FALSE;
$this->is_private = FALSE;
$this->is_public = TRUE;
$this->is_public = TRUE;
$this->id = $this->info->id;
$this->id = $this->info->id;
return $this->id;
return $this->id;
}
}
public function get_latest_dogum($force_refresh=FALSE)
public function get_latest_dogum($force_refresh=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
$cachekey = 'n:'.$this->id.',latest_dogum_userz';
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
return $data;
}
$data = array();
$data = array();
$num = 40;
$num = 20;
$tarih = pdate("m-d", time());
$tarih = pdate("m-d", time());
$this->db2->query('SELECT * FROM users where birthdate LIKE "%'.$tarih.'" ORDER BY id DESC LIMIT '.$num);
$this->db2->query('SELECT * FROM users where birthdate LIKE "%'.$tarih.'" ORDER BY id DESC LIMIT '.$num);
while($obj = $this->db2->fetch_object()) {
while($obj = $this->db2->fetch_object()) {
$data[] = intval($obj->id);
$data[] = intval($obj->id);
}
}
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
return $data;
return $data;
}
}
public function load_network_settings()
public function load_network_settings()
{
{
$db = &$this->db1;
$db = &$this->db1;
$r = $db->query('SELECT * FROM settings', FALSE);
$r = $db->query('SELECT * FROM settings', FALSE);
while($obj = $db->fetch_object($r)) {
while($obj = $db->fetch_object($r)) {
$this->C->{$obj->word} = stripslashes($obj->value);
$this->C->{$obj->word} = stripslashes($obj->value);
}
}
global $C;
global $C;
foreach($this->C as $k=>$v) {
foreach($this->C as $k=>$v) {
$C->$k = & $this->C->$k;
$C->$k = & $this->C->$k;
}
}
if( ! isset($C->ATTACH_LINK_DISABLED) ) { $C->ATTACH_LINK_DISABLED = 0; }
if( ! isset($C->ATTACH_LINK_DISABLED) ) { $C->ATTACH_LINK_DISABLED = 0; }
if( ! isset($C->ATTACH_FILE_DISABLED) ) { $C->ATTACH_FILE_DISABLED = 0; }
if( ! isset($C->ATTACH_FILE_DISABLED) ) { $C->ATTACH_FILE_DISABLED = 0; }
if( ! isset($C->ATTACH_IMAGE_DISABLED) ) { $C->ATTACH_IMAGE_DISABLED = 0; }
if( ! isset($C->ATTACH_IMAGE_DISABLED) ) { $C->ATTACH_IMAGE_DISABLED = 0; }
if( ! isset($C->ATTACH_VIDEO_DISABLED) ) { $C->ATTACH_VIDEO_DISABLED = 0; }
if( ! isset($C->ATTACH_VIDEO_DISABLED) ) { $C->ATTACH_VIDEO_DISABLED = 0; }
if( ! isset($C->HDR_SHOW_COMPANY) ) { $C->HDR_SHOW_COMPANY = 1; }
if( ! isset($C->HDR_SHOW_COMPANY) ) { $C->HDR_SHOW_COMPANY = 1; }
if( ! isset($C->HDR_SHOW_LOGO) ) { $C->HDR_SHOW_LOGO = 1; }
if( ! isset($C->HDR_SHOW_LOGO) ) { $C->HDR_SHOW_LOGO = 1; }
if( ! isset($C->HDR_CUSTOM_LOGO) ) { $C->HDR_CUSTOM_LOGO = ''; }
if( ! isset($C->HDR_CUSTOM_LOGO) ) { $C->HDR_CUSTOM_LOGO = ''; }
if( ! isset($C->HDR_SHOW_FAVICON) ) { $C->HDR_SHOW_FAVICON = 1; }
if( ! isset($C->HDR_SHOW_FAVICON) ) { $C->HDR_SHOW_FAVICON = 1; }
if( ! isset($C->HDR_CUSTOM_FAVICON) ) { $C->HDR_CUSTOM_FAVICON = ''; }
if( ! isset($C->HDR_CUSTOM_FAVICON) ) { $C->HDR_CUSTOM_FAVICON = ''; }
if( ! isset($C->MOBI_DISABLED) ) { $C->MOBI_DISABLED = 0; }
if( ! isset($C->MOBI_DISABLED) ) { $C->MOBI_DISABLED = 0; }
$current_language = new stdClass;
$current_language = new stdClass;
include($C->INCPATH.'languages/'.$C->LANGUAGE.'/language.php');
include($C->INCPATH.'languages/'.$C->LANGUAGE.'/language.php');
setlocale(LC_ALL, $current_language->php_locale);
setlocale(LC_ALL, $current_language->php_locale);
if( ! isset($C->DEF_TIMEZONE) ) {
if( ! isset($C->DEF_TIMEZONE) ) {
$C->DEF_TIMEZONE = $current_language->php_timezone;
$C->DEF_TIMEZONE = $current_language->php_timezone;
}
}
date_default_timezone_set($C->DEF_TIMEZONE);
date_default_timezone_set($C->DEF_TIMEZONE);
if( !isset($C->SITE_TITLE) || empty($C->SITE_TITLE) ) {
if( !isset($C->SITE_TITLE) || empty($C->SITE_TITLE) ) {
$C->SITE_TITLE = 'Sharetronix';
$C->SITE_TITLE = 'Sharetronix';
}
}
$C->OUTSIDE_SITE_TITLE = $C->SITE_TITLE;
$C->OUTSIDE_SITE_TITLE = $C->SITE_TITLE;
}
}
public function get_user_by_username($uname, $force_refresh=FALSE, $return_id=FALSE)
public function get_user_by_username($uname, $force_refresh=FALSE, $return_id=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
if( empty($uname) ) {
if( empty($uname) ) {
return FALSE;
return FALSE;
}
}
$cachekey = 'n:'.$this->id.',username:'.strtolower($uname);
$cachekey = 'n:'.$this->id.',username:'.strtolower($uname);
$uid = $this->cache->get($cachekey);
$uid = $this->cache->get($cachekey);
if( FALSE!==$uid && TRUE!=$force_refresh ) {
if( FALSE!==$uid && TRUE!=$force_refresh ) {
return $return_id ? $uid : $this->get_user_by_id($uid);
return $return_id ? $uid : $this->get_user_by_id($uid);
}
}
$uid = FALSE;
$uid = FALSE;
$r = $this->db2->query('SELECT id FROM users WHERE username="'.$this->db2->escape($uname).'" LIMIT 1', FALSE);
$r = $this->db2->query('SELECT id FROM users WHERE username="'.$this->db2->escape($uname).'" AND active=1 LIMIT 1', FALSE);
if( $o = $this->db2->fetch_object($r) ) {
if( $o = $this->db2->fetch_object($r) ) {
$uid = intval($o->id);
$uid = intval($o->id);
$this->cache->set($cachekey, $uid, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $uid, $GLOBALS['C']->CACHE_EXPIRE);
return $return_id ? $uid : $this->get_user_by_id($uid);
return $return_id ? $uid : $this->get_user_by_id($uid);
}
}
$this->cache->del($cachekey);
$this->cache->del($cachekey);
return FALSE;
return FALSE;
}
}
public function get_user_by_email($email, $force_refresh=FALSE, $return_id=FALSE)
public function get_user_by_email($email, $force_refresh=FALSE, $return_id=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
if( ! is_valid_email($email) ) {
if( ! is_valid_email($email) ) {
return FALSE;
return FALSE;
}
}
$cachekey = 'n:'.$this->id.',usermail:'.strtolower($email);
$cachekey = 'n:'.$this->id.',usermail:'.strtolower($email);
$uid = $this->cache->get($cachekey);
$uid = $this->cache->get($cachekey);
if( FALSE!==$uid && TRUE!=$force_refresh ) {
if( FALSE!==$uid && TRUE!=$force_refresh ) {
return $return_id ? $uid : $this->get_user_by_id($uid);
return $return_id ? $uid : $this->get_user_by_id($uid);
}
}
$uid = FALSE;
$uid = FALSE;
$r = $this->db2->query('SELECT id FROM users WHERE email="'.$this->db2->escape($email).'" AND sus_time<"'.time().'" LIMIT 1', FALSE);
$r = $this->db2->query('SELECT id FROM users WHERE email="'.$this->db2->escape($email).'" AND active=1 LIMIT 1', FALSE);
if( $o = $this->db2->fetch_object($r) ) {
if( $o = $this->db2->fetch_object($r) ) {
$uid = intval($o->id);
$uid = intval($o->id);
$this->cache->set($cachekey, $uid, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $uid, $GLOBALS['C']->CACHE_EXPIRE);
return $return_id ? $uid : $this->get_user_by_id($uid);
return $return_id ? $uid : $this->get_user_by_id($uid);
}
}
$this->cache->del($cachekey);
$this->cache->del($cachekey);
return FALSE;
return FALSE;
}
}
public function get_user_by_id($uid, $force_refresh=FALSE)
public function get_user_by_id($uid, $force_refresh=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
$uid = intval($uid);
$uid = intval($uid);
if( 0 == $uid ) {
if( 0 == $uid ) {
return FALSE;
return FALSE;
}
}
static $loaded = array();
static $loaded = array();
$cachekey = 'n:'.$this->id.',userid:'.$uid;
$cachekey = 'n:'.$this->id.',userid:'.$uid;
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
return $loaded[$cachekey];
return $loaded[$cachekey];
}
}
$data = $this->cache->get($cachekey);
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
$loaded[$cachekey] = $data;
$loaded[$cachekey] = $data;
return $data;
return $data;
}
}
$r = $this->db2->query('SELECT * FROM users WHERE id="'.$uid.'" LIMIT 1', FALSE);
$r = $this->db2->query('SELECT * FROM users WHERE id="'.$uid.'" LIMIT 1', FALSE);
if($o = $this->db2->fetch_object($r)) {
if($o = $this->db2->fetch_object($r)) {
$o->active = intval($o->active);
$o->active = intval($o->active);
$o->fullname = stripslashes($o->fullname);
$o->fullname = stripslashes($o->fullname);
$o->about_me = stripslashes($o->about_me);
$o->about_me = stripslashes($o->about_me);
$o->tags = trim(stripslashes($o->tags));
$o->tags = trim(stripslashes($o->tags));
$o->tags = empty($o->tags) ? array() : explode(', ', $o->tags);
$o->tags = empty($o->tags) ? array() : explode(', ', $o->tags);
if( empty($o->avatar) ) {
if( empty($o->avatar) ) {
if($o->gender=='m'){
$o->avatar = $GLOBALS['C']->DEF_AVATAR_USER;
$o->avatar = $GLOBALS['C']->DEF_AVATAR_MUSER;
}elseif($o->gender=='f'){
$o->avatar = $GLOBALS['C']->DEF_AVATAR_FUSER;
}else{
$o->avatar = $GLOBALS['C']->DEF_AVATAR_USER;
}
}
}
$o->age = '';
$o->age = '';
$bd_day = intval( substr($o->birthdate, 8, 2) );
$bd_day = intval( substr($o->birthdate, 8, 2) );
$bd_month = intval( substr($o->birthdate, 5, 2) );
$bd_month = intval( substr($o->birthdate, 5, 2) );
$bd_year = intval( substr($o->birthdate, 0, 4) );
$bd_year = intval( substr($o->birthdate, 0, 4) );
if( $bd_day>0 && $bd_month>0 && $bd_year>0 ) {
if( $bd_day>0 && $bd_month>0 && $bd_year>0 ) {
if( date('Y') > $bd_year ) {
if( date('Y') > $bd_year ) {
$o->age = date('Y') - $bd_year;
$o->age = date('Y') - $bd_year;
if( $bd_month>date('m') || ($bd_month==date('m') && $bd_day>date('d')) ) {
if( $bd_month>date('m') || ($bd_month==date('m') && $bd_day>date('d')) ) {
$o->age --;
$o->age --;
}
}
}
}
}
}
$o->position = stripslashes($o->position);
$o->position = stripslashes($o->position);
$o->location = stripslashes($o->location);
$o->location = stripslashes($o->location);
$o->network_id = $this->id;
$o->network_id = $this->id;
$o->user_details = FALSE;
$o->user_details = FALSE;
$rr = $this->db2->query('SELECT * FROM users_details WHERE user_id="'.$uid.'" LIMIT 1', FALSE);
$rr = $this->db2->query('SELECT * FROM users_details WHERE user_id="'.$uid.'" LIMIT 1', FALSE);
if( $ud = $this->db2->fetch_object($rr) ) {
if( $ud = $this->db2->fetch_object($rr) ) {
$o->user_details = new stdClass;
$o->user_details = new stdClass;
foreach($ud as $k=>$v) {
foreach($ud as $k=>$v) {
$o->user_details->$k = stripslashes($v);
$o->user_details->$k = stripslashes($v);
}
}
}
}
$this->cache->set($cachekey, $o, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $o, $GLOBALS['C']->CACHE_EXPIRE);
$loaded[$cachekey] = $o;
$loaded[$cachekey] = $o;
return $o;
return $o;
}
}
$this->cache->del($cachekey);
$this->cache->del($cachekey);
return FALSE;
return FALSE;
}
}
//////////////////////// User Like ///////////////////////////
//////////////////////// User Like ///////////////////////////
public function get_user_likes($uid, $force_refresh=FALSE, $type = FALSE)
public function get_user_likes($uid, $force_refresh=FALSE, $type = FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
$uid = intval($uid);
$uid = intval($uid);
if( 0 == $uid ) {
if( 0 == $uid ) {
return FALSE;
return FALSE;
}
}
static $loaded = array();
static $loaded = array();
$cachekey = 'n:'.$this->id.',userlikes:'.$uid.($type ? ',type:'.$type : '');
$cachekey = 'n:'.$this->id.',userlikes:'.$uid.($type ? ',type:'.$type : '');
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
return $loaded[$cachekey];
return $loaded[$cachekey];
}
}
$data = $this->cache->get($cachekey);
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
$loaded[$cachekey] = $data;
$loaded[$cachekey] = $data;
return $data;
return $data;
}
}
$data = new stdClass;
$data = new stdClass;
$data->likers = array();
$data->likers = array();
$data->like_users = array();
$data->like_users = array();
if( ($type && $type == 'hislikers') || ($type === FALSE) ){
if( ($type && $type == 'hislikers') || ($type === FALSE) ){
$r = $this->db2->query('SELECT who, whom_from_postid FROM users_liked WHERE whom="'.$uid.'" ORDER BY id DESC', FALSE);
$r = $this->db2->query('SELECT who, whom_from_postid FROM users_liked WHERE whom="'.$uid.'" ORDER BY id DESC', FALSE);
while($o = $this->db2->fetch_object($r)) {
while($o = $this->db2->fetch_object($r)) {
$data->likers[intval($o->who)] = $o->whom_from_postid;
$data->likers[intval($o->who)] = $o->whom_from_postid;
}
}
}
}
if( ($type && $type == 'helikes') || ($type === FALSE) ){
if( ($type && $type == 'helikes') || ($type === FALSE) ){
$r = $this->db2->query('SELECT whom, whom_from_postid FROM users_liked WHERE who="'.$uid.'" ORDER BY id DESC', FALSE);
$r = $this->db2->query('SELECT whom, whom_from_postid FROM users_liked WHERE who="'.$uid.'" ORDER BY id DESC', FALSE);
while($o = $this->db2->fetch_object($r)) {
while($o = $this->db2->fetch_object($r)) {
$data->like_users[intval($o->whom)] = $o->whom_from_postid;
$data->like_users[intval($o->whom)] = $o->whom_from_postid;
}
}
}
}
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$loaded[$cachekey] = $data;
$loaded[$cachekey] = $data;
return $data;
return $data;
}
}
///////////////////////// User Like /////////////////////////////
///////////////////////// User Like /////////////////////////////
public function get_user_follows($uid, $force_refresh=FALSE)
public function get_user_follows($uid, $force_refresh=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
$uid = intval($uid);
$uid = intval($uid);
if( 0 == $uid ) {
if( 0 == $uid ) {
return FALSE;
return FALSE;
}
}
static $loaded = array();
static $loaded = array();
$cachekey = 'n:'.$this->id.',userfollows:'.$uid;
$cachekey = 'n:'.$this->id.',userfollows:'.$uid;
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
return $loaded[$cachekey];
return $loaded[$cachekey];
}
}
$data = $this->cache->get($cachekey);
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
$loaded[$cachekey] = $data;
$loaded[$cachekey] = $data;
return $data;
return $data;
}
}
$data = new stdClass;
$data = new stdClass;
$data->followers = array();
$data->followers = array();
$data->follow_users = array();
$data->follow_users = array();
$data->follow_groups = array();
$data->follow_groups = array();
$r = $this->db2->query('SELECT who, whom_from_postid FROM users_followed WHERE whom="'.$uid.'" ORDER BY id DESC', FALSE);
$r = $this->db2->query('SELECT who, whom_from_postid FROM users_followed WHERE whom="'.$uid.'" ORDER BY id DESC', FALSE);
while($o = $this->db2->fetch_object($r)) {
while($o = $this->db2->fetch_object($r)) {
$data->followers[intval($o->who)] = $o->whom_from_postid;
$data->followers[intval($o->who)] = $o->whom_from_postid;
}
}
$r = $this->db2->query('SELECT whom, whom_from_postid FROM users_followed WHERE who="'.$uid.'" ORDER BY id DESC', FALSE);
$r = $this->db2->query('SELECT whom, whom_from_postid FROM users_followed WHERE who="'.$uid.'" ORDER BY id DESC', FALSE);
while($o = $this->db2->fetch_object($r)) {
while($o = $this->db2->fetch_object($r)) {
$data->follow_users[intval($o->whom)] = $o->whom_from_postid;
$data->follow_users[intval($o->whom)] = $o->whom_from_postid;
}
}
$r = $this->db2->query('SELECT group_id, group_from_postid FROM groups_followed WHERE user_id="'.$uid.'" ORDER BY id DESC', FALSE);
$r = $this->db2->query('SELECT group_id, group_from_postid FROM groups_followed WHERE user_id="'.$uid.'" ORDER BY id DESC', FALSE);
while($o = $this->db2->fetch_object($r)) {
while($o = $this->db2->fetch_object($r)) {
$data->follow_groups[intval($o->group_id)] = $o->group_from_postid;
$data->follow_groups[intval($o->group_id)] = $o->group_from_postid;
}
}
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$loaded[$cachekey] = $data;
$loaded[$cachekey] = $data;
return $data;
return $data;
}
}
public function get_mostactive_users($force_refresh=FALSE)
public function get_mostactive_users($force_refresh=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
$cachekey = 'n:'.$this->id.',mostactive_userz';
$cachekey = 'n:'.$this->id.',mostactive_userz';
$data = $this->cache->get($cachekey);
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
return $data;
return $data;
}
}
$data = array();
$data = array();
$days = 5;
$days = 5;
$num = 20;
$num = 20;
$this->db2->query('SELECT user_id, COUNT(id) AS c FROM posts WHERE user_id<>0 GROUP BY user_id ORDER BY c DESC LIMIT '.$num);
$this->db2->query('SELECT user_id, COUNT(id) AS c FROM posts WHERE user_id<>0 GROUP BY user_id ORDER BY c DESC LIMIT '.$num);
while($obj = $this->db2->fetch_object()) {
while($obj = $this->db2->fetch_object()) {
$data[] = intval($obj->user_id);
$data[] = intval($obj->user_id);
}
}
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
return $data;
return $data;
}
}
public function get_latest_users($force_refresh=FALSE)
public function get_latest_users($force_refresh=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
$cachekey = 'n:'.$this->id.',latest_userz';
$cachekey = 'n:'.$this->id.',latest_userz';
$data = $this->cache->get($cachekey);
$data = $cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
return $data;
return $data;
}
}
$data = array();
$data = array();
$num = 20;
$num = 20;
$this->db2->query('SELECT id FROM users WHERE active=1 OR sus_time<"'.time().'" ORDER BY id DESC LIMIT '.$num);
$this->db2->query('SELECT id FROM users WHERE active=1 ORDER BY id DESC LIMIT '.$num);
while($obj = $this->db2->fetch_object()) {
while($obj = $this->db2->fetch_object()) {
$data[] = intval($obj->id);
$data[] = intval($obj->id);
}
}
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
return $data;
return $data;
}
}
public function get_online_users($force_refresh=FALSE)
public function get_online_users($force_refresh=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
$cachekey = 'n:'.$this->id.',online_userz';
$cachekey = 'n:'.$this->id.',online_userz';
$data = $this->cache->get($cachekey);
$data = $cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
return $data;
return $data;
}
}
$data = array();
$data = array();
$num = 30;
$num = 20;
$time = 15*60;
$this->db2->query('SELECT id, lastclick_date FROM users WHERE active=1 ORDER BY lastclick_date DESC LIMIT '.$num);
$this->db2->query('SELECT id, lastclick_date FROM users WHERE active=1 ORDER BY lastclick_date DESC LIMIT '.($num+1));
while($obj = $this->db2->fetch_object()) {
while($obj = $this->db2->fetch_object()) {
if( $obj->lastclick_date < time() - $time ) {
if( $obj->lastclick_date < time()-30*60 ) {
break;
break;
}
}
$data[] = $this->get_user_by_id($obj->id);
$data[] = intval($obj->id);
}
}
$data = array_slice($data, 0, $num);
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set( $cachekey, $data, 10*60 );
return $data;
return $data;
}
}
public function get_group_by_name($gname, $force_refresh=FALSE, $return_id=FALSE)
public function get_group_by_name($gname, $force_refresh=FALSE, $return_id=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
if( empty($gname) ) {
if( empty($gname) ) {
return FALSE;
return FALSE;
}
}
$cachekey = 'n:'.$this->id.',groupname:'.strtolower($gname);
$cachekey = 'n:'.$this->id.',groupname:'.strtolower($gname);
$gid = $this->cache->get($cachekey);
$gid = $this->cache->get($cachekey);
if( FALSE!==$gid && TRUE!=$gid ) {
if( FALSE!==$gid && TRUE!=$gid ) {
return $return_id ? $gid : $this->get_group_by_id($gid);
return $return_id ? $gid : $this->get_group_by_id($gid);
}
}
$gid = FALSE;
$gid = FALSE;
$r = $this->db2->query('SELECT id FROM groups WHERE groupname="'.$this->db2->escape($gname).'" OR title="'.$this->db2->escape($gname).'" LIMIT 1', FALSE);
$r = $this->db2->query('SELECT id FROM groups WHERE groupname="'.$this->db2->escape($gname).'" OR title="'.$this->db2->escape($gname).'" LIMIT 1', FALSE);
if( $o = $this->db2->fetch_object($r) ) {
if( $o = $this->db2->fetch_object($r) ) {
$gid = intval($o->id);
$gid = intval($o->id);
$this->cache->set($cachekey, $gid, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $gid, $GLOBALS['C']->CACHE_EXPIRE);
return $return_id ? $gid : $this->get_group_by_id($gid);
return $return_id ? $gid : $this->get_group_by_id($gid);
}
}
$this->cache->del($cachekey);
$this->cache->del($cachekey);
return FALSE;
return FALSE;
}
}
public function get_group_by_id($gid, $force_refresh=FALSE)
public function get_group_by_id($gid, $force_refresh=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
$gid = intval($gid);
$gid = intval($gid);
if( 0 == $gid ) {
if( 0 == $gid ) {
return FALSE;
return FALSE;
}
}
static $loaded = array();
static $loaded = array();
$cachekey = 'n:'.$this->id.',groupid:'.$gid;
$cachekey = 'n:'.$this->id.',groupid:'.$gid;
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
return $loaded[$cachekey];
return $loaded[$cachekey];
}
}
$data = $this->cache->get($cachekey);
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
$loaded[$cachekey] = $data;
$loaded[$cachekey] = $data;
return $data;
return $data;
}
}
$r = $this->db2->query('SELECT * FROM groups WHERE id="'.$gid.'" LIMIT 1', FALSE);
$r = $this->db2->query('SELECT * FROM groups WHERE id="'.$gid.'" LIMIT 1', FALSE);
if($o = $this->db2->fetch_object($r)) {
if($o = $this->db2->fetch_object($r)) {
$o->title = stripslashes($o->title);
$o->title = stripslashes($o->title);
$o->is_public = $o->is_public==1;
$o->is_public = $o->is_public==1;
$o->is_private = !$o->is_public;
$o->is_private = !$o->is_public;
$o->is_deleted = FALSE;
$o->is_deleted = FALSE;
$o->about_me = stripslashes($o->about_me);
$o->about_me = stripslashes($o->about_me);
if( empty($o->avatar) ) {
if( empty($o->avatar) ) {
$o->avatar = $GLOBALS['C']->DEF_AVATAR_GROUP;
$o->avatar = $GLOBALS['C']->DEF_AVATAR_GROUP;
}
}
$this->cache->set($cachekey, $o, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $o, $GLOBALS['C']->CACHE_EXPIRE);
$loaded[$cachekey] = $o;
$loaded[$cachekey] = $o;
return $o;
return $o;
}
}
$this->cache->del($cachekey);
$this->cache->del($cachekey);
return FALSE;
return FALSE;
}
}
public function get_deleted_group_by_id($gid, $force_refresh=FALSE)
public function get_deleted_group_by_id($gid, $force_refresh=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
$gid = intval($gid);
$gid = intval($gid);
if( 0 == $gid ) {
if( 0 == $gid ) {
return FALSE;
return FALSE;
}
}
static $loaded = array();
static $loaded = array();
$cachekey = 'n:'.$this->id.',deletedgroupid:'.$gid;
$cachekey = 'n:'.$this->id.',deletedgroupid:'.$gid;
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
return $loaded[$cachekey];
return $loaded[$cachekey];
}
}
$data = $this->cache->get($cachekey);
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
$loaded[$cachekey] = $data;
$loaded[$cachekey] = $data;
return $data;
return $data;
}
}
$r = $this->db2->query('SELECT * FROM groups_deleted WHERE id="'.$gid.'" LIMIT 1', FALSE);
$r = $this->db2->query('SELECT * FROM groups_deleted WHERE id="'.$gid.'" LIMIT 1', FALSE);
if($o = $this->db2->fetch_object($r)) {
if($o = $this->db2->fetch_object($r)) {
$o->title = stripslashes($o->title);
$o->title = stripslashes($o->title);
$o->is_public = $o->is_public==1;
$o->is_public = $o->is_public==1;
$o->is_private = !$o->is_public;
$o->is_private = !$o->is_public;
$o->is_deleted = TRUE;
$o->is_deleted = TRUE;
$this->cache->set($cachekey, $o, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $o, $GLOBALS['C']->CACHE_EXPIRE);
$loaded[$cachekey] = $o;
$loaded[$cachekey] = $o;
return $o;
return $o;
}
}
$this->cache->del($cachekey);
$this->cache->del($cachekey);
return FALSE;
return FALSE;
}
}
public function get_group_invited_members($gid, $force_refresh=FALSE)
public function get_group_invited_members($gid, $force_refresh=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
if( ! $g = $this->get_group_by_id($gid, $force_refresh) ) {
if( ! $g = $this->get_group_by_id($gid, $force_refresh) ) {
return FALSE;
return FALSE;
}
}
static $loaded = array();
static $loaded = array();
$cachekey = 'n:'.$this->id.',group_invited_members:'.$gid;
$cachekey = 'n:'.$this->id.',group_invited_members:'.$gid;
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
return $loaded[$cachekey];
return $loaded[$cachekey];
}
}
$data = $this->cache->get($cachekey);
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
$loaded[$cachekey] = $data;
$loaded[$cachekey] = $data;
return $data;
return $data;
}
}
$data = array();
$data = array();
$r = $this->db2->query('SELECT user_id FROM groups_private_members WHERE group_id="'.$g->id.'" ORDER BY id ASC', FALSE);
$r = $this->db2->query('SELECT user_id FROM groups_private_members WHERE group_id="'.$g->id.'" ORDER BY id ASC', FALSE);
while($obj = $this->db2->fetch_object($r)) {
while($obj = $this->db2->fetch_object($r)) {
$data[] = intval($obj->user_id);
$data[] = intval($obj->user_id);
}
}
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$loaded[$cachekey] = $data;
$loaded[$cachekey] = $data;
return $data;
return $data;
}
}
public function get_group_members($gid, $force_refresh=FALSE)
public function get_group_members($gid, $force_refresh=FALSE)
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return FALSE;
return FALSE;
}
}
if( ! $g = $this->get_group_by_id($gid, $force_refresh) ) {
if( ! $g = $this->get_group_by_id($gid, $force_refresh) ) {
return FALSE;
return FALSE;
}
}
$cachekey = 'n:'.$this->id.',group_members:'.$gid;
$cachekey = 'n:'.$this->id.',group_members:'.$gid;
$data = $this->cache->get($cachekey);
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
return $data;
return $data;
}
}
$data = array();
$data = array();
if($g->is_public == 0) {
if($g->is_public == 0) {
$u_in = $this->get_group_invited_members($gid, $force_refresh);
$u_in = $this->get_group_invited_members($gid, $force_refresh);
$r = $this->db2->query('SELECT id FROM users WHERE (active=1 OR sus_time<"'.time().'") AND is_network_admin=1', FALSE);
$r = $this->db2->query('SELECT id FROM users WHERE active=1 AND is_network_admin=1', FALSE);
while($sdf = $this->db2->fetch_object($r)) {
while($sdf = $this->db2->fetch_object($r)) {
$u_in[] = intval($sdf->id);
$u_in[] = intval($sdf->id);
}
}
$u_in = array_unique($u_in);
$u_in = array_unique($u_in);
$u_in = count($u_in)==0 ? '-1' : implode(', ', $u_in);
$u_in = count($u_in)==0 ? '-1' : implode(', ', $u_in);
$r = $this->db2->query('SELECT user_id, group_from_postid FROM groups_followed WHERE group_id="'.$g->id.'" AND user_id IN('.$u_in.') ORDER BY id ASC', FALSE);
$r = $this->db2->query('SELECT user_id, group_from_postid FROM groups_followed WHERE group_id="'.$g->id.'" AND user_id IN('.$u_in.') ORDER BY id ASC', FALSE);
}
}
else {
else {
$r = $this->db2->query('SELECT user_id, group_from_postid FROM groups_followed WHERE group_id="'.$g->id.'" ORDER BY id ASC', FALSE);
$r = $this->db2->query('SELECT user_id, group_from_postid FROM groups_followed WHERE group_id="'.$g->id.'" ORDER BY id ASC', FALSE);
}
}
while($o = $this->db2->fetch_object($r)) {
while($o = $this->db2->fetch_object($r)) {
$data[intval($o->user_id)] = intval($o->group_from_postid);
$data[intval($o->user_id)] = intval($o->group_from_postid);
}
}
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
return $data;
return $data;
}
}
public function get_last_post_id()
public function get_last_post_id()
{
{
if( ! $this->id ) {
if( ! $this->id ) {
return 0;
return 0;
}
}
return intval($this->db2->fetch_field('SELECT MAX(id) FROM posts'));
return intval($this->db2->fetch_field('SELECT MAX(id) FROM posts'));
}
}
public function get_recent_posttags($in_sql, $count=20, $force_refresh=FALSE)
public function get_recent_posttags($in_sql, $count=20, $force_refresh=FALSE)
{
{
$cachekey = 'n:'.$this->id.',active_tags:'.md5($in_sql);
$cachekey = 'n:'.$this->id.',active_tags:'.md5($in_sql);
$data = $this->cache->get($cachekey);
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
return array_slice($data, 0, $count);
return array_slice($data, 0, $count);
}
}
// this is to avoid running the query below multiple times at once
// this is to avoid running the query below multiple times at once
$inprogressflag = 'n:'.$this->id.',active_tags_loading';
$inprogressflag = 'n:'.$this->id.',active_tags_loading';
if( $this->cache->get($inprogressflag) == 12345 ) { return array(); }
if( $this->cache->get($inprogressflag) == 12345 ) { return array(); }
$this->cache->set($inprogressflag, 12345, 5*60);
$this->cache->set($inprogressflag, 12345, 5*60);
//
//
$data = array();
$data = array();
$this->db2->query('SELECT message, date FROM posts WHERE api_id<>2 AND api_id<>6 AND posttags<>0 '.$in_sql.' ORDER BY id DESC LIMIT 1000');
$this->db2->query('SELECT message, date FROM posts WHERE api_id<>2 AND api_id<>6 AND posttags<>0 '.$in_sql.' ORDER BY id DESC LIMIT 1000');
while($tmp = $this->db2->fetch_object()) {
while($tmp = $this->db2->fetch_object()) {
if( ! preg_match_all('/\#([א-תÀ-ÿ一-龥а-яa-z0-9\-_]{1,50})/iu', stripslashes($tmp->message), $matches, PREG_PATTERN_ORDER) ) {
if( ! preg_match_all('/\#([א-תا-یÀ-ÿ一-龥а-яآ-یa-z0-9\-_]{1,50})/iu', stripslashes($tmp->message), $matches, PREG_PATTERN_ORDER) ) {
continue;
continue;
}
}
$thisposttags = array();
$thisposttags = array();
foreach($matches[1] as $tg) {
foreach($matches[1] as $tg) {
$thisposttags[] = mb_strtolower(trim($tg));
$thisposttags[] = mb_strtolower(trim($tg));
}
}
$thisposttags = array_unique($thisposttags);
$thisposttags = array_unique($thisposttags);
$weight = 1;
$weight = 1;
if( $tmp->date > time()-24*3600 ) {
if( $tmp->date > time()-24*3600 ) {
$weight = 100;
$weight = 100;
}
}
elseif( $tmp->date > time()-7*24*3600 ) {
elseif( $tmp->date > time()-7*24*3600 ) {
$weigth = 20;
$weigth = 20;
}
}
elseif( $tmp->date > time()-30*24*3600 ) {
elseif( $tmp->date > time()-30*24*3600 ) {
$weight = 5;
$weight = 5;
}
}
foreach($thisposttags as $tg) {
foreach($thisposttags as $tg) {
if( ! isset($data[$tg]) ) {
if( ! isset($data[$tg]) ) {
$data[$tg] = 0;
$data[$tg] = 0;
}
}
$data[$tg] += $weight;
$data[$tg] += $weight;
}
}
}
}
arsort($data);
arsort($data);
$data = array_keys($data);
$data = array_keys($data);
$data = array_slice($data, 0, 50);
$data = array_slice($data, 0, 50);
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->del($inprogressflag);
$this->cache->del($inprogressflag);
return array_slice($data, 0, $count);
return array_slice($data, 0, $count);
}
}
public function get_user_notif_rules($user_id, $force_refresh=FALSE)
public function get_user_notif_rules($user_id, $force_refresh=FALSE)
{
{
$cachekey = 'n:'.$this->id.',usr_ntf_rulz:'.$user_id;
$cachekey = 'n:'.$this->id.',usr_ntf_rulz:'.$user_id;
$data = $this->cache->get($cachekey);
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
return $data;
return $data;
}
}
$this->db2->query('SELECT * FROM users_notif_rules WHERE user_id="'.$user_id.'" LIMIT 1');
$this->db2->query('SELECT * FROM users_notif_rules WHERE user_id="'.$user_id.'" LIMIT 1');
if( ! $obj = $this->db2->fetch_object() ) {
if( ! $obj = $this->db2->fetch_object() ) {
require_once( $GLOBALS['C']->INCPATH.'helpers/func_signup.php' );
require_once( $GLOBALS['C']->INCPATH.'helpers/func_signup.php' );
set_user_default_notification_rules($user_id);
set_user_default_notification_rules($user_id);
}
}
$this->db2->query('SELECT * FROM users_notif_rules WHERE user_id="'.$user_id.'" LIMIT 1');
$this->db2->query('SELECT * FROM users_notif_rules WHERE user_id="'.$user_id.'" LIMIT 1');
if( ! $obj = $this->db2->fetch_object() ) {
if( ! $obj = $this->db2->fetch_object() ) {
return FALSE;
return FALSE;
}
}
unset($obj->user_id);
unset($obj->user_id);
$this->cache->set($cachekey, $obj, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $obj, $GLOBALS['C']->CACHE_EXPIRE);
return $obj;
return $obj;
}
}
public function get_posts_api($id, $force_refresh=FALSE)
public function get_posts_api($id, $force_refresh=FALSE)
{
{
$id = intval($id);
$id = intval($id);
static $loaded = array();
static $loaded = array();
$cachekey = 'n:'.$this->id.',post_app:'.$id;
$cachekey = 'n:'.$this->id.',post_app:'.$id;
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
if( isset($loaded[$cachekey]) && TRUE!=$force_refresh ) {
return $loaded[$cachekey];
return $loaded[$cachekey];
}
}
$data = $this->cache->get($cachekey);
$data = $this->cache->get($cachekey);
if( FALSE!==$data && TRUE!=$force_refresh ) {
if( FALSE!==$data && TRUE!=$force_refresh ) {
$loaded[$cachekey] = $data;
$loaded[$cachekey] = $data;
return $data;
return $data;
}
}
$r = $this->db2->query('SELECT id, name FROM applications WHERE id="'.$id.'" LIMIT 1', FALSE);
$r = $this->db2->query('SELECT id, name FROM applications WHERE id="'.$id.'" LIMIT 1', FALSE);
if( $data = $this->db2->fetch_object($r) ) {
if( $data = $this->db2->fetch_object($r) ) {
$data->name = stripslashes($data->name);
$data->name = stripslashes($data->name);
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$this->cache->set($cachekey, $data, $GLOBALS['C']->CACHE_EXPIRE);
$loaded[$cachekey] = $data;
$loaded[$cachekey] = $data;
return $data;
return $data;
}
}
return FALSE;
return FALSE;
}
}
public function send_notification_post($to_user_id, $in_group_id, $lang_key, $lang_params, $if_exists_action='ignore')
public function send_notification_post($to_user_id, $in_group_id, $lang_key, $lang_params, $if_exists_action='ignore')
{
{
// $if_exists_action: 'ignore' or 'replace' or 'quit' - please use 'ignore', otherwise it could cause heavy performance leaks
// $if_exists_action: 'ignore' or 'replace' or 'quit' - please use 'ignore', otherwise it could cause heavy performance leaks
$if_exists_action='ignore';
global $C;
global $C;
$to_user_id = intval($to_user_id);
$to_user_id = intval($to_user_id);
$in_group_id = intval($in_group_id);
$in_group_id = intval($in_group_id);
if( $C->API_ID == 1 ) {
if( $C->API_ID == 1 ) {
if( preg_match('/^(http(s)?\:\/\/)m\.(.*)$/iu', $C->SITE_URL, $m) ) {
if( preg_match('/^(http(s)?\:\/\/)m\.(.*)$/iu', $C->SITE_URL, $m) ) {
$siteurl = $m[1].$m[3];
$siteurl = $m[1].$m[3];
foreach($lang_params as &$p) {
foreach($lang_params as &$p) {
$p = str_replace($C->SITE_URL, $siteurl, $p);
$p = str_replace($C->SITE_URL, $siteurl, $p);
}
}
}
}
elseif( preg_match('/\/m(\/|$)/iu', $C->SITE_URL, $m) ) {
elseif( preg_match('/\/m(\/|$)/iu', $C->SITE_URL, $m) ) {
$siteurl = preg_replace('/\/m(\/|$)/', '', $C->SITE_URL);
$siteurl = preg_replace('/\/m(\/|$)/', '', $C->SITE_URL);
$siteurl = rtrim($siteurl,'/').'/';
$siteurl = rtrim($siteurl,'/').'/';
foreach($lang_params as &$p) {
foreach($lang_params as &$p) {
$p = str_replace($C->SITE_URL, $siteurl, $p);
$p = str_replace($C->SITE_URL, $siteurl, $p);
}
}
}
}
}
}
$data = (object) array (
$data = (object) array (
'type' => 'notif',
'type' => 'notif',
'to_user_id' => $to_user_id,
'to_user_id' => $to_user_id,
'in_group_id' => $in_group_id,
'in_group_id' => $in_group_id,
'lang_key' => $lang_key,
'lang_key' => $lang_key,
'lang_params' => $lang_params,
'lang_params' => $lang_params,
'from_user_id' => $GLOBALS['user']->id,
'from_user_id' => $GLOBALS['user']->id,
);
);
$data = $this->db2->e(serialize($data));
$data = $this->db2->e(serialize($data));
if( $to_user_id > 0 ) {
if( $to_user_id > 0 ) {
if( $if_exists_action != 'ignore' ) {
if( $if_exists_action != 'ignore' ) {
$r = $this->db2->query('SELECT id FROM posts WHERE user_id="0" AND group_id="0" AND message="'.$data.'" LIMIT 1', FALSE);
$r = $this->db2->query('SELECT id FROM posts WHERE user_id="0" AND group_id="0" AND message="'.$data.'" LIMIT 1', FALSE);
if($obj = $this->db2->fetch_object($r)) {
if($obj = $this->db2->fetch_object($r)) {
if( $if_exists_action == 'quit' ) {
if( $if_exists_action == 'quit' ) {
return;
return;
}
}
if( $if_exists_action == 'replace' ) {
if( $if_exists_action == 'replace' ) {
$this->db2->query('DELETE FROM posts WHERE id="'.$obj->id.'" LIMIT 1', FALSE);
$this->db2->query('DELETE FROM posts WHERE id="'.$obj->id.'" LIMIT 1', FALSE);
$this->db2->query('DELETE FROM post_userbox WHERE post_id="'.$obj->id.'" ', FALSE);
$this->db2->query('DELETE FROM post_userbox WHERE post_id="'.$obj->id.'" ', FALSE);
}
}
}
}
}
}
$this->db2->query('INSERT INTO posts SET user_id="0", message="'.$data.'", date="'.time().'", ip_addr="'.ip2long($_SERVER['REMOTE_ADDR']).'" ', FALSE);
$this->db2->query('INSERT INTO posts SET user_id="0", message="'.$data.'", date="'.time().'", ip_addr="'.ip2long($_SERVER['REMOTE_ADDR']).'" ', FALSE);
// $this->db2->query('INSERT DELAYED INTO post_userbox SET user_id="'.$to_user_id.'", post_id="'.intval($this->db2->insert_id()).'" ');
$this->db2->query('INSERT DELAYED INTO post_userbox SET user_id="'.$to_user_id.'", post_id="'.intval($this->db2->insert_id()).'" ');
$this->set_dashboard_tabstate($to_user_id, 'system', 1);
}
}
elseif( $in_group_id > 0 ) {
elseif( $in_group_id > 0 ) {
if( $if_exists_action != 'ignore' ) {
if( $if_exists_action != 'ignore' ) {
$r = $this->db2->query('SELECT id FROM posts WHERE user_id="0" AND group_id="'.$in_group_id.'" AND message="'.$data.'" LIMIT 1', FALSE);
$r = $this->db2->query('SELECT id FROM posts WHERE user_id="0" AND group_id="'.$in_group_id.'" AND message="'.$data.'" LIMIT 1', FALSE);
if($obj = $this->db2->fetch_object($r)) {
if($obj = $this->db2->fetch_object($r)) {
if( $if_exists_action == 'quit' ) {
if( $if_exists_action == 'quit' ) {
return;
return;
}
}
if( $if_exists_action == 'replace' ) {
if( $if_exists_action == 'replace' ) {
$this->db2->query('DELETE FROM posts WHERE id="'.$obj->id.'" LIMIT 1', FALSE);
$this->db2->query('DELETE FROM posts WHERE id="'.$obj->id.'" LIMIT 1', FALSE);
}
}
}
}
}
}
$this->db2->query('INSERT DELAYED INTO posts SET group_id="'.$in_group_id.'", message="'.$data.'", date="'.time().'", ip_addr="'.ip2long($_SERVER['REMOTE_ADDR']).'" ', FALSE);
$this->db2->query('INSERT DELAYED INTO posts SET group_id="'.$in_group_id.'", message="'.$data.'", date="'.time().'", ip_addr="'.ip2long($_SERVER['REMOTE_ADDR']).'" ', FALSE);
}
}
}
}
public function send_notification_email($to_user_id, $notif_type, $subject, $message_txt, $message_html, $inD=FALSE)
public function send_notification_email($to_user_id, $notif_type, $subject, $message_txt, $message_html, $inD=FALSE)
{
{
global $C, $D, $page;
global $C, $D, $page;
if( $inD ) {
if( $inD ) {
foreach($inD as $k=>$v) {
foreach($inD as $k=>$v) {
$D->$k = $v;
$D->$k = $v;
}
}
}
}
$to_user = $this->get_user_by_id($to_user_id);
$to_user = $this->get_user_by_id($to_user_id);
if( !$to_user || empty($subject) || empty($message_txt) || empty($message_html) ) {
if( !$to_user || empty($subject) || empty($message_txt) || empty($message_html) ) {
return;
return;
}
}
$D->page = & $page;
$D->page = & $page;
$D->user = $to_user;
$D->user = $to_user;
$D->subject = $subject;
$D->subject = $subject;
$D->message_txt = $message_txt;
$D->message_txt = $message_txt;
$D->message_html = $message_html;
$D->message_html = $message_html;
$msgtxt = $page->load_template('email/notifications_txt.php', FALSE);
$msgtxt = $page->load_template('email/notifications_txt.php', FALSE);
$msghtml = $page->load_template('email/notifications_html.php', FALSE);
$msghtml = $page->load_template('email/notifications_html.php', FALSE);
if( empty($msgtxt) || empty($msghtml) ) {
if( empty($msgtxt) || empty($msghtml) ) {
return;
return;
}
}
if( $C->SITE_URL != $C->DEF_SITE_URL ) {
if( $C->SITE_URL != $C->DEF_SITE_URL ) {
$msgtxt = str_replace($C->SITE_URL, $C->DEF_SITE_URL, $msgtxt);
$msgtxt = str_replace($C->SITE_URL, $C->DEF_SITE_URL, $msgtxt);
$msghtml = str_replace($C->SITE_URL, $C->DEF_SITE_URL, $msghtml);
$msghtml = str_replace($C->SITE_URL, $C->DEF_SITE_URL, $msghtml);
}
}
if( preg_match('/^(http(s)?\:\/\/)m\.(.*)$/iu', $C->DEF_SITE_URL, $m) ) {
if( preg_match('/^(http(s)?\:\/\/)m\.(.*)$/iu', $C->DEF_SITE_URL, $m) ) {
$siteurl = $m[1].$m[3];
$siteurl = $m[1].$m[3];
$msgtxt = str_replace($C->DEF_SITE_URL, $siteurl, $msgtxt);
$msgtxt = str_replace($C->DEF_SITE_URL, $siteurl, $msgtxt);
$msghtml = str_replace($C->DEF_SITE_URL, $siteurl, $msghtml);
$msghtml = str_replace($C->DEF_SITE_URL, $siteurl, $msghtml);
}
}
do_send_mail_html($to_user->email, $subject, $msgtxt, $msghtml);
do_send_mail_html($to_user->email, $subject, $msgtxt, $msghtml);
}
}
public function get_dashboard_tabstate($user_id, $tabs)
public function get_dashboard_tabstate($user_id, $tabs)
{
{
$user_id = intval($user_id);
$user_id = intval($user_id);
if( is_array($tabs) ) {
if( is_array($tabs) ) {
$result = array();
$result = array();
$tmp = array();
$tmp = array();
foreach($tabs as $tab) {
foreach($tabs as $tab) {
$result[$tab] = 0;
$result[$tab] = 0;
$tmp[] = '"'.$this->db2->e($tab).'"';
$tmp[] = '"'.$this->db2->e($tab).'"';
}
}
$tmp = implode(', ', $tmp);
$tmp = implode(', ', $tmp);
$r = $this->db2->query('SELECT tab, state, newposts FROM users_dashboard_tabs WHERE user_id="'.$user_id.'" AND tab IN('.$tmp.') LIMIT '.count($tabs),
$r = $this->db2->query('SELECT tab, state, newposts FROM users_dashboard_tabs WHERE user_id="'.$user_id.'" AND tab IN('.$tmp.') LIMIT '.count($tabs), FALSE);
while( $obj = $this->db2->fetch_object($r) ) {
$result[$obj->tab] = $obj->state==0 ? 0 : intval($obj->newposts);
if( $result[$obj->tab] > 99 ) {
$result[$obj->tab] = '99+';
}
}
return $result;
}
else {
$r = $this->db2->query('SELECT tab, state, newposts FROM users_dashboard_tabs WHERE user_id="'.$user_id.'" AND tab="'.$this->db2->e($tabs).'" LIMIT 1', FALSE);
if( ! $obj = $this->db2->fetch_object($r) ) {
return 0;
}