Skip to content

Commit

Permalink
[INIT]
Browse files Browse the repository at this point in the history
  • Loading branch information
clickstorm committed May 18, 2016
0 parents commit 3af362d
Show file tree
Hide file tree
Showing 37 changed files with 1,181 additions and 0 deletions.
154 changes: 154 additions & 0 deletions Classes/Controller/YoutubeDataController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
namespace Clickstorm\CsYoutubeData\Controller;

/***************************************************************
*
* Copyright notice
*
* (c) 2014 Andreas Kirilow <[email protected]>, clickstorm GmbH
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Utility\ArrayUtility;

/**
* YoutubeDataController
*/
class YoutubeDataController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

/**
* action initialize
*
* @return void
*/
public function initializeAction() {
$this->extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['cs_youtube_data']);
}

/**
* action list
*
* @return void
*/
public function listAction() {
//Max results
$maxResults = $this->settings['maxResults'];
//APIKey String
$apiString = $this->extConf['apiKey'];
//If blank are in line
$apiArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(' ', $apiString);
//APIKey without blank in line
$apiKey = implode($apiArray);
//Channel id
$channelId = $this->settings['channelId'];
// Order settings
$order = $this->settings['order'];
//Part for Video (id,snippet,contentDetails,statistics,recordingDetails,player)
$videoUrlPart = $this->settings['videoUrlPart'];
//API url
$apiUrl = 'https://www.googleapis.com/youtube/v3/';

// get all IDs from channel videos and cast them to one string
$searchUrl = $apiUrl . 'search?';
$searchUrl .= 'order='.$order;
$searchUrl .= '&part=id';
$searchUrl .= '&channelId='.$channelId;
$searchUrl .= '&type=video';
$searchUrl .= '&maxResults='.$maxResults;
$searchUrl .= '&key='.$apiKey;

// initializes the request
$curl = curl_init();

// sets the url
curl_setopt($curl, CURLOPT_URL, $searchUrl);

// enables that curl_exec() returns content instead of status code
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// allows redirects
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);

// performs the actual request
$data = curl_exec($curl);
// destructs the request
curl_close($curl);

// this line converts the json string which is returned into a php object
$data = json_decode($data);
if(!empty($data->error)){

//Errorcode API
$errorCode = $data->error->code;
$errorCodeLanguage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_csyoutubedata_error_code', 'cs_youtube_data');

//Errormessage API
$errorMessage = $data->error->message;
$errorMessageLanguage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_csyoutubedata_error_message', 'cs_youtube_data');

//Reason API
$reason = $data->error->errors[0]->reason;
$errorReasonLanguage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_csyoutubedata_error_reason', 'cs_youtube_data');

//Error Link
$errorLinkLanguage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_csyoutubedata_error_link', 'cs_youtube_data');
$errorLink = '<a href="https://developers.google.com/youtube/v3/docs/errors" target="_blank">'.$errorLinkLanguage.'</a>';

$messageTitle = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_csyoutubedata_error', 'cs_youtube_data');
$messageBody = $errorCodeLanguage.$errorCode.'<br />'.$errorMessageLanguage.$errorMessage.'<br />'.$errorReasonLanguage.$reason.'<br />'.$errorLink;

$this->addFlashMessage(
$messageBody,
$messageTitle,
\TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR
);
}elseif(!empty($data->items)){
$items = array();

$max = sizeof($data->items);
for($i = 0; $i < $max;$i++){
$items[$i] = $data->items[$i]->id->videoId;
}

$videoIDs = implode(',',$items);

if($videoIDs) {
// get all data for the given videos by IDs
$videosUrl = $apiUrl . 'videos?';
$videosUrl .= 'part='.$videoUrlPart;
$videosUrl .= '&id='.$videoIDs;
$videosUrl .= '&key='.$apiKey;
$videos = json_decode(file_get_contents($videosUrl), true);

//Rendering
$this->view->assign('videos', $videos['items']);
}
}else{
$messageTitle = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_csyoutubedata_channel_false_check', 'cs_youtube_data');
$messageBody = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_csyoutubedata_channel_false', 'cs_youtube_data').' - '.$channelId.'!';
$this->addFlashMessage(
$messageBody,
$messageTitle,
\TYPO3\CMS\Core\Messaging\AbstractMessage::WARNING
);
}
}



}
33 changes: 33 additions & 0 deletions Classes/Helper/CsYoutubeDataWizicon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Created by PhpStorm.
* User: akirilow
* Date: 02.04.2015
* Time: 14:25
*/
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/**
* Class that adds the wizard icon.
*/
class CsYoutubeDataWizicon {

/**
* Processing the wizard items array
*
* @param array $wizardItems : The wizard items
* @return Modified array with wizard items
*/
function proc( $wizardItems ) {

$wizardItems['plugins_tx_csyoutubedata_pi1'] = array(
'icon' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('cs_youtube_data') . 'Resources/Public/Icons/wizard_icon.png',
'title' => LocalizationUtility::translate('plugin_label', 'cs_youtube_data'),
'description' => LocalizationUtility::translate('plugin_value', 'cs_youtube_data'),
'params' => '&defVals[tt_content][CType]=list&defVals[tt_content][list_type]=csyoutubedata_pi1'
);

return $wizardItems;
}

}
43 changes: 43 additions & 0 deletions Classes/ViewHelpers/ConvertDurationViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace Clickstorm\CsYoutubeData\ViewHelpers;
/**
* Created by PhpStorm.
* User: akirilow
* Date: 02.04.2015
* Time: 09:13
*/
class ConvertDurationViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

