Skip to content

Instantly share code, notes, and snippets.

@derpixler
Created June 15, 2011 07:17
Show Gist options
  • Save derpixler/1026631 to your computer and use it in GitHub Desktop.
Save derpixler/1026631 to your computer and use it in GitHub Desktop.
G-Lock Double Opt-in Manager without js and Hooks
<?php
/**
* hook in the title
*
* @param array $args
* @return array
*
*/
function my_gsom_form_title($args){
return array('title' => $args['title'],'before' => false, 'after' => false);
}
/**
* hook in the array with the Form attributes
*
* @param array $array
* @return array
*
*/
function my_gsom_form_array($array){
return $array;
}
/**
* hook in the Formfields
*
* @param string $content
* @return string
*
*/
function my_gsom_form_fields($content){
return $content;
}
/**
* hook in the completely Form
*
* @param string $content
* @return string
*
*/
function my_gsom_form_content($content){
return $content;
}
/** hook for deactivate the JS functionality **/
add_filter('gsom_form_without_js',create_function('','return true;'));
/** hooks in for the gsom_put_form function **/
add_filter('gsom_form_title','my_gsom_form_title');
add_filter('gsom_form_array','my_gsom_form_array');
add_filter('gsom_form_fields','my_gsom_form_fields');
add_filter('gsom_form_content','my_gsom_form_content');
?>
<?php
/**
*
* The gsom_put_form modification by Rene Reimann
*
* @autor Rene Reimann Germany saxony-anhalt halle (saale)
* @mail [email protected]
*
* The double opt-in form will only work with activated JS.
* So, unfortunately, the flexibility is restricted. The JS
* implementation creates a bloated html construct.
*
* I adapted the "gsom_put_form" function so that it is now
* possible to integrated the form with or without JS.
*
* Here was the "gsom_form_without_js"-hook involved.
* It ensures the integration of the form without JS. To increase
* the flexibility of the function I added some hooks.
*
* This modification is localized in glsft-optin.php @ line 2749
*
*/
function gsom_put_form($print = true)
{
global $gsom_form_vars;
$gsom_def_form = get_option('gsom_def_form');
$gsom_form = get_option('gsom_form');
$gsom_sform_header = get_option('gsom_sform_header');
$gsom_sform_footer = get_option('gsom_sform_footer');
$gsom_form_title = get_option('gsom_form_title');
$rnd = ceil(microtime(true)*10)+rand(10,100);
if (trim($gsom_form) == '')
$gsom_form = $gsom_def_form;
if (func_num_args() >= 4)
{
$before_title = func_get_arg(1);
$after_title = func_get_arg(2);
$before_widget = func_get_arg(3);
$after_widget = func_get_arg(4);
}
else
{
$before_title = '<h2>';
$after_title = '</h2>';
$before_widget = '';
$after_widget = '';
}
$data = '';
$s = (trim($gsom_form) != '') ? $gsom_form : $gsom_def_form;
$gsom_form_without_js = apply_filters('gsom_form_without_js',false);
$data .= $before_widget;
$data .= $before_title
. strip_tags($gsom_form_title)
. $after_title;
$title = apply_filters('gsom_form_title',array('title' => $gsom_form_title,'before' => $before_title,'after' => $after_title));
$data = $title['before'].$title['title'].$title['after'].$gsom_sform_header;
if(!$print)
{
$clsa_form = 'class="gsom-sa-from"';
$clsa_placehldr = ' gsom-sa-placeholder';
}
else
{
$clsa_form = '';
$clsa_placehldr = '';
}
if($gsom_form_without_js === true){
$data .= '<form '.$clsa_form.' name="gsom-optin" action="'.$gsom_form_vars['blog_url'].'" method="post">';
$s = apply_filters('gsom_form_array',json_decode(&$gsom_form));
foreach($s as $k => $elem){
if($s[$k]->type != 'submit'){
$gsom_form_elem .= '<label for="'.$s[$k]->name.'">'.$s[$k]->label.'</label>';
}
$gsom_form_elem .= '<input name="'.$s[$k]->name.'" value="'.$s[$k]->value.'" type="'.$s[$k]->type.'"/>';
}
$data .= apply_filters('gsom_form_fields',$gsom_form_elem);
$data .='</form>';
}else{
$data .= '<script src="'.$gsom_form_vars['wp_url'].PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)) . '/js/glock2.min.js'.'"></script>';
$data .= '<script src="'.$gsom_form_vars['wp_url'].PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)) . '/js/gsom_s.min.js'.'"></script>';
$data .= '<form '.$clsa_form.' name="gsom-optin" action="'.$gsom_form_vars['blog_url'].'" method="post">
<div class="gsom-optin-form'.$clsa_placehldr.'" id="gsom-optin-form-'.$rnd.'">
</div>
</form>';
}
$data .= $gsom_sform_footer;
/*
* WP Double Opt-in Plugin has required a great deal of time and effort to develop.
* If it's been useful to you then you can support this development by retaining the
* link to www.glockeasymail.com. This will act as an incentive for us to carry on developing it,
* providing countless hours of support, and including any enhancements that are suggested.
*
* Since "Link love" is the only form of appreciation we ask from our plugin users, the best
* if you simply leave the links in place.
*
* Alternatively, you can place links in some other place on your site (e.g. credits page,
* write a review post for this plugin on your blog, etc.).
* If you don't give any credits to the developers, then support on our forum
* and via email may be refused.
*
* G-Lock Software : 2008
*/
$anc = base64_decode(get_option('gsom_form_xdata'));
$data .= '<noscript><a href="http://www.glockeasymail.com/wordpress-email-newsletter-plugin-for-double-opt-in-subscription/">G-Lock opt-in manager</a> for <a href="http://www.glockeasymail.com">'.$anc.'</a> The gsom double optin Plugin is modified by <a href="http://www.die-pixler.de?gsom">Rene Reimann</a> for a usage without JavaScript.</noscript>';
if($gsom_form_without_js != true){
$data .= '<script type="text/javascript">
(function(){
function rungsom() {
var gsomForm = '.$s.';';
$data .= '
gsomBuildForm({makeDivs: true, arr:gsomForm, place:"gsom-optin-form-'.$rnd.'"});
}
if (window.addEventListener) {
window.addEventListener("load", rungsom, false);
} else {
window.attachEvent("onload", rungsom);
}
})();
</script>';
}
$data .= $after_widget;
$data = apply_filters('gsom_form_content',$data);
if ($print) {
echo $data;
} else {
return '<div class="gsom-sa-wrapper">'.$data.'</div>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment