Esempio n. 1
0
 public function __construct($data = array())
 {
     $db = JO_Db::getDefaultAdapter();
     try {
         $db->beginTransaction();
         $data['user_id'] = isset($data['user_id']) ? $data['user_id'] : JO_Session::get('user[user_id]');
         $data['public'] = isset($data['public']) ? (int) $data['public'] : 1;
         $data['date_added'] = date('Y-m-d H:i:s');
         $board_id = Helper_Db::create('boards', $data);
         if (!$board_id) {
             return $this;
         }
         Helper_Db::insert('users_boards', array('user_id' => isset($data['user_id']) ? (string) $data['user_id'] : JO_Session::get('user[user_id]'), 'board_id' => $board_id, 'is_author' => 1));
         if (isset($data['friends'])) {
             foreach ($data['friends'] as $fr) {
                 Helper_Db::insert('users_boards', array('user_id' => $fr, 'board_id' => $board_id));
             }
         }
         $config_private_boards = Helper_Config::get('config_private_boards');
         Helper_Db::update('users', array('boards' => new JO_Db_Expr("(SELECT COUNT(board_id) FROM boards WHERE user_id = '" . (isset($data['user_id']) ? (string) $data['user_id'] : JO_Session::get('user[user_id]')) . "' " . ($config_private_boards ? ' AND public = 1' : '') . ")")), array('user_id = ?' => isset($data['user_id']) ? (string) $data['user_id'] : JO_Session::get('user[user_id]')));
         ////autoseo
         new Model_Boards_Autoseo($board_id);
         $this->board_id = $board_id;
         $db->commit();
     } catch (JO_Exception $e) {
         $db->rollBack();
         $this->error = $e->getMessage();
     }
 }
Esempio n. 2
0
 public function __construct($board_id)
 {
     $db = JO_Db::getDefaultAdapter();
     try {
         $db->beginTransaction();
         $board_info = new Model_Boards_Board($board_id);
         if (!$board_info->count()) {
             return $this;
         }
         $result = null;
         if ($board_info['board_pins'] > 0) {
             $pins_query = $db->select()->from('pins')->where('board_id = ?', $board_id)->where('user_id = ?', $board_info['user_user_id']);
             $pins = $db->fetchAll($pins_query);
             if ($pins) {
                 foreach ($pins as $pin) {
                     $deleted = new Model_Pins_Delete($pin['pin_id']);
                     if (!$result) {
                         $result = $deleted;
                     }
                 }
             }
         }
         $res = Helper_Db::delete('users_following', array('board_id = ?' => $board_id));
         if (!$result) {
             $result = $res;
         }
         $res = Helper_Db::delete('users_following_ignore', array('board_id = ?' => $board_id));
         if (!$result) {
             $result = $res;
         }
         $res = Helper_Db::delete('users_boards', array('board_id = ?' => $board_id));
         if (!$result) {
             $result = $res;
         }
         $res = Helper_Db::delete('users_history', array('board_id = ?' => $board_id));
         if (!$result) {
             $result = $res;
         }
         $res = Helper_Db::delete('url_alias', array('query = ?' => 'board_id=' . $board_id));
         if (!$result) {
             $result = $res;
         }
         $res = Helper_Db::delete('boards', array('board_id = ?' => $board_id));
         if (!$result) {
             $result = $res;
         }
         $res = Helper_Db::update('users', array('boards' => new JO_Db_Expr("(SELECT COUNT(board_id) FROM boards WHERE user_id = '" . $board_info['user_user_id'] . "')")), array('user_id = ?' => $board_info['user_user_id']));
         if (!$result) {
             $result = $res;
         }
         if ($board_info['board_pins'] > 0) {
             ///////////////// update latest pins for user /////////////////////
             new Model_Users_UpdateLatestPins($board_info['user_user_id']);
         }
         $this->affected_rows = $result;
         $db->commit();
     } catch (JO_Exception $e) {
         $db->rollBack();
     }
 }
Esempio n. 3
0
 public function __construct($data)
 {
     $comment_id = Helper_Db::create('pins_comments', $data);
     if (!$comment_id) {
         return $this;
     }
     Helper_Db::update('pins', array('comments' => new JO_Db_Expr("(SELECT COUNT(comment_id) FROM pins_comments WHERE pin_id = '" . (string) $data['pin_id'] . "')"), 'latest_comments' => new JO_Db_Expr("(SELECT GROUP_CONCAT(comment_id ORDER BY comment_id ASC) FROM (SELECT comment_id FROM pins_comments WHERE pin_id = '" . (string) $data['pin_id'] . "' ORDER BY comment_id ASC LIMIT 4) AS tmp)")), array('pin_id = ?' => $data['pin_id']));
     $this->comment_id = $comment_id;
 }
Esempio n. 4
0
 public function __construct($user_id)
 {
     $db = JO_Db::getDefaultAdapter();
     $user_info = new Model_Users_User($user_id);
     if ($user_info->count()) {
         $config_private_boards = Helper_Config::get('config_private_boards');
         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 OR user_id = users.user_id)' : '') . ')'), 'boards' => new JO_Db_Expr('(SELECT COUNT(DISTINCT board_id) FROM boards WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND (public = 1 OR user_id = users.user_id)' : '') . ')'), '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) )'), 'latest_pins' => new JO_Db_Expr('( SUBSTRING_INDEX( (SELECT GROUP_CONCAT(pin_id ORDER BY `pin_id` DESC) FROM `pins` WHERE user_id = users.user_id), \',\', 15 ) )')), array('user_id = ?' => $user_id));
     }
 }
