public static function copyFromUrl($url, $target) { if (!@copy($url, $target)) { $http = new JO_Http(); $http->useCurl(true); if (($host = JO_Validate::validateHost($url)) !== false) { $http->setReferrer('http://' . $host); } $http->execute($url); if ($http->error) { return false; } else { $im = @ImageCreateFromString($http->result); if (!$im) { return false; } return @file_put_contents($target, $im); } } else { return true; } }
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')); } }
private function checkDisabled($url) { $curl = new JO_Http(); $curl->initialize(array('target' => $url, 'method' => 'GET', 'timeout' => 10)); $curl->useCurl(true); $curl->execute(); return $curl->status == 200; }
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 function instagram_cronAction() { $ud = Model_Users::getUser(JO_Session::get('user[user_id]')); if ($ud) { $curl = new JO_Http(); $curl->initialize(array('target' => WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=instagram&action=cronfirst&user='******'user_id']), 'method' => 'GET', 'timeout' => 30)); $curl->useCurl(true); $curl->execute(); } exit('[]'); }