Skip to content

Commit

Permalink
3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chipslays committed Oct 24, 2022
1 parent e4b4496 commit aa3c393
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 40 deletions.
36 changes: 20 additions & 16 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function editAccountInfo(
* Available fields: `short_name`, `author_name`, `author_url`, `auth_url`, `page_count`.
*
* @param string|Account $accessToken [Required] Access token of the Telegraph account.
* @param array $fields [Required] List of account fields to return.
* @param string[] $fields [Required] List of account fields to return.
* @return Account
*/
public function getAccountInfo(
Expand Down Expand Up @@ -130,7 +130,7 @@ public function revokeAccessToken(string|Account $accessToken): Account
* @param string|NodeElement[] $content [Required, up to 64 KB] Content of the page.
* @param string|null $authorName [Optional, 0-128 characters] Author name, displayed below the article's title.
* @param string|null $authorUrl [Optional, 0-512 characters] Can be any link, not necessarily to a Telegram profile or channel.
* @param boolean $returnContent [Optional] If `true`, a content field will be returned in the `Page` object.
* @param bool $returnContent [Optional] If `true`, a content field will be returned in the `Page` object.
* @return Page
*/
public function createPage(
Expand Down Expand Up @@ -163,10 +163,10 @@ public function createPage(
* @param string|Account $accessToken [Required] Access token of the Telegraph account.
* @param string|Page $path [Required] Path to the Telegraph page (e.g. `http://telegra.ph/Title-12-31` or `Title-12-31`).
* @param string $title [Required, 1-256 characters] Page title.
* @param string|array $content [Required, up to 64 KB] Content of the page.
* @param string|NodeElement[] $content [Required, up to 64 KB] Content of the page.
* @param string|null $authorName [Optional, 0-128 characters] Author name, displayed below the article's title.
* @param string|null $authorUrl [Optional, 0-512 characters] Can be any link, not necessarily to a Telegram profile or channel.
* @param boolean $returnContent [Optional] If `true`, a content field will be returned in the `Page` object.
* @param bool $returnContent [Optional] If `true`, a content field will be returned in the `Page` object.
* @return Page
*/
public function editPage(
Expand Down Expand Up @@ -195,8 +195,8 @@ public function editPage(
*
* Returns a `Page` object on success.
*
* @param string $path [Required] Path to the Telegraph page (e.g. `http://telegra.ph/Title-12-31` or `Title-12-31`).
* @param boolean $returnContent [Optional] If `true`, content field will be returned in `Page` object.
* @param string|Page $path [Required] Path to the Telegraph page (e.g. `http://telegra.ph/Title-12-31` or `Title-12-31`).
* @param bool $returnContent [Optional] If `true`, content field will be returned in `Page` object.
* @return Page
*/
public function getPage(string|Page $path, bool $returnContent = false): Page
Expand All @@ -214,8 +214,8 @@ public function getPage(string|Page $path, bool $returnContent = false): Page
* Returns a `PageList` object, sorted by most recently created pages first.
*
* @param string|Account $accessToken [Required] Access token of the Telegraph account.
* @param integer $offset [Optional] Sequential number of the first page to be returned.
* @param integer $limit [Optional, 0-200] Limits the number of pages to be retrieved.
* @param int $offset [Optional] Sequential number of the first page to be returned.
* @param int $limit [Optional, 0-200] Limits the number of pages to be retrieved.
* @return PageList
*/
public function getPageList(string|Account $accessToken, int $offset = 0, int $limit = 50): PageList
Expand All @@ -233,8 +233,8 @@ public function getPageList(string|Account $accessToken, int $offset = 0, int $l
* Get a list of pages belonging to a Telegraph account by pagination.
*
* @param string|Account $accessToken
* @param integer $offset
* @param integer $limit
* @param int $offset
* @param int $limit
* @param Closure $callback
* @return void
*/
Expand Down Expand Up @@ -266,12 +266,12 @@ public function getPageListWithPagination(
*
* Returns the total number of page views.
*
* @param string $path [Required] Path to the Telegraph page (e.g. `http://telegra.ph/Title-12-31` or `Title-12-31`).
* @param integer|null $year [Required if month is passed, 2000-2100] If passed, the number of page views for the requested year will be returned.
* @param integer|null $month [Required if day is passed, 1-12] If passed, the number of page views for the requested month will be returned.
* @param integer|null $day [Required if hour is passed, 1-31] If passed, the number of page views for the requested day will be returned.
* @param integer|null $hour [Optional, 0-24] If passed, the number of page views for the requested hour will be returned.
* @return integer
* @param string|Page $path [Required] Path to the Telegraph page (e.g. `http://telegra.ph/Title-12-31` or `Title-12-31`).
* @param int|null $year [Required if month is passed, 2000-2100] If passed, the number of page views for the requested year will be returned.
* @param int|null $month [Required if day is passed, 1-12] If passed, the number of page views for the requested month will be returned.
* @param int|null $day [Required if hour is passed, 1-31] If passed, the number of page views for the requested day will be returned.
* @param int|null $hour [Optional, 0-24] If passed, the number of page views for the requested hour will be returned.
* @return int
*/
public function getViews(
string|Page $path,
Expand All @@ -291,6 +291,10 @@ public function getViews(
return $response['views'];
}

/**
* @param string|Page $path
* @return string
*/
protected function processPath(string|Page $path): string
{
if ($path instanceof Page) {
Expand Down
149 changes: 147 additions & 2 deletions src/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,154 @@
*/
class Element
{
/**
* Make <p> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function text(string|array $text): NodeElement
{
return new NodeElement('p', $text);
}

/**
* Make <b> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function boldText(string|array $text): NodeElement
{
return new NodeElement('b', $text);
}

/**
* Make <strong> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function strongText(string|array $text): NodeElement
{
return new NodeElement('strong', $text);
}

/**
* Make <i> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function italicText(string|array $text): NodeElement
{
return new NodeElement('i', $text);
}

/**
* Make <s> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function strikeText(string|array $text): NodeElement
{
return new NodeElement('s', $text);
}

/**
* Make <u> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function underlineText(string|array $text): NodeElement
{
return new NodeElement('u', $text);
}

/**
* Make <em> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function emphasizedText(string|array $text): NodeElement
{
return new NodeElement('em', $text);
}

/**
* Make <h3> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function bigHeading(string|array $text): NodeElement
{
return new NodeElement('h3', $text);
}

/**
* Make <h4> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function smallHeading(string|array $text): NodeElement
{
return new NodeElement('h4', $text);
}

/**
* Make <ul> tag.
*
* @param NodeElement[] $childrens
* @return NodeElement
*/
public static function ul(array $childrens): NodeElement
{
return new NodeElement('ul', $childrens);
}

/**
* Make <ol> tag.
*
* @param NodeElement[] $childrens
* @return NodeElement
*/
public static function ol(array $childrens): NodeElement
{
return new NodeElement('ol', $childrens);
}

/**
* Make <li> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function li(string|array $text): NodeElement
{
return new NodeElement('li', $text);
}

/**
* Make <blockquote> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function blockquote(string|array $text): NodeElement
{
return new NodeElement('blockquote', $text);
}

/**
* Make a list <ul> or <ol> with <li> items.
*
* @param string[]|NodeElement[] $items
* @param boolean $numericList
* @param bool $numericList
* @return NodeElement
*/
public static function list(array $items, $numericList = false): NodeElement
Expand All @@ -90,31 +170,67 @@ public static function list(array $items, $numericList = false): NodeElement
return $numericList ? self::ol($childrens) : self::ul($childrens);
}

/**
* Make <pre> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function pre(string|array $text): NodeElement
{
return new NodeElement('pre', $text);
}

/**
* Make <code> tag.
*
* @param string|NodeElement[] $text
* @return NodeElement
*/
public static function code(string|array $text): NodeElement
{
return new NodeElement('code', $text);
}

/**
* Make <hr> tag.
*
* @return NodeElement
*/
public static function line(): NodeElement
{
return new NodeElement('hr');
}

/**
* Make <br> tag.
*
* @return NodeElement
*/
public static function space(): NodeElement
{
return new NodeElement('br');
}

/**
* Make <a> tag.
*
* @param string|array $text
* @param string|NodeElement[] $href
* @return NodeElement
*/
public static function link(string|array $text, string $href): NodeElement
{
return new NodeElement('a', $text, compact('href'));
}

/**
* Make <img> tag.
*
* @param string $src
* @param string|null $caption
* @return NodeElement
*/
public static function image(string $src, ?string $caption = null): NodeElement
{
if (!str_starts_with($src, 'http')) {
Expand All @@ -128,11 +244,19 @@ public static function image(string $src, ?string $caption = null): NodeElement
}

return new NodeElement('figure', [
new NodeElement('div', [$image], forceTag: true),
$image,
new NodeElement('figcaption', $caption),
]);
}

/**
* Make embed iframe like youtube, vimeo, twitter, etc.
*
* @param string $vendorName
* @param string $url
* @param string $caption
* @return NodeElement
*/
public static function embed(string $vendorName, string $url, string $caption = ''): NodeElement
{
return new NodeElement('figure', [
Expand All @@ -141,16 +265,37 @@ public static function embed(string $vendorName, string $url, string $caption =
]);
}

/**
* Make Youtube video embed.
*
* @param string $video
* @param string $caption
* @return NodeElement
*/
public static function youtube(string $video, string $caption = ''): NodeElement
{
return self::embed('youtube', $video, $caption);
}

/**
* Make Vimeo video embed.
*
* @param string $video
* @param string $caption
* @return NodeElement
*/
public static function vimeo(string $video, string $caption = ''): NodeElement
{
return self::embed('vimeo', $video, $caption);
}

/**
* Make Twitter post embed.
*
* @param string $post
* @param string $caption
* @return NodeElement
*/
public static function twitter(string $post, string $caption = ''): NodeElement
{
return self::embed('twitter', $post, $caption);
Expand Down
Loading

0 comments on commit aa3c393

Please sign in to comment.