<?php require_once "../../phplib/util.php"; util_assertModerator(PRIV_EDIT); util_assertNotMirror(); $reports = array(array('text' => 'Definiții nemoderate', 'url' => 'admin/viewPendingDefinitions', 'count' => Model::factory('Definition')->where('status', ST_PENDING)->count(), 'privilege' => PRIV_EDIT), array('text' => 'Definiții cu greșeli de tipar', 'url' => 'admin/viewTypos', 'count' => Model::factory('Typo')->select('definitionId')->distinct()->count(), 'privilege' => PRIV_EDIT), array('text' => 'Definiții cu abrevieri ambigue', 'url' => 'admin/randomAbbrevReview', 'count' => Definition::countAmbiguousAbbrevs(), 'privilege' => PRIV_EDIT), array('text' => 'Definiții OCR neverificate', 'url' => 'admin/definitionEdit', 'count' => sprintf("%d (disponibile: %d)", Model::factory('OCR')->where('status', 'raw')->count(), OCR::countAvailable(session_getUserId())), 'privilege' => PRIV_EDIT), array('text' => 'Definiții neasociate cu niciun lexem', 'url' => 'admin/viewUnassociatedDefinitions', 'count' => Definition::countUnassociated(), 'privilege' => PRIV_EDIT), array('text' => 'Lexeme neasociate cu nicio definiție', 'url' => 'admin/viewUnassociatedLexems', 'count' => Lexem::countUnassociated(), 'privilege' => PRIV_EDIT), array('text' => 'Lexeme cu comentarii', 'url' => 'admin/viewLexemsWithComments', 'count' => Model::factory('Lexem')->where_not_null('comment')->count(), 'privilege' => PRIV_EDIT), array('text' => 'Lexeme fără accent', 'url' => 'admin/viewLexemsWithoutAccents', 'count' => Model::factory('Lexem')->where('consistentAccent', 0)->count(), 'privilege' => PRIV_EDIT), array('text' => 'Lexeme ambigue', 'url' => 'admin/viewAmbiguousLexems', 'count' => 'numărătoare dezactivată', 'privilege' => PRIV_EDIT), array('text' => 'Lexeme fără paradigme', 'url' => 'admin/viewTemporaryLexems', 'count' => Model::factory('LexemModel')->where('modelType', 'T')->count(), 'privilege' => PRIV_EDIT)); SmartyWrap::assign('recentLinks', RecentLink::loadForUser()); SmartyWrap::assign("allStatuses", util_getAllStatuses()); SmartyWrap::assign('structStatusNames', Lexem::$STRUCT_STATUS_NAMES); SmartyWrap::assign('reports', $reports); SmartyWrap::assign('sectionTitle', 'Pagina moderatorului'); SmartyWrap::addCss('jqueryui', 'select2'); SmartyWrap::addJs('jquery', 'jqueryui', 'select2', 'select2Dev', 'modelDropdown'); SmartyWrap::displayAdminPage('admin/index.ihtml');
/** * Saves the data * @access protected * @return error string (empty for success) * */ protected function doSave() { if ($this->id != null) { $wotd = WordOfTheDay::get_by_id($this->id); } else { $wotd = Model::factory('WordOfTheDay')->create(); $wotd->userId = session_getUserId(); } $today = date('Y-m-d', time()); $isPast = $wotd->displayDate && $wotd->displayDate < $today; if ($isPast && $this->displayDate != $wotd->displayDate) { return 'Nu puteți modifica data pentru un cuvânt al zilei deja afișat'; } if (!$this->refId) { return 'Trebuie să alegeți o definiție'; } $wotd->displayDate = $this->displayDate ? $this->displayDate : null; $wotd->priority = $this->priority; $wotd->image = $this->image; $wotd->description = $this->description; $wotd->save(); $wotdr = WordOfTheDayRel::get_by_wotdId($wotd->id); if (!$wotdr) { $wotdr = Model::factory('WordOfTheDayRel')->create(); } $wotdr->refId = $this->refId; $wotdr->refType = $this->refType ? $this->refType : 'Definition'; $wotdr->wotdId = $wotd->id; $wotdr->save(); return ''; }
public static function loadForUser() { $userId = session_getUserId(); $recentLinks = Model::factory('RecentLink')->where('userId', $userId)->order_by_desc('visitDate')->find_many(); while (count($recentLinks) > MAX_RECENT_LINKS) { $deadLink = array_pop($recentLinks); $deadLink->delete(); } return $recentLinks; }
public static function mapDefinitionArray($definitionArray) { if (empty($definitionArray)) { return array(); } $results = array(); $defIds = array(); $sourceIds = array(); $userIds = array(); foreach ($definitionArray as $definition) { $defIds[] = $definition->id; $sourceIds[] = $definition->sourceId; $userIds[] = $definition->userId; } $userMap = self::mapById(Model::factory('User')->where_in('id', array_unique($userIds))->find_many()); $sourceMap = self::mapById(Model::factory('Source')->where_in('id', array_unique($sourceIds))->find_many()); foreach ($definitionArray as $definition) { $result = new SearchResult(); $result->definition = $definition; $result->user = $userMap[$definition->userId]; $result->source = $sourceMap[$definition->sourceId]; $result->typos = array(); $result->comment = null; $result->wotd = false; $result->bookmark = false; $results[$definition->id] = $result; } $typos = Model::factory('Typo')->where_in('definitionId', $defIds)->find_many(); foreach ($typos as $t) { $results[$t->definitionId]->typos[] = $t; } $comments = Model::factory('Comment')->where_in('definitionId', $defIds)->where('status', ST_ACTIVE)->find_many(); foreach ($comments as $c) { $results[$c->definitionId]->comment = $c; // We still run one query per comment author, but there are very few comments $results[$c->definitionId]->commentAuthor = User::get_by_id($c->userId); } if ($suid = session_getUserId()) { $defIdString = implode(',', $defIds); // This actually requires a stronger condition: that the user has PRIV_WOTD privileges; but that check would require a DB hit. // So we check that the user is logged in, which is cheap. The admin permission is checked in the template. $wotdStatuses = ORM::for_table('WordOfTheDay')->raw_query("select R.refId, W.displayDate from WordOfTheDay W join WordOfTheDayRel R on W.id = R.wotdId " . "where R.refId in ({$defIdString}) and refType = 'Definition'")->find_many(); foreach ($wotdStatuses as $w) { $results[$w->refId]->wotd = $w->displayDate ? $w->displayDate : true; } $bookmarks = Model::factory('UserWordBookmark')->where('userId', $suid)->where_in('definitionId', $defIds)->find_many(); foreach ($bookmarks as $b) { $results[$b->definitionId]->bookmark = true; } } return $results; }
static function createFromFile($fileName) { $v = Model::factory('Visual')->create(); $v->path = $fileName; $v->userId = session_getUserId(); $url = Config::get('static.url') . self::STATIC_DIR . $fileName; $dim = getimagesize($url); $v->width = $dim[0]; $v->height = $dim[1]; $v->save(); $v->createThumb(); return $v; }
if (StringUtil::isSpam($def)) { $errorMessage = 'Definiția dumneavoastră este spam.'; } } } if ($errorMessage) { smarty_assign('lexemNames', $lexemNames); smarty_assign('sourceId', $sourceId); smarty_assign('def', $def); FlashMessage::add($errorMessage); smarty_assign('previewDivContent', AdminStringUtil::htmlize($def, $sourceId)); } else { $definition = Model::factory('Definition')->create(); $definition->displayed = 0; $definition->status = ST_PENDING; $definition->userId = session_getUserId(); $definition->sourceId = $sourceId; $definition->internalRep = $def; $definition->htmlRep = AdminStringUtil::htmlize($def, $sourceId); $definition->lexicon = AdminStringUtil::extractLexicon($definition); $definition->abbrevReview = count($ambiguousMatches) ? ABBREV_AMBIGUOUS : ABBREV_REVIEW_COMPLETE; $definition->save(); log_userLog("Added definition {$definition->id} ({$definition->lexicon})"); $ldms = array(); foreach ($lexemNames as $lexemName) { $lexemName = addslashes(AdminStringUtil::formatLexem($lexemName)); if ($lexemName) { $matches = Lexem::loadByExtendedName($lexemName); if (count($matches) >= 1) { foreach ($matches as $match) { LexemDefinitionMap::associate($match->id, $definition->id);
public function save() { $this->modUserId = session_getUserId(); return parent::save(); }
function util_isModerator($type) { // Check the actual database, not the session user $userId = session_getUserId(); $user = $userId ? User::get_by_id($userId) : null; return $user ? $user->moderator & $type : false; }
<?php require_once "../../phplib/util.php"; $definitionId = util_getRequestParameter('definitionId'); $response = array(); $userId = session_getUserId(); if (!$userId) { $response['status'] = 'redirect'; $response['url'] = 'login'; echo json_encode($response); exit; } $bookmarks = UserWordBookmarkDisplayObject::getByUser($userId); if (count($bookmarks) < Config::get('global.maxBookmarks')) { $existing = Model::factory('UserWordBookmark')->where('userId', $userId)->where('definitionId', $definitionId)->find_one(); if (!$existing) { $bookmark = Model::factory('UserWordBookmark')->create(); $bookmark->userId = $userId; $bookmark->definitionId = $definitionId; $bookmark->save(); log_userLog("Added to favorites: {$bookmark->id} - the definition with the id {$bookmark->definitionId} for user {$bookmark->userId}"); } $response['status'] = 'success'; } else { $response['status'] = 'error'; $response['msg'] = 'Ați depășit limita de cuvinte favorite. Limita este ' . Config::get('global.maxBookmarks') . ' cuvinte favorite.'; } echo json_encode($response);
static function saveTree($meanings, $lexem) { $seenMeaningIds = array(); // Keep track of the previous meaning ID at each level. This allows us to populate the parentId field $meaningStack = array(); $displayOrder = 1; foreach ($meanings as $tuple) { $m = $tuple->id ? self::get_by_id($tuple->id) : Model::factory('Meaning')->create(); $m->parentId = $tuple->level ? $meaningStack[$tuple->level - 1] : 0; $m->displayOrder = $displayOrder++; $m->breadcrumb = $tuple->breadcrumb; $m->userId = session_getUserId(); $m->lexemId = $lexem->id; $m->internalRep = $tuple->internalRep; $m->htmlRep = AdminStringUtil::htmlize($m->internalRep, 0); $m->internalEtymology = $tuple->internalEtymology; $m->htmlEtymology = AdminStringUtil::htmlize($m->internalEtymology, 0); $m->internalComment = $tuple->internalComment; $m->htmlComment = AdminStringUtil::htmlize($m->internalComment, 0); $m->save(); $meaningStack[$tuple->level] = $m->id; $sourceIds = StringUtil::explode(',', $tuple->sourceIds); MeaningSource::updateList(array('meaningId' => $m->id), 'sourceId', $sourceIds); $meaningTagIds = StringUtil::explode(',', $tuple->meaningTagIds); MeaningTagMap::updateList(array('meaningId' => $m->id), 'meaningTagId', $meaningTagIds); foreach ($tuple->relationIds as $type => $lexemIdString) { if ($type) { $lexemIds = StringUtil::explode(',', $lexemIdString); Relation::updateList(array('meaningId' => $m->id, 'type' => $type), 'lexemId', $lexemIds); } } $seenMeaningIds[] = $m->id; } self::deleteNotInSet($seenMeaningIds, $lexem->id); }
function handleLexemActions() { $lexemId = util_getRequestParameter('lexemId'); $lexem = Lexem::get_by_id($lexemId); $associateDefinitionId = util_getRequestParameter('associateDefinitionId'); if ($associateDefinitionId) { LexemDefinitionMap::associate($lexem->id, $associateDefinitionId); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $dissociateDefinitionId = util_getRequestParameter('dissociateDefinitionId'); if ($dissociateDefinitionId) { LexemDefinitionMap::dissociate($lexem->id, $dissociateDefinitionId); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $createDefinition = util_getRequestParameter('createDefinition'); $miniDefTarget = util_getRequestParameter('miniDefTarget'); if ($createDefinition) { $def = Model::factory('Definition')->create(); $def->userId = session_getUserId(); $def->sourceId = Source::get_by_shortName('Neoficial')->id; $def->lexicon = $lexem->formNoAccent; $def->internalRep = '@' . mb_strtoupper(AdminStringUtil::internalize($lexem->form, false)) . '@ v. @' . $miniDefTarget . '.@'; $def->htmlRep = AdminStringUtil::htmlize($def->internalRep, $def->sourceId); $def->status = Definition::ST_ACTIVE; $def->save(); LexemDefinitionMap::associate($lexem->id, $def->id); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $deleteLexem = util_getRequestParameter('deleteLexem'); if ($deleteLexem) { $homonyms = Model::factory('Lexem')->where('formNoAccent', $lexem->formNoAccent)->where_not_equal('id', $lexem->id)->find_many(); $lexem->delete(); SmartyWrap::assign('lexem', $lexem); SmartyWrap::assign('homonyms', $homonyms); SmartyWrap::displayAdminPage('admin/lexemDeleted.tpl'); exit; } $cloneLexem = util_getRequestParameter('cloneLexem'); if ($cloneLexem) { $newLexem = $lexem->cloneLexem(); log_userLog("Cloned lexem {$lexem->id} ({$lexem->form}), new id is {$newLexem->id}"); util_redirect("lexemEdit.php?lexemId={$newLexem->id}"); } $mergeLexem = util_getRequestParameter('mergeLexem'); $mergeLexemId = util_getRequestParameter('mergeLexemId'); if ($mergeLexem) { $other = Lexem::get_by_id($mergeLexemId); if ($lexem->form != $other->form) { FlashMessage::add('Nu pot unifica lexemele deoarece accentele diferă. Rezolvați diferența și încercați din nou.'); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $defs = Definition::loadByLexemId($lexem->id); foreach ($defs as $def) { LexemDefinitionMap::associate($other->id, $def->id); } // Add lexem models from $lexem to $other if the form is the same. Exclude T-type models. $displayOrder = count($other->getLexemModels()); foreach ($lexem->getLexemModels() as $lm) { if ($lm->modelType != 'T' && !$other->hasModel($lm->modelType, $lm->modelNumber)) { $lm->lexemId = $other->id; $lm->displayOrder = ++$displayOrder; $lm->save(); } } // Add meanings from $lexem to $other and renumber their displayOrder and breadcrumb // displayOrders are generated sequentially regardless of level. // Breadcrumbs follow levels so only their first part changes. $counter = Model::factory('Meaning')->where('lexemId', $other->id)->count(); $numRoots = Model::factory('Meaning')->where('lexemId', $other->id)->where('parentId', 0)->count(); $meanings = Model::factory('Meaning')->where('lexemId', $lexem->id)->order_by_asc('displayOrder')->find_many(); foreach ($meanings as $m) { $m->lexemId = $other->id; $m->displayOrder = ++$counter; $parts = explode('.', $m->breadcrumb, 2); $parts[0] += $numRoots; $m->breadcrumb = implode('.', $parts); $m->save(); } // Add images and image tags from $lexem to $other $visuals = Visual::get_all_by_lexemeId($lexem->id); foreach ($visuals as $v) { $v->lexemeId = $other->id; $v->save(); } $visualTags = VisualTag::get_all_by_lexemeId($lexem->id); foreach ($visualTags as $vt) { $vt->lexemeId = $other->id; $vt->save(); } $lexem->delete(); util_redirect("lexemEdit.php?lexemId={$other->id}"); } }
$createDefinition = util_getRequestParameter('createDefinition'); $lexem = Lexem::get_by_id($lexemId); $oldModelType = $lexem->modelType; $oldModelNumber = $lexem->modelNumber; if ($associateDefinitionId) { LexemDefinitionMap::associate($lexem->id, $associateDefinitionId); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } if ($dissociateDefinitionId) { LexemDefinitionMap::dissociate($lexem->id, $dissociateDefinitionId); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } if ($createDefinition) { $def = Model::factory('Definition')->create(); $def->displayed = 0; $def->userId = session_getUserId(); $def->sourceId = Source::get_by_shortName('Neoficial')->id; $def->lexicon = $lexem->formNoAccent; $def->internalRep = '@' . mb_strtoupper(AdminStringUtil::internalize($lexem->form, false)) . '@ v. @' . $miniDefTarget . '.@'; $def->htmlRep = AdminStringUtil::htmlize($def->internalRep, $def->sourceId); $def->status = ST_ACTIVE; $def->save(); LexemDefinitionMap::associate($lexem->id, $def->id); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); exit; } if ($deleteLexem) { $homonyms = Model::factory('Lexem')->where('formNoAccent', $lexem->formNoAccent)->where_not_equal('id', $lexem->id)->find_many(); $lexem->delete(); smarty_assign('lexem', $lexem); smarty_assign('homonyms', $homonyms);
$commend->status = ST_ACTIVE; $comment->definitionId = $definitionId; } $newContents = AdminStringUtil::internalizeDefinition($commentContents, $sourceId); if ($newContents != $comment->contents) { $comment->contents = $newContents; $comment->htmlContents = AdminStringUtil::htmlize($comment->contents, $sourceId); if (!$preserveCommentUser) { $comment->userId = session_getUserId(); } } } else { if ($comment) { // User wiped out the existing comment, set status to DELETED. $comment->status = ST_DELETED; $comment->userId = session_getUserId(); } } if (($acceptButton || $moveButton) && !$hasErrors) { // The only difference between these two is that but_move also changes the // status to Active if ($moveButton) { $definition->status = ST_ACTIVE; } // Accept the definition and delete the typos associated with it. $definition->save(); db_execute("delete from Typo where definitionId = {$definition->id}"); if ($comment) { $comment->save(); } if ($definition->status == ST_DELETED) {
/** * Saves the data * @access protected * @return void * */ protected function doSave() { if ($this->id != null) { $wotd = WordOfTheDay::get_by_id($this->id); // $wotd->oldDefinitionId = $this->oldDefinitionId; } else { $wotd = Model::factory('WordOfTheDay')->create(); $wotd->userId = session_getUserId(); } $wotd->displayDate = $this->displayDate ? $this->displayDate : null; $wotd->priority = $this->priority; $wotd->image = $this->image; $wotd->description = $this->description; $wotd->save(); $wotdr = WordOfTheDayRel::get_by_wotdId($wotd->id); if (!$wotdr) { $wotdr = Model::factory('WordOfTheDayRel')->create(); } $wotdr->refId = $this->refId ? $this->refId : $this->oldDefinitionId; // No idea what's going on here, but this fixes it -- cata $wotdr->refType = $this->refType ? $this->refType : 'Definition'; $wotdr->wotdId = $wotd->id; $wotdr->save(); return ''; }
<?php require_once "../phplib/util.php"; util_assertModerator(PRIV_WOTD); util_assertNotMirror(); $defId = util_getRequestParameter('defId'); $status = WordOfTheDay::getStatus($defId); if (is_null($status)) { $wotd = Model::factory('WordOfTheDay')->create(); $wotd->userId = session_getUserId(); $wotd->priority = 0; $wotd->save(); $wotdr = Model::factory('WordOfTheDayRel')->create(); $wotdr->refId = $defId; $wotdr->refType = 'Definition'; $wotdr->wotdId = $wotd->id; $wotdr->save(); log_userLog("Added new word of the day: {$wotd->id} - the definition with the id {$wotdr->refId}"); } $where_to_go = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/'; header("Location: {$where_to_go}");