HJI WP Membership Code Reference
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Hook Reference
  • Slipstream API Docs

Namespaces

  • hji
    • AgentRoster
      • controllers
      • models
      • utils
    • common
      • factories
      • interfaces
      • models
      • utils
    • construction
      • admin
        • controllers
        • models
      • core
      • front
        • controllers
      • interfaces
      • models
        • listings
        • subdivisions
      • views
    • geofarms
      • common
      • controllers
      • models
      • widgets
    • homevalue
      • controllers
      • core
        • abstracts
      • models
    • lifestylefinder
    • listingstoblog
      • controllers
    • membership
      • abstracts
      • controllers
      • entities
      • extension
        • abstracts
        • interfaces
      • factories
      • includes
      • interfaces
      • models
        • data
        • webservice
          • abstracts
          • actions
          • interfaces
      • observers
      • services
    • recentsales
      • controllers
      • tinymce
      • widgets
    • ResponsiveIDX
      • abstracts
      • adapters
      • controllers
      • core
        • abstracts
      • entities
      • models
      • services
      • tinymce
      • utils
      • widgets
    • schools
      • controllers
      • tinymce
      • widgets
    • users
      • abstracts
      • admin
        • controllers
        • models
      • controllers
      • core
        • abstracts
      • entities
      • models
      • utils
  • None
  • REL
    • controllers
    • Models
    • Taxonomies
    • Utils
      • Convert
    • widgets

