示例#1
0
文件: Pin.php 项目: noikiy/amatteur
 public static function returnHtmlDetail($pin, $banners = false)
 {
     //XPER: función que carga PIN
     static $view = null, $model_images = null, $request = null;
     if ($view === null) {
         $view = JO_View::getInstance();
     }
     if ($model_images === null) {
         $model_images = new Helper_Images();
     }
     if ($request === null) {
         $request = JO_Request::getInstance();
     }
     $next_pin = Model_Pins::getNextPin($pin['pin_id']);
     if ($next_pin) {
         $view->next_navigation_pin = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $next_pin['pin_id']);
     }
     $prev_pin = Model_Pins::getPrevPin($pin['pin_id']);
     if ($prev_pin) {
         $view->prev_navigation_pin = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $prev_pin['pin_id']);
     }
     $image = call_user_func(array(self::formatUploadModule($pin['store']), 'getPinImage'), $pin, '_B');
     if ($image) {
         $pin['thumb'] = $image['image'];
         $pin['thumb_width'] = $image['width'];
         $pin['thumb_height'] = $image['height'];
         $pin['original_image'] = $image['original'];
     } else {
         JO_Action::getInstance()->forward('error', 'error404');
     }
     $image = call_user_func(array(self::formatUploadModule($pin['store']), 'getPinImage'), $pin, '_D');
     if ($image) {
         $pin['popup'] = $image['image'];
         $pin['popup_width'] = $image['width'];
         $pin['popup_height'] = $image['height'];
         $pin['original_image'] = $image['original'];
     } else {
         JO_Action::getInstance()->forward('error', 'error404');
     }
     $pin_description = self::descriptionFix($pin['description']);
     $pin['real_description'] = self::descriptionFix($pin['description']);
     $pin['description'] = self::descriptionFix($pin['description']);
     $pin['href'] = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $pin['pin_id']);
     $pin['pinmarklet_href'] = WM_Router::create($request->getBaseUrl() . '?controller=pages&action=read&page_id=' . JO_Registry::get('page_pinmarklet'));
     $pin['onto_href'] = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $pin['user_id'] . '&board_id=' . $pin['board_id']);
     $pin['price_formated'] = WM_Currency::format($pin['price']);
     $view->author = $pin['user'];
     $avatar = Helper_Uploadimages::avatar($pin['user'], '_A');
     $view->author['avatar'] = $avatar['image'];
     $view->author['profile'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $pin['user_id']);
     $view->comments = array();
     if ($pin['latest_comments']) {
         foreach ($pin['latest_comments'] as $key => $comment) {
             if (!isset($comment['user']['store'])) {
                 unset($pin['latest_comments'][$key]);
                 continue;
             }
             $avatar = Helper_Uploadimages::avatar($comment['user'], '_A');
             $comment['user']['avatar'] = $avatar['image'];
             $comment['user']['profile'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $comment['user_id']);
             $comment['delete'] = '';
             if (!Model_Pins::commentIsReported($comment['comment_id'])) {
                 $comment['report'] = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=reportComment&comment_id=' . $comment['comment_id']);
             } else {
                 $comment['report'] = '';
             }
             if (JO_Session::get('user[user_id]')) {
                 if (JO_Session::get('user[is_admin]') || JO_Session::get('user[user_id]') == $comment['user_id'] || JO_Session::get('user[user_id]') == $pin['board_data']['user_id']) {
                     $comment['delete'] = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=deleteComment&comment_id=' . $comment['comment_id']);
                 }
             }
             $view->comments[] = $comment;
         }
     }
     $view->via = array();
     $view->via_repin = array();
     if ($pin['via'] && $pin['user_via']) {
         $view->via = array('profile' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $pin['via']), 'fullname' => $pin['user_via']['fullname']);
     }
     $view->replin_info = false;
     if ($request->isXmlHttpRequest()) {
         $view->target_repin = false;
         if ($pin['repin_from']) {
             $pin_repin = Model_Pins::getPin($pin['repin_from']);
             if ($pin_repin) {
                 $view->source = array();
                 $view->source['source'] = $pin_repin['board'];
                 $pin['from'] = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $pin_repin['user_id'] . '&board_id=' . $pin_repin['board_id']);
                 $view->target_repin = true;
             } else {
                 $view->source = Model_Source::getSource($pin['source_id']);
             }
         } else {
             $view->source = Model_Source::getSource($pin['source_id']);
         }
     } else {
         $view->source = Model_Source::getSource($pin['source_id']);
         if ($pin['repin_from']) {
             $repina = Model_Pins::getPin($pin['repin_from']);
             if ($repina) {
                 $view->replin_info = array('pin_href' => WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $pin['repin_from']), 'profile' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $repina['user_id']), 'fullname' => $repina['user']['fullname']);
             }
         }
     }
     if ($pin['from'] && !preg_match('/^https?:\\/\\//', $pin['from'])) {
         $pin['from'] = 'http://' . $pin['from'];
     }
     if ($pin['from_repin'] && !preg_match('/^https?:\\/\\//', $pin['from_repin'])) {
         $pin['from_repin'] = 'http://' . $pin['from_repin'];
     }
     $pin['onto_board'] = $pin['onto_board2'] = array();
     $pin['originally_pinned'] = $pin['originally_pinned2'] = array();
     if ($request->isXmlHttpRequest()) {
         $pin['onto_board'] = self::getBoardPins($pin['board_id']);
         $pin['originally_pinned'] = self::getOriginallyPinned($pin['via'] ? $pin['via'] : $pin['user_id']);
     } else {
         $pin['onto_board2'] = self::getBoardPins($pin['board_id']);
         $pin['originally_pinned2'] = self::getOriginallyPinned($pin['via'] ? $pin['via'] : $pin['user_id']);
     }
     if ($view->source && $request->isXmlHttpRequest()) {
         $pin['source_pins'] = self::getSourcePins($pin['source_id']);
     } else {
         $pin['source_pins'] = array();
     }
     $pin['boardIsFollow'] = Model_Users::isFollow(array('board_id' => $pin['board_id']));
     $pin['userIsFollow'] = Model_Users::isFollowUser($pin['user_id']);
     if ($pin['via']) {
         $pin['userViaIsFollow'] = Model_Users::isFollowUser($pin['via']);
     } else {
         $pin['userViaIsFollow'] = Model_Users::isFollowUser($pin['user_id']);
     }
     $pin['userFollowIgnore'] = $pin['user_id'] == JO_Session::get('user[user_id]');
     $pin['userViaFollowIgnore'] = ($pin['via'] ? $pin['via'] : $pin['user_id']) == JO_Session::get('user[user_id]');
     $view->follow = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=follow&user_id=' . $pin['user_id'] . '&board_id=' . $pin['board_id']);
     $view->follow_user = WM_Router::create($request->getBaseUrl() . '?controller=users&action=follow&user_id=' . $pin['user_id']);
     if ($pin['via']) {
         $view->follow_user_via = WM_Router::create($request->getBaseUrl() . '?controller=users&action=follow&user_id=' . $pin['via']);
     } else {
         $view->follow_user_via = WM_Router::create($request->getBaseUrl() . '?controller=users&action=follow&user_id=' . $pin['user_id']);
     }
     $view->get_user_friends = WM_Router::create($request->getBaseUrl() . '?controller=users&action=friends');
     if (JO_Session::get('user[user_id]')) {
         $view->enable_follow = $pin['user_id'] != JO_Session::get('user[user_id]');
     } else {
         $view->enable_follow = false;
     }
     if (JO_Session::get('user[user_id]')) {
         $pin['url_like'] = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=like&pin_id=' . $pin['pin_id']);
         $pin['url_repin'] = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=repin&pin_id=' . $pin['pin_id']);
         $pin['url_comment'] = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=comment&pin_id=' . $pin['pin_id']);
         $pin['comment'] = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=comment&pin_id=' . $pin['pin_id']);
         $pin['edit'] = JO_Session::get('user[user_id]') == $pin['user_id'] ? WM_Router::create($request->getBaseUrl() . '?controller=pin&action=edit&pin_id=' . $pin['pin_id']) : false;
     } else {
         $pin['url_like'] = $pin['url_repin'] = $pin['url_comment'] = $pin['comment'] = WM_Router::create($request->getBaseUrl() . '?controller=landing');
         $pin['edit'] = false;
     }
     $likes = self::getPinLikes($pin['pin_id']);
     $pin['likes'] = $likes['data'];
     $pin['likes_total'] = $likes['total'];
     $pin['repins'] = self::getRePins($pin['pin_id']);
     $pin['pinIsReported'] = Model_Pins::pinIsReported($pin['pin_id']);
     $date_dif = array_shift(WM_Date::dateDiff($pin['date_added'], time()));
     $pin['date_dif'] = $date_dif;
     $view->loged = JO_Session::get('user[user_id]');
     $view->site_name = JO_Registry::get('site_name');
     if ($view->loged) {
         $avatar = Helper_Uploadimages::avatar(JO_Session::get('user'), '_A');
         $view->self_avatar = $avatar['image'];
         $view->self_profile = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $view->loged);
         $view->self_fullname = JO_Session::get('user[firstname]') . ' ' . JO_Session::get('user[lastname]');
     }
     if ($pin['is_video']) {
         $auto = new Helper_AutoEmbed();
         if ($pin['repin_from'] && $auto->parseUrl($pin['from_repin'])) {
             $auto->setWidth('100%');
             $auto->setHeight('350');
             $pin['video_code'] = $auto->getEmbedCode();
             $attr = $auto->getObjectAttribs();
             $pin['thumb_width'] = $attr['width'];
             $pin['thumb_height'] = $attr['height'];
         } else {
             if ($auto->parseUrl($pin['from'])) {
                 $auto->setWidth('100%');
                 $auto->setHeight('350');
                 $pin['video_code'] = $auto->getEmbedCode();
                 $attr = $auto->getObjectAttribs();
                 $pin['thumb_width'] = $attr['width'];
                 $pin['thumb_height'] = $attr['height'];
             } else {
                 $pin['is_video'] = false;
             }
         }
     } else {
         $auto = new Helper_AutoEmbed();
         if ($pin['repin_from'] && $auto->parseUrl($pin['from_repin'])) {
             $auto->setWidth('100%');
             $auto->setHeight('350');
             $pin['video_code'] = $auto->getEmbedCode();
             $attr = $auto->getObjectAttribs();
             $pin['thumb_width'] = $attr['width'];
             $pin['thumb_height'] = $attr['height'];
             $pin['is_video'] = true;
         } else {
             if ($auto->parseUrl($pin['from'])) {
                 $auto->setWidth('100%');
                 $auto->setHeight('350');
                 $pin['video_code'] = $auto->getEmbedCode();
                 $attr = $auto->getObjectAttribs();
                 $pin['thumb_width'] = $attr['width'];
                 $pin['thumb_height'] = $attr['height'];
                 $pin['is_video'] = true;
             } else {
                 $pin['is_video'] = false;
             }
         }
     }
     $view->pin_url = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $pin['pin_id']);
     $view->login_href = WM_Router::create($request->getBaseUrl() . '?controller=users&action=login&next=' . urlencode($pin['href']));
     Model_Pins::updateViewed($pin['pin_id']);
     JO_Layout::getInstance()->meta_title = $pin['board'] . ' - ' . strip_tags(html_entity_decode($pin_description));
     JO_Layout::getInstance()->placeholder('pin_url', $view->replin_info ? $view->replin_info['pin_href'] : $view->pin_url);
     JO_Layout::getInstance()->placeholder('pin_description', $pin_description);
     $params = array();
     $params['content'] = html_entity_decode($pin['description'] . ' ' . $pin['board'], ENT_QUOTES, 'UTF-8');
     //page content
     $keywords = new WM_Keywords($params);
     $get_keywords = $keywords->get_keywords();
     if ($get_keywords) {
         JO_Layout::getInstance()->placeholder('keywords', $get_keywords);
     }
     JO_Layout::getInstance()->placeholder('pin_image', $pin['thumb']);
     JO_Layout::getInstance()->placeholder('board_title', $pin['board']);
     $view->banners = array();
     if ($banners) {
         foreach ($banners as $banner1) {
             foreach ($banner1 as $e) {
                 $e['html'] = html_entity_decode($e['html']);
                 $view->banners[] = $e;
             }
         }
     }
     $view->pin = $pin;
     return $view->render('pinBoxDetail', 'pin');
 }