Exemplo n.º 1
0
 function js($files, $inline = false, $duress = false)
 {
     // Register in header to prevent duplicates
     $registry = ClassRegistry::getObject('javascript');
     if (is_array($files)) {
         $out = '';
         foreach ($files as $i) {
             if ($duress || !isset($registry[$i])) {
                 $out .= "\n\t" . $this->js($i, $inline, $duress);
             }
         }
         if ($out != '' && $inline) {
             echo $out . "\n";
         }
         return;
     }
     ClassRegistry::setObject($files, 1, 'javascript');
     if (substr($files, -3) != '.js') {
         $files = $files . '.js';
     }
     if (false !== strpos($files, MVC_ADMIN)) {
         // Automatic routing to admin path
         $files = str_replace(MVC_ADMIN . '/', '', $files);
         $jsUrl = $this->locateScript($files, true);
     } else {
         $jsUrl = $this->locateScript($files);
     }
     if ($jsUrl) {
         $out = sprintf($this->tags['javascriptlink'], $jsUrl);
         cmsFramework::addScript($out, $inline, $duress);
     }
 }
Exemplo n.º 2
0
    function startup(&$controller)
    {
        $this->c =& $controller;
        if (!$this->runPlugin($controller)) {
            return false;
        }
        // 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;
        }
        // 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->google_api_url = $this->google_url . "/maps?file=api&v=2&async=2&key={$this->google_api_key}&sensor=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
         */
        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;
                        $Html = new HtmlHelper();
                        $Html->app = 'jreviews';
                        $jsGlobals = 'var GeomapsGoogleApi = "' . $this->google_api_url . '";';
                        $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}';";
                        }
                        cmsFramework::addScript($controller->makeJS($jsGlobals), true);
                        $Html->js('geomaps', 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':
                        App::import('Helper', 'html');
                        $Html = new HtmlHelper();
                        $Html->app = 'jreviews';
                        $jsGlobals = 'var GeomapsGoogleApi = "' . $this->google_api_url . '";';
                        $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}';";
                        }
                        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), true);
                            $Html->js('geomaps', true);
                        }
                        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;
                // 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' || $address == '') {
                    return;
                }
                if ($controller->action == '_process') {
                    $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;
                        // Append default country
                        if ($this->country_def != '') {
                            $address .= ' ' . $this->country_def;
                        }
                        // Geocode address
                        App::import('Component', 'geocoding');
                        $Geocoding = ClassRegistry::getClass('GeocodingComponent');
                        $Geocoding->Config =& $controller->Config;
                        $response = $Geocoding->geocode($address);
                        if ($response['status'] == 200) {
                            $center = $response;
                        }
                        if ($center && !empty($center)) {
                            $controller->data['Field']['Listing'][$this->jr_lat] = $center['lat'];
                            $controller->data['Field']['Listing'][$this->jr_lon] = $center['lon'];
                            unset($controller->data['Field']['Listing'][$this->jr_lat . '_operator']);
                            unset($controller->data['Field']['Listing'][$this->jr_lon . '_operator']);
                        }
                    }
                }
                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]+/i', '', $controller->passedArgs['url']);
                        $controller->passedArgs['url'] = preg_replace('/\\/' . $search_address_field . _PARAM_CHAR . '[a-z0-9-\\s]+/i', '', $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.º 3
0
 function ModuleDirectories()
 {
     $module_id = Sanitize::getInt($this->params, 'module_id', rand());
     $inline = in_array(getCmsVersion(), array(CMS_JOOMLA10, CMS_MAMBO46));
     $assets = array('js' => array('jquery', 'jq.treeview'), 'css' => array('theme', 'jq.treeview'));
     $this->send($assets, $inline);
     // Render tree view
     cmsFramework::addScript("\n            <script type=\"text/javascript\">\n            jQuery(document).ready(function() {\n                        jQuery('#jr_treeView{$module_id}').treeview({\n                            animated: 'fast',\n                            unique: true,\n                            collaped: false,\n                            persist: 'location'\n                        });\n                    });   \n             </script>            \n        ");
 }
Exemplo n.º 4
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.º 5
0
 /**
  * Adds js and css assets to the assets array to be processed later on by the assets helper
  * Need to be set here instead of theme files for pages that can be cached
  * 
  */
 function loadAssets()
 {
     switch ($this->c->name) {
         case 'com_content':
             cmsFramework::addScript('<script src="' . $this->google_url . '/maps?file=api&amp;v=2&amp;sensor=false&amp;key=' . Sanitize::getString($this->c->Config, 'geomaps.google_key') . '" type="text/javascript"></script>');
             $this->c->assets['css'][] = 'geomaps';
             if ($this->c->action == 'com_content_view') {
                 $this->c->assets['js'] = array('geomaps');
             }
             break;
         case 'categories':
             $this->c->assets['css'][] = 'geomaps';
             $this->c->assets['js'] = array('jquery', 'jquery/jquery.scroll-follow', 'geomaps');
             break;
     }
 }
Exemplo n.º 6
0
 function transform($return = false)
 {
     switch ($this->editor) {
         case 'tinyMCE':
         case 'JCE':
             if ($return == true) {
                 return "jQuery('.wysiwyg_editor').tinyMCE();";
             } else {
                 cmsFramework::addScript("<script type='text/javascript'>jQuery(document).ready(function() {jQuery('.wysiwyg_editor').tinyMCE();});</script>");
             }
             break;
     }
 }
Exemplo n.º 7
0
 /**
  * Facebook Open Graph implementation
  * 
  * @param mixed $listing
  * @param mixed $meta
  */
 function facebookOpenGraph(&$listing, $meta)
 {
     // http://developers.facebook.com/docs/opengraph/
     $option = Sanitize::getString($_REQUEST, 'option', '');
     $view = Sanitize::getString($_REQUEST, 'view', '');
     $id = Sanitize::getInt($_REQUEST, 'id');
     // Make sure this is a Joomla article page
     if (!($option == 'com_content' && $view == 'article' && $id)) {
         return;
     }
     $Config = Configure::read('JreviewsSystem.Config');
     if (empty($Config)) {
         $cache_file = 'jreviews_config_' . md5(cmsFramework::getConfig('secret'));
         $Config = S2Cache::read($cache_file);
     }
     $facebook_xfbml = Sanitize::getBool($Config, 'facebook_opengraph') && Sanitize::getBool($Config, 'facebook_appid');
     // Make sure FB is enabled and we have an FB App Id
     if (!$facebook_xfbml) {
         return;
     }
     extract($meta);
     $title == '' and $title = $listing['Listing']['title'];
     $description == '' and $description = Sanitize::htmlClean(Sanitize::stripAll($listing['Listing'], 'summary'));
     $image = isset($listing['Listing']['images'][0]) ? cmsFramework::makeAbsUrl(_DS . _JR_WWW_IMAGES . $listing['Listing']['images'][0]['path']) : null;
     if (!$image) {
         $img_src = '/<img[^>]+src[\\s=\'"]+([^"\'>\\s]+(jpg)+)/is';
         preg_match($img_src, $listing['Listing']['summary'], $matches);
         if (isset($matches[1])) {
             $image = $matches[1];
         }
     }
     $url = cmsFramework::makeAbsUrl($listing['Listing']['url'], array('sef' => true, 'ampreplace' => true));
     $fields = $listing['Field']['pairs'];
     // You can add other Open Graph meta tags by adding the attribute, custom field pair to the array below
     $tags = array('title' => $title, 'url' => $url, 'image' => $image, 'site_name' => cmsFramework::getConfig('sitename'), 'description' => $description, 'type' => Sanitize::getString($listing['ListingType']['config'], 'facebook_opengraph_type'), 'latitude' => Sanitize::getString($Config, 'geomaps.latitude'), 'longitude' => Sanitize::getString($Config, 'geomaps.longitude'), 'street-address' => Sanitize::getString($Config, 'geomaps.address1'), 'locality' => Sanitize::getString($Config, 'geomaps.city'), 'region' => Sanitize::getString($Config, 'geomaps.state'), 'postal-code' => Sanitize::getString($Config, 'geomaps.postal_code'), 'country-name' => Sanitize::getString($Config, 'geomaps.country', Sanitize::getString($Config, 'geomaps.default_country')));
     cmsFramework::addScript('<meta property="fb:app_id" content="' . Sanitize::getString($Config, 'facebook_appid') . '"/>');
     Sanitize::getString($Config, 'facebook_admins') != '' and cmsFramework::addScript('<meta property="fb:admins" content="' . str_replace(' ', '', $Config->facebook_admins) . '"/>');
     //        cmsFramework::addScript('<meta property="fb:admins" content="YOUR-ADMIN-ID"/>'); // It's app_id or this, not both
     # Loop through the tags array to add the additional FB meta tags
     foreach ($tags as $attr => $fname) {
         $content = '';
         if (substr($fname, 0, 3) == 'jr_') {
             // It's a custom field
             $content = isset($fields[$fname]) ? htmlspecialchars($fields[$fname]['text'][0], ENT_QUOTES, 'utf-8') : '';
         } elseif ($fname != '') {
             // It's a static text, not a custom field
             $content = htmlspecialchars($fname);
         }
         $content != '' and cmsFramework::addScript('<meta property="og:' . $attr . '" content="' . $content . '"/>');
     }
 }
Exemplo n.º 8
0
 function beforeFilter()
 {
     # Init Access
     if (isset($this->Access)) {
         $this->Access->init($this->Config);
     }
     # Dynamic Community integration loading
     $community_extension = Configure::read('Community.extension');
     $community_extension = $community_extension != '' ? $community_extension : 'community_builder';
     App::import('Model', $community_extension, 'jreviews');
     $this->Community = new CommunityModel();
     # Set Theme
     $this->viewTheme = $this->Config->template;
     $this->viewImages = S2Paths::get('jreviews', 'S2_THEMES_URL') . 'default' . _DS . 'theme_images' . _DS;
     # Set template type for lists and template suffix
     $this->__initTemplating();
     # Set pagination vars
     // First check url, then menu parameter. Otherwise the limit list in pagination doesn't respond b/c menu params always wins
     $this->limit = Sanitize::getInt($this->params, 'limit', Sanitize::getInt($this->data, 'limit_special', Sanitize::getInt($this->data, 'limit')));
     //		$this->passedArgs['limit'] = $this->limit;
     $this->page = Sanitize::getInt($this->data, 'page', Sanitize::getInt($this->params, 'page', 1));
     if (!$this->limit) {
         if (Sanitize::getVar($this->params, 'action') == 'myreviews') {
             $this->limit = Sanitize::getInt($this->params, 'limit', $this->Config->user_limit);
         } else {
             $this->limit = Sanitize::getInt($this->params, 'limit', $this->Config->list_limit);
         }
     }
     // Set a hard code limit to prevent abuse
     $this->limit = max(min($this->limit, 50), 1);
     // Need to normalize the limit var for modules
     if (isset($this->params['module'])) {
         $module_limit = Sanitize::getInt($this->params['module'], 'module_limit', 5);
     } else {
         $module_limit = 5;
     }
     $this->module_limit = Sanitize::getInt($this->data, 'module_limit', $module_limit);
     $this->module_page = Sanitize::getInt($this->data, 'module_page', 1);
     $this->module_page = $this->module_page === 0 ? 1 : $this->module_page;
     $this->module_offset = (int) ($this->module_page - 1) * $this->module_limit;
     if ($this->module_offset < 0) {
         $this->module_offset = 0;
     }
     $this->page = $this->page === 0 ? 1 : $this->page;
     $this->offset = (int) ($this->page - 1) * $this->limit;
     if ($this->offset < 0) {
         $this->offset = 0;
     }
     # Add global javascript variables
     if (!defined('MVC_GLOBAL_JS_VARS') && !$this->ajaxRequest && $this->action != '_save') {
         cmsFramework::addScript('<script type="text/javascript">
         //<![CDATA[
         var xajaxUri = "' . getXajaxUri() . '";
         //]]>
         </script>');
         cmsFramework::addScript('<script type="text/javascript">
         //<![CDATA[
         var s2AjaxUri = "' . getAjaxUri() . '";
         //]]>
         </script>');
         cmsFramework::addScript('<script type="text/javascript">
             var jr_translate= new Array();
             jr_translate["cancel"] = "' . __t("Cancel", true) . '";
             jr_translate["submit"] = "' . __t("Submit", true) . '";
         </script>');
         $javascriptcode = '<script type="text/javascript">%s</script>';
         # Set calendar image
         cmsFramework::addScript(sprintf($javascriptcode, 'var datePickerImage = "' . $this->viewImages . 'calendar.gif";'));
         # Find and set one public Itemid to use for Ajax requests
         $menu_id = '';
         if (!defined('MVC_FRAMEWORK_ADMIN')) {
             App::import('Model', 'menu', 'jreviews');
             $MenuModel = RegisterClass::getInstance('MenuModel');
             $menu_id = $MenuModel->get('jreviews_public');
             $menu_id = $menu_id != '' ? $menu_id : 99999;
             $this->set('public_menu_id', $menu_id);
         }
         # Set JReviews public menu
         cmsFramework::addScript(sprintf($javascriptcode, 'var jr_publicMenu = ' . $menu_id . ';'));
         define('MVC_GLOBAL_JS_VARS', 1);
     }
     # Init plugin system
     $this->_initPlugins();
 }
Exemplo n.º 9
0
 function loadXajax()
 {
     // Prevents xajax from loading twice if already loaded by jReviews or BlueFlame Platform
     if (!class_exists('xajax') && !defined('XAJAX_LOADED') && !defined('XAJAX_VER')) {
         define('XAJAX_LOADED', 1);
         App::import('Vendor', 'xajax_05final' . DS . 'xajax_core' . DS . 'xajax.inc');
         if (defined('MVC_FRAMEWORK_ADMIN')) {
             $xajax = new xajax('index2.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP') . '&task=xajax&no_html=1');
         } else {
             $xajax = new xajax();
         }
         $xajax->setCharEncoding(strtoupper(cmsFramework::getCharset()));
         if (strtolower(cmsFramework::getCharset()) == 'utf-8') {
             $decodeUTF8 = false;
         } else {
             $decodeUTF8 = true;
         }
         /* Set defaults from params */
         $this->xajax_statusMessage ? $xajax->setFlag('statusMessages', true) : $xajax->setFlag('statusMessages', false);
         $this->xajax_waitCursor ? $xajax->setFlag('waitCursor', true) : $xajax->setFlag('waitCursor', false);
         $this->xajax_debug ? $xajax->setFlag('debug', true) : $xajax->setFlag('debug', false);
         $decodeUTF8 ? $xajax->setFlag('decodeUTF8Input', true) : $xajax->setFlag('decodeUTF8Input', false);
         $xajax->registerFunction('xajaxDispatch');
         //			ob_start('ob_gzhandler');		// Results in wrong encoding error ni certain servers
         $xajax->processRequest();
         $js = $xajax->getJavascript(S2_VENDORS_URL . 'xajax_05final' . _DS);
         cmsFramework::addScript($js);
     }
 }
Exemplo n.º 10
0
 function js($files, $inline = false, $duress = false, $nocache = false)
 {
     /**
      * BYPASSES THE JS METHOD IN FAVOR OF CJS (cached)
      */
     if (Configure::read('Cache.assets_js') && !defined('MVC_FRAMEWORK_ADMIN') && !$inline && $nocache === false) {
         $this->cjs($files, $duress);
         return;
     }
     // Register in header to prevent duplicates
     $headCheck = RegisterClass::getInstance('HeadTracking');
     if (is_array($files)) {
         $out = '';
         foreach ($files as $i) {
             // Check if already in header
             if ($duress || !$headCheck->check($i, 'js')) {
                 $out .= "\n\t" . $this->js($i, $inline, $duress, $nocache);
             }
         }
         if ($out != '' && $inline) {
             echo $out . "\n";
         }
         return;
     }
     $headCheck->register($files, 'js');
     if (empty($this->AppPaths)) {
         $App =& App::getInstance($this->app);
         $this->AppPaths = $App->{$this->app . 'Paths'};
     }
     if (!strstr($files, '.js')) {
         $files = $files . '.js';
     }
     if (false !== strpos($files, MVC_ADMIN)) {
         // Automatic routing to admin path
         $files = str_replace(MVC_ADMIN . '/', '', $files);
         $jsUrl = $this->locateScript($files, true);
     } else {
         $jsUrl = $this->locateScript($files);
     }
     if ($jsUrl) {
         $out = sprintf($this->tags['javascriptlink'], $jsUrl);
         cmsFramework::addScript($out, $inline, $duress);
     }
 }