Classes

  • hji\AgentRoster\AgentRoster
  • hji\AgentRoster\controllers\AgentRosterAdmin
  • hji\AgentRoster\controllers\Testimonials
  • hji\AgentRoster\models\TestimonialsModel
  • hji\AgentRoster\utils\ContactForm
  • hji\common\factories\mcePluginFactory
  • hji\common\factories\WidgetTrioFactory
  • hji\common\interfaces\AbstractSettingsModel
  • hji\common\interfaces\Shortcode
  • hji\common\interfaces\Widget
  • hji\common\interfaces\WidgetShortcode
  • hji\common\models\Alerts
  • hji\common\models\GForms
  • hji\common\models\JsVars
  • hji\common\models\mcePluginModel
  • hji\common\models\Notices
  • hji\common\models\PluginJsVars
  • hji\common\utils\APIClient
  • hji\common\utils\Cookies
  • hji\common\utils\GFHelper
  • hji\common\utils\HTTP
  • hji\common\utils\ipAddress
  • hji\common\utils\MetaBoxes
  • hji\common\utils\Modal
  • hji\common\utils\Paths
  • hji\common\utils\SiteInfo
  • hji\common\utils\String
  • hji\common\utils\Updater
  • hji\common\utils\Validator
  • hji\common\utils\View
  • hji\common\utils\Views
  • hji\common\utils\WPCache
  • hji\common\utils\WPHelper
  • hji\construction\admin\AdminController
  • hji\construction\admin\controllers\GeneralPageController
  • hji\construction\admin\models\GeneralPageModel
  • hji\construction\App
  • hji\construction\core\Component
  • hji\construction\core\Controller
  • hji\construction\core\DataModel
  • hji\construction\core\DataObjectPostView
  • hji\construction\core\Model
  • hji\construction\core\Paths
  • hji\construction\core\PostModel
  • hji\construction\core\WebService
  • hji\construction\core\Widget
  • hji\construction\front\controllers\ListingsController
  • hji\construction\front\controllers\SubdivisionsController
  • hji\construction\front\FrontController
  • hji\construction\models\Images
  • hji\construction\models\Labels
  • hji\construction\models\listings\ListingModel
  • hji\construction\models\listings\ListingsGetFilters
  • hji\construction\models\listings\ListingsModel
  • hji\construction\models\listings\ListingsSearchFilters
  • hji\construction\models\NCSearchWidget
  • hji\construction\models\NCSearchWidgetViewModel
  • hji\construction\models\Pagination
  • hji\construction\models\Settings
  • hji\construction\models\subdivisions\SubdivisionModel
  • hji\construction\models\subdivisions\SubdivisionsGetFilters
  • hji\construction\models\subdivisions\SubdivisionsGetOptions
  • hji\construction\models\subdivisions\SubdivisionsModel
  • hji\construction\models\subdivisions\SubdivisionsSearchFilters
  • hji\construction\models\subdivisions\SubdivisionsSearchOptions
  • hji\construction\NewConstruction
  • hji\construction\ServiceContainer
  • hji\construction\views\ListingsView
  • hji\construction\views\SubdivisionsView
  • hji\geofarms\common\ImageResize
  • hji\geofarms\common\RewriteRules
  • hji\geofarms\controllers\AreaCache
  • hji\geofarms\controllers\CMB
  • hji\geofarms\controllers\CPT
  • hji\geofarms\controllers\FrontEnd
  • hji\geofarms\controllers\Settings
  • hji\geofarms\controllers\Shortcodes
  • hji\geofarms\controllers\Slipstream
  • hji\geofarms\controllers\Taxonomy
  • hji\geofarms\controllers\TinyMCE
  • hji\geofarms\controllers\UpdateNeighborhoods
  • hji\geofarms\GeoFarms
  • hji\geofarms\models\CMB
  • hji\geofarms\models\CPT
  • hji\geofarms\models\Settings
  • hji\geofarms\models\Slipstream
  • hji\geofarms\models\Taxonomy
  • hji\geofarms\models\TinyMCE
  • hji\geofarms\widgets\Display
  • hji\geofarms\widgets\Map
  • hji\homevalue\controllers\HomeValueTinyMCE
  • hji\homevalue\controllers\HomeValueWidget
  • hji\homevalue\controllers\Settings
  • hji\homevalue\controllers\Shortcodes
  • hji\homevalue\core\abstracts\Component
  • hji\homevalue\core\Controller
  • hji\homevalue\core\Model
  • hji\homevalue\HomeValue
  • hji\homevalue\models\Settings
  • hji\lifestylefinder\LifestyleFinder
  • hji\listingstoblog\controllers\ImportListings
  • hji\listingstoblog\controllers\Settings
  • hji\listingstoblog\ListingsToBlog
  • hji\membership\abstracts\Component
  • hji\membership\abstracts\Controller
  • hji\membership\abstracts\Model
  • hji\membership\controllers\APIClient
  • hji\membership\controllers\CommonScripts
  • hji\membership\controllers\Dependency
  • hji\membership\controllers\DependencyResolver
  • hji\membership\controllers\Dispatcher
  • hji\membership\controllers\Downloads
  • hji\membership\controllers\GForms
  • hji\membership\controllers\ProductManager
  • hji\membership\controllers\ProductRegistrar
  • hji\membership\controllers\RegistryEntry
  • hji\membership\controllers\RequireJs
  • hji\membership\controllers\Settings
  • hji\membership\controllers\UpdateManager
  • hji\membership\entities\Event
  • hji\membership\entities\UserActionEvent
  • hji\membership\extension\abstracts\Component
  • hji\membership\factories\ProductFactory
  • hji\membership\includes\CustomerInfoSynchronizer
  • hji\membership\interfaces\Product
  • hji\membership\Membership
  • hji\membership\models\APIClientModel
  • hji\membership\models\Customer
  • hji\membership\models\data\Address
  • hji\membership\models\data\Image
  • hji\membership\models\data\Images
  • hji\membership\models\data\Paging
  • hji\membership\models\data\Sorting
  • hji\membership\models\DependencyEntity
  • hji\membership\models\DependencyModel
  • hji\membership\models\PluginEntity
  • hji\membership\models\ProductDependencies
  • hji\membership\models\Settings
  • hji\membership\models\ThemeEntity
  • hji\membership\models\UserActionLogger
  • hji\membership\models\UserSession
  • hji\membership\models\webservice\abstracts\QueryProperties
  • hji\membership\models\webservice\abstracts\WebService
  • hji\membership\models\webservice\abstracts\WebServiceFilters
  • hji\membership\models\webservice\actions\ActionsSearchFilters
  • hji\membership\models\webservice\actions\ActionsWebService
  • hji\membership\models\webservice\WebServiceOptions
  • hji\membership\models\WpCatalog
  • hji\membership\observers\EventDispatcher
  • hji\membership\observers\EventLogger
  • hji\membership\services\CPT_Router
  • hji\membership\services\DependencyInjector
  • hji\membership\services\DependencyInjectorInterface
  • hji\membership\services\Request
  • hji\membership\services\Route
  • hji\membership\services\Router
  • hji\membership\services\ServiceContainer
  • hji\membership\services\SocialGraph
  • hji\recentsales\controllers\Shortcodes
  • hji\recentsales\RecentSales
  • hji\recentsales\tinymce\RecentSales
  • hji\recentsales\widgets\RecentSales
  • hji\ResponsiveIDX\abstracts\FilterSchema
  • hji\ResponsiveIDX\adapters\IdxAdapter
  • hji\ResponsiveIDX\adapters\LegalAdapter
  • hji\ResponsiveIDX\adapters\ListingAdapter
  • hji\ResponsiveIDX\controllers\BaseController
  • hji\ResponsiveIDX\controllers\IdxApp
  • hji\ResponsiveIDX\controllers\Pagination
  • hji\ResponsiveIDX\controllers\RecentlyViewed
  • hji\ResponsiveIDX\controllers\RegistrationForm
  • hji\ResponsiveIDX\controllers\Settings
  • hji\ResponsiveIDX\controllers\Upgrader
  • hji\ResponsiveIDX\core\abstracts\Component
  • hji\ResponsiveIDX\core\Controller
  • hji\ResponsiveIDX\core\Model
  • hji\ResponsiveIDX\entities\ComplianceRule
  • hji\ResponsiveIDX\entities\ListingEntity
  • hji\ResponsiveIDX\models\ComplianceModel
  • hji\ResponsiveIDX\models\ComplianceViewModel
  • hji\ResponsiveIDX\models\FieldLabels
  • hji\ResponsiveIDX\models\HashMap
  • hji\ResponsiveIDX\models\IdxSearchModel
  • hji\ResponsiveIDX\models\MarketMetadata
  • hji\ResponsiveIDX\models\PaginationViewModel
  • hji\ResponsiveIDX\models\QuickSearchViewModel
  • hji\ResponsiveIDX\models\SearchFilters
  • hji\ResponsiveIDX\models\SearchParams
  • hji\ResponsiveIDX\models\SearchResultsViewModel
  • hji\ResponsiveIDX\models\ShortcodesModel
  • hji\ResponsiveIDX\models\SpatialMatchModel
  • hji\ResponsiveIDX\ResponsiveIDX
  • hji\ResponsiveIDX\services\ServiceContainer
  • hji\ResponsiveIDX\tinymce\FeaturedListings
  • hji\ResponsiveIDX\utils\ArrayFormat
  • hji\ResponsiveIDX\utils\PluginDependency
  • hji\ResponsiveIDX\utils\StringFormat
  • hji\ResponsiveIDX\utils\View
  • hji\ResponsiveIDX\widgets\FeaturedListings_TinyMCE
  • hji\ResponsiveIDX\widgets\FeaturedListings_Widget
  • hji\ResponsiveIDX\widgets\QuickSearch_Widget
  • hji\schools\controllers\Shortcodes
  • hji\schools\Schools
  • hji\schools\tinymce\Schools
  • hji\schools\widgets\Schools
  • hji\users\abstracts\AdminPageModel
  • hji\users\abstracts\UserAdminTable
  • hji\users\admin\AdminController
  • hji\users\admin\BaseController
  • hji\users\admin\controllers\ActionsPageController
  • hji\users\admin\controllers\UsersPageController
  • hji\users\admin\models\ActionsPageModel
  • hji\users\admin\models\UsersPageModel
  • hji\users\controllers\GravityForms
  • hji\users\controllers\GravityFormsAdmin
  • hji\users\controllers\RegistrationPrompter
  • hji\users\controllers\Settings
  • hji\users\controllers\SocialAuth
  • hji\users\controllers\User
  • hji\users\controllers\UserPanel
  • hji\users\core\abstracts\Component
  • hji\users\core\Controller
  • hji\users\core\Model
  • hji\users\entities\GFEntry
  • hji\users\entities\User
  • hji\users\entities\UserProfile
  • hji\users\models\ActionsSearchFilters
  • hji\users\models\ActionsWebServiceOptions
  • hji\users\models\FavoritesViewModel
  • hji\users\models\FrontEndNotices
  • hji\users\models\RegistrationNotificationViewModel
  • hji\users\models\Request
  • hji\users\models\Settings
  • hji\users\models\SettingsTab
  • hji\users\models\User
  • hji\users\models\UserActionsModel
  • hji\users\models\UserFactory
  • hji\users\models\UsersSearchModel
  • hji\users\Users
  • hji\users\utils\GravityFormsHelper
  • hji\users\utils\UserActionsTable
  • hji\users\utils\UserAuth
  • hji\users\utils\UserFavoritesTable
  • hji\users\utils\UserFormEntriesTable
  • hji\users\utils\UserListTable
  • hji\users\utils\UserSearchesTable
  • hji\users\utils\UserSessionsTable
  • REL\controllers\Admin
  • REL\controllers\FSBO
  • REL\controllers\PocketListings
  • REL\controllers\rIDXImport
  • REL\Models\ListingViewModel
  • REL\Models\rIDXImport
  • REL\Models\Upgrades
  • REL\RealEstateListings
  • REL\Taxonomies\CustomTaxonomies
  • REL\Utils\Convert\ListingConverter
  • REL\widgets\PocketListingsSearchWidget
  • REL\widgets\PocketListingsWidget
  • SM_API_Client

