示例#1
0
 public function indexAction()
 {
     //		var_dump( htmlspecialchars('⚐') );exit;
     $request = $this->getRequest();
     $pin_id = $request->getRequest('pin_id');
     $pin_info = Model_Pins::getPin($pin_id);
     if (!$pin_info) {
         $this->forward('error', 'error404');
     }
     if ($request->isPost()) {
         $data = $request->getParams();
         $write_comment = $request->getPost('write_comment');
         if (JO_Session::get('user[user_id]') && $request->issetPost('friends') && is_array($request->getPost('friends'))) {
             foreach ($request->getPost('friends') as $user_id => $fullname) {
                 if (Model_Users::isFriendUser($user_id, JO_Session::get('user[user_id]'))) {
                     $profile = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $user_id);
                     $write_comment = preg_replace('/\\@' . $fullname . '/i', ' <a class="link comment-user-profile" href="' . $profile . '">@' . $fullname . '</a> ', $write_comment);
                 }
             }
         }
         $data['write_comment'] = $write_comment;
         if ($request->isXmlHttpRequest()) {
             if (JO_Session::get('user[user_id]')) {
                 $result = Model_Pins::addComment($data, $pin_info['latest_comments'], Model_Users::$allowed_fields);
                 $this->view = JO_View::getInstance()->reset();
                 if ($result) {
                     $avatar = Helper_Uploadimages::avatar($result['user'], '_A');
                     $result['user']['avatar'] = $avatar['image'];
                     $result['user']['profile'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $result['user_id']);
                     $this->view->ok = true;
                     $result['pin'] = self::getPinStat($pin_id);
                     if (JO_Session::get('user[user_id]')) {
                         if (JO_Session::get('user[is_admin]') || JO_Session::get('user[user_id]') == $result['user_id']) {
                             $result['delete_comment'] = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=deleteComment&comment_id=' . $result['comment_id']);
                         }
                     }
                     if ($request) {
                         Model_History::addHistory($pin_info['user_id'], Model_History::COMMENTPIN, $pin_id, 0, $request->getPost('write_comment'));
                         if ($pin_info['user']['email_interval'] == 1 && $pin_info['user']['comments_email']) {
                             $this->view->user_info = $pin_info['user'];
                             $this->view->text_email = $this->translate('comment your');
                             $this->view->profile_href = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . JO_Session::get('user[user_id]'));
                             $this->view->full_name = JO_Session::get('user[firstname]') . ' ' . JO_Session::get('user[lastname]');
                             $this->view->pin_href = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $pin_id);
                             Model_Email::send($pin_info['user']['email'], JO_Registry::get('noreply_mail'), JO_Session::get('user[firstname]') . ' ' . JO_Session::get('user[lastname]') . ' ' . $this->translate('comment your pin'), $this->view->render('comment_pin', 'mail'));
                         }
                     }
                     $this->view->comment = $result;
                 } else {
                     $this->view->error = $this->translate('There was a problem with the record. Please try again!');
                 }
             } else {
                 $this->view->location = WM_Router::create($request->getBaseUrl() . '?controller=landing');
             }
             echo $this->renderScript('json');
             exit;
         } else {
             if (JO_Session::get('user[user_id]')) {
                 $result = Model_Pins::addComment($data, $pin_info['latest_comments']);
                 $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $pin_id));
             } else {
                 $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=landing'));
             }
         }
     }
     $this->view->show_buttonswrapper = true;
     $this->view->url_like = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=like&pin_id=' . $pin_id);
     $this->view->url_tweet = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $pin_id);
     $this->view->url_embed = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=embed&pin_id=' . $pin_id);
     $this->view->url_report = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=report&pin_id=' . $pin_id);
     $this->view->url_email = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=email&pin_id=' . $pin_id);
     $this->view->url_repin = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=repin&pin_id=' . $pin_id);
     $this->view->url_comment = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=comment&pin_id=' . $pin_id);
     $banners = Model_Banners::getBanners(new JO_Db_Expr("`controller` = '" . $request->getController() . "'"));
     if ($request->isXmlHttpRequest()) {
         $this->view->popup = true;
         echo Helper_Externallinks::fixExternallinks(Helper_Pin::returnHtmlDetail($pin_info, $banners));
         $this->noViewRenderer(true);
     } else {
         $this->view->pins_details = Helper_Pin::returnHtmlDetail($pin_info, $banners);
         JO_Registry::set('pin_info', $pin_info);
         $this->view->children = array('header_part' => 'layout/header_part', 'footer_part' => 'layout/footer_part', 'left_part' => 'pin/left_part');
     }
 }
