Skip to content

Commit

Permalink
Feed Component & Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Squarius committed Aug 16, 2016
1 parent c3b7063 commit a261c79
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 40 deletions.
1 change: 0 additions & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ public function registerComponents()
'DigitalRonin\Twitch\Components\Toplist' => 'toplist'
];
}

}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ The simplest way to add the Twitch Online Check is to use the component's defaul
If you don't like the standard template you can create your own partial in your theme. The default partial is located in `plugins/digitalronin/twitch/components/check/default.htm`.


## Toplist
## Twitch Feed
Display Twitch Channel Feed Posts on any front-end page. Add the Twitch Feed component to a page or layout. Click the added component and paste your Twitch Channel Name in the **Channel Name** field. Close the Inspector and save the page.

## Twitch Toplist
You can put the Twitch Toplist on any front-end page. Add the Twitch Toplist component to a page or layout. Click the added component and select the type you want for the Toplist and enter the limit. Close the Inspector and save the page.


Expand Down
24 changes: 14 additions & 10 deletions components/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
class Check extends ComponentBase
{
/**
* @var
* @var bool
*/
private $channelStatus;
public $channelIsOnline;

/**
* @inheritdoc
Expand Down Expand Up @@ -37,17 +37,21 @@ public function defineProperties()
}

/**
* @return bool
* @inheritdoc
*/
public function channelStatus(){
public function onRun()
{
$this->addCss('/plugins/digitalronin/twitch/assets/css/twitch.css');

if ($this->channelStatus !== NULL) {
return $this->channelStatus;
}
$this->channelIsOnline = $this->page['channelIsOnline'] = $this->getChannelStatus();
}

/**
* @return bool
*/
public function getChannelStatus()
{
$twitch = new TwitchAPI();
$this->channelStatus = $twitch->isChannelLive($this->property('channel'));

return $this->channelStatus;
return $twitch->isChannelLive($this->property('channel'));
}
}
41 changes: 20 additions & 21 deletions components/Toplist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ class Toplist extends ComponentBase
/**
* @var array
*/
protected $twitchItems;
public $twitchItems;

/**
* @var int
*/
protected $totalItems;
public $totalItems;

/**
* @var string
*/
public $toplistType;

/**
* @inheritdoc
*/
public function ComponentDetails()
{
return [
'name' => 'digitalronin.twitch::lang.component.toplist_name',
'description' => 'digitalronin.twitch::lang.component.toplist_description'
'name' => 'digitalronin.twitch::lang.toplist.name',
'description' => 'digitalronin.twitch::lang.toplist.description'
];
}

Expand All @@ -33,10 +38,10 @@ public function defineProperties()
{
return [
'toplistType' => [
'title' => 'digitalronin.twitch::lang.component.toplist_toplistType_title',
'title' => 'digitalronin.twitch::lang.toplist.type_title',
'type' => 'dropdown',
'default' => 'games',
'placeholder' => 'digitalronin.twitch::lang.component.toplist_toplistType_placeholder',
'placeholder' => 'digitalronin.twitch::lang.toplist.type_placeholder',
'options' => ['games'=>'Games', 'streams'=>'Streams']
],
'limit' => [
Expand All @@ -57,41 +62,35 @@ public function onRun()
$this->addJs('//npmcdn.com/isotope-layout@3/dist/isotope.pkgd.js');
$this->addJs('//npmcdn.com/imagesloaded@4/imagesloaded.pkgd.js');
$this->addJs('/plugins/digitalronin/twitch/assets/js/toplist.js');

$this->toplistType = $this->page['toplistType'] = $this->getToplistType();
$this->totalItems = $this->page['totalItems'] = $this->getTotalItems();
$this->twitchItems = $this->page['twitchItems'] = $this->getTwitchItems();
}

/**
* @return array
*/
public function twitchItems()
public function getTwitchItems()
{
if ($this->twitchItems !== null) {
return $this->twitchItems;
}

$twitch = new TwitchAPI();
$this->twitchItems = $twitch->getTopList( $this->property('toplistType'), $this->totalItems() );

return $this->twitchItems;
return $twitch->getTopList( $this->toplistType, $this->totalItems );
}

/**
* Total amount of Games set by the User
*
* @return int
*/
public function totalItems()
public function getTotalItems()
{
if ($this->totalItems == null) {
$this->totalItems = intval($this->property('limit'));
}

return $this->totalItems;
return intval($this->property('limit'));
}

/**
* @return string
*/
public function toplistType()
public function getToplistType()
{
return $this->property('toplistType');
}
Expand Down
2 changes: 1 addition & 1 deletion components/check/default.htm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
{% if __SELF__.channelStatus %}
{% if __SELF__.channelIsOnline %}
<span class="twitch-online twitch-dot twitch-status">Online</span>
{% else %}
<span class="twitch-offline twitch-dot twitch-status">Offline</span>
Expand Down
2 changes: 1 addition & 1 deletion components/toplist/default.htm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% if __SELF__.twitchItems %}
{% set listType = __SELF__.toplistType() %}
{% set listType = __SELF__.toplistType %}

<div class="twitch-toplist">
<h2 class="first-up">Top {{ __SELF__.totalItems }} {{ listType }}</h2><br>
Expand Down
17 changes: 12 additions & 5 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@
'name' => 'Twitch Online Check',
'description' => 'Shows if a Channel is online.'
],
'component' => [
'toplist_name' => 'Twitch Toplist',
'toplist_description' => 'Outputs a Twitch Toplist.',
'toplist_toplistType_title' => 'Toplist Type',
'toplist_toplistType_placeholder' => 'Select Toplist type',
'feed' => [
'name' => 'Twitch Feed',
'description' => 'Show Twitch Feed Posts.',
'disabled' => 'This Channel Feed is disabled.',
'posts_no_posts' => 'Show Twitch Feed Posts.',
'posts_no_posts_description' => 'Show Twitch Feed Posts.'
],
'toplist' => [
'name' => 'Twitch Toplist',
'description' => 'Outputs a Twitch Toplist.',
'type_title' => 'Toplist Type',
'type_placeholder' => 'Select Toplist type',
],
];
4 changes: 4 additions & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
1.0.1:
- Initialize plugin.
1.0.2:
- Feed Component added
- Bugfixes

0 comments on commit a261c79

Please sign in to comment.