Interfaces

  • hji\construction\interfaces\IPost
  • hji\membership\extension\interfaces\ExtensionInterface
  • hji\membership\interfaces\CRUD
  • hji\membership\interfaces\Dispatchable
  • hji\membership\interfaces\EventDispatcherInterface
  • hji\membership\interfaces\Loggable
  • hji\membership\models\webservice\interfaces\IGettable
  • hji\membership\models\webservice\interfaces\ISearchable

Functions

  • __admin_redirect
  • get_pocket_listing
  • hji\membership\controllers\__inject_plugin_table
  • hji\membership\controllers\__inject_theme_table
  • hji_user_favorite_toggle
  • hjigf_display
  • hjigf_display_map
  • hjigf_get_community_feature
  • hjigf_get_post_thumbnail
  • hjigf_has_area_map
  • ridx_get_listing
  • ridx_is_results_page
  • ridx_is_single
  • ridx_is_single_print
  • table_hjpl_cache
   1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99  100  101  102  103  104  105  106  107  108  109  110  111  112  113  114  115  116  117  118  119  120  121  122  123  124  125  126  127  128  129  130  131  132  133  134  135  136  137  138  139  140  141  142  143  144  145  146  147  148  149  150  151  152  153  154  155  156  157  158  159  160  161  162  163  164  165  166  167  168  169  170  171  172  173  174  175  176  177  178  179  180  181  182  183  184  185  186  187  188  189  190  191  192  193  194  195  196  197  198  199  200  201  202  203  204  205  206  207  208  209  210  211  212  213  214  215  216  217  218  219  220  221  222  223  224  225  226  227  228  229  230  231  232  233  234  235  236  237  238  239  240  241  242  243  244  245  246  247  248  249  250  251  252  253  254  255  256  257  258  259  260  261  262  263  264  265  266  267  268  269  270  271  272  273  274  275  276  277  278  279  280  281  282  283  284  285  286  287  288  289  290  291  292  293  294  295  296  297  298  299  300  301  302  303  304  305  306  307  308  309  310  311  312  313  314  315  316  317  318  319  320  321  322  323  324  325  326  327  328  329  330  331  332  333  334  335  336  337  338  339  340  341  342  343  344  345  346  347  348  349  350  351  352  353  354  355  356  357  358  359  360  361  362  363  364  365  366  367  368  369  370  371  372  373  374  375  376  377  378  379  380  381  382  383  384  385  386  387  388  389  390  391  392  393  394  395  396  397  398  399  400  401  402  403  404  405  406  407  408  409  410  411  412  413  414  415  416  417  418  419  420  421  422  423  424  425  426  427  428  429  430  431  432  433  434  435  436  437  438  439  440  441  442  443  444  445  446  447  448  449  450  451  452  453  454  455  456  457  458  459  460  461  462  463  464  465  466  467  468  469  470  471  472  473  474  475  476  477  478  479  480  481  482  483  484  485  486  487  488  489  490  491  492  493  494  495  496  497  498  499  500  501  502  503  504  505  506  507  508  509  510  511  512  513  514  515  516  517  518  519  520  521  522  523  524  525  526  527  528  529  530  531  532  533  534  535  536  537  538  539  540  541  542  543  544  545  546  547  548  549  550  551  552  553  554  555  556  557  558  559  560  561  562  563  564  565  566  567  568  569  570  571  572  573  574  575  576  577  578  579  580  581  582  583  584  585  586  587  588  589  590  591  592  593  594  595  596  597  598  599  600  601  602  603  604  605  606  607  608  609  610  611  612  613  614  615  616  617  618  619  620  621  622  623  624  625  626  627  628  629  630  631  632  633  634  635  636  637  638  639  640  641  642  643  644  645  646  647  648  649  650  651  652  653  654  655  656  657  658  659  660  661  662  663  664  665  666  667  668  669  670  671  672  673  674  675  676  677  678  679  680  681  682  683  684  685  686  687  688  689  690  691  692  693  694  695  696  697  698  699  700  701  702  703  704  705  706  707  708  709  710  711  712  713  714  715  716  717  718  719  720  721  722  723  724  725  726  727  728  729  730  731  732  733  734  735  736  737  738  739  740  741  742  743  744  745  746  747  748  749  750  751  752  753  754  755  756  757  758  759  760  761  762  763  764  765  766  767  768  769  770  771  772  773  774  775  776  777  778  779  780  781  782  783  784  785  786  787  788  789  790  791  792  793  794  795  796  797  798  799  800  801  802  803  804  805  806  807  808  809  810  811  812  813  814  815  816  817  818  819  820  821  822  823  824  825  826  827  828  829  830  831  832  833  834  835  836  837  838  839  840  841  842  843  844  845  846  847  848  849  850  851  852  853  854  855  856  857  858  859  860  861  862  863  864  865  866  867  868  869  870  871  872  873  874  875  876  877  878  879  880  881  882  883  884  885  886  887  888  889  890  891  892  893  894  895  896  897  898  899  900  901  902  903  904  905  906  907  908  909  910  911  912  913  914  915  916  917  918  919  920  921  922  923  924  925  926  927  928  929  930  931  932  933  934  935  936  937  938  939  940  941  942  943  944  945  946  947  948  949  950  951  952  953  954  955  956  957  958  959  960  961  962  963  964  965  966  967  968  969  970  971  972  973  974  975  976  977  978  979  980  981  982  983  984  985  986  987  988  989  990  991  992  993  994  995  996  997  998  999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 
