本文整理汇总了PHP中Text::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP Text::isEmpty方法的具体用法?PHP Text::isEmpty怎么用?PHP Text::isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Text
的用法示例。
在下文中一共展示了Text::isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addUser
function addUser($args)
{
global $dbUsers;
global $Language;
// Check if the username already exist in db.
if (Text::isEmpty($args['username'])) {
Alert::set($Language->g('username-field-is-empty'));
return false;
}
if ($dbUsers->userExists($args['username'])) {
Alert::set($Language->g('username-already-exists'));
return false;
}
// Validate password.
if ($args['password'] != $args['confirm-password'] || Text::isEmpty($args['password'])) {
Alert::set($Language->g('The password and confirmation password do not match'));
return false;
}
// Add the user.
if ($dbUsers->add($args)) {
Alert::set($Language->g('user-has-been-added-successfully'));
return true;
} else {
Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the account.');
return false;
}
}
示例2: add
public function add($args)
{
$dataForDb = array();
// This data will be saved in the database
$dataForFile = array();
// This data will be saved in the file
// Generate the database key.
$key = $this->generateKey($args['slug']);
// The user is always the one loggued.
$args['username'] = Session::get('username');
if (Text::isEmpty($args['username'])) {
return false;
}
// The current unix time stamp.
if (empty($args['unixTimeCreated'])) {
$args['unixTimeCreated'] = Date::unixTime();
}
// Verify arguments with the database fields.
foreach ($this->dbFields as $field => $options) {
if (isset($args[$field])) {
// Sanitize if will be saved on database.
if (!$options['inFile']) {
$tmpValue = Sanitize::html($args[$field]);
} else {
$tmpValue = $args[$field];
}
} else {
$tmpValue = $options['value'];
}
// Check where the field will be written, if in the file or in the database.
if ($options['inFile']) {
$dataForFile[$field] = Text::firstCharUp($field) . ': ' . $tmpValue;
} else {
// Set type
settype($tmpValue, gettype($options['value']));
// Save on database
$dataForDb[$field] = $tmpValue;
}
}
// Make the directory.
if (Filesystem::mkdir(PATH_POSTS . $key) === false) {
Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the directory ' . PATH_POSTS . $key);
return false;
}
// Make the index.txt and save the file.
$data = implode("\n", $dataForFile);
if (file_put_contents(PATH_POSTS . $key . DS . 'index.txt', $data) === false) {
Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to put the content in the file index.txt');
return false;
}
// Save the database
$this->db[$key] = $dataForDb;
if ($this->save() === false) {
Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
return false;
}
return true;
}
示例3: siteBodyEnd
public function siteBodyEnd()
{
$html = PHP_EOL . '<!-- Google Analytics -->' . PHP_EOL;
$html .= "<script>\n\t(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n\t(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n\tm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n\t})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\n\tga('create', '" . $this->getDbField('tracking-id') . "', 'auto');\n\tga('send', 'pageview');\n</script>" . PHP_EOL;
if (Text::isEmpty($this->getDbField('tracking-id'))) {
return false;
}
return $html;
}
示例4: siteBodyEnd
public function siteBodyEnd()
{
$html = PHP_EOL . '<!-- Yandex.Metrika counter -->' . PHP_EOL;
$html .= "<script type='text/javascript'>\n (function (d, w, c) {\n (w[c] = w[c] || []).push(function() {\n try {\n w.yaCounter" . $this->getDbField('yametrika-id') . " = new Ya.Metrika({\n id:" . $this->getDbField('yametrika-id') . ",\n clickmap:true,\n trackLinks:true,\n accurateTrackBounce:true\n });\n } catch(e) { }\n });\n\n var n = d.getElementsByTagName('script')[0],\n s = d.createElement('script'),\n f = function () { n.parentNode.insertBefore(s, n); };\n s.type = 'text/javascript';\n s.async = true;\n s.src = 'https://mc.yandex.ru/metrika/watch.js';\n\n if (w.opera == '[object Opera]') {\n d.addEventListener('DOMContentLoaded', f, false);\n } else { f(); }\n })(document, window, 'yandex_metrika_callbacks');\n</script>\n<noscript><div><img src='https://mc.yandex.ru/watch/" . $this->getDbField('yametrika-id') . "' style='position:absolute; left:-9999px;' alt='' /></div></noscript>" . PHP_EOL;
if (Text::isEmpty($this->getDbField('yametrika-id'))) {
return false;
}
return $html;
}
示例5: siteHead
public function siteHead()
{
$html = PHP_EOL . '<!-- Pinterest Verification -->' . PHP_EOL;
$html .= '<meta name="p:domain_verify" content="' . $this->getDbField('pinterest-verification-code') . '">' . PHP_EOL;
if (Text::isEmpty($this->getDbField('pinterest-verification-code'))) {
return false;
}
return $html;
}
示例6: setPassword
function setPassword($username, $new_password, $confirm_password)
{
global $dbUsers;
global $Language;
if ($new_password === $confirm_password && !Text::isEmpty($new_password)) {
if ($dbUsers->setPassword($username, $new_password)) {
Alert::set($Language->g('The changes have been saved'));
} else {
Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to change the user password.');
}
} else {
Alert::set($Language->g('The password and confirmation password do not match'));
return false;
}
}
示例7: render
/**
* Renders the tag
*
* @return string The HTML string
*/
public function render()
{
$html = new Text();
$html->append('<')->append($this->getName());
foreach ($this->attributes as $name => $value) {
$html->append(' ')->append($name)->append('=')->append('"')->append($value)->append('"');
}
if ($this->text->isEmpty()) {
if ($this->type == self::TYPE_BLOCK) {
return (string) $html->append('>')->append('</')->append($this->getName())->append('>');
} else {
return (string) $html->append($this->emptyTagSuffix);
}
}
return (string) $html->append('>')->append($this->text)->append('</')->append($this->getName())->append('>');
}
示例8: addUser
function addUser($args)
{
global $dbUsers;
global $Language;
// Check empty username
if (Text::isEmpty($args['new_username'])) {
Alert::set($Language->g('username-field-is-empty'), ALERT_STATUS_FAIL);
return false;
}
// Check already exist username
if ($dbUsers->userExists($args['new_username'])) {
Alert::set($Language->g('username-already-exists'), ALERT_STATUS_FAIL);
return false;
}
// Password length
if (strlen($args['new_password']) < 6) {
Alert::set($Language->g('Password must be at least 6 characters long'), ALERT_STATUS_FAIL);
return false;
}
// Check new password and confirm password are equal
if ($args['new_password'] != $args['confirm_password']) {
Alert::set($Language->g('The password and confirmation password do not match'), ALERT_STATUS_FAIL);
return false;
}
// Filter form fields
$tmp = array();
$tmp['username'] = $args['new_username'];
$tmp['password'] = $args['new_password'];
$tmp['role'] = $args['role'];
// Add the user to the database
if ($dbUsers->add($tmp)) {
Alert::set($Language->g('user-has-been-added-successfully'), ALERT_STATUS_OK);
return true;
} else {
Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the account.');
return false;
}
}
示例9: generateKey
public function generateKey($text, $parent = NO_PARENT_CHAR, $returnSlug = false, $oldKey = '')
{
if (Text::isEmpty($text)) {
$text = 'empty';
}
if (Text::isEmpty($parent) || $parent == NO_PARENT_CHAR) {
$newKey = Text::cleanUrl($text);
} else {
$newKey = Text::cleanUrl($parent) . '/' . Text::cleanUrl($text);
}
if ($newKey !== $oldKey) {
// Verify if the key is already been used.
if (isset($this->db[$newKey])) {
if (!Text::endsWithNumeric($newKey)) {
$newKey = $newKey . '-0';
}
while (isset($this->db[$newKey])) {
$newKey++;
}
}
}
if ($returnSlug) {
$explode = explode('/', $newKey);
if (isset($explode[1])) {
return $explode[1];
}
return $explode[0];
}
return $newKey;
}
示例10: add
public function add($args)
{
$dataForDb = array();
// This data will be saved in the database
$dataForFile = array();
// This data will be saved in the file
$currentDate = Date::current(DB_DATE_FORMAT);
// Generate the database key.
$key = $this->generateKey($args['slug']);
// The user is always who is loggued.
$args['username'] = Session::get('username');
if (Text::isEmpty($args['username'])) {
return false;
}
// Date
if (!Valid::date($args['date'], DB_DATE_FORMAT)) {
$args['date'] = $currentDate;
}
// Schedule post?
if ($args['date'] > $currentDate && $args['status'] == 'published') {
$args['status'] = 'scheduled';
}
// Verify arguments with the database fields.
foreach ($this->dbFields as $field => $options) {
// If the field is in the arguments.
if (isset($args[$field])) {
if ($field == 'tags') {
$tmpValue = $this->generateTags($args['tags']);
} else {
// Sanitize if will be saved on database.
if (!$options['inFile']) {
$tmpValue = Sanitize::html($args[$field]);
} else {
$tmpValue = $args[$field];
}
}
} else {
$tmpValue = $options['value'];
}
// Check where the field will be written, if in the file or in the database.
if ($options['inFile']) {
$dataForFile[$field] = Text::firstCharUp($field) . ': ' . $tmpValue;
} else {
// Set type
settype($tmpValue, gettype($options['value']));
// Save on database
$dataForDb[$field] = $tmpValue;
}
}
// Make the directory.
if (Filesystem::mkdir(PATH_POSTS . $key) === false) {
Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the directory ' . PATH_POSTS . $key);
return false;
}
// Make the index.txt and save the file.
$data = implode("\n", $dataForFile);
if (file_put_contents(PATH_POSTS . $key . DS . 'index.txt', $data) === false) {
Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to put the content in the file index.txt');
return false;
}
// Save the database
$this->db[$key] = $dataForDb;
// Sort posts before save.
$this->sortByDate();
if ($this->save() === false) {
Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
return false;
}
return $key;
}
示例11: getSlugAfterFilter
private function getSlugAfterFilter($filter)
{
// Remove both slash from the filter
$filter = trim($filter, '/');
// Add to the filter the root directory
$filter = HTML_PATH_ROOT . $filter;
// Check if the filter is in the uri.
$position = Text::stringPosition($this->uri, $filter);
// If the position is FALSE, the filter isn't in the URI.
if ($position === false) {
return false;
}
// Start position to cut
$start = $position + Text::length($filter);
// End position to cut
$end = $this->uriStrlen;
// Get the slug from the URI
$slug = Text::cut($this->uri, $start, $end);
if (Text::isEmpty($slug)) {
return '';
}
if ($slug[0] == '/') {
return ltrim($slug, '/');
}
if ($filter == HTML_PATH_ROOT) {
return $slug;
}
return false;
}
示例12: foreach
$Page = $pages[$key];
$friendlyURL = Text::isEmpty($Url->filters('page')) ? '/' . $Page->key() : '/' . $Url->filters('page') . '/' . $Page->key();
echo '<tr>';
echo '<td>';
echo '<a href="' . HTML_PATH_ADMIN_ROOT . 'edit-page/' . $Page->key() . '">' . ($Page->published() ? '' : '<span class="label-draft">' . $Language->g('Draft') . '</span> ') . ($Page->title() ? $Page->title() : '<span class="label-empty-title">' . $Language->g('Empty title') . '</span> ') . '</a>';
echo '</td>';
echo '<td class="uk-text-center">' . $Page->position() . '</td>';
echo '<td><a target="_blank" href="' . $Page->permalink() . '">' . $friendlyURL . '</a></td>';
echo '</tr>';
// If the page has children
if (isset($pagesParents[$Page->key()])) {
// Get the children
$children = $pagesParents[$Page->key()];
foreach ($children as $keyChildren => $dbChildren) {
// Parent page
$Page = $pages[$keyChildren];
$friendlyURL = Text::isEmpty($Url->filters('page')) ? '/' . $Page->key() : '/' . $Url->filters('page') . '/' . $Page->key();
echo '<tr class="children">';
echo '<td class="children">';
echo '<a href="' . HTML_PATH_ADMIN_ROOT . 'edit-page/' . $Page->key() . '">' . ($Page->published() ? '' : '<span class="label-draft">' . $Language->g('Draft') . '</span> ') . ($Page->title() ? $Page->title() : '<span class="label-empty-title">' . $Language->g('Empty title') . '</span> ') . '</a>';
echo '</td>';
echo '<td class="uk-text-center">' . $Page->position() . '</td>';
echo '<td><a target="_blank" href="' . $Page->permalink() . '">' . $friendlyURL . '</a></td>';
echo '</tr>';
}
}
}
echo '
</tbody>
</table>
';
示例13: _findExcerpt
/**
* Enter description here ...
*
* @return Text
*/
protected function _findExcerpt()
{
$config = $this->getConfig();
$excerpt = null;
$SEO_ignFilters = $config->get($config::EXCERPT_SEO_TAGS_IGNORE_FILTERS);
foreach ($config->get($config::EXCERPT_SEARCH_TAGS) as $tag) {
switch ($tag) {
case 'meta og:description':
// method: search <meta property="og:description" content="" />
// try to find a meta tag with property og:description as according to
// open graph protocol (@see http://developers.facebook.com/docs/opengraph/)
$elements = $this->_xpath->query('/html/head/meta[@property="og:description"]/@content');
foreach ($elements as $elem) {
$candidate = new Text($elem->nodeValue, true, $this->_config);
if (!$candidate->isEmpty() && ($SEO_ignFilters || $candidate->matches($this->_getFilterOpts(static::FIELD_EXCERPT)))) {
// found
$excerpt = $candidate;
break 3;
}
}
break;
case 'meta description':
// method: search <meta name="description" content="" />
$elements = $this->_xpath->query('/html/head/meta[@name="description"]/@content');
foreach ($elements as $elem) {
$candidate = new Text($elem->nodeValue, true, $this->_config);
if (!$candidate->isEmpty() && ($SEO_ignFilters || $candidate->matches($this->_getFilterOpts(static::FIELD_EXCERPT)))) {
// found
$excerpt = $candidate;
break 3;
}
}
break;
case 'article section':
// new html5 method
$elements = $this->_xpath->query('/html/body//article/section');
foreach ($elements as $elem) {
$candidate = new Text($elem->nodeValue, true, $this->_config);
if ($candidate->matches($this->_getFilterOpts(static::FIELD_EXCERPT))) {
// found
$excerpt = $candidate;
break 3;
}
}
break;
default:
// default behaviour: search "normal" tags for text
$elements = $this->_dom->getElementsByTagName($tag);
foreach ($elements as $elem) {
$candidate = new Text(Util::DOMinnerHTML($elem), true, $this->_config);
if ($candidate->matches($this->_getFilterOpts(static::FIELD_EXCERPT))) {
// found
$excerpt = $candidate;
break 3;
}
}
}
// end switch
}
// end foreach
if ($excerpt instanceof Text) {
if ($config->get($config::EXCERPT_TRUNCATE)) {
$excerpt->truncate($config->get($config::EXCERPT_TRUNCATE_LENGTH), $config->get($config::EXCERPT_TRUNCATE_TERMINATOR));
}
if ($config->get($config::EXCERPT_LINKIFY)) {
$excerpt->linkify();
}
}
$this->excerpt = $excerpt;
return $excerpt;
}
示例14: domain
public function domain()
{
// If the URL field is not set, try detect the domain.
if (Text::isEmpty($this->url())) {
if (!empty($_SERVER['HTTPS'])) {
$protocol = 'https://';
} else {
$protocol = 'http://';
}
$domain = $_SERVER['HTTP_HOST'];
return $protocol . $domain . HTML_PATH_ROOT;
}
// Parse the domain from the field URL.
$parse = parse_url($this->url());
$domain = $parse['scheme'] . "://" . $parse['host'];
return $domain;
}
示例15: foreach
<th>' . $L->g('Friendly URL') . '</th>
</tr>
</thead>
<tbody>
';
foreach ($posts as $Post) {
$status = false;
if ($Post->scheduled()) {
$status = $Language->g('Scheduled');
} elseif (!$Post->published()) {
$status = $Language->g('Draft');
}
echo '<tr>';
echo '<td><a href="' . HTML_PATH_ADMIN_ROOT . 'edit-post/' . $Post->key() . '">' . ($status ? '<span class="label-draft">' . $status . '</span>' : '') . ($Post->title() ? $Post->title() : '<span class="label-empty-title">' . $Language->g('Empty title') . '</span> ') . '</a></td>';
echo '<td class="uk-text-center">' . $Post->dateRaw() . '</td>';
$friendlyURL = Text::isEmpty($Url->filters('post')) ? '/' . $Post->key() : '/' . $Url->filters('post') . '/' . $Post->key();
echo '<td><a target="_blank" href="' . $Post->permalink() . '">' . $friendlyURL . '</a></td>';
echo '</tr>';
}
echo '
</tbody>
</table>
';
?>
<div id="paginator">
<ul>
<?php
if (Paginator::get('showNewer')) {
echo '<li class="previous"><a href="' . HTML_PATH_ADMIN_ROOT . 'manage-posts?page=' . Paginator::get('prevPage') . '">« ' . $Language->g('Prev page') . '</a></li>';
}