Skip to content

Commit

Permalink
ginger unlocked
Browse files Browse the repository at this point in the history
  • Loading branch information
webgrafia committed Mar 23, 2017
0 parents commit 5a69b36
Show file tree
Hide file tree
Showing 49 changed files with 6,120 additions and 0 deletions.
5 changes: 5 additions & 0 deletions addon/adsense/ginger.adsense.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
add_filter('ginger_script_async_tags', 'ginger_addsesneremover',10,3);
function ginger_addsesneremover($array){
return array_merge($array, array('adsbygoogle', 'googlesyndication'));
}
4 changes: 4 additions & 0 deletions addon/adsense/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
//Adsense
require_once('ginger.adsense.php');

126 changes: 126 additions & 0 deletions addon/analytics/ginger.analytics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php
/**
* Created by PhpStorm.
* User: matteobarale
* Date: 26/06/15
* Time: 12:02
*/

add_action('ginger_add_menu', 'add_ginger_analytics');
function add_ginger_analytics(){
add_submenu_page( 'ginger-setup', "Ginger Analytics", __("Google Analytics", "ginger"), 'manage_options', 'ginger-analytics', 'ginger_analytics');
}

function ginger_analytics(){
if ( ! current_user_can( 'manage_options' ) ) die();


$option_analitycs = get_option('gingeranalytics');
?>
<?php
if($_POST):
if(isset($_POST['enable_ginger_analytics']) && $_POST['enable_ginger_analytics'] == 1):
$content = file_get_contents(get_bloginfo('url') .'/?analytics=check');
$array_to_check = array(
'www.google-analytics.com/analytics.js',
'google-analytics.com/ga.js',
'_getTracker',
);

foreach($array_to_check as $check):
if(strpos( $content, $check) !== false):
$find = 'trovatocodice';
$_POST['enable_ginger_analytics'] = 0;
break;
endif;
endforeach;

endif;
$args = array(
'enable_ginger_analytics' => $_POST['enable_ginger_analytics'],
'ginger_analytics_code' => $_POST['ginger_analytics_code'],
'anonymize_ginger_analytics' => $_POST['anonymize_ginger_analytics']
);
update_option('gingeranalytics_option', $args);
endif;
?>
<div class="wrap">
<?php $option = get_option('gingeranalytics_option');?>
<h2>Ginger - Analytics Add On</h2>
<?php if(isset($find)): ?>
<h3><?php _e("Attenzione è stato trovato un codice analytics nella pagina", "ginger"); ?></h3>
<?php endif; ?>
<form method="post" action="admin.php?page=<?php echo $_GET["page"]; ?>">
<?php wp_nonce_field('save_ginger_analytics_options', 'ginger_analytics_options'); ?>
<table class="form-table striped">
<thead>
<tr>
<td colspan="2">
<h3><?php _e('Impostazioni Add on', 'ginger'); ?></h3>
</td>
</tr>
</thead>
<tr>
<th scope="row" style="padding-left:20px;"><?php _e("Enable Ginger Analytics", "ginger"); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e("Enable Ginger Analytics", "ginger"); ?></span></legend>
<p>
<label>
<input name="enable_ginger_analytics" type="radio" value="1" class="tog" <?php if(isset($option['enable_ginger_analytics']) && $option['enable_ginger_analytics'] == 1 ): echo 'checked'; endif;?>>Abilitato
</label>
</p>
<p>
<label>
<input name="enable_ginger_analytics" type="radio" value="0" class="tog" <?php if(isset($option['enable_ginger_analytics']) && $option['enable_ginger_analytics'] == 0 ): echo 'checked'; endif;?>>Disabilitato
</label>
</p>
</fieldset>
</td>
</tr>
<tr>
<th scope="row" style="padding-left:20px;"><?php _e("Codice Analytics (Ex: UA-XXXXXXX-X)", "ginger"); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e("Codice Analytics (Ex: UA-XXXXXXX-X)", "ginger"); ?></span></legend>
<p>
<label>
<input name="ginger_analytics_code" type="text" value="<?php if(isset($option['ginger_analytics_code']) && $option['ginger_analytics_code'] != '' ): echo $option['ginger_analytics_code']; endif;?>" placeholder="<?php _e('Inserisci qui il tuo traking code', 'ginger'); ?>">
</label>
</p>
</fieldset>
</td>
</tr>
</table>
<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e("Save Changes", "ginger"); ?>"></p>
</form>
</div>

<?php }


add_action( 'wp_head', 'ginger_anyltics_script_anonymize');
function ginger_anyltics_script_anonymize(){ ?>
<?php $option = get_option('gingeranalytics_option');?>
<script>gingeranalytics('<?php if(isset($option['ginger_analytics_code']) && $option['ginger_analytics_code'] != '' ): echo $option['ginger_analytics_code']; endif;?>')</script>
<?php }

// Registro script per il controllo dello script Analytics
add_action( 'wp_enqueue_scripts', 'ginger_analytics_style_script' );
function ginger_analytics_style_script() {
wp_register_script( 'ginger-analytics_script', plugin_dir_url( __FILE__ ) . 'gingeranalytics.min.js' );
wp_enqueue_script( 'ginger-analytics_script' );
}

add_filter('ginger_script_tags', 'ginger_analytics_remover',10,3);
function ginger_analytics_remover($array){
$option = get_option('gingeranalytics_option');
if(isset($option['enable_ginger_analytics']) && $option['enable_ginger_analytics'] == 1 ):
$pos = array_search('www.google-analytics.com/analytics.js', $array);
unset($array[$pos]);
$pos = array_search('google-analytics.com/ga.js', $array);
unset($array[$pos]);
return $array;
endif;
return $array;
}
33 changes: 33 additions & 0 deletions addon/analytics/gingeranalytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Created by matteobarale on 09/07/15.
*/
function gingeranalytics(code) {
console.log(code);
console.log(getCookie('ginger-cookie'));

if(getCookie('ginger-cookie') == 'Y'){
var gacode = "ga('create', '" + code + "', 'auto'); ga('send', 'pageview');";
}else{
var gacode = "ga('create', '" + code + "', 'auto'); ga('set', 'anonymizeIP', true); ga('send', 'pageview');";
}

var scriptanalytics = document.createElement('script');
scriptanalytics.type = 'text/javascript';
scriptanalytics.innerHTML = '(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){'
+'(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),'
+'m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)'
+'})(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');' + gacode;
console.log(scriptanalytics);
document.getElementsByTagName('head')[0].appendChild(scriptanalytics);
}

function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}
1 change: 1 addition & 0 deletions addon/analytics/gingeranalytics.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions addon/analytics/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require_once('ginger.analytics.php');
67 changes: 67 additions & 0 deletions addon/exporter/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Import/Export tool
*/

add_action('ginger_add_menu', 'add_ginger_export', 100);
function add_ginger_export(){
add_submenu_page( 'ginger-setup', "Import Export", __("Import/Export", "ginger"), 'manage_options', 'ginger-export', 'ginger_export');
}


function ginger_export(){
if(isset($_POST["submit"]) && !wp_verify_nonce($_POST['save_ginger_export_options'], 'ginger_export_options')){
return;
}
if(isset($_POST["action"]) && $_POST["action"] == "import"){
if($newconf = @unserialize(stripslashes($_POST["data"]))) {
foreach($newconf as $key => $val){
update_option($key, $val);
}
echo '<div class="updated"><p>'.__( 'All done! Your configuration was saved!', 'ginger' ).'</p></div>';
}else{
echo '<div class="updated error"><p>'.__( 'Error! Copied text is wrong...', 'ginger' ).'</p></div>';
}
}
?>
<div class="wrap">
<h2>Ginger - Import/Export</h2>
<h3><?php _e("Export", "ginger"); ?></h3>
<p><?php _e("You can export your configuration and import it on a Ginger Managed websites!", "ginger"); ?></p>
<p><?php _e("Simply copy & paste this code in Import Textarea:", "ginger"); ?></p>
<textarea style="width:100%;" rows="10" ><?php
$export = array();

$export["ginger_general"] = get_option('ginger_general');
$export["ginger_banner"] = get_option('ginger_banner');
// $ $export["ginger_policy"] = get_option('ginger_policy');
$export["gingerjscustom"] = get_option('gingerjscustom');
$export["ginger_jscustom"]= get_option('ginger_jscustom_options');
$export["gingeradsense"] = get_option('gingeradsense');
$export["gingerwpml"] = get_option('gingerwpml');
$export["ginger_wpml_options"] = get_option('ginger_wpml_options');
$export["gingerpolylang"] = get_option('gingerpolylang');
$export["ginger_polylang_options"] = get_option('ginger_polylang_options');
$export["gingeranalytics"] = get_option('gingeranalytics');
$export["gingeranalytics_option"] = get_option('gingeranalytics_option');
echo serialize($export);
?></textarea>

<input type="hidden" name="action" value="export">

<br>
<hr>
<h3><?php _e("Import", "ginger"); ?></h3>

<p><?php _e("Upload here the export file to overwrite existing settings!", "ginger"); ?></p>
<form method="post" action="admin.php?page=<?php echo $_GET["page"]; ?>">
<?php wp_nonce_field('save_ginger_export_options', 'ginger_export_options'); ?>
<input type="hidden" name="action" value="import" >
<textarea name="data" style="width:100%;" rows="10" ></textarea>
<p> <small><b><?php _e("Attention: you must define manually a privacy policy page if you are using {{privacy_policy}} shortcode!", "ginger"); ?></b></small></p>

<input type="submit" value="<?php _e("Import Configuration", "ginger"); ?>" class="button" />
</form>
</div>
<?php
}
28 changes: 28 additions & 0 deletions addon/ginger.addon.utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*
* Option Analitics: gingeranalytics_option -> Contine l'array con le impostazioni del plugin - gingeranalytics -> Contine le optin con il serial number e l'attivazione;
*
*
*/

