Exemplo n.º 1
0
 /**
  * Checks the decsep and thousandssep config strings are set correctly
  *
  * @link http://tracker.moodle.org/browse/MDL-31332
  * @return bool check success flag
  */
 protected function check_decsep_thousandssep()
 {
     $details = array();
     $langnames = array();
     $tree = mlang_tools::components_tree(array('component' => 'langconfig'));
     foreach ($tree as $branch => $languages) {
         $version = mlang_version::by_code($branch);
         foreach (array_keys($languages) as $language) {
             $langconfig = mlang_component::from_snapshot('langconfig', $language, $version);
             if ($langname = $langconfig->get_string('thislanguageint')) {
                 $langnames[$language] = $langname->text;
             } else {
                 $langnames[$language] = $language;
             }
             if ($decsep = $langconfig->get_string('decsep')) {
                 $decsep = $decsep->text;
             }
             if ($thousandssep = $langconfig->get_string('thousandssep')) {
                 $thousandssep = $thousandssep->text;
             }
             if (empty($decsep) and empty($thousandssep)) {
                 $details[$language][$version->label] = 1;
             } else {
                 if (empty($decsep) or empty($thousandssep)) {
                     $details[$language][$version->label] = 2;
                 } else {
                     if ($decsep === $thousandssep) {
                         $details[$language][$version->label] = 3;
                     }
                 }
             }
         }
     }
     ksort($details);
     foreach ($details as $language => $branches) {
         $msg = sprintf('Invalid decsep and/or thousandssep in %s {%s} at', $langnames[$language], $language);
         foreach ($branches as $branch => $severity) {
             $msg .= ' ' . $branch . str_repeat('!', $severity);
         }
         $this->output($msg, true);
     }
     if (empty($details)) {
         return 0;
     }
     return 1;
 }
