예제 #1
0
 /** ====================================================================================================================================================
  * Ensure that the needed folders are writable by the webserver. 
  * Will check usual folders and files.
  * You may add this in your configuration page <code>$this->check_folder_rights( array(array($theFolderToCheck, "rw")) ) ;</code>
  * If not a error msg is printed
  * 
  * @param array $folders list of array with a first element (the complete path of the folder to check) and a second element (the needed rights "r", "w" [or a combination of those])
  * @return void
  */
 public function check_folder_rights($folders)
 {
     $f = array(array(WP_CONTENT_DIR . '/sedlex/', "rw"), array(WP_PLUGIN_DIR . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . 'readme.txt', "rw"), array(WP_PLUGIN_DIR . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . 'css/', "r"), array(WP_PLUGIN_DIR . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . 'js/', "r"), array(WP_PLUGIN_DIR . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . 'lang/', "rw"), array(WP_PLUGIN_DIR . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . 'core/', "r"), array(WP_PLUGIN_DIR . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . 'core/img/', "r"), array(WP_PLUGIN_DIR . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . 'core/templates/', "r"), array(WP_PLUGIN_DIR . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . 'core/lang/', "rw"), array(WP_PLUGIN_DIR . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . 'core/js/', "r"), array(WP_PLUGIN_DIR . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . 'core/css/', "r"));
     $folders = array_merge($folders, $f);
     $result = "";
     foreach ($folders as $f) {
         if (is_dir($f[0]) || @is_file($f[0])) {
             $readable = SLFramework_Utils::is_readable($f[0]);
             $writable = SLFramework_Utils::is_writable($f[0]);
             @chmod($f[0], 0755);
             $pb = false;
             if (strpos($f[1], "r") !== false && !$readable) {
                 $pb = true;
             }
             if (strpos($f[1], "w") !== false && !$writable) {
                 $pb = true;
             }
             if ($pb) {
                 if (is_dir($f[0])) {
                     $result .= "<p>" . sprintf(__('The folder %s is not %s !', 'SL_framework'), "<code>" . $f[0] . "</code>", "<code>" . $f[1] . "</code>") . "</p>";
                 }
                 if (@is_file($f[0])) {
                     $result .= "<p>" . sprintf(__('The file %s is not %s !', 'SL_framework'), "<code>" . $f[0] . "</code>", "<code>" . $f[1] . "</code>") . "</p>";
                 }
             }
         } else {
             // We check if the last have an extension
             if (strpos(basename($f[0]), ".") === false) {
                 // It is a folder
                 if (!@mkdir($f[0], 0755, true)) {
                     $result .= "<p>" . sprintf(__('The folder %s does not exists and cannot be created !', 'SL_framework'), "<code>" . $f[0] . "</code>") . "</p>";
                 }
             } else {
                 $foldtemp = str_replace(basename($f[0]), "", str_replace(basename($f[0]) . "/", "", $f[0]));
                 // We create the sub folders
                 if (!is_dir($foldtemp) && !@mkdir($foldtemp, 0755, true)) {
                     $result .= "<p>" . sprintf(__('The folder %s does not exists and cannot be created !', 'SL_framework'), "<code>" . $foldtemp . "</code>") . "</p>";
                 } else {
                     // We touch the file
                     @chmod($foldtemp, 0755);
                     if (@file_put_contents($f[0], '') === false) {
                         $result .= "<p>" . sprintf(__('The file %s does not exists and cannot be created !', 'SL_framework'), "<code>" . $f[0] . "</code>") . "</p>";
                     }
                 }
             }
         }
     }
     if ($result != "") {
         echo "<div class='error fade'><p>" . __('There are some issues with folders rights. Please corret them as soon as possible as they could induce bugs and instabilities.', 'SL_framework') . "</p><p>" . __('Please see below:', 'SL_framework') . "</p>" . $result . "</div>";
     }
 }
