Пример #1
0
 public static function edit($pin_id, $data)
 {
     $pin_info = self::getPin($pin_id);
     if (!$pin_info) {
         return;
     }
     $db = JO_Db::getDefaultAdapter();
     $date_modified = WM_Date::format(time(), 'yy-mm-dd H:i:s');
     $board_info = Model_Boards::getBoard($data['board_id']);
     $source_id = Model_Source::getSourceByUrl($data['from']);
     /* price */
     $price = $pin_info['price'];
     if (preg_match('/(\\$|\\£|\\€|\\¥|\\₪|zł|\\฿)([\\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) {
             $price = round($price_tmp / $currency, 4);
         }
     }
     $data['is_video'] = 'false';
     $help_video = new Helper_AutoEmbed();
     if ($help_video->parseUrl($data['from'])) {
         $data['is_video'] = 'true';
     }
     $is_update = $db->update('pins', array('category_id' => (string) $board_info['category_id'], 'board_id' => $data['board_id'], 'date_modified' => $date_modified, 'from' => $data['from'], 'from_md5' => md5($data['from']), 'description' => $data['description'], 'price' => $price, 'is_video' => $data['is_video'] == 'true' ? 1 : 0, 'source_id' => isset($data['source_id']) ? $data['source_id'] : $source_id, 'date_modified' => new JO_Db_Expr('NOW()')), array('pin_id = ?' => $pin_id));
     $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::common()) && $word[0] . $word[1] != '&#') {
             $words[$word] = $word;
         }
     }
     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' => $pin_id, 'dic_id' => $dic_id));
         }
     }
     if ($pin_info['board_id'] != $data['board_id']) {
         //mahame i slagame ot stariq i v noviq/////
         Model_Boards::updateLatestPins($pin_info['board_id']);
         Model_Boards::updateLatestPins($data['board_id']);
         $board_info2 = Model_Boards::getBoard($pin_info['board_id']);
         if ($board_info2['cover'] == $pin_id) {
             $db->update('boards', array('cover' => 0), array('board_id = >' => $pin_info['board_id']));
         }
     }
     Model_Users::updateLatestPins($pin_info['user_id']);
     self::deleteCache($pin_info);
 }
