Plugin Directory

Changeset 358037


Ignore:
Timestamp:
03/10/2011 07:45:25 AM (15 years ago)
Author:
codeswan
Message:

Added edit functionality! Users can now edit recipes that they have already entered.

Location:
recipeseo
Files:
20 added
4 edited

Legend:

Unmodified
Added
Removed
  • recipeseo/trunk/readme.txt

    r357031 r358037  
    2121It's quick. It's simple. And best of all, your recipes now have a much better chance of showing up in Google's Recipe View, with very little additional work from you!
    2222
     23(If you don't use WordPress.org, or would rather be able to edit the formatted HTML on your own, check out my [RecipeSEO App!](http://recipeseo.com/))
     24
    2325== Installation ==
    2426
     
    3032
    3133== Frequently Asked Questions ==
     34
     35=Why do you put a placeholder image into my Edit Post page, instead of my actual recipe?=
     36
     37Because of the way WordPress' text editor works, if you decide to add or remove something from your recipe using the text editor, it can very easily mess up the markup of the code - so the RecipeSEO plugin prevents that from happening by not allowing you to edit the recipe in the text editor. Although currently there is no way to edit an existing recipe, the next version of the RecipeSEO plugin (which will be released in a few days) will have the functionality to do so.
     38
     39=What if my site is in HTML5?=
     40
     41We will have a version that uses microdata (instead of microformats) for websites that use HTML5 very soon! But for now, the microformats that we use should work just fine for all HTML5 sites.
    3242
    3343= How can I request a feature to be added in future versions of the RecipeSEO Plugin? =
     
    45557. Once you preview or publish the post, your recipe will be there with all your microformats... without any extra work from you!
    46568. Voila! Your new recipe can easily be styled with CSS, to look however you would like.
     579. But what if you want to make changes to the recipe you just entered?  All you have to do is click on the placeholder image, and then click on the big fat edit image (the left-hand one).
     5810. Make your changes and click the "Update Recipe" button...
     5911. Edited!  Easy as can be.
    4760
    4861== Changelog ==
     
    54671.1.2 Fixed the bug that was keeping the plugin from working with the HTML post editor.
    5568
     691.2 Added edit functionality!
     70
    5671== Upgrade Notice ==
    5772
    58 No upgrades so far... this is the first version!
     731.2 Users can now edit recipes that they have already entered.
    5974
    6075== Coming Soon... ==
     
    6277**Features that will be added in upcoming versions of the RecipeSEO Plugin:**
    6378
    64 * The ability to edit existing recipes
    6579* Custom recipe styling options
     80* Ability to change titles ("Ingredients", "Prep time", etc.)
     81* ISO 8601 duration format for prep/cook/total times
    6682* **Have a suggestion for a feature I should add? [Tell me!](http://sushiday.com/contact/)**
  • recipeseo/trunk/recipeseo.css

    r355541 r358037  
    3333#amd-recipeseo-uploader #add-another-ingredient { margin-top: 6px; }
    3434#amd-recipeseo-uploader a { color: #21759B; margin-bottom: 32px; display: block; }
     35#amd-recipeseo-uploader #amd-recipeseo-instructions small { font-weight: normal; display: block; }
    3536#amd-recipeseo-uploader #amd-recipeseo-instructions textarea { width: 585px; }
    3637#amd-recipeseo-uploader input[type="submit"] { -moz-border-radius: 11px; -khtml-border-radius: 11px; -webkit-border-radius: 11px; border-radius: 11px -moz-box-sizing: content-box; border-style: solid; cursor: pointer; line-height: 13px; padding: 10px 25px; text-decoration: none; margin: 16px; text-shadow: 0 1px 0 #fff; background-color: #fff; border: 1px solid #bbb; font-size: 123.1%; font-weight: bold; }
  • recipeseo/trunk/recipeseo.php

    r357031 r358037  
    22/*
    33Plugin Name: RecipeSEO
    4 Plugin URI: http://sushiday.com/recipeseo
     4Plugin URI: http://sushiday.com/recipe-seo-plugin/
    55Description: A plugin that adds all the necessary microdata to your recipes, so it will show up in Google's Recipe Search
    6 Version: 1.1.2
     6Version: 1.2
    77Author: Allison Day
    88Author URI: http://codeswan.com
     
    3535
    3636add_action('media_buttons', 'amd_recipeseo_add_recipe_button', 30);
     37add_action('init', 'amd_recipeseo_enhance_mce');
    3738
    3839if (strpos($_SERVER['REQUEST_URI'], 'media-upload.php') && strpos($_SERVER['REQUEST_URI'], '&type=amd_recipeseo') && !strpos($_SERVER['REQUEST_URI'], '&wrt='))
    3940{
    40     amd_recipeseo_iframe_content($_POST);
     41    amd_recipeseo_iframe_content($_POST, $_REQUEST);
    4142    exit;
     43}
     44
     45function amd_recipeseo_enhance_mce() {
     46    if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
     47        return;
     48    if ( get_user_option('rich_editing') == 'true') {
     49        add_filter('mce_external_plugins', 'amd_recipeseo_tinymce_plugin');
     50    }
     51}
     52
     53function amd_recipeseo_tinymce_plugin($plugin_array) {
     54   
     55   $plugin_array['amdrecipeseo'] =  get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/recipeseo_editor_plugin.js';
     56   
     57   return $plugin_array;
    4258}
    4359
     
    99115}
    100116
    101 function amd_recipeseo_iframe_content($post_info = null) {
     117function amd_recipeseo_iframe_content($post_info = null, $get_info = null) {
    102118    $recipe_id = 0;
    103     if ($post_info) {
    104         $recipe_title = htmlentities($post_info["recipe_title"], ENT_QUOTES);
    105         $summary = htmlentities($post_info["summary"], ENT_QUOTES);
    106         $rating = htmlentities($post_info["rating"], ENT_QUOTES);
    107         $prep_time = htmlentities($post_info["prep_time"], ENT_QUOTES);
    108         $cook_time = htmlentities($post_info["cook_time"], ENT_QUOTES);
    109         $total_time = htmlentities($post_info["total_time"], ENT_QUOTES);
    110         $yield = htmlentities($post_info["yield"], ENT_QUOTES);
    111         $serving_size = htmlentities($post_info["serving_size"], ENT_QUOTES);
    112         $calories = htmlentities($post_info["calories"], ENT_QUOTES);
    113         $fat = htmlentities($post_info["fat"], ENT_QUOTES);
    114         $ingredients = array();
    115         for ($i = 0; $i < count($post_info["ingredients"]); $i++) {
    116             $ingredients[$i]["name"] = htmlentities($post_info["ingredients"][$i]["name"], ENT_QUOTES);
    117             $ingredients[$i]["amount"] = htmlentities($post_info["ingredients"][$i]["amount"], ENT_QUOTES);
    118         }
    119         $instructions = htmlentities($post_info["instructions"], ENT_QUOTES);
    120         if ($recipe_title != null && $recipe_title != '' && $ingredients[0]['name'] != null && $ingredients[0]['name'] != '') {
    121             $recipe_id = amd_recipeseo_insert_db($post_info);
     119    $iframe_title = "Add a Recipe";
     120    $submit = "Add Recipe";
     121    if ($post_info || $get_info) {
     122        if ($get_info["post_id"] && !$get_info["add-recipe-button"] && strpos($get_info["post_id"], '-') !== false) {
     123            $recipe_id = preg_replace('/[0-9]*?\-/i', '', $get_info["post_id"]);
     124            $recipe = amd_recipeseo_select_recipe_db($recipe_id);
     125            $ingredients_list = amd_recipeseo_select_ingredients_db($recipe_id);
     126           
     127            $recipe_title = $recipe->recipe_title;
     128            $summary = $recipe->summary;
     129            $rating = $recipe->rating;
     130            $prep_time = $recipe->prep_time;
     131            $cook_time = $recipe->cook_time;
     132            $total_time = $recipe->total_time;
     133            $yield = $recipe->yield;
     134            $serving_size = $recipe->serving_size;
     135            $calories = $recipe->calories;
     136            $fat = $recipe->fat;
     137            $ingredients = array();
     138            $i = 0;
     139            foreach ($ingredients_list as $ingredient) {
     140                $ingredients[$i]["name"] = $ingredient->name;
     141                $ingredients[$i]["amount"] = $ingredient->amount;
     142                $i++;
     143            }
     144            $instructions = $recipe->instructions;
     145            $iframe_title = "Update Your Recipe";
     146            $submit = "Update Recipe";
     147        } else {
     148            $recipe_id = htmlentities($post_info["recipe_id"], ENT_QUOTES);
     149            $recipe_title = htmlentities($post_info["recipe_title"], ENT_QUOTES);
     150            $summary = htmlentities($post_info["summary"], ENT_QUOTES);
     151            $rating = htmlentities($post_info["rating"], ENT_QUOTES);
     152            $prep_time = htmlentities($post_info["prep_time"], ENT_QUOTES);
     153            $cook_time = htmlentities($post_info["cook_time"], ENT_QUOTES);
     154            $total_time = htmlentities($post_info["total_time"], ENT_QUOTES);
     155            $yield = htmlentities($post_info["yield"], ENT_QUOTES);
     156            $serving_size = htmlentities($post_info["serving_size"], ENT_QUOTES);
     157            $calories = htmlentities($post_info["calories"], ENT_QUOTES);
     158            $fat = htmlentities($post_info["fat"], ENT_QUOTES);
     159            $ingredients = array();
     160            for ($i = 0; $i < count($post_info["ingredients"]); $i++) {
     161                $ingredients[$i]["name"] = htmlentities($post_info["ingredients"][$i]["name"], ENT_QUOTES);
     162                $ingredients[$i]["amount"] = htmlentities($post_info["ingredients"][$i]["amount"], ENT_QUOTES);
     163            }
     164            $instructions = htmlentities($post_info["instructions"], ENT_QUOTES);
     165            if ($recipe_title != null && $recipe_title != '' && $ingredients[0]['name'] != null && $ingredients[0]['name'] != '') {
     166                $recipe_id = amd_recipeseo_insert_db($post_info);
     167            }
    122168        }
    123169    }
     
    131177    }
    132178    $addingredients = '';
    133     if (!empty($ingredients)) {
     179    if (!empty($ingredients) && count($ingredients) > 5) {
    134180        $num_ingredients = count($ingredients);
    135181    } else {
     
    152198        function amdRecipeseoAddIngredient(count, amount, name) {
    153199            five = true;
     200            amount1 = '';
     201            name1 = '';
    154202            if (count!=undefined) {
    155203                globalCount=count;
     
    215263<body id="amd-recipeseo-uploader">
    216264    <form enctype='multipart/form-data' method='post' action='' name='recipe_form'>
    217         <h3 class='amd-recipeseo-title'>Add a Recipe</h3>
     265        <h3 class='amd-recipeseo-title'>$iframe_title</h3>
    218266        <div id='amd-recipeseo-form-items'>
    219267            <input type='hidden' name='post_id' value='$id' />
     268            <input type='hidden' name='recipe_id' value='$recipe_id' />
    220269            <p id='recipe-title'><label>Recipe Title <span class='required'>*</span></label> <input type='text' name='recipe_title' value='$recipe_title' /></p>
    221270            <span id='amd_recipeseo_ingredients' class='cls'><p><label class='cls'>Ingredients <span class='required'>*</span></label></p>
     
    225274            </span>
    226275            <p id='add-another-ingredient'><a href='#' class='cls'>+ Add more ingredients</a></p>
    227             <p id='amd-recipeseo-instructions' class='cls'><label>Instructions</label><textarea name='instructions'>$instructions</textarea></label></p>
     276            <p id='amd-recipeseo-instructions' class='cls'><label>Instructions <small>(Put each instruction on a separate line. There is no need to number your instructions.)</small></label><textarea name='instructions'>$instructions</textarea></label></p>
    228277            <p><a href='#' id='more-options-toggle'>More options</a></p>
    229278            <div id='more-options'>
     
    238287                <p><label>Fat</label> <input type='text' name='fat' value='$fat' /></p>
    239288            </div>
    240             <input type='submit' value='Add Recipe' name='add-recipe-button' />
     289            <input type='submit' value='$submit' name='add-recipe-button' />
    241290        </div>
    242291    </form>
     
    247296function amd_recipeseo_insert_db($post_info) {
    248297    global $wpdb;
     298   
     299    $recipe_id = $post_info["recipe_id"];
    249300       
    250301    $recipe = array (
     
    263314    );
    264315   
    265     $wpdb->insert( $wpdb->prefix . "amd_recipeseo_recipes", $recipe );
    266     $recipe_id = $wpdb->insert_id;
     316    if (amd_recipeseo_select_recipe_db($recipe_id) == null) {
     317        $wpdb->insert( $wpdb->prefix . "amd_recipeseo_recipes", $recipe );
     318        $recipe_id = $wpdb->insert_id;
     319    } else {
     320        $wpdb->update( $wpdb->prefix . "amd_recipeseo_recipes", $recipe, array( 'recipe_id' => $recipe_id ));
     321        $wpdb->query("DELETE FROM " . $wpdb->prefix . "amd_recipeseo_ingredients WHERE recipe_id = '" . $recipe_id . "'");
     322    }
    267323   
    268324    for ($i = 0; $i < count($post_info["ingredients"]); $i++) {
     
    273329                "name" => $post_info["ingredients"][$i]["name"],
    274330            );
    275            
     331       
    276332            $wpdb->insert( $wpdb->prefix . "amd_recipeseo_ingredients", $ingredient );
    277333        }
     
    282338
    283339function amd_recipeseo_plugin_footer() {
     340    $url = get_option('siteurl');
     341    $dirname = dirname(plugin_basename(__FILE__));
     342   
    284343    echo <<< HTML
     344    <style type="text/css" media="screen">
     345        #wp_editrecipebtns { position:absolute;display:block;z-index:999998; }
     346        #wp_editrecipebtn { margin-right:20px; }
     347        #wp_editrecipebtn,#wp_delrecipebtn { cursor:pointer; padding:12px;background:#010101; -moz-border-radius:8px;-khtml-border-radius:8px;-webkit-border-radius:8px;border-radius:8px; filter:alpha(opacity=80); -moz-opacity:0.8; -khtml-opacity: 0.8; opacity: 0.8; }
     348        #wp_editrecipebtn:hover,#wp_delrecipebtn:hover { background:#000; filter:alpha(opacity=100); -moz-opacity:1; -khtml-opacity: 1; opacity: 1; }
     349    </style>
    285350    <script>//<![CDATA[
     351    var baseurl = '$url';
     352    var dirname = '$dirname';
    286353        function amdRecipeseoInsertIntoPostEditor(rid,getoption,dirname) {
    287354            tb_remove();
     
    291358            var output = '<img id="amd-recipeseo-recipe-';
    292359            output += rid;
    293             output += '" class="amd-recipeseo-recipe" src="' + getoption + '/wp-content/plugins/' + dirname + '/recipeseo-placeholder.png?ver=1.0" alt="" />';
     360            output += '" class="amd-recipeseo-recipe" src="' + getoption + '/wp-content/plugins/' + dirname + '/recipeseo-placeholder.png" alt="" />';
    294361           
    295362           
     
    307374            }
    308375        }
    309 
    310376    //]]></script>
    311377HTML;
     
    316382function amd_recipeseo_convert_to_recipe($post_text) {
    317383    $output = $post_text;
    318     $needle = 'id="amd-recipeseo-recipe-';
    319     $preg_needle = '/(id)=("(amd-recipeseo-recipe-)[0-9^"]*")/i';
    320    
    321     if (strpos($post_text, $needle) !== false) {
    322         preg_match_all($preg_needle, $post_text, $matches);
     384    $needle_old = 'id="amd-recipeseo-recipe-';
     385    $preg_needle_old = '/(id)=("(amd-recipeseo-recipe-)[0-9^"]*")/i';
     386    $needle = '[amd-recipeseo-recipe:';
     387    $preg_needle = '/\[amd-recipeseo-recipe:([0-9]+)\]/i';
     388   
     389    if (strpos($post_text, $needle_old) !== false) {
     390        // This is for backwards compatability. Please do not delete or alter.
     391        preg_match_all($preg_needle_old, $post_text, $matches);
    323392        foreach ($matches[0] as $match) {
    324393            $recipe_id = str_replace('id="amd-recipeseo-recipe-', '', $match);
     
    332401            $output = str_replace('<img id="amd-recipeseo-recipe-' . $recipe_id . '" class="amd-recipeseo-recipe" src="' . get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/recipeseo-placeholder.png?ver=1.0" alt="" />', $formatted_recipe, $output);
    333402        }
    334        
     403    }
     404   
     405    if (strpos($post_text, $needle) !== false) {
     406        preg_match_all($preg_needle, $post_text, $matches);
     407        foreach ($matches[0] as $match) {
     408            $recipe_id = str_replace('[amd-recipeseo-recipe:', '', $match);
     409            $recipe_id = str_replace(']', '', $recipe_id);
     410
     411            $recipe = amd_recipeseo_select_recipe_db($recipe_id);
     412            $ingredients = amd_recipeseo_select_ingredients_db($recipe_id);
     413
     414            $formatted_recipe = amd_recipeseo_format_recipe($recipe, $ingredients);
     415
     416            $output = str_replace('[amd-recipeseo-recipe:' . $recipe_id . ']', $formatted_recipe, $output);
     417        }
    335418    }
    336419   
     
    354437
    355438    return $ingredients;
     439}
     440
     441function amd_recipeseo_delete_recipe_db($recipe_id) {
     442    global $wpdb;
     443   
     444   
     445}
     446
     447function amd_recipeseo_delete_ingredients_db($recipe_id) {
     448   
    356449}
    357450
     
    415508        $j = 0;
    416509        foreach ($instructions as $instruction) {
    417             $output .= '<li id="recipeseo-instruction-' . $j . '" class="instruction">';
    418                 $output .= $instruction;
    419             $output .= '</li>';
    420             $j++;
     510            if (strlen($instruction) > 1) {           
     511                $output .= '<li id="recipeseo-instruction-' . $j . '" class="instruction">';
     512                    $output .= $instruction;
     513                $output .= '</li>';
     514                $j++;
     515            }
    421516        }
    422517        $output .= '</ol>';
Note: See TracChangeset for help on using the changeset viewer.