/** * Funzione per aggiungere codice javascript nel footer di * wordpress con caricamento asincrono seguendo metodo google * * @return void */ function setJavascriptPlusOne() { // Se ho già inserito il codice javascript nella sezione footer // esco dalla funzione altrimenti setto la variabile e continuo if (self::$JavascriptPlusone) { return; } else { self::$JavascriptPlusone = true; } $addLanguage = ''; $addURLforScript = ''; // Controllo se istanza di google plus è attiva altrimenti // inserisco il codice senza parametri di personalizzazione if ($object = self::getObject('SZGoogleModulePlus')) { $options = (object) $object->getOptions(); // Se nel modulo di google+ è stato indicato di non caricare // il framework javascript di google esco dalla funzione if ($options->plus_system_javascript == '1') { return; } // Controllo il codice lingua da associare al framework javascript // se viene indicato "99" prendo il codice lingua di wordpress if ($options->plus_language == '99') { $addLanguage = substr(get_bloginfo('language'), 0, 2); } else { $addLanguage = $options->plus_language; } // Controllo se devo attivare raccomandazioni mobile e quindi aggiungere publisher id // in mancanza del plublisher di defaul o funzione disattivata non aggiungo niente if ($options->plus_enable_recommendations == '1' and $options->plus_page != '') { $addURLforScript = "?publisherid=" . trim($options->plus_page); } } // Codice javascript per il rendering dei componenti google plus $javascript = '<script type="text/javascript">'; if ($addLanguage != '') { $javascript .= "window.___gcfg = {lang:'" . trim($addLanguage) . "'};"; } $javascript .= "(function() {"; $javascript .= "var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;"; $javascript .= "po.src = 'https://apis.google.com/js/plusone.js" . $addURLforScript . "';"; $javascript .= "var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);"; $javascript .= "})();"; $javascript .= "</script>" . "\n"; // Esecuzione echo su footer del codice javascript generato echo $javascript; }
/** * Function to add javascript code in the footer of wordpress * with asynchronous loading method according to google */ function setJavascriptPlusOne() { // If you've already entered the Javascript code in the footer section // leave the partition function otherwise the variable and constant if (self::$JavascriptPlusone) { return; } else { self::$JavascriptPlusone = true; } $addLanguage = ''; $addURLforScript = ''; // Check if instance of google plus is active otherwise // insert the code without customization parameters if ($object = self::getObject('SZGoogleModulePlus')) { $options = (object) $object->getOptions(); // If in the form of Google+ has been shown not to load // the javascript framework of google leave the function if ($options->plus_system_javascript == '1') { return; } // Check the language code to associate with the javascript // framework, if you see "99" I take the language code of wordpress if ($options->plus_language == '99') { $addLanguage = substr(get_bloginfo('language'), 0, 2); } else { $addLanguage = $options->plus_language; } // Checking if I have to turn the recommendations of the mobile, then add publisher id // without the publisher's default function turned off or do not add anything if ($options->plus_enable_recommendations == '1' and $options->plus_page != '') { $addURLforScript = "?publisherid=" . trim($options->plus_page); } } // Javascript code to render the component google+ // this method is used for asynchronous loading $javascript = '<script type="text/javascript">'; if ($addLanguage != '') { $javascript .= "window.___gcfg = {lang:'" . trim($addLanguage) . "'};"; } $javascript .= "(function() {"; $javascript .= "var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;"; $javascript .= "po.src = 'https://apis.google.com/js/plusone.js" . $addURLforScript . "';"; $javascript .= "var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);"; $javascript .= "})();"; $javascript .= "</script>" . "\n"; // Running echo on the footer of the javascript code generated // This code is added to a single block together with other functions echo $javascript; }