Exemple #1
0
 foreach ($_REQUEST as $name => $value) {
     if ((StringUtil::startsWith($name, 'caps_') || StringUtil::startsWith($name, 'model_') || StringUtil::startsWith($name, 'comment_') || StringUtil::startsWith($name, 'singular_') || StringUtil::startsWith($name, 'plural_') || StringUtil::startsWith($name, 'verifSp_') || StringUtil::startsWith($name, 'delete_') || StringUtil::startsWith($name, 'deleteConfirm_')) && $value) {
         $parts = preg_split('/_/', $name);
         assert(count($parts) == 2);
         $lexemId = $parts[1];
         if (!array_key_exists($lexemId, $lexemMap)) {
             $lexemMap[$lexemId] = Lexem::get_by_id($lexemId);
         }
         $l = $lexemMap[$lexemId];
         $lm = $l->getFirstLexemModel();
         switch ($parts[0]) {
             case 'caps':
                 if (StringUtil::startsWith($l->form, "'")) {
                     $l->form = "'" . AdminStringUtil::capitalize(mb_substr($l->form, 1));
                 } else {
                     $l->form = AdminStringUtil::capitalize($l->form);
                 }
                 $l->formNoAccent = str_replace("'", '', $l->form);
                 break;
             case 'singular':
                 $lm->restriction = 'S';
                 break;
             case 'plural':
                 $lm->restriction = 'P';
                 break;
             case 'model':
                 if ($value) {
                     $m = Model::factory('FlexModel')->where_raw("concat(modelType, number) = '{$value}'")->find_one();
                     if ($m) {
                         $oldModelType = $lm->modelType;
                         $oldModelNumber = $lm->modelNumber;
    // Collect the user choices
    $choices = array();
    foreach ($_REQUEST as $name => $value) {
        if (StringUtil::startsWith($name, 'radio_')) {
            $choices[substr($name, 6)] = $value;
        }
    }
    // Collect the positions of ambiguous abbreviations
    $matches = array();
    AdminStringUtil::markAbbreviations($def->internalRep, $def->sourceId, $matches);
    usort($matches, 'positionCmp');
    $s = $def->internalRep;
    foreach ($matches as $i => $m) {
        if ($choices[count($choices) - 1 - $i] == 'abbrev') {
            $orig = substr($s, $m['position'], $m['length']);
            $replacement = StringUtil::isUppercase(StringUtil::getCharAt($orig, 0)) ? AdminStringUtil::capitalize($m['abbrev']) : $m['abbrev'];
            $s = substr_replace($s, "#{$replacement}#", $m['position'], $m['length']);
        }
    }
    $def->internalRep = $s;
    $def->htmlRep = AdminStringUtil::htmlize($def->internalRep, $def->sourceId);
    $def->abbrevReview = ABBREV_REVIEW_COMPLETE;
    $def->save();
}
$MARKER = 'DEADBEEF';
// any string that won't occur naturally in a definition
$def = null;
$ids = db_getArray(sprintf('select id from Definition where status != %d and abbrevReview = %d', ST_DELETED, ABBREV_AMBIGUOUS));
if (count($ids)) {
    $defId = $ids[array_rand($ids, 1)];
    $def = Definition::get_by_id($defId);