示例#2
0
 public function indexAction()
 {
     ini_set('memory_limit', '4200M');
     $this->noViewRenderer(true);
     ignore_user_abort(true);
     for ($i = 1; $i < 5; $i++) {
         $html = @file_get_contents('http://pinterest.com/?page=' . $i);
         if ($html) {
             $dom = new JO_Html_Dom();
             $dom->load($html);
             $hrefs = $dom->find('.PinImage');
             if ($hrefs) {
                 foreach ($hrefs as $href) {
                     $price = 0;
                     $url = JO_Url_Relativetoabsolute::toAbsolute('http://pinterest.com/?page=' . $i, $href->href);
                     $html2 = @file_get_contents($url);
                     if ($html2) {
                         $dom = new JO_Html_Dom();
                         $dom->load($html2);
                         $board = $dom->find('h3.serif a', 0)->innertext;
                         $image = $dom->find('#pinCloseupImage', 0)->src;
                         $description = $dom->find('#PinCaption', 0)->innertext;
                         $description = explode('<', $description);
                         $description = $description[0];
                         $from = $dom->find('#PinSource a', 0)->href;
                         $usernames = $dom->find('#PinnerName a', 0)->innertext;
                         $avatar = $dom->find('#PinnerImage img', 0)->src;
                         $username = trim($dom->find('#PinnerName a', 0)->href, '/');
                         $price_o = $dom->find('.buyable', 0);
                         if ($price_o) {
                             $price = $price_o->innertext;
                         }
                         $user_id = Model_Users::getUserByName($username, $usernames, $avatar);
                         if (!$user_id) {
                             continue;
                         }
                         WM_Users::initSession($user_id);
                         $board_id = Model_Boards::getBoardId(trim($board));
                         $price_f = 0;
                         if (preg_match('/([0-9.]{1,})/', $price, $m)) {
                             $price_f = $m[1];
                         }
                         $pin_id = Model_Pins::create(array('board_id' => $board_id, 'description' => htmlspecialchars($description, ENT_QUOTES, 'utf-8'), 'image' => (string) $image, 'price' => (double) $price, 'from' => urldecode($from), 'public' => '1'));
                         $commm = $dom->find('.PinComments .comment');
                         if ($commm) {
                             foreach ($commm as $com) {
                                 $avatar = $com->find('.CommenterImage img', 0)->src;
                                 $usernames = $com->find('.CommenterName', 0)->innertext;
                                 $username = trim($com->find('.CommenterName', 0)->href, '/');
                                 $text = explode('<br />', $com->find('.CommenterMeta', 0)->innertext);
                                 $text = isset($text[1]) ? $text[1] : '';
                                 if ($text) {
                                     $user_id = Model_Users::getUserByName($username, $usernames, $avatar);
                                     if (!$user_id) {
                                         continue;
                                     }
                                     WM_Users::initSession($user_id);
                                     $pin_info = Model_Pins::getPin($pin_id);
                                     Model_Pins::addComment(array('write_comment' => $text, 'pin_id' => $pin_id), $pin_info['latest_comments']);
                                 }
                             }
                             sleep(1);
                         }
                         sleep(1);
                     }
                 }
             }
         }
     }
 }