コード例 #1
0
 /**
  * @AdminRequired
  * @NoCSRFRequired
  */
 public function Save()
 {
     \OCP\JSON::setContentTypeHeader('application/json');
     $Error = false;
     $Message = null;
     if (isset($_POST['KEY']) && strlen(trim($_POST['KEY'])) > 0 && isset($_POST['VAL']) && strlen(trim($_POST['VAL'])) >= 0) {
         $PostKey = $_POST['KEY'];
         $PostValue = $_POST['VAL'];
         if (in_array($PostKey, $this->OCDSettingKeys)) {
             $this->Settings->SetKey($PostKey);
             if (strcmp($PostKey, 'YTDLBinary') == 0) {
                 $PostValue = trim(str_replace(' ', '\\ ', $PostValue));
                 if (!file_exists($PostValue)) {
                     $PostValue = null;
                     $Error = true;
                     $Message = (string) $this->L10N->t('Unable to find YouTube-DL binary');
                 }
             } elseif (strcmp($PostKey, 'ProxyAddress') == 0) {
                 if (!Tools::CheckURL($PostValue) && strlen(trim($PostValue)) > 0) {
                     $PostValue = null;
                     $Error = true;
                     $Message = (string) $this->L10N->t('Invalid proxy address URL');
                 }
             } elseif (strcmp($PostKey, 'ProxyPort') == 0) {
                 if (!is_numeric($PostValue)) {
                     $PostValue = null;
                     $Error = true;
                     $Message = (string) $this->L10N->t('Proxy port should be a numeric value');
                 } elseif ($PostValue <= 0 || $PostValue > 65536) {
                     $PostValue = null;
                     $Error = true;
                     $Message = (string) $this->L10N->t('Proxy port should be a value from 1 to 65536');
                 }
             } elseif (strcmp($PostKey, 'CheckForUpdates') == 0) {
                 if (!in_array($PostValue, array('Y', 'N'))) {
                     $PostValue = 'Y';
                 }
             } elseif (strcmp($PostKey, 'WhichDownloader') == 0) {
                 if (!in_array($PostValue, array('ARIA2', 'CURL'))) {
                     $PostValue = 'ARIA2';
                 } elseif (strcmp($PostValue, 'ARIA2') != 0) {
                     Tools::ResetAria2($this->DbType);
                 }
             } elseif (strcmp($PostKey, 'ProxyOnlyWithYTDL') == 0) {
                 if (!in_array($PostValue, array('Y', 'N'))) {
                     $PostValue = 'N';
                 }
             } else {
                 $PostValue = null;
                 $Error = true;
             }
             if (strlen(trim($PostValue)) <= 0) {
                 $PostValue = null;
             }
             if ($this->Settings->CheckIfKeyExists()) {
                 $this->Settings->UpdateValue($PostValue);
             } else {
                 $this->Settings->InsertValue($PostValue);
             }
         }
     }
     return new JSONResponse(array('ERROR' => $Error, 'MESSAGE' => is_null($Message) ? (string) $this->L10N->t('Saved') : $Message));
 }