Esempio n. 1
0
 public function __construct($data = array())
 {
     $db = JO_Db::getDefaultAdapter();
     //select default pin data
     $query = self::getListPinsQuery();
     if (isset($data['filter_description']) && trim($data['filter_description'])) {
         $words = JO_Utf8::str_word_split(mb_strtolower($data['filter_description'], 'utf-8'), self::$searchWordLenght);
         if (count($words) > 0) {
             $sub = "SELECT `dic_id`, `dic_id` FROM `pins_dictionary` `d` WHERE ( ";
             foreach ($words as $key => $word) {
                 if ($key) {
                     $sub .= ' OR ';
                 }
                 $sub .= "`d`.`word` = " . $db->quote($word) . " OR `d`.`word` LIKE " . $db->quote('%' . $word . '%') . "";
             }
             $sub .= ')';
             $dicts = $db->fetchPairs($sub);
             $tmp_dic_ids = array();
             if (COUNT($dicts) > 0) {
                 $query->joinLeft('pins_invert', 'pins.pin_id = pins_invert.pin_id', 'dic_id')->where('pins_invert.`dic_id` IN (' . implode(',', $dicts) . ')')->group('pins.pin_id');
             } else {
                 $query->where('pins.pin_id = 0');
             }
         } else {
             $query->where('pins.pin_id = 0');
         }
     } else {
         $query->where('pins.pin_id = 0');
     }
     //v2.2
     if (Helper_Config::get('config_enable_follow_private_profile')) {
         $query = self::filterFriend($query);
     }
     //sort and limit add to query from Model_Pins_Abstract
     $query = self::sortOrderLimit($query, $data);
     $this->data = $db->fetchAll($query);
     // 		parent::__construct($db->fetchAll($query));
 }
Esempio n. 2
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. 3
0
 /**
  * @param JO_Db_Select $query
  * @param array $data
  * @return JO_Db_Select
  */
 private static function FilterBuilder(JO_Db_Select $query, $data = array())
 {
     $db = JO_Db::getDefaultAdapter();
     if (isset($data['filter_pin_id']) && $data['filter_pin_id']) {
         $query->where('p.pin_id = ?', (string) $data['filter_pin_id']);
     }
     if (isset($data['filter_user_id']) && $data['filter_user_id']) {
         $query->where('p.user_id = ?', (string) $data['filter_user_id']);
     }
     if (isset($data['filter_fullname']) && $data['filter_fullname']) {
         $query->where('u.firstname LIKE ? OR u.lastname LIKE ?', '%' . $data['filter_fullname'] . '%');
     }
     if (isset($data['filter_username']) && $data['filter_username']) {
         $query->where('u.username LIKE ?', '%' . $data['filter_username'] . '%');
     }
     if (isset($data['filter_board']) && $data['filter_board']) {
         $query->where('b.title LIKE ?', '%' . $data['filter_board'] . '%');
     }
     if (isset($data['filter_board_id']) && !is_null($data['filter_board_id'])) {
         $query->where('p.board_id = ?', (string) $data['filter_board_id']);
     }
     if (isset($data['filter_description']) && $data['filter_description']) {
         $words = JO_Utf8::str_word_split(mb_strtolower($data['filter_description'], 'utf-8'), self::$searchWordLenght);
         if (count($words) > 0) {
             $sub = "SELECT `dic_id`, `dic_id` FROM `pins_dictionary` `d` WHERE ( ";
             foreach ($words as $key => $word) {
                 if ($key) {
                     $sub .= ' OR ';
                 }
                 $sub .= "`d`.`word` = " . $db->quote($word) . " OR MATCH(`d`.`word`) AGAINST (" . $db->quote($word) . ")";
             }
             $sub .= ')';
             $dicts = $db->fetchPairs($sub);
             $tmp_dic_ids = array();
             if (COUNT($dicts) > 0) {
                 $query->joinLeft('pins_invert', 'p.pin_id = pins_invert.pin_id', 'dic_id')->where('pins_invert.`dic_id` IN (' . implode(',', $dicts) . ')')->group('p.pin_id');
             } else {
                 $query->where('p.pin_id = 0');
             }
         } else {
             $query->where('p.pin_id = 0');
         }
     }
     return $query;
 }
Esempio n. 4
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);
 }
Esempio n. 5
0
 /**
  * @param JO_Db_Select $query
  * @param array $data
  * @return JO_Db_Select
  */
 private static function FilterBuilder(JO_Db_Select $query, $data = array())
 {
     $db = JO_Db::getDefaultAdapter();
     $ignore_in = false;
     $query->where('pins.store != ""');
     if (isset($data['filter_likes']) && $data['filter_likes']) {
         $ignore_in = true;
     }
     //		if(isset($data['filter_likes']) && $data['filter_likes'] ) {
     ////			$query->where("pins.pin_id IN ( SELECT DISTINCT pin_id FROM pins_likes WHERE user_id = '".$data['filter_likes']."' )");
     //			$query->joinLeft('pins_likes', 'pins.pin_id = pins_likes.pin_id', array())
     //					->where('pins_likes.user_id = ?', $data['filter_likes'])
     //					/*->group('pins.pin_id')*/;
     //			$ignore_in = true;
     //		}
     if (isset($data['filter_pin_id']) && $data['filter_pin_id']) {
         $query->where('pins.pin_id = ?', (string) $data['filter_pin_id']);
     }
     if (isset($data['filter_like_repin_comment']) && $data['filter_like_repin_comment'] === true) {
         $query->where('pins.likes > 0')->where('pins.repins > 0')->where('pins.comments > 0');
     }
     if (isset($data['delete_request']) && $data['delete_request'] === true) {
         $query->where('pins.delete_request = 1');
     }
     if (isset($data['filter_price_from']) && (int) $data['filter_price_from']) {
         $query->where('pins.price >= ?', (int) $data['filter_price_from']);
         $ignore_in = true;
     } elseif (isset($data['allow_gifts'])) {
         $query->where('pins.price > 0.0000');
         $ignore_in = true;
     }
     if (isset($data['filter_id_in']) && $data['filter_id_in']) {
         $query->where('pins.pin_id IN (?)', new JO_Db_Expr($data['filter_id_in']));
         $ignore_in = true;
     }
     if (isset($data['filter_id_not']) && $data['filter_id_not']) {
         $query->where('pins.pin_id NOT IN (?)', new JO_Db_Expr($data['filter_id_not']));
         $ignore_in = true;
     }
     if (isset($data['filter_price_to']) && (int) $data['filter_price_to']) {
         $query->where('pins.price <= ?', (int) $data['filter_price_to']);
         $ignore_in = true;
     }
     if (isset($data['filter_marker']) && (string) $data['filter_marker']) {
         $query->where('pins.pin_id <= ?', (string) $data['filter_marker']);
         $ignore_in = true;
     }
     if (isset($data['filter_repin_from']) && !is_null($data['filter_repin_from'])) {
         $query->where('pins.repin_from = ?', (string) $data['filter_repin_from']);
         $ignore_in = true;
     }
     if (isset($data['filter_source_id']) && !is_null($data['filter_source_id'])) {
         $query->where('pins.source_id = ?', (string) $data['filter_source_id']);
         $ignore_in = true;
     }
     if (isset($data['filter_from']) && !is_null($data['filter_from'])) {
         $query->where('pins.from = ?', $data['filter_from']);
         $ignore_in = true;
     }
     if (isset($data['filter_from_md5']) && !is_null($data['filter_from_md5'])) {
         $query->where('pins.from_md5 = ?', $data['filter_from_md5']);
         $ignore_in = true;
     }
     if (isset($data['filter_category_id']) && !is_null($data['filter_category_id'])) {
         $query->where('pins.category_id = ?', (string) $data['filter_category_id']);
         $ignore_in = true;
     }
     if (isset($data['filter_is_video']) && !is_null($data['filter_is_video'])) {
         $query->where('pins.is_video = ?', (int) $data['filter_is_video']);
         $ignore_in = true;
     }
     if (isset($data['filter_board_id']) && !is_null($data['filter_board_id'])) {
         $query->where('pins.board_id = ?', (string) $data['filter_board_id']);
         $ignore_in = true;
     }
     //		if(isset($data['filter_ub_id']) && !is_null($data['filter_ub_id'])) {
     //			$query->where('pins.ub_id = ?', (string)$data['filter_ub_id']);
     //			$ignore_in = true;
     //		}
     if (isset($data['filter_user_id']) && !is_null($data['filter_user_id'])) {
         $query->where('pins.user_id = ?', (string) $data['filter_user_id']);
         $ignore_in = true;
     }
     if (isset($data['filter_description'])) {
         $words = JO_Utf8::str_word_split(mb_strtolower($data['filter_description'], 'utf-8'), self::$searchWordLenght);
         if (count($words) > 0) {
             /*$sub = "SELECT `i`.`pin_id` FROM `pins_invert` `i`, `pins_dictionary` `d` WHERE `i`.`dic_id` = `d`.`dic_id` AND ( ";
             		foreach($words AS $key => $word) {
             			if($key) {
             				$sub .= ' OR ';
             			}
             			$sub .= "`d`.`word` = " . $db->quote($word) . " OR MATCH(`d`.`word`) AGAINST (" . $db->quote($word) . ")";
             		}
             		$sub .= ')';
             		
             		$query->where('pins.pin_id IN (' . $sub . ')');
             		
             		$sub = "SELECT `dic_id`, `dic_id` FROM `pins_dictionary` `d` WHERE ( ";
             		foreach($words AS $key => $word) {
             			if($key) {
             				$sub .= ' OR ';
             			}
             			$sub .= "`d`.`word` = " . $db->quote($word) . " OR MATCH(`d`.`word`) AGAINST (" . $db->quote($word) . ")";
             		}
             		$sub .= ')';
             		
             		$dicts = $db->fetchPairs($sub);
             		
             		$tmp_dic_ids = array();
             		if(COUNT($dicts) > 0) { 
             			
             			$pins = $db->fetchPairs("SELECT `pin_id`, `pin_id` FROM `pins_invert` `i` WHERE `i`.`dic_id` IN (" . implode(',', $dicts) . ")");
             			
             			if(count($pins) > 0) {
             				$query->where('pins.pin_id IN (' . implode(',', $pins) . ')');
             			} else {
             				$query->where('pins.pin_id = 0');
             			}
             		} else {
             			$query->where('pins.pin_id = 0');
             		}*/
             $sub = "SELECT `dic_id`, `dic_id` FROM `pins_dictionary` `d` WHERE ( ";
             foreach ($words as $key => $word) {
                 if ($key) {
                     $sub .= ' OR ';
                 }
                 $sub .= "`d`.`word` = " . $db->quote($word) . " OR MATCH(`d`.`word`) AGAINST (" . $db->quote($word) . ")";
             }
             $sub .= ')';
             $dicts = $db->fetchPairs($sub);
             $tmp_dic_ids = array();
             if (COUNT($dicts) > 0) {
                 //					$pins = $db->fetchPairs("SELECT `pin_id`, `pin_id` FROM `pins_invert` `i` WHERE `i`.`dic_id` IN (" . implode(',', $dicts) . ")");
                 //$query->where('pins.pin_id IN ( SELECT DISTINCT `pin_id` FROM `pins_invert` `i` WHERE `i`.`dic_id` IN (' . implode(',', $dicts) . ') )');
                 $query->joinLeft('pins_invert', 'pins.pin_id = pins_invert.pin_id', 'dic_id')->where('pins_invert.`dic_id` IN (' . implode(',', $dicts) . ')')->group('pins.pin_id');
                 $ignore_in = true;
             } else {
                 $query->where('pins.pin_id = 0');
             }
         } else {
             $query->where('pins.pin_id = 0');
         }
     }
     if (isset($data['following_users_from_user_id']) && (string) $data['following_users_from_user_id']) {
         if (JO_Session::get('user[following]')) {
             $sql1 = "SELECT following_id FROM users_following_user WHERE user_id = ?";
             $sql = "SELECT p.pin_id FROM `users_following` a, pins p WHERE a.following_id NOT IN(" . $sql1 . ") AND a.`board_id` = p.`board_id`";
             $query->where("((pins.pin_id IN (" . $sql . ") OR pins.user_id IN (" . $sql1 . ")) AND (`board_id` NOT IN (SELECT board_id FROM `users_following_ignore` WHERE following_id IN(" . $sql1 . ") AND user_id = ?))) OR pins.user_id = ?", (string) JO_Session::get('user[user_id]'));
         }
         /*$sql1 = "SELECT following_id FROM users_following_user WHERE user_id = ?";
         //			$sql = "SELECT p.pin_id FROM `users_following` a, `users_boards` b, pins p WHERE
         //					a.following_id NOT IN(" . $sql1 . ") AND a.`board_id`=b.`board_id` AND b.`public`=1 AND a.`board_id` = p.`board_id` AND
         //					(p.pin_id IN (SELECT pin_id FROM pins WHERE public = 1) OR p.user_id=".(string)JO_Session::get('user[user_id]').")";
         //			$sql = "SELECT p.pin_id FROM `users_following` a, `users_following_ignore` c, `boards` b, pins p WHERE
         //					a.following_id NOT IN(" . $sql1 . ") AND a.`board_id`=b.`board_id` AND b.`public`=1 AND a.`board_id` = p.`board_id` AND
         //					(p.pin_id IN (SELECT pin_id FROM pins WHERE public = 1) OR p.user_id=?)";
         			$sql = "SELECT p.pin_id FROM `users_following` a, pins p WHERE a.following_id NOT IN(" . $sql1 . ") AND a.`board_id` = p.`board_id`";
         			$query->where("((pins.pin_id IN (" . $sql . ") OR pins.user_id IN (" . $sql1 . ")) AND (`board_id` NOT IN (SELECT board_id FROM `users_following_ignore` WHERE following_id IN(" . $sql1 . ") AND user_id = ?))) OR pins.user_id = ?", (string)JO_Session::get('user[user_id]'));
         //			$query->where("pins.board_id IN (SELECT board_id FROM users_following WHERE user_id = '" . (string)$data['following_users_from_user_id'] . "')");
         //echo $query; exit;
          			
         			/*$sql = "SELECT board_id FROM users_boards WHERE (
         					  user_id IN (
         					    SELECT following_id FROM users_following_user WHERE user_id = ?
         					  ) 
         					OR
         					  board_id IN (
         					    SELECT board_id FROM users_following WHERE user_id = ?
         					  )
         					)
         					AND
         					board_id NOT IN (
         					  SELECT board_id FROM users_following_ignore WHERE user_id = ?
         					)";
         			$query->where("pins.board_id IN (" . $sql . ") OR pins.user_id = ?", (string)JO_Session::get('user[user_id]'));
         			*/
     } else {
         //			if($ignore_in) {
         //				if((string)JO_Session::get('user[user_id]')) {
         //					$query->where("(pins.public = 1 OR user_id = ".(string)JO_Session::get('user[user_id]').")");
         //				} else {
         //					$query->where("pins.public = 1");
         //				}
         //			} else {
         //				if((string)JO_Session::get('user[user_id]')) {
         //					$query->where("(pins.pin_id IN (SELECT pin_id FROM pins WHERE public = 1)) OR (pins.user_id IN (SELECT DISTINCT user_id FROM pins WHERE user_id = ".(string)JO_Session::get('user[user_id]')."))");
         //				} else {
         //					$query->where("pins.pin_id IN (SELECT pin_id FROM pins WHERE public = 1)");
         //				}
         //			}
     }
     //		echo $query; exit;
     return $query;
 }