function list_all_categories()
 {
     if (is_main_query() and get_query_var("chronosly_category") != "") {
         wp_register_style('chronosly-front-css' . CHRONOSLY_VERSION, CHRONOSLY_URL . '/css/front_template.css');
         wp_enqueue_style('chronosly-front-css' . CHRONOSLY_VERSION);
         if (file_exists(CHRONOSLY_PATH . DIRECTORY_SEPARATOR . "css" . DIRECTORY_SEPARATOR . "custom.css")) {
             wp_register_style('chronosly-custom-css', CHRONOSLY_URL . '/css/custom.css');
             wp_enqueue_style('chronosly-custom-css');
         }
         if (!$settings["chronosly-disable-gmap-js"]) {
             wp_register_script('chronosly-gmap', 'http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array('jquery'));
             wp_enqueue_script('chronosly-gmap');
         }
         wp_enqueue_script('jquery-ui-core');
         wp_enqueue_script('jquery-ui-datepicker');
         wp_enqueue_script('jquery-ui-tabs');
         wp_enqueue_script('jquery-ui-tooltip');
         wp_enqueue_script('jquery-ui-resizable');
         wp_enqueue_script('jquery-ui-draggable');
         wp_register_style('chronosly-icons', CHRONOSLY_URL . '/css/icons/styles.css');
         wp_enqueue_style('chronosly-icons');
         wp_register_style('chronosly-fa-icons', "http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css");
         wp_enqueue_style('chronosly-fa-icons');
         if (!is_admin() or stripos($_SERVER["REQUEST_URI"], "wp-admin") === FALSE) {
             wp_register_script('chronosly-front-js', CHRONOSLY_URL . '/js/front.js', array('jquery'));
             $translation_array = array("weburl" => get_site_url(), "calendarurl" => Post_Type_Chronosly_Calendar::get_permalink(), 'ajaxurl' => admin_url('admin-ajax.php'));
             wp_localize_script('chronosly-front-js', 'translated1', $translation_array);
             wp_enqueue_script('chronosly-front-js');
         }
         wp_register_style('chronosly-templates-base', CHRONOSLY_URL . '/css/templates_base.css');
         wp_enqueue_style('chronosly-templates-base');
         //templates and addons css
         do_action("chronosly_custom_frontend_css");
         $sets = unserialize(get_option("chronosly-settings"));
         if (isset($sets["chronosly-base-templates-id"]) and $sets["chronosly-base-templates-id"] != 0 and !$_REQUEST["js_render"]) {
             if (get_query_var("chronosly_category") == "list_all_cats") {
                 $_REQUEST["shortcode_categories"] = 1;
             } else {
                 $_REQUEST["shortcode_category"] = 1;
             }
             Post_Type_Chronosly::base_template_code("ch-category");
             //exit;
         } else {
             if (get_query_var("chronosly_category") == "list_all_cats") {
                 include CHRONOSLY_PATH . DIRECTORY_SEPARATOR . "templates" . DIRECTORY_SEPARATOR . 'archive-category-chronosly.php';
             } else {
                 add_action('pre_get_posts', array("Post_Type_Chronosly", 'add_custom_post_vars'));
                 include CHRONOSLY_PATH . DIRECTORY_SEPARATOR . "templates" . DIRECTORY_SEPARATOR . 'single-category-chronosly.php';
             }
             exit;
         }
     }
 }
 public function inicia_scripts()
 {
     wp_enqueue_media();
     wp_register_style('chronosly-custom_wp_admin_css', CHRONOSLY_URL . '/css/admin_template1.css', false, '1.0.0');
     wp_enqueue_style('chronosly-custom_wp_admin_css');
     $wpScripts = new WP_Scripts();
     // if(!$wpScripts->query('jquery','enqueued')){
     //     wp_register_script( 'chronosly-jquery', CHRONOSLY_URL.'/js/jquery.js');
     // }
     wp_register_script('chronosly-admin', CHRONOSLY_URL . '/js/admin.js', array('jquery'));
     wp_register_script('chronosly-front', CHRONOSLY_URL . '/js/front.js', array('jquery'));
     $translation_array = array("scrollOnOpen" => !$this->settings["disable_slide_on_show"], "weburl" => get_site_url(), "calendarurl" => Post_Type_Chronosly_Calendar::get_permalink(), 'ajaxurl' => admin_url('admin-ajax.php'));
     wp_localize_script('chronosly-front-js', 'translated1', $translation_array);
     if (!$this->settings["chronosly-disable-gmap-js"]) {
         wp_register_script('chronosly-gmap', 'http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array('jquery'));
         wp_enqueue_script('chronosly-gmap');
     }
     $translation_array = array("days" => __("days", "chronosly"), "weeks" => __("weeks", "chronosly"), "months" => __("months", "chronosly"), "year" => __("year", "chronosly"), "color_cancel" => __("Cancel", "chronosly"), "color_choose" => __("Choose", "chronosly"), "stop_prev" => __("Slower preview", "chronosly"), "start_prev" => __("Faster preview", "chronosly"), "overwritted" => __("overwritted", "chronosly"), "specify_name" => __("You have to specify a name or select a template to update", "chronosly"), "wrong_name" => __("The name have incorrect characters, only are alowed chars between a-z,A-Z,0-9 and - or _", "chronosly"), "succes" => __("Saved successfully", "chronosly"), "duplicate_succes" => __("Cloned successfully", "chronosly"), "save_url" => CHRONOSLY_URL . "ev-functions/save_template.php", "guardamos" => $this->settings["chronosly_template_default"], 'ajaxurl' => admin_url('admin-ajax.php'));
     wp_localize_script('chronosly-admin', 'translated1', $translation_array);
     // if(!$this->settings["jquery-admin-disable"]) wp_enqueue_script('chronosly-jquery');
     //load progress
     wp_register_script('chronosly-dateformat', CHRONOSLY_URL . '/js/dateFormat.js', array('jquery'));
     wp_enqueue_script('chronosly-dateformat');
     wp_register_script('chronosly-colorbox', CHRONOSLY_URL . '/js/colorbox/jquery.colorbox.js', array('jquery'));
     wp_enqueue_script('chronosly-colorbox');
     wp_register_style('chronosly-colorbox-css', CHRONOSLY_URL . '/js/colorbox/css/colorbox.css');
     wp_enqueue_style('chronosly-colorbox-css');
     wp_enqueue_script('chronosly-admin');
     if (!is_admin() or stripos($_SERVER["REQUEST_URI"], "wp-admin") === FALSE) {
         wp_enqueue_script('chronosly-front');
     }
     wp_enqueue_script('jquery-ui-core');
     wp_enqueue_script('jquery-ui-datepicker');
     wp_enqueue_script('jquery-ui-tabs');
     wp_enqueue_script('jquery-ui-tooltip');
     wp_enqueue_script('jquery-ui-resizable');
     wp_enqueue_script('jquery-ui-draggable');
     wp_register_style('chronosly-admin-jquery-ui-css', CHRONOSLY_URL . '/css/smoothness/jquery-ui-1.10.4.custom.css');
     wp_enqueue_style('chronosly-admin-jquery-ui-css');
     //colorpicker
     wp_register_script('chronosly-spectrum', CHRONOSLY_URL . '/js/spectrum/spectrum.js', array('jquery'));
     wp_enqueue_script('chronosly-spectrum');
     wp_register_style('chronosly-spectrum-css', CHRONOSLY_URL . '/js/spectrum/spectrum.css');
     wp_enqueue_style('chronosly-spectrum-css');
     wp_register_style('chronosly-templates-base', CHRONOSLY_URL . '/css/templates_base.css');
     wp_enqueue_style('chronosly-templates-base');
     wp_register_style('chronosly-icons', CHRONOSLY_URL . '/css/icons/styles.css');
     wp_enqueue_style('chronosly-icons');
     wp_register_style('chronosly-fa-icons', "http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css");
     wp_enqueue_style('chronosly-fa-icons');
     do_action("chronosly_custom_backend_css");
     //select efects
     /*wp_register_script( 'chronosly-selectizer', CHRONOSLY_URL.'/js/selectize/dist/js/standalone/selectize.js');
       wp_enqueue_script('chronosly-selectizer');
       wp_register_style( 'chronosly-selectizer-css', CHRONOSLY_URL.'/js/selectize/dist/css/selectize.bootstrap3.css');
       wp_enqueue_style('chronosly-selectizer-css');*/
     /*   wp_register_script( 'chronosly-select2', CHRONOSLY_URL.'/js/select2/select2.js');
                    wp_enqueue_script('chronosly-select2');
                    wp_register_style( 'chronosly-select2-css', CHRONOSLY_URL.'/js/select2/select2.css');
                    wp_enqueue_style('chronosly-select2-css');
        */
 }
    }
    echo "<div class='chronosly-content-block' style='" . $stilo . ";clear:both;'>";
    if ($_REQUEST["from"]) {
        echo "<div style='display:none'>\r\n            <div class='ch_from'>" . $_REQUEST["from"] . "</div>\r\n            <div class='ch_to'>" . $_REQUEST["to"] . "</div>\r\n            <input type='hidden' name='y' value='{$year}'/>\r\n            <input type='hidden' name='mo' value='{$month}'/>\r\n            <input type='hidden' name='w' value='{$week}'/>\r\n        </div>";
    }
    if (isset($Post_Type_Chronosly->template)) {
        $template = $Post_Type_Chronosly->template;
    } else {
        $template = new Chronosly_Templates();
    }
    $template->templates_tabs("dad1", 1);
    ?>


            <?php 
    $days = Post_Type_Chronosly_Calendar::get_days_by_date($year, $month, $week, $query, $repeated);
    $events = $repeats = array();
    $type = "year";
    $week_in_sunday = 0;
    if ($Post_Type_Chronosly->settings["chronosly_week_start"] == 1) {
        $week_in_sunday = 1;
    }
    if ($month) {
        $type = "month";
    } else {
        if ($week) {
            $type = "week";
        }
    }
    $i = $mi = 0;
    $m = array(__("January"), __("February"), __("March"), __("April"), __("May"), __("June"), __("July"), __("August"), __("September"), __("October"), __("November"), __("December"));
 public static function repeats($meta, $year, $month, $week, $start, $end, $id, $elements, $repeated = 0)
 {
     $settings = unserialize(get_option("chronosly-settings"));
     $pos = Post_Type_Chronosly_Calendar::get_event_position_by_hour($meta, $id);
     if (isset($meta["ev-repeat"][0]) and $meta["ev-repeat"][0] != "" and isset($meta["ev-repeat-every"][0]) and $meta["ev-repeat-every"][0] > 0) {
         if (!$month and !$week) {
             if ($repeated) {
                 $start_min = strtotime("01-01-" . $year);
             }
             //start building array
             $end_top = strtotime("31-12-" . $year);
             //limit of repeats per year
             if (isset($meta["ev-repeat-option"][0]) and $meta["ev-repeat-option"][0] == "until" and isset($meta["ev-until"][0]) and strtotime($meta["ev-until"][0]) < $end_top) {
                 $end_top = strtotime($meta["ev-until"][0]);
             }
         } else {
             if ($week) {
                 if ($repeated) {
                     $start_min = strtotime($year . "W" . str_pad($week, 2, '0', STR_PAD_LEFT));
                 }
                 //start building array
                 $end_top = strtotime($year . "W" . str_pad($week + 1, 2, '0', STR_PAD_LEFT) . " -1 day");
                 //limit of repeats per week
                 if (isset($meta["ev-repeat-option"][0]) and $meta["ev-repeat-option"][0] == "until" and isset($meta["ev-until"][0]) and strtotime($meta["ev-until"][0]) < $end_top) {
                     $end_top = strtotime($meta["ev-until"][0]);
                 }
                 // if($settings["chronosly_week_start"] == 1) {
                 //     // $start_min -= (60*60*24);
                 //     // $end_top -= (60*60*24);
                 // }
             } else {
                 if ($month) {
                     if ($repeated) {
                         $start_min = strtotime("01-{$month}-{$year}");
                     }
                     //start building array
                     $end_top = strtotime(date("Y-m-t", strtotime($year . "-" . $month)));
                     //limit of repeats per month
                     if (isset($meta["ev-repeat-option"][0]) and $meta["ev-repeat-option"][0] == "until" and isset($meta["ev-until"][0]) and strtotime($meta["ev-until"][0]) < $end_top) {
                         $end_top = strtotime($meta["ev-until"][0]);
                     }
                 }
             }
         }
         if ($repeated and $start_min > $end_top) {
             return $elements;
         } else {
             if (!$repeated and $start > $end_top) {
                 return $elements;
             }
         }
         $count = -1;
         //for count repetitions
         if (isset($meta["ev-repeat-option"][0]) and $meta["ev-repeat-option"][0] == "count" and isset($meta["ev-end_count"][0]) and $meta["ev-end_count"][0] > 0) {
             $count = $meta["ev-end_count"][0];
         }
         $distance = $meta["ev-repeat-every"][0];
         //distance between repeats
         $event_days = $end - $start;
         // event days duration
         switch ($meta["ev-repeat"][0]) {
             case "day":
                 $start = $end;
                 while ($start < $end_top and $count) {
                     //mientras no estemos en el tope superior
                     $start += $distance * 60 * 60 * 24;
                     //añadimos la distancia de dias
                     $start1 = $start;
                     $end = $start + $event_days;
                     //recalculamos el final
                     --$count;
                     while ($start <= $end and $start <= $end_top) {
                         //rellenamos los dias de este tramo
                         if ($start >= $start_min and ($settings["hide_past_on_calendar"] != 1 or $start >= strtotime(date("Y-m-d")))) {
                             $elements["days"][date('Y-m-d', $start)][$pos] = array("id" => $id, "start" => $start1, "end" => $end);
                         }
                         $start = strtotime("+ 1 day", $start);
                         //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>";
                     }
                     $start = strtotime("- 1 day", $start);
                     //restamos un dia porque si no el ultimo dia no se cuenta al salir del bucle
                 }
                 break;
             case "week":
                 $start = $end;
                 while ($start < $end_top and $count) {
                     //mientras no estemos en el tope superior
                     $start += $distance * 7 * 60 * 60 * 24 - $event_days;
                     //añadimos la distancia de semanas, restando los dias que dura el evento...si el evento dura mas de una semana es un total absurdo usarlo
                     $start1 = $start;
                     $end = $start + $event_days;
                     //recalculamos el final
                     --$count;
                     //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>";
                     while ($start <= $end and $start <= $end_top) {
                         //rellenamos los dias de este tramo
                         if ((!$repeated or $start >= $start_min) and ($settings["hide_past_on_calendar"] != 1 or $start >= strtotime(date("Y-m-d")))) {
                             $elements["days"][date('Y-m-d', $start)][$pos] = array("id" => $id, "start" => $start1, "end" => $end);
                         }
                         $start = strtotime("+ 1 day", $start);
                         //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>";
                     }
                     $start = strtotime("- 1 day", $start);
                     //restamos un dia porque si no el ultimo dia no se cuenta al salir del bucle
                 }
                 break;
             case "month":
                 $start = $end;
                 while ($start < $end_top and $count) {
                     //mientras no estemos en el tope superior
                     $start = strtotime("+{$distance} month", $start) - $event_days;
                     //añadimos la distancia de semanas, restando los dias que dura el evento...si el evento dura mas de una semana es un total absurdo usarlo
                     $start1 = $start;
                     $end = $start + $event_days;
                     //recalculamos el final
                     --$count;
                     //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>";
                     while ($start <= $end and $start <= $end_top) {
                         //rellenamos los dias de este tramo
                         if ((!$repeated or $start >= $start_min) and ($settings["hide_past_on_calendar"] != 1 or $start >= strtotime(date("Y-m-d")))) {
                             $elements["days"][date('Y-m-d', $start)][$pos] = array("id" => $id, "start" => $start1, "end" => $end);
                         }
                         $start = strtotime("+ 1 day", $start);
                         //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>";
                     }
                     $start = strtotime("- 1 day", $start);
                     //restamos un dia porque si no el ultimo dia no se cuenta al salir del bucle
                 }
                 break;
             case "year":
                 $start = $end;
                 while ($start < $end_top and $count) {
                     //mientras no estemos en el tope superior
                     $start = strtotime("+{$distance} year", $start) - $event_days;
                     //añadimos la distancia de semanas, restando los dias que dura el evento...si el evento dura mas de una semana es un total absurdo usarlo
                     $start1 = $start;
                     $end = $start + $event_days;
                     //recalculamos el final
                     --$count;
                     //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>";
                     while ($start <= $end and $start <= $end_top) {
                         //rellenamos los dias de este tramo
                         if ((!$repeated or $start >= $start_min) and ($settings["hide_past_on_calendar"] != 1 or $start >= strtotime(date("Y-m-d")))) {
                             $elements["days"][date('Y-m-d', $start)][$pos] = array("id" => $id, "start" => $start1, "end" => $end);
                         }
                         $start = strtotime("+ 1 day", $start);
                         //echo date('Y-m-d',$start)." ".date('Y-m-d',$end)."<br/>";
                     }
                     $start = strtotime("- 1 day", $start);
                     //restamos un dia porque si no el ultimo dia no se cuenta al salir del bucle
                 }
                 break;
         }
     }
     return $elements;
 }