Exemplo n.º 2
0
define('CLI_SCRIPT', true);
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php';
require_once $CFG->dirroot . '/local/amos/cli/config.php';
require_once $CFG->dirroot . '/local/amos/mlanglib.php';
// Let us get an information about existing components
$sql = "SELECT branch,lang,component,COUNT(stringid) AS numofstrings\n          FROM {amos_repository}\n         WHERE deleted=0\n      GROUP BY branch,lang,component\n      ORDER BY branch,lang,component";
$rs = $DB->get_recordset_sql($sql);
$tree = array();
// [branch][language][component] => numofstrings
foreach ($rs as $record) {
    $tree[$record->branch][$record->lang][$record->component] = $record->numofstrings;
}
$rs->close();
remove_dir(AMOS_EXPORT_DIR, true);
foreach ($tree as $vercode => $languages) {
    $version = mlang_version::by_code($vercode);
    foreach ($languages as $langcode => $components) {
        if ($langcode == 'en') {
            continue;
        }
        foreach ($components as $componentname => $unused) {
            $component = mlang_component::from_snapshot($componentname, $langcode, $version);
            if ($component->has_string()) {
                $file = AMOS_EXPORT_DIR . '/' . $version->dir . '/' . $langcode . '/' . $component->get_phpfile_location(false);
                if (!file_exists(dirname($file))) {
                    mkdir(dirname($file), 0755, true);
                }
                echo "{$file}\n";
                $component->export_phpfile($file);
            }
            $component->clear();
Exemplo n.º 3
0
 */
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once dirname(__FILE__) . '/locallib.php';
require_once dirname(__FILE__) . '/mlanglib.php';
require_once dirname(__FILE__) . '/execute_form.php';
require_login(SITEID, false);
require_capability('local/amos:execute', get_system_context());
require_capability('local/amos:stage', get_system_context());
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/local/amos/execute.php');
navigation_node::override_active_url(new moodle_url('/local/amos/stage.php'));
$PAGE->set_title('AMOS ' . get_string('scriptexecute', 'local_amos'));
$PAGE->set_heading('AMOS ' . get_string('scriptexecute', 'local_amos'));
$executeform = new local_amos_execute_form(null, local_amos_execute_options());
if ($data = $executeform->get_data()) {
    $version = mlang_version::by_code($data->version);
    $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
    $instructions = mlang_tools::extract_script_from_text($data->script);
    if (!empty($instructions)) {
        foreach ($instructions as $instruction) {
            $changes = mlang_tools::execute($instruction, $version);
            if ($changes instanceof mlang_stage) {
                foreach ($changes->get_iterator() as $component) {
                    $stage->add($component, true);
                }
                $changes->clear();
            } elseif ($changes < 0) {
                throw new moodle_exception('error_during_amoscript_execution', 'local_amos', '', null, $changes);
            }
            unset($changes);
        }
Exemplo n.º 4
0
require_once dirname(__FILE__) . '/locallib.php';
require_once dirname(__FILE__) . '/mlanglib.php';
require_once dirname(__FILE__) . '/merge_form.php';
require_login(SITEID, false);
require_capability('local/amos:commit', get_system_context());
// for langpack maintainers only
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/local/amos/merge.php');
navigation_node::override_active_url(new moodle_url('/local/amos/stage.php'));
$PAGE->set_title('AMOS ' . get_string('merge', 'local_amos'));
$PAGE->set_heading('AMOS ' . get_string('merge', 'local_amos'));
$mergeform = new local_amos_merge_form(null, local_amos_merge_options());
if ($data = $mergeform->get_data()) {
    $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
    $sourceversion = mlang_version::by_code($data->sourceversion);
    $targetversion = mlang_version::by_code($data->targetversion);
    if (is_null($sourceversion) or is_null($targetversion)) {
        notice('Invalid version selected', new moodle_url('/local/amos/stage.php'));
    }
    $tree = mlang_tools::components_tree(array('branch' => $sourceversion->code, 'lang' => $data->language));
    $sourcecomponentnames = array_keys(reset(reset($tree)));
    unset($tree);
    foreach ($sourcecomponentnames as $sourcecomponentname) {
        // get a snapshot of both components and merge source into target
        $sourcecomponent = mlang_component::from_snapshot($sourcecomponentname, $data->language, $sourceversion);
        $targetcomponent = mlang_component::from_snapshot($sourcecomponent->name, $sourcecomponent->lang, $targetversion);
        mlang_tools::merge($sourcecomponent, $targetcomponent);
        $sourcecomponent->clear();
        // keep just strings that are defined in english
        $englishcomponent = mlang_component::from_snapshot($sourcecomponent->name, 'en', $targetversion);
        $targetcomponent->intersect($englishcomponent);
Exemplo n.º 5
0
require_once dirname(__FILE__) . '/diff_form.php';
require_login(SITEID, false);
require_capability('local/amos:stage', get_system_context());
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/local/amos/diff.php');
navigation_node::override_active_url(new moodle_url('/local/amos/stage.php'));
$PAGE->set_title('AMOS ' . get_string('diff', 'local_amos'));
$PAGE->set_heading('AMOS ' . get_string('diff', 'local_amos'));
$diffform = new local_amos_diff_form(null, local_amos_diff_options());
if ($data = $diffform->get_data()) {
    if ($data->versiona == $data->versionb) {
        notice(get_string('nodiffs', 'local_amos'), new moodle_url('/local/amos/stage.php'));
    }
    $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
    $versiona = mlang_version::by_code($data->versiona);
    $versionb = mlang_version::by_code($data->versionb);
    $tree = mlang_tools::components_tree(array('branch' => $versiona->code, 'lang' => 'en'));
    $componentnames = array_keys($tree[$versiona->code]['en']);
    $total = count($componentnames);
    unset($tree);
    echo $OUTPUT->header();
    $progressbar = new progress_bar();
    $progressbar->create();
    // prints the HTML code of the progress bar
    // we may need a bit of extra execution time and memory here
    @set_time_limit(HOURSECS);
    raise_memory_limit(MEMORY_EXTRA);
    // number of differences
    $num = 0;
    foreach ($componentnames as $i => $componentname) {
        $progressbar->update($i, $total, get_string('diffprogress', 'local_amos'));
Exemplo n.º 6
0
    header('HTTP/1.1 403 Forbidden');
    die;
}
if (!confirm_sesskey()) {
    header('HTTP/1.1 403 Forbidden');
    die;
}
$stringid = optional_param('stringid', null, PARAM_ALPHANUMEXT);
$text = optional_param('text', null, PARAM_RAW);
if (is_null($stringid) or is_null($text)) {
    header('HTTP/1.1 400 Bad Request');
    die;
}
list($lang, $originalid, $translationid) = local_amos_translator::decode_identifier($stringid);
$record = $DB->get_record('amos_repository', array('id' => $originalid), 'id,stringid,component,branch', MUST_EXIST);
$version = mlang_version::by_code($record->branch);
$component = new mlang_component($record->component, $lang, $version);
if ($version->code < mlang_version::MOODLE_20) {
    header('HTTP/1.1 400 Bad Request');
    die;
}
$string = new mlang_string($record->stringid, $text);
$string->clean_text();
$component->add_string($string);
$stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
$stage->add($component, true);
$stage->store();
mlang_stash::autosave($stage);
header('Content-Type: application/json; charset: utf-8');
$response = new stdclass();
$response->text = local_amos_renderer::add_breaks(s($string->text));
Exemplo n.º 7
0
define('AJAX_SCRIPT', true);
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
//require_once(dirname(__FILE__).'/locallib.php');
require_once dirname(__FILE__) . '/mlanglib.php';
require_login(SITEID, false);
if (!has_capability('local/amos:stage', get_system_context())) {
    header('HTTP/1.1 403 Forbidden');
    die;
}
if (!confirm_sesskey()) {
    header('HTTP/1.1 403 Forbidden');
    die;
}
$name = required_param('component', PARAM_ALPHANUMEXT);
$branch = required_param('branch', PARAM_INT);
$lang = required_param('lang', PARAM_ALPHANUMEXT);
$unstage = required_param('unstage', PARAM_STRINGID);
$response = new stdClass();
$response->success = true;
$response->error = '';
$stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
$component = $stage->get_component($name, $lang, mlang_version::by_code($branch));
if ($component) {
    $component->unlink_string($unstage);
    $stage->store();
} else {
    $response->success = false;
    $response->error = 'Unable to get load component';
}
header('Content-Type: application/json; charset: utf-8');
echo json_encode($response);
Exemplo n.º 8
0
 /**
  * Fetches the required commits from the repository
  *
  * @param array $filter allows to filter commits
  */
 public function __construct(array $filter = array())
 {
     global $DB;
     // we can not use limits inside subquery so firstly let us get commits we are interested in
     $params = array();
     $where = array();
     $getsql = "SELECT id";
     $countsql = "SELECT COUNT(*)";
     $sql = "  FROM {amos_commits}";
     if (!empty($filter['userid'])) {
         $where['userid'] = "userid = ?";
         $params[] = $filter['userid'];
     }
     if (!empty($filter['userinfo'])) {
         $where['userinfo'] = $DB->sql_like('userinfo', '?', false, false);
         $params[] = '%' . $filter['userinfo'] . '%';
     }
     if (!empty($where['userinfo']) and !empty($where['userid'])) {
         $where['user'] = '******' . $where['userid'] . ') OR (' . $where['userinfo'] . ')';
         unset($where['userinfo']);
         unset($where['userid']);
     }
     if (!empty($filter['committedafter'])) {
         $where['committedafter'] = 'timecommitted >= ?';
         $params[] = $filter['committedafter'];
     }
     if (!empty($filter['committedbefore'])) {
         $where['committedbefore'] = 'timecommitted < ?';
         $params[] = $filter['committedbefore'];
     }
     if (!empty($filter['source'])) {
         $where['source'] = 'source = ?';
         $params[] = $filter['source'];
     }
     if (!empty($filter['commitmsg'])) {
         $where['commitmsg'] = $DB->sql_like('commitmsg', '?', false, false);
         $params[] = '%' . $filter['commitmsg'] . '%';
     }
     if (!empty($filter['commithash'])) {
         $where['commithash'] = $DB->sql_like('commithash', '?', false, false);
         $params[] = $filter['commithash'] . '%';
     }
     if ($where) {
         $where = '(' . implode(') AND (', $where) . ')';
         $sql .= " WHERE {$where}";
     }
     $ordersql = " ORDER BY timecommitted DESC, id DESC";
     $this->numofcommits = $DB->count_records_sql($countsql . $sql, $params);
     $commitids = $DB->get_records_sql($getsql . $sql . $ordersql, $params, 0, self::LIMITCOMMITS);
     if (empty($commitids)) {
         // nothing to load
         return;
     }
     // now get all repository records modified by these commits
     // and optionally filter them if requested
     $params = array();
     list($csql, $params) = $DB->get_in_or_equal(array_keys($commitids));
     if (!empty($filter['branch'])) {
         list($branchsql, $branchparams) = $DB->get_in_or_equal(array_keys($filter['branch']));
     } else {
         $branchsql = '';
     }
     if (!empty($filter['lang'])) {
         list($langsql, $langparams) = $DB->get_in_or_equal($filter['lang']);
     } else {
         $langsql = '';
     }
     if (!empty($filter['component'])) {
         list($componentsql, $componentparams) = $DB->get_in_or_equal($filter['component']);
     } else {
         $componentsql = '';
     }
     $countsql = "SELECT COUNT(r.id)";
     $getsql = "SELECT r.id, c.source, c.timecommitted, c.commitmsg, c.commithash, c.userid, c.userinfo,\n                              r.commitid, r.branch, r.lang, r.component, r.stringid, r.text, r.timemodified, r.deleted";
     $sql = "  FROM {amos_commits} c\n                         JOIN {amos_repository} r ON (c.id = r.commitid)\n                        WHERE c.id {$csql}";
     if ($branchsql) {
         $sql .= " AND r.branch {$branchsql}";
         $params = array_merge($params, $branchparams);
     }
     if ($langsql) {
         $sql .= " AND r.lang {$langsql}";
         $params = array_merge($params, $langparams);
     }
     if ($componentsql) {
         $sql .= " AND r.component {$componentsql}";
         $params = array_merge($params, $componentparams);
     }
     if (!empty($filter['stringid'])) {
         $sql .= " AND r.stringid = ?";
         $params[] = $filter['stringid'];
     }
     $ordersql = " ORDER BY c.timecommitted DESC, c.id DESC, r.branch DESC, r.lang, r.component, r.stringid";
     $this->numofstrings = $DB->count_records_sql($countsql . $sql, $params);
     $rs = $DB->get_recordset_sql($getsql . $sql . $ordersql, $params);
     $numofcommits = 0;
     foreach ($rs as $r) {
         if (!isset($this->commits[$r->commitid])) {
             if ($numofcommits == self::LIMITCOMMITS) {
                 // we already have enough
                 break;
             }
             $commit = new stdclass();
             $commit->id = $r->commitid;
             $commit->source = $r->source;
             $commit->timecommitted = $r->timecommitted;
             $commit->commitmsg = $r->commitmsg;
             $commit->commithash = $r->commithash;
             $commit->userid = $r->userid;
             $commit->userinfo = $r->userinfo;
             $commit->strings = array();
             $this->commits[$r->commitid] = $commit;
             $numofcommits++;
         }
         $string = new stdclass();
         $string->branch = mlang_version::by_code($r->branch)->label;
         $string->component = $r->component;
         $string->lang = $r->lang;
         $string->stringid = $r->stringid;
         $string->deleted = $r->deleted;
         $this->commits[$r->commitid]->strings[] = $string;
     }
     $rs->close();
 }
Exemplo n.º 9
0
 * Register new language
 *
 * @package   local-amos
 * @copyright 2010 David Mudrak <*****@*****.**>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php';
require_once dirname(dirname(__FILE__)) . '/mlanglib.php';
require_once dirname(__FILE__) . '/newlanguage_form.php';
require_login(SITEID, false);
require_capability('local/amos:manage', get_system_context());
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/local/amos/admin/newlanguage.php');
$PAGE->set_title('AMOS ' . get_string('newlanguage', 'local_amos'));
$PAGE->set_heading('AMOS ' . get_string('newlanguage', 'local_amos'));
$form = new local_amos_newlanguage_form();
if ($data = $form->get_data()) {
    $component = new mlang_component('langconfig', $data->langcode, mlang_version::by_code(mlang_version::MOODLE_22));
    $data->langname = mlang_string::fix_syntax($data->langname);
    $data->langnameint = mlang_string::fix_syntax($data->langnameint);
    $component->add_string(new mlang_string('thislanguage', $data->langname));
    $component->add_string(new mlang_string('thislanguageint', $data->langnameint));
    $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
    $stage->add($component);
    $stage->store();
    redirect(new moodle_url('/local/amos/stage.php'));
}
/// Output starts here
echo $OUTPUT->header();
$form->display();
echo $OUTPUT->footer();
Exemplo n.º 10
0
if (!empty($submit)) {
    require_sesskey();
    $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
    $stash = mlang_stash::instance_from_stage($stage, $stage->userid);
    $stash->push();
    redirect(new moodle_url('/local/amos/stash.php', array('sesskey' => sesskey(), 'submit' => $stash->id)));
}
if (!empty($propagate)) {
    require_sesskey();
    $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
    $ver = optional_param('ver', array(), PARAM_INT);
    $num = null;
    if (!empty($ver) and is_array($ver)) {
        $versions = array();
        foreach ($ver as $versioncode) {
            $versions[] = mlang_version::by_code($versioncode);
        }
        if ($versions) {
            $num = $stage->propagate($versions);
            $stage->store();
        }
    }
    if (is_null($num)) {
        redirect($PAGE->url);
    } else {
        redirect(new moodle_url($PAGE->url, array('justpropagated' => $num)));
    }
}
$output = $PAGE->get_renderer('local_amos');
// make sure that USER contains sesskey property
$sesskey = sesskey();