From a13b193d5b6a31f9d338624af677d84fd3b80a7f Mon Sep 17 00:00:00 2001 From: AK Delfin Date: Thu, 18 Aug 2022 01:49:10 +0300 Subject: [PATCH] add parser arriah.ru --- arriah.php | 127 ++++++++++++++++++++++++++++++++++ category-rosselkhoznadzor.php | 1 + single-37.php | 93 +++++++++++++++++++++++++ 3 files changed, 221 insertions(+) create mode 100644 arriah.php create mode 100644 single-37.php diff --git a/arriah.php b/arriah.php new file mode 100644 index 0000000..741f784 --- /dev/null +++ b/arriah.php @@ -0,0 +1,127 @@ +array( + "verify_peer"=>false, + "verify_peer_name"=>false, + ), + ); + + $xml = file_get_contents($feed, false, stream_context_create($arrContextOptions)); + + $result = array(); + $res = array(); + + $xml = simplexml_load_string($xml); + $n_old = 0; + $nn = 0; + + foreach ($xml->xpath('//item') as $item){ + + $link = (string)$item->link; + $link = trim($link, '/'); + $f_end = strrpos($link,'/'); + + if ($f_end){ + $code = substr($link, $f_end+1); + } + else + continue; + + + if (isset($find_news['ID'])){ + $n_old++; + continue; + } + else { + + $date = (string)$item->pubDate; + $mysqldate = date('Y-m-d H:i:s',strtotime($date)); + + $title = (string)$item->title; + $title = wp_strip_all_tags($title); + $text = (string)$item->description; + $text = str_replace('src="/local/', 'src="https://new.arriah.ru/local/', $text); + //$text = replace_br($text); + //$text = delete_p($text); + $text = str_replace('
', '

', $text); + $slug = express_slug(vij_slug($title)); + + $sql = "SELECT `ID` from `wp_posts` WHERE `post_name` = '$slug' and `post_date` = '$mysqldate'"; + $result = $wpdb->get_results($sql); + + if ($result) { + continue; + } + + + $my_post = [ + 'post_title' => $title, + 'post_name' => $slug, + 'post_type' => 'post', + 'post_content' => $text, + 'post_date' => $mysqldate, + 'post_status' => 'publish', + 'post_author' => 1, + 'comment_status' => 'closed', + 'post_category' => array( 37 ) + ]; + + wp_insert_post( $my_post); + + } + + } + + return True; + +} + + +function file_get_contents_curl( $url ) { + + $ch = curl_init(); + + curl_setopt( $ch, CURLOPT_AUTOREFERER, TRUE ); + curl_setopt( $ch, CURLOPT_HEADER, 0 ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); + curl_setopt( $ch, CURLOPT_URL, $url ); + curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE ); + + $data = curl_exec( $ch ); + curl_close( $ch ); + + return $data; + +} + + + +function replace_br($html) { + + $html = preg_replace('#(?:\s*?){2,}#', '

', $html); + return "

$html

"; + +} + +function delete_p($html){ + + $pattern = "/]*><\\/p[^>]*>/"; + return preg_replace($pattern, '', $html); + +} \ No newline at end of file diff --git a/category-rosselkhoznadzor.php b/category-rosselkhoznadzor.php index 356400e..fc2da80 100644 --- a/category-rosselkhoznadzor.php +++ b/category-rosselkhoznadzor.php @@ -46,6 +46,7 @@ $nn = 0;?> <?the_title();?>

+
diff --git a/single-37.php b/single-37.php new file mode 100644 index 0000000..1a4ded8 --- /dev/null +++ b/single-37.php @@ -0,0 +1,93 @@ + + + + + +
+ + + + + + term_id; + $category_link = get_category_link($category_id); + $post_id = get_the_ID(); + ?> + + + + +
+

+ + + + + +
+ <?the_title();?> +
+
+ +
+ +
+ +
+
+ name;?>, +
+
+ +
+
+ +
+

Свежие отраслевые новости на нашем канале в Telegram

+

Добавьте «Ветеринарию и жизнь» в избранное в ЯНДЕКС.НОВОСТИ

+

Подписывайтесь на канал «ВиЖ» в ЯНДЕКС.ДЗЕН

+
+ + + + + +
+ +
+ + +
+ + + +
+ +
+ + + +
+ + + + +