Skip to content

Instantly share code, notes, and snippets.

@micahredding
Created July 23, 2013 15:53
Show Gist options
  • Save micahredding/6063531 to your computer and use it in GitHub Desktop.
Save micahredding/6063531 to your computer and use it in GitHub Desktop.
<?php
/* @begin - Blocks */
function liveschool_block_info() {
$blocks = array();
$blocks['any_device'] = array(
'info' => t('Any Device, Anywhere.'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['starts_here'] = array(
'info' => t('It all starts here'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['share'] = array(
'info' => t('Share'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['follow'] = array(
'info' => t('Follow'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['school_features_list'] = array(
'info' => t('School Features List'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['school_list'] = array(
'info' => t('School List'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['features_list'] = array(
'info' => t('Features List'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['school_needs'] = array(
'info' => t('School Needs'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['matters_bar'] = array(
'info' => t('Why It Matters floating bar'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['matters_signup'] = array(
'info' => t('Why It Matters signup'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
function liveschool_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'any_device':
$block['subject'] = NULL;
$block['content'] = '<div class="devices"></div>';
break;
case 'starts_here':
$block['subject'] = NULL;
$block['content'] = '<div class="title">It all starts <strong>here</strong></div>';
break;
case 'follow':
$block['subject'] = NULL;
$block['content'] = liveschool_block_content($delta);
break;
case 'share':
$block['subject'] = NULL;
$block['content'] = liveschool_block_content($delta);
break;
case 'features_list':
$block['subject'] = NULL;
$block['content'] = liveschool_block_node($delta, 'linkless');
break;
case 'school_list':
$block['subject'] = NULL;
$block['content'] = liveschool_block_node($delta, 'headless');
break;
case 'school_features_list':
$block['subject'] = NULL;
$block['content'] = liveschool_block_node($delta, 'linkless');
break;
case 'school_needs':
$block['subject'] = NULL;
$block['content'] = liveschool_block_node($delta, 'headless');
break;
case 'matters_bar':
$block['subject'] = NULL;
$block['content'] = '
<div id="bar">
<div id="bar-inner">
<div id="bar-links">
<span id="bar-links-left">
<a href="#field-collection-id-28">It all starts here</a>
<a href="#field-collection-id-34">The Problem?</a>
<a href="#field-collection-id-42">Facts</a>
<a href="#field-collection-id-57">Our Solution</a>
</span>
<span id="bar-links-right">
<a href="#signup">Sign Up Today</a>
<a href="#share">Share</a>
</span>
</div>
<div id="bar-hanger">
<a href="#page">Back to the top</a>
</div>
</div>
</div>
';
break;
case 'matters_signup':
$block['subject'] = NULL;
$block['content'] = liveschool_block_content($delta);
break;
}
return $block;
}
function liveschool_block_configure($delta = '') {
$form = array();
switch($delta) {
case 'follow':
$social_sites = liveschool_social_sites();
foreach($social_sites as $site) {
$form[$site] = array(
'#type' => 'textfield',
'#title' => t($site . ' url'),
'#size' => 240,
'#description' => t('The url to your social account.'),
'#default_value' => variable_get('liveschool_block_' . $delta . '_' . $site, ''),
);
}
break;
case 'features_list':
$form['content'] = array(
'#type' => 'textfield',
'#title' => t('Node ID'),
'#size' => 240,
'#description' => t('This node will appear in the block.'),
'#default_value' => variable_get('liveschool_block_' . $delta, 10),
);
break;
case 'school_list':
$form['content'] = array(
'#type' => 'textfield',
'#title' => t('Node ID'),
'#size' => 240,
'#description' => t('This node will appear in the block.'),
'#default_value' => variable_get('liveschool_block_' . $delta, 16),
);
break;
case 'school_features_list':
$form['content'] = array(
'#type' => 'textfield',
'#title' => t('Node ID'),
'#size' => 240,
'#description' => t('This node will appear in the block.'),
'#default_value' => variable_get('liveschool_block_' . $delta, 10),
);
break;
case 'school_needs':
$form['content'] = array(
'#type' => 'textfield',
'#title' => t('Node ID'),
'#size' => 240,
'#description' => t('This node will appear in the block.'),
'#default_value' => variable_get('liveschool_block_' . $delta, 16),
);
break;
case 'matters_signup':
$form['signup'] = array(
'#type' => 'textfield',
'#title' => t('Sign up text'),
'#size' => 240,
'#description' => t('Sign up text.'),
'#default_value' => variable_get('liveschool_block_' . $delta . '_signup', 'Sign up today, for free'),
);
$form['signup_url'] = array(
'#type' => 'textfield',
'#title' => t('Sign up URL'),
'#size' => 240,
'#description' => t('Sign up URL.'),
'#default_value' => variable_get('liveschool_block_' . $delta . '_signup_url', 'signup'),
);
$form['pricing'] = array(
'#type' => 'textfield',
'#title' => t('View pricing text'),
'#size' => 240,
'#description' => t('View pricing text.'),
'#default_value' => variable_get('liveschool_block_' . $delta . '_pricing', 'Or View Our Pricing Plans for Schools'),
);
$form['pricing_url'] = array(
'#type' => 'textfield',
'#title' => t('Pricing URL'),
'#size' => 240,
'#description' => t('Pricing URL.'),
'#default_value' => variable_get('liveschool_block_' . $delta . '_pricing_url', 'view'),
);
break;
case 'share':
$form['content'] = array(
'#type' => 'textarea',
'#title' => t('Welcome message'),
'#size' => 240,
'#description' => t('This text will appear in the block.'),
'#default_value' => variable_get('liveschool_block_' . $delta, ''),
);
$form['share'] = array(
'#type' => 'textfield',
'#title' => t('Share Heading'),
'#size' => 24,
'#description' => t('This text will appear in the block.'),
'#default_value' => variable_get('liveschool_block_' . $delta . '_share', ''),
);
$form['social'] = array(
'#type' => 'textfield',
'#title' => t('Social Heading'),
'#size' => 24,
'#description' => t('This text will appear in the block.'),
'#default_value' => variable_get('liveschool_block_' . $delta . '_social', ''),
);
case '';
break;
}
return $form;
}
function liveschool_block_save($delta = '', $edit = array()) {
switch($delta) {
case 'features_list':
case 'school_list':
case 'school_needs':
case 'school_features_list':
variable_set('liveschool_block_' . $delta, $edit['content']);
break;
case 'follow':
$social_sites = liveschool_social_sites();
foreach($social_sites as $site) {
variable_set('liveschool_block_' . $delta . '_' . $site, $edit[$site]);
}
break;
case 'share':
variable_set('liveschool_block_' . $delta . '_title', $edit['title']);
variable_set('liveschool_block_' . $delta, $edit['content']);
variable_set('liveschool_block_' . $delta . '_share', $edit['share']);
variable_set('liveschool_block_' . $delta . '_social', $edit['social']);
break;
case 'matters_signup':
variable_set('liveschool_block_' . $delta . '_signup', $edit['signup']);
variable_set('liveschool_block_' . $delta . '_pricing', $edit['pricing']);
variable_set('liveschool_block_' . $delta . '_signup_url', $edit['signup_url']);
variable_set('liveschool_block_' . $delta . '_pricing_url', $edit['pricing_url']);
break;
}
return;
}
function liveschool_block_content($delta = '') {
$content = '';
switch($delta) {
case 'follow':
$social_sites = liveschool_social_sites();
$content = '<strong>Follow us</strong><span class="links">';
foreach($social_sites as $site) {
$url = variable_get('liveschool_block_' . $delta . '_' . $site, '');
if($url !== '') {
$content .= '<a href="' . $url . '" class="' . $site . '">'. $site .'</a>';
}
}
$content .= '</span>';
break;
case 'share':
$domain = 'http://whyliveschool.com';
$title = 'LiveSchool';
$tweet = 'Check out @whyliveschool';
$description = 'Check out LiveSchool';
$share_form = drupal_get_form('forward_form', 'epostcard');
$share_form['#id'] = 'forward-form-share';
hide($share_form['message']['instructions']);
hide($share_form['message']['subject']);
hide($share_form['message']['body']);
unset($share_form['message']['recipients']['#description']);
$block_title = variable_get('liveschool_block_' . $delta . '_title', 'Share LiveSchool');
$share_title = variable_get('liveschool_block_' . $delta . '_share', 'Share With Your School');
$social_title = variable_get('liveschool_block_' . $delta . '_social', 'Social');
$content_block = variable_get('liveschool_block_' . $delta, 'Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.');
$content = '<div>' . $content_block . '</div>'
. '<div class="liveschool-share-form"><h3>'.$share_title.'</h3>'. drupal_render($share_form) .'</div>'
. '<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_32x32_style"
addthis:url="'.$domain.'"
addthis:title="'.$title.'"
addthis:description="'.$description.'"
>'
. '<h3>'.$social_title.'</h3>'
. '<a class="addthis_button_preferred_1" style="margin:15px;" addthis:title="'.$tweet.'"></a>
<a class="addthis_button_preferred_2" style="margin:15px;"></a>
<a class="addthis_button_preferred_3" style="margin:15px;"></a>
<a class="addthis_button_preferred_4" style="margin:15px;"></a>
<a class="addthis_button_compact" style="margin:15px;"></a>
</div>
<!-- AddThis Button END -->';
break;
case 'matters_signup':
$content = '<div><a href="'
. variable_get('liveschool_block_' . $delta . '_signup_url', 'signup')
. '" class="signup" id="signup" name="signup">'
. variable_get('liveschool_block_' . $delta . '_signup', 'Sign up today, for free')
. '</a></div><div><a href="'
. variable_get('liveschool_block_' . $delta . '_pricing_url', 'view')
. '" class="view">'
. variable_get('liveschool_block_' . $delta . '_pricing', 'Or View Our Pricing Plans for Schools')
. '</a></div>';
break;
}
return $content;
}
function liveschool_block_node($delta = '', $view_mode) {
switch($delta) {
case 'features_list':
$nid = variable_get('liveschool_block_' . $delta, 10);
break;
case 'school_list':
$nid = variable_get('liveschool_block_' . $delta, 16);
break;
case 'school_features_list':
$nid = variable_get('liveschool_block_' . $delta, 10);
break;
case 'school_needs':
$nid = variable_get('liveschool_block_' . $delta, 16);
break;
default:
$nid = 0;
break;
}
return node_view(node_load($nid), $view_mode);
}
/* @end - Blocks */
/* @begin - Custom Formatter */
function liveschool_file_formatter_info() {
$formatters = array();
$formatters = array(
'preview_to_colorbox' => array(
'label' => t('Preview to Colorbox'),
'behaviors' => array(
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
'default value' => FIELD_BEHAVIOR_DEFAULT,
),
'view callback' => 'liveschool_file_formatter_preview_to_colorbox_view',
),
);
return $formatters;
}
function liveschool_file_formatter_preview_to_colorbox_view($file, $display, $langcode) {
$path_array = explode('/',$file->uri);
$path = end($path_array);
$image = file_view_file($file, 'preview');
$url = url('http://www.youtube.com' . '/embed/' . $path);
$path = file_create_url($image['#path']);
$element = array(
'#type' => 'link',
'#title' => render($image),
'#href' => $url,
'#options' => array(
'html' => TRUE,
'attributes' => array(
'class' => array(
'liveschool-video-preview',
),
),
),
);
return($element);
}
/* @end - Custom Formatter */
function liveschool_form_alter(&$form, &$form_state, $form_id) {
// dsm($form_id);
}
function liveschool_form_search_block_form_alter(&$form, &$form_state, $form_id) {
$form['actions']['submit']['#value'] = 'Go';
$form['search_block_form']['#attributes']['placeholder'] = t('Enter your search terms...');
}
function liveschool_form_forward_form_alter(&$form, &$form_state, $form_id) {
$form['message']['recipients']['#type'] = 'textfield';
$form['message']['recipients']['#title'] = 'To: (separate multiple emails with commas)';
$form['message']['recipients']['#weight'] = -100;
$form['message']['name']['#weight'] = -90;
}
function liveschool_form_webform_client_form_13_alter(&$form, &$form_state, $form_id) {
$form['submitted']['what_kind_of_school']['#empty_option'] = '- What kind of school? - ';
}
function liveschool_social_sites() {
return array(
'facebook',
'twitter',
'instagram',
'youtube',
'e',
'pinterest',
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment