コード例 #1
0
    die('<h1>Forbidden</h1>');
}
// determine if there are any slides not attached properly to slide groups, and re-attach by inferring
// ownership from the legacy data
$ts_ug_201_wpdb =& $GLOBALS['wpdb'];
$orphaned_slides_query = "SELECT ID, post_title, post_name, post_content, post_status FROM {$ts_ug_201_wpdb->prefix}posts\n\tLEFT JOIN {$ts_ug_201_wpdb->prefix}term_relationships\n\t\tON {$ts_ug_201_wpdb->prefix}posts.ID = {$ts_ug_201_wpdb->prefix}term_relationships.object_id\n\tWHERE post_type = 'total_slider_slide'\n\tAND term_taxonomy_id IS NULL\n";
$orphaned_slides = $ts_ug_201_wpdb->get_results($orphaned_slides_query, OBJECT);
if (is_array($orphaned_slides) && count($orphaned_slides) > 0) {
    // pull in legacy slides, so we can title + description match slides to determine their correct slide group ownership
    // for the new data format
    $legacy_slide_groups = get_option('total_slider_slide_groups');
    $legacy_slides = array();
    if (is_array($legacy_slide_groups) && count($legacy_slide_groups) > 0) {
        foreach ($legacy_slide_groups as $lsg) {
            if (is_a($lsg, 'Total_Slide_Group')) {
                $lsg->slug = Total_Slider::sanitize_slide_group_slug($lsg->slug);
                $legacy_slides[$lsg->slug] = get_option('total_slider_slides_' . $lsg->slug);
            }
        }
        // now that we have pulled legacy slide groups and their slides, we can match orphaned slides to these
        foreach ($orphaned_slides as $orphan) {
            $found_parent = false;
            // loop through all legacy slide groups
            foreach ($legacy_slides as $slug => $lsg) {
                // this still gives us groups -- slides are one level down
                if ($found_parent) {
                    break;
                }
                if (is_array($lsg) && count($lsg) > 0) {
                    foreach ($lsg as $ls) {
                        if ($found_parent) {
コード例 #2
0
 /**
  * Update the Widget settings with the new selected Slide Group.
  *
  * @param array $new_instance
  * @param array $old_instance
  */
 public function update($new_instance, $old_instance)
 {
     if ('**INVALID**' != $new_instance['groupSlug']) {
         return array('groupSlug' => Total_Slider::sanitize_slide_group_slug($new_instance['groupSlug']));
     } else {
         return $old_instance;
     }
 }
コード例 #3
0
 /**
  * Fetch this Slide Group's properties, including slug, name, templateLocation, template, from the database.
  *
  * This uses the slug provided in the constructor to load in this Slide Group's other properties.
  *
  * @return boolean
  *
  */
 public function load()
 {
     $term = get_term_by('slug', $this->originalSlug, 'total_slider_slide_group');
     if (!$term) {
         return false;
     }
     $this->name = $term->name;
     $this->slug = Total_Slider::sanitize_slide_group_slug($term->slug);
     $this->term_id = intval($term->term_id);
     // get template from wp_option
     /*
     	The slide group template and template location are stored in a wp_option
     	similarly named to that which was formerly (1.x) used for the actual slide data.
     
     	This is a string, delimited by a pipe (|) character, with the templateLocation
     	('builtin','theme','downloaded','legacy') before the pipe, and the template
     	slug after the pipe.
     */
     $group_options = get_option('total_slider_grptpl_' . $this->slug);
     if (false === $group_options) {
         // set default template information if none found
         $this->set_default_template();
     } else {
         $group_options_expl = explode('|', $group_options);
         if (!is_array($group_options_expl) || count($group_options_expl) < 1) {
             $this->set_default_template();
         } else {
             foreach ($group_options_expl as $key => $opt) {
                 if ($key == 0) {
                     // templateLocation
                     if (!in_array($opt, Total_Slider::$allowed_template_locations)) {
                         $this->set_default_template();
                         break;
                     }
                     $this->templateLocation = $opt;
                 }
                 if ($key == 1) {
                     // template slug
                     $this->template = Total_Slider_Template::sanitize_slug($opt);
                 }
             }
         }
     }
     return true;
 }
コード例 #4
0
if (is_array($legacy_slide_groups) && count($legacy_slide_groups) > 0) {
    $legacy_slide_group_names = array();
    // to detect and handle Slide Group name clashes, which are now a problem with the 2.0 data format
    foreach ($legacy_slide_groups as $key => $legacy_group) {
        if (is_a($legacy_group, 'Total_Slide_Group')) {
            // convert this group to the new format
            $new_slug = Total_Slider::sanitize_slide_group_slug($legacy_group->slug);
            $legacy_slides = get_option('total_slider_slides_' . $new_slug);
            $new_group = new Total_Slide_Group($new_slug, $legacy_group->name);
            $new_group->template = $legacy_group->template;
            $new_group->templateLocation = $legacy_group->templateLocation;
            // if this legacy group name collides with an existing legacy group name, we must rename and re-slug it
            // or WP will combine posts attached to the two terms, merging the Slide Groups!
            if (in_array($legacy_group->name, $legacy_slide_group_names)) {
                $new_group->name = $legacy_group->name . ' (duplicate name)';
                $new_group->slug = Total_Slider::sanitize_slide_group_slug(substr($legacy_group->slug, 0, 12) . sanitize_title_with_dashes(uniqid('', true)));
            }
            $new_group->save();
            $new_slide_ids = array();
            if (is_array($legacy_slides) && count($legacy_slides) > 0) {
                foreach ($legacy_slides as $legacy_slide) {
                    $title = $legacy_slide['title'];
                    $description = $legacy_slide['description'];
                    $background = $legacy_slide['background'];
                    $link = $legacy_slide['link'];
                    $title_pos_x = $legacy_slide['title_pos_x'];
                    $title_pos_y = $legacy_slide['title_pos_y'];
                    $new_slide_ids[] = $new_group->new_slide($title, $description, $background, $link, $title_pos_x, $title_pos_y, 'publish');
                }
            }
            // make sure we don't use this name again
コード例 #5
0
 /**
  * Create a Total Slider WP_Widget from a [totalslider] shortcode in the post body and return its contents.
  *
  * @param array $atts An array containing the shortcode attributes. See WordPress Codex documentation. We desire a string, 'group', containing the slide group slug.
  * @param string $content Not used by our shortcode handler. 
  * @param string $tag Not used by our shortcode handler.
  * @return string
  */
 public function shortcode_handler($atts, $content, $tag)
 {
     extract(shortcode_atts(array('group' => NULL), $atts));
     // require a slide group
     if (empty($group)) {
         return __('<strong>Total Slider:</strong> No slide group selected to show.', 'total-slider');
     }
     // require a valid slide group
     $group_obj = new Total_Slide_Group(Total_Slider::sanitize_slide_group_slug($group));
     if (!$group_obj->load()) {
         return __('<strong>Total Slider:</strong> Could not find the selected slide group to show. Does it still exist?', 'total-slider');
     }
     ob_start();
     the_widget('Total_Slider_Widget', array('groupSlug' => Total_Slider::sanitize_slide_group_slug($group)));
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }