Автор: Jan Vansteenlandt (jan@okfn.be)
Наследование: extends Eloquent
Пример #1
0
    /**
     * Cache a file containing the dispatch list.
     *
     * Serializes the server definition stores the information
     * in $filename.
     *
     * Returns false on any error (typically, inability to write to file), true
     * on success.
     *
     * @param  string $filename
     * @param  \Zend\Server\Server $server
     * @return bool
     */
    public static function save($filename, Server $server)
    {
        if (!is_string($filename)
            || (!file_exists($filename) && !is_writable(dirname($filename))))
        {
            return false;
        }

        $methods = $server->getFunctions();

        if ($methods instanceof Definition) {
            $definition = new Definition();
            foreach ($methods as $method) {
                if (in_array($method->getName(), self::$_skipMethods)) {
                    continue;
                }
                $definition->addMethod($method);
            }
            $methods = $definition;
        }

        if (0 === @file_put_contents($filename, serialize($methods))) {
            return false;
        }

        return true;
    }
Пример #2
0
 /**
  * @param Definition $definition
  */
 public function add(Definition $definition)
 {
     if (!class_exists($definition->getClass())) {
         throw new \InvalidArgumentException(sprintf("Invalid class \"%s\"", $definition->getClass()));
     }
     $this->classes[$definition->getName()] = $definition;
 }
Пример #3
0
 /**
  * @test
  */
 public function expects_an_expected_field_in_each_expectation()
 {
     $this->assertException(new \Exception('Missing expected field.'), function () {
         $definitions = array('expectations' => array(array('uri' => 'http://www.example.com', 'type' => 'json')));
         $d = new Definition($definitions);
         $d->getExpectations();
     });
 }
 /**
  * {@inheritdoc}
  */
 public function create($type, $path, array $properties = array())
 {
     $definition = new Definition();
     $definition->setType($type);
     $definition->setPath($path);
     $definition->setProperties($properties);
     return $definition;
 }
Пример #5
0
/**
 * Creates a matrix with 7 columns, one per day of week, and as many rows (weeks) as necessary.
 * Every cell contains a dictionary with the wotd, the definition and other info.
 */
function createCalendar($year, $month)
{
    $days = listDaysOfMonth($year, $month);
    $today = date('Y-m-d');
    $calendar = array();
    // Pad beginning
    $startDow = date('N', strtotime("{$year}-{$month}-01"));
    for ($i = 1; $i < $startDow; $i++) {
        $calendar[] = array();
    }
    // Create a record per day
    foreach ($days as $i => $date) {
        $wotd = WordOfTheDay::get_by_displayDate($date);
        $wotdr = $wotd ? WordOfTheDayRel::get_by_wotdId($wotd->id) : null;
        $def = $wotdr ? Definition::get_by_id($wotdr->refId) : null;
        $visible = $def && ($date <= $today || util_isModerator(PRIV_WOTD));
        $calendar[] = array('wotd' => $wotd, 'def' => $def, 'visible' => $visible, 'dayOfMonth' => $i + 1);
    }
    // Pad end
    while (count($calendar) % 7 != 0) {
        $calendar[] = array();
    }
    // Wrap 7 records per line
    $weeks = array();
    while (count($calendar)) {
        $weeks[] = array_splice($calendar, 0, 7);
    }
    return $weeks;
}
Пример #6
0
function smarty_fetchSkin()
{
    $skin = session_getSkin();
    // Set some skin variables based on the skin preferences in the config file.
    // Also assign some skin-specific variables so we don't compute them unless we need them
    $skinVariables = session_getSkinPreferences($skin);
    switch ($skin) {
        case 'zepu':
            $skinVariables['afterSearchBoxBanner'] = true;
            break;
        case 'polar':
            $wordCount = Definition::getWordCount();
            $wordCountRough = $wordCount - $wordCount % 10000;
            smarty_assign('words_total', util_formatNumber($wordCount, 0));
            smarty_assign('words_rough', util_formatNumber($wordCountRough, 0));
            smarty_assign('words_last_month', util_formatNumber(Definition::getWordCountLastMonth(), 0));
            break;
        case 'mobile':
            smarty_assign('words_total', util_formatNumber(Definition::getWordCount(), 0));
            smarty_assign('words_last_month', util_formatNumber(Definition::getWordCountLastMonth(), 0));
            break;
    }
    smarty_assign('skinVariables', $skinVariables);
    smarty_register_outputfilters();
    return $GLOBALS['smarty_theSmarty']->fetch("{$skin}/pageLayout.ihtml");
}
Пример #7
0
 public function parseError($str = "", ParserError $hash = null)
 {
     $this->parserErrors[] = $str;
     if ($this->verbose) {
         parent::parseError($str, $hash);
     }
 }
