Improved the compiler, added the option to add the update server file to the zipped package, fixed a few bugs.
This commit is contained in:
@ -45,8 +45,8 @@ class ###Component###ControllerDownload extends JControllerLegacy
|
||||
switch($task)
|
||||
{
|
||||
case 'file':
|
||||
$keys = $jinput->get('key', NULL, 'BASE64');
|
||||
$enUrl = $jinput->get('link', NULL, 'BASE64');
|
||||
$keys = ###Component###Helper::base64_urldecode($jinput->get('key', NULL, 'STRING'));
|
||||
$enUrl = ###Component###Helper::base64_urldecode($jinput->get('link', NULL, 'STRING'));
|
||||
$filename = $jinput->get('filename', NULL, 'CMD');
|
||||
if((base64_encode(base64_decode($enUrl, true)) === $enUrl) && (base64_encode(base64_decode($keys, true)) === $keys) && $filename)
|
||||
{
|
||||
@ -60,7 +60,7 @@ class ###Component###ControllerDownload extends JControllerLegacy
|
||||
// Get local key
|
||||
$localkey = ###Component###Helper::getLocalKey();
|
||||
$opener = new FOFEncryptAes($localkey, 128);
|
||||
$link = rtrim($opener->decryptString(base64_decode($enUrl)));
|
||||
$link = rtrim($opener->decryptString($enUrl), "\0");
|
||||
$info = $this->getContentInfo($link);
|
||||
// set headers
|
||||
$app = JFactory::getApplication();
|
||||
@ -108,7 +108,7 @@ class ###Component###ControllerDownload extends JControllerLegacy
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
die('Restricted access');
|
||||
}
|
||||
|
||||
protected function getContentInfo($url)
|
||||
|
@ -3,9 +3,9 @@
|
||||
Vast Development Method
|
||||
/-------------------------------------------------------------------------------------------------------/
|
||||
|
||||
@version 1.0.0 - 01st July, 2015
|
||||
@package Dropbox Links builder
|
||||
@subpackage dropboxlinks.php
|
||||
@version 2.0.0 - 03rd November, 2016
|
||||
@package Dropbox API 2
|
||||
@subpackage dropbox.php
|
||||
@author Llewellyn van der Merwe <http://www.vdm.io>
|
||||
@copyright Copyright (C) 2015. All Rights Reserved
|
||||
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
||||
@ -20,295 +20,390 @@ defined('_JEXEC') or die;
|
||||
*/
|
||||
class Dropbox
|
||||
{
|
||||
// the file name
|
||||
public $fileName;
|
||||
/**
|
||||
* final url
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* The array for the post url
|
||||
*/
|
||||
protected $postUrl = array(
|
||||
"protocol" => "https://",
|
||||
"suddomain" => "api.",
|
||||
"domain" => "dropboxapi.com",
|
||||
"path" => "/2/"
|
||||
);
|
||||
|
||||
// the file array
|
||||
public $files = array();
|
||||
/**
|
||||
* the verious pathes we need
|
||||
*/
|
||||
protected $domainpath = array(
|
||||
"list_folder" => "files/list_folder",
|
||||
"list_folder_continue" => "files/list_folder/continue",
|
||||
"create_shared_link" => "sharing/create_shared_link",
|
||||
"get_shared_link_metadata" => "sharing/get_shared_link_metadata",
|
||||
"revoke" => "auth/token/revoke"
|
||||
);
|
||||
|
||||
// the extension to get
|
||||
protected $getfiles = array();
|
||||
/**
|
||||
* the target pathe to get
|
||||
*/
|
||||
protected $targetPath = false;
|
||||
protected $targetPathOriginal = false;
|
||||
|
||||
// the extensions to leave
|
||||
protected $notfiles = array();
|
||||
/**
|
||||
* oauth token
|
||||
*/
|
||||
protected $oauthToken;
|
||||
|
||||
// the folder array
|
||||
protected $folders = array();
|
||||
/**
|
||||
* the verious pathes we need
|
||||
*/
|
||||
protected $permissionType;
|
||||
|
||||
// folder identifiers
|
||||
protected $getfolders = array('?dl=0');
|
||||
/**
|
||||
* The loop controller in calling Dropbox API
|
||||
*/
|
||||
protected $continueCalling = array();
|
||||
|
||||
// the list of extension to help identify what is folders (not exhaustive, only some of the commen files)
|
||||
protected $notfolders = array(
|
||||
'.3gp','.3gpp','.7z','.aac','.act','.aiff','.aiff','.amr','.ape','.ar','.asf','.au','.avi','.awb','.bmp','.bup','.bzip2','.crx','.css','.dct','.deb','.djvu',
|
||||
'.doc','.docx','.drc','.dss','.ear','.egg','.exe','.flac','.flv','.gif','.gifv','.gzip','.htaccess','.html','.ico','.ini','.iso','.jar','.jpeg','.jpg','.js',
|
||||
'.json','.lzip','.m3u','.m4a','.m4p','.m4v','.mkv','.mmf','.mng','.mov','.mp3','.mp4','.mpc','.mpeg','.mpeg4','.mpegps','.mpg','.mpkg','.msi','.odt','.ogg',
|
||||
'.opus','.pdf','.pea','.php','.pkg','.png','.ppt','.pptx','.ps','.psd','.pst','.pxv','.rar','.raw','.rm','.rmvb','.rpm','.rtf','.shar','.sql','.svg','.sxw',
|
||||
'.tar','.tgz','.tgz','.tiff','.txt','.veg','.vep','.vob','.wav','.webm','.wma','.wmv','.xar','.xls','.xml','.yuv','.zip' );
|
||||
/**
|
||||
* the success switch
|
||||
*/
|
||||
protected $succes;
|
||||
|
||||
// the directory where the downloaded files should be stored
|
||||
protected $dir;
|
||||
/**
|
||||
* the type call
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* the query for the call
|
||||
*/
|
||||
protected $query;
|
||||
|
||||
/**
|
||||
* the query for the call
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* the mediaData bucket
|
||||
*/
|
||||
public $mediaData = array();
|
||||
|
||||
/**
|
||||
* the error messages
|
||||
*/
|
||||
public $error_summary = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($mainurl, $config = array('save' => false, 'filename' => 'dropbox', 'download' => false, 'dir' => __DIR__))
|
||||
public function __construct(JModelLegacy $model, $buildType)
|
||||
{
|
||||
if ($this->checkArray($config))
|
||||
// set the url at this point for now
|
||||
$this->url = $this->postUrl["protocol"].$this->postUrl["suddomain"].$this->postUrl["domain"].$this->postUrl["path"];
|
||||
// set the local model
|
||||
$this->model = $model;
|
||||
// set the build type
|
||||
$this->build = (int) $buildType;
|
||||
}
|
||||
|
||||
/**
|
||||
* getFiles
|
||||
*
|
||||
* =============
|
||||
* $details
|
||||
* =============
|
||||
* dropboxOption
|
||||
* dropboxTarget
|
||||
* addTypes
|
||||
*
|
||||
*/
|
||||
public function getFiles($token, $permissiontype, $details = array())
|
||||
{
|
||||
// we need more then the normal time to run this script 5 minutes at least.
|
||||
ini_set('max_execution_time', 500);
|
||||
// set the oauth toke
|
||||
$this->oauthToken = $token;
|
||||
|
||||
// set the permission type
|
||||
$this->permissionType = $permissiontype;
|
||||
|
||||
// set the details
|
||||
if ($this->checkArray($details))
|
||||
{
|
||||
// we need more then the normal time to run this script 5 minutes at least.
|
||||
ini_set('max_execution_time', 500); // TODO this is not the best option I am sure, but for now seems like the only option.
|
||||
// set main url
|
||||
$this->mainurl = $mainurl;
|
||||
// if custom get list is set use it
|
||||
if (isset($config['get']) && $this->checkArray($config['get']))
|
||||
foreach ($details as $detail => $value)
|
||||
{
|
||||
$this->getfiles = $config['get'];
|
||||
}
|
||||
elseif (isset($config['get']) && $this->checkString($config['get']))
|
||||
{
|
||||
$this->getfiles = array($config['get']);
|
||||
}
|
||||
// if custom excludelist is set use it
|
||||
if (isset($config['not']) && $this->checkArray($config['not']))
|
||||
{
|
||||
$this->notfiles = $config['not'];
|
||||
}
|
||||
elseif (isset($config['not']) && $this->checkString($config['not']))
|
||||
{
|
||||
$this->notfiles = array($config['not']);
|
||||
}
|
||||
// set main folder name
|
||||
$this->fileName = (isset($config['filename'])) ? md5($this->mainurl.$config['filename']) : md5($this->mainurl.'nofilenamewasset');
|
||||
// set save switch
|
||||
$save = (isset($config['save'])) ? $config['save'] : false;
|
||||
// set download switch
|
||||
$download = (isset($config['download'])) ? $config['download'] : false;
|
||||
// make sure the note folder identifiers are complete
|
||||
$this->notfolders = array_unique(array_merge($this->getfiles,$this->notfiles,$this->notfolders));
|
||||
// set local directory
|
||||
$this->dir = (isset($config['dir'])) ? $config['dir'] : __DIR__;
|
||||
// check if the parching of the drobox files is up to date
|
||||
if (($json = @file_get_contents($this->fileName.".json")) !== FALSE)
|
||||
{
|
||||
$this->files = json_decode($json, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// set all folders
|
||||
$this->parseFolders($this->mainurl, 'VDM_pLeK_h0uEr');
|
||||
}
|
||||
// check if we should save the file
|
||||
if ($save)
|
||||
{
|
||||
$this->save();
|
||||
}
|
||||
// check if we should download the file
|
||||
if ($download)
|
||||
{
|
||||
$this->download();
|
||||
$this->$detail = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// set the curent folder path
|
||||
if (!$this->setFolderPath())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// start the main factory that calles for the folder data
|
||||
$this->query = array("path" => $this->targetPath, "recursive" => true, "include_media_info" => true);
|
||||
$this->type = 'list_folder';
|
||||
if ($this->makeCall())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function revokeToken($token = null)
|
||||
{
|
||||
if ($token)
|
||||
{
|
||||
// set the oauth toke
|
||||
$this->oauthToken = $token;
|
||||
}
|
||||
// set the call to revoke the token
|
||||
$this->query = 'null';
|
||||
$this->type = 'revoke';
|
||||
if ($this->makeCall())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function download($dir = null)
|
||||
|
||||
protected function setFolderPath()
|
||||
{
|
||||
if ($this->checkArray($this->files))
|
||||
if ('full' == $this->permissionType && isset($this->dropboxOption) && isset($this->dropboxTarget) && $this->checkString($this->dropboxTarget))
|
||||
{
|
||||
// insure the directory is set
|
||||
$dir = ($dir) ? $dir : $this->dir;
|
||||
foreach($this->files as $path => $url)
|
||||
if (2 == $this->dropboxOption)
|
||||
{
|
||||
// now setup correct path
|
||||
$path = str_replace('VDM_pLeK_h0uEr', $dir, $path);
|
||||
// boom here we go move....
|
||||
$this->getFile($url, $path);
|
||||
// simply set the path
|
||||
$this->targetPath = '/'.trim(strtolower($this->dropboxTarget), '/');
|
||||
|
||||
return true;
|
||||
}
|
||||
elseif (1 == $this->dropboxOption)
|
||||
{
|
||||
// make a call to get the path
|
||||
$this->query = array("url" => $this->dropboxTarget);
|
||||
$this->type = 'get_shared_link_metadata';
|
||||
if ($this->makeCall())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getFile($url, $path)
|
||||
{
|
||||
$newfname = $path;
|
||||
if (($file = @fopen($url, "rb")) !== FALSE)
|
||||
elseif ('app' == $this->permissionType)
|
||||
{
|
||||
$filename = substr($path, strrpos($path, '/'));
|
||||
$makePath = str_replace($filename,'',$path);
|
||||
if (!file_exists($makePath))
|
||||
{
|
||||
mkdir($makePath, 0755, true);
|
||||
}
|
||||
|
||||
$newf = fopen($newfname, "wb");
|
||||
$this->targetPath = "";
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function makeCall()
|
||||
{
|
||||
if ($this->_isCurl())
|
||||
{
|
||||
return $this->makeCurlCall();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo 'error! '.$url.' not found';
|
||||
}
|
||||
|
||||
if ($newf)
|
||||
{
|
||||
while(!feof($file))
|
||||
{
|
||||
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
|
||||
}
|
||||
}
|
||||
|
||||
if ($file)
|
||||
{
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
if ($newf)
|
||||
{
|
||||
fclose($newf);
|
||||
return $this->makeGetCall();
|
||||
}
|
||||
}
|
||||
|
||||
public function save($filename = null)
|
||||
|
||||
protected function makeGetCall()
|
||||
{
|
||||
if ($this->checkString($filename))
|
||||
{
|
||||
// set main folder name
|
||||
$this->fileName = md5($this->mainurl.$filename);
|
||||
}
|
||||
if ($this->checkArray($this->files))
|
||||
{
|
||||
$data = json_encode($this->files);
|
||||
// now save this folders data to a file.
|
||||
$this->saveJson($data);
|
||||
$query = json_encode($this->query);
|
||||
|
||||
$options = array(
|
||||
'http' => array(
|
||||
'header' => "Content-Type: application/json\r\n".
|
||||
"Authorization: Bearer ".$this->oauthToken,
|
||||
'method' => "POST",
|
||||
'content' => $query
|
||||
),
|
||||
);
|
||||
|
||||
$context = stream_context_create($options);
|
||||
$response = file_get_contents($this->url.$this->domainpath[$this->type], false, $context);
|
||||
|
||||
return true;
|
||||
|
||||
if ($response === FALSE)
|
||||
{
|
||||
$this->error_summary[] = $this->type.'_error';
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// store the result
|
||||
return $this->setTheResult(json_decode($response));
|
||||
}
|
||||
}
|
||||
|
||||
protected function makeCurlCall()
|
||||
{
|
||||
$query = json_encode($this->query);
|
||||
|
||||
$headers = array('Authorization: Bearer '. $this->oauthToken,
|
||||
'Content-Type: application/json'
|
||||
);
|
||||
|
||||
$ch = curl_init($this->url.$this->domainpath[$this->type]);
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
// curl_setopt($ch, CURLOPT_VERBOSE, 1); // debug
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
if ($this->checkJson($response))
|
||||
{
|
||||
$response = json_decode($response);
|
||||
}
|
||||
// store the result
|
||||
return $this->setTheResult($response);
|
||||
}
|
||||
|
||||
protected function setTheResult($data)
|
||||
{
|
||||
// if there was an error stop!!!
|
||||
if (isset($data->error_summary))
|
||||
{
|
||||
$this->error_summary[] = $data->error_summary;
|
||||
return false;
|
||||
}
|
||||
|
||||
// deal with each type
|
||||
switch ($this->type)
|
||||
{
|
||||
case "list_folder":
|
||||
case "list_folder_continue":
|
||||
if (isset($data->entries) && $this->checkArray($data->entries))
|
||||
{
|
||||
if ($this->storeFiles($data->entries))
|
||||
{
|
||||
// run the continue if needed
|
||||
if (isset($data->has_more) && $data->has_more && isset($data->cursor))
|
||||
{
|
||||
// start the main factory that calles for the folder data
|
||||
$this->query = array("cursor" => $data->cursor);
|
||||
$this->type = 'list_folder_continue';
|
||||
if ($this->makeCall())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$this->error_summary[] = $this->type.'_error';
|
||||
break;
|
||||
case "create_shared_link":
|
||||
if (isset($data->url) && isset($data->path) && $this->storeSharedLink($this->fixPath($data->path), str_replace('?dl=0','?dl=1',$data->url)))
|
||||
{
|
||||
// we stored the link
|
||||
return true;
|
||||
}
|
||||
$this->error_summary[] = $this->type.'_error';
|
||||
break;
|
||||
case "get_shared_link_metadata":
|
||||
if (isset($data->path_lower))
|
||||
{
|
||||
$this->targetPath = $data->path_lower;
|
||||
return true;
|
||||
}
|
||||
$this->error_summary[] = $this->type.'_error';
|
||||
break;
|
||||
case "revoke":
|
||||
if (is_null($data))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
$this->error_summary[] = $this->type.'_error';
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function storeSharedLink($path, $url)
|
||||
{
|
||||
// we need to store the url to DB
|
||||
if (isset($this->mediaData[$path]))
|
||||
{
|
||||
$localListing = array();
|
||||
$localListing['id'] = 0;
|
||||
$localListing['name'] = $this->mediaData[$path]['name'];
|
||||
$localListing['size'] = $this->mediaData[$path]['size'];
|
||||
$localListing['key'] = $path;
|
||||
$localListing['url'] = $url;
|
||||
$localListing['build'] = $this->build;
|
||||
// free some memory
|
||||
unset($this->mediaData[$path]);
|
||||
// check if item already set
|
||||
if ($id = $this->model->searchForId($path))
|
||||
{
|
||||
// update item
|
||||
$localListing['id'] = $id;
|
||||
}
|
||||
return $this->model->save($localListing);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function saveJson($data)
|
||||
{
|
||||
if ($this->checkString($data))
|
||||
{
|
||||
/*
|
||||
for now it will save
|
||||
the files in the same
|
||||
directory as the php
|
||||
file where the class
|
||||
is called we will have
|
||||
to change this to suite
|
||||
your custom needs.
|
||||
*/
|
||||
$fp = fopen($this->fileName.'.json', 'w');
|
||||
fwrite($fp, $data);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseFolders($url, $foldername)
|
||||
{
|
||||
if ($this->checkString($url))
|
||||
{
|
||||
// get the page html
|
||||
if (($html = @file_get_contents($url)) !== FALSE)
|
||||
protected function storeFiles($entries)
|
||||
{
|
||||
foreach ($entries as $item)
|
||||
{
|
||||
if (isset($item->{'.tag'}) && 'file' == $item->{'.tag'} && isset($item->name))
|
||||
{
|
||||
//Create a new DOM document
|
||||
$dom = new DOMDocument;
|
||||
|
||||
//Parse the HTML. The @ is used to suppress any parsing errors
|
||||
//that will be thrown if the $html string isn't valid XHTML.
|
||||
@$dom->loadHTML($html);
|
||||
|
||||
//Get all links. You could also use any other tag name here,
|
||||
//like 'img' or 'table', to extract other tags.
|
||||
$links = $dom->getElementsByTagName('a');
|
||||
|
||||
//Iterate over the extracted links and display their URLs
|
||||
if ($this->checkObject($links))
|
||||
$addLink = false;
|
||||
// remove if not related to type
|
||||
if (isset($this->addTypes) && $this->checkArray($this->addTypes))
|
||||
{
|
||||
// the types
|
||||
$types = array('folders','files');
|
||||
foreach ($types as $type)
|
||||
foreach ($this->addTypes as $add)
|
||||
{
|
||||
// folder bucket
|
||||
$buket = array();
|
||||
foreach ($links as $nr => $link)
|
||||
if (strpos($item->name,$add) !== false)
|
||||
{
|
||||
// switch to add link
|
||||
$add = false;
|
||||
// get actual link
|
||||
$href = $link->getAttribute('href');
|
||||
// only use link reated to type
|
||||
if ($this->checkArray($this->{'get'.$type}) && $this->checkString($href))
|
||||
{
|
||||
foreach ($this->{'get'.$type} as $get)
|
||||
{
|
||||
if (!$add)
|
||||
{
|
||||
if (strpos($get,'?dl') === false)
|
||||
{
|
||||
$get = $get . '?dl=0';
|
||||
}
|
||||
if (strpos($href,'https://www.dropbox.com/') !== false && strpos($href,$get) !== false)
|
||||
{
|
||||
$add = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strpos($href,'https://www.dropbox.com/') !== false && strpos($href,'?dl=0') !== false)
|
||||
{
|
||||
$add = true;
|
||||
}
|
||||
}
|
||||
|
||||
// remove if not related to type
|
||||
if ($this->checkArray($this->{'not'.$type}) && $this->checkString($href) && $add)
|
||||
{
|
||||
foreach ($this->{'not'.$type} as $not)
|
||||
{
|
||||
if ($add)
|
||||
{
|
||||
if (strpos($href,$not) !== false)
|
||||
{
|
||||
$add = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now add if still related to type
|
||||
if ($add)
|
||||
{
|
||||
if (!in_array($href,$buket))
|
||||
{
|
||||
$name = str_replace('?dl=0','',substr($href, strrpos($href, '/') + 1));
|
||||
|
||||
if ($type == 'folders' && strpos($name,'.') === false)
|
||||
{
|
||||
// parse this folder for more files and sub folders
|
||||
$this->parseFolders($href, $foldername.'/'.str_replace('?lst','',$name));
|
||||
$buket[] = $href;
|
||||
unset($links->$nr);
|
||||
|
||||
}
|
||||
elseif ($type == 'files' && strpos($name,'.') !== false)
|
||||
{
|
||||
// Add to file list
|
||||
$this->files[$foldername.'/'.$name] = str_replace('?dl=0','?dl=1',$href);
|
||||
$buket[] = $href;
|
||||
unset($links->$nr);
|
||||
}
|
||||
}
|
||||
}
|
||||
$addLink = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if ($addLink && isset($item->path_lower))
|
||||
{
|
||||
// store media info
|
||||
$this->mediaData[$this->fixPath($item->path_lower)] = array('name' => $item->name, 'size' => $item->size);
|
||||
// get the shared link
|
||||
$this->query = array("path" => $item->path_lower);
|
||||
$this->type = 'create_shared_link';
|
||||
if (!$this->makeCall())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function fixPath($path)
|
||||
{
|
||||
if ($this->checkString($this->targetPath))
|
||||
{
|
||||
$path = str_replace($this->targetPath, 'VDM_pLeK_h0uEr', $path);
|
||||
}
|
||||
else
|
||||
{
|
||||
$path = 'VDM_pLeK_h0uEr'.$path;
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
protected function checkObject($object)
|
||||
@ -328,6 +423,16 @@ class Dropbox
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function checkJson($string)
|
||||
{
|
||||
if ($this->checkString($string))
|
||||
{
|
||||
json_decode($string);
|
||||
return (json_last_error() === JSON_ERROR_NONE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function checkString($string)
|
||||
{
|
||||
@ -337,6 +442,10 @@ class Dropbox
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function _isCurl()
|
||||
{
|
||||
return function_exists('curl_version');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -22,10 +22,6 @@ defined('_JEXEC') or die('Restricted access');
|
||||
*/
|
||||
class Dropboxupdater
|
||||
{
|
||||
/**
|
||||
* to see where we are in the prosses
|
||||
**/
|
||||
public $progress = array('report' => 0);
|
||||
|
||||
/**
|
||||
* update flag (if false update will not happen)
|
||||
@ -33,14 +29,19 @@ class Dropboxupdater
|
||||
protected $okay = true;
|
||||
|
||||
/**
|
||||
* the type of linksto update
|
||||
* update flag (if false update will not happen)
|
||||
**/
|
||||
protected $type;
|
||||
protected $data = null;
|
||||
|
||||
/**
|
||||
* allow a forced manual update
|
||||
* the file Key
|
||||
**/
|
||||
protected $runManual;
|
||||
protected $fileKey;
|
||||
|
||||
/**
|
||||
* allow a forced update
|
||||
**/
|
||||
protected $forceUpdate;
|
||||
|
||||
/**
|
||||
* Todays date-time
|
||||
@ -58,14 +59,9 @@ class Dropboxupdater
|
||||
protected $updateMethod;
|
||||
|
||||
/**
|
||||
* update links
|
||||
* update targets
|
||||
**/
|
||||
protected $updateLinks = array();
|
||||
|
||||
/**
|
||||
* Listing of dropbox links
|
||||
**/
|
||||
protected $listing = array();
|
||||
protected $updateTarget;
|
||||
|
||||
/**
|
||||
* info related to this update
|
||||
@ -78,10 +74,20 @@ class Dropboxupdater
|
||||
**/
|
||||
protected $localkey = false;
|
||||
|
||||
/**
|
||||
* Main dropbox class
|
||||
**/
|
||||
protected $dropbox;
|
||||
|
||||
/**
|
||||
* component parameters
|
||||
**/
|
||||
protected $app_params;
|
||||
|
||||
/**
|
||||
* the errors
|
||||
**/
|
||||
protected $errors = array();
|
||||
|
||||
/**
|
||||
* everything we want done when initialized
|
||||
@ -90,32 +96,68 @@ class Dropboxupdater
|
||||
{
|
||||
// get params
|
||||
$this->app_params = JComponentHelper::getParams('com_###component###');
|
||||
|
||||
// set local key
|
||||
$this->localkey = md5($this->app_params->get('link_encryption', 'localKey34fdWEkl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* update mehtod
|
||||
* get the logged errors array
|
||||
**/
|
||||
public function update($type = false, $runManual = false)
|
||||
public function getErrors()
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the error to the log
|
||||
**/
|
||||
protected function setErrors($error)
|
||||
{
|
||||
if (###Component###Helper::checkString($error))
|
||||
{
|
||||
$this->errors[] = $error;
|
||||
}
|
||||
elseif (###Component###Helper::checkArray($error))
|
||||
{
|
||||
foreach($error as $log)
|
||||
{
|
||||
if (###Component###Helper::checkString($log))
|
||||
{
|
||||
$this->errors[] = $log;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* update method
|
||||
**/
|
||||
public function update($id, $target, $type = false, $forceUpdate = false, $sleutel = null)
|
||||
{
|
||||
if ($type)
|
||||
{
|
||||
// start frech
|
||||
// start fresh
|
||||
$this->okay = true;
|
||||
// set type
|
||||
$this->data = null;
|
||||
// is this a forced run
|
||||
$this->forceUpdate = $forceUpdate;
|
||||
// the file key
|
||||
$this->fileKey = ###Component###Helper::safeString($id.$target.$type);
|
||||
// set the type of this listing
|
||||
$this->type = $type;
|
||||
$this->runManual = $runManual;
|
||||
|
||||
// set progress file name
|
||||
$this->progressFilePath = JPATH_COMPONENT_SITE.'/helpers/'.md5($this->type.'progress'.$this->localkey).'.json';
|
||||
// get the external source data being updated
|
||||
$this->setExternalSourceData($id);
|
||||
|
||||
// load the token if manualy set
|
||||
if ($sleutel)
|
||||
{
|
||||
$this->setExternalSourceData($id, array('oauthtoken' => $sleutel));
|
||||
}
|
||||
|
||||
// what update method is set
|
||||
$this->setUpdateMethod();
|
||||
|
||||
// set the update links
|
||||
$this->setUpdateLinks();
|
||||
$this->setUpdateTarget($target);
|
||||
|
||||
// set needed dates
|
||||
if ($this->okay)
|
||||
@ -126,7 +168,7 @@ class Dropboxupdater
|
||||
// get info data or set if not found
|
||||
if ($this->okay)
|
||||
{
|
||||
$this->setInfoData();
|
||||
$this->setUpdateInfoData();
|
||||
}
|
||||
|
||||
// check if update should run now
|
||||
@ -134,11 +176,6 @@ class Dropboxupdater
|
||||
{
|
||||
$this->checkUpdateStatus();
|
||||
}
|
||||
// set progress
|
||||
if ($this->okay)
|
||||
{
|
||||
$this->saveProgress();
|
||||
}
|
||||
|
||||
// before update save update info incase class is called again
|
||||
if($this->okay)
|
||||
@ -161,35 +198,60 @@ class Dropboxupdater
|
||||
if ($this->okay)
|
||||
{
|
||||
// set the config
|
||||
$this->setDropboxConfig();
|
||||
// set progress
|
||||
$this->progress['report'] = 30;
|
||||
$this->saveProgress();
|
||||
$this->setDetailsConfig();
|
||||
// load the file
|
||||
JLoader::import('dropbox', JPATH_COMPONENT_SITE.'/helpers');
|
||||
// okay now update
|
||||
if ($this->doUpdate())
|
||||
$build = 1;
|
||||
if ('auto' == $this->type)
|
||||
{
|
||||
return $this->okay;
|
||||
$build = 2;
|
||||
}
|
||||
// load the dropbox class
|
||||
$this->dropbox = new Dropbox(###Component###Helper::getModel('local_listing', JPATH_COMPONENT_ADMINISTRATOR), $build);
|
||||
// okay now update
|
||||
$this->okay = $this->doUpdate();
|
||||
}
|
||||
// always reset if all okay
|
||||
return $this->resetUpdate();
|
||||
}
|
||||
$this->setErrors('The update type is unknown.');
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the exsternal source data
|
||||
*/
|
||||
protected function setExternalSourceData($id, $data = array())
|
||||
{
|
||||
// get the data if not set
|
||||
if (!$this->data || !###Component###Helper::checkObject($this->data))
|
||||
{
|
||||
// load model to get the data
|
||||
$model = ###Component###Helper::getModel('external_source', JPATH_COMPONENT_ADMINISTRATOR);
|
||||
$this->data = $model->getItem($id);
|
||||
}
|
||||
// if new data is set load it
|
||||
if (###Component###Helper::checkArray($data))
|
||||
{
|
||||
foreach ($data as $key => $value)
|
||||
{
|
||||
$this->data->$key = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set update mehtod
|
||||
**/
|
||||
protected function setUpdateMethod()
|
||||
{
|
||||
$method = $this->app_params->get($this->type.'_link_update_method', 0);
|
||||
if ($this->runManual)
|
||||
if ($this->forceUpdate)
|
||||
{
|
||||
// this is a manual method
|
||||
$this->updateMethod = 'manual';
|
||||
}
|
||||
elseif (2 == $method)
|
||||
{
|
||||
elseif (2 == $this->data->update_method)
|
||||
{
|
||||
// this it an auto mehtod
|
||||
$this->updateMethod = 'auto';
|
||||
}
|
||||
@ -200,31 +262,53 @@ class Dropboxupdater
|
||||
}
|
||||
|
||||
/**
|
||||
* set update Links
|
||||
* set update target
|
||||
**/
|
||||
protected function setUpdateLinks()
|
||||
protected function setUpdateTarget($nr)
|
||||
{
|
||||
// the number of links
|
||||
$numbers = range(1, 4);
|
||||
// now check if they are set
|
||||
foreach ($numbers as $number)
|
||||
// get target based on type and position
|
||||
if ('full' == $this->data->permissiontype && $nr > 0)
|
||||
{
|
||||
// set the number to string
|
||||
$numStr = ###Component###Helper::safeString($number);
|
||||
// Get the url
|
||||
$url = $this->app_params->get($this->type.'dropbox'.$numStr, null);
|
||||
// only load those that are set
|
||||
if ($url)
|
||||
$position = $nr - 1;
|
||||
if (1 == $this->data->dropboxoptions && ###Component###Helper::checkJson($this->data->sharedurl))
|
||||
{
|
||||
$this->updateLinks[] = $url;
|
||||
$targets = json_decode($this->data->sharedurl)->tsharedurl;
|
||||
}
|
||||
elseif (2 == $this->data->dropboxoptions && ###Component###Helper::checkJson($this->data->folder))
|
||||
{
|
||||
$targets = json_decode($this->data->folder)->tfolder;
|
||||
}
|
||||
// check if we found any
|
||||
if (!isset($targets[$position]) || !###Component###Helper::checkString($targets[$position]))
|
||||
{
|
||||
$this->setErrors('The target Shared-url or Folder is not set.');
|
||||
$this->okay = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->updateTarget = $targets[$position];
|
||||
}
|
||||
}
|
||||
// check if we found any
|
||||
if (!isset($this->updateLinks) || !###Component###Helper::checkArray($this->updateLinks))
|
||||
else
|
||||
{
|
||||
$this->okay = false;
|
||||
$this->updateTarget = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set the configeration for exsternal source class
|
||||
**/
|
||||
protected function setDetailsConfig()
|
||||
{
|
||||
// reset config
|
||||
$this->detailsConfig = array();
|
||||
// get the legal files set
|
||||
$this->detailsConfig['addTypes'] = $this->data->filetypes;
|
||||
// set other config settings
|
||||
$this->detailsConfig['dropboxOption'] = $this->data->dropboxoptions;
|
||||
// set dropbox target
|
||||
$this->detailsConfig['dropboxTarget'] = $this->updateTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* set next update time
|
||||
@ -243,7 +327,7 @@ class Dropboxupdater
|
||||
else
|
||||
{
|
||||
// based on the auto time we will set the next update date/time
|
||||
$timer = $this->app_params->get($this->type.'_dropbox_timer', '60');
|
||||
$timer = $this->data->update_timer;
|
||||
if ($timer != 0)
|
||||
{
|
||||
// Get Next Update Time
|
||||
@ -252,18 +336,19 @@ class Dropboxupdater
|
||||
// if timer is 0 we should not update
|
||||
else
|
||||
{
|
||||
$this->setErrors('The timer is not setup correctly.');
|
||||
$this->okay = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set update mehtod
|
||||
* set update info data
|
||||
**/
|
||||
protected function setInfoData()
|
||||
protected function setUpdateInfoData()
|
||||
{
|
||||
// set the info file name
|
||||
$fileName = md5($this->type.'info'.$this->localkey);
|
||||
$fileName = md5($this->fileKey.'info'.$this->localkey);
|
||||
// set file path
|
||||
$this->infoFilePath = JPATH_COMPONENT_SITE.'/helpers/'.$fileName.'.json';
|
||||
|
||||
@ -289,11 +374,13 @@ class Dropboxupdater
|
||||
if ($this->updateInfo->updateactive)
|
||||
{
|
||||
$this->okay = false;
|
||||
$this->setErrors('There is an update already running.');
|
||||
}
|
||||
// check if the time has come to do the next update
|
||||
elseif (('auto' == $this->updateMethod) && ($this->updateInfo->nextupdate > $this->today))
|
||||
{
|
||||
$this->okay = false;
|
||||
$this->setErrors('It is not yet time to run this update.');
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -301,14 +388,6 @@ class Dropboxupdater
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* save the update info
|
||||
**/
|
||||
protected function saveProgress()
|
||||
{
|
||||
return $this->saveJson(json_encode($this->progress),$this->progressFilePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* save the update info
|
||||
**/
|
||||
@ -324,93 +403,32 @@ class Dropboxupdater
|
||||
{
|
||||
// we need more then the normal time to run this script 5 minutes at least.
|
||||
ini_set('max_execution_time', 500);
|
||||
// get data of all the urls
|
||||
foreach ($this->updateLinks as $mainUrl)
|
||||
// get data of all the shared links of all target items
|
||||
if (!$this->dropbox->getFiles($this->data->oauthtoken, $this->data->permissiontype, $this->detailsConfig))
|
||||
{
|
||||
// set progress
|
||||
if ($this->progress['report'] < 60)
|
||||
{
|
||||
$this->progress['report'] = $this->progress['report'] + 5;
|
||||
$this->saveProgress();
|
||||
}
|
||||
// get ldropbox links
|
||||
$dropbox = new Dropbox($mainUrl, $this->dropboxConfig);
|
||||
// set progress
|
||||
if ($this->progress['report'] < 70)
|
||||
{
|
||||
$this->progress['report'] = $this->progress['report'] + 5;
|
||||
$this->saveProgress();
|
||||
}
|
||||
// get the links
|
||||
if (###Component###Helper::checkArray($dropbox->files))
|
||||
{
|
||||
$this->listing = array_merge($this->listing, $dropbox->files);
|
||||
}
|
||||
// set progress
|
||||
if ($this->progress['report'] < 80)
|
||||
{
|
||||
$this->progress['report'] = $this->progress['report'] + 5;
|
||||
$this->saveProgress();
|
||||
}
|
||||
unset($dropbox);
|
||||
$this->setErrors($this->dropbox->error_summary);
|
||||
return false;
|
||||
}
|
||||
// if this is a manual update, then revoke the token
|
||||
if ($this->forceUpdate)
|
||||
{
|
||||
$this->dropbox->revokeToken($this->data->oauthtoken);
|
||||
}
|
||||
|
||||
// now store the new listing
|
||||
return $this->setNewListing();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function setNewListing()
|
||||
{
|
||||
// set progress
|
||||
$this->progress['report'] = 100;
|
||||
$this->saveProgress();
|
||||
// reset storage
|
||||
$storeage = array();
|
||||
// set the listing file name
|
||||
$fileName = md5($this->type.'listing'.$this->localkey);
|
||||
// set file path
|
||||
$listingFilePath = JPATH_COMPONENT_SITE.'/helpers/'.$fileName.'.json';
|
||||
|
||||
// now store the new listing
|
||||
if (###Component###Helper::checkArray($this->listing))
|
||||
{
|
||||
// encrypt the urls
|
||||
$locker = new FOFEncryptAes($this->localkey, 128);
|
||||
foreach ($this->listing as $folder => $link)
|
||||
{
|
||||
$storeage[$folder] = base64_encode($locker->encryptString($link));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->okay = false;
|
||||
}
|
||||
// save the update links.
|
||||
$this->saveJson(json_encode($storeage),$listingFilePath);
|
||||
// make sure the update reset
|
||||
$this->updateInfo->nextupdate = $this->next;
|
||||
$this->updateInfo->updateactive = false;
|
||||
$this->updateInfo->updatenow = false;
|
||||
|
||||
return $this->saveUpdateInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* set the configeration for dropbox class
|
||||
**/
|
||||
protected function setDropboxConfig()
|
||||
protected function resetUpdate()
|
||||
{
|
||||
// reset config
|
||||
$this->dropboxConfig = array();
|
||||
// get the legal files set
|
||||
$getfiles = $this->app_params->get('dropbox_filetypes', null);
|
||||
if (###Component###Helper::checkArray($getfiles))
|
||||
if ($this->okay)
|
||||
{
|
||||
$this->dropboxConfig['get'] = $getfiles;
|
||||
// make sure the update reset
|
||||
$this->updateInfo->nextupdate = $this->next;
|
||||
$this->updateInfo->updateactive = false;
|
||||
$this->updateInfo->updatenow = false;
|
||||
|
||||
return $this->saveUpdateInfo();
|
||||
}
|
||||
// set other config settings
|
||||
$this->dropboxConfig['save'] = false;
|
||||
$this->dropboxConfig['download'] = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function saveJson($data,$filename)
|
||||
|
Reference in New Issue
Block a user