Advertisement
mikelieman

eatregularly-bodycomp/index.php

Oct 8th, 2013
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.01 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Body Composition Change Calculator
  4. Plugin URI: http://code.eatregularly.com/wordpress/eatregularly.com-bodycompcalc.html
  5. 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 ).  
  6. Author: eatregularly.com
  7. Version: 1.0
  8. Author URI: http://www.eatregularly.com
  9. License: GNU GPL see http://www.gnu.org/licenses/licenses.html#GPL
  10. */
  11.  
  12. class eatregularlydotcom_bodycomp_calculator {
  13.  
  14.  
  15.         function bodycomp_calculator_init() {
  16.                 $class_name = 'eatregularlydotcom_bodycomp_calculator';
  17.         $calc_title = 'Body Compostiton Calculator';
  18.         $calc_desc = 'Calculates the caloric difference between two body composition profiles.';
  19.              
  20.         if (!function_exists('wp_register_sidebar_widget')) return;
  21.    
  22.         wp_register_sidebar_widget(
  23.             $class_name,
  24.             $calc_title,
  25.             array($class_name, 'bodycomp_calculator_widget'),
  26.             array(
  27.                 'classname' => $class_name,
  28.                 'description' => $calc_desc
  29.             )        
  30.         ); // wp_register_sidebar_widget
  31.              
  32.         wp_register_widget_control(
  33.             $class_name,
  34.             $calc_title,
  35.             array($class_name, 'bodycomp_calculator_control'),
  36.             array('width' => '100%')
  37.         ); // wp_register_widget_congrol
  38.              
  39.         add_shortcode(
  40.             $class_name,
  41.             array($class_name, 'bodycomp_calculator_shortcode')
  42.         ); // add_shortcode
  43.  
  44.         } // function bodycomp_calc_init
  45.  
  46.  
  47.         function display($is_widget, $args=array()) {
  48.                 if ($is_widget) {
  49.                         extract($args);
  50.                         $options = get_option('eatregularlydotcom_bodycomp_calculator');
  51.                         $title = $options['title'];
  52.                         $output[] = $before_widget . $before_title . $title . $after_title;
  53.                 } // if $is_widget
  54.  
  55.                 $output[] = '<div style="margin-top:5px;">
  56. <table><caption>Body Composition Change Calculator</caption>
  57. <form>
  58.  
  59. <tr>
  60. <td>
  61. <label for="cpound">Weight (pounds)</label>
  62. <input type="number" id="cpound" name="cpound" value="220">
  63. </td>
  64. </tr>
  65.  
  66. <tr>
  67. <td>
  68. <fieldset>
  69. <legend>Starting Composition</legend>
  70. <label for="cbeforebfpct">Body Fat (%)</label>
  71. <input type="number" id="cbeforebfpct" name="cbeforebfpct" value="25">
  72. <br>
  73. <label for="cbeforesmpct">Skeletal Muscle (%)</label>
  74. <input type="number" id="cbeforesmpct" name="cbeforesmpct" value="35">
  75. </fieldset>
  76. <fieldset>
  77. <legend>Ending Composition</legend>
  78. <label for="cendbfpct">Body Fat (%)</label>
  79. <input type="number" id="cendbfpct" name="cendbfpct" value="20">
  80. <br>
  81. <label for="cendsmpct">Skeletal Muscle (%)</label>
  82. <input type="number" id="cendsmpct" name="cendsmpct" value="40">
  83. </fieldset>
  84. <input type="button" value="Calculate" onclick="bodycompcalc()">
  85. </td>
  86. </tr>
  87.  
  88. <tr>
  89. <td>
  90. <div id="coutput"></div>
  91. </td>
  92. </tr>
  93.  
  94. </form>
  95. </table>
  96.  
  97.                </div>';
  98.         $output[] = $after_widget;
  99.                 return join($output, "\n");
  100.  
  101.         } // function display
  102.  
  103.  
  104.         function bodycomp_calculator_control() {
  105.                 $class_name = 'eatregularlydotcom_bodycomp_calculator';
  106.                 $calc_title = 'Body Compostiton Calculator';
  107.  
  108.                 $options = get_option($class_name);
  109.  
  110.                 if (!is_array($options)) $options = array('title'=>$calc_title);
  111.  
  112.                 if ($_POST[$class_name.'_submit']) {
  113.                 $options['title'] = strip_tags(stripslashes($_POST[$class_name.'_title']));
  114.                 update_option($class_name, $options);
  115.                 } // if
  116.  
  117.                 $title = htmlspecialchars($options['title'], ENT_QUOTES);
  118.  
  119.                 echo '<p>Title: <input style="width: 180px;" name="'.$class_name.'_title" type="text" value="'.$title.'" /></p>';
  120.                 echo '<input type="hidden" name="'.$class_name.'_submit" value="1" />';
  121.         } // function bodycomp_calculator_control
  122.  
  123.  
  124.         function bodycomp_calculator_shortcode($args, $content=null) {
  125.                 wp_enqueue_script('bodycomp-script', plugins_url('bodycomp.js', __FILE__), false, false, false);
  126.         return eatregularlydotcom_bodycomp_calculator::display(false, $args);
  127.         } // function bodycomp_calculator_shortcode
  128.  
  129.  
  130.         function bodycomp_calculator_widget($args) {
  131.                 wp_enqueue_script('bodycomp-script', plugins_url('bodycomp.js', __FILE__), false, false, false);
  132.                 echo eatregularlydotcom_bodycomp_calculator::display(true, $args);
  133.         } // function bodycomp_calculator_widget
  134.  
  135.  
  136. } // class eatregularlydotcom_bodycomp_calculator
  137.  
  138. add_action('widgets_init', array('eatregularlydotcom_bodycomp_calculator', 'bodycomp_calculator_init'));
  139.  
  140.  
  141. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement