Beiträge von Pedro

    Hallo,

    Rezepte können in Programm verwaltet und in einem bestimmten Austauschformat gespeichert werden. Ein kurzes Beispiel:

    MMMMM----- Meal-Master-Rezept - RezkonvSuite v0.98

    Title: Ayran
    Categories: Saucen, Marinaden
    Yield: 1

    1 pk Joghurt (150g)
    1 Knoblauchzehe, Salz

    Knoblauch schälen und pressen, Joghurt dazugeben. Mit Salz
    abschmecken. Je nach Geschmack mit Wasser oder Milch verdünnen.
    Fertig!

    :Stichworte : Dressing, Sauce

    MMMMM

    Auf dieser mit WORDPRESS erstellten Site:
    http://delicat.ca/cookbook/?page_id=39
    kann man ein Sript downloaden, welches das anscheinend macht. Könnt mir sagen, wo und wie ich das einbinde?

    Script:

    <?php
    define('DATAFILE', 'ATEST.TXT');
    // Example:
    // define('DATAFILE', '/home/example/public_html/file.txt');
    // or if it's in the same directory as import-mm.php
    // define('DATAFILE', 'file.txt');

    $post_author = 1; // Author to import posts as author ID

    function unhtmlentities($string) { // From php.net for < 4.3 compat
    $trans_tbl = get_html_translation_table(HTML_ENTITIES);
    $trans_tbl = array_flip($trans_tbl);
    return strtr($string, $trans_tbl);
    }

    if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. You must install WordPress before you import any entries.");
    require('../wp-config.php');

    $step = $_GET['step'];
    if (!$step) $step = 0;
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <title>Import from Meal Master</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style media="screen" type="text/css">
    body {
    font-family: Georgia, "Times New Roman", Times, serif;
    margin-left: 20%;
    margin-right: 20%;
    }
    #logo {
    margin: 0;
    padding: 0;
    background-repeat: no-repeat;
    height: 60px;
    border-bottom: 4px solid #333;
    }
    #logo a {
    display: block;
    text-decoration: none;
    text-indent: -100em;
    height: 60px;
    }
    p {
    line-height: 140%;
    }
    </style>
    </head><body>
    <?php
    switch($step) {

    case 0:
    ?>


    Howdy! This importer allows you to extract posts from a Meal Master export file. Use the MealMaster export utility to export your recipes to a text file in NORMAL format. To get started you must edit the following line in this file (<code>import-mm.php</code>) </p>


    <code>define('DATAFILE', '');</code></p>


    You want to define where the export file we'll be working with is, for example: </p>


    <code>define('DATAFILE', 'cakes.txt');</code></p>


    You have to do this manually for security reasons.</p>


    If you've done that and you’re all ready, let's go!</p>
    <?php
    break;

    case 1:
    if ('' != DATAFILE && !file_exists(DATAFILE)) die("The file you specified does not seem to exist. Please check the path you've given.");
    if ('' == DATAFILE) die("You must edit the DATAFILE line as described on the previous page to continue.");

    // Bring in the data
    set_magic_quotes_runtime(0);
    // Read the file into an array
    $datalines = file(DATAFILE);

    // Read each line
    foreach ($datalines as $line)
    {
    //if it's the Meal-Master line, continue
    if (preg_match('|(.*?)Recipe via Meal-Master(.*?)|', $line)){
    }
    //if it's a title, create the title and post_name variables
    elseif (preg_match('|Title:(.*?)\n|', $line, $title)){
    $title = addslashes( trim($title[1]) );
    $post_name = sanitize_title($title);
    settype($post_title, "string");
    $post_title = $title;
    }
    //if it's the categories, create a category array
    elseif (preg_match('|Categories:(.*?)\n|', $line, $categories)){
    $categories = addslashes( trim($categories[1]) );
    $categories = str_replace(', ',',', $categories);
    //split the categories into a nifty array
    $categories = explode(',', $categories);
    settype($post_category, "array");
    $post_categories = $categories;
    }
    //now anything else it finds that isn't the end-flag in the file should be the body
    elseif (!preg_match('|-----\n|', $line)) {
    $body[] = nl2br($line);
    }
    //this should only take effect when it finds the end-flag "-----"
    else {
    //format the body array into a nice string
    $bodytext = implode('', $body);
    $post_date = date('Y-m-d H:i:s', $date);
    //insert post in database
    //check to see if the recipe exists
    if ($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_title'")) :
    echo 'Post already imported';
    //if it doesn't exist, enter it in the DB
    else :
    $wpdb->query("INSERT INTO $wpdb->posts
    (post_author, post_date, post_date_gmt, post_content, post_title, post_status, comment_status, ping_status, post_name)
    VALUES
    ('$post_author', '$post_date', DATE_ADD('$post_date', INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE), '$bodytext', '$post_title', 'publish', '$comment_status', '$ping_status', '$post_name')");
    echo 'Entered recipe ';
    echo htmlentities($post_title);

    //clear the data from the body array
    unset($body);
    //get the post id
    $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_title'");
    //die if the post id doesn't exist
    if (!$post_id) :
    die("couldn't get post ID");
    endif;

    //if there are categories in the array
    if (0 != count($post_categories)) :
    //for each category, as a string called 'category'
    foreach ($post_categories as $category) {
    //tidy up the category, enter into string called $post_category
    $post_category = unhtmlentities($category);
    //get the cat_id value if the category exists
    $cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'");
    //if something
    if (!$cat_id && '' != trim($post_category)) {
    //make a nicer category name
    $cat_nicename = sanitize_title($post_category);
    //enter post_category and nicer name into db
    echo $cat_nicename;
    $wpdb->query("INSERT INTO $wpdb->categories (cat_name, category_nicename) VALUES ('$post_category', '$cat_nicename')");
    //now get the cat id of the category you just inserted
    $cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'");
    }
    if ('' == trim($post_category)) $cat_id = 1;
    // Double check it's not there already
    $exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_id AND category_id = $cat_id");

    if (!$exists) {
    $wpdb->query("
    INSERT INTO $wpdb->post2cat
    (post_id, category_id)
    VALUES
    ($post_id, $cat_id)
    ");
    }
    }//endforeach
    else:
    $exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_id AND category_id = 1");
    if (!$exists) $wpdb->query("INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES ($post_id, 1) ");
    endif;
    endif;
    echo '
    ';
    }

    }

    ?>


    <h3>All done. Have fun!</h3>
    <?php
    break;
    }
    ?>
    </body>
    </html>