Last active
December 16, 2015 04:49
-
-
Save everdaniel/5380248 to your computer and use it in GitHub Desktop.
Demo files from a competition site built for an Ad Agency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define Forms namespace | |
grr.forms = grr.forms || {}; | |
/** | |
* Forms Validation Startup | |
*/ | |
grr.forms.start = function() { | |
if ($('#upload-forms').length > 0) | |
{ | |
if (typeof upload_entry_active_tab === 'undefined') | |
var upload_entry_active_tab = 0; | |
$('#upload-forms').accordion({ | |
autoHeight: false, | |
navigation: true, | |
active: upload_entry_active_tab | |
}); | |
} | |
// Signup | |
if ($('#form-signup').length > 0) | |
grr.forms.validateSignup(); | |
// Validate Submit Entry page | |
if ($('#form-submit-entry').length > 0) | |
grr.forms.validateEntry(); | |
// Remember Me Form | |
if ($('#form-remember-me').length > 0) | |
grr.forms.validateRemember(); | |
} | |
/** | |
* Forms Validation - Sign Up Page 1 | |
*/ | |
grr.forms.validateSignup = function() { | |
$('#form-signup').validate({ | |
errorElement: 'label', | |
errorClass: 'error', | |
errorPlacement: function(error, element) { | |
if ($(element).attr('type') == 'radio') | |
{ | |
error.addClass('error-radio'); | |
$(element).parent().append(error); | |
} | |
else | |
error.insertAfter(element); | |
}, | |
highlight: function(element) { | |
if ($(element).attr('type') == 'radio') | |
{ | |
$(element).parent().parent().addClass('error').removeClass('valid'); | |
} | |
}, | |
unhighlight: function(element) { | |
if ($(element).attr('type') == 'radio') | |
{ | |
$(element).parent().parent().removeClass('error').addClass('valid'); | |
} | |
}, | |
rules: { | |
first_name: { | |
required: true, | |
minlength: 3 | |
}, | |
last_name: { | |
required: true, | |
minlength: 3 | |
}, | |
email_address: { | |
required: true, | |
email: true | |
}, | |
company: { | |
required: true, | |
minlength: 2 | |
}, | |
title: { | |
required: true, | |
minlength: 2 | |
}, | |
starting_point: { | |
required: true | |
}, | |
"questions[1]": { | |
required: true | |
}, | |
"questions[2]": { | |
required: true | |
}, | |
"questions[3]": { | |
required: true | |
}, | |
"questions[4]": { | |
required: true | |
}, | |
"questions[5]": { | |
required: true | |
} | |
}, | |
messages: { | |
first_name: { | |
required: 'Please enter your First Name.', | |
minlength: 'Your first name must consist of at least 3 characters' | |
}, | |
last_name: { | |
required: 'Please enter your Last Name.', | |
minlength: 'Your first name must consist of at least 3 characters' | |
}, | |
email_address: { | |
required: 'Please enter your Email Address.', | |
email: 'Please enter a valid Email Address.' | |
}, | |
company: { | |
required: 'Please enter your Company.', | |
minlength: 'Your Company must consist of at least 3 characters' | |
}, | |
title: { | |
required: 'Please enter your Title.', | |
minlength: 'Your Title must consist of at least 3 characters' | |
}, | |
starting_point: { | |
required: 'Please select How did you Hear?.' | |
} | |
} | |
}); | |
} | |
/** | |
* Forms Validation - Remember Me | |
*/ | |
grr.forms.validateRemember = function() { | |
// Form validation | |
$('#form-remember-me').validate({ | |
errorElement: 'span', | |
errorClass: 'error', | |
validClass: 'is-valid', | |
highlight: function(element) { | |
$(element).parent().addClass('error-col').removeClass('valid-col'); | |
}, | |
unhighlight: function(element) { | |
$(element).parent().removeClass('error-col').addClass('valid-col'); | |
}, | |
rules: { | |
email_address: { | |
required: true, | |
email: true | |
} | |
}, | |
messages: { | |
email_address: { | |
required: 'Please enter your email address.', | |
email: 'Please enter a valid email address.' | |
} | |
} | |
}); | |
} | |
/** | |
* Validate Submit Entry | |
*/ | |
grr.forms.validateEntry = function() { | |
// Show/Hide submit based on terms accepted or not | |
$('#cb_terms').bind('click', function() { | |
if (this.checked) | |
$('#btn_submit_entry').css({ 'display': 'block' }); | |
else | |
$('#btn_submit_entry').css({ 'display': 'none' }); | |
}); | |
$('#form-submit-entry').validate({ | |
submitHandler: function(form) { | |
$('#form-submit-entry').css({ 'display': 'none' }); | |
$('#form-upload-processing').css({ 'display': 'block' }); | |
form.submit(); | |
}, | |
errorPlacement: function(error, element) { | |
if ($(element).attr('type') == 'checkbox') | |
{ | |
error.addClass('error-radio'); | |
$(element).parent().append(error); | |
} | |
else | |
error.insertAfter(element); | |
}, | |
rules: { | |
entry_title: { | |
required: true, | |
minlength: 2 | |
}, | |
what_inspires_you: { | |
required: true, | |
minlength: 2, | |
maxwords: true | |
}, | |
youtube_url: { | |
required: grr.forms.requireYoutubeURL | |
}, | |
image_file: { | |
required: grr.forms.requireImageFile | |
}, | |
youtube_video_id: { | |
required: grr.forms.requireYoutubeID | |
}, | |
cb_terms: { | |
required: grr.forms.requireTerms | |
} | |
}, | |
messages: { | |
entry_title: { | |
required: 'Please enter your Entry Title', | |
minlength: 'Your Entry Title must consist of at least 2 characters' | |
}, | |
what_inspires_you: { | |
required: 'Please describe what inspires you.', | |
minlength: 'What inspires you must consist of at least 2 characters', | |
maxwords: 'What inspires you should no exceed 100 words' | |
}, | |
youtube_url: { | |
required: 'Please enter the URL of your YouTube video' | |
}, | |
image_file: { | |
required: 'Please select an image file to upload' | |
}, | |
youtube_video_id: { | |
required: 'Please upload a video' | |
}, | |
cb_terms: { | |
required: 'Please accept the Terms & Conditions' | |
} | |
} | |
}); | |
} | |
/** | |
* Implemented max word validation method | |
*/ | |
$.validator.addMethod('maxwords', function(value, element) { | |
total_words = value.split(/[\s\.\?]+/).length; | |
return !(total_words > 100); | |
}), 'What inspires you in around 100 words or less.'; | |
/** | |
* Sets YouTube URL as required or not based on whether others fields have data | |
*/ | |
grr.forms.requireYoutubeURL = function() { | |
if (($('#image_file').val() == '') && ($('#youtube_video_id').val() == '')) | |
return true; | |
else | |
return false; | |
} | |
/** | |
* Sets Image Upload as required or not based on whether others fields have data | |
*/ | |
grr.forms.requireImageFile = function() { | |
if (($('#youtube_url').val() == '') && ($('#youtube_video_id').val() == '')) | |
return true; | |
else | |
return false; | |
} | |
/** | |
* Sets Video Upload as required or not based on whether others fields have data | |
*/ | |
grr.forms.requireYoutubeID = function() { | |
if (($('#youtube_url').val() == '') && ($('#image_file').val() == '')) | |
return true; | |
else | |
return false; | |
} | |
/** | |
* Sets Terms Checkbox as required if necessary | |
*/ | |
grr.forms.requireTerms = function() { | |
if ($('input[name=cb_terms]').length == 0) | |
return false; | |
else | |
return $('input[name=cb_terms]').val() == 'yes'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define App Namespace | |
window.grr = window.app || {}; | |
// Define GRR Application Namespace | |
grr.app = grr.app || {}; | |
// Define site values | |
grr.app.baseUrl = ''; // App is responsible to set this up | |
/** | |
* Load a GRR Module and start it | |
*/ | |
grr.app.load = function(module) { | |
goForIt = new Function('grr.' + module + '.start()'); | |
goForIt(); | |
} | |
$(document).ready(function(){ | |
grr.app.load('forms'); | |
grr.app.load('participant'); | |
if ($('a.fancy-iframe').length > 0) | |
$('a.fancy-iframe').fancybox({ | |
'width' : '75%', | |
'height' : '75%', | |
'autoScale' : false, | |
'transitionIn' : 'none', | |
'transitionOut' : 'none', | |
'type' : 'iframe' | |
}); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define Participant namespace | |
grr.participant = grr.participant || {}; | |
// Slideshow Internval | |
grr.participant.slideShowInterval = null; | |
// Time Interval | |
grr.participant.slideShowIntervalTime = 4000; | |
// Participant Entries | |
grr.participant.entries = new Array(); | |
// Current active entry | |
grr.participant.currentEntry = 0; | |
// Gallery Thumbs container | |
grr.participant.thumbsContainer = '#entry-list'; | |
/** | |
* Participant Startup | |
*/ | |
grr.participant.start = function() { | |
grr.participant.gallerySetup(); | |
} | |
/** | |
* Gallery Setup | |
*/ | |
grr.participant.gallerySetup = function() { | |
if (typeof window.participant_entries === 'undefined') | |
window.participant_entries = new Array(); | |
// Get entries | |
grr.participant.entries = window.participant_entries; | |
// If we have entries | |
if (grr.participant.entries.length > 0) { | |
// Add Thumbs | |
grr.participant.galleryAddThumbs(); | |
// Setup Prev/Next links | |
$('#entry-btn-prev').bind('click', grr.participant.galleryPrevEntry); | |
$('#entry-btn-next').bind('click', grr.participant.galleryNextEntry); | |
$('#entry-btn-slideshow').bind('click', grr.participant.gallerySlideshowHandler); | |
$('#readMore').find('a').bind('click', grr.participant.galleryToggleDescription); | |
grr.participant.galleryDisplayEntry(0); | |
} | |
} | |
/** | |
* Gallery - Displays an entry | |
*/ | |
grr.participant.galleryDisplayEntry = function(entryIndex) { | |
if (grr.participant.entries.length > 0) { | |
grr.participant.currentEntry = entryIndex | |
var currentEntry = grr.participant.entries[entryIndex]; | |
$('#entry-preview-contents').fadeOut('slow', function() { | |
// Set Entry Title | |
$('#entry-title').html(currentEntry.title); | |
// Set Entry Description | |
$('#entry-description').removeClass(); | |
$('#entry-description').css({'display': 'none'}); | |
$('#entry-description').html(currentEntry.description); | |
// Set Entry Participant | |
$('#entry-participant').text('Submitted by ' + currentEntry.participantFullName); | |
// Cleanup entry-content | |
$('#entry-content').html('<!-- -->'); | |
// Setup contents based on whether the entry is an image or a video | |
if (currentEntry.mediaType == 'image') { | |
$('#entry-content').html($('<img>').attr('src', currentEntry.fullURL).attr('alt', currentEntry.title)); | |
} | |
else { | |
// Add a temporary container for the swf object | |
$('#entry-content').append($('<div>').attr('id', 'entry-content-video')); | |
// Add SWF object | |
swfobject.embedSWF(currentEntry.fullURL, 'entry-content-video', '452', '453', '9.0.0'); | |
} | |
// Fade in the contents | |
$('#entry-preview-contents').fadeIn('slow'); | |
}); | |
} | |
} | |
/** | |
* Add Thumbs links | |
*/ | |
grr.participant.galleryAddThumbs = function() { | |
// Make sure we have entries | |
if (grr.participant.entries.length > 0) { | |
// Iterate through entries, add thumbs and preload images | |
$.each(grr.participant.entries, function(entryID, entry) { | |
var liElement = $('<li>'); | |
var aElement = $('<a>').attr('href', '#').attr('rel', entryID).bind('click', grr.participant.galleryThumbHandler); | |
var imgElement = $('<img>').attr('src', entry.thumbURL).attr('alt', entry.title).attr('width', 72).attr('height', 72); | |
$(grr.participant.thumbsContainer).append(liElement.append(aElement.append(imgElement))); | |
// Preload image if necessary | |
if (entry.mediaType == 'image') { | |
var fullImage = new Image(); | |
fullImage.src = entry.fullURL; | |
} | |
}); | |
} | |
} | |
/** | |
* Thumb click handler | |
*/ | |
grr.participant.galleryThumbHandler = function() { | |
grr.participant.galleryDisplayEntry(parseInt($(this).attr('rel'))); | |
return false; | |
} | |
/** | |
* Gallery - Next handler | |
*/ | |
grr.participant.galleryNextEntry = function() { | |
// Check if we are on the last thumb | |
if (grr.participant.entries[grr.participant.currentEntry].isLast) | |
{ | |
// Click Next | |
} | |
else | |
{ | |
grr.participant.currentEntry++; | |
grr.participant.galleryDisplayEntry(grr.participant.currentEntry); | |
} | |
return false; | |
} | |
/** | |
* Gallery - Prev handler | |
*/ | |
grr.participant.galleryPrevEntry = function() { | |
// Check if we are on the first thumb | |
if (grr.participant.entries[grr.participant.currentEntry].isFirst) { | |
// Click Prev | |
} | |
else { | |
grr.participant.currentEntry--; | |
grr.participant.galleryDisplayEntry(grr.participant.currentEntry); | |
} | |
return false; | |
} | |
/** | |
* Gallery - Slideshow Handler | |
*/ | |
grr.participant.gallerySlideshowHandler = function() { | |
if ($(this).hasClass('stopped')) { | |
grr.participant.slideShowInterval = setInterval('grr.participant.gallerySlideshow()', grr.participant.slideShowIntervalTime); | |
$(this).removeClass('stopped').addClass('playing'); | |
$(this).text('STOP SLIDESHOW'); | |
} | |
else { | |
clearInterval(grr.participant.slideShowInterval); | |
$(this).removeClass('playing').addClass('stopped'); | |
$(this).text('PLAY SLIDESHOW'); | |
} | |
return false; | |
} | |
/** | |
* Gallery - Slideshow | |
*/ | |
grr.participant.gallerySlideshow = function() { | |
if (grr.participant.entries[grr.participant.currentEntry].isLast) | |
grr.participant.currentEntry = 0; | |
else | |
grr.participant.currentEntry++; | |
grr.participant.galleryDisplayEntry(grr.participant.currentEntry); | |
} | |
/** | |
* Gallery - Toggle Description On/Off | |
*/ | |
grr.participant.galleryToggleDescription = function() { | |
if ($('#entry-description').hasClass('active')) { | |
$('#entry-description').slideUp('slow'); | |
$('#entry-description').removeClass('active'); | |
} | |
else { | |
$('#entry-description').addClass('active'); | |
$('#entry-description').slideDown('slow'); | |
$('#entry-description').addClass('active'); | |
} | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* Base Admin Controller | |
* | |
*/ | |
class GRR_Admin_Controller extends CI_Controller | |
{ | |
/** | |
* Assets (JS/CSS) from the Controllers | |
* | |
* @var array | |
*/ | |
public $assets = array(); | |
/** | |
* JavaScript Variables | |
* | |
* @var array | |
*/ | |
public $js_vars = array(); | |
/** | |
* JavaScript DOM Ready code | |
* | |
* @var array | |
*/ | |
public $dom_ready = array(); | |
/** | |
* Global View Variables | |
* | |
* @var array | |
*/ | |
public $public_vars = array(); | |
/** | |
* Local View Variables | |
* | |
* @var array | |
*/ | |
public $local_vars = array(); | |
/** | |
* Page Titles | |
* | |
* @var array | |
*/ | |
public $page_titles = array(); | |
/** | |
* Page CSS ID | |
* | |
* @var array | |
*/ | |
public $page_id = array(); | |
/** | |
* Page CSS Classes | |
* | |
* @var array | |
*/ | |
public $page_classes = array(); | |
/** | |
* Current user is logged in? | |
* | |
* @var boolean | |
*/ | |
private $user_is_logged_in = FALSE; | |
/** | |
* Class Constructor | |
*/ | |
function __construct() | |
{ | |
// Call Parent Constructor | |
parent::__construct(); | |
// Site Page Title | |
$this->page_titles[] = 'Admin Panel - Contest'; | |
// Set user state | |
$this->user_is_logged_in = ($this->session->userdata('admin_logged_in') === TRUE); | |
// Initialize array with assets we use site wide | |
$this->assets['css'][] = array( | |
'yui.css', | |
'style_admin.css' | |
); | |
$this->assets['js'][] = array( | |
'jquery/jquery-1.5.1.min.js', // jQuery Framework | |
'jquery/jquery-ui-1.8.10.custom.min.js', // jQuery UI | |
); | |
if (APPLICATION_ENV == 'development') $this->output->enable_profiler(TRUE); | |
} | |
/** | |
* User is logged in? | |
* | |
* @return boolean | |
*/ | |
public function is_logged_in() | |
{ | |
return $this->user_is_logged_in; | |
} | |
/** | |
* Prepare Javascript for inclusion | |
*/ | |
function prepare_javascript() | |
{ | |
// Define GR Javascript Namespace | |
$this->js_vars[] = 'window.grr = window.grr || {};'; | |
$this->js_vars[] = 'grr.app = grr.app || {};'; | |
// Set Base URL | |
$this->js_vars[] = "grr.app.baseUrl = '" . base_url() . "'"; | |
// Get Javascript Include | |
$this->public_vars['static_js'] = $this->load->view('admin/layout/_include_javascript', array('js_vars' => $this->js_vars, 'dom_ready' => $this->dom_ready), TRUE); | |
} | |
/** | |
* Prepare the site page title | |
*/ | |
function prepare_page_title() | |
{ | |
krsort($this->page_titles); | |
$this->public_vars['page_title'] = implode($this->page_titles, $this->config->item('grr_site_default_title_separator')); | |
} | |
/** | |
* Prepare assets for inclusion | |
*/ | |
function prepare_assets() | |
{ | |
// Initialize assets variables | |
$this->public_vars['css_assets'] = ''; | |
$this->public_vars['js_assets'] = ''; | |
// Load Assets Helper | |
$this->load->helper('assets'); | |
// Make sure there are css assets first, then add them | |
if (count($this->assets['css']) > 0) | |
foreach($this->assets['css'] as $asset) | |
$this->public_vars['css_assets'].= asset_link($asset, 'css'); | |
// Make sure there are js assets first, then add them | |
if (count($this->assets['js']) > 0) | |
foreach($this->assets['js'] as $asset) | |
$this->public_vars['js_assets'].= asset_link($asset, 'js'); | |
} | |
/** | |
* Renders main menu | |
*/ | |
function render_main_menu() | |
{ | |
$this->public_vars['main_menu'] = $this->load->view('admin/layout/main_menu', $this->public_vars, TRUE); | |
} | |
/** | |
* Renders footer menu | |
*/ | |
function render_footer_menu() | |
{ | |
$this->public_vars['footer_menu'] = ''; | |
} | |
/** | |
* Renders page | |
*/ | |
function render_page() | |
{ | |
// Some renders might need this early on | |
$this->public_vars['is_logged_in'] = $this->is_logged_in(); | |
// Prepare assets(javascript/css) for inclusion | |
$this->prepare_assets(); | |
// Prepare javascript | |
$this->prepare_javascript(); | |
// Generates the Page Title | |
$this->prepare_page_title(); | |
// Renders Main and Footer menu | |
$this->render_main_menu(); | |
$this->render_footer_menu(); | |
$this->public_vars['page_id'] = $this->page_id; | |
$this->public_vars['page_classes'] = implode(' ', $this->page_classes); | |
// Renders the main layout | |
$this->load->view('admin/layout/main.php', $this->public_vars); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* Base Controller | |
* | |
*/ | |
class GRR_Controller extends CI_Controller | |
{ | |
/** | |
* Assets (JS/CSS) from the Controllers | |
* | |
* @var array | |
*/ | |
public $assets = array(); | |
/** | |
* JavaScript Variables | |
* | |
* @var array | |
*/ | |
public $js_vars = array(); | |
/** | |
* JavaScript DOM Ready code | |
* | |
* @var array | |
*/ | |
public $dom_ready = array(); | |
/** | |
* Global View Variables | |
* | |
* @var array | |
*/ | |
public $public_vars = array(); | |
/** | |
* Local View Variables | |
* | |
* @var array | |
*/ | |
public $local_vars = array(); | |
/** | |
* Page Titles | |
* | |
* @var array | |
*/ | |
public $page_titles = array(); | |
/** | |
* Page CSS ID | |
* | |
* @var array | |
*/ | |
public $page_id = array(); | |
/** | |
* Page CSS Classes | |
* | |
* @var array | |
*/ | |
public $page_classes = array(); | |
/** | |
* Class Constructor | |
*/ | |
function __construct() | |
{ | |
// Call Parent Constructor | |
parent::__construct(); | |
// Site Page Title | |
$this->page_titles[] = $this->config->item('grr_site_default_title'); | |
// Initialize array with assets we use site wide | |
$this->assets['css'][] = array( | |
'styles.css' | |
); | |
$this->assets['js'][] = array( | |
'jquery/jquery-1.5.1.min.js', // jQuery Framework | |
'jquery/jquery-ui-1.8.10.custom.min.js', // jQuery UI | |
'swfobject/swfobject.js', // jQuery UI | |
'jquery.validation/jquery.metadata.js', // jQuery Metadata | |
'jquery.validation/jquery.validate.min.js', // jQuery Validate Plugin | |
'gr.js', // GR JS | |
'gr.forms.js', // GRR Forms Validation | |
'gr.participant.js', // GRR Participant | |
'jquery.cross-slide.min.js', // minislideshows | |
'fancybox/jquery.mousewheel-3.0.4.pack.js', | |
'fancybox/jquery.fancybox-1.3.4.pack.js', | |
); | |
} | |
/** | |
* Prepare Javascript for inclusion | |
*/ | |
function prepare_javascript() | |
{ | |
// Define GR Javascript Namespace | |
$this->js_vars[] = 'window.grr = window.grr || {};'; | |
$this->js_vars[] = 'grr.app = grr.app || {};'; | |
// Set Base URL | |
$this->js_vars[] = "grr.app.baseUrl = '" . base_url() . "'"; | |
// Get Javascript Include | |
$data= array('js_vars' => $this->js_vars, | |
'dom_ready' => $this->dom_ready); | |
$this->public_vars['static_js'] = $this->load->view('layout/_include_javascript',$data,TRUE); | |
} | |
/** | |
* Prepare the site page title | |
*/ | |
function prepare_page_title() | |
{ | |
krsort($this->page_titles); | |
$this->public_vars['page_title'] = implode( | |
$this->page_titles, | |
$this->config->item('grr_site_default_title_separator')); | |
} | |
/** | |
* Prepare assets for inclusion | |
*/ | |
function prepare_assets() | |
{ | |
// Initialize assets variables | |
$this->public_vars['css_assets'] = ''; | |
$this->public_vars['js_assets'] = ''; | |
// Load Assets Helper | |
$this->load->helper('assets'); | |
// Make sure there are css assets first, then add them | |
if (count($this->assets['css']) > 0) | |
foreach($this->assets['css'] as $asset) | |
$this->public_vars['css_assets'].= asset_link($asset, 'css'); | |
// Make sure there are js assets first, then add them | |
if (count($this->assets['js']) > 0) | |
foreach($this->assets['js'] as $asset) | |
$this->public_vars['js_assets'].= asset_link($asset, 'js'); | |
} | |
/** | |
* Renders main menu | |
*/ | |
function render_main_menu() | |
{ | |
$this->public_vars['main_menu'] = $this->load->view( | |
'layout/main_menu', array(), TRUE); | |
} | |
/** | |
* Renders footer menu | |
*/ | |
function render_footer_menu() | |
{ | |
$this->public_vars['footer_menu'] = $this->load->view( | |
'layout/footer_menu', array(), TRUE); | |
} | |
/** | |
* Renders page | |
*/ | |
function render_page() | |
{ | |
// Prepare assets(javascript/css) for inclusion | |
$this->prepare_assets(); | |
// Prepare javascript | |
$this->prepare_javascript(); | |
// Generates the Page Title | |
$this->prepare_page_title(); | |
// Renders Main and Footer menu | |
$this->render_main_menu(); | |
$this->render_footer_menu(); | |
$this->public_vars['page_id'] = $this->page_id; | |
$this->public_vars['page_classes'] = implode(' ', $this->page_classes); | |
// Renders the main layout | |
$this->load->view('layout/main.php', $this->public_vars); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* Email Library | |
* | |
*/ | |
class GRR_Email extends CI_Email | |
{ | |
var $CI; | |
/** | |
* Class constructor | |
* | |
* @param array $rules | |
*/ | |
function __construct($config = array()) | |
{ | |
parent::__construct($config); | |
$this->CI =& get_instance(); | |
// Define Default From field | |
$this->from($this->CI->config->item('grr_site_email_from_email'), | |
$this->CI->config->item('grr_site_email_from_name')); | |
} | |
/** | |
* Send Participation Email | |
* | |
* @param array $participant | |
*/ | |
function send_participant_email($participant) | |
{ | |
$this->to($participant['participant_email']); | |
$this->subject('<Company> Launches Promotion'); | |
$this->message($this->CI->load->view('email/participant/participant_html', $participant, TRUE)); | |
$this->send(); | |
} | |
/** | |
* Send Winner Email | |
* | |
* @param array $participant | |
*/ | |
function send_winner_email($participant) | |
{ | |
$this->to($participant['participant_email']); | |
$this->subject('<Company> Launches Promotion'); | |
$this->message($this->CI->load->view('email/winner/winner_html', $participant, TRUE)); | |
$this->send(); | |
} | |
/** | |
* Notify Participant that his/her entry was received | |
* | |
* @param array $data | |
*/ | |
function notify_participant_entry_received($data) | |
{ | |
$this->to($data['participant_email']); | |
$this->subject('<Company> Has Received Your Power of Inspiration Entry'); | |
$this->message($this->CI->load->view('email/participant/participant_entry_received', $data, TRUE)); | |
$this->send(); | |
} | |
/** | |
* Send Admin Email | |
* | |
* @param array $participant | |
*/ | |
function send_admin_email($participant) | |
{ | |
$this->to('user@domain.com'); | |
$this->subject('[Company] New participant'); | |
$this->message($this->CI->load->view('email/administrator/administrator_html', $participant, TRUE)); | |
$this->send(); | |
} | |
/** | |
* Send Email to Admin with Video Info | |
*/ | |
function notify_admin_entry_video($data) | |
{ | |
$this->to('user@domain.com'); | |
$this->subject('ALERT! <Company>, Contest: New Entry Submitted'); | |
$this->message($this->CI->load->view('email/administrator/new_video_html', $data, TRUE)); | |
$this->send(); | |
} | |
/** | |
* Send Email to Admin with YouTube URL Info | |
*/ | |
function notify_admin_entry_youtube($data) | |
{ | |
$this->to('user@domain.com'); | |
$this->subject('ALERT! <Company>, Contest: New Entry Submitted'); | |
$this->message($this->CI->load->view('email/administrator/new_youtube_html', $data, TRUE)); | |
$this->send(); | |
} | |
/** | |
* Send Email to Admin with Entry Image Info | |
*/ | |
function notify_admin_entry_image($data) | |
{ | |
$this->to('user@domain.com'); | |
$this->subject('ALERT! <Company>, Contest: New Entry Submitted'); | |
$this->message($this->CI->load->view('email/administrator/new_image_html', $data, TRUE)); | |
$this->send(); | |
} | |
/** | |
* Send Remember Me Hash to Participant | |
*/ | |
function send_participant_hash($participant) | |
{ | |
$this->to($participant['participant_email']); | |
$this->subject('[Contest] Your activation key'); | |
$this->message($this->CI->load->view('email/participant/participant_hash_html', $participant, TRUE)); | |
$this->send(); | |
} | |
/** | |
* Notify Participant that files were approved | |
* | |
* @param array $data | |
*/ | |
function notify_participant_approved_files($data) | |
{ | |
$this->to($data['participant_email']); | |
$this->subject('<Company> Has Approved Your Entry'); | |
$this->message($this->CI->load->view('email/participant/participant_entries_approved_html', $data, TRUE)); | |
$this->send(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* Form Validation | |
* | |
*/ | |
class GRR_Form_validation extends CI_Form_validation | |
{ | |
/** | |
* Class constructor | |
* | |
* @param array $rules | |
*/ | |
function __construct($rules = array()) | |
{ | |
parent::__construct($rules); | |
$this->set_error_delimiters('<label class="error" generated="true">', '</label>'); | |
} | |
/** | |
* Check if the current email is in the list of blocked emails | |
* | |
* @param string $email | |
* @return boolean | |
*/ | |
function blocked_email_domains($email) | |
{ | |
$tmp = explode('@', $email); | |
if (count($tmp) == 2) $domain = $tmp[1]; | |
else $domain = 'blocked.domain'; | |
$blocked_domains = $this->CI->config->item('grr_blocked_domains'); | |
if (is_array($blocked_domains)) | |
{ | |
foreach ($blocked_domains as $blocked_domain) | |
{ | |
if (strtolower($domain) == strtolower($blocked_domain)) | |
{ | |
$this->set_message(__FUNCTION__, 'Please use a different email address.'); | |
return FALSE; | |
} | |
} | |
} | |
return TRUE; | |
} | |
/** | |
* Check if the current email is unique or not already registered | |
* | |
* @param string $email | |
* @return boolean | |
*/ | |
function unique_email($email) | |
{ | |
$this->CI->load->model('participant_model'); | |
$email_exists = $this->CI->participant_model->email_exists($email); | |
if ( ! $email_exists) | |
return TRUE; | |
$this->set_message(__FUNCTION__, 'This email address is already in use.'); | |
return FALSE; | |
} | |
/** | |
* Check if the current email is unique or not already registered | |
* | |
* @param string $email | |
* @return boolean | |
*/ | |
function email_exists($email) | |
{ | |
$this->CI->load->model('participant_model'); | |
$email_exists = $this->CI->participant_model->email_exists($email); | |
if ( ! $email_exists) | |
{ | |
$this->set_message(__FUNCTION__, 'This email address does not exist.'); | |
return FALSE; | |
} | |
return TRUE; | |
} | |
/** | |
* Check if the current url is a valid url and a valid youtube url | |
* | |
* @param string $url | |
* @return boolean | |
*/ | |
function valid_youtube_url($url) | |
{ | |
// Make sure the str is a valid url | |
if (filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) === FALSE) | |
{ | |
$this->set_message(__FUNCTION__, 'Please enter a valid url.'); | |
return FALSE; | |
} | |
// Make sure the url is a valid youtube url | |
$url_parts = parse_url($url); | |
if (stristr($url_parts['host'], 'youtube') === FALSE) | |
{ | |
$this->set_message(__FUNCTION__, 'Please enter a valid YouTube video url.'); | |
return FALSE; | |
} | |
// Make the youtube url does actually have info after the hostname | |
if ( ! isset($url_parts['query']) || (trim($url_parts['query']) == '')) | |
{ | |
$this->set_message(__FUNCTION__, 'Please enter a valid YouTube video url.'); | |
return FALSE; | |
} | |
// Make the youtube url does actually have video info | |
parse_str($url_parts['query'], $query_string_parts); | |
if ( ! isset($query_string_parts['v']) || (trim($query_string_parts['v']) == '')) | |
{ | |
$this->set_message(__FUNCTION__, 'Please enter a valid YouTube video url.'); | |
return FALSE; | |
} | |
// Validate the YouTube video, make sure we can actually get the embed code | |
$this->CI->load->library('GRR_Zend'); | |
$this->CI->grr_zend->load('Zend/Gdata/YouTube'); | |
$yt = new Zend_Gdata_YouTube(); | |
$video_entry = $yt->getVideoEntry($query_string_parts['v']); | |
if ($video_entry->getFlashPlayerUrl() == NULL) | |
{ | |
$this->set_message(__FUNCTION__, 'Please use a YouTube video with embedding enabled.'); | |
return FALSE; | |
} | |
return TRUE; | |
} | |
/** | |
* Check how many words are in a string and make sure it's less than | |
* a given number | |
* | |
* @param string $value | |
* @param integer $count | |
* @return boolean | |
*/ | |
function word_count($value, $count = 100) | |
{ | |
if (count(str_word_count($value, 1)) > 100) | |
{ | |
$this->set_message(__FUNCTION__, 'Please enter less than ' . $count . ' words.'); | |
return FALSE; | |
} | |
return TRUE; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* Image Resizer | |
*/ | |
class GRR_Resizer | |
{ | |
/** | |
* CI Front Controller Instance | |
* | |
* @var CI_Controller | |
*/ | |
var $CI; | |
/** | |
* List of errors | |
* | |
* @var array | |
*/ | |
var $errors = array(); | |
/** | |
* Path to the uploads folder | |
* | |
* @var array | |
*/ | |
var $uploads_path = ''; | |
/** | |
* Class constructor | |
* | |
* @param array $rules | |
*/ | |
function __construct() | |
{ | |
$this->CI =& get_instance(); | |
$this->uploads_path = str_replace("\\", "/", FCPATH . 'uploads'); | |
} | |
function get_errors() | |
{ | |
return $this->errors; | |
} | |
/** | |
* | |
* @param array $file | |
* @param <type> $size | |
* @param <type> $type | |
* @return <type> | |
*/ | |
function resize($file, $size = '96x96', $type = 'relative') | |
{ | |
// Reset errors array | |
$this->errors = array(); | |
// Make sure the file exists | |
$source_file = $this->uploads_path . '/source/' . $file['file_name']; | |
if ($source_file) | |
{ | |
// Check the size and get the requested width and height | |
if (is_string($size)) | |
$size = explode('x', $size); | |
$width = (int)$size[0]; | |
$height = (int)$size[1]; | |
// Check if this file was already resized | |
$destination_path = $this->uploads_path . "/{$width}x{$height}"; | |
$destination_file = $destination_path . "/" . $file['file_name']; | |
if ( ! file_exists($destination_file)) | |
{ | |
// Check destination path and create it if necessary | |
if ( ! is_dir($destination_path)) | |
{ | |
if ( ! mkdir($destination_path, 0777)) | |
{ | |
$this->errors[] = 'Error while re-creating resize folders.'; | |
return FALSE; | |
} | |
} | |
// Resize the image | |
if ($type == 'relative') | |
$this->resize_relative($source_file, $destination_file, $width, $height); | |
else | |
$this->resize_absolute($source_file, $destination_file, $width, $height); | |
} | |
else | |
return $destination_file; | |
} | |
else | |
{ | |
// the file doesn't exists, return false | |
$this->errors[] = 'The given file does not exists.'; | |
return FALSE; | |
} | |
} | |
/** | |
* Resize an image using a relative width and height | |
* (resized images meets either the max width and/or height) | |
* | |
* @param string $source_file | |
* @param string $dest_file | |
* @param integer $dest_width | |
* @param integer $dest_height | |
* @return boolean | |
*/ | |
function resize_relative($source_file, $dest_file, $dest_width, $dest_height) | |
{ | |
// Load CI Image Library | |
$config['image_library'] = 'gd2'; | |
$config['source_image'] = $source_file; | |
$config['new_image'] = $dest_file; | |
$config['width'] = $dest_height; | |
$config['height'] = $dest_height; | |
$config['create_thumb'] = TRUE; | |
$config['thumb_marker'] = ''; | |
$config['maintain_ratio'] = TRUE; | |
// Load Library | |
$this->CI->load->library('image_lib'); | |
$this->CI->image_lib->initialize($config); | |
// Resize image | |
$this->CI->image_lib->resize(); | |
$this->CI->image_lib->clear(); | |
} | |
/** | |
* Resize an image using an absolute width and height | |
* (resized images meets requested width and height) | |
* | |
* @param string $source_file | |
* @param string $dest_file | |
* @param integer $dest_width | |
* @param integer $dest_height | |
* @param integer $jpg_quality | |
* @return boolean | |
*/ | |
function resize_absolute($source_file, $dest_file, $dest_width, $dest_height, $jpg_quality = 80) | |
{ | |
$result = array(); | |
if ( ! file_exists($source_file)) return FALSE; | |
if ( ! function_exists('getimagesize')) | |
return FALSE; | |
else | |
list($src_width, $src_height, $file_type, ) = getimagesize($source_file); | |
switch ($file_type) | |
{ | |
case 1 : | |
$src_handler = imagecreatefromgif($source_file); | |
break; | |
case 2 : | |
$src_handler = imagecreatefromjpeg($source_file); | |
break; | |
case 3 : | |
$src_handler = imagecreatefrompng($source_file); | |
break; | |
default : | |
return FALSE; | |
} | |
if ( ! $src_handler) return FALSE; | |
// Defining Shape | |
if ($src_height < $src_width) | |
{ | |
// Source has a horizontal Shape | |
$ratio = (double)($src_height / $dest_height); | |
$copy_width = round($dest_width * $ratio); | |
if ($copy_width > $src_width) | |
{ | |
$ratio = (double)($src_width / $dest_width); | |
$copy_width = $src_width; | |
$copy_height = round($dest_height * $ratio); | |
$x_offset = 0; | |
$y_offset = round(($src_height - $copy_height) / 2); | |
} | |
else | |
{ | |
$copy_height = $src_height; | |
$x_offset = round(($src_width - $copy_width) / 2); | |
$y_offset = 0; | |
} | |
} | |
else | |
{ | |
// Source has a Vertical Shape | |
$ratio = (double)($src_width / $dest_width); | |
$copy_height = round($dest_height * $ratio); | |
if ($copy_height > $src_height) | |
{ | |
$ratio = (double)($src_height / $dest_height); | |
$copy_height = $src_height; | |
$copy_width = round($dest_width * $ratio); | |
$x_offset = round(($src_width - $copy_width) / 2); | |
$y_offset = 0; | |
} | |
else | |
{ | |
$copy_width = $src_width; | |
$x_offset = 0; | |
$y_offset = round(($src_height - $copy_height) / 2); | |
} | |
} | |
// Let's figure it out what to use | |
if (function_exists('imagecreatetruecolor')) | |
{ | |
$create = 'imagecreatetruecolor'; | |
$copy = 'imagecopyresampled'; | |
} | |
else | |
{ | |
$create = 'imagecreate'; | |
$copy = 'imagecopyresized'; | |
} | |
$dst_handler = $create($dest_width, $dest_height); | |
$copy($dst_handler, $src_handler, 0, 0, $x_offset, $y_offset, $dest_width, $dest_height, $copy_width, $copy_height); | |
switch ($file_type) | |
{ | |
case 1 : | |
@imagegif($dst_handler, $dest_file); | |
$result = TRUE; | |
break; | |
case 2 : | |
// Code taken from CI Image_lib Library | |
// PHP 4.4.1 bug #35060 - workaround | |
if (phpversion() == '4.4.1') @touch($dest_file); | |
@imagejpeg($dst_handler, $dest_file, $jpg_quality); | |
$result = TRUE; | |
break; | |
case 3 : | |
@imagepng($dst_handler, $dest_file); | |
$result = TRUE; | |
break; | |
default : | |
return FALSE; | |
} | |
// Kill the file handlers | |
imagedestroy($src_handler); | |
imagedestroy($dst_handler); | |
// Set the file to 777 -- From CI Image_lib Library | |
@chmod($dest_file, DIR_WRITE_MODE); | |
return $result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Microsite Controller | |
* | |
*/ | |
class Microsite extends GRR_Controller | |
{ | |
/** | |
* Controller Constructor | |
*/ | |
function __construct() | |
{ | |
parent::__construct(); | |
// Load Email Library | |
$this->load->library('email'); | |
// Load file model | |
$this->load->model('file_model'); | |
// Load participant model | |
$this->load->model('participant_model'); | |
} | |
/** | |
* Index | |
*/ | |
function index() | |
{ | |
// Make sure we have participant data in a cookie | |
if ( ! $this->session->userdata('ID_participant')) | |
redirect('registration'); | |
$this->local_vars['show_terms'] = 'no'; | |
// Did this participant already accept the terms? | |
if ($this->session->userdata('participant_accepted_terms') == 'no') | |
{ | |
// nope, he/she needs to | |
$this->local_vars['show_terms'] = 'yes'; | |
} | |
else | |
{ | |
// yeap, remove the terms validation | |
// @TODO This doesn't look quite right, re-check later if you have the time | |
unset($this->form_validation->_config_rules['submit_entry'][2]); | |
unset($this->form_validation->_config_rules['submit_entry_youtube_url'][3]); | |
unset($this->form_validation->_config_rules['submit_entry_youtube_id'][3]); | |
} | |
if ($this->input->post('btn_submit') !== FALSE) | |
{ | |
// Check if we need to validate a youtube url | |
if ($this->input->post('youtube_url') != '') | |
{ | |
if ($this->form_validation->run('submit_entry_youtube_url')) | |
{ | |
// Get video ID from url | |
$url_parts = parse_url($this->input->post('youtube_url', TRUE)); | |
parse_str($url_parts['query'], $query_string_parts); | |
// Load required libraries | |
$this->load->library('GRR_Zend'); | |
$this->grr_zend->load('Zend/Gdata/YouTube'); | |
// Get entry info | |
$video_title = $this->input->post('entry_title', TRUE); | |
$video_description = $this->input->post('what_inspires_you', TRUE); | |
// Get Video Entry | |
$yt = new Zend_Gdata_YouTube(); | |
$video_entry = $yt->getVideoEntry($query_string_parts['v']); | |
// Get data to save in the DB | |
$video_thumbs = $video_entry->getVideoThumbnails(); | |
$video_links = $video_entry->getLink(); | |
$video_data = array( | |
'ID_participant' => $this->session->userdata('ID_participant'), | |
'video_title' => $video_title, | |
'video_description' => $video_description, | |
'video_id' => $video_entry->getVideoID(), | |
'video_thumb_0' => $video_thumbs[0]['url'], | |
'video_thumb_1' => $video_thumbs[1]['url'], | |
'video_thumb_2' => $video_thumbs[2]['url'], | |
'video_thumb_3' => $video_thumbs[3]['url'], | |
'video_flashplayer_url' => $video_entry->getFlashPlayerUrl(), | |
'video_link' => $video_links[0]->getHref(), | |
'video_uploadedthru' => 'url' | |
); | |
// Save the video to the DB | |
$this->file_model->add_video($video_data); | |
// Update the cookie, the user accepted the terms | |
$this->session->set_userdata('participant_accepted_terms', 'yes'); | |
// Enable participant notification if checked | |
if ($this->input->post('notify_me', TRUE) == 'yes') | |
$this->participant_model->enable_notification($this->session->userdata('ID_participant')); | |
// Add participant info for the notification email | |
$video_data = array_merge($video_data, array( | |
'participant_firstname' => $this->session->userdata('participant_firstname'), | |
'participant_lastname' => $this->session->userdata('participant_lastname'), | |
'participant_email' => $this->session->userdata('participant_email') | |
)); | |
// Notify Participant | |
$this->email->notify_participant_entry_received($video_data); | |
// Notify Administrators | |
$this->email->notify_admin_entry_youtube($video_data); | |
// Set flash message in case we are going to use it | |
$this->session->set_flashdata('messages', $this->load->view('microsite/upload_success', array(), TRUE)); | |
// Redirect to microsite again | |
redirect('microsite'); | |
} | |
} | |
// Check if we need to validate a youtube ID | |
elseif ($this->input->post('youtube_video_id') != '') | |
{ | |
if ($this->form_validation->run('submit_entry_youtube_id')) | |
{ | |
// Load required libraries | |
$this->load->library('GRR_Zend'); | |
$this->grr_zend->load('Zend/Gdata/YouTube'); | |
// Get entry info | |
$video_title = $this->input->post('entry_title', TRUE); | |
$video_description = $this->input->post('what_inspires_you', TRUE); | |
// We need to auth in order to update the video | |
$httpClient = $this->_get_youtube_http_client(); | |
$developerKey = $this->config->item('grr_youtube_developer_key'); | |
$applicationId = 'Testing'; | |
$clientId = 'Testing'; | |
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey); | |
// Get Video Entry | |
$video_entry = $yt->getVideoEntry($this->input->post('youtube_video_id', TRUE), NULL, TRUE); | |
// Get data to save in the DB | |
$video_thumbs = $video_entry->getVideoThumbnails(); | |
$video_links = $video_entry->getLink(); | |
$video_data = array( | |
'ID_participant' => $this->session->userdata('ID_participant'), | |
'video_title' => $video_title, | |
'video_description' => $video_description, | |
'video_id' => $video_entry->getVideoID(), | |
'video_thumb_0' => $video_thumbs[0]['url'], | |
'video_thumb_1' => $video_thumbs[1]['url'], | |
'video_thumb_2' => $video_thumbs[2]['url'], | |
'video_thumb_3' => $video_thumbs[3]['url'], | |
'video_flashplayer_url' => $video_entry->getFlashPlayerUrl(), | |
'video_link' => $video_links[0]->getHref(), | |
'video_uploadedthru' => 'youtube_form' | |
); | |
// Save the video to the DB | |
$this->file_model->add_video($video_data); | |
// Update the video title and description | |
$put_url = $video_entry->getEditLink()->getHref(); | |
$video_entry->setVideoTitle($video_title); | |
$video_entry->setVideoDescription($video_description); | |
$yt->updateEntry($video_entry, $put_url); | |
// Update the cookie, the user accepted the terms | |
$this->session->set_userdata('participant_accepted_terms', 'yes'); | |
// Enable participant notification if checked | |
if ($this->input->post('notify_me', TRUE) == 'yes') | |
$this->participant_model->enable_notification($this->session->userdata('ID_participant')); | |
// Add participant info for the notification email | |
$video_data = array_merge($video_data, array( | |
'participant_firstname' => $this->session->userdata('participant_firstname'), | |
'participant_lastname' => $this->session->userdata('participant_lastname'), | |
'participant_email' => $this->session->userdata('participant_email') | |
)); | |
// Notify Participant | |
$this->email->notify_participant_entry_received($video_data); | |
// Notify Administrators | |
$this->email->notify_admin_entry_video($video_data); | |
// Set flash message in case we are going to use it | |
$this->session->set_flashdata('messages', $this->load->view('microsite/upload_success', array(), TRUE)); | |
// Redirect to microsite again | |
redirect('microsite'); | |
} | |
} | |
else | |
{ | |
// Load Upload Library | |
$this->load->library('upload'); | |
// Not any of the above, validate the entry and upload the file | |
if ($this->form_validation->run('submit_entry') AND $this->upload->do_upload('image_file')) | |
{ | |
// Get data from uploaded file | |
$upload_data = $this->upload->data(); | |
// Get File and Participant data | |
$file_data = array( | |
'ID_participant' => $this->session->userdata('ID_participant'), | |
'file_title' => $this->input->post('entry_title', TRUE), | |
'file_description' => $this->input->post('what_inspires_you', TRUE), | |
); | |
// Merge data to save in the db | |
$data = array_merge($file_data, $upload_data); | |
// Save to DB | |
$this->file_model->add($data); | |
// Update the cookie, the user accepted the terms | |
$this->session->set_userdata('participant_accepted_terms', 'yes'); | |
// Enable participant notification if checked | |
if ($this->input->post('notify_me', TRUE) == 'yes') | |
$this->participant_model->enable_notification($this->session->userdata('ID_participant')); | |
// Add participant info for the notification email | |
$data = array_merge($data, array( | |
'participant_firstname' => $this->session->userdata('participant_firstname'), | |
'participant_lastname' => $this->session->userdata('participant_lastname'), | |
'participant_email' => $this->session->userdata('participant_email') | |
)); | |
// Notify Participant | |
$this->email->notify_participant_entry_received($data); | |
// Notify Administrators | |
$this->email->notify_admin_entry_image($data); | |
// Set flash message in case we are going to use it | |
$this->session->set_flashdata('messages', $this->load->view('microsite/upload_success', array(), TRUE)); | |
// Redirect to microsite again | |
redirect('microsite'); | |
} | |
else | |
// If there are upload errors, send it back to the view | |
$this->local_vars['upload_errors'] = $this->upload->display_errors('<label class="error">', '</label>'); | |
} | |
} | |
// Page Title | |
$this->page_titles[] = 'Upload your photo or video!'; | |
// Set Page title and classes | |
$this->page_classes[] = 'microsite'; | |
// Load Forms Validation | |
$this->dom_ready[] = "grr.app.load('forms');"; | |
// Render content and page | |
$this->public_vars['content'] = $this->load->view('microsite/index', $this->local_vars, TRUE); | |
$this->render_page(); | |
} | |
/** | |
* Get YouTube upload form | |
*/ | |
function youtube_upload() | |
{ | |
// Load required libraries | |
$this->load->library('GRR_Zend'); | |
$this->grr_zend->load('Zend/Gdata/YouTube'); | |
$this->grr_zend->load('Zend/Gdata/YouTube/VideoEntry'); | |
$this->grr_zend->load('Zend/Gdata/AuthSub'); | |
$this->grr_zend->load('Zend/Gdata/App/Exception'); | |
$this->grr_zend->load('Zend/Gdata/ClientLogin'); | |
// Load assets helper | |
$this->load->helper('assets'); | |
$httpClient = $this->_get_youtube_http_client(); | |
$developerKey = $this->config->item('grr_youtube_developer_key'); | |
$applicationId = 'Testing'; | |
$clientId = 'Testing'; | |
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey); | |
// create a new VideoEntry object | |
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry(); | |
$myVideoEntry->setVideoTitle('Temporary Title'); | |
$myVideoEntry->setVideoDescription('Temporary Description'); | |
// The category must be a valid YouTube category! | |
$myVideoEntry->setVideoCategory('Autos'); | |
$myVideoEntry->setVideoPrivate('true'); | |
// Set keywords. Please note that this must be a comma-separated string | |
// and that individual keywords cannot contain whitespace | |
$myVideoEntry->SetVideoTags('cars, funny'); | |
$myVideoEntry->setVideoDeveloperTags(array( | |
'pID_' .$this->session->userdata('ID_participant') | |
)); | |
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken'; | |
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl); | |
$local_vars['token_value'] = $tokenArray['token']; | |
$local_vars['post_url'] = $tokenArray['url']; | |
// place to redirect user after upload | |
$local_vars['next_url'] = site_url('microsite/youtube_status/' . $this->session->userdata('ID_participant')); | |
$this->load->view('microsite/youtube_upload', $local_vars); | |
} | |
/** | |
* Handles YouTube response | |
*/ | |
function youtube_status() | |
{ | |
// Load assets helper | |
$this->load->helper('assets'); | |
// Make sure we have the Participant ID | |
if ($this->uri->segment(3) === FALSE) | |
{ | |
$this->load->view('microsite/youtube_error', array()); | |
return; | |
} | |
// Parse YouTube Query Response | |
parse_str($_SERVER['QUERY_STRING'], $response); | |
if (is_array($response) AND ($response['status'] == '200')) | |
{ | |
$local_vars['youtube_id'] = $response['id']; | |
$this->load->view('microsite/youtube_success', $local_vars); | |
return; | |
} | |
else | |
$this->load->view('microsite/youtube_error', array()); | |
return; | |
} | |
/** | |
* Returns an authenticated HTTP Client for YouTube | |
* | |
* @return Zend_Gdata_ClientLogin | |
*/ | |
function _get_youtube_http_client() | |
{ | |
// Load required libraries | |
$this->load->library('GRR_Zend'); | |
$this->grr_zend->load('Zend/Gdata/YouTube'); | |
$this->grr_zend->load('Zend/Gdata/YouTube/VideoEntry'); | |
$this->grr_zend->load('Zend/Gdata/AuthSub'); | |
$this->grr_zend->load('Zend/Gdata/App/Exception'); | |
$this->grr_zend->load('Zend/Gdata/ClientLogin'); | |
// Login user | |
$authenticationURL = 'https://www.google.com/accounts/ClientLogin'; | |
return Zend_Gdata_ClientLogin::getHttpClient( | |
$username = $this->config->item('grr_youtube_username'), | |
$password = $this->config->item('grr_youtube_password'), | |
$service = 'youtube', | |
$client = null, | |
$source = 'Contest', | |
$loginToken = null, | |
$loginCaptcha = null, | |
$authenticationURL); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* Participant Model | |
* | |
*/ | |
class Participant_model extends CI_Model | |
{ | |
/** | |
* MySQL Date Time Format | |
*/ | |
const MYSQL_DATETIME = 'Y-m-d H:i:s'; | |
/** | |
* Model Constructor | |
*/ | |
function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Inserts a new participant in the database | |
* | |
* @param array $data | |
* @return integer | |
*/ | |
function add($data) | |
{ | |
if ( ! isset($data['participant_is_active'])) | |
$data['participant_is_active'] = 'yes'; | |
if ( ! isset($data['participant_accepted_terms'])) | |
$data['participant_accepted_terms'] = 'no'; | |
if ( ! isset($data['participant_signedupon'])) | |
$data['participant_signedupon'] = date(self::MYSQL_DATETIME); | |
if ( ! isset($data['participant_updatedon'])) | |
$data['participant_updatedon'] = date(self::MYSQL_DATETIME); | |
$this->db->insert('participant', $data); | |
return $this->db->insert_id(); | |
} | |
/** | |
* Update participant data | |
* | |
* @param integer $ID_participant | |
* @param array $data | |
* @return integer | |
*/ | |
function update($ID_participant, $data) | |
{ | |
$this->db->where('ID_participant', $ID_participant); | |
$this->db->update('participant', $data); | |
return $this->db->affected_rows(); | |
} | |
/** | |
* Return data from DB | |
* | |
* @param array|string $where | |
* @param array $order | |
* @param array $limit | |
* @return array|boolean | |
*/ | |
function get_data($where, $order = NULL, $limit = NULL) | |
{ | |
$this->db->from('participant'); | |
$this->db->where($where); | |
if ( ! is_null($order)) | |
$this->db->order_by($order); | |
if ( ! is_null($limit)) | |
$this->db->limit($limit); | |
$results = $this->db->get(); | |
return ($results->num_rows() > 0) ? $results->result_array() : FALSE; | |
} | |
/** | |
* Generates a Site ID for the participant using his/her first and last name | |
* @param string $first_name | |
* @param string $last_name | |
* @return string | |
*/ | |
function generate_site_id($first_name, $last_name) | |
{ | |
// Lets see if first name was already taken | |
$this->db->where('participant_siteid', $first_name); | |
if ($this->db->count_all_results('participant') > 0) | |
{ | |
// it is, lets see if first and last name are taken too | |
$this->db->where('participant_siteid', $first_name . '_' . $last_name); | |
if ($this->db->count_all_results('participant') > 0) | |
{ | |
// it is, lets get some random number and concatenate it with first_name | |
return $first_name . '_' . rand(rand(50, 100), getrandmax()); | |
} | |
else | |
return $first_name . '_' . $last_name; | |
} | |
else | |
return $first_name; | |
} | |
/** | |
* Check if a given siteid exists | |
* | |
* @param string $siteid | |
* @return boolean | |
*/ | |
function site_exists($siteid) | |
{ | |
// Make sure siteid exists | |
$this->db->where('participant_siteid', $siteid); | |
return (($this->db->count_all_results('participant') > 0)); | |
} | |
/** | |
* Check if a given siteid exists and is valid | |
* | |
* @param string $siteid | |
* @return boolean | |
*/ | |
function site_is_valid($siteid) | |
{ | |
// Make sure siteid exists | |
if ($this->site_exists($siteid)) | |
{ | |
// it does, now make sure this siteid does has approved files | |
$this->db->where('participant_siteid', $siteid); | |
$this->db->where('file_isapproved', 'yes'); | |
$this->db->join('file', 'participant.ID_participant = file.ID_participant', 'left'); | |
$files = ($this->db->count_all_results('participant') > 0); | |
$this->db->where('participant_siteid', $siteid); | |
$this->db->where('video_isapproved', 'yes'); | |
$this->db->join('file_video', 'participant.ID_participant = file_video.ID_participant', 'left'); | |
$videos = ($this->db->count_all_results('participant') > 0); | |
return ($files OR $videos); | |
} | |
else | |
return FALSE; | |
} | |
/** | |
* Check if a given email address exists in the database | |
* | |
* @param string $email | |
* @return boolean | |
*/ | |
function email_exists($email) | |
{ | |
$this->db->where('participant_email', $email); | |
return ($this->db->count_all_results('participant') > 0); | |
} | |
/** | |
* Clean an string, replace spaces, avoid accented characters, and make it lowercase | |
* | |
* @param string $str | |
* @return string | |
*/ | |
function clear_input($str) | |
{ | |
// Replaces spaces by underscore | |
$str= str_replace(' ', '_', $str); | |
// Convert accented characters to "plain" characters | |
$str = convert_accented_characters($str); | |
// Make it lowercase | |
$str = strtolower($str); | |
return $str; | |
} | |
/** | |
* Enable participant notification when submissions are approved | |
* | |
* @param integer $ID_participant | |
* @return integer | |
*/ | |
function enable_notification($ID_participant) | |
{ | |
return $this->update($ID_participant, array('participant_notifyapprovals' => 'yes')); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Registration Controller | |
* | |
*/ | |
class Registration extends GRR_Controller | |
{ | |
const WINNER_ID = 12388; | |
/** | |
* Controller Constructor | |
*/ | |
function __construct() | |
{ | |
parent::__construct(); | |
// Load Email Library | |
$this->load->library('email'); | |
// Load Participant Model | |
$this->load->model('participant_model'); | |
// Load Question Model | |
$this->load->model('question_model'); | |
// Load Starting Point Model | |
$this->load->model('startingpoint_model'); | |
} | |
/** | |
* Index | |
*/ | |
function index() | |
{ | |
// If we have participant data redirect to microsite | |
if ($this->session->userdata('ID_participant')) | |
redirect('microsite'); | |
// Set Page title and classes | |
$this->page_titles[] = 'Contest'; | |
// Get starting points | |
$this->local_vars['starting_points'] = $this->startingpoint_model->get_all(); | |
// Check if the sign up is valid | |
if ($this->form_validation->run('registration')) | |
{ | |
// Load Helper | |
$this->load->helper('text'); | |
// Generate Site ID | |
$first_name =$this->participant_model->clear_input($this->input->post('first_name', TRUE)); | |
$last_name = $this->participant_model->clear_input($this->input->post('last_name', TRUE)); | |
// Generate Site ID | |
$participant_site_id = $this->participant_model->generate_site_id($first_name, $last_name); | |
$participant = array( | |
'participant_siteid' => $participant_site_id, | |
'participant_firstname' => $this->input->post('first_name', TRUE), | |
'participant_lastname' => $this->input->post('last_name', TRUE), | |
'participant_email' => $this->input->post('email_address', TRUE), | |
'participant_company' => $this->input->post('company', TRUE), | |
'participant_title' => $this->input->post('title', TRUE), | |
'participant_startingpoint' => $this->input->post('starting_point', TRUE), | |
'participant_accepted_terms' => 'no' | |
); | |
$ID_participant = $this->participant_model->add($participant); | |
// Save responses to questions | |
$this->question_model->save_responses($ID_participant, $this->input->post('questions', TRUE)); | |
// Set vars for the email notification | |
$participant['participant_personal_site'] = site_url('participant/' . $participant['participant_siteid']); | |
$participant['participant_startingpoint'] = $this->local_vars['starting_points'][$participant['participant_startingpoint']]; | |
$participant['ID_participant'] = $ID_participant; | |
$participant['is_winner'] = ($participant['ID_participant'] == self::WINNER_ID); | |
// Send notification email to participant | |
if ($participant['ID_participant'] == self::WINNER_ID) | |
$this->email->send_winner_email($participant); | |
else | |
$this->email->send_participant_email($participant); | |
// Send notification email to Admin | |
$this->email->send_admin_email($participant); | |
// Save this participant data in a Cookie | |
$this->session->set_userdata($participant); | |
// Redirect to Landing | |
redirect('landing'); | |
} | |
// Render content and page | |
$this->public_vars['content'] = $this->load->view('registration/sign_up.php', $this->local_vars, TRUE); | |
$this->render_page(); | |
} | |
function remember_me($hash = NULL) | |
{ | |
// Cookie is already there, redirect to participant site | |
if ($this->session->userdata('ID_participant')) | |
redirect('microsite'); | |
if ( ! is_null($hash)) | |
{ | |
// Lookup hash | |
$participant = $this->participant_model->get_data( | |
array('participant_hash' => $hash) | |
); | |
$participant = $participant[0]; | |
// Check if exsits, if so, clear it up | |
if (count($participant) > 0) | |
{ | |
// Update hash | |
$this->participant_model->update($participant['ID_participant'], | |
array('participant_hash' => NULL)); | |
$participant['participant_hash'] = NULL; | |
// Save this participant data in a Cookie | |
$this->session->set_userdata($participant); | |
// Redirect to microsite page | |
redirect('microsite'); | |
} | |
// Hash key is not valid, redirect to remember_me | |
redirect('remember_me'); | |
} | |
else | |
{ | |
// Check if the sign up is valid | |
if ($this->form_validation->run('remember_me')) | |
{ | |
// Lookup participant | |
$email_address = $this->input->post('email_address', TRUE); | |
$participant = $this->participant_model->get_data( | |
array('participant_email' => $email_address) | |
); | |
$participant = $participant[0]; | |
// Generate hash | |
$hash = sha1($participant['participant_siteid'] . $email_address . date('Y-m-d H:i:s')); | |
$participant['participant_hash'] = $hash; | |
// Update hash | |
$this->participant_model->update($participant['ID_participant'], | |
array('participant_hash' => $hash)); | |
// Send notification email | |
$this->email->send_participant_hash($participant); | |
redirect('microsite'); | |
} | |
// Render content | |
$this->public_vars['content'] = | |
$this->load->view('registration/remember_me.php', $this->local_vars, TRUE); | |
} | |
// Load Forms Validation | |
$this->dom_ready[] = "grr.app.load('forms');"; | |
// Render page | |
$this->render_page(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment