Beispiel #1
0
 function manage()
 {
     global $cms;
     global $parametersMod;
     $answer = '';
     if (isset($_GET['action'])) {
         switch ($_GET['action']) {
             case 'import':
                 $standardForm = new \Library\Php\Form\Standard($this->importFields);
                 $errors = $standardForm->getErrors();
                 if (sizeof($errors) > 0) {
                     $answer = $standardForm->generateErrorAnswer($errors);
                 } else {
                     $fileUpload = new \Library\Php\File\UploadFile();
                     $fileUpload->allowOnly(array("php", "conf", "txt"));
                     $file = $fileUpload->upload('config', TMP_FILE_DIR);
                     if ($file == UPLOAD_ERR_OK) {
                         $_SESSION['backend_modules']['developer']['config_exp_imp']['uploaded_file'] = BASE_DIR . TMP_FILE_DIR . $fileUpload->fileName;
                         $answer .= HtmlOutput::header();
                         $answer .= '
             <script type="text/javascript">
               //<![CDATA[
               parent.document.location = \'' . $cms->generateUrl($cms->curModId, 'action=import_uploaded') . '\';
               //]]
             </script>';
                         $answer .= HtmlOutput::footer();
                     } else {
                         $errors['config'] = 'impossible to upload';
                         $answer .= HtmlOutput::header();
                         $answer .= $standardForm->generateErrorAnswer($errors);
                         $answer .= HtmlOutput::footer();
                     }
                 }
                 break;
             case 'import_uploaded':
                 $info = pathinfo($_SESSION['backend_modules']['developer']['config_exp_imp']['uploaded_file']);
                 if ($info['extension'] == 'conf') {
                     $answer .= HtmlOutput::header();
                     $config = unserialize(file_get_contents($_SESSION['backend_modules']['developer']['config_exp_imp']['uploaded_file']));
                     $answer .= '<h1>' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'import_title_preview')) . '</h1>';
                     $answer .= '<br /><a href="' . $cms->generateUrl($cms->curModId, 'action=import_confirmed') . '" class="button">' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'import_button_preview')) . '</a><br /><br /><br />';
                     $answer .= $config->previewParameters();
                     $answer .= '<br /><a href="' . $cms->generateUrl($cms->curModId, 'action=import_confirmed') . '" class="button">' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'import_button_preview')) . '</a><br /><br />';
                     $answer .= HtmlOutput::footer();
                 } else {
                     $answer .= HtmlOutput::header();
                     $answer .= '<h1>' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'import_title_preview')) . '</h1>';
                     $answer .= '<br /><a href="' . $cms->generateUrl($cms->curModId, 'action=import_confirmed') . '" class="button">' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'import_button_preview')) . '</a><br /><br /><br />';
                     $answer .= \Modules\developer\localization\Manager::previewParameters($_SESSION['backend_modules']['developer']['config_exp_imp']['uploaded_file']);
                     $answer .= '<br /><a href="' . $cms->generateUrl($cms->curModId, 'action=import_confirmed') . '" class="button">' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'import_button_preview')) . '</a><br /><br />';
                     $answer .= HtmlOutput::footer();
                     $answer .= HtmlOutput::header();
                 }
                 break;
             case 'import_confirmed':
                 if (isset($_SESSION['backend_modules']['developer']['config_exp_imp']['uploaded_file'])) {
                     $info = pathinfo($_SESSION['backend_modules']['developer']['config_exp_imp']['uploaded_file']);
                     if ($info['extension'] == 'conf') {
                         $config = unserialize(file_get_contents($_SESSION['backend_modules']['developer']['config_exp_imp']['uploaded_file']));
                         $answer .= HtmlOutput::header();
                         //$config_import = new mod_developer_config_exp_imp_parameters();
                         //$config_import->save_parameters();
                         $config->saveParameters();
                         $answer .= '
             <div class="content">
               <h1>' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'parameters_imported')) . '</h1>
               <a href="' . $cms->generateUrl($cms->curModId) . '" class="button">' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'continue')) . '</a>
               <div class="clear"><!-- --></div>
             </div>
           ';
                         $answer .= HtmlOutput::footer();
                     } else {
                         $answer .= HtmlOutput::header();
                         //$config_import = new mod_developer_config_exp_imp_parameters();
                         //$config_import->save_parameters();
                         \Modules\developer\localization\Manager::saveParameters($_SESSION['backend_modules']['developer']['config_exp_imp']['uploaded_file']);
                         $answer .= '
           <div class="content">
             <h1>' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'parameters_imported')) . '</h1>
             <a href="' . $cms->generateUrl($cms->curModId) . '" class="button">' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'continue')) . '</a>
             <div class="clear">&nbsp;<!-- --></div>
           </div>
             ';
                         $answer .= HtmlOutput::footer();
                     }
                 }
                 break;
             case 'export':
                 $standardForm = new \Library\Php\Form\Standard($this->exportFields);
                 $errors = $standardForm->getErrors();
                 if (sizeof($errors) > 0) {
                     $answer .= HtmlOutput::header();
                     $answer .= $standardForm->generateErrorAnswer($errors);
                     $answer .= HtmlOutput::footer();
                 } else {
                     $file = $this->writeParametersToFile();
                     header("Content-type: application/octet-stream");
                     header("Content-Disposition: attachment; filename=\"" . $file . "\"");
                     $answer = file_get_contents(TMP_FILE_DIR . $file);
                 }
                 break;
         }
     } else {
         $answer .= HtmlOutput::header();
         $answer .= '<div class="content">';
         $answer .= '<h1>' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'import_title')) . '</h1>';
         $answer .= $this->importForm();
         $answer .= '</div><div class="content">';
         $answer .= '<h1>' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'export_title')) . '</h1>';
         $answer .= $this->exportForm();
         $answer .= '</div>';
         $answer .= HtmlOutput::footer();
     }
     return $answer;
 }
 function checkField($prefix, $action, $area)
 {
     global $parametersMod;
     if ($action == 'insert' && $this->disabledOnInsert || $action == 'insert' && !$this->visibleOnInsert || $action == 'update' && $this->disabledOnUpdate || $action == 'update' && !$this->visibleOnUpdate) {
         return null;
     }
     $uploadFile = new \Library\Php\File\UploadFile();
     if (sizeof($this->extensions) > 0) {
         $uploadFile->allowOnly($this->extensions);
     }
     if (isset($_FILES[$prefix])) {
         $error = $uploadFile->upload($prefix, TMP_FILE_DIR);
         if ($error == UPLOAD_ERR_OK) {
             $this->memFile = $uploadFile->fileName;
             return null;
         } elseif ($error == UPLOAD_ERR_NO_FILE && $this->required && !isset($this->memFile) && $action == 'insert') {
             return $parametersMod->getValue('developer', 'std_mod', 'admin_translations', 'error_required');
         } elseif ($error == UPLOAD_ERR_NO_FILE) {
             return null;
         } elseif ($error == UPLOAD_ERR_EXTENSION) {
             return $parametersMod->getValue('developer', 'std_mod', 'admin_translations', 'error_file_type') . ' ' . implode(', ', $this->extensions);
         } else {
             return $parametersMod->getValue('developer', 'std_mod', 'admin_translations', 'error_file_upload') . " " . $error;
         }
     }
     if (isset($_POST[$prefix . '_delete']) && $this->required) {
         return $parametersMod->getValue('developer', 'std_mod', 'admin_translations', 'error_required');
     }
     return null;
 }
