public function testFileSize() { // file size $this->assertEquals(FileHandler::filesize(0), '0Byte'); $this->assertEquals(FileHandler::filesize(1), '1Byte'); $this->assertEquals(FileHandler::filesize(386), '386Bytes'); $this->assertEquals(FileHandler::filesize(1023), '1023Bytes'); $this->assertEquals(FileHandler::filesize(1024), '1.0KB'); $this->assertEquals(FileHandler::filesize(2480), '2.4KB'); $this->assertEquals(FileHandler::filesize(1024 * 1024 - 1), '1024.0KB'); $this->assertEquals(FileHandler::filesize(1024 * 1024), '1.00MB'); $this->assertEquals(FileHandler::filesize(3 * 1024 * 1024 + 210 * 1024), '3.21MB'); // return bytes $this->assertEquals(FileHandler::returnBytes('0B'), 0); $this->assertEquals(FileHandler::returnBytes('1024B'), 1024); $this->assertEquals(FileHandler::returnBytes('1K'), 1024); $this->assertEquals(FileHandler::returnBytes('102.48K'), 1024 * 102.48); $this->assertEquals(FileHandler::returnBytes('1M'), 1024 * 1024); $this->assertEquals(FileHandler::returnBytes('1.12M'), 1024 * 1024 * 1.12); $this->assertEquals(FileHandler::returnBytes('1023.99M'), 1024 * 1024 * 1023.99); $this->assertEquals(FileHandler::returnBytes('1G'), 1024 * 1024 * 1024); $this->assertEquals(FileHandler::returnBytes('12.02G'), 1024 * 1024 * 1024 * 12.02); }
/** * Return messages for file upload and it depends whether an admin is or not * * @param int $attached_size * @return string */ function getUploadStatus($attached_size = 0) { $file_config = $this->getUploadConfig(); // Display upload status $upload_status = sprintf('%s : %s/ %s<br /> %s : %s (%s : %s)', Context::getLang('allowed_attach_size'), FileHandler::filesize($attached_size), FileHandler::filesize($file_config->allowed_attach_size * 1024 * 1024), Context::getLang('allowed_filesize'), FileHandler::filesize($file_config->allowed_filesize * 1024 * 1024), Context::getLang('allowed_filetypes'), $file_config->allowed_filetypes); return $upload_status; }
</th> </tr> <?php } ?> <!-- one document end --> <tr> <td><a href="<?php echo htmlspecialchars_decode($__Context->val->download_url); ?> "><?php echo htmlspecialchars($__Context->val->source_filename, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); ?> </a></td> <td class="nowr"><?php echo FileHandler::filesize($__Context->val->file_size); ?> </td> <td class="nowr"><?php echo $__Context->val->download_count; ?> </td> <td class="nowr"> <?php if ($__Context->val->upload_target_type == 'doc' && $__Context->document_list[$__Context->document_srl]) { ?> <a href="#popup_menu_area" class="member_<?php echo $__Context->document_list[$__Context->document_srl]->get('member_srl'); ?> "><?php echo $__Context->document_list[$__Context->document_srl]->getNickName();
/** * Prints debug messages * * Display $buff contents into the file ./files/_debug_message.php. * You can see the file on your prompt by command: tail-f./files/_debug_message.php * * @param mixed $debug_output Target object to be printed * @param bool $display_option boolean Flag whether to print seperator (default:true) * @param string $file Target file name * @return void */ function debugPrint($debug_output = NULL, $display_option = TRUE, $file = '_debug_message.php') { static $debug_file; static $debug_file_exist; if (!(__DEBUG__ & 1)) { return; } static $firephp; $bt = debug_backtrace(); if (is_array($bt)) { $bt_debug_print = array_shift($bt); $bt_called_function = array_shift($bt); } $file_name = str_replace(_XE_PATH_, '', $bt_debug_print['file']); $line_num = $bt_debug_print['line']; $function = $bt_called_function['class'] . $bt_called_function['type'] . $bt_called_function['function']; if (__DEBUG_OUTPUT__ == 2 && version_compare(PHP_VERSION, '6.0.0') === -1) { if (!isset($firephp)) { $firephp = FirePHP::getInstance(TRUE); } $type = FirePHP::INFO; $label = sprintf('[%s:%d] %s() (Memory usage: current=%s, peak=%s)', $file_name, $line_num, $function, FileHandler::filesize(memory_get_usage()), FileHandler::filesize(memory_get_peak_usage())); // Check a FirePHP option if ($display_option === 'TABLE') { $label = $display_option; } if ($display_option === 'ERROR') { $type = $display_option; } // Check if the IP specified by __DEBUG_PROTECT__ option is same as the access IP. if (__DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) { $debug_output = 'The IP address is not allowed. Change the value of __DEBUG_PROTECT_IP__ into your IP address in config/config.user.inc.php or config/config.inc.php'; $label = NULL; } $firephp->fb($debug_output, $label, $type); } else { if (__DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) { return; } $print = array(); if ($debug_file_exist === NULL) { $print[] = '<?php exit() ?>'; } if (!$debug_file) { $debug_file = _XE_PATH_ . 'files/' . $file; } if (!$debug_file_exist) { $debug_file_exist = file_exists($debug_file); } if ($display_option === TRUE || $display_option === 'ERROR') { $print[] = str_repeat('=', 80); } $print[] = sprintf("[%s %s:%d] %s() - mem(%s)", date('Y-m-d H:i:s'), $file_name, $line_num, $function, FileHandler::filesize(memory_get_usage())); $type = gettype($debug_output); if (!in_array($type, array('array', 'object', 'resource'))) { if ($display_option === 'ERROR') { $print[] = 'ERROR : ' . var_export($debug_output, TRUE); } else { $print[] = $type . '(' . var_export($debug_output, TRUE) . ')'; } $print[] = PHP_EOL . PHP_EOL; } else { $print[] = print_r($debug_output, TRUE); $print[] = PHP_EOL; } @file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND | LOCK_EX); } }
/** * Print debugging message to designated output source depending on the value set to __DEBUG_OUTPUT_. \n * This method only functions when __DEBUG__ variable is set to 1. * __DEBUG_OUTPUT__ == 0, messages are written in ./files/_debug_message.php * @return void */ function _debugOutput() { if (!__DEBUG__) { return; } $end = getMicroTime(); // Firebug console output if (__DEBUG_OUTPUT__ == 2 && version_compare(PHP_VERSION, '6.0.0') === -1) { static $firephp; if (!isset($firephp)) { $firephp = FirePHP::getInstance(true); } if (__DEBUG_PROTECT__ == 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) { $firephp->fb('Change the value of __DEBUG_PROTECT_IP__ into your IP address in config/config.user.inc.php or config/config.inc.php', 'The IP address is not allowed.'); return; } // display total execution time and Request/Response info if (__DEBUG__ & 2) { $firephp->fb(array('Request / Response info >>> ' . $_SERVER['REQUEST_METHOD'] . ' / ' . Context::getResponseMethod(), array(array('Request URI', 'Request method', 'Response method', 'Response contents size', 'Memory peak usage'), array(sprintf("%s:%s%s%s%s", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING'] ? '?' : '', $_SERVER['QUERY_STRING']), $_SERVER['REQUEST_METHOD'], Context::getResponseMethod(), $this->content_size . ' byte', FileHandler::filesize(memory_get_peak_usage())))), 'TABLE'); $firephp->fb(array('Elapsed time >>> Total : ' . sprintf('%0.5f sec', $end - __StartTime__), array(array('DB queries', 'class file load', 'Template compile', 'XmlParse compile', 'PHP', 'Widgets', 'Trans Content'), array(sprintf('%0.5f sec', $GLOBALS['__db_elapsed_time__']), sprintf('%0.5f sec', $GLOBALS['__elapsed_class_load__']), sprintf('%0.5f sec (%d called)', $GLOBALS['__template_elapsed__'], $GLOBALS['__TemplateHandlerCalled__']), sprintf('%0.5f sec', $GLOBALS['__xmlparse_elapsed__']), sprintf('%0.5f sec', $end - __StartTime__ - $GLOBALS['__template_elapsed__'] - $GLOBALS['__xmlparse_elapsed__'] - $GLOBALS['__db_elapsed_time__'] - $GLOBALS['__elapsed_class_load__']), sprintf('%0.5f sec', $GLOBALS['__widget_excute_elapsed__']), sprintf('%0.5f sec', $GLOBALS['__trans_content_elapsed__'])))), 'TABLE'); } // display DB query history if (__DEBUG__ & 4 && $GLOBALS['__db_queries__']) { $queries_output = array(array('Result/' . PHP_EOL . 'Elapsed time', 'Query ID', 'Query')); foreach ($GLOBALS['__db_queries__'] as $query) { $queries_output[] = array($query['result'] . PHP_EOL . sprintf('%0.5f', $query['elapsed_time']), str_replace(_XE_PATH_, '', $query['called_file']) . PHP_EOL . $query['called_method'] . '()' . PHP_EOL . $query['query_id'], $query['query']); } $firephp->fb(array('DB Queries >>> ' . count($GLOBALS['__db_queries__']) . ' Queries, ' . sprintf('%0.5f sec', $GLOBALS['__db_elapsed_time__']), $queries_output), 'TABLE'); } // dislpay the file and HTML comments } else { $buff = array(); // display total execution time and Request/Response info if (__DEBUG__ & 2) { if (__DEBUG_PROTECT__ == 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) { return; } // Request/Response information $buff[] = "\n- Request/ Response info"; $buff[] = sprintf("\tRequest URI \t\t\t: %s:%s%s%s%s", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING'] ? '?' : '', $_SERVER['QUERY_STRING']); $buff[] = sprintf("\tRequest method \t\t\t: %s", $_SERVER['REQUEST_METHOD']); $buff[] = sprintf("\tResponse method \t\t: %s", Context::getResponseMethod()); $buff[] = sprintf("\tResponse contents size\t: %d byte", $this->content_size); // total execution time $buff[] = sprintf("\n- Total elapsed time : %0.5f sec", $end - __StartTime__); $buff[] = sprintf("\tclass file load elapsed time \t: %0.5f sec", $GLOBALS['__elapsed_class_load__']); $buff[] = sprintf("\tTemplate compile elapsed time\t: %0.5f sec (%d called)", $GLOBALS['__template_elapsed__'], $GLOBALS['__TemplateHandlerCalled__']); $buff[] = sprintf("\tXmlParse compile elapsed time\t: %0.5f sec", $GLOBALS['__xmlparse_elapsed__']); $buff[] = sprintf("\tPHP elapsed time \t\t\t\t: %0.5f sec", $end - __StartTime__ - $GLOBALS['__template_elapsed__'] - $GLOBALS['__xmlparse_elapsed__'] - $GLOBALS['__db_elapsed_time__'] - $GLOBALS['__elapsed_class_load__']); $buff[] = sprintf("\tDB class elapsed time \t\t\t: %0.5f sec", $GLOBALS['__dbclass_elapsed_time__'] - $GLOBALS['__db_elapsed_time__']); // widget execution time $buff[] = sprintf("\tWidgets elapsed time \t\t\t: %0.5f sec", $GLOBALS['__widget_excute_elapsed__']); // layout execution time $buff[] = sprintf("\tLayout compile elapsed time \t: %0.5f sec", $GLOBALS['__layout_compile_elapsed__']); // Widgets, the editor component replacement time $buff[] = sprintf("\tTrans Content \t\t\t\t\t: %0.5f sec", $GLOBALS['__trans_content_elapsed__']); } // DB Logging if (__DEBUG__ & 4) { if (__DEBUG_PROTECT__ == 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) { return; } if ($GLOBALS['__db_queries__']) { $buff[] = sprintf("\n- DB Queries : %d Queries. %0.5f sec", count($GLOBALS['__db_queries__']), $GLOBALS['__db_elapsed_time__']); $num = 0; foreach ($GLOBALS['__db_queries__'] as $query) { if ($query['result'] == 'Success') { $query_result = "Query Success"; } else { $query_result = sprintf("Query {$s} : %d\n\t\t\t %s", $query['result'], $query['errno'], $query['errstr']); } $buff[] = sprintf("\t%02d. %s\n\t\t%0.6f sec. %s.", ++$num, $query['query'], $query['elapsed_time'], $query_result); $buff[] = sprintf("\t\tConnection: %s.", $query['connection']); $buff[] = sprintf("\t\tQuery ID: %s", $query['query_id']); $buff[] = sprintf("\t\tCalled: %s. %s()", str_replace(_XE_PATH_, '', $query['called_file']), $query['called_method']); } } } // Output in HTML comments if ($buff && __DEBUG_OUTPUT__ == 1 && Context::getResponseMethod() == 'HTML') { $buff = implode("\r\n", $buff); $buff = sprintf("[%s %s:%d]\r\n%s", date('Y-m-d H:i:s'), $file_name, $line_num, print_r($buff, true)); if (__DEBUG_PROTECT__ == 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) { $buff = 'The IP address is not allowed. Change the value of __DEBUG_PROTECT_IP__ into your IP address in config/config.user.inc.php or config/config.inc.php'; } return "<!--\r\n" . $buff . "\r\n-->"; } // Output to a file if ($buff && __DEBUG_OUTPUT__ == 0) { $debug_file = _XE_PATH_ . 'files/_debug_message.php'; $buff = implode(PHP_EOL, $buff); $buff = sprintf("[%s]\n%s", date('Y-m-d H:i:s'), print_r($buff, true)); $buff = str_repeat('=', 80) . "\n" . $buff . "\n" . str_repeat('-', 80); $buff = "\n<?php\n/*" . $buff . "*/\n?>\n"; if (!@file_put_contents($debug_file, $buff, FILE_APPEND | LOCK_EX)) { return; } } } }
/** * get file list * * @return Object **/ function procFileGetList() { if (!Context::get('is_logged')) { return new Object(-1, 'msg_not_permitted'); } $fileSrls = Context::get('file_srls'); if ($fileSrls) { $fileSrlList = explode(',', $fileSrls); } global $lang; if (count($fileSrlList) > 0) { $oFileModel =& getModel('file'); $fileList = $oFileModel->getFile($fileSrlList); if (!is_array($fileList)) { $fileList = array($fileList); } if (is_array($fileList)) { foreach ($fileList as $key => $value) { $value->human_file_size = FileHandler::filesize($value->file_size); if ($value->isvalid == 'Y') { $value->validName = $lang->is_valid; } else { $value->validName = $lang->is_stand_by; } } } } else { $fileList = array(); $this->setMessage($lang->no_files); } $this->add('file_list', $fileList); }
/** * @brief get input extra vars */ function getNproductInputExtraVars($extra_info) { $extend_form_list = $extra_info; $formTags = array(); if (!$extend_form_list) { return $formTags; } foreach ($extend_form_list as $no => $formInfo) { unset($formTag); $inputTag = ''; $formTag = $formInfo; $formTag->title = $formInfo->column_title; if ($formInfo->required == 'Y') { $formTag->title = $formTag->title . ' <em style="color:red">*</em>'; } $extendForm = $formInfo; $replace = array('column_name' => $extendForm->column_name, 'value' => $extendForm->value); $extentionReplace = array(); if ($extendForm->column_type == 'text' || $extendForm->column_type == 'homepage' || $extendForm->column_type == 'email_address') { $template = '<input type="text" name="%column_name%" value="%value%" />'; } else { if ($extendForm->column_type == 'tel') { $extentionReplace = array('tel_0' => $extendForm->value[0], 'tel_1' => $extendForm->value[1], 'tel_2' => $extendForm->value[2]); $template = '<input type="text" name="%column_name%[]" value="%tel_0%" size="4" />-<input type="text" name="%column_name%[]" value="%tel_1%" size="4" />-<input type="text" name="%column_name%" value="%tel_2%" size="4" />'; } else { if ($extendForm->column_type == 'textarea') { $template = '<textarea name="%column_name%">%value%</textarea>'; } else { if ($extendForm->column_type == 'checkbox') { $template = ''; if ($extendForm->default_value) { $__i = 0; foreach ($extendForm->default_value as $v) { $checked = ''; if (is_array($extendForm->value) && in_array($v, $extendForm->value)) { $checked = 'checked="checked"'; } $template .= '<input type="checkbox" id="%column_name%' . $__i . '" name="%column_name%[]" value="' . htmlspecialchars($v) . '" ' . $checked . ' /><label for="%column_name%' . $__i . '">' . $v . '</label>'; $__i++; } } } else { if ($extendForm->column_type == 'radio') { $template = ''; if ($extendForm->default_value) { $template = '<ul class="radio">%s</ul>'; $optionTag = array(); foreach ($extendForm->default_value as $v) { if ($extendForm->value == $v) { $checked = 'checked="checked"'; } else { $checked = ''; } $optionTag[] = '<li><input type="radio" name="%column_name%" value="' . $v . '" ' . $checked . ' />' . $v . '</li>'; } $template = sprintf($template, implode('', $optionTag)); } } else { if ($extendForm->column_type == 'select') { $template = '<select name="' . $formInfo->column_name . '">%s</select>'; $optionTag = array(); if ($extendForm->default_value) { foreach ($extendForm->default_value as $v) { if ($v == $extendForm->value) { $selected = 'selected="selected"'; } else { $selected = ''; } $optionTag[] = sprintf('<option value="%s" %s >%s</option>', $v, $selected, $v); } } $template = sprintf($template, implode('', $optionTag)); } else { if ($extendForm->column_type == 'date') { $extentionReplace = array('date' => zdate($extendForm->value, 'Y-m-d'), 'cmd_delete' => $lang->cmd_delete); $template = '<input type="hidden" name="%column_name%" id="date_%column_name%" value="%value%" /><input type="text" class="inputDate" value="%date%" readonly="readonly" /> <input type="button" value="%cmd_delete%" class="dateRemover" />'; } else { if ($extendForm->column_type == 'file') { $oFileModel =& getModel('file'); if ($extendForm->value) { $file = $oFileModel->getFile($extendForm->value); $template = '<p><a href="' . $file->download_url . '">' . $file->source_filename . '</a> (' . FileHandler::filesize($file->file_size) . ')</p>'; } $template .= '<input type="file" name="%column_name%" />'; } } } } } } } } $replace = array_merge($extentionReplace, $replace); $inputTag = preg_replace('@%(\\w+)%@e', '$replace[$1]', $template); $formTag->inputTag = $inputTag; $formTags[] = $formTag; } return $formTags; }
/** * Set attachment information (for administrator) * * @return Object */ function dispFileAdminConfig() { $oFileModel = getModel('file'); $config = $oFileModel->getFileConfig(); Context::set('config', $config); $iniPostMaxSize = FileHandler::returnbytes(ini_get('post_max_size')); $iniUploadMaxSize = FileHandler::returnbytes(ini_get('upload_max_filesize')); $iniMinSize = min($iniPostMaxSize, $iniUploadMaxSize); Context::set('upload_max_filesize', FileHandler::filesize($iniMinSize)); // Set a template file $this->setTemplatePath($this->module_path . 'tpl'); $this->setTemplateFile('adminConfig'); }
if ($__Context->item_info->download_file) { ?> <div id="contents_file_select" class="x_control-group"> <label class="x_control-label" for="contents_file"><?php echo $__Context->lang->contents_file; ?> </label> <div class="x_controls"> <p id="file_info"><a href="<?php echo $__Context->item_info->download_file->download_url; ?> "><?php echo $__Context->item_info->download_file->source_filename; ?> </a> (<?php echo FileHandler::filesize($__Context->item_info->download_file->file_size); ?> ) <button onClick="delete_file(<?php echo $__Context->item_info->file_srl; ?> )"><?php echo $__Context->lang->cmd_delete; ?> </button></p> <p><a href="<?php echo getUrl('act', 'dispNstore_digital_contentsAdminItemList'); ?> "><?php echo $__Context->lang->nstore_digital_management; ?> </a><?php
/** * Prints debug messages * * Display $buff contents into the file ./files/_debug_message.php. * You can see the file on your prompt by command: tail-f./files/_debug_message.php * * @param mixed $debug_output Target object to be printed * @param bool $display_option boolean Flag whether to print seperator (default:true) * @param string $file Target file name * @return void **/ function debugPrint($debug_output = null, $display_option = true, $file = '_debug_message.php') { if (!(__DEBUG__ & 1)) { return; } static $firephp; $bt = debug_backtrace(); if (is_array($bt)) { $first = array_shift($bt); } $file_name = array_pop(explode(DIRECTORY_SEPARATOR, $first['file'])); $line_num = $first['line']; if (__DEBUG_OUTPUT__ == 2 && version_compare(PHP_VERSION, '6.0.0') === -1) { if (!isset($firephp)) { $firephp = FirePHP::getInstance(true); } if (function_exists("memory_get_usage")) { $label = sprintf('[%s:%d] (m:%s)', $file_name, $line_num, FileHandler::filesize(memory_get_usage())); } else { $label = sprintf('[%s:%d] ', $file_name, $line_num); } // Check a FirePHP option if ($display_option === 'TABLE') { $label = $display_option; } // Check if the IP specified by __DEBUG_PROTECT__ option is same as the access IP. if (__DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) { $debug_output = 'The IP address is not allowed. Change the value of __DEBUG_PROTECT_IP__ into your IP address in config/config.user.inc.php or config/config.inc.php'; $label = null; } $firephp->fb($debug_output, $label); } else { if (__DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) { return; } $debug_file = _XE_PATH_ . 'files/' . $file; if (function_exists("memory_get_usage")) { $debug_output = sprintf("[%s %s:%d] - mem(%s)\n%s\n", date('Y-m-d H:i:s'), $file_name, $line_num, FileHandler::filesize(memory_get_usage()), print_r($debug_output, true)); } else { $debug_output = sprintf("[%s %s:%d]\n%s\n", date('Y-m-d H:i:s'), $file_name, $line_num, print_r($debug_output, true)); } if ($display_option === true) { $debug_output = str_repeat('=', 40) . "\n" . $debug_output . str_repeat('-', 40); } $debug_output = "\n<?php\n/*" . $debug_output . "*/\n?>\n"; if (@(!($fp = fopen($debug_file, 'a')))) { return; } fwrite($fp, $debug_output); fclose($fp); } }