Подскажите как добавить рецепты

Использование системы в различных ситуациях, вопросы программирования сценариев.

Модератор: immortal

Ответить
Murat
Сообщения: 17
Зарегистрирован: Ср мар 07, 2018 4:09 pm
Благодарил (а): 10 раз
Поблагодарили: 0

Подскажите как добавить рецепты

Сообщение Murat » Пт мар 09, 2018 1:26 pm

Скачал и установил скрипт он постоянно говорит (ничего не найдено) я так понял на сайте нужно как-то добавить рецепт и не могу разобраться

Код: Выделить всё

$queryString = $matches[2];


  $findParams = array(
  'aerogrill' => '22', // Рецепты для аэрогриля
  'waffle' => '27', // Для вафельницы
  'yoghurt' => '28', // Для йогуртиницы
  'multivarka' => '25', //Рецепты для мультиварки
  'steamer' => '15', //Для пароварки
  'pressureCooker' => '46', //Для скороварки
  'breadMaker' => '23', //Для хлебопечки
  'fondue' => '24'  //Рецепты фондю
  );

 
$findParams = array();

$recipeNumber = rand(0, 5);

$recipesList = findRecipes($queryString, $findParams);

if (!empty($recipesList)) {
    $recipe = getRecipes($recipesList[$recipeNumber]['link']);
    $recipe['link'] = $recipesList[$recipeNumber]['link'];
    $recipe['name'] = $recipesList[$recipeNumber]['text'];
    sayRecipe($recipe);
} else {
    sayReply('Ничего не найдено.',5);
}

function sayRecipe($recipe) {
    sayReply($recipe['name'],5);

    if (!empty($recipe['description'])) {
        foreach ($recipe['description'] as $e) {
            sayReply($e,5);
        }
    }

    $ingrstr = 'Нам понадобится: ';
    foreach ($recipe['ingredients'] as $e) {
        $ingrstr .= $e . ', ';
    }
    
    sayReply($ingrstr,5);

    sayReply('Способ приготовления:');

    foreach ($recipe['preparing'] as $e) {
        sayReply($e,5);
        //registerError('my_debug', urlencode($e));

    }
}

function getRecipes($recipeLink) {
    if (empty($recipeLink)) {
        return FALSE;
    }

    $html = @file_get_contents($recipeLink);

    $doc = new DOMDocument();
    @$doc->loadHTML($html);

    $xpath = new DOMXpath($doc);
    $ingredients = array();
    $description = array();

    $ingredientsDom = $xpath->query('//table[@class="rec-ingred-table"]/tr');
    if ($ingredientsDom->length > 0) {
        foreach ($ingredientsDom as $item) {
            $ingredients[] = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
        }

        $descriptionDom = $xpath->query('//div[@class="b-page_block__outside"]/p');
        foreach ($descriptionDom as $item) {
            $description[] = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
        }
    } else {
        $ingredientsDom = $xpath->query('//div[@class="b-page_block__outside"]/p');
        foreach ($ingredientsDom as $item) {
            $ingredients[] = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
        }
    }
    $preparingDom = $xpath->query('//div[@class="b-list__clause__text"]/p');
    $preparing = array();
    foreach ($preparingDom as $item) {
        $preparing[] = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
    }

    $recipe = array(
        'description' => $description,
        'ingredients' => $ingredients,
        'preparing' => $preparing
    );

    return $recipe;
}

function findRecipes($queryString, $params) {
    if (empty($queryString)) {
        return FALSE;
    }

    $url = 'http://www.edimdoma.ru/search?utf8=%E2%9C%93&asset=recipes&index=title_search&query=' . urlencode($queryString) . '&search%5Bmain_category_id%5D=&search%5Bcuisine_id%5D=';

    if (!empty($params)) {
        foreach ($params as &$value) {
            $url .= '&cooking_method_ids%5B%5D=' . $value;
        }
    }

    $url .= '&user_name=';

    $html = @file_get_contents($url);
    $doc = new DOMDocument();
    @$doc->loadHTML($html);

    $xpath = new DOMXpath($doc);
    $articles = $xpath->query('//div[@class="b-page_block__header"]');

    $links = array();
    foreach ($articles as $container) {
        $arr = $container->getElementsByTagName("a");
        foreach ($arr as $item) {
            if ($item->parentNode->tagName == "h2") {
                $href = $item->getAttribute("href");
                $text = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
                $links[] = array(
                    'link' => $href,
                    'text' => $text
                );
            }
        }
    }

    return $links;
}
Ответить