/** ==================================================================================================================================================== * 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&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'); ?> " /> <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; }
/** ==================================================================================================================================================== * Callback function for modifying a translation * * @access private * @return void */ static function translate_modify() { ob_start(); require 'translation.inc.php'; // We sanitize the language $lang = preg_replace("/[^a-zA-Z_]/", "", $_POST['lang']); $domain = preg_replace("/[^a-zA-Z0-9_-]/", "", $_POST['domain']); $plugin = preg_replace("/[^a-zA-Z0-9_-]/", "", $_POST['plugin']); $actionOnClose = preg_replace("/[^a-zA-Z0-9_-]/", "", $_POST['actionOnClose']); $native = $code_locales[$lang]['lang-native']; $isFramework = $_POST['isFramework']; $plugin_lien = $plugin; echo "<h3>" . sprintf(__('Modifying the translation for this language: %s', 'SL_framework'), "{$native} ({$lang})") . "</h3>"; // Create the table $table = new SLFramework_Table(); $table->title(array(__('Sentence to translate', 'SL_framework'), __('Translation', 'SL_framework'))); $table->removeFooter(); if ($isFramework != 'false') { $content_pot = file(WP_PLUGIN_DIR . "/" . $isFramework . "/core/lang/SL_framework.pot"); $content_po = file(WP_PLUGIN_DIR . "/" . $isFramework . "/core/lang/SL_framework-" . $lang . ".po"); } else { $content_pot = file(WP_PLUGIN_DIR . "/" . $plugin . "/lang/" . $domain . ".pot"); $content_po = file(WP_PLUGIN_DIR . "/" . $plugin . "/lang/" . $domain . "-" . $lang . ".po"); } $i = 0; // We build an array with all the sentences for pot $pot_array = array(); foreach ($content_pot as $ligne_pot) { if (preg_match("/^msgid \\\"(.*)\\\"\$/", trim($ligne_pot), $match)) { $pot_array[sha1(trim($match[1]))] = trim($match[1]); } } // We build an array with all the sentences for po $po_array = array(); $msgid = ""; foreach ($content_po as $ligne_po) { if (preg_match("/^msgid \\\"(.*)\\\"\$/", trim($ligne_po), $match)) { $msgid = $match[1]; } else { if (preg_match("/^msgstr \\\"(.*)\\\"\$/", trim($ligne_po), $match)) { if (trim($match[1]) != "") { $po_array[sha1(trim($msgid))] = array(trim($msgid), trim($match[1])); } } } } $i = 0; // We display text translation foreach ($pot_array as $md5 => $ligne) { if (!isset($po_array[$md5])) { $cel1 = new adminCell("<p>" . ($i + 1) . ") <b style='color:#000099'>" . htmlentities($ligne) . "</b></p>"); // We search for the levenstein match between the pot and the po file $close = ""; foreach ($po_array as $ligne_po) { //if ($ligne!=$ligne_po[0]) { $cl = levenshtein($ligne, $ligne_po[0]); if ($cl / strlen($ligne) * 100 < 10) { if ($close == "") { $close .= $ligne_po[1]; } else { $close .= " / " . $ligne_po[1]; } } //} } if ($close == "") { $cel2 = new adminCell("<input id='trad" . $i . "' type='text' name='trad" . $i . "' value='' style='width:100%' />"); } else { $cel2 = new adminCell("<input id='trad" . $i . "' type='text' name='trad" . $i . "' value='' style='width:100%' /><br/><p style='color:#BBBBBB'>" . $close . "</p>"); } $table->add_line(array($cel1, $cel2), '1'); $i++; } else { list($text, $value) = $po_array[$md5]; // Convert the value in UTF8 if needed if (!seems_utf8($value)) { $value = utf8_encode($value); } // Count %s $count1 = substr_count($text, "%s"); $count2 = substr_count($value, "%s"); if ($count1 == $count2 || trim($value) == "") { $cel1 = new adminCell("<p>" . ($i + 1) . ") <i>" . htmlentities($ligne) . "</i></p>"); } else { $cel1 = new adminCell("<p>" . ($i + 1) . ") <i>" . htmlentities($ligne) . "</i></p><p style='color:#AA0000'><b>" . __('The number of occurrence of %s does not match in both string. Please note that the string %s will be replaced with a contextual string.', 'SL_framework') . "</b></p>"); } $cel2 = new adminCell("<input id='trad" . $i . "' type='text' name='trad" . $i . "' value='" . $value . "' style='width:100%' />"); $table->add_line(array($cel1, $cel2), '1'); $i++; } } echo $table->flush(); $options = get_option('SL_framework_options'); echo "<p>" . __('Your name:', 'SL_framework') . " <input id='nameAuthor' type='text' name='nameAuthor' value='" . $options['nameTranslator'] . "'/></p>"; echo "<p>" . __('Your email or your website:', 'SL_framework') . " <input id='emailAuthor' type='text' name='emailAuthor' value='" . $options['emailTranslator'] . "'/></p>"; if ($actionOnClose == "") { echo "<input type='submit' name='create' class='button-primary validButton' onclick='translate_save_after_modification(\"" . $plugin_lien . "\",\"" . $domain . "\",\"" . $isFramework . "\",\"" . $lang . "\", {$i});return false;' value='" . __('Modify the translation files', 'SL_framework') . "' />"; } else { echo "<input type='submit' name='create' class='button-primary validButton' onclick='" . $actionOnClose . "(\"" . $plugin_lien . "\",\"" . $domain . "\",\"" . $isFramework . "\",\"" . $lang . "\", {$i});return false;' value='" . __('Modify the translation files', 'SL_framework') . "' />"; } $x = plugin_dir_url("/") . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)); echo "<img id='wait_translation_modify' src='" . $x . "/img/ajax-loader.gif' style='display:none;'>"; $content = ob_get_clean(); $popup = new SLFramework_Popup(__("Modify translations", 'SL_framework'), $content); echo $popup->render(); //Die in order to avoid the 0 character to be printed at the end die; }