diff --git a/appinfo/info.xml b/appinfo/info.xml index da689d6..a5e0e6d 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -20,7 +20,7 @@ download videos from 700+ video sites(youtube,youku,vimo,dailymotion,twitter,fac https://github.com/shiningw/ncdownloader - + diff --git a/hooks/run.php b/hooks/run.php new file mode 100644 index 0000000..fc786c5 --- /dev/null +++ b/hooks/run.php @@ -0,0 +1,13 @@ +#!/usr/bin/php + +add($cmd); +$app->run(); diff --git a/lib/Command/Aria2Command.php b/lib/Command/Aria2Command.php index 68dceb1..e334f68 100644 --- a/lib/Command/Aria2Command.php +++ b/lib/Command/Aria2Command.php @@ -11,9 +11,12 @@ use Symfony\Component\Console\Output\OutputInterface; class Aria2Command extends Base { +// public function __construct() private $dbconn; public function __construct(\OCP\IDBConnection $connection) { +// $this->dbconn = new DbHelper(); + $this->dbconn = new DbHelper($connection); parent::__construct(); } diff --git a/lib/Controller/Aria2Controller.php b/lib/Controller/Aria2Controller.php index 83ca542..2aef8cd 100644 --- a/lib/Controller/Aria2Controller.php +++ b/lib/Controller/Aria2Controller.php @@ -11,6 +11,7 @@ use OCP\AppFramework\Http\JSONResponse; use OCP\Files\IRootFolder; use OCP\IL10N; use OCP\IRequest; +use OC_Util; use \OC\Files\Filesystem; class Aria2Controller extends Controller @@ -33,9 +34,9 @@ class Aria2Controller extends Controller $this->uid = $UserId; $this->l10n = $IL10N; $this->rootFolder = $rootFolder; - $this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); + $this->urlGenerator = \OC::$server->getURLGenerator(); $this->downloadDir = Helper::getDownloadDir(); - \OC_Util::setupFS(); + OC_Util::setupFS(); //$this->config = \OC::$server->getAppConfig(); $this->aria2 = $aria2; $this->aria2->init(); diff --git a/lib/Controller/MainController.php b/lib/Controller/MainController.php index a82c699..0066fb3 100644 --- a/lib/Controller/MainController.php +++ b/lib/Controller/MainController.php @@ -15,6 +15,7 @@ use OCP\AppFramework\Http\TemplateResponse; //use OCP\Files\IRootFolder; use OCP\IL10N; use OCP\IRequest; +use OC_Util; use OCP\Util; class MainController extends Controller @@ -46,7 +47,7 @@ class MainController extends Controller //$this->rootFolder = $rootFolder; $this->aria2 = $aria2; $this->aria2->init(); - $this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); + $this->urlGenerator = \OC::$server->getURLGenerator(); $this->dbconn = new DbHelper(); $this->counters = new Counters($aria2, $this->dbconn, $UserId); $this->ytdl = $ytdl; @@ -63,8 +64,8 @@ class MainController extends Controller { // $str = \OC::$server->getDatabaseConnection()->getInner()->getPrefix(); //$config = \OC::$server->getAppConfig(); - Util::addScript($this->appName, 'app'); - Util::addStyle($this->appName, 'app'); + Util::addInitScript($this->appName, 'app'); + OC_Util::addStyle($this->appName, 'app'); $params = $this->buildParams(); $response = new TemplateResponse($this->appName, 'Index', $params); diff --git a/lib/Controller/SearchController.php b/lib/Controller/SearchController.php index 371ea2d..5d52679 100644 --- a/lib/Controller/SearchController.php +++ b/lib/Controller/SearchController.php @@ -23,7 +23,7 @@ class SearchController extends Controller parent::__construct($appName, $request); $this->appName = $appName; $this->uid = $UserId; - $this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); + $this->urlGenerator = \OC::$server->getURLGenerator(); $this->search = new siteSearch(); } /** diff --git a/lib/Controller/YtdlController.php b/lib/Controller/YtdlController.php index 1d52b97..5270408 100644 --- a/lib/Controller/YtdlController.php +++ b/lib/Controller/YtdlController.php @@ -32,7 +32,7 @@ class YtdlController extends Controller parent::__construct($appName, $request); $this->appName = $appName; $this->uid = $UserId; - $this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); + $this->urlGenerator = \OC::$server->getURLGenerator(); $this->l10n = $IL10N; $this->downloadDir = Helper::getDownloadDir(); $this->dbconn = new DbHelper(); diff --git a/lib/Db/Helper.php b/lib/Db/Helper.php index 5cc6862..91f3684 100644 --- a/lib/Db/Helper.php +++ b/lib/Db/Helper.php @@ -12,7 +12,7 @@ class Helper public function __construct() { - $this->conn = \OC::$server->get(\OCP\IDBConnection::class); + $this->conn = \OC::$server->getDatabaseConnection(); $this->queryBuilder = $this->conn->getQueryBuilder(); $this->prefixedTable = $this->queryBuilder->getTableName($this->table); //$container = \OC::$server->query(\OCP\IServerContainer::class); @@ -130,7 +130,7 @@ class Helper public function getDBType(): string { - return \OC::$server->get(\OCP\IConfig::class)->getSystemValue('dbtype', "mysql"); + return \OC::$server->getConfig()->getSystemValue('dbtype', "mysql"); } public function getExtra($data) diff --git a/lib/Db/Settings.php b/lib/Db/Settings.php index 63e899a..65e6dce 100644 --- a/lib/Db/Settings.php +++ b/lib/Db/Settings.php @@ -2,7 +2,9 @@ namespace OCA\NCDownloader\Db; -class Settings +use OC\AllConfig; + +class Settings extends AllConfig { //@config OC\AppConfig private $appConfig; @@ -10,6 +12,8 @@ class Settings //@OC\SystemConfig private $sysConfig; + //@OC\AllConfig + private $allConfig; private $user; private $appName; //type of settings (system = 1 or app =2) @@ -18,11 +22,13 @@ class Settings public const TYPE = ['SYSTEM' => 1, 'USER' => 2, 'APP' => 3]; public function __construct($user = null) { - $this->appConfig = \OC::$server->get(\OCP\IConfig::class); - $this->sysConfig = \OC::$server->get(\OCP\IConfig::class); + //$this->appConfig = \OC::$server->getAppConfig(); + //$this->appConfig = \OC::$server->getAppConfig(); + $this->sysConfig = \OC::$server->getSystemConfig(); $this->appName = 'ncdownloader'; $this->type = self::TYPE['USER']; $this->user = $user; + $this->allConfig = new AllConfig($this->sysConfig); //$this->connAdapter = \OC::$server->getDatabaseConnection(); //$this->conn = $this->connAdapter->getInner(); } @@ -42,16 +48,16 @@ class Settings public function get($key, $default = null) { if ($this->type == self::TYPE['USER'] && isset($this->user)) { - return $this->appConfig->getUserValue($this->user, $this->appName, $key, $default); + return $this->allConfig->getUserValue($this->user, $this->appName, $key, $default); } else if ($this->type == self::TYPE['SYSTEM']) { - return $this->appConfig->getSystemValue($key, $default); + return $this->allConfig->getSystemValue($key, $default); } else { - return $this->appConfig->getAppValue($this->appName, $key, $default); + return $this->allConfig->getAppValue($this->appName, $key, $default); } } public function getAria2() { - $settings = $this->appConfig->getUserValue($this->user, $this->appName, "custom_aria2_settings", ''); + $settings = $this->allConfig->getUserValue($this->user, $this->appName, "custom_aria2_settings", ''); return json_decode($settings, 1); } @@ -74,11 +80,11 @@ class Settings { try { if ($this->type == self::TYPE['USER'] && isset($this->user)) { - $this->appConfig->setUserValue($this->user, $this->appName, $key, $value); + $this->allConfig->setUserValue($this->user, $this->appName, $key, $value); } else if ($this->type == self::TYPE['SYSTEM']) { - $this->appConfig->setSystemValue($key, $value); + $this->allConfig->setSystemValue($key, $value); } else { - $this->appConfig->setAppValue($this->appName, $key, $value); + $this->allConfig->setAppValue($this->appName, $key, $value); } } catch (\Exception $e) { return ['error' => $e->getMessage()]; @@ -91,22 +97,22 @@ class Settings $keys = $this->getAllKeys(); $value = []; foreach ($keys as $key) { - $value[$key] = $this->appConfig->getAppValue($this->appName, $key); + $value[$key] = $this->allConfig->getAppValue($this->appName, $key); } return $value; } public function getAllKeys() { - return $this->appConfig->getAppKeys($this->appName); + return $this->allConfig->getAppKeys($this->appName); } public function getAllUserSettings() { - $keys = $this->appConfig->getUserKeys($this->user, $this->appName); + $keys = $this->allConfig->getUserKeys($this->user, $this->appName); $value = []; foreach ($keys as $key) { - $value[$key] = $this->appConfig->getUserValue($this->user, $this->appName, $key); + $value[$key] = $this->allConfig->getUserValue($this->user, $this->appName, $key); } return $value; } -} \ No newline at end of file +} diff --git a/lib/Search/siteSearch.php b/lib/Search/siteSearch.php index 3c26520..7b98482 100644 --- a/lib/Search/siteSearch.php +++ b/lib/Search/siteSearch.php @@ -15,7 +15,7 @@ class siteSearch private $defaultSite = __NAMESPACE__ . '\Sites\TPB'; public function __construct() { - $this->container = \OC::$server->get(IServerContainer::class); + $this->container = \OC::$server->query(IServerContainer::class); $this->site = __NAMESPACE__ . '\Sites\TPB'; } public function go($keyword): array diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php index 5c6addc..caaf971 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -10,8 +10,6 @@ use OCP\Settings\ISettings; use OCA\NCDownloader\Db\Settings; use OCA\NCDownloader\Tools\Helper; -use OCP\IUserManager; - class Personal implements ISettings { @@ -21,22 +19,18 @@ class Personal implements ISettings private $timeFactory; /** @var IConfig */ private $config; - /** @var IUserManager */ - private $userManager; private $uid; private $settings; public function __construct( IDBConnection $connection, ITimeFactory $timeFactory, - IConfig $config, - IUserManager $userManager + IConfig $config ) { $this->connection = $connection; $this->timeFactory = $timeFactory; $this->config = $config; - $this->userManager = $userManager; - $this->uid = \OC::$server->get(\OCP\IUserSession::class)->getUser()->getUID(); + $this->uid = \OC::$server->getUserSession()->getUser()->getUID(); $this->settings = new Settings($this->uid); } @@ -46,10 +40,7 @@ class Personal implements ISettings public function getForm() { $path = '/apps/ncdownloader/personal/save'; - $user = $this->userManager->get($this->uid); - $groupManager = \OC::$server->get(\OCP\IGroupManager::class); - $isAdmin = ($user !== null) ? $groupManager->isInGroup($user->getUID(), 'admin') : false; - $parameters = [ + $parameters = [ "settings" => [ "ncd_downloader_dir" => Helper::getDownloadDir(), "ncd_torrents_dir" => $this->settings->get("ncd_torrents_dir"), @@ -58,7 +49,7 @@ class Personal implements ISettings 'ncd_seed_time' => $this->settings->get("ncd_seed_time"), "path" => $path, "disallow_aria2_settings" => Helper::getAdminSettings("disallow_aria2_settings"), - "is_admin" => $isAdmin, + "is_admin" => \OC_User::isAdminUser($this->uid), ], "options" => [ [ diff --git a/lib/Tools/Helper.php b/lib/Tools/Helper.php index da0c79b..8328a18 100644 --- a/lib/Tools/Helper.php +++ b/lib/Tools/Helper.php @@ -8,6 +8,7 @@ use OCA\NCDownloader\Aria2\Options as aria2Options; use OCA\NCDownloader\Db\Settings; use OCP\IUser; use OC\Files\Filesystem; +use OC_Util; use Psr\Log\LoggerInterface; use OCA\NCDownloader\Aria2\Aria2; use OCA\NCDownloader\Ytdl\Ytdl; @@ -147,6 +148,8 @@ class Helper if (is_array($msg)) { $msg = implode(",", $msg); } + $logger = \OC::$server->get(LoggerInterface::class); +// $logger = \OC::$server->getLogger(); $logger = self::getLogger(); $logger->error($msg, ['app' => 'ncdownloader']); } @@ -159,19 +162,7 @@ class Helper { if (!isset($filter)) { $filter = array( - 'status', - 'followedBy', - 'totalLength', - 'errorMessage', - 'dir', - 'uploadLength', - 'completedLength', - 'downloadSpeed', - 'files', - 'numSeeders', - 'connections', - 'gid', - 'following', + 'status', 'followedBy', 'totalLength', 'errorMessage', 'dir', 'uploadLength', 'completedLength', 'downloadSpeed', 'files', 'numSeeders', 'connections', 'gid', 'following', ); } $value = array_filter($data, function ($k) use ($filter) { @@ -236,7 +227,8 @@ class Helper if ($memcache->hasKey($program)) { return $memcache->get($program); } - $dataPath = \OC::$server->get(\OCP\IConfig::class)->getSystemValue('datadirectory'); + + $dataPath = \OC::$server->getSystemConfig()->getValue('datadirectory'); $paths = ['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin', '/opt/bin', $dataPath . "/bin"]; $result = $default; $exeSniffer = new ExecutableFinder(); @@ -403,13 +395,13 @@ class Helper public static function getDataDir(): string { - return \OC::$server->get(\OCP\IConfig::class)->getSystemValue('datadirectory'); + return \OC::$server->getSystemConfig()->getValue('datadirectory'); } public static function getLocalFolder(string $path): string { if (self::getUID()) { - \OC_Util::setupFS(); + OC_Util::setupFS(); //get the real path of the file in the filesystem return \OC\Files\Filesystem::getLocalFile($path); } @@ -429,6 +421,7 @@ class Helper public static function getUser(): ?IUser { +// return \OC::$server->getUserSession()->getUser(); return \OC::$server->get(\OCP\IUserSession::class)->getUser(); } @@ -498,7 +491,7 @@ class Helper public static function getAppPath(): string { - return \OC::$server->get(\OCP\App\IAppManager::class)->getAppPath('ncdownloader'); + return \OC::$server->getAppManager()->getAppPath('ncdownloader'); } public static function folderUpdated(string $dir): bool { diff --git a/lib/Ytdl/Helper.php b/lib/Ytdl/Helper.php index 9471812..5e4853f 100644 --- a/lib/Ytdl/Helper.php +++ b/lib/Ytdl/Helper.php @@ -19,7 +19,7 @@ class Helper { $this->dbconn = new DbHelper(); $this->tablename = $this->dbconn->queryBuilder->getTableName("ncdownloader_info"); - $this->user = \OC::$server->get(\OCP\IUserSession::class)->getUser()->getUID(); + $this->user = \OC::$server->getUserSession()->getUser()->getUID(); } public static function create()