public function load_mk_templates()
 {
     $ex = new Chronosly_Extend();
     $cont = $ex->get_templates_feed();
     echo json_encode($cont);
     die;
 }
 public static function set_new_bubble_tags($type, $fields_array, $style)
 {
     $args = array("box_name" => __("Tags", "chronosly"), "name" => "tags", "type" => "hidden", "php_function" => array("Chronosly_Dad_Elements", "chronosly_create_tags"), "js_function" => array("Chronosly_Dad_Elements", "chronosly_create_tags_js"), "fields_associated" => array(array("name" => "custom_text_before"), array("name" => "custom_text_after")));
     $return = Chronosly_Extend::create_dad_buble($args, $type, $fields_array, $style);
     return $return;
 }
 public static function custom_css_field($cont, $style)
 {
     $value = "";
     $name = "css";
     if (isset($style[$name])) {
         $value = $style[$name];
     }
     $args = array("label" => __("Custom css", "chronosly"), "name" => $name, "type" => "textarea", "value" => $value, "el_type" => "style", "style_fields" => array("css"), "js_style_values" => array("value"), "php_style_values" => array("'value'"));
     return $cont . Chronosly_Extend::create_dad_field($args);
 }
 public static function create_dad_buble($data, $inside_template = 0, $fields_array = array(), $style = array())
 {
     global $ch_bubble_create_js_code, $ch_bubble_modify_js_code;
     if (!count($data)) {
         return;
     }
     //el data tiene que ser un array valido
     if ($data['name'] != "box" and (!$data["name"] or !$data["box_name"] or !$data["type"])) {
         return;
     }
     //aseguramos que tenemos los minimos
     $return = "";
     if (!$inside_template and isset($data["box_info"])) {
         $return .= "<li class='draggable info' title='" . $data["box_info"] . "'> <span class='title'>" . __($data["box_name"], "chronosly") . "</span>";
     } else {
         if (!$inside_template) {
             $return .= "<li class='draggable'> <span class='title'>" . $data["box_name"] . "</span>";
         }
     }
     //añadimos el d&d si es una box
     if ($data['name'] != "box") {
         $return .= "<div class='ev-hidden'>\n                            <div class='vars'>";
         if (isset($fields_array["bubble_value"])) {
             $data["value"] = $fields_array["bubble_value"];
         }
         $return .= Chronosly_Extend::create_field($data, 1);
         //creamos el campo
         if ($data['js_function']) {
             //si no la hemos añadido ya antes
             if (stripos($ch_bubble_create_js_code, $data["name"] . "chseparator1") === FALSE) {
                 //si existe la funcion llamamos para generar el array de funciones que imprimiremos en el js al crear el elemento o eliminarlo
                 if (!is_array($data['js_function'])) {
                     if (function_exists($data['js_function'])) {
                         $ch_bubble_create_js_code .= $data["name"] . "chseparator1" . call_user_func($data['js_function'], "create") . "chseparator2";
                         $ch_bubble_modify_js_code .= $data["name"] . "chseparator1" . call_user_func($data['js_function'], "modify") . "chseparator2";
                     }
                 } else {
                     if (class_exists($data['js_function'][0]) and method_exists($data['js_function'][0], $data['js_function'][1])) {
                         $ch_bubble_create_js_code .= $data["name"] . "chseparator1" . call_user_func($data['js_function'], "create") . "chseparator2";
                         $ch_bubble_modify_js_code .= $data["name"] . "chseparator1" . call_user_func($data['js_function'], "modify") . "chseparator2";
                     }
                 }
             }
         }
         //llamamos a los fields associados a este value
         if (isset($data['fields_associated'])) {
             foreach ($data['fields_associated'] as $field) {
                 if (has_filter("chronosly_field_" . $field["name"])) {
                     $default = $field;
                     if (count($fields_array) and isset($fields_array[$field["name"]])) {
                         $default = array_merge($default, $fields_array[$field["name"]]);
                     }
                     //setting values to fields
                     $return .= apply_filters("chronosly_field_" . $field["name"], $default);
                 }
             }
         }
         $return .= "</div>";
     }
     /* STYLE BOXES */
     $styleboxes = Chronosly_Paint::default_style_boxes();
     foreach ($styleboxes as $id => $box) {
         $return .= "<div class='{$id}'>";
         $cont = "";
         $cont .= apply_filters("chronosly_style_box_" . $id . "_fields", $cont, $style);
         //genramos los inputs de los stylers
         $return .= $cont;
         $return .= "</div>";
     }
     if ($data['name'] != "box") {
         $return .= "</div>";
         if (!$inside_template) {
             $return .= "</li>";
         }
         //creamos el filter para hacer render en el frontend
         if ($data['php_function']) {
             if (!has_filter("chronosly_bubble_render_" . $data['name'])) {
                 add_filter("chronosly_bubble_render_" . $data["name"], $data['php_function'], 10, 3);
             }
         }
     }
     return $return;
 }
 /**
  * Activate the plugin
  */
 public static function activate()
 {
     global $Chronosly_Extend;
     //TODO MIRAR LA FUNCION add_role PARA AÑADIR ROLES DE USUARIOS NUEVOS
     // Capabilities for the chronosly custom post type
     $WP_Roles = new WP_Roles();
     foreach (array('chronosly_author', 'edit_' . CHRONOSLY_CAPABILITY_TYPE, 'read_' . CHRONOSLY_CAPABILITY_TYPE, 'delete_' . CHRONOSLY_CAPABILITY_TYPE, 'delete_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'edit_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'edit_others_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'edit_published_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'delete_published_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'delete_private_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'delete_others_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'publish_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'read_private_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'chronosly_options', 'chronosly_license') as $cap) {
         $WP_Roles->add_cap(CHRONOSLY_ADMIN_ROLE, $cap);
     }
     $ext = new Chronosly_Extend();
     //the new code will set CHRONOSLY_VERSION code to the latest
     //update templates and addons
     $ext->update_addons();
     $ext->update_templates();
     $ext->rebuild_template_addons("default");
     Chronosly_Cache::clear_cache();
     wp_schedule_event(time(), "daily", 'chronosly_update_addons');
     wp_schedule_event(time(), "daily", 'chronosly_update_templates');
 }
                        echo '<div class="bubbleerror">There was an error installing this addon.</div>';
                    }
                }
            } else {
                wp_die("The file type that you've uploaded is not a Chronosly Addons ZIP.");
            }
            // end if/else
        }
        // end if
    }
} else {
    if (isset($_REQUEST["update_addon"]) and $_REQUEST["update_addon"] and isset($_REQUEST['addon'])) {
        if (!current_user_can('manage_options')) {
            wp_die(__('You do not have sufficient permissions to access this page.'));
        }
        $ext = new Chronosly_Extend();
        echo $ext->update_addons($_REQUEST['addon']);
    } else {
        if (isset($_REQUEST["delete"])) {
            if (!current_user_can('manage_options')) {
                wp_die(__('You do not have sufficient permissions to access this page.'));
            }
            if (has_filter("chronosly_update_template_" . $_REQUEST["delete"])) {
                $Post_Type_Chronosly->template->full_update_templates_by_addon($_REQUEST["delete"], array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), "remove");
            }
            if (has_action("chronosly_remove_" . $_REQUEST["delete"])) {
                do_action("chronosly_remove_" . $_REQUEST["delete"]);
            }
            //remove files and reload page
            $utils = new Chronosly_Utils();
            $utils->rrmdir(CHRONOSLY_ADDONS_PATH . DIRECTORY_SEPARATOR . $_REQUEST["delete"]);
 public function template_edit_page()
 {
     global $Post_Type_Chronosly;
     if (!current_user_can('manage_options')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     if (isset($_POST['chronosly_nonce'])) {
         //uploading templates
         if (wp_verify_nonce($_POST['chronosly_nonce'], "chronosly_addons_upload")) {
             if (!empty($_FILES['chronosly_addon']['name'])) {
                 Chronosly_Cache::clear_cache();
                 //print_r($_FILES['chronosly_addon']);
                 // Setup the array of supported file types. In this case, it's just PDF.
                 $supported_types = array('application/zip');
                 // Get the file type of the upload
                 $arr_file_type = wp_check_filetype(basename($_FILES['chronosly_addon']['name']));
                 $uploaded_type = $arr_file_type['type'];
                 // Check if the type is supported. If not, throw an error.
                 if (in_array($uploaded_type, $supported_types)) {
                     // Use the WordPress API to upload the file
                     $upload = wp_upload_bits($_FILES['chronosly_addon']['name'], null, file_get_contents($_FILES['chronosly_addon']['tmp_name']));
                     if (isset($upload['error']) && $upload['error'] != 0) {
                         echo '<div class="bubbleerror">' . __(sprintf('There was an error uploading your file. The error is: %s', "chronosly"), $upload['error']) . "</div>";
                     } else {
                         WP_Filesystem();
                         $destination_path = CHRONOSLY_TEMPLATES_PATH;
                         $upload['file'] = str_replace(array("/", "\\"), DIRECTORY_SEPARATOR, $upload['file']);
                         $unzipfile = unzip_file($upload['file'], $destination_path);
                         unlink($upload['file']);
                         if ($unzipfile === true) {
                             $names = explode(DIRECTORY_SEPARATOR, $upload['file']);
                             $name = str_replace(".zip", "", $names[count($names) - 1]);
                             //volvemos a construir los addons
                             Chronosly_Extend::rebuild_template_addons($name);
                             echo "<div class='bubblegreen'>{$name} " . __("template installed", "chronosly") . "</div>";
                             wp_redirect("admin.php?page=chronosly_edit_templates&installed={$name}");
                         } else {
                             echo '<div class="bubbleerror">' . __("There was an error installing this template", "chronosly") . '</div>';
                         }
                     }
                 } else {
                     echo '<div class="bubbleerror">' . __("The file type that you've uploaded is not a Chronosly Template ZIP.", "chronosly") . "</div>";
                 }
                 // end if/else
             }
             // end if
         }
     }
     $Post_Type_Chronosly->inicia_scripts();
     include CHRONOSLY_PATH . DIRECTORY_SEPARATOR . "metaboxes" . DIRECTORY_SEPARATOR . "settings" . DIRECTORY_SEPARATOR . "template-editor.php";
 }