Beispiel #3
0
 function manage()
 {
     global $cms;
     global $parametersMod;
     $answer = '';
     if (isset($_GET['action'])) {
         switch ($_GET['action']) {
             case 'import':
                 $standardForm = new \Library\Php\Form\Standard($this->importFields);
                 $errors = $standardForm->getErrors();
                 if (sizeof($errors) > 0) {
                     $answer = $standardForm->generateErrorAnswer($errors);
                 } else {
                     $fileUpload = new \Library\Php\File\UploadFile();
                     $fileUpload->allowOnly(array("php"));
                     $file = $fileUpload->upload('config', TMP_FILE_DIR);
                     //security check
                     if ($file == UPLOAD_ERR_OK && function_exists('token_get_all')) {
                         $error = false;
                         $content = file_get_contents(BASE_DIR . TMP_FILE_DIR . $fileUpload->fileName);
                         $tokens = token_get_all($content);
                         foreach ($tokens as $key => $token) {
                             if (is_array($token)) {
                                 if ($token[0] == 307) {
                                     $error = true;
                                 }
                             }
                         }
                         if ($error) {
                             unlink(BASE_DIR . TMP_FILE_DIR . $fileUpload->fileName);
                             $errors['config'] = 'Incorrect language file';
                             $answer .= HtmlOutput::header();
                             $answer .= $standardForm->generateErrorAnswer($errors);
                             $answer .= HtmlOutput::footer();
                             break;
                         }
                     }
                     //end security check
                     if ($file == UPLOAD_ERR_OK) {
                         $_SESSION['backend_modules']['developer']['localization']['uploaded_file'] = BASE_DIR . TMP_FILE_DIR . $fileUpload->fileName;
                         $answer .= HtmlOutput::header();
                         $answer .= '
             <script type="text/javascript">
               //<![CDATA[
               parent.document.location = \'' . $cms->generateUrl($cms->curModId, 'action=import_uploaded') . '\';
               //]]
             </script>';
                         $answer .= HtmlOutput::footer();
                     } else {
                         $errors['config'] = 'impossible to upload';
                         $answer .= HtmlOutput::header();
                         $answer .= $standardForm->generateErrorAnswer($errors);
                         $answer .= HtmlOutput::footer();
                     }
                 }
                 break;
             case 'import_uploaded':
                 $answer .= HtmlOutput::header();
                 $answer .= '<h1>' . htmlspecialchars($parametersMod->getValue('developer', 'localization', 'admin_translations', 'preview')) . '</h1>';
                 $answer .= '<br /><a href="' . $cms->generateUrl($cms->curModId, 'action=import_confirmed') . '" class="button">' . htmlspecialchars($parametersMod->getValue('developer', 'localization', 'admin_translations', 'import_language_file')) . '</a><br /><br /><br />';
                 $answer .= $this->previewParameters($_SESSION['backend_modules']['developer']['localization']['uploaded_file']);
                 $answer .= '<br /><a href="' . $cms->generateUrl($cms->curModId, 'action=import_confirmed') . '" class="button">' . htmlspecialchars($parametersMod->getValue('developer', 'localization', 'admin_translations', 'import_language_file')) . '</a><br /><br />';
                 $answer .= HtmlOutput::footer();
                 break;
             case 'import_confirmed':
                 if (isset($_SESSION['backend_modules']['developer']['localization']['uploaded_file'])) {
                     //$config = unserialize(file_get_contents(TMP_FILE_DIR.$_SESSION['backend_modules']['developer']['config_exp_imp']['uploaded_file']));
                     $answer .= HtmlOutput::header();
                     //$config_import = new mod_developer_config_exp_imp_parameters();
                     //$config_import->save_parameters();
                     $this->saveParameters($_SESSION['backend_modules']['developer']['localization']['uploaded_file']);
                     $answer .= '
           <div class="content">
             <h1>' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'parameters_imported')) . '</h1>
             <a href="' . $cms->generateUrl($cms->curModId) . '" class="button">' . htmlspecialchars($parametersMod->getValue('developer', 'config_exp_imp', 'admin_translations', 'continue')) . '</a>
             <div class="clear">&nbsp;<!-- --></div>
           </div>
         ';
                     $answer .= HtmlOutput::footer();
                 }
                 break;
             case 'export':
                 if ($_REQUEST['language'] == 'backend') {
                     $standardForm = new \Library\Php\Form\Standard($this->exportFields);
                     $errors = $standardForm->getErrors();
                     if (sizeof($errors) > 0) {
                         $answer .= HtmlOutput::header();
                         $answer .= $standardForm->generateErrorAnswer($errors);
                         $answer .= HtmlOutput::footer();
                     } else {
                         header("Content-type: application/octet-stream");
                         header("Content-Disposition: attachment; filename=\"administrator_interface_" . $parametersMod->getValue('standard', 'configuration', 'advanced_options', 'administrator_interface_language') . ".php\"");
                         $answer = $this->generateAdministratorInterfaceLanguageFile();
                     }
                 } else {
                     $standardForm = new \Library\Php\Form\Standard($this->exportFields);
                     $errors = $standardForm->getErrors();
                     if (sizeof($errors) > 0) {
                         $answer .= HtmlOutput::header();
                         $answer .= $standardForm->generateErrorAnswer($errors);
                         $answer .= HtmlOutput::footer();
                     } else {
                         header("Content-type: application/octet-stream");
                         $language = Db::getLanguage($_REQUEST['language']);
                         header("Content-Disposition: attachment; filename=\"public_interface_" . $language['code'] . ".php\"");
                         $answer = $this->generatePublicInterfaceLanguageFile($_REQUEST['language']);
                     }
                 }
                 break;
         }
     } else {
         $answer .= HtmlOutput::header();
         $answer .= '<div class="content">';
         $answer .= '<h1>' . htmlspecialchars($parametersMod->getValue('developer', 'localization', 'admin_translations', 'import_language_file')) . '</h1>';
         $answer .= $this->importForm();
         $answer .= '</div><div class="content">';
         $answer .= '<h1>' . htmlspecialchars($parametersMod->getValue('developer', 'localization', 'admin_translations', 'export_language_file')) . '</h1>';
         $answer .= $this->exportForm();
         $answer .= '</div>';
         $answer .= HtmlOutput::footer();
     }
     return $answer;
 }
 function upload_tmp_video()
 {
     global $errors;
     $upload_file = new \Library\Php\File\UploadFile();
     $upload_file->allowOnly(array('flv'));
     $answer = $upload_file->upload('new_photo', TMP_VIDEO_DIR);
     if ($answer == UPLOAD_ERR_OK) {
         $this->set_variable("name0", $upload_file->fileName);
     } else {
         $this->set_error($answer);
     }
     $this->javascript_answer();
 }
 function check_field($prefix, $action)
 {
     global $parametersMod;
     $upload_file = new \Library\Php\File\UploadFile();
     if (isset($_FILES[$prefix])) {
         $error = $upload_file->upload($prefix, TMP_FILE_DIR);
         if ($error == UPLOAD_ERR_OK) {
             if (sizeof($this->extensions) == 0) {
                 $this->mem_file = $upload_file->fileName;
                 return null;
             } else {
                 $good = false;
                 foreach ($this->extensions as $key => $extension) {
                     if ($_FILES[$prefix]['type'] == $extension) {
                         $good = true;
                     }
                 }
                 if ($good) {
                     $this->mem_file = $upload_file->fileName;
                     return null;
                 } else {
                     return $parametersMod->getValue('developer', 'std_mod', 'admin_translations', 'error_file_type') . ' ' . implode(', ', $this->extensions);
                 }
             }
             return null;
         } elseif ($error == UPLOAD_ERR_NO_FILE && $this->required && !isset($this->mem_file) && $action == 'insert') {
             return $parametersMod->getValue('developer', 'std_mod', 'admin_translations', 'error_required');
         } elseif ($error == UPLOAD_ERR_NO_FILE) {
             return null;
         } elseif ($error == UPLOAD_ERR_EXTENSION) {
             return $parametersMod->getValue('developer', 'std_mod', 'admin_translations', 'error_file_type') . ' ' . implode(', ', $this->extensions);
         } else {
             return $parametersMod->getValue('developer', 'std_mod', 'admin_translations', 'error_file_upload') . " " . $error;
         }
     }
     if (isset($_POST[$prefix . '_delete']) && $this->required) {
         return $parametersMod->getValue('developer', 'std_mod', 'admin_translations', 'error_required');
     }
     return null;
 }