Пример #1
0
 private function _crawl()
 {
     $this->_init();
     //preload existing json
     $files = array();
     if (is_dir($this->cache_path)) {
         $jsons = scandir($this->cache_path);
         foreach ($jsons as $json_filename) {
             if (substr($json_filename, -5) != '.json') {
                 continue;
             }
             list($file, $type) = explode('.', substr($json_filename, 0, -5));
             if ($type != 'updated' && $type != 'log') {
                 continue;
             }
             list($project, $lang, $id) = explode('-', $file);
             $files[$project][$lang][$id][$type] = file_get_json($this->cache_path . $json_filename);
             unset($file, $type, $project, $lang, $id);
         }
     }
     unset($jsons, $json_filename);
     //crawl repos and build update
     $devices_path = $this->repo_path;
     $devices = @scandir($devices_path);
     if (!empty($devices)) {
         foreach ($devices as $device_index => $device) {
             if (substr($device, 0, 1) == '.' || !is_dir($devices_path . $device . '/')) {
                 unset($devices[$device_index]);
                 continue;
             }
             $projects_path = $devices_path . $device . '/';
             $projects = scandir($projects_path);
             if (!empty($projects)) {
                 foreach ($projects as $project_index => $project_filename) {
                     if (substr($project_filename, 0, 3) != 'uw-' || !is_dir($projects_path . $project_filename . '/')) {
                         unset($projects[$project_index]);
                         continue;
                     }
                     list($project, $lang) = explode('-', substr($project_filename, 3));
                     $ids_path = $projects_path . $project_filename . '/';
                     $ids = scandir($ids_path);
                     if (!empty($ids)) {
                         foreach ($ids as $id_index => $id) {
                             if (substr($id, 0, 1) == '.' || !is_dir($ids_path . $id . '/')) {
                                 unset($ids[$id_index]);
                                 continue;
                             }
                             $data =& $files[$project][$lang][$id];
                             $frames_path = $ids_path . $id . '/';
                             $frames = scandir($frames_path);
                             if (!empty($frames)) {
                                 foreach ($frames as $frame_index => $frame_filename) {
                                     if (substr($frame_filename, -4) != '.txt') {
                                         unset($frames[$frame_index]);
                                         continue;
                                     }
                                     $frame = substr($frame_filename, 0, -4);
                                     $updated = date('Y-m-d H:i:s', filemtime($frames_path . $frame_filename));
                                     if ($data['log'][$device][$frame]['time'] < $updated) {
                                         $data['updated']['devices'][$device][$frame] = $updated;
                                         $data['updated']['frames'][$frame][] = $device;
                                         $data['log'][$device][$frame] = array('time' => $updated, 'action' => 'updated');
                                     }
                                 }
                             }
                             unset($frame_index, $frame_filename, $frame, $updated);
                         }
                     }
                     unset($id_index, $id);
                 }
             }
             unset($project_index, $project);
         }
     }
     unset($device_index, $device);
     //update json
     foreach ($files as $project => $langs) {
         foreach ($langs as $lang => $ids) {
             foreach ($ids as $id => $content) {
                 file_put_json($this->cache_path . $this->_get_log_filename($project, $lang, $id, 'updated'), $content['updated']);
                 file_put_json($this->cache_path . $this->_get_log_filename($project, $lang, $id, 'log'), $content['log']);
             }
         }
     }
     unset($files, $project, $langs, $lang, $ids, $id, $content);
 }
Пример #2
0
<?php

/**
 * Generates the address_format_changes.json file.
 */
set_time_limit(0);
date_default_timezone_set('UTC');
// Create a list of changes between the new and the old definitions.
$addressFormats = load_definitions('address_format');
$previousAddressFormats = load_definitions('../resources/address_format');
$addressFormatChanges = load_change_listing('address_format');
$addressFormatChanges[] = generate_address_format_changes($previousAddressFormats, $addressFormats);
file_put_json('address_format_changes.json', $addressFormatChanges);
echo "Generated a list of changes.\n";
/**
 * Converts the provided data into json and writes it to the disk.
 */
function file_put_json($filename, $data)
{
    $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
    file_put_contents($filename, $data);
}
/**
 * Loads all definitions of the provided type (address_format or subdivision).
 */
function load_definitions($path)
{
    $data = [];
    if ($handle = opendir($path)) {
        while (false !== ($entry = readdir($handle))) {
            if (substr($entry, 0, 1) != '.') {
Пример #3
0
    if (strpos($locale, '-') !== false) {
        $localeParts = explode('-', $locale);
        array_pop($localeParts);
        $parentLocale = implode('-', $localeParts);
        $diff = array_diff_assoc($formatData, $numberFormats[$parentLocale]);
        if (empty($diff)) {
            // The duplicates are not removed right away because they might
            // still be needed for other duplicate checks (for example,
            // when there are locales like bs-Latn-BA, bs-Latn, bs).
            $duplicates[] = $locale;
        }
    }
}
// Remove the duplicates.
foreach ($duplicates as $locale) {
    unset($numberFormats[$locale]);
}
// Write out the data.
foreach ($numberFormats as $locale => $numberFormat) {
    file_put_json($locale . '.json', $numberFormat);
}
/**
 * Converts the provided data into json and writes it to the disk.
 */
function file_put_json($filename, $data)
{
    $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
    // Indenting with tabs instead of 4 spaces gives us 20% smaller files.
    $data = str_replace('    ', "\t", $data);
    file_put_contents($filename, $data);
}
Пример #4
0
         $a->content(h::{'button[type=submit]'}($L->{$check_dependencies ? $L->yes : 'force_update_not_recommended'}));
         break;
     }
     if (!file_exists(MODULES . "/{$module_name}") && !mkdir(MODULES . "/{$module_name}", 0700)) {
         $Page->warning($L->cant_unpack_module_no_write_permissions);
         unlink($tmp_file);
         break;
     }
     $fs = file_get_json("{$tmp_dir}/fs.json");
     $extract = array_product(array_map(function ($index, $file) use($tmp_dir, $module_name) {
         if (!file_exists(dirname(MODULES . "/{$module_name}/{$file}")) && !mkdir(dirname(MODULES . "/{$module_name}/{$file}"), 0700, true)) {
             return 0;
         }
         return (int) copy("{$tmp_dir}/fs/{$index}", MODULES . "/{$module_name}/{$file}");
     }, $fs, array_keys($fs)));
     file_put_json(MODULES . "/{$module_name}/fs.json", array_keys($fs));
     unlink($tmp_file);
     unset($tmp_file, $tmp_dir);
     if (!$extract) {
         $Page->warning($L->module_files_unpacking_error);
         break;
     }
     $Config->components['modules'][$module_name] = ['active' => -1, 'db' => [], 'storage' => []];
     unset($module_name);
     ksort($Config->components['modules'], SORT_STRING | SORT_FLAG_CASE);
     $Config->save();
 } elseif ($rc[3] == 'upload') {
     break;
 }
 $show_modules = false;
 $Page->title($L->installation_of_module($rc[3]));
Пример #5
0
        array_shift($languages);
    }
    if (isset($definition['sub_keys'])) {
        $subdivisionPaths = [];
        $subdivisionKeys = explode('~', $definition['sub_keys']);
        foreach ($subdivisionKeys as $subdivisionKey) {
            $subdivisionPaths[] = $countryCode . '_' . $subdivisionKey;
        }
        $groupedSubdivisions += generate_subdivisions($countryCode, [$countryCode], $subdivisionPaths, $languages);
    }
    $addressFormats[$countryCode] = $addressFormat;
}
echo "Writing the final definitions to disk.\n";
// Subdivisions are stored in JSON.
foreach ($groupedSubdivisions as $parentId => $subdivisions) {
    file_put_json('subdivision/' . $parentId . '.json', $subdivisions);
}
// Generate the subdivision depths for each country.
$depths = generate_subdivision_depths($foundCountries);
foreach ($depths as $countryCode => $depth) {
    $addressFormats[$countryCode]['subdivision_depth'] = $depth;
}
// Address formats are stored in PHP, then manually transferred to
// AddressFormatRepository.
file_put_php('address_formats.php', $addressFormats);
echo "Done.\n";
/**
 * Converts the provided data into json and writes it to the disk.
 */
