diff --git a/lib/Controller/Aria2Controller.php b/lib/Controller/Aria2Controller.php index 2aef8cd..83ca542 100644 --- a/lib/Controller/Aria2Controller.php +++ b/lib/Controller/Aria2Controller.php @@ -11,7 +11,6 @@ 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 @@ -34,9 +33,9 @@ class Aria2Controller extends Controller $this->uid = $UserId; $this->l10n = $IL10N; $this->rootFolder = $rootFolder; - $this->urlGenerator = \OC::$server->getURLGenerator(); + $this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); $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 fae1add..a82c699 100644 --- a/lib/Controller/MainController.php +++ b/lib/Controller/MainController.php @@ -15,7 +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 +46,7 @@ class MainController extends Controller //$this->rootFolder = $rootFolder; $this->aria2 = $aria2; $this->aria2->init(); - $this->urlGenerator = \OC::$server->getURLGenerator(); + $this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); $this->dbconn = new DbHelper(); $this->counters = new Counters($aria2, $this->dbconn, $UserId); $this->ytdl = $ytdl; @@ -63,8 +63,8 @@ class MainController extends Controller { // $str = \OC::$server->getDatabaseConnection()->getInner()->getPrefix(); //$config = \OC::$server->getAppConfig(); - OC_Util::addScript($this->appName, 'app'); - OC_Util::addStyle($this->appName, 'app'); + Util::addScript($this->appName, 'app'); + 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 5d52679..371ea2d 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->getURLGenerator(); + $this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); $this->search = new siteSearch(); } /** diff --git a/lib/Controller/YtdlController.php b/lib/Controller/YtdlController.php index 7e070ae..b114834 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->getURLGenerator(); + $this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); $this->l10n = $IL10N; $this->downloadDir = Helper::getDownloadDir(); $this->dbconn = new DbHelper(); diff --git a/lib/Db/Helper.php b/lib/Db/Helper.php index 91f3684..5cc6862 100644 --- a/lib/Db/Helper.php +++ b/lib/Db/Helper.php @@ -12,7 +12,7 @@ class Helper public function __construct() { - $this->conn = \OC::$server->getDatabaseConnection(); + $this->conn = \OC::$server->get(\OCP\IDBConnection::class); $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->getConfig()->getSystemValue('dbtype', "mysql"); + return \OC::$server->get(\OCP\IConfig::class)->getSystemValue('dbtype', "mysql"); } public function getExtra($data) diff --git a/lib/Db/Settings.php b/lib/Db/Settings.php index e0ec2a5..63e899a 100644 --- a/lib/Db/Settings.php +++ b/lib/Db/Settings.php @@ -2,9 +2,7 @@ namespace OCA\NCDownloader\Db; -use OC\AllConfig; - -class Settings extends AllConfig +class Settings { //@config OC\AppConfig private $appConfig; @@ -12,8 +10,6 @@ class Settings extends AllConfig //@OC\SystemConfig private $sysConfig; - //@OC\AllConfig - private $allConfig; private $user; private $appName; //type of settings (system = 1 or app =2) @@ -22,12 +18,11 @@ class Settings extends AllConfig public const TYPE = ['SYSTEM' => 1, 'USER' => 2, 'APP' => 3]; public function __construct($user = null) { - $this->appConfig = \OC::$server->getAppConfig(); - $this->sysConfig = \OC::$server->getSystemConfig(); + $this->appConfig = \OC::$server->get(\OCP\IConfig::class); + $this->sysConfig = \OC::$server->get(\OCP\IConfig::class); $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(); } @@ -47,16 +42,16 @@ class Settings extends AllConfig public function get($key, $default = null) { if ($this->type == self::TYPE['USER'] && isset($this->user)) { - return $this->allConfig->getUserValue($this->user, $this->appName, $key, $default); + return $this->appConfig->getUserValue($this->user, $this->appName, $key, $default); } else if ($this->type == self::TYPE['SYSTEM']) { - return $this->allConfig->getSystemValue($key, $default); + return $this->appConfig->getSystemValue($key, $default); } else { - return $this->allConfig->getAppValue($this->appName, $key, $default); + return $this->appConfig->getAppValue($this->appName, $key, $default); } } public function getAria2() { - $settings = $this->allConfig->getUserValue($this->user, $this->appName, "custom_aria2_settings", ''); + $settings = $this->appConfig->getUserValue($this->user, $this->appName, "custom_aria2_settings", ''); return json_decode($settings, 1); } @@ -79,11 +74,11 @@ class Settings extends AllConfig { try { if ($this->type == self::TYPE['USER'] && isset($this->user)) { - $this->allConfig->setUserValue($this->user, $this->appName, $key, $value); + $this->appConfig->setUserValue($this->user, $this->appName, $key, $value); } else if ($this->type == self::TYPE['SYSTEM']) { - $this->allConfig->setSystemValue($key, $value); + $this->appConfig->setSystemValue($key, $value); } else { - $this->allConfig->setAppValue($this->appName, $key, $value); + $this->appConfig->setAppValue($this->appName, $key, $value); } } catch (\Exception $e) { return ['error' => $e->getMessage()]; @@ -96,22 +91,22 @@ class Settings extends AllConfig $keys = $this->getAllKeys(); $value = []; foreach ($keys as $key) { - $value[$key] = $this->allConfig->getAppValue($this->appName, $key); + $value[$key] = $this->appConfig->getAppValue($this->appName, $key); } return $value; } public function getAllKeys() { - return $this->allConfig->getAppKeys($this->appName); + return $this->appConfig->getAppKeys($this->appName); } public function getAllUserSettings() { - $keys = $this->allConfig->getUserKeys($this->user, $this->appName); + $keys = $this->appConfig->getUserKeys($this->user, $this->appName); $value = []; foreach ($keys as $key) { - $value[$key] = $this->allConfig->getUserValue($this->user, $this->appName, $key); + $value[$key] = $this->appConfig->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 7b98482..3c26520 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->query(IServerContainer::class); + $this->container = \OC::$server->get(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 caaf971..5c6addc 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -10,6 +10,8 @@ use OCP\Settings\ISettings; use OCA\NCDownloader\Db\Settings; use OCA\NCDownloader\Tools\Helper; +use OCP\IUserManager; + class Personal implements ISettings { @@ -19,18 +21,22 @@ 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 + IConfig $config, + IUserManager $userManager ) { $this->connection = $connection; $this->timeFactory = $timeFactory; $this->config = $config; - $this->uid = \OC::$server->getUserSession()->getUser()->getUID(); + $this->userManager = $userManager; + $this->uid = \OC::$server->get(\OCP\IUserSession::class)->getUser()->getUID(); $this->settings = new Settings($this->uid); } @@ -40,7 +46,10 @@ class Personal implements ISettings public function getForm() { $path = '/apps/ncdownloader/personal/save'; - $parameters = [ + $user = $this->userManager->get($this->uid); + $groupManager = \OC::$server->get(\OCP\IGroupManager::class); + $isAdmin = ($user !== null) ? $groupManager->isInGroup($user->getUID(), 'admin') : false; + $parameters = [ "settings" => [ "ncd_downloader_dir" => Helper::getDownloadDir(), "ncd_torrents_dir" => $this->settings->get("ncd_torrents_dir"), @@ -49,7 +58,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" => \OC_User::isAdminUser($this->uid), + "is_admin" => $isAdmin, ], "options" => [ [ diff --git a/lib/Tools/Helper.php b/lib/Tools/Helper.php index 89ed61a..da0c79b 100644 --- a/lib/Tools/Helper.php +++ b/lib/Tools/Helper.php @@ -8,7 +8,6 @@ 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; @@ -160,7 +159,19 @@ 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) { @@ -225,8 +236,7 @@ class Helper if ($memcache->hasKey($program)) { return $memcache->get($program); } - - $dataPath = \OC::$server->getSystemConfig()->getValue('datadirectory'); + $dataPath = \OC::$server->get(\OCP\IConfig::class)->getSystemValue('datadirectory'); $paths = ['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin', '/opt/bin', $dataPath . "/bin"]; $result = $default; $exeSniffer = new ExecutableFinder(); @@ -393,13 +403,13 @@ class Helper public static function getDataDir(): string { - return \OC::$server->getSystemConfig()->getValue('datadirectory'); + return \OC::$server->get(\OCP\IConfig::class)->getSystemValue('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); } @@ -488,7 +498,7 @@ class Helper public static function getAppPath(): string { - return \OC::$server->getAppManager()->getAppPath('ncdownloader'); + return \OC::$server->get(\OCP\App\IAppManager::class)->getAppPath('ncdownloader'); } public static function folderUpdated(string $dir): bool { diff --git a/lib/Ytdl/Helper.php b/lib/Ytdl/Helper.php index cff4dbb..c5ce7d2 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->getUserSession()->getUser()->getUID(); + $this->user = \OC::$server->get(\OCP\IUserSession::class)->getUser()->getUID(); } public static function create()