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')); } }
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 indexAction() { $request = $this->getRequest(); if (!JO_Session::get('user[user_id]')) { $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login&popup=true&next=' . urlencode($request->getFullUrl()))); } $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->title = JO_Utf8::convertToUtf8($request->getQuery('title')); $this->view->url = JO_Utf8::convertToUtf8(urldecode($request->getQuery('url'))); $this->view->media = JO_Utf8::convertToUtf8($request->getQuery('media')); $this->view->is_video = JO_Utf8::convertToUtf8($request->getQuery('is_video')); $this->view->description = JO_Utf8::convertToUtf8($request->getQuery('description')); $this->view->charset = JO_Utf8::convertToUtf8($request->getQuery('charset')); if (!trim($this->view->description)) { $this->view->description = $this->view->title; } if (JO_Session::get('success_added')) { $this->view->pin_url = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . JO_Session::get('success_added')); $this->setViewChange('success'); JO_Session::clear('success_added'); } else { if ($request->isPost()) { $result = Model_Pins::create(array('title' => $this->view->title, 'from' => $this->view->url, 'image' => $this->view->media, 'is_video' => $this->view->is_video, 'description' => $request->getPost('message'), 'price' => $request->getPost('price'), 'board_id' => $request->getPost('board_id'), 'pinmarklet' => 1)); if ($result) { Model_History::addHistory(0, Model_History::ADDPIN, $result); $session_user = JO_Session::get('user[user_id]'); $group = Model_Boards::isGroupBoard($request->getPost('board_id')); if ($group) { $users = explode(',', $group); foreach ($users as $user_id) { if ($user_id != $session_user) { $user_data = Model_Users::getUser($user_id); if ($user_data && $user_data['email_interval'] == 1 && $user_data['groups_pin_email']) { $this->view->user_info = $user_data; $this->view->profile_href = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . JO_Session::get('user[user_id]')); $this->view->full_name = JO_Session::get('user[firstname]') . ' ' . JO_Session::get('user[lastname]'); $this->view->pin_href = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $result); $board_info = Model_Boards::getBoard($request->getPost('board_id')); if ($board_info) { $this->view->board_title = $board_info['title']; $this->view->board_href = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $board_info['user_id'] . '&board_id=' . $board_info['board_id']); } Model_Email::send($user_data['email'], JO_Registry::get('noreply_mail'), JO_Session::get('user[firstname]') . ' ' . JO_Session::get('user[lastname]') . ' ' . $this->translate('added new pin to a group board'), $this->view->render('group_board', 'mail')); } } } } JO_Session::set('success_added', $result); $this->redirect($request->getBaseUrl() . '?controller=bookmarklet'); } } } }
public function indexAction() { $request = $this->getRequest(); if (!JO_Session::get('user[user_id]')) { $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login&popup=true&next=' . urlencode($request->getFullUrl()))); } $this->view->createBoard = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=create'); $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); } } $this->view->title = JO_Utf8::convertToUtf8($request->getQuery('title')); $this->view->url = JO_Utf8::convertToUtf8(urldecode($request->getQuery('url'))); $this->view->media = JO_Utf8::convertToUtf8($request->getQuery('media')); $this->view->is_video = JO_Utf8::convertToUtf8($request->getQuery('is_video')); $this->view->description = JO_Utf8::convertToUtf8($request->getQuery('description')); $this->view->charset = JO_Utf8::convertToUtf8($request->getQuery('charset')); if (is_array($request->getPost())) { foreach ($request->getPost() as $k => $v) { $this->view->{$k} = $v; } } if (!trim($this->view->description)) { $this->view->description = $this->view->title; } if (JO_Session::get('success_added')) { return $this->success(); } else { if ($request->isPost()) { $validate = new Helper_Validate(); $validate->_set_rules($request->getPost('description'), $this->translate('Description'), 'not_empty;min_length[1];max_length[500]'); $validate->_set_rules($request->getPost('board_id'), $this->translate('Board'), 'not_empty;'); if ($validate->_valid_form()) { $result = new Model_Pins_Create($request->getPost()); if ($result->count()) { $result = $result->data; ///add history new Model_History_AddHistory(JO_Session::get('user[user_id]'), Model_History_Abstract::ADDPIN, $result['pin_id']); //send notification $users = new Model_Users_GroupBoardUsers($request->getPost('board_id')); if ($users->count()) { $template = Model_Notification::getTemplate('group_board'); if ($template) { $pin_info = new Model_Pins_Pin($result['pin_id']); if ($pin_info->count()) { $mail_footer = html_entity_decode(Helper_Config::get('mail_footer'), ENT_QUOTES, 'utf-8'); foreach ($users as $user) { if ($user['email_interval'] == 1 && $user['groups_pin_email']) { $template_data = array('user_id' => $user['user_id'], 'user_firstname' => $user['firstname'], 'user_lastname' => $user['lastname'], 'user_fullname' => $user['fullname'], 'user_username' => $user['username'], 'author_url' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $pin_info['user_user_id']), 'author_fullname' => $pin_info['user_fullname'], 'board_url' => WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $pin_info['user_user_id'] . '&board_id=' . $pin_info['board_board_id']), 'board_name' => $pin_info['board_title'], 'pin_url' => WM_Router::pinAction($result['pin_id']), 'mail_footer' => $mail_footer); if (!$template['title']) { $template['title'] = '${author_fullname} ' . $this->translate('added new pin to a group board'); } $title = Model_Notification::parseTemplate(html_entity_decode($template['title'], ENT_QUOTES, 'utf-8'), $template_data); $body = Model_Notification::parseTemplate(html_entity_decode($template['template'], ENT_QUOTES, 'utf-8'), $template_data); Model_Email::send($user['email'], Helper_Config::get('noreply_mail'), $title, $body); } } } } } JO_Session::set('success_added', $result['pin_id']); $this->redirect($request->getBaseUrl() . '?controller=bookmarklet'); } else { if ($result->error) { $this->view->error = $result->error; } else { $this->view->error = $this->translate('There was a problem with the record. Please try again!'); } } } else { $this->view->error = $validate->_get_error_messages(); } } } }