예제 #2
0
 /** ====================================================================================================================================================
  * Create the sql file
  * 
  * @param string $sqlfilename the path of the sql file to create
  * @param integer $maxExecutionTime the maximum execution time (in second)
  * @param integer $maxAllocatedMemory the maximum memory allocated by the process (in bytes)
  * @return array with the name of the file (or 'finished' => false and if an error occured see 'error' for the error message)
  */
 function createSQL($sqlfilename, $maxExecutionTime = 20, $maxAllocatedMemory = 4000000)
 {
     global $wpdb;
     $sepBlog = $this->sepBlog;
     $extension = array();
     $timedebut = time();
     $all_path_files = array();
     $path = dirname($sqlfilename);
     // We check that no process is running
     if (is_file($path . "/sql_in_progress")) {
         $timestart = @file_get_contents($path . "/sql_in_progress");
         if ($timestart === FALSE) {
             return array('finished' => false, "error" => sprintf(__('The file %s cannot be read. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/sql_in_progress</code>"));
         }
         $timeprocess = time() - (int) $timestart;
         // We ensure that the process has not been started a too long time ago
         return array('finished' => false, 'error' => sprintf(__("An other process is still running (it runs for %s seconds)", "SL_framework"), $timeprocess), 'for' => $timeprocess);
     }
     // We create a file with the time inside to indicate that this process is doing something
     $r = @file_put_contents(dirname($sqlfilename) . "/sql_in_progress", time());
     if ($r === FALSE) {
         return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/sql_in_progress</code>"));
     }
     // Default value
     $current_index = 0;
     $current_offset = 0;
     $max_size = 10;
     $contentOfTable = "";
     // We look if the .sql.tmp file exists, if so, it means that we have to restart the zip process where it stopped
     if (is_file($sqlfilename . ".sql.tmp")) {
         // We retrieve the process
         $content = @file_get_contents($sqlfilename . ".sql.tmp");
         if ($content === FALSE) {
             return array('finished' => false, "error" => sprintf(__('The file %s cannot be read. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $sqlfilename . ".sql.tmp</code>"));
         }
         list($list_table, $current_index, $current_offset, $nb_entry_total, $nb_entry_current, $sqlfilename, $extension, $all_path_files, $timedebut) = unserialize($content);
     } else {
         $list_table = $wpdb->get_results("show tables LIKE '" . $this->filter . "%'", ARRAY_N);
         $nb_entry_total = 0;
         $nb_entry_current = 0;
         foreach ($list_table as $table) {
             $nb_entry_total += $wpdb->get_var("SELECT COUNT(*) FROM " . $table[0]);
         }
     }
     // We create the sql file
     for ($i = $current_index; $i < count($list_table); $i++) {
         $table = $list_table[$i];
         $nb_response = $max_size;
         $ext_blog = "";
         if (!isset($extension[$ext_blog])) {
             $extension[$ext_blog] = 1;
             $all_path_files[$sqlfilename . $ext_blog . ".sql1"] = time();
         }
         while ($nb_response == $max_size) {
             // We check whether there is no more entry in that table
             // Now we retrieve the content.
             if ($current_offset == 0) {
                 // On doit separer les différents blogs
                 if ($sepBlog != "") {
                     if (preg_match("/^" . $sepBlog . "([0-9]*)_/", $table[0], $match)) {
                         if ($ext_blog != "_blog" . $match[1]) {
                             $ext_blog = "_blog" . $match[1];
                             if (!isset($extension[$ext_blog])) {
                                 $extension[$ext_blog] = 1;
                             }
                             if (!is_file($sqlfilename . $ext_blog . ".sql" . $extension[$ext_blog])) {
                                 $all_path_files[$sqlfilename . $ext_blog . ".sql" . $extension[$ext_blog]] = time();
                             }
                         }
                     }
                 }
                 $contentOfTable .= "\n\n";
                 $contentOfTable .= "-- ===============================================================\n";
                 $contentOfTable .= "\n";
                 $contentOfTable .= "-- DROP and CREATE " . $table[0] . "\n";
                 $contentOfTable .= "-- -----------------------------\n";
                 $contentOfTable .= "DROP TABLE IF EXISTS " . $table[0] . ";\n";
                 $contentOfTable .= $wpdb->get_var("show create table " . $table[0], 1) . ";";
                 $contentOfTable .= "\n\n";
                 $contentOfTable .= "-- INSERT INTO " . $table[0] . "\n";
                 $contentOfTable .= "-- -----------------------------\n\n";
             }
             $lignes = $wpdb->get_results("SELECT * FROM " . $table[0] . " LIMIT " . $current_offset . "," . $max_size, ARRAY_N);
             $nb_response = count($lignes);
             foreach ($lignes as $ligne) {
                 $current_offset++;
                 $nb_entry_current++;
                 $contentOfTable .= "INSERT INTO " . $table[0] . " VALUES(";
                 for ($ii = 0; $ii < count($ligne); $ii++) {
                     if ($ii != 0) {
                         $contentOfTable .= ", ";
                     }
                     //DATE, TIMESTAMP, TIMESTAMP
                     $delimit = "'";
                     if ($wpdb->get_col_info('type', $ii) == "string" || $wpdb->get_col_info('type', $ii) == "blob" || $wpdb->get_col_info('type', $ii) == "datetime" || $wpdb->get_col_info('type', $ii) == "date" || $wpdb->get_col_info('type', $ii) == "timestamp" || $wpdb->get_col_info('type', $ii) == "time" || $wpdb->get_col_info('type', $ii) == "year") {
                         if ($ligne[$ii] == NULL) {
                             $ligne[$ii] = "";
                         }
                     } else {
                         if ($ligne[$ii] == NULL) {
                             $ligne[$ii] = "NULL";
                             $delimit = "";
                         }
                     }
                     $contentOfTable .= $delimit . addslashes($ligne[$ii]) . $delimit;
                 }
                 $contentOfTable .= ");\n";
                 // WE SAVE THE DATA in THE FILE
                 // We check if the file is too big
                 clearstatcache();
                 $filesizeSQL = 0;
                 if (is_file($sqlfilename . $ext_blog . ".sql" . $extension[$ext_blog])) {
                     $filesizeSQL = filesize($sqlfilename . $ext_blog . ".sql" . $extension[$ext_blog]);
                 }
                 if ($maxAllocatedMemory * 2 / 3 < strlen($contentOfTable) + $filesizeSQL) {
                     $extension[$ext_blog]++;
                     $all_path_files[$sqlfilename . $ext_blog . ".sql" . $extension[$ext_blog]] = time();
                 }
                 // We save the content on the disk and we restart
                 $r = @file_put_contents($sqlfilename . $ext_blog . ".sql" . $extension[$ext_blog], $contentOfTable, FILE_APPEND);
                 $contentOfTable = "";
                 if ($r === FALSE) {
                     return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $sqlfilename . $ext_blog . ".sql" . $extension[$ext_blog] . "</code>"));
                 }
                 // We check that the time is not exceeded
                 $nowtime = microtime(true);
                 if ($maxExecutionTime != 0) {
                     if ($nowtime - $this->starttime > $maxExecutionTime) {
                         $r = @file_put_contents($sqlfilename . ".sql.tmp", serialize(array($list_table, $i, $current_offset, $nb_entry_total, $nb_entry_current, $sqlfilename, $extension, $all_path_files, $timedebut)));
                         if ($r === FALSE) {
                             return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $sqlfilename . ".sql.tmp</code>"));
                         }
                         // we inform that the process is finished
                         if (!SLFramework_Utils::rm_rec($path . "/sql_in_progress")) {
                             return array('finished' => false, "step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/sql_in_progress" . "</code>"));
                         }
                         return array('finished' => false, 'nb_to_finished' => $nb_entry_total - $nb_entry_current, 'nb_finished' => $nb_entry_current, 'info' => $table[0], 'start' => $timedebut);
                     }
                 }
             }
         }
         $current_offset = 0;
     }
     $filesizeSQL = 0;
     if (is_file($sqlfilename . $ext_blog . ".sql" . $extension[$ext_blog])) {
         $filesizeSQL = filesize($sqlfilename . $ext_blog . ".sql" . $extension[$ext_blog]);
     }
     if ($maxAllocatedMemory < strlen($contentOfTable) + $filesizeSQL) {
         $extension[$ext_blog]++;
         $all_path_files[$sqlfilename . $ext_blog . ".sql" . $extension[$ext_blog]] = time();
     }
     // We complete the tmp files with current content
     $r = @file_put_contents($sqlfilename . $ext_blog . ".sql" . $extension[$ext_blog], $contentOfTable, FILE_APPEND);
     if ($r === FALSE) {
         return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $sqlfilename . ".sql.tmp</code>"));
     }
     // we inform that the process is finished
     if (!SLFramework_Utils::rm_rec($path . "/sql_in_progress")) {
         return array('finished' => false, "step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/sql_in_progress" . "</code>"));
     }
     if (!SLFramework_Utils::rm_rec($sqlfilename . ".sql.tmp")) {
         return array('finished' => false, "step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $sqlfilename . ".sql.tmp" . "</code>"));
     }
     return array('finished' => true, 'nb_to_finished' => 0, 'nb_finished' => $nb_entry_current, 'path' => $all_path_files, 'start' => $timedebut);
 }
        /** ====================================================================================================================================================
         * Print the form with parameters
         * 	
         * @return void
         */
        function flush()
        {
            global $_POST;
            global $_FILES;
            global $wpdb;
            $this->buffer[] = array('end', "");
            // We create the beginning of the form
            $this->output = "<h3>" . __("Parameters", 'SL_framework') . "</h3>";
            if ($this->obj->getPluginID() != "") {
                $this->output .= "<p>" . __("Here are the parameters of the plugin. Modify them at will to fit your needs.", "SL_framework") . "</p>";
            } else {
                $this->output .= "<p>" . __("Here are the parameters of the framework. Modify them at will to fit your needs.", "SL_framework") . "</p>";
            }
            $this->output .= "<div class='wrap parameters'><form enctype='multipart/form-data' method='post' action='" . $_SERVER["REQUEST_URI"] . "'>\n";
            // We compute the parameter output
            $hastobeclosed = false;
            $maj = false;
            $modified = false;
            $error = false;
            $warning = false;
            $toExecuteWhenLoaded = "";
            $macroisdisplayed_count = 0;
            $macroisdisplayed = false;
            $macroisdisplayed_avoidnext = false;
            for ($iii = 0; $iii < count($this->buffer); $iii++) {
                $ligne = $this->buffer[$iii];
                // Is it a title
                if ($ligne[0] == "end" || $ligne[0] == "title" || $ligne[0] == "title_macro") {
                    if ($hastobeclosed) {
                        $this->output .= $currentTable->flush() . "<br/>";
                        $hastobeclosed = false;
                    }
                    // On test si on doit recommencer
                    if ($macroisdisplayed && !$macroisdisplayed_avoidnext) {
                        $nnn = 1;
                        // We search for the next parameter
                        $found_param = false;
                        while (isset($this->buffer[$macro_lasttitle + $nnn])) {
                            $first_param_after = $this->buffer[$macro_lasttitle + $nnn];
                            if ($first_param_after[0] == 'param') {
                                $found_param = true;
                                $first_param_after = $first_param_after[1];
                                break;
                            } else {
                                if ($first_param_after[0] == 'comment') {
                                    $nnn++;
                                } else {
                                    break;
                                }
                            }
                        }
                        // if the param has been found
                        if ($found_param) {
                            $all_names = $this->obj->get_name_params();
                            if (in_array($first_param_after . "_macro" . ($macroisdisplayed_count + 1), $all_names)) {
                                $iii = $macro_lasttitle - 1;
                                $macroisdisplayed_count++;
                                $macroisdisplayed_avoidnext = true;
                                continue;
                            } else {
                                $macroisdisplayed_count = 0;
                                $macroisdisplayed = false;
                                $macroisdisplayed_avoidnext = false;
                            }
                        }
                    }
                    $macroisdisplayed_avoidnext = false;
                    // We create a new table
                    $currentTable = new SLFramework_Table();
                    $currentTable->removeFooter();
                    $hastobeclosed = true;
                    if ($ligne[0] == "title") {
                        $currentTable->title(array($ligne[1], ""));
                        $macroisdisplayed = false;
                        $macroisdisplayed_text = "";
                    } else {
                        if ($ligne[0] == "title_macro") {
                            // Add delete button
                            $params = "[";
                            $count_param_temp = 0;
                            $nnn = 1;
                            while (isset($this->buffer[$iii + $nnn])) {
                                $first_param_after = $this->buffer[$iii + $nnn];
                                if ($first_param_after[0] == 'param') {
                                    if ($count_param_temp != 0) {
                                        $params .= ",";
                                    }
                                    $params .= "\"" . $first_param_after[1] . "_macro" . $macroisdisplayed_count . "\"";
                                    $nnn++;
                                    $count_param_temp++;
                                } else {
                                    if ($first_param_after[0] == 'comment') {
                                        $nnn++;
                                    } else {
                                        break;
                                    }
                                }
                            }
                            $params .= "]";
                            $md5 = sha1($params);
                            $delete = " <a href='#' onclick='del_param(" . $params . ", \"" . $md5 . "\", \"" . $this->obj->pluginID . "\");return false ; ' style='font-size:80%'>" . __('(Delete)', 'SL_framework') . "</a>";
                            $x = plugin_dir_url("/") . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__));
                            $delete .= "<img id='wait_" . $md5 . "' src='" . $x . "/img/ajax-loader.gif' style='display:none;'>";
                            // Add add button
                            $add = "";
                            $macroisdisplayed_text = $ligne[2];
                            if ($macroisdisplayed_count == 0) {
                                $params = "[";
                                $count_param_temp = 0;
                                $nnn = 1;
                                while (isset($this->buffer[$iii + $nnn])) {
                                    $first_param_after = $this->buffer[$iii + $nnn];
                                    if ($first_param_after[0] == 'param') {
                                        if ($count_param_temp != 0) {
                                            $params .= ",";
                                        }
                                        $params .= "\"" . $first_param_after[1] . "_macro\"";
                                        $nnn++;
                                        $count_param_temp++;
                                    } else {
                                        if ($first_param_after[0] == 'comment') {
                                            $nnn++;
                                        } else {
                                            break;
                                        }
                                    }
                                }
                                $params .= "]";
                                $md5 = sha1($params);
                                $add = " <a href='#' onclick='add_param(" . $params . ", \"" . $md5 . "\", \"" . $this->obj->pluginID . "\");return false ; ' style='font-size:80%'>(" . $macroisdisplayed_text . ")</a>";
                                $x = plugin_dir_url("/") . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__));
                                $add .= "<img id='wait_" . $md5 . "' src='" . $x . "/img/ajax-loader.gif' style='display:none;'>";
                            }
                            if (strpos($ligne[1], "%s") !== false) {
                                $currentTable->title(array(sprintf($ligne[1], $macroisdisplayed_count + 1) . $delete . $add, ""));
                            } else {
                                $currentTable->title(array($ligne[1] . $delete, ""));
                            }
                            $macro_lasttitle = $iii;
                            $macroisdisplayed_count_elements = 0;
                            $macroisdisplayed = true;
                        }
                    }
                }
                // compte le nombre d element dans la macro
                if ($macroisdisplayed) {
                    $macroisdisplayed_count_elements++;
                } else {
                    $macroisdisplayed_count_elements = 0;
                }
                // Is it a comment
                if ($ligne[0] == "comment") {
                    if (!$hastobeclosed) {
                        // We create a default table as no title has been provided
                        $currentTable = new SLFramework_Table();
                        $currentTable->removeFooter();
                        $currentTable->title(array(__("Parameters", "SL_framework"), __("Values", "SL_framework")));
                        $hastobeclosed = true;
                    }
                    $cl = "<p class='paramComment' style='color: #a4a4a4;'>" . $ligne[1] . "</p>";
                    // We check if there is a comment just after it
                    while (isset($this->buffer[$iii + 1])) {
                        if ($this->buffer[$iii + 1][0] != "comment") {
                            break;
                        }
                        $cl .= "<p class='paramComment' style='color: #a4a4a4;'>" . $this->buffer[$iii + 1][1] . "</p>";
                        $iii++;
                    }
                    $cel_label = new adminCell($cl);
                    $cel_value = new adminCell("");
                    $currentTable->add_line(array($cel_label, $cel_value), '1');
                }
                // Is it a param
                if ($ligne[0] == "param") {
                    $param = $ligne[1];
                    $param_default = $ligne[1];
                    //macro
                    if ($macroisdisplayed) {
                        $param = $param . "_macro" . $macroisdisplayed_count;
                    }
                    $name = $ligne[2];
                    $forbid = $ligne[3];
                    $allow = $ligne[4];
                    $related = $ligne[5];
                    if (!$hastobeclosed) {
                        // We create a default table as no title has been provided
                        $currentTable = new SLFramework_Table();
                        $currentTable->removeFooter();
                        $currentTable->title(array(__("Parameters", "SL_framework"), __("Values", "SL_framework")));
                        $hastobeclosed = true;
                    }
                    // What is the type of the parameter ?
                    //---------------------------------------
                    $type = "string";
                    if (is_bool($this->obj->get_default_option($param_default))) {
                        $type = "boolean";
                    }
                    if (is_int($this->obj->get_default_option($param_default))) {
                        $type = "int";
                    }
                    if (is_array($this->obj->get_default_option($param_default))) {
                        $type = "list";
                    }
                    // C'est un text si dans le texte par defaut, il y a une etoile
                    if (is_string($this->obj->get_default_option($param_default))) {
                        if (strpos($this->obj->get_default_option($param_default), "*") === 0) {
                            $type = "text";
                        }
                    }
                    // C'est un file si dans le texte par defaut est egal a [file]
                    if (is_string($this->obj->get_default_option($param_default))) {
                        if (str_replace("[file]", "", $this->obj->get_default_option($param_default)) != $this->obj->get_default_option($param_default)) {
                            $type = "file";
                        }
                    }
                    // C'est un password si dans le texte par defaut est egal a [password]
                    if (is_string($this->obj->get_default_option($param_default))) {
                        if (str_replace("[password]", "", $this->obj->get_default_option($param_default)) != $this->obj->get_default_option($param_default)) {
                            $type = "password";
                        }
                    }
                    // C'est un media si dans le texte par defaut est egal a [media]
                    if (is_string($this->obj->get_default_option($param_default))) {
                        if (str_replace("[media]", "", $this->obj->get_default_option($param_default)) != $this->obj->get_default_option($param_default)) {
                            $type = "media";
                        }
                    }
                    // C'est un page si dans le texte par defaut est egal a [page]
                    if (is_string($this->obj->get_default_option($param_default))) {
                        if (str_replace("[page]", "", $this->obj->get_default_option($param_default)) != $this->obj->get_default_option($param_default)) {
                            $type = "page";
                        }
                    }
                    // We reset the param
                    //---------------------------------------
                    $problem_e = "";
                    $problem_w = "";
                    if (isset($_POST['resetOptions'])) {
                        $maj = true;
                        $new_param = $this->get_new_value($param_default);
                        $modified = true;
                        $this->obj->set_param($param, $new_param);
                    }
                    // We update the param
                    //---------------------------------------
                    $problem_e = "";
                    $problem_w = "";
                    if (isset($_POST['submitOptions'])) {
                        $maj = true;
                        $new_param = $this->get_new_value($param);
                        $old_param = $this->obj->get_param($param);
                        if (is_array($new_param) && isset($new_param[0]) && $new_param[0] == 'error') {
                            $problem_e .= $new_param[1];
                            $error = true;
                        } else {
                            // Warning management
                            if ($type == "string" || $type == "text" || $type == "password") {
                                if (isset($_POST[$param])) {
                                    if ($new_param != stripslashes($_POST[$param])) {
                                        $problem_w .= "<p>" . __('Warning: some characters have been removed because they are not allowed here', 'SL_framework') . " (" . $forbid . ")!</p>\n";
                                        $warning = true;
                                    }
                                }
                            }
                            // Update of the value
                            if ($new_param != $old_param) {
                                $modified = true;
                                $this->obj->set_param($param, $new_param);
                                SLFramework_Debug::log(get_class(), "The parameter " . $param . " of the plugin " . $this->obj->getPluginID() . " have been modified", 4);
                            }
                        }
                    }
                    // We built a new line for the table
                    //---------------------------------------
                    if ($type == "boolean") {
                        $cl = "<p class='paramLine'><label for='" . $param . "'>" . $name . "</label></p>";
                        // We check if there is a comment just after it
                        while (isset($this->buffer[$iii + 1])) {
                            if ($this->buffer[$iii + 1][0] != "comment") {
                                break;
                            }
                            $cl .= "<p class='paramComment' style='color: #a4a4a4;'>" . $this->buffer[$iii + 1][1] . "</p>";
                            $iii++;
                        }
                        $cel_label = new adminCell($cl);
                        $checked = "";
                        if ($this->obj->get_param($param)) {
                            $checked = "checked";
                        }
                        if (count($related) > 0) {
                            $onClick = "onClick='activateDeactivate_Params(\"" . $param . "\",new Array(\"" . implode("\",\"", $related) . "\"))'";
                            $toExecuteWhenLoaded .= "activateDeactivate_Params(\"" . $param . "\",new Array(\"" . implode("\",\"", $related) . "\"));\n";
                        } else {
                            $onClick = "";
                        }
                        $workaround = "<input type='hidden' value='0' name='" . $param . "_workaround' id='" . $param . "_workaround'>";
                        $cel_value = new adminCell("<p class='paramLine'>" . $workaround . "<input " . $onClick . " name='" . $param . "' id='" . $param . "' type='checkbox' " . $checked . " ></p>");
                        $currentTable->add_line(array($cel_label, $cel_value), '1');
                    }
                    if ($type == "int") {
                        $ew = "";
                        if ($problem_e != "") {
                            $ew .= "<div class='errorSedLex'>" . $problem_e . "</div>";
                        }
                        if ($problem_w != "") {
                            $ew .= "<div class='warningSedLex'>" . $problem_w . "</div>";
                        }
                        $cl = "<p class='paramLine'><label for='" . $param . "'>" . $name . "</label></p>" . $ew;
                        // We check if there is a comment just after it
                        while (isset($this->buffer[$iii + 1])) {
                            if ($this->buffer[$iii + 1][0] != "comment") {
                                break;
                            }
                            $cl .= "<p class='paramComment' style='color: #a4a4a4;'>" . $this->buffer[$iii + 1][1] . "</p>";
                            $iii++;
                        }
                        $cel_label = new adminCell($cl);
                        $cel_value = new adminCell("<p class='paramLine'><input name='" . $param . "' id='" . $param . "' type='text' value='" . $this->obj->get_param($param) . "' size='" . min(30, max(6, strlen($this->obj->get_param($param) . '') + 1)) . "'> " . __('(integer)', 'SL_framework') . "</p>");
                        $currentTable->add_line(array($cel_label, $cel_value), '1');
                    }
                    if ($type == "string") {
                        $ew = "";
                        if ($problem_e != "") {
                            $ew .= "<div class='errorSedLex'>" . $problem_e . "</div>";
                        }
                        if ($problem_w != "") {
                            $ew .= "<div class='warningSedLex'>" . $problem_w . "</div>";
                        }
                        $cl = "<p class='paramLine'><label for='" . $param . "'>" . $name . "</label></p>" . $ew;
                        // We check if there is a comment just after it
                        while (isset($this->buffer[$iii + 1])) {
                            if ($this->buffer[$iii + 1][0] != "comment") {
                                break;
                            }
                            $cl .= "<p class='paramComment' style='color: #a4a4a4;'>" . $this->buffer[$iii + 1][1] . "</p>";
                            $iii++;
                        }
                        $cel_label = new adminCell($cl);
                        $cel_value = new adminCell("<p class='paramLine'><input name='" . $param . "' id='" . $param . "' type='text' value='" . htmlentities($this->obj->get_param($param), ENT_QUOTES, "UTF-8") . "' size='" . min(30, max(6, strlen($this->obj->get_param($param) . '') + 1)) . "'></p>");
                        $currentTable->add_line(array($cel_label, $cel_value), '1');
                    }
                    if ($type == "password") {
                        $ew = "";
                        if ($problem_e != "") {
                            $ew .= "<div class='errorSedLex'>" . $problem_e . "</div>";
                        }
                        if ($problem_w != "") {
                            $ew .= "<div class='warningSedLex'>" . $problem_w . "</div>";
                        }
                        $cl = "<p class='paramLine'><label for='" . $param . "'>" . $name . "</label></p>" . $ew;
                        // We check if there is a comment just after it
                        while (isset($this->buffer[$iii + 1])) {
                            if ($this->buffer[$iii + 1][0] != "comment") {
                                break;
                            }
                            $cl .= "<p class='paramComment' style='color: #a4a4a4;'>" . $this->buffer[$iii + 1][1] . "</p>";
                            $iii++;
                        }
                        $cel_label = new adminCell($cl);
                        $cel_value = new adminCell("<p class='paramLine'><input name='" . $param . "' id='" . $param . "' type='password' value='" . htmlentities($this->obj->get_param($param), ENT_QUOTES, "UTF-8") . "' size='" . min(30, max(6, strlen($this->obj->get_param($param) . '') + 1)) . "'></p>");
                        $currentTable->add_line(array($cel_label, $cel_value), '1');
                    }
                    if ($type == "text") {
                        $num = min(22, count(explode("\n", $this->obj->get_param($param))) + 1);
                        $ew = "";
                        if ($problem_e != "") {
                            $ew .= "<div class='errorSedLex'>" . $problem_e . "</div>";
                        }
                        if ($problem_w != "") {
                            $ew .= "<div class='warningSedLex'>" . $problem_w . "</div>";
                        }
                        $cl = "<p class='paramLine'><label for='" . $param . "'>" . $name . "</label></p>" . $ew;
                        // We check if there is a comment just after it
                        while (isset($this->buffer[$iii + 1])) {
                            if ($this->buffer[$iii + 1][0] != "comment") {
                                break;
                            }
                            $cl .= "<p class='paramComment' style='color: #a4a4a4;'>" . $this->buffer[$iii + 1][1] . "</p>";
                            $iii++;
                        }
                        $cel_label = new adminCell($cl);
                        $cel_value = new adminCell("<p class='paramLine'><div style='width:100%'><textarea style='width:100%' name='" . $param . "' id='" . $param . "' rows='" . $num . "'>" . htmlentities($this->obj->get_param($param), ENT_QUOTES, "UTF-8") . "</textarea></div></p>");
                        $currentTable->add_line(array($cel_label, $cel_value), '1');
                    }
                    if ($type == "list") {
                        $cl = "<p class='paramLine'><label for='" . $param . "'>" . $name . "</label></p>";
                        // We check if there is a comment just after it
                        while (isset($this->buffer[$iii + 1])) {
                            if ($this->buffer[$iii + 1][0] != "comment") {
                                break;
                            }
                            $cl .= "<p class='paramComment' style='color: #a4a4a4;'>" . $this->buffer[$iii + 1][1] . "</p>";
                            $iii++;
                        }
                        $cel_label = new adminCell($cl);
                        $cc = "";
                        ob_start();
                        ?>
							<p class='paramLine'>
							<select name='<?php 
                        echo $param;
                        ?>
' id='<?php 
                        echo $param;
                        ?>
'>
							<?php 
                        $array = $this->obj->get_param($param);
                        echo "//";
                        print_r($array);
                        foreach ($array as $a) {
                            if (!is_array($a)) {
                                $selected = "";
                                if (is_string($a) && substr($a, 0, 1) == "*") {
                                    $selected = "selected";
                                    $a = substr($a, 1);
                                }
                                ?>
										<option value="<?php 
                                echo SLFramework_Utils::create_identifier($a);
                                ?>
" <?php 
                                echo $selected;
                                ?>
><?php 
                                echo $a;
                                ?>
</option>
									<?php 
                            } else {
                                $selected = "";
                                if (is_string($a[0]) && substr($a[0], 0, 1) == "*") {
                                    $selected = "selected";
                                    $a[0] = substr($a[0], 1);
                                }
                                ?>
										<option value="<?php 
                                echo $a[1];
                                ?>
" <?php 
                                echo $selected;
                                ?>
><?php 
                                echo $a[0];
                                ?>
</option>
									<?php 
                            }
                        }
                        ?>
							</select>
							</p>
						<?php 
                        $cc = ob_get_clean();
                        $cel_value = new adminCell($cc);
                        $currentTable->add_line(array($cel_label, $cel_value), '1');
                    }
                    if ($type == "media") {
                        $cl = "<p class='paramLine'><label for='" . $param . "'>" . $name . "</label></p>" . $ew;
                        // We check if there is a comment just after it
                        while (isset($this->buffer[$iii + 1])) {
                            if ($this->buffer[$iii + 1][0] != "comment") {
                                break;
                            }
                            $cl .= "<p class='paramComment' style='color: #a4a4a4;'>" . $this->buffer[$iii + 1][1] . "</p>";
                            $iii++;
                        }
                        $cel_label = new adminCell($cl);
                        // If this is the URL of an auto-generated thumbnail, get the URL of the original image
                        $attachment_url = preg_replace('/-\\d+x\\d+(?=\\.(jpg|jpeg|png|gif)$)/i', '', $this->obj->get_param($param));
                        $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid='%s';", $attachment_url));
                        if (isset($attachment[0])) {
                            $id_media = $attachment[0];
                            $msg_media = "<p class='paramComment' style='color: #a4a4a4;'>" . sprintf(__("The URL is correct and the ID of the media file is %s.", 'SL_framework'), '<code>' . $id_media . "</code>") . "</p>";
                            if (wp_attachment_is_image($id_media)) {
                                $msg_media .= '<p class="paramComment" style="color: #a4a4a4; text-align:center;"><a href="' . get_attachment_link($id_media) . '">' . wp_get_attachment_image($id_media, "thumbnail") . '</a></p>';
                            } else {
                                $msg_media .= '<p class="paramComment" style="color: #a4a4a4; text-align:center;>coucou</p>';
                            }
                        } else {
                            $msg_media = "<p class='paramComment' style='color: #a4a4a4;'>" . __("The URL is not a media file.", 'SL_framework') . "</p>";
                        }
                        $cel_value = new adminCell("<p class='paramLine'><div style='width:100%'><input id='" . $param . "' type='text' size='20' name='" . $param . "' value='" . htmlentities($this->obj->get_param($param), ENT_QUOTES, "UTF-8") . "' /><input id='media_" . $param . "' class='button' type='button' value='" . __('Choose a media', 'SL_framework') . "' onclick=\"paramMediaReturn = '" . $param . "'; formfield = jQuery('#" . $param . "').attr('name'); tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true'); return false;\"/></div></p>" . $msg_media);
                        $currentTable->add_line(array($cel_label, $cel_value), '1');
                    }
                    if ($type == "page") {
                        $cl = "<p class='paramLine'><label for='" . $param . "'>" . $name . "</label></p>" . $ew;
                        // We check if there is a comment just after it
                        while (isset($this->buffer[$iii + 1])) {
                            if ($this->buffer[$iii + 1][0] != "comment") {
                                break;
                            }
                            $cl .= "<p class='paramComment' style='color: #a4a4a4;'>" . $this->buffer[$iii + 1][1] . "</p>";
                            $iii++;
                        }
                        $cel_label = new adminCell($cl);
                        $selected = 0;
                        if ($this->obj->get_param($param) != "[page]") {
                            $selected = $this->obj->get_param($param);
                        }
                        $cel_value = new adminCell("<p class='paramLine'>" . wp_dropdown_pages(array('echo' => 0, 'name' => $param, 'selected' => $selected, "show_option_none" => __('(none)', "SLFramework"), "option_none_value" => '[page]')) . "</p>");
                        $currentTable->add_line(array($cel_label, $cel_value), '1');
                    }
                    if ($type == "file") {
                        $ew = "";
                        if ($problem_e != "") {
                            $ew .= "<div class='errorSedLex'>" . $problem_e . "</div>";
                        }
                        if ($problem_w != "") {
                            $ew .= "<div class='warningSedLex'>" . $problem_w . "</div>";
                        }
                        $cl = "<p class='paramLine'><label for='" . $param . "'>" . $name . "</label></p>" . $ew;
                        // We check if there is a comment just after it
                        while (isset($this->buffer[$iii + 1])) {
                            if ($this->buffer[$iii + 1][0] != "comment") {
                                break;
                            }
                            $cl .= "<p class='paramComment' style='color: #a4a4a4;'>" . $this->buffer[$iii + 1][1] . "</p>";
                            $iii++;
                        }
                        $cel_label = new adminCell($cl);
                        $cc = "";
                        ob_start();
                        $upload_dir = wp_upload_dir();
                        if (!file_exists($upload_dir["basedir"] . $this->obj->get_param($param))) {
                            $this->obj->set_param($param, $this->obj->get_default_option($param_default));
                        }
                        if ($this->obj->get_default_option($param_default) == $this->obj->get_param($param)) {
                            ?>
								<p class='paramLine'><input type='file' name='<?php 
                            echo $param;
                            ?>
' id='<?php 
                            echo $param;
                            ?>
'/></p>
								<?php 
                        } else {
                            $path = $upload_dir["baseurl"] . $this->obj->get_param($param);
                            $pathdir = $upload_dir["basedir"] . $this->obj->get_param($param);
                            $info = pathinfo($pathdir);
                            if (strtolower($info['extension']) == "png" || strtolower($info['extension']) == "gif" || strtolower($info['extension']) == "jpg" || strtolower($info['extension']) == "bmp") {
                                list($width, $height) = getimagesize($pathdir);
                                $max_width = 100;
                                $max_height = 100;
                                $ratioh = $max_height / $height;
                                $ratiow = $max_width / $width;
                                $ratio = min($ratioh, $ratiow);
                                // New dimensions
                                $width = min(intval($ratio * $width), $width);
                                $height = min(intval($ratio * $height), $height);
                                ?>
									<p class='paramLine'><img src='<?php 
                                echo $path;
                                ?>
' width="<?php 
                                echo $width;
                                ?>
px" height="<?php 
                                echo $height;
                                ?>
px" style="vertical-align:middle;"/> <a href="<?php 
                                echo $path;
                                ?>
"><?php 
                                echo $this->obj->get_param($param);
                                ?>
</a></p>
									<?php 
                            } else {
                                ?>
									<p class='paramLine'><img src='<?php 
                                echo plugin_dir_url("/") . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . "img/file.png";
                                ?>
' width="75px" style="vertical-align:middle;"/> <a href="<?php 
                                echo $path;
                                ?>
"><?php 
                                echo $this->obj->get_param($param);
                                ?>
</a></p>
									<?php 
                            }
                            ?>
								<p class='paramLine'><?php 
                            echo sprintf(__("(If you want to delete this file, please check this box %s)", "SL_framework"), "<input type='checkbox'  name='delete_" . $param . "' value='1' id='delete_" . $param . "'>");
                            ?>
</p>
								<?php 
                        }
                        $cc = ob_get_clean();
                        $cel_value = new adminCell($cc);
                        $currentTable->add_line(array($cel_label, $cel_value), '1');
                    }
                }
                // End is it a param?
            }
            // We finish the form output
            ob_start();
            ?>
					<div class="submit">
						<input type="submit" name="submitOptions" class='button-primary validButton' value="<?php 
            echo __('Update', 'SL_framework');
            ?>
