/**
  * Initializes the Component.
  * @since 1.0.0
  */
 function __construct()
 {
     $this->name = get_class($this);
     $this->includes();
     if ('status' == skip\value('fbfpi_settings', 'insert_post_type')) {
         add_action('init', array($this, 'custom_post_types'), 11);
     }
     // Functions in Admin
     if (is_admin()) {
         // add_action( 'admin_menu', array( $this, 'admin_menu' ) );
     }
 }
Example #2
0
function skip_test()
{
    echo '<div class="wrap">';
    echo '<h2>Check</h2>';
    echo '<p>Wir testen die Formularfunktionen.</p>';
    skip\form_start('testform');
    skip\textfield('name', 'Name');
    skip\textarea('description', 'Describe you a bit');
    skip\color('color', 'Choose your favourite color');
    skip\checkbox('checkthis', 'yes', 'Check This!');
    skip\radio('radioval', '1', 'Eins');
    skip\radio('radioval', '2', 'Zwei');
    skip\radio('radioval', '3', 'Drei');
    skip\select('selectval', 'Eins,Zwei,Drei', 'Wähl mal');
    skip\autocomplete('completeit', 'Car,House,Fish,Meal', 'Autocomplete');
    skip\editor('mylonghtmltext', 'Ein Langer Text');
    skip\file('uploadme', 'Datei');
    skip\wp_file('uploadmetoo', 'WP Dateiupload');
    skip\hidden('hiddenvalue');
    skip\button('Save');
    skip\form_end();
    echo skip\value('testform', 'radioval');
    echo '</div>';
}
 /**
  * Functions of the Component
  * @since 1.0.0
  */
 public function import()
 {
     global $wpdb;
     set_time_limit(240);
     $ffbc = new FacebookFanpageConnect($this->page_id);
     $page_details = $ffbc->get_page();
     $entries = $ffbc->get_posts($this->update_num);
     if ('status' == skip\value('fbfpi_settings', 'insert_post_type')) {
         $post_type = 'status-message';
     } else {
         $post_type = 'post';
     }
     $post_status = skip\value('fbfpi_settings', 'insert_post_status');
     if ('' == $post_status) {
         $post_status = 'draft';
     }
     $author_id = skip\value('fbfpi_settings', 'insert_user_id');
     $post_format = skip\value('fbfpi_settings', 'insert_post_format');
     if ('' == $post_format) {
         $post_format = 'none';
     }
     $i = 0;
     if (count($entries) > 0) {
         foreach ($entries as $entry) {
             $sql = $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} AS p, {$wpdb->postmeta} AS m WHERE p.ID = m.post_id  AND p.post_type='%s' AND p.post_status <> 'trash' AND m.meta_key = 'entry_id'  AND m.meta_value = '%s'", $post_type, $entry->id);
             $post_count = $wpdb->get_var($sql);
             if ($post_count > 0) {
                 // If entry already exists
                 continue;
             }
             if (!property_exists($entry, 'message')) {
                 continue;
             }
             // Get post picture URL (Made here, because needed twice)
             $post_picture = $ffbc->get_post_picture($entry->id);
             if (property_exists($post_picture, 'full_picture')) {
                 $picture_url = $post_picture->full_picture;
             }
             // Post title
             $post_title = '';
             if (property_exists($entry, 'message') && '' != $entry->message) {
                 $post_title = $entry->message;
             }
             if (property_exists($entry, 'description') && '' != $entry->description && '' == $post_title) {
                 $post_title = $entry->description;
             }
             $post_title = $this->set_title($post_title);
             // Inserting raw post without content
             $post = array('comment_status' => 'closed', 'ping_status' => 'open', 'post_date' => date('Y-m-d H:i:s', strtotime($entry->created_time)), 'post_status' => $post_status, 'post_title' => $post_title, 'post_type' => $post_type, 'post_excerpt' => $entry->message, 'post_author' => $author_id);
             $post_id = wp_insert_post($post);
             $post = get_post($post_id);
             $attach_id = '';
             // Relink URLs
             $entry->message = $this->set_links($entry->message);
             // Getting Hashtags
             preg_match_all("/(#\\w+)/", $entry->message, $found_hash_tags);
             $found_hash_tags = $found_hash_tags[1];
             $tags = array();
             foreach ($found_hash_tags as $hash_tag) {
                 $tags[] = substr($hash_tag, 1, strlen($hash_tag));
             }
             if (count($tags) > 0) {
                 wp_set_post_tags($post_id, $tags);
             }
             // Post content
             switch ($entry->type) {
                 case 'link':
                     if (!empty($picture_url)) {
                         $attach_id = $this->fetch_picture($picture_url, $post_id);
                     }
                     $post->post_content = $this->get_link_content($entry, $attach_id);
                     break;
                 case 'photo':
                     $picture_url = $ffbc->get_photo_by_object($entry->object_id);
                     if (!empty($picture_url)) {
                         $attach_id = $this->fetch_picture($picture_url, $post_id);
                     }
                     $post->post_content = $this->get_photo_content($entry, $attach_id);
                     if (!empty($attach_id)) {
                         set_post_thumbnail($post_id, $attach_id);
                     }
                     break;
                 case 'video':
                     if (!empty($entry->picture)) {
                         $attach_id = $this->fetch_picture($entry->picture, $post_id);
                     }
                     $post->post_content = $this->get_video_content($entry, $attach_id);
                     if (!empty($attach_id)) {
                         set_post_thumbnail($post_id, $attach_id);
                     }
                     break;
                 case 'status':
                     $post->post_content = $this->set_links($entry->message);
                     if (!empty($attach_id)) {
                         set_post_thumbnail($post_id, $attach_id);
                     }
                     break;
                 default:
                     // skip\p( $entry );
                     break;
             }
             wp_update_post($post);
             // skip\p($entry);
             // Updating post meta
             $ids = explode('_', $entry->id);
             $pure_entry_id = $ids[1];
             $entry_url = $page_details->link . '/posts/' . $pure_entry_id;
             if (property_exists($entry, 'id')) {
                 update_post_meta($post_id, 'entry_id', $entry->id);
             }
             if (property_exists($entry, 'message')) {
                 update_post_meta($post_id, 'message', $entry->message);
             }
             if (property_exists($entry, 'description')) {
                 update_post_meta($post_id, 'description', $entry->description);
             }
             update_post_meta($post_id, 'image_url', $post_picture);
             update_post_meta($post_id, 'fanpage_id', $this->page_id);
             update_post_meta($post_id, 'fanpage_name', $page_details->name);
             update_post_meta($post_id, 'fanpage_link', $page_details->link);
             update_post_meta($post_id, 'entry_url', $entry_url);
             update_post_meta($post_id, 'type', $entry->type);
             if ('none' != $post_format) {
                 set_post_format($post_id, $post_format);
             }
             $i++;
         }
         $this->notices[] = sprintf(__('%s entries have been imported.', 'fbfpi'), $i);
     }
 }
 /**
  * Registers and enqueues plugin-specific styles.
  * @since 1.0.0
  */
 public function register_plugin_styles()
 {
     if ('' == skip\value('fbfpi_settings', 'own_css')) {
         wp_enqueue_style('fbfpi-plugin-styles', FBFPI_URLPATH . '/includes/css/display.css');
     }
 }
 /**
  * Content of the admin page.
  * @since 1.0.0
  */
 public function admin_page()
 {
     echo '<div class="wrap">';
     echo '<div id="icon-options-general" class="icon32 icon32-posts-post"></div>';
     echo '<h2>' . __('Facebook Fanpage Import', 'fbfpi') . '</h2>';
     echo '<p>' . __('Just put in your Fanpage ID and start importing.', 'fbfpi') . '</p>';
     skip\form_start('fbfpi_settings');
     /**
      * Fanpage ID
      */
     skip\textfield('page_id', __('Page ID', 'fbfpi'));
     /**
      * Select stream languages
      */
     $available_languages = get_available_languages();
     if (!in_array('en_US', $available_languages)) {
         $available_languages[] = 'en_US';
     }
     foreach ($available_languages as $language) {
         $select_languages[] = array('value' => $language);
     }
     skip\select('stream_language', $select_languages, __('Facebook Language', 'fbfpi'));
     /**
      * Import WP Cron settings
      */
     $schedules = wp_get_schedules();
     // Getting WordPress schedules
     foreach ($schedules as $key => $schedule) {
         $select_schedules[] = array('label' => $schedule['display'], 'value' => $key);
     }
     skip\select('update_interval', $select_schedules, __('Import Interval', 'fbfpi'));
     /**
      * Num of entries to import
      */
     skip\select('update_num', '5,10,25,50,100,200', __('Entries to import', 'fbfpi'));
     /**
      * Select where to import, as posts or as own post type
      */
     $args = array(array('value' => 'posts', 'label' => __('Posts')), array('value' => 'status', 'label' => __('Status message (own post type)', 'fbfpi')));
     skip\select('insert_post_type', $args, __('Insert Messages as', 'fbfpi'));
     /**
      * Select importing User
      */
     $users = get_users(array('fields' => array('ID', 'display_name')));
     $user_list = array();
     foreach ($users as $user) {
         $user_list[] = array('value' => $user->ID, 'label' => $user->display_name);
     }
     skip\select('insert_user_id', $user_list, __('Inserting User', 'fbfpi'));
     /**
      * Post status
      */
     $post_status_values = array(array('value' => 'publish', 'label' => __('Published')), array('value' => 'draft', 'label' => __('Draft')));
     skip\select('insert_post_status', $post_status_values, __('Post status', 'fbfpi'));
     /**
      * Link target for imported links
      */
     $link_select_values = array(array('value' => '_self', 'label' => __('same window', 'fbfpi')), array('value' => '_blank', 'label' => __('new window', 'fbfpi')));
     skip\select('link_target', $link_select_values, __('Open Links in', 'fbfpi'));
     /**
      * Selecting post formats if existing
      */
     if (current_theme_supports('post-formats')) {
         $post_formats = get_theme_support('post-formats');
         if (FALSE != $post_formats) {
             $post_formats = $post_formats[0];
             $post_format_list = array();
             $post_format_list[] = array('value' => 'none', 'label' => __('-- None --', 'fbfpi'));
             foreach ($post_formats as $post_format) {
                 $post_format_list[] = array('value' => $post_format, 'label' => $post_format);
             }
             skip\select('insert_post_format', $post_format_list, __('Post format', 'fbfpi'));
         }
     }
     skip\checkbox('own_css', 'yes', __('Deactivate Plugin CSS', 'fbfpi'));
     do_action('fbfpi_settings_form');
     /**
      * Save Button
      */
     skip\button(__('Save', 'fbfpi'));
     /**
      * Import button
      */
     if ('' != skip\value('fbfpi_settings', 'page_id')) {
         echo ' <input type="submit" name="bfpi-now" value="' . __('Import Now', 'fbfpi') . '" class="button" style="margin-left:10px;" /> ';
     }
     skip\form_end();
     echo '</div>';
 }