Пример #8
0
 public static function handle($uri)
 {
     $definitions = \Definition::all();
     // Polyfill
     if (!function_exists('array_column')) {
         function array_column($array, $column_name)
         {
             return array_map(function ($element) use($column_name) {
                 return $element[$column_name];
             }, $array);
         }
     }
     // Get unique properties
     $keywords = Definitions\KeywordController::getKeywordList($definitions);
     $languages = array_count_values(array_filter(array_column($definitions->toArray(), 'language')));
     $licenses = array_count_values(array_filter(array_column($definitions->toArray(), 'rights')));
     $themes = array_count_values(array_filter(array_column($definitions->toArray(), 'theme')));
     $publishers = array_count_values(array_filter(array_column($definitions->toArray(), 'publisher_name')));
     // Sort by "Popularity"
     // For alphabetical order: use ksort
     arsort($keywords);
     arsort($languages);
     arsort($licenses);
     arsort($themes);
     arsort($publishers);
     $view = \View::make('home')->with('title', 'Datasets | The Datatank')->with('page_title', 'Datasets')->with('keywords', $keywords)->with('languages', $languages)->with('licenses', $licenses)->with('themes', $themes)->with('publishers', $publishers)->with('definitions', $definitions);
     return \Response::make($view);
 }
 public static function deleteByLexemId($lexemId)
 {
     $ldms = LexemDefinitionMap::get_all_by_lexemId($lexemId);
     foreach ($ldms as $ldm) {
         Definition::updateModDate($ldm->definitionId);
         $ldm->delete();
     }
 }
Пример #10
0
 public function test()
 {
     $loader = new ResourceLoader();
     $definitions = new Definition($loader->load($this->source));
     foreach ($definitions->getExpectations() as $definition) {
         if (null !== $definition['type']) {
             $actual = $loader->getType($definition['uri']);
             if ($actual !== $definition['type']) {
                 throw new FailedExpectationException("Type mismatch for {$definition['uri']}. Got [{$actual}] but expected [{$definition['type']}]");
             }
         }
         $expectation = new Expectation($definition['expected']);
         if (!$expectation->assert($loader->load($definition['uri']))) {
             throw new FailedExpectationException(implode("\n", $expectation->getMessages()));
         }
     }
     return true;
 }
 public function process(ContainerBuilder $container)
 {
     $methods = $container->findTaggedServiceIds('knp_rad_prototype.method');
     foreach ($methods as $id => $tags) {
         foreach ($tags as $tag) {
             $tag = array_merge(['alias' => $tag['method'], 'domain' => null], $tag);
             $definition = new Definition('Knp\\Rad\\Prototype\\Prototype\\Method', [sprintf('@%s', $id), $tag['method']]);
             $definition->addTag('knp_rad_prototype.prototype_method', $tag);
             $name = sprintf('knp_rad_prototype.prototype.method.%s', Inflector::tableize($tag['alias']));
             $container->setDefinition($name, $definition);
         }
     }
     $methodContainer = $container->getDefinition('knp_rad_prototype.prototype.container');
     $methods = $container->findTaggedServiceIds('knp_rad_prototype.prototype_method');
     foreach ($methods as $id => $tags) {
         $tag = current($tags);
         $methodContainer->addMethodCall('addMethod', [$tag['alias'], new Reference($id), $tag['domain']]);
     }
 }