" />&nbsp;
						<input type="submit" name="resetOptions" class='button validButton' value="<?php 
            echo __('Reset to default values', 'SL_framework');
            ?>
" />
					</div>
				</form>
			</div>
			<script>
				if (window.attachEvent) {window.attachEvent('onload', toExecuteWhenLoadedParameter);}
				else if (window.addEventListener) {window.addEventListener('load', toExecuteWhenLoadedParameter, false);}
				else {document.addEventListener('load', toExecuteWhenLoadedParameter, false);} 
				
				function toExecuteWhenLoadedParameter() {
					<?php 
            echo $toExecuteWhenLoaded;
            ?>
				}
			</script>
			<?php 
            // If the parameter have been modified, we say it !
            if ($error && $maj) {
                ?>
				<div class="error fade">
					<p><?php 
                echo __('Some parameters have not been updated due to errors (see below)!', 'SL_framework');
                ?>
</p>
				</div>
				<?php 
            } else {
                if ($warning && $maj) {
                    ?>
				<div class="updated  fade">
					<p><?php 
                    echo __('Parameters have been updated (but with some warnings)!', 'SL_framework');
                    ?>
</p>
				</div>
				<?php 
                } else {
                    if ($modified && $maj) {
                        if (!isset($_POST['resetOptions'])) {
                            ?>
				<div class="updated  fade">
					<p><?php 
                            echo __('Parameters have been updated successfully!', 'SL_framework');
                            ?>
</p>
				</div>
				<?php 
                        } else {
                            ?>
				<div class="updated  fade">
					<p><?php 
                            echo __('Parameters have been reset to their default values!', 'SL_framework');
                            ?>
</p>
				</div>
				<?php 
                        }
                    }
                }
            }
            $this->output .= ob_get_clean();
            echo $this->output;
        }
 /** ====================================================================================================================================================
  * Send Email when the backup ends
  *
  * @return void
  */
 function sendSummaryEmail()
 {
     if (preg_match('/(?:[a-z0-9!#$%&*+\\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&*+\\/=?^_`{|}~-]+)*|"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])/', $this->get_param('ftp_mail'))) {
         $message = "";
         $message .= "<p>" . __("Dear sirs,", $this->pluginID) . "</p><p>&nbsp;</p>";
         $message .= "<p>" . __("Please find hereafter a summary of the backup process.", $this->pluginID) . "</p>";
         $info = $this->get_param('info_process');
         $seconds = ($info['end'] - $info['start']) % 60;
         $minutes = floor(($info['end'] - $info['start']) / 60);
         $message .= "<h3>" . __("Global synthesis", $this->pluginID) . "</h3>";
         $message .= "<p>" . sprintf(__("The backup process has started on %s and have lasted %s minutes and %s seconds", $this->pluginID), date_i18n("F j, Y H:i:s", $info['start']), $minutes, $seconds) . "</p>";
         if (isset($info['sql'])) {
             $message .= "<h3>" . __("SQL synthesis", $this->pluginID) . "</h3>";
             $seconds = ($info['sql']['end'] - $info['sql']['start']) % 60;
             $minutes = floor(($info['sql']['end'] - $info['sql']['start']) / 60);
             $message .= "<p>" . sprintf(__("The SQL extraction has started on %s and have lasted %s minutes and %s seconds", $this->pluginID), date_i18n("F j, Y H:i:s", $info['sql']['start']), $minutes, $seconds) . "</p>";
             $message .= "<p>" . sprintf(__("%s entries have been extracted and have been stored in %s files.", $this->pluginID), $info['sql']['total_entries'], count($info['sql']['files'])) . "</p>";
             foreach ($info['sql']['files'] as $f => $time) {
                 $message .= "<li>";
                 $message .= sprintf(__("%s created on %s", $this->pluginID), basename($f), date_i18n("F j, Y H:i:s", $time));
                 $message .= "</li>";
             }
             $message .= "</ul>";
         }
         if (isset($info['zip'])) {
             $message .= "<h3>" . __("ZIP synthesis", $this->pluginID) . "</h3>";
             $seconds = ($info['zip']['end'] - $info['zip']['start']) % 60;
             $minutes = floor(($info['zip']['end'] - $info['zip']['start']) / 60);
             $message .= "<p>" . sprintf(__("The ZIP creation phase has started on %s and have lasted %s minutes and %s seconds", $this->pluginID), date_i18n("F j, Y H:i:s", $info['zip']['start']), $minutes, $seconds) . "</p>";
             $message .= "<p>" . sprintf(__("%s files have been stored into %s split files (zip, z01, z02, etc.).", $this->pluginID), $info['zip']['total_entries'], count($info['zip']['files'])) . "</p>";
             if (count(count($info['zip']['excluded_entries'])) != 0) {
                 $message .= "<p>" . sprintf(__("Please note that %s files have been excluded from the backup process because their sizes exceed the chunk size (i.e. %s Mo).", $this->pluginID), count($info['zip']['excluded_entries']), $this->get_param('max_allocated')) . "</p>";
                 $message .= "<ul>";
                 foreach ($info['zip']['excluded_entries'] as $f) {
                     $message .= "<li>";
                     $message .= sprintf(__("%s (size %s)", $this->pluginID), str_replace(ABSPATH, "", $f), SLFramework_Utils::byteSize(filesize($f)));
                     $message .= "</li>";
                 }
                 $message .= "</ul>";
             }
             $message .= "<p>" . sprintf(__("These zip files are accessible for %s days at the following path:", $this->pluginID), $this->get_param('delete_after')) . "</p>";
             $message .= "<ul>";
             foreach ($info['zip']['files'] as $time => $f) {
                 $message .= "<li>";
                 $message .= sprintf(__("%s created on %s", $this->pluginID), "<a href='" . str_replace(WP_CONTENT_DIR, WP_CONTENT_URL, $f) . "'>" . basename($f) . "</a>", date_i18n("F j, Y H:i:s", $time));
                 $message .= "</li>";
             }
             $message .= "</ul>";
         }
         if (isset($info['ftp'])) {
             $message .= "<h3>" . __("FTP synthesis", $this->pluginID) . "</h3>";
             $message .= "<p>" . sprintf(__("The %s zip files have been stored on the specified FTP: %s", $this->pluginID), count($info['ftp']), $this->get_ftp_host()) . "</p>";
             $message .= "<ul>";
             foreach ($info['ftp'] as $fi) {
                 if (is_file($fi['file'])) {
                     if (!$fi['error']) {
                         $message .= "<li>";
                         $message .= sprintf(__("%s stored on %s", $this->pluginID), "<a href='" . $this->get_ftp_host() . "/" . basename($fi['file']) . "'>" . basename($fi['file']) . "</a>", date_i18n("F j, Y H:i:s", $fi['date']));
                         $message .= "</li>";
                     } else {
                         $message .= "<li>";
                         $message .= sprintf(__("ERROR: %s has not been stored. The error message was: %s", $this->pluginID), basename($fi['file']), "<code>" . $fi['error_msg'] . "</code>");
                         $message .= "</li>";
                     }
                 }
             }
             $message .= "</ul>";
         }
         $message .= "<p>" . __("Best regards,", $this->pluginID) . "</p><p>&nbsp;</p>";
         $headers = "MIME-Version: 1.0\n" . "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n";
         $subject = sprintf(__("Backup of %s on %s", $this->pluginID), get_bloginfo('name'), date_i18n('Y-m-d'));
         // send the email
         $res = wp_mail($this->get_param('ftp_mail'), $subject, $message, $headers);
         if (!$res) {
             SLFramework_Debug::log(get_class(), "An error occurred sending the mail to " . $this->get_param('ftp_mail'), 2);
         } else {
             SLFramework_Debug::log(get_class(), "The email has been successfully sent  to " . $this->get_param('ftp_mail'), 4);
         }
     }
 }