<?php
namespace hji\ResponsiveIDX\controllers
{


    use hji\common\utils\WPHelper;
    use hji\membership\Membership;
    use hji\ResponsiveIDX\models\FieldLabels;
    use \hji\ResponsiveIDX\ResponsiveIDX;
    use \hji\ResponsiveIDX\adapters\IdxAdapter;
    use \hji\ResponsiveIDX\models\ShortcodesModel;
    use \hji\ResponsiveIDX\models\SearchParams;
    use \hji\ResponsiveIDX\models\IdxSearchModel;
    use \hji\ResponsiveIDX\models\SearchResultsViewModel;
    use \hji\ResponsiveIDX\models\SpatialMatchModel;
    use \hji\ResponsiveIDX\utils\View;


    class IdxApp extends BaseController
    {
        // IdxApp object instance

        private static $instance;

        // Settings Controller

        public $settingsController;

        // IDX Search Model

        public $idxSearchModel;

        // Submitted IDX Search Parameters

        public $searchParams;

        // Shortcodes Model

        public $shortcodesModel;

        // API Client

        private $api;

        // License Keys

        private $license_keys     = false;

        //array of disclaimers from scrolling widget
        //rendered in the footer
        private $footerDisclaimers = array();

        // Array of already rendered disclaimers to avoid duplication.

        private $renderedDisclaimers = array();

        /**
         * Set if current page is listing details
         */
        public $is_listing_details_page = false;

        /**
         * Set if current page is a listing print page
         */
        public $is_listing_print_page = false;


        // JavaScript variables that will be set in HJI.rIDX
        // TODO: naming convention conflict with JsVars object used in the constructor

        static $jsVars = false;


        public function __construct()
        {
            parent::__construct();

            // Settings Object

            $this->settingsController = Settings::getInstance();

            // JsVars

            $this->JsVars = new \hji\common\models\PluginJsVars('rIDX');

            if ($this->membership->isLicensed())
            {
                $this->init();
            }

            // instantiate Pagination Logger

            \hji\ResponsiveIDX\models\PaginationViewModel::instance();


            // instantiate recently viewed tracker
            // Coming in version 3.0

            $recentlyViewed = RecentlyViewed::getInstance();
            $recentlyViewed->registerActions();

            // instantiate Registration Form only if HJI Users is not loaded
            // otherwise Users plugin will extend the Registration

            if (!class_exists("\\hji\\users\\Users"))
            {
                new RegistrationForm();
            }
        }


        /**
         * Returns current IdxApp instance.
         *
         * @return IdxApp
         */
        static function getInstance()
        {
            if (!self::$instance)
            {
                self::$instance = new IdxApp();
            }

            return self::$instance;
        }


        function setSearchParams($rawParams)
        {
            $this->searchParams = $rawParams;
        }


        function getSearchParams()
        {
            return $this->searchParams;
        }


        function init()
        {
            $this->api = Membership::getInstance()->apiController->api;

            // if set DEVmode via wp-config

            if (defined('HJI_DEV') && HJI_DEV === true)
            {
                $this->api->SetDeveloperMode(true);
            }

            // Starts application listeners only with valid license keys

            $this->idxSearchModel       = new IdxSearchModel();

            $this->registerActions();
        }