Пример #12
0
 /**
  * Adds a service
  *
  * @param string $id
  * @param Definition $definition
  * @return string
  */
 private function addService($id, $definition)
 {
     $code = "  {$id}:\n";
     if ($definition->getClass()) {
         $code .= sprintf("    class: %s\n", $definition->getClass());
     }
     $tagsCode = '';
     foreach ($definition->getTags() as $name => $tags) {
         foreach ($tags as $attributes) {
             $att = array();
             foreach ($attributes as $key => $value) {
                 $att[] = sprintf('%s: %s', Yaml::dump($key), Yaml::dump($value));
             }
             $att = $att ? ', ' . implode(' ', $att) : '';
             $tagsCode .= sprintf("      - { name: %s%s }\n", Yaml::dump($name), $att);
         }
     }
     if ($tagsCode) {
         $code .= "    tags:\n" . $tagsCode;
     }
     if ($definition->getFile()) {
         $code .= sprintf("    file: %s\n", $definition->getFile());
     }
     if ($definition->getFactoryMethod()) {
         $code .= sprintf("    factory_method: %s\n", $definition->getFactoryMethod());
     }
     if ($definition->getFactoryService()) {
         $code .= sprintf("    factory_service: %s\n", $definition->getFactoryService());
     }
     if ($definition->getArguments()) {
         $code .= sprintf("    arguments: %s\n", Yaml::dump($this->dumpValue($definition->getArguments()), 0));
     }
     if ($definition->getProperties()) {
         $code .= sprintf("    properties: %s\n", Yaml::dump($this->dumpValue($definition->getProperties()), 0));
     }
     if ($definition->getMethodCalls()) {
         $code .= sprintf("    calls:\n      %s\n", str_replace("\n", "\n      ", Yaml::dump($this->dumpValue($definition->getMethodCalls()), 1)));
     }
     if (ContainerInterface::SCOPE_CONTAINER !== ($scope = $definition->getScope())) {
         $code .= sprintf("    scope: %s\n", $scope);
     }
     if ($callable = $definition->getConfigurator()) {
         if (is_array($callable)) {
             if (is_object($callable[0]) && $callable[0] instanceof Reference) {
                 $callable = array($this->getServiceCall((string) $callable[0], $callable[0]), $callable[1]);
             } else {
                 $callable = array($callable[0], $callable[1]);
             }
         }
         $code .= sprintf("    configurator: %s\n", Yaml::dump($callable, 0));
     }
     return $code;
 }
Пример #13
0
 /**
  * __construct() - For concrete implementation of Zend_Db_Table
  *
  * @param string|array $config string can reference a \Zend\Registry key for a db adapter
  *                             OR it can reference the name of a table
  * @param array|\Zend\Db\Table\Definition $definition
  */
 public function __construct($config = array(), $definition = null)
 {
     if ($definition !== null && is_array($definition)) {
         $definition = new Definition($definition);
     }
     if (is_string($config)) {
         if (\Zend\Registry::isRegistered($config)) {
             trigger_error(__CLASS__ . '::' . __METHOD__ . '(\'registryName\') is not valid usage of Zend_Db_Table, ' . 'try extending Zend_Db_Table_Abstract in your extending classes.', E_USER_NOTICE);
             $config = array(self::ADAPTER => $config);
         } else {
             // process this as table with or without a definition
             if ($definition instanceof Definition && $definition->hasTableConfig($config)) {
                 // this will have DEFINITION_CONFIG_NAME & DEFINITION
                 $config = $definition->getTableConfig($config);
             } else {
                 $config = array(self::NAME => $config);
             }
         }
     }
     parent::__construct($config);
 }