Esempio n. 5
0
 public function updateStat()
 {
     /*Helper_Db::update('users', array(
     				'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) )')
     		), array('user_id = ?' => (string)$this->user_id2));
     		Helper_Db::update('users', array(
     				'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)$this->user_id));*/
     Helper_Db::update('users', array('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) $this->user_id2));
     Helper_Db::update('users', array('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) $this->user_id));
     Helper_Db::update('boards', array('followers' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = boards.user_id AND user_id != boards.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE following_id = boards.user_id AND user_id != boards.user_id LIMIT 1) - (SELECT COUNT(DISTINCT user_id) FROM users_following_ignore WHERE following_id = boards.user_id AND board_id = boards.board_id AND user_id != boards.user_id LIMIT 1) )')), array('user_id = ?' => (string) $this->user_id));
 }
Esempio n. 6
0
 public function __construct($ids = array(), $page = 1)
 {
     $db = JO_Db::getDefaultAdapter();
     try {
         $db->beginTransaction();
         $result = 0;
         $plus = (int) (Helper_Config::get('config_front_limit') * $page) - Helper_Config::get('config_front_limit');
         if (is_array($ids)) {
             foreach ($ids as $sort_order => $id) {
                 $result += Helper_Db::update('boards', array('sort_order' => (int) ($sort_order + $plus)), array('board_id = ?' => (string) $id, 'user_id = ?' => JO_Session::get('user[user_id]')));
             }
         }
         $this->affected_rows = $result;
         $db->commit();
     } catch (JO_Exception $e) {
         $db->rollBack();
     }
 }
Esempio n. 7
0
 public function unlike()
 {
     if ($this->pin && $this->total) {
         $db = JO_Db::getDefaultAdapter();
         try {
             $db->beginTransaction();
             $result = Helper_Db::delete('pins_likes', array('pin_id = ?' => (string) $this->pin['pin_pin_id'], 'user_id = ?' => (string) JO_Session::get('user[user_id]')));
             if ($result) {
                 $user_id = JO_Session::get('user[user_id]');
                 Helper_Db::update('pins', array('likes' => new JO_Db_Expr('(' . $db->select()->from('pins_likes', 'COUNT(like_id)')->where('pin_id = ?', (string) $this->pin['pin_pin_id'])->limit(1) . ')')), array('pin_id = ?' => (string) $this->pin['pin_pin_id']));
                 Helper_Db::update('users', array('likes' => new JO_Db_Expr('(' . $db->select()->from('pins_likes', 'COUNT(like_id)')->where('user_id = ?', (string) $user_id)->limit(1) . ')')), array('user_id = ?' => (string) $user_id));
             }
             $db->commit();
             return $result;
         } catch (JO_Exception $e) {
             $db->rollBack();
         }
     }
     return false;
 }
Esempio n. 8
0
 public function __construct($comment_id)
 {
     $db = JO_Db::getDefaultAdapter();
     try {
         $db->beginTransaction();
         $info = self::getComment($comment_id);
         if ($info) {
             $result = Helper_Db::delete('pins_comments', array('comment_id = ?' => $comment_id));
             $res = Helper_Db::delete('pins_reports_comments', array('comment_id = ?' => $comment_id));
             if (!$result) {
                 $result = $res;
             }
             $res = Helper_Db::update('pins', array('comments' => new JO_Db_Expr("(SELECT COUNT(comment_id) FROM pins_comments WHERE pin_id = '" . (string) $info['pin_id'] . "')"), 'latest_comments' => new JO_Db_Expr("(SELECT GROUP_CONCAT(comment_id ORDER BY comment_id ASC) FROM (SELECT comment_id FROM pins_comments WHERE pin_id = '" . (string) $info['pin_id'] . "' ORDER BY comment_id ASC LIMIT 4) AS tmp)")), array('pin_id = ?' => (string) $info['pin_id']));
             if (!$result) {
                 $result = $res;
             }
             $this->affected_rows = $result;
         }
         $db->commit();
     } catch (JO_Exception $e) {
         $db->rollBack();
     }
 }
Esempio n. 9
0
 public static function delete($board_id)
 {
     $board_info = self::getBoard($board_id);
     if (!$board_info) {
         return;
     }
     $deleted_pins = 0;
     $db = JO_Db::getDefaultAdapter();
     $pins_query = $db->select()->from('pins')->where('board_id = ?', $board_id);
     $pins = $db->fetchAll($pins_query);
     if ($pins) {
         foreach ($pins as $pin) {
             $deleted = Model_Pins::delete($pin['pin_id']);
             if ($deleted) {
                 $deleted_pins++;
             }
         }
     }
     $db->delete('users_following', array('board_id = ?' => $board_id));
     $db->delete('users_following_ignore', array('board_id = ?' => $board_id));
     $del_boards = $db->delete('boards', array('board_id = ?' => $board_id));
     $db->delete('users_boards', array('board_id = ?' => $board_id));
     $db->delete('users_history', array('board_id = ?' => $board_id));
     $db->query("DELETE FROM url_alias WHERE query = 'board_id=" . $board_id . "'");
     /*$update = array(
     			'boards' => new JO_Db_Expr("(SELECT COUNT(board_id) FROM boards WHERE user_id = '".$board_info['user_id']."')")
     		);*/
     //$db->update('users', $update, array('user_id=?'=>$board_info['user_id']));
     Helper_Db::update('users', array('pins' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins WHERE user_id = users.user_id)'), 'boards' => new JO_Db_Expr('(SELECT COUNT(DISTINCT board_id) FROM boards WHERE user_id = users.user_id)'), '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=?' => $board_info['user_id']));
     Model_Users::updateLatestPins($board_info['user_id']);
     return $del_boards;
 }
Esempio n. 10
0
 public static function editeSource($source_id, $data)
 {
     if (($data['source'] = JO_Validate::validateHost($data['source'])) === false) {
         return false;
     }
     return Helper_Db::update('pins_sources', array('source' => $data['source']), array('source_id = ?' => $source_id)) === false ? false : true;
 }
Esempio n. 11
0
 public function update($data)
 {
     return Helper_Db::update('oauth_instagram', array('username' => $data['username'], 'access_token' => $data['access_token']), array('id = ?' => $this->row['id']));
 }
Esempio n. 12
0
 public function __construct($pin_id, $data = array())
 {
     $db = JO_Db::getDefaultAdapter();
     try {
         $db->beginTransaction();
         $pin_info = new Model_Pins_Pin($pin_id);
         if (!$pin_info->count()) {
             return $this;
         }
         $pin_info = $pin_info->data;
         if (isset($data['board_id'])) {
             $board_info = new Model_Boards_Board($data['board_id']);
             if ($board_info->count()) {
                 $data['board_id'] = $board_info['board_board_id'];
                 $data['category_id'] = $board_info['board_category_id'];
                 $data['public'] = $board_info['board_public'];
             } else {
                 $data['board_id'] = 0;
             }
         }
         $data['likes'] = new JO_Db_Expr('(SELECT COUNT(DISTINCT user_id) FROM pins_likes WHERE pin_id = pins.pin_id)');
         $data['comments'] = new JO_Db_Expr('(SELECT COUNT(DISTINCT comment_id) FROM pins_comments WHERE pin_id = pins.pin_id)');
         $data['date_modified'] = WM_Date::format(time(), 'yy-mm-dd H:i:s');
         $data['source_id'] = 0;
         //sorce
         if (isset($data['from']) && $data['from']) {
             $source = new Model_Sources_GetSourceByUrl($data['from']);
             if ($source->source_id) {
                 $data['source_id'] = $source->source_id;
             }
         }
         $data['from_md5'] = md5(isset($data['from']) ? $data['from'] : time());
         /* price */
         //$data['price'] = 0;
         if (isset($data['price']) && $data['price']) {
             $currencies = WM_Currency::getCurrencies();
             $price_left = array();
             $price_right = array();
             if ($currencies) {
                 foreach ($currencies as $currency) {
                     if (trim($currency['symbol_left'])) {
                         $price_left[] = preg_quote(trim($currency['symbol_left']));
                     }
                     if (trim($currency['symbol_right'])) {
                         $price_right[] = preg_quote(trim($currency['symbol_right']));
                     }
                 }
                 if ($price_left) {
                     if (preg_match('/(' . implode('|', $price_left) . ')([\\s]{0,2})?(?:(?:\\d{1,5}(?:\\,\\d{3})+)|(?:\\d+))(?:\\.\\d{2})?/', $data['price'], $match)) {
                         $price_tmp = trim(str_replace(trim($match[1]), '', $match[0]));
                         $currency = self::getCurrencyBySimbol(trim($match[1]));
                         if ($currency) {
                             $data['price'] = round($price_tmp / $currency, 4);
                         }
                     }
                 }
                 if (!$data['price'] && $price_right) {
                     if (preg_match('/(?:(?:\\d{1,5}(?:\\,\\d{3})+)|(?:\\d+))(?:\\.\\d{2})?([\\s]{0,2})?(' . implode('|', $price_right) . ')/', $data['price'], $match)) {
                         $price_tmp = trim(str_replace(trim($match[2]), '', $match[0]));
                         $currency = self::getCurrencyBySimbol(trim($match[2]));
                         if ($currency) {
                             $data['price'] = round($price_tmp / $currency, 4);
                         }
                     }
                 }
             }
         }
         /* end price */
         $from = isset($data['from']) ? $data['from'] : time();
         $data['is_video'] = isset($data['is_video']) && $data['is_video'] == 'true' ? 1 : 0;
         if (!$data['is_video']) {
             $auto = new Helper_AutoEmbed();
             if ($auto->parseUrl($from)) {
                 $data['is_video'] = 1;
             }
         }
         /* is video */
         ///////////////// Event onComplete /////////////////////
         $on_add_call = Helper_Config::get('pin_onbefore_edit');
         if ($on_add_call) {
             foreach ($on_add_call as $call) {
                 call_user_func($call, $data);
             }
         }
         //edit pin
         $result = Helper_Db::update('pins', $data, array('pin_id = ?' => $pin_id));
         ///////////////// update latest pins for board /////////////////////
         if (isset($data['board_id']) && $data['board_id'] && $pin_info['pin_board_id'] != $data['board_id']) {
             new Model_Boards_UpdateLatestPins($data['board_id']);
             new Model_Boards_UpdateLatestPins($pin_info['pin_board_id']);
             $board_info = new Model_Boards_Board($data['board_id']);
             if ($board_info->count()) {
                 if ($board_info['board_cover'] == $pin_id) {
                     $res = Helper_Db::update('boards', array('cover' => 0), array('board_id = >' => $pin_info['pin_board_id']));
                     if (!$result && $res) {
                         $result = $res;
                     }
                 }
             }
         }
         ///////////////// update latest pins for user /////////////////////
         new Model_Users_UpdateLatestPins($pin_info['pin_user_id']);
         ///////////////// Word for search index's /////////////////////
         $spl = JO_Utf8::str_word_split(strip_tags(html_entity_decode($data['description'], ENT_QUOTES, 'utf-8')), self::$searchWordLenght);
         $words = array();
         foreach ($spl as $word) {
             $word = mb_strtolower($word, 'utf-8');
             if (!in_array($word, self::blackWordsDictionary()) && $word[0] . $word[1] != '&#') {
                 $words[$word] = $word;
             }
         }
         ///////////////// Word for search index's insert /////////////////////
         Helper_Db::delete('pins_invert', array('pin_id = ?' => $pin_id));
         foreach ($words as $word => $data1) {
             $dic_id = $db->fetchOne($db->select()->from('pins_dictionary', 'dic_id')->where('word = ?', $word));
             if (!$dic_id) {
                 $dic_id = Helper_Db::insert('pins_dictionary', array('word' => $word));
             }
             if ($dic_id) {
                 $res = Helper_Db::insert('pins_invert', array('pin_id' => $pin_id, 'dic_id' => $dic_id));
                 if (!$result && $res) {
                     $result = $res;
                 }
             }
         }
         ///////////////// Extension on edit //////////////////
         $extensions = Model_Extensions::getByMethod('pin_onedit');
         if ($extensions) {
             $front = JO_Front::getInstance();
             foreach ($extensions as $id => $ext) {
                 $pin_data_ext = call_user_func(array($front->formatModuleName('model_' . $ext . '_pin'), 'onedit'), $pin_id, $data);
                 if ($pin_data_ext && is_array($pin_data_ext)) {
                     $data = array_merge(data, $pin_data_ext);
                 }
             }
         }
         ///////////////// Event onComplete /////////////////////
         $trigger = new Helper_Triggers_PinOnEdit();
         $trigger->bind($pin_id);
         $this->affected_rows = $result;
         $db->commit();
     } catch (JO_Exception $e) {
         echo $e;
         exit;
         $db->rollBack();
     }
 }
Esempio n. 13
0
 public function __construct($pin_id)
 {
     $db = JO_Db::getDefaultAdapter();
     try {
         $db->beginTransaction();
         $pin_info = new Model_Pins_Pin($pin_id);
         if (!$pin_info->count()) {
             return $this;
         }
         $pin_info = $pin_info->data;
         $result = null;
         if ($pin_info['pin_image']) {
             $res = Helper_Db::create('pins_images_for_delete', array('pin_id' => $pin_info['pin_pin_id'], 'date_added' => $pin_info['pin_date_added'], 'image' => $pin_info['pin_image'], 'store' => $pin_info['pin_store'], 'gallery_id' => 0));
             if (!$result) {
                 $result = $res;
             }
         }
         $gallery = new Model_Pins_Gallery($pin_info['pin_pin_id']);
         if ($gallery->count()) {
             foreach ($gallery->data as $gal) {
                 $res = Helper_Db::create('pins_images_for_delete', array('pin_id' => $gal['pin_id'], 'date_added' => $pin_info['pin_date_added'], 'image' => $gal['image'], 'store' => $gal['store'], 'gallery_id' => $gal['gallery_id']));
                 if (!$result) {
                     $result = $res;
                 }
             }
         }
         if ($pin_info['pin_comments']) {
             $comments = Model_Comments::getComments2(array('filter_pin_id' => $pin_id));
             foreach ($comments as $comment) {
                 $del = new Model_Pins_DeleteComment($comment['comment_id']);
                 if (!$result) {
                     $result = $del->affected_rows;
                 }
             }
         }
         $res = Helper_Db::delete('pins', array('pin_id = ?' => $pin_id));
         if (!$result) {
             $result = $res;
         }
         $res = Helper_Db::delete('pins_invert', array('pin_id = ?' => $pin_id));
         if (!$result) {
             $result = $res;
         }
         if ($pin_info['pin_likes']) {
             $res = Helper_Db::delete('pins_likes', array('pin_id = ?' => $pin_id));
             if (!$result) {
                 $result = $res;
             }
         }
         $res = Helper_Db::delete('pins_reports', array('pin_id = ?' => $pin_id));
         if (!$result) {
             $result = $res;
         }
         $res = Helper_Db::delete('pins_views', array('pin_id = ?' => $pin_id));
         if (!$result) {
             $result = $res;
         }
         $res = Helper_Db::delete('users_history', array('pin_id = ?' => $pin_id));
         if (!$result) {
             $result = $res;
         }
         $res = Helper_Db::delete('pins_images', array('pin_id = ?' => $pin_id));
         if (!$result) {
             $result = $res;
         }
         $res = Helper_Db::update('users', array('likes' => new JO_Db_Expr('(' . $db->select()->from('pins_likes', 'COUNT(like_id)')->where('pin_id IN (?)', new JO_Db_Expr('(' . $db->select()->from('pins', 'pin_id')->where('user_id = ?', $pin_info['user_user_id']) . ')'))->limit(1) . ')')), array('user_id=?' => $pin_info['user_user_id']));
         if (!$result) {
             $result = $res;
         }
         ///////////////// update latest pins for user and board /////////////////////
         new Model_Users_UpdateLatestPins($pin_info['user_user_id']);
         new Model_Boards_UpdateLatestPins($pin_info['board_board_id']);
         ///////////////// Extension on delete //////////////////
         $extensions = Model_Extensions::getByMethod('pin_ondelete');
         if ($extensions) {
             $front = JO_Front::getInstance();
             foreach ($extensions as $id => $ext) {
                 $res = call_user_func(array($front->formatModuleName('model_' . $ext . '_pin'), 'ondelete'), $pin_id);
                 if (!$result) {
                     $result = $res;
                 }
             }
         }
         $this->affected_rows = $result;
         $db->commit();
     } catch (JO_Exception $e) {
         $db->rollBack();
     }
 }
Esempio n. 14
0
 public function updateTimelineByUserId($user_id, $timeline)
 {
     return Helper_Db::update('oauth_facebook', array('access_token' => $this->facebook->getAccessToken(), 'timeline' => (int) $timeline), array('user_id = ?' => (string) $user_id));
 }
Esempio n. 15
0
 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();
     }
 }
Esempio n. 16
0
 public function __construct($user_id, $data = array())
 {
     $db = JO_Db::getDefaultAdapter();
     try {
         $db->beginTransaction();
         $user_info_get = new Model_Users_User($user_id);
         if (!$user_info_get) {
             return $this;
         }
         $rows = Helper_Db::describeTable('users');
         $update = 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) {
                             $update[$row] = $data[$row];
                         } else {
                             $update[$row] = md5($data[$row]);
                         }
                     } else {
                         $update[$row] = '';
                     }
                 } elseif ($row == 'avatar') {
                     $avatar = $data[$row];
                     unset($data[$row]);
                 } else {
                     $update[$row] = $data[$row];
                 }
             }
         }
         if (count($update) == 0 && $avatar == '') {
             return $this;
         }
         $result = Helper_Db::update('users', $update, array('user_id = ?' => (string) $user_id));
         //add user avatar
         if ($avatar) {
             $image = false;
             $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 && $image && isset($image['image']) && $image['image']) {
                 $res = Helper_Db::update('users', array('avatar' => $image['image'], 'store' => $image['store'], 'height' => $image['height'], 'width' => $image['width'], 'last_action_datetime' => new JO_Db_Expr('NOW()')), array('user_id = ?' => (string) $user_id));
                 if (!$result) {
                     $result = $res;
                 }
                 Helper_Db::delete('users_avatars', array('user_id = ?' => (string) $user_id));
                 if ($user_info_get && $user_info_get['avatar']) {
                     if ($user_info_get['avatar'] != $image['image']) {
                         call_user_func(array($user_info_get['store'], 'deleteUserImage'), $user_info_get);
                     }
                 }
             }
         }
         if (isset($data['username'])) {
             $result = new Model_Users_Autoseo($user_id);
             if (!$result->affected_rows) {
                 $result = $res;
             }
         }
         $config_private_boards = Helper_Config::get('config_private_boards');
         $res = 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 OR user_id = users.user_id)' : '') . ')'), 'boards' => new JO_Db_Expr('(SELECT COUNT(DISTINCT board_id) FROM boards WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND (public = 1 OR user_id = users.user_id)' : '') . ')'), '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) )'), 'latest_pins' => new JO_Db_Expr('( SUBSTRING_INDEX( (SELECT GROUP_CONCAT(pin_id ORDER BY `pin_id` DESC) FROM `pins` WHERE user_id = users.user_id), \',\', 15 ) )')), array('user_id = ?' => (string) $user_id));
         if (!$result) {
             $result = $res;
         }
         $this->affected_rows = $result;
         $db->commit();
     } catch (JO_Exception $e) {
         $db->rollBack();
     }
 }
Esempio n. 17
0
 public function editDescriptionAction()
 {
     $request = $this->getRequest();
     if (!JO_Session::get('user[user_id]')) {
         if ($request->isXmlHttpRequest()) {
             $this->view->redirect = WM_Router::create($request->getBaseUrl() . '?controller=users&action=login');
         } else {
             $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'));
         }
     } else {
         $result = Helper_Db::update('users', array('description' => $request->getPost('description')), array('user_id = ?' => (string) JO_Session::get('user[user_id]')));
         if ($result) {
             $this->view->ok = $request->getPost('description');
         } else {
             $this->view->error = $this->translate('There was a problem with the record. Please try again!');
         }
     }
     echo $this->renderScript('json');
 }
Esempio n. 18
0
 public static function setPinMedia($media_id, $pin_id)
 {
     $db = JO_Db::getDefaultAdapter();
     return Helper_Db::update('instagram_media', array('pin_id' => (string) $pin_id), array('media_id = ?' => $media_id));
 }
Esempio n. 19
0
 public static function edit($user_id, $data)
 {
     $db = JO_Db::getDefaultAdapter();
     $rows = self::describeTable('users');
     $user_info_get = self::getUser($user_id);
     $date_added = WM_Date::format($user_info_get['date_added'], 'yy-mm-dd H:i:s');
     $update = array();
     $avatar = '';
     foreach ($rows as $row) {
         if (array_key_exists($row, $data)) {
             if ($row == 'avatar') {
                 if ($data[$row]) {
                     JO_Session::clear('upload_avatar');
                     $avatar = $data[$row];
                 } else {
                     //$update[$row] = $data[$row];
                 }
             } elseif ($row == 'password' || $row == 'new_password') {
                 $update[$row] = md5($data[$row]);
             } else {
                 $update[$row] = $data[$row];
             }
         }
     }
     if (!$update) {
         if (!$avatar) {
             return false;
         }
     }
     $rebuild = $result = $db->update('users', $update, array('user_id = ?' => (string) $user_id));
     if ($avatar) {
         $image = false;
         //$error = false;
         $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($upload_model, 'getError') );
         }
         if ($image) {
             $result = $db->update('users', array('avatar' => $image['image'], 'store' => $image['store'], 'height' => $image['height'], 'width' => $image['width'], 'last_action_datetime' => new JO_Db_Expr('NOW()')), array('user_id = ?' => (string) $user_id));
             $db->delete('users_avatars', array('user_id = ?' => (string) $user_id));
             if ($user_info_get && $user_info_get['avatar']) {
                 if ($user_info_get['avatar'] != $image['image']) {
                     call_user_func(array($user_info_get['store'], 'deleteUserImage'), $user_info_get);
                 }
             }
             if (!$rebuild) {
                 $rebuild = $result;
             }
         }
     }
     if (isset($data['username'])) {
         $db->query("DELETE FROM url_alias WHERE query = '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'));
     }
     if ($rebuild) {
         $total = $db->update('pins', array('date_modified' => WM_Date::format(time(), 'yy-mm-dd H:i:s')), array('user_id = ? OR (pin_id IN (SELECT DISTINCT pin_id FROM pins_comments WHERE user_id = ?))' => (string) $user_id));
     }
     $config_private_boards = Helper_Config::get('config_private_boards');
     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) )'), 'latest_pins' => new JO_Db_Expr('( SUBSTRING_INDEX( (SELECT GROUP_CONCAT(pin_id ORDER BY `pin_id` DESC) FROM `pins` WHERE user_id = users.user_id), \',\', 15 ) )')), array('user_id = ?' => $user_id));
     return true;
 }
Esempio n. 20
0
 public static function delete($pin_id)
 {
     $db = JO_Db::getDefaultAdapter();
     $pin_info = self::getPin($pin_id);
     if (!$pin_info) {
         return false;
     }
     if ($pin_info['image']) {
         $res = Helper_Db::create('pins_images_for_delete', array('pin_id' => $pin_info['pin_id'], 'date_added' => $pin_info['date_added'], 'image' => $pin_info['image'], 'store' => $pin_info['store']));
     }
     $comments = Model_Comments::getComments(array('filter_pin_id' => $pin_id));
     if ($comments) {
         foreach ($comments as $comment) {
             $db->delete('pins_comments', array('comment_id = ?' => $comment['comment_id']));
             $db->delete('pins_reports_comments', array('comment_id = ?' => $comment['comment_id']));
         }
     }
     $del = $db->delete('pins', array('pin_id = ?' => $pin_id));
     if (!$del) {
         return false;
     } else {
         $db->query("INSERT INTO `pins_images_for_delete`(`pin_id`, `gallery_id`, `date_added`, `image`, `store`) SELECT `pin_id`, `gallery_id`, '" . $pin_info['date_added'] . "', `image`, `store` FROM `pins_gallery` WHERE `pin_id` = '" . $pin_id . "'");
         $db->delete('pins_invert', array('pin_id = ?' => $pin_id));
         $db->delete('pins_likes', array('pin_id = ?' => $pin_id));
         $db->delete('pins_reports', array('pin_id = ?' => $pin_id));
         $db->delete('pins_views', array('pin_id = ?' => $pin_id));
         $db->delete('users_history', array('pin_id = ?' => $pin_id));
         $db->delete('pins_gallery', array('pin_id = ?' => $pin_id));
         $db->delete('pins_images', array('pin_id = ?' => $pin_id));
         $config_private_boards = Helper_Config::get('config_private_boards');
         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) )'), 'latest_pins' => new JO_Db_Expr('( SUBSTRING_INDEX( (SELECT GROUP_CONCAT(pin_id ORDER BY `pin_id` DESC) FROM `pins` WHERE user_id = users.user_id), \',\', 15 ) )')), array('user_id=?' => $pin_info['user_id']));
         Helper_Db::update('boards', array('pins' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins WHERE board_id = boards.board_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'followers' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = boards.user_id AND user_id != boards.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE following_id = boards.user_id AND user_id != boards.user_id LIMIT 1) - (SELECT COUNT(DISTINCT user_id) FROM users_following_ignore WHERE following_id = boards.user_id AND board_id = boards.board_id AND user_id != boards.user_id LIMIT 1) )'), 'latest_pins' => new JO_Db_Expr('( SUBSTRING_INDEX( (SELECT GROUP_CONCAT(pin_id ORDER BY `pin_id` DESC) FROM `pins` WHERE board_id = boards.board_id), \',\', 15 ) )')), array('board_id=?' => $pin_info['board_id']));
         self::deleteCache($pin_info);
         return true;
     }
 }
