本文整理汇总了PHP中str::template方法的典型用法代码示例。如果您正苦于以下问题:PHP str::template方法的具体用法?PHP str::template怎么用?PHP str::template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::template方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param mixed $source
* @param array $params
*/
public function __construct($source, $params = array())
{
$this->source = $this->result = is_a($source, 'Media') ? $source : new Media($source);
$this->options = array_merge(static::$defaults, $this->params($params));
$this->destination = new Obj();
$this->destination->filename = str::template($this->options['filename'], array('extension' => $this->source->extension(), 'name' => $this->source->name(), 'filename' => $this->source->filename(), 'safeName' => f::safeName($this->source->name()), 'safeFilename' => f::safeName($this->source->name()) . '.' . $this->extension(), 'width' => $this->options['width'], 'height' => $this->options['height'], 'hash' => md5($this->source->root() . $this->settingsIdentifier())));
$this->destination->url = $this->options['url'] . '/' . $this->destination->filename;
$this->destination->root = $this->options['root'] . DS . $this->destination->filename;
// don't create the thumbnail if it's not necessary
if ($this->isObsolete()) {
return;
}
// don't create the thumbnail if it exists
if (!$this->isThere()) {
// check for a valid image
if (!$this->source->exists() or $this->source->type() != 'image') {
throw new Error('The given image is invalid', static::ERROR_INVALID_IMAGE);
}
// check for a valid driver
if (!array_key_exists($this->options['driver'], static::$drivers)) {
throw new Error('Invalid thumbnail driver', static::ERROR_INVALID_DRIVER);
}
// create the thumbnail
$this->create();
// check if creating the thumbnail failed
if (!file_exists($this->destination->root)) {
return;
}
}
// create the result object
$this->result = new Media($this->destination->root, $this->destination->url);
}
示例2: parseFileAttributes
public function parseFileAttributes()
{
$source = $this->data[self::ARRAY_ATTR][self::PARA_IMG_SOURCE];
$source = is_object($source) ? $source : $this->imageExt->getPage()->file($source);
if ($source) {
$this->data[self::ARRAY_ATTR][self::PARA_IMG_SOURCE] = $source->filename();
$this->data[self::ARRAY_ATTR][self::PARA_IMG_SOURCE_MODIFIED] = $source->modified();
$this->data[self::ARRAY_ATTR][self::PARA_IMG_EXTENSION] = $source->extension();
$this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_FILENAME] = \str::template($this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_FILENAME], array('extension' => $source->extension(), 'name' => $source->name(), 'filename' => $source->filename(), 'safeName' => \f::safeName($source->name()), 'safeFilename' => \f::safeName($source->name()) . '.' . $this->data[self::ARRAY_ATTR][self::PARA_IMG_EXTENSION], 'width' => $this->data[self::ARRAY_ATTR][self::PARA_IMG_WIDTH], 'height' => $this->data[self::ARRAY_ATTR][self::PARA_IMG_HEIGHT], 'hash' => md5($source->root() . $this->settingsIdentifier())));
$this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_URL] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_URL] . '/' . $this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_FILENAME];
$this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_ROOT] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_ROOT] . DS . $this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_FILENAME];
if ($this->data[self::ARRAY_ATTR][self::PARA_GALLERY_ID] !== false && !empty($this->data[self::ARRAY_ATTR][self::PARA_GALLERY_ID])) {
$this->data[self::ARRAY_ATTR][self::PARA_LINK_URL] = $source->url();
}
if (is_string($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT]) && WebHelper::startsWith($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT], '{file-') && WebHelper::endsWith($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT], '}')) {
$field = substr($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT], 6, strlen($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT]) - 7);
$this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT] = $source->{$field}()->toString();
}
if (is_string($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE]) && WebHelper::startsWith($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE], '{file-') && WebHelper::endsWith($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE], '}')) {
$field = substr($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE], 6, strlen($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE]) - 7);
$this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE] = $source->{$field}()->toString();
}
if (is_string($this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE]) && WebHelper::startsWith($this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE], '{file-') && WebHelper::endsWith($this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE], '}')) {
$field = substr($this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE], 6, strlen($this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE]) - 7);
$this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE] = $source->{$field}()->toString();
}
}
}
示例3: to
public function to()
{
$source = $this->source();
$name = f::name($source['name']);
$extension = f::extension($source['name']);
$safeName = f::safeName($name);
$safeExtension = str_replace('jpeg', 'jpg', str::lower($extension));
return str::template($this->options['to'], array('name' => $name, 'filename' => $source['name'], 'safeName' => $safeName, 'safeFilename' => $safeName . '.' . $safeExtension, 'extension' => $extension, 'safeExtension' => $safeExtension));
}
示例4: copy
protected function copy()
{
if ($this->input->getOption('bare')) {
$blueprint = f::read($this->template());
$blueprint = str::template($blueprint, ['title' => ucfirst($this->name())]);
f::write($this->file(), $blueprint);
} else {
$this->questions();
}
}
示例5: destination
/**
* Build the destination object
*
* @return Obj
*/
public function destination()
{
if (is_callable($this->options['destination'])) {
return call($this->options['destination'], $this);
} else {
$destination = new Obj();
$destination->filename = str::template($this->options['filename'], array('extension' => $this->source->extension(), 'name' => $this->source->name(), 'filename' => $this->source->filename(), 'safeName' => f::safeName($this->source->name()), 'safeFilename' => f::safeName($this->source->name()) . '.' . $this->extension(), 'width' => $this->options['width'], 'height' => $this->options['height'], 'hash' => md5($this->source->root() . $this->settingsIdentifier())));
$destination->url = $this->options['url'] . '/' . $destination->filename;
$destination->root = $this->options['root'] . DS . $destination->filename;
return $destination;
}
}
示例6: getEmailParams
public function getEmailParams()
{
//if we have a correct email template
if ($this->emailTemplate) {
//store template content in a string
$emailWithPlaceholders = $this->emailTemplate->read();
//replace placeholders in $emailWithPlaceholders with data
$emailWithData = str::template($emailWithPlaceholders, $this->emailData);
//return array
return yaml::decode($emailWithData);
}
//return emmpty array in case of error while getting email template
return '';
}
示例7: to
public function to()
{
if (!is_null($this->to)) {
return $this->to;
}
$source = $this->source();
$name = f::name($source['name']);
$extension = f::extension($source['name']);
$safeName = f::safeName($name);
$safeExtension = str_replace('jpeg', 'jpg', str::lower($extension));
if (empty($safeExtension)) {
$safeExtension = f::mimeToExtension(f::mime($source['tmp_name']));
}
return $this->to = str::template($this->options['to'], array('name' => $name, 'filename' => $source['name'], 'safeName' => $safeName, 'safeFilename' => $safeName . r(!empty($safeExtension), '.' . $safeExtension), 'extension' => $extension, 'safeExtension' => $safeExtension));
}
示例8: __construct
/**
* Constructor
*
* @param mixed $source
* @param array $params
*/
public function __construct($source, $params = array())
{
$this->source = $this->result = is_a($source, 'Media') ? $source : new Media($source);
// set source root as default
static::$defaults['url'] = $this->source->url();
static::$defaults['root'] = $this->source->dir();
$this->options = array_merge(static::$defaults, $params);
$this->destination = new Obj();
$this->destination->filename = str::template($this->options['filename'], array('extension' => $this->source->extension(), 'name' => $this->source->name(), 'filename' => $this->source->filename(), 'safeName' => f::safeName($this->source->name()), 'safeFilename' => f::safeName($this->source->name()) . '.' . $this->extension(), 'width' => $this->options['width'], 'height' => $this->options['height']));
$this->destination->url = $this->options['url'] . '/' . $this->destination->filename;
$this->destination->root = $this->options['root'] . DS . $this->destination->filename;
// check for a valid image
if (!$this->source->exists() or $this->source->type() != 'image') {
throw new Exception('The given image is invalid', static::ERROR_INVALID_IMAGE);
}
}
示例9: __construct
/**
* @param string $id The unique ID of this form.
*
* @param string $recipient e-mail adress the form content should be sent to.
*
* @param array $options Array of sendform options.
*/
public function __construct($id, $recipient, $options)
{
if (empty($id)) {
throw new Error('No SendForm ID was given.');
}
if (empty($recipient)) {
throw new Error('No SendForm recipient was given.');
}
$this->id = $id;
$this->erroneousFields = array();
// the token is stored as session variable until the form is sent
// successfully
$this->token = s::get($this->id);
if (!$this->token) {
$this->generateToken();
}
// get the data to be sent (if there is any)
$this->data = get();
if ($this->requestValid()) {
$this->options = array('subject' => str::template(a::get($options, 'subject', l::get('sendform-default-subject')), $this->data), 'snippet' => a::get($options, 'snippet', false), 'copy' => a::get($options, 'copy', array()), 'required' => a::get($options, 'required', array()), 'validate' => a::get($options, 'validate', array()), 'to' => $recipient, 'service' => a::get($options, 'service', 'mail'), 'service-options' => a::get($options, 'service-options', array()));
// remove newlines to prevent malicious modifications of the email
// header
$this->options['subject'] = str_replace("\n", '', $this->options['subject']);
// extend the data array so email snippets get these fields, too
$this->data['_subject'] = $this->options['subject'];
$this->data['_to'] = $this->options['to'];
if (array_key_exists('_receive_copy', $this->data)) {
array_unshift($this->options['copy'], $this->data['_from']);
}
$this->sentSuccessful = false;
$this->message = '';
$requiredFields = a::merge($this->options['required'], array('_from' => 'email'));
$validateFields = a::merge($this->options['validate'], $requiredFields);
if ($this->dataValid($requiredFields, $validateFields)) {
$this->sendForm();
}
}
}
示例10: return
return false;
} else {
if (array_key_exists($action, $this->actionOutput)) {
return (bool) a::get($this->actionOutput[$action], 'message');
} else {
return false;
}
}
}
}
/* DEFAULT ACTIONS */
/*
* The action to send the form data as an email.
*/
uniform::$actions['email'] = function ($form, $actionOptions) {
$options = array('subject' => str::template(a::get($actionOptions, 'subject', l::get('uniform-email-subject')), $form), 'snippet' => a::get($actionOptions, 'snippet', false), 'to' => a::get($actionOptions, 'to'), 'sender' => a::get($actionOptions, 'sender'), 'service' => a::get($actionOptions, 'service', 'mail'), 'service-options' => a::get($actionOptions, 'service-options', array()));
// remove newlines to prevent malicious modifications of the email
// header
$options['subject'] = str_replace("\n", '', $options['subject']);
$mailBody = "";
$snippet = $options['snippet'];
if (empty($snippet)) {
foreach ($form as $key => $value) {
if (str::startsWith($key, '_')) {
continue;
}
$mailBody .= ucfirst($key) . ': ' . $value . "\n\n";
}
} else {
$mailBody = snippet($snippet, compact('form', 'options'), true);
if ($mailBody === false) {
示例11: _template
protected function _template($what)
{
$template = f::read(__DIR__ . '/templates/plugin/' . $what);
$template = str::template($template, ['name' => $this->name()]);
return $template;
}
示例12: createTable
/**
* Creates a table with a simple scheme array for columns
*
* @todo add more options per column
* @param string $table The table name
* @param array $columns
* @param string $type mysql or sqlite
* @return string
*/
public function createTable($table, $columns = array())
{
$type = strtolower($this->db->type());
$output = array();
$keys = array();
if (!in_array($type, array('mysql', 'sqlite'))) {
throw new Exception('Unsupported database type: ' . $type);
}
foreach ($columns as $name => $column) {
$template = array();
switch ($column['type']) {
case 'id':
$template['mysql'] = '"{column.name}" INT(11) UNSIGNED NOT NULL AUTO_INCREMENT';
$template['sqlite'] = '"{column.name}" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE';
$keys[$name] = 'PRIMARY';
break;
case 'varchar':
$template['mysql'] = '"{column.name}" varchar(255) {column.null}';
$template['sqlite'] = '"{column.name}" TEXT {column.null} {column.key}';
break;
case 'text':
$template['mysql'] = '"{column.name}" TEXT';
$template['sqlite'] = '"{column.name}" TEXT {column.null} {column.key}';
break;
case 'int':
$template['mysql'] = '"{column.name}" INT(11) UNSIGNED {column.null}';
$template['sqlite'] = '"{column.name}" INTEGER {column.null} {column.key}';
break;
case 'timestamp':
$template['mysql'] = '"{column.name}" INT(11) UNSIGNED {column.null}';
$template['sqlite'] = '"{column.name}" INTEGER {column.null} {column.key}';
break;
default:
throw new Exception('Unsupported column type: ' . $column['type']);
}
if (isset($column['key'])) {
$key = strtoupper($column['key']);
$keys[$name] = $key;
} else {
$key = false;
}
$output[] = trim(str::template($template[$type], array('column.name' => $name, 'column.null' => a::get($column, 'null') === false ? 'NOT NULL' : 'NULL', 'column.key' => ($key and $key != 'INDEX') ? $key : false)));
}
// all columns
$inner = implode(', ' . PHP_EOL, $output);
// add keys for mysql
if ($type == 'mysql') {
foreach ($keys as $name => $key) {
$inner .= ', ' . PHP_EOL . trim(r($key != 'INDEX', $key) . ' KEY (`' . $name . '`)');
}
}
// make it a string
$output = 'CREATE TABLE "' . $table . '" (' . PHP_EOL . $inner . PHP_EOL . ');';
if ($type == 'mysql') {
$output = str_replace('"', '`', $output);
}
// add index keys for sqlite
if ($type == 'sqlite') {
foreach ($keys as $name => $key) {
if ($key != 'INDEX') {
continue;
}
$output .= PHP_EOL . 'CREATE INDEX "' . $name . '" ON "' . $table . '" ("' . $name . '");';
}
}
return $output;
}
示例13: function
<?php
/*
* The action to send the form data as an email.
*/
uniform::$actions['email'] = function ($form, $actionOptions) {
// the form could contain arrays which are incompatible with the template function
$templatableItems = array_filter($form, function ($item) {
return is_scalar($item);
});
$options = ['subject' => str::template(a::get($actionOptions, 'subject', l::get('uniform-email-subject')), $templatableItems), 'snippet' => a::get($actionOptions, 'snippet', false), 'receive-copy' => a::get($actionOptions, 'receive-copy', true), 'to' => a::get($actionOptions, 'to'), 'sender' => a::get($actionOptions, 'sender'), 'service' => a::get($actionOptions, 'service', 'mail'), 'service-options' => a::get($actionOptions, 'service-options', [])];
// remove newlines to prevent malicious modifications of the email
// header
$options['subject'] = str_replace("\n", '', $options['subject']);
$mailBody = '';
$snippet = $options['snippet'];
if (empty($snippet)) {
foreach ($form as $key => $value) {
if (str::startsWith($key, '_')) {
continue;
}
if (is_array($value)) {
$value = implode(', ', array_filter($value, function ($i) {
return $i !== '';
}));
}
$mailBody .= ucfirst($key) . ': ' . $value . "\n\n";
}
} else {
$mailBody = snippet($snippet, compact('form', 'options'), true);
if ($mailBody === false) {
示例14: trim
// backwards compatibility
if ($column['key'] === 'PRIMARY') {
$column['key'] = 'PRIMARY KEY';
}
if (in_array($column['key'], array('PRIMARY KEY', 'INDEX'))) {
$key = $column['key'];
$keys[$name] = $key;
}
}
// default value
$default = null;
if (isset($column['default'])) {
// Apparently SQLite doesn't support bindings for default values
$default = "'" . $sql->database->escape($column['default']) . "'";
}
$output[] = trim(str::template($template, array('column.name' => $sql->quoteIdentifier($name), 'column.null' => $null, 'column.key' => r($key && $key != 'INDEX', $key), 'column.default' => r(!is_null($default), 'DEFAULT ' . $default))));
}
// combine columns
$inner = implode(',' . PHP_EOL, $output);
// make it a string
$query = 'CREATE TABLE ' . $sql->quoteIdentifier($table) . ' (' . PHP_EOL . $inner . PHP_EOL . ')';
// set bindings for our first query
$sql->bindings($query, $bindings);
// add index keys
foreach ($keys as $name => $key) {
if ($key != 'INDEX') {
continue;
}
$indexQuery = 'CREATE INDEX ' . $sql->quoteIdentifier($table . '_' . $name) . ' ON ' . $sql->quoteIdentifier($table) . ' (' . $sql->quoteIdentifier($name) . ')';
$query .= ';' . PHP_EOL . $indexQuery;
}
示例15: panel
<?php
$license = panel()->license();
if ($license->type() == 'trial' and !$license->local()) {
return array('title' => array('text' => l('dashboard.index.license.title'), 'link' => false, 'compressed' => false), 'html' => function () {
return tpl::load(__DIR__ . DS . 'license.html.php', array('text' => kirbytext(str::template(l('dashboard.index.license.text'), array('buy' => 'http://getkirby.com/buy', 'docs' => 'http://getkirby.com/docs/installation/license-code')))));
});
} else {
return false;
}