| Server IP : 172.67.178.83 / Your IP : 216.73.217.141 Web Server : Apache System : Linux hosting01.arsenalhost.com 4.18.0-425.13.1.lve.el8.x86_64 #1 SMP Mon Feb 27 15:23:24 EST 2023 x86_64 User : corbizre ( 1013) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/corbizre/officespace4lease.com/wp-content/plugins/officespace/ |
Upload File : |
<?php
/*
Plugin Name: Office Space
Plugin URI: http://wecandevelopit.com
Description: Office Space.
Version: 1.0
Author: Wecandevelopit
Author URI: http://wecandevelopit.com
*/
class Officespace
{
protected $stateList = array();
public function init()
{
add_action( 'init', array( $this, 'flush_rules' ) );
add_action('init', array( $this, 'register_css' ));
add_filter( 'query_vars', array( $this, 'query_vars' ) );
add_filter( 'the_content', array( $this, 'content_filter' ) );
add_filter( 'the_title', array( $this, 'title_filter' ));
add_filter('wp_nav_menu_items', array( $this, 'menu_filter' ), 10, 2);
add_action('wp_enqueue_scripts', array( $this, 'enqueue_style' ));
}
public function content_filter( $content )
{
$pagename = urldecode(get_query_var( 'pagename' ));
$state = urldecode(get_query_var( 'state' ));
$city = urldecode(get_query_var( 'city' ));
if ( $pagename === "officespace") {
$locations = $state;
$locations .= ($city)? " ".$city: null;
$locations = str_replace(' ', ", ", $locations);
$locations = str_replace("-", " ", $locations);
if($city){
$search = str_replace("-", " ", $city);
$search = str_replace('St Louis', 'St. Louis', $search);
$column = "location4_name";
}else{
$search = str_replace("-", " ", $state);
$column = "location2_name";
}
$content = str_replace('{$locations}', $locations, $content);
$content .= '[WPL kind="0" sf_advancedlocationtextsearch="'.$search.'" sf_advancedlocationcolumn="'.$column.'" wplorderby="p.mls_id" wplorder="DESC" wplcolumns="3"]';
}elseif ($pagename === ""){
$html = "<ul class='state-list'>";
foreach($this->stateList as $row) {
if ($row->location2_name) {
$state = str_replace(" ", "-", $row->location2_name);
$html .= '<li><a href="/officespace/'.$state.'" >'.$row->location2_name.'</a></li>';
}
}
$html .= "</ul>";
$content = str_replace('{$StateList}', $html, $content);
}
return $content;
}
public function title_filter( $title )
{
$pagename = urldecode(get_query_var( 'pagename' ));
$state = urldecode(get_query_var( 'state' ));
$city = urldecode(get_query_var( 'city' ));
if ( $pagename === "officespace" && $title == 'OfficeSpace') {
$title = ucfirst(str_replace("-", " ", $state));
$title .= ($city)? ", ".ucfirst(str_replace("-", " ", $city)) : null;
$title = "Find an Office in ".$title;
}elseif ($pagename === "properties" && $title == 'Properties'){
$wpl_qs = urldecode(get_query_var( 'wpl_qs' ));
$ex = explode('-',$wpl_qs);
if($ex['0'] && is_numeric($ex['0'])){
$cond = ' AND `id` = "'.(int)$ex['0'].'"';
$property = wpl_property::select_active_properties($cond, 'field_313');
if($property && isset($property[0]['field_313'])){
$title = $property[0]['field_313'];
$pos = strpos($title, 'Office');
if($pos){
$title = trim(substr($title, 0, $pos), ', ');
}
}
}
}
return $title;
}
public function menu_filter($items, $args)
{
if( $args->theme_location == 'main-menu' ){
$results = $this->stateList = $this->getStatesList();
$items .= '<li><a href="#">Search Property</a>';
$items .= '<ul class="sub-menu">';
foreach($results as $result)
{
if($result->location2_name){
$state = str_replace(" ", "-", $result->location2_name);
$items .= '<li class=""><a href="/officespace/'.$state.'">'.$result->location2_name.'</a>';
$cities = explode(',', $result->city);
if($cities){
$items .= '<ul class="sub-menu" style="left: 95%">';
foreach ($cities as $city){
$city1 = str_replace(".", "", $city);
$city1 = str_replace(" ", "-", $city1);
$items .= '<li class=""><a href="/officespace/'. $state.'/'.$city1.'">'.$city.'</a></li>';
}
$items .= "</ul>";
}
$items .= "</li>";
}
}
$items .= "</ul></li>";
}
return $items;
}
public function flush_rules()
{
$this->rewrite_rules();
flush_rewrite_rules();
}
public function rewrite_rules()
{
add_rewrite_rule(
'^officespace/(.*)/(.*)/?$',
'index.php?pagename=officespace&state=$matches[1]&city=$matches[2]',
'top' );
add_rewrite_rule(
'^officespace/(.*)/?$',
'index.php?pagename=officespace&state=$matches[1]',
'top' );
}
public function query_vars( $vars ) {
array_push( $vars, 'state', 'city');
return $vars;
}
public function register_css() {
wp_register_style( 'officespace_css', plugins_url('style.css',__FILE__ ) );
}
public function enqueue_style()
{
wp_enqueue_style( 'officespace_css' );
}
protected function getStatesList()
{
$query = "SELECT location2_name, GROUP_CONCAT(DISTINCT location4_name) as city
FROM `#__wpl_properties` GROUP BY location2_name";
return wpl_db::select($query);
}
}
add_action( 'plugins_loaded', array( new Officespace, 'init' ) );