Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Tokokoo Framework
- *
- * @category Tokokoo
- * @package Tokokoo Themes
- * @copyright Copyright (c) 2010-2011 Tokokoo
- * @license http://www.opensource.org/licenses/gpl-2.0.php GNU GPL version 2
- * @version $Id:$
- *
- * @developer Onnay Okheng (@onnayokheng)
- */
- // Do not delete these lines
- if (!empty($_SERVER['SCRIPT_FILENAME']) && 'functions.php' == basename($_SERVER['SCRIPT_FILENAME']))
- die('Please do not load this page directly. Thanks!');
- function wp_debug($variable, $die = false) {
- echo '<pre>' . print_r($variable, true) . '</pre>';
- if ($die)
- die();
- }
- ################################################################################
- // Add theme panels
- ################################################################################
- include 'resources/path.php';
- require_once ('admin/admin-functions.php');
- require_once ('admin/admin-interface.php');
- require_once ('admin/theme-options.php');
- require_once ('admin/theme-functions.php');
- include_once ('admin/theme-enqueue.php');
- include_once ('functions/themes-shortcode.php'); // include shortcode library.
- include_once ('resources/core.php');
- ################################################################################
- // Add theme sidebars
- ################################################################################
- if (function_exists('register_sidebar')) {
- register_sidebar(array(
- 'name' => __('Blog Sidebar'),
- 'description' => 'This widget appears on the blog sidebar',
- 'before_widget' => '<div id="%1$s" class="widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<p class="widget-title">',
- 'after_title' => '</p>',
- ));
- register_sidebar(array(
- 'name' => __('Bottom Left'),
- 'description' => 'This widget appears on the bottom area above footer',
- 'before_widget' => '<div id="%1$s" class="widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<p class="widget-title">',
- 'after_title' => '</p>',
- ));
- register_sidebar(array(
- 'name' => __('Bottom Center Left'),
- 'description' => 'This widget appears on the bottom area above footer',
- 'before_widget' => '<div id="%1$s" class="widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<p class="widget-title">',
- 'after_title' => '</p>',
- ));
- register_sidebar(array(
- 'name' => __('Bottom Center Right'),
- 'description' => 'This widget appears on the bottom area above footer',
- 'before_widget' => '<div id="%1$s" class="widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<p class="widget-title">',
- 'after_title' => '</p>',
- ));
- register_sidebar(array(
- 'name' => __('Bottom Right'),
- 'description' => 'This widget appears on the bottom area above footer',
- 'before_widget' => '<div id="%1$s" class="widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<p class="widget-title">',
- 'after_title' => '</p>',
- ));
- register_sidebar(array(
- 'name' => __('Product Sidebar'),
- 'description' => 'This widget appears on the single product sidebar',
- 'before_widget' => '<div id="%1$s" class="widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<p class="widget-title">',
- 'after_title' => '</p>',
- ));
- }
- ################################################################################
- // Add theme support
- ################################################################################
- if (function_exists('add_theme_support')) {
- add_theme_support('post-thumbnails');
- set_post_thumbnail_size(150, 150, true); // Normal post thumbnails
- // add_theme_support('post-formats', array('aside', 'gallery')); // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
- add_image_size('slider', 1250, 500, true); // slider
- add_image_size('blog', 462, 341, true); // blog
- add_image_size('best-big', 735, 570, true); // home best seller big
- add_image_size('best-landscape', 515, 300, true); // home best seller / sale landscape
- add_image_size('sale-portrait', 250, 570, true); // sale portrait
- add_theme_support('automatic-feed-links'); // Add default posts and comments RSS feed links to head
- // add_custom_background(); // Add custom background functions
- add_theme_support('custom-background');; // Add custom background functions
- }
- function show_posts_nav() {
- global $wp_query;
- return ($wp_query->max_num_pages > 1);
- }
- ################################################################################
- // Configure WP2.9+ Navigation Menus
- ################################################################################
- register_nav_menus(
- array(
- 'header' => __('Header Menu', 'tokokoo'),
- 'footer' => __('Footer Menu', 'tokokoo')
- ));
- ################################################################################
- // Fixing the Read More in the Excerpts
- // This removes the annoying [?] to a Read More link
- ################################################################################
- function tk_excerpt_more($more) {
- global $post;
- // edit here if you like
- // return ' <a href="'. get_permalink($post->ID) . '" title="Read more '.get_the_title($post->ID).'">Read more →</a>';
- return ' <a href="'. get_permalink($post->ID) . '" title="' . sprintf(__('Read more %s', 'tokokoo'), get_the_title($post->ID)) .'">'. __('Read more →', 'tokokoo') . '</a>';
- }
- add_filter('excerpt_more', 'tk_excerpt_more');
- ################################################################################
- // Disable plugin update
- ################################################################################
- add_filter('site_transient_update_plugins', 'tk_remove_update_plugin');
- function tk_remove_update_plugin($value) {
- $removed = 'woocommerce/woocommerce.php';
- if (isset($value->checked[$removed])) {
- unset($value->checked[$removed]);
- }
- return $value;
- }
- add_filter('http_request_args', 'tk_prevent_plugin_update', 10, 2);
- function tk_prevent_plugin_update($r, $url) {
- if (0 === strpos($url, 'http://api.wordpress.org/plugins/update-check/')) {
- $removed = 'woocommerce/woocommerce.php';
- $plugins = unserialize($r['body']['plugins']);
- unset($plugins->plugins[$removed]);
- unset($plugins->active[array_search($removed, $plugins->active)]);
- $r['body']['plugins'] = serialize($plugins);
- }
- return $r;
- }
- ################################################################################
- // Actions + Filters
- ################################################################################
- // Remove links to the extra feeds (e.g. category feeds)
- remove_action( 'wp_head', 'feed_links_extra', 3 );
- // Remove links to the general feeds (e.g. posts and comments)
- remove_action( 'wp_head', 'feed_links', 2 );
- // Remove link to the RSD service endpoint, EditURI link
- remove_action( 'wp_head', 'rsd_link' );
- // Remove link to the Windows Live Writer manifest file
- remove_action( 'wp_head', 'wlwmanifest_link' );
- // Remove index link
- remove_action( 'wp_head', 'index_rel_link' );
- // Remove prev link
- remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
- // Remove start link
- remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
- // Display relational links for adjacent posts
- remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
- // Remove XHTML generator showing WP version
- remove_action( 'wp_head', 'wp_generator' );
- ?>
- <?php
- /**
- * Limit How Many Checkboxes Can Be Checked
- * http://gravitywiz.com/2012/06/11/limiting-how-many-checkboxes-can-be-checked/
- */
- class GFLimitCheckboxes {
- public static $field_limits;
- function __construct($form_id, $field_limits) {
- $this->field_limits = $field_limits;
- add_filter("gform_pre_render_$form_id", array(&$this, 'pre_render'));
- add_filter("gform_validation_$form_id", array(&$this, 'validate'));
- }
- function pre_render($form) {
- $script = '';
- $output_script = false;
- foreach($form['fields'] as $field) {
- $field_id = $field['id'];
- if( !array_key_exists($field['id'], $this->field_limits) // if field limits not provided for this field
- || RGFormsModel::get_input_type($field) != 'checkbox' // or if this field is not a checkbox
- || !isset($this->field_limits[$field_id]['max']) // or if 'max' is not set for this field
- )
- continue;
- $output_script = true;
- $max = $this->field_limits[$field_id]['max'];
- $script .= "jQuery(\"#field_{$form['id']}_{$field['id']} .gfield_checkbox input:checkbox\").checkboxLimit({$max});";
- }
- GFFormDisplay::add_init_script($form['id'], 'limit_checkboxes', GFFormDisplay::ON_PAGE_RENDER, $script);
- if($output_script):
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function($) {
- $.fn.checkboxLimit = function(n) {
- var checkboxes = this;
- this.toggleDisable = function() {
- // if we have reached or exceeded the limit, disable all other checkboxes
- if(this.filter(':checked').length >= n) {
- var unchecked = this.not(':checked');
- unchecked.prop('disabled', true);
- }
- // if we are below the limit, make sure all checkboxes are available
- else {
- this.prop('disabled', false);
- }
- }
- // when form is rendered, toggle disable
- checkboxes.bind('gform_post_render', checkboxes.toggleDisable());
- // when checkbox is clicked, toggle disable
- checkboxes.click(function(event) {
- checkboxes.toggleDisable();
- // if we are equal to or below the limit, the field should be checked
- return checkboxes.filter(':checked').length <= n;
- });
- }
- });
- </script>
- <?php
- endif;
- return $form;
- }
- function validate($validation_result) {
- $form = $validation_result['form'];
- foreach($form['fields'] as &$field) {
- if(!$this->should_field_be_validated($form, $field))
- continue;
- $field_id = $field['id'];
- $min = isset($this->field_limits[$field_id]['min']) ? $this->field_limits[$field_id]['min'] : false;
- $max = isset($this->field_limits[$field_id]['max']) ? $this->field_limits[$field_id]['max'] : false;
- $count = 0;
- foreach($_POST as $key => $value) {
- if(strpos($key, "input_{$field_id}_") !== false)
- $count++;
- }
- if($count < $min) {
- $field['failed_validation'] = true;
- $field['validation_message'] = sprintf( _n('You must select at least %s item.', 'You must select at least %s items.', $min), $min );
- $validation_result['is_valid'] = false;
- }
- else if($count > $max) {
- $field['failed_validation'] = true;
- $field['validation_message'] = sprintf( _n('You may only select %s item.', 'You may only select %s items.', $max), $max );
- $validation_result['is_valid'] = false;
- }
- }
- $validation_result['form'] = $form;
- return $validation_result;
- }
- function should_field_be_validated($form, $field) {
- // if no limits provided for this field
- if( !array_key_exists($field['id'], $this->field_limits) )
- return false;
- // or if this field is not a checkbox
- if( RGFormsModel::get_input_type($field) != 'checkbox' )
- return false;
- // or if this field is hidden
- if( RGFormsModel::is_field_hidden($form, $field, array()) )
- return false;
- return true;
- }
- }
- new GFLimitCheckboxes(5, array(
- 5 => array(
- 'min' => 2,
- 'max' => 3
- ),
- 6 => array(
- 'max' => 3
- )
- ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement