private function initInstagram(&$instagramoauth) { if ($this->user_data) { return true; } $instagramoauth = new Helper_Modules_Instagram(); $InstagramAccessToken = $instagramoauth->getAccessToken(); $user_data = JO_Json::decode($instagramoauth->getUser(), true); if (isset($user_data['meta']['code']) && $user_data['meta']['code'] == 200) { JO_Session::set('InstagramAccessToken', $InstagramAccessToken); $this->user_data = $user_data['data']; } elseif ($InstagramAccessToken) { JO_Session::set('InstagramAccessToken', $InstagramAccessToken); $instagramoauth->setAccessToken($InstagramAccessToken); } elseif (JO_Session::get('InstagramAccessToken')) { $instagramoauth->setAccessToken(JO_Session::get('InstagramAccessToken')); } if (!$this->user_data) { $user_data = JO_Json::decode($instagramoauth->getUser(), true); if (isset($user_data['meta']['code']) && $user_data['meta']['code'] == 200) { $this->user_data = $user_data['data']; } } return $this->user_data ? true : false; }
public static function getCordinatesByPlace($place) { $old_agent = ini_get('user_agent'); ini_set('user_agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110303 SUSE/3.6.15-0.2.2 Firefox/3.6.15'); $url = 'http://maps.google.com/maps/geo?q=' . urlencode($place) . '&output=json&oe=utf8&sensor=false&key=' . JO_Registry::get('config_google_map'); if (ini_get('allow_url_fopen')) { $code = file_get_contents($url); } else { $code = self::file_get_contents_curl($url); } ini_set('user_agent', $old_agent); if (!$code) { return array('Lat' => 0, 'Lng' => 0); } $result = JO_Json::decode($code, true); if (isset($result['Placemark'][0]['Point']['coordinates'][1])) { return array('Lat' => $result['Placemark'][0]['Point']['coordinates'][1], 'Lng' => $result['Placemark'][0]['Point']['coordinates'][0]); } return array('Lat' => 0, 'Lng' => 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'); } }
public static function getPins($data = array(), &$pin_ids = array()) { $db = JO_Db::getDefaultAdapter(); $cache_live = (int) JO_Registry::get('config_cache_live'); if ($cache_live && isset($data['filter_rand']) && $data['filter_rand'] == true && isset($data['start']) && isset($data['limit'])) { $check = $db->select()->from('cache_index')->where('start_limit = ?', $data['start'] . '.' . $data['limit'])->where('`date` >= ?', time())->limit(1); $cache = $db->fetchRow($check); if ($cache) { $results = JO_Json::decode($cache['data'], true); if ($results && is_array($results)) { $return = array(); foreach ($results as $result) { if (self::pinIsExist($result['pin_id'])) { $return[] = $result; } } return $return; } } } elseif ($cache_live && isset($data['filter_like_repin_comment']) && $data['filter_like_repin_comment'] == true && isset($data['start']) && isset($data['limit'])) { $check = $db->select()->from('cache_popular')->where('start_limit = ?', $data['start'] . '.' . $data['limit'])->where('`date` >= ?', time())->limit(1); $cache = $db->fetchRow($check); if ($cache) { $results = JO_Json::decode($cache['data'], true); if ($results && is_array($results)) { $return = array(); foreach ($results as $result) { if (self::pinIsExist($result['pin_id'])) { $return[] = $result; } } return $return; } } } if (isset($data['filter_likes']) && $data['filter_likes']) { $query = $db->select()->from('pins', array('pins.*', 'gift' => new JO_Db_Expr('pins.price > 0.0000')))->where('pins.pin_id IN (SELECT pins_likes.pin_id FROM pins_likes WHERE user_id = ?)', $data['filter_likes']); } else { $query = $db->select()->from('pins', array('pins.*', 'gift' => new JO_Db_Expr('pins.price > 0.0000'))); } $query = self::FilterBuilder($query, $data); if (isset($data['start']) && isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } $query->limit($data['limit'], $data['start']); } if (isset($data['sort']) && strtolower($data['sort']) == 'asc') { $sort = ' ASC'; } else { $sort = ' DESC'; } $allow_sort = array('pins.pin_id', 'pins.views'); if (isset($data['order']) && in_array($data['order'], $allow_sort)) { $query->order($data['order'] . $sort); } elseif (isset($data['order']) && $data['order'] instanceof JO_Db_Expr) { $query->order($data['order']); } else { $query->order('pins.pin_id' . $sort); } $start = microtime(true); //echo $query.'<hr />'; $results = $db->fetchAll($query); $results_array = array(); if ($results) { foreach ($results as $result) { $userinfo = Model_Users::getUser($result['user_id'], false, Model_Users::$allowed_fields); if ($userinfo) { $result['user_via'] = $result['via'] ? Model_Users::getUser($result['via'], false, Model_Users::$allowed_fields) : false; $result['user'] = $userinfo; $result['board'] = Model_Boards::getBoardTitle($result['board_id']); $result['latest_comments'] = $result['comments'] ? Model_Comments::getLatestComments($result['latest_comments']) : array(); $result['liked'] = $result['likes'] ? self::pinIsLiked($result['pin_id']) : 0; $results_array[] = $result; // array_push($pin_ids, $result['pin_id']); } } } // var_dump( microtime(true)-JO_Registry::get('start_microtime') ); exit; return $results_array; }
public function get($key) { $db = JO_Db::getDefaultAdapter(); $query = $db->select()->from($this->getTable(), $this->getData())->where($this->getMd5Key() . ' = ?', md5($key)); $result = $db->fetchOne($query); if ($result) { return JO_Json::decode($result, true); } return false; }
public function indexAction() { $this->noViewRenderer(true); $request = $this->getRequest(); if ($request->getQuery('openId') && strlen($request->getQuery('openId')) == 32 && $request->getServer('HTTP_REFERER')) { $referer = str_replace('www.', '', JO_Validate::validateHost($request->getServer('HTTP_REFERER'))); $domain = $request->getDomain(); if ($referer && $referer != $domain && self::allowledReferal($referer)) { //check user if ($result = Model_Extensions_Singlesignon::checkUser($referer, $domain, $request->getQuery('openId'))) { if ($result && $result['status'] == 'activate') { $groups = unserialize($result['groups']); if (is_array($groups) and count($groups) > 1) { unset($result['groups']); $fetch_all = Model_Users::getGroups($groups); $result['access'] = array(); if ($fetch_all) { foreach ($fetch_all as $row) { $modules = unserialize($row['rights']); if (is_array($modules)) { foreach ($modules as $module => $ison) { $result['access'][$module] = $module; } } } } } if (isset($result['access']) && count($result['access'])) { $result['is_admin'] = true; } JO_Session::set($result); } } elseif (!JO_Session::get('user_id')) { $url = 'http://' . $referer . '/public/extensions_singlesignon/getUserData/?openId=' . $request->getQuery('openId') . '&referer=' . $referer . '&domain=' . $domain; if (ini_get('allow_url_fopen')) { $response = file_get_contents($url); } elseif (function_exists('curl_init')) { $response = $this->file_get_contents_curl($url); } if ($response) { $response = JO_Json::decode(JO_Encrypt_Md5::decrypt($response, $domain), true); //register user if ($response && is_array($response)) { if ($result = Model_Extensions_Singlesignon::createUser($response)) { $groups = self::mb_unserialize($result['groups']); if (is_array($groups) and count($groups) > 1) { unset($result['groups']); $fetch_all = Model_Users::getGroups($groups); $result['access'] = array(); if ($fetch_all) { foreach ($fetch_all as $row) { $modules = self::mb_unserialize($row['rights']); if (is_array($modules)) { foreach ($modules as $module => $ison) { $result['access'][$module] = $module; } } } } } if (isset($result['access']) && count($result['access'])) { $result['is_admin'] = true; } JO_Session::set($result); } } } } } $this->redirect($request->getBaseUrl()); } $this->view->single_sign_on = array(); $single_sign_on = WM_Store::getSettingsPairs(array('filter_group' => 'single_sign_on')); $model_images = new Model_Images(); $sort_order = array(); foreach ($single_sign_on as $row => $data) { $sort_order[$row] = isset($data['sort_order']) ? $data['sort_order'] : 0; if ($data['site_logo'] && file_exists(BASE_PATH . '/uploads/' . $data['site_logo'])) { $data['preview'] = 'uploads/' . $data['site_logo']; } else { $data['preview'] = ''; } $data['preview'] = $model_images->resize($data['site_logo'], 140, 30); $data['href'] = 'http://' . $data['url'] . '/public/'; if (JO_Registry::get('singlesignon_enable_login') && JO_Session::get('user_id')) { $data['href'] .= '?openId=' . md5($request->getDomain() . $data['url'] . JO_Session::get('username') . JO_Session::get('email')); } $this->view->single_sign_on[$row] = $data; } array_multisort($sort_order, SORT_ASC, $this->view->single_sign_on); if (JO_Registry::get('singlesignon_enable_dropdown') && count($this->view->single_sign_on)) { $this->view->ext_css = WM_Router::create($request->getBaseUrl() . '?controller=cache&extension=singlesignon&action=css&setFile=css.css'); $this->view->ext_js = WM_Router::create($request->getBaseUrl() . '?controller=cache&extension=singlesignon&action=js&setFile=js.js'); $this->getLayout()->placeholder('singlesignon', $this->view->render('index', 'extensions_singlesignon')); } }
private function getMediaData($user_id, $timeout = 30, array $params) { $curl = new JO_Http(); $curl->initialize(array('target' => 'https://api.instagram.com/v1/users/' . $user_id . '/media/recent', 'method' => 'GET', 'timeout' => $timeout, 'params' => $params)); $curl->useCurl(true); $curl->execute(); return JO_Json::decode($curl->result, true); }
public function instagram_connectAction() { $request = $this->getRequest(); if (!JO_Session::get('user[user_id]')) { if (!$request->isXmlHttpRequest()) { $this->redirect(WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=settings')); } exit('[]'); } if ($request->getQuery('state') && $request->getQuery('state') == JO_Session::get('state')) { $state = JO_Session::get('state'); } else { $state = md5(uniqid(rand(), TRUE)); JO_Session::set('state', $state); } $config = array('client_id' => JO_Registry::get('oauth_in_key'), 'client_secret' => JO_Registry::get('oauth_in_secret'), 'grant_type' => 'authorization_code', 'redirect_uri' => WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=instagram&next=' . urlencode(WM_Router::create($request->getBaseUrl() . '?controller=settings&action=instagram_connect&state=' . $state)))); $instagram = new WM_Instagram($config); $InstagramAccessToken = $instagram->getAccessToken(); $user_data = JO_Json::decode($instagram->getUser(), true); if (isset($user_data['meta']['code']) && $user_data['meta']['code'] == 200) { JO_Session::set('InstagramAccessToken', $InstagramAccessToken); } elseif ($InstagramAccessToken) { JO_Session::set('InstagramAccessToken', $InstagramAccessToken); $instagram->setAccessToken($InstagramAccessToken); } elseif (JO_Session::get('InstagramAccessToken')) { $instagram->setAccessToken(JO_Session::get('InstagramAccessToken')); } elseif (JO_Session::get('user[instagram_token]')) { JO_Session::set('InstagramAccessToken', JO_Session::get('user[instagram_token]')); $instagram->setAccessToken(JO_Session::get('user[instagram_token]')); } if (!isset($user_data['meta']['code']) || $user_data['meta']['code'] != 200) { $user_data = JO_Json::decode($instagram->getUser(), true); } if ($request->getQuery('state') && $request->getQuery('state') == JO_Session::get('state') && isset($user_data['meta']['code']) && $user_data['meta']['code'] == 200) { JO_Session::clear('state'); Model_Users::edit2(JO_Session::get('user[user_id]'), array('instagram_connect' => '1', 'instagram_profile_id' => $user_data['data']['id'], 'instagram_token' => (string) JO_Session::get('InstagramAccessToken'))); $this->redirect(WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=settings')); exit; } if ($request->getPost('instagram_connect') == 'on') { if (isset($user_data['meta']['code']) && $user_data['meta']['code'] == 200) { Model_Users::edit2(JO_Session::get('user[user_id]'), array('instagram_connect' => '1', 'instagram_profile_id' => $user_data['data']['id'], 'instagram_token' => (string) JO_Session::get('InstagramAccessToken'))); } else { JO_Session::set('InstagramAccessToken', false); JO_Session::set('user[instagram_token]', array_merge((array) JO_Session::get('user'), array('instagram_token' => null))); $this->view->login = WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=instagram&next=' . urlencode(WM_Router::create($request->getBaseUrl() . '?controller=settings&action=instagram_connect&state=' . $state))); } } else { Model_Users::edit2(JO_Session::get('user[user_id]'), array('instagram_connect' => '0', 'instagram_profile_id' => '0', 'instagram_token' => '')); } if (!$this->view->login) { $ud = Model_Users::getUser(JO_Session::get('user[user_id]'), true); if ($ud) { $this->view->connected = $ud['instagram_connect'] ? 'on' : 'off'; } else { JO_Session::set('InstagramAccessToken', false); JO_Session::set('user[instagram_token]', array_merge((array) JO_Session::get('user'), array('instagram_token' => null))); $this->view->connected = 'off'; } } if (!$request->isXmlHttpRequest()) { $this->redirect(WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=settings')); exit; } echo $this->renderScript('json'); }