本文整理汇总了PHP中Idno\Core\Webmention类的典型用法代码示例。如果您正苦于以下问题:PHP Webmention类的具体用法?PHP Webmention怎么用?PHP Webmention使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Webmention类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: saveDataFromInput
function saveDataFromInput()
{
$page = Idno::site()->currentPage();
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$this->likeof = $page->getInput('like-of');
if ($this->likeof) {
foreach ((array) $this->likeof as $likeofurl) {
$this->syndicatedto = Webmention::addSyndicatedReplyTargets($likeofurl, $this->syndicatedto);
}
}
$this->description = $page->getInput('description');
if (empty($this->description)) {
$result = \IdnoPlugins\Reactions\Pages\Fetch::fetch($this->likeof);
if (!empty($result['description'])) {
$this->description = $result['description'];
}
}
$this->setAccess($page->getInput('access'));
Idno::site()->logging()->log("saving like. new: {$new}");
if ($this->publish($new)) {
Idno::site()->logging()->log("sending webmentions from {$this->getURL()} to {$this->likeof}");
Webmention::sendWebmentionPayload($this->getURL(), $this->likeof);
}
return true;
}
开发者ID:kylewm,项目名称:KnownReactions,代码行数:29,代码来源:Like.php
示例2: testAddSyndicatedReplyTargets
function testAddSyndicatedReplyTargets()
{
// test u-syndication
$doc = <<<EOD
<div class="h-entry">
<span class="p-name e-content">This is a post</span>
<a class="u-url" href="http://foo.bar/post">permalink</a>
<a class="u-syndication" href="https://twitter.com/foobar/12345">on Twitter</a>
<a class="u-syndication" href="https://www.facebook.com/foobar/posts/12345">on Facebook</a>
</div>
EOD;
$result = Webmention::addSyndicatedReplyTargets('http://foo.bar/post', [], ['response' => 200, 'content' => $doc]);
$this->assertEquals(['https://twitter.com/foobar/12345', 'https://www.facebook.com/foobar/posts/12345'], $result);
// test rel-syndication
$doc = <<<EOD
<head>
<link rel="syndication" href="https://twitter.com/foobar/12345" />
<link rel="syndication" href="https://www.facebook.com/foobar/posts/12345" />
</head>
<body>
<div class="h-entry">
<span class="p-name e-content">This is a post</span>
<a class="u-url" href="http://foo.bar/post">permalink</a>
</div>
</body>
EOD;
$result = Webmention::addSyndicatedReplyTargets('http://foo.bar/post', [], ['response' => 200, 'content' => $doc]);
$this->assertEquals(['https://twitter.com/foobar/12345', 'https://www.facebook.com/foobar/posts/12345'], $result);
}
开发者ID:smartboyathome,项目名称:Known,代码行数:29,代码来源:WebmentionTest.php
示例3: saveDataFromInput
function saveDataFromInput()
{
$page = Idno::site()->currentPage();
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$this->repostof = $page->getInput('repost-of');
if ($this->repostof) {
foreach ((array) $this->repostof as $repostofurl) {
$this->syndicatedto = Webmention::addSyndicatedReplyTargets($repostofurl, $this->syndicatedto);
}
}
$this->description = $page->getInput('description');
$this->body = $page->getInput('body');
if (empty($this->description) && empty($this->body)) {
$result = \IdnoPlugins\Reactions\Pages\Fetch::fetch($this->repostof);
if (isset($result['description'])) {
$this->description = $result['description'];
}
if (isset($result['content'])) {
$this->body = $result['content'];
}
}
$this->setAccess($page->getInput('access'));
if ($this->publish($new)) {
Webmention::sendWebmentionPayload($this->getURL(), $this->repostof);
}
return true;
}
开发者ID:kylewm,项目名称:KnownReactions,代码行数:31,代码来源:Repost.php
示例4: postContent
function postContent()
{
$body = strip_tags($this->getInput('body'));
$name = strip_tags($this->getInput('name'));
$url = trim($this->getInput('url'));
$url2 = trim($this->getInput('url-2'));
$validator = $this->getInput('validator');
if (!empty($url2)) {
$this->deniedContent();
}
$this->referrerGatekeeper();
if (!empty($body) && !empty($name) && !empty($validator)) {
if ($object = Entity::getByUUID($validator)) {
if ($url = Webservice::sanitizeURL($url)) {
if ($content = Webservice::get($url)) {
if ($content['response'] == '200') {
$icon = Webmention::getIconFromWebsiteContent($content['content'], $url);
}
}
}
if (empty($icon)) {
$bn = hexdec(substr(md5($url), 0, 15));
$number = 1 + $bn % 5;
$icon = \Idno\Core\site()->config()->url . 'gfx/users/default-' . str_pad($number, 2, '0', STR_PAD_LEFT) . '.png';
}
$object->addAnnotation('reply', $name, $url, $icon, $body);
$this->forward($object->getDisplayURL());
}
}
}
开发者ID:emory,项目名称:Known,代码行数:30,代码来源:Post.php
示例5: saveDataFromInput
/**
* Saves changes to this object based on user input
* @return bool
*/
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$this->title = \Idno\Core\site()->currentPage()->getInput('title');
$this->body = \Idno\Core\site()->currentPage()->getInput('body');
$this->setAccess('PUBLIC');
// Get photo
if ($new) {
if (!empty($_FILES['photo']['tmp_name'])) {
if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name'])) {
if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true)) {
$this->attachFile($photo);
if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'])) {
$this->thumbnail = \Idno\Core\site()->config()->url . 'file/' . $thumbnail;
$this->thumbnail_id = substr($thumbnail, 0, strpos($thumbnail, '/'));
}
} else {
\Idno\Core\site()->session()->addMessage('Image wasn\'t attached.');
}
} else {
\Idno\Core\site()->session()->addMessage('This doesn\'t seem to be an image ..');
}
} else {
\Idno\Core\site()->session()->addMessage('We couldn\'t access your image. Please try again.');
return false;
}
}
if ($this->save()) {
if ($new) {
$this->addToFeed();
}
// Add it to the Activity Streams feed
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getDescription()));
\Idno\Core\site()->session()->addMessage('Your photo was successfully saved.');
return true;
} else {
return false;
}
}
开发者ID:phpsource,项目名称:idno,代码行数:47,代码来源:Photo.php
示例6: post
function post()
{
parse_str(trim(file_get_contents("php://input")), $vars);
// Check that both source and target are non-empty
if (!empty($vars['source']) && !empty($vars['target']) && $vars['source'] != $vars['target']) {
$source = urldecode($vars['source']);
$target = urldecode($vars['target']);
// Get the page handler for target
if ($page = \Idno\Core\site()->getPageHandler($target)) {
// Check that source exists, parse it for mf2 content,
// and ensure that it genuinely mentions this page
if ($source_content = \Idno\Core\Webmention::getPageContent($source)) {
if (substr_count($source_content['content'], $target) || $source_content['response'] == 410) {
$source_mf2 = \Idno\Core\Webmention::parseContent($source_content['content']);
// Set source and target information as input variables
$page->setPermalink();
if ($page->webmentionContent($source, $target, $source_content, $source_mf2)) {
$this->setResponse(202);
// Webmention received a-ok.
exit;
} else {
$error = 'target_not_supported';
$error_text = 'This is not webmentionable.';
}
} else {
$error = 'no_link_found';
$error_text = 'The source URI does not contain a link to the target URI.';
error_log('No link from ' . $source . ' to ' . $target);
}
} else {
$error = 'source_not_found';
$error_text = 'The source content could not be obtained.';
error_log('No content from ' . $source);
}
} else {
$error = 'target_not_found';
$error_text = 'The target page does not exist.';
}
}
$this->setResponse(400);
// Webmention failed.
echo json_encode(['error' => $error, 'error_text' => $error_text]);
}
开发者ID:phpsource,项目名称:idno,代码行数:43,代码来源:Endpoint.php
示例7: getContent
function getContent()
{
if (!\Idno\Core\site()->session()->isLoggedIn()) {
$this->setResponse(401);
$this->forward('/session/login');
}
$url = $this->getInput('share_url');
$title = $this->getInput('share_title');
$share_type = 'note';
if ($content = \Idno\Core\Webmention::getPageContent($url)) {
if ($mf2 = \Idno\Core\Webmention::parseContent($content['content'])) {
if (substr_count($content['content'], 'h-entry') == 1) {
$share_type = 'reply';
if (substr_count($content['content'], 'h-event') == 1) {
$share_type = 'rsvp';
}
}
}
}
$content_type = \Idno\Common\ContentType::getRegisteredForIndieWebPostType($share_type);
if (!empty($content_type)) {
if ($page = \Idno\Core\site()->getPageHandler('/' . $content_type->camelCase($content_type->getEntityClassName()) . '/edit')) {
if ($share_type == 'note' && !substr_count($url, 'twitter.com')) {
$page->setInput('body', $title . ' ' . $url);
} else {
$page->setInput('url', $url);
if (substr_count($url, 'twitter.com')) {
preg_match("|https?://(www\\.)?twitter\\.com/(#!/)?@?([^/]*)|", $url, $matches);
if (!empty($matches[3])) {
$page->setInput('body', '@' . $matches[3] . ' ');
}
}
}
$page->setInput('hidenav', true);
$page->get();
}
} else {
$t = \Idno\Core\site()->template();
$body = $t->__(['share_type' => $share_type, 'content_type' => $content_type])->draw('firefox/share');
$t->__(['title' => 'Share', 'body' => $body, 'hidenav' => true])->drawPage();
}
}
开发者ID:phpsource,项目名称:idno,代码行数:42,代码来源:Share.php
示例8: saveDataFromInput
/**
* Saves changes to this object based on user input
* @return bool
*/
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$this->title = \Idno\Core\site()->currentPage()->getInput('title');
$this->body = \Idno\Core\site()->currentPage()->getInput('body');
$this->setAccess('PUBLIC');
// Get video
if ($new) {
if (!empty($_FILES['video']['tmp_name'])) {
if (true) {
if ($video = \Idno\Entities\File::createFromFile($_FILES['video']['tmp_name'], $_FILES['video']['name'], $_FILES['video']['type'], true)) {
$this->attachFile($video);
} else {
\Idno\Core\site()->session()->addMessage('Video wasn\'t attached.');
}
} else {
\Idno\Core\site()->session()->addMessage('This doesn\'t seem to be a video ..');
}
} else {
\Idno\Core\site()->session()->addMessage('We couldn\'t access your video. Please try again.');
return false;
}
}
if ($this->save()) {
if ($new) {
$this->addToFeed();
}
// Add it to the Activity Streams feed
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getDescription()));
\Idno\Core\site()->session()->addMessage('Your video was successfully saved.');
return true;
} else {
return false;
}
}
开发者ID:phpsource,项目名称:idno,代码行数:43,代码来源:Video.php
示例9: deleteData
function deleteData()
{
if ($this->getAccess() == 'PUBLIC') {
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getDescription()));
}
}
开发者ID:smartboyathome,项目名称:Known,代码行数:6,代码来源:Event.php
示例10: saveDataFromInput
/**
* Saves changes to this object based on user input
* @return bool
*/
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
if ($new) {
if (!\Idno\Core\Idno::site()->triggerEvent("file/upload", [], true)) {
return false;
}
}
$this->title = \Idno\Core\Idno::site()->currentPage()->getInput('title');
$this->body = \Idno\Core\Idno::site()->currentPage()->getInput('body');
$this->tags = \Idno\Core\Idno::site()->currentPage()->getInput('tags');
$access = \Idno\Core\Idno::site()->currentPage()->getInput('access');
$this->setAccess($access);
if ($time = \Idno\Core\Idno::site()->currentPage()->getInput('created')) {
if ($time = strtotime($time)) {
$this->created = $time;
}
}
// Get photo
if ($new) {
if (!empty($_FILES['photo']['tmp_name'])) {
if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name']) || \Idno\Entities\File::isSVG($_FILES['photo']['tmp_name'], $_FILES['photo']['name'])) {
// Extract exif data so we can rotate
if (is_callable('exif_read_data') && $_FILES['photo']['type'] == 'image/jpeg') {
try {
if (function_exists('exif_read_data')) {
if ($exif = exif_read_data($_FILES['photo']['tmp_name'])) {
$this->exif = base64_encode(serialize($exif));
// Yes, this is rough, but exif contains binary data that can not be saved in mongo
}
}
} catch (\Exception $e) {
$exif = false;
}
} else {
$exif = false;
}
if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true, true)) {
$this->attachFile($photo);
// Now get some smaller thumbnails, with the option to override sizes
$sizes = \Idno\Core\Idno::site()->events()->dispatch('photo/thumbnail/getsizes', new \Idno\Core\Event(array('sizes' => array('large' => 800, 'medium' => 400, 'small' => 200))));
$eventdata = $sizes->data();
foreach ($eventdata['sizes'] as $label => $size) {
$filename = $_FILES['photo']['name'];
// Experiment: let's not save thumbnails for GIFs, in order to enable animated GIF posting.
if ($_FILES['photo']['type'] != 'image/gif') {
if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], "{$filename}_{$label}", $size, false)) {
$varname = "thumbnail_{$label}";
$this->{$varname} = \Idno\Core\Idno::site()->config()->url . 'file/' . $thumbnail;
$varname = "thumbnail_{$label}_id";
$this->{$varname} = substr($thumbnail, 0, strpos($thumbnail, '/'));
}
}
}
} else {
\Idno\Core\Idno::site()->session()->addErrorMessage('Image wasn\'t attached.');
}
} else {
\Idno\Core\Idno::site()->session()->addErrorMessage('This doesn\'t seem to be an image ..');
}
} else {
\Idno\Core\Idno::site()->session()->addErrorMessage('We couldn\'t access your image. Please try again.');
return false;
}
}
if ($this->save($new)) {
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription()));
return true;
} else {
return false;
}
}
开发者ID:jirkadus,项目名称:Known,代码行数:80,代码来源:Photo.php
示例11: deleteData
function deleteData()
{
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription()));
}
开发者ID:jirkadus,项目名称:Known,代码行数:4,代码来源:Checkin.php
示例12: getFeedDetails
/**
* Given the URL of a website, returns a single linked array containing the URL and title of a feed
* (whether Microformats or RSS / Atom). The function will attempt to discover RSS and Atom feeds in
* the page if this is an HTML site. Returns false if there is no feed.
* @param $url
* @return array|false
*/
function getFeedDetails($url)
{
if (!filter_var($url, FILTER_VALIDATE_URL)) {
return false;
}
$client = new Webservice();
if ($result = $client->get($url)) {
$feed = array();
if (!empty($result['content'])) {
$feed['webmention'] = Webmention::supportsMentions($url, $result['content']);
if ($html = @\DOMDocument::loadHTML($result['content'])) {
$xpath = new \DOMXpath($html);
$title = $xpath->query('//title')->item(0)->nodeValue;
if ($xpath->query("//*[contains(concat(' ', @class, ' '), ' h-entry ')]")->length > 0) {
$feed['type'] = 'mf2';
$feed['url'] = $url;
if (!empty($title)) {
$feed['title'] = $title;
}
return $feed;
}
if ($rss_url = $this->findXMLFeedURL($html)) {
$feed['type'] = 'xml';
$feed['url'] = $rss_url;
if (!empty($title)) {
$feed['title'] = $title;
}
return $feed;
}
}
if ($xml = @simplexml_load_string($result['content'])) {
if (!empty($xml->rss->channel->item) || !empty($xml->feed) || !empty($xml->channel->item)) {
$feed['type'] = 'xml';
$feed['url'] = $url;
if (!empty($xml->rss->channel->title)) {
$feed['title'] = $xml->rss->channel->title;
} else {
if (!empty($xml->channel->title)) {
$feed['title'] = $xml->channel->title;
} else {
if (!empty($xml->title)) {
$feed['title'] = $xml->title;
}
}
}
return $feed;
}
}
}
}
return false;
}
开发者ID:sintoris,项目名称:Known,代码行数:59,代码来源:Reader.php
示例13: getActionTypeFromHTML
/**
* Given content, returns the type of action you can respond with
* @param $content
* @return string
*/
static function getActionTypeFromHTML($content)
{
$share_type = 'comment';
if ($mf2 = \Idno\Core\Webmention::parseContent($content['content'])) {
if (!empty($mf2['items'])) {
foreach ($mf2['items'] as $item) {
if (!empty($item['type'])) {
if (in_array('h-entry', $item['type'])) {
$share_type = 'reply';
}
if (in_array('h-event', $item['type'])) {
$share_type = 'rsvp';
}
}
}
}
}
return $share_type;
}
开发者ID:d6-9b,项目名称:Known,代码行数:24,代码来源:Webmention.php
示例14: getContent
function getContent()
{
$this->gatekeeper();
$url = $this->getInput('share_url');
$title = $this->getInput('share_title');
$type = $this->getInput('share_type');
// Provide a hook to a URL shortener (TODO: Tidy this up when #237 is merged)
$event = new \Idno\Core\Event();
$event->setResponse($url);
\Idno\Core\site()->events()->dispatch('url/shorten', $event);
$url = $event->response();
if (!in_array($type, ['note', 'reply', 'rsvp', 'like'])) {
$share_type = 'note';
if ($content = \Idno\Core\Webservice::get($url)) {
if ($mf2 = \Idno\Core\Webmention::parseContent($content['content'])) {
if (!empty($mf2['items'])) {
foreach ($mf2['items'] as $item) {
if (!empty($item['type'])) {
if (in_array('h-entry', $item['type'])) {
$share_type = 'reply';
}
if (in_array('h-event', $item['type'])) {
$share_type = 'rsvp';
}
}
}
}
}
}
} else {
$share_type = $type;
}
$content_type = \Idno\Common\ContentType::getRegisteredForIndieWebPostType($share_type);
$hide_nav = false;
if ($this->getInput('via') == 'ff_social') {
$hide_nav = true;
}
if (!empty($content_type)) {
if ($page = \Idno\Core\site()->getPageHandler('/' . $content_type->camelCase($content_type->getEntityClassName()) . '/edit')) {
if ($share_type == 'note') {
$page->setInput('body', $title . ' ' . $url);
} else {
$page->setInput('url', $url);
if (substr_count($url, 'twitter.com')) {
preg_match("|https?://(www\\.)?twitter\\.com/(#!/)?@?([^/]*)|", $url, $matches);
if (!empty($matches[3])) {
$page->setInput('body', '@' . $matches[3] . ' ');
}
}
}
$page->setInput('hidenav', $hide_nav);
$page->setInput('sharing', true);
$page->setInput('share_type', $share_type);
$page->get();
}
} else {
$t = \Idno\Core\site()->template();
$body = $t->__(['share_type' => $share_type, 'content_type' => $content_type, 'sharing' => true])->draw('entity/share');
$t->__(['title' => 'Share', 'body' => $body, 'hidenav' => $hide_nav])->drawPage();
}
}
开发者ID:avewrigley,项目名称:idno,代码行数:61,代码来源:Share.php
示例15: post
function post()
{
parse_str(trim(file_get_contents("php://input")), $vars);
// Check that both source and target are non-empty
if (!empty($vars['source']) && !empty($vars['target']) && $vars['source'] != $vars['target']) {
$source = $vars['source'];
$target = $vars['target'];
// Remove anchors from target URL, but save them to '#' input so we can still reference them later
if (strpos($target, '#')) {
list($target, $fragment) = explode('#', $target, 2);
if (!empty($fragment)) {
$this->setInput('#', $fragment);
}
}
// Get the page handler for target
if ($page = \Idno\Core\Idno::site()->getPageHandler($target)) {
// First of all, make sure the target page isn't the source page. Let's not webmention ourselves!
$webmention_ok = true;
if (\Idno\Common\Entity::isLocalUUID($source)) {
if ($source_page = \Idno\Core\Idno::site()->getPageHandler($source)) {
if ($source_page == $page) {
$webmention_ok = false;
}
}
}
// Check that source exists, parse it for mf2 content,
// and ensure that it genuinely mentions this page
if ($webmention_ok) {
if ($source_content = \Idno\Core\Webservice::get($source)) {
if (substr_count($source_content['content'], $target) || $source_content['response'] == 410) {
$source_mf2 = \Idno\Core\Webmention::parseContent($source_content['content'], $source);
// Set source and target information as input variables
$page->setPermalink();
if ($page->webmentionContent($source, $target, $source_content, $source_mf2)) {
$this->setResponse(202);
// Webmention received a-ok.
exit;
} else {
$error = 'target_not_supported';
$error_text = 'This is not webmentionable.';
}
} else {
$error = 'no_link_found';
$error_text = 'The source URI does not contain a link to the target URI.';
\Idno\Core\Idno::site()->logging->warning('No link from ' . $source . ' to ' . $target);
}
} else {
$error = 'source_not_found';
$error_text = 'The source content for ' . $source . ' could not be obtained.';
\Idno\Core\Idno::site()->logging->warning('No content from ' . $source);
}
} else {
$error = 'target_not_supported';
$error_text = 'A page can\'t webmention itself.';
}
} else {
$error = 'target_not_found';
$error_text = 'The target page ' . $target . ' does not exist.';
\Idno\Core\Idno::site()->logging()->error('Could not find handler for ' . $target);
}
}
$this->setResponse(400);
// Webmention failed.
if (empty($error)) {
$error = 'unknown_error';
$error_text = 'Not all the required webmention variables were set.';
}
echo json_encode(array('error' => $error, 'error_text' => $error_text));
}
开发者ID:knownunknowns,项目名称:Known,代码行数:69,代码来源:Endpoint.php
示例16: webmentionContent
/**
* A webmention to our profile page means someone mentioned us.
*/
function webmentionContent($source, $target, $source_response, $source_mf2)
{
Idno::site()->logging()->info("received user mention from {$source} to {$target}");
if (empty($this->arguments)) {
Idno::site()->logging()->debug("could not process user mention, no pagehandler arguments");
return false;
}
$user = User::getByHandle($this->arguments[0]);
if (empty($user)) {
Idno::site()->logging()->debug('could not process user mention, no user for handle ' . $this->arguments[0]);
return false;
}
Idno::site()->logging()->debug("found target user {$user->getHandle()}");
// if this is anything other than a normal mention (e.g. a delete), accept the wm, but do nothing
if ($source_response['response'] !== 200) {
return true;
}
$title = Webmention::getTitleFromContent($source_response['content'], $source);
$mention = ['permalink' => $source, 'title' => $title];
// look for the first and only h-entry or h-event on the page
$entry = Webmention::findRepresentativeHEntry($source_mf2, $source, ['h-entry', 'h-event']);
$card = Webmention::findAuthorHCard($source_mf2, $source, $entry);
// try to get some more specific details of the mention from mf2 content
if ($entry) {
if (!empty($entry['properties']['url'])) {
$mention['permalink'] = $entry['properties']['url'][0];
}
if (!empty($entry['properties']['content'])) {
$content = $entry['properties']['content'][0];
$mention['content'] = Idno::site()->template()->sanitize_html(is_array($content) ? $content['html'] : $content);
}
}
$sender_url = false;
if ($card) {
if (!empty($card['properties']['url'])) {
$sender_url = $card['properties']['url'][0];
$mention['owner_url'] = $card['properties']['url'][0];
}
if (!empty($card['properties']['name'])) {
$mention['owner_name'] = $card['properties']['name'][0];
}
}
$message = 'You were mentioned';
if (isset($mention['owner_name'])) {
$message .= ' by ' . $mention['owner_name'];
}
$message .= ' on ' . parse_url($mention['permalink'], PHP_URL_HOST);
$notif = new Notification();
if ($notif->setNotificationKey(['mention', $user->getUUID(), $source, $target])) {
$notif->setOwner($user);
$notif->setMessage($message);
$notif->setMessageTemplate('content/notification/mention');
$notif->setActor($sender_url);
$notif->setVerb('mention');
$notif->setObject($mention);
$notif->setTarget($user);
$notif->save();
$user->notify($notif);
} else {
\Idno\Core\Idno::site()->logging()->debug("ignoring duplicate notification", ['source' => $source, 'target' => $target, 'user' => $user->getHandle()]);
}
return true;
}
开发者ID:smartboyathome,项目名称:Known,代码行数:66,代码来源:View.php
示例17: saveDataFromInput
/**
* Saves changes to this object based on user input
* @return bool
*/
function saveDataFromInput()
{
if (empty($this->_id)) {
$new = true;
} else {
$new = false;
}
$this->title = \Idno\Core\site()->currentPage()->getInput('title');
$this->body = \Idno\Core\site()->currentPage()->getInput('body');
$this->tags = \Idno\Core\site()->currentPage()->getInput('tags');
$this->setAccess('PUBLIC');
if ($time = \Idno\Core\site()->currentPage()->getInput('created')) {
if ($time = strtotime($time)) {
$this->created = $time;
}
}
// Get photo
if ($new) {
if (!empty($_FILES['photo']['tmp_name'])) {
if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name'])) {
if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true)) {
$this->attachFile($photo);
// Now get some smaller thumbnails, with the option to override sizes
$sizes = \Idno\Core\site()->events()->dispatch('photo/thumbnail/getsizes', new \Idno\Core\Event(array('sizes' => ['large' => 800, 'medium' => 400, 'small' => 200])));
foreach ($sizes->data()['sizes'] as $label => $size) {
$filename = $_FILES['photo']['name'];
// Experiment: let's not save thumbnails for GIFs, in order to enable animated GIF posting.
if ($_FILES['photo']['type'] != 'image/gif') {
if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], "{$filename}_{$label}", $size)) {
$varname = "thumbnail_{$label}";
$this->{$varname} = \Idno\Core\site()->config()->url . 'file/' . $thumbnail;
$varname = "thumbnail_{$label}_id";
$this->{$varname} = substr($thumbnail, 0, strpos($thumbnail, '/'));
}
}
}
} else {
\Idno\Core\site()->session()->addMessage('Image wasn\'t attached.');
}
} else {
\Idno\Core\site()->session()->addMessage('This doesn\'t seem to be an image ..');
}
} else {
\Idno\Core\site()->session()->addMessage('We couldn\'t access your image. Please try again.');
return false;
}
}
if ($this->save()) {
if ($new) {
$this->addToFeed();
}
// Add it to the Activity Streams feed
\Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription()));
return true;
} else {
return false;
}
}
开发者ID:avewrigley,项目名称:idno,代码行数:62,代码来源:Photo.php
示例18: addWebmentions
/**
* Add webmentions as annotations based on Microformats 2 data
*
* @param string $source The source URL
* @param string $target The target URL (i.e., the page on this site that was pinged)
* @param string $source_content The source page's HTML
* @param array $source_mf2 Parsed Microformats 2 content from $source
* @return bool Success
*/
function addWebmentions($source, $target, $source_content, $source_mf2)
{
if ($source_content['response'] == 410) {
$this->removeAnnotation($source);
$this->save();
} else {
if (!empty($source_mf2) && !empty($source_mf2['items']) && is_array($source_mf2['items'])) {
// At this point, we don't know who owns the page or what the content is.
// First, we'll initialize some variables that we're interested in filling.
$mentions = array('owner' => array(), 'mentions' => array());
// Content owner and usable webmention items
$return = true;
// Return value;
// Get the page title from the source content
$title = $source;
try {
$dom = new \DOMDocument();
$dom->loadHTML($source_content['content']);
$xpath = new \DOMXPath($dom);
if ($xpath_title = $xpath->query('//title')->item(0)->textContent) {
$title = $xpath_title;
}
} catch (\Exception $e) {
// Do nothing
}
// And then let's cycle through them!
// A first pass for overall owner ...
foreach ($source_mf2['items'] as $item) {
// Figure out what kind of Microformats 2 item we have
if (!empty($item['type']) && is_array($item['type'])) {
foreach ($item['type'] as $type) {
switch ($type) {
case 'h-card':
if (!empty($item['properties'])) {
if (!empty($item['properties']['name'])) {
$mentions['owner']['name'] = $item['properties']['name'][0];
}
if (!empty($item['properties']['url'])) {
$mentions['owner']['url'] = $item['properties']['url'][0];
}
if (!empty($item['properties']['photo'])) {
//$mentions['owner']['photo'] = $item['properties']['photo'][0];
$tmpfname = tempnam(sys_get_temp_dir(), 'webmention_avatar');
file_put_contents($tmpfname, \Idno\Core\Webservice::file_get_contents($item['properties']['photo'][0]));
$name = md5($item['properties']['url'][0]);
// TODO: Don't update the cache image for every webmention
if ($icon = \Idno\Entities\File::createThumbnailFromFile($tmpfname, $name, 300)) {
$mentions['owner']['photo'] = \Idno\Core\Idno::site()->config()->url . 'file/' . (string) $icon;
} else {
if ($icon = \Idno\Entities\File::createFromFile($tmpfname, $name)) {
$mentions['owner']['photo'] = \Idno\Core\Idno::site()->config()->url . 'file/' . (string) $icon;
}
}
unlink($tmpfname);
}
}
break;
}
if (!empty($mentions['owner'])) {
break;
}
}
}
}
// And now a second pass for per-item owners and mentions ...
foreach ($source_mf2['items'] as $item) {
$mentions = $this->addWebmentionItem($item, $mentions, $source, $target, $title);
if (!empty($item['type']) && is_array($item['type'])) {
}
}
if (!empty($mentions['mentions']) && !empty($mentions['owner']) && !empty($mentions['owner']['url'])) {
if (empty($mentions['owner']['photo'])) {
$mentions['owner']['photo'] = '';
}
if (empty($mentions['owner']['url'])) {
$mentions['owner']['url'] = $source;
}
if (empty($mentions['owner']['name'])) {
$mentions['owner']['name'] = 'Web user';
}
if (empty($mentions['title'])) {
$mentions['title'] = '';
}
$this->removeAnnotation($source);
foreach ($mentions['mentions'] as $mention) {
if (!empty($mention['url'])) {
$permalink = implode('', $mention['url']);
} else {
$permalink = $source;
}
// Special exemption for bridgy
//.........这里部分代码省略.........
开发者ID:sensiblemn,项目名称:Known,代码行数:101 |
请发表评论