Skip to content
Permalink
Browse files

Register attributes too

  • Loading branch information...
bloatware committed Nov 7, 2019
1 parent b336886 commit 36ae4bba9184d82a7a5aafdd5ce96a7c230239b9
Showing with 47 additions and 141 deletions.
  1. +23 −132 textpattern/publish/taghandlers.php
  2. +24 −9 textpattern/vendors/Textpattern/Tag/Registry.php
@@ -73,10 +73,10 @@
->register('article_url_title')
->register('if_article_id')
->register('posted')
->register('expires')
->register('posted', 'modified', 'modified')
->register('posted', 'expires', 'expires')
->register('if_expires')
->register('if_expired')
->register('modified')
->register('comments_count')
->register('comments_invite')
->register('comments_form')
@@ -102,7 +102,7 @@
->register('title')
->register('excerpt')
->register('article_category', 'category1')
->register('article_category', 'category2', 2)
->register('article_category', array('category2', array('number' => 2)))
->register('category')
->register('section')
->register('keywords')
@@ -186,8 +186,9 @@
->register('txp_item', 'item')
->register('comments_help')
->register('comment_name_input')
->register('comment_email_input')
->register('comment_web_input')
->register('comment_name_input', 'comment_email_input', 'email', 'clean_url')
->register('comment_name_input', array('comment_web_input', array('placeholder' => 'http(s)://')), 'web', 'clean_url')
// ->register('comment_web_input')
->register('comment_message_input')
->register('comment_remember')
->register('comment_preview')
@@ -1926,67 +1927,13 @@ function if_article_id($atts, $thing = null)
// -------------------------------------------------------------
function posted($atts)
function posted($atts, $thing = null, $time = 'posted')
{
global $thisarticle, $id, $c, $pg, $dateformat, $archive_dateformat;
assert_article();
extract(lAtts(array(
'format' => '',
'gmt' => '',
'lang' => '',
), $atts));
if ($format) {
$out = safe_strftime($format, $thisarticle['posted'], $gmt, $lang);
} else {
if ($id || $c || $pg) {
$out = safe_strftime($archive_dateformat, $thisarticle['posted'], $gmt, $lang);
} else {
$out = safe_strftime($dateformat, $thisarticle['posted'], $gmt, $lang);
}
}
return $out;
}
// -------------------------------------------------------------
function modified($atts)
{
global $thisarticle, $id, $c, $pg, $dateformat, $archive_dateformat;
assert_article();
extract(lAtts(array(
'format' => '',
'gmt' => '',
'lang' => '',
), $atts));
if ($format) {
$out = safe_strftime($format, $thisarticle['modified'], $gmt, $lang);
} else {
if ($id || $c || $pg) {
$out = safe_strftime($archive_dateformat, $thisarticle['modified'], $gmt, $lang);
} else {
$out = safe_strftime($dateformat, $thisarticle['modified'], $gmt, $lang);
}
}
return $out;
}
// -------------------------------------------------------------
function expires($atts)
{
global $thisarticle, $id, $c, $pg, $dateformat, $archive_dateformat;
assert_article();
if ($thisarticle['expires'] == 0) {
if (empty($thisarticle[$time])) {
return '';
}
@@ -1997,12 +1944,12 @@ function expires($atts)
), $atts));
if ($format) {
$out = safe_strftime($format, $thisarticle['expires'], $gmt, $lang);
$out = safe_strftime($format, $thisarticle[$time], $gmt, $lang);
} else {
if ($id || $c || $pg) {
$out = safe_strftime($archive_dateformat, $thisarticle['expires'], $gmt, $lang);
$out = safe_strftime($archive_dateformat, $thisarticle[$time], $gmt, $lang);
} else {
$out = safe_strftime($dateformat, $thisarticle['expires'], $gmt, $lang);
$out = safe_strftime($dateformat, $thisarticle[$time], $gmt, $lang);
}
}
@@ -2206,7 +2153,7 @@ function comments_form($atts, $thing = null)
// -------------------------------------------------------------
function comment_name_input($atts)
function comment_name_input($atts, $thing = null, $field = 'name', $clean = false)
{
global $prefs, $thiscommentsform;
@@ -2216,80 +2163,24 @@ function comment_name_input($atts)
'placeholder' => '',
), $atts));
$namewarn = false;
$name = pcs('name');
$warn = false;
$val = is_callable($clean) ? $clean(pcs($field)) : pcs($field);
$h5 = ($prefs['doctype'] == 'html5');
$required = get_pref('comments_require_'.$field);
if (ps('preview')) {
$comment = getComment();
$name = $comment['name'];
$namewarn = ($prefs['comments_require_name'] && !$name);
$val = $comment[$field];
$warn = $required && !$val;
}
return fInput('text', array(
'name' => 'name',
'aria-label' => $aria_label,
'autocomplete' => 'name',
'placeholder' => $placeholder,
), $name, 'comment_name_input'.($namewarn ? ' comments_error' : ''), '', '', $size, '', 'name', false, $h5 && $prefs['comments_require_name']);
}
// -------------------------------------------------------------
function comment_email_input($atts)
{
global $prefs, $thiscommentsform;
extract(lAtts(array(
'size' => $thiscommentsform['isize'],
'aria_label' => '',
'placeholder' => '',
), $atts));
$emailwarn = false;
$email = clean_url(pcs('email'));
$h5 = ($prefs['doctype'] == 'html5');
if (ps('preview')) {
$comment = getComment();
$email = $comment['email'];
$emailwarn = ($prefs['comments_require_email'] && !$email);
}
return fInput($h5 ? 'email' : 'text', array(
'name' => 'email',
'aria-label' => $aria_label,
'autocomplete' => 'email',
'placeholder' => $placeholder,
), $email, 'comment_email_input'.($emailwarn ? ' comments_error' : ''), '', '', $size, '', 'email', false, $h5 && $prefs['comments_require_email']);
}
// -------------------------------------------------------------
function comment_web_input($atts)
{
global $prefs, $thiscommentsform;
extract(lAtts(array(
'size' => $thiscommentsform['isize'],
'aria_label' => '',
'placeholder' => 'http(s)://',
), $atts));
$web = clean_url(pcs('web'));
$h5 = ($prefs['doctype'] == 'html5');
if (ps('preview')) {
$comment = getComment();
$web = $comment['web'];
}
return fInput($h5 ? 'url' : 'text', array(
'name' => 'web',
'name' => $field,
'aria-label' => $aria_label,
'autocomplete' => 'url',
'autocomplete' => $field == 'web' ? 'url' : $field,
'placeholder' => $placeholder,
), $web, 'comment_web_input', '', '', $size, '', 'web');
'required' => $h5 && $required
), $val, 'comment_'.$field.'_input'.($warn ? ' comments_error' : ''), '', '', $size, '', $field);
}
// -------------------------------------------------------------
@@ -2952,14 +2843,14 @@ function excerpt($atts = array(), $thing = null)
// -------------------------------------------------------------
function article_category($atts, $thing = null, $number = 1)
function article_category($atts, $thing = null)
{
global $thisarticle, $s, $permlink_mode;
assert_article();
extract(lAtts(array(
'number' => $number,
'number' => 1,
'class' => '',
'link' => 0,
'title' => 0,
@@ -39,8 +39,9 @@ class Registry implements \Textpattern\Container\ReusableInterface
*/
private $tags = array();
private $params = array();
private $atts = array();
private $params = array();
private $attr = array();
/**
* Registers a tag.
@@ -62,13 +63,21 @@ public function register($callback, $tag = null)
$tag = $callback;
}
if (is_array($tag)) {
list($tag, $atts) = $tag + array(null, null);
}
if ($tag) {
$this->tags[$tag] = $callback;
$params = array_slice(func_get_args(), 2);
if (!empty($params)) {
$this->params[$tag] = $params;
}
if (isset($atts)) {
$this->atts[$tag] = (array)$atts;
}
}
}
@@ -92,14 +101,14 @@ public function registerAttr($callback, $tag = null)
// is_callable only checks syntax here to avoid autoloading
if (is_bool($callback)) {
foreach (do_list_unique($tag) as $tag) {
$this->atts[$tag] = $callback;
$this->attr[$tag] = $callback;
}
} elseif ($callback && is_callable($callback, true)) {
if ($tag === null && is_string($callback)) {
$this->atts[$callback] = $callback;
$this->attr[$callback] = $callback;
} else {
foreach (do_list_unique($tag) as $tag) {
$this->atts[$tag] = $callback;
$this->attr[$tag] = $callback;
}
}
}
@@ -119,11 +128,17 @@ public function registerAttr($callback, $tag = null)
public function process($tag, array $atts = null, $thing = null)
{
if ($this->isRegistered($tag)) {
$atts = (array)$atts;
if (isset($this->atts[$tag])) {
$atts += $this->atts[$tag];
}
//TODO: switch to args unpacking for php 5.6+
return isset($this->params[$tag]) ?
// (string) call_user_func($this->tags[$tag], (array)$atts, $thing, ...$this->params[$tag]) :
(string) call_user_func_array($this->tags[$tag], array_merge(array((array)$atts, $thing), $this->params[$tag])) :
(string) call_user_func($this->tags[$tag], (array)$atts, $thing);
(string) call_user_func_array($this->tags[$tag], array_merge(array($atts, $thing), $this->params[$tag])) :
(string) call_user_func($this->tags[$tag], $atts, $thing);
} else {
return false;
}
@@ -141,7 +156,7 @@ public function process($tag, array $atts = null, $thing = null)
public function processAttr($tag, $atts = null, $thing = null)
{
if ($this->isRegisteredAttr($tag)) {
return (string) call_user_func($this->atts[$tag], $atts, $thing);
return (string) call_user_func($this->attr[$tag], $atts, $thing);
} else {
return false;
}
@@ -168,7 +183,7 @@ public function isRegistered($tag)
public function isRegisteredAttr($tag)
{
return isset($this->atts[$tag]) && is_callable($this->atts[$tag]);
return isset($this->attr[$tag]) && is_callable($this->attr[$tag]);
}
/**
@@ -180,6 +195,6 @@ public function isRegisteredAttr($tag)
public function getRegistered($is_attr = false)
{
return $is_attr ? $this->atts : $this->tags;
return $is_attr ? $this->attr : $this->tags;
}
}

0 comments on commit 36ae4bb

Please sign in to comment.
You can’t perform that action at this time.