help.php
13 years ago
home.php
13 years ago
import.php
13 years ago
manage.php
13 years ago
settings.php
13 years ago
settings.php
187 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Admin Statistics page |
| 4 | * |
| 5 | * @author Pavel Kulbakin <p.kulbakin@gmail.com> |
| 6 | */ |
| 7 | class PMXI_Admin_Settings extends PMXI_Controller_Admin { |
| 8 | |
| 9 | public function index() { |
| 10 | $this->data['post'] = $post = $this->input->post(PMXI_Plugin::getInstance()->getOption()); |
| 11 | |
| 12 | if ($this->input->post('is_settings_submitted')) { // save settings form |
| 13 | check_admin_referer('edit-settings', '_wpnonce_edit-settings'); |
| 14 | |
| 15 | if ( ! preg_match('%^\d+$%', $post['history_file_count'])) { |
| 16 | $this->errors->add('form-validation', __('History File Count must be a non-negative integer', 'pmxi_plugin')); |
| 17 | } |
| 18 | if ( ! preg_match('%^\d+$%', $post['history_file_age'])) { |
| 19 | $this->errors->add('form-validation', __('History Age must be a non-negative integer', 'pmxi_plugin')); |
| 20 | } |
| 21 | if (empty($post['html_entities'])) $post['html_entities'] = 0; |
| 22 | if (empty($post['utf8_decode'])) $post['utf8_decode'] = 0; |
| 23 | |
| 24 | if ( ! $this->errors->get_error_codes()) { // no validation errors detected |
| 25 | |
| 26 | PMXI_Plugin::getInstance()->updateOption($post); |
| 27 | $files = new PMXI_File_List(); $files->sweepHistory(); // adjust file history to new settings specified |
| 28 | |
| 29 | wp_redirect(add_query_arg('pmxi_nt', urlencode(__('Settings saved', 'pmxi_plugin')), $this->baseUrl)); die(); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | if ($this->input->post('is_templates_submitted')) { // delete templates form |
| 34 | $templates_ids = $this->input->post('templates', array()); |
| 35 | if (empty($templates_ids)) { |
| 36 | $this->errors->add('form-validation', __('Templates must be selected', 'pmxi_plugin')); |
| 37 | } |
| 38 | if ( ! $this->errors->get_error_codes()) { // no validation errors detected |
| 39 | $template = new PMXI_Template_Record(); |
| 40 | foreach ($templates_ids as $template_id) { |
| 41 | $template->clear()->set('id', $template_id)->delete(); |
| 42 | } |
| 43 | wp_redirect(add_query_arg('pmxi_nt', urlencode(sprintf(_n('%d template deleted', '%d templates deleted', count($templates_ids), 'pmxi_plugin'), count($templates_ids))), $this->baseUrl)); die(); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | $this->render(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * upload.php |
| 52 | * |
| 53 | * Copyright 2009, Moxiecode Systems AB |
| 54 | * Released under GPL License. |
| 55 | * |
| 56 | * License: http://www.plupload.com/license |
| 57 | * Contributing: http://www.plupload.com/contributing |
| 58 | */ |
| 59 | public function upload(){ |
| 60 | |
| 61 | // HTTP headers for no cache etc |
| 62 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
| 63 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
| 64 | header("Cache-Control: no-store, no-cache, must-revalidate"); |
| 65 | header("Cache-Control: post-check=0, pre-check=0", false); |
| 66 | header("Pragma: no-cache"); |
| 67 | |
| 68 | // Settings |
| 69 | //$targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload"; |
| 70 | $uploads = wp_upload_dir(); |
| 71 | |
| 72 | $targetDir = $uploads['path']; |
| 73 | |
| 74 | $cleanupTargetDir = true; // Remove old files |
| 75 | $maxFileAge = 5 * 3600; // Temp file age in seconds |
| 76 | |
| 77 | // 5 minutes execution time |
| 78 | @set_time_limit(5 * 60); |
| 79 | |
| 80 | // Uncomment this one to fake upload time |
| 81 | // usleep(5000); |
| 82 | |
| 83 | // Get parameters |
| 84 | $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0; |
| 85 | $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0; |
| 86 | $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : ''; |
| 87 | |
| 88 | // Clean the fileName for security reasons |
| 89 | $fileName = preg_replace('/[^\w\._]+/', '_', $fileName); |
| 90 | |
| 91 | // Make sure the fileName is unique but only if chunking is disabled |
| 92 | if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) { |
| 93 | $ext = strrpos($fileName, '.'); |
| 94 | $fileName_a = substr($fileName, 0, $ext); |
| 95 | $fileName_b = substr($fileName, $ext); |
| 96 | |
| 97 | $count = 1; |
| 98 | while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b)) |
| 99 | $count++; |
| 100 | |
| 101 | $fileName = $fileName_a . '_' . $count . $fileName_b; |
| 102 | } |
| 103 | |
| 104 | $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName; |
| 105 | |
| 106 | // Create target dir |
| 107 | if (!file_exists($targetDir)) |
| 108 | @mkdir($targetDir); |
| 109 | |
| 110 | // Remove old temp files |
| 111 | if ($cleanupTargetDir && is_dir($targetDir) && ($dir = opendir($targetDir))) { |
| 112 | while (($file = readdir($dir)) !== false) { |
| 113 | $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file; |
| 114 | |
| 115 | // Remove temp file if it is older than the max age and is not the current file |
| 116 | if (preg_match('/\.part$/', $file) && (filemtime($tmpfilePath) < time() - $maxFileAge) && ($tmpfilePath != "{$filePath}.part")) { |
| 117 | @unlink($tmpfilePath); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | closedir($dir); |
| 122 | } else |
| 123 | exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 100, "message" => "Failed to open temp directory."), "id" => "id"))); |
| 124 | |
| 125 | |
| 126 | // Look for the content type header |
| 127 | if (isset($_SERVER["HTTP_CONTENT_TYPE"])) |
| 128 | $contentType = $_SERVER["HTTP_CONTENT_TYPE"]; |
| 129 | |
| 130 | if (isset($_SERVER["CONTENT_TYPE"])) |
| 131 | $contentType = $_SERVER["CONTENT_TYPE"]; |
| 132 | |
| 133 | // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5 |
| 134 | if (strpos($contentType, "multipart") !== false) { |
| 135 | if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { |
| 136 | // Open temp file |
| 137 | $out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab"); |
| 138 | if ($out) { |
| 139 | // Read binary input stream and append it to temp file |
| 140 | $in = fopen($_FILES['file']['tmp_name'], "rb"); |
| 141 | |
| 142 | if ($in) { |
| 143 | while ($buff = fread($in, 4096)) |
| 144 | fwrite($out, $buff); |
| 145 | } else |
| 146 | exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 101, "message" => "Failed to open input stream."), "id" => "id"))); |
| 147 | fclose($in); |
| 148 | fclose($out); |
| 149 | @unlink($_FILES['file']['tmp_name']); |
| 150 | } else |
| 151 | die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); |
| 152 | } else |
| 153 | exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 103, "message" => "Failed to move uploaded file."), "id" => "id"))); |
| 154 | } else { |
| 155 | // Open temp file |
| 156 | $out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab"); |
| 157 | if ($out) { |
| 158 | // Read binary input stream and append it to temp file |
| 159 | $in = fopen("php://input", "rb"); |
| 160 | |
| 161 | if ($in) { |
| 162 | while ($buff = fread($in, 4096)) |
| 163 | fwrite($out, $buff); |
| 164 | } else |
| 165 | exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 101, "message" => "Failed to open input stream."), "id" => "id"))); |
| 166 | |
| 167 | fclose($in); |
| 168 | fclose($out); |
| 169 | } else |
| 170 | exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 102, "message" => "Failed to open output stream."), "id" => "id"))); |
| 171 | } |
| 172 | |
| 173 | // Check if file has been uploaded |
| 174 | if (!$chunks || $chunk == $chunks - 1) { |
| 175 | // Strip the temp .part suffix off |
| 176 | rename("{$filePath}.part", $filePath); chmod($filePath, 0755); |
| 177 | } |
| 178 | |
| 179 | // Return JSON-RPC response |
| 180 | exit(json_encode(array("jsonrpc" => "2.0", "result" => null, "id" => "id", "name" => $filePath))); |
| 181 | |
| 182 | } |
| 183 | |
| 184 | public function download(){ |
| 185 | PMXI_download::csv(PMXI_Plugin::ROOT_DIR.'/logs/'.$_GET['file'].'.txt'); |
| 186 | } |
| 187 | } |