/**
  * Search for publications.
  *
  * @param array $args
  * @return array
  */
 private function publication_query($args = array())
 {
     $query = array('post_type' => 'seoslides-slideset', 'suppress_filters' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'post_status' => 'publish', 'order' => 'DESC', 'orderby' => 'post_date', 'posts_per_page' => 20);
     $args['pagenum'] = isset($args['pagenum']) ? absint($args['pagenum']) : 1;
     if (isset($args['s'])) {
         $query['s'] = $args['s'];
     }
     $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ($args['pagenum'] - 1) : 0;
     // Run the query
     $get_posts = new WP_Query();
     $posts = $get_posts->query($query);
     $results = array();
     if (0 === $get_posts->post_count) {
         return $results;
     }
     // Populate results
     foreach ($posts as $post) {
         // Get the embed ID for the first slide in the presentation
         $slideset = new SEOSlides_Slideset($post->ID);
         /** @var SEOSlides_Embed $embed */
         $embed = SEOSlides_Module_Provider::get('SEOSlides Embed');
         $embed_id = $embed->get_embed_unique_id($post->ID, $slideset->first_slide()->slug);
         $embed_url = $embed->get_embed_url($post->ID, $slideset->first_slide()->slug);
         $shortcode = '[seoslides embed_id="' . $embed_id . '"';
         $shortcode .= ' script_src="' . preg_replace('/\\/(slides|embeds)\\//', '/embed-script/', $embed_url) . '"';
         $shortcode .= ' overview_src="' . get_permalink($post) . '"';
         $shortcode .= ' title="' . get_the_title($post) . '"';
         $shortcode .= ' site_src="' . get_home_url() . '"';
         $shortcode .= ' site_title="' . get_bloginfo('name') . '"';
         $shortcode .= ' /]';
         $results[] = array('ID' => $post->ID, 'title' => trim(esc_html(strip_tags(get_the_title($post)))), 'shortcode' => esc_attr($shortcode), 'info' => mysql2date(__('Y/m/d'), $post->post_date));
     }
     return $results;
 }
Exemple #2
0
 public function create_from_media()
 {
     $response = array();
     $response['success'] = false;
     $response['data'] = array();
     if (!wp_verify_nonce($_POST['_nonce'], 'seoslides-media')) {
         wp_send_json($response);
     }
     // First, get our slideset
     $slideset_id = (int) $_POST['slideset'];
     $slideset = new SEOSlides_Slideset($slideset_id);
     $defaults = $slideset->default_slide();
     // Now get our attachments
     $attachment_ids = $_POST['slides'];
     $attachment_ids = array_map('intval', $attachment_ids);
     // Initial position of new slide
     $position = count($slideset->slides);
     // Iteratively insert new slides
     foreach ($attachment_ids as $attachment_id) {
         $image = wp_get_attachment_image_src($attachment_id, 'full');
         // Create our slide content
         $content = array('title' => $slideset->title . ' - ' . ($position + 1), 'content' => '', 'image' => '', 'bg-image' => $image[0]);
         // Create the slide
         $slide = wp_insert_post(array('post_parent' => $slideset_id, 'post_type' => 'seoslides-slide', 'menu_order' => $position, 'post_status' => 'publish', 'post_content' => serialize($content)));
         if (0 !== $slide && !is_wp_error($slide)) {
             update_post_meta($slide, 'seoslides_fillcolor', '');
             update_post_meta($slide, 'seoslides_oembed', $defaults->oembed);
             // Update SEO
             $seo = array('title' => $defaults->title, 'description' => $defaults->seo_description, 'keywords' => $defaults->seo_keywords);
             update_post_meta($slide, 'seoslides_seo_settings', $seo);
             /** @var SEOSlides_CanvasObject $object */
             foreach ($defaults->objects as $object) {
                 add_post_meta($slide, 'seoslides_canvas_object', $object);
             }
             // Add our slide to the response array
             $response['data'][] = array('id' => $slide);
             // Increment the position for next time
             $position += 1;
         }
     }
     $response['success'] = true;
     wp_send_json($response);
 }
