Guest User

Untitled

a guest
Nov 9th, 2018
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 64.25 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Users extends CI_Controller {
  3.  
  4. public $loggedIn;
  5.  
  6.  
  7. /*
  8. * Check if logged in or not and assign it to all methods
  9. */
  10. function __construct() {
  11. parent::__construct();
  12. $this->loggedIn = $this->session->userdata('loggedIn');
  13. $this->load->model("UsersModel");
  14. }
  15.  
  16. /*
  17. * Messages/Read body
  18. */
  19. public function read_message() {
  20. if(!$this->loggedIn)
  21. {
  22. redirect('/users/login');
  23. exit;
  24. }
  25.  
  26. //estabilish fromID
  27. $userID = abs(intval($this->loggedIn));
  28.  
  29. //estabilish msgID
  30. $msgID = $this->uri->segment(3);
  31. $msgID = abs(intval($msgID));
  32.  
  33. if(!$msgID) die("No msgID");
  34.  
  35. //get msg body
  36. $this->db->select("body")->from('messages')->where("msgID", $msgID)->where("toID", $userID);
  37. $rs = $this->db->get();
  38.  
  39. if(count($rs)) {
  40. echo nl2br($rs->row()->body);
  41. }else{
  42. echo _('There is no message with this ID or you dont have the rights to read it');
  43. }
  44.  
  45. }
  46.  
  47. /*
  48. * Messages/Send
  49. */
  50. public function message() {
  51. if(!$this->loggedIn)
  52. {
  53. redirect('/users/login');
  54. exit;
  55. }
  56.  
  57. //estabilish fromID
  58. $userID = abs(intval($this->loggedIn));
  59.  
  60. //estabilish toID
  61. $toID = $this->uri->segment(3);
  62. $toID = abs(intval($toID));
  63.  
  64.  
  65. //check if in reply to
  66. if($this->uri->segment(4) AND ($this->uri->segment(4) == 'replyto') AND $this->uri->segment(5)) {
  67. $replyTo = abs(intval($this->uri->segment(5)));
  68. if(!$replyTo) die("Invalid replyto");
  69.  
  70. $this->db->select("subject");
  71. $this->db->from("messages");
  72. $this->db->where("msgID", $replyTo);
  73. $rs = $this->db->get()->row();
  74.  
  75. if($rs) {
  76. $data['reply_subject'] = _('Re : ') . $rs->subject;
  77. }
  78.  
  79. }
  80.  
  81. if(!$toID) die(_('You received this page in error. Go Back!'));
  82.  
  83. if($userID == $toID) die(_('You cannot send a message to yourself!'));
  84.  
  85.  
  86. if($this->input->post('sb_msg')) {
  87.  
  88. $subject = trim(strip_tags($this->input->post('subject')));
  89. $body = trim(strip_tags($this->input->post('body')));;
  90.  
  91. if(strlen($subject) < 5 || strlen($body) < 10) {
  92. $data['form_message'] = "<div class='alert alert-danger'>";
  93. $data['form_message'] .= _('Subject min 5 characters and body min 10 please.');
  94. $data['form_message'] .= '</div>';
  95. }else{
  96.  
  97. $insert = array();
  98. $insert['fromID'] = $userID;
  99. $insert['toID'] = $toID;
  100. $insert['subject'] = $subject;
  101. $insert['body'] = $body;
  102. $insert['msg_date'] = time();
  103.  
  104. $this->db->insert("messages", $insert);
  105.  
  106. // email the listing owner
  107. $headers = 'MIME-Version: 1.0' . "\r\n";
  108. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  109. $headers .= "From: " . $this->config->item('email_from') . "\r\n";
  110. $headers .= "Reply-To: ". $this->config->item('email_from') . "\r\n";
  111.  
  112. $query = $this->db->query("SELECT username, email FROM users WHERE userID = ? LIMIT 1", array($toID));
  113. $user_data = $query->row();
  114.  
  115. $to = $user_data->email;
  116.  
  117. $body = 'Hi there <srong>'.$user_data->username.'</strong>,<br/><br/>';
  118.  
  119. $body .= 'You have received a new message:<br/>';
  120. $body .= '<br/>Please login to view the message!';
  121. $body .= '<br/><a href="'.base_url().'?login=yes">'.base_url().'?login=yes</a><br /><br />';
  122. $body .= 'Then go to your messages inbox<br/><br/>';
  123. $body .= '<a href="'.base_url().'users/inbox">'.base_url().'users/inbox</a><br /><br />';
  124.  
  125. mail($to, "New Message Received", $body, $headers);
  126.  
  127. $data['form_message'] = "<div class='alert alert-success'>";
  128. $data['form_message'] .= _('Your message has been sent to the recipient.');
  129. $data['form_message'] .= '</div>';
  130.  
  131. }
  132. }
  133.  
  134. if(!isset($data)) $data = array();
  135. $this->load->view('user-msg', $data);
  136.  
  137. }
  138.  
  139. /*
  140. * Messages/Inbox
  141. */
  142. public function inbox() {
  143. if(!$this->loggedIn)
  144. {
  145. redirect('/users/login');
  146. exit;
  147. }
  148.  
  149.  
  150. //estabilish userID
  151. $userID = abs(intval($this->loggedIn));
  152.  
  153. //get messages for this user
  154. $this->db->select("messages.*, username");
  155. $this->db->from("messages");
  156. $this->db->where(array("toID" => $userID));
  157. $this->db->join("users", "messages.fromID=users.userID");
  158. $this->db->order_by("msgID", "DESC");
  159. $messages = $this->db->get();
  160.  
  161. $data['messages'] = $messages->result();
  162.  
  163. if(!$messages->num_rows()) {
  164. $data['msg'] = _('You have no messages');
  165. }
  166.  
  167. $this->load->view('user-inbox', $data);
  168.  
  169. }
  170.  
  171. /*
  172. * Bids made
  173. */
  174. public function offers() {
  175. if(!$this->loggedIn)
  176. {
  177. redirect('/users/login');
  178. exit;
  179. }
  180.  
  181. //estabilish userID
  182. $userID = abs(intval($this->loggedIn));
  183.  
  184. //if sold
  185. if($this->uri->segment(3) AND ($this->uri->segment(3) == 'sold') AND $this->uri->segment(4)) {
  186. $listingID = abs(intval($this->uri->segment(4)));
  187.  
  188. $lastBid = $this->db->select("MAX(amount) as amt")->from("bids")->where("bid_listing", $listingID);
  189. $lastBid = $this->db->get()->row()->amt;
  190.  
  191. if($this->db->update('listings',
  192. array("sold" => 'Y', 'sold_date' => time(), "sold_price" => $lastBid),
  193. array("listingID" => $listingID, "list_uID" => $userID)))
  194. {
  195. echo '<meta http-equiv="refresh" content="0;url=/users/offers">';
  196. exit;
  197. }
  198. }
  199.  
  200. //if rejected
  201. if($this->uri->segment(3) AND ($this->uri->segment(3) == 'reject') AND $this->uri->segment(4)) {
  202. $listingID = abs(intval($this->uri->segment(4)));
  203. if($this->db->delete('bids', array("bidID" => $listingID, "owner_ID" => $userID)))
  204. {
  205. echo '<meta http-equiv="refresh" content="0;url=/users/offers">';
  206. exit;
  207. }
  208. }
  209.  
  210. //get bids
  211. $bids = $this->db->query("SELECT bidID,listingID, listing_title, listing_url, bid_date, username, amount, sold, sold_date FROM bids
  212. JOIN listings ON listingID = bid_listing
  213. JOIN users ON bidder_ID = userID
  214. WHERE listingID IN (SELECT CONCAT_WS(',', listingID) FROM listings WHERE list_uID = $userID)
  215. ORDER BY bidID DESC");
  216. if($bids->num_rows()) {
  217. $bids = $bids->result();
  218. $data['bids'] = $bids;
  219. }else{
  220. $data['msg'] = _('No offers yet');
  221. }
  222.  
  223. $this->load->view('user-offers.php', $data);
  224.  
  225. }
  226.  
  227.  
  228. /*
  229. * Bids made
  230. */
  231. public function bids() {
  232. if(!$this->loggedIn)
  233. {
  234. redirect('/users/login');
  235. exit;
  236. }
  237.  
  238. //estabilish userID
  239. $userID = abs(intval($this->loggedIn));
  240.  
  241.  
  242. //get bids
  243. $bids = $this->db->query("SELECT bidID,listingID, listing_title, listing_url, bid_date, username, amount, sold, sold_date FROM bids
  244. JOIN listings ON listingID = bid_listing
  245. JOIN users ON list_uID = userID
  246. WHERE bidder_ID = $userID
  247. ORDER BY bidID DESC");
  248. if($bids->num_rows()) {
  249. $bids = $bids->result();
  250. $data['bids'] = $bids;
  251. }else{
  252. $data['msg'] = _('No bids made');
  253. }
  254.  
  255. $this->load->view('user-bids.php', $data);
  256.  
  257. }
  258.  
  259.  
  260. /*
  261. * User Listings
  262. */
  263. public function mylistings() {
  264. if(!$this->loggedIn)
  265. {
  266. redirect('/users/login');
  267. exit;
  268. }
  269.  
  270. $this->load->library('table');
  271.  
  272. $userID = $this->loggedIn;
  273.  
  274. $this->db->select("listingID,
  275.  
  276. CONCAT('<a href=\"/listings/', listingID ,'/mylistings\">', listing_url, '</a>') AS listing_url, listing_url AS rawurl,
  277.  
  278. CONCAT('$', FORMAT(bin,2 )) AS BIN,
  279.  
  280. FROM_UNIXTIME(list_date, '%D %b %Y') as list_date,
  281.  
  282. CASE list_expires WHEN 0 THEN '-' ELSE FROM_UNIXTIME(list_expires, '%D %b %Y') END
  283. AS list_expires,
  284.  
  285. sold,
  286.  
  287. CASE sold_date WHEN 0 THEN '-' ELSE FROM_UNIXTIME(sold_date, '%D %b %Y') END
  288. AS sold_date,
  289.  
  290. CASE WHEN list_expires < '".time()."' THEN
  291. CONCAT('<a href=\"/payments/relist/', listingID, '\" class=\"btn btn-xs btn-warning\">%s</a>') ELSE '-' END
  292. AS payLink,
  293.  
  294. CONCAT('<a href=\"/users/goedit/', listingID, '\" class=\"btn btn-xs btn-default\">%s</a>') as editl, featured", false);
  295.  
  296. $userListings = $this->db->get_where("listings", array("list_uID" => $userID));
  297.  
  298. $tmpl = array ( 'table_open' => '<table class="table table-bordered table-hover">' );
  299.  
  300. $this->table->set_template($tmpl);
  301. $this->table->set_heading('#ID', 'URL', 'Price', 'Date', 'Expires', 'Sold', 'Sold Date', 'Relist', '<b class="icon-edit"></b>');
  302. $data['table'] = $this->table->generate($userListings);
  303.  
  304. $data['listings'] = $userListings->result();
  305.  
  306. $data['listings_count'] = $userListings->num_rows();
  307.  
  308. $this->load->view('mylistings', $data);
  309.  
  310. }
  311.  
  312. /*
  313. * Redirect to edit
  314. */
  315. public function goedit() {
  316. ob_start();
  317. if(!$this->loggedIn)
  318. {
  319. redirect('/users/login');
  320. exit;
  321. }
  322.  
  323. $id = $this->uri->segment(3);
  324. $id = abs(intval($id));
  325.  
  326. if(!$id) die("Edit #ID wrong");
  327.  
  328. //check if owner is correct
  329. $listing = $this->db->get_where("listings", array("listingID" => $id, "list_uID" => $this->loggedIn));
  330.  
  331. if(!$listing->num_rows()) {
  332. die(_("This listing isn't yours. Don't try edit other people listings"));
  333. }else{
  334. $this->session->set_userdata("listingID", $id);
  335. redirect('/users/newlisting');
  336. }
  337. ob_end_flush();
  338. }
  339.  
  340.  
  341. /*
  342. * User home
  343. */
  344. public function index()
  345. {
  346. if(!$this->loggedIn)
  347. {
  348. redirect('/users/login');
  349. exit;
  350. }
  351.  
  352. if($this->input->post('sb_signup')) {
  353. if(!$this->input->post('email') OR !$this->input->post('password')) {
  354. $data['form_message'] = div_class("Email and password are required", 'alert alert-danger');
  355. }else{
  356.  
  357. $this->db->where(array("email" => $this->input->post('email', TRUE)));
  358. $this->db->where("userID != " . is_user_logged_in());
  359. $user = $this->db->get("users");
  360.  
  361. if(count($user->result())) {
  362. $data['form_message'] = '<div class="alert alert-warning">';
  363. $data['form_message'] .= _('Username/Email taken, please chose another one.');
  364. $data['form_message'] .= '</div>';
  365. }else{
  366.  
  367. //profile pic
  368. if(isset($_FILES['file']) AND $_FILES['file']['error'] == 0) {
  369. //make thumbnail
  370. $rand = md5(uniqid());
  371. $ext = explode(".", $_FILES['file']['name']);
  372. $ext = strtolower(end($ext));
  373.  
  374. if(!@getimagesize($_FILES['file']['tmp_name'])) die(_("Invalid picture"));
  375.  
  376. $config['image_library'] = 'gd2';
  377. #$config['source_image'] = getcwd() .'/uploads/' . $rand . '.' . $ext;
  378. $config['source_image'] = $_FILES['file']['tmp_name'];
  379. $config['create_thumb'] = FALSE;
  380. $config['maintain_ratio'] = TRUE;
  381. $config['width'] = 48;
  382. $config['height'] = 48;
  383. $config['new_image'] = getcwd() . '/uploads/' . $rand . '.' . $ext;
  384.  
  385. $this->load->library('image_lib', $config);
  386.  
  387. $this->image_lib->resize();
  388.  
  389. if ( ! $this->image_lib->resize())
  390. {
  391. echo $this->image_lib->display_errors();
  392. }else{
  393. $thephoto = $rand . '.' . $ext;
  394. $this->db->where("userID", is_user_logged_in());
  395. $this->db->update("users", array('photo' => $thephoto));
  396. }
  397. }
  398.  
  399. $this->db->where("userID", is_user_logged_in());
  400. $this->db->update("users", array('email' => $this->input->post('email'),
  401. 'password' => md5($this->input->post('password')),
  402. 'about' => trim(strip_tags($this->input->post('about')))));
  403. $data['form_message'] = div_class("Account updated", 'alert alert-success');
  404.  
  405. }
  406. }
  407. }
  408.  
  409. $user = $this->db->get_where("users", array("userID" => is_user_logged_in()));
  410. $user = $user->row();
  411. $data['user'] = $user;
  412.  
  413. if( $this->input->get( 'just_activated' ) )
  414. $data[ 'form_message' ] = '<div class="alert alert-warning">Congratulations, your account has been activated!</div>';
  415.  
  416. $this->load->view('user-account', $data);
  417. }
  418.  
  419.  
  420. /*
  421. * User Login
  422. */
  423. public function login() {
  424. ob_start();
  425.  
  426. if($this->loggedIn)
  427. {
  428. redirect('/users');
  429. exit;
  430. }
  431.  
  432. if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) OR $_SERVER['HTTP_X_REQUESTED_WITH']!="XMLHttpRequest") {
  433. redirect("/?login=yes");
  434. }
  435.  
  436. $data = array();
  437.  
  438. if($this->input->post('sbLogin')) {
  439. $user = $this->input->post('uname', TRUE);
  440. $pass = $this->input->post('upwd', TRUE);
  441.  
  442. if(!empty($user) AND !empty($pass)) {
  443. $this->db->where(array("username" => $user));
  444. $this->db->where(array("password" => md5($pass)));
  445. $user = $this->db->get("users");
  446.  
  447. if(count($user->result())) {
  448.  
  449. $u = $user->row();
  450.  
  451. if( $u->isActive == 'No' ) {
  452. echo '<div class="alert alert-danger">This account is not confirmed. Please confirm it by email first (check your inbox/spambox).</div>';
  453. }else{
  454. echo '<div class="alert alert-success">Ok, redirecting..</div>';
  455.  
  456. foreach($user->result() as $u) {
  457. $this->session->set_userdata('loggedIn', $u->userID);
  458. }
  459.  
  460. echo '<script>window.location.href = "/users"</script>';
  461. }
  462.  
  463. }else{
  464. echo '<div class="alert alert-danger">'._('Invalid username and/or password').'</div>';
  465. }
  466.  
  467. }else{
  468. echo '<div class="alert alert-danger">'._('Invalid username and password').'</div>';
  469. }
  470.  
  471. }
  472.  
  473. }
  474.  
  475.  
  476. /*
  477. * Logout function
  478. */
  479. public function logout() {
  480. $this->session->unset_userdata('loggedIn');
  481. redirect('/users/login');
  482. }
  483.  
  484.  
  485. /*
  486. * Register Form/Page
  487. */
  488. public function join() {
  489. if($this->loggedIn)
  490. {
  491. redirect('/users');
  492. exit;
  493. }
  494.  
  495. $this->load->view('join-now');
  496. }
  497.  
  498.  
  499. /*
  500. * Register via AJAX
  501. */
  502. public function ajax_join() {
  503.  
  504. if($this->input->post('sb_signup')) {
  505.  
  506. unset($_POST['sb_signup']);
  507.  
  508. $insert = array();
  509.  
  510. foreach($this->input->post() as $k=>$v) {
  511. if($this->input->post($k, TRUE) != "") {
  512. $insert[$k] = $this->input->post($k, TRUE);
  513. }else{
  514. print '<div class="alert alert-danger">';
  515. print _('All fields are mandatory');
  516. print '</div>';
  517. exit;
  518. }
  519. }
  520.  
  521. $this->db->where(array("username" => $this->input->post('username', TRUE)));
  522. $this->db->or_where(array("email" => $this->input->post('email', TRUE)));
  523. $user = $this->db->get("users");
  524.  
  525. if(count($user->result())) {
  526. print '<div class="alert alert-danger">';
  527. print _('Username/Email taken, please chose another one.');
  528. print '</div>';
  529. exit;
  530. }
  531.  
  532. $insert['ip'] = ip2long($_SERVER['REMOTE_ADDR']);
  533. $insert['password'] = md5($insert['password']);
  534.  
  535. if($this->db->insert("users", $insert)) {
  536.  
  537. // send mail
  538. $headers = 'MIME-Version: 1.0' . "\r\n";
  539. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  540. $headers .= "From: " . $this->config->item('email_from') . "\r\n";
  541. $headers .= "Reply-To: ". $this->config->item('email_from') . "\r\n";
  542.  
  543. // build confirmation url
  544. $hash = md5( $this->input->post('email', TRUE) );
  545. $confirmURL = 'http://' . $_SERVER['SERVER_NAME'] . '/users/confirmation/' . $hash;
  546.  
  547. // body
  548. $body = 'Hi ' . $this->input->post('username', TRUE) . ', <br/><br />';
  549. $body .= 'Please confirm your account by going to the following link: <a href="'.$confirmURL.'">'.$confirmURL.'</a><br/><br />';
  550. $body .= 'Thanks for joining.';
  551.  
  552. mail( $this->input->post('email', TRUE), 'Please confirm your account', $body, $headers );
  553.  
  554. print '<div class="alert alert-success">';
  555. print _('Thanks for joining! Please check your email inbox/spambox for account confirmation!');
  556. print '</div>';
  557. }else{
  558. print '<div class="alert alert-danger">';
  559. print _('DB Error');
  560. print '</div>';
  561. }
  562.  
  563.  
  564. }else{
  565. print '<div class="alert alert-danger">';
  566. print _('-No post-');
  567. print '</div>';
  568. }
  569.  
  570.  
  571. }
  572.  
  573. /*
  574. New user confirmation
  575. */
  576. public function confirmation( $code ) {
  577. if( !isset( $code ) or empty( $code ) )
  578. die( "Invalid activation code" );
  579.  
  580. // match hash
  581. $u = $this->db->get_where( 'users', array( 'md5(email)' => $code, 'isActive' => 'No' ) )->row();
  582.  
  583. if( count( $u ) ) {
  584.  
  585. // activate account
  586. $this->db->query( "UPDATE users SET isActive = 'Yes' WHERE userID = ?", array( $u->userID ) );
  587.  
  588. // login
  589. $this->session->set_userdata( 'loggedIn', $u->userID );
  590.  
  591. // redirect
  592. redirect('/users?just_activated=true');
  593.  
  594. }else{
  595. echo 'We could not find an account for this activation hash.';
  596. }
  597.  
  598. }
  599.  
  600.  
  601. /*
  602. * User Profiles
  603. */
  604. public function profile() {
  605. $username = trim(strip_tags($this->uri->segment(3)));
  606.  
  607. if(!$username) {
  608. $data['error'] = _('User not found');
  609. $this->load->view('user-profiles', $data);
  610. }else{
  611. $user = $this->db->get_where("users", array("username" => $username));
  612. $user = $user->row();
  613. $data['user'] = $user;
  614.  
  615.  
  616. if(count($user)) {
  617. //get listings
  618. $this->db->select("listingID, listing_title, listing_url, bin, CONCAT('$', FORMAT(`bin`,0)) as `starting_`,
  619. site_age, `starting_` as starting_bid,
  620. CONCAT('$', FORMAT(rev_avg,0)) as rev_avg,
  621. list_date,list_expires,
  622. FORMAT(traffic_avg_visits,0) as traffic_avg_visits, pagerank,
  623. PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'), FROM_UNIXTIME(site_age, '%Y%m')) AS diff", false);
  624. $this->db->from("listings");
  625. $this->db->where("list_uID = $user->userID");
  626. $playlist= $this->db->get();
  627. $data['listings'] = $playlist->result();
  628. $data['tl'] = $playlist->num_rows();
  629.  
  630. //get total bids
  631. $this->db->select("COUNT(*) as bids")->from("bids")->where("bidder_ID", $user->userID);
  632. $b = $this->db->get()->row();
  633. $data['tbids'] = $b->bids;
  634. }else{
  635. $data['listings'] = new stdClass;
  636. }
  637.  
  638. $this->load->view('user-profiles', $data);
  639.  
  640. }
  641.  
  642. }
  643.  
  644.  
  645. /*
  646. * Add new listing
  647. */
  648. public function newlisting() {
  649. ob_start();
  650. if(!$this->loggedIn)
  651. {
  652. redirect('/users/login');
  653. exit;
  654. }
  655. $this->load->model('ValidateURL');
  656.  
  657. $validateURL = new ValidateURL();
  658.  
  659. $data = array();
  660. $percentage = 10;
  661.  
  662. if(isset($_POST['sbStep1'])) {
  663. //check URL
  664. $url = $this->input->post('listing_url');
  665.  
  666. $data['basic_icon'] = 'glyphicon glyphicon-remove';
  667. $data['desc_icon'] = 'glyphicon glyphicon-remove';
  668. $data['siteage_icon'] = 'glyphicon glyphicon-remove';
  669. $data['revenue_icon'] = 'glyphicon glyphicon-remove';
  670. $data['pricing_icon'] = 'glyphicon glyphicon-remove';
  671. $data['traffic_icon'] = 'glyphicon glyphicon-remove';
  672. $data['monetization_icon'] = 'glyphicon glyphicon-remove';
  673. $data['unique_icon'] = 'glyphicon glyphicon-remove';
  674. $data['payments_icon'] = 'glyphicon glyphicon-remove';
  675. $data['tags_icon'] = 'glyphicon glyphicon-remove';
  676. $data['verify_icon'] = 'glyphicon glyphicon-remove';
  677.  
  678. if($validateURL->isValidURL($url)) {
  679. if($validateURL->websiteListed($url)) {
  680. $data['err_msg'] = _('Website/Domain already listed on our site.');
  681. }else{
  682.  
  683. $dbURL = $validateURL->dbURLify($url);
  684.  
  685. $this->db->insert("listings",
  686. array(
  687. "list_uID" => $this->loggedIn,
  688. "listing_url" => $dbURL,
  689. "alexa" => get_alexa($dbURL),
  690. "pagerank" => get_pagerank($dbURL),
  691. "list_expires" => strtotime("+30 Days"),
  692. "list_date" => time()));
  693.  
  694. $insertID = $this->db->insert_id();
  695.  
  696. if($insertID) {
  697. $this->session->set_userdata('listingID', $insertID);
  698. redirect('/users/goedit/' . $insertID);
  699. exit;
  700. $data['step'] = TRUE;
  701. }else{
  702. $data['err_msg'] = _('Could not add domain to database.');
  703. }
  704. }
  705. }else{
  706. $data['err_msg'] = _('URL could not be reached');
  707. }
  708.  
  709. }
  710.  
  711. if($this->session->userdata('listingID')) {
  712.  
  713. $id = $this->session->userdata('listingID');
  714. $id = abs(intval($id));
  715.  
  716. $listing = $this->db->get_where("listings", array("listingID" => $id, "list_uID" => $this->loggedIn));
  717.  
  718. if(!$listing->num_rows()) {
  719. echo _("Listing doesn't seem to be yours");
  720. $this->session->unset_userdata('listingID');
  721. echo '<meta http-equiv="refresh" content="2; url=/home"/>"';
  722. exit;
  723. }
  724.  
  725. $l = $listing->row();
  726.  
  727. $data['l'] = $l;
  728.  
  729.  
  730. //update percentage and basic icon
  731. if((!empty($l->listing_title) AND $l->starting_ > 0 AND $l->bin > 0)) $percentage += 20;
  732. $data['basic_icon'] = (!empty($l->listing_title) AND $l->starting_ > 0 AND $l->bin > 0) ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove';
  733.  
  734. //update percentage and description icon
  735. if(!empty($l->listing_description)) $percentage += 15;
  736. $data['desc_icon'] = !empty($l->listing_description) ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove';
  737.  
  738. //update site age icon
  739. if($l->site_age != 0) $percentage += 5;
  740. $data['siteage_icon'] = ($l->site_age != 0) ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove';
  741.  
  742.  
  743. //revenue icon & percentage update
  744. if($l->revenue_details != "" && $l->rev_avg != "") $percentage += 10;
  745. $data['revenue_icon'] = ($l->revenue_details != "" && $l->rev_avg != "") ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove';
  746.  
  747.  
  748. $data['pricing_icon'] = 'glyphicon glyphicon-remove';
  749.  
  750.  
  751. //traffic icon & percentage
  752. if($l->traffic_details != "" && $l->traffic_avg_visits != "" && $l->traffic_avg_views != "") $percentage += 10;
  753. $data['traffic_icon'] = ($l->traffic_details != "" && $l->traffic_avg_visits != "" && $l->traffic_avg_views != "") ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove';
  754.  
  755. //update monetization icon and percentage
  756. if(!empty($l->monetization)) $percentage += 10;
  757. $data['monetization_icon'] = !empty($l->monetization) ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove';
  758.  
  759. //update unique icon and percentage
  760. //$percentage += 5;
  761. $data['unique_icon'] = 'glyphicon glyphicon-ok';
  762.  
  763.  
  764. //payments accepted icon & percentage
  765. if(!empty($l->payment_options)) $percentage += 5;
  766. $data['payments_icon'] = !empty($l->payment_options) ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove';
  767.  
  768.  
  769. //tags icon
  770. if(!empty($l->tag_niche) && !empty($l->tag_implementation) &&! empty($l->tag_type)) $percentage += 5;
  771. $data['tags_icon'] = (!empty($l->tag_niche) && !empty($l->tag_implementation) && !empty($l->tag_type)) ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove';
  772.  
  773. //verify icon
  774. if($l->verified == 'Y') $percentage += 10;
  775. $data['verify_icon'] = ($l->verified == 'Y') ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove';
  776.  
  777.  
  778. //get listing attachments
  779. $att = $this->db->get_where("attachments", array("listID" => $l->listingID));
  780. $data['att'] = $att->result();
  781.  
  782. }
  783.  
  784. $data['percent'] = $percentage;
  785. $data['id'] = @$id;
  786. $data['listing'] = @$l;
  787. $this->load->view('newlisting', $data);
  788.  
  789. ob_end_flush();
  790. }
  791.  
  792. /*
  793. * Unset listingID from session to allow new listing startover
  794. */
  795. public function clearlisting() {
  796. ob_start();
  797.  
  798. if(!$this->loggedIn)
  799. {
  800. redirect('/users/login');
  801. exit;
  802. }
  803.  
  804. $id = $this->session->userdata("listingID");
  805. $id = abs(intval($id));
  806.  
  807. #$this->db->delete("listings", array("listingID" => $id, "list_uID" => $this->loggedIn));
  808.  
  809. $this->session->unset_userdata('listingID');
  810.  
  811. header("Location: /users/newlisting");
  812. ob_end_flush();
  813.  
  814. }
  815.  
  816. /*
  817. * Edit Listing
  818. */
  819. public function editlisting() {
  820. ob_start();
  821. if(!$this->loggedIn)
  822. {
  823. redirect('/users/login');
  824. exit;
  825. }
  826.  
  827. $this->htmlheader();
  828.  
  829. $id = $this->uri->segment(4);
  830. $action = $this->uri->segment(5);
  831.  
  832. if(!$id || !$action) die(div_class('Error! No ID / Action!'));
  833.  
  834.  
  835. $listing = $this->db->get_where("listings", array("listingID" => $id));
  836. #$listing = $listing->result();
  837.  
  838. if ($listing->num_rows() > 0)
  839. {
  840. $listing = $listing->row();
  841. }else{
  842. $listing = null;
  843. }
  844.  
  845. switch($action) {
  846. case "basic":
  847. ?>
  848. <form method="post" action="/users/updatelistings/<?php echo $id ?>" class="ajax-modal-forms">
  849. <label><?=_('Listing Type')?>:</label>
  850. <input type="radio" name="list_type" value="domain" <?php if($listing && $listing->list_type == 'domain') echo 'checked=""'; ?>/> Domain Only
  851. <input type="radio" name="list_type" value="website" <?php if($listing && $listing->list_type == 'website') echo 'checked=""'; ?>/> Website
  852.  
  853. <label><?=_('Listing Title')?>:</label>
  854. <input type="text" name="listing_title" value="<?php if($listing) echo $listing->listing_title; ?>" class="input-xxlarge required"/><br/>
  855.  
  856. <label><?=_('Starting Price')?>:</label>
  857. <input type="number" name="starting_" value="<?php if($listing) echo $listing->starting_; ?>" class="input-xxlarge required"/><br/>
  858.  
  859. <label><?=_('Reserve Price')?>:</label>
  860. <input type="number" name="reserve" value="<?php if($listing) echo $listing->reserve; ?>" class="input-xxlarge required"/><br/>
  861.  
  862. <label><?=_('BIN Price')?>:</label>
  863. <input type="number" name="bin" value="<?php if($listing) echo $listing->bin; ?>" class="input-xxlarge required"/><br/>
  864.  
  865. <input type="submit" name="sb" value="<?=_('Update')?>" class="update-sb btn btn-warning" />
  866. </form>
  867.  
  868. <div class="ajax-modal-result"></div>
  869. <?php
  870. break;
  871.  
  872. case "description":
  873. ?>
  874. <form method="post" action="/users/updatelistings/<?php echo $id ?>" class="ajax-modal-forms">
  875. <textarea name="listing_description" id="listing_description" rows="12" class="input-xxlarge required" style="width:650px;"><?php echo $listing->listing_description; ?></textarea>
  876. <br/>
  877. <input type="submit" name="sb" value="<?=_('Update') ?>" class="update-sb btn btn-warning" />
  878. </form>
  879.  
  880. <div class="ajax-modal-result"></div>
  881. <?php
  882. break;
  883.  
  884. case "site_age":
  885. $months = array(1 => 'Jan.', 2 => 'Feb.', 3 => 'Mar.', 4 => 'Apr.', 5 => 'May', 6 => 'Jun.', 7 => 'Jul.', 8 => 'Aug.', 9 => 'Sep.', 10 => 'Oct.', 11 => 'Nov.', 12 => 'Dec.');
  886.  
  887. ?>
  888. <form method="post" action="/users/updatelistings/<?php echo $id ?>" class="ajax-modal-forms form-horizontal">
  889. <label><strong><?=_('Date Estabilished') ?>:</strong></label>
  890.  
  891. <select name="month" class="input-small">
  892. <?php foreach($months as $k=> $m) {
  893. $m = str_replace(".", "", $m);
  894. if($listing AND $listing->site_age != 0) {
  895. if(date("M", $listing->site_age) == $m) {
  896. echo '<option value="'.$k.'" selected="">'.$m.'</option>';
  897. }else{
  898. echo '<option value="'.$k.'">'.$m.'</option>';
  899. }
  900. }else{
  901. echo '<option value="'.$k.'">'.$m.'</option>';
  902. }
  903. }
  904. ?>
  905. </select>
  906. <select name="day" class="input-small">
  907. <?php
  908. for($i = 1; $i<= 31; $i++)
  909. {
  910. if($listing AND $listing->site_age != 0) {
  911. if(date("j", $listing->site_age) == $i) {
  912. echo '<option value="'.$i.'" selected="">'.$i.'</option>';
  913. }else{
  914. echo '<option value="'.$i.'">'.$i.'</option>';
  915. }
  916. }else{
  917. echo '<option value="'.$i.'">'.$i.'</option>';
  918. }
  919. }
  920. ?>
  921. </select>
  922. <select name="year" class="input-small">
  923. <?php
  924. for($i = 1990; $i<= date("Y"); $i++)
  925. {
  926. if($listing AND $listing->site_age != 0) {
  927. if(date("Y", $listing->site_age) == $i) {
  928. echo '<option value="'.$i.'" selected="">'.$i.'</option>';
  929. }else{
  930. echo '<option value="'.$i.'">'.$i.'</option>';
  931. }
  932. }else{
  933. echo '<option value="'.$i.'">'.$i.'</option>';
  934. }
  935. }
  936. ?>
  937. </select>
  938.  
  939.  
  940. <input type="submit" name="sb" value="<?=_('Update') ?>" class="update-sb btn btn-warning" />
  941. </form>
  942.  
  943. <div class="ajax-modal-result"></div>
  944. <?php
  945. break;
  946.  
  947.  
  948. case "monetization":
  949. ?>
  950. <form method="post" action="/users/updatelistings/<?php echo $id ?>" class="ajax-modal-forms form-horizontal">
  951. <label><strong><?=_('Monetization Methods') ?>:</strong></label>
  952.  
  953. <input type="checkbox" name="monetization[]" value="Sales of Products or Services" <?php if($listing AND preg_match('/Sales of Products or Services/i', $listing->monetization)) echo 'checked=""'; ?>/> <?=_('Sales of Products or Services') ?><br/>
  954. <input type="checkbox" name="monetization[]" value="Affiliate Income" <?php if($listing AND preg_match('/Affiliate Income/i', $listing->monetization)) echo 'checked=""'; ?>/> <?=_('Affiliate Income') ?><br/>
  955. <input type="checkbox" name="monetization[]" value="Advertising Sales" <?php if($listing AND preg_match('/Advertising Sales/i', $listing->monetization)) echo 'checked=""'; ?>/> <?=_('Advertising Sales') ?><br/>
  956.  
  957. <br/>
  958. <input type="submit" name="sb" value="<?=_('Update') ?>" class="update-sb btn btn-warning" />
  959. </form>
  960.  
  961. <div class="ajax-modal-result"></div>
  962. <?php
  963. break;
  964.  
  965. case "unique":
  966. ?>
  967. <form method="post" action="/users/updatelistings/<?php echo $id ?>" class="ajax-modal-forms form-horizontal">
  968. <label><strong><?=_('Is your Design/Content Unique?') ?></strong></label>
  969.  
  970. <input type="radio" name="unique_" value="not unique" <?php if($listing AND $listing->unique_ == 'not unique') echo 'checked=""'; ?>/> <?=_('Not Unique') ?><br/>
  971. <input type="radio" name="unique_" value="design" <?php if($listing AND $listing->unique_ == 'design') echo 'checked=""'; ?>/> <?=_('Design is Unique') ?><br/>
  972. <input type="radio" name="unique_" value="content" <?php if($listing AND $listing->unique_ == 'content') echo 'checked=""'; ?>/> <?=_('Content is Unique') ?><br/>
  973. <input type="radio" name="unique_" value="design & content" <?php if($listing AND $listing->unique_ == 'design & content') echo 'checked=""'; ?>/> <?=_('Both Content &amp; Design are Unique') ?><br/>
  974.  
  975. <br/>
  976. <input type="submit" name="sb" value="<?=_('Update') ?>" class="update-sb btn btn-warning" />
  977. </form>
  978.  
  979. <div class="ajax-modal-result"></div>
  980. <?php
  981. break;
  982.  
  983. case "payments_accepted":
  984. ?>
  985. <form method="post" action="/users/updatelistings/<?php echo $id ?>" class="ajax-modal-forms form-horizontal">
  986. <label><strong><?=_('Accepted Payment Methods') ?>:</strong></label>
  987.  
  988. <input type="checkbox" name="payment_options[]" value="Escrow.com" <?php if($listing AND preg_match('/Escrow/i', $listing->payment_options)) echo 'checked=""'; ?>/> Escrow.com<br/>
  989. <input type="checkbox" name="payment_options[]" value="Credit Card" <?php if($listing AND preg_match('/Credit Card/i', $listing->payment_options)) echo 'checked=""'; ?>/> Credit Card<br/>
  990. <input type="checkbox" name="payment_options[]" value="Cheque" <?php if($listing AND preg_match('/Cheque/i', $listing->payment_options)) echo 'checked=""'; ?>/> Cheque<br/>
  991. <input type="checkbox" name="payment_options[]" value="PayPal" <?php if($listing AND preg_match('/PayPal/i', $listing->payment_options)) echo 'checked=""'; ?>/> PayPal<br/>
  992.  
  993. <br/>
  994. <input type="submit" name="sb" value="<?=_('Update') ?>" class="update-sb btn btn-warning" />
  995. </form>
  996.  
  997. <div class="ajax-modal-result"></div>
  998. <?php
  999. break;
  1000.  
  1001. case "revenue":
  1002. ?>
  1003. <form method="post" action="/users/updatelistings/<?php echo $id ?>" class="ajax-modal-forms">
  1004. <label><strong><?=_('Last three months AVERAGE') ?>:</strong></label>
  1005. <input type="text" name="rev_avg" value="<?php echo $listing->rev_avg; ?>"/> per month<br/>
  1006. <br/><br/>
  1007. <label><strong><?=_('Describe revenue as much as possible') ?>:</strong></label>
  1008. <textarea name="revenue_details" id="listing_description" rows="8" class="input-xxlarge required" style="width:650px;"><?php echo $listing->revenue_details; ?></textarea>
  1009. <br/>
  1010. <input type="submit" name="sb" value="<?=_('Update') ?>" class="update-sb btn btn-warning" />
  1011. </form>
  1012.  
  1013. <div class="ajax-modal-result"></div>
  1014. <?php
  1015. break;
  1016.  
  1017. case "traffic_details":
  1018. ?>
  1019. <form method="post" action="/users/updatelistings/<?php echo $id ?>" class="ajax-modal-forms">
  1020. <label><strong><?=_('Last three months AVERAGE visits') ?>:</strong></label>
  1021. <input type="text" name="traffic_avg_visits" value="<?php echo $listing->traffic_avg_visits; ?>"/> per month<br/>
  1022. <br/>
  1023.  
  1024. <label><strong><?=_('Last three months AVERAGE views') ?>:</strong></label>
  1025. <input type="text" name="traffic_avg_views" value="<?php echo $listing->traffic_avg_views; ?>"/> per month<br/>
  1026.  
  1027. <br/><br/>
  1028.  
  1029. <label><strong><?=_('Traffic description') ?>:</strong></label>
  1030. <textarea name="traffic_details" id="listing_description" rows="8" class="input-xxlarge required" style="width:650px;"><?php echo $listing->traffic_details; ?></textarea>
  1031.  
  1032. <br/>
  1033. <input type="submit" name="sb" value="<?=_('Update') ?>" class="update-sb btn btn-warning" />
  1034. </form>
  1035.  
  1036. <div class="ajax-modal-result"></div>
  1037. <?php
  1038. break;
  1039.  
  1040. case "tags":
  1041. ?>
  1042.  
  1043. <form method="post" action="/users/updatelistings/<?php echo $id ?>" class="ajax-modal-forms">
  1044. <p class="alert alert-warning"><?=_('Only one keyword per tag is allowed.') ?></p>
  1045.  
  1046. <label><strong><?=_('Niche') ?>:</strong><?=_('(health, sports, etc.)') ?></label>
  1047. <input type="text" name="tag_niche" value="<?php echo $listing->tag_niche; ?>"/>
  1048. <br/>
  1049.  
  1050. <label><strong><?=_('Type') ?>:</strong><?=_('(forum, blog, etc.)') ?></label>
  1051. <input type="text" name="tag_type" value="<?php echo $listing->tag_type; ?>"/>
  1052. <br/>
  1053.  
  1054. <label><strong><?=_('Implementation') ?>:</strong><?=_('(custom, wordpress, etc.)') ?></label>
  1055. <input type="text" name="tag_implementation" value="<?php echo $listing->tag_implementation; ?>"/>
  1056. <br/>
  1057.  
  1058. <br/>
  1059. <input type="submit" name="sb" value="<?=_('Update') ?>" class="update-sb btn btn-warning" />
  1060. </form>
  1061.  
  1062. <div class="ajax-modal-result"></div>
  1063.  
  1064. <?php
  1065. break;
  1066.  
  1067. case "verify":
  1068.  
  1069. ?>
  1070. <h3 class="text-info"><?=_('Upload a file to your host') ?>:</h3>
  1071. <span class="text-info"><?=_('Upload a file called ') ?><span class="text-warning">verify_<?php echo $id ?>.txt</span>
  1072. <?=_("so it's accessibile on this URL : ") ?><span class="text-warning">http://<?php echo $listing->listing_url; ?>/verify_<?php echo $id ?>.txt</span></span>
  1073.  
  1074. <br/>
  1075.  
  1076. <a href="/users/verify_file/<?php echo $id; ?>" target="_blank" style="font-weight:bold;color:#cc0000;font-size:16px;"><?=_('Download file') ?></a>
  1077.  
  1078. <br/><br/>
  1079. <form method="post" action="/users/updatelistings/<?php echo $id ?>" class="ajax-modal-forms">
  1080. <br/>
  1081. <input type="hidden" name="verify_file" value="<?php echo $id; ?>" />
  1082. <input type="submit" name="sb" value="<?=_('Update') ?>" class="update-sb btn btn-warning" />
  1083. </form>
  1084. <div class="ajax-modal-result"></div>
  1085. <?php
  1086. break;
  1087.  
  1088.  
  1089. }
  1090.  
  1091. $this->htmlfooter();
  1092.  
  1093. ob_end_flush();
  1094. }
  1095.  
  1096.  
  1097. /*
  1098. * AJAX Attachments
  1099. */
  1100. public function att() {
  1101. if(!$this->loggedIn)
  1102. {
  1103. redirect('/users/login');
  1104. exit;
  1105. }
  1106.  
  1107. $id = $this->session->userdata("listingID");
  1108. $id = abs(intval($id));
  1109. $userID = $this->loggedIn;
  1110.  
  1111. if(!$id) die("Listing ID Not set");
  1112.  
  1113. if(!$this->input->post("sb_att")) die("Page reached in error");
  1114.  
  1115. $att_title = $this->input->post('att_title');
  1116.  
  1117. if(!$att_title or empty($att_title)) die(_("Attachment title please"));
  1118.  
  1119. //image upload
  1120. if(isset($_FILES['file'])) {
  1121.  
  1122. //get extension
  1123. $ext = explode(".", $_FILES['file']['name']);
  1124. $ext = strtolower(end($ext));
  1125. $rand = md5(uniqid());
  1126.  
  1127. if($ext != "png" and $ext != "jpg" and $ext != "jpeg") {
  1128. echo '<div class="alert alert-danger">' . _("File must be PNG/JPEG ONLY") .'</div>';
  1129. exit;
  1130. }
  1131.  
  1132. if(!@getimagesize($_FILES['file']['tmp_name'])){
  1133. echo '<div class="alert alert-danger">' . _("Invalid/Corrupt image file. Try another one") .'</div>';
  1134. exit;
  1135. }
  1136.  
  1137. if(move_uploaded_file($_FILES['file']['tmp_name'], getcwd() .'/uploads/' . $rand . '.' . $ext)) {
  1138.  
  1139. //make thumbnail
  1140. $config['image_library'] = 'gd2';
  1141. $config['source_image'] = getcwd() .'/uploads/' . $rand . '.' . $ext;
  1142. $config['create_thumb'] = FALSE;
  1143. $config['maintain_ratio'] = TRUE;
  1144. $config['width'] = 44;
  1145. $config['height'] = 26;
  1146. $config['new_image'] = getcwd() . '/uploads/small-' . $rand . '.' . $ext;
  1147.  
  1148. $this->load->library('image_lib', $config);
  1149.  
  1150. $this->image_lib->resize();
  1151.  
  1152. if ( ! $this->image_lib->resize())
  1153. {
  1154. echo $this->image_lib->display_errors();
  1155. exit;
  1156. }
  1157.  
  1158.  
  1159. $this->db->insert("attachments",
  1160. array("listID" => $id,
  1161. "att_title" => trim(strip_tags($att_title)),
  1162. "att_file" => $rand . '.' . $ext));
  1163.  
  1164. if($this->db->affected_rows()) {
  1165. echo '<script>window.parent.location.reload();</script>';
  1166. } else{
  1167. echo $this->db->last_error();
  1168. }
  1169.  
  1170. }else{
  1171. echo _('Image could not be uploaded.');
  1172. }
  1173.  
  1174. }else{
  1175. echo _("Please choose a file to be uploaded!");
  1176. }
  1177. }
  1178.  
  1179.  
  1180. /*
  1181. * Remove attachments
  1182. */
  1183. public function remove_att() {
  1184. ob_start();
  1185.  
  1186. if(!$this->loggedIn)
  1187. {
  1188. redirect('/users/login');
  1189. exit;
  1190. }
  1191.  
  1192.  
  1193. $attID = $this->uri->segment(3);
  1194. $attID = abs(intval($attID));
  1195. $userID = $this->loggedIn;
  1196.  
  1197.  
  1198. if(!$attID || !$userID) exit(div_class('Error! No Attachment ID / UserID'));
  1199.  
  1200. //check if owns this attachments
  1201. $rs = $this->db->get_where("attachments", array("attachID" => $attID));
  1202. $rs = $rs->row();
  1203.  
  1204. if(!count($rs)) die("No att with this id");
  1205.  
  1206. $rs = $this->db->query("select list_uID from listings where listingID = '$rs->listID'");
  1207. $u = $rs->row();
  1208.  
  1209.  
  1210. if(!count($u)) die("could not get list owner info");
  1211.  
  1212. if($u->list_uID != $userID) die("You dont own this listing");
  1213.  
  1214. $this->db->delete("attachments", array("attachID" => $attID));
  1215.  
  1216. header("Location: /users/newlisting");
  1217.  
  1218.  
  1219. ob_end_flush();
  1220. }
  1221.  
  1222.  
  1223.  
  1224. /*
  1225. * AJAX Listing Insert/Update
  1226. */
  1227. public function updatelistings() {
  1228. if(!$this->loggedIn)
  1229. {
  1230. redirect('/users/login');
  1231. die("Not logged in");
  1232. }
  1233.  
  1234.  
  1235. $listingID = $this->uri->segment(3);
  1236. $listingID = abs(intval($listingID));
  1237. $userID = $this->loggedIn;
  1238.  
  1239.  
  1240. if(!$listingID || !$userID) exit(div_class('Error! No ID / UserID'));
  1241.  
  1242.  
  1243. foreach($_POST as $k => $v) {
  1244.  
  1245. if(!is_array($v)) {
  1246. if($k != "listing_description" AND $k != "revenue_details" AND $k != "traffic_details") {
  1247. $_POST[$k] = trim(strip_tags($v));
  1248. }elseif($k == "listing_description"){
  1249. $_POST[$k] = trim(strip_tags($v, "<i><em><p><br><ol><ul><li><b><strong><h1><h2><h3><h4><h5><h6><font><span><div>"));
  1250. }
  1251.  
  1252. if($k == "tag_niche" || $k == "tag_implementation" || $k == "tag_type") {
  1253. $_POST[$k] = str_replace(array('"', "'"), array("", ""), $v);
  1254. $_POST[$k] = preg_replace('/[^,]*,\s*/', "", $v);
  1255. }
  1256.  
  1257. if(strlen($v) == 0) {
  1258. echo div_class(_("All fields are required. If you see this in error hit Submit again.") . " " . $k);
  1259. exit;
  1260. }
  1261.  
  1262.  
  1263. //validate numbers
  1264. if($k == 'reserve' || $k == 'bin' || $k == 'starting_') {
  1265. $v = abs(intval($v));
  1266.  
  1267. if($v < 10) {
  1268. echo div_class(_("BIN/Starting/Reserve must be at least 10"));
  1269. exit;
  1270. }
  1271.  
  1272. }
  1273. }
  1274.  
  1275. }//foreach
  1276.  
  1277. //validate date estabilished
  1278. if($this->input->post('month') && $this->input->post('day') && $this->input->post('year')) {
  1279. $date = mktime(0,0,0,$this->input->post('month'),$this->input->post('day'), $this->input->post('year'));
  1280. $_POST['site_age'] = $date;
  1281. }
  1282.  
  1283.  
  1284. //monetization serialize (if set)
  1285. if($this->input->post('monetization')) {
  1286. if(!empty($_POST['monetization']) AND isset($_POST['monetization'])) {
  1287. $_POST['monetization'] = serialize($_POST['monetization']);
  1288. }
  1289. }
  1290.  
  1291. //payment methods serialize (if set)
  1292. if($this->input->post('payment_options')) {
  1293. if(!empty($_POST['payment_options']) AND isset($_POST['payment_options'])) {
  1294. $_POST['payment_options'] = serialize($_POST['payment_options']);
  1295. }
  1296. }
  1297.  
  1298. //update listing
  1299. if(isset($_POST[0])) unset($_POST[0]);
  1300. if(isset($_POST['year'])) unset($_POST['year']);
  1301. if(isset($_POST['month'])) unset($_POST['month']);
  1302. if(isset($_POST['day'])) unset($_POST['day']);
  1303.  
  1304. unset($_POST['sb']);
  1305.  
  1306.  
  1307. //verify file
  1308. if($this->input->post('verify_file')) {
  1309.  
  1310. $uri = $this->db->get_where("listings", array("listingID" => $listingID, 'list_uID' => $userID));
  1311.  
  1312. if($uri->num_rows()) {
  1313. $uri = $uri->row();
  1314.  
  1315. //try reading the file
  1316. $file = 'http://' . $uri->listing_url . '/verify_' . $listingID . '.txt';
  1317.  
  1318. $ch = curl_init();
  1319. $timeout = 5;
  1320. curl_setopt($ch, CURLOPT_URL, $file);
  1321. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1322. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  1323. $contents = curl_exec($ch);
  1324. curl_close($ch);
  1325.  
  1326. if ($contents) {
  1327. if($contents != md5('verify-' . $listingID)) {
  1328. echo div_class("Error : File doesn't contain the validation code");
  1329. exit;
  1330. }else{
  1331. $_POST['verified'] = 'Y';
  1332. unset($_POST['verify_file']);
  1333. }
  1334. }// if contenst
  1335.  
  1336. } // if num rows
  1337. }// if verify file
  1338.  
  1339. // verify by meta tags
  1340. if( $this->input->post( 'verify_meta' ) ) {
  1341.  
  1342. $uri = $this->db->get_where("listings",
  1343. array("listingID" => $listingID, 'list_uID' => $userID));
  1344.  
  1345. if($uri->num_rows()) {
  1346.  
  1347. $uri = $uri->row();
  1348.  
  1349. //try reading the file
  1350. $file = 'http://' . $uri->listing_url;
  1351. $tags = get_meta_tags( $file );
  1352.  
  1353. if( count( $tags ) ) {
  1354. if( isset( $tags[ 'marketplace-site-verification' ] ) ) {
  1355. $_POST['verified'] = 'Y';
  1356. }else{
  1357. die(div_class("Error: We couldn't find meta tag 'marketplace-site-verification'"));
  1358. }
  1359. }else{
  1360. die( div_class("No meta tags detected.") );
  1361. }
  1362.  
  1363.  
  1364. }
  1365.  
  1366. unset( $_POST[ 'verify_meta' ] );
  1367. unset( $_POST[ 'sbMeta' ] );
  1368. }
  1369.  
  1370. // verify by DNS TXT Record
  1371. if( $this->input->post( 'verify_dns' ) ) {
  1372.  
  1373. $uri = $this->db->get_where("listings",
  1374. array("listingID" => $listingID, 'list_uID' => $userID));
  1375.  
  1376. if($uri->num_rows()) {
  1377.  
  1378. $uri = $uri->row();
  1379.  
  1380. //try reading the file
  1381. $file = 'http://' . $uri->listing_url;
  1382. $dns = dns_get_record( $uri->listing_url, DNS_TXT );
  1383.  
  1384. if( count( $dns ) ) {
  1385. $found = false;
  1386. $entries = '';
  1387.  
  1388. foreach( $dns as $entry ) {
  1389. if( $entry[ 'type' ] == 'txt' AND $entry[ 'txt' ] == 'marketplace-site-verification-' . $listingID ) {
  1390.  
  1391. $_POST['verified'] = 'Y';
  1392.  
  1393. $found = true;
  1394. }
  1395.  
  1396. $entries .= 'TXT: ' . $entry[ 'txt' ] . '<br/>';
  1397. }
  1398.  
  1399. if( !$found ) {
  1400. echo div_class("Error: We couldn't TXT entry 'marketplace-site-verification'");
  1401. echo div_class('Following entries were found<br/>' . $entries, 'alert alert-info');
  1402. exit;
  1403. }
  1404.  
  1405. }else{
  1406. die( div_class("No TXT DNS tags detected. Try again later as it may take up to 24 hours for DNS entries to propagate depending on your provider.") );
  1407. }
  1408.  
  1409.  
  1410. }
  1411.  
  1412. unset( $_POST[ 'verify_dns' ] );
  1413. unset( $_POST[ 'sbDNS' ] );
  1414. }
  1415.  
  1416.  
  1417.  
  1418. if($this->input->post()) {
  1419. $this->db->update("listings", $this->input->post(), array("listingID" => $listingID, 'list_uID' => $userID));
  1420. echo '<div class="alert alert-success">Successfully saved.</div>';
  1421.  
  1422. // increase progress dinamically
  1423. if( $this->input->post( 'list_type' ) ) {
  1424. $progress = 30;
  1425. $icon = 'basic-icon';
  1426. } elseif ( $this->input->post( 'listing_description' ) ) {
  1427. $progress = 45;
  1428. $icon = 'desc-icon';
  1429. }elseif( $this->input->post( 'site_age' ) ) {
  1430. $progress = 50;
  1431. $icon = 'siteage-icon';
  1432. }elseif( $this->input->post( 'rev_avg' ) ) {
  1433. $progress = 70;
  1434. $icon = 'revenue-icon';
  1435. }elseif( $this->input->post( 'traffic_avg_visits' ) ) {
  1436. $progress = 80;
  1437. $icon = 'traffic-icon';
  1438. }elseif( $this->input->post( 'unique_' ) ) {
  1439. $progress = 80;
  1440. $icon = 'unique-icon';
  1441. }elseif( $this->input->post( 'payment_options' ) ) {
  1442. $progress = 85;
  1443. $icon = 'payments-icon';
  1444. }elseif( $this->input->post( 'tag_niche' ) ) {
  1445. $progress = 90;
  1446. $icon = 'tags-icon';
  1447. }elseif( $this->input->post( 'verified' ) ) {
  1448. $progress = 100;
  1449. $icon = 'verify-icon';
  1450. }else{
  1451. $progress = 0;
  1452. $icon = 'none';
  1453. }
  1454.  
  1455. echo '<script>
  1456.  
  1457. $(".progress-bar").css("width", "'.$progress.'%").attr("aria-valuenow", '.$progress.');
  1458. $(".progress-bar").html("'.$progress.'%");
  1459. $("#'.$icon.'").removeClass("glyphicon-remove").addClass("glyphicon-ok");
  1460. </script>';
  1461.  
  1462. }else{
  1463. echo div_class(_("Nothing to be saved."));
  1464. }
  1465. }
  1466.  
  1467. /*
  1468. * HTML Headers -- for iframe forms
  1469. */
  1470. public function htmlheader() {
  1471. ?>
  1472. <!DOCTYPE html>
  1473. <html lang="en">
  1474. <head>
  1475. <meta charset="utf-8">
  1476. <title>Website Marketplace</title>
  1477. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  1478. <link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css' />
  1479. <link href='https://fonts.googleapis.com/css?family=Cabin:400' rel='stylesheet' type='text/css'>
  1480. <link href="<?php echo base_url(); ?>css/bootstrap.css" type="text/css" rel="stylesheet" />
  1481. <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/style.css" />
  1482. <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
  1483. <script src="<?php echo base_url(); ?>js/bootstrap.min.js" type="text/javascript"></script>
  1484. <script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.validate.js"></script>
  1485. <script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.form.js"></script>
  1486. <script type="text/javascript" src="<?php echo base_url(); ?>js/ajax.js"></script>
  1487. <script src="<?php echo base_url(); ?>js/nicEdit.js" type="text/javascript"></script>
  1488. <script type="text/javascript">
  1489. bkLib.onDomLoaded(function() {
  1490. new nicEditor({iconsPath : '<?php echo base_url(); ?>img/nicEditorIcons.gif', maxHeight : 400, buttonList : ['forecolor', 'fontFormat','bold','italic','underline','strikeThrough','subscript','superscript', 'ol', 'ul', 'left', 'center', 'right']}).panelInstance('listing_description');
  1491. });
  1492. </script>
  1493. <!--[if gte IE 9]>
  1494. <style type="text/css">
  1495. .gradient {
  1496. filter: none;
  1497. }
  1498. </style>
  1499. <![endif]-->
  1500. </head>
  1501. <body style="background:white;">
  1502. <div style="margin-top:15px;margin-left:15px;">
  1503. <?php
  1504. }
  1505.  
  1506.  
  1507. /*
  1508. * HTML Footer -- for iframe forms
  1509. */
  1510. public function htmlfooter() {
  1511. echo '</div></body></html>';
  1512. }
  1513.  
  1514.  
  1515. /*
  1516. * Verify file generate
  1517. */
  1518. public function verify_file() {
  1519. ob_start();
  1520. if(!$this->loggedIn)
  1521. {
  1522. redirect('/users/login');
  1523. exit;
  1524. }
  1525.  
  1526. $id = $this->uri->segment(3);
  1527. $id = abs(intval($id));
  1528.  
  1529. if(!$id) die("Invalid Listing ID");
  1530.  
  1531. header('Content-type: text/plain');
  1532. header('Content-Disposition: attachment; filename="verify_'.$id.'.txt"');
  1533.  
  1534. echo md5('verify-' . $id);
  1535.  
  1536. ob_end_flush();
  1537. }
  1538.  
  1539. /*
  1540. * Manage Website Screenshot Preferences
  1541. */
  1542. public function screenshots( $listingID ) {
  1543.  
  1544. if(!$this->loggedIn)
  1545. {
  1546. redirect('/users/login');
  1547. exit;
  1548. }
  1549.  
  1550. // validate id
  1551. $id = abs(intval($listingID));
  1552.  
  1553. if(!$id)
  1554. die("Invalid Listing ID");
  1555.  
  1556. // is he the owner
  1557. $isItTheOwner = $this->db->get_where( 'listings', array( 'listingID' => $id, 'list_uID' => $this->loggedIn ) )->row();
  1558.  
  1559. if( !count( $isItTheOwner ) )
  1560. die( "Sorry, you don't own this listing or listing doesn't exist." );
  1561.  
  1562. $data[ 'message' ] = '';
  1563.  
  1564. // save autogenerated preference
  1565. if( $pref = $this->input->post( 'screenshot_preferences' ) ) {
  1566. set_option( 'thumbnail_' . $listingID, 'autogenerated' );
  1567. $data[ 'message' ] = div_class( 'Preferences saved. <a href="/users/mylistings">Back to my listings</a>', 'alert alert-warning' );
  1568. }
  1569.  
  1570. // save uploaded thumbnail
  1571. if( isset( $_FILES[ 'screenshot' ] ) ) {
  1572.  
  1573. //get extension
  1574. $ext = explode(".", $_FILES['screenshot']['name']);
  1575. $ext = strtolower(end($ext));
  1576. $rand = md5(uniqid());
  1577.  
  1578. if($ext != "png" and $ext != "jpg" and $ext != "jpeg") {
  1579. $data[ 'message' ] = '<div class="alert alert-danger">' . _("File must be PNG/JPEG ONLY") .'</div>';
  1580. }elseif (!@getimagesize($_FILES['screenshot']['tmp_name'])) {
  1581. $data[ 'message' ] = '<div class="alert alert-danger">' . _("Invalid/Corrupt image file. Try another one") .'</div>';
  1582. }else{
  1583.  
  1584. if(move_uploaded_file($_FILES['screenshot']['tmp_name'],
  1585. getcwd() .'/uploads/' . $rand . '.' . $ext)) {
  1586.  
  1587. $filename = $rand . '.' . $ext;
  1588. set_option( 'thumbnail_' . $listingID, $filename );
  1589.  
  1590. $data[ 'message' ] = div_class('Your website screenshot was successfully saved', 'alert alert-warning');
  1591.  
  1592. }else{
  1593. $data[ 'message' ] = 'Trouble uploading files to /uploads/ folder. Set 0755 permsissions to that folder.';
  1594. }
  1595.  
  1596. }
  1597. }
  1598.  
  1599. // pass listing info
  1600. $data[ 'l' ] = $isItTheOwner;
  1601.  
  1602. // get this listing info
  1603. $option = get_option( 'thumbnail_' . $listingID, 'autogenerated' );
  1604. $data[ 'pref' ] = $option;
  1605.  
  1606. // load view
  1607. $this->load->view( 'screenshot-preferences', $data );
  1608.  
  1609. }
  1610. }
Add Comment
Please, Sign In to add comment