<?php

/*

SELECT `post_title`, `post_content`, `post_type`
FROM `wp_posts`
WHERE `post_type` = 'post'
AND `post_status` = 'publish'


SELECT `post_title`, `post_content`, `post_type`
FROM `wp_posts`
WHERE `post_type` = 'page'
AND `post_status` = 'publish'


SELECT `post_title`, `post_content`, `post_type`
FROM `wp_posts`
WHERE `post_type` = 'portfolio'
AND `post_status` = 'publish'


SELECT `post_title`, `post_content`, `post_type`
FROM `wp_posts`
WHERE `post_type` = 'wpcf7_contact_form'
AND `post_status` = 'publish'


*/

  
class dataInstallPosts{

    public $structure;
    public $ids = array();
    
    function addToWP( $post_type = '' ){
        foreach( $this->structure as $key=>$settings) {
            if( ! empty($post_type) ){
                if( $post_type != $settings['post_type'] ){
                    continue;
                }
            }

            // avoid to insert that post twice
            //$post = get_page_by_title( $settings['post_title'], 'OBJECT', $settings['post_type'] );
            $post = ffGetByTitle::post( $settings['post_title'] );
            if( $post ){
                //$this->structure[$key]['ID'] = $post->ID;
                $this->structure[$key]['ID'] = $post;
            }else{
                $this->structure[$key]['ID'] = wp_insert_post( $settings, TRUE );
            }
            $this->ids[ $settings['post_title'] ] = $this->structure[$key]['ID'];
            
            if( ( 'post' == $settings['post_type'] ) or ( 'portfolio' == $settings['post_type'] ) ){
                // add featured image
                add_post_meta(
                    $this->structure[$key]['ID'],
                    '_thumbnail_id',
                    ffGetByTitle::image('Placeholder #1'),
                    true
                );
            }

            if( !empty($settings['category']) ){
                $this->setTaxIds($this->structure[$key]['ID'], $settings['category'], 'category');
            }

            if( !empty($settings['post_tag']) ){
                $this->setTaxIds($this->structure[$key]['ID'], $settings['post_tag'], 'post_tag');
            }
        }
    }
    
    function setTaxIds($post_ID, $tax_text, $tax_type){

        if( FALSE === strpos($tax_text, ',') ){
            $t_tax = array( trim($tax_text) );
        }else{
            $t_tax = explode(',',$tax_text);
            foreach ($t_tax as $key=>$title) {
                $t_tax[$key] = trim($title);
            }
        }

        $tax_IDs = array();

        foreach ($t_tax as $key=>$title) {
            $tax_ID = ffGetByTitle::term($title);
            if( 0 == $tax_ID ){
                continue;
            }

            $tax_IDs[] = $tax_ID;
        }

        wp_set_object_terms( $post_ID, $tax_IDs, $tax_type, false);

    }

