public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args)) { return ''; } if (WPUltimateRecipe::is_premium_active()) { $text = WPUltimateRecipe::option('recipe_sharing_twitter', '%title% - Powered by @WPUltimRecipe'); } else { $text = '%title% - Powered by @WPUltimRecipe'; } $text = str_ireplace('%title%', $recipe->title(), $text); $output = $this->before_output(); ob_start(); ?> <div data-url="<?php echo $recipe->link(); ?> " data-text="<?php echo esc_attr($text); ?> " data-layout="<?php echo $this->layout; ?> "<?php echo $this->style(); ?> ></div> <?php $output .= ob_get_contents(); ob_end_clean(); return $this->after_output($output, $recipe); }
public function redirect() { // Keyword to check for in URL $keyword = urlencode(WPUltimateRecipe::option('print_template_keyword', 'print')); if (strlen($keyword) <= 0) { $keyword = 'print'; } // Current URL $schema = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://'; $url = $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // Check if URL ends with /print preg_match("/^(.*?)\\/{$keyword}()\$/", $url, $url_data); if (empty($url_data)) { // Check if URL ends with /print/parameters preg_match("/^(.*?)\\/{$keyword}\\/(.*?)\$/", $url, $url_data); } if (isset($url_data[1])) { $post_id = url_to_postid($url_data[1]); $post = get_post($post_id); if ($post_id == 0) { // Check for plain permalinks $slug = substr(strrchr($url_data[1], '='), 1); if ($slug) { $post = get_page_by_path($slug, OBJECT, WPURP_POST_TYPE); } } if ($post && $post->post_type == WPURP_POST_TYPE) { $recipe = new WPURP_Recipe($post); $this->print_recipe($recipe, $url_data[2]); exit; } } }
public function custom_css() { if (WPUltimateRecipe::option('custom_code_public_css', '') !== '') { echo '<style type="text/css">'; echo WPUltimateRecipe::option('custom_code_public_css', ''); echo '</style>'; } }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args)) { return ''; } $icon = '<i class="fa ' . esc_attr($this->icon) . '"></i>'; $classes = array(); $shopping_list_recipes = array(); if (isset($_COOKIE['WPURP_Shopping_List_Recipes_v2'])) { $shopping_list_recipes = explode(';', stripslashes($_COOKIE['WPURP_Shopping_List_Recipes_v2'])); } $in_shopping_list = in_array($recipe->ID(), $shopping_list_recipes); if ($in_shopping_list) { $classes[] = 'in-shopping-list'; } $tooltip_text = WPUltimateRecipe::option('add_to_shopping_list_tooltip_text', __('Add to Shopping List', 'wp-ultimate-recipe')); $tooltip_alt_text = WPUltimateRecipe::option('added_to_shopping_list_tooltip_text', __('This recipe is in your Shopping List', 'wp-ultimate-recipe')); if ($tooltip_text && $tooltip_alt_text) { $classes[] = 'recipe-tooltip'; } if ($in_shopping_list) { $tooltip_text_backup = $tooltip_text; $tooltip_text = $tooltip_alt_text; $tooltip_alt_text = $tooltip_text_backup; } $this->classes = $classes; $output = $this->before_output(); ob_start(); ?> <a href="#"<?php echo $this->style(); ?> data-recipe-id="<?php echo $recipe->ID(); ?> "><?php echo $icon; ?> </a> <?php if ($tooltip_text && $tooltip_alt_text) { ?> <div class="recipe-tooltip-content"> <div class="tooltip-shown"><?php echo $tooltip_text; ?> </div> <div class="tooltip-alt"><?php echo $tooltip_alt_text; ?> </div> </div> <?php } $output .= ob_get_contents(); ob_end_clean(); return $this->after_output($output, $recipe); }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args)) { return ''; } $icon = '<i class="fa ' . esc_attr($this->icon) . '"></i>'; $classes = array(); $tooltip_text = WPUltimateRecipe::option('add_to_meal_plan_tooltip_text', __('Add to Meal Plan:', 'wp-ultimate-recipe')); $tooltip_alt_text = WPUltimateRecipe::option('added_to_meal_plan_tooltip_text', __('This recipe has been added to your Meal Plan', 'wp-ultimate-recipe')); $classes[] = 'recipe-tooltip'; $this->classes = $classes; $output = $this->before_output(); ob_start(); ?> <a href="#"<?php echo $this->style(); ?> data-recipe-id="<?php echo $recipe->ID(); ?> "><?php echo $icon; ?> </a> <div class="recipe-tooltip-content"> <div class="tooltip-shown"> <span class="wpurp-meal-plan-button-text"><?php echo $tooltip_text; ?> </span> <input type="text" class="wpurp-meal-plan-button-date" value="<?php $today = new DateTime('today', WPUltimateRecipe::get()->timezone()); echo $today->format('m/d/Y'); ?> "> <select class="wpurp-meal-plan-button-course"> <option value="0"><?php _e('Select Course to Add:', 'wp-ultimate-recipe'); ?> </option> <?php $meal_plan = WPUltimateRecipe::addon('meal-planner')->get_meal_plan(); foreach ($meal_plan['courses'] as $course) { echo '<option value="' . esc_attr($course) . '">' . $course . '</option>'; } ?> </select> </div> <div class="tooltip-alt"><?php echo $tooltip_alt_text; ?> </div> </div> <?php $output .= ob_get_contents(); ob_end_clean(); return $this->after_output($output, $recipe); }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args) || !isset($args['ingredient_quantity']) || !$args['ingredient_quantity']) { return ''; } $output = $this->before_output(); $fraction = WPUltimateRecipe::option('recipe_adjustable_servings_fractions', '0') == '1' ? true : false; $fraction = strpos($args['ingredient_quantity'], '/') === false ? $fraction : true; $output .= '<span data-normalized="' . $args['ingredient_quantity_normalized'] . '" data-fraction="' . $fraction . '" data-original="' . $args['ingredient_quantity'] . '"' . $this->style() . '>' . $args['ingredient_quantity'] . '</span>'; return $this->after_output($output, $recipe); }
public function hide_theme_thumbnail($html) { if (get_post_type() == 'recipe' && in_the_loop()) { $thumb = WPUltimateRecipe::option('recipe_theme_thumbnail', 'archive'); if ($thumb == 'never' || $thumb == 'archive' && is_single() || $thumb == 'recipe' && !is_single()) { $html = ''; // Hide theme thumbnail } } return $html; }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args)) { return ''; } if (!is_user_logged_in() || !WPUltimateRecipe::is_addon_active('favorite-recipes')) { return ''; } $current_icon = WPURP_Favorite_Recipes::is_favorite_recipe($recipe->ID()) ? $this->iconAlt : $this->icon; $icon = '<i class="fa ' . esc_attr($current_icon) . '" data-icon="' . esc_attr($this->icon) . '" data-icon-alt="' . esc_attr($this->iconAlt) . '"></i>'; $tooltip_text = WPUltimateRecipe::option('favorite_recipes_tooltip_text', __('Add to your Favorite Recipes', 'wp-ultimate-recipe')); $tooltip_alt_text = WPUltimateRecipe::option('favorited_recipes_tooltip_text', __('This recipe is in your Favorite Recipes', 'wp-ultimate-recipe')); if ($tooltip_text && $tooltip_alt_text) { $this->classes = array('recipe-tooltip'); } if (WPURP_Favorite_Recipes::is_favorite_recipe($recipe->ID())) { $tooltip_text_backup = $tooltip_text; $tooltip_text = $tooltip_alt_text; $tooltip_alt_text = $tooltip_text_backup; } $output = $this->before_output(); ob_start(); ?> <a href="#"<?php echo $this->style(); ?> data-recipe-id="<?php echo $recipe->ID(); ?> "><?php echo $icon; ?> </a> <?php if ($tooltip_text && $tooltip_alt_text) { ?> <div class="recipe-tooltip-content"> <div class="tooltip-shown"><?php echo $tooltip_text; ?> </div> <div class="tooltip-alt"><?php echo $tooltip_alt_text; ?> </div> </div> <?php } $output .= ob_get_contents(); ob_end_clean(); return $this->after_output($output, $recipe); }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args)) { return ''; } if (WPUltimateRecipe::is_addon_active('user-ratings') && WPUltimateRecipe::option('user_ratings_enable', 'everyone') != 'disabled') { $stars = WPUltimateRecipe::addon('user-ratings')->output($recipe); } else { $stars = $this->stars_author($recipe); } $output = $this->before_output(); $output .= '<span' . $this->style() . '>' . $stars . '</span>'; return $this->after_output($output, $recipe); }
public function remove_recipe_slug_in_parse_request($query) { if (WPUltimateRecipe::option('remove_recipe_slug', '0') == '1') { if (!$query->is_main_query()) { return; } if (2 != count($query->query) || !isset($query->query['page'])) { return; } if (!empty($query->query['name'])) { $query->set('post_type', array('post', 'recipe', 'page')); } } }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args)) { return ''; } $output = $this->before_output(); if (WPUltimateRecipe::option('recipe_adjustable_servings', '1') == '1') { if (WPUltimateRecipe::is_addon_active('unit-conversion')) { $output .= '<span' . $this->style() . '><input type="number" class="advanced-adjust-recipe-servings" data-original="' . $recipe->servings_normalized() . '" data-start-servings="' . $recipe->servings_normalized() . '" value="' . $recipe->servings_normalized() . '"' . $this->style('input') . '/> ' . $recipe->servings_type() . '</span>'; } else { $output = '<span' . $this->style() . '><input type="number" class="adjust-recipe-servings" data-original="' . $recipe->servings_normalized() . '" data-start-servings="' . $recipe->servings_normalized() . '" value="' . $recipe->servings_normalized() . '"' . $this->style('input') . '/> ' . $recipe->servings_type() . '</span>'; } } return $this->after_output($output, $recipe); }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args)) { return ''; } $output = $this->before_output(); if (WPUltimateRecipe::is_addon_active('unit-conversion') && WPUltimateRecipe::option('recipe_adjustable_units', '1') == '1') { $output = '<span' . $this->style() . '>'; $output .= '<select onchange="RecipeUnitConversion.recalculate(this)" class="adjust-recipe-unit"' . $this->style('select') . '>'; $systems = WPUltimateRecipe::get()->helper('ingredient_units')->get_active_systems(); foreach ($systems as $i => $system) { $output .= '<option value="' . $i . '">' . $system['name'] . '</option>'; } $output .= '</select></span>'; } return $this->after_output($output, $recipe); }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args)) { return ''; } $output = $this->before_output(); $notes = wpautop($recipe->notes()); // Add !important flags to styles added by visual editor if (WPUltimateRecipe::option('recipe_template_force_style', '1') == '1') { preg_match_all('/style="[^"]+/', $notes, $styles); foreach ($styles[0] as $style) { $new_style = preg_replace("/([^;]+)/", "\$1 !important", $style); $notes = str_ireplace($style, $new_style, $notes); } } $output .= '<div' . $this->style() . '>' . $this->cut_off($notes) . '</div>'; return $this->after_output($output, $recipe); }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args)) { return ''; } if (!$this->icon) { $icon = '<img src="' . WPUltimateRecipe::get()->coreUrl . '/img/printer.png">'; } else { $icon = '<i class="fa ' . esc_attr($this->icon) . '"></i>'; } $tooltip_text = WPUltimateRecipe::option('print_tooltip_text', __('Print Recipe', 'wp-ultimate-recipe')); if ($tooltip_text) { $this->classes = array('recipe-tooltip'); } $recipe_id = WPUltimateRecipe::option('print_version_legacy_code', '0') == '1' ? ' data-recipe-id="' . $recipe->ID() . '"' : ''; $output = $this->before_output(); ob_start(); ?> <a href="<?php echo $recipe->link_print(); ?> " target="_blank"<?php echo $recipe_id . $this->style(); ?> ><?php echo $icon; ?> </a> <?php if ($tooltip_text) { ?> <div class="recipe-tooltip-content"> <?php echo $tooltip_text; ?> </div> <?php } $output .= ob_get_contents(); ob_end_clean(); return $this->after_output($output, $recipe); }
function recipe_shortcode($options) { $options = shortcode_atts(array('id' => 'random', 'template' => 'default'), $options); $recipe_post = null; if ($options['id'] == 'random') { $posts = get_posts(array('post_type' => 'recipe', 'nopaging' => true)); $recipe_post = $posts[array_rand($posts)]; } else { $recipe_post = get_post(intval($options['id'])); } if (!is_null($recipe_post) && $recipe_post->post_type == 'recipe' && (!is_feed() || WPUltimateRecipe::option('recipe_rss_feed_shortcode', '1') == '1')) { $recipe = new WPURP_Recipe($recipe_post); $type = is_feed() ? 'feed' : 'recipe'; $template = is_feed() ? null : $options['template']; $output = apply_filters('wpurp_output_recipe', $recipe->output_string($type, $template), $recipe); } else { $output = ''; } return do_shortcode($output); }
public function content_filter($content) { $api_request = defined('REST_REQUEST'); $ignore_query = apply_filters('wpurp_recipe_content_loop_check', !in_the_loop() || !is_main_query()); if (!$api_request && !is_feed() && $ignore_query) { return $content; } if (get_post_type() == 'recipe') { remove_filter('the_content', array($this, 'content_filter'), 10); $recipe = new WPURP_Recipe(get_post()); if (!post_password_required() && (is_single() || WPUltimateRecipe::option('recipe_archive_display', 'full') == 'full' || is_feed() && WPUltimateRecipe::option('recipe_rss_feed_display', 'full') == 'full')) { $taxonomies = WPUltimateRecipe::get()->tags(); unset($taxonomies['ingredient']); $type = is_feed() ? 'feed' : 'recipe'; $recipe_box = apply_filters('wpurp_output_recipe', $recipe->output_string($type), $recipe); if (strpos($content, '[recipe]') !== false) { $content = str_replace('[recipe]', $recipe_box, $content); } else { if (preg_match("/<!--\\s*nextpage.*-->/", $recipe->post_content(), $out)) { // Add metadata if there is a 'nextpage' tag and there wasn't a '[recipe]' tag on this specific page $content .= $recipe->output_string('metadata'); } else { if (is_single() || !preg_match("/<!--\\s*more.*-->/", $recipe->post_content(), $out)) { // Add recipe box to the end of single pages or excerpts (unless there's a 'more' tag $content .= $recipe_box; } } } } else { $content = str_replace('[recipe]', '', $content); // Remove shortcode from excerpt $content = $this->excerpt_filter($content); } // Remove searchable part $content = preg_replace("/\\[wpurp-searchable-recipe\\][^\\[]*\\[\\/wpurp-searchable-recipe\\]/", "", $content); add_filter('the_content', array($this, 'content_filter'), 10); } return $content; }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args) || !isset($args['ingredient_name'])) { return ''; } $taxonomy = get_term_by('name', $args['ingredient_name'], 'ingredient'); $taxonomy_slug = is_object($taxonomy) ? $taxonomy->slug : $args['ingredient_name']; $ingredient_links = WPUltimateRecipe::option('recipe_ingredient_links', 'archive_custom'); $output = $this->before_output(); $plural = WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy_slug, 'plural'); $plural = is_array($plural) ? false : $plural; $plural_data = $plural ? ' data-singular="' . esc_attr($args['ingredient_name']) . '" data-plural="' . esc_attr($plural) . '"' : ''; $output .= '<span' . $this->style() . $plural_data . '>'; $closing_tag = ''; if (!empty($taxonomy) && $ingredient_links != 'disabled') { if ($ingredient_links == 'archive_custom' || $ingredient_links == 'custom') { $custom_link = WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy_slug, 'link'); } else { $custom_link = false; } if (WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy_slug, 'hide_link') !== '1') { if ($custom_link !== false && $custom_link !== '') { $nofollow = WPUltimateRecipe::option('recipe_ingredient_custom_links_nofollow', '0') == '1' ? ' rel="nofollow"' : ''; $output .= '<a href="' . $custom_link . '" class="custom-ingredient-link" target="' . WPUltimateRecipe::option('recipe_ingredient_custom_links_target', '_blank') . '"' . $nofollow . '>'; $closing_tag = '</a>'; } else { if ($ingredient_links != 'custom') { $output .= '<a href="' . get_term_link($taxonomy_slug, 'ingredient') . '">'; $closing_tag = '</a>'; } } } } $output .= $plural && $args['ingredient_quantity_normalized'] != 1 ? $plural : $args['ingredient_name']; $output .= $closing_tag; $output .= '</span>'; return $this->after_output($output, $recipe); }
/** * TODO Refactor this. */ private function tags_list($recipe) { $tags = array(); $taxonomies = WPUltimateRecipe::get()->tags(); unset($taxonomies['ingredient']); foreach ($taxonomies as $taxonomy => $options) { if (!in_array($taxonomy, WPUltimateRecipe::option('recipe_tags_hide_in_recipe', array()))) { $terms = get_the_term_list($recipe->ID(), $taxonomy, '', ', '); if (!is_wp_error($terms) && $terms != '') { $tags[$options['labels']['singular_name']] = $terms; } } } // Categories as tags if (WPUltimateRecipe::is_addon_active('custom-taxonomies') && WPUltimateRecipe::option('recipe_tags_show_in_recipe', '0') == '1') { $categories = wp_get_post_categories($recipe->ID()); $category_groups = array(); foreach ($categories as $category) { $cat = get_category($category); if (!is_null($cat->parent) && $cat->parent != 0) { $category_groups[$cat->parent][] = $cat; } } foreach ($category_groups as $group => $categories) { $group_category = get_category($group); $group_name = $group_category->name; $cats = array(); foreach ($categories as $cat) { $link = get_category_link($cat->cat_ID); $cats[] = '<a href="' . $link . '">' . $cat->name . '</a>'; } $tags[$group_name] = implode(', ', $cats); } } return apply_filters('wpurp_output_recipe_block_recipe-tags_terms', $tags, $recipe); }
private function instructions_list($recipe, $args) { $out = ''; $previous_group = ''; $instructions = $recipe->instructions(); for ($i = 0; $i < count($instructions); $i++) { $instruction = $instructions[$i]; if (isset($instruction['group']) && $instruction['group'] != $previous_group) { $out .= '</ol>'; $out .= '<div class="wpurp-recipe-instruction-group recipe-instruction-group"' . $this->style('group') . '>' . $instruction['group'] . '</div>'; $out .= '<ol' . $this->style() . '>'; $previous_group = $instruction['group']; } $style = !isset($instructions[$i + 1]) || $instruction['group'] != $instructions[$i + 1]['group'] ? array('li', 'li-last') : 'li'; $meta = $args['template_type'] == 'recipe' && $args['desktop'] ? ' itemprop="recipeInstructions"' : ''; $out .= '<li class="wpurp-recipe-instruction"' . $this->style($style) . '>'; $out .= '<span' . $this->style('instruction') . $meta . '>' . $instruction['description'] . '</span>'; if ($this->show_images && $instruction['image'] != '') { $thumb = wp_get_attachment_image_src($instruction['image'], 'large'); $thumb_url = $thumb['0']; $full_img = wp_get_attachment_image_src($instruction['image'], 'full'); $full_img_url = $full_img['0']; $title_tag = WPUltimateRecipe::option('recipe_instruction_images_title', 'attachment') == 'attachment' ? esc_attr(get_the_title($instruction['image'])) : esc_attr($instruction['description']); if (WPUltimateRecipe::option('recipe_images_clickable', '0') == 1) { $out .= '<a href="' . $full_img_url . '" rel="lightbox" title="' . $title_tag . '">'; $out .= '<img src="' . $thumb_url . '" alt="' . esc_attr(get_post_meta($instruction['image'], '_wp_attachment_image_alt', true)) . '" title="' . $title_tag . '"' . $this->style('img') . '/>'; $out .= '</a>'; } else { $out .= '<img src="' . $thumb_url . '" alt="' . esc_attr(get_post_meta($instruction['image'], '_wp_attachment_image_alt', true)) . '" title="' . $title_tag . '"' . $this->style('img') . '/>'; } } $out .= '</li>'; } return $out; }
_e('Recipe notes', 'wp-ultimate-recipe'); ?> </h4> <?php $options = array('textarea_rows' => 7); if (isset($wpurp_user_submission)) { $options['media_buttons'] = false; } wp_editor($recipe->notes(), 'recipe_notes', $options); ?> </div> <?php $custom_fields_addon = WPUltimateRecipe::addon('custom-fields'); if ($custom_fields_addon && (!isset($wpurp_user_submission) || WPUltimateRecipe::option('recipe_fields_in_user_submission', '1') == '1')) { $custom_fields = $custom_fields_addon->get_custom_fields(); $custom_fields_in_user_submission = WPUltimateRecipe::option('recipe_fields_user_submission', array_keys($custom_fields)); if (count($custom_fields) > 0) { ?> <div class="recipe-custom-fields-container"> <h4><?php _e('Custom Fields', 'wp-ultimate-recipe'); ?> </h4> <table class="recipe-general-form"> <?php foreach ($custom_fields as $key => $custom_field) { if (isset($wpurp_user_submission) && !in_array($key, $custom_fields_in_user_submission)) { continue; } ?> <tr>
protected function after_output($output, $recipe) { if (!$this->show_on_desktop || !$this->show_on_mobile) { $output .= '</div>'; } // TODO Better way of doing this? if ($this->link_color && WPUltimateRecipe::option('recipe_template_inline_css', '1') == '1') { if (WPUltimateRecipe::option('recipe_template_force_style', '1') == '1') { $important = ' !important'; } else { $important = ''; } preg_match_all("/<a [^><]*>/i", $output, $links); foreach ($links[0] as $link) { $new_link = preg_replace('/( style=")([^"]*")/i', '$1color: ' . $this->link_color . $important . ';$2', $link); if ($new_link == $link) { $new_link = str_ireplace('<a ', '<a style="color: ' . $this->link_color . $important . ';" ', $link); } $output = str_ireplace($link, $new_link, $output); } } return apply_filters('wpurp_output_recipe_block_' . $this->type, $output, $recipe, $this); }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args)) { return ''; } if (!isset($this->thumbnail)) { $this->thumbnail = 'full'; } $thumb = wp_get_attachment_image_src($recipe->image_ID(), $this->thumbnail); if (!$thumb) { return ''; } // No recipe image found $image_url = $thumb[0]; if (is_null($image_url)) { return ''; } // Check image size unless a specific thumbnail was specified if (is_array($this->thumbnail)) { $new_width = $this->thumbnail[0]; $new_height = $this->thumbnail[1]; if ($thumb[1] && $thumb[2]) { // Use image size if passed along $width = $thumb[1]; $height = $thumb[2]; } else { // Or look it up for ourselves otherwise $size = getimagesize($image_url); $width = $size[0]; $height = $size[1]; } // Don't distort the image $undistored_height = floor($new_width * ($height / $width)); $this->add_style('height', $undistored_height . 'px'); // Get correct thumbnail size $correct_thumb = array($new_width, $undistored_height); $thumb = wp_get_attachment_image_src($recipe->image_ID(), $correct_thumb); $image_url = $thumb[0]; // Cropping the image if ($this->crop) { $this->add_style('overflow', 'hidden', 'outer'); $this->add_style('max-width', $new_width . 'px', 'outer'); $this->add_style('max-height', $new_height . 'px', 'outer'); if ($new_height < $undistored_height) { $margin = -1 * (1 - $new_height / $undistored_height) * 100 / 2; $this->add_style('margin-top', $margin . '%'); $this->add_style('margin-bottom', $margin . '%'); $this->add_style('width', '100%'); $this->add_style('height', 'auto'); } elseif ($new_height > $undistored_height) { // We need a larger image $larger_width = $new_height * ($new_width / $undistored_height); $larger_thumb = array($larger_width, $new_height); $thumb = wp_get_attachment_image_src($recipe->image_ID(), $larger_thumb); $image_url = $thumb[0]; $margin = ($new_width - $larger_width) / 2; $this->add_style('margin-left', $margin . 'px'); $this->add_style('margin-right', $margin . 'px'); $this->add_style('width', $larger_width . 'px'); $this->add_style('max-width', $larger_width . 'px'); $this->add_style('height', $new_height . 'px'); } } } else { if ($this->thumbnail == 'full') { // Get better thumbnail size based on max possible block size $correct_thumb = array($args['max_width'], $args['max_height']); $thumb = wp_get_attachment_image_src($recipe->image_ID(), $correct_thumb); $image_url = $thumb[0]; } } $full_image_url = $recipe->image_url('full'); $args['desktop'] = $args['desktop'] && $this->show_on_desktop; $meta = $args['template_type'] == 'recipe' && $args['desktop'] ? ' itemprop="image"' : ''; $title_tag = WPUltimateRecipe::option('recipe_image_title', 'attachment') == 'attachment' ? esc_attr(get_the_title($recipe->image_ID())) : esc_attr($recipe->title()); $output = $this->before_output(); ob_start(); ?> <div<?php echo $this->style('outer'); ?> > <?php if (WPUltimateRecipe::option('recipe_images_clickable', '0') == 1) { ?> <a href="<?php echo $full_image_url; ?> " rel="lightbox" title="<?php echo $title_tag; ?> "> <img src="<?php echo $image_url; ?> "<?php echo $meta; ?> alt="<?php echo esc_attr(get_post_meta($recipe->image_ID(), '_wp_attachment_image_alt', true)); ?> " title="<?php echo $title_tag; ?> "<?php echo $this->style(); ?> /> </a> <?php } else { ?> <img src="<?php echo $image_url; ?> "<?php echo $meta; ?> alt="<?php echo esc_attr(get_post_meta($recipe->image_ID(), '_wp_attachment_image_alt', true)); ?> " title="<?php echo $title_tag; ?> "<?php echo $this->style(); ?> /> <?php } ?> </div> <?php $output .= ob_get_contents(); ob_end_clean(); return $this->after_output($output, $recipe); }
function wpurp_admin_user_submission_required_fields() { $fields = array(); $default_fields = array('title' => __('Recipe title', 'wp-ultimate-recipe'), 'recipe-author' => __('Your name', 'wp-ultimate-recipe') . ' (' . __('guests', 'wp-ultimate-recipe') . ')', 'recipe_description' => __('Description', 'wp-ultimate-recipe'), 'recipe_servings' => __('Servings', 'wp-ultimate-recipe'), 'recipe_prep_time' => __('Prep Time', 'wp-ultimate-recipe'), 'recipe_cook_time' => __('Cook Time', 'wp-ultimate-recipe'), 'recipe_passive_time' => __('Passive Time', 'wp-ultimate-recipe')); foreach ($default_fields as $value => $label) { $fields[] = array('value' => $value, 'label' => $label); } if (WPUltimateRecipe::option('recipe_fields_in_user_submission', '1') == '1') { foreach (wpurp_admin_custom_fields() as $custom_field) { $custom_field['label'] = __('Custom Fields', 'wp-ultimate-recipe') . ': ' . $custom_field['label']; $fields[] = $custom_field; } } return $fields; }
public function rating() { if (WPUltimateRecipe::is_addon_active('user-ratings') && WPUltimateRecipe::option('user_ratings_enable', 'everyone') != 'disabled') { $user_rating = WPURP_User_Ratings::get_recipe_rating($this->ID()); return $user_rating['rating']; } else { return $this->rating_author(); } }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args) || !isset($args['instruction_image']) || $args['instruction_image'] == '') { return ''; } if (!isset($this->thumbnail)) { $this->thumbnail = 'full'; } $thumb = wp_get_attachment_image_src($args['instruction_image'], $this->thumbnail); if (!$thumb) { return ''; } // No recipe image found $image_url = $thumb[0]; if (is_null($image_url)) { return ''; } // Check image size unless a specific thumbnail was specified if (is_array($this->thumbnail)) { $new_width = $this->thumbnail[0]; $new_height = $this->thumbnail[1]; if ($thumb[1] && $thumb[2]) { // Use image size if passed along $width = $thumb[1]; $height = $thumb[2]; } else { // Or look it up for ourselves otherwise $size = getimagesize($image_url); $width = $size[0]; $height = $size[1]; } // Don't distort the image $undistored_height = floor($new_width * ($height / $width)); $this->add_style('height', $undistored_height . 'px'); // Get correct thumbnail size $correct_thumb = array($new_width, $undistored_height); $thumb = wp_get_attachment_image_src($args['instruction_image'], $correct_thumb); $image_url = $thumb[0]; // Cropping the image if ($this->crop) { $this->add_style('overflow', 'hidden', 'outer'); $this->add_style('max-width', $new_width . 'px', 'outer'); $this->add_style('max-height', $new_height . 'px', 'outer'); if ($new_height < $undistored_height) { $margin = -1 * (1 - $new_height / $undistored_height) * 100 / 2; $this->add_style('margin-top', $margin . '%'); $this->add_style('margin-bottom', $margin . '%'); $this->add_style('width', '100%'); $this->add_style('height', 'auto'); } elseif ($new_height > $undistored_height) { // We need a larger image $larger_width = $new_height * ($new_width / $undistored_height); $larger_thumb = array($larger_width, $new_height); $thumb = wp_get_attachment_image_src($args['instruction_image'], $larger_thumb); $image_url = $thumb[0]; $margin = ($new_width - $larger_width) / 2; $this->add_style('margin-left', $margin . 'px'); $this->add_style('margin-right', $margin . 'px'); $this->add_style('width', $larger_width . 'px'); $this->add_style('max-width', $larger_width . 'px'); $this->add_style('height', $new_height . 'px'); } } } else { if ($this->thumbnail == 'full') { // Get better thumbnail size based on max possible block size $correct_thumb = array($args['max_width'], $args['max_height']); $thumb = wp_get_attachment_image_src($args['instruction_image'], $correct_thumb); $image_url = $thumb[0]; } } $full_img = wp_get_attachment_image_src($args['instruction_image'], 'full'); $full_image_url = $full_img['0']; $description = isset($args['instruction_description']) ? $args['instruction_description'] : ''; $title_tag = WPUltimateRecipe::option('recipe_instruction_images_title', 'attachment') == 'attachment' ? esc_attr(get_the_title($args['instruction_image'])) : esc_attr($description); if (WPUltimateRecipe::option('recipe_images_clickable', '0') == 1) { $img = '<a href="' . $full_image_url . '" rel="lightbox" title="' . $title_tag . '">'; $img .= '<img src="' . $image_url . '" alt="' . esc_attr(get_post_meta($args['instruction_image'], '_wp_attachment_image_alt', true)) . '" title="' . $title_tag . '"' . $this->style() . '/>'; $img .= '</a>'; } else { $img = '<img src="' . $image_url . '" alt="' . esc_attr(get_post_meta($args['instruction_image'], '_wp_attachment_image_alt', true)) . '" title="' . $title_tag . '"' . $this->style() . '/>'; } $output = $this->before_output(); $output .= '<div' . $this->style('outer') . '>' . $img . '</div>'; return $this->after_output($output, $recipe); }
private function ingredients_list($recipe, $args) { $out = ''; $previous_group = ''; foreach ($recipe->ingredients() as $ingredient) { if (isset($ingredient['ingredient_id'])) { $term = get_term($ingredient['ingredient_id'], 'ingredient'); if ($term !== null && !is_wp_error($term)) { $ingredient['ingredient'] = $term->name; } } if (isset($ingredient['group']) && $ingredient['group'] != $previous_group) { $out .= '<li class="group"' . $this->style(array('li', 'li-group')) . '>' . $ingredient['group'] . '</li>'; $previous_group = $ingredient['group']; } $fraction = WPUltimateRecipe::option('recipe_adjustable_servings_fractions', '0') == '1' ? true : false; $fraction = strpos($ingredient['amount'], '/') === false ? $fraction : true; $meta = $args['template_type'] == 'recipe' && $args['desktop'] ? ' itemprop="ingredients"' : ''; $out .= '<li class="wpurp-recipe-ingredient"' . $this->style(array('li', 'li-ingredient')) . $meta . '>'; $out .= '<span class="recipe-ingredient-quantity-unit"' . $this->style('quantity-unit') . '><span class="wpurp-recipe-ingredient-quantity recipe-ingredient-quantity" data-normalized="' . $ingredient['amount_normalized'] . '" data-fraction="' . $fraction . '" data-original="' . $ingredient['amount'] . '"' . $this->style('quantity') . '>' . $ingredient['amount'] . '</span> <span class="wpurp-recipe-ingredient-unit recipe-ingredient-unit" data-original="' . $ingredient['unit'] . '"' . $this->style('unit') . '>' . $ingredient['unit'] . '</span></span>'; $taxonomy = get_term_by('name', $ingredient['ingredient'], 'ingredient'); $plural = WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy->slug, 'plural'); $plural = is_array($plural) ? false : $plural; $plural_data = $plural ? ' data-singular="' . esc_attr($ingredient['ingredient']) . '" data-plural="' . esc_attr($plural) . '"' : ''; $out .= ' <span class="wpurp-recipe-ingredient-name recipe-ingredient-name"' . $this->style('name') . $plural_data . '>'; $ingredient_links = WPUltimateRecipe::option('recipe_ingredient_links', 'archive_custom'); $closing_tag = ''; if (!empty($taxonomy) && $ingredient_links != 'disabled') { if ($ingredient_links == 'archive_custom' || $ingredient_links == 'custom') { $custom_link = WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy->slug, 'link'); } else { $custom_link = false; } if (WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy->slug, 'hide_link') !== '1') { if ($custom_link !== false && $custom_link !== '') { $nofollow = WPUltimateRecipe::option('recipe_ingredient_custom_links_nofollow', '0') == '1' ? ' rel="nofollow"' : ''; $out .= '<a href="' . $custom_link . '" class="custom-ingredient-link" target="' . WPUltimateRecipe::option('recipe_ingredient_custom_links_target', '_blank') . '"' . $nofollow . $this->style('link') . '>'; $closing_tag = '</a>'; } else { if ($ingredient_links != 'custom') { $out .= '<a href="' . get_term_link($taxonomy->slug, 'ingredient') . '"' . $this->style('link') . '>'; $closing_tag = '</a>'; } } } } $out .= $plural && $ingredient['amount_normalized'] != 1 ? $plural : $ingredient['ingredient']; $out .= $closing_tag; $out .= '</span>'; if ($ingredient['notes'] != '') { $out .= ' '; $out .= '<span class="wpurp-recipe-ingredient-notes recipe-ingredient-notes"' . $this->style('notes') . '>' . $ingredient['notes'] . '</span>'; } $out .= '</li>'; } return $out; }
public function get_template($type, $template) { $mapping = $this->get_mapping(); // Only return non-default templates for WP Ultimate Recipe Premium if ($template !== 'default' && isset($mapping[$template]) && WPUltimateRecipe::is_premium_active()) { return $this->get_template_code($template); } else { switch ($type) { case 'print': $default_template = WPUltimateRecipe::option('recipe_template_print_template', 1); break; case 'user_menus': $default_template = WPUltimateRecipe::option('user_menus_recipe_print_template', 1); break; case 'grid': $default_template = WPUltimateRecipe::option('recipe_template_recipegrid_template', 2); break; case 'feed': $default_template = WPUltimateRecipe::option('recipe_template_feed_template', 99); break; case 'metadata': // Empty Recipe Container, but includes Recipe metadata return unserialize(base64_decode('TzoxNDoiV1BVUlBfVGVtcGxhdGUiOjM6e3M6NjoiYmxvY2tzIjthOjE6e2k6MDtPOjI0OiJXUFVSUF9UZW1wbGF0ZV9Db250YWluZXIiOjE0OntzOjExOiJlZGl0b3JGaWVsZCI7czo5OiJjb250YWluZXIiO3M6NDoidHlwZSI7czo5OiJjb250YWluZXIiO3M6ODoiY2hpbGRyZW4iO2E6MDp7fXM6ODoic2V0dGluZ3MiO086ODoic3RkQ2xhc3MiOjQxOntzOjQ6InR5cGUiO3M6OToiY29udGFpbmVyIjtzOjg6Im1heFdpZHRoIjtzOjA6IiI7czo5OiJtYXJnaW5Ub3AiO3M6MDoiIjtzOjEyOiJtYXJnaW5Cb3R0b20iO3M6MDoiIjtzOjEwOiJtYXJnaW5MZWZ0IjtzOjA6IiI7czoxMToibWFyZ2luUmlnaHQiO3M6MDoiIjtzOjY6ImNlbnRlciI7YjowO3M6NToib3JkZXIiO2k6LTE7czo1OiJpbmRleCI7aTowO3M6NjoicGFyZW50IjtpOi0xO3M6MTA6ImNvbmRpdGlvbnMiO2E6MDp7fXM6NToiZmxvYXQiO3M6NDoibm9uZSI7czo5OiJ3aWR0aFR5cGUiO3M6MjoicHgiO3M6MTA6ImhlaWdodFR5cGUiO3M6MjoicHgiO3M6MTI6Im1pbldpZHRoVHlwZSI7czoyOiJweCI7czoxMzoibWluSGVpZ2h0VHlwZSI7czoyOiJweCI7czoxMjoibWF4V2lkdGhUeXBlIjtzOjI6InB4IjtzOjEzOiJtYXhIZWlnaHRUeXBlIjtzOjI6InB4IjtzOjg6InBvc2l0aW9uIjtzOjY6InN0YXRpYyI7czoxMToiYm9yZGVyQ29sb3IiO3M6MDoiIjtzOjExOiJib3JkZXJTdHlsZSI7czo1OiJzb2xpZCI7czo5OiJib3JkZXJUb3AiO2I6MTtzOjEyOiJib3JkZXJCb3R0b20iO2I6MTtzOjEwOiJib3JkZXJMZWZ0IjtiOjE7czoxMToiYm9yZGVyUmlnaHQiO2I6MTtzOjEwOiJzaGFkb3dUeXBlIjtzOjA6IiI7czo5OiJ0ZXh0QWxpZ24iO3M6NzoiaW5oZXJpdCI7czoxMzoidmVydGljYWxBbGlnbiI7czo3OiJpbmhlcml0IjtzOjg6ImZvbnRCb2xkIjtiOjA7czoxMzoiZm9udFNtYWxsQ2FwcyI7YjowO3M6ODoiZm9udFNpemUiO3M6MDoiIjtzOjEyOiJmb250U2l6ZVVuaXQiO3M6MjoicHgiO3M6MTA6ImxpbmVIZWlnaHQiO3M6MDoiIjtzOjE0OiJsaW5lSGVpZ2h0VW5pdCI7czoyOiJweCI7czo5OiJmb250Q29sb3IiO3M6MDoiIjtzOjE0OiJmb250RmFtaWx5VHlwZSI7czowOiIiO3M6MTM6ImZvbnRGYW1pbHlHV0YiO3M6OToiT3BlbitTYW5zIjtzOjExOiJjdXN0b21DbGFzcyI7czowOiIiO3M6MTE6ImN1c3RvbVN0eWxlIjtzOjA6IiI7czo1OiJ3aWR0aCI7czowOiIiO3M6NjoiaGVpZ2h0IjtzOjA6IiI7fXM6NToic3R5bGUiO2E6MTp7czo3OiJkZWZhdWx0IjthOjI6e3M6ODoicG9zaXRpb24iO3M6Njoic3RhdGljIjtzOjE0OiJ2ZXJ0aWNhbC1hbGlnbiI7czo3OiJpbmhlcml0Ijt9fXM6MTA6ImNvbmRpdGlvbnMiO2E6MDp7fXM6NjoicGFyZW50IjtpOi0xO3M6Mzoicm93IjtpOjA7czo2OiJjb2x1bW4iO2k6MDtzOjU6Im9yZGVyIjtpOjA7czoxODoiACoAc2hvd19vbl9kZXNrdG9wIjtiOjE7czoxNzoiACoAc2hvd19vbl9tb2JpbGUiO2I6MTtzOjEzOiIAKgBsaW5rX2NvbG9yIjtiOjA7czoyMDoiACoAYmFja2dyb3VuZF9wcmVzZXQiO2I6MDt9fXM6OToiY29udGFpbmVyIjtyOjM7czo1OiJmb250cyI7YTowOnt9fQ==')); break; default: $default_template = WPUltimateRecipe::option('recipe_template_recipe_template', 0); break; } return $this->get_template_code($default_template); } }
public function output($recipe, $args = array()) { if (!$this->output_block($recipe, $args)) { return ''; } // Default arguments $args['desktop'] = true; $args['max_width'] = 9999; $args['max_height'] = 9999; $args['max_width'] = $this->max_width && $args['max_width'] > $this->max_width ? $this->max_width : $args['max_width']; $args['max_height'] = $this->max_height && $args['max_height'] > $this->max_height ? $this->max_height : $args['max_height']; if (isset($args['classes'])) { $this->classes = $args['classes']; } if (isset($args['wp-ultimate-post-grid'])) { $this->add_style('position', 'absolute'); } $meta = $args['template_type'] == 'recipe' || $args['template_type'] == 'metadata' ? ' itemscope itemtype="http://schema.org/Recipe"' : ''; $output = $this->before_output(); ob_start(); ?> <div<?php echo $meta; ?> id="wpurp-container-recipe-<?php echo $recipe->ID(); ?> " data-permalink="<?php echo $recipe->link(); ?> " data-servings-original="<?php echo $recipe->servings_normalized(); ?> "<?php echo $this->style(); ?> > <?php if ($args['template_type'] == 'recipe' || $args['template_type'] == 'metadata') { ?> <meta itemprop="url" content="<?php echo esc_attr($recipe->link()); ?> " /> <meta itemprop="author" content="<?php echo esc_attr($recipe->author()); ?> "> <meta itemprop="datePublished" content="<?php echo esc_attr($recipe->date()); ?> "> <meta itemprop="recipeYield" content="<?php echo esc_attr($recipe->servings()) . ' ' . esc_attr($recipe->servings_type()); ?> "> <?php if (WPUltimateRecipe::option('output_yandex_metadata', '0') == '1') { ?> <link itemprop="resultPhoto" href="<?php echo esc_attr($recipe->image_url('full')); ?> "> <?php } ?> <?php // Ratings metadata $show_rating = false; $count = null; $rating = null; // Check user ratings if (WPUltimateRecipe::is_addon_active('user-ratings') && WPUltimateRecipe::option('user_ratings_enable', 'everyone') != 'disabled') { $rating_data = WPURP_User_Ratings::get_recipe_rating($recipe->ID()); $count = $rating_data['votes']; $rating = $rating_data['rating']; // Optional rounding $rounding = WPUltimateRecipe::option('user_ratings_rounding', 'disabled'); if ($rounding == 'half') { $rating = ceil($rating * 2) / 2; } else { if ($rounding == 'integer') { $rating = ceil($rating); } } // Do we have the minimum # of votes? $minimum_votes = intval(WPUltimateRecipe::option('user_ratings_minimum_votes', '1')); $show_rating = $count >= $minimum_votes ? true : false; } // Use the author rating if we don't already have a rating to display if (!$show_rating) { $count = 1; $rating = $recipe->rating_author(); if ($rating != 0) { $show_rating = true; } } if ($show_rating) { ?> <div class="wpurp-meta" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating"> <meta itemprop="ratingValue" content="<?php echo $rating; ?> "> <meta itemprop="reviewCount" content="<?php echo $count; ?> "> </div> <?php } ?> <?php // Nutritional Metadata if (WPUltimateRecipe::is_addon_active('nutritional-information')) { $nutritional_meta = '<div class="wpurp-meta" itemprop="nutrition" itemscope itemtype="http://schema.org/NutritionInformation">'; $nutritional = $recipe->nutritional(); $mapping = array('calories' => 'calories', 'fat' => 'fatContent', 'saturated_fat' => 'saturatedFatContent', 'unsaturated_fat' => 'unsaturatedFatContent', 'trans_fat' => 'transFatContent', 'carbohydrate' => 'carbohydrateContent', 'sugar' => 'sugarContent', 'fiber' => 'fiberContent', 'protein' => 'proteinContent', 'cholesterol' => 'cholesterolContent', 'sodium' => 'sodiumContent'); // Unsaturated Fat = mono + poly if (isset($nutritional['monounsaturated_fat']) && $nutritional['monounsaturated_fat'] !== '') { $nutritional['unsaturated_fat'] = floatval($nutritional['monounsaturated_fat']); } if (isset($nutritional['polyunsaturated_fat']) && $nutritional['polyunsaturated_fat'] !== '') { $mono = isset($nutritional['unsaturated_fat']) ? $nutritional['unsaturated_fat'] : 0; $nutritional['unsaturated_fat'] = $mono + floatval($nutritional['polyunsaturated_fat']); } // Output metadata $nutritional_meta_set = false; foreach ($mapping as $field => $meta_field) { if (isset($nutritional[$field]) && $nutritional[$field] !== '') { $nutritional_meta_set = true; $nutritional_meta .= '<meta itemprop="' . $meta_field . '" content="' . floatval($nutritional[$field]) . '">'; } } $nutritional_meta .= '</div>'; if ($nutritional_meta_set) { echo $nutritional_meta; } } } ?> <?php if ($args['template_type'] == 'metadata') { ?> <meta itemprop="image" content="<?php echo esc_attr($recipe->image_url('full')); ?> "> <meta itemprop="name" content="<?php echo esc_attr($recipe->title()); ?> "> <meta itemprop="description" content="<?php echo esc_attr($recipe->description()); ?> "> <?php if ($recipe->prep_time_meta()) { ?> <meta itemprop="prepTime" content="<?php echo $recipe->prep_time_meta(); ?> "><?php } ?> <?php if ($recipe->cook_time_meta()) { ?> <meta itemprop="cookTime" content="<?php echo $recipe->cook_time_meta(); ?> "><?php } ?> <?php // Ingredients metadata (done here to avoid doubles) if ($recipe->has_ingredients()) { $previous_group = null; foreach ($recipe->ingredients() as $ingredient) { $group = isset($ingredient['group']) ? $ingredient['group'] : ''; if ($group !== $previous_group) { if (!is_null($previous_group)) { echo '</div>'; } echo '<div class="wpurp-meta wpurp-meta-ingredient-group" content="' . esc_attr($group) . '">'; $previous_group = $group; } $meta = $ingredient['amount'] . ' ' . $ingredient['unit'] . ' ' . $ingredient['ingredient']; if (trim($ingredient['notes']) !== '') { $meta .= ' (' . $ingredient['notes'] . ')'; } echo '<meta itemprop="ingredients" content="' . esc_attr($meta) . '">'; } echo '</div>'; } // Instructions metadata if ($recipe->has_instructions()) { $previous_group = null; foreach ($recipe->instructions() as $instruction) { $group = isset($instruction['group']) ? $instruction['group'] : ''; if ($group !== $previous_group) { if (!is_null($previous_group)) { echo '</div>'; } echo '<div class="wpurp-meta wpurp-meta-instruction-group" content="' . esc_attr($group) . '">'; $previous_group = $group; } echo '<meta itemprop="recipeInstructions" content="' . esc_attr($instruction['description']) . '">'; } echo '</div>'; } } ?> <?php $this->output_children($recipe, 0, 0, $args); ?> </div> <?php $output .= ob_get_contents(); ob_end_clean(); return $this->after_output($output, $recipe); }
/** * Get normalized amount. 0 if not a valid amount. * * @param $amount Amount to be normalized * @return int */ public function normalize_amount($amount) { if (is_null($amount) || trim($amount) == '') { return 0; } // Treat " to " as a dash for ranges $amount = str_ireplace(' to ', '-', $amount); $amount = preg_replace("/[^\\d\\.\\/\\,\\s-–—]/", "", $amount); // Only keep digits, comma, point, forward slash, space and dashes // Replace en and em dash with a normal dash $amount = str_replace('–', '-', $amount); $amount = str_replace('—', '-', $amount); if (WPUltimateRecipe::option('recipe_adjustable_servings_hyphen', '1') != '1') { $amount = str_replace('-', ' ', $amount); } // Only take first part if we have a dash (e.g. 1-2 cups) $parts = explode('-', $amount); $amount = $parts[0]; // If spaces treat as separate amounts to be added (e.g. 2 1/2 cups = 2 + 1/2) $parts = explode(' ', $amount); $float = 0.0; foreach ($parts as $amount) { $separator = $this->find_separator($amount); switch ($separator) { case '/': $amount = str_replace('.', '', $amount); $amount = str_replace(',', '', $amount); $parts = explode('/', $amount); $denominator = floatval($parts[1]); if ($denominator == 0) { $denominator = 1; } $float += floatval($parts[0]) / $denominator; break; case '.': $amount = str_replace(',', '', $amount); $float += floatval($amount); break; case ',': $amount = str_replace('.', '', $amount); $amount = str_replace(',', '.', $amount); $float += floatval($amount); break; default: $float += floatval($amount); } } return $float; }
public function get_unit_user_abbreviations() { $out = array(); foreach ($this->units as $units) { foreach ($units as $unit => $default_aliases) { $user_aliases = WPUltimateRecipe::option('unit_conversion_alias_' . $unit, false); if ($user_aliases) { $aliases = explode(';', $user_aliases); } else { $aliases = $default_aliases; } $singular = intval(WPUltimateRecipe::option('unit_conversion_alias_' . $unit . '_singular', '0')); $plural = intval(WPUltimateRecipe::option('unit_conversion_alias_' . $unit . '_plural', '0')); $out[$unit] = array('singular' => $aliases[$singular], 'plural' => $aliases[$plural]); } } return $out; }