<?php
  
class dataInstallWidgets{

    public $structure;
    public $widgets;

    function addToWP(){

        global $wpdb;
        $prefix = $wpdb->prefix;

        self::clearWidgets();
        
        $value = serialize( $this->widgets );

        $SQL = $wpdb->prepare(
            " INSERT INTO ".$wpdb->options."
              (`option_name`, `option_value`, `autoload`)
              VALUES
              ('sidebars_widgets', %s, 'yes')",
              $value
        );

        mysql_query( $SQL );
        
        foreach ($this->structure as $name=>$value) {
            $value = serialize( $value );

            $SQL = $wpdb->prepare(
                " INSERT INTO ".$wpdb->options."
                  (`option_name`, `option_value`, `autoload`)
                  VALUES
                  (%s, %s, 'yes')",
                  $name, $value
            );

            mysql_query( $SQL );
        }
    }
    
    function clearWidgets(){
        global $wpdb;
        $prefix = $wpdb->prefix;

        $SQL = "DELETE FROM ".$wpdb->options." WHERE `option_name` LIKE 'widget_%'";
        mysql_query( $SQL );

        $SQL = "DELETE FROM ".$wpdb->options." WHERE `option_name` = 'sidebars_widgets'";
        mysql_query( $SQL );
    }
    
