Exemple #1
0
</ul>
</div>
</div>


<div id="caja_contenido_tab">	




    <div id="main">
    
    <?php 
    $desc = "";
    if (isset($id)) {
        $recipe = get_recipe($id);
        $name = $recipe['name'];
        $version = $recipe['version'];
        $module = $recipe['module'];
        $recipe_text = $recipe['recipe'];
        $galaxy_module = $recipe['galaxy_module'];
        $requirements = $recipe['requirements'];
        $desc = $recipe['description'];
        ?>
        <br> 
        <div class='h1'>:: Edit Recipe ::</div>

	 <div id="caja_form_groups">

    <?php 
        if (check_admin_user()) {
Exemple #2
0
<?php

//libxml_use_internal_errors(true);
$recipe = $_GET['recipe'];
echo get_recipe($recipe);
function get_recipe($recipe)
{
    global $doc, $xpath;
    $url = 'http://www.marmiton.org/recettes/recherche.aspx?aqt=' . urlencode($recipe);
    $pageList = file_get_contents($url);
    // get response list and match recipes titles
    if (preg_match_all('#m_titre_resultat[^\\<]*<a .*title="(.+)".* href="(.+)"#isU', $pageList, $matchesList)) {
        // echo"<xmp>";print_r($matchesList[1]);echo"</xmp>";
        // for each recipes titles
        // foreach($matchesList[1] as $recipeTitle) {
        // }
        // take first recipe
        $n = 0;
        $url = 'http://www.marmiton.org' . $matchesList[2][$n];
        $pageRecipe = file_get_contents($url);
        // get recipe (minimize/clean before dom load)
        if (preg_match('#<div class="m_content_recette_main">.*<div id="recipePrevNext2"></div>\\s*</div>#isU', $pageRecipe, $match)) {
            $recipe = $match[0];
            $recipe = preg_replace('#<script .*</script>#isU', '', $recipe);
            $doc = loadDOC($pageRecipe);
            $xpath = new DOMXpath($doc);
            $recipeTitle = fetchOne('//h1[@class="m_title"]');
            $recipeMain = fetchOne('//div[@class="m_content_recette_main"]');
            return '<div class="recipe_root">' . $recipeTitle . $recipeMain . '</div>';
        }
    }
    #Prepare sql statement.
    $query = $db->prepare("SELECT * FROM recipestbl WHERE id = ?");
    #Bind data to placeholder in statement.
    $query->bind_param("i", $recipe_id);
    #execute prepared statement.
    $query->execute();
    #bind results
    $query->bind_result($recipeid, $title, $ingredients, $instructions, $category);
    #fetch values
    while ($query->fetch()) {
        $row_arr = array('title' => $title, 'ingredients' => $ingredients, 'instructions' => $instructions, 'action' => 'getRecipe');
        echo json_encode($row_arr);
    }
}
/*DIVIDE*/
#parse contents of json object and determine what function to call.
$request = file_get_contents("php://input");
$message = json_decode($request, true);
switch ($message["action"]) {
    case "insert":
        #create a new row in the recipestbl table from form data.
        insert_data($db, $message);
        break;
    case "getRecipe":
        #get the ingredients and instructions of a specific recipe when the user clicks on it.
        get_recipe($db, $message);
        break;
    default:
        //do nothing
        //break;
}