'); $second_cut = strrchr($frist_cut, '>'); return str_replace('>', '', $second_cut); break; case $page === 'Genbeta': $frist_cut = get_string_between($content, ''); $second_cut = strrchr($frist_cut, '>'); return str_replace('>', '', $second_cut); break; case $page === 'Infobae': return $author = get_string_between($content, ',t.authors="', '",'); break; case $page === 'TN': return $author = 0; break; default: return 0; break; } } function get_string_between($string, $start, $end){ $string = ' ' . $string; $ini = strpos($string, $start); if ($ini == 0) return ''; $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini; return substr($string, $ini, $len); //! CREDITS: https://stackoverflow.com/a/9826656 } function get_contents($news_unique, $page, $author) { $content = file_get_contents($news_unique); switch ($page) { case $page === 'Xataka': $pre_title = get_string_between($content, '

', '

'); $title = get_string_between($pre_title, '', ''); $pre_icon = get_string_between($content, ', '); $icon = get_string_between($pre_icon, 'src=', ' '); $inner_HTML = get_string_between($content, '
', '
') . ''; $frist_p = strip_tags(get_string_between($inner_HTML, '

', '

')); break; case $page === 'Genbeta': $pre_title = get_string_between($content, '

', '

'); $title = get_string_between($pre_title, '', ''); $pre_icon = get_string_between($content, ', '); $icon = get_string_between($pre_icon, 'src=', ' '); $inner_HTML = get_string_between($content, '
', '
') . ''; $frist_p = strip_tags(get_string_between($inner_HTML, '

', '

')); break; case $page === 'Infobae': $title = get_string_between($content, '', '- Infobae'); $pre_icon = get_string_between($content, '
', '
'); $icon = get_string_between($pre_icon, '992w,', ' 1200w" '); $inner_HTML = get_string_between($content, '
', '
') . ''; $frist_p = get_string_between($content, '', ' | TN'); $icon = get_string_between($content, '', '') . ''; $frist_p = get_string_between($content, ',"description":"', '","articleBody":"'); break; default: echo 0; return 0; break; } return [ 'title' => $title, 'inner_HTML' => $inner_HTML, 'icon' => $icon, 'page_source' => $page, 'author' => $author, 'frist_p' => $frist_p ]; } function create_entry_in_DB($mySQLconnectRoute, $page_data, $news_unique) { require $mySQLconnectRoute; //* ASIGNACIÓN DE VARIABLES $title = $page_data['title']; $inner_HTML = $page_data['inner_HTML']; $icon = $page_data['icon']; $page = $page_data['page_source']; $author = $page_data['author']; $frist_p = $page_data['frist_p']; //* QUERY A LA DB $insert_news = $mySQLconnect -> prepare('insert into noticias (title, content, icon_route, page_source, author, frist_paragraph) values (?, ?, ?, ?, ?, ?)'); $insert_news -> bindParam(1, $title, PDO::PARAM_STR); $insert_news -> bindParam(2, $inner_HTML, PDO::PARAM_STR); $insert_news -> bindParam(3, $icon, PDO::PARAM_STR); $insert_news -> bindParam(4, $page, PDO::PARAM_STR); $insert_news -> bindParam(5, $author, PDO::PARAM_STR); $insert_news -> bindParam(6, $frist_p, PDO::PARAM_STR); $insert_news -> execute(); $ids_done = file_get_contents('./control-files/00_ids_done.txt'); $num = $ids_done + 1; file_put_contents('./control-files/00_ids_done.txt', $num); rename($news_unique,"./news/$num.html"); file_put_contents('./control-files/00_news_done.txt', " ./news/$num.html", FILE_APPEND); } function create_new_pages($cant_news, $news_per_page) { require './pages/print_page_data.php'; $cant_pages = ceil($cant_news / $news_per_page); for ($i=0; $i < $cant_pages; $i++) { $num = $i + 1; file_put_contents("./pages/pages-$num.php", file_get_contents('./pages/template.html')); foreach( php_code($num, $news_per_page) as $block){ file_put_contents("./pages/pages-$num.php", $block, FILE_APPEND); } //file_put_contents("./pages/pages-$num.php", print_template($num)[2], FILE_APPEND); } } function bring_the_news_back_home($actual_page, $news_per_page, $mySQLconnectRoute) { require $mySQLconnectRoute; $frist_calc = ($actual_page * $news_per_page) + 1; $second_calc = ($actual_page * $news_per_page) - $news_per_page; $prepared_query = $mySQLconnect -> prepare("select id, title, frist_paragraph, icon_route, page_source from noticias where id < ? and id > ?"); $prepared_query -> bindParam(1, $frist_calc, PDO::PARAM_INT); $prepared_query -> bindParam(2, $second_calc, PDO::PARAM_INT); //$prepared_query -> execute(array($actual_page * 10, $actual_page * 10 - 10)); $prepared_query -> execute(); $return = $prepared_query -> fetchAll(); return $return; } function bring_the_choosen_one($id, $mySQLconnectRoute) { require $mySQLconnectRoute; $prepared_query = $mySQLconnect -> prepare('select * from noticias where id = ?'); $prepared_query -> bindParam(1, $id, PDO::PARAM_INT); $prepared_query -> execute(); $return = $prepared_query -> fetchAll(); return $return; } ?>