예제 #5
0
 /** ====================================================================================================================================================
  * Check if a folder or a file is writable
  * 
  * @param string $path the path to the folder or the file
  * @return boolean true if the folder or the file is writable
  */
 static function is_writable($path)
 {
     if ($path[strlen($path) - 1] == '/') {
         // recursively return a temporary file path
         return SLFramework_Utils::is_writable($path . uniqid(mt_rand()) . '.tmp');
     } else {
         if (is_dir($path)) {
             return SLFramework_Utils::is_writable($path . '/' . uniqid(mt_rand()) . '.tmp');
         }
     }
     // check tmp file for read/write capabilities
     $rm = file_exists($path);
     $f = @fopen($path, 'a');
     if ($f === false) {
         return false;
     }
     @fclose($f);
     if (!$rm) {
         @unlink($path);
     }
     return true;
 }
예제 #6
0
 /** ====================================================================================================================================================
  * In order to uninstall the plugin, few things are to be done ... 
  * (do not modify this function)
  * 
  * @return void
  */
 public static function uninstall_removedata()
 {
     global $wpdb;
     // DELETE OPTIONS
     delete_option('my_plugin' . '_options');
     if (is_multisite()) {
         delete_site_option('my_plugin' . '_options');
     }
     // DELETE SQL
     if (function_exists('is_multisite') && is_multisite()) {
         $old_blog = $wpdb->blogid;
         $old_prefix = $wpdb->prefix;
         // Get all blog ids
         $blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM " . $wpdb->blogs));
         foreach ($blogids as $blog_id) {
             switch_to_blog($blog_id);
             $wpdb->query("DROP TABLE " . str_replace($old_prefix, $wpdb->prefix, $wpdb->prefix . "pluginSL_" . 'my_plugin'));
         }
         switch_to_blog($old_blog);
     } else {
         $wpdb->query("DROP TABLE " . $wpdb->prefix . "pluginSL_" . 'my_plugin');
     }
     // DELETE FILES if needed
     //SLFramework_Utils::rm_rec(WP_CONTENT_DIR."/sedlex/my_plugin/");
     $plugins_all = get_plugins();
     $nb_SL = 0;
     foreach ($plugins_all as $url => $pa) {
         $info = pluginSedlex::get_plugins_data(WP_PLUGIN_DIR . "/" . $url);
         if ($info['Framework_Email'] == "*****@*****.**") {
             $nb_SL++;
         }
     }
     if ($nb_SL == 1) {
         SLFramework_Utils::rm_rec(WP_CONTENT_DIR . "/sedlex/");
     }
 }
