Пример #1
0
 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();
             }
         }
     }
 }
Пример #2
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');
 }
Пример #3
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');
 }