Skip to content

Commit

Permalink
Merge branch 'modular'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomnomnom committed Feb 29, 2012
2 parents 91cacd7 + 463b5cb commit d1081cb
Show file tree
Hide file tree
Showing 105 changed files with 35,900 additions and 206 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
config.php
config.ini
*.log
20 changes: 20 additions & 0 deletions Hooks/Postupload/write-hash.php
@@ -0,0 +1,20 @@
#!/usr/bin/env php
<?php
define('STORE_FILE', '/tmp/vimeo-upload-store.php');

$filename = $argv[1];
$hash = md5_file($filename);

if (file_exists(STORE_FILE)){
$store = require STORE_FILE;
} else {
$store = array();
}

$store[$hash] = $filename;

$codeString = var_export($store, true);

$code = '<?php return '.$codeString.';';

file_put_contents(STORE_FILE, $code);
21 changes: 21 additions & 0 deletions Hooks/Preupload/read-hash.php
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php
define('STORE_FILE', '/tmp/vimeo-upload-store.php');

$filename = $argv[1];
$hash = md5_file($filename);

if (file_exists(STORE_FILE)){
$store = require STORE_FILE;
} else {
// If there's no store the file hasn't been uploaded
exit(0);
}

if (isset($store[$hash])){
// The file has already been uploaded
exit(1);
}

// If we've got to here then the file hasn't been uploaded before
exit(0);
38 changes: 38 additions & 0 deletions Include/Init.php
@@ -0,0 +1,38 @@
<?php
error_reporting(-1);

define('CONFIG_FILE', __DIR__.'/../config.ini');

function stdout($data){
fputs(STDOUT, $data, strlen($data));
}

function stderr($data){
fputs(STDERR, $data, strlen($data));
}

spl_autoload_register(function($class){
$class = str_replace('\\', '/', $class);
require __DIR__."/../Library/{$class}.php";
});

set_exception_handler(function($e){
$type = get_class($e);
stderr("Uncaught {$type} [{$e->getCode()}]: {$e->getMessage()}\n");
stderr($e->getTraceAsString().PHP_EOL);
exit(1);
});

if (!file_exists(CONFIG_FILE)){
stderr("You must create a config.ini file in ".realpath(__DIR__.'/../'));
exit(1);
}

$settings = parse_ini_file(CONFIG_FILE, true);

if (!$settings){
stderr("Failed to parse [".CONFIG_FILE."] as valid ini file");
}

return (object) $settings;

17 changes: 17 additions & 0 deletions Include/Messages.php
@@ -0,0 +1,17 @@
<?php
return (object) array(
'help' => array(
'general' =>
"Usage: tvyv <command> [<args>]\n".
"\n".
"Commands:\n".
" upload\n".
"\n".
"See 'tvyv help <command>' for more information on a specifc command",

'upload' =>
"Usage 1: tvyv upload <dir>\n".
"Usage 2: tvyv upload <file>\n"
)
);

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions Library/Factory.php
@@ -0,0 +1,11 @@
<?php
abstract class Factory {
protected $settings;

public function __construct($settings){
$this->settings = $settings;
}

abstract public function make();
}

31 changes: 31 additions & 0 deletions Library/Factory/Logger.php
@@ -0,0 +1,31 @@
<?php
namespace Factory;

class Logger extends \Factory {

public function make(){
switch ($this->settings->log['type']){
case 'file':
// Make relative files relative to the config file
$file = $this->settings->log['file'];
if (!is_writable($file)){
throw new \InvalidArgumentException("[{$file}] is not writable");
}
if (in_array(substr($file, 0, 2), array('./', '..'))){
$file = __DIR__.'/../../'.$file;
}
return new \Logger\File($this->settings->log['level'], $file);
break;

case 'screen':
return new \Logger\Screen($this->settings->log['level']);
break;

case 'null':
default:
return new \Logger\Null($this->settings->log['level']);
break;
}
}
}

4 changes: 4 additions & 0 deletions Library/Factory/README.mkd
@@ -0,0 +1,4 @@
# Factory directory
Factories for creating other objects.

Filenames and classnames should map to abstract classes in the level above.
37 changes: 37 additions & 0 deletions Library/Factory/Vimeo.php
@@ -0,0 +1,37 @@
<?php
namespace Factory;

class Vimeo extends \Factory {
protected $settings;

public function __construct(\StdClass $settings){
$this->settings = $settings;
}

public function make(){
if ($this->haveToken()){
$client = new \Vimeo\Client(
$this->settings->vimeo['consumer_key'],
$this->settings->vimeo['consumer_secret'],
$this->settings->vimeo['token'],
$this->settings->vimeo['token_secret']
);
} else {
$client = new \Vimeo\Client(
$this->settings->vimeo['consumer_key'],
$this->settings->vimeo['consumer_secret']
);
}

return $client;
}

public function haveToken(){
if (!isset($this->settings->vimeo['token'])) return false;
if (!$this->settings->vimeo['token']) return false;
if (!isset($this->settings->vimeo['token_secret'])) return false;
if (!$this->settings->vimeo['token_secret']) return false;
return true;
}
}

0 comments on commit d1081cb

Please sign in to comment.