Esempio n. 21
0
 public function coverAction()
 {
     $this->noLayout(true);
     $request = $this->getRequest();
     if (!$request->isXmlHttpRequest()) {
         $this->forward('error', 'error404');
     }
     $board_id = $request->getRequest('board_id');
     $board_info = new Model_Boards_Board($board_id);
     if ($board_info->count() > 0) {
         if ($board_info['user_user_id'] != JO_Session::get('user[user_id]')) {
             $this->forward('error', 'error404');
         }
         if ($request->isPost() && $request->getPost('pin_id')) {
             $result = Helper_Db::update('boards', array('cover' => $request->getPost('pin_id')), array('board_id = ?' => $board_id));
             if ($result !== false) {
                 $this->view->success = $request->getPost('pin_id');
             } else {
                 $this->view->error = $this->translate('There was an error, please try again!');
             }
             echo $this->renderScript('json');
             exit;
         }
         $pins = new Model_Pins_Boards(array('filter_board_id' => $board_id, 'start' => 0, 'limit' => 100));
         $this->view->pins = array();
         if ($pins->count()) {
             foreach ($pins->data as $pin) {
                 $filter = array('pin_id' => $pin['pin_pin_id'], 'pin_pin_id' => $pin['pin_pin_id'], 'image' => $pin['pin_image'], 'pin_store' => $pin['pin_store']);
                 foreach ($pin as $k => $v) {
                     if (strpos($k, 'pin_thumb_') !== false) {
                         $filter[$k] = $v;
                     }
                 }
                 $image = Helper_Uploadimages::pinThumbs($filter);
                 if ($image['thumb_image_b']) {
                     $this->view->pins[] = array('image' => $image['thumb_image_b'], 'image_c' => $image['thumb_image_c'], 'pin_id' => (string) $pin['pin_pin_id']);
                 }
             }
         }
         $this->view->history_id = $request->getParam('hid');
         $this->view->form_action = $request->getFullUrl();
         $this->view->board_id = $board_id;
     } else {
         $this->forward('error', 'error404');
     }
 }