Exemple #3
0
 /**
  * Filter the display of the custom Presentation columns.
  *
  * @param string $column
  * @param int    $slideset_id
  *
  * @return void
  */
 public function filter_custom_columns($column, $slideset_id)
 {
     switch ($column) {
         case 'thumbnail':
             $slideset = new SEOSlides_Slideset($slideset_id);
             $title = $slideset->title;
             $slides = array_filter($slideset->slides, array('SEOSlides_Slide', 'slide_is_published'));
             if (count($slides) > 0) {
                 $cover = $slideset->first_slide();
                 if (current_user_can('edit_post', $slideset_id)) {
                     echo '<a href="' . get_edit_post_link($slideset_id) . '">';
                 }
                 echo '<div class="list thumbnail">';
                 if (false === $cover->preview || 'false' === $cover->preview) {
                     // There is no preview thumbnail for this image, so we'll try to create one instead
                     // First, build out the inline style, using auto-generated thumbnail images
                     // Build out inline style
                     $style = ' style="';
                     if ('' !== $cover->bg_image) {
                         $image = $cover->bg_image;
                         $image_id = SEOSlides_Util::get_attachment_id_from_url($cover->bg_image);
                         if (false === $image_id) {
                             if (function_exists('jetpack_photon_url')) {
                                 $image = jetpack_photon_url($cover->bg_image, array(), '//');
                             }
                         } else {
                             $image_arr = wp_get_attachment_image_src($image_id, 'seoslides-thumb');
                             $image = $image_arr[0];
                         }
                         $style .= 'background-image:url(' . $image . ');';
                     }
                     $style .= 'background-color:' . $cover->fill_color . ';"';
                     echo "<section class='slide'><div class='slide-body' {$style}>";
                     if (!empty($cover->oembed)) {
                         $embed_url = SEOSlides_Slide::get_embed_url($cover->oembed);
                         $thumb_url = SEOSlides_Slide::get_embed_thumbnail($cover->oembed);
                         if (!is_wp_error($embed_url) && !is_wp_error($thumb_url)) {
                             echo '<img class="seoslides_iframe_thumb" src="' . $thumb_url . '" />';
                             echo '<iframe class="seoslides_iframe" src="' . $embed_url . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
                         }
                     }
                     foreach ($cover->objects as $object) {
                         echo '<div ';
                         echo "data-element='{$object->element_id}' ";
                         echo "data-plugin='{$object->plugin_id}' ";
                         echo "data-width='{$object->settings->size->w}' ";
                         echo "data-height='{$object->settings->size->h}' ";
                         echo "data-top='{$object->settings->position->top}' ";
                         echo "data-left='{$object->settings->position->left}' ";
                         $style = 'position:absolute; ';
                         $style .= 'top:' . $object->settings->position->top . 'px; ';
                         $style .= 'left:' . $object->settings->position->left . 'px; ';
                         $style .= 'width:' . $object->settings->size->w . 'px; ';
                         $style .= 'height:' . $object->settings->size->h . 'px;';
                         echo "style='{$style}'";
                         echo '>';
                         if (isset($object->settings->content)) {
                             echo $object->settings->content;
                         }
                         echo '</div>';
                     }
                     echo '</div></section>';
                 } else {
                     echo "<img src=\"{$cover->preview}\" title=\"{$cover->title}\" />";
                 }
                 echo '</div>';
                 if (current_user_can('edit_post', $slideset_id)) {
                     echo '</a>';
                 }
             }
             break;
         case 'description':
             $slideset = $this->get_slideset($slideset_id);
             echo $slideset->excerpt;
             break;
         case 'slide_count':
             echo self::get_slide_count($slideset_id);
             break;
         case 'updated':
             $slideset = $this->get_slideset($slideset_id);
             $updated = mysql2date('G', $slideset->last_updated_gmt, false);
             $diff = time() - $updated;
             if ($diff > 0 && $diff < DAY_IN_SECONDS) {
                 $time = sprintf(__('%s ago'), human_time_diff($updated));
             } else {
                 $time = mysql2date(__('Y/m/d'), $slideset->last_updated);
             }
             echo $time;
             break;
     }
 }