Esempio n. 1
0
 /**
  * @return \app\imgur\Imgur
  * @throws Exception if token file no exist
  */
 public static function facade()
 {
     if (!is_file(self::KEY_PATH)) {
         throw new Exception('The json token no exits. Create it first by createKeyToken method');
     }
     if (is_file(self::ALBUM_PATH)) {
         static::setAlbums();
     }
     $token = json_decode(file_get_contents(self::KEY_PATH));
     $imgur = new Imgur($token->api_key, $token->api_secret);
     $imgur->authorize();
     return $imgur;
 }
Esempio n. 2
0
 protected function setRely()
 {
     $this->rely = new Rely();
     $this->rely->setDirectory(ImageFile::IMAGE_DIRECTORY);
     $this->rely->setExtendedServer('google', new GoogleFile(), 'uploadOnGoogleDrive');
     $this->rely->setExtendedServer('imgur', Imgur::facade(), 'uploadOnImgur');
 }
Esempio n. 3
0
use app\google\GoogleFile;
use app\imgur\Imgur;
use models\Images;
defined('ROOT_DIR') || define('ROOT_DIR', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
require_once 'main.php';
configuration();
setAutoloader();
dbconnect();
if (php_sapi_name() != 'cli') {
    throw new Exception('This application must be run on the command line.');
}
$images = R::find(Images::tableName(), ' `imgur` IS NULL ');
foreach ($images as $image) {
    R::begin();
    try {
        $imgur = Imgur::facade();
        $imgur->setCatalog(trim($image->type, '12'));
        $imgur->setFilename(ROOT_DIR . Images::IMAGE_DIRECTORY . DIRECTORY_SEPARATOR . $image->id . '.png');
        $imgur->setDescription('R18');
        $imgur->setName($image->units->name);
        $response = $imgur->uploadFile();
        if (isset($response['data']['id']) && isset($response['data']['deletehash'])) {
            $image->imgur = $response['data']['id'];
            $image->delhash = $response['data']['deletehash'];
            R::store($image);
            R::commit();
        }
    } catch (Exception $ex) {
        var_dump($ex);
        R::rollback();
    }