Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dshanske committed Feb 24, 2018
1 parent b238b1a commit 8f5b81d
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 39 deletions.
8 changes: 4 additions & 4 deletions includes/class-link-preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public static function register_routes() {
'validate_callback' => array( 'Link_Preview', 'is_valid_url' ),
'sanitize_callback' => 'esc_url_raw',
),
'kind' => array(
'sanitize_callback' => 'sanitize_key'
)
'kind' => array(
'sanitize_callback' => 'sanitize_key',
),
),
'permission_callback' => function () {
return current_user_can( 'publish_posts' );
Expand Down Expand Up @@ -125,7 +125,7 @@ private static function mergeparse( $content, $url, $kind ) {
public static function read( $request ) {
// We don't need to specifically check the nonce like with admin-ajax. It is handled by the API.
$params = $request->get_params();
$kind = ifset( $params['kind'] );
$kind = ifset( $params['kind'] );
if ( isset( $params['kindurl'] ) && ! empty( $params['kindurl'] ) ) {
return self::parse( $params['kindurl'], $kind );
}
Expand Down
18 changes: 9 additions & 9 deletions languages/post_kinds.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgstr ""
"Project-Id-Version: Post Kinds 3.0.0\n"
"Report-Msgid-Bugs-To: "
"http://wordpress.org/support/plugin/indieweb-post-kinds\n"
"POT-Creation-Date: 2018-02-23 14:35:23+00:00\n"
"POT-Creation-Date: 2018-02-24 23:00:49+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -729,15 +729,15 @@ msgid_plural " %d seconds"
msgstr[0] ""
msgstr[1] ""

#: includes/class-link-preview.php:129 includes/class-link-preview.php:189
#: includes/class-link-preview.php:133 includes/class-link-preview.php:193
msgid "Missing or Invalid URL"
msgstr ""

#: includes/class-link-preview.php:140
#: includes/class-link-preview.php:144
msgid "Missing Kind"
msgstr ""

#: includes/class-link-preview.php:147
#: includes/class-link-preview.php:151
msgid "Missing Content or KindURL"
msgstr ""

Expand Down Expand Up @@ -773,7 +773,7 @@ msgstr ""
msgid "(Multiple Entries separated by semicolon)"
msgstr ""

#: templates/reply-author.php:6 templates/reply-metabox.php:32
#: templates/reply-author.php:6 templates/reply-metabox.php:39
msgid "Author"
msgstr ""

Expand Down Expand Up @@ -813,19 +813,19 @@ msgstr ""
msgid "Featured Image"
msgstr ""

#: templates/reply-metabox.php:31
#: templates/reply-metabox.php:38
msgid "Details"
msgstr ""

#: templates/reply-metabox.php:33
#: templates/reply-metabox.php:40
msgid "Clear"
msgstr ""

#: templates/reply-metabox.php:36
#: templates/reply-metabox.php:43
msgid "URL"
msgstr ""

#: templates/reply-metabox.php:42
#: templates/reply-metabox.php:49
msgid "Name"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ The functions `has_post_kind`, `set_post_kind`, and `set_post_kind` will allow y

## Changelog ##

### 3.0.0 ( 2018-02-?? ) ###
### 3.0.0 ( 2018-02-24 ) ###
* Redo metabox into new more dynamic function
* Move metabox to default above editor
* Hide metabox when note or article is selected
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ The functions `has_post_kind`, `set_post_kind`, and `set_post_kind` will allow y

== Changelog ==

= 3.0.0 ( 2018-02-?? ) =
= 3.0.0 ( 2018-02-24 ) =
* Redo metabox into new more dynamic function
* Move metabox to default above editor
* Hide metabox when note or article is selected
Expand Down
135 changes: 111 additions & 24 deletions vendor/mf2/mf2/Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,33 @@ function convertTimeFormat($time) {
}
}

/**
* If a date value has a timezone offset, normalize it.
* @param string $dtValue
* @return string isolated, normalized TZ offset for implied TZ for other dt- properties
*/
function normalizeTimezoneOffset(&$dtValue) {
preg_match('/Z|[+-]\d{1,2}:?(\d{2})?$/i', $dtValue, $matches);

if (empty($matches)) {
return null;
}

if ( $matches[0] != 'Z' ) {
$timezoneString = str_replace(':', '', $matches[0]);
$plus_minus = substr($timezoneString, 0, 1);
$timezoneOffset = substr($timezoneString, 1);
if ( strlen($timezoneOffset) <= 2 ) {
$timezoneOffset .= '00';
}
$timezoneOffset = str_pad($timezoneOffset, 4, 0, STR_PAD_LEFT);
$timezoneOffset = $plus_minus . $timezoneOffset;
$dtValue = preg_replace('/Z?[+-]\d{1,2}:?(\d{2})?$/i', $timezoneOffset, $dtValue);
}

return $timezoneOffset;
}

function applySrcsetUrlTransformation($srcset, $transformation) {
return implode(', ', array_filter(array_map(function ($srcsetPart) use ($transformation) {
$parts = explode(" \t\n\r\0\x0B", trim($srcsetPart), 2);
Expand Down Expand Up @@ -652,9 +679,10 @@ public function parseU(\DOMElement $u) {
*
* @param DOMElement $dt The element to parse
* @param array $dates Array of dates processed so far
* @param string $impliedTimezone
* @return string The datetime string found
*/
public function parseDT(\DOMElement $dt, &$dates = array()) {
public function parseDT(\DOMElement $dt, &$dates = array(), &$impliedTimezone = null) {
// Check for value-class pattern
$valueClassChildren = $this->xpath->query('./*[contains(concat(" ", @class, " "), " value ") or contains(concat(" ", @class, " "), " value-title ")]', $dt);
$dtValue = false;
Expand All @@ -666,73 +694,96 @@ public function parseDT(\DOMElement $dt, &$dates = array()) {
foreach ($valueClassChildren as $e) {
if (strstr(' ' . $e->getAttribute('class') . ' ', ' value-title ')) {
$title = $e->getAttribute('title');
if (!empty($title))
if (!empty($title)) {
$dateParts[] = $title;
}
}
elseif ($e->tagName == 'img' or $e->tagName == 'area') {
// Use @alt
$alt = $e->getAttribute('alt');
if (!empty($alt))
if (!empty($alt)) {
$dateParts[] = $alt;
}
}
elseif ($e->tagName == 'data') {
// Use @value, otherwise innertext
$value = $e->hasAttribute('value') ? $e->getAttribute('value') : unicodeTrim($e->nodeValue);
if (!empty($value))
if (!empty($value)) {
$dateParts[] = $value;
}
}
elseif ($e->tagName == 'abbr') {
// Use @title, otherwise innertext
$title = $e->hasAttribute('title') ? $e->getAttribute('title') : unicodeTrim($e->nodeValue);
if (!empty($title))
if (!empty($title)) {
$dateParts[] = $title;
}
}
elseif ($e->tagName == 'del' or $e->tagName == 'ins' or $e->tagName == 'time') {
// Use @datetime if available, otherwise innertext
$dtAttr = ($e->hasAttribute('datetime')) ? $e->getAttribute('datetime') : unicodeTrim($e->nodeValue);
if (!empty($dtAttr))
if (!empty($dtAttr)) {
$dateParts[] = $dtAttr;
}
}
else {
if (!empty($e->nodeValue))
if (!empty($e->nodeValue)) {
$dateParts[] = unicodeTrim($e->nodeValue);
}
}
}

// Look through dateParts
$datePart = '';
$timePart = '';
$timezonePart = '';
foreach ($dateParts as $part) {
// Is this part a full ISO8601 datetime?
if (preg_match('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?(?:Z?[+|-]\d{2}:?\d{2})?$/', $part)) {
if (preg_match('/^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}(:\d{2})?(Z|[+-]\d{2}:?\d{2})?$/', $part)) {
// Break completely, we’ve got our value.
$dtValue = $part;
break;
} else {
// Is the current part a valid time(+TZ?) AND no other time representation has been found?
if ((preg_match('/\d{1,2}:\d{1,2}(Z?[+|-]\d{2}:?\d{2})?/', $part) or preg_match('/\d{1,2}[a|p]m/', $part)) and empty($timePart)) {
if ((preg_match('/^\d{1,2}:\d{2}(:\d{2})?(Z|[+-]\d{1,2}:?\d{2})?$/', $part) or preg_match('/^\d{1,2}(:\d{2})?(:\d{2})?[ap]\.?m\.?$/i', $part)) and empty($timePart)) {
$timePart = $part;
} elseif (preg_match('/\d{4}-\d{2}-\d{2}/', $part) and empty($datePart)) {

$timezoneOffset = normalizeTimezoneOffset($timePart);
if (!$impliedTimezone && $timezoneOffset) {
$impliedTimezone = $timezoneOffset;
}
} elseif (preg_match('/^\d{4}-\d{2}-\d{2}$/', $part) and empty($datePart)) {
// Is the current part a valid date AND no other date representation has been found?
$datePart = $part;
} elseif (preg_match('/^(Z|[+-]\d{1,2}:?(\d{2})?)$/', $part) and empty($timezonePart)) {
$timezonePart = $part;

$timezoneOffset = normalizeTimezoneOffset($timezonePart);
if (!$impliedTimezone && $timezoneOffset) {
$impliedTimezone = $timezoneOffset;
}
}

if ( !empty($datePart) && !in_array($datePart, $dates) ) {
$dates[] = $datePart;
}

if (!empty($timezonePart) && !empty($timePart)) {
$timePart .= $timezonePart;
}

$dtValue = '';

if ( empty($datePart) && !empty($timePart) ) {
$timePart = convertTimeFormat($timePart);
$dtValue = unicodeTrim($timePart, 'T');
$dtValue = unicodeTrim($timePart);
}
else if ( !empty($datePart) && empty($timePart) ) {
$dtValue = rtrim($datePart, 'T');
}
else {
$timePart = convertTimeFormat($timePart);
$dtValue = rtrim($datePart, 'T') . 'T' . unicodeTrim($timePart, 'T');
$dtValue = rtrim($datePart, 'T') . ' ' . unicodeTrim($timePart);
}
}
}
Expand All @@ -742,36 +793,54 @@ public function parseDT(\DOMElement $dt, &$dates = array()) {
// Use @alt
// Is it an entire dt?
$alt = $dt->getAttribute('alt');
if (!empty($alt))
if (!empty($alt)) {
$dtValue = $alt;
}
} elseif (in_array($dt->tagName, array('data'))) {
// Use @value, otherwise innertext
// Is it an entire dt?
$value = $dt->getAttribute('value');
if (!empty($value))
if (!empty($value)) {
$dtValue = $value;
else
}
else {
$dtValue = $this->textContent($dt);
}
} elseif ($dt->tagName == 'abbr') {
// Use @title, otherwise innertext
// Is it an entire dt?
$title = $dt->getAttribute('title');
if (!empty($title))
if (!empty($title)) {
$dtValue = $title;
else
}
else {
$dtValue = $this->textContent($dt);
}
} elseif ($dt->tagName == 'del' or $dt->tagName == 'ins' or $dt->tagName == 'time') {
// Use @datetime if available, otherwise innertext
// Is it an entire dt?
$dtAttr = $dt->getAttribute('datetime');
if (!empty($dtAttr))
if (!empty($dtAttr)) {
$dtValue = $dtAttr;
else
}
else {
$dtValue = $this->textContent($dt);
}

} else {
$dtValue = $this->textContent($dt);
}

// if the dtValue is not just YYYY-MM-DD, normalize the timezone offset
if (!preg_match('/^(\d{4}-\d{2}-\d{2})$/', $dtValue)) {
$timezoneOffset = normalizeTimezoneOffset($dtValue);
if (!$impliedTimezone && $timezoneOffset) {
$impliedTimezone = $timezoneOffset;
}
}

$dtValue = unicodeTrim($dtValue);

if (preg_match('/(\d{4}-\d{2}-\d{2})/', $dtValue, $matches)) {
$dates[] = $matches[0];
}
Expand All @@ -781,9 +850,14 @@ public function parseDT(\DOMElement $dt, &$dates = array()) {
* if $dtValue is only a time and there are recently parsed dates,
* form the full date-time using the most recently parsed dt- value
*/
if ((preg_match('/^\d{1,2}:\d{1,2}(Z?[+|-]\d{2}:?\d{2})?/', $dtValue) or preg_match('/^\d{1,2}[a|p]m/', $dtValue)) && !empty($dates)) {
if ((preg_match('/^\d{1,2}:\d{2}(:\d{2})?(Z|[+-]\d{2}:?\d{2}?)?$/', $dtValue) or preg_match('/^\d{1,2}(:\d{2})?(:\d{2})?[ap]\.?m\.?$/i', $dtValue)) && !empty($dates)) {
$timezoneOffset = normalizeTimezoneOffset($dtValue);
if (!$impliedTimezone && $timezoneOffset) {
$impliedTimezone = $timezoneOffset;
}

$dtValue = convertTimeFormat($dtValue);
$dtValue = end($dates) . 'T' . unicodeTrim($dtValue, 'T');
$dtValue = end($dates) . ' ' . unicodeTrim($dtValue);
}

return $dtValue;
Expand Down Expand Up @@ -857,6 +931,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
$return = array();
$children = array();
$dates = array();
$impliedTimezone = null;

// each rel-bookmark with an href attribute
foreach ( $this->xpath->query('.//a[contains(concat(" ",normalize-space(@rel)," ")," bookmark ") and @href]', $e) as $el )
Expand Down Expand Up @@ -956,25 +1031,37 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
$this->elementPrefixParsed($u, 'u');
}

$temp_dates = array();

// Handle dt-*
foreach ($this->xpath->query('.//*[contains(concat(" ", @class), " dt-")]', $e) as $dt) {
if ($this->isElementParsed($dt, 'dt')) {
continue;
}

$dtValue = $this->parseDT($dt, $dates);
$dtValue = $this->parseDT($dt, $dates, $impliedTimezone);

if ($dtValue) {
// Add the value to the array for dt- properties
foreach (mfNamesFromElement($dt, 'dt-') as $propName) {
$return[$propName][] = $dtValue;
$temp_dates[$propName][] = $dtValue;
}
}

// Make sure this sub-mf won’t get parsed as a top level mf
$this->elementPrefixParsed($dt, 'dt');
}

foreach ($temp_dates as $propName => $data) {
foreach ( $data as $dtValue ) {
// var_dump(preg_match('/[+-]\d{2}(\d{2})?$/i', $dtValue));
if ( $impliedTimezone && preg_match('/[+-]\d{2}(\d{2})?$/i', $dtValue, $matches) == 0 ) {
$dtValue .= $impliedTimezone;
}

$return[$propName][] = $dtValue;
}
}

// Handle e-*
foreach ($this->xpath->query('.//*[contains(concat(" ", @class)," e-")]', $e) as $em) {
if ($this->isElementParsed($em, 'e')) {
Expand Down

0 comments on commit 8f5b81d

Please sign in to comment.