Plugin Directory

Changeset 1465597


Ignore:
Timestamp:
08/02/2016 12:45:32 AM (10 years ago)
Author:
ppohler
Message:

add multiple servers

Location:
rets-rabbit/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • rets-rabbit/trunk/readme.txt

    r1437341 r1465597  
    44Requires at least: 3.0.1
    55Tested up to: 4.3
    6 Stable tag: 1.0.7
     6Stable tag: 1.0.8
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • rets-rabbit/trunk/retsrabbit.php

    r1437341 r1465597  
    44Plugin URI: http://retsrabbit.com/wordpress
    55Description: Plugin to integrate the real estate cloud service, Rets Rabbit, with Wordpress.
    6 Version: 1.0.6
     6Version: 1.0.8
    77Author: Patrick Pohler
    88Author URI: http://www.anecka.com
     
    2929
    3030register_activation_hook(__FILE__, 'retsrabbit_update_check' );
    31 
     31register_activation_hook( __FILE__, 'rr_install' );
    3232?>
  • rets-rabbit/trunk/rr_adapter.php

    r1437341 r1465597  
    3131    }
    3232
    33     public function metadata() {
     33    public function metadata($server_hash = "") {
    3434        $client = new Client($this->access_token);
    3535        $this->_getAPIEndpoint($client);
     
    3939
    4040            if(sizeof($servers) > 0) {
    41                 $server_hash = $servers[0]->server_hash;
     41                if($server_hash == "")
     42                    $server_hash = $servers[0]->server_hash;
    4243
    4344                $metadata = get_transient("rr-metadata");
     
    5657    }
    5758
    58     public function get_listing($mls_id, $num_photos = -1, $cache = false, $cache_duration = 4) {
     59    public function get_servers() {
    5960        $client = new Client($this->access_token, true);
    6061        $this->_getAPIEndpoint($client);
    6162
    6263        $servers = $client->getServers();
    63         $server_hash = $servers[0]['server_hash']; //dangerous, need to adjust this
     64        return $servers;
     65    }
     66
     67    public function get_listing($mls_id, $server_num, $num_photos = -1, $cache = false, $cache_duration = 4) {
     68        $client = new Client($this->access_token, true);
     69        $this->_getAPIEndpoint($client);
     70
     71        $servers = $client->getServers();
     72        if(isset($servers[$server_num])) {
     73            $server_hash = $servers[$server_num]['server_hash']; //dangerous, need to adjust this
     74        } else {
     75            $server_hash = $servers[0]['server_hash'];
     76        }
    6477        $response = null;
    6578        $query_key = "";
     
    8093        }
    8194
    82         $variables = array();
     95        $variable = array();
    8396
    8497        if($response != null) {
    85             $variable = array();
    8698            $variable['mls_id'] = $response['mls_id'];
    8799            foreach($response['fields'] as $key => $field) {
     
    95107    }
    96108
    97     public function run_search($params, $limit, $num_photos, $orderby = "", $sort_order = "", $sort_option = "", $cache = false, $cache_duration = 4) {
     109    public function run_search($params, $limit, $num_photos, $server_num, $orderby = "", $sort_order = "", $sort_option = "", $cache = false, $cache_duration = 4) {
    98110        $client = new Client($this->access_token, true);
    99111        $this->_getAPIEndpoint($client);
    100112
    101113        $servers = $client->getServers();
    102         $server_hash = $servers[0]['server_hash']; //dangerous, need to adjust this
     114        if(isset($servers[$server_num])) {
     115            $server_hash = $servers[$server_num]['server_hash']; //dangerous, need to adjust this
     116        } else {
     117            $server_hash = $servers[0]['server_hash'];
     118        }
     119
    103120        $response = null;
    104121        $query_key = "";
     
    120137        }
    121138
    122 
    123139        $variables = array();
    124140
     
    127143        $variables['total_records'] = $this->total_records;
    128144        $variables['params'] = $params;
     145        $results = [];
    129146
    130147        if (is_array($response['results']) || is_object($response['results'])){
     
    139156
    140157               $variable = $this->_photo_array_builder($listing, $variable, $num_photos);
    141                $variables[] = $variable;
    142             }
    143         }
     158                $results[] = $variable;
     159            }
     160        }
     161
     162        $variables['results'] = $results;
    144163
    145164        return $variables;
  • rets-rabbit/trunk/rr_shortcodes.php

    r1437341 r1465597  
    1313        $cache = (isset($atts['cache']) ? $atts['cache'] : false);
    1414        $cache_duration = (isset($atts['cache_duration']) ? $atts['cache_duration'] : 4);
     15        $server_num = intval((isset($atts['server_num']) ? $atts['server_num'] : 0));
     16        $params = json_decode($atts['params'], true);
     17       
     18        foreach($params as $key => $param) {
     19            if(strpos($key, ":escapedash") > -1) {
     20                unset($params[$key]);
     21                $key = str_replace(":escapedash", "", $key);
    1522
    16         $params = json_decode($atts['params'], true);
     23                if (strpos($param, "|") > -1) {
     24                    $values = explode("|", $param);
     25                    $param_array = [];
     26                    foreach ($values as $value) {
     27                        $param_array[] = "'" . $value . "'";
     28                    }
     29                    $params[$key] = implode("|", $param_array);
     30                } else {
     31                    $params[$key] = "'" . $param . "'";
     32                }
     33            }
     34        }
     35
    1736
    1837        $rr_adapter = new rr_adapter();
    19         $results = $rr_adapter->run_search($params, $limit, $num_photos, $orderby, $sort_order, $cache, $cache_duration);
     38        $results = $rr_adapter->run_search($params, $limit, $num_photos, $server_num, $orderby, $sort_order, $cache, $cache_duration);
    2039        //$results = $response->results;
    2140        return $rr_adapter->parse($results, $template, $paginate, $limit);
     
    2948        $cache = (isset($atts['cache']) ? $atts['cache'] : false);
    3049        $cache_duration = (isset($atts['cache_duration']) ? $atts['cache_duration'] : 4);
     50        $server_num = intval((isset($atts['server_num']) ? $atts['server_num'] : 0));
     51
    3152
    3253        if(!$mls_id = get_query_var('mls_id'))
     
    3455
    3556        $rr_adapter = new rr_adapter();
    36         $result = $rr_adapter->get_listing($mls_id, $num_photos, $cache, $cache_duration);
     57        $result = $rr_adapter->get_listing($mls_id, $server_num, $num_photos, $cache, $cache_duration);
    3758        return $rr_adapter->parse_single($result, $template);
    3859    }
     
    87108        $cache = (isset($atts['cache']) ? $atts['cache'] : false);
    88109        $cache_duration = (isset($atts['cache_duration']) ? $atts['cache_duration'] : 4);
     110        $server_num = intval((isset($atts['server_num']) ? $atts['server_num'] : 0));
    89111
    90112        $key = (isset($_GET['key']) ? $_GET['key'] : '');
     
    103125        if($params != null && sizeof($params) > 0) {
    104126            $rr_adapter = new rr_adapter();
    105             $results = $rr_adapter->run_search($params, $limit, $num_photos, $orderby, $sort_order, $sort_option, $cache, $cache_duration);
     127            $results = $rr_adapter->run_search($params, $limit, $num_photos, $server_num, $orderby, $sort_order, $sort_option, $cache, $cache_duration);
    106128
    107129            return $rr_adapter->parse($results, $template, $paginate, $limit);
  • rets-rabbit/trunk/settings.php

    r1437341 r1465597  
    9999    $table_data = array();
    100100
    101     $types = $rr_adapter->metadata();
     101    $servers = $rr_adapter->get_servers();
     102    $x = 0;
     103    $filter_html = "";
     104    $filter_html .= "<h2>Select Servers</h2>";
     105    $filter_html .= "<form method='POST' action=''>";
     106    $filter_html .= "<label for='server'>Servers</label>";
     107    $filter_html .= "<select name='server' id='server'>";
     108
     109    $selected_server = (isset($_POST['server']) ? $_POST['server'] : '');
     110    foreach ($servers as $server) {
     111        $selected = "";
     112        if($selected_server == $server['server_hash']) {
     113            $selected = " selected ";
     114        }
     115        $filter_html .= "<option value='".$server['server_hash']."'".$selected.">".$x." - ".$server['name']."</option>";
     116        $x++;
     117    }
     118    $filter_html .= "</select>";
     119    $filter_html .= "<input type='submit' value='Submit'>";
     120    $filter_html .= "</form>";
     121
     122    echo($filter_html);
     123
     124    $types = $rr_adapter->metadata($selected_server);
    102125
    103126    if(sizeof($types) == 0)
Note: See TracChangeset for help on using the changeset viewer.