Пример #2
0
 public function steptwoAction()
 {
     $this->noLayout(true);
     $request = $this->getRequest();
     if (JO_Session::get('user[user_id]')) {
         $this->view->images = array();
         if ($request->isGet() && $request->getQuery('url')) {
             $cleared = preg_replace('/^www./i', '', JO_Validate::validateHost($request->getQuery('url')));
             $cleared = mb_strtolower($cleared, 'utf-8');
             if (Model_Blacksources::is_exists($cleared)) {
                 $this->view->error = sprintf($this->translate('Source %s is blocked!'), $cleared);
                 $this->setViewChange('stepone');
             } else {
                 $video_url = $request->getQuery('url');
                 $video_url = trim($video_url);
                 if (strpos($video_url, 'http') === false) {
                     $video_url = 'http://' . $video_url;
                 }
                 $http = new JO_Http();
                 $http->setUseragent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');
                 $http->setReferrer($video_url);
                 $http->useCurl(true);
                 $http->execute($video_url, $request->getBaseUrl(), 'GET');
                 $http->setMaxredirect(5);
                 /*if(isset($http->headers['location']) && $http->headers['location']) {
                 			$new_url = $http->headers['location'];
                 			$http = new JO_Http();
                 			$http->setUseragent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');
                 			$http->setReferrer($video_url);
                 			$http->useCurl(true);
                 			$http->execute($new_url, $request->getBaseUrl(), 'GET');
                 			if(is_array($new_url)) {
                 				$video_url = array_shift($new_url);
                 			} else if($new_url) {
                 				$video_url = $new_url;
                 			}
                 		}*/
                 $videoObject = new Helper_AutoEmbed();
                 $parsedVideo = $videoObject->parseUrl($video_url);
                 $video_image = false;
                 if ($parsedVideo) {
                     $video_image = $videoObject->getImageURL();
                 }
                 $config_image_minimum_size = (int) Helper_Config::get('config_image_minimum_size');
                 if (!$config_image_minimum_size) {
                     $config_image_minimum_size = 80;
                 }
                 if ($http->error) {
                     $this->view->error = str_replace("'", "\\'", $http->error);
                 } elseif ($video_url && ($imagesize = @getimagesize($video_url)) !== false) {
                     if ($imagesize && $imagesize[0] >= $config_image_minimum_size && $imagesize[1] >= $config_image_minimum_size) {
                         $this->view->images[] = array('src' => $video_url, 'width' => $imagesize[0], 'height' => $imagesize[1]);
                     }
                 } elseif ($video_image && ($imagesize = @getimagesize($video_image)) !== false) {
                     if ($imagesize && $imagesize[0] >= $config_image_minimum_size && $imagesize[1] >= $config_image_minimum_size) {
                         $this->view->images[] = array('src' => $video_image, 'width' => $imagesize[0], 'height' => $imagesize[1]);
                     }
                 } else {
                     $html = $http->result;
                     $dom = new JO_Dom_Query($html);
                     $meta = $dom->query('meta');
                     $charset = false;
                     if ($meta->count()) {
                         for ($i = 0; $i < $meta->count(); $i++) {
                             $content = $meta->getItem($i)->getAttribute('content');
                             if (preg_match('/charset=([^\\"\']+)/', $content, $match)) {
                                 $charset = trim($match[1]);
                             }
                         }
                     }
                     if ($charset) {
                         $html = iconv($charset, "UTF-8", $html);
                     } else {
                         $html = JO_Utf8::convertToUtf8($http->result);
                     }
                     $this->view->title = '';
                     if (preg_match('/<title>(.*)<\\/title>/sim', $html, $match)) {
                         $this->view->title = $match[1];
                     }
                     $meta_image = $dom->query('meta[property="og:image"]');
                     $meta_image_src = null;
                     if ($meta_image->count()) {
                         $meta_image_src = $meta_image->rewind()->getAttribute('content');
                     }
                     if ($meta_image_src) {
                         if (($imagesize = @getimagesize($meta_image_src)) !== false) {
                             if ($imagesize && $imagesize[0] >= $config_image_minimum_size && $imagesize[1] >= $config_image_minimum_size) {
                                 $this->view->images[] = array('src' => $meta_image_src, 'width' => $imagesize[0], 'height' => $imagesize[1]);
                             }
                         }
                     }
                     $images = $dom->query('img');
                     if ($images->count() > 0) {
                         $images_array = array();
                         for ($i = 0; $i < $images->count(); $i++) {
                             $src = $images->getItem($i)->getAttribute('src');
                             $image_full = JO_Url_Relativetoabsolute::toAbsolute($request->getQuery('url'), $src);
                             $images_array[$image_full] = $image_full;
                         }
                         foreach ($images_array as $image_full) {
                             $imagesize = @getimagesize($image_full);
                             if ($imagesize && $imagesize[0] >= $config_image_minimum_size && $imagesize[1] >= $config_image_minimum_size) {
                                 $this->view->images[] = array('src' => $image_full, 'width' => $imagesize[0], 'height' => $imagesize[1]);
                             }
                         }
                     }
                 }
                 $this->view->from = $video_url;
             }
         }
         $this->view->total_images = count($this->view->images);
         if ($this->view->total_images < 1) {
             $this->view->form_action = WM_Router::create($request->getBaseUrl() . '?controller=addpin_fromurl&action=steptwo');
             $this->view->error_total_images = true;
             $this->setViewChange('stepone');
         } else {
             $this->view->createBoard = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=createboardwithoutcategory');
             $this->view->from_url = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=createpin');
             $boards = new Model_Boards_BoardsWithShared(array('filter_user_id' => JO_Session::get('user[user_id]')));
             $this->view->boards = array();
             if ($boards->count()) {
                 foreach ($boards as $board) {
                     $this->view->boards[] = array('board_id' => $board['board_board_id'], 'title' => $board['board_title']);
                 }
             }
             ///////////////// Extension on create //////////////////
             $this->view->form_extensions = array();
             $extensions = Model_Extensions::getByMethod('pin_oncreateform');
             if ($extensions) {
                 $front = JO_Front::getInstance();
                 foreach ($extensions as $id => $ext) {
                     $this->view->form_extensions[] = array('html' => $this->view->callChildren('modules_' . $ext . '_oncreateform'), 'view' => $this->view->callChildrenView('modules_' . $ext . '_oncreateform'), 'key' => $ext);
                 }
             }
         }
     } else {
         // 			$this->view->redirect = WM_Router::create( $request->getBaseUrl() . '?controller=users&action=login' );
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'));
     }
 }
Пример #3
0
 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();
     }
 }
Пример #4
0
 public function get_imagesAction()
 {
     $request = $this->getRequest();
     $this->view->form_action = WM_Router::create($request->getBaseUrl() . '?controller=addpin&action=get_images');
     $this->view->total_images = 0;
     if ($request->isGet() && $request->getQuery('url')) {
         $http = new JO_Http();
         $http->setUseragent('Amatteur bot v' . JO_Registry::get('system_version'));
         $http->useCurl(true);
         $http->execute($request->getQuery('url'), $request->getBaseUrl(), 'GET');
         $video_url = $request->getQuery('url');
         if (isset($http->headers['location']) && $http->headers['location']) {
             $new_url = $http->headers['location'];
             $http = new JO_Http();
             $http->setUseragent('Amatteur bot v' . JO_Registry::get('system_version'));
             $http->useCurl(true);
             $http->execute($new_url, $request->getBaseUrl(), 'GET');
             $video_url = $new_url;
         }
         $video_url = trim($video_url);
         if (strpos($video_url, 'http') === false) {
             $video_url = 'http://' . $video_url;
         }
         $this->view->from = $video_url;
         if ($http->error) {
             $this->view->error = $http->error;
         } elseif (($imagesize = $this->getimagesize2($video_url)) !== false) {
             $this->view->images[] = array('src' => $video_url, 'width' => $imagesize[0], 'height' => $imagesize[1]);
             $this->view->total_images = 1;
             $this->view->from_url = WM_Router::create($request->getBaseUrl() . '?controller=addpin&action=fromurl');
             $this->view->createBoard = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=create');
             $boards = Model_Boards::getBoards(array('filter_user_id' => JO_Session::get('user[user_id]'), 'order' => 'boards.sort_order', 'sort' => 'ASC', 'friendly' => JO_Session::get('user[user_id]')));
             $this->view->boards = array();
             if ($boards) {
                 foreach ($boards as $board) {
                     $this->view->boards[] = array('board_id' => $board['board_id'], 'title' => $board['title']);
                 }
             }
             $this->view->is_video = 'false';
             $this->view->title = basename($video_url);
             $this->view->popup_main_box = $this->view->render('from_url', 'addpin');
         } else {
             $html = JO_Utf8::convertToUtf8($http->result);
             $dom = new JO_Dom_Query($html);
             $title = $dom->query('title');
             $this->view->title = '';
             if ($title->innerHtml()) {
                 $this->view->title = trim($title->innerHtml());
             }
             $this->view->images = array();
             $meta_image = $dom->query('meta[property="og:image"]');
             // 				$meta_image_src_dom = $meta_image->rewind();//->getAttribute('content');
             $meta_image_src = null;
             if ($meta_image->count()) {
                 $meta_image_src = $meta_image->rewind()->getAttribute('content');
             }
             if ($meta_image_src) {
                 if (($imagesize = $this->getimagesize2($meta_image_src)) !== false) {
                     if ($imagesize && $imagesize[0] >= 80 && $imagesize[1] >= 80) {
                         $this->view->images[] = array('src' => $meta_image_src, 'width' => $imagesize[0], 'height' => $imagesize[1]);
                     }
                 }
             }
             $images = $dom->query('img');
             if ($images->count() > 0) {
                 $images_array = array();
                 for ($i = 0; $i < $images->count(); $i++) {
                     $src = $images->getItem($i)->getAttribute('src');
                     $image_full = JO_Url_Relativetoabsolute::toAbsolute($request->getQuery('url'), $src);
                     $images_array[$image_full] = $image_full;
                 }
                 foreach ($images_array as $image_full) {
                     $imagesize = $this->getimagesize2($image_full);
                     if ($imagesize && $imagesize[0] >= 80 && $imagesize[1] >= 80) {
                         $this->view->images[] = array('src' => $image_full, 'width' => $imagesize[0], 'height' => $imagesize[1]);
                     }
                 }
             }
             $this->view->total_images = count($this->view->images);
             $this->view->from_url = WM_Router::create($request->getBaseUrl() . '?controller=addpin&action=fromurl');
             $this->view->createBoard = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=create');
             $boards = Model_Boards::getBoards(array('filter_user_id' => JO_Session::get('user[user_id]'), 'order' => 'boards.sort_order', 'sort' => 'ASC', 'friendly' => JO_Session::get('user[user_id]')));
             $this->view->boards = array();
             if ($boards) {
                 foreach ($boards as $board) {
                     $this->view->boards[] = array('board_id' => $board['board_id'], 'title' => $board['title']);
                 }
             }
             //////////// Categories ////////////
             $this->view->categories = array();
             $categories = Model_Categories::getCategories(array('filter_status' => 1));
             foreach ($categories as $category) {
                 $category['subcategories'] = Model_Categories::getSubcategories($category['category_id']);
                 $this->view->categories[] = $category;
             }
             $this->view->is_video = 'false';
             $help_video = new Helper_AutoEmbed();
             if ($help_video->parseUrl($video_url)) {
                 $this->view->is_video = 'true';
                 if (!count($this->view->images)) {
                     $img = $help_video->getImageURL();
                     $image_full = null;
                     if ($img) {
                         $image_full = $img;
                     } elseif (preg_match('~http://(?:www\\.)?vimeo\\.com/([0-9]{1,12})~imu', $video_url, $match)) {
                         $url = 'http://vimeo.com/api/v2/video/' . $match[1] . '.json?callback=';
                         $http = new JO_Http();
                         $http->setUseragent('Amatteur bot v' . JO_Registry::get('system_version'));
                         $http->useCurl(true);
                         $http->execute($url, $request->getBaseUrl(), 'GET');
                         if ($http->error) {
                             $this->view->error = $http->error;
                         } else {
                             $meta_image = $dom->query('meta[property="og:image"]');
                             $meta_image_src = $meta_image->rewind()->getAttribute('content');
                             if ($meta_image_src && @getimagesize($meta_image->content)) {
                                 $image_full = $meta_image_src;
                             } else {
                                 $data = JO_Json::decode($http->result, true);
                                 if (isset($data[0]['thumbnail_large'])) {
                                     $image_full = $data[0]['thumbnail_large'];
                                 } elseif (isset($data[0]['thumbnail_medium'])) {
                                     $image_full = $data[0]['thumbnail_medium'];
                                 } elseif (isset($data[0]['thumbnail_small'])) {
                                     $image_full = $data[0]['thumbnail_small'];
                                 }
                             }
                         }
                     }
                     if ($image_full && ($imagesize = @getimagesize($image_full))) {
                         if ($imagesize && $imagesize[0] >= 80 && $imagesize[1] >= 80) {
                             $this->view->images[] = array('src' => $image_full, 'width' => $imagesize[0], 'height' => $imagesize[1]);
                         }
                     }
                     $this->view->total_images = count($this->view->images);
                 }
             }
             $this->view->popup_main_box = $this->view->render('from_url', 'addpin');
         }
         if (count($this->view->images) == 0) {
             $this->view->error_total_images = 1;
             $this->view->popup_main_box = $this->view->render('fromurl', 'addpin');
         }
         $this->setViewChange('index');
         if ($request->isXmlHttpRequest()) {
             $this->noViewRenderer(true);
             echo $this->view->popup_main_box;
             //$this->renderScript('json');
         } else {
             $this->view->is_popup = false;
             $this->view->children = array('header_part' => 'layout/header_part', 'footer_part' => 'layout/footer_part', 'left_part' => 'layout/left_part');
         }
     } else {
         $this->forward('error', 'error404');
     }
 }
