PageRenderTime 57ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/classes/recipe-press-core.php

http://recipe-press.googlecode.com/
PHP | 638 lines | 448 code | 82 blank | 108 comment | 67 complexity | 84bd01e9b9130f6bacd2ef396555be4d MD5 | raw file
  1. <?php
  2. if ( preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF']) ) {
  3. die('You are not allowed to call this page directly.');
  4. }
  5. /**
  6. * recipe-press-core.php - RecipePress Core Class
  7. *
  8. * @package RecipePress
  9. * @subpackage classes
  10. * @author GrandSlambert
  11. * @copyright 2009-2011
  12. * @access public
  13. * @since 2.0.4
  14. */
  15. class recipePressCore {
  16. var $menuName = 'recipe-press';
  17. var $pluginName = 'RecipePress';
  18. var $version = '2.2';
  19. var $optionsName = 'recipe-press-options';
  20. var $options = array();
  21. var $showCaptcha = false;
  22. var $recipeCreated = false;
  23. var $xmlURL = 'http://grandslambert.com/xml/recipe-press/';
  24. var $inUpdateOption = false;
  25. var $in_shortcode = false;
  26. var $publicForm = false;
  27. var $dir_sep = '/';
  28. /**
  29. * Initialize the plugin.
  30. */
  31. function recipePressCore() {
  32. /* Load Langauge Files */
  33. load_plugin_textdomain('recipe-press', false, dirname(dirname(plugin_basename(__FILE__))) . '/lang');
  34. /* Plugin Settings */
  35. /* translators: The name of the plugin, should be a translation of "RecipePress" only! */
  36. $this->pluginName = __('RecipePress', 'recipe-press');
  37. /* Plugin Folders */
  38. $this->pluginPath = WP_PLUGIN_DIR . '/' . basename(dirname(dirname(__FILE__))) . '/';
  39. $this->pluginURL = WP_PLUGIN_URL . '/' . basename(dirname(dirname(__FILE__))) . '/';
  40. $this->templatesPath = WP_PLUGIN_DIR . '/' . basename(dirname(dirname(__FILE__))) . '/templates/';
  41. $this->templatesURL = WP_PLUGIN_URL . '/' . basename(dirname(dirname(__FILE__))) . '/templates/';
  42. $this->loadSettings();
  43. /* Add custom images sizes for RecipePress */
  44. foreach ( $this->options['image-sizes'] as $image => $size ) {
  45. add_image_size('recipe-press-' . $image, $size['width'], $size['height'], $size['crop']);
  46. }
  47. }
  48. /**
  49. * Load plugin settings.
  50. */
  51. function loadSettings() {
  52. $options = get_option($this->optionsName);
  53. $defaults = array(
  54. /* Recipe Options */
  55. 'use-plugin-permalinks' => false,
  56. 'index-slug' => 'recipes',
  57. 'identifier' => 'recipe',
  58. 'permalink' => (get_option('permalink_structure')) ? '%identifier%' . get_option('permalink_structure') : '%identifier%/%postname%',
  59. 'plural-name' => __('Recipes', 'recipe-press'),
  60. 'singular-name' => __('Recipe', 'recipe-press'),
  61. 'use-taxonomies' => false,
  62. 'use-servings' => false,
  63. 'use-times' => false,
  64. 'use-thumbnails' => false,
  65. 'use-featured' => false,
  66. 'use-comments' => false,
  67. 'use-trackbacks' => false,
  68. 'use-custom-fields' => false,
  69. 'use-revisions' => false,
  70. 'use-nutritional-value' => false,
  71. 'use-post-categories' => false,
  72. 'use-post-tags' => false,
  73. 'use-categories' => false, /* Depreciated */
  74. 'use-cuisines' => false, /* Depreciated */
  75. 'plural-times' => false,
  76. /* Taxonomy Defaults */
  77. 'taxonomies' => array(
  78. 'recipe-category' => array('slug' => 'recipe-category', 'plural' => __('Recipe Categories', 'recipe-press'), 'singular' => __('Recipe Category', 'recipe-press'), 'hierarchical' => true, 'active' => true, 'default' => false, 'allow_multiple' => true, 'page' => false, 'builtin' => true, 'per-page' => 10),
  79. 'recipe-cuisine' => array('slug' => 'recipe-cuisine', 'plural' => __('Cuisines', 'recipe-press'), 'singular' => __('Cuisine', 'recipe-press'), 'hierarchical' => false, 'active' => true, 'default' => false, 'allow_multiple' => true, 'page' => false, 'builtin' => true, 'per-page' => 10)
  80. ),
  81. 'ingredient-slug' => 'recipe-ingredients',
  82. 'ingredients-per-page' => 10,
  83. 'ingredient-page' => 0,
  84. /* Image Sizes */
  85. 'image-sizes' => array(
  86. 'image' => array('name' => 'RecipePress Image', 'width' => 250, 'height' => 250, 'crop' => isset($options['image-sizes']['image']['crop']) ? $options['image-sizes']['image']['crop'] : true, 'builtin' => true),
  87. 'thumb' => array('name' => 'RecipePress Thumbnail', 'width' => 50, 'height' => 50, 'crop' => isset($options['image-sizes']['thumb']['crop']) ? $options['image-sizes']['thumb']['crop'] : true, 'builtin' => true),
  88. ),
  89. /* Display Settings */
  90. 'menu-position' => 5,
  91. 'default-excerpt-length' => 20,
  92. 'recipe-count' => get_option('posts_per_page'),
  93. 'recipe-orderby' => 'title',
  94. 'recipe-order' => 'asc',
  95. 'add-to-author-list' => false,
  96. 'disable-content-filter' => false,
  97. 'custom-css' => (count($options) > 2) ? isset($options['custom-css']) : true,
  98. 'hour-text' => __(' hour', 'recipe-press'),
  99. 'minute-text' => __(' min', 'recipe-press'),
  100. 'time-display-type' => 'double',
  101. 'pluralize-singularize-ingredients' => (count($options) > 2) ? isset($options['pluralize-singularize-ingredients']) : true,
  102. 'pluralize-singularize-servings' => (count($options) > 2) ? isset($options['pluralize-singularize-servings']) : true,
  103. /* Form Defaults */
  104. 'form-page' => NULL,
  105. 'form-redirect' => NULL,
  106. 'use-form' => false,
  107. 'form-identifier' => 'submit-recipe',
  108. 'form-permalink' => '%identifier%',
  109. 'form-extension' => false,
  110. 'on-submit-redirect' => false,
  111. 'new-recipe-status' => 'pending',
  112. 'ingredients-fields' => 5,
  113. 'required-fields' => array('title', 'instructions', 'name', 'email'),
  114. 'submit-title' => 'Share a Recipe',
  115. 'require-login' => false,
  116. 'share-slug' => 'recipe-share', /* Depricated */
  117. /* Widget Defaults */
  118. 'widget-orderby' => 'name',
  119. 'widget-order' => 'asc',
  120. 'widget-style' => 'list',
  121. 'widget-show-count' => false,
  122. 'widget-hide-empty' => (count($options) > 2) ? isset($options['widget-hide-empty']) : true,
  123. 'widget-items' => 10,
  124. 'widget-depth' => 0,
  125. 'widget-pad-counts' => false,
  126. 'widget-taxonomy' => 'recipe-category',
  127. 'widget-type' => 'Newest',
  128. 'widget-target' => NULL,
  129. 'widget-show-icon' => false,
  130. 'widget-icon-size' => 25,
  131. /* Printing Options */
  132. 'use-recipe-print' => false,
  133. 'default-print-template' => 'card-3x5',
  134. /* Sharing Options */
  135. 'use-recipe-share' => false,
  136. 'default-share-template' => 'share',
  137. /* Recipe Box Options */
  138. 'use-recipe-box' => true,
  139. 'recipe-box-slug' => 'rp-recipe-box',
  140. 'recipe-box-page' => false,
  141. 'recipe-box-title' => __('My Recipe Box', 'recipe-press'),
  142. 'recipe-box-add-title' => __('Add To Box', 'recipe-press'),
  143. 'recipe-box-view-title' => __('View My Box', 'recipe-press'),
  144. /* Non-Configurable Settings */
  145. 'menu-icon' => $this->pluginURL . 'images/icons/small_logo.png',
  146. /* Size Settings - DEPRICATED FOR TAXONOMY USE */
  147. 'standard' => array(
  148. 'ingredient-sizes' => array('bag', 'big', 'bottle', 'box', 'bunch', 'can', 'carton', 'container', 'count', 'cup', 'clove', 'dash', 'dozen', 'drop', 'envelope', 'fluid ounce', 'gallon', 'gram', 'head', 'jar', 'large', 'pound', 'leaf', 'link', 'liter', 'loaf', 'medium', 'ounce', 'package', 'packet', 'piece', 'pinch', 'pint', 'quart', 'scoop', 'sheet', 'slice', 'small', 'sprig', 'stalk', 'stick', 'strip', 'tablespoon', 'teaspoon', 'whole'),
  149. 'serving-sizes' => array('cup', 'quart', 'pint', 'gallon', 'dozen', 'serving', 'piece')
  150. ),
  151. 'metric' => array(
  152. 'ingredient-sizes' => array('drop', 'dash', 'pinch', 'teaspoon', 'desert spoon', 'tablespoon', 'fluid ounce', 'pint', 'quart', 'gallon', 'pound', 'gram', 'stone', 'ton', 'milligram', 'kilogram'),
  153. 'serving-sizes' => array('quart', 'pint', 'gallon', 'serving', 'piece')
  154. ),
  155. /* Nutritional Markers */
  156. 'nutritional-markers' => array(
  157. 'txt_glycemic_load' => array('name' => 'Glycemic Load'),
  158. 'txt_calories' => array('name' => 'Calories'),
  159. 'txt_total_fat' => array('name' => 'Total Fat', 'size' => 'g'),
  160. 'txt_saturated_fat' => array('name' => 'Saturated Fat', 'size' => 'g'),
  161. 'txt_polyunsaturated_fat' => array('name' => 'Polyunsaturated Fat', 'size' => 'g'),
  162. 'txt_monounsaturated_fat' => array('name' => 'Monounsaturated Fat', 'size' => 'g'),
  163. 'txt_cholesterol' => array('name' => 'Cholesterol', 'size' => 'mg'),
  164. 'txt_sodium' => array('name' => 'Sodium', 'size' => 'mg'),
  165. 'txt_potassium' => array('name' => 'Potassium', 'size' => 'mg'),
  166. 'txt_total_carbohydrate' => array('name' => 'Total Carbohydrates', 'size' => 'g'),
  167. 'txt_dietary_fiber' => array('name' => 'Dietary Fiber', 'size' => 'g'),
  168. 'txt_sugars' => array('name' => 'Sugars', 'size' => 'g'),
  169. 'txt_protein' => array('name' => 'Protein', 'size' => 'g'),
  170. ),
  171. );
  172. $this->options = wp_parse_args($options, $defaults);
  173. /* Handle renaming of built-in taxonomies */
  174. if ( isset($this->options['taxonomies']['recipe-categories']) ) {
  175. $this->options['taxonomies']['recipe-category'] = $this->options['taxonomies']['recipe-categories'];
  176. unset($this->options['taxonomies']['recipe-categories']);
  177. }
  178. if ( isset($this->options['taxonomies']['recipe-cuisines']) ) {
  179. $this->options['taxonomies']['recipe-cuisine'] = $this->options['taxonomies']['recipe-cuisines'];
  180. unset($this->options['taxonomies']['recipe-cuisines']);
  181. }
  182. if ( $this->options['use-thumbnails'] ) {
  183. add_theme_support('post-thumbnails');
  184. }
  185. $this->formFieldNames = array(
  186. 'title' => __('Recipe Name', 'recipe-press'),
  187. 'image' => __('Recipe Image', 'recipe-press'),
  188. 'notes' => __('Recipe Notes', 'recipe-press'),
  189. 'recipe-category' => $this->options['taxonomies']['recipe-category']['singular'],
  190. 'recipe-cuisine' => $this->options['taxonomies']['recipe-cuisine']['singular'],
  191. 'servings' => __('Servings', 'recipe-press'),
  192. 'prep_time' => __('Prep Time', 'recipe-press'),
  193. 'cook_time' => __('Cook Time', 'recipe-press'),
  194. 'measure_type' => __('Measurement', 'recipe-press'),
  195. 'ingredients' => __('Ingredients', 'recipe-press'),
  196. 'instructions' => __('Instructions', 'recipe-press'),
  197. 'recaptcha' => __('Verify', 'recipe-press'),
  198. 'submitter' => __('Name', 'recipe-press'),
  199. 'submitter_email' => __('Email', 'recipe-press'),
  200. );
  201. /* Eliminate individual taxonomies */
  202. if ( $this->options['use-categories'] ) {
  203. $this->options['use-taxonomies'] = true;
  204. $this->options['taxonomies']['recipe-category'] = array(
  205. 'plural' => __('Categories', 'recipe-press'),
  206. 'singular' => __('Category', 'recipe-press'),
  207. 'hierarchical' => true,
  208. 'active' => true,
  209. 'page' => $this->options['categories-page'],
  210. 'converted' => true
  211. );
  212. }
  213. if ( $this->options['use-cuisines'] ) {
  214. $this->options['use-taxonomies'] = true;
  215. $this->options['taxonomies']['recipe-cuisine'] = array(
  216. 'plural' => __('Cuisines', 'recipe-press'),
  217. 'singular' => __('Cuisine', 'recipe-press'),
  218. 'hierarchical' => false,
  219. 'active' => true,
  220. 'page' => $this->options['cuisines-page'],
  221. 'converted' => true
  222. );
  223. }
  224. if ( is_array($this->options['taxonomies']) ) {
  225. foreach ( $this->options['taxonomies'] as $key => $taxonomy ) {
  226. if ( isset($taxonomy['page']) ) {
  227. $this->pageIDs[$key] = $taxonomy['page'];
  228. $this->taxonomyPages[$key] = $taxonomy['page'];
  229. }
  230. }
  231. } else {
  232. $this->options['taxonomies'] = array();
  233. }
  234. if ( isset($this->options['new-recipe-status']) and $this->options['new-recipe-status'] == 'active' ) {
  235. $this->options['new-recipe-status'] = 'publish';
  236. }
  237. return $this->options;
  238. }
  239. /**
  240. * Collect recipe details from front end form.
  241. *
  242. * @global <type> $current_user
  243. * @param <type> $object
  244. * @return <type>
  245. */
  246. function input($data = NULL) {
  247. global $current_user;
  248. get_currentuserinfo();
  249. if ( !$data ) {
  250. $data = $_POST;
  251. }
  252. if ( count($data) == 0 ) {
  253. return array('ingredients' => array());
  254. }
  255. $ingredients = array();
  256. if ( isset($data['ingredients']) ) {
  257. $ingredientArray = $data['ingredients'];
  258. if ( is_array($ingredientArray) ) {
  259. foreach ( $ingredientArray as $id => $ingredient ) {
  260. if ( $id != 'NULL' and (isset($ingredient['item']) or $ingredient['size'] == 'divider') ) {
  261. $ingredients[$id] = $ingredient;
  262. }
  263. }
  264. }
  265. } else {
  266. $ingredients = array();
  267. }
  268. return array(
  269. 'title' => @$data['title'],
  270. 'user_id' => @$data['user_id'],
  271. 'notes' => @$data['notes'],
  272. 'prep_time' => @$data['prep_time'],
  273. 'cook_time' => @$data['cook_time'],
  274. 'ready_time' => @$this->readyTime(),
  275. 'ready_time_raw' => @$this->readyTime(NULL, NULL, false),
  276. 'recipe-category' => @$data['recipe-category'],
  277. 'recipe-cuisine' => @$data['recipe-cuisine'],
  278. 'ingredients' => @$ingredients,
  279. 'instructions' => @$data['instructions'],
  280. 'servings' => @$data['servings'],
  281. 'serving_size' => @$data['serving-size'],
  282. 'status' => @$data['status'],
  283. 'submitter' => @$data['submitter'],
  284. 'submitter_email' => @$data['submitter_email'],
  285. 'updated' => time(),
  286. );
  287. }
  288. function is_field_required($name) {
  289. return in_array( $name, $this->options['required-fields'] );
  290. }
  291. /**
  292. * Method to populate default taxonomy settings.
  293. *
  294. * @param array $tax
  295. * @return array
  296. */
  297. function taxDefaults($tax) {
  298. $defaults = array(
  299. 'default' => false,
  300. 'hierarchical' => false,
  301. 'active' => false,
  302. 'delete' => false,
  303. 'allow_multiple' => false,
  304. 'page' => false,
  305. 'per-page' => 10,
  306. );
  307. /* Make sure the taxonomy has the singular and plural names. */
  308. if ( $tax['singular'] == '' ) {
  309. $tax['singular'] = ucwords(rp_inflector::humanize($tax['slug']));
  310. }
  311. if ( $tax['plural'] == '' ) {
  312. $tax['plural'] = rp_inflector::plural(ucwords(rp_inflector::humanize($tax['slug'])));
  313. }
  314. return wp_parse_args($tax, $defaults);
  315. }
  316. /**
  317. * Method to filter the output and add the recipe details.
  318. *
  319. * @global object $post
  320. * @global object $wp
  321. * @global object $current_user
  322. * @param string $content
  323. * @return string
  324. */
  325. function the_content_filter($content) {
  326. global $post, $wp, $current_user;
  327. get_currentuserinfo();
  328. $files = get_theme(get_option('current_theme'));
  329. if ( is_single ( ) ) {
  330. $template_file = get_stylesheet_directory() . '/single-recipe.php';
  331. } elseif ( is_archive ( ) ) {
  332. $template_file = get_stylesheet_directory() . '/archive-recipe.php';
  333. } else {
  334. $template_file = get_stylesheet_directory() . '/index-recipe.php';
  335. }
  336. if ( $post->post_type != 'recipe' or in_array($template_file, $files['Template Files']) or $this->in_shortcode ) {
  337. return $content;
  338. }
  339. remove_filter('the_content', array(&$this, 'the_content_filter'));
  340. if ( is_archive ( ) ) {
  341. $template = $this->get_template('recipe-archive');
  342. } elseif ( is_single ( ) ) {
  343. $template = $this->get_template('recipe-single');
  344. } elseif ( $post->post_type == 'recipe' and in_the_loop() ) {
  345. $template = $this->get_template('recipe-loop');
  346. } else {
  347. return $content;
  348. }
  349. ob_start();
  350. require ($template);
  351. $content = ob_get_contents();
  352. ob_end_clean();
  353. add_filter('the_content', array(&$this, 'the_content_filter'));
  354. return $content;
  355. }
  356. /**
  357. * Save the ingredients.
  358. *
  359. * @global object $post
  360. * @param string $post_id
  361. * @param array $ingredients
  362. */
  363. function save_ingredients($post_id, $ingredients) {
  364. global $post;
  365. $detailkey = '_recipe_ingredient_value';
  366. $postIngredients = array();
  367. delete_post_meta($post_id, $detailkey);
  368. $ictr = 0;
  369. foreach ( $ingredients as $id => $ingredient ) {
  370. $ingredient['order'] = $ictr;
  371. if ( ( isset($ingredient[ 'item' ] ) and $ingredient[ 'item' ] != -1 and $ingredient[ 'item' ] != 0 and $ingredient[ 'item' ] != '' )
  372. or (isset($ingredient['new-ingredient']) and $ingredient['new-ingredient'] != '') ) {
  373. if ( isset($ingredient['size']) and $ingredient['size'] == 'divider' ) {
  374. $ingredient['item'] = $ingredient['new-ingredient'];
  375. } else {
  376. /* Save ingredient taxonomy information */
  377. if ( isset($ingredient['item']) ) {
  378. $term = get_term_by('id', $ingredient['item'], 'recipe-ingredient');
  379. } else {
  380. $term = array();
  381. }
  382. if ( is_object($term) and !isset($term->errors) ) {
  383. array_push($postIngredients, (int) $term->term_id);
  384. } elseif ( isset($ingredient['new-ingredient']) and $ingredient['new-ingredient'] != '' ) {
  385. $term = wp_insert_term($ingredient['new-ingredient'], 'recipe-ingredient');
  386. if ( isset($term->errors) ) {
  387. $ingredient['item'] = $term->error_data['term_exists'];
  388. } else {
  389. $ingredient['item'] = $term['term_id'];
  390. }
  391. $term = get_term_by('id', $ingredient['item'], 'recipe-ingredient');
  392. array_push($postIngredients, $term->slug);
  393. }
  394. }
  395. unset($ingredient['new-ingredient']);
  396. add_post_meta($post_id, $detailkey, $ingredient, false);
  397. }
  398. ++$ictr;
  399. }
  400. wp_set_object_terms($post_id, $postIngredients, 'recipe-ingredient', false);
  401. }
  402. /**
  403. * Retrieve a template file from either the theme or the plugin directory.
  404. *
  405. * @param <string> $template The name of the template.
  406. * @return <string> The full path to the template file.
  407. */
  408. function get_template($template = NULL, $ext = '.php', $type = 'path') {
  409. if ( $template == NULL ) {
  410. return false;
  411. }
  412. $themeFile = get_stylesheet_directory() . '/' . $template . $ext;
  413. $folder = '/';
  414. if ( !file_exists($themeFile) ) {
  415. $themeFile = get_stylesheet_directory() . '/recipe-press/' . $template . $ext;
  416. $folder = '/recipe-press/';
  417. }
  418. if ( file_exists($themeFile) and !$this->in_shortcode ) {
  419. if ( $type == 'url' ) {
  420. $file = get_bloginfo('template_url') . $folder . $template . $ext;
  421. } else {
  422. $file = get_stylesheet_directory() . $folder . $template . $ext;
  423. }
  424. } elseif ( $type == 'url' ) {
  425. $file = $this->templatesURL . $template . $ext;
  426. } else {
  427. $file = $this->templatesPath . $template . $ext;
  428. }
  429. return $file;
  430. }
  431. /**
  432. * Creates the ingredient form for both sides of the system.
  433. *
  434. * @param array $ingredients
  435. * @return string
  436. */
  437. function get_ingredient_form($ingredients = array()) {
  438. if ( !$ingredients ) {
  439. $ingredients = $this->emptyIngredients($this->options['ingredients-fields']);
  440. }
  441. $this->publicForm = true;
  442. $file = $this->pluginPath . 'includes/ingredient-form.php';
  443. ob_start();
  444. require($file);
  445. $output = ob_get_contents();
  446. ob_end_clean();
  447. return $output;
  448. }
  449. /**
  450. * Get the ingredients stored in the post meta.
  451. *
  452. * @global <object> $post If no ID is specified, use the preloaded post object.
  453. * @param <integer> $post ID of the post, NOT the post object.
  454. * @return <array>
  455. */
  456. function getIngredients($post = NULL) {
  457. if ( !$post ) {
  458. global $post;
  459. }
  460. $ingredients = get_post_meta($post->ID, '_recipe_ingredient_value');
  461. if ( count($ingredients) < 1 ) {
  462. return $this->emptyIngredients($this->options['ingredients-fields']);
  463. } else {
  464. $ings = array();
  465. $defaults = array(
  466. 'quantity' => NULL,
  467. 'size' => 0,
  468. 'item' => 0,
  469. 'notes' => NULL,
  470. 'page-link' => NULL,
  471. 'url' => NULL,
  472. 'order' => 0
  473. );
  474. foreach ( $ingredients as $ingredient ) {
  475. $ings[$ingredient['order']] = $ingredient;
  476. wp_parse_args($ings[$ingredient['order']], $defaults);
  477. }
  478. ksort($ings);
  479. return $ings;
  480. }
  481. }
  482. /**
  483. * Return an empty array for creating ingredients form on new posts.
  484. *
  485. * @param <integer> $count
  486. * @return <array>
  487. */
  488. function emptyIngredients($count = 5) {
  489. $ingredients = array();
  490. for ( $ctr = 0; $ctr < $count; ++$ctr ) {
  491. $ingredients[$ctr]['size'] = 'none';
  492. $ingredients[$ctr]['item'] = 0;
  493. }
  494. return $ingredients;
  495. }
  496. /**
  497. * Calculate the ready time for a recipe.
  498. *
  499. * @param <integer> $prep The prep time.
  500. * @param <integer> $cook The cook time.
  501. * @return <string> Formatted ready time.
  502. */
  503. function readyTime($prep = NULL, $cook = NULL, $formatted = true) {
  504. if ( !isset($prep) ) {
  505. $prep = isset($_POST['recipe_details']['recipe_prep_time']) ? $_POST['recipe_details']['recipe_prep_time'] : 0;
  506. }
  507. if ( !isset($cook) ) {
  508. $cook = isset($_POST['recipe_details']['recipe_cook_time']) ? $_POST['recipe_details']['recipe_cook_time'] : 0;
  509. }
  510. $hplural = '';
  511. $mplural = '';
  512. $total = $prep + $cook;
  513. if ( $total > 60 ) {
  514. $hours = floor($total / 60);
  515. if ( $hours > 1 and $this->options['plural-times'] )
  516. $hplural = 's';
  517. else
  518. $mplural = '';
  519. $hours = $hours . ' ' . $this->options['hour-text'] . $hplural . ', ';
  520. } else {
  521. $hours = '';
  522. }
  523. $mins = $total - ( $hours * 60);
  524. if ( $mins > 1 and $this->options['plural-times'] )
  525. $mplural = 's';
  526. else
  527. $mplural = '';
  528. if ($formatted) {
  529. return $hours . $mins . ' ' . $this->options['minute-text'] . $mplural;
  530. } else {
  531. return $total;
  532. }
  533. }
  534. /**
  535. * Create a help icon on the administration pages.
  536. *
  537. * @param <string> $text
  538. */
  539. function help($text) {
  540. echo '<img src="' . $this->pluginURL . 'images/icons/help.jpg" align="absmiddle"onmouseover="return overlib(\'' . $text . '\');" onmouseout="return nd();" />';
  541. }
  542. /**
  543. * Displayes any data sent in textareas.
  544. *
  545. * @param <type> $input
  546. */
  547. function debug($input) {
  548. $contents = func_get_args();
  549. foreach ( $contents as $content ) {
  550. print '<textarea style="width:49%; height:250px; float: left;">';
  551. print_r($content);
  552. print '</textarea>';
  553. }
  554. echo '<div style="clear: both"></div>';
  555. }
  556. }