コード例 #1
0
ファイル: Follow.php プロジェクト: NareshChennuri/pyng
 public function __construct($board_id)
 {
     $db = JO_Db::getDefaultAdapter();
     $board_info = new Model_Boards_Board($board_id);
     if (!$board_info->count()) {
         return $this;
     }
     $this->board_id = $board_id;
     $this->user_id = $board_info['user_user_id'];
     if (!(string) JO_Session::get('user[user_id]') || (string) JO_Session::get('user[user_id]') == $board_info['user_user_id']) {
         return $this;
     }
     $query = $db->select()->from('users_following', 'COUNT(users_following_id)')->where('user_id = ?', (string) JO_Session::get('user[user_id]'))->where('board_id = ?', (string) $board_id)->limit(1);
     $is_follow = $db->fetchOne($query);
     if ($is_follow) {
         $query = $db->select()->from('users_following_ignore', 'COUNT(users_following_id)')->where('user_id = ?', (string) JO_Session::get('user[user_id]'))->where('board_id = ?', (string) $board_id)->limit(1);
         $is_follow_disable = $db->fetchOne($query);
         if ($is_follow_disable) {
             $is_follow = false;
         }
     }
     if (!$is_follow) {
         $is_follow_user = $this->isFollowUser($board_info['user_user_id']);
         if ($is_follow_user) {
             $is_follow = true;
         }
     }
     $this->is_follow = $is_follow ? true : false;
 }
コード例 #2
0
ファイル: Delete.php プロジェクト: NareshChennuri/pyng
 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();
     }
 }
コード例 #3
0
 public function __construct($board_id)
 {
     $db = JO_Db::getDefaultAdapter();
     $board_info = new Model_Boards_Board($board_id);
     if ($board_info->count()) {
         $config_private_boards = Helper_Config::get('config_private_boards');
         $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 OR 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) )'), '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 = ?' => (string) $board_id));
     }
 }
コード例 #4
0
ファイル: Autoseo.php プロジェクト: NareshChennuri/pyng
 public function __construct($board_id)
 {
     $db = JO_Db::getDefaultAdapter();
     $board_info = new Model_Boards_Board($board_id);
     if (!$board_info->count()) {
         return $this;
     }
     if (($cleared = trim($this->clear($board_info['board_title']))) != '') {
         $slug = $uniqueSlug = $cleared;
     } else {
         $slug = $uniqueSlug = 'user-board';
     }
     Helper_Db::delete('url_alias', array('query = ?' => 'board_id=' . $board_id));
     $uniqueSlug = $this->renameIfExist($uniqueSlug);
     Helper_Db::insert('url_alias', array('query' => 'board_id=' . (int) $board_id, 'keyword' => $uniqueSlug, 'path' => $uniqueSlug, 'route' => 'boards/view'));
 }
コード例 #5
0
 public function __construct($title, $user_id = 0, $category_id = 0)
 {
     $db = JO_Db::getDefaultAdapter();
     $user_id = $user_id ? $user_id : JO_Session::get('user[user_id]');
     //select default pin data
     $query = self::getListBoardsQuery();
     $query->where('boards.title LIKE ?', $title)->where('boards.user_id = ?', $user_id);
     $query->limit(1);
     $response = $db->fetchRow($query);
     if (!$response) {
         $result = new Model_Boards_Create(array('title' => $title, 'category_id' => $category_id, 'user_id' => $user_id));
         if ($result->board_id) {
             $board_data = new Model_Boards_Board($result->board_id);
             if ($board_data) {
                 $response = $board_data->toArray();
             }
         }
     }
     $response = is_array($response) ? $response : array();
     parent::__construct($response);
 }