function file_put_json($filename, $data)
{
Пример #6
0
 $extract = array_product(array_map(function ($index, $file) use($tmp_dir, $module_dir) {
     if (!file_exists(dirname(DIR . "/{$file}")) && !mkdir(dirname(DIR . "/{$file}"), 0700, true)) {
         return 0;
     }
     return (int) copy("{$tmp_dir}/fs/{$index}", DIR . "/{$file}");
 }, $fs, array_keys($fs)));
 unlink($tmp_file);
 unset($tmp_file, $tmp_dir);
 if (!$extract) {
     $Page->warning($L->system_files_unpacking_error);
     unlink(DIR . '/core/fs_old.json');
     unlink("{$module_dir}/meta_old.json");
     break;
 }
 unset($extract);
 file_put_json(DIR . '/core/fs.json', $fs = array_keys($fs));
 /**
  * Removing of old unnecessary files and directories
  */
 foreach (array_diff(file_get_json(DIR . '/core/fs_old.json'), $fs) as $file) {
     $file = DIR . "/{$file}";
     if (file_exists($file) && is_writable($file)) {
         unlink($file);
         if (!get_files_list($dir = dirname($file))) {
             rmdir($dir);
         }
     }
 }
 unset($fs, $file, $dir);
 /**
  * Updating of System
Пример #7
0
        }
        $groupedSubdivisions += generate_subdivisions($countryCode, $countryCode, $subdivisionPaths, $languages);
    }
    $addressFormats[$countryCode] = $addressFormat;
}
echo "Writing the final definitions to disk.\n";
// Write the new definitions to disk.
foreach ($addressFormats as $countryCode => $addressFormat) {
    file_put_json('address_format/' . $countryCode . '.json', $addressFormat);
}
foreach ($groupedSubdivisions as $parentId => $subdivisions) {
    file_put_json('subdivision/' . $parentId . '.json', $subdivisions);
}
// Generate the subdivision depths for each country.
$depths = generate_subdivision_depths($foundCountries);
file_put_json('subdivision/depths.json', $depths);
echo "Done. You can now apply the library customizations by running 'patch -p2 < ../resources/library_customizations.patch'.\n";
/**
 * Converts the provided data into json and writes it to the disk.
 */
function file_put_json($filename, $data)
{
    $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
    // Indenting with tabs instead of 4 spaces gives us 20% smaller files.
    $data = str_replace('    ', "\t", $data);
    file_put_contents($filename, $data);
}
/**
 * Generates a list of all urls that need to be downloaded using aria2.
 */
function generate_url_list()
Пример #8
0
 $extract = array_product(array_map(function ($index, $file) use($tmp_dir, $theme_dir) {
     if (!file_exists(dirname("{$theme_dir}/{$file}")) && !mkdir(dirname("{$theme_dir}/{$file}"), 0700, true)) {
         return 0;
     }
     return (int) copy("{$tmp_dir}/fs/{$index}", "{$theme_dir}/{$file}");
 }, $fs, array_keys($fs)));
 unlink($tmp_file);
 unset($tmp_file, $tmp_dir);
 if (!$extract) {
     $Page->warning($L->theme_files_unpacking_error);
     unlink("{$theme_dir}/fs_old.json");
     unlink("{$theme_dir}/meta_old.json");
     break;
 }
 unset($extract);
 file_put_json("{$theme_dir}/fs.json", $fs = array_keys($fs));
 /**
  * Removing of old unnecessary files and directories
  */
 foreach (array_diff(file_get_json("{$theme_dir}/fs_old.json"), $fs) as $file) {
     $file = "{$theme_dir}/{$file}";
     if (file_exists($file) && is_writable($file)) {
         unlink($file);
         if (!get_files_list($dir = dirname($file))) {
             rmdir($dir);
         }
     }
 }
 unset($fs, $file, $dir);
 unlink("{$theme_dir}/fs_old.json");
 unlink("{$theme_dir}/meta_old.json");
Пример #9
0
         $a->content(h::{'button[type=submit]'}($L->{$check_dependencies ? $L->yes : 'force_update_not_recommended'}));
         return;
     }
     if (!file_exists(PLUGINS . "/{$plugin}") && !mkdir(PLUGINS . "/{$plugin}", 0700)) {
         $Page->warning($L->cant_unpack_plugin_no_write_permissions);
         unlink($tmp_file);
         break;
     }
     $fs = file_get_json("{$tmp_dir}/fs.json");
     $extract = array_product(array_map(function ($index, $file) use($tmp_dir, $plugin) {
         if (!file_exists(dirname(PLUGINS . "/{$plugin}/{$file}")) && !mkdir(dirname(PLUGINS . "/{$plugin}/{$file}"), 0700, true)) {
             return 0;
         }
         return (int) copy("{$tmp_dir}/fs/{$index}", PLUGINS . "/{$plugin}/{$file}");
     }, $fs, array_keys($fs)));
     file_put_json(PLUGINS . "/{$plugin}/fs.json", array_keys($fs));
     unset($tmp_dir);
     if (!$extract) {
         $Page->warning($L->plugin_files_unpacking_error);
         break;
     }
     unlink($tmp_file);
     $plugins[] = $plugin;
     unset($tmp_file, $plugin);
 }
 if (!in_array($rc[3], $Config->components['plugins']) && in_array($rc[3], $plugins)) {
     $Page->title($L->enabling_of_plugin($rc[3]));
     $a->content(h::{'p.lead.cs-center'}($L->enabling_of_plugin($rc[3])));
     $check_dependencies = check_dependencies($rc[3], 'plugin');
     if (!$check_dependencies && $Config->core['simple_admin_mode']) {
         break;
Пример #10
0
        });
        if (empty($diff)) {
            // The duplicates are not removed right away because they might
            // still be needed for other duplicate checks (for example,
            // when there are locales like bs-Latn-BA, bs-Latn, bs).
            $duplicates[] = $locale;
        }
    }
}
// Remove the duplicates.
foreach ($duplicates as $locale) {
    unset($languages[$locale]);
}
// Write out the localizations.
foreach ($languages as $locale => $localizedLanguages) {
    $collator = collator_create($locale);
    uasort($localizedLanguages, function ($a, $b) use($collator) {
        return collator_compare($collator, $a['name'], $b['name']);
    });
    file_put_json($locale . '.json', $localizedLanguages);
}
/**
 * Converts the provided data into json and writes it to the disk.
 */
function file_put_json($filename, $data)
{
    $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
    // Indenting with tabs instead of 4 spaces gives us 20% smaller files.
    $data = str_replace('    ', "\t", $data);
    file_put_contents($filename, $data);
}
Пример #11
0
 /**
  * Rebuilding of JavaScript and CSS cache
  *
  * @return Page
  */
 protected function rebuild_cache()
 {
     $this->includes_dependencies_and_map($dependencies, $includes_map);
     $structure = [];
     foreach ($includes_map as $filename_prefix => $includes) {
         $filename_prefix = str_replace('/', '+', $filename_prefix);
         $structure[$filename_prefix] = $this->create_cached_includes_files($filename_prefix, $includes);
     }
     unset($includes_map, $filename_prefix, $includes);
     file_put_json(PCACHE . "/{$this->pcache_basename}.json", ['dependencies' => $dependencies, 'structure' => $structure]);
     unset($structure);
     Trigger::instance()->run('System/Page/rebuild_cache');
     return $this;
 }
Пример #12
0
        });
        if (empty($diff)) {
            // The duplicates are not removed right away because they might
            // still be needed for other duplicate checks (for example,
            // when there are locales like bs-Latn-BA, bs-Latn, bs).
            $duplicates[] = $locale;
        }
    }
}
// Remove the duplicates.
foreach ($duplicates as $locale) {
    unset($currencies[$locale]);
}
// Write out the localizations.
foreach ($currencies as $locale => $localizedCurrencies) {
    $collator = collator_create($locale);
    uasort($localizedCurrencies, function ($a, $b) use($collator) {
        return collator_compare($collator, $a['name'], $b['name']);
    });
    file_put_json($locale . '.json', $localizedCurrencies);
}
/**
 * Converts the provided data into json and writes it to the disk.
 */
function file_put_json($filename, $data)
{
    $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
    // Indenting with tabs instead of 4 spaces gives us 20% smaller files.
    $data = str_replace('    ', "\t", $data);
    file_put_contents($filename, $data);
}
Пример #13
0
            // when there are locales like bs-Latn-BA, bs-Latn, bs).
            $duplicates[] = $locale;
        }
    }
}
// Remove the duplicates.
foreach ($duplicates as $locale) {
    unset($countries[$locale]);
}
// Write out the localizations.
foreach ($countries as $locale => $localizedCountries) {
    $collator = collator_create($locale);
    uasort($localizedCountries, function ($a, $b) use($collator) {
        return collator_compare($collator, $a['name'], $b['name']);
    });
    file_put_json($locale . '.json', $localizedCountries);
}
/**
 * Converts the provided data into json and writes it to the disk.
 */
function file_put_json($filename, $data)
{
    $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
    // Indenting with tabs instead of 4 spaces gives us 20% smaller files.
    $data = str_replace('    ', "\t", $data);
    file_put_contents($filename, $data);
}
/**
 * Prepares the currencies for a specific country.
 */
function prepare_currencies($currencies)
Пример #14
0
 $extract = array_product(array_map(function ($index, $file) use($tmp_dir, $plugin_dir) {
     if (!file_exists(dirname("{$plugin_dir}/{$file}")) && !mkdir(dirname("{$plugin_dir}/{$file}"), 0700, true)) {
         return 0;
     }
     return (int) copy("{$tmp_dir}/fs/{$index}", "{$plugin_dir}/{$file}");
 }, $fs, array_keys($fs)));
 unlink($tmp_file);
 unset($tmp_file, $tmp_dir);
 if (!$extract) {
     $Page->warning($L->plugin_files_unpacking_error);
     unlink("{$plugin_dir}/fs_old.json");
     unlink("{$plugin_dir}/meta_old.json");
     break;
 }
 unset($extract);
 file_put_json("{$plugin_dir}/fs.json", $fs = array_keys($fs));
 /**
  * Removing of old unnecessary files and directories
  */
 foreach (array_diff(file_get_json("{$plugin_dir}/fs_old.json"), $fs) as $file) {
     $file = "{$plugin_dir}/{$file}";
     if (file_exists($file) && is_writable($file)) {
         unlink($file);
         if (!get_files_list($dir = dirname($file))) {
             rmdir($dir);
         }
     }
 }
 unset($fs, $file, $dir);
 /**
  * Updating of plugin
Пример #15
0
    if (isset($cache[$class])) {
        return require_once $cache[$class];
    }
    $prepared_class_name = ltrim($class, '\\');
    if (substr($prepared_class_name, 0, 3) == 'cs\\') {
        $prepared_class_name = substr($prepared_class_name, 3);
    }
    $prepared_class_name = explode('\\', $prepared_class_name);
    $namespace = count($prepared_class_name) > 1 ? implode('/', array_slice($prepared_class_name, 0, -1)) : '';
    $class_name = array_pop($prepared_class_name);
    /**
     * Try to load classes from different places. If not found in one place - try in another.
     */
    if (_require_once($file = CLASSES . "/{$namespace}/{$class_name}.php", false) || _require_once($file = THIRDPARTY . "/{$namespace}/{$class_name}.php", false) || _require_once($file = TRAITS . "/{$namespace}/{$class_name}.php", false) || _require_once($file = ENGINES . "/{$namespace}/{$class_name}.php", false) || _require_once($file = MODULES . "/../{$namespace}/{$class_name}.php", false)) {
        $cache[$class] = realpath($file);
        file_put_json(CACHE . '/classes_autoloading', $cache);
        return true;
    }
    return false;
}, true, true);
/**
 * Correct termination
 */
register_shutdown_function(function () {
    if (!class_exists('\\cs\\Core', false)) {
        return;
    }
    Index::instance(true)->__finish();
    Page::instance()->__finish();
    User::instance(true)->__finish();
});
Пример #16
0
<?php

/**
 * @package        Download
 * @category       modules
 * @author         Nazar Mokrynskyi <*****@*****.**>
 * @copyright      Copyright (c) 2014, Nazar Mokrynskyi
 * @license        MIT License, see license.txt
 */
namespace cs;

if (!file_exists(DIR . '/downloads')) {
    $downloads = 0;
} else {
    $downloads = file_get_json(DIR . '/downloads');
}
$downloads++;
file_put_json(DIR . '/downloads', $downloads);
header('Location: https://opir.org/storage/public/opir.org.apk', true, 301);
interface_off();
Index::instance()->stop = true;