本文整理汇总了PHP中when函数的典型用法代码示例。如果您正苦于以下问题:PHP when函数的具体用法?PHP when怎么用?PHP when使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了when函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: shouldReturnAJsonRepresentationOfASession
/**
* @test
* @group mocking
*/
public function shouldReturnAJsonRepresentationOfASession()
{
$session = mock('WhiteboardSession');
when($session)->info()->thenReturn(array('pretend-that' => 'this is a valid session info'));
when($this->request)->getParameter('token')->thenReturn('aTokenValue');
when($this->whiteboardSessionPeer)->loadByToken('aTokenValue')->thenReturn($session);
$this->actions->executeInfo($this->request);
$json = $this->getResponseContents();
$this->assertEquals('{"pretend-that":"this is a valid session info"}', $json);
}
开发者ID:rayku,项目名称:rayku,代码行数:14,代码来源:SessionActionsTest.php
示例2: __invoke
function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$this->redirection->setRequest($request);
$base = $this->settings->urlPrefix();
$base = $base ? "{$base}..." : '*';
return $this->router->set([$base => [when($this->settings->requireAuthentication(), AuthenticationMiddleware::class), '.' => page('platform/home.html'), 'settings...' => [when($this->settings->enableUsersManagement(), ['users-management...' => ['users' => factory(function (UsersPage $page) {
// This is done here just to show off this possibility
$page->templateUrl = 'platform/users/users.html';
return $page;
}), 'users/@id' => UserPage::class, 'profile' => factory(function (UserPage $page) {
$page->editingSelf = true;
return $page;
})]])]]])->__invoke($request, $response, $next);
}
开发者ID:selene-framework,项目名称:admin-module,代码行数:14,代码来源:Routes.php
示例3: loop_when
public static function loop_when()
{
$j = self::$lista->from();
$k = 0;
do {
if ($j < self::$lista->getSize()) {
when(self::$lista, $j);
$j = $j + 1;
$k = $k + 1;
} else {
$k = self::$lista->getQuantidadePorPagina();
}
} while ($k < self::$lista->getQuantidadePorPagina());
}
开发者ID:DaniloEpic,项目名称:slast,代码行数:14,代码来源:ListaHelper.php
示例4: create
/**
* Function: create
* Attempts to create a comment using the passed information. If a Defensio API key is present, it will check it.
*
* Parameters:
* $author - The name of the commenter.
* $email - The commenter's email.
* $url - The commenter's website.
* $body - The comment.
* $post - The <Post> they're commenting on.
* $type - The type of comment. Optional, used for trackbacks/pingbacks.
*/
static function create($author, $email, $url, $body, $post, $type = null)
{
if (!self::user_can($post->id) and !in_array($type, array("trackback", "pingback"))) {
return;
}
$config = Config::current();
$route = Route::current();
$visitor = Visitor::current();
if (!$type) {
$status = $post->user_id == $visitor->id ? "approved" : $config->default_comment_status;
$type = "comment";
} else {
$status = $type;
}
if (!empty($config->defensio_api_key)) {
$comment = array("user-ip" => $_SERVER['REMOTE_ADDR'], "article-date" => when("Y/m/d", $post->created_at), "comment-author" => $author, "comment-type" => $type, "comment-content" => $body, "comment-author-email" => $email, "comment-author-url" => $url, "permalink" => $post->url(), "referrer" => $_SERVER['HTTP_REFERER'], "user-logged-in" => logged_in());
$defensio = new Defensio($config->url, $config->defensio_api_key);
list($spam, $spaminess, $signature) = $defensio->auditComment($comment);
if ($spam) {
self::add($body, $author, $url, $email, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], "spam", $signature, null, null, $post, $visitor->id);
error(__("Spam Comment"), __("Your comment has been marked as spam. It will have to be approved before it will show up.", "comments"));
} else {
$comment = self::add($body, $author, $url, $email, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $status, $signature, null, null, $post, $visitor->id);
fallback($_SESSION['comments'], array());
$_SESSION['comments'][] = $comment->id;
if (isset($_POST['ajax'])) {
exit("{ comment_id: " . $comment->id . ", comment_timestamp: \"" . $comment->created_at . "\" }");
}
Flash::notice(__("Comment added."), $post->url() . "#comment_" . $comment->id);
}
} else {
$comment = self::add($body, $author, $url, $email, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $status, "", null, null, $post, $visitor->id);
fallback($_SESSION['comments'], array());
$_SESSION['comments'][] = $comment->id;
if (isset($_POST['ajax'])) {
exit("{ comment_id: " . $comment->id . ", comment_timestamp: \"" . $comment->created_at . "\" }");
}
Flash::notice(__("Comment added."), $post->url() . "#comment_" . $comment->id);
}
}
开发者ID:homebru,项目名称:bandb,代码行数:52,代码来源:model.Comment.php
示例5: __construct
/**
* Function: __construct
* Prepares an array for pagination.
*
* Parameters:
* $array - The array to paginate.
* $per_page - Number of items per page.
* $name - The name of the $_GET parameter to use for determining the current page.
* $model - If this is true, each item in $array that gets shown on the page will be
* initialized as a model of whatever is passed as the second argument to $array.
* The first argument of $array is expected to be an array of IDs.
* $page - Page number to start at.
*
* Returns:
* A paginated array of length $per_page or smaller.
*/
public function __construct($array, $per_page = 5, $name = "page", $model = null, $page = null)
{
self::$names[] = $name;
$this->array = (array) $array;
$this->per_page = $per_page;
$this->name = $name;
$this->model = fallback($model, count($this->array) == 2 and is_array($this->array[0]) and is_string($this->array[1]) and class_exists($this->array[1]));
if ($model) {
list($this->array, $model_name) = $this->array;
}
$this->total = count($this->array);
$this->page = oneof($page, @$_GET[$name], 1);
$this->pages = ceil($this->total / $this->per_page);
$offset = ($this->page - 1) * $this->per_page;
$this->result = array();
if ($model) {
for ($i = $offset; $i < $offset + $this->per_page; $i++) {
if (isset($this->array[$i])) {
$this->result[] = new $model_name(null, array("read_from" => $this->array[$i]));
}
}
} else {
$this->result = array_slice($this->array, $offset, $this->per_page);
}
$shown_dates = array();
if ($model) {
foreach ($this->result as &$result) {
if (isset($result->created_at)) {
$pinned = (isset($result->pinned) and $result->pinned);
$shown = in_array(when("m-d-Y", $result->created_at), $shown_dates);
$result->first_of_day = (!$pinned and !$shown and !AJAX);
if (!$pinned and !$shown) {
$shown_dates[] = when("m-d-Y", $result->created_at);
}
}
}
}
$this->paginated = $this->paginate = $this->list =& $this->result;
}
开发者ID:betsyzhang,项目名称:chyrp,代码行数:55,代码来源:Paginator.php
示例6: twig_strftime_format_filter
function twig_strftime_format_filter($timestamp, $format = '%x %X')
{
return when($format, $timestamp, true);
}
开发者ID:betsyzhang,项目名称:chyrp,代码行数:4,代码来源:runtime.php
示例7: function
<?php
/**
* Somewhere within your application:
*
* This is just an example of what you can do.
*/
namespace FileSystem;
class Space extends Directory
{
}
$application->bind('FileSystem\\Space', function (User $user) {
return new Space($user->allocatedSpacePath);
});
// In your business logic:
use FileSystem\File;
use FileSystem\FileSystem;
use FileSystem\Space;
when('i want to make a directory inside my space', then(apply(a(function (FileSystem $fileSystem, Space $space, File $file) {
$fileSystem->write($file, inside($space));
}))));
开发者ID:lionar,项目名称:file-system,代码行数:22,代码来源:writing+a+file+inside+a+directory.php
示例8: when
<?php
use FileSystem\File;
use FileSystem\FileSystem;
when('i want to rename a file', then(apply(a(function (FileSystem $fileSystem, File $file) {
$fileSystem->rename($file);
}))));
/*
|--------------------------------------------------------------------------
| Notes: renaming behind the scenes.
|--------------------------------------------------------------------------
|
| Behind the scenes in your technical code you call:
| $file->renameTo ( 'new name' );
|
| The business code here can choose to save it to the file
| system as it has done in the above code. Other options
| might include just ignoring the technical provided name
| and renaming the file to something else.
*/
开发者ID:lionar,项目名称:file-system,代码行数:20,代码来源:renaming+a+file.php
示例9: selected
<option value="spam"<?php
selected($comment->status, "spam");
?>
><?php
echo __("Spam", "comments");
?>
</option>
</select>
</p>
<p>
<label for="created_at"><?php
echo __("Timestamp");
?>
</label>
<input class="text" type="text" name="created_at" value="<?php
echo when("F jS, Y H:i:s", $comment->created_at);
?>
" id="created_at" />
</p>
<div class="clear"></div>
</div>
<br />
<input type="hidden" name="id" value="<?php
echo fix($comment->id);
?>
" id="id" />
<input type="hidden" name="ajax" value="true" id="ajax" />
<div class="buttons">
<input type="submit" value="<?php
echo __("Update");
?>
开发者ID:vito,项目名称:chyrp-site,代码行数:31,代码来源:edit_form.php
示例10: export
/**
* Function: export
* Export posts, pages, etc.
*/
public function export()
{
if (!Visitor::current()->group->can("add_post")) {
show_403(__("Access Denied"), __("You do not have sufficient privileges to export content."));
}
if (empty($_POST)) {
return $this->display("export");
}
$config = Config::current();
$trigger = Trigger::current();
$route = Route::current();
$exports = array();
if (isset($_POST['posts'])) {
list($where, $params) = keywords($_POST['filter_posts'], "post_attributes.value LIKE :query OR url LIKE :query", "post_attributes");
if (!empty($_GET['month'])) {
$where["created_at like"] = $_GET['month'] . "-%";
}
$visitor = Visitor::current();
if (!$visitor->group->can("view_draft", "edit_draft", "edit_post", "delete_draft", "delete_post")) {
$where["user_id"] = $visitor->id;
}
$results = Post::find(array("placeholders" => true, "drafts" => true, "where" => $where, "params" => $params));
$ids = array();
foreach ($results[0] as $result) {
$ids[] = $result["id"];
}
if (!empty($ids)) {
$posts = Post::find(array("drafts" => true, "where" => array("id" => $ids), "order" => "id ASC"), array("filter" => false));
} else {
$posts = new Paginator(array());
}
$latest_timestamp = 0;
foreach ($posts as $post) {
if (strtotime($post->created_at) > $latest_timestamp) {
$latest_timestamp = strtotime($post->created_at);
}
}
$id = substr(strstr($config->url, "//"), 2);
$id = str_replace("#", "/", $id);
$id = preg_replace("/(" . preg_quote(parse_url($config->url, PHP_URL_HOST)) . ")/", "\\1," . date("Y", $latest_timestamp) . ":", $id, 1);
$posts_atom = '<?xml version="1.0" encoding="utf-8"?>' . "\r";
$posts_atom .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:chyrp="http://chyrp.net/export/1.0/">' . "\r";
$posts_atom .= ' <title>' . fix($config->name) . ' Posts</title>' . "\r";
$posts_atom .= ' <subtitle>' . fix($config->description) . '</subtitle>' . "\r";
$posts_atom .= ' <id>tag:' . parse_url($config->url, PHP_URL_HOST) . ',' . date("Y", $latest_timestamp) . ':Chyrp</id>' . "\r";
$posts_atom .= ' <updated>' . date("c", $latest_timestamp) . '</updated>' . "\r";
$posts_atom .= ' <link href="' . $config->url . '" rel="self" type="application/atom+xml" />' . "\r";
$posts_atom .= ' <generator uri="http://chyrp.net/" version="' . CHYRP_VERSION . '">Chyrp</generator>' . "\r";
foreach ($posts as $post) {
$title = fix($post->title(), false);
fallback($title, ucfirst($post->feather) . " Post #" . $post->id);
$updated = $post->updated ? $post->updated_at : $post->created_at;
$tagged = substr(strstr(url("id/" . $post->id), "//"), 2);
$tagged = str_replace("#", "/", $tagged);
$tagged = preg_replace("/(" . preg_quote(parse_url($post->url(), PHP_URL_HOST)) . ")/", "\\1," . when("Y-m-d", $updated) . ":", $tagged, 1);
$url = $post->url();
$posts_atom .= ' <entry xml:base="' . fix($url) . '">' . "\r";
$posts_atom .= ' <title type="html">' . $title . '</title>' . "\r";
$posts_atom .= ' <id>tag:' . $tagged . '</id>' . "\r";
$posts_atom .= ' <updated>' . when("c", $updated) . '</updated>' . "\r";
$posts_atom .= ' <published>' . when("c", $post->created_at) . '</published>' . "\r";
$posts_atom .= ' <link href="' . fix($trigger->filter($url, "post_export_url", $post)) . '" />' . "\r";
$posts_atom .= ' <author chyrp:user_id="' . $post->user_id . '">' . "\r";
$posts_atom .= ' <name>' . fix(oneof($post->user->full_name, $post->user->login)) . '</name>' . "\r";
if (!empty($post->user->website)) {
$posts_atom .= ' <uri>' . fix($post->user->website) . '</uri>' . "\r";
}
$posts_atom .= ' <chyrp:login>' . fix($post->user->login) . '</chyrp:login>' . "\r";
$posts_atom .= ' </author>' . "\r";
$posts_atom .= ' <content>' . "\r";
foreach ($post->attributes as $key => $val) {
$posts_atom .= ' <' . $key . '>' . fix($val) . '</' . $key . '>' . "\r";
}
$posts_atom .= ' </content>' . "\r";
foreach (array("feather", "clean", "url", "pinned", "status") as $attr) {
$posts_atom .= ' <chyrp:' . $attr . '>' . fix($post->{$attr}) . '</chyrp:' . $attr . '>' . "\r";
}
$trigger->filter($posts_atom, "posts_export", $post);
$posts_atom .= ' </entry>' . "\r";
}
$posts_atom .= '</feed>' . "\r";
$exports["posts.atom"] = $posts_atom;
}
if (isset($_POST['pages'])) {
list($where, $params) = keywords($_POST['filter_pages'], "title LIKE :query OR body LIKE :query", "pages");
$pages = Page::find(array("where" => $where, "params" => $params, "order" => "id ASC"), array("filter" => false));
$latest_timestamp = 0;
foreach ($pages as $page) {
if (strtotime($page->created_at) > $latest_timestamp) {
$latest_timestamp = strtotime($page->created_at);
}
}
$pages_atom = '<?xml version="1.0" encoding="utf-8"?>' . "\r";
$pages_atom .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:chyrp="http://chyrp.net/export/1.0/">' . "\r";
$pages_atom .= ' <title>' . fix($config->name) . ' Pages</title>' . "\r";
$pages_atom .= ' <subtitle>' . fix($config->description) . '</subtitle>' . "\r";
//.........这里部分代码省略.........
开发者ID:eadz,项目名称:chyrp,代码行数:101,代码来源:Admin.php
示例11: renderMenuItem
private function renderMenuItem(\Iterator $links, $xi, $parentIsActive, $depth = 1)
{
$links->rewind();
if (!$links->valid() || $depth >= $this->props->depth) {
return null;
}
return h('ul.nav.collapse.' . $this->depthClass[$depth], map($links, function (NavigationLinkInterface $link) use($xi, $depth, $parentIsActive) {
if (!$link->isActuallyVisible() || $link->isGroup() && $link->title() == '-' && $this->props->excludeDividers) {
return null;
}
$children = $link->getMenu();
$sub = '';
/** @var NavigationLinkInterface $child */
foreach ($children as $child) {
if ($child->isActuallyVisible()) {
$sub = '.sub';
break;
}
}
$children->rewind();
$active = $link->isActive() ? '.active' : '';
$current = $link->isSelected() ? '.current' : '';
$disabled = !$link->isActuallyEnabled();
$url = $disabled || $link->isGroup() && !isset($link->defaultURI) ? null : $link->url();
$disabledClass = $disabled ? '.disabled' : '';
return [h("li{$active}{$sub}{$current}", [h("a{$active}{$disabledClass}", ['href' => $url], [when($link->icon(), h('i', ['class' => $link->icon()])), $link->title(), when(isset($xi) && $sub, h("span.{$xi}"))]), when($sub, $this->renderMenuItem($children, $xi, false, $depth + 1))])];
}));
}
开发者ID:selenia-modules,项目名称:theme-gentelella,代码行数:28,代码来源:SideBarMenu.php
示例12: posts_export
public function posts_export($atom, $post)
{
$comments = Comment::find(array("where" => array("post_id" => $post->id)), array("filter" => false));
foreach ($comments as $comment) {
$updated = $comment->updated ? $comment->updated_at : $comment->created_at;
$atom .= " <chyrp:comment>\r";
$atom .= ' <updated>' . when("c", $updated) . '</updated>' . "\r";
$atom .= ' <published>' . when("c", $comment->created_at) . '</published>' . "\r";
$atom .= ' <author chyrp:user_id="' . $comment->user_id . '">' . "\r";
$atom .= " <name>" . fix($comment->author) . "</name>\r";
if (!empty($comment->author_url)) {
$atom .= " <uri>" . fix($comment->author_url) . "</uri>\r";
}
$atom .= " <email>" . fix($comment->author_email) . "</email>\r";
$atom .= " <chyrp:login>" . fix(@$comment->user->login) . "</chyrp:login>\r";
$atom .= " <chyrp:ip>" . long2ip($comment->author_ip) . "</chyrp:ip>\r";
$atom .= " <chyrp:agent>" . fix($comment->author_agent) . "</chyrp:agent>\r";
$atom .= " </author>\r";
$atom .= " <content>" . fix($comment->body) . "</content>\r";
foreach (array("status", "signature") as $attr) {
$atom .= " <chyrp:" . $attr . ">" . fix($comment->{$attr}) . "</chyrp:" . $attr . ">\r";
}
$atom .= " </chyrp:comment>\r";
}
return $atom;
}
开发者ID:relisher,项目名称:chyrp,代码行数:26,代码来源:comments.php
示例13: describe
<?php
require 'Stack.php';
describe('Stack', function () {
Given('stack', function ($initial_contents) {
return new Stack($initial_contents);
});
context('with no items', function () {
given('initial_contents', function () {
return [];
});
when(function (Stack $stack) {
$stack->push(3);
});
then(function (Stack $stack) {
return $stack->size() === 1;
});
});
context('with one item', function () {
given('initial_contents', function () {
return ['an item'];
});
when(function (Stack $stack) {
$stack->push('another item');
});
then(function (Stack $stack) {
return $stack->size() === 2;
});
});
});
开发者ID:digitalsadhu,项目名称:given-php,代码行数:30,代码来源:test_stack.php
示例14: describe
});
});
describe('calling #reportEnd', function () {
given('errors', array());
given('labels', array());
given('results', array());
given('an instance of the tap reporter', 'reporter', new TapReporter());
context('no tests were executed', function () {
given('total', 0);
when('reporter #reportEnd is called', 'result', function ($reporter, $total, $errors, $labels, $results) {
ob_start();
$reporter->reportEnd($total, $errors, $labels, $results);
return ob_get_clean();
});
then('result should be a valid string', function ($result) {
return empty($result);
});
});
context('11 tests with no errors was executed', function () {
given('total', 11);
when('reporter #reportEnd is called', 'result', function ($reporter, $total, $errors, $labels, $results) {
ob_start();
$reporter->reportEnd($total, $errors, $labels, $results);
return ob_get_clean();
});
then('result should be a valid string', function ($result) {
return !(false === strpos($result, '1..11'));
});
});
});
});
开发者ID:digitalsadhu,项目名称:given-php,代码行数:31,代码来源:test_TapReporter.php
示例15: testCanStub
function testCanStub()
{
$mock = mock(MockMe::class);
when($mock->Foo())->return(1);
$this->assertEquals($mock->Foo(), 1);
}
开发者ID:crashuxx,项目名称:phockito,代码行数:6,代码来源:GlobalsTest.php
示例16: search
/**
* Function: search
* Returns an array of model objects that are found by the $options array.
*
* Parameters:
* $options - An array of options, mostly SQL things.
* $options_for_object - An array of options for the instantiation of the model.
*
* Options:
* select - What to grab from the table. @(modelname)s@ by default.
* from - Which table(s) to grab from? @(modelname)s.*@ by default.
* left_join - A @LEFT JOIN@ associative array. Example: @array("table" => "foo", "where" => "foo = :bar")@
* where - A string or array of conditions. @array("__(modelname)s.id = :id")@ by default.
* params - An array of parameters to pass to PDO. @array(":id" => $id)@ by default.
* group - A string or array of "GROUP BY" conditions.
* order - What to order the SQL result by. @__(modelname)s.id DESC@ by default.
* offset - Offset for SQL query.
* limit - Limit for SQL query.
*
* See Also:
* <Model.grab>
*/
protected static function search($model, $options = array(), $options_for_object = array())
{
$model_name = strtolower($model);
fallback($options["select"], "*");
fallback($options["from"], pluralize(strtolower($model)));
fallback($options["left_join"], array());
fallback($options["where"], null);
fallback($options["params"], array());
fallback($options["group"], array());
fallback($options["order"], "id DESC");
fallback($options["offset"], null);
fallback($options["limit"], null);
fallback($options["placeholders"], false);
fallback($options["ignore_dupes"], array());
$options["where"] = (array) $options["where"];
$options["from"] = (array) $options["from"];
$options["select"] = (array) $options["select"];
$trigger = Trigger::current();
$trigger->filter($options, pluralize(strtolower($model_name)) . "_get");
$grab = SQL::current()->select($options["from"], $options["select"], $options["where"], $options["order"], $options["params"], $options["limit"], $options["offset"], $options["group"], $options["left_join"])->fetchAll();
$shown_dates = array();
$results = array();
$rows = array();
foreach ($grab as $row) {
foreach ($row as $column => $val) {
$rows[$row["id"]][$column][] = $val;
}
}
foreach ($rows as &$row) {
foreach ($row as $name => &$column) {
$column = !in_array($name, $options["ignore_dupes"]) ? array_unique($column) : $column;
$column = count($column) == 1 ? $column[0] : $column;
}
}
foreach ($rows as $result) {
if ($options["placeholders"]) {
$results[] = $result;
continue;
}
$options_for_object["read_from"] = $result;
$result = new $model(null, $options_for_object);
if (isset($result->created_at)) {
$pinned = (isset($result->pinned) and $result->pinned);
$shown = in_array(when("m-d-Y", $result->created_at), $shown_dates);
$result->first_of_day = (!$pinned and !$shown and !AJAX);
if (!$pinned and !$shown) {
$shown_dates[] = when("m-d-Y", $result->created_at);
}
}
$results[] = $result;
}
return $options["placeholders"] ? array($results, $model_name) : $results;
}
开发者ID:homebru,项目名称:bandb,代码行数:75,代码来源:Model.php
示例17: name
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="dine.css?v=0.1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body id="plate">
<div id="text">
<?php
$who = name();
$where = place();
$when = when();
$duration = duration();
$email = email();
$why = reason();
$mail_text = "Who: {$who}\r\n" . "Where: {$where}\r\n" . "When: {$when}\r\n" . "Duration: {$duration} hour(s) \r\n" . "Email: {$email}\r\n" . "Reason: {$why}\r\n";
if (verify_captcha()) {
send_mail($mail_text, $email, $who);
echo "Mail sent, now you must wait for me to respond.";
} else {
echo "Captcha failed, I don't dine with robots";
}
?>
</div>
</body>
</html>
开发者ID:TabLand,项目名称:dine_me,代码行数:30,代码来源:mail_out.php
示例18: render
protected function render()
{
$prop = $this->props;
$align = $prop->align;
switch ($align) {
case 'left':
$this->attr('style', 'float:left');
break;
case 'right':
$this->attr('style', 'float:right');
break;
case 'center':
$this->attr('style', 'margin: 0 auto;display:block');
break;
}
if (exists($prop->alt)) {
$this->attr('alt', $prop->alt);
}
if (exists($prop->onClick)) {
$this->attr('onclick', $prop->onClick);
}
if (exists($prop->href)) {
$this->attr('onclick', "location='{$prop->href}'");
}
if (exists($prop->value)) {
$url = $this->contentRepo->getImageUrl($prop->value, ['w' => when(isset($prop->width), $prop->width), 'h' => when(isset($prop->height), $prop->height), 'q' => when(isset($prop->quality), $prop->quality), 'fit' => when(isset($prop->fit), $prop->fit), 'fm' => when(isset($prop->format), $prop->format), 'nc' => when(!$prop->cache, '1'), 'bg' => when(isset($prop->background), $prop->background)]);
if ($this->containerTag == 'img') {
$this->addAttrs(['src' => $url, 'width' => $prop->width, 'height' => $prop->height]);
} else {
$this->attr('style', enum(';', "background-image:url({$url})", "background-repeat:no-repeat", when(exists($prop->size) && $prop->size != 'auto', "background-size:{$prop->size}"), when($prop->position, "background-position:{$prop->position}"), when($prop->width, "width:{$prop->width}px"), when($prop->height, "height:{$prop->height}px")));
}
}
}
开发者ID:electro-modules,项目名称:matisse-components,代码行数:33,代码来源:Image.php
示例19: url
/**
* Function: url
* Returns a post's URL.
*/
public function url()
{
if ($this->no_results) {
return false;
}
$config = Config::current();
$visitor = Visitor::current();
if (!$config->clean_urls) {
return $config->url . "/?action=view&url=" . urlencode($this->url);
}
$login = strpos($config->post_url, "(author)") !== false ? $this->user->login : null;
$vals = array(when("Y", $this->created_at), when("m", $this->created_at), when("d", $this->created_at), when("H", $this->created_at), when("i", $this->created_at), when("s", $this->created_at), $this->id, urlencode($login), urlencode($this->clean), urlencode($this->url), urlencode($this->feather), urlencode(pluralize($this->feather)));
Trigger::current()->filter($vals, "url_vals", $this);
return $config->url . "/" . str_replace(array_keys(self::$url_attrs), $vals, $config->post_url);
}
开发者ID:relisher,项目名称:chyrp,代码行数:19,代码来源:Post.php
示例20: archives_list
/**
* Function: archive_list
* Generates an array of all of the archives, by month.
*
* Parameters:
* $limit - Amount of months to list
* $order_by - What to sort it by
* $order - "asc" or "desc"
*
* Returns:
* The array. Each entry as "month", "year", and "url" values, stored as an array.
*/
public function archives_list($limit = 0, $order_by = "created_at", $order = "desc")
{
if (isset($this->archives_list["{$limit},{$order_by},{$order}"])) {
return $this->archives_list["{$limit},{$order_by},{$order}"];
}
$sql = SQL::current();
$dates = $sql->select("posts", array("DISTINCT YEAR(created_at) AS year", "MONTH(created_at) AS month", "created_at AS created_at", "COUNT(id) AS posts"), array("status" => "public", Post::feathers()), $order_by . " " . strtoupper($order), array(), $limit == 0 ? null : $limit, null, array("created_at"));
$archives = array();
$grouped = array();
while ($date = $dates->fetchObject()) {
if (isset($grouped[$date->month . " " . $date->year])) {
$archives[$grouped[$date->month . " " . $date->year]]["count"]++;
} else {
$grouped[$date->month . " " . $date->year] = count($archives);
$archives[] = array("month" => $date->month, "year" => $date->year, "when" => $date->created_at, "url" => url("archive/" . when("Y/m/", $date->created_at)), "count" => $date->posts);
}
}
return $this->archives_list["{$limit},{$order_by},{$order}"] = $archives;
}
开发者ID:eadz,项目名称:chyrp,代码行数:31,代码来源:Theme.php
注:本文中的when函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论