/** * @BeforeSuite */ public static function prepare(SuiteEvent $scope) { $promoTitle = 'Test (system) - promo'; $postTitle = 'Test (system) - promo post'; $promo = new \Mesh\Post($promoTitle, 'promo'); $promo->set('data_to_capture', 'a:1:{i:0;s:8:"fullName";}'); $promo->set('collect_optins', 1); $promo->set('third_party_optins_0_optin_name', 'Croissant'); $promo->set('third_party_optins_0_optin_label', 'Would you like to hear from Croissant?'); $promo->set('third_party_optins', 1); $promo->set('terms_and_conditions_label', 'I accept the terms and conditions'); $promo->set('terms_and_conditions', 'Test terms and conditions'); $promo->set('start_time', 1441065600); $promo->set('end_time', 1916697600); $promo->set('selected_passport', '{"id":"test_promotion_main-subscribe","shared_secret":"6a9962bdd2359e32a4090951829247b1db507fc3b66b25c34e02e257c3ef9e48"}'); $promo->set('promotion_passport', '{"id":"test_promotion_main-subscribe","shared_secret":"6a9962bdd2359e32a4090951829247b1db507fc3b66b25c34e02e257c3ef9e48"}'); self::$testPostPromo = new Mesh\Post($postTitle, 'post'); self::$testPostPromo->set('short_headline', 'Test (system) - promo'); self::$testPostPromo->set('sell', 'This is an automated test'); self::$testPostPromo->set('widgets_0_promo_post', $promo->id); self::$testPostPromo->set('widgets', 'a:1:{i:0;s:12:"promo_plugin";}'); self::$testPostPromo->set('post_status', 'publish'); }
public static function getPostFromUrl($postUrl) { $fail = false; $postJsonUrl = $postUrl . '.json'; try { $postString = file_get_contents($postJsonUrl); } catch (Exception $e) { self::notifyError('Unable to retrieve JSON from URL ' . $postJsonUrl); return false; } if (!($object = json_decode($postString))) { self::notifyError('Unable to retrieve JSON from URL ' . $postJsonUrl); $fail = true; } if (!isset($object->article)) { self::notifyError('"Article" property does not exist in JSON, might be a full page embed or microsite'); $fail = true; } if ($fail) { return false; } $postObject = $object->article; $postDom = HtmlDomParser::str_get_html($object->content); $postReformatted = new stdClass(); $meshPost = new \Mesh\Post($postObject->slug); $meshPost->set('catfish_importer_url', $postUrl, true); $meshPost->set('catfish_importer_imported', true, true); $meshPost->set('catfish_importer_date_updated', time(), true); $meshPost->set('post_title', $postObject->headline); $meshPost->set('header_type', 'standard-hero'); $meshPost->set('header_display_headline', true); $meshPost->set('header_display_sell', true); // Set post published date $displayDate = strtotime($postObject->displayDate); $displayDate = date('o\\-m\\-d G\\:i\\:s', $displayDate); wp_update_post(array('ID' => $meshPost->id, 'post_date' => $displayDate, 'post_date_gmt' => $displayDate, 'post_modified' => $displayDate, 'post_modified_gmt' => $displayDate)); if (isset($object->article->__author) && isset($object->article->__author->emailAddress) && $object->article->__author->emailAddress) { $meshPost->set('post_author', self::setAuthor($object->article->__author)); } else { $get_author_details = get_field('catfish_default_author', 'option'); $default_author = $get_author_details['ID']; $meshPost->set('post_author', $default_author, true); } Category::attachCategories($object->article->section, $postUrl, $meshPost->id); $postTags = array(); foreach ($object->article->tags as $tag) { if ($tag->type !== 'System') { array_push($postTags, ucwords($tag->tag)); } } wp_set_post_tags($meshPost->id, $postTags); $sell = !empty($postObject->sell) ? $postObject->sell : $postObject->headline; $meshPost->set('short_headline', $postObject->shortHeadline, true); $meshPost->set('sell', $sell, true); $meshPost->set('catfish_importer_imported', true, true); // If automated testing, set some metadata if (isset($_SERVER['is-automated-testing'])) { $meshPost->set('automated_testing', true, true); } if (!($post = new TimberPost($meshPost->id))) { self::notifyError('Unexpected exception where Mesh did not create/fetch a post'); } $show_header = self::setHeroImages($post, $postDom, $postObject); $meshPost->set('header_display_hero_image', $show_header); $widgets = Widget::getWidgetsFromDom($postDom); Widget::setPostWidgets($post, $widgets, $postObject); do_action('catfish_importer_post', $post->ID); return $post; }