/**
*Converts the duration of Youtube Video
*
* @param int $duration
* @return string string
* @author Andreas Kirilow <[email protected]>
*/
public function render($duration) {
preg_match('#PT(.*?)H(.*?)M(.*?)S#si',$duration,$out);
if(empty($out[1])){
preg_match('#PT(.*?)M(.*?)S#si',$duration,$out);
if(empty($out[1])){
preg_match('#PT(.*?)S#si',$duration,$out);
if(empty($out[1])){
return '00:00';
}else{
if(strlen($out[1])==1){ $out[1]= '0'.$out[1]; }
return '00:'.$out[1];
}
}else{
if(strlen($out[1])==1){ $out[1]= '0'.$out[1]; }
if(strlen($out[2])==1){ $out[2]= '0'.$out[2]; }
return $out[1].':'.$out[2];
}
}else{
if(strlen($out[1])==1){ $out[1]= '0'.$out[1]; }
if(strlen($out[2])==1){ $out[2]= '0'.$out[2]; }
if(strlen($out[3])==1){ $out[3]= '0'.$out[3]; }
return $out[1].':'.$out[2].':'.$out[3];
}
}
}
?>
65 changes: 65 additions & 0 deletions Configuration/FlexForms/flexform_pi1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<T3DataStructure>
<meta>
<langDisable>1</langDisable>
<langChildren>1</langChildren>
</meta>
<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>LLL:EXT:cs_youtube_data/Resources/Private/Language/locallang.xlf:tx_csyoutubedata_flexform_sheet</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.channelId>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:cs_youtube_data/Resources/Private/Language/locallang.xlf:tx_csyoutubedata_flexform_settings.channelId</label>
<config>
<type>input</type>
</config>
</TCEforms>
</settings.channelId>
<settings.order>
<TCEforms>
<label>
LLL:EXT:cs_youtube_data/Resources/Private/Language/locallang.xlf:tx_csyoutubedata_flexform_settings.order
</label>
<config>
<type>select</type>
<items>
<numIndex index="0" type="array">
<numIndex index="0">LLL:EXT:cs_youtube_data/Resources/Private/Language/locallang.xlf:tx_csyoutubedata_flexform_settings.order.date</numIndex>
<numIndex index="1">date</numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="0">LLL:EXT:cs_youtube_data/Resources/Private/Language/locallang.xlf:tx_csyoutubedata_flexform_settings.order.viewCount</numIndex>
<numIndex index="1">viewCount</numIndex>
</numIndex>
<numIndex index="2">
<numIndex index="0">LLL:EXT:cs_youtube_data/Resources/Private/Language/locallang.xlf:tx_csyoutubedata_flexform_settings.order.rating</numIndex>
<numIndex index="1">rating</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</settings.order>
<settings.maxResults>
<TCEforms>
<exclude>1</exclude>
<label>
LLL:EXT:cs_youtube_data/Resources/Private/Language/locallang.xlf:tx_csyoutubedata_flexform_settings.maxResults
</label>
<config>
<type>input</type>
<default>5</default>
</config>
</TCEforms>
</settings.maxResults>
</el>
</ROOT>
</sDEF>
</sheets>

</T3DataStructure>
23 changes: 23 additions & 0 deletions Configuration/TypoScript/constants.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

plugin.tx_csyoutubedata {
view {
# cat=plugin.tx_csyoutubedata/file; type=string; label=Path to template root (FE)
templateRootPath = EXT:cs_youtube_data/Resources/Private/Templates/
# cat=plugin.tx_csyoutubedata/file; type=string; label=Path to template partials (FE)
partialRootPath = EXT:cs_youtube_data/Resources/Private/Partials/
# cat=plugin.tx_csyoutubedata/file; type=string; label=Path to template layouts (FE)
layoutRootPath = EXT:cs_youtube_data/Resources/Private/Layouts/
}
persistence {
# cat=plugin.tx_csyoutubedata//a; type=string; label=Default storage PID
storagePid =
}
settings {
# cat=plugin.tx_csyoutubedata//a; type=string; label=The part parameter (id, snippet, contentDetails, fileDetails, liveStreamingDetails, localizations, player, processingDetails, recordingDetails, statistics, status, suggestions, and topicDetails)
videoUrlPart = id,snippet,contentDetails,statistics,recordingDetails,player
# cat=plugin.tx_csyoutubedata//a; type=intenger; label=Width of the video in px
videoPlayerWidth = 560
# cat=plugin.tx_csyoutubedata//a; type=intenger; label=Height of the video in px
videoPlayerHeight = 315
}
}
Loading

0 comments on commit 3af362d

Please sign in to comment.