public function testStandardLettersAreNot() { $this->assertFalse(EmojiRecognizer::isSingleEmoji('j')); $this->assertFalse(EmojiRecognizer::isSingleEmoji('US')); $this->assertFalse(EmojiRecognizer::isSingleEmoji('jp')); $this->assertFalse(EmojiRecognizer::isSingleEmoji('%gg')); $this->assertFalse(EmojiRecognizer::isSingleEmoji('%aa')); $this->assertFalse(EmojiRecognizer::isSingleEmoji('#aa')); $this->assertFalse(EmojiRecognizer::isSingleEmoji('#00')); }
/** * try to convert remote content to comment * * @param int $post_id ID of post * @param string $source Originator URL * @param string $target Target URL * @param array $content (Mf2) array of remote content * * @return bool|int false on error; insterted comment ID on success */ protected static function try_parse_remote($post_id, $source, $target, $content) { // default $c = array('comment_author' => $source, 'comment_author_url' => $source, 'comment_author_email' => '', 'comment_post_ID' => $post_id, 'comment_type' => 'webmention', 'comment_date' => date("Y-m-d H:i:s"), 'comment_date_gmt' => date("Y-m-d H:i:s"), 'comment_agent' => __CLASS__, 'comment_approved' => 0, 'comment_content' => sprintf(__('This entry was webmentioned on <a href="%s">%s</a>.'), $source, $source), 'comment_meta' => array()); // try to find the actual entry $item = false; $p_authors = $items = $comments = array(); if (isset($content['items']['properties']) && isset($content['items']['type'])) { $item = $content['items']; } elseif (is_array($content['items'])) { foreach ($content['items'] as $i) { if ('h-entry' == $i['type']) { $items[] = $i; } elseif ('h-card' == $i['type']) { $p_authors[] = $i; } elseif ('u-comment' == $i['type']) { $comments[] = $i; } } } if (!empty($items)) { $item = array_pop($items); } elseif (empty($items) && !empty($comments)) { $item = array_pop($comments); } // if the entry wasn't found, fall back to a regular mention if (!$item || empty($item)) { static::debug(' no parseable h-entry found, saving as standard mention comment', 6); static::debug(' the content was:' . json_encode($content), 7); return $c; } // otherwise start parsing // get real source if set if (isset($item['properties']['url']) && !empty($item['properties']['url'])) { $c['comment_meta']['comment_url'] = is_array($item['properties']['url']) ? array_pop($item['properties']['url']) : $item['properties']['url']; } // try to get author if (isset($item['properties']['author'])) { $a = $item['properties']['author']; } elseif (!empty($p_authors)) { $a = array_pop($p_authors); } // try to process author if ($a && isset($a['properties'])) { $a = $a['properties']; // author name if (isset($a['name']) && !empty($a['name'])) { $c['comment_author'] = $a['name']; } // avatar $try_photos = array('photo', 'avatar'); $p = false; foreach ($try_photos as $photo) { if (isset($a[$photo]) && !empty($a[$photo])) { $p = $a[$photo]; if (!empty($p)) { $c['comment_meta']['avatar'] = $p; break; } } } // author url & author email if (isset($a['url']) && !empty($a['url'])) { if (is_array($a['url'])) { $c['comment_author_url'] = array_pop($a['url']); } else { $c['comment_author_url'] = $a['url']; } $c['comment_author_email'] = static::try_get_author_email($c['comment_author_url']); } } foreach (static::mftypes() as $k => $mapped) { if (is_array($item['properties']) && isset($item['properties'][$mapped])) { $c['comment_type'] = $k; } } //process content $content = ''; if (isset($item['properties']['content']) && isset($item['properties']['content']['html'])) { $content = $item['properties']['content']['html']; } elseif (isset($item['properties']['content']) && isset($item['properties']['content']['value'])) { $content = $item['properties']['content']['value']; } // REACJI $emoji = EmojiRecognizer::isSingleEmoji($content); if ($emoji) { $c['comment_type'] = 'reacji'; } $content = apply_filters('wp_webmention_again_comment_content', $content); //$c['comment_content'] = wp_filter_kses ( $content ); //$c['comment_content'] = wp_kses_post ( $content ); //static::debug( 'before kses: ' . $content ); $allowed_tags = apply_filters('wp_webmention_again_kses_allowed_tags', array('a' => array('href' => true, 'rel' => true), 'abbr' => array(), 'acronym' => array(), 'b' => array(), 'blockquote' => array(), 'br' => array(), 'cite' => array(), 'code' => array(), 'del' => array('datetime' => true), 'dd' => array(), 'dfn' => array(), 'dl' => array(), 'dt' => array(), 'em' => array(), 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(), 'hr' => array(), 'i' => array(), 'img' => array('alt' => true, 'hspace' => true, 'longdesc' => true, 'vspace' => true, 'src' => true), 'ins' => array('datetime' => true, 'cite' => true), 'li' => array(), 'p' => array(), 'pre' => array(), 'q' => array('cite' => true), 'strike' => array(), 'strong' => array(), 'sub' => array(), 'sup' => array(), 'table' => array(), 'td' => array('colspan' => true, 'rowspan' => true), 'th' => array('colspan' => true, 'rowspan' => true), 'thead' => array(), 'tbody' => array(), 'tr' => array(), 'tt' => array(), 'u' => array(), 'ul' => array(), 'ol' => array('start' => true))); //static::debug( 'after kses: ' . $content ); $c['comment_content'] = trim(wp_kses($content, $allowed_tags)); // process date if (isset($item['properties']['modified'])) { $c['comment_date'] = date("Y-m-d H:i:s", strtotime($item['properties']['modified'])); } elseif (isset($item['properties']['published'])) { $c['comment_date'] = date("Y-m-d H:i:s", strtotime($item['properties']['published'])); } return $c; }