Skip to content

Commit

Permalink
Fixed problems with empty stream field
Browse files Browse the repository at this point in the history
  • Loading branch information
GodMod committed Sep 20, 2018
1 parent a2b44ca commit 85d0f1e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 37 deletions.
4 changes: 3 additions & 1 deletion admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ public function save()
if ($objForm->error){
$this->arrData = $arrValues;
} else {

$messages = array();
// update configuration
$this->config->set($arrValues, '', 'livestreams');
// Success message
$messages[] = $this->user->lang('ls_config_saved');

$this->pdc->del_prefix('plugin.livestream.accounts.');

$this->display($messages);
}
Expand Down
78 changes: 43 additions & 35 deletions includes/livestream_helper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getStreamAccounts(){

foreach($arrUserIDs as $intUserID){

$strTwitch = $this->pdh->get('user', 'profilefield_by_name', array($intUserID, 'twitch', false, true));
$strTwitch = trim($this->pdh->get('user', 'profilefield_by_name', array($intUserID, 'twitch', false, true)));

if($strTwitch && $strTwitch != ""){

Expand All @@ -55,10 +55,16 @@ public function getStreamAccounts(){
}
}

$strAdditionalAccounts = $this->config->get('twitch_streams', 'livestreams');
$arrParts = explode("\r\n", $strAdditionalAccounts);

$strAdditionalAccounts = $this->config->get('twitch_streams', 'livestreams');
if(strlen($strAdditionalAccounts)){
$arrParts = explode("\r\n", $strAdditionalAccounts);
} else {
$arrParts = array();
}
foreach($arrParts as $strTwitch){
$strTwitch = trim($strTwitch);
if($strTwitch != "") continue;

$arrAccounts[] = array(
'username' => '',
'userlink' => '',
Expand Down Expand Up @@ -91,41 +97,43 @@ public function queryTwitch($arrAccounts){

$arrReturnData = array();

//Query User Information
$mixRequest = register('urlfetcher')->fetch('https://api.twitch.tv/helix/users?login='.implode('&login=', $arrTwitchUsers), array('Client-ID: '.$this->strTwitchClientID));

$arrUserIDToLogin = array();

if ($mixRequest){
$arrResponseData = json_decode($mixRequest, true);
foreach($arrResponseData['data'] as $arrUserData){
$arrReturnData[$arrUserData['login']] = $arrUserData;
$arrUserIDToLogin[$arrUserData['id']] = $arrUserData['login'];
if(count($arrTwitchUsers)){
//Query User Information
$mixRequest = register('urlfetcher')->fetch('https://api.twitch.tv/helix/users?login='.implode('&login=', $arrTwitchUsers), array('Client-ID: '.$this->strTwitchClientID));

$arrUserIDToLogin = array();

if ($mixRequest){
$arrResponseData = json_decode($mixRequest, true);
foreach($arrResponseData['data'] as $arrUserData){
$arrReturnData[$arrUserData['login']] = $arrUserData;
$arrUserIDToLogin[$arrUserData['id']] = $arrUserData['login'];
}
}
}

//Query Stream Information
$arrGames = array();
$mixRequest = register('urlfetcher')->fetch('https://api.twitch.tv/helix/streams?user_login='.implode('&user_login=', $arrTwitchUsers), array('Client-ID: '.$this->strTwitchClientID));
if ($mixRequest){
$arrResponseData = json_decode($mixRequest, true);
foreach($arrResponseData['data'] as $arrStreamData){
$strLoginName = $arrUserIDToLogin[$arrStreamData['user_id']];

$arrReturnData[$strLoginName]['stream_data'] = $arrStreamData;
$arrGames[$arrStreamData['game_id']] = $arrStreamData['game_id'];
//Query Stream Information
$arrGames = array();
$mixRequest = register('urlfetcher')->fetch('https://api.twitch.tv/helix/streams?user_login='.implode('&user_login=', $arrTwitchUsers), array('Client-ID: '.$this->strTwitchClientID));
if ($mixRequest){
$arrResponseData = json_decode($mixRequest, true);
foreach($arrResponseData['data'] as $arrStreamData){
$strLoginName = $arrUserIDToLogin[$arrStreamData['user_id']];
$arrReturnData[$strLoginName]['stream_data'] = $arrStreamData;
$arrGames[$arrStreamData['game_id']] = $arrStreamData['game_id'];
}
}
}

//Query Games Information
$mixRequest = register('urlfetcher')->fetch('https://api.twitch.tv/helix/games?id='.implode('&id=', $arrGames), array('Client-ID: '.$this->strTwitchClientID));
$arrGameIDs = array();
if ($mixRequest){
$arrResponseData = json_decode($mixRequest, true);

foreach($arrResponseData['data'] as $arrGameData){
$arrGameIDs[$arrGameData['id']] = $arrGameData;
//Query Games Information
$mixRequest = register('urlfetcher')->fetch('https://api.twitch.tv/helix/games?id='.implode('&id=', $arrGames), array('Client-ID: '.$this->strTwitchClientID));
$arrGameIDs = array();
if ($mixRequest){
$arrResponseData = json_decode($mixRequest, true);

foreach($arrResponseData['data'] as $arrGameData){
$arrGameIDs[$arrGameData['id']] = $arrGameData;

}
}
}

Expand Down
2 changes: 1 addition & 1 deletion livestreams_plugin_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
+--------------------------------------------------------------------------*/
class livestreams extends plugin_generic {

public $version = '1.0.0';
public $version = '1.0.1';
public $build = '';
public $copyright = 'GodMod';

Expand Down

0 comments on commit 85d0f1e

Please sign in to comment.