Пример #5
0
 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);
 }
Пример #6
0
 public static function create($data)
 {
     $board_info = Model_Boards::getBoard($data['board_id']);
     $db = JO_Db::getDefaultAdapter();
     $date_added = WM_Date::format(time(), 'yy-mm-dd H:i:s');
     $image = '';
     $price = '';
     $source_id = Model_Source::getSourceByUrl($data['from']);
     /* price */
     $currencies = WM_Currency::getCurrencies();
     $price_left = '';
     $price_right = '';
     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) {
                     $price = round($price_tmp / $currency, 4);
                 }
             }
         }
         if (!$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) {
                     $price = round($price_tmp / $currency, 4);
                 }
             }
         }
     }
     /* end price */
     $from = isset($data['from']) ? $data['from'] : time();
     $is_video = isset($data['is_video']) && $data['is_video'] == 'true' ? 1 : 0;
     if (!$is_video) {
         $auto = new Helper_AutoEmbed();
         if ($auto->parseUrl($from)) {
             $is_video = 1;
         }
     }
     /* add to db */
     $db->insert('pins', array('category_id' => (string) $board_info['category_id'], 'board_id' => (string) $data['board_id'], 'user_id' => (string) JO_Session::get('user[user_id]'), 'date_added' => $date_added, 'date_modified' => $date_added, 'description' => $data['description'], 'title' => isset($data['title']) ? $data['title'] : '', 'price' => $price, 'from' => $from, 'from_md5' => md5($from), 'is_video' => $is_video, 'source_id' => isset($data['source_id']) ? $data['source_id'] : $source_id, 'via' => isset($data['via']) ? $data['via'] : '', 'repin_from' => isset($data['repin_from']) ? $data['repin_from'] : '', 'public' => (int) $board_info['public'], 'pinmarklet' => isset($data['pinmarklet']) ? 1 : 0, 'from_repin' => isset($data['from_repin']) ? $data['from_repin'] : '', 'store' => JO_Registry::get('default_upload_method') ? JO_Registry::get('default_upload_method') : 'locale'));
     $pin_id = $db->lastInsertId();
     if (!$pin_id) {
         return false;
     }
     ///// upload images
     $front = JO_Front::getInstance();
     $request = JO_Request::getInstance();
     $upload_model = Helper_Pin::formatUploadModule(JO_Registry::get('default_upload_method'));
     $upload_model_file = $front->getModuleDirectoryWithDefault($request->getModule()) . '/' . $front->classToFilename($upload_model);
     if (!file_exists($upload_model_file)) {
         $upload_model = Helper_Pin::formatUploadModule('locale');
         $upload_model_file = $front->getModuleDirectoryWithDefault($request->getModule()) . '/' . $front->classToFilename($upload_model);
     }
     $image = false;
     if (file_exists($upload_model_file)) {
         $image = call_user_func(array($upload_model, 'uploadPin'), $data['image'], isset($data['title']) && $data['title'] ? $data['title'] : null, $pin_id);
     }
     // 		if(!$image && $upload_model != $front->formatModuleName('model_upload_locale')) {
     // 			$image = call_user_func(array($upload_model, 'uploadPin'), $data['image'], (isset($data['title']) && $data['title'] ? $data['title'] : null), $pin_id );
     // 		}
     if (!$image) {
         $db->delete('pins', array('pin_id = ?' => (string) $pin_id));
         return false;
     } else {
         $db->update('pins', array('image' => $image['image'], 'store' => $image['store'], 'height' => $image['height'], 'width' => $image['width']), array('pin_id = ?' => (string) $pin_id));
     }
     //if($board_info['user_id'] == JO_Session::get('user[user_id]')) {
     Model_Boards::updateLatestPins($data['board_id'], $pin_id);
     //}
     Model_Users::updateLatestPins($pin_id);
     if (isset($data['repin_from']) && $data['repin_from']) {
         $pin_repin = self::getPin($data['repin_from']);
         if ($pin_repin) {
             $db->update('pins', array('repins' => $pin_repin['repins'] + 1), array('pin_id = ?' => $data['repin_from']));
         }
     }
     $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::common()) && $word[0] . $word[1] != '&#') {
             $words[$word] = $word;
         }
     }
     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' => $pin_id, 'dic_id' => $dic_id));
         }
     }
     if (JO_Session::get('user[facebook_connect]') && JO_Session::get('user[facebook_timeline]')) {
         try {
             $session = JO_Registry::get('facebookapi')->getUser();
             JO_Registry::get('facebookapi')->setExtendedAccessToken();
             if (JO_Registry::get('facebookapi')->api('/me')) {
                 $access_token = JO_Registry::get('facebookapi')->getAccessToken();
                 $pin_url = WM_Router::create(JO_Request::getInstance()->getBaseUrl() . '?controller=pin&pin_id=' . $pin_id);
                 $statusUpdate = JO_Registry::get('facebookapi')->api('/me/feed', 'post', array('link' => $pin_url, 'cb' => ''));
                 $og_namespace = trim(JO_Registry::get('og_namespace'));
                 $og_recipe = trim(JO_Registry::get('og_recipe'));
                 if (!$og_recipe) {
                     $og_namespace = '';
                 }
                 if ($og_namespace) {
                     $params = array($og_recipe => $pin_url, 'access_token' => $access_token);
                     $response = JO_Registry::get('facebookapi')->api('/me/' . $og_namespace . ':' . $og_recipe, 'post', $params);
                 }
             }
         } catch (JO_Exception $e) {
         }
     }
     self::rebuildCache(array($pin_id));
     if (isset($data['repin_from'])) {
         self::rebuildCache($data['repin_from']);
     }
     return $pin_id;
 }
