Skip to content

Instantly share code, notes, and snippets.

@Heft9nic
Created October 20, 2016 13:00
Show Gist options
  • Save Heft9nic/cb485bba884dda676a2600a6e1b8e457 to your computer and use it in GitHub Desktop.
Save Heft9nic/cb485bba884dda676a2600a6e1b8e457 to your computer and use it in GitHub Desktop.
<?php
function tegsignup_menu(){
$items['ajax/getresponse'] = array(
'page callback' => '_tegsignup_getresponse_submit',
'access callback' => true,
);
$items['submit/tellafriend'] = array(
'page callback' => '_tegsignup_tellafriend_submit',
'access callback' => true,
);
return $items;
}
/**
* Implements hook_block_info().
*/
function tegsignup_block_info() {
$blocks = array();
$blocks['tegsignup'] = array(
'info' => t('######## TEG Signup Block'),
'cache' => DRUPAL_CACHE_PER_ROLE,
);
$blocks['tegsignupfront'] = array(
'info' => t('######## TEG Signup Front Page Block'),
'cache' => DRUPAL_CACHE_PER_ROLE,
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function tegsignup_block_view($block_name = '') {
if ($block_name == 'tegsignup') {
$block = array(
'content' => array(
'#markup' =>_tegsignup_block_content(),
'#attached' => array('js' => array(drupal_get_path('module', 'tegsignup') .'/js/formvalidate.js'))
)
);
return $block;
}
if ($block_name == 'tegsignupfront') {
$block = array(
'content' => array(
'#markup' =>_tegsignup_frontblock_content(),
'#attached' => array('js' => array(drupal_get_path('module', 'tegsignup') .'/js/formvalidate.js'))
)
);
return $block;
}
}
function _tegsignup_block_content(){
$content = <<<EOF
<div id = 'tegsignupform-trigger'>
<div id = 'tegsignupform-trigger-tick'><img src="/sites/all/themes/teg/images/tick.png"></div><div id = 'tegsignupform-trigger-text'>Sign up for free games!</div>
</div>
<div id = 'tegsignupform-wrapper'>
<div id = 'tegsignupform-wrapper-tick'><img src="/sites/all/themes/teg/images/tick.png"></div>
<div id = 'tegsignupform-header'>
Get Your Free Teaching English Games Below!
You need ESL games for:
</div>
<form id='tegsignupform' action='/ajax/getresponse' method='POST'>
<div><input type="checkbox" name="preschool" id="preschool-checkbox">Preschool children</div>
<div><input type="checkbox" name="primary" id="primary-checkbox">Primary school children</div>
<div><input type="checkbox" name="teens" id="teens-checkbox">Teens and adults</div>
<br>
<div class='label'>First name:</div>
<input name="tegsignup-name" id="tegsignup-name">
<div class='label'>Email address:</div>
<input name="tegsignup-mail" id="tegsignup-mail"><br>
<div id="tegsignupform-feedback"></div>
<input id="tegsignupform-submit" type = 'submit'>
<div id = "tegsignup-privacy">We hate <a href="/antispam.htm">spam</a> and your <a href="/privacy.htm">privacy</a> is 100% respected</div>
</form>
</div>
EOF;
return $content;
}
function _tegsignup_getresponse_submit(){
require_once($_SERVER['DOCUMENT_ROOT'] . '/sites/all/libraries/getresponse/wrappers/PHP/PHPwrapper/GetResponseAPI.class.php');
dd("Start");
$api = new GetResponse('f5297f0e49ab9621c41f81a6c2ae7acc');
$response = array();
if(isset($_POST['preschool'])){
if( $_POST['preschool'] == 'true' ){
$response[] = $api->addContact("K31", $_POST['name'], $_POST['email']);
}
}
if(isset($_POST['primary'])){
if( $_POST['primary'] == 'true' ){
$response[] = $api->addContact("KXu", $_POST['name'], $_POST['email']);
}
}
if(isset($_POST['teens'])){
if( $_POST['teens'] == 'true' ){
$response[] = $api->addContact("Kme", $_POST['name'], $_POST['email']);
}
}
dd(print_r($response, TRUE));
$returned = new stdClass;
$returned->message = true;
dd("End");
drupal_json_output($returned);
}
function _tegsignup_tellafriend_submit(){
$from = $_POST['Email'];
$fromname = $_POST['Name'];
$toname = $_POST['FriendName'];
$to = $_POST['FriendEmail'];
$message = $_POST['emailtext'];
require_once($_SERVER['DOCUMENT_ROOT'] . "/sites/all/libraries/PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->SetFrom($from, $fromname);
$mail->AddReplyTo($from, $fromname);
$mail->AddAddress($to, $toname);
$mail->Subject = "Message sent from TeachingEnglishGames.com";
$mail->MsgHTML($message);
if(!$mail->Send()) {
$content = "Sorry, there was a mailer error: " . $mail->ErrorInfo;
} else {
$content = "Thank you! Your message has been sent.";
}
return $content;
drupal_json_output(true);
}
function _tegsignup_frontblock_content(){
$content = <<<EOF
<div id='tegsignupformfront-wrapper'>
<div id='tegsignupformfront-header'>
<div class='title'>
Get Your Free Teaching English Games Below!
</div>
</div>
<div class="block-wrapper">
<div class='signature'>
<p>You need ESL games for:</p>
</div>
<form class="form-footer" id='tegsignupform' action='/ajax/getresponse'
method='POST'>
<div class="edit-checkboxes-fieldset-collapsible">
<div class="form-item form-type-checkbox">
<input type="checkbox" name="preschoolfront" id="preschool-checkbox">
<label class="edit-checkboxes-fieldset-collapsible"
for="preschool-checkbox">Preschool children</label>
</div>
<div class="form-item form-type-checkbox">
<input type="checkbox" name="primaryfront" id="primary-checkbox">
<label class="edit-checkboxes-fieldset-collapsible"
for="primary-checkbox">Primary school children</label>
</div>
<div class="form-item form-type-checkbox">
<input type="checkbox" name="teensfront" id="teens-checkbox">
<label class="edit-checkboxes-fieldset-collapsible"
for="teens-checkbox">Teens and adults</label>
</div>
<div class="form-item form-type-checkbox">
<input type="checkbox" name="onetoone" id="onetoone-checkbox">
<label class="edit-checkboxes-fieldset-collapsible"
for="onetoone-checkbox">Onetoone</label>
</div>
</div>
<div class="input-field">
<label class='label'>First name:</label>
<input type="text" name="tegsignupfront-name" id="tegsignupfront-name">
</div>
<div class="input-field">
<label class='label'>Email address:</label>
<input type="text" name="tegsignup-mail" id="tegsignup-mail">
</div>
<div id="tegsignupform-feedback"></div>
<div class="message-validator" id="tegsignupformfront-feedback"></div>
<div class='submit-wrap'>
<input id="tegsignupformfront-submit" type='submit' value="Get Free">
</div>
</form>
</div>
</div>
EOF;
return $content;
}
function tegsignup_node_view($node, $view_mode, $langcode){
//we are going to detect if the form substitution token is present
if(isset($node->content['body'])){
if(strpos($node->content['body'][0]['#markup'], "[CONTACT FORM]") != FALSE){
$node->content['body'][0]['#markup'] = str_replace("[CONTACT FORM]", _tegsignup_frontblock_content(), $node->content['body'][0]['#markup']);
}
if(strpos($node->content['body'][0]['#markup'], "[SHARE]") != FALSE){
$node->content['body'][0]['#markup'] = str_replace("[SHARE]", _tegsignup_inline_addthis(), $node->content['body'][0]['#markup']);
}
}
}
function _tegsignup_inline_addthis(){
$content = <<<EOF
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_button_pinterest_pinit" pi:pinit:layout="horizontal"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript">var addthis_config = {"data_track_addressbar":false};</script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-52f4b3ef45a9b8c6"></script>
<!-- AddThis Button END -->
EOF;
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment