<?php
/*

SELECT p.`post_title` , m.`meta_key` , m.`meta_value`
FROM  `wp_posts` p,  `wp_postmeta` m
WHERE p.`ID` = m.`post_id`
AND ( p.`post_type` = 'post' OR p.`post_type` = 'page' OR p.`post_type` = 'portfolio' OR p.`post_type` = 'wpcf7_contact_form' )
AND m.`meta_key` != 'contact_form_name'
AND m.`meta_key` != 'map_hnear'
AND m.`meta_key` != 'map_ll'
AND m.`meta_key` NOT LIKE '_edit_%'
AND m.`meta_key` != '_thumbnail_id'
ORDER BY p.`post_title`, m.`meta_key`, p.`ID`

*/


class dataInstallMetas{

    public $structure;
    public $posts;

    function addToWP(){
        foreach( $this->structure as $settings) {
            if( 'a:' == substr($settings['meta_value'],0,2) ){
                $settings['meta_value'] = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $settings['meta_value']);
                $settings['meta_value'] = unserialize($settings['meta_value']);
            }

            $ID = ffGetByTitle::post( $settings['post_title'] );
            
            if( empty($ID) ){
                continue;
            }
            
            add_post_meta(
                $ID,
                $settings['meta_key'],
                $settings['meta_value'],
                TRUE // UNIQUE
            );
        }
    }

    function __construct(){
        $gallery_slider_1 = "" . ffGetByTitle::image('Placeholder #1') . "";
        $gallery_slider_3 = "" . ffGetByTitle::image('Placeholder #1') . ","
                               . ffGetByTitle::image('Placeholder #2') . ","
                               . ffGetByTitle::image('Placeholder #3') . "";

        $this->structure = array(
  array('post_title' => '1000s of Images In My Mind','meta_key' => 'description_bc_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => '1000s of Images In My Mind','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => '1000s of Images In My Mind','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => '1000s of Images In My Mind','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => '1000s of Images In My Mind','meta_key' => 'fw_sidebar','meta_value' => 'default'),
  array('post_title' => '1000s of Images In My Mind','meta_key' => 'fw_sidebar_position','meta_value' => 'right'),
  array('post_title' => '1000s of Images In My Mind','meta_key' => 'map_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => '1000s of Images In My Mind','meta_key' => 'slider_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'About','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'About','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'About','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'About','meta_key' => 'gallery_columns','meta_value' => '3'),
  array('post_title' => 'About','meta_key' => 'gallery_slider','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'About','meta_key' => '_wp_page_template','meta_value' => 'default'),
  array('post_title' => 'Another awesome blog post','meta_key' => 'description_bc_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'Another awesome blog post','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Another awesome blog post','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'Another awesome blog post','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Another awesome blog post','meta_key' => 'fw_sidebar','meta_value' => 'default'),
  array('post_title' => 'Another awesome blog post','meta_key' => 'fw_sidebar_position','meta_value' => 'right'),
  array('post_title' => 'Another awesome blog post','meta_key' => 'map_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'Another awesome blog post','meta_key' => 'slider_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'Contact','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Contact','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'Contact','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Contact','meta_key' => 'gallery_columns','meta_value' => '3'),
  array('post_title' => 'Contact','meta_key' => 'gallery_slider','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Contact','meta_key' => '_wp_page_template','meta_value' => 'default'),
  array('post_title' => 'Contact form 1','meta_key' => '_additional_settings','meta_value' => ''),
  array('post_title' => 'Contact form 1','meta_key' => '_form','meta_value' => '<p>Your Name (required)<br />
    [text* your-name] </p>

<p>Your Email (required)<br />
    [email* your-email] </p>

<p>Subject<br />
    [text your-subject] </p>

<p>Your Message<br />
    [textarea your-message] </p>

<p>[submit "Send"]</p>'),
  array('post_title' => 'Contact form 1','meta_key' => '_mail','meta_value' => 'a:7:{s:7:"subject";s:14:"[your-subject]";s:6:"sender";s:26:"[your-name] <[your-email]>";s:4:"body";s:185:"From: [your-name] <[your-email]>
Subject: [your-subject]

Message Body:
[your-message]

--
This mail is sent via contact form on London Creative + http://demo.freshface.net/file/lcp5/wp";s:9:"recipient";s:27:"freshface.support@gmail.com";s:18:"additional_headers";s:0:"";s:11:"attachments";s:0:"";s:8:"use_html";i:0;}'),
  array('post_title' => 'Contact form 1','meta_key' => '_mail_2','meta_value' => 'a:8:{s:6:"active";b:0;s:7:"subject";s:14:"[your-subject]";s:6:"sender";s:26:"[your-name] <[your-email]>";s:4:"body";s:127:"Message body:
[your-message]

--
This mail is sent via contact form on London Creative + http://demo.freshface.net/file/lcp5/wp";s:9:"recipient";s:12:"[your-email]";s:18:"additional_headers";s:0:"";s:11:"attachments";s:0:"";s:8:"use_html";i:0;}'),
  array('post_title' => 'Contact form 1','meta_key' => '_messages','meta_value' => 'a:7:{s:12:"mail_sent_ok";s:43:"Your message was sent successfully. Thanks.";s:12:"mail_sent_ng";s:93:"Failed to send your message. Please try later or contact the administrator by another method.";s:16:"validation_error";s:74:"Validation errors occurred. Please confirm the fields and submit it again.";s:4:"spam";s:93:"Failed to send your message. Please try later or contact the administrator by another method.";s:12:"accept_terms";s:35:"Please accept the terms to proceed.";s:13:"invalid_email";s:28:"Email address seems invalid.";s:16:"invalid_required";s:31:"Please fill the required field.";}'),
  array('post_title' => 'Fullwidth Page','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Fullwidth Page','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'Fullwidth Page','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Fullwidth Page','meta_key' => 'gallery_columns','meta_value' => '3'),
  array('post_title' => 'Fullwidth Page','meta_key' => '_wp_page_template','meta_value' => 'fullwidth.php'),
  array('post_title' => 'Gallery','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Gallery','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'Gallery','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Gallery','meta_key' => 'gallery_columns','meta_value' => '3'),
  array('post_title' => 'Gallery','meta_key' => 'gallery_slider','meta_value' => '5'),
  array('post_title' => 'Gallery','meta_key' => '_wp_page_template','meta_value' => 'gallery.php'),
  array('post_title' => 'Gallery Fullwidth','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Gallery Fullwidth','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'Gallery Fullwidth','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Gallery Fullwidth','meta_key' => 'gallery_columns','meta_value' => '3'),
  array('post_title' => 'Gallery Fullwidth','meta_key' => 'gallery_slider','meta_value' => '5'),
  array('post_title' => 'Gallery Fullwidth','meta_key' => '_wp_page_template','meta_value' => 'gallery_fullwidth.php'),
  array('post_title' => 'HTML Test Page','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'HTML Test Page','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'HTML Test Page','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'HTML Test Page','meta_key' => 'gallery_columns','meta_value' => '3'),
  array('post_title' => 'HTML Test Page','meta_key' => '_wp_page_template','meta_value' => 'default'),
  array('post_title' => 'Lost Behind Alice In Wonderland','meta_key' => 'description_bc_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'Lost Behind Alice In Wonderland','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Lost Behind Alice In Wonderland','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'Lost Behind Alice In Wonderland','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Lost Behind Alice In Wonderland','meta_key' => 'fw_sidebar','meta_value' => 'default'),
  array('post_title' => 'Lost Behind Alice In Wonderland','meta_key' => 'fw_sidebar_position','meta_value' => 'right'),
  array('post_title' => 'Lost Behind Alice In Wonderland','meta_key' => 'map_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'Lost Behind Alice In Wonderland','meta_key' => 'slider_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'My New Buddy Is a DJ','meta_key' => 'description_bc_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'My New Buddy Is a DJ','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'My New Buddy Is a DJ','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'My New Buddy Is a DJ','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'My New Buddy Is a DJ','meta_key' => 'fw_sidebar','meta_value' => 'default'),
  array('post_title' => 'My New Buddy Is a DJ','meta_key' => 'fw_sidebar_position','meta_value' => 'right'),
  array('post_title' => 'My New Buddy Is a DJ','meta_key' => 'map_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'My New Buddy Is a DJ','meta_key' => 'slider_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'My New Digital Camera Joko VFX-5000','meta_key' => 'description_bc_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'My New Digital Camera Joko VFX-5000','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'My New Digital Camera Joko VFX-5000','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'My New Digital Camera Joko VFX-5000','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'My New Digital Camera Joko VFX-5000','meta_key' => 'fw_sidebar','meta_value' => 'default'),
  array('post_title' => 'My New Digital Camera Joko VFX-5000','meta_key' => 'fw_sidebar_position','meta_value' => 'right'),
  array('post_title' => 'My New Digital Camera Joko VFX-5000','meta_key' => 'map_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'My New Digital Camera Joko VFX-5000','meta_key' => 'slider_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'My New Ride','meta_key' => 'description_bc_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'My New Ride','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'My New Ride','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'My New Ride','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'My New Ride','meta_key' => 'fw_sidebar','meta_value' => 'default'),
  array('post_title' => 'My New Ride','meta_key' => 'fw_sidebar_position','meta_value' => 'right'),
  array('post_title' => 'My New Ride','meta_key' => 'map_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'My New Ride','meta_key' => 'slider_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'New Custom Widgets','meta_key' => 'description_bc_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'New Custom Widgets','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'New Custom Widgets','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'New Custom Widgets','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'New Custom Widgets','meta_key' => 'fw_sidebar','meta_value' => 'default'),
  array('post_title' => 'New Custom Widgets','meta_key' => 'fw_sidebar_position','meta_value' => 'right'),
  array('post_title' => 'New Custom Widgets','meta_key' => 'map_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'New Custom Widgets','meta_key' => 'slider_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'Pssst – Don’t talk, the wall’s are thin','meta_key' => 'description_bc_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'Pssst – Don’t talk, the wall’s are thin','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Pssst – Don’t talk, the wall’s are thin','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'Pssst – Don’t talk, the wall’s are thin','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Pssst – Don’t talk, the wall’s are thin','meta_key' => 'fw_sidebar','meta_value' => 'default'),
  array('post_title' => 'Pssst – Don’t talk, the wall’s are thin','meta_key' => 'fw_sidebar_position','meta_value' => 'right'),
  array('post_title' => 'Pssst – Don’t talk, the wall’s are thin','meta_key' => 'map_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'Pssst – Don’t talk, the wall’s are thin','meta_key' => 'slider_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'Pure And Clear Diamond','meta_key' => 'description_bc_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'Pure And Clear Diamond','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Pure And Clear Diamond','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'Pure And Clear Diamond','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'Pure And Clear Diamond','meta_key' => 'fw_sidebar','meta_value' => 'default'),
  array('post_title' => 'Pure And Clear Diamond','meta_key' => 'fw_sidebar_position','meta_value' => 'right'),
  array('post_title' => 'Pure And Clear Diamond','meta_key' => 'map_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'Pure And Clear Diamond','meta_key' => 'slider_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'This is a headline of your Blog Post','meta_key' => 'description_bc_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'This is a headline of your Blog Post','meta_key' => 'featured_image_height','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'This is a headline of your Blog Post','meta_key' => 'featured_image_type','meta_value' => 'lightbox'),
  array('post_title' => 'This is a headline of your Blog Post','meta_key' => 'featured_image_video_link','meta_value' => '_!!!fieldIsEmpty!!!_'),
  array('post_title' => 'This is a headline of your Blog Post','meta_key' => 'fw_sidebar','meta_value' => 'default'),
  array('post_title' => 'This is a headline of your Blog Post','meta_key' => 'fw_sidebar_position','meta_value' => 'right'),
  array('post_title' => 'This is a headline of your Blog Post','meta_key' => 'map_show','meta_value' => '_!!!fieldUnchecked!!!_'),
  array('post_title' => 'This is a headline of your Blog Post','meta_key' => 'slider_show','meta_value' => '_!!!fieldUnchecked!!!_'),
);

    }
}