Advertisement
Guest User

Wallpaper_private.php

a guest
Jun 16th, 2015
1,708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 18.64 KB | None | 0 0
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2.  
  3. class Wallpaper_private extends wsFrontend
  4. {
  5.  
  6.     public function __construct()
  7.     {
  8.         parent::__construct();
  9.         if (strpos(strtolower($this->uri->uri_string()), 'wallpaper_private') !== false) {
  10.             redirect(base_url());
  11.         }
  12.         $this->db->cache_set_path(dirname($this->db->cachedir) . '/wallpaper_page/');
  13.     }
  14.  
  15.     public function index($category_slug = '', $wallpaper_slug = '', $wallpaper_hash_id = '')
  16.     {
  17.         $data = array();
  18.  
  19.         if (!$category_slug && !$wallpaper_slug && !$wallpaper_hash_id)
  20.             custom_404();
  21.  
  22.         $filter['category_slug'] = rawurldecode($category_slug);
  23.         $filter['wallpaper_slug'] = $wallpaper_slug;
  24.         $filter['wallpaper_hash'] = $wallpaper_hash_id;
  25.         $this->load->model('wallpaper_model');
  26.         $data['wallpaper'] = $this->wallpaper_model->get_wallpaper($filter);
  27.  
  28.  
  29.         if (!$data['wallpaper'] && $wallpaper_hash_id) {
  30.             $data['wallpaper'] = $this->wallpaper_model->get_wallpaper(array('wallpaper_hash' => $wallpaper_hash_id));
  31.         }
  32.         if (!$data['wallpaper']) {
  33.             unset($filter['wallpaper_hash']);
  34.             $data['wallpaper'] = $this->wallpaper_model->get_wallpaper($filter);
  35.         }
  36.  
  37.         if (!$data['wallpaper'])
  38.             custom_404();
  39.  
  40.         $data['search_replace'] = array(
  41.             '{C_SLUG_FULL}' => $data['wallpaper']->cFullSlug,
  42.             '{C_SLUG}' => $data['wallpaper']->category_slug,
  43.             '{W_SLUG}' => $data['wallpaper']->wallpaper_slug,
  44.             '{W_HASH}' => $data['wallpaper']->wallpaper_hash
  45.         );
  46.         $data['url'] = $this->route_links->build_link('wallpaper_page', $data['search_replace']);
  47.         $data['facebook_cover_url'] = $this->route_links->build_link('wallpapers_page_cover_facebook', $data['search_replace']);
  48.         if ($data['url'] != current_url())
  49.             redirect($data['url']);
  50.  
  51.  
  52.         if (!$this->config->item('facebook_comment')) {
  53.             $this->load->helper('date');
  54.         }
  55.  
  56.         $data['captcha'] = $data['captchaError'] = false;
  57.         if ($this->config->item('enable_captcha') && !$this->user->is_loggedIn()) {
  58.             $data['captcha'] = true;
  59.         }
  60.  
  61.         //Force Turn off captcha
  62.         //$data['captcha'] = false;
  63.  
  64.         $this->comment_submit($data);
  65.  
  66.         $data['comments'] = $data['comment_count'] = false;
  67.         if (!$this->config->item('facebook_comment')) {
  68.             $comment_db = array(
  69.                 'wallpaper_hash' => $data['wallpaper']->wallpaper_hash,
  70.                 'per_page' => $this->config->item('comment_limit'),
  71.                 'offset' => 0,
  72.             );
  73.             $data['comments'] = $this->wallpaper_model->get_comments($comment_db);
  74.             $data['comment_count'] = $this->wallpaper_model->get_comments($comment_db + array('count' => true));
  75.         }
  76.  
  77.  
  78.         $this->tpl->active_category = explode('/', $data['wallpaper']->cFullSlug);
  79.  
  80.  
  81.         $cFullSlug = explode('/', $data['wallpaper']->cFullSlug);
  82.         $cFullName = explode('|', $data['wallpaper']->cFullName);
  83.         $appendSlug = '';
  84.  
  85.         $this->tpl->breadcrumbs['Category'] = base_url($this->route_links->get('category_page_index'));
  86.         foreach ($cFullSlug as $k => $cSlug) {
  87.             if ($appendSlug)
  88.                 $appendSlug .= '/';
  89.             $category_slug_build = $this->route_links->build_link('category_page', array(
  90.                 '{C_SLUG_FULL}' => $appendSlug . $cSlug
  91.             ));
  92.             $this->tpl->breadcrumbs[(isset($cFullName[$k]) ? $cFullName[$k] : $k)] = $category_slug_build;
  93.             $appendSlug .= $cSlug;
  94.         }
  95.         $this->tpl->breadcrumbs[$data['wallpaper']->wallpaper_name] = 'active';
  96.  
  97.         $this->db->custom_seqgment('resolution', 'index');
  98.         $this->load->model('resolution_model');
  99.         $data['resolutions'] = $this->frontend_helper->resolutions_grouping($this->resolution_model->get_AllResolutions());
  100.         $this->db->reset_custom_seqgment();
  101.  
  102.         $data['previous_next'] = $this->wallpaper_model->previousNext($data['wallpaper']->wallpaper_seq_id);
  103.  
  104.         $this->insert_view($data['wallpaper']->wallpaper_seq_id);
  105.  
  106.         $data['favourite'] = false;
  107.         if ($this->user->is_loggedIn()) {
  108.             $data['favourite'] = $this->wallpaper_model->is_userAddedToFavourite($data['wallpaper']->wallpaper_seq_id, $this->user->get_id());
  109.         }
  110.  
  111.         $data['colors'] = $this->wallpaper_model->get_colors($data['wallpaper']->wallpaper_seq_id);
  112.  
  113.         $data['related_wallpapers'] = $this->wallpaper_model->getWallpapers(array(
  114.             'per_page' => $this->config->item('related_wallpaper_limit'),
  115.             'category' => $data['wallpaper']->category_seq_id,
  116.             'wallpaper_id_not' => array($data['wallpaper']->wallpaper_seq_id),
  117.             'keyword_related' => $data['wallpaper']->wallpaper_name
  118.         ));
  119.  
  120.  
  121.         $search_replace = array(
  122.             '{WALL_NAME}' => $data['wallpaper']->wallpaper_name,
  123.             '{WALL_CAT_NAME}' => $data['wallpaper']->category_name,
  124.             '{WALL_TAGS}' => $data['wallpaper']->tags
  125.         );
  126.         if ($data['wallpaper']->wallpaper_metatitle)
  127.             $this->tpl->meta ['title'] = $data['wallpaper']->wallpaper_metatitle;
  128.         else
  129.             $this->tpl->meta ['title'] = $this->metadata->get_metadata('_wallpaper_index_title', 'wallpaper_page', $search_replace);
  130.  
  131.         if ($data['wallpaper']->wallpaper_metadescription)
  132.             $this->tpl->meta ['description'] = $data['wallpaper']->wallpaper_metadescription;
  133.         else
  134.             $this->tpl->meta ['description'] = $this->metadata->get_metadata('_wallpaper_index_description', 'wallpaper_page', $search_replace);
  135.  
  136.         if ($data['wallpaper']->wallpaper_metakeywords)
  137.             $this->tpl->meta ['keywords'] = $data['wallpaper']->wallpaper_metakeywords;
  138.         else
  139.             $this->tpl->meta ['keywords'] = $this->metadata->get_metadata('_wallpaper_index_keywords', 'wallpaper_page', $search_replace);
  140.  
  141.  
  142.         $this->tpl->contents [] = $this->tpl->fetch('contents/wallpaper_single', $data, true);
  143.         $this->tpl->render('layouts/home');
  144.     }
  145.  
  146.     public function preview($category_slug = '', $wallpaper_slug = '', $wallpaper_hash_id = '', $width = false, $Height = false, $download = false)
  147.     {
  148.         if (!$category_slug && !$wallpaper_slug && !$wallpaper_hash_id)
  149.             custom_404();
  150.  
  151.         $filter['category_slug'] = rawurldecode($category_slug);
  152.         $filter['wallpaper_slug'] = $wallpaper_slug;
  153.         $filter['wallpaper_hash'] = $wallpaper_hash_id;
  154.         $this->load->model('wallpaper_model');
  155.         $data['wallpaper'] = $this->wallpaper_model->get_wallpaper($filter);
  156.  
  157.         @ini_set('memory_limit', '256M');
  158.  
  159.         if (!$data['wallpaper'] && $wallpaper_hash_id) {
  160.             $data['wallpaper'] = $this->wallpaper_model->get_wallpaper(array('wallpaper_hash' => $wallpaper_hash_id));
  161.         }
  162.         if (!$data['wallpaper']) {
  163.             unset($filter['wallpaper_hash']);
  164.             $data['wallpaper'] = $this->wallpaper_model->get_wallpaper($filter);
  165.         }
  166.  
  167.         if (!$data['wallpaper'])
  168.             custom_404();
  169.         $data['width'] = $width;
  170.         $data['height'] = $Height;
  171.         $data['search_replace'] = array(
  172.             '{C_SLUG_FULL}' => $data['wallpaper']->cFullSlug,
  173.             '{C_SLUG}' => $data['wallpaper']->category_slug,
  174.             '{W_SLUG}' => $data['wallpaper']->wallpaper_slug,
  175.             '{W_HASH}' => $data['wallpaper']->wallpaper_hash,
  176.             '{R_WIDTH}' => $width,
  177.             '{R_HEIGHT}' => $Height,
  178.         );
  179.         $data['url'] = $this->route_links->build_link('wallpaper_page', $data['search_replace']);
  180.         $data['colors'] = $this->wallpaper_model->get_colors($data['wallpaper']->wallpaper_seq_id);
  181.  
  182.         if (!$width || !$Height)
  183.             redirect($data['url']);
  184.  
  185.         if ($data['wallpaper']->wallpaper_width < $width || $data['wallpaper']->wallpaper_height < $Height) {
  186.             $this->session->set_flashdata('FLASH_ERROR', $this->language->get_text('SRSBLTTAR', 'wallpaper'));
  187.             redirect($data['url']);
  188.         }
  189.  
  190.  
  191.         if (!file_exists(ORIGINALS_FOLDER . DS . $data['wallpaper']->wallpaper_image_path)) {
  192.             $this->session->set_flashdata('FLASH_ERROR', $this->language->get_text('sorry-original-image-doest-exists', 'wallpaper'));
  193.             redirect($data['url']);
  194.         }
  195.  
  196.         if ($download) {
  197.             $data['image'] = $this->image_workshop->convert_resolution($data['wallpaper']->wallpaper_image_path, $data['wallpaper']->wallpaper_hash, $data['wallpaper']->wallpaper_date_created, $width, $Height, $data['wallpaper']->wallpaper_crop_position, true);
  198.             $this->load->helper('download');
  199.             $this->insert_download($data['wallpaper']->wallpaper_seq_id);
  200.             force_download($data['image'], NULL);
  201.         }
  202.  
  203.         $data['image'] = $this->image_workshop->convert_resolution($data['wallpaper']->wallpaper_image_path, $data['wallpaper']->wallpaper_hash, $data['wallpaper']->wallpaper_date_created, $width, $Height, $data['wallpaper']->wallpaper_crop_position);
  204.         $this->insert_view($data['wallpaper']->wallpaper_seq_id);
  205.  
  206.         $search_replace = array(
  207.             '{WALL_NAME}' => $data['wallpaper']->wallpaper_name,
  208.             '{WALL_CAT_NAME}' => $data['wallpaper']->category_name,
  209.             '{WALL_TAGS}' => $data['wallpaper']->tags,
  210.             '{R_WIDTH}' => $width,
  211.             '{R_HEIGHT}' => $Height,
  212.         );
  213.         if ($data['wallpaper']->wallpaper_metatitle)
  214.             $this->tpl->meta ['title'] = $data['wallpaper']->wallpaper_metatitle;
  215.         else
  216.             $this->tpl->meta ['title'] = $this->metadata->get_metadata('_wallpaper_preview_title', 'wallpaper_page', $search_replace);
  217.  
  218.         if ($data['wallpaper']->wallpaper_metadescription)
  219.             $this->tpl->meta ['description'] = $data['wallpaper']->wallpaper_metadescription;
  220.         else
  221.             $this->tpl->meta ['description'] = $this->metadata->get_metadata('_wallpaper_preview_description', 'wallpaper_page', $search_replace);
  222.  
  223.         if ($data['wallpaper']->wallpaper_metakeywords)
  224.             $this->tpl->meta ['keywords'] = $data['wallpaper']->wallpaper_metakeywords;
  225.         else
  226.             $this->tpl->meta ['keywords'] = $this->metadata->get_metadata('_wallpaper_preview_keywords', 'wallpaper_page', $search_replace);
  227.  
  228.  
  229.         $data['previous_next'] = $this->wallpaper_model->previousNext($data['wallpaper']->wallpaper_seq_id, $width, $Height);
  230.  
  231.         $this->tpl->contents [] = $this->tpl->fetch('contents/wallpaper_single_preview', $data, true);
  232.         $this->tpl->render('layouts/empty');
  233.     }
  234.  
  235.     private function comment_submit($data)
  236.     {
  237.         if (isset($_POST['submit_comment'])) {
  238.             $return['captcha'] = $data['captcha'];
  239.             $this->load->library('form_validation');
  240.             if (!$this->user->is_loggedIn()) {
  241.                 $this->form_validation->set_rules('guest_name', $this->language->get_text('guest-name', 'comment'), 'required');
  242.                 $this->form_validation->set_rules('guest_email', $this->language->get_text('guest-email', 'comment'), 'required|valid_email');
  243.                 if ($data['captcha'])
  244.                     $this->form_validation->set_rules('recaptcha_response_field', $this->language->get_text('captcha-code', 'account'), 'required');
  245.             }
  246.             $this->form_validation->set_rules('comment_text', $this->language->get_text('comment-text', 'comment'), 'required|min_length[4]');
  247.             if ($this->form_validation->run()) {
  248.                 $has_error = false;
  249.                 if ($data['captcha']) {
  250.                     $resp = recaptcha_check_answer('', $_SERVER["REMOTE_ADDR"], $this->input->post('recaptcha_challenge_field'), $this->input->post('recaptcha_response_field'));
  251.                     if (!$resp->is_valid) {
  252.                         $data['captchaError'] = $return['error'] = $resp->error;
  253.                         $has_error = true;
  254.                     }
  255.                 }
  256.  
  257.                 if (!$has_error) {
  258.                     $return['success'] = $this->language->get_text('your-comment-has-been-submitted', 'comment');
  259.                     $insert_data = array(
  260.                         'wallpaper_seq_id' => $data['wallpaper']->wallpaper_seq_id,
  261.                         'comment_description' => strip_tags($this->input->post('comment_text')),
  262.                         'comment_date' => date('Y-m-d H:i:s'),
  263.                     );
  264.                     if ($this->user->is_loggedIn()) {
  265.                         $insert_data['user_seq_id'] = $this->user->get_id();
  266.                         $insert_data['comment_status'] = 1;
  267.                     } else {
  268.                         $insert_data['guest_name'] = $this->input->post('guest_name');
  269.                         $insert_data['guest_email'] = $this->input->post('guest_email');
  270.                     }
  271.                     $insert_id = $this->wallpaper_model->insert_comment($insert_data);
  272.                     if ($this->input->is_ajax_request()) {
  273.                         $comment_data = array('comment' => $this->wallpaper_model->get_single_commentBYID($insert_id));
  274.                         $return['html'] = $this->tpl->fetch('contents/comment_single', $comment_data);
  275.                     } else {
  276.                         $this->session->set_flashdata('FLASH_MSG', $this->language->get_text('your-comment-has-been-submitted', 'comment') . ' ' . (!$this->user->is_loggedIn() ? $this->language->get_text('waiting-for-approval', 'comment') : ''));
  277.                         redirect($data['url']);
  278.                     }
  279.                 }
  280.             } else {
  281.                 if ($this->input->is_ajax_request()) {
  282.                     $return['error'] = validation_errors();
  283.                 }
  284.             }
  285.  
  286.             if ($this->input->is_ajax_request()) {
  287.                 echo json_encode($return);
  288.                 exit;
  289.             }
  290.         }
  291.     }
  292.  
  293.     private function insert_view($wallpaper_seq_id)
  294.     {
  295.         $ip = ip2long($this->input->ip_address());
  296.         $search_log = array(
  297.             'DATE(wv_date)' => date('Y-m-d'),
  298.             'INET_NTOA(wv_ip)' => $ip ? $ip : '0.0.0.0',
  299.             'wv_wid' => $wallpaper_seq_id
  300.         );
  301.         if ($this->user->is_loggedIn())
  302.             $search_log['wv_uid'] = $this->user->get_id();
  303.         $is_viewed = $this->wallpaper_model->is_viewed($search_log);
  304.  
  305.         if (!$is_viewed) {
  306.             $insert_log = array(
  307.                 'wv_uid' => $this->user->get_id(),
  308.                 'wv_wid' => $wallpaper_seq_id,
  309.                 'wv_ip' => ip2long($this->input->ip_address()),
  310.                 'wv_date' => date('Y-m-d H:i:s')
  311.             );
  312.             $this->wallpaper_model->insert_view($insert_log);
  313.         }
  314.     }
  315.  
  316.     private function insert_download($wallpaper_seq_id)
  317.     {
  318.         $insert_log = array(
  319.             'wd_uid' => $this->user->get_id(),
  320.             'wd_wid' => $wallpaper_seq_id,
  321.             'wd_ip' => ip2long($this->input->ip_address()),
  322.             'wd_date' => date('Y-m-d H:i:s')
  323.         );
  324.         $this->wallpaper_model->insert_download($insert_log);
  325.     }
  326.  
  327.  
  328.     public function cover($category_slug = '', $wallpaper_slug = '', $wallpaper_hash_id = '', $type = false)
  329.     {
  330.         $allowed_type = array(
  331.             'facebook'
  332.         );
  333.         if ((!$category_slug && !$wallpaper_slug && !$wallpaper_hash_id) || !in_array($type, $allowed_type))
  334.             custom_404();
  335.  
  336.         $filter['category_slug'] = rawurldecode($category_slug);
  337.         $filter['wallpaper_slug'] = $wallpaper_slug;
  338.         $filter['wallpaper_hash'] = $wallpaper_hash_id;
  339.         $this->load->model('wallpaper_model');
  340.         $data['wallpaper'] = $this->wallpaper_model->get_wallpaper($filter);
  341.  
  342.         if (!$data['wallpaper'] && $wallpaper_hash_id) {
  343.             $data['wallpaper'] = $this->wallpaper_model->get_wallpaper(array('wallpaper_hash' => $wallpaper_hash_id));
  344.         }
  345.         if (!$data['wallpaper']) {
  346.             unset($filter['wallpaper_hash']);
  347.             $data['wallpaper'] = $this->wallpaper_model->get_wallpaper($filter);
  348.         }
  349.  
  350.         if (!$data['wallpaper'])
  351.             custom_404();
  352.  
  353.  
  354.         $data['search_replace'] = array(
  355.             '{C_SLUG_FULL}' => $data['wallpaper']->cFullSlug,
  356.             '{C_SLUG}' => $data['wallpaper']->category_slug,
  357.             '{W_SLUG}' => $data['wallpaper']->wallpaper_slug,
  358.             '{W_HASH}' => $data['wallpaper']->wallpaper_hash,
  359.         );
  360.  
  361.         switch ($type) {
  362.             case'facebook':
  363.                 $data['width'] = FB_WIDTH;
  364.                 $data['height'] = FB_HEIGHT;
  365.                 $data['slug'] = 'wallpapers_page_cover_facebook';
  366.                 break;
  367.         }
  368.  
  369.         $data['type'] = $type;
  370.  
  371.         $data['url'] = $this->route_links->build_link($data['slug'], $data['search_replace']);
  372.         $data['w_url'] = $this->route_links->build_link('wallpaper_page', $data['search_replace']);
  373.         $data['colors'] = $this->wallpaper_model->get_colors($data['wallpaper']->wallpaper_seq_id);
  374.  
  375.         if ($data['url'] != current_url())
  376.             redirect($data['url']);
  377.  
  378.         $data['previous_next'] = $this->wallpaper_model->previousNext($data['wallpaper']->wallpaper_seq_id, $data['width'], $data['height']);
  379.  
  380.  
  381.         $search_replace = array(
  382.             '{WALL_NAME}' => $data['wallpaper']->wallpaper_name,
  383.             '{WALL_CAT_NAME}' => $data['wallpaper']->category_name,
  384.             '{WALL_TAGS}' => $data['wallpaper']->tags
  385.         );
  386.  
  387.         if ($data['wallpaper']->wallpaper_metatitle)
  388.             $this->tpl->meta ['title'] = $data['wallpaper']->wallpaper_metatitle;
  389.         else
  390.             $this->tpl->meta ['title'] = $this->metadata->get_metadata('_wallpapers_page_facebook_title', 'wallpaper_page', $search_replace);
  391.  
  392.         if ($data['wallpaper']->wallpaper_metadescription)
  393.             $this->tpl->meta ['description'] = $data['wallpaper']->wallpaper_metadescription;
  394.         else
  395.             $this->tpl->meta ['description'] = $this->metadata->get_metadata('_wallpapers_page_facebook_description', 'wallpaper_page', $search_replace);
  396.  
  397.         if ($data['wallpaper']->wallpaper_metakeywords)
  398.             $this->tpl->meta ['keywords'] = $data['wallpaper']->wallpaper_metakeywords;
  399.         else
  400.             $this->tpl->meta ['keywords'] = $this->metadata->get_metadata('_wallpapers_page_facebook_keywords', 'wallpaper_page', $search_replace);
  401.  
  402.         $this->tpl->contents [] = $this->tpl->fetch('contents/wallpaper_single_cover', $data, true);
  403.         $this->tpl->render('layouts/empty_nocontainer');
  404.     }
  405. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement