public static function initSessionCookie($cookie) { $db = JO_Db::getDefaultAdapter(); $query = $db->select()->from('users', array('*', 'fullname' => "CONCAT(firstname,' ',lastname)"))->where("MD5(CONCAT(user_id,'" . JO_Request::getInstance()->getDomain() . "',date_added)) = ?", (string) $cookie)->limit(1); $user_data = $db->fetchRow($query); if ($user_data && $user_data['status']) { $groups = unserialize($user_data['groups']); if (is_array($groups) && count($groups) > 0) { $query_group = $db->select()->from('user_groups')->where("ug_id IN (?)", new JO_Db_Expr(implode(',', array_keys($groups)))); $fetch_all = $db->fetchAll($query_group); $user_data['access'] = array(); if ($fetch_all) { foreach ($fetch_all as $row) { $modules = unserialize($row['rights']); if (is_array($modules)) { foreach ($modules as $module => $ison) { foreach ($ison as $m => $on) { $user_data['access'][$module][$m] = $m; } } } } } } $db->update('users', array('last_action_datetime' => new JO_Db_Expr('NOW()'), 'ip_address' => JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp())), array('user_id = ?' => (string) $user_data['user_id'])); } // foreach($user_data AS $key => $data) { // self::{$key} = $data; // } JO_Session::set(array('user' => $user_data)); return $user_data; }
public static function updateViewed($board_id) { $db = JO_Db::getDefaultAdapter(); if (!self::isViewedBoard($board_id)) { $db->update('boards', array('views' => new JO_Db_Expr('views+1')), array('board_id = ?' => (string) $board_id)); $db->insert('boards_views', array('user_id' => (string) JO_Session::get('user[user_id]'), 'date_added' => new JO_Db_Expr('NOW()'), 'board_id' => (string) $board_id, 'user_ip' => JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp()))); } $db->update('boards', array('total_views' => new JO_Db_Expr('total_views+1')), array('board_id = ?' => (string) $board_id)); }
public static function getTotalWords($data = array()) { $db = JO_Db::getDefaultAdapter(); $query = $db->select()->from('users_ip_allow_admin', 'COUNT(id)')->limit(1); ////////////filter if (isset($data['filter_id']) && $data['filter_id']) { $query->where('id = ?', (int) $data['filter_id']); } if (isset($data['filete_ip']) && $data['filete_ip']) { $query->where('ip_address LIKE ?', JO_Request_Server::encode_ip(trim($data['filete_ip']))); } return $db->fetchOne($query); }
public static function eventIsReported($event_id) { $db = JO_Db::getDefaultAdapter(); $query = $db->select()->from('events_reports', 'COUNT(pr_id)')->where('event_id = ?', (string) $event_id)->where('checked = 0')->limit(1); if ((string) JO_Session::get('user[user_id]')) { $query->where("user_id = '" . (string) JO_Session::get('user[user_id]') . "' OR user_ip = '" . JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp()) . "'"); } else { $query->where("user_ip = ?", JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp())); } return $db->fetchOne($query); }
public function __construct($data) { $db = JO_Db::getDefaultAdapter(); try { $db->beginTransaction(); $date_added = WM_Date::format(time(), 'yy-mm-dd H:i:s'); $data['date_added'] = $date_added; $data['last_login'] = $date_added; $data['status'] = 1; $data['last_action_datetime'] = $date_added; $data['ip_address'] = JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp()); $data['new_email'] = $data['email']; $data['store'] = JO_Registry::get('default_upload_method'); if (!$data['store']) { $data['store'] = 'Model_Upload_Locale'; } /*$avatar = ''; if(isset($data['avatar']) && $data['avatar']) { $avatar = $data['avatar']; $data['avatar'] = ''; }*/ $rows = Helper_Db::describeTable('users'); $insert = array(); $avatar = ''; foreach ($rows as $row => $def) { if (isset($data[$row])) { if (in_array($row, array('password', 'new_password'))) { if ($data[$row]) { if ($data[$row] instanceof JO_Db_Expr) { $insert[$row] = $data[$row]; } else { $insert[$row] = md5($data[$row]); } } else { $insert[$row] = ''; } } elseif ($row == 'avatar') { $avatar = $data[$row]; $data[$row] = ''; } else { $insert[$row] = $data[$row]; } } else { $insert[$row] = $def; } } //create user $user_id = Helper_Db::create('users', $insert); if (!$user_id) { return $this; } //upload avatar if ($avatar) { $method_for_upload = Helper_Config::get('file_upload_method'); if ($method_for_upload) { $image = call_user_func(array($method_for_upload, 'uploadUserAvatar'), $avatar, $user_id); $error = call_user_func(array($method_for_upload, 'getError')); if ($error) { $this->error[] = $error; } if ($image && isset($image['image']) && $image['image']) { Helper_Db::update('users', array('avatar' => $image['image'], 'store' => $image['store'], 'height' => $image['height'], 'width' => $image['width']), array('user_id = ?' => (string) $user_id)); } } } //create user alias new Model_Users_Autoseo($user_id); /*Helper_Db::insert('url_alias', array( 'query' => 'user_id=' . (string)$user_id, 'keyword' => $data['username'], 'path' => $data['username'], 'route' => 'users/profile' ));*/ //add default boards if (is_array(Helper_Config::get('default_boards'))) { foreach (Helper_Config::get('default_boards') as $def) { new Model_Boards_Create(array('category_id' => $def['category_id'], 'title' => $def['title'], 'user_id' => (string) $user_id)); } } //set following $config_private_boards = Helper_Config::get('config_private_boards'); if (isset($data['following_user']) && $data['following_user'] && $data['following_user'] != -1) { Helper_Db::insert('users_following_user', array('user_id' => (string) $user_id, 'following_id' => (string) $data['following_user'])); Helper_Db::insert('users_following_user', array('user_id' => (string) $data['following_user'], 'following_id' => (string) $user_id)); //update following user info Helper_Db::update('users', array('pins' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'boards' => new JO_Db_Expr('(SELECT COUNT(DISTINCT board_id) FROM boards WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'likes' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins_likes WHERE user_id = users.user_id)'), 'following' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT following_id) FROM users_following_user WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) )'), 'followers' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) )')), array('user_id = ?' => (string) $data['following_user'])); } //update user info Helper_Db::update('users', array('pins' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'boards' => new JO_Db_Expr('(SELECT COUNT(DISTINCT board_id) FROM boards WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'likes' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins_likes WHERE user_id = users.user_id)'), 'following' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT following_id) FROM users_following_user WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT following_id) FROM users_following WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) )'), 'followers' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) )')), array('user_id = ?' => (string) $user_id)); $this->user_id = $user_id; $db->commit(); } catch (JO_Exception $e) { $this->error[] = $e->getMessage(); $db->rollBack(); } }
public static function create($data) { $db = JO_Db::getDefaultAdapter(); $rows = self::describeTable('users'); $date_added = WM_Date::format(time(), 'yy-mm-dd H:i:s'); $data['date_added'] = $date_added; $data['status'] = 1; $data['last_action_datetime'] = $date_added; $data['ip_address'] = JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp()); $insert = array(); $avatar = ''; foreach ($rows as $row) { if (array_key_exists($row, $data)) { if ($row == 'avatar') { if ($data[$row]) { $avatar = $data[$row]; } else { //$insert[$row] = $data[$row]; } } elseif ($row == 'password') { $insert[$row] = md5($data[$row]); } elseif ($row == 'location') { if ($data[$row] != "Introduce tu ubicación") { $insert[$row] = $data[$row]; } } elseif ($row == 'firstname') { $insert[$row] = self::quotesFix($data[$row]); } elseif ($row == 'description') { $insert[$row] = self::quotesFix($data[$row]); } else { $insert[$row] = $data[$row]; } } } if (!$insert) { return false; } $insert['new_email'] = $insert['email']; $insert['store'] = JO_Registry::get('default_upload_method'); if (!$insert['store']) { $insert['store'] = 'locale'; } $db->insert('users', $insert); $user_id = $db->lastInsertId(); if (!$user_id) { return false; } if ($avatar) { ///// upload images $front = JO_Front::getInstance(); $request = JO_Request::getInstance(); $upload_model = Helper_Pin::formatUploadModule(JO_Registry::get('default_upload_method')); $upload_model_file = $front->getModuleDirectoryWithDefault($request->getModule()) . '/' . $front->classToFilename($upload_model); if (!file_exists($upload_model_file)) { $upload_model = Helper_Pin::formatUploadModule('locale'); $upload_model_file = $front->getModuleDirectoryWithDefault($request->getModule()) . '/' . $front->classToFilename($upload_model); } $image = false; if (file_exists($upload_model_file)) { $image = call_user_func(array($upload_model, 'uploadUserAvatar'), $avatar, $user_id); } if ($image) { $db->update('users', array('avatar' => $image['image'], 'store' => $image['store'], 'height' => $image['height'], 'width' => $image['width']), array('user_id = ?' => (string) $user_id)); } } $db->insert('url_alias', array('query' => 'user_id=' . (string) $user_id, 'keyword' => $data['username'], 'path' => $data['username'], 'route' => 'users/profile')); $total_boards = 0; if (is_array(JO_Registry::forceGet('default_boards'))) { foreach (JO_Registry::get('default_boards') as $def) { $res = Model_Boards::createBoard(array('category_id' => $def['category_id'], 'title' => $def['title'], 'user_id' => (string) $user_id)); if ($res) { $total_boards++; } } $db->update('users', array('boards' => $total_boards), array('user_id = ?' => (string) $user_id)); } if (isset($data['delete_email']) && $data['delete_email']) { $db->delete('shared_content', array('email = ?' => $data['delete_email'])); } if (isset($data['delete_code']) && $data['delete_code']) { $db->delete('invate_facebook', array('if_id = ?' => (string) $data['delete_code'])); } if (isset($data['following_user']) && $data['following_user'] && $data['following_user'] != -1) { if ($db->insert('users_following_user', array('user_id' => (string) $user_id, 'following_id' => (string) $data['following_user']))) { /*$db->update('users', array( 'following' => new JO_Db_Expr('following+1') ), array('user_id = ?' => (string)$user_id)); $db->update('users', array( 'followers' => new JO_Db_Expr('followers+1') ), array('user_id = ?' => (string)$data['following_user']));*/ } if ($db->insert('users_following_user', array('user_id' => (string) $data['following_user'], 'following_id' => (string) $user_id))) { /*$db->update('users', array( 'following' => new JO_Db_Expr('following+1') ), array('user_id = ?' => (string)$data['following_user'])); $db->update('users', array( 'followers' => new JO_Db_Expr('followers+1') ), array('user_id = ?' => (string)$user_id));*/ } } $db->update('users', array('boards' => new JO_Db_Expr('(SELECT COUNT(DISTINCT board_id) FROM boards WHERE user_id = users.user_id)'), 'following' => new JO_Db_Expr('(SELECT COUNT(DISTINCT following_id) FROM users_following_user WHERE user_id = users.user_id AND following_id != users.user_id)'), 'followers' => new JO_Db_Expr('(SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = users.user_id AND user_id != users.user_id)')), array('user_id = ?' => (string) $user_id)); if (isset($data['facebook_session']) && $data['facebook_session']) { $db->update('users', array('facebook_session' => is_array($data['facebook_session']) ? serialize($data['facebook_session']) : ''), array('user_id = ?' => (string) $user_id)); } return $user_id; }
public static function isViewedPin($pin_id) { $db = JO_Db::getDefaultAdapter(); $query = $db->select()->from('pins_views', 'COUNT(pv_id)')->where('pin_id = ?', (string) $pin_id)->limit(1); if ((string) JO_Session::get('user[user_id]')) { $query->where("user_id = '" . (string) JO_Session::get('user[user_id]') . "' OR user_ip = '" . JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp()) . "'"); } else { $query->where("user_ip = ?", JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp())); } return $db->fetchOne($query); }
public static function getComments2($data) { $db = JO_Db::getDefaultAdapter(); $is_reported = $db->select()->from('pins_reports_comments', 'COUNT(pr_id)')->where('pins_reports_comments.comment_id = pins_comments.comment_id')->where('checked = 0')->limit(1); if ((string) JO_Session::get('user[user_id]')) { $is_reported->where("user_id = '" . (string) JO_Session::get('user[user_id]') . "' OR user_ip = '" . JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp()) . "'"); } else { $is_reported->where("user_ip = ?", JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp())); } $pin_user_id = new JO_Db_Expr('(' . $db->select()->from('pins', 'user_id')->where('pin_id = pins_comments.pin_id')->limit(1) . ')'); switch (Helper_Config::get('config_user_view')) { case 'username': $user_seo_url = new JO_Db_Expr('users.username'); break; case 'firstname': $user_seo_url = new JO_Db_Expr('users.firstname'); break; case 'fullname': default: $user_seo_url = new JO_Db_Expr('CONCAT(users.firstname, " ", users.lastname)'); break; } $query = $db->select()->from('pins_comments', array('*', 'is_reported' => new JO_Db_Expr('(' . $is_reported . ')')))->joinLeft('users', 'pins_comments.user_id = users.user_id', array('firstname', 'lastname', 'avatar', 'store', 'username', 'fullname' => $user_seo_url, 'pin_user_id' => $pin_user_id)); if (isset($data['filter_pin_id'])) { $query->where('pins_comments.pin_id = ?', (string) $data['filter_pin_id']); } if (isset($data['start']) && isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } $query->limit($data['limit'], $data['start']); } if (isset($data['sort']) && strtolower($data['sort']) == 'desc') { $sort = ' DESC'; } else { $sort = ' ASC'; } $allow_sort = array('pins_comments.comment_id'); if (isset($data['order']) && in_array($data['order'], $allow_sort)) { $query->order($data['order'] . $sort); } else { $query->order('pins_comments.comment_id' . $sort); } return $db->fetchAll($query); }
/** * @return Ambigous <JO_Db_Select, JO_Db_Select> */ public static function getListPinsQuery() { $db = JO_Db::getDefaultAdapter(); $rows_pins = self::describeTable('pins', 'pin_'); $rows_users = self::describeTable('users', 'user_'); $rows_via = self::describeTable('users', 'via_'); $rows_boards = self::describeTable('boards', 'board_'); /////other rows $rows_pins['pin_gift'] = new JO_Db_Expr('pins.price > 0.0000'); //$rows_boards['board_url'] = new JO_Db_Expr('('.$db->select()->from('url_alias', 'IF(`path`,`path`,`keyword`)')->where('query = CONCAT(\'board_id=\',boards.board_id)')->limit(1).')'); switch (Helper_Config::get('config_user_view')) { case 'username': $rows_users['user_fullname'] = new JO_Db_Expr('users.username'); $rows_via['via_fullname'] = new JO_Db_Expr('via.username'); break; case 'firstname': $rows_users['user_fullname'] = new JO_Db_Expr('users.firstname'); $rows_via['via_fullname'] = new JO_Db_Expr('via.firstname'); break; case 'fullname': default: $rows_users['user_fullname'] = new JO_Db_Expr('CONCAT(users.firstname, " ", users.lastname)'); $rows_via['via_fullname'] = new JO_Db_Expr('CONCAT(via.firstname, " ", via.lastname)'); break; } /*if(JO_Session::get('user[user_id]')) { $rows_pins['following_board'] = new JO_Db_Expr('('.$db->select()->from('users_following','COUNT(users_following_id)')->where('user_id = ?', JO_Session::get('user[user_id]'))->where('following_id = pins.user_id')->where('board_id = pins.board_id')->limit(1) .')'); $rows_pins['following_user'] = new JO_Db_Expr('('.$db->select()->from('users_following_user', 'COUNT(ufu_id)')->where('user_id = ?', JO_Session::get('user[user_id]'))->where('following_id = pins.user_id')->limit(1).')'); } else { $rows_pins['following_board'] = new JO_Db_Expr("'login'"); $rows_pins['following_user'] = new JO_Db_Expr("'login'"); }*/ if (JO_Session::get('user[user_id]')) { $rows_pins['pin_is_liked'] = new JO_Db_Expr('(' . $db->select()->from('pins_likes', 'COUNT(like_id)')->where('pin_id = pins.pin_id')->where('user_id = ?', JO_Session::get('user[user_id]'))->limit(1) . ')'); } else { $rows_pins['pin_is_liked'] = new JO_Db_Expr("0"); } /* is reported */ $query_is_reported = $db->select()->from('pins_reports', 'COUNT(pr_id)')->where('pin_id = pins.pin_id')->where('checked = 0')->limit(1); if ((string) JO_Session::get('user[user_id]')) { $query_is_reported->where("user_id = '" . (string) JO_Session::get('user[user_id]') . "' OR user_ip = '" . JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp()) . "'"); } else { $query_is_reported->where("user_ip = ?", JO_Request_Server::encode_ip(JO_Request::getInstance()->getClientIp())); } $rows_pins['pin_is_reported'] = new JO_Db_Expr("(" . $query_is_reported . ")"); $thumbs = Model_Upload_Abstract::pinThumbSizes(); foreach ($thumbs as $size => $prefix) { $rows_pins['pin_thumb' . strtolower($prefix)] = new JO_Db_Expr('(' . $db->select()->from('pins_images', 'CONCAT_WS(\'|||\',image,width,height,original,mime)')->where('pin_id = pins.pin_id')->where('size = ?', $prefix)->limit(1) . ')'); } $thumbs = Model_Upload_Abstract::userThumbSizes(); foreach ($thumbs as $size => $prefix) { $rows_users['user_avatar' . strtolower($prefix)] = new JO_Db_Expr('(' . $db->select()->from('users_avatars', 'CONCAT_WS(\'|||\',image,width,height,original,mime)')->where('user_id = users.user_id')->where('size = ?', $prefix)->limit(1) . ')'); } $query = $db->select()->from('pins', $rows_pins)->joinLeft('users', 'pins.user_id = users.user_id', $rows_users)->joinLeft('boards', 'pins.board_id = boards.board_id', $rows_boards)->joinLeft(array('via' => 'users'), 'pins.via = via.user_id', $rows_via); //for public boards if (Helper_Config::get('config_private_boards')) { if (JO_Session::get('user[user_id]')) { $query->where('pins.user_id = ? OR IF(pins.user_id = ?, 1, pins.public) = 1', JO_Session::get('user[user_id]')); } else { $query->where('pins.public = 1'); } } return $query; }