コード例 #6
0
 public function getPinsAction($return_data = false)
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $page = (int) $request->getRequest('page');
     if ($page < 1) {
         $page = 1;
     }
     $pp = (int) Helper_Config::get('config_front_limit');
     if (!(int) $pp) {
         $pp = 50;
     }
     if ((int) $request->getRequest('per_page') > 0 && (int) $request->getRequest('per_page') < 300) {
         $pp = (int) $request->getRequest('per_page');
     }
     $data = array('start' => $pp * $page - $pp, 'limit' => $pp);
     $return = array();
     //Recent Activity
     if ($page == 1 && JO_Session::get('user[user_id]')) {
         $history_data = Model_History_Activity::getHistoryV2(array('start' => 0, 'limit' => 10, 'sort' => 'DESC', 'order' => 'history_id'));
         $history = array();
         foreach ($history_data as $row) {
             $user_avatars = Helper_Uploadimages::userAvatars(array('avatar' => $row['user_avatar'], 'store' => $row['user_store'], 'user_id' => $row['user_user_id']));
             $haystack_pins = array(Model_History_Abstract::REPIN, Model_History_Abstract::ADDPIN, Model_History_Abstract::COMMENTPIN, Model_History_Abstract::LIKEPIN);
             $text = $row['history_text_type'];
             $href_pin = false;
             /*if( in_array($row['history_history_action'], $haystack_pins) ) {
             // 				if($row['history_history_action'] == Model_History_Abstract::REPIN) {
             					$href = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $row['history_pin_id']);
             				} else {*/
             $href = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $row['history_from_user_id']);
             if (Model_History_Abstract::REPIN == $row['history_history_action']) {
                 $text = array($this->translate('repinned your'), $this->translate('pin'), 1);
                 $href_pin = WM_Router::pinAction($row['history_pin_id']);
             } elseif (Model_History_Abstract::LIKEPIN == $row['history_history_action']) {
                 $text = array($this->translate('like your'), $this->translate('pin'), 1);
                 $href_pin = WM_Router::pinAction($row['history_pin_id']);
             } elseif (Model_History_Abstract::UNLIKEPIN == $row['history_history_action']) {
                 $text = array($this->translate('unlike your'), $this->translate('pin'), 1);
                 $href_pin = WM_Router::pinAction($row['history_pin_id']);
             } elseif (Model_History_Abstract::COMMENTPIN == $row['history_history_action']) {
                 $text = array($this->translate('comment your'), $this->translate('pin'), 1);
                 $href_pin = WM_Router::pinAction($row['history_pin_id']);
             } elseif (Model_History_Abstract::FOLLOW == $row['history_history_action']) {
                 $board_info = new Model_Boards_Board($row['history_board_id']);
                 if ($board_info->count()) {
                     $text = array($this->translate('is now following your'), $board_info['board_title']);
                     $href_pin = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $board_info['board_user_id'] . '&board_id=' . $board_info['board_board_id']);
                 }
             } elseif (Model_History_Abstract::UNFOLLOW == $row['history_history_action']) {
                 $board_info = new Model_Boards_Board($row['history_board_id']);
                 if ($board_info->count()) {
                     $text = array($this->translate('has unfollow your'), $board_info['board_title']);
                     $href_pin = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $board_info['board_user_id'] . '&board_id=' . $board_info['board_board_id']);
                 }
             }
             //}
             $history[] = array('history_id' => $row['history_history_id'], 'date_added' => $row['history_date_added'], 'profile' => array('fullname' => $row['user_fullname'], 'avatars' => $user_avatars), 'href' => $href, 'href_pin' => $href_pin, 'text_type' => $text, 'text_date_dif' => sprintf($this->translate('%d %s ago'), $row['history_date_dif']['value'], $this->translate($row['history_date_dif']['key'])));
         }
         if ($history) {
             $return[] = array('template' => 'home_history', 'history' => $history, 'text_title_box' => $this->translate('Recent Activity'));
         }
     }
     // pins data
     $pins = new Model_Pins_HomePage($data);
     //format response data
     $formatObject = new Helper_Format();
     if ($pins->count()) {
         $banners = Model_Banners::getBanners(new JO_Db_Expr("`controller` = '" . $request->getController() . "' AND position >= '" . (int) $data['start'] . "' AND position <= '" . (int) ($data['start'] + $pp) . "'"));
         foreach ($pins->data as $row => $pin) {
             ///banners
             $key = $row + ($pp * $page - $pp);
             if (isset($banners[$key]) && $banners[$key]) {
                 if (($banners_result = $formatObject->fromatListBanners($banners[$key])) !== false) {
                     $return[] = $banners_result;
                 }
             }
             //pins
             $return[] = $formatObject->fromatList($pin);
         }
     } else {
         if ($page == 1) {
             $message = $this->translate('No pyngs!');
         } else {
             $message = $this->translate('No more pyngs!');
         }
         $return[] = $formatObject->fromatListNoResults($message);
     }
     if ($return_data) {
         return $return;
     }
     $formatObject->responseJsonCallback($return);
     $this->noViewRenderer(true);
 }
コード例 #7
0
ファイル: Edit.php プロジェクト: NareshChennuri/pyng
 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();
     }
 }
コード例 #8
0
 public function allowInvateAction()
 {
     $this->noViewRenderer(true);
     $request = $this->getRequest();
     if (!JO_Session::get('user[user_id]')) {
         $this->redirect(WM_Router::create($request->getBaseUrl()));
     }
     if ($request->getRequest('board_id') && $request->getRequest('type')) {
         $board_info = new Model_Boards_Board($request->getRequest('board_id'));
         if ($board_info->count()) {
             $users = explode(',', $board_info['board_users_not_allow']);
             if (in_array(JO_Session::get('user[user_id]'), $users)) {
                 if ($request->getRequest('type') == 'accept') {
                     Model_Boards::acceptUsersBoard($request->getRequest('board_id'));
                 } elseif ($request->getRequest('type') == 'decline') {
                     Model_Boards::deleteUsersBoard($request->getRequest('board_id'));
                 }
             }
         }
     }
     $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . JO_Session::get('user[user_id]')));
 }
コード例 #9
0
ファイル: PinController.php プロジェクト: NareshChennuri/pyng
 public function getOtherDataAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $pin_id = $request->getRequest('pin_id');
     $pin_info = new Model_Pins_Pin($pin_id);
     $return = array();
     $formatObject = new Helper_Format();
     if ($pin_info->count()) {
         $pin_info = $pin_info->data;
         $pin_info = array_merge((array) $pin_info, Helper_Pin::formatPinData((array) $pin_info));
         $loged = JO_Session::get('user[user_id]');
         /* v2.2 */
         $config_enable_follow_private_profile = Helper_Config::get('config_enable_follow_private_profile');
         if ($config_enable_follow_private_profile) {
             $user_enable_follow = $pin_info['via_user_id'] ? $pin_info['via_enable_follow'] : $pin_info['user_enable_follow'];
         } else {
             $user_enable_follow = true;
         }
         /* v2.2 */
         $return = array('loged' => $loged, 'enable_follow_board' => $loged ? $pin_info['board_user_id'] != $loged && $user_enable_follow : false, 'enable_follow_user' => $loged ? $pin_info['user_user_id'] != $loged && $user_enable_follow : false, 'enable_follow_via' => $loged ? ($pin_info['via_user_id'] ? $pin_info['via_user_id'] : $pin_info['user_user_id']) != $loged && $user_enable_follow : false, 'board_is_follow' => $pin_info['following_board'], 'via_is_follow' => $pin_info['via_user_id'] ? $pin_info['following_via'] : $pin_info['following_user'], 'pin_likes' => $pin_info['pin_likes'], 'pin_likes_total' => $pin_info['pin_likes'] > 20 ? $pin_info['pin_likes'] - 20 : 0, 'user_follow_href' => $pin_info['user_follow_href'], 'board_follow_href' => $pin_info['board_follow_href'], 'via_follow_href' => $pin_info['via_follow_href'], 'text_unfollow' => $this->translate('Unfollow'), 'text_follow' => $this->translate('Follow'), 'text_likes' => $this->translate('Likes'), 'text_repins' => $this->translate('Repins'), 'text_onto_board' => $this->translate('Pinned onto the board'), 'text_onto' => $this->translate('onto'), 'text_originally_pinned' => $this->translate('Originally pinned by'), 'text_pined_via' => sprintf($this->translate('Pinned via %s from'), Helper_Config::get('site_name')), 'pin_likes_total_text' => sprintf($this->translate('+%d more likes'), $pin_info['pin_likes'] - 20));
         //other pins from board
         $return['onto_board'] = false;
         $pins = new Model_Pins_Boards(array('start' => 0, 'limit' => 12, 'filter_board_id' => $pin_info['pin_board_id']));
         if ($pins->count()) {
             $board_info = new Model_Boards_Board($pin_info['pin_board_id']);
             if ($board_info->count()) {
                 $href = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $pin_info['pin_user_id'] . '&board_id=' . $pin_info['pin_board_id']);
                 $return['onto_board'] = array('pins' => array(), 'url' => $href, 'name' => $pin_info['board_title'], 'user_id' => $board_info['user_user_id']);
                 $total = $pins->count();
                 foreach ($pins->data as $row => $pin) {
                     $pin['pin_id'] = $pin['pin_pin_id'];
                     $key = false;
                     if ($row == 0) {
                         $key = 'first';
                     } else {
                         if ($row == $total - 1) {
                             $key = 'last';
                         }
                     }
                     $return['onto_board']['pins'][] = array('images' => Helper_Uploadimages::pinThumbs($pin), 'href' => $href, 'key' => $key);
                 }
             }
         }
         // others pin from via or user
         $return['originally_pinned'] = false;
         $pins = new Model_Pins_Users(array('start' => 0, 'limit' => 6, 'filter_user_id' => $pin_info['via_user_id'] ? $pin_info['via_user_id'] : $pin_info['pin_user_id']));
         if ($pins->count()) {
             $href = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . ($pin_info['via_user_id'] ? $pin_info['via_user_id'] : $pin_info['pin_user_id']));
             $return['originally_pinned'] = array('pins' => array(), 'url' => $href, 'name' => $pin_info['via_user_id'] ? $pin_info['via_fullname'] : $pin_info['user_fullname'], 'via' => $pin_info['via_user_id'] ? true : false, 'user_id' => $pin_info['via_user_id'] ? $pin_info['via_user_id'] : $pin_info['pin_user_id']);
             $total = $pins->count();
             foreach ($pins->data as $row => $pin) {
                 $pin['pin_id'] = $pin['pin_pin_id'];
                 $key = false;
                 if ($row == 0) {
                     $key = 'first';
                 } else {
                     if ($row == $total - 1) {
                         $key = 'last';
                     }
                 }
                 $return['originally_pinned']['pins'][] = array('images' => Helper_Uploadimages::pinThumbs($pin), 'href' => $href, 'key' => $key);
             }
         }
         // others pin from source
         $return['source'] = false;
         if ($pin_info['pin_source_id']) {
             $pins = new Model_Pins_Source(array('start' => 0, 'limit' => 5, 'filter_source_id' => $pin_info['pin_source_id']));
             if ($pins->count()) {
                 $href = WM_Router::create($request->getBaseUrl() . '?controller=source&source_id=' . $pin_info['pin_source_id']);
                 $return['source'] = array('pins' => array(), 'url' => $href, 'name' => $pin_info['source_source']);
                 $total = $pins->count();
                 foreach ($pins->data as $row => $pin) {
                     $pin['pin_id'] = $pin['pin_pin_id'];
                     $key = false;
                     if ($row == 0) {
                         $key = 'first';
                     } else {
                         if ($row == $total - 1) {
                             $key = 'last';
                         }
                     }
                     $return['source']['pins'][] = array('images' => Helper_Uploadimages::pinThumbs($pin), 'href' => $href, 'key' => $key);
                 }
             }
         }
         // others pin likes
         $return['users_likes'] = false;
         if ($pin_info['pin_likes']) {
             $users = new Model_Users_LikesPin(array('start' => 0, 'limit' => 20, 'filter_like_pin_id' => $pin_info['pin_id']));
             if ($users->count()) {
                 $total = $users->count();
                 foreach ($users as $row => $user) {
                     $user['pin_id'] = $pin['pin_pin_id'];
                     $key = false;
                     if ($row == 0) {
                         $key = 'first';
                     } else {
                         if ($row == $total - 1) {
                             $key = 'last';
                         }
                     }
                     $return['users_likes'][] = array('avatars' => Helper_Uploadimages::userAvatars($user), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $user['user_id']), 'fullname' => $user['fullname'], 'key' => $key);
                 }
             }
         }
         // others pin from source
         $return['users_repins'] = false;
         if ($pin_info['pin_repins']) {
             $pins = new Model_Pins_Repins(array('start' => 0, 'limit' => 6, 'filter_like_pin_id' => $pin_info['pin_id']));
             if ($pins->count()) {
                 $total = $pins->count();
                 foreach ($pins->data as $row => $pin) {
                     $pin['pin_id'] = $pin['pin_pin_id'];
                     $key = false;
                     if ($row == 0) {
                         $key = 'first';
                     } else {
                         if ($row == $total - 1) {
                             $key = 'last';
                         }
                     }
                     $return['users_repins'][$pin['user_user_id']] = array('user' => array('fullname' => $pin['user_fullname'], 'avatars' => Helper_Uploadimages::userAvatars(array('avatar' => $pin['user_avatar'], 'store' => $pin['user_store'], 'user_id' => $pin['user_user_id'])), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $pin['user_user_id'])), 'board' => array('name' => $pin['board_title'], 'href' => WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $pin['user_user_id'] . '&board_id=' . $pin['board_board_id'])), 'key' => $key);
                 }
             }
         }
     }
     //format response data
     $formatObject = new Helper_Format();
     $formatObject->responseJsonCallback($return);
     $this->noViewRenderer(true);
 }