예제 #7
0
 /** ====================================================================================================================================================
  * Create the archive and split it if necessary
  * 
  * @param string $splitfilename the path of the zip file to create
  * @param integer $chunk_size the maximum size of the archive
  * @param integer $maxExecutionTime the maximum execution time in second (if this time is exceeded, the function will return false. You just have to relaunch this function to complete the zip from where it has stopped)
  * @param integer $maxExecutionTime the maximum memory allocated by the process (in bytes)
  * @return array with the name of the file (or 'finished' => false if an error occured see 'error' for the error message)
  */
 function createZip($splitfilename, $chunk_size = 1000000000000000, $maxExecutionTime = 150, $maxAllocatedMemory = 4000000)
 {
     // Init variables
     //---------------------
     $zipfile_comment = "Compressed/Splitted by the SL framework (SedLex)";
     $path = str_replace(basename($splitfilename), "", $splitfilename);
     $pathToReturn = array();
     $disk_number = 1;
     $split_signature = "PK";
     // Optionnal
     $nbentry = 0;
     $nbfolder = 0;
     $data_segments = "";
     $files_not_included_due_to_filesize = array();
     $this->allocatedSize = 0;
     //  We check whether a process is running
     //----------------------------------------------
     if (is_file(dirname($splitfilename) . "/zip_in_progress")) {
         $timestart = @file_get_contents(dirname($splitfilename) . "/zip_in_progress");
         // We cannot read the lock file
         if ($timestart === FALSE) {
             if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                 SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress cannot be deleted", 2);
                 return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
             }
             SLFramework_Debug::log(get_class(), "The file " . dirname($splitfilename) . "/zip_in_progress cannot be deleted", 2);
             return array('finished' => false, "error" => sprintf(__('The file %s cannot be read. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . dirname($splitfilename) . "/zip_in_progress</code>"));
         }
         $timeprocess = time() - (int) $timestart;
         SLFramework_Debug::log(get_class(), "An other process is still running  for " . $timeprocess, 2);
         return array('finished' => false, 'error' => sprintf(__("An other process is still running (it runs for %s seconds)", "SL_framework"), $timeprocess));
     }
     //  We create a lock file
     //----------------------------------------------
     $r = @file_put_contents(dirname($splitfilename) . "/zip_in_progress", time());
     if ($r === FALSE) {
         SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress cannot be modified/created", 2);
         if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
             SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress cannot be deleted", 2);
             return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
         }
         return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . dirname($splitfilename) . "/zip_in_progress</code>"));
     } else {
         SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress has be created to ensure that a lock file exists", 5);
     }
     //  We retrieve old saved param
     //      if the .tmp file exists, it means that we have to restart the zip process where it stopped
     //----------------------------------------------
     if (is_file($splitfilename . ".tmp")) {
         // We retrieve the process
         $content = @file_get_contents($splitfilename . ".tmp");
         if ($content === FALSE) {
             SLFramework_Debug::log(get_class(), "The file " . $splitfilename . ".tmp cannot be read", 2);
             if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                 SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress cannot be deleted", 2);
                 return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
             }
             return array('finished' => false, "error" => sprintf(__('The file %s cannot be read. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $splitfilename . ".tmp</code>"));
         }
         list($nbentry, $nbfolder, $pathToReturn, $disk_number, $this->filelist, $files_not_included_due_to_filesize) = unserialize($content);
         SLFramework_Debug::log(get_class(), "Get the unserialized content of  " . $splitfilename . ".tmp", 4);
         //  We start a new process if nothing have yet started
         //----------------------------------------------
     } else {
         // We add the signature in the zip file
         $r = @file_put_contents($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), $split_signature);
         $pathToReturn[time() . " " . sprintf("%02d", $disk_number)] = $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number);
         if ($r === FALSE) {
             SLFramework_Debug::log(get_class(), "The signature of the zip file cannot be added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 2);
             if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                 SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress cannot be deleted", 2);
                 return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
             }
             return array('finished' => false, "error" => sprintf(__('The file %s cannot be created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number) . "</code>"));
         } else {
             SLFramework_Debug::log(get_class(), "The signature of the zip file has been added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 4);
         }
         // We create the list of folder
         SLFramework_Debug::log(get_class(), "Begin the list of folders", 4);
         foreach ($this->filelist as $k => $filename_array) {
             $add_t = $filename_array[2];
             $remove_t = $filename_array[1];
             $filename = $filename_array[0];
             $newfilename = str_replace("//", "/", $add_t . str_replace(str_replace("\\", "/", $remove_t), "", str_replace("\\", "/", $filename)));
             if (!is_file($filename)) {
                 continue;
             }
             $ch = explode("/", $newfilename);
             // We delete the last item because it is the filename of the file
             unset($ch[count($ch) - 1]);
             while (count($ch) > 0) {
                 $chemin = implode("/", $ch) . "/";
                 if (!isset($this->dirlist[md5($chemin)])) {
                     $this->dirlist[md5($chemin)] = $chemin;
                 }
                 unset($ch[count($ch) - 1]);
             }
         }
         usort($this->dirlist, array($this, 'sort_by_length_dir'));
         usort($this->filelist, array($this, 'sort_by_length_file'));
         // We add the folder
         foreach ($this->dirlist as $dir) {
             $relative_offset_in_disk = 0;
             if (is_file($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number))) {
                 clearstatcache();
                 $relative_offset_in_disk = @filesize($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number));
             }
             $dir = SLFramework_Utils::convertUTF8($dir);
             $local_file_header = "PK";
             // 4 bytes  (0x04034b50) local_file_header_signature
             $local_file_header .= "";
             // 2 bytes version_needed_to_extract
             $local_file_header .= "";
             // 2 bytes general_purpose_bit_flag (we say that the name should be encode in UTF8)
             $local_file_header .= pack('v', 0);
             // 2 bytes compression_method
             $local_file_header .= pack('v', 0);
             // 2 bytes last mod file time
             $local_file_header .= pack('v', 0);
             // 2 bytes last mod file time
             $local_file_header .= pack('V', 0);
             // 4 bytes crc_32
             $local_file_header .= pack('V', 0);
             // 4 bytes compressed_size
             $local_file_header .= pack('V', 0);
             // 4 bytes uncompressed_size
             $local_file_header .= pack('v', strlen($dir));
             // 2 bytes filename_length
             $local_file_header .= pack('v', 0);
             // 2 bytes extra_field_length
             $local_file_header .= $dir;
             // variable size filename
             $local_file_header .= "";
             // variable size extra fields
             $r = @file_put_contents($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), $local_file_header, FILE_APPEND);
             if ($r === FALSE) {
                 SLFramework_Debug::log(get_class(), "The folder " . $dir . " can not be added to zip file " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 2);
                 if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                     SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress cannot be deleted", 2);
                     return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
                 }
                 return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number) . "</code>"));
             } else {
                 SLFramework_Debug::log(get_class(), "The folder " . $dir . " has been added to zip file " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 5);
             }
             //Set central File Header
             $central_file_header = "PK";
             // 4 bytes (0x02014b50) central file header signature
             $central_file_header .= "";
             // 2 bytes version made by (0 = MS-DOS and OS/2 compatible)
             $central_file_header .= "";
             // 2 bytes version needed to extract
             $central_file_header .= "";
             // 2 bytes general_purpose_bit_flag (we say that the name should be encode in UTF8)
             $central_file_header .= pack('v', 0);
             // 2 bytes compression_method
             $central_file_header .= pack('v', 0);
             // 2 bytes last mod file time
             $central_file_header .= pack('v', 0);
             // 2 bytes last mod file time
             $central_file_header .= pack('V', 0);
             // 4 bytes crc_32
             $central_file_header .= pack('V', 0);
             // 4 bytes compressed_size
             $central_file_header .= pack('V', 0);
             // 4 bytes uncompressed_size
             $central_file_header .= pack('v', strlen($dir));
             // 2 bytes filename_length
             $central_file_header .= pack('v', 0);
             // 2 bytes extra_field_length
             $central_file_header .= pack('v', 0);
             // 2 bytes  comment length
             $central_file_header .= pack('v', $disk_number - 1);
             // 2 bytes disk number start
             $central_file_header .= pack('v', 0);
             // 2 bytes internal file attribute
             $central_file_header .= pack('V', 16);
             // 4 bytes external file attribute
             $central_file_header .= pack('V', $relative_offset_in_disk);
             // 4 bytes relative offset of local header
             $central_file_header .= $dir;
             // variable size filename
             $central_file_header .= "";
             // variable size extra fields
             $central_file_header .= "";
             // variable size file comment
             $nbfolder++;
             $r = @file_put_contents($splitfilename . ".centraldirectory.tmp", $central_file_header, FILE_APPEND);
             if ($r === FALSE) {
                 SLFramework_Debug::log(get_class(), "The folder " . $dir . " cannot be added to central header file " . $splitfilename . ".centraldirectory.tmp", 2);
                 if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                     SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress cannot be deleted", 2);
                     return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
                 }
                 return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $splitfilename . ".centraldirectory.tmp</code>"));
             } else {
                 SLFramework_Debug::log(get_class(), "The folder " . $dir . " has been added to central header file " . $splitfilename . ".centraldirectory.tmp", 5);
             }
         }
         SLFramework_Debug::log(get_class(), "End the list of  folders", 4);
     }
     //  The creation of the zip begin
     //----------------------------------------------
     SLFramework_Debug::log(get_class(), "Begin the loop for " . count($this->filelist) . " files", 4);
     foreach ($this->filelist as $k => $filename_array) {
         $add_t = $filename_array[2];
         $remove_t = $filename_array[1];
         $filename = $filename_array[0];
         //  If the time limit exceed, we save into temp files
         //----------------------------------------------
         $nowtime = microtime(true);
         if ($maxExecutionTime != 0) {
             if ($nowtime - $this->starttime > $maxExecutionTime) {
                 // We remove the files already inserted in the zip
                 $this->filelist = array_slice($this->filelist, $k);
                 // We save the content on the disk
                 $r = @file_put_contents($splitfilename . ".tmp", serialize(array($nbentry, $nbfolder, $pathToReturn, $disk_number, $this->filelist, $files_not_included_due_to_filesize)));
                 if ($r === FALSE) {
                     SLFramework_Debug::log(get_class(), "The serialized information cannot be written in " . $splitfilename . ".tmp", 2);
                     if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                         SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress cannot be deleted", 2);
                         return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
                     }
                     return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $splitfilename . ".tmp</code>"));
                 } else {
                     SLFramework_Debug::log(get_class(), "The serialized information has been written successfully in " . $splitfilename . ".tmp", 4);
                 }
                 // we inform that the process is finished
                 if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                     SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress cannot be deleted", 2);
                     return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
                 }
                 SLFramework_Debug::log(get_class(), "The Zip process is delayed due to time execution limitation (" . $nbentry . "/" . (count($this->filelist) + $nbentry) . " files)", 4);
                 return array('finished' => false, 'nb_to_finished' => count($this->filelist), 'nb_finished' => $nbentry, 'not_included' => $files_not_included_due_to_filesize);
             }
         }
         //  If the memory limit exceed, we save into temp files
         //----------------------------------------------
         if ($maxAllocatedMemory != 0) {
             if ($this->allocatedSize > 2 * $maxAllocatedMemory) {
                 // We remove the files already inserted in the zip
                 $this->filelist = array_slice($this->filelist, $k);
                 // We save the content on the disk
                 $r = @file_put_contents($splitfilename . ".tmp", serialize(array($nbentry, $nbfolder, $pathToReturn, $disk_number, $this->filelist, $files_not_included_due_to_filesize)));
                 if ($r === FALSE) {
                     SLFramework_Debug::log(get_class(), "The serialized information cannot be written in " . $splitfilename . ".tmp", 2);
                     if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                         SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress cannot be deleted", 2);
                         return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
                     }
                     return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $splitfilename . ".tmp</code>"));
                 } else {
                     SLFramework_Debug::log(get_class(), "The serialized information has been written successfully in " . $splitfilename . ".tmp", 4);
                 }
                 // we inform that the process is finished
                 if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                     SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress cannot be deleted", 2);
                     return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
                 }
                 SLFramework_Debug::log(get_class(), "The Zip process is delayed due to memory allocation limitation (" . $nbentry . "/" . (count($this->filelist) + $nbentry) . " files)", 4);
                 return array('finished' => false, 'nb_to_finished' => count($this->filelist), 'nb_finished' => $nbentry, 'not_included' => $files_not_included_due_to_filesize);
             }
         }
         //  Check if the file to be inserted in the zip file still exists
         //----------------------------------------------
         if (!is_file($filename)) {
             SLFramework_Debug::log(get_class(), "The file " . $filename . " does not exists and is ignored", 3);
             continue;
         }
         // Check the length of the file
         clearstatcache();
         if (@filesize($filename) > $maxAllocatedMemory) {
             SLFramework_Debug::log(get_class(), "The file " . $filename . " is too big (i.e. " . @filesize($filename) . ") and is then ignored", 3);
             $files_not_included_due_to_filesize[] = $filename;
             continue;
         } else {
             $this->allocatedSize += @filesize($filename);
         }
         //  Compress
         //----------------------------------------------
         $nbentry++;
         //Get the data
         $filedata = @file_get_contents($filename);
         if ($filedata === FALSE) {
             SLFramework_Debug::log(get_class(), "The file " . $filename . " can not be read", 2);
             if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                 SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
                 return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
             }
             return array('finished' => false, "error" => sprintf(__('The file %s cannot be read. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $filename . "</code>"));
         } else {
             SLFramework_Debug::log(get_class(), "The content of the file " . $filename . " has been read", 5);
         }
         //Compressing data
         $c_data = @gzcompress($filedata);
         if ($c_data === FALSE) {
             SLFramework_Debug::log(get_class(), "The content of the file " . $filename . " can not be compressed", 2);
             if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                 SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
                 return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
             }
             return array('finished' => false, "error" => sprintf(__('The file %s cannot be compressed.', 'SL_framework'), "<code>" . $filename . "</code>"));
         } else {
             SLFramework_Debug::log(get_class(), "The content of the file " . $filename . " has been compressed", 5);
         }
         $compressed_filedata = substr(substr($c_data, 0, strlen($c_data) - 4), 2);
         // fix crc bug
         // Get the time
         clearstatcache();
         $filetime = @filectime($filename);
         if ($filetime == 0) {
             $timearray = getdate();
         } else {
             $timearray = getdate($filetime);
         }
         if ($timearray['year'] < 1980) {
             $timearray['year'] = 1980;
             $timearray['mon'] = 1;
             $timearray['mday'] = 1;
             $timearray['hours'] = 0;
             $timearray['minutes'] = 0;
             $timearray['seconds'] = 0;
         }
         $dostime = $timearray['year'] - 1980 << 25 | $timearray['mon'] << 21 | $timearray['mday'] << 16 | $timearray['hours'] << 11 | $timearray['minutes'] << 5 | $timearray['seconds'] >> 1;
         $dtime = dechex($dostime);
         $hexdtime = '\\x' . $dtime[6] . $dtime[7] . '\\x' . $dtime[4] . $dtime[5];
         $hexddate = '\\x' . $dtime[2] . $dtime[3] . '\\x' . $dtime[0] . $dtime[1];
         eval('$hexdtime = "' . $hexdtime . '";');
         eval('$hexddate = "' . $hexddate . '";');
         $last_mod_file_time = $hexdtime;
         $last_mod_file_date = $hexddate;
         //Set Local File Header
         $newfilename = str_replace("//", "/", $add_t . str_replace(str_replace("\\", "/", $remove_t), "", str_replace("\\", "/", $filename)));
         if (substr($newfilename, 0, 1) == "/") {
             $newfilename = substr($newfilename, 1);
         }
         /*
          A.  Local file header:
         	local file header signature     4 bytes  (0x04034b50)
         	version needed to extract       2 bytes
         	general purpose bit flag        2 bytes
         	compression method              2 bytes
         	last mod file time              2 bytes
         	last mod file date              2 bytes
         	crc-32                          4 bytes
         	compressed size                 4 bytes
         	uncompressed size               4 bytes
         	file name length                2 bytes
         	extra field length              2 bytes
         	file name 						(variable size)
         	extra field 					(variable size)
         */
         $newfilename = SLFramework_Utils::convertUTF8($newfilename);
         $local_file_header = "PK";
         // 4 bytes  (0x04034b50) local_file_header_signature
         $local_file_header .= "";
         // 2 bytes version_needed_to_extract
         $local_file_header .= "";
         // 2 bytes general_purpose_bit_flag (we say that the name should be encode in UTF8)
         $local_file_header .= "";
         // 2 bytes compression_method
         $local_file_header .= $last_mod_file_time;
         // 2 bytes last mod file time
         $local_file_header .= $last_mod_file_date;
         // 2 bytes last mod file time
         $local_file_header .= pack('V', crc32($filedata));
         // 4 bytes crc_32
         $local_file_header .= pack('V', strlen($compressed_filedata));
         // 4 bytes compressed_size
         $local_file_header .= pack('V', strlen($filedata));
         // 4 bytes uncompressed_size
         $local_file_header .= pack('v', strlen($newfilename));
         // 2 bytes filename_length
         $local_file_header .= pack('v', 0);
         // 2 bytes extra_field_length
         $local_file_header .= $newfilename;
         // variable size filename
         $local_file_header .= "";
         // variable size extra fields
         // We add the local header in the zip files
         clearstatcache();
         if (strlen($local_file_header) + @filesize($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number)) <= $chunk_size) {
             // We get the index of the file
             $relative_offset_in_disk = @filesize($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number));
             $r = @file_put_contents($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), $local_file_header, FILE_APPEND);
             if ($r === FALSE) {
                 SLFramework_Debug::log(get_class(), "The local file header of the file cannot be been added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 2);
                 if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                     SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
                     return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
                 }
                 return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number) . "</code>"));
             } else {
                 SLFramework_Debug::log(get_class(), "The local file header of the file has been added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 5);
             }
             // If the local header will be split, we create a new disk
         } else {
             $disk_number++;
             // We get the index of the file
             $relative_offset_in_disk = 0;
             $pathToReturn[time() . " " . sprintf("%02d", $disk_number)] = $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number);
             $r = @file_put_contents($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), $local_file_header);
             if ($r === FALSE) {
                 SLFramework_Debug::log(get_class(), "The local file header of the file cannot be been added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 2);
                 if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                     SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
                     return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
                 }
                 return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number) . "</code>"));
             } else {
                 SLFramework_Debug::log(get_class(), "The local file header of the file has been been added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 5);
             }
         }
         $disk_number_of_local_header = $disk_number;
         /* 
          B.  File data
         	  Immediately following the local header for a file
         	  is the compressed or stored data for the file. 
         	  The series of [local file header][file data]
         	  repeats for each file in the .ZIP archive. 
         */
         // We add the compressed file in the zip files
         clearstatcache();
         if (strlen($compressed_filedata) + @filesize($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number)) <= $chunk_size) {
             $r = @file_put_contents($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), $compressed_filedata, FILE_APPEND);
             if ($r === FALSE) {
                 SLFramework_Debug::log(get_class(), "The compressed content of the file cannot be been added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 2);
                 if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                     SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
                     return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
                 }
                 return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number) . "</code>"));
             } else {
                 SLFramework_Debug::log(get_class(), "The compressed content of the file has been been added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 5);
             }
             // If the compressed file will be split, we create a new disk
         } else {
             clearstatcache();
             $part1 = substr($compressed_filedata, 0, $chunk_size - @filesize($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number)));
             $part2 = substr($compressed_filedata, $chunk_size - @filesize($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number)));
             $r = @file_put_contents($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), $part1, FILE_APPEND);
             if ($r === FALSE) {
                 SLFramework_Debug::log(get_class(), "The first part of the compressed content of the file cannot be added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 2);
                 if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                     SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
                     return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
                 }
                 return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number) . "</code>"));
             } else {
                 SLFramework_Debug::log(get_class(), "The first part of the compressed content of the file has been added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 5);
             }
             $disk_number++;
             $pathToReturn[time() . " " . sprintf("%02d", $disk_number)] = $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number);
             $r = @file_put_contents($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), $part2);
             if ($r === FALSE) {
                 SLFramework_Debug::log(get_class(), "The second part of the compressed content of the file cannot be added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 2);
                 if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                     SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
                     return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
                 }
                 return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number) . "</code>"));
             } else {
                 SLFramework_Debug::log(get_class(), "The second part of the compressed content of the file has been added to " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 5);
             }
         }
         /*
         				  F.  Central directory structure:
         					  [file header 1]
         					  ...
         					  [file header n]
         				
         					 File header:
         						central file header signature   4 bytes  (0x02014b50)
         						version made by                 2 bytes
         						version needed to extract       2 bytes
         						general purpose bit flag        2 bytes
         						compression method              2 bytes
         						last mod file time              2 bytes
         						last mod file date              2 bytes
         						crc-32                          4 bytes
         						compressed size                 4 bytes
         						uncompressed size               4 bytes
         						file name length                2 bytes
         						extra field length              2 bytes
         						file comment length             2 bytes
         						disk number start               2 bytes
         						internal file attributes        2 bytes
         						external file attributes        4 bytes
         						relative offset of local header 4 bytes
         						file name 						(variable size)
         						extra field 					(variable size)
         						file comment 					(variable size)
         */
         //Set central File Header
         $central_file_header = "PK";
         // 4 bytes (0x02014b50) central file header signature
         $central_file_header .= "";
         // 2 bytes version made by (0 = MS-DOS and OS/2 compatible)
         $central_file_header .= "";
         // 2 bytes version needed to extract
         $central_file_header .= "";
         // 2 bytes general_purpose_bit_flag (we say that the name should be encode in UTF8)
         $central_file_header .= "";
         // 2 bytes compression_method
         $central_file_header .= $last_mod_file_time;
         // 2 bytes last mod file time
         $central_file_header .= $last_mod_file_date;
         // 2 bytes last mod file time
         $central_file_header .= pack('V', crc32($filedata));
         // 4 bytes crc_32
         $central_file_header .= pack('V', strlen($compressed_filedata));
         // 4 bytes compressed_size
         $central_file_header .= pack('V', strlen($filedata));
         // 4 bytes uncompressed_size
         $central_file_header .= pack('v', strlen($newfilename));
         // 2 bytes filename_length
         $central_file_header .= pack('v', 0);
         // 2 bytes extra_field_length
         $central_file_header .= pack('v', 0);
         // 2 bytes  comment length
         $central_file_header .= pack('v', $disk_number_of_local_header - 1);
         // 2 bytes disk number start
         $central_file_header .= pack('v', 0);
         // 2 bytes internal file attribute
         $central_file_header .= pack('V', 32);
         // 4 bytes external file attribute
         $central_file_header .= pack('V', $relative_offset_in_disk);
         // 4 bytes relative offset of local header
         $central_file_header .= $newfilename;
         // variable size filename
         $central_file_header .= "";
         // variable size extra fields
         $central_file_header .= "";
         // variable size file comment
         $r = @file_put_contents($splitfilename . ".centraldirectory.tmp", $central_file_header, FILE_APPEND);
         if ($r === FALSE) {
             SLFramework_Debug::log(get_class(), "The central header cannot been added to " . $splitfilename . ".centraldirectory.tmp", 2);
             if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
                 SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
                 return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
             }
             return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $splitfilename . ".centraldirectory.tmp</code>"));
         } else {
             SLFramework_Debug::log(get_class(), "The central header  has been added to " . $splitfilename . ".centraldirectory.tmp", 5);
         }
     }
     //  Finalization
     //----------------------------------------------
     /*
      I.  End of central directory record:
     	end of central dir signature    												4 bytes  (0x06054b50)
     	number of this disk            		 											2 bytes
     	number of the disk with the start of the central directory  					2 bytes
     	total number of entries in the central directory on this disk  					2 bytes
     	total number of entries in the central directory           						2 bytes
     	size of the central directory  					 								4 bytes
     	offset of start of central directory with respect to the starting disk number   4 bytes
     	.ZIP file comment length        												2 bytes
     	.ZIP file comment       														(variable size)
     */
     // We finalize
     clearstatcache();
     $end_central_dir_record = "PK";
     // 4 bytes  (0x06054b50)
     $end_central_dir_record .= pack('v', $disk_number - 1);
     // 2 bytes number of this disk
     $end_central_dir_record .= pack('v', $disk_number - 1);
     // 2 bytes number of the disk with the start of the central directory
     $end_central_dir_record .= pack('v', $nbentry + $nbfolder);
     // 2 bytes total number of entries in the central directory on this disk
     $end_central_dir_record .= pack('v', $nbentry + $nbfolder);
     // 2 bytes total number of entries in the central directory
     $end_central_dir_record .= pack('V', @filesize($splitfilename . ".centraldirectory.tmp"));
     // 4 bytes size of the central directory
     $end_central_dir_record .= pack('V', @filesize($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number)));
     // 4 bytes offset of start of central directory with respect to the starting disk number
     $end_central_dir_record .= pack('v', strlen($zipfile_comment));
     // 2 bytes .ZIP file comment length
     $end_central_dir_record .= $zipfile_comment;
     // variable size .ZIP file comment
     // We complete the data segments file
     $r = @file_put_contents($splitfilename . ".centraldirectory.tmp", $end_central_dir_record, FILE_APPEND);
     if ($r === FALSE) {
         SLFramework_Debug::log(get_class(), "The end of the central header cannot been added to " . $splitfilename . ".centraldirectory.tmp", 2);
         if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
             SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
             return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
         }
         return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $splitfilename . ".centraldirectory.tmp" . "</code>"));
     } else {
         SLFramework_Debug::log(get_class(), "The end of the central header has been added to " . $splitfilename . ".centraldirectory.tmp", 4);
     }
     // We copy the content of the central directory into the last file
     // TODO boucler sur des petits morceaux pour eviter une saturation mémoire
     // TODO ne pas depasser la taille max (sans pour autant couper une entrée)
     $r = @file_put_contents($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), @file_get_contents($splitfilename . ".centraldirectory.tmp"), FILE_APPEND);
     if ($r === FALSE) {
         SLFramework_Debug::log(get_class(), "The content of the file " . $splitfilename . ".centraldirectory.tmp cannot be copied into " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 2);
         if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
             SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
             return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
         }
         return array('finished' => false, "error" => sprintf(__('The file %s cannot be modified/created. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $splitfilename . ".centraldirectory.tmp</code>"));
     } else {
         SLFramework_Debug::log(get_class(), "The content of the file " . $splitfilename . ".centraldirectory.tmp has been copied into " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), 4);
     }
     // rename the last file
     $r = @rename($path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number), $splitfilename);
     if ($r === FALSE) {
         SLFramework_Debug::log(get_class(), "The file " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number) . " cannot be renamed into " . $splitfilename, 2);
         if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
             SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
             return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
         }
         return array('finished' => false, "error" => sprintf(__('The file %s cannot be renamed. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number) . "</code>"));
     } else {
         SLFramework_Debug::log(get_class(), "The file " . $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number) . " has been renamed into " . $splitfilename, 4);
     }
     $pathToReturn[time() . " " . sprintf("%02d", $disk_number)] = $splitfilename;
     $newpathToReturn = array();
     // Remove from the above list the last file (because it has just been renamed)
     foreach ($pathToReturn as $k => $f) {
         if ($f != $path . basename($splitfilename, ".zip") . ".z" . sprintf("%02d", $disk_number)) {
             $newpathToReturn[$k] = $f;
         }
     }
     $pathToReturn = $newpathToReturn;
     // delete the  temp file
     if (!SLFramework_Utils::rm_rec($splitfilename . ".centraldirectory.tmp")) {
         SLFramework_Debug::log(get_class(), "The file " . $splitfilename . ".centraldirectory.tmp cannot be deleted", 2);
         if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
             SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
             return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
         }
         return array('finished' => false, "error" => sprintf(__('The file %s cannot be renamed. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $splitfilename . ".centraldirectory.tmp" . "</code>"));
     } else {
         SLFramework_Debug::log(get_class(), "The file " . $splitfilename . ".centraldirectory.tmp has been deleted", 4);
     }
     if (!SLFramework_Utils::rm_rec($splitfilename . ".tmp")) {
         SLFramework_Debug::log(get_class(), "The file " . $splitfilename . ".tmp cannot be deleted", 2);
         if (!SLFramework_Utils::rm_rec($path . "/zip_in_progress")) {
             SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
             return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $path . "/zip_in_progress</code>"));
         }
         return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . $splitfilename . ".tmp</code>"));
     } else {
         SLFramework_Debug::log(get_class(), "The file " . $splitfilename . ".tmp has been deleted", 4);
     }
     // we inform that the process is finished
     if (!SLFramework_Utils::rm_rec(dirname($splitfilename) . "/zip_in_progress")) {
         SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress can not be deleted", 2);
         return array("step" => "error", "error" => sprintf(__('The file %s cannot be deleted. You should have a problem with file permissions or security restrictions.', 'SL_framework'), "<code>" . dirname($splitfilename) . "/zip_in_progress</code>"));
     } else {
         SLFramework_Debug::log(get_class(), "The file " . $path . "/zip_in_progress has been deleted", 2);
     }
     SLFramework_Debug::log(get_class(), "The ZIP process has ended by compressing " . $nbentry . " files and ignoring " . count($files_not_included_due_to_filesize) . " files due to filesize limitations", 4);
     return array('finished' => true, 'nb_finished' => $nbentry, 'nb_to_finished' => 0, 'not_included' => $files_not_included_due_to_filesize, 'nb_files' => $nbentry, 'path' => $pathToReturn);
 }
