public function applyCover($teamId, $fileName, $imageType = false, $width = false, $height = false, $existingCoverDate = 0) { if (!$imageType || !$width || !$height) { $imageInfo = @getimagesize($fileName); if (!$imageInfo) { throw new Nobita_Teams_Exception_Abstract('Non-image passed in to applyCover'); } $width = $imageInfo[0]; $height = $imageInfo[1]; $imageType = $imageInfo[2]; } if (!in_array($imageType, array(IMAGETYPE_JPEG, IMAGETYPE_PNG))) { throw new Nobita_Teams_Exception_Abstract('Invalid image type passed in to applyCover'); } if (!XenForo_Image_Abstract::canResize($width, $height)) { throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('uploaded_image_is_too_big'), true); } $maxFileSize = XenForo_Application::getOptions()->Teams_coverFileSize; if ($maxFileSize && filesize($fileName) > $maxFileSize) { @unlink($fileName); throw new XenForo_Exception(new XenForo_Phrase('Teams_your_cover_file_size_large_smaller_x', array('size' => XenForo_Locale::numberFormat($maxFileSize, 'size'))), true); } if ($existingCoverDate) { $existedFile = $this->getCoverCropFilePath($teamId, $existingCoverDate); @unlink($existedFile); } $this->_witerCoverPhoto($teamId, $fileName); @unlink($fileName); $dwData = array('cover_date' => XenForo_Application::$time, 'cover_crop_details' => array('height' => $height, 'width' => $width)); $dw = XenForo_DataWriter::create('Nobita_Teams_DataWriter_Team'); $dw->setExistingData($teamId); $dw->bulkSet($dwData); $dw->save(); return $dwData; }
/** * @param int $position * @param array $options * @param string $detailedMessage * @return bool|int|string|true */ public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '') { $options['batch'] = max(1, isset($options['batch']) ? $options['batch'] : 10); /* @var sonnb_XenGallery_Model_Location $locationModel */ $locationModel = XenForo_Model::create('sonnb_XenGallery_Model_Location'); $locations = $locationModel->getLocationsWithoutCoordinate($position, $options['batch']); if (count($locations) < 1) { return true; } XenForo_Db::beginTransaction(); $db = XenForo_Application::getDb(); /** @var sonnb_XenGallery_Model_Location $locationModel */ $locationModel = XenForo_Model::create('sonnb_XenGallery_Model_Location'); foreach ($locations as $locationId => $location) { $position = $location['location_id']; try { $client = XenForo_Helper_Http::getClient($locationModel->getGeocodeUrlForAddress($location['location_name'])); $response = $client->request('GET'); $response = @json_decode($response->getBody(), true); if (empty($response['results'][0])) { continue; } $address = $response['results'][0]['formatted_address']; $lat = $response['results'][0]['geometry']['location']['lat']; $lng = $response['results'][0]['geometry']['location']['lng']; $db->update('sonnb_xengallery_location', array('location_name' => $address, 'location_lat' => $lat, 'location_lng' => $lng), array('location_id = ?' => $location['location_id'])); } catch (Exception $e) { continue; } } XenForo_Db::commit(); $detailedMessage = XenForo_Locale::numberFormat($position); return $position; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $inputHandler = new XenForo_Input($data); $input = $inputHandler->filter(array('batch' => XenForo_Input::UINT, 'start' => XenForo_Input::UINT, 'extra_data' => XenForo_Input::ARRAY_SIMPLE, 'delay' => XenForo_Input::UNUM, 'content_type' => XenForo_Input::STRING, 'delete_index' => XenForo_Input::UINT)); if ($input['delay'] >= 0.01) { usleep($input['delay'] * 1000000); } /* @var $searchModel XenForo_Model_Search */ $searchModel = XenForo_Model::create('XenForo_Model_Search'); $searchContentTypes = $searchModel->getSearchContentTypes(); $extraData = $input['extra_data']; if (!isset($extraData['content_types']) || !is_array($extraData['content_types'])) { if ($input['content_type'] && isset($searchContentTypes[$input['content_type']])) { $extraData['content_types'] = array($input['content_type']); } else { $extraData['content_types'] = array_keys($searchContentTypes); } } if (empty($extraData['current_type'])) { $extraData['current_type'] = array_shift($extraData['content_types']); } if (empty($extraData['type_start'])) { $extraData['type_start'] = 0; } $originalExtraData = $extraData; while (!isset($searchContentTypes[$extraData['current_type']])) { if (!$extraData['content_types']) { return false; } $extraData['current_type'] = array_shift($extraData['content_types']); } if ($input['delete_index']) { $source = XenForo_Search_SourceHandler_Abstract::getDefaultSourceHandler(); $source->deleteIndex($input['content_type'] ? $input['content_type'] : null); } $dataHandler = false; $searchHandler = $searchContentTypes[$extraData['current_type']]; if (class_exists($searchHandler)) { $dataHandler = XenForo_Search_DataHandler_Abstract::create($searchHandler); $indexer = new XenForo_Search_Indexer(); $indexer->setIsRebuild(true); $nextStart = $dataHandler->rebuildIndex($indexer, $extraData['type_start'], $input['batch']); $indexer->finalizeRebuildSet(); } else { $nextStart = false; } if ($nextStart === false) { // move on to next type $extraData['current_type'] = ''; $extraData['type_start'] = 0; } else { $extraData['type_start'] = $nextStart; } $data = array('batch' => $input['batch'], 'start' => $input['start'] + 1, 'extra_data' => $extraData, 'delay' => $input['delay']); $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('search_index'); $text = $dataHandler ? $dataHandler->getSearchContentTypePhrase() : new XenForo_Phrase($originalExtraData['current_type']); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, "{$text} " . XenForo_Locale::numberFormat($originalExtraData['type_start'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 70), $data); $data['batch'] = max(1, $data['batch']); /* @var $postModel XenForo_Model_Post */ $postModel = XenForo_Model::create('XenForo_Model_Post'); $postIds = $postModel->getPostIdsInRange($data['position'], $data['batch']); if (sizeof($postIds) == 0) { return true; } foreach ($postIds as $postId) { $data['position'] = $postId; /* @var $postDw XenForo_DataWriter_DiscussionMessage_Post */ $postDw = XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post', XenForo_DataWriter::ERROR_SILENT); if ($postDw->setExistingData($postId)) { XenForo_Db::beginTransaction(); $postDw->rebuildPostVerseCache(); XenForo_Db::commit(); } } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('posts'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 5, 'positionRebuild' => false), $data); $data['batch'] = max(1, $data['batch']); /* @var $mediaModel XenGallery_Model_Media */ $mediaModel = XenForo_Model::create('XenGallery_Model_Media'); /* @var $commentModel XenGallery_Model_Comment */ $commentModel = XenForo_Model::create('XenGallery_Model_Comment'); $mediaIds = $mediaModel->getMediaIdsInRange($data['position'], $data['batch'], 'all'); if (sizeof($mediaIds) == 0) { return true; } foreach ($mediaIds as $mediaId) { $conditions = array('media_id' => $mediaId); $count = $commentModel->countComments($conditions); $mediaWriter = XenForo_DataWriter::create('XenGallery_DataWriter_Media'); $mediaWriter->setExistingData($mediaId); $mediaWriter->set('comment_count', $count); $mediaWriter->save(); if ($data['positionRebuild']) { // $mediaWriter->rebuildCommentPositions(); } $data['position'] = $mediaId; } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('xengallery_rebuilding_media_comment_counts'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('userId' => null, 'cutOff' => null, 'count' => 0, 'total' => null), $data); if (!$data['userId'] || $data['cutOff'] === null) { return false; } $s = microtime(true); /* @var $editHistoryModel XenForo_Model_EditHistory */ $editHistoryModel = XenForo_Model::create('XenForo_Model_EditHistory'); $edits = $editHistoryModel->getEditHistoryByUserSinceDate($data['userId'], $data['cutOff']); if (!$edits) { return false; } if ($data['total'] === null) { $data['total'] = count($edits); } $continue = false; foreach ($edits as $edit) { $editHistoryModel->revertToHistoryId($edit['edit_history_id']); $data['count']++; if ($targetRunTime && microtime(true) - $s > $targetRunTime) { $continue = true; break; } } if (!$continue) { return false; } $actionPhrase = new XenForo_Phrase('reverting_edits'); $status = sprintf('%s... %s (%s/$s)', $actionPhrase, XenForo_Locale::numberFormat($data['count']), XenForo_Locale::numberFormat($data['total'])); return $data; }
/** * Rebuilds the data. * * @see XenForo_CacheRebuilder_Abstract::rebuild() */ public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '') { $options['batch'] = isset($options['batch']) ? $options['batch'] : 75; $options['batch'] = max(1, $options['batch']); /* @var $userModel XenForo_Model_User */ $userModel = XenForo_Model::create('XenForo_Model_User'); /* @var $conversationModel XenForo_Model_Conversation */ $conversationModel = XenForo_Model::create('XenForo_Model_Conversation'); $userIds = $userModel->getUserIdsInRange($position, $options['batch']); if (sizeof($userIds) == 0) { return true; } XenForo_Db::beginTransaction(); foreach ($userIds as $userId) { $position = $userId; /* @var $userDw XenForo_DataWriter_User */ $userDw = XenForo_DataWriter::create('XenForo_DataWriter_User', XenForo_DataWriter::ERROR_SILENT); if ($userDw->setExistingData($userId)) { $userDw->set('alerts_unread', $userModel->getUnreadAlertsCount($userId)); $userDw->set('conversations_unread', $conversationModel->countUnreadConversationsForUser($userId)); $userDw->save(); $userDw->rebuildUserGroupRelations(); $userDw->rebuildPermissionCombinationId(); $userDw->rebuildDisplayStyleGroupId(); $userDw->rebuildIdentities(); } } XenForo_Db::commit(); $detailedMessage = XenForo_Locale::numberFormat($position); return $position; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 10), $data); $data['batch'] = max(1, $data['batch']); /* @var $albumModel XenGallery_Model_Album */ $albumModel = XenForo_Model::create('XenGallery_Model_Album'); $albumIds = $albumModel->getSharedAlbumIdsInRange($data['position'], $data['batch']); if (sizeof($albumIds) == 0) { return true; } $db = XenForo_Application::getDb(); XenForo_Db::beginTransaction($db); foreach ($albumIds as $albumId) { $data['position'] = $albumId; $album = $albumModel->getAlbumByIdSimple($albumId); $bind = array($album['album_id'], $album['album_user_id']); $ownerShared = $db->fetchOne('SELECT shared_user_id FROM xengallery_shared_map WHERE album_id = ? AND shared_user_id = ?', $bind); if (!$ownerShared) { $db->query(' INSERT IGNORE INTO xengallery_shared_map (album_id, shared_user_id) VALUES (?, ?) ', $bind); } } XenForo_Db::commit($db); $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('xengallery_album_permissions'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
/** * Rebuilds the data. * * @see XenForo_CacheRebuilder_Abstract::rebuild() */ public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '') { $options['batch'] = max(1, isset($options['batch']) ? $options['batch'] : 10); $socialForumModel = ThemeHouse_SocialGroups_SocialForum::getSocialForumModel(); if ($position == 0) { $socialForumModel->unlinkMovedThreads(); } $socialForums = $socialForumModel->getSocialForums(array(), array('limit' => $options['batch'], 'offset' => $position)); XenForo_Db::beginTransaction(); foreach ($socialForums as $socialForum) { $position++; /* @var $socialForumDw ThemeHouse_SocialGroups_DataWriter_SocialForum */ $socialForumDw = XenForo_DataWriter::create('ThemeHouse_SocialGroups_DataWriter_SocialForum', XenForo_DataWriter::ERROR_SILENT); if ($socialForumDw->setExistingData($socialForum, true)) { $socialForumDw->rebuildCounters(); $socialForumDw->save(); } } XenForo_Db::commit(); $detailedMessage = XenForo_Locale::numberFormat($position); if (!$socialForums) { return true; } else { return $position; } }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('userGroupId' => 0, 'displayPriority' => 0, 'count' => 0), $data); if (!$data['userGroupId']) { return false; } $s = microtime(true); /* @var $groupModel XenForo_Model_UserGroup */ $groupModel = XenForo_Model::create('XenForo_Model_UserGroup'); $limit = 100; do { $results = $groupModel->removeUserGroupFromUsers($data['userGroupId'], XenForo_Model_User::$defaultRegisteredGroupId, $limit); if (!$results[0] && !$results[1]) { $groupModel->recalculateUserGroupDisplayStylePriority($data['userGroupId'], $data['displayPriority'], -1); $groupModel->rebuildDisplayStyleCache(); $groupModel->rebuildUserBannerCache(); return false; } $data['count'] += $limit; } while ($targetRunTime && microtime(true) - $s < $targetRunTime); $actionPhrase = new XenForo_Phrase('deleting'); $typePhrase = new XenForo_Phrase('user_group'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['count'])); return $data; }
/** * Rebuilds the data. * * @see XenForo_CacheRebuilder_Abstract::rebuild() */ public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '') { $options = array_merge(array('batch' => 100, 'positionRebuild' => false), $options); /* @var $threadModel XenForo_Model_Thread */ $threadModel = XenForo_Model::create('XenForo_Model_Thread'); $threadIds = $threadModel->getThreadIdsInRange($position, $options['batch']); if (sizeof($threadIds) == 0) { return true; } XenForo_Db::beginTransaction(); foreach ($threadIds as $threadId) { $position = $threadId; $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT); if ($dw->setExistingData($threadId)) { $dw->setOption(XenForo_DataWriter_Discussion::OPTION_UPDATE_CONTAINER, false); if ($options['positionRebuild']) { $dw->rebuildDiscussion(); } else { $dw->rebuildDiscussionCounters(); } $dw->save(); } } XenForo_Db::commit(); $detailedMessage = XenForo_Locale::numberFormat($position); return $position; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('batch' => 100, 'position' => 0, 'positionRebuild' => false), $data); /* @var $threadModel XenForo_Model_Thread */ $threadModel = XenForo_Model::create('XenForo_Model_Thread'); $threadIds = $threadModel->getThreadIdsInRange($data['position'], $data['batch']); if (sizeof($threadIds) == 0) { return false; } $forums = XenForo_Model::create('XenForo_Model_Forum')->getForumsByThreadIds($threadIds); foreach ($threadIds as $threadId) { $data['position'] = $threadId; $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT); if ($dw->setExistingData($threadId)) { $dw->setOption(XenForo_DataWriter_Discussion::OPTION_UPDATE_CONTAINER, false); if (isset($forums[$dw->get('node_id')])) { $dw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forums[$dw->get('node_id')]); } if ($data['positionRebuild']) { $dw->rebuildDiscussion(); } else { $dw->rebuildDiscussionCounters(); } $dw->save(); } } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('threads'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('batch' => 10, 'position' => 0, 'positionRebuild' => false), $data); /* @var sonnb_XenGallery_Model_Location $locationModel */ $locationModel = XenForo_Model::create('sonnb_XenGallery_Model_Location'); $locations = $locationModel->getLocationsWithoutCoordinate($data['position'], $data['batch']); if (count($locations) < 1) { return false; } $db = XenForo_Application::getDb(); /** @var sonnb_XenGallery_Model_Location $locationModel */ $locationModel = XenForo_Model::create('sonnb_XenGallery_Model_Location'); foreach ($locations as $locationId => $location) { $data['position'] = $location['location_id']; try { $client = XenForo_Helper_Http::getClient($locationModel->getGeocodeUrlForAddress($location['location_name'])); $response = $client->request('GET'); $response = @json_decode($response->getBody(), true); if (empty($response['results'][0])) { continue; } $address = $response['results'][0]['formatted_address']; $lat = $response['results'][0]['geometry']['location']['lat']; $lng = $response['results'][0]['geometry']['location']['lng']; $db->update('sonnb_xengallery_location', array('location_name' => $address, 'location_lat' => $lat, 'location_lng' => $lng), array('location_id = ?' => $location['location_id'])); } catch (Exception $e) { continue; } } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('sonnb_xengallery_location'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
/** * Formats the given number for a currency. * * @param float|integer $number Number to format * @param int|null $currencyId Currency to override default * * @return string Formatted number */ public static function currencyFormat($number = 0) { $currency = array('symbol_left' => '', 'symbol_right' => ' VNĐ', 'value' => 1, 'decimal_place' => 0); $negative = false; $formated = ''; if (is_numeric($number)) { if ($number < 0) { $negative = true; $number *= -1; } $number *= $currency['value']; $number = XenForo_Locale::numberFormat($number, $currency['decimal_place']); } else { $number = XenForo_Locale::numberFormat(0, $currency['decimal_place']); } $formated = $negative ? ' - ' : ''; if ($currency['symbol_left']) { $formated .= $currency['symbol_left']; } $formated .= $number; if ($currency['symbol_right']) { $formated .= $currency['symbol_right']; } return $formated; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 70), $data); $data['batch'] = max(1, $data['batch']); /* @var $userModel XenForo_Model_User */ $userModel = XenForo_Model::create('XenForo_Model_User'); /* @var $conversationModel XenForo_Model_Conversation */ $conversationModel = XenForo_Model::create('XenForo_Model_Conversation'); $userIds = $userModel->getUserIdsInRange($data['position'], $data['batch']); if (sizeof($userIds) == 0) { return true; } foreach ($userIds as $userId) { $data['position'] = $userId; /* @var $userDw XenForo_DataWriter_User */ $userDw = XenForo_DataWriter::create('XenForo_DataWriter_User', XenForo_DataWriter::ERROR_SILENT); if ($userDw->setExistingData($userId)) { XenForo_Db::beginTransaction(); $userDw->set('alerts_unread', $userModel->getUnreadAlertsCount($userId)); $userDw->set('conversations_unread', $conversationModel->countUnreadConversationsForUser($userId)); $userDw->save(); $userDw->rebuildUserGroupRelations(); $userDw->rebuildPermissionCombinationId(); $userDw->rebuildDisplayStyleGroupId(); $userDw->rebuildCustomFields(); $userDw->rebuildIgnoreCache(); XenForo_Db::commit(); } } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('users'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 10), $data); $data['batch'] = max(1, $data['batch']); /* @var $albumModel XenGallery_Model_Album */ $albumModel = XenForo_Model::create('XenGallery_Model_Album'); /* @var $mediaModel XenGallery_Model_Media */ $mediaModel = XenForo_Model::create('XenGallery_Model_Media'); $albumIds = $albumModel->getAlbumIdsInRange($data['position'], $data['batch']); if (sizeof($albumIds) == 0) { return true; } foreach ($albumIds as $albumId) { $data['position'] = $albumId; $writer = XenForo_DataWriter::create('XenGallery_DataWriter_Album'); $writer->setExistingData($albumId); if (!$writer->get('manual_media_cache') && !$writer->get('album_thumbnail_date')) { $media = $mediaModel->getMediaForAlbumCache($albumId); $writer->bulkSet(array('media_cache' => serialize($media))); $writer->save(); } } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('xengallery_rebuild_album_thumbnails'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 100), $data); $data['batch'] = max(1, $data['batch']); /* @var $trophyModel XenForo_Model_Trophy */ $trophyModel = XenForo_Model::create('XenForo_Model_Trophy'); $trophies = $trophyModel->getAllTrophies(); if (!$trophies) { return true; } /* @var $userModel XenForo_Model_User */ $userModel = XenForo_Model::create('XenForo_Model_User'); $userIds = $userModel->getUserIdsInRange($data['position'], $data['batch']); if (sizeof($userIds) == 0) { return true; } $data['position'] = end($userIds); $users = $userModel->getUsers(array('user_state' => 'valid', 'is_banned' => 0, 'user_id' => $userIds), array('join' => XenForo_Model_User::FETCH_USER_FULL)); $userTrophies = $trophyModel->getUserTrophiesByUserIds(array_keys($users)); foreach ($users as $user) { $trophyModel->updateTrophiesForUser($user, isset($userTrophies[$user['user_id']]) ? $userTrophies[$user['user_id']] : array(), $trophies); $trophyModel->updateTrophyPointsForUser($user['user_id']); } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('trophies'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 100), $data); $data['batch'] = max(1, $data['batch']); if ($data['position'] == 0) { XenForo_Model::create('XenForo_Model_Node')->updateNestedSetInfo(); } /* @var $forumModel XenForo_Model_Forum */ $forumModel = XenForo_Model::create('XenForo_Model_Forum'); $forums = $forumModel->getForums(array(), array('limit' => $data['batch'], 'offset' => $data['position'])); if (!$forums) { return false; } foreach ($forums as $forum) { $data['position']++; $forumDw = XenForo_DataWriter::create('XenForo_DataWriter_Forum', XenForo_DataWriter::ERROR_SILENT); if ($forumDw->setExistingData($forum, true)) { $forumDw->rebuildCounters(); $forumDw->save(); } } $rbPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('forums'); $status = sprintf('%s... %s (%s)', $rbPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
/** * Rebuilds the data. * * @see XenForo_CacheRebuilder_Abstract::rebuild() */ public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '') { $options['batch'] = max(1, isset($options['batch']) ? $options['batch'] : 10); if ($position == 0) { XenForo_Model::create('XenForo_Model_Node')->updateNestedSetInfo(); } /* @var $forumModel XenForo_Model_Forum */ $forumModel = XenForo_Model::create('XenForo_Model_Forum'); $forums = $forumModel->getForums(array(), array('limit' => $options['batch'], 'offset' => $position)); XenForo_Db::beginTransaction(); foreach ($forums as $forum) { $position++; $forumDw = XenForo_DataWriter::create('XenForo_DataWriter_Forum', XenForo_DataWriter::ERROR_SILENT); if ($forumDw->setExistingData($forum, true)) { $forumDw->rebuildCounters(); $forumDw->save(); } } XenForo_Db::commit(); $detailedMessage = XenForo_Locale::numberFormat($position); if (!$forums) { return true; } else { return $position; } }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 70), $data); $data['batch'] = max(1, $data['batch']); /* @var $userModel XenForo_Model_User */ $userModel = XenForo_Model::create('XenForo_Model_User'); /* @var $conversationModel XenForo_Model_Conversation */ $conversationModel = XenForo_Model::create('XenForo_Model_Conversation'); $userIds = $userModel->getUserIdsInRange($data['position'], $data['batch']); if (sizeof($userIds) == 0) { return true; } foreach ($userIds as $userId) { $data['position'] = $userId; $userWriter = XenForo_DataWriter::create('XenForo_DataWriter_User'); $userWriter->setExistingData($userId); $user = $userWriter->getMergedData(); $leecherLevel = $userModel->calculateLeecherLevel($user); if ($leecherLevel !== false) { $userWriter->set('leecher_level_unknown', 0); $userWriter->set('leecher_level', $leecherLevel); } else { $userWriter->set('leecher_level_unknown', 1); $userWriter->set('leecher_level', 0); } $userWriter->set('leecher_level_last_check', XenForo_Application::$time); $userWriter->save(); } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('users'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 5), $data); $data['batch'] = max(1, $data['batch']); /* @var $albumModel XenGallery_Model_Album */ $albumModel = XenForo_Model::create('XenGallery_Model_Album'); /* @var $mediaModel XenGallery_Model_Media */ $mediaModel = XenForo_Model::create('XenGallery_Model_Media'); $albumIds = $albumModel->getAlbumIdsInRange($data['position'], $data['batch']); if (sizeof($albumIds) == 0) { return true; } foreach ($albumIds as $albumId) { $count = $mediaModel->countMedia(array('album_id' => $albumId)); $albumWriter = XenForo_DataWriter::create('XenGallery_DataWriter_Album'); $albumWriter->setExistingData($albumId); $albumWriter->set('album_media_count', $count); $albumWriter->save(); $data['position'] = $albumId; } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('xengallery_rebuilding_album_media_counts'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('tagId' => null, 'position' => 0, 'deleteFirst' => false), $data); if (!$data['tagId']) { return false; } $db = XenForo_Application::getDb(); $matches = $db->fetchAll("\r\n\t\t\tSELECT tag_content_id, content_type, content_id\r\n\t\t\tFROM xf_tag_content\r\n\t\t\tWHERE tag_id = ?\r\n\t\t\t\tAND tag_content_id > ?\r\n\t\t\tORDER BY tag_content_id\r\n\t\t\tLIMIT 1000\r\n\t\t", array($data['tagId'], $data['position'])); if (!$matches) { return false; } /** @var XenForo_Model_Tag $tagModel */ $tagModel = XenForo_Model::create('XenForo_Model_Tag'); XenForo_Db::beginTransaction($db); $limitTime = $targetRunTime > 0; $s = microtime(true); foreach ($matches as $match) { $data['position'] = $match['tag_content_id']; if ($data['deleteFirst']) { $db->delete('xf_tag_content', 'tag_content_id = ' . $match['tag_content_id']); } $tagModel->rebuildTagCache($match['content_type'], $match['content_id']); if ($limitTime && microtime(true) - $s >= $targetRunTime) { break; } } XenForo_Db::commit($db); $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('tags'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { return true; $data = array_merge(array('position' => 0, 'batch' => 10), $data); $data['batch'] = max(1, $data['batch']); /* @var $feedbackModel NixFifty_XenTrader_Model_Feedback */ $feedbackModel = XenForo_Model::create('NixFifty_XenTrader_Model_Feedback'); $feedbackItems = $feedbackModel->getUserIdsInFeedbackRange($data['position'], $data['batch']); if (sizeof($feedbackItems) == 0) { return true; } $db = XenForo_Application::getDb(); XenForo_Db::beginTransaction($db); foreach ($feedbackItems as $feedbackItem) { $data['position'] = $item['media_id']; $feedbackCount = $db->fetchOne(' SELECT COUNT(*) FROM xf_nixfifty_xentrader_feedback WHERE to_user_id = ? ', $feedbackItem); $db->update('xf_nixfifty_xentrader_user', array('total' => $feedbackCount), 'user_id = ' . $db->quote($feedbackItem)); } XenForo_Db::commit($db); $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = 'fam i think im broken'; //new XenForo_Phrase('xengallery_rebuild_thumbnails'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = parent::execute($deferred, $data, $targetRunTime, $status); $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('th_user_promotions_userpromotions'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('batch' => 100, 'position' => 0), $data); /* @var $attachmentModel XenForo_Model_Attachment */ $attachmentModel = XenForo_Model::create('XenForo_Model_Attachment'); $s = microtime(true); $dataIds = $attachmentModel->getAttachmentDataIdsInRange($data['position'], $data['batch']); if (sizeof($dataIds) == 0) { return false; } foreach ($dataIds as $dataId) { $data['position'] = $dataId; $dw = XenForo_DataWriter::create('XenForo_DataWriter_AttachmentData', XenForo_DataWriter::ERROR_SILENT); if ($dw->setExistingData($dataId) && $dw->get('width') && XenForo_Image_Abstract::canResize($dw->get('width'), $dw->get('height'))) { $attach = $dw->getMergedData(); $attachFile = $attachmentModel->getAttachmentDataFilePath($attach); $imageInfo = @getimagesize($attachFile); if ($imageInfo) { try { $image = XenForo_Image_Abstract::createFromFile($attachFile, $imageInfo[2]); } catch (Exception $e) { XenForo_Error::logException($e, false, "Thumbnail rebuild error {$attachFile}: "); continue; } if ($image) { if ($image->thumbnail(XenForo_Application::get('options')->attachmentThumbnailDimensions)) { ob_start(); $image->output($imageInfo[2]); $thumbData = ob_get_contents(); ob_end_clean(); } else { // no resize necessary, use the original $thumbData = file_get_contents($attachFile); } $dw->set('thumbnail_width', $image->getWidth()); $dw->set('thumbnail_height', $image->getHeight()); $dw->setExtraData(XenForo_DataWriter_AttachmentData::DATA_THUMB_DATA, $thumbData); try { $dw->save(); } catch (Exception $e) { XenForo_Error::logException($e, false, "Thumb rebuild for #{$dataId}: "); } unset($image); } } } if ($targetRunTime && microtime(true) - $s > $targetRunTime) { break; } } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('attachment_thumbnails'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 10), $data); $data['batch'] = max(1, $data['batch']); /* @var $mediaModel XenGallery_Model_Media */ $mediaModel = XenForo_Model::create('XenGallery_Model_Media'); /* @var $attachmentModel XenForo_Model_Attachment */ $attachmentModel = XenForo_Model::create('XenForo_Model_Attachment'); $watermarkModel = $this->_getWatermarkModel(); if (!$this->_db) { $this->_db = XenForo_Application::getDb(); } $mediaIds = $mediaModel->getMediaIdsInRange($data['position'], $data['batch']); if (sizeof($mediaIds) == 0) { return true; } $options = XenForo_Application::getOptions(); $fetchOptions = array('join' => XenGallery_Model_Media::FETCH_ATTACHMENT); $media = $mediaModel->getMediaByIds($mediaIds, $fetchOptions); $media = $mediaModel->prepareMediaItems($media); foreach ($media as $item) { $data['position'] = $item['media_id']; if (empty($item['watermark_id'])) { continue; } try { $attachment = $attachmentModel->getAttachmentById($item['attachment_id']); $originalPath = $mediaModel->getOriginalDataFilePath($attachment, true); $filePath = $attachmentModel->getAttachmentDataFilePath($attachment); $watermarkPath = $watermarkModel->getWatermarkFilePath($item['watermark_id']); if (XenForo_Helper_File::createDirectory(dirname($originalPath), true)) { $image = new XenGallery_Helper_Image($originalPath); $watermark = new XenGallery_Helper_Image($watermarkPath); $watermark->resize($image->getWidth() / 100 * $options->xengalleryWatermarkDimensions['width'], $image->getHeight() / 100 * $options->xengalleryWatermarkDimensions['height'], 'fit'); $image->addWatermark($watermark->tmpFile); $image->writeWatermark($options->xengalleryWatermarkOpacity, $options->xengalleryWatermarkMargin['h'], $options->xengalleryWatermarkMargin['v'], $options->xengalleryWatermarkHPos, $options->xengalleryWatermarkVPos); $image->saveToPath($filePath); unset($watermark); unset($image); clearstatcache(); $this->_db->update('xf_attachment_data', array('file_size' => filesize($filePath)), 'data_id = ' . $attachment['data_id']); $mediaWriter = XenForo_DataWriter::create('XenGallery_DataWriter_Media'); $mediaWriter->setExistingData($item['media_id']); $mediaWriter->set('last_edit_date', XenForo_Application::$time); $mediaWriter->save(); } } catch (Exception $e) { } } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('xengallery_rebuild_watermarks'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 10), $data); $data['batch'] = max(1, $data['batch']); /* @var $mediaModel XenGallery_Model_Media */ $mediaModel = XenForo_Model::create('XenGallery_Model_Media'); /** @var XenForo_Model_Tag $tagModel */ $tagModel = XenForo_Model::create('XenForo_Model_Tag'); $tagIds = $mediaModel->getTagIdsInRange($data['position'], $data['batch']); if (sizeof($tagIds) == 0) { return true; } $db = XenForo_Application::getDb(); foreach ($tagIds as $oldTagId) { $data['position'] = $oldTagId; $xfmgTag = $db->fetchRow('SELECT * FROM xengallery_content_tag WHERE tag_id = ?', $oldTagId); $tagMap = $db->fetchAll('SELECT * FROM xengallery_content_tag_map WHERE tag_id = ?', $oldTagId); if (!$xfmgTag || !$tagMap) { continue; } $tagId = $tagModel->createTag($xfmgTag['tag_name']); if (!$tagId) { continue; } $tag = $tagModel->getTagById($tagId); $mediaIds = array(); $media = array(); foreach ($tagMap as $tagUse) { $mediaIds[] = $tagUse['media_id']; } if ($mediaIds) { $media = $mediaModel->getMediaByIds($mediaIds); } foreach ($tagMap as $tagUse) { if (!isset($media[$tagUse['media_id']])) { continue; } $item = $media[$tagUse['media_id']]; try { $db->insert('xf_tag_content', array('content_type' => 'xengallery_media', 'content_id' => $tagUse['media_id'], 'tag_id' => $tag['tag_id'], 'add_user_id' => $item['user_id'], 'add_date' => $item['media_date'], 'visible' => $item['media_state'] == 'visible', 'content_date' => $item['media_date'])); } catch (Zend_Db_Exception $e) { continue; } $tagModel->recalculateTagUsageByContentTagged('xengallery_media', $item['media_id']); $tagModel->rebuildTagCache('xengallery_media', $item['media_id']); } } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('tags'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'batch' => 30), $data); $data['batch'] = max(1, $data['batch']); /* @var $invoiceDataModel ThemeHouse_Infusionsoft_Model_InfusionsoftApi_DataService_Invoice */ $invoiceDataModel = XenForo_Model::create('ThemeHouse_Infusionsoft_Model_InfusionsoftApi_DataService_Invoice'); $invoices = $invoiceDataModel->getInvoicesInRange($data['position'], $data['batch']); if (sizeof($invoices) == 0) { return true; } $data['position'] = $invoiceDataModel->pullInvoices($invoices, $data['position']); $actionPhrase = new XenForo_Phrase('th_synchronising_infusionsoftapi'); $typePhrase = new XenForo_Phrase('th_invoices_infusionsoftapi'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function renderJson() { $album = $this->_params['album']; if (!empty($album['likes'])) { $params = array('message' => $album, 'likesUrl' => XenForo_Link::buildPublicLink('xengallery/albums/likes', $album)); $output = $this->_renderer->getDefaultOutputArray(get_class($this), $params, 'likes_summary'); } else { $output = array('templateHtml' => '', 'js' => '', 'css' => ''); } if ($this->_params['inline']) { $likeCount = $this->_params['album']['likes']; $output += XenGallery_ViewPublic_Helper_Like::getLikeViewParams($this->_params['liked'], XenForo_Locale::numberFormat($likeCount)); } else { $output += XenForo_ViewPublic_Helper_Like::getLikeViewParams($this->_params['liked']); } return XenForo_ViewRenderer_Json::jsonEncodeForOutput($output); }
public static function likesHtml($postid, $number, $like_date = 0, array $users = array()) { $visitor = XenForo_Visitor::getInstance(); if (empty($users)) { return new XenForo_Phrase('likes_x_people_like_this', array('likes' => self::numberFormat($number), 'likesLink' => 'tt://likes/' . $postid)); } $you_like = false; if ($like_date) { $you_like = true; $visitorid = XenForo_Visitor::getUserId(); foreach ($users as $key => $user) { if ($user['user_id'] == $visitorid) { unset($users[$key]); break; } } if (count($users) == 3) { unset($users[2]); } $users = array_values($users); } $user1 = $user2 = $user3 = ''; if (isset($users[0])) { $user1 = self::helperUserName($users[0]); if (isset($users[1])) { $user2 = self::helperUserName($users[1]); if (isset($users[2])) { $user3 = self::helperUserName($users[2]); } } } $phrase_params = array('user1' => $user1, 'user2' => $user2, 'user3' => $user3, 'others' => XenForo_Locale::numberFormat($number - 3, 0, $visitor->getLanguage()), 'likesLink' => 'tt://likes/' . $postid); switch ($number) { case 1: return new XenForo_Phrase($you_like ? 'likes_you_like_this' : 'likes_user1_likes_this', $phrase_params, false); case 2: return new XenForo_Phrase($you_like ? 'likes_you_and_user1_like_this' : 'likes_user1_and_user2_like_this', $phrase_params, false); case 3: return new XenForo_Phrase($you_like ? 'likes_you_user1_and_user2_like_this' : 'likes_user1_user2_and_user3_like_this', $phrase_params, false); case 4: return new XenForo_Phrase($you_like ? 'likes_you_user1_user2_and_1_other_like_this' : 'likes_user1_user2_user3_and_1_other_like_this', $phrase_params, false); default: return new XenForo_Phrase($you_like ? 'likes_you_user1_user2_and_x_others_like_this' : 'likes_user1_user2_user3_and_x_others_like_this', $phrase_params, false); } }