示例#1
0
 public function createpinAction()
 {
     $request = $this->getRequest();
     if (JO_Session::get('user[user_id]')) {
         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()) {
                 //if validate post
                 $result = new Model_Pins_Create($request->getPost());
                 if ($result->count()) {
                     $result = $result->data;
                     $this->view->pin_url = WM_Router::pinAction($result['pin_id']);
                     if (JO_Session::get('user[first_login]')) {
                         $this->view->callChildren('index/sendWelcome');
                     }
                     ///add history
                     new Model_History_AddHistory(JO_Session::get('user[user_id]'), Model_History_Abstract::ADDPIN, $result['pin_id']);
                     //send notification
                     if ($request->getPost('repin_from')) {
                         $pin_info = new Model_Pins_Pin($request->getPost('repin_from'));
                         if ($pin_info->count()) {
                             $pin_info = $pin_info->data;
                             $template = Model_Notification::getTemplate('repin_pin');
                             if ($template) {
                                 $template_data = array('user_id' => $pin_info['user_user_id'], 'user_firstname' => $pin_info['user_firstname'], 'user_lastname' => $pin_info['user_lastname'], 'user_fullname' => $pin_info['user_fullname'], 'user_username' => $pin_info['user_username'], 'author_url' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . JO_Session::get('user[user_id]')), 'author_fullname' => JO_Session::get('user[fullname]'), 'pin_url' => WM_Router::pinAction($pin_info['pin_pin_id']), 'mail_footer' => html_entity_decode(Helper_Config::get('mail_footer'), ENT_QUOTES, 'utf-8'));
                                 if (!$template['title']) {
                                     $template['title'] = '${author_fullname} ' . $this->translate('repin your PIN');
                                 }
                                 $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($pin_info['user_email'], Helper_Config::get('noreply_mail'), $title, $body);
                             }
                             $this->view->repin_from = $pin_info['pin_pin_id'];
                             $this->view->stats = $this->getPinStat($pin_info['pin_pin_id']);
                         }
                     }
                     $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()) {
                                 $pin_info = $pin_info->data;
                                 $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($pin_info['pin_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);
                                     }
                                 }
                             }
                         }
                     }
                 } 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();
             }
         }
     } else {
         $this->view->redirect = WM_Router::create($request->getBaseUrl() . '?controller=users&action=login');
         $this->view->error = $this->translate('You must login or register to pinit!');
     }
     echo $this->renderScript('json');
 }
示例#2
0
 public function pinMediaCallbackAction()
 {
     $request = $this->getRequest();
     if (JO_Session::get('user[user_id]')) {
         $media = Model_Instagram_Media::getMedia($request->getPost('media_id'));
         if ($media) {
             if ($media['user_id'] == JO_Session::get('user[user_id]')) {
                 $result = new Model_Pins_Create(array('title' => $media['title'], 'from' => $media['from'], 'image' => $media['media'], 'description' => $media['title'], 'board_id' => JO_Session::get('instagram_media[board_id]')));
                 if ($result->count()) {
                     $result = $result->data;
                     $this->view->pin_url = WM_Router::pinAction($result['pin_id']);
                     Model_Instagram_Media::setPinMedia($media['media_id'], $result['pin_id']);
                     ///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(JO_Session::get('instagram_media[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($pin_info['pin_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);
                                     }
                                 }
                             }
                         }
                     }
                     $this->view->ok = true;
                 } else {
                     $this->view->error = $this->translate('There was a problem with the record. Please try again!');
                 }
             } else {
                 $this->view->error = $this->translate('Private media!');
             }
         } else {
             $this->view->error = $this->translate('Media not found!');
         }
     } else {
         $this->view->location = WM_Router::create($request->getBaseUrl() . '?controller=users&action=login');
     }
     echo $this->renderScript('json');
 }
 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();
             }
         }
     }
 }
示例#4
0
 public function indexAction()
 {
     //exit;
     $base_url = 'http://pinterest.com/moose44/horse-barns-stalls/';
     $pages = 5;
     $enable_comments = false;
     $category_id = 29;
     $config_user_id = false;
     $enable_defaul_board_create = false;
     ///end config
     //exit;
     ini_set('memory_limit', '500M');
     $this->noViewRenderer(true);
     ignore_user_abort(true);
     if (!$enable_defaul_board_create) {
         Helper_Config::set('default_boards', false);
     }
     for ($i = 1; $i < $pages; $i++) {
         $base_url_format = $base_url . (strpos($base_url, '?') !== false ? '&' : '?') . 'page=' . $i;
         $html = @file_get_contents($base_url_format);
         if ($html) {
             $dom = new JO_Html_Dom();
             $dom->load($html);
             $hrefs = $dom->find('.PinImage');
             if ($hrefs) {
                 foreach ($hrefs as $href) {
                     $price = 0;
                     $url = JO_Url_Relativetoabsolute::toAbsolute($base_url_format, $href->href);
                     $html2 = @file_get_contents($url);
                     if ($html2) {
                         $dom = new JO_Html_Dom();
                         $dom->load($html2);
                         $board = $dom->find('h3.serif a', 0)->innertext;
                         $image = $dom->find('#pinCloseupImage', 0)->src;
                         $description = $dom->find('#PinCaption .description', 0)->innertext;
                         $from = $dom->find('#PinSource a', 0)->href;
                         $usernames = $dom->find('#PinnerName a', 0)->innertext;
                         $avatar = $dom->find('#PinnerImage img', 0)->src;
                         $ext = strtolower(strrchr($avatar, '.'));
                         $avatar = preg_replace('/_60' . preg_quote($ext) . '$/i', '_600' . $ext, $avatar);
                         if (!@getimagesize($avatar)) {
                             $avatar = preg_replace('/' . preg_quote($ext) . '$/i', '_600' . $ext, $avatar);
                         }
                         $username = trim($dom->find('#PinnerName a', 0)->href, '/');
                         $price_o = $dom->find('.buyable', 0);
                         if ($price_o) {
                             $price = $price_o->innertext;
                         }
                         if (!$config_user_id) {
                             $user_id = Model_Users_Spider_Users::getUserByName($username, $usernames, $avatar);
                             if (!$user_id) {
                                 continue;
                             }
                         } else {
                             $user_id = $config_user_id;
                         }
                         $board_data = new Model_Boards_BoardIdByTitle(trim($board), $user_id, $category_id);
                         if (!$board_data->count()) {
                             continue;
                         }
                         $board_id = $board_data['board_board_id'];
                         $price_f = 0;
                         if (preg_match('/([0-9.]{1,})/', $price, $m)) {
                             $price_f = $m[1];
                         }
                         $result = new Model_Pins_Create(array('board_id' => $board_id, 'description' => htmlspecialchars(strip_tags($description), ENT_QUOTES, 'utf-8'), 'image' => (string) $image, 'price' => (double) $price, 'from' => urldecode($from), 'public' => '1', 'user_id' => $user_id));
                         if (!$result->count()) {
                             continue;
                         }
                         $pin_id = $result->data['pin_id'];
                         //// get comments
                         if ($enable_comments) {
                             $commm = $dom->find('.PinComments .comment');
                             if ($commm) {
                                 foreach ($commm as $com) {
                                     $avatar = $com->find('.CommenterImage img', 0)->src;
                                     $usernames = $com->find('.CommenterName', 0)->innertext;
                                     $username = trim($com->find('.CommenterName', 0)->href, '/');
                                     $text = explode('<br />', $com->find('.comment .CommenterMeta', 0)->innertext);
                                     $text = isset($text[1]) ? $text[1] : '';
                                     if ($text) {
                                         $user_id = Model_Users_Spider_Users::getUserByName($username, $usernames, $avatar);
                                         if (!$user_id) {
                                             continue;
                                         }
                                         $result = new Model_Pins_AddComment(array('pin_id' => $pin_id, 'user_id' => $user_id, 'comment' => $text, 'date_added' => WM_Date::format(null, 'yy-mm-dd H:i:s')));
                                     }
                                 }
                                 sleep(1);
                             }
                         }
                         sleep(1);
                     }
                 }
             }
         }
     }
     exit;
 }