/**
  * Update record to database
  * @return bool
  */
 protected function _saveSlides()
 {
     //saving all dates
     //1. set all existing update_status=0
     //2. insert new and update existing (all new and have update_status=1)
     //3. delete all not updated where update_status=0
     $oFlexSliderSlide = new FlexSliderSlide();
     $oFlexSliderSlide->setStatusAsNotUpdated($this->_iId);
     $i = 0;
     $iNextParentId = 0;
     if (is_array($_POST['image'])) {
         foreach ($_POST['image'] as $iKey => $sVal) {
             $bStatus = $oFlexSliderSlide->save($iKey, $this->_iId, $sVal, $i);
             $i++;
         }
     }
     $oFlexSliderSlide->deleteNotUpdated($this->_iId);
     return true;
 }
function ts_flexslider_func($atts, $content = null)
{
    extract(shortcode_atts(array("id" => ""), $atts));
    if (!(int) $id) {
        return '';
    }
    require_once get_template_directory() . '/framework/class/FlexSliderSlider.class.php';
    require_once get_template_directory() . '/framework/class/FlexSliderSlide.class.php';
    $oSlider = new FlexSliderSlider($id);
    $oRecord = $oSlider->get();
    if ($oRecord === false) {
        return '';
    }
    $oSlides = new FlexSliderSlide();
    $aSlides = $oSlides->getSliderSlides($id);
    if (is_array($aSlides) && count($aSlides) > 0) {
        require_once get_template_directory() . '/framework/class/freshizer.php';
        foreach ($aSlides as $oSlide) {
            $image = ts_get_resized_image_by_size($oSlide->image, 'slider');
            $content .= '<li>' . $image . '</li>';
        }
    }
    $rand = $id . '-' . rand(1, 5000);
    $animation = 'slide';
    if (in_array($oRecord->animation, array('slide', 'fade'))) {
        $animation = $oRecord->animation;
    }
    $direction = 'horizontal';
    if (in_array($oRecord->direction, array('horizontal', 'vertical'))) {
        $direction = $oRecord->direction;
    }
    $slideshow_speed = 100;
    if ((int) $oRecord->slideshow_speed > 100) {
        $slideshow_speed = $oRecord->slideshow_speed;
    }
    $animation_speed = 100;
    if ((int) $oRecord->animation_speed > 100) {
        $animation_speed = $oRecord->animation_speed;
    }
    $reverse = false;
    if ((int) $oRecord->reverse == 1) {
        $reverse = true;
    }
    $randomize = false;
    if ((int) $oRecord->randomize == 1) {
        $randomize = true;
    }
    $controlNav = true;
    if ((int) $oRecord->control_nav == 0) {
        $controlNav = false;
    }
    $directionNav = true;
    if ((int) $oRecord->direction_nav == 0) {
        $directionNav = false;
    }
    $before = "";
    $after = "";
    if (!empty($oRecord->background)) {
        $before = "<div class='slider-background' style='background: url(" . $oRecord->background . ");'>";
        $after = "</div>";
    }
    $content = $before . "\n\t\t<div class='flexslider images-slider' id='flexslider-" . $rand . "'>\n\t\t\t<ul class='slides'>" . do_shortcode(shortcode_unautop($content)) . "</ul>\n\t\t</div>" . $after;
    $content .= "\n\t\t<script type='text/javascript'>\n\t\t\tjQuery(document).ready(function() {\n\t\t\t  jQuery('#flexslider-" . $rand . "').flexslider({\n\t\t\t\tanimation: '" . $animation . "',\n\t\t\t\tdirection: '" . $direction . "',\n\t\t\t\tslideshowSpeed: " . $slideshow_speed . ",\n\t\t\t\tanimationSpeed: " . $animation_speed . ",\n\t\t\t\tcontrolNav: " . (int) $controlNav . ",\n\t\t\t\tdirectionNav: " . (int) $directionNav . ",\n\t\t\t\treverse: " . (int) $reverse . ",\n\t\t\t\trandomize: " . (int) $randomize . ",\n\t\t\t\tprevText: \"" . ts_get_prev_slider_text() . "\",\n\t\t\t\tnextText: \"" . ts_get_next_slider_text() . "\"\n\t\t\t  });\n\t\t\t});\n\t\t</script>";
    // Restor original Query & Post Data
    wp_reset_query();
    wp_reset_postdata();
    return $content;
}