From 0b4e75547a7505d86be2371c5ae45d4d43500546 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 11 Apr 2015 22:08:24 +0200 Subject: [PATCH] Smarty --- .gitignore | 2 + api.php | 122 +++-------------------------- common.php | 19 ++++- composer.json | 5 ++ composer.lock | 73 +++++++++++++++++ config.example.php | 1 - disabled.php | 38 ++------- download.php | 23 +++--- extractors.php | 51 ++---------- header.php | 26 ------ index.php | 54 ++----------- json.php | 1 - logo.php | 4 - maintenance.php | 32 ++------ templates/disabled.tpl | 15 ++++ templates/error.tpl | 13 +++ templates/extractors.tpl | 8 ++ footer.php => templates/footer.tpl | 19 +---- head.php => templates/head.tpl | 3 +- templates/header.tpl | 8 ++ templates/index.tpl | 24 ++++++ templates/logo.tpl | 4 + templates/maintenance.tpl | 9 +++ templates/video.tpl | 52 ++++++++++++ youtoubeur.php | 1 - 25 files changed, 276 insertions(+), 331 deletions(-) create mode 100644 composer.json create mode 100644 composer.lock delete mode 100644 header.php delete mode 100644 logo.php create mode 100644 templates/disabled.tpl create mode 100644 templates/error.tpl create mode 100644 templates/extractors.tpl rename footer.php => templates/footer.tpl (61%) rename head.php => templates/head.tpl (98%) create mode 100644 templates/header.tpl create mode 100644 templates/index.tpl create mode 100644 templates/logo.tpl create mode 100644 templates/maintenance.tpl create mode 100644 templates/video.tpl diff --git a/.gitignore b/.gitignore index fd7c5ed..7e9681b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ youtube-dl dist/ node_modules/ config.php +vendor/ +templates_c/ diff --git a/api.php b/api.php index 25c09f2..a42108f 100644 --- a/api.php +++ b/api.php @@ -10,9 +10,8 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -require_once 'config.example.php'; -@include_once 'config.php'; require_once 'common.php'; +$smarty->assign('class', 'video'); require_once 'download.php'; if (isset($_GET["url"])) { if (isset($_GET['audio'])) { @@ -68,121 +67,18 @@ if (isset($_GET["url"])) { } else { $video = VideoDownload::getJSON($_GET["url"]); if (isset($video->webpage_url)) { - include 'head.php'; - ?> - -
-
- -

You are going to download - . - Google Cast™ is disabled - Google Cast™ - Casting to ChromeCast…

- thumbnail, '" alt="" />'; - ?>
- - formats)) { - ?> -

Available formats:

-

(You might have to do a Right click > Save as)

-

- - - formats)) { - ?> - Download
- -
-
- - - - display('head.tpl'); + $smarty->assign('video', $video); + $smarty->display('video.tpl'); + $smarty->display('footer.tpl'); } else { $error=true; } } } if (isset($error)) { - include 'head.php'; - ?> - -
-
- -

An error occured

- Please check the URL of your video. -

- -
- -

-
-
- - - - display('head.tpl'); + $smarty->assign('errors', $video['error']); + $smarty->display('error.tpl'); + $smarty->display('footer.tpl'); } -?> diff --git a/common.php b/common.php index ca94951..be7d0bb 100644 --- a/common.php +++ b/common.php @@ -12,9 +12,22 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -if (DISABLED) { +require_once 'vendor/autoload.php'; +if (is_file('config.php')) { + include_once 'config.php'; +} else { + include_once 'config.example.php'; +} +define('FILENAME', basename($_SERVER["SCRIPT_FILENAME"])); +if (DISABLED && FILENAME != 'disabled.php') { header('Location: disabled.php'); exit; -} else if (MAINTENANCE) { +} else if (MAINTENANCE && FILENAME != 'maintenance.php') { header('Location: maintenance.php'); exit; } -?> +$smarty = new Smarty(); +$smarty->assign( + array( + 'base_url'=>BASE_URL, + 'convert'=>CONVERT + ) +); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..6bc30dd --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "smarty/smarty": "~3.1" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..dcb7559 --- /dev/null +++ b/composer.lock @@ -0,0 +1,73 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "b48850b7da32d0f14515a15b400da402", + "packages": [ + { + "name": "smarty/smarty", + "version": "v3.1.21", + "source": { + "type": "git", + "url": "https://github.com/smarty-php/smarty.git", + "reference": "1f878e6d746ecc8ec8d00d9c75044cf7d23ad94a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/smarty-php/smarty/zipball/1f878e6d746ecc8ec8d00d9c75044cf7d23ad94a", + "reference": "1f878e6d746ecc8ec8d00d9c75044cf7d23ad94a", + "shasum": "" + }, + "require": { + "php": ">=5.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "libs/Smarty.class.php", + "libs/SmartyBC.class.php", + "libs/sysplugins/smarty_security.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Monte Ohrt", + "email": "monte@ohrt.com" + }, + { + "name": "Uwe Tews", + "email": "uwe.tews@googlemail.com" + }, + { + "name": "Rodney Rehm", + "email": "rodney.rehm@medialize.de" + } + ], + "description": "Smarty - the compiling PHP template engine", + "homepage": "http://www.smarty.net", + "keywords": [ + "templating" + ], + "time": "2014-10-31 04:22:20" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/config.example.php b/config.example.php index 5844fa4..3858896 100644 --- a/config.example.php +++ b/config.example.php @@ -18,4 +18,3 @@ define('CONVERT', false); define('MAINTENANCE', false); define('DISABLED', false); define('BASE_URL', 'http://alltubedownload.net/'); -?> diff --git a/disabled.php b/disabled.php index 22b49e0..d7ee805 100644 --- a/disabled.php +++ b/disabled.php @@ -12,39 +12,11 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -require_once 'config.php'; +require_once 'common.php'; if (!DISABLED) { header('Location: index.php'); exit; } -require 'head.php'; -?> - - - - - -
-
-

-
- Due to various technical reasons, - we can no longer host an online version of AllTube.
- However, you are free to - - download the code - and run it on your own server. -
-
-
- - - - - - +$smarty->display('head.tpl'); +$smarty->display('header.tpl'); +$smarty->display('disabled.tpl'); +$smarty->display('footer.tpl'); diff --git a/download.php b/download.php index b0ab7d4..a7ce002 100644 --- a/download.php +++ b/download.php @@ -11,8 +11,7 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -require_once 'config.example.php'; -@include_once 'config.php'; + /** * PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/) * Main class @@ -32,7 +31,7 @@ Class VideoDownload * * @return string Version * */ - function getVersion () + function getVersion() { exec( PYTHON.' '.YOUTUBE_DL.' --version', @@ -45,7 +44,7 @@ Class VideoDownload * * @return string UA * */ - function getUA () + function getUA() { exec( PYTHON.' '.YOUTUBE_DL.' --dump-user-agent', @@ -59,7 +58,7 @@ Class VideoDownload * * @return array Extractors * */ - function listExtractors () + function listExtractors() { exec( PYTHON.' '.YOUTUBE_DL.' --list-extractors', @@ -76,7 +75,7 @@ Class VideoDownload * * @return string Filename * */ - function getFilename ($url, $format=null) + function getFilename($url, $format=null) { $cmd=PYTHON.' youtube-dl'; if (isset($format)) { @@ -97,7 +96,7 @@ Class VideoDownload * * @return string Title * */ - function getTitle ($url) + function getTitle($url) { exec( PYTHON.' '.YOUTUBE_DL.' --get-title '. @@ -116,7 +115,7 @@ Class VideoDownload * * @return string JSON * */ - function getJSON ($url, $format=null) + function getJSON($url, $format=null) { $cmd=PYTHON.' '.YOUTUBE_DL.' '.PARAMS; if (isset($format)) { @@ -141,7 +140,7 @@ Class VideoDownload * * @return string URL of image * */ - function getThumbnail ($url) + function getThumbnail($url) { exec( PYTHON.' '.YOUTUBE_DL.' --get-thumbnail '. @@ -160,7 +159,7 @@ Class VideoDownload * * @return string Title * */ - function getAvailableFormats ($url) + function getAvailableFormats($url) { exec( PYTHON.' '.YOUTUBE_DL.' -F '. @@ -191,7 +190,7 @@ Class VideoDownload * * @return string URL of video * */ - function getURL ($url, $format=null) + function getURL($url, $format=null) { $cmd=PYTHON.' '.YOUTUBE_DL; if (isset($format)) { @@ -209,5 +208,3 @@ Class VideoDownload } } - -?> diff --git a/extractors.php b/extractors.php index ca41de8..f265363 100644 --- a/extractors.php +++ b/extractors.php @@ -12,47 +12,12 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -require_once 'config.example.php'; -@include_once 'config.php'; require_once 'common.php'; -require 'head.php'; -?> - - - - - -
- - - - - -

Supported websites

- -
- - -
    - '.$extractor.''; - } - ?> -
-
-
- - - - - - +$smarty->assign('class', 'extractors'); +require_once 'download.php'; +$smarty->display('head.tpl'); +$smarty->display('header.tpl'); +$smarty->display('logo.tpl'); +$smarty->assign('extractors', VideoDownload::listExtractors()); +$smarty->display('extractors.tpl'); +$smarty->display('footer.tpl'); diff --git a/header.php b/header.php deleted file mode 100644 index 7f991fc..0000000 --- a/header.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @author Olivier Haquette - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -?> -
- -
diff --git a/index.php b/index.php index ee91bee..6be74ec 100644 --- a/index.php +++ b/index.php @@ -12,53 +12,9 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -require_once 'config.example.php'; -@include_once 'config.php'; require_once 'common.php'; -require 'head.php'; -?> - - - - - -
-
-
-
- -
- - - -
- -
-

-

-
- -
-
- See all supported websites -
-
- - - - - - +$smarty->assign('class', 'index'); +$smarty->display('head.tpl'); +$smarty->display('header.tpl'); +$smarty->display('index.tpl'); +$smarty->display('footer.tpl'); diff --git a/json.php b/json.php index a31b14b..3c02e2c 100644 --- a/json.php +++ b/json.php @@ -17,4 +17,3 @@ if (isset($_GET["url"])) { $video = VideoDownload::getJSON($_GET["url"]); echo json_encode($video); } -?> diff --git a/logo.php b/logo.php deleted file mode 100644 index 8accd3f..0000000 --- a/logo.php +++ /dev/null @@ -1,4 +0,0 @@ -

- - AllTube Download -

diff --git a/maintenance.php b/maintenance.php index 3f50ce1..fc64fec 100644 --- a/maintenance.php +++ b/maintenance.php @@ -12,33 +12,11 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -require_once 'config.php'; +require_once 'common.php'; if (!MAINTENANCE) { header('Location: index.php'); exit; } -require 'head.php'; -?> - - - - - -
-
-

-
Due to some issues with our server, - we have to disable AllTube for a few days. - Sorry for the inconvenience.
-
-
- - - - - - +$smarty->display('head.tpl'); +$smarty->display('header.tpl'); +$smarty->display('maintenance.tpl'); +$smarty->display('footer.tpl'); diff --git a/templates/disabled.tpl b/templates/disabled.tpl new file mode 100644 index 0000000..34dce16 --- /dev/null +++ b/templates/disabled.tpl @@ -0,0 +1,15 @@ +
+
+

+
+ Due to various technical reasons, + we can no longer host an online version of AllTube.
+ However, you are free to + + download the code + and run it on your own server. +
+
+
diff --git a/templates/error.tpl b/templates/error.tpl new file mode 100644 index 0000000..6756cf2 --- /dev/null +++ b/templates/error.tpl @@ -0,0 +1,13 @@ +
+
+ {include file="logo.tpl"} +

An error occured

+ Please check the URL of your video. +

+ {foreach $errors as $error} + {$error|escape} +
+ {/foreach} +

+
+
diff --git a/templates/extractors.tpl b/templates/extractors.tpl new file mode 100644 index 0000000..076f99e --- /dev/null +++ b/templates/extractors.tpl @@ -0,0 +1,8 @@ +

Supported websites

+
+
    + {foreach $extractors as $extractor} +
  • {$extractor}
  • + {/foreach} +
+
diff --git a/footer.php b/templates/footer.tpl similarity index 61% rename from footer.php rename to templates/footer.tpl index 554dc6c..fae1230 100644 --- a/footer.php +++ b/templates/footer.tpl @@ -1,17 +1,4 @@ - - * @author Olivier Haquette - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -?> + + + diff --git a/head.php b/templates/head.tpl similarity index 98% rename from head.php rename to templates/head.tpl index dc8f998..a32c850 100644 --- a/head.php +++ b/templates/head.tpl @@ -26,5 +26,4 @@ - - + diff --git a/templates/header.tpl b/templates/header.tpl new file mode 100644 index 0000000..4e10afe --- /dev/null +++ b/templates/header.tpl @@ -0,0 +1,8 @@ +
+ +
+
diff --git a/templates/index.tpl b/templates/index.tpl new file mode 100644 index 0000000..ba89aa6 --- /dev/null +++ b/templates/index.tpl @@ -0,0 +1,24 @@ +
+
+
+ +
+ + + +
+ {if $convert} +
+

+

+
+ {/if} +
+
+ See all supported websites +
diff --git a/templates/logo.tpl b/templates/logo.tpl new file mode 100644 index 0000000..15d3c3f --- /dev/null +++ b/templates/logo.tpl @@ -0,0 +1,4 @@ +

+ +AllTube Download +

diff --git a/templates/maintenance.tpl b/templates/maintenance.tpl new file mode 100644 index 0000000..18ff6ca --- /dev/null +++ b/templates/maintenance.tpl @@ -0,0 +1,9 @@ +
+
+

+
Due to some issues with our server, + we have to disable AllTube for a few days. + Sorry for the inconvenience.
+
+
diff --git a/templates/video.tpl b/templates/video.tpl new file mode 100644 index 0000000..d0116db --- /dev/null +++ b/templates/video.tpl @@ -0,0 +1,52 @@ +
+
+
+{include file="logo.tpl"} +

You are going to download + . +Google Cast™ is disabled +Google Cast™ +Casting to ChromeCast…

+ +
+ +{if $video->formats} +

Available formats:

+

(You might have to do a Right click > Save as)

+

+{else} + +{/if} +{if $video->formats} + Download
+{/if} +
+
diff --git a/youtoubeur.php b/youtoubeur.php index b1e2754..f43478c 100644 --- a/youtoubeur.php +++ b/youtoubeur.php @@ -12,4 +12,3 @@ * @link http://rudloff.pro * */ header('Location: index.php'); -?>