Exemple #1
0
 public static function getBoardAPP($board_id, $user_id, $username, $url_base, $origen)
 {
     $db = JO_Db::getDefaultAdapter();
     $board = array();
     //carpeta
     if ($origen == "carpeta") {
         //error_log("valor board-". $board_id. "-origen " .$origen,0)  ;
         $query = $db->select()->from('boards')->where('boards.board_id = ?', (int) $board_id);
         $board_id = $db->fetchRow($query);
         if ($board_id) {
             $elemento = $board_id;
             //error_log("valor board ". $board_id,0)  ;
             //foreach($board_id AS $elemento)
             //{
             $username = Model_Users::getUsername($elemento["user_id"]);
             //error_log("valor elemento ". $elemento["title"],0)  ;
             $board['data'][] = array("folderName" => $elemento["title"], "folderUrl" => $url_base . $username . "/" . $elemento['title'], "folderImage" => $elemento["image"]);
             //}
         }
     } elseif ($origen == "pindetail") {
         $query = $db->select()->from('boards')->where('boards.board_id = ?', (int) $board_id)->where('boards.user_id = ?', (int) $user_id);
         $board = $db->fetchRow($query);
         //error_log("valor board-". $board_id['title']. "-origen " .$origen,0)  ;
     } elseif ($origen == "userinfo") {
         $query = $db->select()->from('boards')->where('boards.user_id = ?', (int) $user_id);
         $board_id = $db->fetchAll($query);
         //error_log("valor board ". $board_id,0)  ;
         if ($board_id) {
             //error_log("valor board ". $board_id,0)  ;
             foreach ($board_id as $elemento) {
                 //error_log("valor elemento ". $elemento["title"],0)  ;
                 $board['data'][] = array("folderName" => $elemento["title"], "folderUrl" => $url_base . $username . "/" . $elemento['title'], "folderImage" => $elemento["image"], "folderQty" => $elemento["pins"]);
             }
         }
     } elseif ($origen == "folders") {
         $query = $db->select()->from('boards')->where('boards.user_id = ?', (int) $user_id);
         $board_id = $db->fetchAll($query);
         //error_log("valor board ". $board_id,0)  ;
         if ($board_id) {
             //error_log("valor board ". $board_id,0)  ;
             foreach ($board_id as $elemento) {
                 //error_log("valor elemento ". $elemento["title"],0)  ;
                 $board['data'][] = array("folderid" => $elemento["board_id"], "folderName" => $elemento["title"], "folderUrl" => $url_base . $username . "/" . $elemento['title'], "folderImage" => $elemento["image"]);
             }
         }
     }
     return $board;
 }
Exemple #2
0
 public function searchAction()
 {
     $this->noViewRenderer(true);
     $request = $this->getRequest();
     $response = $this->getResponse();
     $page = (int) $request->getRequest('page');
     if ($page < 1) {
         $page = 1;
     }
     $callback = $request->getRequest('callback');
     if (!preg_match('/^([a-z0-9_.]{1,})$/', $callback)) {
         $callback = false;
     }
     $data = array();
     $url = "";
     $return = array();
     $kind = $request->getRequest('kind');
     $query = $request->getRequest('query');
     $userId = $request->getRequest('userId');
     if ($kind == 0) {
         // pins
         $data = array('start' => JO_Registry::get('config_front_limit') * $page - JO_Registry::get('config_front_limit'), 'limit' => JO_Registry::get('config_front_limit'), 'filter_description' => $query, 'filter_marker' => $request->getRequest('marker'));
         $this->view->pins = '';
         $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'];
                 }
                 $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']), '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=timeline' . $url);
         }
     } else {
         if ($kind == 1) {
             //boards
             $data = array('start' => JO_Registry::get('config_front_limit') * $page - JO_Registry::get('config_front_limit'), 'limit' => JO_Registry::get('config_front_limit'), 'filter_title' => $query);
             $this->view->pins = '';
             $boards = Model_Boards::getBoards($data);
             if ($boards) {
                 $view = JO_View::getInstance();
                 $view->loged = JO_Session::get('user[user_id]');
                 $view->enable_sort = false;
                 $model_images = new Helper_Images();
                 foreach ($boards as $board) {
                     $board['href'] = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $board['user_id'] . '&board_id=' . $board['board_id']);
                     $board['thumbs'] = array();
                     $get_big = false;
                     for ($i = 0; $i < 5; $i++) {
                         $image = isset($board['pins_array'][$i]) ? $board['pins_array'][$i]['image'] : false;
                         if ($image) {
                             if ($get_big) {
                                 $size = '_A';
                             } else {
                                 $size = '_C';
                                 $get_big = true;
                             }
                             $data_img = Helper_Uploadimages::pin($board['pins_array'][$i], $size);
                             if ($data_img) {
                                 $board['thumbs'][] = $data_img['image'];
                             } else {
                                 $board['thumbs'][] = false;
                             }
                         } else {
                             $board['thumbs'][] = false;
                         }
                     }
                     $board['boardIsFollow'] = Model_Users::isFollow(array('board_id' => $board['board_id']));
                     $board['userFollowIgnore'] = $board['user_id'] != JO_Session::get('user[user_id]');
                     $board['follow'] = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=follow&user_id=' . $board['user_id'] . '&board_id=' . $board['board_id']);
                     $board['edit'] = false;
                     if ($board['user_id'] == JO_Session::get('user[user_id]') || Model_Boards::allowEdit($board['board_id'])) {
                         $board['userFollowIgnore'] = false;
                         $board['edit'] = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=edit&user_id=' . $board['user_id'] . '&board_id=' . $board['board_id']);
                     }
                     $username = Model_Users::getUsername($board["user_id"]);
                     $url_base = WM_Router::create($request->getBaseUrl());
                     $return['data'][] = array('folderId' => $board['board_id'], 'folderName' => $board['title'], 'folderUrl' => $url_base . $username . "/" . $board['title'], 'folderImage' => $board['image'], 'folderQty' => $board['pins']);
                     //$return[] = $board;
                 }
             }
         } else {
             if ($kind == 2) {
                 //people
                 $data = array('start' => JO_Registry::get('config_front_limit') * $page - JO_Registry::get('config_front_limit'), 'limit' => JO_Registry::get('config_front_limit'), 'filter_username' => $query);
                 $users = Model_Users::getUsers($data);
                 if ($users) {
                     $this->view->follow_user = true;
                     $view = JO_View::getInstance();
                     $view->loged = JO_Session::get('user[user_id]');
                     $model_images = new Helper_Images();
                     foreach ($users as $key => $user) {
                         $avatar = Helper_Uploadimages::avatar($user, '_B');
                         $user['avatar'] = $avatar['image'];
                         if ($view->loged) {
                             $user['userIsFollow'] = Model_Users::isFollowUser($user['user_id']);
                             $user['userFollowIgnore'] = $user['user_id'] == JO_Session::get('user[user_id]');
                         } else {
                             $user['userFollowIgnore'] = true;
                         }
                         $user['href'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $user['user_id']);
                         $user['follow'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=follow&user_id=' . $user['user_id']);
                         $return['data'][] = array('userId' => $user['user_id'], 'userName' => $user['username'], 'userDesc' => $user['description'], 'userLocation' => $user['location'], 'avatar' => $user['avatar'], 'follower' => $user['followers'], 'following' => $user['following']);
                     }
                 }
             }
         }
     }
     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);
 }