Пример #1
0
 public function action_comments()
 {
     $methods = array();
     $methods["send"] = function ($data) {
         $model_comments = new Model_Comments();
         $res = $model_comments->send_comment($data);
         return $res;
     };
     $methods["get_comments"] = function ($data) {
         $model_comments = new Model_Comments();
         $res = $model_comments->get_comments($data);
         return $res;
     };
     $data = Arr::get($_POST, 'data', '');
     if ($data == '') {
         $data = Arr::get($_GET, 'data', '');
     }
     extract(json_decode($data, true));
     $res = false;
     if (isset($methods[$method])) {
         unset($data["captcha"]);
         unset($data["test"]);
         unset($data["method"]);
         $res = $methods[$method]($data);
         PC::debug($res, 'Ajax: "' . $method . '"');
     }
     exit(json_encode($res));
 }
Пример #2
0
 public function deleteMultiCommentsAction()
 {
     $this->setInvokeArg('noViewRenderer', true);
     if (!WM_Users::allow('delete', $this->getRequest()->getController())) {
         echo $this->translate('You do not have permission to this action');
     } else {
         $action_check = $this->getRequest()->getPost('action_check');
         if ($action_check && is_array($action_check)) {
             foreach ($action_check as $record_id) {
                 Model_Comments::deleteComment($record_id);
             }
         }
     }
 }
Пример #3
0
 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();
     }
 }
Пример #4
0
 public static function delete($pin_id)
 {
     $db = JO_Db::getDefaultAdapter();
     $pin_info = self::getPin($pin_id);
     if (!$pin_info) {
         return false;
     }
     if ($pin_info['store'] == 's3') {
         self::deleteImagesAmazon($pin_info['image']);
     } else {
         $model_image = new Helper_Images();
         $model_image->deleteImages($pin_info['image']);
     }
     $comments = Model_Comments::getComments(array('filter_pin_id' => $pin_id));
     if ($comments) {
         foreach ($comments as $comment) {
             $db->delete('pins_comments', array('comment_id = ?' => $comment['comment_id']));
             $db->delete('pins_reports_comments', array('comment_id = ?' => $comment['comment_id']));
         }
     }
     $del = $db->delete('pins', array('pin_id = ?' => $pin_id));
     if (!$del) {
         return false;
     } else {
         $latest_pins = array();
         $pins_query = $db->select()->from('pins', array('pin_id', 'pin_id'))->where('user_id = ?', $pin_info['user_id'])->order('pin_id DESC')->limit(15);
         $latest = $db->fetchPairs($pins_query);
         if ($latest) {
             $latest_pins = $latest;
         }
         $update = array('pins' => new JO_Db_Expr('pins-1'), 'latest_pins' => implode(',', $latest_pins));
         $update['likes'] = new JO_Db_Expr('likes-' . (int) $db->fetchOne($db->select()->from('pins_likes', 'COUNT(like_id)')->where('pin_id = ?', $pin_id)));
         $db->update('users', $update, array('user_id=?' => $pin_info['user_id']));
         $latest_pins = array();
         $pins_query = $db->select()->from('pins', array('pin_id', 'pin_id'))->where('board_id = ?', $pin_info['board_id'])->order('pin_id DESC')->limit(15);
         $latest = $db->fetchPairs($pins_query);
         if ($latest) {
             $latest_pins = $latest;
         }
         $update = array('pins' => new JO_Db_Expr('pins-1'), 'latest_pins' => implode(',', $latest_pins));
         $update['latest_pins'] = implode(',', $latest_pins);
         $db->update('boards', $update, array('board_id=?' => $pin_info['board_id']));
         $db->delete('pins_invert', array('pin_id = ?' => $pin_id));
         $db->delete('pins_likes', array('pin_id = ?' => $pin_id));
         $db->delete('pins_reports', array('pin_id = ?' => $pin_id));
         $db->delete('pins_views', array('pin_id = ?' => $pin_id));
         $db->delete('users_history', array('pin_id = ?' => $pin_id));
         self::deleteCache($pin_info);
         return true;
     }
 }
