Skip to content

Commit

Permalink
Added support for reply-to web action
Browse files Browse the repository at this point in the history
  • Loading branch information
eschnou committed May 11, 2013
1 parent d8e4270 commit 092cf47
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 17 deletions.
2 changes: 1 addition & 1 deletion index.php
@@ -1,6 +1,6 @@
<?php
define("STORYTLR_VERSION","1.3.dev");
define("DATABASE_VERSION", "4");
define("DATABASE_VERSION", "5");
define("AUTO_INSTALL", true);
define("AUTO_UPGRADE", true);

Expand Down
43 changes: 36 additions & 7 deletions protected/application/admin/controllers/PostController.php
Expand Up @@ -50,6 +50,13 @@ public function init() {
$this->view->url = $this->_bkurl;
$this->view->title = $this->_bktitle;
$this->view->selection = $this->_bktext;
} else if ($this->_getParam('reply')) {
$this->_helper->layout->setlayout('bookmarklet');
$this->_bkurl = $this->_getParam('url');
$this->_reply = true;
$this->view->bookmarklet = true;
$this->view->url = $this->_bkurl;
$this->view->reply = true;
}
}

Expand Down Expand Up @@ -96,7 +103,13 @@ public function statusAction() {
$status = "{$this->_bktitle} ({$this->_bkurl})";
$source = StuffpressModel::forUser($this->_application->user->id);
$this->view->form = $this->getFormStatus($source->getID(), 0, $status, false, false);
} else {
} else if ($this->_reply) {
$domain = Stuffpress_Services_Webparse::getHost($this->_bkurl);
$status = "@{$domain} ";
$source = StuffpressModel::forUser($this->_application->user->id);
$this->view->form = $this->getFormStatus($source->getID(), 0, $status, false, false, false, false, false, $this->_bkurl);
}
else {
$this->view->form = $this->getForm('status');
}
}
Expand Down Expand Up @@ -282,7 +295,7 @@ public function verifyAction() {
$this->_helper->json->sendJson(true);
}

$type = $this->_getParam('type');
$type = $this->_getParam('type');
$mode = $this->_getParam('mode');
$edit = ($mode == 'edit');

Expand Down Expand Up @@ -403,6 +416,7 @@ private function newItem($values) {
$data['link'] = @$values['link'];
$data['embed'] = @$values['embed'];
$data['text'] = @$values['text'];
$data['reply_to_url'] = @$values['reply'];

// Process the tags if available
$tags = @explode(',', $values['tags']);
Expand All @@ -414,14 +428,17 @@ private function newItem($values) {
array_push($tags, $match[1]);
}
}


// Is this a reply ?
$is_reply = $data['reply_to_url'] ? true: (substr($data['title'], 0, 1) === '@');

// Add or update the item
$source = StuffpressModel::forUser($this->_application->user->id);
$data_table = new Data();
$item_id = $source->addItem($data, $data['published'], $data['type'], $tags, false, false, $data['title']);
$item_id = $source->addItem($data, $data['published'], $data['type'], $tags, false, false, $data['title'], $is_reply);
$source_id = $source->getID();

// fetch the new item
// Fetch the new item
$item = $data_table->getItem($source_id, $item_id);

// Get longitude if provided
Expand Down Expand Up @@ -616,7 +633,7 @@ private function getForm($type='blog', $edit=false, $item=false) {
return $form;
}