        /**
         * Front-End Actions & Filters => only if license keys are valid
         */
        function registerActions()
        {
            add_action('admin_enqueue_scripts', array($this, 'loadAdminScripts'));
            add_action('admin_print_footer_scripts', array($this, 'adminFooterScripts'));

            // Query related actions

            add_action('pre_get_posts', array($this, 'preactivate'));
            add_filter('posts_request', array($this, 'clearQuery'));
            add_action('parse_request', array($this, 'preprocessQueryParams'));

            // Permalink filter to return correct permalink

            add_filter('post_link', array($this, 'listingPermalink'), 10, 3);

            // Render page content

            add_filter('the_posts', array($this, 'renderListingDetailsPage'));
            add_action('the_content', array($this, 'renderSearchResultsPage'), 99);
            add_action('template_redirect', array($this, 'renderListingDetailsPrintPage'), 1 );

            // Register shortcodes

            $this->shortcodesModel = new ShortcodesModel($this, $this->settingsController, $this->idxSearchModel);

            // Apply Spatial Match widget substitutions

            new SpatialMatchModel($this, $this->settingsController, $this->idxSearchModel);

            // Pre-load custom GMap icon if exists

            add_action('wp_head', array($this, 'loadCustomGmapIcon') );

            // Add path to Membership requireJS

            $requireJS = $this->membership->requireJs;
            $requireJS->addPath('hji-ridx/main', ResponsiveIDX::$scripts . '/main');
            $requireJS->addPath('hji-ridx', ResponsiveIDX::$scripts . '/components');
        }


        function AuthenticateIDXAPI($force = false)
        {
            //this is a duplicate condition, but we can't delete it
            //because of the save_valid_license_keys() method.
            if ($force
                || @!$_SESSION['hjapicookie']
                || (isset($_GET['hjauth'])
                    && $_GET['hjauth'] == 'force' ))
            {
                $result = $this->membership->apiController->authenticate(true);
            }

        }


        /**
         * Sets current license key
         * @param string $license_key - Home Junction License Key
         */
        function set_license_key($license_key)
        {
            if( !is_array($license_key) )
            {
                $this->license_keys = $license_key;
            }
            else
            {
                $license_keys = explode("\n", $license_key);
                $license_keys = array_map("trim", $license_keys);
                $this->license_keys = $license_keys[0];
            }

            $this->api->SetLicenseKey( $this->license_keys );
        }


        function loadAdminScripts()
        {
            wp_enqueue_script('hji-ridx-admin-widgets', ResponsiveIDX::$scripts . '/ridx-admin-widgets.js', array('jquery'), false, true);
            wp_enqueue_style('hji-ridx-admin', ResponsiveIDX::$styles . '/ridx-admin.min.css');
        }


        function adminFooterScripts()
        {
//            $this->loadJsVars();

            // TODO: this should go into respective widget controller
            if (stristr($_SERVER['REQUEST_URI'], 'widgets.php') || stristr($_SERVER['REQUEST_URI'], 'customize.php'))
            {
                ?>
                <script type="text/javascript">
                    jQuery(document).ready(function(){
                        jQuery('.featured-listings-filters').each(function(){
                            jQuery(this).ManageFeaturedPropertiesWidgets();
                        });
                    });
                </script>
            <?php
            }

            if (stristr($_SERVER['REQUEST_URI'], 'hji_ridx_tinymce'))
            {
                ?>
                <script type="text/javascript">
                    jQuery(document).ready(function(){
                        jQuery('.featured-listings-filters').ManageFeaturedPropertiesWidgets({tinymce: true, ajaxurl: '<?php echo admin_url('admin-ajax.php')?>'});
                    });
                </script>
            <?php
            }
        }

        /**
         * Loads Styles and JS Scripts
         */
        function loadScripts()
        {
            $style          = ResponsiveIDX::$styles . '/responsive-idx.min.css';

            //force jQuery UI 1.8.23 in WP 3.4 because default one 1.8.2
            //causes issues with slider listings not being aligned
            global $wp_version;

            if ((version_compare($wp_version, '3.4.0') >= 0) && version_compare($wp_version, '3.5.0') < 0)
            {
                $jquery_ui = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js';
                wp_deregister_script('jquery-ui-core');
                wp_register_script('jquery-ui-core', $jquery_ui, array('jquery'));
            }
            else
            {
//                wp_enqueue_script( 'jquery-effects-core');
            }

            wp_enqueue_script('jquery');
            wp_register_style('ridx-style', $style);
            wp_enqueue_style('font-awesome');

            if (!current_theme_supports('hji-twitter-bootstrap'))
            {
                wp_enqueue_style('ridx-style');
            }

            if (get_query_var('idx-print'))
            {
                wp_enqueue_style('idxprint', ResponsiveIDX::$styles . '/responsive-idx-print.min.css', array(), false, 'all');
            }

            // Load custom color palette

            add_action('wp_head', array($this, 'renderCustomColorsStylesheet') );

        }


        static function setJsVar($key, $value)
        {
//            self::$jsVars[$key] = $value;
            IdxApp::getInstance()->JsVars->setVar($key, $value);
        }


        static function getJsVars()
        {
            return self::$jsVars;
        }


        /**
         * Creates rIDXdata JavaScript object with rIDX related data
         * and loads it on the page before DOM is ready.
         *
         * Use IdxApp::setJsVar($key, $value) to add additional data.
         */
        function loadJsVars()
        {
            $vars = apply_filters('ridx-js-vars', self::getJsVars());

            $vars = ($vars) ? $vars : new \stdClass;

            if ($vars)
            {
                $script = "rIDXdata = " . json_encode($vars) . ';';

                echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5
                echo "/* <![CDATA[ */\n";
                echo "$script\n";
                echo "/* ]]> */\n";
                echo "</script>\n";
            }
        }


        /**
         * Renders JS code on the page to declare custom GMap icon.
         */
        function loadCustomGmapIcon()
        {
            // Get custom icon option value

            $opt = get_option(\hji\ResponsiveIDX\controllers\Settings::$color_settings_key);

            $marker = ResponsiveIDX::$url . '/resources/images/marker.png';

            if(isset($opt['gmap-marker']) && !empty($opt['gmap-marker']))
            {
                $marker = $opt['gmap-marker'];
            }

            echo '<script>var gmapicon = "' . $marker . '";</script>' . "\n";
        }


        /**
         * Is current page a listing details page
         * @return boolean
         */
        function is_listing_details_page()
        {
            return (bool) $this->is_listing_details_page;
        }


        /**
         * Is current page a listing details page
         * @return boolean
         */
        function is_listing_print_page()
        {
            return (bool) $this->is_listing_print_page;
        }


        function clearQuery($query)
        {
            global $wp_query;

            if (isset($wp_query->query["idx-action"]) && ('details' == $wp_query->query["idx-action"]))
            {
                    $this->is_listing = true;
            }

            if (!is_array($wp_query->query) || !isset($wp_query->query["idx-action"]))
            {
                return $query;
            }

            return "";
        }


        /**
         * this is a roundabout way to make sure that
         * any other plugin / widget / etc that uses the WP_Query object doesn't get our IDX data
         * in their query. since we don't actually get the query itself
         * in the "the_posts" filter, we have to step around the issue by
         * checking it BEFORE it gets to the the_posts filter. later, i
         * n the the_posts filter, we restore the previous state of things.
         */
        function preactivate($q)
        {
            global $wp_query;

            if (!$wp_query || !is_array($wp_query->query) || !is_array($q->query) )
                return;

            //enqueue scripts
            add_action('wp_enqueue_scripts', array($this, 'loadScripts'), 99 );

            if ( isset($wp_query->query["idx-action"]) )
            {
                if ( !isset($q->query["idx-action"]) )
                {
                    $wp_query->query["idx-action-swap"] = $wp_query->query["idx-action"];
                    unset( $wp_query->query["idx-action"] );
                }
                else
                {

                    global $wp_version;
                    //caller_get_posts deprecated since v.3.1
                    if ( (version_compare($wp_version, '3.1.0') >= 0) )
                    {
                        $q->query_vars["ignore_sticky_posts"] = true;
                    }
                    else
                    {
                        $q->query_vars["caller_get_posts"] = true;
                    }
                }
            }
        }


        /**
         * Returns correct listing URL when get_permalink() is being called on listing details pages.
         * page_link filter implementation
         *
         * @since 3.0
         *
         * @param $permalink
         * @param $post
         * @param $leavename
         * @return mixed
         */
        function listingPermalink($permalink, $post, $leavename)
        {
            if ($post->listing)
            {
                if ($listingUrl = $post->listing->getPageUrl())
                {
                    $permalink = $listingUrl;
                }

            }

            return $permalink;
        }


        /**
         * Removes idx search widget shortcode from content
         * to avoid duplication on a search results page.
         * Bad logic...
         *
         * @param $content
         * @return mixed
         */
        function removeIdxSearchWidgetSortcode($content)
        {
            $pattern[] = '/\[idx_search_widget(.*)+\]/';
            $pattern[] = '/\[listings(.*)+\]/';
            $content = preg_replace( $pattern, '', $content );

            return $content;
        }


        /**
         * If search is initiated
         * pre-process parameters
         * and trigger next action.
         * This should be before any content is rendered (before headers sent).
         */
        function preprocessQueryParams()
        {
            // Was search initiated by a human

            if (!isset($_GET['idxs_do']))
            {
                return;
            }

            // Remove wpautop => <br/> tags early from the content

            remove_filter('the_content', 'wpautop');

            // Since search page has it's own search widget
            // strip any search widget shortcodes that may have been placed
            // by user on the search page.
            // Priority has to be before 11, since all sortcodes are being parsed at 11 by WP
            if (stristr($_SERVER['REQUEST_URI'], $this->settingsController->getSearchPageSlug()))
            {
                add_filter('the_content', array($this, 'removeIdxSearchWidgetSortcode'), 1);
            }

            $this->setSearchParams($_GET);

            $params = $this->getSearchParams();
            $trackedData = array();

            foreach ($params as $k => $v)
            {
                if (empty($v) || ($k == 'polygon'))
                    continue;

                $label = FieldLabels::getLabel($k);
                $label = ($label) ? $label : $k;

                if ($label == 'polynames')
                {
                    $label = 'Location';
                }

                $trackedData[$label] = $v;
            }

            if ($trackedData)
            {
                $membershipServices = $this->membershipServices();
                $membershipServices->getDispatcher()->dispatchUserAction('Performed IDX Search', $trackedData);
            }

            $this->idxSearchModel->SetSearchParams($this->getSearchParams());
        }