    function __construct(){

        $orig_screen = get_template_directory_uri()."/images/screen_widget.jpg";

        $this->structure = array();


        // PAGES


        /*
        $this->structure[] = array( 'post_title'=>'3D Slider',
                                    'comment_status'=>'closed','ping_status'=>'closed',
                                    'post_status'=>'publish','post_type'=>'page',
                                    'post_content'=>'[templatebuilder name="aboutus"]');
        */

        $this->structure[] = array( 'post_title' => 'Sample Page',
                                    'post_content' => 'This is an example page. It\'s different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:'."\n".''."\n".'<blockquote>Hi there! I\'m a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin\' caught in the rain.)</blockquote>'."\n".''."\n".'...or something like this:'."\n".''."\n".'<blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>'."\n".''."\n".'As a new WordPress user, you should go to <a href="'.get_home_url().'/wp-admin/">your dashboard</a> to delete this page and create new pages for your content. Have fun!',
                                    'comment_status'=>'closed',
                                    'ping_status'=>'closed',
                                    'post_status'=>'publish',
                                    'post_type' => 'page');


        $this->structure[] = array( 'post_title' => 'Fullwidth Page',
                                    'post_content' => 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).'."\n".''."\n".'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).'."\n".''."\n".'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',
                                    'comment_status'=>'closed',
                                    'ping_status'=>'closed',
                                    'post_status'=>'publish',
                                    'post_type' => 'page');


        $this->structure[] = array( 'post_title' => 'HTML Test Page',
                                    'post_content' => '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec libero. Suspendisse bibendum. Cras id urna. Morbi tincidunt, orci ac convallis aliquam, lectus turpis<!--more--></p>'."\n".'<h3>Text and Image</h3>'."\n".'<p><img class="float_left" src="'.$orig_screen.'" alt="screenshot" /> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec libero. Suspendisse bibendum. Cras id urna. Morbi tincidunt, orci ac convallis aliquam, lectus turpis varius lorem, eu posuere nunc justo tempus leo. Donec mattis, purus nec placerat bibendum, dui pede condimentum odio, ac blandit ante orci ut diam. Cras fringilla magna. Phasellus suscipit, leo a pharetra condimentum, lorem tellus eleifend magna, eget fringilla velit magna id neque. Curabitur vel urna. In tristique orci porttitor ipsum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec libero. Suspendisse bibendum. Cras id urna. Morbi tincidunt, orci ac convallis aliquam, lectus turpis varius lorem, eu posuere nunc justo tempus leo.</p>'."\n".'<p>A <a href="#">link</a>, <acronym title="this really isn\'t a very good description">acronym</acronym>, <strong>strong text</strong> and <del>deleted text</del>.</p>'."\n".'<h3>Code</h3>'."\n".'<p><code> code-sample {<br />'."\n".'font-weight: bold;<br />'."\n".'font-style: italic;<br />'."\n".'} </code></p>'."\n".'<h3>Example Lists</h3>'."\n".'<ol>'."\n".'<li>Here is an example</li>'."\n".'<li>of an ordered list</li>'."\n".'</ol>'."\n".'<ul>'."\n".'<li>Here is an example</li>'."\n".'<li>of an unordered list</li>'."\n".'</ul>'."\n".'<h3>Blockquote</h3>'."\n".'<blockquote><p>Someone\'s sitting in the shade today because someone planted a tree a long time ago.</p>'."\n".'<p class="align-right">- Warren Buffett</p>'."\n".'</blockquote>'."\n".'<h3>Headers</h3>'."\n".'<p><a href="#"><br />'."\n".'</a></p>'."\n".'<h1>H1 Heading</h1>'."\n".'<h2>H2 Heading</h2>'."\n".'<h3>H3 Heading</h3>'."\n".'<h4>H4 Heading</h4>'."\n".'<h3>Tabular Data</h3>'."\n".'<table border="0">'."\n".'<tbody>'."\n".'<tr>'."\n".'<th>post date</th>'."\n".'<th>title</th>'."\n".'<th>description</th>'."\n".'</tr>'."\n".'<tr>'."\n".'<td>08.18.2009</td>'."\n".'<td>Augue non nibh</td>'."\n".'<td>Commodo <a href="#">metus</a> vestibulum hdhdh djdjdj djdjdj</td>'."\n".'</tr>'."\n".'<tr>'."\n".'<td>08.18.2009</td>'."\n".'<td>Fusce ut diam</td>'."\n".'<td>Purus in eget odio in sapien</td>'."\n".'</tr>'."\n".'<tr>'."\n".'<td>08.18.2009</td>'."\n".'<td>Augue non nibh</td>'."\n".'<td>Adipiscing blandit</td>'."\n".'</tr>'."\n".'<tr>'."\n".'<td>08.18.2009</td>'."\n".'<td>Sed vestibulum</td>'."\n".'<td>Cras <a href="#">lobortis</a> commodo</td>'."\n".'</tr>'."\n".'</tbody>'."\n".'</table>',
                                    'comment_status'=>'closed',
                                    'ping_status'=>'closed',
                                    'post_status'=>'publish',
                                    'post_type' => 'page');


        $this->structure[] = array( 'post_title' => 'Gallery',
                                    'post_content' => 'Hey guys, this Gallery page feature was introduced in the latest version of London Creative +. You can write some introduction text here if you want or not, it’s up to you, like most things in my theme. All updates are FREE for those who already purchased this theme, so just re-download the package from your account. Enjoy!',
                                    'comment_status'=>'closed',
                                    'ping_status'=>'closed',
                                    'post_status'=>'publish',
                                    'post_type' => 'page');


        $this->structure[] = array( 'post_title' => 'Gallery Fullwidth',
                                    'post_content' => 'Hey guys, this Gallery Fullwidth page was introduced in the latest version of London Creative +. You can write some introduction text here if you want or not, it’s up to you, like most things in my theme. All updates are FREE for those who already purchased this theme, so just re-download the package from your account. Enjoy!',
                                    'comment_status'=>'closed',
                                    'ping_status'=>'closed',
                                    'post_status'=>'publish',
                                    'post_type' => 'page');


        $this->structure[] = array( 'post_title' => 'Contact',
                                    'post_content' => 'Dear Buyer! This is fully working contact form with validation of each field, including validation of inserting the right format of e-mail address. You can try it by hitting Send button. After you will buy this theme, add your e-mail address etc. in Theme Options and you are ready to go. It’s that easy! Oh yeah!'."\n".''."\n".
                                                      '[contact-form-7 id="46" title="Contact form 1"]',
                                    'comment_status'=>'closed',
                                    'ping_status'=>'closed',
                                    'post_status'=>'publish',
                                    'post_type' => 'page');


        $this->structure[] = array( 'post_title' => 'About',
                                    'post_content' => 'This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.',
                                    'comment_status'=>'closed',
                                    'ping_status'=>'closed',
                                    'post_status'=>'publish',
                                    'post_type' => 'page');


        // POSTS

        /*
        $this->structure[] = array(
            'post_title'    => 'Last but not least, I am the lightbox post and I can group media',
            'post_content'  => $lorem, 'post_excerpt' => $excerpt1, 'post_status' => 'publish', 'post_author' => 1,
            'category'      => 'Blog Large',
            'post_tag'      => 'Art, Branding, Development, HTML5, Marketing, PHP, Web Design, Web studio',
            'post_type'     => 'post', );
        */
        
        $this->structure[] = array( 'post_title' => 'This is a headline of your Blog Post',
                                    'post_content' => 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has <!--more-->a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',
                                    'category' => 'Blog',
                                    'post_status'=>'publish',
                                    'post_type' => 'post', );

        $this->structure[] = array( 'post_title' => 'Another awesome blog post',
                                    'post_content' => 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has <!--more-->a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',
                                    'category' => 'Blog',
                                    'post_status'=>'publish',
                                    'post_type' => 'post', );

        $this->structure[] = array( 'post_title' => 'New Custom Widgets',
                                    'post_content' => 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has <!--more-->a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',
                                    'category' => 'Blog',
                                    'post_status'=>'publish',
                                    'post_type' => 'post', );

        $this->structure[] = array( 'post_title' => 'My New Digital Camera Joko VFX-5000',
                                    'post_content' => 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has <!--more-->a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',
                                    'category' => 'Blog',
                                    'post_status'=>'publish',
                                    'post_type' => 'post', );

        $this->structure[] = array( 'post_title' => 'Lost Behind Alice In Wonderland',
                                    'post_content' => 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has <!--more-->a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',
                                    'category' => 'Blog',
                                    'post_status'=>'publish',
                                    'post_type' => 'post', );


        // PORTFOLIO


        /*
        $this->structure[] = array(
            'post_title'    => 'The good old classics',
            'post_content'  => $lorem, 'post_status' => 'publish', 'post_author' => 1,
            'category'      => 'Portfolio Filterable 3, Portfolio Filterable 4, Portfolio Filterable 5, Portfolio Pagination 3, Portfolio Pagination 4, Portfolio Pagination 5',
            'post_tag'      => 'Web Design',
            'post_type'     => 'portfolio', );
        */

        $this->structure[] = array( 'post_title' => 'My New Ride',
                                    'post_content' => 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has <!--more-->a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',
                                    'category' => 'Portfolio, Portfolio Fullwidth',
                                    'post_status'=>'publish',
                                    'post_type' => 'portfolio', );


        $this->structure[] = array( 'post_title' => 'Pure And Clear Diamond',
                                    'post_content' => 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has <!--more-->a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',
                                    'category' => 'Portfolio, Portfolio Fullwidth',
                                    'post_status'=>'publish',
                                    'post_type' => 'portfolio', );


        $this->structure[] = array( 'post_title' => 'My New Buddy Is a DJ',
                                    'post_content' => 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has <!--more-->a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',
                                    'category' => 'Portfolio, Portfolio Fullwidth',
                                    'post_status'=>'publish',
                                    'post_type' => 'portfolio', );


        $this->structure[] = array( 'post_title' => 'Pssst – Don’t talk, the wall’s are thin',
                                    'post_content' => 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has <!--more-->a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',
                                    'category' => 'Portfolio, Portfolio Fullwidth',
                                    'post_status'=>'publish',
                                    'post_type' => 'portfolio', );


        $this->structure[] = array( 'post_title' => '1000s of Images In My Mind',
                                    'post_content' => 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has <!--more-->a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',
                                    'category' => 'Portfolio, Portfolio Fullwidth',
                                    'post_status'=>'publish',
                                    'post_type' => 'portfolio', );



        // CONTACT FORM


        /*
        $this->structure[] = array( 'post_title' => 'WG - request quote',
                                    'comment_status'=>'closed','ping_status'=>'closed',
                                    'post_status'=>'publish','post_type' => 'wpcf7_contact_form',
                                    'post_content' => '<span class="black">Your name*</span><br />.......Your entered code is incorrect.');
        */
        
        $this->structure[] = array( 'post_title' => 'Contact form 1',
                                    'post_content' => '<p>Your Name (required)<br />'."\n".'    [text* your-name] </p>'."\n".''."\n".'<p>Your Email (required)<br />'."\n".'    [email* your-email] </p>'."\n".''."\n".'<p>Subject<br />'."\n".'    [text your-subject] </p>'."\n".''."\n".'<p>Your Message<br />'."\n".'    [textarea your-message] </p>'."\n".''."\n".'<p>[submit "Send"]</p>'."\n".'[your-subject]'."\n".'[your-name] <[your-email]>'."\n".'From: [your-name] <[your-email]>'."\n".'Subject: [your-subject]'."\n".''."\n".'Message Body:'."\n".'[your-message]'."\n".''."\n".'--'."\n".'This mail is sent via contact form on London Creative + http://demo.freshface.net/file/lcp5/wp'."\n".'freshface.support@gmail.com'."\n".''."\n".''."\n".'0'."\n".''."\n".'[your-subject]'."\n".'[your-name] <[your-email]>'."\n".'Message body:'."\n".'[your-message]'."\n".''."\n".'--'."\n".'This mail is sent via contact form on London Creative + http://demo.freshface.net/file/lcp5/wp'."\n".'[your-email]'."\n".''."\n".''."\n".'0'."\n".'Your message was sent successfully. Thanks.'."\n".'Failed to send your message. Please try later or contact the administrator by another method.'."\n".'Validation errors occurred. Please confirm the fields and submit it again.'."\n".'Failed to send your message. Please try later or contact the administrator by another method.'."\n".'Please accept the terms to proceed.'."\n".'Email address seems invalid.'."\n".'Please fill the required field.',
                                    'post_status'=>'publish',
                                    'post_type' => 'wpcf7_contact_form');


    }
}