private function getFormStatus($source_id, $item_id, $status, $date=false, $edit=false,$tags=false, $lat=false, $lon=false) {
private function getFormStatus($source_id, $item_id, $status, $date=false, $edit=false,$tags=false, $lat=false, $lon=false, $reply=false) {
// Get a basic form
$form = $this->getFormCommon($source_id, $item_id, 'status', $date, $edit,$tags,$lat,$lon);

Expand All @@ -626,7 +643,14 @@ private function getFormStatus($source_id, $item_id, $status, $date=false, $edit
$content->setValue($status);
$content->setRequired(true);
$form->addElement($content);


// Create and configure reply element:
$element = $form->createElement('text', 'reply', array('label' => 'Reply to:', 'decorators' => array('ViewHelper', 'Errors')));
$element->addValidator('stringLength', false, array(0, 256));
$element->addFilter('StripTags');
$element->setValue($reply);
$form->addElement($element);

return $form;
}

Expand Down Expand Up @@ -1048,6 +1072,11 @@ private function pingback($item) {
array_push($links, $item->getLink());
}

// If a reply, add the reply_to_url to the list
if ($item->isreply()) {
array_push($links, $item->getReplyTo());
}

// Collect links
foreach ($matches as $link) {
array_push($links, $link[1]);
Expand Down
10 changes: 6 additions & 4 deletions protected/application/admin/models/Data.php
Expand Up @@ -49,7 +49,7 @@ public function getItem($source, $id) {
return $result;
}

public function getLastItems($count=10, $offset=0, $show_hidden=0, $sources=false, $types=false, $location_only=false) {
public function getLastItems($count=10, $offset=0, $show_hidden=0, $sources=false, $types=false, $location_only=false, $show_reply=0) {

if (!$sources) {
$sources = $this->getSources();
Expand All @@ -73,6 +73,7 @@ public function getLastItems($count=10, $offset=0, $show_hidden=0, $sources=fals
. "FROM data d "
. "WHERE d.user_id = :user_id AND source_id IN ($sources) "
. ((!$show_hidden) ? "AND is_hidden = 0 " : " ")
. ((!$show_reply) ? "AND is_reply = 0 " : " ")
. (($types) ? "AND type IN ($t) " : " ")
. (($location_only) ? "AND has_location = true " : " ")
. "ORDER BY timestamp DESC "
Expand Down Expand Up @@ -245,19 +246,20 @@ public function search($source_id, $service, $index, $term, $show_hidden=0) {
return $result;
}

public function addItem($id, $source_id, $user_id, $service, $type, $timestamp, $is_hidden=0) {
public function addItem($id, $source_id, $user_id, $service, $type, $timestamp, $is_hidden=0, $is_reply=0) {

$is_hidden = $is_hidden ? 1 : 0;

$sql = "INSERT INTO `data` (id, source_id, user_id, service, type, timestamp, is_hidden) "
. "VALUES (:id, :source_id, :user_id, :service, :type, FROM_UNIXTIME(:timestamp), :is_hidden)";
$sql = "INSERT INTO `data` (id, source_id, user_id, service, type, timestamp, is_hidden, is_reply) "
. "VALUES (:id, :source_id, :user_id, :service, :type, FROM_UNIXTIME(:timestamp), :is_hidden, :is_reply)";

$data = array(":id" => $id,
":source_id" => $source_id,
":user_id" => $user_id,
":service" => $service,
":type" => $type,
":is_hidden" => $is_hidden,
":is_reply" => $is_reply,
":timestamp" => $timestamp);

$statement = $this->_db->query($sql, $data);
Expand Down
4 changes: 4 additions & 0 deletions protected/application/admin/models/SourceItem.php
Expand Up @@ -122,6 +122,10 @@ public function isHidden() {
return $this->_attributes['is_hidden'];
}

public function isReply() {
return $this->_attributes['is_reply'];
}

public function getAttributes() {
return $this->_attributes;
}
Expand Down
4 changes: 2 additions & 2 deletions protected/application/admin/models/SourceModel.php
Expand Up @@ -185,7 +185,7 @@ public function deleteItem($id) {
$this->delete($where);
}

public function addItem($data, $timestamp, $type, $tags=false, $location=false, $hidden=false, $title=false) {
public function addItem($data, $timestamp, $type, $tags=false, $location=false, $hidden=false, $title=false, $reply=false) {
$data['source_id'] = $this->_source['id'];
$columns = array();
$keys = array();
Expand All @@ -209,7 +209,7 @@ public function addItem($data, $timestamp, $type, $tags=false, $location=false,
}

$data_table = $this->getDataTable();
$data_table->addItem($id, $this->_source['id'], $this->_source['user_id'], $this->_prefix, $type, $timestamp, $hidden);
$data_table->addItem($id, $this->_source['id'], $this->_source['user_id'], $this->_prefix, $type, $timestamp, $hidden, $reply);
$data_table->setTags($this->_source['id'], $id, $tags);
$data_table->setSlug($this->_source['id'], $id, Stuffpress_Permalink::entry($this->_source['id'], $id, $title));

Expand Down
12 changes: 11 additions & 1 deletion protected/application/admin/views/scripts/post/status.phtml
Expand Up @@ -32,7 +32,17 @@ feel free to be more philosophical and go off the beaten track!
<?= $this->form->tags ?>
<p class="hint">A comma separated list of tags</p>
</td>
</tr>
</tr>
<?php if ($this->reply) : ?>
<tr>
<td class='label'>
Reply To:
</td>
<td class='element'>
<?= $this->form->reply ?>
</td>
</tr>
<?php endif ?>
<tr>
<td class='label'>
Date:
Expand Down
Expand Up @@ -240,5 +240,13 @@ public function setDescription($description) {
public function getFile() {
return $this->_data['file'];
}

public function isReply() {
return $this->_data['reply_to_url'] ? true:false;
}

public function getReplyTo() {
return $this->_data['reply_to_url'];
}

}
Expand Up @@ -69,6 +69,11 @@
echo $title;
?>
</div>
<?php if ($this->item->isReply()) :?>
<footer>
<p>In reply to <a href="<?= $this->item->getReplyTo() ?>" class="u-in-reply-to"><?= Stuffpress_Services_Webparse::getHost($this->item->getReplyTo()) ?></a></p>
</footer>
<?php endif ?>
</div>
<?php elseif($type == 'link') : ?>
<div class="storytlr_link">
Expand Down
Expand Up @@ -204,7 +204,7 @@ private function processItems($items) {

if ($is_repost) continue;

$id = $this->addItem($data, strtotime($data['created_at']), $type, $tags, false, $is_hidden, $data['text']);
$id = $this->addItem($data, strtotime($data['created_at']), $type, $tags, false, $is_hidden, $data['text'], $is_reply);

if ($id) $result[] = $id;
unset($data);
Expand Down
Expand Up @@ -4,7 +4,7 @@

<div class="hentry h-entry entry <?php if($this->item->isHidden()) : ?> hidden <?php else : ?> item <?php endif ?>" id='item_<?= $id ?>'>
<div class='item_left'>
<a href="<?= $this->base()->thisUrl()?>/entry/<?= $this->item->getSlug() ?>" rel="bookmark">
<a href="<?= $this->base()->thisUrl()?>/entry/<?= $this->item->getSlug() ?>" class="u-url" rel="bookmark">
<img class="icon" src="<?= $this->item->getIcon();?>" width='16' height='16' />
</a>
<abbr class="published dt-published" title="<?= date("c", $this->item->getTimestamp()); ?>">
Expand Down
2 changes: 2 additions & 0 deletions protected/install/database/update/005/add_reply_column.sql
@@ -0,0 +1,2 @@
ALTER TABLE data ADD `is_reply` tinyint(1) not null default '0';
ALTER TABLE stuffpress_data ADD `reply_to_url` varchar(256);
6 changes: 6 additions & 0 deletions style/public.css
Expand Up @@ -299,6 +299,12 @@ div.story_embed input {
margin-top: 4px;
}

div.item footer {
margin-top: 10px;
font-size: 0.8em;
color: #999;
}

/* Pagination
-------------------------------
*/
Expand Down
4 changes: 4 additions & 0 deletions style/style.css
Expand Up @@ -597,6 +597,10 @@ form input#tags {
width: 475px;
}

form input#reply {
width: 475px;
}

table td {
vertical-align: top;
padding: 4px 20px 0px 0px;
Expand Down

0 comments on commit 092cf47

Please sign in to comment.