Beispiel #1
0
 public function countAction()
 {
     $request = $this->getRequest();
     $json = array('count' => 0);
     $url = urldecode($request->getQuery('url'));
     if ($url && JO_Validate::validateHost($url)) {
         $source_id = Model_Source::getSourceByUrl($url, false);
         if ($source_id) {
             $total_pins = Model_Pins::getTotalPinsLikes(array('filter_source_id' => $source_id, 'filter_from_md5' => md5($url)));
             $json['count'] = $total_pins;
         } else {
             $json['count'] = 0;
         }
     } else {
         $json['error'] = $this->translate('Invalid Url');
     }
     $json['url'] = $url;
     //		$json['count'] = 1212;
     //		$json['error'] = $this->translate('Invalid Url');
     if ($request->getQuery('callback')) {
         $response = $this->getResponse();
         $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');
         echo 'receiveCount(' . JO_Json::encode($json) . ');';
         exit;
     } else {
         foreach ($json as $k => $v) {
             $this->view->{$k} = $v;
         }
         echo $this->renderScript('json');
     }
 }
Beispiel #2
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);
 }
Beispiel #3
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;
 }