Пример #7
0
 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');
 }
Пример #8
0
 public static function formatPinData($pin, $detail = false)
 {
     static $model_images = null, $request = null;
     if ($model_images === null) {
         $model_images = new Helper_Images();
     }
     if ($request === null) {
         $request = JO_Request::getInstance();
     }
     ///////////////////////////////////// PIN INFO /////////////////////////////////////
     $pin['pin_id'] = $pin['pin_pin_id'];
     $pin['image'] = $pin['pin_image'];
     //url's
     $pin['pin_url_embed'] = WM_Router::pinAction($pin['pin_pin_id'], 'embed');
     if (!JO_Session::get('user[user_id]')) {
         $login_url = WM_Router::create($request->getBaseUrl() . '?controller=users&action=login');
         if (Helper_Config::get('enable_free_registration')) {
             //$login_url = WM_Router::create( $request->getBaseUrl() . '?controller=users&action=register' );
         }
         $pin['pin_url_email'] = $pin['pin_url_report'] = $pin['pin_url_like'] = $pin['pin_url_repin'] = $pin['pin_url_comment'] = $login_url;
         $pin['pin_edit'] = false;
     } else {
         $pin['pin_url_email'] = WM_Router::pinAction($pin['pin_pin_id'], 'email');
         $pin['pin_url_report'] = WM_Router::pinAction($pin['pin_pin_id'], 'report');
         $pin['pin_url_like'] = WM_Router::pinAction($pin['pin_pin_id'], 'like');
         $pin['pin_url_repin'] = WM_Router::pinAction($pin['pin_pin_id'], 'repin');
         $pin['pin_url_comment'] = WM_Router::pinAction($pin['pin_pin_id']);
         $pin['pin_edit'] = JO_Session::get('user[user_id]') == $pin['pin_user_id'] ? WM_Router::pinAction($pin['pin_pin_id'], 'edit') : false;
     }
     //$pin['pin_description'] = self::descriptionFix($pin['pin_description']);
     $pin['pin_href'] = WM_Router::pinAction($pin['pin_pin_id']);
     if ($pin['pin_gift']) {
         $pin['pin_price_formated'] = WM_Currency::format($pin['pin_price']);
     } else {
         $pin['pin_price_formated'] = 0;
     }
     //return all image sizes
     $pin['pin_thumbs'] = Helper_Uploadimages::pinThumbs($pin);
     //array_merge($pin, Helper_Uploadimages::pinThumbs($pin));
     $date_dif = array_shift(WM_Date::dateDiff($pin['pin_date_added'], time()));
     $pin['pin_date_dif'] = $date_dif;
     /* URL'S*/
     $pin['pin_onto_href'] = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $pin['board_user_id'] . '&board_id=' . $pin['board_board_id']);
     ////follow urls
     $pin['board_follow_href'] = $pin['user_follow_href'] = $pin['via_follow_href'] = false;
     if (JO_Session::get('user[user_id]') ? $pin['board_user_id'] != JO_Session::get('user[user_id]') : false) {
         $pin['board_follow_href'] = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=follow&user_id=' . $pin['board_user_id'] . '&board_id=' . $pin['board_board_id']);
     }
     if (JO_Session::get('user[user_id]') ? $pin['user_user_id'] != JO_Session::get('user[user_id]') : false) {
         $pin['user_follow_href'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=follow&user_id=' . $pin['user_user_id']);
     }
     if ($pin['via_user_id']) {
         if (JO_Session::get('user[user_id]') ? $pin['via_user_id'] != JO_Session::get('user[user_id]') : false) {
             $pin['via_follow_href'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=follow&user_id=' . $pin['via_user_id']);
         }
     } else {
         if (JO_Session::get('user[user_id]') ? $pin['user_user_id'] != JO_Session::get('user[user_id]') : false) {
             $pin['via_follow_href'] = $pin['user_follow_href'];
         }
     }
     if ($detail) {
         $pin['pin_next_href'] = '';
         if (isset($pin['pin_next']) && $pin['pin_next']) {
             $pin['pin_next_href'] = WM_Router::pinAction($pin['pin_next']);
         }
         $pin['pin_prev_href'] = '';
         if (isset($pin['pin_prev']) && $pin['pin_prev']) {
             $pin['pin_prev_href'] = WM_Router::pinAction($pin['pin_prev']);
         }
     }
     if (Helper_Config::get('config_comments_list') && !$detail && $pin['pin_comments']) {
         $latest_comments = Model_Comments::getLatestComments2($pin['pin_latest_comments']);
         $pin['pin_latest_comments'] = array();
         $user_id = JO_Session::get('user[user_id]');
         $is_admin = JO_Session::get('user[is_admin]');
         $is_developer = JO_Session::get('user[is_developer]');
         foreach ($latest_comments as $key => $comment) {
             $user_avatars = Helper_Uploadimages::userAvatars(array('avatar' => $comment['avatar'], 'store' => $comment['store'], 'user_id' => $comment['user_id']));
             $enable_delete = false;
             if ($is_admin) {
                 $enable_delete = true;
             } elseif ($is_developer) {
                 $enable_delete = true;
             } elseif ($user_id == $comment['user_id']) {
                 $enable_delete = true;
             } elseif ($comment['pin_user_id'] == $user_id) {
                 $enable_delete = true;
             }
             $delete = false;
             if ($enable_delete) {
                 $delete = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=deleteComment&comment_id=' . $comment['comment_id']);
             }
             $pin['pin_latest_comments'][] = array('user' => array('profile' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $comment['user_id']), 'avatars' => $user_avatars, 'fullname' => $comment['fullname']), 'comment' => $comment['comment'], 'delete' => $delete);
         }
     } else {
         $pin['pin_latest_comments'] = array();
     }
     $pin['pin_video_code'] = false;
     if ($detail) {
         if ($pin['pin_is_video']) {
             $auto = new Helper_AutoEmbed();
             if ($pin['pin_repin_from'] && $auto->parseUrl($pin['pin_from_repin'])) {
                 $auto->setWidth('100%');
                 $auto->setHeight('350');
                 $pin['pin_video_code'] = $auto->getEmbedCode();
             } else {
                 if ($auto->parseUrl($pin['pin_from'])) {
                     $auto->setWidth('100%');
                     $auto->setHeight('350');
                     $pin['pin_video_code'] = $auto->getEmbedCode();
                 } else {
                     $pin['pin_is_video'] = false;
                 }
             }
         } else {
             $auto = new Helper_AutoEmbed();
             if ($pin['pin_repin_from'] && $auto->parseUrl($pin['pin_from_repin'])) {
                 $auto->setWidth('100%');
                 $auto->setHeight('350');
                 $pin['pin_video_code'] = $auto->getEmbedCode();
                 $pin['pin_is_video'] = true;
             } else {
                 if ($auto->parseUrl($pin['pin_from'])) {
                     $auto->setWidth('100%');
                     $auto->setHeight('350');
                     $pin['pin_video_code'] = $auto->getEmbedCode();
                     $pin['pin_is_video'] = true;
                 } else {
                     $pin['pin_is_video'] = false;
                 }
             }
         }
         $pin['pin_gallery'] = array();
         $gallery = new Model_Pins_Gallery($pin['pin_pin_id']);
         if ($gallery->count()) {
             foreach ($gallery->data as $gal) {
                 $pin['pin_gallery'][] = Helper_Uploadimages::pinThumbs(array('pin_pin_id' => $gal['pin_id'], 'pin_store' => $gal['store'], 'gallery_id' => $gal['gallery_id'], 'pin_image' => $gal['image']));
             }
         }
     }
     ///////////////////////////////////// AUTHOR INFO /////////////////////////////////////
     //return author all images
     $user_data = array('avatar' => $pin['user_avatar'], 'store' => $pin['user_store'], 'user_id' => $pin['user_user_id']);
     foreach ($pin as $k => $v) {
         if (strpos($k, 'user_avatar_') === 0) {
             $user_data[$k] = $v;
         }
     }
     $pin['user_avatars'] = Helper_Uploadimages::userAvatars($user_data);
     $pin['user_href'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $pin['user_user_id']);
     ///////////////////////////////////// VIA INFO /////////////////////////////////////
     $pin['via_profile'] = array();
     if ($pin['via_user_id']) {
         $via_avatars = Helper_Uploadimages::userAvatars(array('avatar' => $pin['via_avatar'], 'store' => $pin['via_store'], 'user_id' => $pin['via_user_id']));
         $pin['via_profile'] = array('avatars' => $via_avatars, 'profile' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $pin['via_user_id']), 'fullname' => $pin['via_fullname']);
     }
     ///////////////////////////////////// SELF INFO /////////////////////////////////////
     $pin['self_profile'] = false;
     if (JO_Session::get('user[user_id]')) {
         $user_avatars = Helper_Uploadimages::userAvatars(array('avatar' => JO_Session::get('user[avatar]'), 'store' => JO_Session::get('user[store]'), 'user_id' => JO_Session::get('user[user_id]')));
         $pin['self_profile']['avatars'] = $user_avatars;
         $pin['self_profile']['fullname'] = JO_Session::get('user[fullname]');
         $pin['self_profile']['profile'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . JO_Session::get('user[user_id]'));
     }
     ///////////////////////////////////// SOURCE INFO /////////////////////////////////////
     $pin['pin_source'] = array();
     $pin['pin_target_repin'] = false;
     if ($detail) {
         if ($pin['pin_repin_from']) {
             $pin_repin = new Model_Pins_Pin($pin['pin_repin_from']);
             if ($pin_repin->count()) {
                 $pin_repin = $pin_repin->data;
                 $pin['pin_source']['source'] = $pin_repin['board_title'];
                 $pin['pin_from'] = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $pin_repin['user_user_id'] . '&board_id=' . $pin_repin['board_board_id']);
                 $pin['pin_target_repin'] = true;
             } else {
                 $source = new Model_Sources_Source($pin['pin_source_id']);
                 if ($source->count()) {
                     $pin['pin_source']['source'] = $source['source'];
                 }
             }
         } else {
             $source = new Model_Sources_Source($pin['pin_source_id']);
             if ($source->count()) {
                 $pin['pin_source']['source'] = $source['source'];
             }
         }
     }
     ///for mobile
     $pin['mobile_upload'] = false;
     if ($pin['pin_from'] == 'Mobile') {
         $pin['pin_from'] = '';
         $pin['mobile_upload'] = true;
     }
     return $pin;
 }