Esempio n. 22
0
 public function updateTwitByUserId($user_id, $data)
 {
     return Helper_Db::update('oauth_twitter', array('twitter_oauth_token' => $data['twitter_oauth_token'], 'twitter_oauth_token_secret' => $data['twitter_oauth_token_secret'], 'twit' => (int) $data['twit'], 'username' => $data['username']), array('user_id = ?' => (string) $user_id));
 }
Esempio n. 23
0
 public function __construct($board_id, $data = array())
 {
     $db = JO_Db::getDefaultAdapter();
     try {
         $db->beginTransaction();
         $board_info = new Model_Boards_Board($board_id);
         if (!$board_info->count()) {
             return $this;
         }
         $data['date_modified'] = WM_Date::format(time(), 'yy-mm-dd H:i:s');
         $result = Helper_Db::update('boards', $data, array('board_id = ?' => (string) $board_id));
         $usrd = $db->select()->from('users_boards')->where('board_id = ?', (string) $board_id);
         $usd = $db->fetchAll($usrd);
         $tmp = array();
         if ($usd) {
             foreach ($usd as $e) {
                 $tmp[$e['user_id']] = array('allow' => $e['allow'], 'sort_order' => $e['sort_order']);
             }
         }
         Helper_Db::delete('users_boards', array('board_id = ?' => (string) $board_id));
         $ins = Helper_Db::insert('users_boards', array('user_id' => $board_info['user_user_id'], 'board_id' => $board_id, 'is_author' => 1, 'sort_order' => (int) (isset($tmp[$board_info['user_user_id']]['sort_order']) ? $tmp[$board_info['user_user_id']]['sort_order'] : 0)));
         if (!$result) {
             $result = $ins;
         }
         if (isset($data['friends'])) {
             foreach ($data['friends'] as $fr) {
                 $ins = Helper_Db::insert('users_boards', array('user_id' => $fr, 'board_id' => $board_id, 'allow' => (int) (isset($tmp[$fr]['allow']) ? $tmp[$fr]['allow'] : 0), 'sort_order' => (int) (isset($tmp[$fr]['sort_order']) ? $tmp[$fr]['sort_order'] : 0)));
                 if (!$result) {
                     $result = $ins;
                 }
             }
         }
         if ($result && isset($data['category_id']) && $board_info['user_category_id'] != $data['category_id']) {
             $res = Helper_Db::update('pins', array('category_id' => $data['category_id'], 'date_modified' => $data['date_modified']), array('board_id = ?' => $board_id));
             if (!$result) {
                 $result = $res;
             }
         } else {
             $res = Helper_Db::update('pins', array('date_modified' => $data['date_modified']), array('board_id = ?' => $board_id));
             if (!$result) {
                 $result = $res;
             }
         }
         $res = Helper_Db::update('boards', array('pins' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins WHERE board_id = boards.board_id)'), 'followers' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = boards.user_id AND user_id != boards.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE following_id = boards.user_id AND user_id != boards.user_id LIMIT 1) - (SELECT COUNT(DISTINCT user_id) FROM users_following_ignore WHERE following_id = boards.user_id AND board_id = boards.board_id AND user_id != boards.user_id LIMIT 1) )')), array('board_id = ?' => $board_id));
         if (!$result) {
             $result = $res;
         }
         Helper_Db::update('users', array('boards' => new JO_Db_Expr("(SELECT COUNT(board_id) FROM boards WHERE user_id = '" . (isset($data['user_id']) ? (string) $data['user_id'] : JO_Session::get('user[user_id]')) . "')")), array('user_id = ?' => $board_info['user_user_id']));
         //private
         $config_private_boards = Helper_Config::get('config_private_boards');
         if (isset($data['public']) && $data['public'] != $board_info['board_public']) {
             Helper_Db::update('pins', array('public' => $data['public']), array('board_id = ?' => $board_id));
             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 = ?' => $board_info['user_user_id']));
         }
         ////autoseo
         new Model_Boards_Autoseo($board_id);
         $this->affected_rows = $result;
         $db->commit();
     } catch (JO_Exception $e) {
         $db->rollBack();
     }
 }
