本文整理汇总了PHP中ini_size_to_bytes函数的典型用法代码示例。如果您正苦于以下问题:PHP ini_size_to_bytes函数的具体用法?PHP ini_size_to_bytes怎么用?PHP ini_size_to_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ini_size_to_bytes函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: systemMaxUploadBytes
/**
* What is the maximum file size supported system-wide?
*
* Controlled by the system-level directive `upload_max_filesize`, but
* also constrained by the system-level directive `post_max_size`. The
* *lower* of the two values defines the *upper* limit of the maximum
* file size.
*
* If the number of returned bytes equals `PHP_INT_MAX`, there is
* effectively no limit.
*
* @return int Bytes
* @api
* @since 1.0.0
*/
public static function systemMaxUploadBytes()
{
// get both limits as bytes
$post_max = ini_size_to_bytes(ini_get('post_max_size'));
$upload_max = ini_size_to_bytes(ini_get('upload_max_filesize'));
return static::limit($post_max, $upload_max);
}
示例2: __buildPage
private function __buildPage()
{
$start = precision_timer();
if (!($page = $this->resolvePage())) {
$page = $this->_Parent->Database->fetchRow(0, "\n\t\t\t\t\t\t\t\tSELECT `tbl_pages`.* \n\t\t\t\t\t\t\t\tFROM `tbl_pages`, `tbl_pages_types` \n\t\t\t\t\t\t\t\tWHERE `tbl_pages_types`.page_id = `tbl_pages`.id \n\t\t\t\t\t\t\t\tAND tbl_pages_types.`type` = '404' \n\t\t\t\t\t\t\t\tLIMIT 1");
if (empty($page)) {
$this->_Parent->customError(E_USER_ERROR, __('Page Not Found'), __('The page you requested does not exist.'), false, true, 'error', array('header' => 'HTTP/1.0 404 Not Found'));
}
$page['filelocation'] = $this->resolvePageFileLocation($page['path'], $page['handle']);
$page['type'] = $this->__fetchPageTypes($page['id']);
}
####
# Delegate: FrontendPageResolved
# Description: Just after having resolved the page, but prior to any commencement of output creation
# Global: Yes
$this->ExtensionManager->notifyMembers('FrontendPageResolved', '/frontend/', array('page' => &$this, 'page_data' => &$page));
$this->_pageData = $page;
$root_page = @array_shift(explode('/', $page['path']));
$current_path = explode(dirname($_SERVER['SCRIPT_NAME']), $_SERVER['REQUEST_URI'], 2);
$current_path = '/' . ltrim(end($current_path), '/');
// Get max upload size from php and symphony config then choose the smallest
$upload_size_php = ini_size_to_bytes(ini_get('upload_max_filesize'));
$upload_size_sym = Frontend::instance()->Configuration->get('max_upload_size', 'admin');
$this->_param = array('today' => DateTimeObj::get('Y-m-d'), 'current-time' => DateTimeObj::get('H:i'), 'this-year' => DateTimeObj::get('Y'), 'this-month' => DateTimeObj::get('m'), 'this-day' => DateTimeObj::get('d'), 'timezone' => DateTimeObj::get('P'), 'website-name' => $this->_Parent->Configuration->get('sitename', 'general'), 'page-title' => $page['title'], 'root' => URL, 'workspace' => URL . '/workspace', 'root-page' => $root_page ? $root_page : $page['handle'], 'current-page' => $page['handle'], 'current-page-id' => $page['id'], 'current-path' => $current_path, 'parent-path' => '/' . $page['path'], 'current-url' => URL . $current_path, 'upload-limit' => min($upload_size_php, $upload_size_sym), 'symphony-build' => $this->_Parent->Configuration->get('build', 'symphony'));
if (is_array($this->_env['url'])) {
foreach ($this->_env['url'] as $key => $val) {
$this->_param[$key] = $val;
}
}
if (is_array($_GET) && !empty($_GET)) {
foreach ($_GET as $key => $val) {
if (!in_array($key, array('symphony-page', 'debug', 'profile'))) {
$this->_param['url-' . $key] = $val;
}
}
}
if (is_array($_COOKIE[__SYM_COOKIE_PREFIX_]) && !empty($_COOKIE[__SYM_COOKIE_PREFIX_])) {
foreach ($_COOKIE[__SYM_COOKIE_PREFIX_] as $key => $val) {
$this->_param['cookie-' . $key] = $val;
}
}
// Flatten parameters:
General::flattenArray($this->_param);
####
# Delegate: FrontendParamsResolve
# Description: Just after having resolved the page params, but prior to any commencement of output creation
# Global: Yes
$this->ExtensionManager->notifyMembers('FrontendParamsResolve', '/frontend/', array('params' => &$this->_param));
$xml_build_start = precision_timer();
$xml = new XMLElement('data');
$xml->setIncludeHeader(true);
$events = new XMLElement('events');
$this->__processEvents($page['events'], $events);
$xml->appendChild($events);
$this->_events_xml = clone $events;
$this->__processDatasources($page['data_sources'], $xml);
$this->_Parent->Profiler->seed($xml_build_start);
$this->_Parent->Profiler->sample('XML Built', PROFILE_LAP);
if (is_array($this->_env['pool']) && !empty($this->_env['pool'])) {
foreach ($this->_env['pool'] as $handle => $p) {
if (!is_array($p)) {
$p = array($p);
}
foreach ($p as $key => $value) {
if (is_array($value) && !empty($value)) {
foreach ($value as $kk => $vv) {
$this->_param[$handle] .= @implode(', ', $vv) . ',';
}
} else {
$this->_param[$handle] = @implode(', ', $p);
}
}
$this->_param[$handle] = trim($this->_param[$handle], ',');
}
}
####
# Delegate: FrontendParamsPostResolve
# Description: Access to the resolved param pool, including additional parameters provided by Data Source outputs
# Global: Yes
$this->ExtensionManager->notifyMembers('FrontendParamsPostResolve', '/frontend/', array('params' => $this->_param));
## TODO: Add delegate for adding/removing items in the params
$xsl = '<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="./workspace/pages/' . basename($page['filelocation']) . '"/>
</xsl:stylesheet>';
$this->_Parent->Profiler->seed();
$this->setXML($xml->generate(true, 0));
$this->_Parent->Profiler->sample('XML Generation', PROFILE_LAP);
$this->setXSL($xsl, false);
$this->setRuntimeParam($this->_param);
$this->_Parent->Profiler->seed($start);
$this->_Parent->Profiler->sample('Page Built', PROFILE_LAP);
}
示例3: array
$phrasegroups = array('language');
$specialtemplates = array();
// ########################## REQUIRE BACK-END ############################
require_once './global.php';
require_once DIR . '/includes/adminfunctions_language.php';
// ######################## CHECK ADMIN PERMISSIONS #######################
if (!can_administer('canadminlanguages')) {
print_cp_no_permission();
}
$vbulletin->input->clean_array_gpc('r', array('dolanguageid' => TYPE_INT));
// ############################# LOG ACTION ###############################
log_admin_action(iif(!empty($vbulletin->GPC['dolanguageid']), "Language ID = " . $vbulletin->GPC['dolanguageid']));
// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
if (($current_memory_limit = ini_size_to_bytes(@ini_get('memory_limit'))) < 128 * 1024 * 1024 and $current_memory_limit > 0) {
@ini_set('memory_limit', 128 * 1024 * 1024);
}
if (empty($_REQUEST['do'])) {
$_REQUEST['do'] = 'modify';
}
$langglobals = array('title' => TYPE_NOHTML, 'userselect' => TYPE_INT, 'options' => TYPE_ARRAY_BOOL, 'languagecode' => TYPE_STR, 'charset' => TYPE_STR, 'locale' => TYPE_STR, 'imagesoverride' => TYPE_STR, 'dateoverride' => TYPE_STR, 'timeoverride' => TYPE_STR, 'registereddateoverride' => TYPE_STR, 'calformat1override' => TYPE_STR, 'calformat2override' => TYPE_STR, 'logdateoverride' => TYPE_STR, 'decimalsep' => TYPE_STR, 'thousandsep' => TYPE_STR);
$default_skipped_groups = array('cphelptext');
// #############################################################################
if ($_POST['do'] == 'download') {
$vbulletin->input->clean_array_gpc('p', array('filename' => TYPE_STR, 'just_phrases' => TYPE_BOOL, 'product' => TYPE_STR, 'custom' => TYPE_BOOL));
if (empty($vbulletin->GPC['filename'])) {
$vbulletin->GPC['filename'] = DEFAULT_FILENAME;
}
if (function_exists('set_time_limit') and !SAFEMODE) {
@set_time_limit(1200);
示例4: accept_upload
/**
* This function accepts a file via URL or from $_FILES, verifies it, and places it in a temporary location for processing
*
* @param mixed Valid options are: (a) a URL to a file to retrieve or (b) a pointer to a file in the $_FILES array
*/
function accept_upload(&$upload)
{
$this->error = '';
if (!is_array($upload) and strval($upload) != '') {
$this->upload['extension'] = strtolower(file_extension($upload));
// Check extension here so we can save grabbing a large file that we aren't going to use
if (!$this->is_valid_extension($this->upload['extension'])) {
$this->set_error('upload_invalid_file');
return false;
}
// Admins can upload any size file
if ($this->registry->userinfo['permissions']['adminpermissions'] & $this->registry->bf_ugp_adminpermissions['cancontrolpanel']) {
$this->maxuploadsize = 0;
} else {
$this->maxuploadsize = $this->fetch_max_uploadsize($this->upload['extension']);
if (!$this->maxuploadsize) {
$newmem = 20971520;
}
}
if (!preg_match('#^((http|ftp)s?):\\/\\/#i', $upload)) {
$upload = 'http://' . $upload;
}
if (ini_get('allow_url_fopen') == 0 and !function_exists('curl_init')) {
$this->set_error('upload_fopen_disabled');
return false;
} else {
if ($filesize = $this->fetch_remote_filesize($upload)) {
if ($this->maxuploadsize and $filesize > $this->maxuploadsize) {
$this->set_error('upload_remoteimage_toolarge');
return false;
} else {
if (function_exists('memory_get_usage') and $memory_limit = @ini_get('memory_limit') and $memory_limit != -1) {
// Make sure we have enough memory to process this file
$memorylimit = vb_number_format($memory_limit, 0, false, null, '');
$memoryusage = memory_get_usage();
$freemem = $memorylimit - $memoryusage;
$newmemlimit = !empty($newmem) ? $freemem + $newmem : $freemem + $filesize;
if (($current_memory_limit = ini_size_to_bytes(@ini_get('memory_limit'))) < $newmemlimit and $current_memory_limit > 0) {
@ini_set('memory_limit', $newmemlimit);
}
}
require_once DIR . '/includes/class_vurl.php';
$vurl = new vB_vURL($this->registry);
$vurl->set_option(VURL_URL, $upload);
$vurl->set_option(VURL_HEADER, true);
$vurl->set_option(VURL_MAXSIZE, $this->maxuploadsize);
$vurl->set_option(VURL_RETURNTRANSFER, true);
if ($result = $vurl->exec2()) {
} else {
switch ($vurl->fetch_error()) {
case VURL_ERROR_MAXSIZE:
$this->set_error('upload_remoteimage_toolarge');
break;
case VURL_ERROR_NOLIB:
// this condition isn't reachable
$this->set_error('upload_fopen_disabled');
break;
case VURL_ERROR_SSL:
case VURL_URL_URL:
default:
$this->set_error('retrieval_of_remote_file_failed');
}
return false;
}
unset($vurl);
}
} else {
$this->set_error('upload_invalid_url');
return false;
}
}
// write file to temporary directory...
if ($this->registry->options['safeupload']) {
// ... in safe mode
$this->upload['location'] = $this->registry->options['tmppath'] . '/vbupload' . $this->userinfo['userid'] . substr(TIMENOW, -4);
} else {
// ... in normal mode
$this->upload['location'] = $this->registry->userinfo['permissions']['adminpermissions'] & $this->registry->bf_ugp_adminpermissions['cancontrolpanel'] ? tempnam(ini_get('upload_tmp_dir'), 'vbupload') : @tempnam(ini_get('upload_tmp_dir'), 'vbupload');
}
$attachment_write_failed = true;
if (!empty($result['body'])) {
$fp = $this->registry->userinfo['permissions']['adminpermissions'] & $this->registry->bf_ugp_adminpermissions['cancontrolpanel'] ? fopen($this->upload['location'], 'wb') : @fopen($this->upload['location'], 'wb');
if ($fp and $this->upload['location']) {
@fwrite($fp, $result['body']);
@fclose($fp);
$attachment_write_failed = false;
}
} else {
if (file_exists($result['body_file'])) {
if (rename($result['body_file'], $this->upload['location'])) {
$mask = 0777 & ~umask();
@chmod($this->upload['location'], $mask);
$attachment_write_failed = false;
}
}
//.........这里部分代码省略.........
示例5: error_reporting
error_reporting(E_ALL & ~E_NOTICE);
// Attempt to load XML extension if we don't have the XML functions
// already loaded.
if (!function_exists('xml_set_element_handler')) {
$extension_dir = ini_get('extension_dir');
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
$extension_file = 'php_xml.dll';
} else {
$extension_file = 'xml.so';
}
if ($extension_dir and file_exists($extension_dir . '/' . $extension_file)) {
ini_set('display_errors', true);
dl($extension_file);
}
}
if (!function_exists('ini_size_to_bytes') or ($current_memory_limit = ini_size_to_bytes(@ini_get('memory_limit'))) < 128 * 1024 * 1024 and $current_memory_limit > 0) {
@ini_set('memory_limit', 128 * 1024 * 1024);
}
/**
* vBulletin XML Parsing Object
*
* This class allows the parsing of an XML document to an array
*
* @package vBulletin
* @author Scott MacVicar
* @version $Revision: 59788 $
* @date $Date: 2012-02-29 16:39:09 -0800 (Wed, 29 Feb 2012) $
* @copyright http://www.vbulletin.com/license.html
*
*/
class vB_XML_Parser
示例6: __formAction
public function __formAction()
{
$fields = $_POST['fields'];
$this->_errors = array();
if (trim($fields['name']) == '') {
$this->_errors['name'] = __('This is a required field');
}
if (trim($fields['source']) == '') {
$this->_errors['source'] = __('This is a required field');
}
$filters = is_array($fields['filters']) ? $fields['filters'] : array();
$classname = Lang::createHandle($fields['name'], NULL, '_', false, true, array('@^[^a-z\\d]+@i' => '', '/[^\\w-\\.]/i' => ''));
$rootelement = str_replace('_', '-', $classname);
##Check to make sure the classname is not empty after handlisation.
if (empty($classname)) {
$this->_errors['name'] = __('Please ensure name contains at least one Latin-based alphabet.', array($classname));
}
$file = EVENTS . '/event.' . $classname . '.php';
$isDuplicate = false;
$queueForDeletion = NULL;
if ($this->_context[0] == 'new' && is_file($file)) {
$isDuplicate = true;
} elseif ($this->_context[0] == 'edit') {
$existing_handle = $this->_context[1];
if ($classname != $existing_handle && is_file($file)) {
$isDuplicate = true;
} elseif ($classname != $existing_handle) {
$queueForDeletion = EVENTS . '/event.' . $existing_handle . '.php';
}
}
##Duplicate
if ($isDuplicate) {
$this->_errors['name'] = __('An Event with the name <code>%s</code> name already exists', array($classname));
}
if (empty($this->_errors)) {
$multiple = in_array('expect-multiple', $filters);
$eventShell = file_get_contents(TEMPLATE . '/event.tpl');
$about = array('name' => $fields['name'], 'version' => 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), 'release date' => DateTimeObj::getGMT('c'), 'author name' => Administration::instance()->Author->getFullName(), 'author website' => URL, 'author email' => Administration::instance()->Author->get('email'), 'trigger condition' => $rootelement);
$source = $fields['source'];
$filter = NULL;
$elements = NULL;
$this->__injectAboutInformation($eventShell, $about);
$this->__injectFilters($eventShell, $filters);
$documentation = NULL;
$documentation_parts = array();
$documentation_parts[] = new XMLElement('h3', __('Success and Failure XML Examples'));
$documentation_parts[] = new XMLElement('p', __('When saved successfully, the following XML will be returned:'));
if ($multiple) {
$code = new XMLElement($rootelement);
$entry = new XMLElement('entry', NULL, array('index' => '0', 'result' => 'success', 'type' => 'create | edit'));
$entry->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.')));
$code->appendChild($entry);
} else {
$code = new XMLElement($rootelement, NULL, array('result' => 'success', 'type' => 'create | edit'));
$code->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.')));
}
$documentation_parts[] = self::processDocumentationCode($code);
###
$documentation_parts[] = new XMLElement('p', __('When an error occurs during saving, due to either missing or invalid fields, the following XML will be returned') . ($multiple ? __(' (<b>Notice that it is possible to get mixtures of success and failure messages when using the "Allow Multiple" option</b>)') : NULL) . ':');
if ($multiple) {
$code = new XMLElement($rootelement);
$entry = new XMLElement('entry', NULL, array('index' => '0', 'result' => 'error'));
$entry->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
$entry->appendChild(new XMLElement('field-name', NULL, array('type' => 'invalid | missing')));
$code->appendChild($entry);
$entry = new XMLElement('entry', NULL, array('index' => '1', 'result' => 'success', 'type' => 'create | edit'));
$entry->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.')));
$code->appendChild($entry);
} else {
$code = new XMLElement($rootelement, NULL, array('result' => 'error'));
$code->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
$code->appendChild(new XMLElement('field-name', NULL, array('type' => 'invalid | missing')));
}
$code->setValue('...', false);
$documentation_parts[] = self::processDocumentationCode($code);
###
if (is_array($filters) && !empty($filters)) {
$documentation_parts[] = new XMLElement('p', __('The following is an example of what is returned if any options return an error:'));
$code = new XMLElement($rootelement, NULL, array('result' => 'error'));
$code->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
$code->appendChild(new XMLElement('filter', NULL, array('name' => 'admin-only', 'status' => 'failed')));
$code->appendChild(new XMLElement('filter', __('Recipient not found'), array('name' => 'send-email', 'status' => 'failed')));
$code->setValue('...', false);
$documentation_parts[] = self::processDocumentationCode($code);
}
###
$documentation_parts[] = new XMLElement('h3', __('Example Front-end Form Markup'));
$documentation_parts[] = new XMLElement('p', __('This is an example of the form markup you can use on your frontend:'));
$container = new XMLElement('form', NULL, array('method' => 'post', 'action' => '', 'enctype' => 'multipart/form-data'));
$container->appendChild(Widget::Input('MAX_FILE_SIZE', min(ini_size_to_bytes(ini_get('upload_max_filesize')), Symphony::Configuration()->get('max_upload_size', 'admin')), 'hidden'));
$sectionManager = new SectionManager($this->_Parent);
$section = $sectionManager->fetch($fields['source']);
$section_fields = $section->fetchFields();
if (is_array($section_fields) && !empty($section_fields)) {
foreach ($section_fields as $f) {
if ($f->getExampleFormMarkup() instanceof XMLElement) {
$container->appendChild($f->getExampleFormMarkup());
}
}
}
//.........这里部分代码省略.........
示例7: array
}
// ################## Start rebuilding sgicon thumbnails ################
if ($_REQUEST['do'] == 'rebuildsgicons')
{
$vbulletin->input->clean_array_gpc('r', array(
'quality' => TYPE_UINT,
'autoredirect' => TYPE_BOOL,
'perpage' => TYPE_UINT,
'startat' => TYPE_UINT
));
// Increase memlimit
if (($memory_limit = ini_size_to_bytes(@ini_get('memory_limit'))) < 128 * 1024 * 1024 AND $memory_limit > 0)
{
@ini_set('memory_limit', 128 * 1024 * 1024);
}
// Get dimension constants
require_once(DIR . '/includes/functions_socialgroup.php');
// Get image handler
require_once(DIR . '/includes/class_image.php');
$image = vB_Image::fetch_library($vbulletin);
// Check if image manip is supported
if ($vbulletin->options['imagetype'] != 'Magick' AND !function_exists('imagetypes'))
{
print_stop_message('your_version_no_image_support');
示例8: fetch_thumbnail
/**
*
* See function definition in vB_Image_Abstract
*
*/
function fetch_thumbnail($filename, $location, $maxwidth = 100, $maxheight = 100, $quality = 75, $labelimage = false, $drawborder = false, $jpegconvert = false, $sharpen = true, $owidth = null, $oheight = null, $ofilesize = null)
{
$thumbnail = array('filedata' => '', 'filesize' => 0, 'dateline' => 0, 'imageerror' => '');
if ($validfile = $this->is_valid_thumbnail_extension(file_extension($filename)) and $imageinfo = $this->fetch_image_info($location)) {
$new_width = $width = $imageinfo[0];
$new_height = $height = $imageinfo[1];
if ($this->fetch_imagetype_from_extension(file_extension($filename)) != $imageinfo[2]) {
$thumbnail['imageerror'] = 'thumbnail_notcorrectimage';
} else {
if ($width > $maxwidth or $height > $maxheight) {
$memoryok = true;
if (function_exists('memory_get_usage') and $memory_limit = @ini_get('memory_limit') and $memory_limit != -1) {
$memorylimit = vb_number_format($memory_limit, 0, false, null, '');
$memoryusage = memory_get_usage();
$freemem = $memorylimit - $memoryusage;
$checkmem = true;
$tmemory = $width * $height * ($imageinfo[2] == 'JPEG' ? 5 : 2) + 7372.8 + sqrt(sqrt($width * $height));
$tmemory += 166000;
// fudge factor, object overhead, etc
if ($freemem > 0 and $tmemory > $freemem and $tmemory <= $memorylimit * 3) {
// attempt to increase memory within reason, no more than triple
if (($current_memory_limit = ini_size_to_bytes(@ini_get('memory_limit'))) < $memorylimit + $tmemory and $current_memory_limit > 0) {
@ini_set('memory_limit', $memorylimit + $tmemory);
}
$memory_limit = @ini_get('memory_limit');
$memorylimit = vb_number_format($memory_limit, 0, false, null, '');
$memoryusage = memory_get_usage();
$freemem = $memorylimit - $memoryusage;
}
}
switch ($imageinfo[2]) {
case 'GIF':
if (function_exists('imagecreatefromgif')) {
if ($checkmem) {
if ($freemem > 0 and $tmemory > $freemem) {
$thumbnail['imageerror'] = 'thumbnail_notenoughmemory';
$memoryok = false;
}
}
if ($memoryok and !($image = @imagecreatefromgif($location))) {
$thumbnail['imageerror'] = 'thumbnail_nocreateimage';
}
} else {
$thumbnail['imageerror'] = 'thumbnail_nosupport';
}
break;
case 'JPEG':
if (function_exists('imagecreatefromjpeg')) {
if ($checkmem) {
if ($freemem > 0 and $tmemory > $freemem) {
$thumbnail['imageerror'] = 'thumbnail_notenoughmemory';
$memoryok = false;
}
}
if ($memoryok and !($image = @imagecreatefromjpeg($location))) {
$thumbnail['imageerror'] = 'thumbnail_nocreateimage';
}
} else {
$thumbnail['imageerror'] = 'thumbnail_nosupport';
}
break;
case 'PNG':
if (function_exists('imagecreatefrompng')) {
if ($checkmem) {
if ($freemem > 0 and $tmemory > $freemem) {
$thumbnail['imageerror'] = 'thumbnail_notenoughmemory';
$memoryok = false;
}
}
if ($memoryok and !($image = @imagecreatefrompng($location))) {
$thumbnail['imagerror'] = 'thumbnail_nocreateimage';
}
} else {
$thumbnail['imageerror'] = 'thumbnail_nosupport';
}
break;
}
if ($image) {
$xratio = $maxwidth == 0 ? 1 : $width / $maxwidth;
$yratio = $maxheight == 0 ? 1 : $height / $maxheight;
if ($xratio > $yratio) {
$new_width = round($width / $xratio);
$new_height = round($height / $xratio);
} else {
$new_width = round($width / $yratio);
$new_height = round($height / $yratio);
}
if ($drawborder) {
$create_width = $new_width + 2;
$create_height = $new_height + 2;
$dest_x_start = 1;
$dest_y_start = 1;
} else {
$create_width = $new_width;
$create_height = $new_height;
//.........这里部分代码省略.........
示例9: __buildPage
/**
* This function sets the page's parameters, processes the Datasources and
* Events and sets the `$xml` and `$xsl` variables. This functions resolves the `$page`
* by calling the `resolvePage()` function. If a page is not found, it attempts
* to locate the Symphony 404 page set in the backend otherwise it throws
* the default Symphony 404 page. If the page is found, the page's XSL utility
* is found, and the system parameters are set, including any URL parameters,
* params from the Symphony cookies. Events and Datasources are executed and
* any parameters generated by them are appended to the existing parameters
* before setting the Page's XML and XSL variables are set to the be the
* generated XML (from the Datasources and Events) and the XSLT (from the
* file attached to this Page)
*
* @uses FrontendPageResolved
* @uses FrontendParamsResolve
* @uses FrontendParamsPostResolve
* @see resolvePage()
*/
private function __buildPage()
{
$start = precision_timer();
if (!($page = $this->resolvePage())) {
throw new FrontendPageNotFoundException();
}
/**
* Just after having resolved the page, but prior to any commencement of output creation
* @delegate FrontendPageResolved
* @param string $context
* '/frontend/'
* @param FrontendPage $page
* An instance of this class, passed by reference
* @param array $page_data
* An associative array of page data, which is a combination from `tbl_pages` and
* the path of the page on the filesystem. Passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('FrontendPageResolved', '/frontend/', array('page' => &$this, 'page_data' => &$page));
$this->_pageData = $page;
$path = explode('/', $page['path']);
$root_page = is_array($path) ? array_shift($path) : $path;
$current_path = explode(dirname($_SERVER['SCRIPT_NAME']), $_SERVER['REQUEST_URI'], 2);
$current_path = '/' . ltrim(end($current_path), '/');
$split_path = explode('?', $current_path, 3);
$current_path = rtrim(current($split_path), '/');
$querystring = '?' . next($split_path);
// Get max upload size from php and symphony config then choose the smallest
$upload_size_php = ini_size_to_bytes(ini_get('upload_max_filesize'));
$upload_size_sym = Symphony::Configuration()->get('max_upload_size', 'admin');
$this->_param = array('today' => DateTimeObj::get('Y-m-d'), 'current-time' => DateTimeObj::get('H:i'), 'this-year' => DateTimeObj::get('Y'), 'this-month' => DateTimeObj::get('m'), 'this-day' => DateTimeObj::get('d'), 'timezone' => DateTimeObj::get('P'), 'website-name' => Symphony::Configuration()->get('sitename', 'general'), 'page-title' => $page['title'], 'root' => URL, 'workspace' => URL . '/workspace', 'root-page' => $root_page ? $root_page : $page['handle'], 'current-page' => $page['handle'], 'current-page-id' => $page['id'], 'current-path' => $current_path, 'parent-path' => '/' . $page['path'], 'current-query-string' => XMLElement::stripInvalidXMLCharacters(utf8_encode(urldecode($querystring))), 'current-url' => URL . $current_path, 'upload-limit' => min($upload_size_php, $upload_size_sym), 'symphony-version' => Symphony::Configuration()->get('version', 'symphony'));
if (is_array($this->_env['url'])) {
foreach ($this->_env['url'] as $key => $val) {
$this->_param[$key] = $val;
}
}
if (is_array($_GET) && !empty($_GET)) {
foreach ($_GET as $key => $val) {
if (in_array($key, array('symphony-page', 'debug', 'profile'))) {
continue;
}
// If the browser sends encoded entities for &, ie. a=1&b=2
// this causes the $_GET to output they key as amp;b, which results in
// $url-amp;b. This pattern will remove amp; allow the correct param
// to be used, $url-b
$key = preg_replace('/(^amp;|\\/)/', null, $key);
// If the key gets replaced out then it will break the XML so prevent
// the parameter being set.
if (!General::createHandle($key)) {
continue;
}
$this->_param['url-' . $key] = XMLElement::stripInvalidXMLCharacters(utf8_encode(urldecode($val)));
}
}
if (is_array($_COOKIE[__SYM_COOKIE_PREFIX_]) && !empty($_COOKIE[__SYM_COOKIE_PREFIX_])) {
foreach ($_COOKIE[__SYM_COOKIE_PREFIX_] as $key => $val) {
$this->_param['cookie-' . $key] = $val;
}
}
// Flatten parameters:
General::flattenArray($this->_param);
/**
* Just after having resolved the page params, but prior to any commencement of output creation
* @delegate FrontendParamsResolve
* @param string $context
* '/frontend/'
* @param array $params
* An associative array of this page's parameters
*/
Symphony::ExtensionManager()->notifyMembers('FrontendParamsResolve', '/frontend/', array('params' => &$this->_param));
$xml_build_start = precision_timer();
$xml = new XMLElement('data');
$xml->setIncludeHeader(true);
$events = new XMLElement('events');
$this->processEvents($page['events'], $events);
$xml->appendChild($events);
$this->_events_xml = clone $events;
$this->processDatasources($page['data_sources'], $xml);
Symphony::Profiler()->seed($xml_build_start);
Symphony::Profiler()->sample('XML Built', PROFILE_LAP);
if (is_array($this->_env['pool']) && !empty($this->_env['pool'])) {
foreach ($this->_env['pool'] as $handle => $p) {
if (!is_array($p)) {
//.........这里部分代码省略.........
示例10: addFrontendMarkupDoc
public function addFrontendMarkupDoc(array &$doc_parts, $rootelement, $section, $filters)
{
$multiple = $this->hasMultipleFilter($filters);
$doc_parts[] = new XMLElement('h3', __('Example Front-end Form Markup'));
$doc_parts[] = new XMLElement('p', __('This is an example of the form markup you can use on your frontend:'));
$container = new XMLElement('form', null, array('method' => 'post', 'action' => '{$current-url}/', 'enctype' => 'multipart/form-data'));
$container->appendChild(Widget::Input('MAX_FILE_SIZE', (string) min(ini_size_to_bytes(ini_get('upload_max_filesize')), Symphony::Configuration()->get('max_upload_size', 'admin')), 'hidden'));
if (is_numeric($section)) {
$section = SectionManager::fetch($section);
if ($section instanceof Section) {
$section_fields = $section->fetchFields();
if (is_array($section_fields) && !empty($section_fields)) {
foreach ($section_fields as $f) {
if ($f->getExampleFormMarkup() instanceof XMLElement) {
$container->appendChild($f->getExampleFormMarkup());
}
}
}
}
}
$container->appendChild(Widget::Input('action[' . $rootelement . ']', __('Submit'), 'submit'));
$code = $container->generate(true);
$doc_parts[] = self::processDocumentationCode($multiple ? str_replace('fields[', 'fields[0][', $code) : $code);
$doc_parts[] = new XMLElement('p', __('To edit an existing entry, include the entry ID value of the entry in the form. This is best as a hidden field like so:'));
$doc_parts[] = self::processDocumentationCode(Widget::Input('id' . ($multiple ? '[0]' : null), '23', 'hidden'));
$doc_parts[] = new XMLElement('p', __('To redirect to a different location upon a successful save, include the redirect location in the form. This is best as a hidden field like so, where the value is the URL to redirect to:'));
$doc_parts[] = self::processDocumentationCode(Widget::Input('redirect', URL . '/success/', 'hidden'));
}
示例11: display
public function display($url = NULL)
{
self::$Parameters = new Register();
// Default headers. Can be overwritten later
//self::$Headers->append('HTTP/1.0 200 OK');
self::$Headers->append('Content-Type', 'text/html;charset=utf-8');
self::$Headers->append('Expires', 'Mon, 12 Dec 1982 06:14:00 GMT');
self::$Headers->append('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
self::$Headers->append('Cache-Control', 'no-cache, must-revalidate, max-age=0');
self::$Headers->append('Pragma', 'no-cache');
####
# Delegate: FrontendPreInitialise
# Description: TODO
# Global: Yes
Extension::notify('FrontendPreInitialise', '/frontend/', array('view' => &self::$view, 'url' => &$url));
if (!self::$view instanceof View) {
$this->resolve($url);
}
####
# Delegate: FrontendPostInitialise
Extension::notify('FrontendPostInitialise', '/frontend/', array('view' => &self::$view));
// SETTING UP PARAMETERS --------------------------
$root_page = array_shift(explode('/', self::$view->parent()->path));
$current_path = explode(dirname($_SERVER['SCRIPT_NAME']), $_SERVER['REQUEST_URI'], 2);
$current_path = '/' . ltrim(end($current_path), '/');
self::$Parameters->register(array('today' => DateTimeObj::get('Y-m-d'), 'current-time' => DateTimeObj::get('H:i'), 'this-year' => DateTimeObj::get('Y'), 'this-month' => DateTimeObj::get('m'), 'this-day' => DateTimeObj::get('d'), 'timezone' => date_default_timezone_get(), 'website-name' => Symphony::Configuration()->core()->symphony->sitename, 'symphony-version' => Symphony::Configuration()->core()->symphony->version, 'upload-limit' => min(ini_size_to_bytes(ini_get('upload_max_filesize')), Symphony::Configuration()->core()->symphony->{'maximum-upload-size'}), 'root' => URL, 'workspace' => URL . '/workspace', 'page-title' => self::$view->title, 'root-page' => !is_null($root_page) ? $root_page : self::$view->handle, 'current-page' => self::$view->handle, 'current-path' => $current_path, 'parent-path' => '/' . self::$view->path, 'current-url' => URL . $current_path));
if (isset(self::$view->{'url-parameters'}) && is_array(self::$view->{'url-parameters'})) {
foreach (self::$view->{'url-parameters'} as $p) {
self::$Parameters->{$p} = NULL;
}
foreach (self::$view->parameters() as $p => $v) {
self::$Parameters->{$p} = str_replace(' ', '+', $v);
}
}
if (is_array($_GET) && !empty($_GET)) {
foreach ($_GET as $key => $val) {
if (in_array($key, array('symphony-page', 'debug', 'profile'))) {
continue;
}
// self::$Parameters->{"url-{$key}"} = $val; "url" is not prepended by $_GET params
self::$Parameters->{$key} = $val;
}
}
if (is_array($_COOKIE[__SYM_COOKIE_PREFIX__]) && !empty($_COOKIE[__SYM_COOKIE_PREFIX__])) {
foreach ($_COOKIE[__SYM_COOKIE_PREFIX__] as $key => $val) {
self::$Parameters->{"cookie-{$key}"} = $val;
}
}
// RENDER THE VIEW --------------------------
// Can ask the view to operate on an existing
// Document. Useful if we pass it around beyond
// the scope of View::render()
####
# Delegate: FrontendPreRender
# Description: TODO
# Global: Yes
Extension::notify('FrontendPreRender', '/frontend/', array('view' => &self::$view, 'parameters' => &self::$Parameters, 'document' => &self::$Document, 'headers' => &self::$Headers));
$output = self::$view->render(self::$Parameters, self::$Document, self::$Headers);
####
# Delegate: FrontendPostRender
# Description: TODO
# Global: Yes
Extension::notify('FrontendPostRender', '/frontend/', array('output' => &$output, 'headers' => &self::$Headers));
self::Headers()->render();
return $output;
}
示例12: getViewContext
public function getViewContext()
{
$this->context->register(array('view' => array('title' => $this->title, 'handle' => $this->handle, 'path' => $this->path, 'current-url' => URL . '/' . $this->path, 'root-view' => !is_null($root_page) ? $root_page : $this->handle, 'parent-path' => '/' . $this->path, 'upload-limit' => min(ini_size_to_bytes(ini_get('upload_max_filesize')), Symphony::Configuration()->core()->symphony->{'maximum-upload-size'}))));
}