Пример #5
0
 public function recents_for_userAction()
 {
     $request = $this->getRequest();
     $this->setViewChange('search');
     $username = $request->getRequest('recents_for_user');
     $username = trim(mb_strtolower(urldecode($username), 'UTF-8'));
     $this->view->crumbs = array(array('name' => $this->translate('Home'), 'href' => $request->getBaseUrl()), array('name' => $this->translate('Forum'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=forum')), array('name' => $username));
     $this->view->mainCategories = array();
     $this->view->mainCategories = Model_Forum::getAll();
     foreach ($this->view->mainCategories as $k => $v) {
         $this->view->mainCategories[$k]['href'] = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=thread/' . $this->view->mainCategories[$k]['id'] . '/' . WM_Router::clearName($this->view->mainCategories[$k]['name']));
     }
     $this->view->mainCategories = array_merge(array(0 => array('name' => $this->translate('All Topics'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=forum'))), $this->view->mainCategories);
     $this->view->headline = $this->translate('All Topics');
     $this->view->sel_thread = -1;
     $this->view->headline = $this->translate('Recent') . ': ' . $username;
     $threads = Model_Forum::getRecentByUser($username);
     $total_records = count($threads);
     if ($threads) {
         $model_images = new Model_Images();
         $page = (int) $request->getRequest('page', 1);
         if ($page < 1) {
             $page = 1;
         }
         $limit = JO_Registry::get('front_limit');
         $total_records = count($threads);
         $start = $page * $limit - $limit;
         if ($start > $total_records) {
             $page = max(ceil($total_records / $limit), 1);
             $start = $page * $limit - $limit;
         } elseif ($start < 0) {
             $start = 0;
         }
         $threads = array_slice($threads, $start, $limit);
         $bbcode_parser = new WM_BBCode_Parser();
         $bbcode_parser->loadDefaultCodes();
         foreach ($threads as $th) {
             if ($th['avatar']) {
                 $th['avatar'] = $model_images->resize($th['avatar'], JO_Registry::forceGet('user_avatar_width'), JO_Registry::forceGet('user_avatar_height'), true);
             } else {
                 $th['avatar'] = 'data/themes/images/noavatar.png';
             }
             $th['userhref'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=index&username='******'username']));
             $th_link = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=topic/' . $th['id'] . '/' . WM_Router::clearName($th['name']));
             $th['threadhref'] = $thread_link;
             $th['reporthref'] = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=report/' . $th['id']);
             $th['recent_link'] = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=recents_for_user&username='******'username']));
             $th['threads_user_link'] = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=threads_for_user&username='******'username']));
             $bbcode_parser->parse($th['comment']);
             $th['comment_formated'] = Model_Comments::replaceEmoticons($bbcode_parser->getAsHtml());
             $last_page = ceil($thread['cnt'] / $limit);
             $th['datetime'] = WM_Date::format($th['datetime'], 'dd M yy H:i');
             $th['badges'] = Helper_Author::userBadges($th['badges']);
             $this->view->threads[] = $th;
         }
         $pagination = new Model_Pagination();
         $pagination->setLimit($limit);
         $pagination->setPage($page);
         $pagination->setText(array('text_prev' => $this->view->translate('Prev'), 'text_next' => $this->view->translate('Next')));
         $pagination->setTotal($total_records);
         $pagination->setUrl(WM_Router::create($request->getBaseUrl() . '?controller=forum&action=index&page={page}'));
         $this->view->pagination = $pagination->render();
         if (!empty($this->view->pagination)) {
             $this->view->pagination = str_replace('{of}', $this->view->translate('OF'), $this->view->pagination);
         }
     }
     $this->view->children = array();
     $this->view->children['rightside'] = 'forum/rightside';
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }
Пример #6
0
 public function dashboardAction()
 {
     $request = $this->getRequest();
     $model_images = new Model_Images();
     if (!JO_Session::get('user_id')) {
         JO_Session::set('msg_error', $this->translate('You must be logged to view your dashboard'));
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'));
     }
     $this->getLayout()->meta_title = $this->translate('Dashboard');
     $this->getLayout()->meta_description = $this->translate('Dashboard');
     $page = (int) $request->getRequest('page', 1);
     if ($page < 1) {
         $page = 1;
     }
     $limit = JO_Registry::get('front_limit');
     if (JO_Session::get('msg_success')) {
         $this->view->msg_success = JO_Session::get('msg_success');
         JO_Session::clear('msg_success');
     }
     if (JO_Session::get('msg_error')) {
         $this->view->msg_error = JO_Session::get('msg_error');
         JO_Session::clear('msg_error');
     }
     $username = JO_Session::get('username');
     $this->view->crumbs = array(array('name' => $this->translate('Home'), 'href' => $request->getBaseUrl()), array('name' => $username, 'href' => WM_Router::create($request->getBaseUrl() . '?controller=users&username='******'name' => $this->translate('Dashboard')));
     $user = Model_Users::getByUsername($username);
     $this->view->author_header = Helper_Author::authorHeader($user);
     $where = "`items_comments`.`user_id` = '" . $user['user_id'] . "' AND `items_comments`.`reply_to` = 0";
     $total_records = Model_Comments::getTotal($where);
     $start = $page * $limit - $limit;
     if ($start > $total_records) {
         $page = max(ceil($total_records / $limit), 1);
         $start = $page * $limit - $limit;
     } elseif ($start < 0) {
         $start = 0;
     }
     $bayers = Model_Orders::getClients($user['user_id']);
     $comments = Model_Comments::getAll($start, $limit, $where, true, "datetime DESC");
     $this->view->comments = array();
     if ($comments) {
         $bbcode_parser = new WM_BBCode_Parser();
         $bbcode_parser->loadDefaultCodes();
         foreach ($comments as $comment) {
             if ($comment['avatar']) {
                 $comment['avatar'] = $model_images->resize($comment['avatar'], JO_Registry::forceGet('user_avatar_width'), JO_Registry::forceGet('user_avatar_height'), true);
             } else {
                 $comment['avatar'] = 'data/themes/images/noavatar.png';
             }
             $bbcode_parser->parse($comment['comment']);
             $comment['comment'] = Model_Comments::replaceEmoticons($bbcode_parser->getAsHtml());
             $comment['datetime'] = WM_Date::format($comment['datetime'], 'dd M yy');
             $comment['userhref'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=index&username='******'username']));
             $comment['reporthref'] = WM_Router::create($request->getBaseUrl() . '?controller=items&action=report/' . $comment['id']);
             $comment['replyhref'] = WM_Router::create($request->getBaseUrl() . '?controller=items&action=reply&c_id=' . $comment['id']);
             $comment['item_href'] = WM_Router::create($request->getBaseUrl() . '?controller=items&action=comments&item_id=' . $comment['item_id'] . '&name=' . WM_Router::clearName($comment['name'])) . '#c_' . $comment['id'];
             foreach ($comment['reply'] as $key => $reply) {
                 if ($comment['reply'][$key]['avatar']) {
                     $comment['reply'][$key]['avatar'] = $model_images->resize($comment['reply'][$key]['avatar'], 50, 50, true);
                 } else {
                     $comment['reply'][$key]['avatar'] = 'data/themes/images/small_noavatar.png';
                 }
                 $bbcode_parser->parse($comment['reply'][$key]['comment']);
                 $comment['reply'][$key]['comment'] = Model_Comments::replaceEmoticons($bbcode_parser->getAsHtml());
                 $comment['reply'][$key]['datetime'] = WM_Date::format($reply['datetime'], 'dd M yy');
                 $comment['reply'][$key]['is_buy'] = $bayers && in_array($reply['user_id'], $bayers);
                 $comment['reply'][$key]['userhref'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=index&username='******'reply'][$key]['username']));
                 $comment['reply'][$key]['reporthref'] = WM_Router::create($request->getBaseUrl() . '?controller=items&action=report/' . $comment['reply'][$key]['id']);
             }
             $this->view->comments[] = $comment;
         }
     }
     $pagination = new Model_Pagination();
     $pagination->setLimit($limit);
     $pagination->setPage($page);
     $pagination->setText(array('text_prev' => $this->view->translate('Prev'), 'text_next' => $this->view->translate('Next')));
     $pagination->setTotal($total_records);
     $pagination->setUrl(WM_Router::create($request->getBaseUrl() . '?action=users&action=dashboard&page={page}'));
     $this->view->pagination = $pagination->render();
     if (!empty($this->view->pagination)) {
         $this->view->pagination = str_replace('{of}', $this->view->translate('OF'), $this->view->pagination);
     }
     //$this->view->add_comment_link = WM_Router::create($request->getBaseUrl() .'?controller=items&action=add_comment&item_id='. $item['id'] .'&name='. WM_Router::clearName($item['name']));
     $this->view->mainCategories = array();
     $categories = Model_Categories::getMain();
     if ($categories) {
         $this->view->mainCategories = array(array('href' => '', 'name' => $this->translate('Please select category')));
         foreach ($categories as $category) {
             $this->view->mainCategories[] = array('href' => WM_Router::create($request->getBaseUrl() . '?controller=upload&action=form&category_id=' . $category['id']), 'name' => $category['name']);
         }
     }
     $this->view->total_balance = WM_Currency::format($user['total']);
     $this->view->total_sales_cnt = JO_Session::get('sales');
     $this->view->percent = Model_Percentes::getPercentRow($user);
     $help = Model_Pages::get(JO_Registry::forceGet('page_upload_item'));
     if ($help) {
         $this->view->page_upload_item = array('name' => $help['name'], 'href' => WM_Router::create($request->getBaseUrl() . '?controller=pages&page_id=' . $help['id'] . '&name=' . WM_Router::clearName($help['name'])));
     }
     $weekStats = Model_Orders::getWeekStats($user['user_id']);
     $this->view->weekStats_earning = WM_Currency::format($weekStats['earning']);
     $this->view->weekStats_sold = $weekStats['sold'];
     $user['total'] = WM_Currency::format($user['total']);
     $this->view->user = $user;
     $this->view->children = array();
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }
 public function deletepAction()
 {
     $this->setInvokeArg('noViewRenderer', true);
     if (!WM_Users::allow('delete', $this->getRequest()->getController())) {
         echo $this->translate('You do not have permission to this action');
     } else {
         Model_Comments::deleteRC($this->getRequest()->getPost('id'));
     }
 }
Пример #8
0
 public function deleteAction()
 {
     $this->noViewRenderer(true);
     Model_Comments::deleteComment($this->getRequest()->getPost('id'));
 }
Пример #9
0
 public function getCommentsAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $pin_id = $request->getRequest('pin_id');
     $return = array();
     $comments = Model_Comments::getComments2(array('filter_pin_id' => $pin_id));
     $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 ($comments as $key => $comment) {
         $user_avatars = Helper_Uploadimages::userAvatars(array('avatar' => $comment['avatar'], 'store' => $comment['store'], 'user_id' => $comment['user_id']));
         $reported = false;
         if ($user_id && !$comment['is_reported']) {
             $reported = WM_Router::pinAction($pin_id, 'reportComment', 'comment_id=' . $comment['comment_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::pinAction($pin_id, 'deleteComment', 'comment_id=' . $comment['comment_id']);
         }
         $return[] = 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'], 'url_delete' => $delete, 'url_report' => $reported, 'text_delete' => $this->translate('Delete Comment'), 'text_report' => $this->translate('Report Comment'));
     }
     //format response data
     $formatObject = new Helper_Format();
     $formatObject->responseJsonCallback($return);
     $this->noViewRenderer(true);
 }
Пример #10
0
 public static function getAllCategory()
 {
     $data = [];
     $data = Model_Comments::getAll(__CLASS__, 'coment');
     return $data;
 }
Пример #11
0
 public function commentsAction()
 {
     $request = $this->getRequest();
     $this->view->currency = WM_Currency::getCurrency();
     $itemID = $request->getRequest('comments');
     $item = Model_Items::get($itemID);
     if (!is_array($item) || $item['status'] == 'deleted' || JO_Session::get('username') && $item['status'] == 'unapproved' && $item['user_id'] != $_SESSION['user']['user_id'] || $item['status'] == 'queue' || $item['status'] == 'extended_buy') {
         return $this->forward('error', 'error404');
     }
     $this->view->item_link = WM_Router::create($request->getBaseUrl() . '?controller=items&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name']));
     $faqs_data = Model_Faq::getAll($itemID);
     if (JO_Session::get('user_id') == $item['user_id'] || $faqs_data) {
         $this->view->faq_link = WM_Router::create($request->getBaseUrl() . '?controller=items&action=faq&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name']));
     }
     if (JO_Session::get('user_id') == $item['user_id']) {
         $this->view->edit_link = WM_Router::create($request->getBaseUrl() . '?controller=items&action=edit&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name']));
         $this->view->delete_link = WM_Router::create($request->getBaseUrl() . '?controller=items&action=delete&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name']));
     }
     $this->view->comment_link = WM_Router::create($request->getBaseUrl() . '?controller=items&action=comments&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name']));
     JO_Session::set('redirect', $this->view->comment_link);
     if (JO_Session::get('msg_success')) {
         $this->view->msg_success = JO_Session::get('msg_success');
         JO_Session::clear('msg_success');
     }
     if (JO_Session::get('msg_error')) {
         $this->view->msg_error = JO_Session::get('msg_error');
         JO_Session::clear('msg_error');
     }
     $user = $item['user'] = Model_Users::getUser($item['user_id']);
     $this->view->crumbs = array(array('name' => $this->translate('Home'), 'href' => $request->getBaseUrl()), array('name' => $this->translate('Portfolio'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=users&username='******'username']))), array('name' => $item['name'], 'href' => $this->view->item_link), array('name' => $this->translate('Comments')));
     $model_images = new Model_Images();
     $filter = '';
     if ($request->getRequest('filter')) {
         $filter = ' AND items_comments.id = ' . (int) $request->getRequest('filter');
     }
     $bayers = Model_Orders::getBayers($itemID);
     $comments = Model_Comments::getAll(0, 0, "item_id = '" . (int) $itemID . "' AND reply_to = 0" . $filter, true);
     $this->view->smiles = Model_Smiles::getSmilesImages();
     $this->view->comments = array();
     if ($comments) {
         $bbcode_parser = new WM_BBCode_Parser();
         $bbcode_parser->loadDefaultCodes();
         foreach ($comments as $comment) {
             if ($comment['avatar']) {
                 $comment['avatar'] = $model_images->resize($comment['avatar'], JO_Registry::forceGet('user_avatar_width'), JO_Registry::forceGet('user_avatar_height'), true);
             } else {
                 $comment['avatar'] = 'data/themes/images/noavatar.png';
             }
             $bbcode_parser->parse($comment['comment']);
             $comment['comment'] = Model_Comments::replaceEmoticons($bbcode_parser->getAsHtml());
             $comment['badges'] = Helper_Author::userBadges(Model_Users::getUser($comment['owner_id']));
             $comment['datetime'] = WM_Date::format($comment['datetime'], 'dd M yy', true);
             $comment['is_buy'] = $bayers && in_array($comment['user_id'], $bayers);
             $comment['userhref'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=index&username='******'username']));
             $comment['reporthref'] = WM_Router::create($request->getBaseUrl() . '?controller=items&action=report/' . $comment['id']);
             $comment['replyhref'] = WM_Router::create($request->getBaseUrl() . '?controller=items&action=reply&c_id=' . $comment['id']);
             foreach ($comment['reply'] as $key => $reply) {
                 if ($comment['reply'][$key]['avatar']) {
                     $comment['reply'][$key]['avatar'] = $model_images->resize($comment['reply'][$key]['avatar'], 50, 50, true);
                 } else {
                     $comment['reply'][$key]['avatar'] = 'data/themes/images/small_noavatar.png';
                 }
                 $bbcode_parser->parse($comment['reply'][$key]['comment']);
                 $comment['reply'][$key]['comment'] = Model_Comments::replaceEmoticons($bbcode_parser->getAsHtml());
                 $comment['reply'][$key]['badges'] = Helper_Author::userBadges(Model_Users::getUser($comment['reply'][$key]['owner_id']));
                 $comment['reply'][$key]['datetime'] = WM_Date::format($reply['datetime'], 'dd M yy', true);
                 $comment['reply'][$key]['is_buy'] = $bayers && in_array($reply['user_id'], $bayers);
                 $comment['reply'][$key]['userhref'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=index&username='******'reply'][$key]['username']));
                 $comment['reply'][$key]['reporthref'] = WM_Router::create($request->getBaseUrl() . '?controller=items&action=report/' . $comment['reply'][$key]['id']);
             }
             $this->view->comments[] = $comment;
         }
     }
     $this->view->add_comment_link = WM_Router::create($request->getBaseUrl() . '?controller=items&action=add_comment&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name']));
     $this->getLayout()->meta_title = $item['name'];
     $this->getLayout()->meta_description = substr(strip_tags(html_entity_decode($item['description'], ENT_QUOTES, 'utf-8')), 0, 255);
     $this->view->item = $item;
     $this->view->user = $user;
     $this->view->children = array();
     $this->view->children['rightside'] = 'items/rightside';
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }
Пример #12
0
 public static function getPins($data = array(), &$pin_ids = array())
 {
     $db = JO_Db::getDefaultAdapter();
     $cache_live = (int) JO_Registry::get('config_cache_live');
     if ($cache_live && isset($data['filter_rand']) && $data['filter_rand'] == true && isset($data['start']) && isset($data['limit'])) {
         $check = $db->select()->from('cache_index')->where('start_limit = ?', $data['start'] . '.' . $data['limit'])->where('`date` >= ?', time())->limit(1);
         $cache = $db->fetchRow($check);
         if ($cache) {
             $results = JO_Json::decode($cache['data'], true);
             if ($results && is_array($results)) {
                 $return = array();
                 foreach ($results as $result) {
                     if (self::pinIsExist($result['pin_id'])) {
                         $return[] = $result;
                     }
                 }
                 return $return;
             }
         }
     } elseif ($cache_live && isset($data['filter_like_repin_comment']) && $data['filter_like_repin_comment'] == true && isset($data['start']) && isset($data['limit'])) {
         $check = $db->select()->from('cache_popular')->where('start_limit = ?', $data['start'] . '.' . $data['limit'])->where('`date` >= ?', time())->limit(1);
         $cache = $db->fetchRow($check);
         if ($cache) {
             $results = JO_Json::decode($cache['data'], true);
             if ($results && is_array($results)) {
                 $return = array();
                 foreach ($results as $result) {
                     if (self::pinIsExist($result['pin_id'])) {
                         $return[] = $result;
                     }
                 }
                 return $return;
             }
         }
     }
     if (isset($data['filter_likes']) && $data['filter_likes']) {
         $query = $db->select()->from('pins', array('pins.*', 'gift' => new JO_Db_Expr('pins.price > 0.0000')))->where('pins.pin_id IN (SELECT pins_likes.pin_id FROM pins_likes WHERE user_id = ?)', $data['filter_likes']);
     } else {
         $query = $db->select()->from('pins', array('pins.*', 'gift' => new JO_Db_Expr('pins.price > 0.0000')));
     }
     $query = self::FilterBuilder($query, $data);
     if (isset($data['start']) && isset($data['limit'])) {
         if ($data['start'] < 0) {
             $data['start'] = 0;
         }
         $query->limit($data['limit'], $data['start']);
     }
     if (isset($data['sort']) && strtolower($data['sort']) == 'asc') {
         $sort = ' ASC';
     } else {
         $sort = ' DESC';
     }
     $allow_sort = array('pins.pin_id', 'pins.views');
     if (isset($data['order']) && in_array($data['order'], $allow_sort)) {
         $query->order($data['order'] . $sort);
     } elseif (isset($data['order']) && $data['order'] instanceof JO_Db_Expr) {
         $query->order($data['order']);
     } else {
         $query->order('pins.pin_id' . $sort);
     }
     $start = microtime(true);
     //echo $query.'<hr />';
     $results = $db->fetchAll($query);
     $results_array = array();
     if ($results) {
         foreach ($results as $result) {
             $userinfo = Model_Users::getUser($result['user_id'], false, Model_Users::$allowed_fields);
             if ($userinfo) {
                 $result['user_via'] = $result['via'] ? Model_Users::getUser($result['via'], false, Model_Users::$allowed_fields) : false;
                 $result['user'] = $userinfo;
                 $result['board'] = Model_Boards::getBoardTitle($result['board_id']);
                 $result['latest_comments'] = $result['comments'] ? Model_Comments::getLatestComments($result['latest_comments']) : array();
                 $result['liked'] = $result['likes'] ? self::pinIsLiked($result['pin_id']) : 0;
                 $results_array[] = $result;
                 //					array_push($pin_ids, $result['pin_id']);
             }
         }
     }
     //		var_dump( microtime(true)-JO_Registry::get('start_microtime') ); exit;
     return $results_array;
 }
Пример #13
0
 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;
 }
Пример #14
0
 public static function delete($pin_id)
 {
     $db = JO_Db::getDefaultAdapter();
     $pin_info = self::getPin($pin_id);
     if (!$pin_info) {
         return false;
     }
     if ($pin_info['image']) {
         $res = Helper_Db::create('pins_images_for_delete', array('pin_id' => $pin_info['pin_id'], 'date_added' => $pin_info['date_added'], 'image' => $pin_info['image'], 'store' => $pin_info['store']));
     }
     $comments = Model_Comments::getComments(array('filter_pin_id' => $pin_id));
     if ($comments) {
         foreach ($comments as $comment) {
             $db->delete('pins_comments', array('comment_id = ?' => $comment['comment_id']));
             $db->delete('pins_reports_comments', array('comment_id = ?' => $comment['comment_id']));
         }
     }
     $del = $db->delete('pins', array('pin_id = ?' => $pin_id));
     if (!$del) {
         return false;
     } else {
         $db->query("INSERT INTO `pins_images_for_delete`(`pin_id`, `gallery_id`, `date_added`, `image`, `store`) SELECT `pin_id`, `gallery_id`, '" . $pin_info['date_added'] . "', `image`, `store` FROM `pins_gallery` WHERE `pin_id` = '" . $pin_id . "'");
         $db->delete('pins_invert', array('pin_id = ?' => $pin_id));
         $db->delete('pins_likes', array('pin_id = ?' => $pin_id));
         $db->delete('pins_reports', array('pin_id = ?' => $pin_id));
         $db->delete('pins_views', array('pin_id = ?' => $pin_id));
         $db->delete('users_history', array('pin_id = ?' => $pin_id));
         $db->delete('pins_gallery', array('pin_id = ?' => $pin_id));
         $db->delete('pins_images', array('pin_id = ?' => $pin_id));
         $config_private_boards = Helper_Config::get('config_private_boards');
         Helper_Db::update('users', array('pins' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'boards' => new JO_Db_Expr('(SELECT COUNT(DISTINCT board_id) FROM boards WHERE user_id = users.user_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'likes' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins_likes WHERE user_id = users.user_id)'), 'following' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT following_id) FROM users_following_user WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT following_id) FROM users_following WHERE user_id = users.user_id AND following_id != users.user_id LIMIT 1) )'), 'followers' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE following_id = users.user_id AND user_id != users.user_id LIMIT 1) )'), 'latest_pins' => new JO_Db_Expr('( SUBSTRING_INDEX( (SELECT GROUP_CONCAT(pin_id ORDER BY `pin_id` DESC) FROM `pins` WHERE user_id = users.user_id), \',\', 15 ) )')), array('user_id=?' => $pin_info['user_id']));
         Helper_Db::update('boards', array('pins' => new JO_Db_Expr('(SELECT COUNT(DISTINCT pin_id) FROM pins WHERE board_id = boards.board_id ' . ($config_private_boards ? ' AND public = 1' : '') . ')'), 'followers' => new JO_Db_Expr('( (SELECT COUNT(DISTINCT user_id) FROM users_following_user WHERE following_id = boards.user_id AND user_id != boards.user_id LIMIT 1) + (SELECT COUNT(DISTINCT user_id) FROM users_following WHERE following_id = boards.user_id AND user_id != boards.user_id LIMIT 1) - (SELECT COUNT(DISTINCT user_id) FROM users_following_ignore WHERE following_id = boards.user_id AND board_id = boards.board_id AND user_id != boards.user_id LIMIT 1) )'), 'latest_pins' => new JO_Db_Expr('( SUBSTRING_INDEX( (SELECT GROUP_CONCAT(pin_id ORDER BY `pin_id` DESC) FROM `pins` WHERE board_id = boards.board_id), \',\', 15 ) )')), array('board_id=?' => $pin_info['board_id']));
         self::deleteCache($pin_info);
         return true;
     }
 }
