Skip to content

Commit

Permalink
Bookmarks can now also be likes and reposts
Browse files Browse the repository at this point in the history
  • Loading branch information
benwerd committed Oct 10, 2015
1 parent c2ba15f commit 2534172
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion IdnoPlugins/Like/ContentType.php
Expand Up @@ -7,7 +7,7 @@ class ContentType extends \Idno\Common\ContentType {
public $title = 'Bookmark';
public $category_title = 'Bookmarked pages';
public $entity_class = 'IdnoPlugins\\Like\\Like';
public $indieWebContentType = array('bookmark');
public $indieWebContentType = array('bookmark','like','repost');

}

Expand Down
19 changes: 16 additions & 3 deletions IdnoPlugins/Like/Like.php
Expand Up @@ -81,6 +81,8 @@ function saveDataFromInput() {
$tags = \Idno\Core\site()->currentPage()->getInput('tags');
$title = \Idno\Core\site()->currentPage()->getInput('title');
$access = \Idno\Core\site()->currentPage()->getInput('access');
$likeof = \Idno\Core\site()->currentPage()->getInput('like-of');
$repostof = \Idno\Core\site()->currentPage()->getInput('repost-of');

if ($time = \Idno\Core\site()->currentPage()->getInput('created')) {
if ($time = strtotime($time)) {
Expand All @@ -89,13 +91,21 @@ function saveDataFromInput() {
}

$body = trim($body);
if(filter_var($body, FILTER_VALIDATE_URL)){
if (!empty($body)) {
if(filter_var($body, FILTER_VALIDATE_URL) || filter_var($likeof, FILTER_VALIDATE_URL) || filter_var($repostof, FILTER_VALIDATE_URL)){
if (!empty($body) || !empty($likeof) || !empty($repostof)) {
$this->body = $body;
if (!empty($likeof)) {
$this->body = $likeof;
$this->likeof = $likeof;
}
if (!empty($repostof)) {
$this->body = $repostof;
$this->repostof = $repostof;
}
$this->description = $description;
$this->tags = $tags;
if (empty($title)) {
if ($title = $this->getTitleFromURL($body)) {
if ($title = $this->getTitleFromURL($this->body)) {
$this->pageTitle = $title;
} else {
$this->pageTitle = '';
Expand All @@ -104,6 +114,7 @@ function saveDataFromInput() {
$this->pageTitle = $title;
}
if (empty($title)) {
error_log("No title");
\Idno\Core\site()->session()->addErrorMessage('You need to specify a title.');
return false;
}
Expand All @@ -112,9 +123,11 @@ function saveDataFromInput() {
return true;
}
} else {
error_log("No URL");
\Idno\Core\site()->session()->addErrorMessage('You can\'t bookmark an empty URL.');
}
} else {
error_log("Invalid URL");
\Idno\Core\site()->session()->addErrorMessage('That doesn\'t look like a valid URL.');
}
return false;
Expand Down
17 changes: 12 additions & 5 deletions IdnoPlugins/Like/templates/default/entity/Like.tpl.php
@@ -1,8 +1,15 @@
<?php
if (\Idno\Core\site()->currentPage()->isPermalink()) {
$rel = 'rel="like" class="u-like"';
} else {
$rel = '';

$rel = '';
$icon = '';

if (!empty($vars['object']->likeof)) {
$rel = 'rel="like" class="u-like-of"';
$icon = '<i class="fa fa-star-o"></i> ';
}
if (!empty($vars['object']->repostof)) {
$rel = 'rel="like" class="u-repost-of"';
$icon = '<i class="fa fa-retweet"></i> ';
}

if (!empty($vars['object']->pageTitle)) {
Expand All @@ -18,7 +25,7 @@
if (empty($vars['feed_view'])) {

?>
<h2 class="p-bookmark"><a href="<?= $vars['object']->body; ?>" rel="bookmark"
<h2 class="p-bookmark"><?=$icon?><a href="<?= $vars['object']->body; ?>" rel="bookmark"
target="_blank"><?= $this->parseURLs(htmlentities(strip_tags($body)), $rel) ?></a>
</h2>
<?php
Expand Down

0 comments on commit 2534172

Please sign in to comment.