Skip to content

Commit

Permalink
Merge pull request #15 from itinerare/main
Browse files Browse the repository at this point in the history
Meta tags, misc bugfixes and changes
  • Loading branch information
itinerare authored Oct 14, 2020
2 parents a0e171b + 7cd76bf commit bc528dd
Show file tree
Hide file tree
Showing 44 changed files with 356 additions and 86 deletions.
1 change: 1 addition & 0 deletions app/Helpers/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function parse($text, &$pings = null) {
$config->set('Attr.EnableID', true);
$config->set('HTML.DefinitionID', 'include');
$config->set('HTML.DefinitionRev', 2);
$config->set('Cache.DefinitionImpl', null); // TODO: remove this later!
if ($def = $config->maybeGetRawHTMLDefinition()) {
$def->addElement('include', 'Block', 'Empty', 'Common', array('file*' => 'URI', 'height' => 'Text', 'width' => 'Text'));
$def->addAttribute('a', 'data-toggle', 'Enum#collapse,tab');
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Admin/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NewsController extends Controller
public function getIndex()
{
return view('admin.news.news', [
'newses' => News::orderBy('post_at', 'DESC')->paginate(20)
'newses' => News::orderBy('updated_at', 'DESC')->paginate(20)
]);
}

Expand Down Expand Up @@ -64,7 +64,7 @@ public function postCreateEditNews(Request $request, NewsService $service, $id =
{
$id ? $request->validate(News::$updateRules) : $request->validate(News::$createRules);
$data = $request->only([
'title', 'text', 'post_at', 'is_visible'
'title', 'text', 'post_at', 'is_visible', 'bump'
]);
if($id && $service->updateNews(News::find($id), $data, Auth::user())) {
flash('News updated successfully.')->success();
Expand Down
30 changes: 29 additions & 1 deletion app/Http/Controllers/Admin/Users/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,42 @@ class UserController extends Controller
public function getIndex(Request $request)
{
$query = User::join('ranks','users.rank_id', '=', 'ranks.id')->select('ranks.name AS rank_name', 'users.*');
$sort = $request->only(['sort']);

if($request->get('name')) $query->where(function($query) use ($request) {
$query->where('users.name', 'LIKE', '%' . $request->get('name') . '%')->orWhere('users.alias', 'LIKE', '%' . $request->get('name') . '%');
});
if($request->get('rank_id')) $query->where('rank_id', $request->get('rank_id'));

switch(isset($sort['sort']) ? $sort['sort'] : null) {
default:
$query->orderBy('ranks.sort', 'DESC')->orderBy('name');
break;
case 'alpha':
$query->orderBy('name');
break;
case 'alpha-reverse':
$query->orderBy('name', 'DESC');
break;
case 'alias':
$query->orderBy('alias', 'ASC');
break;
case 'alias-reverse':
$query->orderBy('alias', 'DESC');
break;
case 'rank':
$query->orderBy('ranks.sort', 'DESC')->orderBy('name');
break;
case 'newest':
$query->orderBy('created_at', 'DESC');
break;
case 'oldest':
$query->orderBy('created_at', 'ASC');
break;
}

return view('admin.users.index', [
'users' => $query->orderBy('ranks.sort', 'DESC')->orderBy('name')->paginate(30)->appends($request->query()),
'users' => $query->paginate(30)->appends($request->query()),
'ranks' => [0 => 'Any Rank'] + Rank::orderBy('ranks.sort', 'DESC')->pluck('name', 'id')->toArray(),
'count' => $query->count()
]);
Expand Down
56 changes: 43 additions & 13 deletions app/Http/Controllers/BrowseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,42 @@ class BrowseController extends Controller
public function getUsers(Request $request)
{
$query = User::visible()->join('ranks','users.rank_id', '=', 'ranks.id')->select('ranks.name AS rank_name', 'users.*');

$sort = $request->only(['sort']);

if($request->get('name')) $query->where(function($query) use ($request) {
$query->where('users.name', 'LIKE', '%' . $request->get('name') . '%')->orWhere('users.alias', 'LIKE', '%' . $request->get('name') . '%');
});
if($request->get('rank_id')) $query->where('rank_id', $request->get('rank_id'));

switch(isset($sort['sort']) ? $sort['sort'] : null) {
default:
$query->orderBy('ranks.sort', 'DESC')->orderBy('name');
break;
case 'alpha':
$query->orderBy('name');
break;
case 'alpha-reverse':
$query->orderBy('name', 'DESC');
break;
case 'alias':
$query->orderBy('alias', 'ASC');
break;
case 'alias-reverse':
$query->orderBy('alias', 'DESC');
break;
case 'rank':
$query->orderBy('ranks.sort', 'DESC')->orderBy('name');
break;
case 'newest':
$query->orderBy('created_at', 'DESC');
break;
case 'oldest':
$query->orderBy('created_at', 'ASC');
break;
}

return view('browse.users', [
'users' => $query->orderBy('ranks.sort', 'DESC')->orderBy('name')->paginate(30)->appends($request->query()),
'users' => $query->paginate(30)->appends($request->query()),
'ranks' => [0 => 'Any Rank'] + Rank::orderBy('ranks.sort', 'DESC')->pluck('name', 'id')->toArray(),
'blacklistLink' => Settings::get('blacklist_link')
]);
Expand Down Expand Up @@ -93,11 +121,7 @@ public function getCharacters(Request $request)
{
$query = Character::with('user.rank')->with('image.features')->with('rarity')->with('image.species')->myo(0);

$imageQuery = CharacterImage::with('features')->with('rarity')->with('species')->with('features');
if(!Auth::check() || !Auth::user()->hasPower('manage_characters')) {
$query->visible();
$imageQuery->guest();
}
$imageQuery = CharacterImage::images(Auth::check() ? Auth::user() : null)->with('features')->with('rarity')->with('species')->with('features');

if($request->get('name')) $query->where(function($query) use ($request) {
$query->where('characters.name', 'LIKE', '%' . $request->get('name') . '%')->orWhere('characters.slug', 'LIKE', '%' . $request->get('name') . '%');
Expand All @@ -109,7 +133,17 @@ public function getCharacters(Request $request)
if($request->get('sale_value_max')) $query->where('sale_value', '<=', $request->get('sale_value_max'));

if($request->get('is_trading')) $query->where('is_trading', 1);
if($request->get('is_gift_art_allowed')) $query->where('is_gift_art_allowed', 1);
if($request->get('is_gift_art_allowed')) switch($request->get('is_gift_art_allowed')) {
case 1:
$query->where('is_gift_art_allowed', 1);
break;
case 2:
$query->where('is_gift_art_allowed', 2);
break;
case 3:
$query->where('is_gift_art_allowed', 1)->orWhere('is_gift_art_allowed', 2);
break;
}
if($request->get('is_sellable')) $query->where('is_sellable', 1);
if($request->get('is_tradeable')) $query->where('is_tradeable', 1);
if($request->get('is_giftable')) $query->where('is_giftable', 1);
Expand Down Expand Up @@ -201,11 +235,7 @@ public function getMyos(Request $request)
{
$query = Character::with('user.rank')->with('image.features')->with('rarity')->with('image.species')->myo(1);

$imageQuery = CharacterImage::with('features')->with('rarity')->with('species')->with('features');
if(!Auth::check() || !Auth::user()->hasPower('manage_characters')) {
$query->visible();
$imageQuery->guest();
}
$imageQuery = CharacterImage::images(Auth::check() ? Auth::user() : null)->with('features')->with('rarity')->with('species')->with('features');

if($request->get('name')) $query->where(function($query) use ($request) {
$query->where('characters.name', 'LIKE', '%' . $request->get('name') . '%')->orWhere('characters.slug', 'LIKE', '%' . $request->get('name') . '%');
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Characters/CharacterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public function postEditCharacterProfile(Request $request, CharacterManager $ser
public function getCharacterImages($slug)
{
return view('character.images', [
'user' => Auth::check() ? Auth::user() : null,
'character' => $this->character,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NewsController extends Controller
public function getIndex()
{
if(Auth::check() && Auth::user()->is_news_unread) Auth::user()->update(['is_news_unread' => 0]);
return view('news.index', ['newses' => News::visible()->orderBy('id', 'DESC')->paginate(10)]);
return view('news.index', ['newses' => News::visible()->orderBy('updated_at', 'DESC')->paginate(10)]);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Character/Character.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ public function image()
/**
* Get all images associated with the character.
*/
public function images()
public function images($user = null)
{
return $this->hasMany('App\Models\Character\CharacterImage', 'character_id')->guest();
return $this->hasMany('App\Models\Character\CharacterImage', 'character_id')->images($user);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions app/Models/Character/CharacterDesignUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CharacterDesignupdate extends Model
'use_cropper', 'x0', 'x1', 'y0', 'y1',
'hash', 'species_id', 'subtype_id', 'rarity_id',
'has_comments', 'has_image', 'has_addons', 'has_features',
'submitted_at'
'submitted_at', 'update_type'
];

/**
Expand Down Expand Up @@ -173,7 +173,7 @@ public function scopeActive($query)
*/
public function scopeMyos($query)
{
$query->select('design_updates.*')->join('characters', 'design_updates.character_id', 'characters.id')->where('characters.is_myo_slot', 1);
$query->select('design_updates.*')->where('update_type', 'MYO');
}

/**
Expand All @@ -184,7 +184,7 @@ public function scopeMyos($query)
*/
public function scopeCharacters($query)
{
$query->select('design_updates.*')->join('characters', 'design_updates.character_id', 'characters.id')->where('characters.is_myo_slot', 0);
$query->select('design_updates.*')->where('update_type', 'Character');
}

/**********************************************************************************************
Expand Down
16 changes: 3 additions & 13 deletions app/Models/Character/CharacterImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,10 @@ public function artists()
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeGuest($query)
public function scopeImages($query, $user = null)
{
return $query->where('is_visible', 1)->orderBy('sort')->orderBy('id', 'DESC');
}

/**
* Scope a query to include images visible to staff with the required viewing powers.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeMod($query)
{
return $query->orderBy('sort')->orderBy('id', 'DESC');
if(!$user || !$user->hasPower('manage_characters')) return $query->where('is_visible', 1)->orderBy('sort')->orderBy('id', 'DESC');
else return $query->orderBy('sort')->orderBy('id', 'DESC');
}

/**********************************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion app/Models/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public function getOwnershipLogs()
{
$user = $this;
$query = UserCharacterLog::with('sender.rank')->with('recipient.rank')->with('character')->where(function($query) use ($user) {
$query->where('sender_id', $user->id)->where('log_type', '!=', 'Character Created');
$query->where('sender_id', $user->id)->whereNotIn('log_type', ['Character Created', 'MYO Slot Created', 'Character Design Updated', 'MYO Design Approved']);
})->orWhere(function($query) use ($user) {
$query->where('recipient_id', $user->id);
})->orderBy('id', 'DESC');
Expand Down
35 changes: 28 additions & 7 deletions app/Services/CharacterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ public function reuploadImage($data, $image, $user)

// Save thumbnail
if(isset($data['use_cropper'])) $this->cropThumbnail(array_only($data, ['x0','x1','y0','y1']), $image);
else $this->handleImage($data['thumbnail'], $image->thumbnailDirectory, $image->thumbnailFileName);
else $this->handleImage($data['thumbnail'], $image->thumbnailPath, $image->thumbnailFileName);

// Add a log for the character
// This logs all the updates made to the character
Expand Down Expand Up @@ -981,7 +981,7 @@ public function updateCharacterProfile($data, $character, $user, $isAdmin = fals
if($character->is_trading != isset($data['is_trading'])) $notifyTrading = true;
if($character->is_gift_art_allowed != isset($data['is_gift_art_allowed'])) $notifyGiftArt = true;

$character->is_gift_art_allowed = isset($data['is_gift_art_allowed']);
$character->is_gift_art_allowed = isset($data['is_gift_art_allowed']) && $data['is_gift_art_allowed'] <= 2 ? $data['is_gift_art_allowed'] : 0;
$character->is_trading = isset($data['is_trading']);
$character->save();
}
Expand Down Expand Up @@ -1427,14 +1427,14 @@ public function createDesignUpdateRequest($character, $user)
'character_id' => $character->id,
'status' => 'Draft',
'hash' => randomString(10),
'update_type' => $character->is_myo_slot ? 'MYO' : 'Character',

// Set some data based on the character's existing stats
'rarity_id' => $character->image->rarity_id,
'species_id' => $character->image->species_id,
'subtype_id' => $character->image->subtype_id
];


$request = CharacterDesignUpdate::create($data);

// If the character is not a MYO slot, make a copy of the previous image's traits
Expand Down Expand Up @@ -1728,6 +1728,10 @@ public function submitRequest($request)
try {
if($request->status != 'Draft') throw new \Exception("This request cannot be resubmitted to the queue.");

// Recheck and set update type, as insurance/in case of pre-existing drafts
if($request->character->is_myo_slot)
$request->update_type = 'MYO';
else $request->update_type = 'Character';
// We've done validation and all section by section,
// so it's safe to simply set the status to Pending here
$request->status = 'Pending';
Expand Down Expand Up @@ -1805,7 +1809,7 @@ public function approveRequest($data, $request, $user)
'y0' => $request->y0,
'y1' => $request->y1,
'species_id' => $request->species_id,
'subtype_id' => $request->subtype_id,
'subtype_id' => ($request->character->is_myo_slot && isset($request->character->image->subtype_id)) ? $request->character->image->subtype_id : $request->subtype_id,
'rarity_id' => $request->rarity_id,
'sort' => 0,
]);
Expand All @@ -1826,6 +1830,17 @@ public function approveRequest($data, $request, $user)
// Shift the image features over to the new image
$request->rawFeatures()->update(['character_image_id' => $image->id, 'character_type' => 'Character']);

// Make the image directory if it doesn't exist
if(!file_exists($image->imagePath))
{
// Create the directory.
if (!mkdir($image->imagePath, 0755, true)) {
$this->setError('error', 'Failed to create image directory.');
return false;
}
chmod($image->imagePath, 0755);
}

// Move the image file to the new image
File::move($request->imagePath . '/' . $request->imageFileName, $image->imagePath . '/' . $image->imageFileName);
File::move($request->thumbnailPath . '/' . $request->thumbnailFileName, $image->thumbnailPath . '/' . $image->thumbnailFileName);
Expand Down Expand Up @@ -1859,9 +1874,15 @@ public function approveRequest($data, $request, $user)
$request->character->character_image_id = $image->id;
}

// Final recheck and setting of update type, as insurance
if($request->character->is_myo_slot)
$request->update_type = 'MYO';
else $request->update_type = 'Character';
$request->save();

// Add a log for the character and user
$this->createLog($user->id, null, $request->character->user_id, $request->character->user->alias, $request->character->id, $request->character->is_myo_slot ? 'MYO Design Approved' : 'Character Design Updated', '[#'.$image->id.']', 'character');
$this->createLog($user->id, null, $request->character->user_id, $request->character->user->alias, $request->character->id, $request->character->is_myo_slot ? 'MYO Design Approved' : 'Character Design Updated', '[#'.$image->id.']', 'user');
$this->createLog($user->id, null, $request->character->user_id, $request->character->user->alias, $request->character->id, $request->update_type == 'MYO' ? 'MYO Design Approved' : 'Character Design Updated', '[#'.$image->id.']', 'character');
$this->createLog($user->id, null, $request->character->user_id, $request->character->user->alias, $request->character->id, $request->update_type == 'MYO' ? 'MYO Design Approved' : 'Character Design Updated', '[#'.$image->id.']', 'user');

// If this is for a MYO, set user's FTO status and the MYO status of the slot
if($request->character->is_myo_slot)
Expand Down Expand Up @@ -1944,7 +1965,7 @@ public function rejectRequest($data, $request, $user, $forceReject = false)
$request->save();

// Notify the user
Notifications::create('DESIGN_REJECTED', $user, [
Notifications::create('DESIGN_REJECTED', $request->user, [
'design_url' => $request->url,
'character_url' => $request->character->url,
'name' => $request->character->fullName
Expand Down
1 change: 1 addition & 0 deletions app/Services/NewsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function updateNews($news, $data, $user)
$data['parsed_text'] = parse($data['text']);
$data['user_id'] = $user->id;
if(!isset($data['is_visible'])) $data['is_visible'] = 0;
if(isset($data['bump']) && $data['is_visible'] == 1 && $data['bump'] == 1) $this->alertUsers();

$news->update($data);

Expand Down
9 changes: 5 additions & 4 deletions app/Services/RaffleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private function rollWinners($raffle)
$winner->update(['position' => $i + 1]);

// save the winning ticket's user id
if($winner->user_id) $winners['ids'][] = $winner->user_id;
if(isset($winner->user_id)) $winners['ids'][] = $winner->user_id;
else $winners['aliases'][] = $winner->alias;

// remove ticket from the ticket pool after pulled
Expand All @@ -178,13 +178,14 @@ private function rollWinners($raffle)
// remove tickets for the same user...I'm unsure how this is going to hold up with 3000 tickets,
foreach($ticketPool as $key=>$ticket)
{
if($ticket->user_id == $winner->user_id)
if(($ticket->user_id != null && $ticket->user_id == $winner->user_id) || ($ticket->user_id == null && $ticket->alias == $winner->alias))
{
$ticketPool->forget($key);
$ticketPool = $ticketPool->values();
$ticketCount--;
}

}
$ticketPool = $ticketPool->values();
$ticketCount = $ticketPool->count();
}
return $winners;
}
Expand Down
1 change: 1 addition & 0 deletions app/Services/RaffleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function updateRaffleGroup($data, $group)
DB::beginTransaction();
if(!isset($data['is_active'])) $data['is_active'] = 0;
$group->update(array_only($data, ['name', 'is_active']));
foreach($group->raffles as $raffle) $raffle->update(['is_active' => $data['is_active']]);
DB::commit();
return $group;
}
Expand Down
Loading

0 comments on commit bc528dd

Please sign in to comment.