public static function generate(array $params) { $action = Lib\Url::Get('action', null); $out = new stdClass(); $out->success = false; $user = Api\User::getCurrentUser(); if ($user) { if (self::_isFlooding($user)) { $out->message = 'You\'re doing that too fast!'; } else { switch ($action) { case 'nominate': $out = self::_nominate($user); break; case 'vote': $out = self::_vote($user); break; default: $out->message = 'No action specified'; break; } if ($out->success) { self::_setFloodMarker($user); } } } else { $out->message = 'You must be logged in'; } Lib\Display::renderJson($out); }
private static function _cropImage() { $out = new stdClass(); $out->success = false; $out->message = 'Unable to crop image'; $imageFile = Lib\Url::Post('imageFile'); $x = Lib\Url::Post('x', true); $y = Lib\Url::Post('y', true); $width = Lib\Url::Post('width', true); $height = Lib\Url::Post('height', true); if ($imageFile && null !== $x && null !== $y && null !== $width && null !== $height) { $imageFile = $imageFile[0] === '/' ? '.' . $imageFile : $imageFile; $image = Lib\ImageLoader::loadImage($imageFile); if ($image) { $image = self::_sizeUp($image->image); $croppedImage = imagecreatetruecolor(BRACKET_IMAGE_SIZE, BRACKET_IMAGE_SIZE); imagecopyresampled($croppedImage, $image, 0, 0, $x, $y, BRACKET_IMAGE_SIZE, BRACKET_IMAGE_SIZE, $width, $height); $fileName = '/cache/' . md5($imageFile) . '.jpg'; imagejpeg($croppedImage, '.' . $fileName); imagedestroy($image); imagedestroy($croppedImage); $out->success = true; $out->fileName = $fileName; } } else { $out->message = 'Parameters missing'; } Lib\Display::renderJson($out); }
public static function render() { $query = Lib\Url::Get('q'); $bracketId = Lib\Url::GetInt('bracketId'); $out = Api\MalItem::getNameTypeahead($query, 'character'); if ($bracketId) { $out = array_merge($out, self::_getSimilarCharacters($bracketId, $query)); } // Standardize the output $out = self::_standardizeData($out); Lib\Display::renderJson($out); }
private static function _updateCharacter(Api\Bracket $bracket) { $out = new stdClass(); $out->success = false; $id = Lib\Url::Post('characterId', true); $name = Lib\Url::Post('name'); $source = Lib\Url::Post('source'); $action = Lib\Url::Post('action'); if ($id && $name && $action) { $out->action = $action; $character = Api\Character::getById($id); if ($character && $character->bracketId == $bracket->id) { if ($action == 'update') { $character->name = $name; $character->source = $source; if ($character->sync()) { $out->success = true; } else { $out->message = 'Error updating database'; } } else { if ($action == 'delete') { if ($bracket->state == BS_NOMINATIONS || $bracket->state == BS_ELIMINATIONS) { if ($character->delete()) { $out->success = true; } else { $out->message = 'Delete failed'; } } else { $out->message = 'Cannot delete characters after voting has started'; } } else { $out->message = 'Unknown action'; } } } else { $out->message = 'Character does not belong to this bracket'; } } else { $out->message = 'Missing fields'; } Lib\Display::renderJson($out); }