    function __construct(){
        $_image = '<img src="'.get_template_directory_uri().'/images/screen_widget.jpg" style="float: left; padding: 0 10px 0 0;" alt="Screenshot" />';

        $this->structure = array (


              'widget_archives' => array ( '_multiwidget' => 1, ),


              'widget_categories' => array ( '_multiwidget' => 1, ),


              'widget_ffcontact' => array (
                2 => array (
                  'title' => 'Contact Form Widget',
                  '' => '',
                  'trans_name' => 'Name*',
                  'trans_email' => 'Email*',
                  'trans_button_send' => 'Send E-Mail',
                  'trans_message_ok' => 'Message has been sent',
                  'trans_message_wrong' => 'Message was not sent, please try again later',
                  'email' => 'no.mailz.plz@mailinator.com',
                  'subject' => 'TEST email from lcp net demo',
                ),
                '_multiwidget' => 1,
              ),


              'widget_ffpopularposts' => array (
                2 => array (
                  'popular_title' => 'Popular Posts Widget',
                  'popular_categories' => '2',
                  'popular_num_of_posts' => '3',
                ),
                3 => array (
                  'popular_title' => 'Popular',
                  'popular_categories' => '2',
                  'popular_num_of_posts' => '3',
                ),
                '_multiwidget' => 1,
              ),


              'widget_ffsocial' => array (
                2 => array (
                  'title' => 'Social widget',
                  'social' => "https://twitter.com/_freshface\n".
                              "https://www.facebook.com/home.php\n".
                              "http://www.linkedin.com/\n".
                              "https://www.tumblr.com/\n".
                              "http://www.flickr.com/\n".
                              "https://delicious.com/\n".
                              "rss: http://googleblog.blogspot.com/feeds/posts/default?alt=rss\n".
                              "email: mailto:someone@example.com?Subject=Hello\n".
                              "http://www.youtube.com/watch?v=L83cTan6ESk\n".
                              "http://vimeo.com/\n".
                              "http://www.skype.com/\n".
                              "",
                ),
                '_multiwidget' => 1,
              ),


              'widget_fftwitter' => array (
                2 => array (
                  'title' => 'Twitter Widget',
                  'username' => '_freshface',
                  'number' => '2',
                ),
                '_multiwidget' => 1,
              ),


              'widget_meta' => array ( '_multiwidget' => 1, ),


              'widget_nav_menu' => array (
                2 => array (
                  'title' => 'Custom Menu',
                  'nav_menu' => ffGetByTitle::term('blog cat widget'),
                ),
                '_multiwidget' => 1,
              ),


              'widget_recent-comments' => array ( '_multiwidget' => 1, ),


              'widget_recent-posts' => array ( '_multiwidget' => 1, ),


              'widget_rss' => array ( ),


              'widget_search' => array ( '_multiwidget' => 1, ),


              'widget_text' => array (
                  2 => array (
                    'title' => 'This is a text widget',
                    'text' => '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.',
                    'filter' => false,
                  ),
                  3 => array (
                    'title' => 'Informations about this theme',
                    'text' => $_image.'This is a text widget. You can have them as many as you like.<br /><br />'
                              . "\n\n"
                              . 'This theme comes with fully working contact form, awesome slider for your featured images, nasty spinning slider buttons (never saw them anywhere else, so you can call it unique), 2 message buttons under the slider, PrettyPhoto plugin (better clone of Lightbox), 4 widgetized sidebars and theme options panel with extensive possibilities.<br /><br />'
                              . "\n\n"
                              . 'You will also have user-friendly dropdown navigation with infinite dropdown levels where you can manage your menu in special Menu Manager, so no more hassle, it\'s automatic, you can just add posts and you are ready to go!',
                    'filter' => false,
                  ),
                  5 => array (
                    'title' => 'This is a text widget',
                    'text' => $_image.'This is a text widget. You can have them as many as you like.<br /><br />'
                              . "\n\n"
                              . 'This theme comes with fully working contact form, awesome slider for your featured images, nasty spinning slider buttons (never saw them anywhere else, so you can call it unique), 2 message buttons under the slider, PrettyPhoto plugin (better clone of Lightbox), 4 widgetized sidebars and theme options panel with extensive possibilities.<br /><br />'
                              . "\n\n"
                              . 'You will also have user-friendly dropdown navigation with infinite dropdown levels where you can manage your menu in special Menu Manager, so no more hassle, it\'s automatic, you can just add posts and you are ready to go!',
                    'filter' => false,
                  ),
                  6 => array (
                    'title' => 'Informations about this theme',
                    'text' => $_image.'This is a text widget. You can have them as many as you like.<br /><br />'
                              . "\n\n"
                              . 'This theme comes with fully working contact form, awesome slider for your featured images, nasty spinning slider buttons (never saw them anywhere else, so you can call it unique), 2 message buttons under the slider, PrettyPhoto plugin (better clone of Lightbox), 4 widgetized sidebars and theme options panel with extensive possibilities.<br /><br />'
                              . "\n\n"
                              . 'You will also have user-friendly dropdown navigation with infinite dropdown levels where you can manage your menu in special Menu Manager, so no more hassle, it\'s automatic, you can just add posts and you are ready to go!',
                    'filter' => false,
                  ),
                  7 => array (
                    'title' => 'This is a text widget',
                    'text' => '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.',
                    'filter' => false,
                  ),
                  8 => array (
                    'title' => 'Informations about this theme',
                    'text' => $_image.'This is a text widget. You can have them as many as you like.<br /><br />'
                              . "\n\n"
                              . 'This theme comes with fully working contact form, awesome slider for your featured images, nasty spinning slider buttons (never saw them anywhere else, so you can call it unique), 2 message buttons under the slider, PrettyPhoto plugin (better clone of Lightbox), 4 widgetized sidebars and theme options panel with extensive possibilities.<br /><br />'
                              . "\n\n"
                              . 'You will also have user-friendly dropdown navigation with infinite dropdown levels where you can manage your menu in special Menu Manager, so no more hassle, it\'s automatic, you can just add posts and you are ready to go!',
                    'filter' => false,
                  ),
                  9 => array (
                    'title' => 'This is a text widget',
                    'text' => '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.',
                    'filter' => false,
                  ),
                  10 => array (
                    'title' => 'Informations about this theme',
                    'text' => $_image.'This is a little shorter text widget thanks to the 5 different sidebars (Home, Page, Blog, Portfolio, Single).<br /><br />'
                              . "\n\n"
                              . 'This theme comes with fully working contact form, awesome slider for your featured images, nasty spinning slider buttons (never saw them anywhere else, so you can call it unique), 2 message buttons under the slider, PrettyPhoto plugin (better clone of Lightbox), 4 widgetized sidebars and theme options panel with extensive possibilities.',
                    'filter' => false,
                  ),
                  11 => array (
                    'title' => 'This is a text widget',
                    'text' => '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.',
                    'filter' => false,
                  ),
                  12 => array (
                    'title' => 'Informations about this theme',
                    'text' => $_image.'This is a little shorter text widget thanks to the 5 different sidebars (Home, Page, Blog, Portfolio, Single).<br /><br />'
                              . "\n\n"
                              . 'This theme comes with fully working contact form, awesome slider for your featured images, nasty spinning slider buttons (never saw them anywhere else, so you can call it unique), 2 message buttons under the slider, PrettyPhoto plugin (better clone of Lightbox), 4 widgetized sidebars and theme options panel with extensive possibilities.',
                    'filter' => false,
                  ),
                  '_multiwidget' => 1,
                ),
        ); // $this->structure = array (



        $this->widgets = array (
            'wp_inactive_widgets' => array ( ),
            'lcp-global' => array ( ),
            'lcp-home' => array ( 0 => 'text-2', 1 => 'text-3', ),
            'lcp-blog' => array ( 0 => 'text-5', 1 => 'text-6', 2 => 'nav_menu-2', ),
            'lcp-blog-single' => array ( 0 => 'ffsocial-2', 1 => 'ffpopularposts-2', 2 => 'fftwitter-2', 3 => 'ffcontact-2', ),
            'lcp-portfolio-single' => array ( 0 => 'text-7', 1 => 'text-8', 2 => 'ffpopularposts-3', ),
            'lcp-page' => array ( 0 => 'text-9', 1 => 'text-10', ),
            'lcp-search' => array ( 0 => 'text-11', 1 => 'text-12', ),
            'array_version' => 3,
        ); // $this->widgets = array (
    }
}


/*

$wp_options = array(
  array('option_id' => '96','option_name' => 'widget_archives','option_value' => 'a:1:{s:12:"_multiwidget";i:1;}','autoload' => 'yes'),
    ....
);

$widgets = array();
foreach ($wp_options as $key=>$data) {
    $widgets[ $data['name'] ] = unserialize($data['value']);
}

echo var_export($widgets);

*/