Esempio n. 24
0
 public function __construct($data = array())
 {
     $db = JO_Db::getDefaultAdapter();
     $data['category_id'] = 0;
     $data['public'] = 1;
     if (isset($data['board_id'])) {
         $board_info = new Model_Boards_Board($data['board_id']);
         if ($board_info->count()) {
             $data['board_id'] = $board_info['board_board_id'];
             $data['category_id'] = $board_info['board_category_id'];
             $data['public'] = $board_info['board_public'];
         } else {
             $data['board_id'] = 0;
         }
     } else {
         $data['board_id'] = 0;
     }
     $data['date_added'] = WM_Date::format(time(), 'yy-mm-dd H:i:s');
     $data['date_modified'] = $data['date_added'];
     $data['user_id'] = isset($data['user_id']) ? $data['user_id'] : (string) JO_Session::get('user[user_id]');
     $data['store'] = Helper_Config::get('file_upload_method') ? Helper_Config::get('file_upload_method') : 'Model_Upload_Locale';
     $data['source_id'] = 0;
     //sorce
     if (isset($data['from']) && $data['from']) {
         $source = new Model_Sources_GetSourceByUrl($data['from']);
         if ($source->source_id) {
             $data['source_id'] = $source->source_id;
         }
     }
     $data['from_md5'] = md5(isset($data['from']) ? $data['from'] : time());
     /* price */
     //$data['price'] = 0;
     if (isset($data['price']) && $data['price']) {
         $currencies = WM_Currency::getCurrencies();
         $price_left = array();
         $price_right = array();
         if ($currencies) {
             foreach ($currencies as $currency) {
                 if (trim($currency['symbol_left'])) {
                     $price_left[] = preg_quote(trim($currency['symbol_left']));
                 }
                 if (trim($currency['symbol_right'])) {
                     $price_right[] = preg_quote(trim($currency['symbol_right']));
                 }
             }
             if ($price_left) {
                 if (preg_match('/(' . implode('|', $price_left) . ')([\\s]{0,2})?(?:(?:\\d{1,5}(?:\\,\\d{3})+)|(?:\\d+))(?:\\.\\d{2})?/', $data['price'], $match)) {
                     $price_tmp = trim(str_replace(trim($match[1]), '', $match[0]));
                     $currency = self::getCurrencyBySimbol(trim($match[1]));
                     if ($currency) {
                         $data['price'] = round($price_tmp / $currency, 4);
                     }
                 }
             }
             if (!$data['price'] && $price_right) {
                 if (preg_match('/(?:(?:\\d{1,5}(?:\\,\\d{3})+)|(?:\\d+))(?:\\.\\d{2})?([\\s]{0,2})?(' . implode('|', $price_right) . ')/', $data['price'], $match)) {
                     $price_tmp = trim(str_replace(trim($match[2]), '', $match[0]));
                     $currency = self::getCurrencyBySimbol(trim($match[2]));
                     if ($currency) {
                         $data['price'] = round($price_tmp / $currency, 4);
                     }
                 }
             }
         }
     }
     /* end price */
     $from = isset($data['from']) ? $data['from'] : time();
     $data['is_video'] = isset($data['is_video']) && $data['is_video'] == 'true' ? 1 : 0;
     if (!$data['is_video']) {
         $auto = new Helper_AutoEmbed();
         if ($auto->parseUrl($from)) {
             $data['is_video'] = 1;
         }
     }
     /* is video */
     ///////////////// Event onComplete /////////////////////
     $on_add_call = Helper_Config::get('pin_onbefore_create');
     if ($on_add_call) {
         foreach ($on_add_call as $call) {
             call_user_func($call, $data);
         }
     }
     ///////////////// upload image /////////////////////
     $image = false;
     if (isset($data['media']) && !isset($data['image'])) {
         $image = $data['media'];
     } else {
         if (isset($data['image'])) {
             $image = $data['image'];
         }
     }
     if (!isset($data['gallery']) && !$image) {
         return $this;
     }
     $data['image'] = '';
     //create pin
     $data['pin_id'] = Helper_Db::insert('pins', $data);
     if (!$data['pin_id']) {
         return $this;
     }
     if (isset($data['gallery'])) {
         if (is_array($data['gallery']) && count($data['gallery']) > 0) {
             $method_for_upload = Helper_Config::get('file_upload_method');
             if ($method_for_upload) {
                 foreach ($data['gallery'] as $row => $image_get) {
                     if ($this->error) {
                         return $this;
                     }
                     $image = call_user_func(array($method_for_upload, 'uploadPin'), $image_get, isset($data['title']) && $data['title'] ? $data['title'] : $data['description'], $data['pin_id']);
                     $this->error = call_user_func(array($method_for_upload, 'getError'));
                     if ($image && isset($image['image'])) {
                         if ($row == 0) {
                             Helper_Db::update('pins', array('image' => $image['image'], 'store' => $image['store'], 'height' => $image['height'], 'width' => $image['width']), array('pin_id = ?' => (string) $data['pin_id']));
                         } else {
                             $gal_id = Helper_Db::insert('pins_gallery', array('image' => $image['image'], 'store' => $image['store'], 'pin_id' => $data['pin_id'], 'sort_order' => $row));
                             if (!$gal_id) {
                                 return $this;
                             }
                         }
                     } else {
                         return $this;
                     }
                 }
             } else {
                 Helper_Db::delete('pins', array('pin_id = ?' => (string) $data['pin_id']));
                 return $this;
             }
         } else {
             Helper_Db::delete('pins', array('pin_id = ?' => (string) $data['pin_id']));
             return $this;
         }
     } else {
         $method_for_upload = Helper_Config::get('file_upload_method');
         if ($method_for_upload && $image) {
             $image = call_user_func(array($method_for_upload, 'uploadPin'), $image, isset($data['title']) && $data['title'] ? $data['title'] : $data['description'], $data['pin_id']);
             $this->error = call_user_func(array($method_for_upload, 'getError'));
             if ($image && isset($image['image'])) {
                 Helper_Db::update('pins', array('image' => $image['image'], 'store' => $image['store'], 'height' => $image['height'], 'width' => $image['width']), array('pin_id = ?' => (string) $data['pin_id']));
             } else {
                 Helper_Db::delete('pins', array('pin_id = ?' => (string) $data['pin_id']));
                 return $this;
             }
         } else {
             Helper_Db::delete('pins', array('pin_id = ?' => (string) $data['pin_id']));
             return $this;
         }
     }
     ///////////////// update latest pins for board /////////////////////
     if (isset($data['board_id']) && $data['board_id']) {
         new Model_Boards_UpdateLatestPins($data['board_id']);
     }
     ///////////////// update latest pins for user /////////////////////
     new Model_Users_UpdateLatestPins($data['user_id']);
     ///////////////// Pin total repins /////////////////////
     if (isset($data['repin_from']) && $data['repin_from']) {
         $pin_repin = new Model_Pins_Pin($data['repin_from']);
         if ($pin_repin->count()) {
             Helper_Db::update('pins', array('repins' => $db->fetchOne($db->select()->from('pins', 'COUNT(pin_id)')->where('repin_from = ?', $data['repin_from'])->limit(1))), array('pin_id = ?' => $data['repin_from']));
         }
     }
     ///////////////// Word for search index's /////////////////////
     $spl = JO_Utf8::str_word_split(strip_tags(html_entity_decode($data['description'], ENT_QUOTES, 'utf-8')), self::$searchWordLenght);
     $words = array();
     foreach ($spl as $word) {
         $word = mb_strtolower($word, 'utf-8');
         if (!in_array($word, self::blackWordsDictionary()) && $word[0] . $word[1] != '&#') {
             $words[$word] = $word;
         }
     }
     ///////////////// Word for search index's insert /////////////////////
     foreach ($words as $word => $data1) {
         $dic_id = $db->fetchOne($db->select()->from('pins_dictionary', 'dic_id')->where('word = ?', $word));
         if (!$dic_id) {
             $db->insert('pins_dictionary', array('word' => $word));
             $dic_id = $db->lastInsertId();
         }
         if ($dic_id) {
             $db->insert('pins_invert', array('pin_id' => $data['pin_id'], 'dic_id' => $dic_id));
         }
     }
     Helper_Db::delete('pins_images', array('pin_id = ?' => $data['pin_id']));
     ///////////////// Extension on create //////////////////
     $extensions = Model_Extensions::getByMethod('pin_oncreate');
     if ($extensions) {
         $front = JO_Front::getInstance();
         foreach ($extensions as $id => $ext) {
             $pin_data_ext = call_user_func(array($front->formatModuleName('model_' . $ext . '_pin'), 'oncreate'), $data['pin_id'], $data);
             if ($pin_data_ext && is_array($pin_data_ext)) {
                 $data = array_merge(data, $pin_data_ext);
             }
         }
     }
     ///////////////// Event onComplete /////////////////////
     $trigger = new Helper_Triggers_PinOnCreate();
     $trigger->bind($data['pin_id']);
     $this->data = $data;
     // 		parent::__construct($data);
 }