Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Body Composition Change Calculator
- Plugin URI: http://code.eatregularly.com/wordpress/eatregularly.com-bodycompcalc.html
- Description: Using Elia's K(i) values for metabolic rate, display the net caloric difference between two different body compositions. This calculator can be inserted either into the sidebar from the Appearance menu or into any post by placing [eatregularly.com_bodycomp_calculator] in the content ( but not both, please ).
- Author: eatregularly.com
- Version: 1.0
- Author URI: http://www.eatregularly.com
- License: GNU GPL see http://www.gnu.org/licenses/licenses.html#GPL
- */
- class eatregularlydotcom_bodycomp_calculator {
- function bodycomp_calculator_init() {
- $class_name = 'eatregularlydotcom_bodycomp_calculator';
- $calc_title = 'Body Compostiton Calculator';
- $calc_desc = 'Calculates the caloric difference between two body composition profiles.';
- if (!function_exists('wp_register_sidebar_widget')) return;
- wp_register_sidebar_widget(
- $class_name,
- $calc_title,
- array($class_name, 'bodycomp_calculator_widget'),
- array(
- 'classname' => $class_name,
- 'description' => $calc_desc
- )
- ); // wp_register_sidebar_widget
- wp_register_widget_control(
- $class_name,
- $calc_title,
- array($class_name, 'bodycomp_calculator_control'),
- array('width' => '100%')
- ); // wp_register_widget_congrol
- add_shortcode(
- $class_name,
- array($class_name, 'bodycomp_calculator_shortcode')
- ); // add_shortcode
- } // function bodycomp_calc_init
- function display($is_widget, $args=array()) {
- if ($is_widget) {
- extract($args);
- $options = get_option('eatregularlydotcom_bodycomp_calculator');
- $title = $options['title'];
- $output[] = $before_widget . $before_title . $title . $after_title;
- } // if $is_widget
- $output[] = '<div style="margin-top:5px;">
- <table><caption>Body Composition Change Calculator</caption>
- <form>
- <tr>
- <td>
- <label for="cpound">Weight (pounds)</label>
- <input type="number" id="cpound" name="cpound" value="220">
- </td>
- </tr>
- <tr>
- <td>
- <fieldset>
- <legend>Starting Composition</legend>
- <label for="cbeforebfpct">Body Fat (%)</label>
- <input type="number" id="cbeforebfpct" name="cbeforebfpct" value="25">
- <br>
- <label for="cbeforesmpct">Skeletal Muscle (%)</label>
- <input type="number" id="cbeforesmpct" name="cbeforesmpct" value="35">
- </fieldset>
- <fieldset>
- <legend>Ending Composition</legend>
- <label for="cendbfpct">Body Fat (%)</label>
- <input type="number" id="cendbfpct" name="cendbfpct" value="20">
- <br>
- <label for="cendsmpct">Skeletal Muscle (%)</label>
- <input type="number" id="cendsmpct" name="cendsmpct" value="40">
- </fieldset>
- <input type="button" value="Calculate" onclick="bodycompcalc()">
- </td>
- </tr>
- <tr>
- <td>
- <div id="coutput"></div>
- </td>
- </tr>
- </form>
- </table>
- </div>';
- $output[] = $after_widget;
- return join($output, "\n");
- } // function display
- function bodycomp_calculator_control() {
- $class_name = 'eatregularlydotcom_bodycomp_calculator';
- $calc_title = 'Body Compostiton Calculator';
- $options = get_option($class_name);
- if (!is_array($options)) $options = array('title'=>$calc_title);
- if ($_POST[$class_name.'_submit']) {
- $options['title'] = strip_tags(stripslashes($_POST[$class_name.'_title']));
- update_option($class_name, $options);
- } // if
- $title = htmlspecialchars($options['title'], ENT_QUOTES);
- echo '<p>Title: <input style="width: 180px;" name="'.$class_name.'_title" type="text" value="'.$title.'" /></p>';
- echo '<input type="hidden" name="'.$class_name.'_submit" value="1" />';
- } // function bodycomp_calculator_control
- function bodycomp_calculator_shortcode($args, $content=null) {
- wp_enqueue_script('bodycomp-script', plugins_url('bodycomp.js', __FILE__), false, false, false);
- return eatregularlydotcom_bodycomp_calculator::display(false, $args);
- } // function bodycomp_calculator_shortcode
- function bodycomp_calculator_widget($args) {
- wp_enqueue_script('bodycomp-script', plugins_url('bodycomp.js', __FILE__), false, false, false);
- echo eatregularlydotcom_bodycomp_calculator::display(true, $args);
- } // function bodycomp_calculator_widget
- } // class eatregularlydotcom_bodycomp_calculator
- add_action('widgets_init', array('eatregularlydotcom_bodycomp_calculator', 'bodycomp_calculator_init'));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement