Exemplo n.º 1
0
 function onDisplay(&$field, $showImage = true, $value = false, $return = false)
 {
     if (empty($field)) {
         return null;
     }
     $values = array();
     $option = $value ? 'value' : 'text';
     foreach ($field[$option] as $key => $text) {
         switch ($field['type']) {
             case 'banner':
                 $text = '{FIELDTEXT}';
                 $field['properties']['output_format'] = Sanitize::getString($field, 'description');
                 $field['description'] == '';
                 break;
             case 'date':
                 $format = Sanitize::getString($field['properties'], 'date_format');
                 $text = $this->Time->nice($text, $format, 0);
                 break;
             case 'integer':
                 $text = Sanitize::getInt($field['properties'], 'curr_format') ? number_format($text, 0, __l('DECIMAL_SEPARATOR', true), __l('THOUSANDS_SEPARATOR', true)) : $text;
                 break;
             case 'decimal':
                 $text = Sanitize::getInt($field['properties'], 'curr_format') ? number_format($text, 2, __l('DECIMAL_SEPARATOR', true), __l('THOUSANDS_SEPARATOR', true)) : round($text, 2);
                 break;
             case 'email':
                 break;
             case 'website':
                 $text = S2ampReplace($text);
                 !strstr($text, '://') and $text = 'http://' . $text;
                 break;
             case 'code':
                 $text = stripslashes($text);
                 break;
             case 'textarea':
             case 'text':
                 if (!Sanitize::getBool($field['properties'], 'allow_html')) {
                     $text = nl2br($text);
                 }
                 break;
             case 'selectmultiple':
             case 'checkboxes':
             case 'select':
             case 'radiobuttons':
                 $imgSrc = '';
                 if ($showImage && isset($field['image'][$key]) && $field['image'][$key] != '') {
                     if ($imgSrc = $this->locateThemeFile('theme_images', cmsFramework::locale() . '.' . $field['image'][$key], '', true)) {
                         $imgSrc = pathToUrl($imgSrc, true);
                     } elseif ($imgSrc = $this->locateThemeFile('theme_images', $field['image'][$key], '', true)) {
                         $imgSrc = pathToUrl($imgSrc, true);
                     }
                     if ($imgSrc != '') {
                         $text = '<img src="' . $imgSrc . '" title="' . $text . '" alt="' . $text . '" border="0" />';
                     }
                 }
                 break;
             default:
                 $text = stripslashes($text);
                 break;
         }
         $values[] = $text;
         $this->output[] = $text;
     }
     if ($return) {
         return $values;
     }
 }
Exemplo n.º 2
0
 /**
  * Return a static instance of the I18n class
  *
  * @return object I18n
  * @access public
  */
 function &getInstance()
 {
     static $instance = array();
     if (!$instance) {
         $instance[0] = new I18n();
         $instance[0]->l10n = new L10n();
         $language = low(cmsFramework::locale());
         Configure::write('Config.language', $language);
     }
     return $instance[0];
 }
Exemplo n.º 3
0
 function send($assets, $inline = false)
 {
     # Load javascript libraries
     $findjQuery = false;
     $this->Html->app = $this->app;
     unset($this->viewVars);
     /**
      * Send cachable scripts to the head tag from controllers and components by adding it to the head array
      */
     if (!empty($this->assets['head-top'])) {
         foreach ($this->assets['head-top'] as $head) {
             cmsFramework::addScript($head);
         }
     }
     // Incorporate controller set assets before sending
     if (!empty($this->assets['js'])) {
         $assets['js'] = array_merge($assets['js'], $this->assets['js']);
     }
     if (!empty($this->assets['css'])) {
         $assets['css'] = array_merge($assets['css'], $this->assets['css']);
     }
     $assets['css'][] = 'custom_styles';
     cmsFramework::isRTL() and $assets['css'][] = 'rtl';
     # Load CSS stylesheets
     if (isset($assets['css']) && !empty($assets['css'])) {
         $findjQueryUI = array_search('jq.ui.core', $assets['css']);
         if ($findjQueryUI !== false) {
             if (defined('J_JQUERYUI_LOADED')) {
                 unset($assets['css'][array_search('jq.ui.core', $assets['css'])]);
             } else {
                 define('J_JQUERYUI_LOADED', 1);
             }
         }
         $this->Html->css(arrayFilter($assets['css'], $this->Libraries->css()), $inline);
     }
     // For CB
     // Check is done against constants defined in those applications
     if (isset($assets['js']) && !empty($assets['js'])) {
         $findjQuery = array_search('jquery', $assets['js']);
         $findjQueryUI = array_search('jq.ui.core', $assets['js']);
         if ($findjQuery !== false) {
             if (defined('J_JQUERY_LOADED') || JFactory::getApplication()->get('jquery')) {
                 unset($assets['js'][$findjQuery]);
             } else {
                 define('J_JQUERY_LOADED', 1);
                 //                    JFactory::getApplication()->set('jquery', true); This was for Warp, but it loads too late. jQuery must be manually disabled in the configuration
                 //                    define( 'C_ASSET_JQUERY', 1 );
             }
         }
         if ($findjQueryUI != false) {
             $locale = cmsFramework::locale();
             $assets['js'][] = 'jquery/i18n/jquery.ui.datepicker-' . $locale;
         }
     }
     if (isset($assets['js']) && !empty($assets['js'])) {
         $this->Html->js(arrayFilter($assets['js'], $this->Libraries->js()), $inline);
     }
     # Set jQuery defaults
     if ($findjQuery && isset($assets['js']['jreviews'])) {
         ?>
         <script type="text/javascript">
         /* <![CDATA[ */
         jreviews.ajax_init();
         /* ]]> */
         </script>
     <?php 
     }
     if (isset($this->Config) && Sanitize::getBool($this->Config, 'ie6pngfix')) {
         $App =& App::getInstance($this->app);
         $AppPaths = $App->{$this->app . 'Paths'};
         $jsUrl = isset($AppPaths['Javascript']['jquery/jquery.pngfix.pack.js']) ? $AppPaths['Javascript']['jquery/jquery.pngfix.pack.js'] : false;
         if ($jsUrl) {
             cmsFramework::addScript('<!--[if lte IE 6]><script type="text/javascript" src="' . $jsUrl . '"></script><script type="text/javascript">jQuery(document).ready(function(){jQuery(document).pngFix();});</script><![endif]-->');
         }
         unset($App, $AppPaths);
     }
     /**
      * Send cachable scripts to the head tag from controllers and components by adding it to the head array
      */
     if (!empty($this->assets['head'])) {
         foreach ($this->assets['head'] as $head) {
             cmsFramework::addScript($head);
         }
     }
 }
Exemplo n.º 4
0
 function __construct()
 {
     parent::__construct();
     # Check for cached version
     $cache_file = 'jreviews_menu_' . cmsFramework::locale() . '_' . md5(cmsFramework::getConfig('secret'));
     if ($cache = S2Cache::read($cache_file)) {
         $this->___menu_data = $cache['___menu_data'];
         return;
     }
     $menuList = array();
     switch ($this->cmsVersion) {
         case CMS_JOOMLA15:
             $select = "\n                    SELECT \n                        id,\n                        name,\n                        link AS menu_type,\n                        link,\n                        componentid,\n                        params,\n                        access,\n                        published\n                ";
             break;
         case CMS_JOOMLA16:
             $select = "\n                    SELECT \n                        id, \n                        title AS name,\n                        link AS menu_type,\n                        link,\n                        component_id AS componentid,\n                        params,\n                        access,\n                        published\n                ";
             break;
     }
     // Get all com_content category/section menus and JReviews menus
     $sql = $select . "\n            FROM #__menu\n            WHERE published = 1\n            ORDER BY link DESC\n        ";
     $this->_db->setQuery($sql);
     $menuList = $this->_db->loadObjectList();
     // Get itemid for each menu link and store it
     if (!empty($menuList)) {
         foreach ($menuList as $menu) {
             $params = stringToArray($menu->params);
             $m_name = Sanitize::getVar($params, 'sef_name') != '' ? Sanitize::getVar($params, 'sef_name') : $menu->name;
             function_exists("sefEncode") and $m_name = sefEncode($m_name);
             $m_action = Sanitize::getVar($params, 'action');
             $m_dir_id = str_replace(",", "-", Sanitize::getVar($params, 'dirid'));
             $m_cat_id = str_replace(",", "-", Sanitize::getVar($params, 'catid'));
             $m_section_id = str_replace(",", "-", Sanitize::getVar($params, 'sectionid'));
             $m_criteria_id = str_replace(",", "-", Sanitize::getVar($params, 'criteriaid'));
             // Create a variable to get Menu Name from Itemid
             $this->set('jr_itemid_' . $menu->id, $m_name);
             $this->set('jr_menu_' . $m_name, $menu->id);
             if (strpos($menu->menu_type, 'option=com_content&view=section&id=') || strpos($menu->menu_type, 'option=com_content&view=section&layout=blog&id=')) {
                 $menu->componentid = end(explode('id=', $menu->menu_type));
                 $menu->menu_type = 'content_section';
             } elseif (strpos($menu->menu_type, 'option=com_content&view=category&id=') || strpos($menu->menu_type, 'option=com_content&view=category&layout=blog&id=')) {
                 $menu->componentid = end(explode('id=', $menu->menu_type));
                 $menu->menu_type = 'content_category';
             } elseif (strpos($menu->menu_type, 'option=com_content&view=article&id=') || strpos($menu->menu_type, 'option=com_content&task=view&id=')) {
                 $menu->componentid = end(explode('id=', $menu->menu_type));
                 $menu->menu_type = 'content_item_link';
             }
             switch ($menu->menu_type) {
                 case 'content_section':
                 case 'content_blog_section':
                     if ($menu->componentid) {
                         // Only one section id
                         $this->set('core_section_menu_id_' . $menu->componentid, $menu->id);
                     } else {
                         $section_ids = explode(",", Sanitize::getVar($params, 'sectionid'));
                         $this->set('jr_manyIds_' . $menu->id, 1);
                         foreach ($section_ids as $section_id) {
                             $this->set('core_section_menu_id_' . $section_id, $menu->id);
                         }
                     }
                     break;
                 case 'content_category':
                 case 'content_blog_category':
                     if ($menu->componentid) {
                         // Only one category id
                         $this->set('core_category_menu_id_' . $menu->componentid, $menu->id);
                     } else {
                         $cat_ids = explode(",", Sanitize::getVar($params, 'categoryid'));
                         $this->set('jr_manyIds_' . $menu->id, 1);
                         foreach ($cat_ids as $cat_id) {
                             $this->set('core_category_menu_id_' . $cat_id, $menu->id);
                         }
                     }
                     break;
                 case 'content_item_link':
                     $this->set('core_content_menu_id_' . $menu->componentid, $menu->id);
                     break;
                 default:
                     if ($menu->componentid > 0 && strstr($menu->link, 'index.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP'))) {
                         // It's a JReviews menu
                         $access = $this->cmsVersion == CMS_JOOMLA15 ? 0 : 1;
                         // Get a JReviews menu with public access to use in ajax requests
                         if ($menu->access == $access && $menu->published == 1) {
                             $this->set('jreviews_public', $menu->id);
                         }
                         $this->set('jr_menu_action_' . $m_dir_id, $m_action);
                         $this->set('menu_params_' . $menu->id, $params);
                         switch ($m_action) {
                             case '0':
                                 // Directory menu
                                 $this->set('jr_directory_menu_id_' . $m_dir_id, $menu->id);
                                 break;
                             case '1':
                                 // Section menu
                                 $this->set('jr_section_menu_id_' . $m_section_id, $menu->id);
                                 break;
                             case '2':
                                 // Category menu
                                 $this->set('jr_category_menu_id_' . $m_cat_id, $menu->id);
                                 break;
                             case '10':
                                 $this->set('jr_myreviews', $menu->id);
                                 break;
                             case '11':
                                 $m_criteria_id && $this->set('jr_advsearch_' . $m_criteria_id, $menu->id);
                                 !$m_criteria_id && $this->set('jr_advsearch', $menu->id);
                                 break;
                             case '12':
                                 $this->set('jr_mylistings', $menu->id);
                                 break;
                             case '18':
                                 $this->set('jr_reviewers', $menu->id);
                                 break;
                             default:
                                 $this->set('jr_menu_id_action_' . $m_action, $menu->id);
                                 break;
                         }
                     }
                     break;
             }
         }
         S2Cache::write($cache_file, array('___menu_data' => $this->___menu_data));
     }
     //        prx($this->___menu_data);exit;
 }
Exemplo n.º 5
0
 /**
  * Get url language code
  */
 function getUrlLanguageCode()
 {
     if (class_exists('JLanguageHelper')) {
         $lang = JLanguageHelper::getLanguages('lang_code');
         return isset($lang[cmsFramework::locale()]) ? $lang[cmsFramework::locale()]->sef : '';
     }
 }
Exemplo n.º 6
0
 function getParentCatIds($cat_id)
 {
     # Check for cached version
     $cache_file = 'jreviews_menu_cat_' . cmsFramework::locale() . '_' . cmsFramework::getCustomToken($cat_id);
     if (Configure::read('Cache.query') && ($cache = S2Cache::read($cache_file))) {
         return $cache['___menu_cat'];
     }
     $query = "\n        (\n            SELECT \n                ParentCategory.id AS cat_id,\n                ParentCategory.lft AS lft\n            FROM \n                #__categories AS Category, \n                #__categories AS ParentCategory\n            INNER JOIN\n                #__jreviews_categories AS JreviewsCategory ON JreviewsCategory.id = ParentCategory.id\n            WHERE \n                (\n                    ParentCategory.id = " . (int) $cat_id . " AND ParentCategory.published = 1\n                )\n        )\n        UNION\n        (\n            SELECT \n                ParentCategory.id AS cat_id,\n                ParentCategory.lft AS lft\n            FROM\n                #__categories AS Category,\n                #__categories AS ParentCategory\n            INNER JOIN\n                #__jreviews_categories AS JreviewsCategory ON JreviewsCategory.id = ParentCategory.id\n            WHERE\n                (            \n                    Category.published = 1\n                    AND Category.lft BETWEEN ParentCategory.lft AND ParentCategory.rgt\n                    AND Category.id = " . (int) $cat_id . "\n                    AND ParentCategory.parent_id > 0\n                )\n            ORDER BY \n                Category.lft\n        )\n        ";
     $rows = $this->query($query, 'loadObjectList');
     $last = array_shift($rows);
     array_push($rows, $last);
     Configure::read('Cache.query') and S2Cache::write($cache_file, array('___menu_cat' => $rows));
     return $rows;
 }
Exemplo n.º 7
0
    function startup(&$controller)
    {
        $this->c =& $controller;
        // Setup vars used in startup and other plugin methods
        $this->google_url = Sanitize::getString($this->c->Config, 'geomaps.google_url', 'http://maps.google.com');
        $this->google_api_key = trim(Sanitize::getString($controller->Config, 'geomaps.google_key'));
        $this->search_autocomplete = Sanitize::getBool($controller->Config, 'geomaps.search_autocomplete', 1);
        $this->google_api_url = $this->google_url . "/maps/api/js?v=3&async=2&sensor=false&key={$this->google_api_key}";
        $this->google_api_url .= '&language=' . substr(cmsFramework::locale(), 0, 2);
        if ($this->search_autocomplete) {
            $this->google_api_url .= '&libraries=places';
        }
        $controller->set('google_api_url', $this->google_api_url);
        if (!$this->runPlugin($controller)) {
            return false;
        }
        if (!Configure::read('Geomaps.header')) {
            Configure::write('Geomaps.header', true);
            $language_js = '<script type="text/javascript">
			/* <![CDATA[ */
			var GeomapsGoogleApi = "' . $this->google_api_url . '",
				GeomapsOnload = new Array(),
				GeomapsLanguage = {
					submit : "' . __t("Submit", true) . '",
					streeview_unavailable : "' . __t("Street view not available for this address.", true, true) . '",
					cannot_geocode : "' . __t("Address could not be geocoded. Modify the address and click on the Geocode Address button to try again.", true) . '",
					drag_marker : "' . __t("Drag the marker to fine-tune the geographic location on the map.", true) . '",
					directions_bad_address : "' . __t("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.", true) . '",
					directions_request_error : "' . __t("The was an error processing the request.", true) . '",
					enter_location : "' . __t("Enter a location", true) . '"
				};


			/* ]]> */
			</script>';
            if (defined('MVC_FRAMEWORK_ADMIN') && !$controller->ajaxRequest) {
                cmsFramework::addScript($language_js);
            } else {
                $controller->assets['head-top'][] = $language_js;
            }
        }
        // Initialize vars
        $center = array();
        $address = '';
        $lat = 0;
        $lon = 0;
        if (!isset($controller->Config)) {
            $controller->Config = Configure::read('JreviewsSystem.Config');
        }
        if (!isset($controller->Access)) {
            $controller->Config = Configure::read('JreviewsSystem.Access');
        }
        $this->max_radius = Sanitize::getInt($controller->Config, 'geomaps.max_radius', $this->max_radius);
        $this->jr_lat = Sanitize::getString($controller->Config, 'geomaps.latitude');
        $this->jr_lon = Sanitize::getString($controller->Config, 'geomaps.longitude');
        if ($this->jr_lat == '' || $this->jr_lon == '') {
            return false;
        }
        $search_method = Sanitize::getString($controller->Config, 'geomaps.search_method', 'address');
        // address/disabled
        $search_address_field = Sanitize::getString($controller->Config, 'geomaps.advsearch_input');
        $default_radius = Sanitize::getString($controller->Config, 'geomaps.radius');
        $this->distance_metric = array('mi' => __t("Miles", true), 'km' => __t("Km", true));
        $this->distance_in = Sanitize::getString($controller->Config, 'geomaps.radius_metric', 'mi');
        $this->jr_address1 = Sanitize::getString($controller->Config, 'geomaps.address1');
        $this->jr_address2 = Sanitize::getString($controller->Config, 'geomaps.address2');
        $this->jr_city = Sanitize::getString($controller->Config, 'geomaps.city');
        $this->jr_state = Sanitize::getString($controller->Config, 'geomaps.state');
        $this->jr_postal_code = Sanitize::getString($controller->Config, 'geomaps.postal_code');
        $this->jr_country = Sanitize::getString($controller->Config, 'geomaps.country');
        $this->country_def = Sanitize::getString($controller->Config, 'geomaps.default_country');
        $this->gid = $controller->Access->gid;
        $this->address_fields = array_filter(array('address1' => $this->jr_address1, 'address2' => $this->jr_address2, 'city' => $this->jr_city, 'state' => $this->jr_state, 'postal_code' => $this->jr_postal_code, 'country' => $this->jr_country));
        $this->geo_fields = array('lat' => $this->jr_lat, 'lon' => $this->jr_lon);
        $this->c->set(array('address_fields' => $this->address_fields, 'geo_fields' => $this->geo_fields));
        /**
         * Address search checks
         */
        if (isset($controller->data['Field']['Listing'])) {
            $address = Sanitize::getString($controller->data['Field']['Listing'], $search_address_field);
        } else {
            $address = Sanitize::getString($controller->params, $search_address_field);
            $lat = Sanitize::getFloat($controller->params, $this->jr_lat);
            $lon = Sanitize::getFloat($controller->params, $this->jr_lon);
        }
        /**
         * Plugin does different things for different controller methods
         */
        $jsGlobals = 'var geoSearchAutocomplete = "' . $this->search_autocomplete . '";';
        $jsGlobals .= 'var jr_lat = "' . $this->jr_lat . '";';
        $jsGlobals .= 'var jr_lon = "' . $this->jr_lon . '";';
        $jsGlobals .= 'var jr_country_def = "' . $this->country_def . '";';
        $jsGlobals .= 'var geoAddressObj = {};';
        foreach ($this->address_fields as $key => $field) {
            $jsGlobals .= "geoAddressObj.{$key} = '{$field}';";
        }
        switch ($controller->name) {
            case 'com_content':
                $this->published = true;
                $controller->Listing->cacheCallbacks[] = 'plgAfterAfterFind';
                $controller->Listing->fields[] = "`Field`.{$this->jr_lat} AS `Geomaps.lat`";
                $controller->Listing->fields[] = "`Field`.{$this->jr_lon} AS `Geomaps.lon`";
                $controller->Listing->fields[] = "JreviewsCategory.marker_icon AS `Geomaps.icon`";
                break;
            case 'listings':
                switch ($controller->action) {
                    // Load the geomaps js library
                    case 'create':
                        // Submit a new listing
                    // Submit a new listing
                    case 'edit':
                        // Edit a listing
                        $this->published = true;
                        $this->loadAssets();
                        cmsFramework::addScript($controller->makeJS($jsGlobals), true);
                        if ($controller->action == 'edit') {
                            $mapit_field = Sanitize::getString($controller->Config, 'geomaps.mapit_field');
                            if ($mapit_field) {
                                $response = "jQuery(document).ready(function() {\r\n                                    jQuery('#{$mapit_field}','#jr_listingForm').after('<span id=\"gm_geocode\">\r\n                                        <input class=\"jrButton\" type=\"button\" onclick=\"geomaps.mapPopupSimple();\" value=\"" . __t("Map it", true) . "\" />&nbsp;\r\n                                        <input class=\"jrButton\" type=\"button\" onclick=\"geomaps.clearLatLng();\" value=\"" . __t("Clear LatLng", true) . "\" />\r\n                                    </span>');\r\n                                });";
                                cmsFramework::addScript($controller->makeJS($response), true);
                            }
                        }
                        break;
                        // Add geomaps buttons after form is loaded
                    // Add geomaps buttons after form is loaded
                    case '_loadForm':
                        // New listing - Loads submit listing form after category selection
                        $this->published = true;
                        $mapit_field = Sanitize::getString($controller->Config, 'geomaps.mapit_field');
                        if ($mapit_field) {
                            $response = array();
                            $response[] = "\r\n                                jQuery('#gm_geocode').remove();jQuery('#{$mapit_field}','#jr_listingForm').after('<span id=\"gm_geocode\"><input class=\"jrButton\" type=\"button\" onclick=\"geomaps.mapPopupSimple();\" value=\"" . __t("Map it", true) . "\" />&nbsp;<input class=\"jrButton\" type=\"button\" onclick=\"geomaps.clearLatLng();\" value=\"" . __t("Clear LatLng", true) . "\" /></span>');\r\n                                jQuery('#gm_geocode').find(':input').removeAttr('disabled');\r\n                            ";
                            $controller->afterAjaxResponse = $response;
                        }
                        break;
                    case '_save':
                        // Checks if
                        $isNew = Sanitize::getInt($controller->data['Listing'], 'id', 0) == 0 ? true : false;
                        if (Sanitize::getInt($controller->Config, 'geomaps.autogeocode_new') && $isNew && isset($controller->data['Field']) && (Sanitize::getFloat($controller->data['Field']['Listing'], $this->jr_lat, null) == null || Sanitize::getFloat($controller->data['Field']['Listing'], $this->jr_lon, null) == null)) {
                            // Build whole address from fields
                            $address = '';
                            foreach ($this->address_fields as $key => $field) {
                                ${$field} = Sanitize::getVar($controller->data['Field']['Listing'], $field, '');
                                if (${$field} != '') {
                                    $address .= ' ' . ${$field};
                                } elseif ($field == 'section') {
                                    $address .= " " . Sanitize::getString($controller->data, 'section');
                                } elseif ($field == 'parent_category') {
                                    $address .= " " . Sanitize::getString($controller->data, 'parent_category');
                                } elseif ($field == 'category') {
                                    $address .= " " . Sanitize::getString($controller->data, 'category');
                                }
                            }
                            if ($address != '' && !Sanitize::getVar($controller->data['Field']['Listing'], $this->jr_country, false) && $this->country_def != '') {
                                $address .= ' ' . $this->country_def;
                            }
                            if ($address != '') {
                                // Geocode address
                                App::import('Component', 'geocoding');
                                $Geocoding = ClassRegistry::getClass('GeocodingComponent');
                                $Geocoding->Config =& $controller->Config;
                                $response = $Geocoding->geocode($address);
                                if ($response['status'] == 200) {
                                    $controller->data['Field']['Listing'][$this->jr_lat] = $response['lat'];
                                    $controller->data['__raw']['Field']['Listing'][$this->jr_lat] = $response['lat'];
                                    $controller->data['Field']['Listing'][$this->jr_lon] = $response['lon'];
                                    $controller->data['__raw']['Field']['Listing'][$this->jr_lon] = $response['lon'];
                                }
                            }
                        }
                        break;
                }
                break;
            case 'admin_listings':
                switch ($controller->action) {
                    case 'index':
                    case 'browse':
                    case 'moderation':
                        $this->loadAssets();
                        App::import('Helper', 'html');
                        $Html = new HtmlHelper();
                        $Html->app = 'jreviews';
                        if ($controller->action == 'moderation') {
                            ?>
                        <script type="text/javascript">
                        /* <![CDATA[ */
                        <?php 
                            echo $jsGlobals;
                            ?>
                        if(null==jQuery('body').data('geomaps')){
                            jQuery.getScript('<?php 
                            echo $this->locateScript('geomaps');
                            ?>
',function(){jQuery('body').data('geomaps',1)});
                        }
                        /* ]]> */
                        </script>
                        <?php 
                        } else {
                            cmsFramework::addScript($controller->makeJS($jsGlobals));
                            $Html->js('geomaps');
                        }
                        break;
                    case 'edit':
                        $mapit_field = Sanitize::getString($controller->Config, 'geomaps.mapit_field');
                        if ($mapit_field) {
                            $response = "jQuery('#{$mapit_field}').after('<span id=\"gm_geocode\"><input class=\"jrButton\" type=\"button\" onclick=\"geomaps.mapPopupSimple();\" value=\"" . __t("Map it", true) . "\" />&nbsp;<input class=\"jrButton\" type=\"button\" onclick=\"geomaps.clearLatLng();\" value=\"" . __t("Clear LatLng", true) . "\" /></span>');";
                            $controller->pluginResponse = $response;
                        }
                        break;
                }
                break;
            case 'module_geomaps':
                $this->loadAssets();
                // load google maps api and geomaps
                break;
            case 'module_advanced_search':
                if ($search_method == 'disabled') {
                    return;
                }
                if ($controller->action == 'index') {
                    $this->published = true;
                    // Enable the callbacks for this controller/method
                    $this->loadAssets();
                    // load google maps api and geomaps
                    $module_id = Sanitize::getVar($controller->params, 'module_id', '');
                    if (!empty($search_address_field)) {
                        $jsGlobals .= "var geoDistanceSearchAddress = '{$search_address_field}';";
                        $jsGlobals .= "GeomapsOnload.push(function () {";
                        $jsGlobals .= "var search_field = jQuery('#{$search_address_field}', '#JreviewsAdvSearch_{$module_id}').get(0);";
                        $this->search_autocomplete and $jsGlobals .= "if(search_field) geomaps.initializeAutocomplete(search_field);";
                        $jsGlobals .= "jQuery('.jrButton', '#JreviewsAdvSearch_{$module_id}').each(function(i, element) {\r\n\t\t\t\t\t\t\tvar onclick_handler = element.onclick;\r\n\t\t\t\t\t\t\telement.onclick = null;\r\n\t\t\t\t\t\t\tjQuery(element).unbind('click').attr('onclick', '');\r\n\t\t\t\t\t\t\tjQuery(element).click(function(e) {\r\n\t\t\t\t\t\t\t\tgeomaps.mapSearchAddress(this, onclick_handler, e);\r\n\t\t\t\t\t\t\t\te.preventDefault();\r\n\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t\t";
                        $jsGlobals .= "});";
                    }
                    cmsFramework::addScript($controller->makeJS($jsGlobals), true);
                }
                break;
                // A search was performed, make distance the default ordering and copy the entered address to the search address field
            // A search was performed, make distance the default ordering and copy the entered address to the search address field
            case 'search':
                if ($search_method == 'disabled') {
                    return;
                }
                switch ($controller->action) {
                    case 'index':
                        $this->published = true;
                        // Enable the callbacks for this controller/method
                        $this->loadAssets();
                        // load google maps api and geomaps
                        if (!empty($search_address_field)) {
                            $jsGlobals .= "var geoDistanceSearchAddress = '{$search_address_field}';";
                            $jsGlobals .= "GeomapsOnload.push(function () {";
                            $this->search_autocomplete and $jsGlobals .= "\r\n\r\n\t\t\t\t\t\t\t\tjQuery('#jr_advancedSearchForm').delegate('#{$search_address_field}', 'click', function(e) {\r\n\t\t\t\t\t\t\t\t\tgeomaps.initializeAutocomplete(this);\r\n\t\t\t\t\t\t\t\t});";
                            $jsGlobals .= "jQuery('#jr_advancedSearchForm #jr-searchFields').delegate('.jrButton[type=submit]', 'click', function(e) {\r\n\t\t\t\t\t\t\t\t\tvar onclick_handler = this.onclick;\r\n\t\t\t\t\t\t\t\t\tthis.onclick = null;\r\n\t\t\t\t\t\t\t\t\tjQuery(this).unbind('click').attr('onclick', '');\r\n\t\t\t\t\t\t\t\t\tgeomaps.mapSearchAddress(this, onclick_handler, e);\r\n\t\t\t\t\t\t\t\t\te.preventDefault();\r\n\t\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t\t";
                            $jsGlobals .= "});";
                        }
                        cmsFramework::addScript($controller->makeJS($jsGlobals), true);
                        break;
                    case '_process':
                        if ($address == '') {
                            return;
                        }
                        $this->published = true;
                        // Enable the callbacks for this controller/method
                        // Make distance the default ordering
                        $controller->Config->list_order_default = 'distance';
                        if ($address != '' && in_array($search_method, array('address'))) {
                            $controller->data['Field']['Listing'][$search_address_field] = $address;
                        }
                        break;
                }
                break;
                // Display search results
            // Display search results
            case 'categories':
                $controller->Listing->fields[] = "`Field`.{$this->jr_lat} AS `Geomaps.lat`";
                $controller->Listing->fields[] = "`Field`.{$this->jr_lon} AS `Geomaps.lon`";
                $controller->Listing->fields[] = "JreviewsCategory.marker_icon AS `Geomaps.icon`";
                $this->published = true;
                // Enable the callbacks for this controller/method
                if ($search_method == 'disabled' || $lat == 0 || $lon == 0) {
                    return;
                }
                if ($controller->action == 'search') {
                    $radius = min(Sanitize::getFloat($controller->params, $this->radius_field, $default_radius), $this->max_radius);
                    if ($search_method == 'disabled') {
                        $this->published = false;
                        return;
                    }
                    if ($lat != 0 && $lon != 0) {
                        Configure::write('geomaps.enabled', true);
                        // Used to show the Distance ordering in the jreviews.php helper in JReviews.
                        $center = array('lat' => $lat, 'lon' => $lon);
                        // Send center coordinates to theme
                        $controller->set('GeomapsCenter', $center);
                        $sort = $controller->params['order'] = Sanitize::getString($controller->params, 'order', 'distance');
                        // Clear address and coordinate field from parameters because it shouldn't be used on distance searches. Instead we use lat/lon via custom condition below
                        unset($controller->params[$search_address_field], $controller->params['url'][$search_address_field], $controller->params[$this->jr_lat], $controller->params['url'][$this->jr_lat], $controller->params[$this->jr_lon], $controller->params['url'][$this->jr_lon]);
                        $controller->passedArgs['url'] = preg_replace('/\\/' . $search_address_field . _PARAM_CHAR . '[\\p{L},-\\s0-9]+/ui', '', $controller->passedArgs['url']);
                        $controller->passedArgs['url'] = preg_replace('/\\/' . $search_address_field . _PARAM_CHAR . '[a-z,0-9-\\s]+/ui', '', $controller->passedArgs['url']);
                        // One above doesn't work well in all cases, but required for non-latin characters in address
                        $controller->passedArgs['url'] = preg_replace('/\\/' . $this->jr_lat . _PARAM_CHAR . '[\\-a-z0-9\\.\\s]+/i', '', $controller->passedArgs['url']);
                        $controller->passedArgs['url'] = preg_replace('/\\/' . $this->jr_lon . _PARAM_CHAR . '[\\-a-z0-9\\.\\s]+/i', '', $controller->passedArgs['url']);
                        // Create a square around the center to limite the number of rows processed in the zip code table
                        // http://www.free-zipcodes.com/
                        // http://www.mysqlconf.com/mysql2008/public/schedule/detail/347
                        $degreeDistance = $this->distance_in == 'mi' ? 69.172 : 40076 / 360;
                        $lat_range = $radius / $degreeDistance;
                        $lon_range = $radius / abs(cos($center['lat'] * pi() / 180) * $degreeDistance);
                        $min_lat = $center['lat'] - $lat_range;
                        $max_lat = $center['lat'] + $lat_range;
                        $min_lon = $center['lon'] - $lon_range;
                        $max_lon = $center['lon'] + $lon_range;
                        $squareArea = "`Field`.{$this->jr_lat} BETWEEN {$min_lat} AND {$max_lat} AND `Field`.{$this->jr_lon} BETWEEN {$min_lon} AND {$max_lon}";
                        // calculate the distance between two sets of longitude/latitude coordinates
                        // From http://www.mysqlconf.com/mysql2008/public/schedule/detail/347
                        if ($this->distance_in == 'km') {
                            $controller->Listing->fields['distance'] = "6371 * 2 * ASIN(SQRT(  POWER(SIN(({$center['lat']} - {$this->jr_lat}) * pi()/180 / 2), 2) +\r\n                                    COS({$center['lat']} * pi()/180) *  COS({$this->jr_lat} * pi()/180) *  POWER(SIN(({$center['lon']} -{$this->jr_lon}) * pi()/180 / 2), 2)  )) AS `Geomaps.distance`";
                        }
                        if ($this->distance_in == 'mi') {
                            $controller->Listing->fields['distance'] = "3956 * 2 * ASIN(SQRT(  POWER(SIN(({$center['lat']} - {$this->jr_lat}) * pi()/180 / 2), 2) +\r\n                                    COS({$center['lat']} * pi()/180) *  COS({$this->jr_lat} * pi()/180) *  POWER(SIN(({$center['lon']} -{$this->jr_lon}) * pi()/180 / 2), 2)  )) AS `Geomaps.distance`";
                        }
                        $controller->Listing->conditions[] = $squareArea;
                        if ($sort == 'distance') {
                            $controller->Listing->order[] = '`Geomaps.distance` ASC';
                        }
                        // Makes sure that only listings within given radius are shown because square limit might include further points
                        //                        $controller->Listing->having[] = '`Geomaps.distance` <= ' . (int) $radius;
                        // Override search theme suffix
                        $theme_suffix = Sanitize::getString($controller->Config, 'geomaps.search_suffix');
                        if ($theme_suffix != '') {
                            $controller->viewSuffix = $theme_suffix;
                        }
                    }
                }
                break;
        }
    }
Exemplo n.º 8
0
 /**
  * Auxiliary function - used for custom coding
  * Creates an array of fields with field names as array keys and attributes and options using an array of field names as input
  * Used in in geomaps module
  */
 function getFields($names, $location = 'listing', $optionValues = null)
 {
     if (empty($names) || count($names) == 1 & $names[0] == 'category') {
         return array();
     }
     $rows = false;
     # Check for cached version
     $cache_prefix = 'field_model_names';
     $cache_key = func_get_args();
     $cache_key['locale'] = cmsFramework::locale();
     if (isset($cache_key[2])) {
         unset($cache_key[2]);
     }
     // $entry not required to cache the results
     if ($cache = S2cacheRead($cache_prefix, $cache_key)) {
         $rows = $cache;
     }
     if (false == $rows || $rows == '') {
         $location = $location == 'listing' ? 'content' : $location;
         //get field attributes only, no values
         $sql = "\n                SELECT \n                    Field.fieldid AS `Field.id`, Field.name AS `Field.name`, Field.title AS `Field.title`,\n                    Field.type AS `Field.type`, Field.options AS `Field.params`,  Field.required AS `Field.required`, \n                    Field.access_view AS `Field.access_view`, `Group`.groupid AS `Group.group_id`, `Group`.title AS `Group.title`\n                FROM \n                    #__jreviews_fields AS Field\n                INNER JOIN \n                    #__jreviews_groups AS `Group` ON (`Group`.groupid = Field.groupid AND `Group`.groupid AND `Group`.type =  '{$location}' )        \n                WHERE \n                    Field.name IN (" . $this->Quote($names) . ") AND Field.location = " . $this->Quote($location);
         $this->_db->setQuery($sql);
         $rows = $this->_db->loadObjectList();
         # Send to cache
         S2cacheWrite($cache_prefix, $cache_key, $rows);
     }
     if (!$rows || empty($rows)) {
         return;
     }
     //extract field ids from array
     $this->field_ids = $multi_field_ids = $this->_extractFieldIds($rows, array('select', 'selectmultiple', 'radiobuttons', 'checkboxes'));
     //get the field options for multiple choice fields
     $this->_getFieldOptions($optionValues);
     // Reformat array and add field options to each multiple choice field
     foreach ($rows as $row) {
         $row = (array) $row;
         //FieldGroups array
         $fields[$row['Field.name']]['field_id'] = $row['Field.id'];
         $fields[$row['Field.name']]['name'] = $row['Field.name'];
         $fields[$row['Field.name']]['type'] = $row['Field.type'];
         $fields[$row['Field.name']]['title'] = $row['Field.title'];
         $fields[$row['Field.name']]['required'] = $row['Field.required'];
         $fields[$row['Field.name']]['properties']['access_view'] = $row['Field.access_view'];
         $params = explode("\n", $row['Field.params']);
         foreach ($params as $param) {
             $parts = explode("=", $param);
             // Need to use this approach because click2search field has equal signs in the value of the property
             $key = array_shift($parts);
             $value = implode('=', $parts);
             $fields[$row['Field.name']]['properties'][$key] = $value;
         }
         if (isset($this->field_options_alpha[$row['Field.id']])) {
             $ordering = isset($fields[$row['Field.name']]['Fields'][$row['Field.name']]['properties']['option_ordering']) && $fields[$row['Group.title']]['Fields'][$row['Field.name']]['properties']['option_ordering'] ? 'alpha' : 'ordering';
             $method = 'field_options_' . $ordering;
             $methodList = 'field_optionsList_' . $ordering;
             $fields[$row['Field.name']]['options'] = $this->{$method}[$row['Field.id']];
             $fields[$row['Field.name']]['optionList'] = $this->{$methodList}[$row['Field.id']];
         }
     }
     return $fields;
 }