コード例 #10
0
ファイル: Edit.php プロジェクト: NareshChennuri/pyng
 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();
     }
 }
コード例 #11
0
ファイル: Create.php プロジェクト: NareshChennuri/pyng
 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);
 }
コード例 #12
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');
     }
 }
コード例 #13
0
 public function pinMediaCheckAction()
 {
     $request = $this->getRequest();
     $this->view->media = array();
     if (JO_Session::get('user[user_id]')) {
         $media_ids = $request->getPost('media_id');
         $board_info = new Model_Boards_Board($request->getPost('board_id'));
         if (is_array($media_ids) && count($media_ids) > 0) {
             if ($board_info->count()) {
                 $data = array('filter_user_id' => JO_Session::get('user[user_id]'), 'media_id_in' => $media_ids, 'limit' => 'none');
                 $meduas = Model_Instagram_Media::getUserMediasData($data);
                 $medias = array();
                 foreach ($meduas as $image) {
                     $medias[] = $image['media_id'];
                 }
                 $instagram_media = array('media_id' => $medias, 'board_id' => $board_info['board_board_id']);
                 if ($medias) {
                     JO_Session::set('instagram_media', $instagram_media);
                     $this->view->location = WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=modules_instagram_media&action=pinMedia');
                 } else {
                     $this->view->error = $this->translate('You must select media to pinit!');
                 }
             } else {
                 $this->view->error = $this->translate('You must select board to pinit!');
             }
         } else {
             $this->view->error = $this->translate('You must select media to pinit!');
         }
     } else {
         $this->view->location = WM_Router::create($request->getBaseUrl() . '?controller=users&action=login');
     }
     echo $this->renderScript('json');
 }