function createPostFromXML() { $context = stream_context_create(array('http' => array('header' => 'Accept: application/xml'))); $url = 'http://sports.yahoo.com/nba/photos/rss.xml'; $xml = file_get_contents($url, false, $context); $xmlparse = simplexml_load_string($xml); foreach ($xmlparse->channel[0]->item as $node) { //RECUPERATION DE L'IMAGE------------------------------------------------- preg_match("/<img[^>]+\\>/i", $node->description, $m); preg_match("/http:\\/\\/media.zenfs.com(.*)/", $m[0], $n); $j = explode('"', $n[0]); $image = $j[0]; //------------------------------------------------------------------------ //RECUPERATION DE LA DESCRIPTION------------------------------------------ $descriptionWithoutImg = preg_replace("/<img[^>]+\\>/i", "", $node->description); $descriptionWithTag = preg_replace("/<a[^>]+\\>/i", "", $descriptionWithoutImg); $description = strip_tags($descriptionWithTag); //------------------------------------------------------------------------ $post = array('post_title' => $node->title, 'post_content' => $description, 'post_status' => 'publish'); $post_id = wp_insert_post($post, true); set_post_format($post_id, "Image"); generate_Featured_Image($image, $post_id); } }
function addReview() { //Sanitize input data using PHP filter_var(). $name = $_POST["name"]; $mail = $_POST["mail"]; $phone = $_POST["phone"]; $rating = $_POST["rating"]; $message = $_POST["message"]; $post_data = array('post_title' => $name, 'post_content' => $message, 'post_status' => 'draft', 'post_author' => 1, 'post_type' => 'reviews'); $post_id = wp_insert_post($post_data); update_post_meta($post_id, 'rating', $rating); if ($_FILES['file_attach']) { $image = wp_upload_bits($_FILES['file_attach']['name'], null, file_get_contents($_FILES['file_attach']['tmp_name'])); generate_Featured_Image($image['url'], $post_id); } $adminMail = get_option('admin_email'); $str = "С вашего сайта оставили отзыв:<br>"; $str .= 'Имя: ' . $name . ' <br>'; $str .= 'Email: ' . $mail . ' <br>'; $str .= 'Телефон: ' . $phone . ' <br>'; $str .= 'Рейтинг: ' . $rating . ' <br>'; $str .= 'Отзыв : ' . $message . ' <br>'; mail($adminMail, "Письмо с сайта Суши", $str, "Content-type: text/html; charset=UTF-8\r\n"); $output = json_encode(array('message' => 'Спасибо за отзыв!')); die($output); }