public function indexAction() { $request = $this->getRequest(); //first login after registration //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if ($request->getParam('direct_path') == 'true') { $this->sendWelcomeAction(); $this->redirect($request->getBaseUrl()); } if (!Helper_Config::get('config_disable_js')) { //if pin is in detail page $this->view->open_from_pin_detail_page = false; if ($request->getParam('open_from_pin_detail_page')) { $pin_array = new Model_Pins_Pin($request->getParam('open_from_pin_detail_page')); if ($pin_array->count()) { $pin_array = $pin_array->data; $this->getLayout()->placeholder('title', $pin_array['board_title'] . ' - ' . htmlspecialchars(strip_tags(html_entity_decode($pin_array['pin_description'])))); JO_Layout::getInstance()->placeholder('header_metas', $this->view->callChildren('pin/header_metas', $pin_array)); } $this->view->open_from_pin_detail_page = WM_Router::pinAction($request->getParam('open_from_pin_detail_page')); } } ///// get pins $page = (int) $request->getRequest('page'); if ($page < 1) { $page = 1; } $this->view->result_data = ''; if (!Helper_Config::get('config_disable_js')) { //get pins data if ($request->isXmlHttpRequest()) { $this->forward('index', 'getPins'); } } else { if ($page > 1 && $request->isXmlHttpRequest()) { $this->forward('index', 'getPins'); } $pins = (array) $this->getPinsAction(true); foreach ($pins as $pin) { $template = new Helper_Tmpl($pin['template'], $pin); $this->view->result_data .= $template->render($pin['template']); } } //call header and footer childrens $this->view->children = array('header_part' => 'layout/header_part', 'footer_part' => 'layout/footer_part'); }
public function __construct($pin_id, $data = array()) { $db = JO_Db::getDefaultAdapter(); try { $db->beginTransaction(); $pin_info = new Model_Pins_Pin($pin_id); if (!$pin_info->count()) { return $this; } $pin_info = $pin_info->data; if (isset($data['board_id'])) { $board_info = new Model_Boards_Board($data['board_id']); if ($board_info->count()) { $data['board_id'] = $board_info['board_board_id']; $data['category_id'] = $board_info['board_category_id']; $data['public'] = $board_info['board_public']; } else { $data['board_id'] = 0; } } $data['likes'] = new JO_Db_Expr('(SELECT COUNT(DISTINCT user_id) FROM pins_likes WHERE pin_id = pins.pin_id)'); $data['comments'] = new JO_Db_Expr('(SELECT COUNT(DISTINCT comment_id) FROM pins_comments WHERE pin_id = pins.pin_id)'); $data['date_modified'] = WM_Date::format(time(), 'yy-mm-dd H:i:s'); $data['source_id'] = 0; //sorce if (isset($data['from']) && $data['from']) { $source = new Model_Sources_GetSourceByUrl($data['from']); if ($source->source_id) { $data['source_id'] = $source->source_id; } } $data['from_md5'] = md5(isset($data['from']) ? $data['from'] : time()); /* price */ //$data['price'] = 0; if (isset($data['price']) && $data['price']) { $currencies = WM_Currency::getCurrencies(); $price_left = array(); $price_right = array(); if ($currencies) { foreach ($currencies as $currency) { if (trim($currency['symbol_left'])) { $price_left[] = preg_quote(trim($currency['symbol_left'])); } if (trim($currency['symbol_right'])) { $price_right[] = preg_quote(trim($currency['symbol_right'])); } } if ($price_left) { if (preg_match('/(' . implode('|', $price_left) . ')([\\s]{0,2})?(?:(?:\\d{1,5}(?:\\,\\d{3})+)|(?:\\d+))(?:\\.\\d{2})?/', $data['price'], $match)) { $price_tmp = trim(str_replace(trim($match[1]), '', $match[0])); $currency = self::getCurrencyBySimbol(trim($match[1])); if ($currency) { $data['price'] = round($price_tmp / $currency, 4); } } } if (!$data['price'] && $price_right) { if (preg_match('/(?:(?:\\d{1,5}(?:\\,\\d{3})+)|(?:\\d+))(?:\\.\\d{2})?([\\s]{0,2})?(' . implode('|', $price_right) . ')/', $data['price'], $match)) { $price_tmp = trim(str_replace(trim($match[2]), '', $match[0])); $currency = self::getCurrencyBySimbol(trim($match[2])); if ($currency) { $data['price'] = round($price_tmp / $currency, 4); } } } } } /* end price */ $from = isset($data['from']) ? $data['from'] : time(); $data['is_video'] = isset($data['is_video']) && $data['is_video'] == 'true' ? 1 : 0; if (!$data['is_video']) { $auto = new Helper_AutoEmbed(); if ($auto->parseUrl($from)) { $data['is_video'] = 1; } } /* is video */ ///////////////// Event onComplete ///////////////////// $on_add_call = Helper_Config::get('pin_onbefore_edit'); if ($on_add_call) { foreach ($on_add_call as $call) { call_user_func($call, $data); } } //edit pin $result = Helper_Db::update('pins', $data, array('pin_id = ?' => $pin_id)); ///////////////// update latest pins for board ///////////////////// if (isset($data['board_id']) && $data['board_id'] && $pin_info['pin_board_id'] != $data['board_id']) { new Model_Boards_UpdateLatestPins($data['board_id']); new Model_Boards_UpdateLatestPins($pin_info['pin_board_id']); $board_info = new Model_Boards_Board($data['board_id']); if ($board_info->count()) { if ($board_info['board_cover'] == $pin_id) { $res = Helper_Db::update('boards', array('cover' => 0), array('board_id = >' => $pin_info['pin_board_id'])); if (!$result && $res) { $result = $res; } } } } ///////////////// update latest pins for user ///////////////////// new Model_Users_UpdateLatestPins($pin_info['pin_user_id']); ///////////////// Word for search index's ///////////////////// $spl = JO_Utf8::str_word_split(strip_tags(html_entity_decode($data['description'], ENT_QUOTES, 'utf-8')), self::$searchWordLenght); $words = array(); foreach ($spl as $word) { $word = mb_strtolower($word, 'utf-8'); if (!in_array($word, self::blackWordsDictionary()) && $word[0] . $word[1] != '&#') { $words[$word] = $word; } } ///////////////// Word for search index's insert ///////////////////// Helper_Db::delete('pins_invert', array('pin_id = ?' => $pin_id)); foreach ($words as $word => $data1) { $dic_id = $db->fetchOne($db->select()->from('pins_dictionary', 'dic_id')->where('word = ?', $word)); if (!$dic_id) { $dic_id = Helper_Db::insert('pins_dictionary', array('word' => $word)); } if ($dic_id) { $res = Helper_Db::insert('pins_invert', array('pin_id' => $pin_id, 'dic_id' => $dic_id)); if (!$result && $res) { $result = $res; } } } ///////////////// Extension on edit ////////////////// $extensions = Model_Extensions::getByMethod('pin_onedit'); if ($extensions) { $front = JO_Front::getInstance(); foreach ($extensions as $id => $ext) { $pin_data_ext = call_user_func(array($front->formatModuleName('model_' . $ext . '_pin'), 'onedit'), $pin_id, $data); if ($pin_data_ext && is_array($pin_data_ext)) { $data = array_merge(data, $pin_data_ext); } } } ///////////////// Event onComplete ///////////////////// $trigger = new Helper_Triggers_PinOnEdit(); $trigger->bind($pin_id); $this->affected_rows = $result; $db->commit(); } catch (JO_Exception $e) { echo $e; exit; $db->rollBack(); } }
public function __construct($pin_id) { $db = JO_Db::getDefaultAdapter(); try { $db->beginTransaction(); $pin_info = new Model_Pins_Pin($pin_id); if (!$pin_info->count()) { return $this; } $pin_info = $pin_info->data; $result = null; if ($pin_info['pin_image']) { $res = Helper_Db::create('pins_images_for_delete', array('pin_id' => $pin_info['pin_pin_id'], 'date_added' => $pin_info['pin_date_added'], 'image' => $pin_info['pin_image'], 'store' => $pin_info['pin_store'], 'gallery_id' => 0)); if (!$result) { $result = $res; } } $gallery = new Model_Pins_Gallery($pin_info['pin_pin_id']); if ($gallery->count()) { foreach ($gallery->data as $gal) { $res = Helper_Db::create('pins_images_for_delete', array('pin_id' => $gal['pin_id'], 'date_added' => $pin_info['pin_date_added'], 'image' => $gal['image'], 'store' => $gal['store'], 'gallery_id' => $gal['gallery_id'])); if (!$result) { $result = $res; } } } if ($pin_info['pin_comments']) { $comments = Model_Comments::getComments2(array('filter_pin_id' => $pin_id)); foreach ($comments as $comment) { $del = new Model_Pins_DeleteComment($comment['comment_id']); if (!$result) { $result = $del->affected_rows; } } } $res = Helper_Db::delete('pins', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } $res = Helper_Db::delete('pins_invert', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } if ($pin_info['pin_likes']) { $res = Helper_Db::delete('pins_likes', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } } $res = Helper_Db::delete('pins_reports', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } $res = Helper_Db::delete('pins_views', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } $res = Helper_Db::delete('users_history', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } $res = Helper_Db::delete('pins_images', array('pin_id = ?' => $pin_id)); if (!$result) { $result = $res; } $res = Helper_Db::update('users', array('likes' => new JO_Db_Expr('(' . $db->select()->from('pins_likes', 'COUNT(like_id)')->where('pin_id IN (?)', new JO_Db_Expr('(' . $db->select()->from('pins', 'pin_id')->where('user_id = ?', $pin_info['user_user_id']) . ')'))->limit(1) . ')')), array('user_id=?' => $pin_info['user_user_id'])); if (!$result) { $result = $res; } ///////////////// update latest pins for user and board ///////////////////// new Model_Users_UpdateLatestPins($pin_info['user_user_id']); new Model_Boards_UpdateLatestPins($pin_info['board_board_id']); ///////////////// Extension on delete ////////////////// $extensions = Model_Extensions::getByMethod('pin_ondelete'); if ($extensions) { $front = JO_Front::getInstance(); foreach ($extensions as $id => $ext) { $res = call_user_func(array($front->formatModuleName('model_' . $ext . '_pin'), 'ondelete'), $pin_id); if (!$result) { $result = $res; } } } $this->affected_rows = $result; $db->commit(); } catch (JO_Exception $e) { $db->rollBack(); } }
public function editAction() { // var_dump( htmlspecialchars('⚐') );exit; $request = $this->getRequest(); $pin_id = $request->getRequest('pin_id'); // $pin_info = Model_Pins::getPin($pin_id); $pin_info = new Model_Pins_Pin($pin_id); if (!$pin_info->count() || $pin_info->data['pin_user_id'] != JO_Session::get('user[user_id]')) { $this->forward('error', 'error404'); } $pin_info = $pin_info->data; if ($request->isPost()) { $validate = new Helper_Validate(); if ($pin_info['pin_from']) { $validate->_set_rules($request->getPost('from'), $this->translate('Link'), 'not_empty;min_length[3];domain'); } else { if (trim($request->getPost('from'))) { $validate->_set_rules($request->getPost('from'), $this->translate('Link'), 'not_empty;min_length[3];domain'); } } $data = $request->getPost(); if ($validate->_valid_form()) { $edit = new Model_Pins_Edit($pin_id, $request->getPost()); $this->redirect(WM_Router::pinAction($pin_info['pin_pin_id'])); } else { $this->view->error = $validate->_get_error_messages(); } foreach ($data as $k => $v) { if (isset($pin_info['pin_' . $k])) { $pin_info['pin_' . $k] = $v; } } } $pin_info['images'] = Helper_Uploadimages::pinThumbs($pin_info); if ($pin_info['pin_gift']) { $pin_info['price_formated'] = WM_Currency::format($pin_info['pin_price']); } else { $pin_info['price_formated'] = ''; $pin_info['pin_price'] = 0; } $pin_info['href'] = WM_Router::pinAction($pin_info['pin_pin_id']); $this->view->pin_info = $pin_info; $view->get_user_friends = WM_Router::create($request->getBaseUrl() . '?controller=users&action=friends'); $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 edit ////////////////// $this->view->form_extensions = array(); $extensions = Model_Extensions::getByMethod('pin_oneditform'); if ($extensions) { $front = JO_Front::getInstance(); foreach ($extensions as $id => $ext) { $this->view->form_extensions[] = array('html' => $this->view->callChildren('modules_' . $ext . '_oneditform'), 'view' => $this->view->callChildrenView('modules_' . $ext . '_oneditform'), 'key' => $ext); } } $this->view->pin_delete = WM_Router::pinAction($pin_id, 'delete'); $this->view->children = array('header_part' => 'layout/header_part', 'footer_part' => 'layout/footer_part'); }
public function __construct($data = array()) { $db = JO_Db::getDefaultAdapter(); $data['category_id'] = 0; $data['public'] = 1; if (isset($data['board_id'])) { $board_info = new Model_Boards_Board($data['board_id']); if ($board_info->count()) { $data['board_id'] = $board_info['board_board_id']; $data['category_id'] = $board_info['board_category_id']; $data['public'] = $board_info['board_public']; } else { $data['board_id'] = 0; } } else { $data['board_id'] = 0; } $data['date_added'] = WM_Date::format(time(), 'yy-mm-dd H:i:s'); $data['date_modified'] = $data['date_added']; $data['user_id'] = isset($data['user_id']) ? $data['user_id'] : (string) JO_Session::get('user[user_id]'); $data['store'] = Helper_Config::get('file_upload_method') ? Helper_Config::get('file_upload_method') : 'Model_Upload_Locale'; $data['source_id'] = 0; //sorce if (isset($data['from']) && $data['from']) { $source = new Model_Sources_GetSourceByUrl($data['from']); if ($source->source_id) { $data['source_id'] = $source->source_id; } } $data['from_md5'] = md5(isset($data['from']) ? $data['from'] : time()); /* price */ //$data['price'] = 0; if (isset($data['price']) && $data['price']) { $currencies = WM_Currency::getCurrencies(); $price_left = array(); $price_right = array(); if ($currencies) { foreach ($currencies as $currency) { if (trim($currency['symbol_left'])) { $price_left[] = preg_quote(trim($currency['symbol_left'])); } if (trim($currency['symbol_right'])) { $price_right[] = preg_quote(trim($currency['symbol_right'])); } } if ($price_left) { if (preg_match('/(' . implode('|', $price_left) . ')([\\s]{0,2})?(?:(?:\\d{1,5}(?:\\,\\d{3})+)|(?:\\d+))(?:\\.\\d{2})?/', $data['price'], $match)) { $price_tmp = trim(str_replace(trim($match[1]), '', $match[0])); $currency = self::getCurrencyBySimbol(trim($match[1])); if ($currency) { $data['price'] = round($price_tmp / $currency, 4); } } } if (!$data['price'] && $price_right) { if (preg_match('/(?:(?:\\d{1,5}(?:\\,\\d{3})+)|(?:\\d+))(?:\\.\\d{2})?([\\s]{0,2})?(' . implode('|', $price_right) . ')/', $data['price'], $match)) { $price_tmp = trim(str_replace(trim($match[2]), '', $match[0])); $currency = self::getCurrencyBySimbol(trim($match[2])); if ($currency) { $data['price'] = round($price_tmp / $currency, 4); } } } } } /* end price */ $from = isset($data['from']) ? $data['from'] : time(); $data['is_video'] = isset($data['is_video']) && $data['is_video'] == 'true' ? 1 : 0; if (!$data['is_video']) { $auto = new Helper_AutoEmbed(); if ($auto->parseUrl($from)) { $data['is_video'] = 1; } } /* is video */ ///////////////// Event onComplete ///////////////////// $on_add_call = Helper_Config::get('pin_onbefore_create'); if ($on_add_call) { foreach ($on_add_call as $call) { call_user_func($call, $data); } } ///////////////// upload image ///////////////////// $image = false; if (isset($data['media']) && !isset($data['image'])) { $image = $data['media']; } else { if (isset($data['image'])) { $image = $data['image']; } } if (!isset($data['gallery']) && !$image) { return $this; } $data['image'] = ''; //create pin $data['pin_id'] = Helper_Db::insert('pins', $data); if (!$data['pin_id']) { return $this; } if (isset($data['gallery'])) { if (is_array($data['gallery']) && count($data['gallery']) > 0) { $method_for_upload = Helper_Config::get('file_upload_method'); if ($method_for_upload) { foreach ($data['gallery'] as $row => $image_get) { if ($this->error) { return $this; } $image = call_user_func(array($method_for_upload, 'uploadPin'), $image_get, isset($data['title']) && $data['title'] ? $data['title'] : $data['description'], $data['pin_id']); $this->error = call_user_func(array($method_for_upload, 'getError')); if ($image && isset($image['image'])) { if ($row == 0) { Helper_Db::update('pins', array('image' => $image['image'], 'store' => $image['store'], 'height' => $image['height'], 'width' => $image['width']), array('pin_id = ?' => (string) $data['pin_id'])); } else { $gal_id = Helper_Db::insert('pins_gallery', array('image' => $image['image'], 'store' => $image['store'], 'pin_id' => $data['pin_id'], 'sort_order' => $row)); if (!$gal_id) { return $this; } } } else { return $this; } } } else { Helper_Db::delete('pins', array('pin_id = ?' => (string) $data['pin_id'])); return $this; } } else { Helper_Db::delete('pins', array('pin_id = ?' => (string) $data['pin_id'])); return $this; } } else { $method_for_upload = Helper_Config::get('file_upload_method'); if ($method_for_upload && $image) { $image = call_user_func(array($method_for_upload, 'uploadPin'), $image, isset($data['title']) && $data['title'] ? $data['title'] : $data['description'], $data['pin_id']); $this->error = call_user_func(array($method_for_upload, 'getError')); if ($image && isset($image['image'])) { Helper_Db::update('pins', array('image' => $image['image'], 'store' => $image['store'], 'height' => $image['height'], 'width' => $image['width']), array('pin_id = ?' => (string) $data['pin_id'])); } else { Helper_Db::delete('pins', array('pin_id = ?' => (string) $data['pin_id'])); return $this; } } else { Helper_Db::delete('pins', array('pin_id = ?' => (string) $data['pin_id'])); return $this; } } ///////////////// update latest pins for board ///////////////////// if (isset($data['board_id']) && $data['board_id']) { new Model_Boards_UpdateLatestPins($data['board_id']); } ///////////////// update latest pins for user ///////////////////// new Model_Users_UpdateLatestPins($data['user_id']); ///////////////// Pin total repins ///////////////////// if (isset($data['repin_from']) && $data['repin_from']) { $pin_repin = new Model_Pins_Pin($data['repin_from']); if ($pin_repin->count()) { Helper_Db::update('pins', array('repins' => $db->fetchOne($db->select()->from('pins', 'COUNT(pin_id)')->where('repin_from = ?', $data['repin_from'])->limit(1))), array('pin_id = ?' => $data['repin_from'])); } } ///////////////// Word for search index's ///////////////////// $spl = JO_Utf8::str_word_split(strip_tags(html_entity_decode($data['description'], ENT_QUOTES, 'utf-8')), self::$searchWordLenght); $words = array(); foreach ($spl as $word) { $word = mb_strtolower($word, 'utf-8'); if (!in_array($word, self::blackWordsDictionary()) && $word[0] . $word[1] != '&#') { $words[$word] = $word; } } ///////////////// Word for search index's insert ///////////////////// foreach ($words as $word => $data1) { $dic_id = $db->fetchOne($db->select()->from('pins_dictionary', 'dic_id')->where('word = ?', $word)); if (!$dic_id) { $db->insert('pins_dictionary', array('word' => $word)); $dic_id = $db->lastInsertId(); } if ($dic_id) { $db->insert('pins_invert', array('pin_id' => $data['pin_id'], 'dic_id' => $dic_id)); } } Helper_Db::delete('pins_images', array('pin_id = ?' => $data['pin_id'])); ///////////////// Extension on create ////////////////// $extensions = Model_Extensions::getByMethod('pin_oncreate'); if ($extensions) { $front = JO_Front::getInstance(); foreach ($extensions as $id => $ext) { $pin_data_ext = call_user_func(array($front->formatModuleName('model_' . $ext . '_pin'), 'oncreate'), $data['pin_id'], $data); if ($pin_data_ext && is_array($pin_data_ext)) { $data = array_merge(data, $pin_data_ext); } } } ///////////////// Event onComplete ///////////////////// $trigger = new Helper_Triggers_PinOnCreate(); $trigger->bind($data['pin_id']); $this->data = $data; // parent::__construct($data); }
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(); } } } }
public static function formatPinData($pin, $detail = false) { static $model_images = null, $request = null; if ($model_images === null) { $model_images = new Helper_Images(); } if ($request === null) { $request = JO_Request::getInstance(); } ///////////////////////////////////// PIN INFO ///////////////////////////////////// $pin['pin_id'] = $pin['pin_pin_id']; $pin['image'] = $pin['pin_image']; //url's $pin['pin_url_embed'] = WM_Router::pinAction($pin['pin_pin_id'], 'embed'); if (!JO_Session::get('user[user_id]')) { $login_url = WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'); if (Helper_Config::get('enable_free_registration')) { //$login_url = WM_Router::create( $request->getBaseUrl() . '?controller=users&action=register' ); } $pin['pin_url_email'] = $pin['pin_url_report'] = $pin['pin_url_like'] = $pin['pin_url_repin'] = $pin['pin_url_comment'] = $login_url; $pin['pin_edit'] = false; } else { $pin['pin_url_email'] = WM_Router::pinAction($pin['pin_pin_id'], 'email'); $pin['pin_url_report'] = WM_Router::pinAction($pin['pin_pin_id'], 'report'); $pin['pin_url_like'] = WM_Router::pinAction($pin['pin_pin_id'], 'like'); $pin['pin_url_repin'] = WM_Router::pinAction($pin['pin_pin_id'], 'repin'); $pin['pin_url_comment'] = WM_Router::pinAction($pin['pin_pin_id']); $pin['pin_edit'] = JO_Session::get('user[user_id]') == $pin['pin_user_id'] ? WM_Router::pinAction($pin['pin_pin_id'], 'edit') : false; } //$pin['pin_description'] = self::descriptionFix($pin['pin_description']); $pin['pin_href'] = WM_Router::pinAction($pin['pin_pin_id']); if ($pin['pin_gift']) { $pin['pin_price_formated'] = WM_Currency::format($pin['pin_price']); } else { $pin['pin_price_formated'] = 0; } //return all image sizes $pin['pin_thumbs'] = Helper_Uploadimages::pinThumbs($pin); //array_merge($pin, Helper_Uploadimages::pinThumbs($pin)); $date_dif = array_shift(WM_Date::dateDiff($pin['pin_date_added'], time())); $pin['pin_date_dif'] = $date_dif; /* URL'S*/ $pin['pin_onto_href'] = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $pin['board_user_id'] . '&board_id=' . $pin['board_board_id']); ////follow urls $pin['board_follow_href'] = $pin['user_follow_href'] = $pin['via_follow_href'] = false; if (JO_Session::get('user[user_id]') ? $pin['board_user_id'] != JO_Session::get('user[user_id]') : false) { $pin['board_follow_href'] = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=follow&user_id=' . $pin['board_user_id'] . '&board_id=' . $pin['board_board_id']); } if (JO_Session::get('user[user_id]') ? $pin['user_user_id'] != JO_Session::get('user[user_id]') : false) { $pin['user_follow_href'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=follow&user_id=' . $pin['user_user_id']); } if ($pin['via_user_id']) { if (JO_Session::get('user[user_id]') ? $pin['via_user_id'] != JO_Session::get('user[user_id]') : false) { $pin['via_follow_href'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=follow&user_id=' . $pin['via_user_id']); } } else { if (JO_Session::get('user[user_id]') ? $pin['user_user_id'] != JO_Session::get('user[user_id]') : false) { $pin['via_follow_href'] = $pin['user_follow_href']; } } if ($detail) { $pin['pin_next_href'] = ''; if (isset($pin['pin_next']) && $pin['pin_next']) { $pin['pin_next_href'] = WM_Router::pinAction($pin['pin_next']); } $pin['pin_prev_href'] = ''; if (isset($pin['pin_prev']) && $pin['pin_prev']) { $pin['pin_prev_href'] = WM_Router::pinAction($pin['pin_prev']); } } if (Helper_Config::get('config_comments_list') && !$detail && $pin['pin_comments']) { $latest_comments = Model_Comments::getLatestComments2($pin['pin_latest_comments']); $pin['pin_latest_comments'] = array(); $user_id = JO_Session::get('user[user_id]'); $is_admin = JO_Session::get('user[is_admin]'); $is_developer = JO_Session::get('user[is_developer]'); foreach ($latest_comments as $key => $comment) { $user_avatars = Helper_Uploadimages::userAvatars(array('avatar' => $comment['avatar'], 'store' => $comment['store'], 'user_id' => $comment['user_id'])); $enable_delete = false; if ($is_admin) { $enable_delete = true; } elseif ($is_developer) { $enable_delete = true; } elseif ($user_id == $comment['user_id']) { $enable_delete = true; } elseif ($comment['pin_user_id'] == $user_id) { $enable_delete = true; } $delete = false; if ($enable_delete) { $delete = WM_Router::create($request->getBaseUrl() . '?controller=pin&action=deleteComment&comment_id=' . $comment['comment_id']); } $pin['pin_latest_comments'][] = array('user' => array('profile' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $comment['user_id']), 'avatars' => $user_avatars, 'fullname' => $comment['fullname']), 'comment' => $comment['comment'], 'delete' => $delete); } } else { $pin['pin_latest_comments'] = array(); } $pin['pin_video_code'] = false; if ($detail) { if ($pin['pin_is_video']) { $auto = new Helper_AutoEmbed(); if ($pin['pin_repin_from'] && $auto->parseUrl($pin['pin_from_repin'])) { $auto->setWidth('100%'); $auto->setHeight('350'); $pin['pin_video_code'] = $auto->getEmbedCode(); } else { if ($auto->parseUrl($pin['pin_from'])) { $auto->setWidth('100%'); $auto->setHeight('350'); $pin['pin_video_code'] = $auto->getEmbedCode(); } else { $pin['pin_is_video'] = false; } } } else { $auto = new Helper_AutoEmbed(); if ($pin['pin_repin_from'] && $auto->parseUrl($pin['pin_from_repin'])) { $auto->setWidth('100%'); $auto->setHeight('350'); $pin['pin_video_code'] = $auto->getEmbedCode(); $pin['pin_is_video'] = true; } else { if ($auto->parseUrl($pin['pin_from'])) { $auto->setWidth('100%'); $auto->setHeight('350'); $pin['pin_video_code'] = $auto->getEmbedCode(); $pin['pin_is_video'] = true; } else { $pin['pin_is_video'] = false; } } } $pin['pin_gallery'] = array(); $gallery = new Model_Pins_Gallery($pin['pin_pin_id']); if ($gallery->count()) { foreach ($gallery->data as $gal) { $pin['pin_gallery'][] = Helper_Uploadimages::pinThumbs(array('pin_pin_id' => $gal['pin_id'], 'pin_store' => $gal['store'], 'gallery_id' => $gal['gallery_id'], 'pin_image' => $gal['image'])); } } } ///////////////////////////////////// AUTHOR INFO ///////////////////////////////////// //return author all images $user_data = array('avatar' => $pin['user_avatar'], 'store' => $pin['user_store'], 'user_id' => $pin['user_user_id']); foreach ($pin as $k => $v) { if (strpos($k, 'user_avatar_') === 0) { $user_data[$k] = $v; } } $pin['user_avatars'] = Helper_Uploadimages::userAvatars($user_data); $pin['user_href'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $pin['user_user_id']); ///////////////////////////////////// VIA INFO ///////////////////////////////////// $pin['via_profile'] = array(); if ($pin['via_user_id']) { $via_avatars = Helper_Uploadimages::userAvatars(array('avatar' => $pin['via_avatar'], 'store' => $pin['via_store'], 'user_id' => $pin['via_user_id'])); $pin['via_profile'] = array('avatars' => $via_avatars, 'profile' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . $pin['via_user_id']), 'fullname' => $pin['via_fullname']); } ///////////////////////////////////// SELF INFO ///////////////////////////////////// $pin['self_profile'] = false; if (JO_Session::get('user[user_id]')) { $user_avatars = Helper_Uploadimages::userAvatars(array('avatar' => JO_Session::get('user[avatar]'), 'store' => JO_Session::get('user[store]'), 'user_id' => JO_Session::get('user[user_id]'))); $pin['self_profile']['avatars'] = $user_avatars; $pin['self_profile']['fullname'] = JO_Session::get('user[fullname]'); $pin['self_profile']['profile'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . JO_Session::get('user[user_id]')); } ///////////////////////////////////// SOURCE INFO ///////////////////////////////////// $pin['pin_source'] = array(); $pin['pin_target_repin'] = false; if ($detail) { if ($pin['pin_repin_from']) { $pin_repin = new Model_Pins_Pin($pin['pin_repin_from']); if ($pin_repin->count()) { $pin_repin = $pin_repin->data; $pin['pin_source']['source'] = $pin_repin['board_title']; $pin['pin_from'] = WM_Router::create($request->getBaseUrl() . '?controller=boards&action=view&user_id=' . $pin_repin['user_user_id'] . '&board_id=' . $pin_repin['board_board_id']); $pin['pin_target_repin'] = true; } else { $source = new Model_Sources_Source($pin['pin_source_id']); if ($source->count()) { $pin['pin_source']['source'] = $source['source']; } } } else { $source = new Model_Sources_Source($pin['pin_source_id']); if ($source->count()) { $pin['pin_source']['source'] = $source['source']; } } } ///for mobile $pin['mobile_upload'] = false; if ($pin['pin_from'] == 'Mobile') { $pin['pin_from'] = ''; $pin['mobile_upload'] = true; } return $pin; }
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'); }