Пример #14
0
function getSourcesForLexem($lexem)
{
    global $SOURCES;
    $defs = Definition::loadByLexemId($lexem->id);
    $sources = array();
    foreach ($defs as $def) {
        $shortName = $SOURCES[$def->sourceId]->shortName;
        if (!in_array($shortName, $sources)) {
            $sources[] = $shortName;
        }
    }
    return '(' . implode(',', $sources) . ')';
}
Пример #15
0
 public function testDeleteApi()
 {
     // Delete the published definition for each test csv file.
     foreach ($this->test_data as $file) {
         $this->updateRequest('DELETE');
         $controller = \App::make('Tdt\\Core\\Definitions\\DefinitionController');
         $response = $controller->handle("csv/{$file}");
         $this->assertEquals(200, $response->getStatusCode());
     }
     // Check if everything is deleted properly.
     $definitions_count = \Definition::all()->count();
     $csv_count = \CsvDefinition::all()->count();
     $this->assertTrue($csv_count == 0);
     $this->assertTrue($definitions_count == 0);
 }
 private function createDefinitions()
 {
     $definitionList = $this->document->getElementsByTagName('definition');
     foreach ($definitionList as $definition) {
         if ($definition->hasChildNodes()) {
             $definitionChildrenNode = $definition->childNodes;
             $definitionObj = new Definition();
             foreach ($definitionChildrenNode as $definitionChild) {
                 if ($definitionChild->nodeName == "name") {
                     $definitionName = $definitionChild->nodeValue;
                     $definitionObj->setName($definitionName);
                 }
                 if ($definitionChild->nodeName == "base") {
                     $definitionObj->setBase($definitionChild->nodeValue);
                 }
                 if ($definitionChild->nodeName == "put") {
                     $pageKey = "";
                     $value = "";
                     $role = "";
                     if ($definitionChild->hasAttribute('pageKey')) {
                         $pageKey = $definitionChild->getAttribute('pageKey');
                     }
                     if ($definitionChild->hasAttribute('value')) {
                         $value = $definitionChild->getAttribute('value');
                     }
                     if ($definitionChild->hasAttribute('role')) {
                         $role = $definitionChild->getAttribute('role');
                     }
                     $put = new Put($pageKey, $value, $role);
                     $definitionObj->addPut($put);
                 }
             }
             $this->addDefinition($definitionName, $definitionObj);
         }
     }
 }
Пример #17
0
 /**
  * Delete everything out of our testing database.
  */
 public static function tearDownAfterClass()
 {
     parent::tearDownAfterClass();
     \Definition::truncate();
     \CsvDefinition::truncate();
     \InstalledDefinition::truncate();
     \JsonDefinition::truncate();
     \ShpDefinition::truncate();
     \SparqlDefinition::truncate();
     \XlsDefinition::truncate();
     \XmlDefinition::truncate();
     \GeoProperty::truncate();
     \TabularColumns::truncate();
     \Geoprojection::truncate();
 }