        /**
         * Renders search results page via the_content filter.
         *
         * @param $content
         * @return bool|string
         */
        function renderSearchResultsPage($content)
        {
            global $wp_query, $wp_rewrite;

            $params = $this->getSearchParams();

            if (!is_page($this->settingsController->getSearchPageSlug()))
            {
                return $content;
            }

            if (isset($_GET['idxs_do']))
            {
                // Do not append search results to the existing content,
                // because this is not a shortcode and we dedicated a whole page
                // to search results.

                $content = $this->renderSearchResultsView($this->idxSearchModel);
            }
            else if (isset($_GET['idxerr']))
            {
                switch ( $_GET['idxerr'] )
                {
                    case '404':
                        $vars['listing_id'] = (isset($_GET['listing_id'])) ? "(MLS#: {$_GET['listing_id']}) " : '';
                        $vars['mls'] = (isset($_GET['mls']) && !empty($_GET['mls'])) ? $_GET['mls'] : false;
                        $content = $this->view->render('listing-404', $vars);
                    break;
                }
            }
            return $content;
        }


        /**
         * Renders search results view
         *
         * @param \hji\ResponsiveIDX\models\IdxSearchModel $idxSearchModel
         * @internal param null $params
         * @return bool|string
         */
        function renderSearchResultsView(IdxSearchModel $idxSearchModel)
        {
            $content = $this->getIdxContentView($idxSearchModel);

            return $content;
        }


        /**
         * Returns IDX content view from whatever action was set:
         * search results; listing details, scrolling listings etc.
         *
         * @param \hji\ResponsiveIDX\models\IdxSearchModel $idxSearchModel
         * @return bool|string
         */
        public function getIdxContentView(IdxSearchModel $idxSearchModel)
        {
            $searchParams = $idxSearchModel->GetSearchParams();
            $params       = $searchParams->original;

            // Terminate the app with error message
            // is something within the searchModel

            if ($searchParams->error)
            {
                $vars = array(
                    'error' => array(
                        'code'    => 'WP04328',
                        'message' => $searchParams->error
                    )
                );
                return $this->view->render('error-message', $vars);
            }

            // Terminate if no action has been passed

            if (!isset($params['action']))
            {
                return;
            }

            // Construct View models for the current action

            if ('searchListings' == $params['action']
                || 'GetPromotedListings' == $params['action']
                || 'searchSales' == $params['action'])
            {
                $searchResultsViewModel = new SearchResultsViewModel($idxSearchModel, $this->view);

                if ('searchListings' == $params['action'])
                {
                    $this->view = $searchResultsViewModel->getSearchResultsView();
                    $template   = 'listing-results';
                }
                else if ('searchSales' == $params['action'])
                {
                    $this->view = $searchResultsViewModel->getSearchSalesResultsView();
                    $template   = 'sales-results';
                }
                else
                {
                    $this->view = $searchResultsViewModel->getPromotedListingsView();
                    $template   = 'listing-results';
                }

            }
            else if ('GetListingsWidget' == $params['action'])
            {
                $searchResultsViewModel = new SearchResultsViewModel($idxSearchModel, $this->view);

                $this->view = $searchResultsViewModel->getSliderView();
                $this->view->set('button_listing_details', $this->settingsController->getOption('button_listing_details'));

                $template   = 'listing-results-widget';
            }

            // Pass data to the view

            if (isset($template))
            {
                $this->view->set('searchParams', $idxSearchModel->GetSearchParams());

                return $this->view->render($template);
            }
        }


        /**
         * Renders Listing Details page view
         *
         * @param $posts
         * @return array|bool
         */
        function renderListingDetailsPage($posts)
        {
            global $wp_query;

            // see comment about PreActivate
            if (is_array($wp_query->query) && isset($wp_query->query['idx-action-swap']))
            {
                $wp_query->query['idx-action'] = $wp_query->query['idx-action-swap'];
                unset($wp_query->query['idx-action-swap']);
                return $posts;
            }

            // Check if this is a listing details page

            if (!isset($wp_query->query['idx-action']) || 'details' != $wp_query->query['idx-action'])
            {
                return $posts;
            }

            // Set current page type

            $this->is_listing_details_page = true;

            // Remove auto-paragraphs that WP injects into the post object content.

            remove_filter('the_content', 'wpautop');

            // Get search parameters from the $wp_query object

            $params = array();

            if (isset($wp_query->query['idx-MlsID']))
            {
                $params['market'] = $wp_query->query['idx-MlsID'];
            }
            else
            {
                return false;
            }

            if (isset($wp_query->query['idx-MlsNumber']))
            {
                $params['id'] = $wp_query->query['idx-MlsNumber'];
            }

            $membershipServices = $this->membershipServices();
            $membershipServices->getDispatcher()->dispatchUserAction('Viewed Listing Details', array('Listing ID' => $params['id'], 'Market' => $params['market']));

            // Set listing details URL parameter
            // to indicate that this was user initiated listing details view
            $params['referrer'] = WPHelper::getCurrentUrl();

            // Build search model

            $idxSearchModel = new IdxSearchModel();

            $idxSearchModel->SetSearchParams($params);

            // Build results view model

            $searchResultsViewModel = new SearchResultsViewModel($idxSearchModel, $this->view);

            $detailsView = $searchResultsViewModel->getListingDetailsView();

            // Check if listing exists - redirect to 404 otherwise

            // Retrieve listing object from the view model

            $listing = $detailsView->get('listing');

            // Redirect if listing no longer exists

            if (!$listing)
            {
                wp_redirect(site_url(). '/' . $this->settingsController->getSearchPageSlug() . '?idxerr=404&listing_id=' . $wp_query->query['idx-MlsNumber'] . '&mls=' . $wp_query->query['idx-MlsID'], 301);

                exit;
            }

            // Check if listing's URL slug is fully qualified

            $query_slug = "mls-{$listing->id}-" . @$wp_query->query_vars['idx-AddressSlug'];

            $listing_slug_parts = explode('/', trim($listing->getPageUrl(), '/'));
            $listing_slug = array_pop($listing_slug_parts);

            if ($listing_slug != $query_slug)
            {
                // Redirect to fully qualified URL

                wp_redirect($listing->getPageUrl(), 301);
                exit;
            }

            // Add listing object to WP Query, so it can be easily reached.
            $content = $detailsView->render('listing-details', false);

            if ($listing->address)
            {
                $title = apply_filters(
                    'hji_listing_page_title',
                    "MLS# {$listing->id} - {$listing->address}", $listing);
            }
            else
            {
                $title = apply_filters(
                    'hji_listing_page_title',
                    "Property Listing MLS# {$listing->id}", $listing);
            }

            $slug = $this->settingsController->getOption('listings_slug') . '/' . $wp_query->query['idx-AddressSlug'] . '/';

            return $this->getPostObj($listing, $title, $content, $slug);
        }


        /**
         * Generating a fake post object for listing details page
         * this object is exactly the same as WP native post object
         * created during the_posts filter
         *
         * @param      $listing     listing object
         * @param      $title       page title
         * @param      $content     page content
         * @param      $slug        page slug
         * @return array
         */
        function getPostObj($listing, $title, $content, $slug)
        {
            global $wp_query;

            $wp_query->found_posts = 0;
            $wp_query->max_num_pages = 0;
            $wp_query->is_page = 1;
            $wp_query->is_home = null;
            $wp_query->is_singular = 1;

            $description = NULL;

            set_query_var("name", "idx-listing");
            set_query_var("pagename", "idx-listing");

            $searchResultsPageId = $this->settingsController->getOption('search_results_page_id');

            $listingDate = ($listing->listingDate) ?
                $listing->listingDate : strtotime('-' . $listing->daysOnHJI . ' days');
            $modifiedDate = ($listing->modifiedDate) ? $listing->modifiedDate : $listingDate;

            $posts = array((object) array(
                "ID"                => time(),
                "comment_count"     => 0,
                "comment_status"    => "closed",
                "ping_status"       => "closed",
                "post_author"       => 1,
                "post_content"      => $content,
                "post_date"         => date("c", $listingDate),
                "post_date_gmt"     => gmdate("c", $listingDate),
                "post_modified"     => date("c", $modifiedDate),
                "post_modified_gmt" => gmdate("c", $modifiedDate),
                "post_excerpt"      => $description,
                "listing"           => $listing,
                "post_name"         => $slug,
                "post_parent"       => ($searchResultsPageId) ? $searchResultsPageId : '',
                "post_status"       => "publish",
                "post_title"        => $title,
                "post_type"         => "post",
            ));

            do_action('hjpl_get_post', $posts);

            return $posts;
        }


        /**
         * Contact Info hCard
         * http://microformats.org/wiki/hCard
         *
         * @return bool|string
         */
        static function hCard()
        {
            $output = false;

            if ($contact_info = get_option(Settings::$contact_info_settings_key))
            {
                $hcardView = new View();
                $output = $hcardView->render('hcard', array('contact_info' => $contact_info));
            }

            return $output;
        }


        /**
         * Renders custom colors stylesheet on the page
         */
        function renderCustomColorsStylesheet()
        {
            $colors = Settings::get_colors();

            if (!$colors || empty($colors) || !isset($colors['colors-on']))
            {
                return;
            }

            $colorsView = new View();

            $output = $colorsView->render('custom-colors-stylesheet', array('colors' => $colors));

            // remove line breaks to minify a bit

            echo str_replace('    ', '', str_replace("\n", '', $output)) . "\n";
        }


        /**
         * Renders Listing Details Print Page
         */
        function renderListingDetailsPrintPage()
        {
            global $wp_query;

            if (isset($wp_query->query_vars['idx-action']) && $wp_query->query_vars['idx-action'] == 'details' && isset($wp_query->query_vars['idx-print']))
            {
                // Set listing print page

                $this->is_listing_print_page = true;

                $printView = new View();

                echo $printView->render('listing-details-print');

                exit();
            }
        }


        /**
         * Returns HTML for search widget
         *
         * @param $atts parameters passed to search widget shortcode
         * @return string HTML code
         */
        function getSearchWidgetHTML($atts)
        {
            if (!isset($atts['mls']))
            {
                $markets = Membership::getInstance()->getMarkets();

                // Grab first mls on the list

                $atts['mls'] = array_shift($markets);

                return $this->shortcodesModel->renderIdxSearchWidget($atts);
            }
            else
            {
                return $this->shortcodesModel->renderIdxSearchWidget($atts);
            }

            return false;
        }
    }

}

/*** Public Functions - for use in templates ***/
// TODO: move public functions into public-function.php in the root
namespace
{
    /**
     * Conditional function that identifies if current post
     * is a single listing details post.
     * (mimics WP's core function is_single())
     *
     * @return bool
     */
    function ridx_is_single()
    {
        global $post;

        if (isset($post->listing))
        {
            return true;
        }

        return false;
    }


    function ridx_get_listing()
    {
        global $post;

        if (ridx_is_single())
        {
            return $post->listing;
        }
    }


    /**
     * Conditional function that identifies if current page
     * is IDX search results page (which is selected in rIDX Settings)
     *
     * @return bool
     */
    function ridx_is_results_page()
    {
        global $post;

        if (isset($post) && $post->ID == \hji\ResponsiveIDX\controllers\IdxApp::getInstance()->settingsController->getOption('search_results_page_id'))
        {
            return true;
        }

        return false;
    }


    /**
     * Conditional function that identifies if current post
     * is a single listing details post PRINT page.
     *
     * @return bool
     */
    function ridx_is_single_print()
    {
        return get_query_var('idx-print');
    }
}

HJI WP Membership Code Reference API documentation generated by ApiGen