示例#1
0
 public function pindetailAction()
 {
     $this->noViewRenderer(true);
     $request = $this->getRequest();
     $response = $this->getResponse();
     $page = (int) $request->getRequest('page');
     if ($page < 1) {
         $page = 1;
     }
     $limit = (int) $request->getRequest('limit');
     if ($limit < 1 || $limit > 100) {
         $limit = 50;
     }
     //$limit = JO_Registry::get('config_front_limit'); }
     $callback = $request->getRequest('callback');
     if (!preg_match('/^([a-z0-9_.]{1,})$/', $callback)) {
         $callback = false;
     }
     $data = array('start' => $limit * $page - $limit, 'limit' => $limit);
     $url = '&limit=' . $limit . '&page=' . ($page + 1);
     /*
      if($request->getRequest('popular') == 'true') {
      $data['filter_like_repin_comment'] = true;
      $url .= '&popular=true';
      }
      if( (int)$request->getRequest('fromPrice') ) {
      $data['filter_price_from'] = (int)$request->getRequest('fromPrice');
      $url .= '&fromPrice=' . (int)$request->getRequest('fromPrice');
      }
      if( (int)$request->getRequest('toPrice') ) {
      $data['filter_price_to'] = (int)$request->getRequest('toPrice');
      $url .= '&toPrice=' . (int)$request->getRequest('toPrice');
      }
      if( $request->getRequest('source') ) {
      $data['filter_source_id'] = $request->getRequest('source');
      $url .= '&source=' . $request->getRequest('source');
      }
     * 
     */
     if ($request->getRequest('pinId')) {
         $data['filter_pin_id'] = $request->getRequest('pinId');
         $url .= '&pinId=' . $request->getRequest('pinId');
     }
     /*
      if($request->issetRequest('video')) {
      $data['filter_is_video'] = (int)$request->getRequest('video');
      $url .= '&video=' . (int)$request->getRequest('video');
      }
      if( $request->getRequest('board') ) {
      $data['filter_board_id'] = $request->getRequest('board');
      $url .= '&board=' . $request->getRequest('board');
      }
     * 
     */
     if ($request->getRequest('userId')) {
         $data['filter_user_id'] = $request->getRequest('userId');
         $url .= '&user='******'userId');
     }
     /*
      if( $request->getRequest('search') ) {
      $data['filter_description'] = $request->getRequest('search');
      $url .= '&search=' . urlencode($request->getRequest('search'));
      }
      if( $request->getRequest('following') == 'true' ) {
      if(( $user_data = $this->isLoged() ) !== false) {
      $data['following_users_from_user_id'] = $user_data['user_id'];
      $url .= '&following=true';
      }
      }
     */
     $return = array();
     if (!$this->error) {
         $pins = Model_Pins::getPinsAPP($data);
         if ($pins) {
             $model_images = new Helper_Images();
             foreach ($pins as $pin) {
                 $images = array();
                 $image = call_user_func(array(Helper_Pin::formatUploadModule($pin['store']), 'getPinImage'), $pin, '_B');
                 if ($image) {
                     $images['thumb']['src'] = $image['image'];
                     $images['thumb']['width'] = $image['width'];
                     $images['thumb']['height'] = $image['height'];
                     $images['original'] = $image['original'];
                 }
                 $categorias = array();
                 $categories = Model_Categories::getCategory($pin['category_id']);
                 if ($categories['parent_id'] != 0) {
                     $categorias['category_id'] = $categories['parent_id'];
                     $categorias['subcategory_id'] = $categories['category_id'];
                 } else {
                     $categorias['category_id'] = $categories['category_id'];
                     $categorias['subcategory_id'] = $categories['parent_id'];
                 }
                 //error_log("datos entrada ". $pin['pin_id'] ."-". $pin['user_id']);
                 $boards = Model_Boards::getBoardAPP($pin['board_id'], $pin['user_id'], "", WM_Router::create($request->getBaseUrl()), "pindetail");
                 $comments = Model_Pins::commentIsReportedAPP($pin['pin_id'], $pin['user_id']);
                 $likes = Model_Pins::pinIsLikedAPP($pin['pin_id']);
                 $shared = Model_Pins::repinAPP($pin['pin_id']);
                 $next_pin = Model_Pins::getNextPin($pin['pin_id']);
                 $next = "";
                 if ($next_pin) {
                     $next = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $next_pin['pin_id']);
                 }
                 $prev_pin = Model_Pins::getPrevPin($pin['pin_id']);
                 $prev = "";
                 if ($prev_pin) {
                     $prev = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $prev_pin['pin_id']);
                 }
                 //                                            error_log("valor boarder ". $comments,0)  ;
                 //                                        if($comments)
                 //                                        {
                 //                                            error_log("valor board ". $comments,0)  ;
                 //                                        foreach ($comments as &$value)
                 //                                        {
                 //                                            error_log("valor board ". $value["title"],0)  ;
                 //                                        }
                 //                                        }
                 $pos = strripos($pin['image'], '.');
                 $return['data'][] = array('pin_id' => $pin['pin_id'], 'pinFooter' => $pin['description'], 'category_id' => $categorias['category_id'], 'subcategory_id' => $categorias['subcategory_id'], 'pinImage' => substr_replace($pin['image'], '_B.', $pos, 1), 'pinWidth' => $pin['width'], 'pinHeight' => $pin['height'], 'pinUrl' => WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $pin['pin_id']), 'comments' => $comments ? $comments : "", 'likes' => $likes ? $likes : "", 'folder' => $boards ? array($boards['title'], WM_Router::create($request->getBaseUrl() . $pin['username'] . "/" . $boards['title']), $boards['image']) : "", 'shared' => $shared ? $shared : "", 'next' => $next ? $next : "", 'previous' => $prev ? $prev : "", 'userId' => $pin['user_id'], 'username' => $pin['username'], 'avatar' => $pin['avatar'], 'userLike' => $pin['liked'], 'pinVideo' => $pin['from']);
             }
             $return['next_page'] = WM_Router::create($request->getBaseUrl() . '?controller=apiv1&action=pindetail' . $url);
         }
     } else {
         $return = array('error' => $this->error);
     }
     if ($callback) {
         $return = $callback . '(' . JO_Json::encode($return) . ')';
     } else {
         $response->addHeader('Cache-Control: no-cache, must-revalidate');
         $response->addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
         $response->addHeader('Content-type: application/json');
         $return = JO_Json::encode($return);
     }
     $response->appendBody($return);
 }