Пример #18
0
function createLexemDefinitionMap()
{
    LexemDefinitionMap::deleteAll();
    $dbResult = db_selectAllConcepts();
    print "Migrating " . mysql_num_rows($dbResult) . " concepts...\n";
    $seen = 0;
    while ($dbRow = mysql_fetch_assoc($dbResult)) {
        $concept = new Concept();
        $concept->populateFromDbRow($dbRow);
        $words = Word::loadByConceptId($concept->id);
        $definitions = Definition::loadByConceptId($concept->id);
        if ($definitions) {
            // Select distinct words
            $distinctWords = array();
            foreach ($words as $word) {
                $distinctWords[$word->name] = 1;
            }
            // For every word, look up all the lexems. Then map each of those lexems
            // to every definition.
            foreach ($distinctWords as $word => $ignored) {
                $lexems = Lexem::loadByUnaccented($word);
                // Create lexem if necessary so that we don't lose any words during the
                // migration
                if (count($lexems) == 0) {
                    $lexem = Lexem::create($word, 'T', 1, '');
                    $lexem->save();
                    $lexem->id = db_getLastInsertedId();
                    $lexems[] = $lexem;
                    $lexem->regenerateParadigm();
                }
                foreach ($lexems as $lexem) {
                    foreach ($definitions as $definition) {
                        $ldm = LexemDefinitionMap::load($lexem->id, $definition->id);
                        if (!$ldm) {
                            $ldm = LexemDefinitionMap::create($lexem->id, $definition->id);
                            $ldm->save();
                        }
                    }
                }
            }
        }
        $seen++;
        if ($seen % 1000 == 0) {
            print "Seen: {$seen};\n";
        }
    }
    print "Seen: {$seen};\n";
}
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('definitions', function ($table) {
         $table->string('title', 255);
     });
     // Denormalize the definitions by copying the existing titles and descriptions
     foreach (\Definition::all() as $definition) {
         $source_model = new $definition->source_type();
         $source = $source_model->find($definition->source_id);
         if (!empty($source->title)) {
             $definition->title = $source->title;
         }
         if (!empty($source->description)) {
             $definition->description = $source->description;
         }
         $definition->save();
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('definition_facet_types', function ($table) {
         $table->increments('id');
         $table->string('facet_name', 255);
     });
     $facet_types = ['rights', 'keyword', 'language', 'theme', 'publisher_name'];
     $facet_type_models = [];
     foreach ($facet_types as $facet) {
         $facet_type = \FacetType::create(['facet_name' => $facet]);
         $facet_type->save();
         if ($facet != 'keyword') {
             $facet_type_model[$facet] = $facet_type;
         } else {
             $facet_type_model['keywords'] = $facet_type;
         }
     }
     Schema::create('definition_facets', function ($table) {
         $table->increments('id');
         $table->integer('definition_id');
         $table->integer('facet_id');
         $table->string('facet_name');
         $table->string('value');
     });
     // Copy all of the facet related info to the new definition_facets table
     $definitions = \Definition::all();
     foreach ($definitions as $definition) {
         foreach ($facet_type_models as $facet_name => $facet_type) {
             if ($facet_name != 'keywords' && !empty($definition->{$facet_name})) {
                 $facet = \Facet::create(['definition_id' => $definition->id, 'facet_id' => $facet_type->id, 'facet_name' => $facet_name, 'value' => $definition->{$facet_name}]);
                 $facet->save();
             } else {
                 // split the keywords
                 if (!empty($definition->keywords)) {
                     $keywords = explode(',', $definition->keywords);
                     foreach ($keywords as $keyword) {
                         $facet = \Facet::create(['definition_id' => $definition->id, 'facet_id' => $facet_type->id, 'facet_name' => 'keyword', 'value' => $keyword]);
                         $facet->save();
                     }
                 }
             }
         }
     }
 }
Пример #21
0
 /** Parses one definition line, i.e. extracts {{label}}, definition,
  * {{example|Quotation sentence.}}, creates and fills a meaning (WMeaning).
  * @param page_title    word which is described in this article 'text'
  * @param lang_section  language of this section of an article
  * @param line          definition line
  * @return WMeaning or null if the line is not started from "#" or = "# "
  */
 public static function parseOneDefinition($page_title, $lang_section, $line)
 {
     if (preg_match("/\\{\\{Нужен перевод\\}\\}/", $line)) {
         return null;
     }
     // remove empty quotations: {{пример|}} and {{пример}}
     $line = preg_replace("/\\{\\{пример\\|\\}\\}/", "", $line);
     $line = preg_replace("/\\{\\{пример\\}\\}/", "", $line);
     $line = preg_replace("/\\{\\{пример перевод\\|\\}\\}/", "", $line);
     // todo check - does exist this example
     $line = preg_replace("/\\[\\[\\]\\]/", "", $line);
     // empty definition
     $line = Definition::stripNumberSign($page_title, $line);
     if (0 == strlen($line)) {
         return null;
     }
     if (preg_match("/\\A\\{\\{морфема/", $line)) {
         return null;
     }
     // skip now, todo (parse) in future
     $label_text = LabelRu . extractLabelsTrimText(line);
     if (null == label_text) {
         return null;
     }
     /*
             $line = label_text.getText();
             
             // 2. extract text till first {{пример|
             String wiki_definition = WQuoteRu.getDefinitionBeforeFirstQuote(page_title, line);
     
             // 3. parsing wiki-text
             //StringBuffer definition = WikiWord.parseDoubleBrackets(page_title, new StringBuffer(wiki_definition));
     
             // 4. extract wiki-links (internal links)
             //WikiWord[] ww = WikiWord.getWikiWords(page_title, new StringBuffer(wiki_definition));
     
             // 5. extract quotations
             WQuote[] quote = WQuoteRu.getQuotes(page_title, line);        
     
             return new WMeaning(page_title, label_text.getLabels(), wiki_definition, quote, false);
     */
 }
 public function setPublic($boolean)
 {
     $this->changes['public'] = true;
     return parent::setPublic($boolean);
 }
Пример #23
0
 public static function searchMultipleWords($words, $hasDiacritics, $sourceId, $exclude_unofficial)
 {
     $defCounts = array();
     foreach ($words as $word) {
         $lexems = Lexem::searchInflectedForms($word, $hasDiacritics);
         if (count($lexems)) {
             $definitions = self::loadForLexems($lexems, $sourceId, $word, $exclude_unofficial);
             foreach ($definitions as $def) {
                 $defCounts[$def->id] = array_key_exists($def->id, $defCounts) ? $defCounts[$def->id] + 1 : 1;
             }
         }
     }
     arsort($defCounts);
     $result = array();
     foreach ($defCounts as $defId => $cnt) {
         if ($cnt >= 2) {
             $d = Definition::get_by_id($defId);
             if ($d) {
                 // Hidden definitions might return null
                 $result[] = $d;
             }
         }
     }
     return $result;
 }
Пример #24
0
require_once "../../phplib/util.php";
util_assertModerator(PRIV_EDIT);
util_assertNotMirror();
$reportId = util_getRequestParameter('report');
switch ($reportId) {
    case 'unassociatedLexems':
        echo count(Lexem::loadUnassociated());
        break;
    case 'unassociatedDefinitions':
        echo Definition::countUnassociated();
        break;
    case 'definitionsWithTypos':
        echo Model::factory('Typo')->select('definitionId')->distinct()->count();
        break;
    case 'temporaryDefinitions':
        echo Definition::countByStatus(ST_PENDING);
        break;
    case 'temporaryLexems':
        echo Model::factory('Lexem')->where('modelType', 'T')->count();
        break;
    case 'lexemsWithComments':
        echo Model::factory('Lexem')->where_not_equal('comment', '')->count();
        break;
    case 'lexemsWithoutAccents':
        echo Model::factory('Lexem')->where_raw("form not rlike '\\''")->where('noAccent', false)->count();
        break;
    case 'wotd':
        echo Model::factory('WordOfTheDay')->count();
        break;
    case 'definitionsWithAmbiguousAbbrev':
        echo Model::factory('Definition')->where_not_equal('status', ST_DELETED)->where('abbrevReview', ABBREV_AMBIGUOUS)->count();
Пример #25
0
// Display a custom ad 50% of the times
if (rand(0, 99) < 50) {
    AdsModule::runAllModules(null, null);
}
$widgets = Preferences::getWidgets(session_getUser());
$numEnabledWidgets = array_reduce($widgets, function ($result, $w) {
    return $result + $w['enabled'];
});
$wordCount = Definition::getWordCount();
$wordCountRough = $wordCount - $wordCount % 10000;
SmartyWrap::assign('page_title', 'Dicționar explicativ al limbii române');
SmartyWrap::assign('onHomePage', '1');
SmartyWrap::assign('letters', preg_split('//u', 'aăâbcdefghiîjklmnopqrsștțuvwxyz'));
SmartyWrap::assign('words_total', util_formatNumber($wordCount, 0));
SmartyWrap::assign('words_rough', util_formatNumber($wordCountRough, 0));
SmartyWrap::assign('words_last_month', util_formatNumber(Definition::getWordCountLastMonth(), 0));
SmartyWrap::assign('widgets', $widgets);
SmartyWrap::assign('numEnabledWidgets', $numEnabledWidgets);
/* WotD part */
$wotd = WordOfTheDay::getTodaysWord();
if (!$wotd) {
    WordOfTheDay::updateTodaysWord();
    $wotd = WordOfTheDay::getTodaysWord();
}
$defId = WordOfTheDayRel::getRefId($wotd->id);
$def = Model::factory('Definition')->where('id', $defId)->where('status', ST_ACTIVE)->find_one();
SmartyWrap::assign('thumbUrl', $wotd->getThumbUrl());
SmartyWrap::assign('title', $def->lexicon);
SmartyWrap::assign('today', date('Y/m/d'));
/* WotM part */
$wotm = WordOfTheMonth::getCurrentWotM();
Пример #26
0
<?php

require_once "../phplib/util.php";
$dbResult = db_execute("select id from Definition where sourceId = 33 and status = 0 order by id", PDO::FETCH_ASSOC);
$i = 0;
$modified = 0;
$ambiguousDefinitions = 0;
$ambiguities = 0;
foreach ($dbResult as $row) {
    $def = Definition::get_by_id($row['id']);
    $ambiguousMatches = array();
    // Remove existing hash signs
    $newRep = str_replace('#', '', $def->internalRep);
    $newRep = AdminStringUtil::internalizeDefinition($newRep, $def->sourceId, $ambiguousMatches);
    if (count($ambiguousMatches) || $newRep !== $def->internalRep) {
        print "{$def->id} {$newRep}\n";
    }
    if ($newRep !== $def->internalRep) {
        $modified++;
        $def->internalRep = $newRep;
        $def->htmlRep = AdminStringUtil::htmlize($newRep, $def->sourceId);
    }
    if (count($ambiguousMatches)) {
        $def->abbrevReview = ABBREV_AMBIGUOUS;
        $ambiguousDefinitions++;
        $ambiguities += count($ambiguousMatches);
        print "  AMBIGUOUS:";
        foreach ($ambiguousMatches as $match) {
            print " [{$match['abbrev']}]@{$match['position']}";
        }
        print "\n";
Пример #27
0
<?php

require_once "../phplib/util.php";
util_assertModerator(PRIV_EDIT);
util_assertNotMirror();
$id = util_getRequestIntParameter('id');
$def = Definition::get_by_id($id);
$recordSet = db_execute("SELECT old.Version AS OldVersion, new.Version AS NewVersion, old.ModDate AS OldDate, new.ModDate AS NewDate, old.UserId AS OldUserId, new.UserId AS NewUserId, oldUser.nick AS OldUserNick, newUser.nick AS NewUserNick, old.Status AS OldStatus, new.Status AS NewStatus, old.SourceId AS OldSourceId, new.SourceId AS NewSourceId, oldSource.shortName AS OldSourceName, newSource.shortName AS NewSourceName, old.Lexicon AS OldLexicon, new.Lexicon as NewLexicon, old.ModUserId AS OldModUserId, new.ModUserId AS NewModUserId, oldModUser.nick AS OldModUserNick, newModUser.nick AS NewModUserNick, old.InternalRep AS OldInternalRep, new.InternalRep AS NewInternalRep FROM history_Definition AS old LEFT JOIN User AS oldUser ON old.UserId = oldUser.id LEFT JOIN User AS oldModUser ON old.ModUserId = oldModUser.id LEFT JOIN Source AS oldSource ON old.SourceId = oldSource.id, history_Definition AS new LEFT JOIN User AS newUser ON new.UserId = newUser.id LEFT JOIN User AS newModUser ON new.ModUserId = newModUser.id LEFT JOIN Source AS newSource ON new.SourceId = newSource.id WHERE old.Id = new.Id AND old.Action = new.Action AND new.Version = old.Version + 1 AND old.NewDate = new.ModDate AND old.Action = 'UPDATE' AND old.Id = '{$id}' ORDER BY old.Version DESC");
$changeSets = array();
$diffs = array();
$statuses = Definition::$STATUS_NAMES;
foreach ($recordSet as $row) {
    $changeSet = $row;
    $changeSet['changesCount'] = 0;
    if ($row['OldUserId'] !== $row['NewUserId']) {
        $changeSet['changesCount']++;
    }
    if ($row['OldSourceId'] !== $row['NewSourceId']) {
        $changeSet['changesCount']++;
    }
    if ($row['OldStatus'] !== $row['NewStatus']) {
        $changeSet['OldStatusName'] = $statuses[$row['OldStatus']];
        $changeSet['NewStatusName'] = $statuses[$row['NewStatus']];
        $changeSet['changesCount']++;
    }
    if ($row['OldLexicon'] !== $row['NewLexicon']) {
        $changeSet['changesCount']++;
    }
    if ($row['OldModUserId'] !== $row['NewModUserId']) {
        $changeSet['changesCount']++;
    }
Пример #28
0
for ($d = 0; $d <= NUM_DAYS; $d++) {
    $date = date("Y-m-d", strtotime("+{$d} days"));
    // Check that exactly one WotD exists
    $wotds = WordOfTheDay::get_all_by_displayDate($date);
    if (count($wotds) != 1) {
        $messages[$date] = count($wotds) ? sprintf("Există %s cuvinte", count($wotds)) : "Nu există niciun cuvânt";
        continue;
    }
    // Check that it has exactly one WotD rel
    $rels = WordOfTheDayRel::get_all_by_wotdId($wotds[0]->id);
    if (count($rels) != 1) {
        $messages[$date] = count($rels) ? sprintf("Există %s definiții asociate", count($rels)) : "Nu există nicio definiție asociată";
        continue;
    }
    // Check that the definition exists
    $def = Definition::get_by_id($rels[0]->refId);
    if (!$def) {
        $messages[$date] = sprintf("Definiția cu id-ul %s nu există", $rels[0]->refId);
        continue;
    }
    // Check that there is an image
    if (!$wotds[0]->image) {
        $messages[$date] = sprintf("Definiția '%s' nu are o imagine asociată", $def->lexicon);
        continue;
    }
    // Check that the image file exists
    if (!$wotds[0]->imageFileExists()) {
        $messages[$date] = sprintf("Definiția '%s' are imaginea asociată '%s', dar fișierul nu există", $def->lexicon, $wotds[0]->image);
        continue;
    }
    if ($firstProblem == $d) {
Пример #29
0
<?php

require_once '../../phplib/util.php';
assert_options(ASSERT_BAIL, 1);
debug_off();
$dbResult = mysql_query("select * from lexems where lexem_id not in " . "(select LexemId from LexemDefinitionMap, Definition " . "where DefinitionId = Definition.Id " . "and SourceId not in (6, 8) and Status = 0)");
$seen = 0;
$split = 0;
while (($dbRow = mysql_fetch_assoc($dbResult)) != null) {
    $l = Lexem::createFromDbRow($dbRow);
    $defs = Definition::loadByLexemId($l->id);
    if (!count($defs)) {
        continue;
    }
    $seen++;
    // Remove the -ul accent where possible.
    if (text_endsWith($l->form, 'ul')) {
        $form = substr($l->form, 0, strlen($l->form) - 2);
        $otherLexems = Lexem::loadByForm($form);
        if (count($otherLexems)) {
            print "REMOVING -UL FROM: {$l->form}\n";
            foreach ($otherLexems as $otherLexem) {
                foreach ($defs as $def) {
                    LexemDefinitionMap::associate($otherLexem->id, $def->id);
                }
            }
            $l->delete();
            $split++;
            continue;
        }
    }
Пример #30
0
            $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);
    // Collect the positions of ambiguous abbreviations
    $matches = array();
    AdminStringUtil::markAbbreviations($def->internalRep, $def->sourceId, $matches);
    usort($matches, 'positionCmp');
    // Inject our marker around each ambiguity and htmlize the definition
    $s = $def->internalRep;
    foreach ($matches as $m) {
        $s = substr($s, 0, $m['position']) . " {$MARKER} " . substr($s, $m['position'], $m['length']) . " {$MARKER} " . substr($s, $m['position'] + $m['length']);
    }
    $s = AdminStringUtil::htmlize($s, $def->sourceId);
    // Split the definition into n ambiguities and n+1 bits of text between the ambiguities
    $text = array();
    $ambiguities = array();
    while (($p = strpos($s, $MARKER)) !== false) {
        $chunk = trim(substr($s, 0, $p));