예제 #8
0
 /** ====================================================================================================================================================
  * To add an external link in the 
  * 
  * @return the short_url
  */
 function add_external_link($link, $comment)
 {
     global $wpdb;
     $table_name = $this->table_name;
     // We add the shortlink
     $car_minus = $this->get_param('low_char');
     $car_maxus = $this->get_param('upp_char');
     $car_nombr = $this->get_param('num_char');
     $car_longu = $this->get_param('length');
     $temp_url = "";
     $url_ext = addslashes(str_replace("'", "", $link));
     $comment = addslashes(str_replace("'", "", $comment));
     $char = ($car_maxus ? "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "") . ($car_minus ? "abcdefghijklmnopqrstuvwxyz" : "") . ($car_nombr ? "1234567890" : "");
     $ok = false;
     // Search for existing short link
     $short = $wpdb->get_var("SELECT short_url FROM {$table_name} WHERE id_post=0 AND url_externe='" . $url_ext . "'");
     if ($short != "") {
         return $short;
     } else {
         while (!$ok) {
             $result = $this->get_param('prefix') . SLFramework_Utils::rand_str($car_longu, $char);
             $select = "SELECT id_post FROM {$table_name} WHERE short_url='" . $result . "'";
             $temp_id = $wpdb->get_var($select);
             if ($temp_id == null || $temp_id === false || !is_numeric($temp_id)) {
                 $ok = true;
                 $sql = "DELETE FROM {$table_name} WHERE url_externe='" . $url_ext . "'";
                 $wpdb->query($sql);
                 $sql = "INSERT INTO {$table_name} (id_post, short_url, url_externe, comment) VALUES ('0', '" . $result . "', '" . $url_ext . "', '" . $comment . "')";
                 $wpdb->query($sql);
                 return $result;
             }
         }
     }
 }