Exemplo n.º 1
0
 public function __construct($resource_or_fields, $missing_tokens = null, $data_locale = null, $verbose = null, $objective_field = null, $objective_field_present = null, $include = null)
 {
     # The constructor can be instantiated with resources or a fields
     # structure. The structure is checked and fields structure is returned
     # if a resource type is matched.
     $DEFAULT_MISSING_TOKENS = array("", "N/A", "n/a", "NULL", "null", "-", "#DIV/0", "#REF!", "#NAME?", "NIL", "nil", "NA", "na", "#VALUE!", "#NULL!", "NaN", "#N/A", "#NUM!", "?");
     try {
         $resource_info = get_fields_structure($resource_or_fields);
         $this->fields = $resource_info[0];
         $resource_locale = $resource_info[1];
         $resource_missing_tokens = $resource_info[2];
         if (is_null($data_locale)) {
             $data_locale = $resource_locale;
         }
         if (is_null($missing_tokens)) {
             if (!is_null(${$resource_missing_tokens})) {
                 $missing_tokens = $resource_missing_tokens;
             }
         }
     } catch (Exception $e) {
         $this->fields = $resource_or_fields;
         if (is_null($data_locale)) {
             $data_locale = "en_utf8";
         }
         if (is_null($missing_tokens)) {
             $missing_tokens = $DEFAULT_MISSING_TOKENS;
         }
     }
     if (is_null($this->fields)) {
         error_log("No fields structure was found.");
         return;
     }
     $this->fields_by_name = invert_dictionary($this->fields, 'name');
     $this->fields_by_column_number = invert_dictionary($this->fields, 'column_number');
     find_locale($data_locale, $verbose);
     $this->missing_tokens = $missing_tokens;
     $this->fields_columns = array();
     foreach ($this->fields_by_column_number as $value) {
         array_push($this->fields_columns, $value);
     }
     sort($this->fields_columns);
     $this->filtered_fields = array();
     # Ids of the fields to be included
     if (is_null($include)) {
         foreach ($this->fields as $key => $value) {
             array_push($this->filtered_fields, $key);
         }
     } else {
         $this->filtered_fields = $include;
     }
     # To be updated in update_objective_field
     $this->row_ids = null;
     $this->headers = null;
     $this->objective_field = null;
     $this->objective_field_present = null;
     $this->filtered_indexes = null;
 }
Exemplo n.º 2
0
function zip_up_lang($language)
{
    global $tp;
    $ret = array();
    $ret['file'] = "";
    if ($_SESSION['lancheck'][$language]['total'] > 0 && !E107_DEBUG_LEVEL) {
        $ret = array();
        $ret['error'] = TRUE;
        $message = defined('LANG_LAN_34') ? LANG_LAN_34 : LANG_LAN_115;
        $ret['message'] = str_replace("[x]", $_SESSION['lancheck'][$language]['total'], $message);
        return $ret;
    }
    if (!isset($_SESSION['lancheck'][$language])) {
        $ret = array();
        $ret['error'] = TRUE;
        $ret['message'] = defined('LANG_LAN_27') ? LANG_LAN_27 : LANG_LAN_116;
        return $ret;
    }
    if (varset($_POST['contribute_pack']) && varset($_SESSION['lancheck'][$language]['total']) != '0') {
        $ret['error'] = TRUE;
        $ret['message'] = defined("LANG_LAN_29") ? LANG_LAN_29 : LANG_LAN_117;
        $ret['message'] .= "<br />";
        $ret['message'] .= defined('LANG_LAN_27') ? LANG_LAN_27 : LANG_LAN_116;
        return $ret;
    }
    if (!is_writable(e_FILE . "public")) {
        $ret['error'] = TRUE;
        $ret['message'] = LAN_UPLOAD_777 . " " . e_FILE . "public";
        return $ret;
    }
    if (is_readable(e_ADMIN . "ver.php")) {
        include e_ADMIN . "ver.php";
    }
    $core_plugins = array("alt_auth", "banner", "blogcalendar_menu", "calendar_menu", "chatbox_menu", "clock_menu", "comment_menu", "download", "faqs", "featurebox", "forum", "gallery", "gsitemap", "import", "links_page", "linkwords", "list_new", "log", "login_menu", "newforumposts_main", "newsfeed", "news", "newsletter", "online", "page", "pm", "poll", "rss_menu", "search_menu", "siteinfo", "tagwords", "tinymce", "trackback", "tree_menu", "user_menu");
    $core_themes = array("bootstrap");
    require_once e_HANDLER . 'pclzip.lib.php';
    list($ver, $tmp) = explode(" ", $e107info['e107_version']);
    if (!($locale = find_locale($language))) {
        $ret['error'] = TRUE;
        $file = "e107_languages/{$language}/{$language}.php";
        $def = defined('LANG_LAN_25') ? LANG_LAN_25 : LANG_LAN_119;
        $ret['message'] = str_replace("[x]", $file, $def);
        //
        return $ret;
    }
    global $THEMES_DIRECTORY, $PLUGINS_DIRECTORY, $LANGUAGES_DIRECTORY, $HANDLERS_DIRECTORY, $HELP_DIRECTORY;
    if ($HANDLERS_DIRECTORY != "e107_handlers/" || $LANGUAGES_DIRECTORY != "e107_languages/" || $THEMES_DIRECTORY != "e107_themes/" || $HELP_DIRECTORY != "e107_docs/help/" || $PLUGINS_DIRECTORY != "e107_plugins/") {
        $ret['error'] = TRUE;
        $ret['message'] = defined('LANG_LAN_26') ? LANG_LAN_26 : LANG_LAN_120;
        return $ret;
    }
    $newfile = e_MEDIA_FILE . "e107_" . $ver . "_" . $language . "_" . $locale . "-utf8.zip";
    $archive = new PclZip($newfile);
    $core = grab_lans(e_LANGUAGEDIR . $language . "/", $language, '', 0);
    $core_admin = grab_lans(e_BASE . $LANGUAGES_DIRECTORY . $language . "/admin/", $language, '', 2);
    $plugs = grab_lans(e_BASE . $PLUGINS_DIRECTORY, $language, $core_plugins);
    // standardized path.
    $theme = grab_lans(e_BASE . $THEMES_DIRECTORY, $language, $core_themes);
    $docs = grab_lans(e_BASE . $HELP_DIRECTORY, $language);
    $handlers = grab_lans(e_BASE . $HANDLERS_DIRECTORY, $language);
    // standardized path.
    $file = array_merge($core, $core_admin, $plugs, $theme, $docs, $handlers);
    $data = implode(",", $file);
    if ($archive->create($data, PCLZIP_OPT_REMOVE_PATH, e_BASE) == 0) {
        $ret['error'] = TRUE;
        $ret['message'] = $archive->errorInfo(true);
        return $ret;
    } else {
        $fileName = e_FILE . "public/" . $language . ".xml";
        if (is_readable($fileName)) {
            @unlink($fileName);
        }
        $fileData = '<?xml version="1.0" encoding="utf-8"?>
<e107Language name="' . $language . '" compatibility="' . $ver . '" date="' . date("Y-m-d") . '" >
<author name ="' . USERNAME . '" email="' . USEREMAIL . '" url="' . SITEURL . '" />
</e107Language>';
        if (file_put_contents($fileName, $fileData)) {
            $addTag = $archive->add($fileName, PCLZIP_OPT_ADD_PATH, 'e107_languages/' . $language, PCLZIP_OPT_REMOVE_PATH, e_FILE . 'public/');
            $_SESSION['lancheck'][$language]['xml'] = "Yes";
        } else {
            $_SESSION['lancheck'][$language]['xml'] = "No";
        }
        @unlink($fileName);
        $ret['file'] = $newfile;
        $ret['message'] = str_replace("../", "", e_MEDIA_FILE) . "<a href='" . $newfile . "' >" . basename($newfile) . "</a>";
        $ret['error'] = FALSE;
        return $ret;
    }
}
Exemplo n.º 3
0
 function to_prediction($value_as_string, $data_locale = "UTF-8")
 {
     /*
        Given a prediction string, returns its value in the required type
     */
     if (!mb_check_encoding($value_as_string, 'UTF-8')) {
         $value_as_sring = utf8_encode($value_as_string);
     }
     $tree = $this->tree;
     $objective_id = $tree->objective_id;
     if ($this->fields->{$objective_id}->optype == 'numeric') {
         if ($data_locale == null) {
             $data_locale = $this->locale;
         }
         find_locale($data_locale);
         $datatype = $this->fields->{$objective_id}->datatype;
         if ($datatype == "double" || $datatype == "float") {
             return floatval($value_as_string);
         } else {
             return intval($value_as_string);
         }
     }
     return $value_as_string;
 }