Use graphqlite-like API
This commit is contained in:
parent
d5bc9ffb7c
commit
180f21e29e
7 changed files with 57 additions and 47 deletions
|
@ -4,7 +4,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shimmie2;
|
||||
|
||||
use GQLA\Expose;
|
||||
use GQLA\Type;
|
||||
use GQLA\Field;
|
||||
use GQLA\Query;
|
||||
|
||||
/**
|
||||
* Class Image
|
||||
|
@ -15,27 +17,27 @@ use GQLA\Expose;
|
|||
* image per se, but could be a video, sound file, or any
|
||||
* other supported upload type.
|
||||
*/
|
||||
#[Expose(name: "Post")]
|
||||
#[Type(name: "Post")]
|
||||
class Image
|
||||
{
|
||||
public const IMAGE_DIR = "images";
|
||||
public const THUMBNAIL_DIR = "thumbs";
|
||||
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public ?int $id = null;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public int $height = 0;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public int $width = 0;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public string $hash;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public int $filesize;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public string $filename;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
private string $ext;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
private string $mime;
|
||||
|
||||
/** @var ?string[] */
|
||||
|
@ -84,7 +86,7 @@ class Image
|
|||
}
|
||||
}
|
||||
|
||||
#[Expose(extends: "Query", name: "post_by_id")]
|
||||
#[Query(name: "post_by_id")]
|
||||
public static function by_id(int $id): ?Image
|
||||
{
|
||||
global $database;
|
||||
|
@ -154,7 +156,7 @@ class Image
|
|||
* #param string[] $tags
|
||||
* #return Image[]
|
||||
*/
|
||||
#[Expose(extends: "Query", name: "posts", type: "[Post]", args: ["tags" => "[string]"])]
|
||||
#[Query(name: "posts", type: "[Post]", args: ["tags" => "[string]"])]
|
||||
public static function find_images(?int $start = 0, ?int $limit = null, array $tags=[]): array
|
||||
{
|
||||
$result = self::find_images_internal($start, $limit, $tags);
|
||||
|
@ -360,7 +362,7 @@ class Image
|
|||
/**
|
||||
* Find the User who owns this Image
|
||||
*/
|
||||
#[Expose(name: "owner")]
|
||||
#[Field(name: "owner")]
|
||||
public function get_owner(): User
|
||||
{
|
||||
return User::by_id($this->owner_id);
|
||||
|
@ -459,9 +461,9 @@ class Image
|
|||
/**
|
||||
* Get this image's tags as an array.
|
||||
*
|
||||
* #return string[]
|
||||
* @return String[]
|
||||
*/
|
||||
#[Expose(name: "tags", type: "[string]")]
|
||||
#[Field(name: "tags", type: "[string]")]
|
||||
public function get_tag_array(): array
|
||||
{
|
||||
global $database;
|
||||
|
@ -489,7 +491,7 @@ class Image
|
|||
/**
|
||||
* Get the URL for the full size image
|
||||
*/
|
||||
#[Expose(name: "image_link")]
|
||||
#[Field(name: "image_link")]
|
||||
public function get_image_link(): string
|
||||
{
|
||||
return $this->get_link(ImageConfig::ILINK, '_images/$hash/$id%20-%20$tags.$ext', 'image/$id.$ext');
|
||||
|
@ -498,7 +500,7 @@ class Image
|
|||
/**
|
||||
* Get the nicely formatted version of the file name
|
||||
*/
|
||||
#[Expose(name: "nice_name")]
|
||||
#[Field(name: "nice_name")]
|
||||
public function get_nice_image_name(): string
|
||||
{
|
||||
$plte = new ParseLinkTemplateEvent('$id - $tags.$ext', $this);
|
||||
|
@ -509,7 +511,7 @@ class Image
|
|||
/**
|
||||
* Get the URL for the thumbnail
|
||||
*/
|
||||
#[Expose(name: "thumb_link")]
|
||||
#[Field(name: "thumb_link")]
|
||||
public function get_thumb_link(): string
|
||||
{
|
||||
global $config;
|
||||
|
@ -544,7 +546,7 @@ class Image
|
|||
* Get the tooltip for this image, formatted according to the
|
||||
* configured template.
|
||||
*/
|
||||
#[Expose(name: "tooltip")]
|
||||
#[Field(name: "tooltip")]
|
||||
public function get_tooltip(): string
|
||||
{
|
||||
global $config;
|
||||
|
@ -557,7 +559,7 @@ class Image
|
|||
* Get the info for this image, formatted according to the
|
||||
* configured template.
|
||||
*/
|
||||
#[Expose(name: "info")]
|
||||
#[Field(name: "info")]
|
||||
public function get_info(): string
|
||||
{
|
||||
global $config;
|
||||
|
|
|
@ -4,14 +4,16 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shimmie2;
|
||||
|
||||
use GQLA\Expose;
|
||||
use GQLA\Type;
|
||||
use GQLA\Field;
|
||||
use GQLA\Query;
|
||||
|
||||
#[Expose(name: "TagUsage")]
|
||||
#[Type(name: "TagUsage")]
|
||||
class TagUsage
|
||||
{
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public string $tag;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public int $uses;
|
||||
|
||||
public function __construct(string $tag, int $uses)
|
||||
|
@ -20,7 +22,7 @@ class TagUsage
|
|||
$this->uses = $uses;
|
||||
}
|
||||
|
||||
#[Expose(extends: "Query", name: "tags", type: '[TagUsage]')]
|
||||
#[Query(name: "tags", type: '[TagUsage]')]
|
||||
public static function tags(string $search, int $limit=10): array
|
||||
{
|
||||
global $cache, $database;
|
||||
|
|
|
@ -4,7 +4,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shimmie2;
|
||||
|
||||
use GQLA\Expose;
|
||||
use GQLA\Type;
|
||||
use GQLA\Field;
|
||||
use GQLA\Query;
|
||||
|
||||
function _new_user(array $row): User
|
||||
{
|
||||
|
@ -19,12 +21,12 @@ function _new_user(array $row): User
|
|||
*
|
||||
* The currently logged in user will always be accessible via the global variable $user.
|
||||
*/
|
||||
#[Expose(name: "User")]
|
||||
#[Type(name: "User")]
|
||||
class User
|
||||
{
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public int $id;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public string $name;
|
||||
public ?string $email;
|
||||
public string $join_date;
|
||||
|
@ -63,7 +65,7 @@ class User
|
|||
}
|
||||
}
|
||||
|
||||
#[Expose(extends: "Query")]
|
||||
#[Query]
|
||||
public static function me(): User
|
||||
{
|
||||
global $user;
|
||||
|
|
|
@ -4,7 +4,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shimmie2;
|
||||
|
||||
use GQLA\Expose;
|
||||
use GQLA\Type;
|
||||
use GQLA\Field;
|
||||
use GQLA\Query;
|
||||
use GQLA\Mutation;
|
||||
|
||||
require_once "vendor/ifixit/php-akismet/akismet.class.php";
|
||||
|
||||
|
@ -43,7 +46,7 @@ class CommentPostingException extends SCoreException
|
|||
{
|
||||
}
|
||||
|
||||
#[Expose(name: "Comment")]
|
||||
#[Type(name: "Comment")]
|
||||
class Comment
|
||||
{
|
||||
public ?User $owner;
|
||||
|
@ -51,12 +54,12 @@ class Comment
|
|||
public string $owner_name;
|
||||
public ?string $owner_email;
|
||||
public string $owner_class;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public string $comment;
|
||||
public int $comment_id;
|
||||
public int $image_id;
|
||||
public string $poster_ip;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public string $posted;
|
||||
|
||||
public function __construct($row)
|
||||
|
@ -83,7 +86,7 @@ class Comment
|
|||
", ["owner_id"=>$user->id]);
|
||||
}
|
||||
|
||||
#[Expose(name: "owner")]
|
||||
#[Field(name: "owner")]
|
||||
public function get_owner(): User
|
||||
{
|
||||
if (empty($this->owner)) {
|
||||
|
@ -92,13 +95,13 @@ class Comment
|
|||
return $this->owner;
|
||||
}
|
||||
|
||||
#[Expose(extends: "Post", name: "comments", type: "[Comment]")]
|
||||
#[Field(extends: "Post", name: "comments", type: "[Comment]")]
|
||||
public function get_comments(Image $post): array
|
||||
{
|
||||
return CommentList::get_comments($post->id);
|
||||
}
|
||||
|
||||
#[Expose(extends: "Mutation", name: "create_comment")]
|
||||
#[Mutation(name: "create_comment")]
|
||||
public function create_comment(int $post_id, string $comment): bool
|
||||
{
|
||||
global $user;
|
||||
|
|
|
@ -4,7 +4,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shimmie2;
|
||||
|
||||
use GQLA\Expose;
|
||||
use GQLA\Type;
|
||||
use GQLA\Field;
|
||||
use GQLA\Query;
|
||||
|
||||
class SendPMEvent extends Event
|
||||
{
|
||||
|
@ -17,21 +19,20 @@ class SendPMEvent extends Event
|
|||
}
|
||||
}
|
||||
|
||||
#[Expose]
|
||||
#[Type]
|
||||
class PM
|
||||
{
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public int $id;
|
||||
public int $from_id;
|
||||
public string $from_ip;
|
||||
public int $to_id;
|
||||
/** @var mixed */
|
||||
public $sent_date;
|
||||
#[Expose]
|
||||
public mixed $sent_date;
|
||||
#[Field]
|
||||
public string $subject;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public string $message;
|
||||
#[Expose]
|
||||
#[Field]
|
||||
public bool $is_read;
|
||||
|
||||
public function __construct($from_id=0, string $from_ip="0.0.0.0", int $to_id=0, string $subject="A Message", string $message="Some Text", bool $read=false)
|
||||
|
|
|
@ -6,5 +6,5 @@ parameters:
|
|||
- ../tests
|
||||
- ../themes/default
|
||||
ignoreErrors:
|
||||
- '#Attribute class GQLA\\Expose#'
|
||||
- '#Attribute class GQLA\\#'
|
||||
- '#Access to an undefined property Shimmie2\\Image::\$#'
|
||||
|
|
Reference in a new issue