Пример #15
0
 public function addComment($id, $comment)
 {
     $data['parent_name'] = $this->_name;
     $data['parent_id'] = $id;
     $data['comment'] = $comment;
     $Table = new Model_Comments();
     $Table->insert($data);
     $this->getAdapter()->query('UPDATE ' . $this->_name . ' SET counter = counter + 1  WHERE id = ' . $id);
 }
Пример #16
0
 public function commentsAction()
 {
     $this->noViewRenderer(true);
     $request = $this->getRequest();
     $response = $this->getResponse();
     $page = (int) $request->getRequest('page');
     if ($page < 1) {
         $page = 1;
     }
     $callback = $request->getRequest('callback');
     if (!preg_match('/^([a-z0-9_.]{1,})$/', $callback)) {
         $callback = false;
     }
     $return = array();
     $pin_id = (int) $request->getRequest('pinId');
     $pin_info = Model_Pins::getPin($pin_id);
     if (!$pin_info) {
         $return = array('error' => $this->translate('There was a problem with the record. Please try again!'));
     } else {
         if ($request->getParam('comments') == 'post') {
             if ($this->isLoged()) {
                 ///add comment
             } else {
                 $return = array('error' => $this->error);
             }
         } else {
             $data = array('filter_pin_id' => $pin_id);
             $return = array('data' => array());
             $comments = Model_Comments::getComments($data);
             if ($comments) {
                 foreach ($comments as $comment) {
                     $return['data'][] = array('userId' => $comment['user']['user_id'], 'userName' => $comment['user']['username'], 'avatar' => $comment['user']['avatar'], 'comment' => $comment['comment']);
                 }
             }
         }
     }
     if ($callback) {
         $return = $callback . '(' . JO_Json::encode($return) . ')';
     } else {
         $response->addHeader('Cache-Control: no-cache, must-revalidate');
         $response->addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
         $response->addHeader('Content-type: application/json');
         $return = JO_Json::encode($return);
     }
     $response->appendBody($return);
 }