$addons = ginger_include_addons();

function ginger_include_addons(){
// check native gallery types
$addons = array();
$addondir = plugin_dir_path( __FILE__ );

$files = scandir($addondir);


foreach($files as $file){
if(is_dir($addondir.'/'.$file) && $file != "." && $file != ".."){
if(file_exists($addondir.'/'.$file.'/index.php')){
require_once($addondir.'/'.$file.'/index.php');
$addons[]=$file;
}
}
}

return $addons;
}
97 changes: 97 additions & 0 deletions addon/jscustom/ginger.jscustom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php


add_action('ginger_add_menu', 'add_ginger_jscustom');
function add_ginger_jscustom(){
add_submenu_page( 'ginger-setup', "Ginger JsCustom", __("Custom JS", "ginger"), 'manage_options', 'ginger-jscustom', 'ginger_jscustom_menu_page');
add_submenu_page( 'ginger-setup', "Ginger Iframe Custom", __("Custom Iframe", "ginger"), 'manage_options', 'ginger-iframe', 'ginger_iframe_menu_page');
}


function ginger_jscustom_menu_page(){


$key = "ginger_jscustom_options";
if(isset($_POST["submit"]) && !wp_verify_nonce($_POST['ginger_options'], 'save_ginger_jscustom')){
return;
}

if(isset($_REQUEST["action"]) && $_REQUEST["action"] == "saveurl"){
$params = $_POST["ginger_urls"];
update_option($key, $params);
echo '<div class="updated"><p>'.__( 'Updated!', 'ginger' ).'</p></div>';
}

$options = get_option($key);
include("page/ginger-jscustom.php");

}


function ginger_iframe_menu_page(){

$key = "ginger_iframecustom_options";
if(isset($_POST["submit"]) && !wp_verify_nonce($_POST['ginger_options'], 'save_ginger_jscustom')){
return;
}

if(isset($_REQUEST["action"]) && $_REQUEST["action"] == "saveurl"){
$params = $_POST["ginger_urls"];
update_option($key, $params);
echo '<div class="updated"><p>'.__( 'Updated!', 'ginger' ).'</p></div>';
}

$options = get_option($key);

include("page/ginger-iframe.php");


}


add_filter("ginger_script_tags", "ginger_jscustom_tags");
function ginger_jscustom_tags($array){
$key = "ginger_jscustom_options";
$options = get_option($key);
if($options == "") return $array;
// cicle over params to get sync
foreach ($options as $option) {
if(isset($option["ginger_url_enable"][0]) && $option["ginger_url_enable"][0]){
if(!isset($option["ginger_url_async"][0]) || !$option["ginger_url_async"][0]){
$array[]=$option["ginger_url"];
}
}
}
return $array;
}


add_filter("ginger_script_async_tags", "ginger_jscustom_async_tags");
function ginger_jscustom_async_tags($array){
$key = "ginger_jscustom_options";
$options = get_option($key);
if($options == "") return $array;
// cicle over params to get sync
foreach ($options as $option) {
if(isset($option["ginger_url_enable"][0]) && $option["ginger_url_enable"][0]){
if(isset($option["ginger_url_async"][0]) && $option["ginger_url_async"][0]){
$array[]=$option["ginger_url"];
}
}
}
return $array;
}

add_filter("ginger_add_iframe", "ginger_iframe_async_tags");
function ginger_iframe_async_tags($array){
$key = "ginger_iframecustom_options";
$options = get_option($key);
if($options == "") return $array;
// cicle over params to get sync
foreach ($options as $option) {
if($option["ginger_url_enable"][0]){
$array[]=$option["ginger_url"];
}
}
return $array;
}
2 changes: 2 additions & 0 deletions addon/jscustom/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
require_once('ginger.jscustom.php');
Loading

0 comments on commit 5a69b36

Please sign in to comment.