Commit b6da5b49 authored by Malcolm Blaney's avatar Malcolm Blaney

Added initial support for photo posts, which can be added via the

Writer module and will be rendered as a lightbox in the Post module.
Post module now also sends webmentions when a post is removed.
Removed code that was used to publish to Facebook, as that can no
longer be done via brid.dy. Control bar now has either static or
sticky positioning, as neither of these values obscure the rest of
the page. SimplePie Parser bug fix, an extra array was being added
to the Media RSS format which wasn't required.
parent 7b94ae6c
Pipeline #35825954 passed with stage
in 1 minute and 21 seconds
......@@ -74,18 +74,12 @@ class Post extends Base {
$object['notify'] = true;
}
$object['permalink'] = $post['permalink'];
// Check the 'Send to Twitter' or 'Send to Facebook' boxes if a link
// was added previously.
// Check the 'Send to Twitter' box if a link was added previously.
$twitter_checked = '';
$twitter_link = 'https://brid.gy/publish/twitter';
if (strpos($post['description'], $twitter_link) !== false) {
$twitter_checked = ' checked="checked"';
}
$facebook_checked = '';
$facebook_link = 'https://brid.gy/publish/facebook';
if (strpos($post['description'], $facebook_link) !== false) {
$facebook_checked = ' checked="checked"';
}
// Set Webaction if a class name is found in the description.
$class = '';
$url = '';
......@@ -149,11 +143,6 @@ class Post extends Base {
'<input id="post-twitter-input" name="twitter" type="checkbox"' .
$twitter_checked . '>' .
'</div>' .
'<div class="form-spacing">' .
'<label for="post-facebook-input">Send to Facebook:</label>' .
'<input id="post-facebook-input" name="facebook" type="checkbox"' .
$facebook_checked . '>' .
'</div>' .
'<button type="submit">Submit</button>' .
'</form>';
}
......@@ -203,6 +192,22 @@ class Post extends Base {
// simplifies creating permalinks, but it must be escaped here.
$title = htmlspecialchars($post['title']);
$description = $post['description'];
$enclosure = json_decode($post['enclosure'], true);
$count = count($enclosure);
if ($count === 1) {
$media .= '<p><img class="u-photo" src="' . $enclosure[0] .'"></p>';
}
else if ($count > 1) {
$image_set_id = preg_replace('/[[:^alnum:]]/', '', $enclosure[0]);
$media .= '<p class="photo-list">';
for ($i = 0; $i < $count; $i++) {
$hidden = $i <= 1 ? '' : 'class="hidden" ';
$media .= '<a href="' . $enclosure[$i] . '" ' . $hidden .
'data-lightbox="' . $image_set_id . '">' .
'<img class="u-photo" src="' . $enclosure[$i] . '"></a>';
}
$media .= '<br><b>' . $count . ' photos</b></p>';
}
// The author is escaped in SetContent.
$author = $post['author'];
$prev_tag = '';
......@@ -579,12 +584,14 @@ class Post extends Base {
'<div class="published">' .
'By <span class="h-card p-author">!author</span> on !date</div>' .
'<div class="dobrado-editable p-name e-content">!description</div>' .
'<div class="options">!category</div>!navigation</article>';
'<div class="media">!media</div><div class="options">!category</div>' .
'!navigation</article>';
$post_with_title = '<article class="h-entry">!title' .
'<div class="published">' .
'By <span class="h-card p-author">!author</span> on !date</div>' .
'<div class="dobrado-editable e-content">!description</div>' .
'<div class="options">!category</div>!navigation</article>';
'<div class="media">!media</div><div class="options">!category</div>' .
'!navigation</article>';
// The h-entry class is added to a parent element on the permalink page.
// The u-comment markup is required on permalink pages to differentiate a
// microformats comments feed from a single h-entry in a feed.
......@@ -592,14 +599,14 @@ class Post extends Base {
'<div class="published">' .
'By <span class="h-card p-author">!author</span> on !date</div>' .
'<div class="dobrado-editable p-name e-content">!description</div>' .
'<div class="options">!category</div>!navigation</article>' .
'<div class="u-comment h-entry"></div>';
'<div class="media">!media</div><div class="options">!category</div>' .
'!navigation</article><div class="u-comment h-entry"></div>';
$permalink_with_title = '<article>!title' .
'<div class="published">' .
'By <span class="h-card p-author">!author</span> on !date</div>' .
'<div class="dobrado-editable e-content">!description</div>' .
'<div class="options">!category</div>!navigation</article>' .
'<div class="u-comment h-entry"></div>';
'<div class="media">!media</div><div class="options">!category</div>' .
'!navigation</article><div class="u-comment h-entry"></div>';
$template = ['"post-no-title", "", ' .
'"' . $mysqli->escape_string($post_no_title) . '"',
'"post-with-title", "", ' .
......@@ -636,10 +643,14 @@ class Post extends Base {
$mysqli = connect_db();
if (isset($id)) {
// Copies of this post can point to the same permalink page, so only
// remove it when there's only one reference left.
// remove the permalink page when there's one reference left. (Note that
// posts are tombstoned rather than deleted from the database, so need to
// skip those when looking for copies to count.)
$tombstone = $mysqli->escape_string($this->Tombstone());
$query = 'SELECT permalink FROM post WHERE user = "' . $this->owner .'" '.
'AND description != "' . $tombstone . '" ' .
'AND permalink = (SELECT permalink FROM post WHERE ' .
'user = "' . $this->owner . '" AND box_id = ' . $id . ')';
'user = "' . $this->owner . '" AND box_id = ' . $id . ')';
if ($result = $mysqli->query($query)) {
if ($result->num_rows === 1) {
$this->RemovePermalinkPage($id);
......@@ -660,7 +671,6 @@ class Post extends Base {
}
$this->RemoveNotify($id);
$this->UpdatePager($id);
$tombstone = $mysqli->escape_string($this->Tombstone());
$query = 'UPDATE post SET title = "", description = "' . $tombstone.'", '.
'author = "", category = "", enclosure = "" WHERE ' .
'user = "' . $this->owner . '" AND box_id = ' . $id;
......@@ -721,8 +731,8 @@ class Post extends Base {
}
$us_title = isset($us_content['title']) ? $us_content['title'] : '';
$mp_syndicate_to = '';
// If the user has chosen to send the post to twitter or facebook, add a
// link in the post to brid.gy to enable webmentions.
// If the user has chosen to send the post to twitter, add a link in the
// post to brid.gy to enable webmentions.
if (isset($us_content['twitter']) && (int)$us_content['twitter'] === 1) {
if ($micropub) {
$mp_syndicate_to .= 'https://twitter.com';
......@@ -741,36 +751,21 @@ class Post extends Base {
}
$us_data .= '<a href="' . $twitter_link . '"></a>';
}
// Also add u-photo to any images so that brid.gy posts them too.
if (strpos($us_data, '<img') !== false) {
$regex = '/<img .*src="(.+)".*>/U';
$replacement = '<img src="$1" class="u-photo">';
$us_data = preg_replace($regex, $replacement, $us_data);
}
}
}
if (isset($us_content['facebook']) && (int)$us_content['facebook'] === 1) {
if ($mp_syndicate_to !== '') {
$us_data['properties']['mp-syndicate-to'] = $mp_syndicate_to;
}
$us_enclosure = '';
if (isset($us_content['enclosure'])) {
if ($micropub) {
if ($mp_syndicate_to !== '') $mp_syndicate_to .= ',';
$mp_syndicate_to .= 'https://facebook.com';
$us_content['properties']['photo'] =
json_decode($us_content['enclosure'], true);
}
else {
// Don't need the link back on Facebook as it shows the full content.
$facebook_link =
'https://brid.gy/publish/facebook?bridgy_omit_link=true';
if (strpos($us_data, $facebook_link) === false) {
$us_data .= '<a href="' . $facebook_link . '"></a>';
}
if (strpos($us_data, '<img') !== false) {
$regex = '/<img .*src="(.+)".*>/U';
$replacement = '<img src="$1" class="u-photo">';
$us_data = preg_replace($regex, $replacement, $us_data);
}
$us_enclosure = $us_content['enclosure'];
}
}
if ($mp_syndicate_to !== '') {
$us_data['properties']['mp-syndicate-to'] = $mp_syndicate_to;
}
// If a webaction is set, make sure it's marked up correctly.
if (isset($us_content['webactionType']) &&
isset($us_content['webactionUrl'])) {
......@@ -850,8 +845,7 @@ class Post extends Base {
$us_category = isset($us_content['category']) ?
$us_content['category'] : '';
$category = $mysqli->escape_string($us_category);
$enclosure = isset($us_content['enclosure']) ?
$mysqli->escape_string($us_content['enclosure']) : '';
$enclosure = $mysqli->escape_string($us_enclosure);
$permalink = '';
$old_title = '';
$us_old_description = '';
......@@ -905,7 +899,7 @@ class Post extends Base {
if (strip_tags($description) === '') {
$permalink = $date . '-' . mt_rand();
// Having both an empty title and description is really bad because
// Content will return false, which means the post can't be removed.
// Content() will return false, which means the post can't be removed.
if ($description === '') {
$description = $empty_post;
}
......@@ -942,7 +936,7 @@ class Post extends Base {
// The permalink may not have changed just because the title has
// (due to characters that are removed), so compare first.
if ($permalink !== $old_permalink) {
$this->Permalink($id, $permalink, $old_permalink, $feed);
$this->CreatePermalinkPage($id, $permalink, $old_permalink, $feed);
}
}
// Otherwise check if anything else has changed and return if not.
......@@ -1407,7 +1401,7 @@ class Post extends Base {
$mysqli->close();
}
private function Permalink($id, $permalink, $old_permalink, $feed) {
private function CreatePermalinkPage($id, $permalink, $old_permalink, $feed) {
$this->RemovePermalinkPage($id, $old_permalink);
// Need to override the user set in config to match the current page owner.
......@@ -1714,32 +1708,43 @@ class Post extends Base {
return [$received[0], $received[1]];
}
private function RemovePermalinkPage($id, $permalink = '') {
private function RemovePermalinkPage($id, $old_permalink = '') {
$mysqli = connect_db();
$tombstone = false;
$us_old_description = '';
$us_old_category = '';
$permalink = '';
$feed = '';
if ($permalink === '') {
$query = 'SELECT permalink, feed FROM post WHERE ' .
'user = "' . $this->owner . '" AND box_id = ' . $id;
if ($result = $mysqli->query($query)) {
if ($post = $result->fetch_assoc()) {
$permalink = $mysqli->escape_string($post['permalink']);
$feed = $mysqli->escape_string($post['feed']);
}
$result->close();
}
else {
$this->Log('Post->RemovePermalinkPage 1: ' . $mysqli->error);
}
if ($permalink === '') {
$mysqli->close();
return;
// First store the old content so that webmentions can be sent to notify
// links that they've been removed.
$query = 'SELECT description, category, permalink, feed FROM post ' .
'WHERE user = "' . $this->owner . '" AND box_id = ' . $id;
if ($result = $mysqli->query($query)) {
if ($post = $result->fetch_assoc()) {
$us_old_description = $post['description'];
$us_old_category = $post['category'];
$permalink = $mysqli->escape_string($post['permalink']);
$feed = $mysqli->escape_string($post['feed']);
}
// When a permalink is not given the post is being removed, in which case
// we'll replace it with a tombstone post.
$tombstone = true;
$result->close();
}
else {
$this->Log('Post->RemovePermalinkPage 1: ' . $mysqli->error);
}
// Return if old_permalink was not provided and current permalink not found.
if ($old_permalink === '' && $permalink === '') {
$mysqli->close();
return;
}
$tombstone = true;
// When old_permalink is provided it means the permalink is being updated,
// so the old page is removed here and a tombstone post is not required.
// Otherwise the current permalink is used to remove the contents of that
// page, which then also requires a tombstone post.
if ($old_permalink !== '') {
$tombstone = false;
$permalink = $old_permalink;
}
// Call the Remove method for all other modules on the page.
$query = 'SELECT box_id, label FROM modules WHERE ' .
'user = "' . $this->owner . '" AND box_id != ' . $id . ' AND ' .
......@@ -1797,6 +1802,10 @@ class Post extends Base {
$this->SetContent($new_id, ['data' => $description, 'notify' => true]);
}
$mysqli->close();
// Once all the updates have been done send webmentions to old links.
$this->ContentUpdated($id, $us_old_description, $us_old_category, $feed,
$permalink, false);
}
private function SendWebmention($url, $permalink, $endpoint = '') {
......
......@@ -153,9 +153,9 @@ class Writer extends Base {
'<div class="arrow"></div>' .
'<ul class="menu">' .
'<li id="writer-options-title"><div>Add a title</div></li>' .
'<li id="writer-options-photo"><div>Add a photo</div></li>' .
$author .
'<li id="writer-options-twitter"><div>Send to Twitter</div></li>' .
'<li id="writer-options-facebook"><div>Send to Facebook</div></li>'.
'</ul>' .
'</div>' .
$writer_settings .
......@@ -179,9 +179,11 @@ class Writer extends Base {
'<button class="writer-remove-twitter">remove</button>' .
'<span class="writer-twitter">Send to Twitter</span>' .
'</div>' .
'<div class="writer-options-facebook hidden">' .
'<button class="writer-remove-facebook">remove</button>' .
'<span class="writer-facebook">Send to Facebook</span>' .
'<div class="writer-options-photo hidden">' .
'<button class="writer-remove-photo">remove</button>' .
'<span class="writer-photo">Add photos to display as an album:</span>' .
'<button id="writer-photo-browse">browse</button>' .
'<div id="writer-photo-selected"></div>' .
'</div>' .
$designate_page;
}
......@@ -262,7 +264,6 @@ class Writer extends Base {
'"",".writer-options-title","padding","2px"',
'"",".writer-options-author","padding","2px"',
'"",".writer-options-twitter","padding","2px"',
'"",".writer-options-facebook","padding","2px"',
'"",".writer-menu-wrapper","opacity",".8"',
'"",".writer-menu-wrapper","position","absolute"',
'"",".writer-menu-wrapper","left","-3px"',
......@@ -295,15 +296,19 @@ class Writer extends Base {
'"",".writer-remove-title","float","left"',
'"",".writer label[for=writer-title]","width","4em"',
'"",".writer label[for=writer-title]","float","none"',
'"",".writer label[for=writer-title]","text-align","right"',
'"",".writer label[for=writer-title]","margin-right","5px"',
'"",".writer label[for=writer-title]","display",' .
'"inline-block"',
'"",".writer label[for=writer-author]","width","4em"',
'"",".writer label[for=writer-author]","float","none"',
'"",".writer label[for=writer-author]","text-align","right"',
'"",".writer label[for=writer-author]","margin-right","5px"',
'"",".writer label[for=writer-author]","display",' .
'"inline-block"',
'"",".writer-twitter","margin-left","10px"',
'"",".writer-facebook","margin-left","10px"',
'"","#writer-follow","float","right"'];
'"","#writer-follow","float","right"',
'"","#writer-photo-selected img","height","50px"'];
$this->AddSiteStyle($site_style);
return $this->Dependencies(['post']);
}
......
......@@ -25,52 +25,51 @@
// for the JavaScript code in this page.
if(!this.dobrado.writer){dobrado.writer={};}
(function(){'use strict';var sendToTwitter=0;var sendToFacebook=0;var webactionType='';var webactionUrl='';var defaultText='Write a new post...';$(function(){if($('#writer-content').length===0){return;}
$("#writer-content").click(function(){if(!$(".extended").dialog("isOpen")){dobrado.writer.showEditor();}});$(".writer-post").button({disabled:true}).click(function(){dobrado.log("Creating post...","info");dobrado.createModule("writer","post","post");});$("#writer-author").val(dobrado.readCookie("user"));$("#writer-title").val("");$("#writer-tag-input").val("");$("#writer-tags").checkboxradio({icon:false}).click(toggleTags);$(".writer .menu").menu();$(".writer-edit-settings").button({icon:'ui-icon-signal-diag',showLabel:false}).click(function(){$(".writer .designate").toggle();$(".reader-settings").toggle();});$('#writer-designate-action').val('post').change(showDesignate);$(".writer .submit-designate").button().click(designate);$(".writer .submit-feed-title").button().click(feedTitle);$(".writer-remove-title").button({icon:'ui-icon-closethick',showLabel:false}).click(removeTitle);$(".writer-remove-author").button({icon:'ui-icon-closethick',showLabel:false}).click(removeAuthor);$(".writer-remove-twitter").button({icon:'ui-icon-closethick',showLabel:false}).click(removeTwitter);$(".writer-remove-facebook").button({icon:'ui-icon-closethick',showLabel:false}).click(removeFacebook);$("#writer-remove-action").button({icon:'ui-icon-closethick',showLabel:false}).click(removeActionExplicit);if(dobrado.reader){$("#writer-follow").button().click(dobrado.reader.addFeed);}
if($(".post-comment").length===0){$("<div></div>").addClass("post-comment").appendTo(".writer");}
webactionType=$("#writer-action-type").html();if(webactionType==='like'||webactionType==='reply'){$('#writer-content').val('');}
webactionUrl=$("#writer-action-url").attr("href");if(webactionType==='share'){shareFullText();}
$('.writer-options-add').button({icon:'ui-icon-plus',showLabel:false}).click(add);$('.writer-menu-wrapper .menu li').each(function(){$(this).click(showOptions);});hideOptions();dobrado.writer.showEditor();$('.writer-options').show();});function hideMenu(){$(".writer-menu-wrapper").hide();}
function add(){dobrado.hideOtherMenu("writer-menu-wrapper");dobrado.toggleMenu("writer-menu-wrapper");$("body").one("click",hideMenu);return false;}
function showDesignate(){var action=$("#writer-designate-action").val();dobrado.log("Loading page for displaying "+action+".","info");$.post("/php/request.php",{request:"writer",mode:"showDesignate",action:action,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"writer showDesignate")){return;}
var designate=JSON.parse(response);$("#writer-designate-input").val(designate.page);});return false;}
function designate(){var action=$("#writer-designate-action").val();dobrado.log("Updating page for displaying "+action+".","info");$.post("/php/request.php",{request:"writer",mode:"designate",action:action,designate:$("#writer-designate-input").val(),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"writer designate")){return;}});return false;}
function feedTitle(){dobrado.log("Updating feed title.","info");$.post("/php/request.php",{request:"writer",mode:"feedTitle",title:$("#writer-feed-title-input").val(),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"writer feedTitle")){return;}});return false;}
function showOptions(event){event.preventDefault();var className=$(this).attr("id");$("."+className).show();if(className==="writer-options-twitter"){sendToTwitter=1;}
else if(className==="writer-options-facebook"){sendToFacebook=1;}}
function hideOptions(){var writerOptions=["title","author","twitter","facebook"];$(writerOptions).each(function(i,item){var value=item==="author"?dobrado.readCookie("user"):"";$("#writer-"+item).val(value);$(".writer-options-"+item).hide();});}
function toggleTags(){$("#writer-tag-input").toggle();}
function removeTitle(){$("#writer-title").val("");$(".writer-options-title").hide();}
function removeAuthor(){$("#writer-author").val(dobrado.readCookie("user"));$(".writer-options-author").hide();}
function removeTwitter(){sendToTwitter=0;$(".writer-options-twitter").hide();}
function removeFacebook(){sendToFacebook=0;$(".writer-options-facebook").hide();}
function removeActionExplicit(){dobrado.log("Removing action...","info");removeAction(true);}
function removeAction(cancelled){$.post("/php/request.php",{request:"writer",mode:"removeWebaction",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"writer removeAction")){return;}
(function(){'use strict';var sendToTwitter=0;var webactionType='';var webactionUrl='';var defaultText='Write a new post...';$(function(){if($('#writer-content').length===0){return;}
$('#writer-content').click(function(){if(!$('.extended').dialog('isOpen')){dobrado.writer.showEditor();}});$('.writer-post').button({disabled:true}).click(function(){dobrado.log('Creating post...','info');dobrado.createModule('writer','post','post');});$('#writer-author').val(dobrado.readCookie('user'));$('#writer-title').val('');$('#writer-tag-input').val('');$('#writer-tags').checkboxradio({icon:false}).click(toggleTags);$('.writer .menu').menu();$('#writer-photo-browse').button().click(function(){dobrado.createModule('browser','browser','writer');});$('.writer-edit-settings').button({icon:'ui-icon-signal-diag',showLabel:false}).click(function(){$('.writer .designate').toggle();$('.reader-settings').toggle();});$('#writer-designate-action').val('post').change(showDesignate);$('.writer .submit-designate').button().click(designate);$('.writer .submit-feed-title').button().click(feedTitle);$('.writer-remove-title').button({icon:'ui-icon-closethick',showLabel:false}).click(removeTitle);$('.writer-remove-author').button({icon:'ui-icon-closethick',showLabel:false}).click(removeAuthor);$('.writer-remove-twitter').button({icon:'ui-icon-closethick',showLabel:false}).click(removeTwitter);$('.writer-remove-photo').button({icon:'ui-icon-closethick',showLabel:false}).click(removePhoto);$('#writer-remove-action').button({icon:'ui-icon-closethick',showLabel:false}).click(removeActionExplicit);if(dobrado.reader){$('#writer-follow').button().click(dobrado.reader.addFeed);}
if($('.post-comment').length===0){$('<div></div>').addClass('post-comment').appendTo('.writer');}
webactionType=$('#writer-action-type').html();if(webactionType==='like'||webactionType==='reply'){$('#writer-content').val('');}
webactionUrl=$('#writer-action-url').attr('href');if(webactionType==='share'){shareFullText();}
$('.writer-options-add').button({icon:'ui-icon-plus',showLabel:false}).click(add);$('.writer-menu-wrapper .menu li').each(function(){$(this).click(showOptions);});hideOptions();dobrado.writer.showEditor();$('.writer-options').show();});function hideMenu(){$('.writer-menu-wrapper').hide();}
function add(){dobrado.hideOtherMenu('writer-menu-wrapper');dobrado.toggleMenu('writer-menu-wrapper');$('body').one('click',hideMenu);return false;}
function showDesignate(){var action=$('#writer-designate-action').val();dobrado.log('Loading page for displaying '+action+'.','info');$.post('/php/request.php',{request:'writer',mode:'showDesignate',action:action,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'writer showDesignate')){return;}
var designate=JSON.parse(response);$('#writer-designate-input').val(designate.page);});return false;}
function designate(){var action=$('#writer-designate-action').val();dobrado.log('Updating page for displaying '+action+'.','info');$.post('/php/request.php',{request:'writer',mode:'designate',action:action,designate:$('#writer-designate-input').val(),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'writer designate')){return;}});return false;}
function feedTitle(){dobrado.log('Updating feed title.','info');$.post('/php/request.php',{request:'writer',mode:'feedTitle',title:$('#writer-feed-title-input').val(),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'writer feedTitle')){return;}});return false;}
function showOptions(event){event.preventDefault();var className=$(this).attr('id');$('.'+className).show();if(className==='writer-options-twitter'){sendToTwitter=1;}
else if(className==='writer-options-photo'){$('#writer-photo-browse').click();}}
function hideOptions(){var writerOptions=['title','photo','author','twitter'];$(writerOptions).each(function(i,item){var value=item==='author'?dobrado.readCookie('user'):'';$('#writer-'+item).val(value);$('.writer-options-'+item).hide();});}
function toggleTags(){$('#writer-tag-input').toggle();}
function removeTitle(){$('#writer-title').val('');$('.writer-options-title').hide();}
function removePhoto(){$('#writer-photo-selected').html('');$('.writer-options-photo').hide();}
function removeAuthor(){$('#writer-author').val(dobrado.readCookie('user'));$('.writer-options-author').hide();}
function removeTwitter(){sendToTwitter=0;$('.writer-options-twitter').hide();}
function removeActionExplicit(){dobrado.log('Removing action...','info');removeAction(true);}
function removeAction(cancelled){$.post('/php/request.php',{request:'writer',mode:'removeWebaction',url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'writer removeAction')){return;}
var writer=JSON.parse(response);history.pushState({},'',writer.url);if(dobrado.editor){dobrado.editor.setData('');}
else{$("#writer-content").val('');}
$("#writer-title").val('');$("#writer-tag-input").val('');$("#writer-webaction-info").html('');$("#writer-author").val(dobrado.readCookie("user"));if(dobrado.reader){dobrado.reader.scrollback(webactionUrl,cancelled);}
sendToTwitter=0;sendToFacebook=0;webactionType='';webactionUrl='';});}
function quoteContent(){webactionType='';$("#writer-author").val('');var data=dobrado.editor.getData();dobrado.editor.setData('<br><br><cite class="h-cite u-quotation-of">'+
else{$('#writer-content').val('');}
$('#writer-title').val('');$('#writer-tag-input').val('');$('#writer-webaction-info').html('');$('#writer-author').val(dobrado.readCookie('user'));if(dobrado.reader){dobrado.reader.scrollback(webactionUrl,cancelled);}
sendToTwitter=0;webactionType='';webactionUrl='';});}
function quoteContent(){webactionType='';$('#writer-author').val('');var data=dobrado.editor.getData();dobrado.editor.setData('<br><br><cite class="h-cite u-quotation-of">'+
data+'<br><a class="u-url" href="'+
webactionUrl+'">'+webactionUrl+'</a></cite>');}
function shareFullText(){dobrado.log("Loading content...","info");$.post("/php/request.php",{request:"writer",mode:"shareFullText",share:webactionUrl,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"writer shareFullText")){return;}
function shareFullText(){dobrado.log('Loading content...','info');$.post('/php/request.php',{request:'writer',mode:'shareFullText',share:webactionUrl,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'writer shareFullText')){return;}
var share=JSON.parse(response);if(dobrado.editor){dobrado.editor.setData(share.content);dobrado.editor.once('focus',quoteContent);}
else{$("#writer-content").val(share.content);}
$("#writer-author").val(share.author);if(share.title!==''){$("#writer-title").val(share.title);$(".writer-options-title").show();}
if(share.category!==''){$("#writer-tag-input").val(share.category);if(!$("#writer-tags").is(":checked")){$("#writer-tags").click();}}});}
else{$('#writer-content').val(share.content);}
$('#writer-author').val(share.author);if(share.title!==''){$('#writer-title').val(share.title);$('.writer-options-title').show();}
if(share.category!==''){$('#writer-tag-input').val(share.category);if(!$('#writer-tags').is(':checked')){$('#writer-tags').click();}}});}
dobrado.writer.action=function(action,url,sendTo){webactionType=action;webactionUrl=url;if(dobrado.editor&&webactionType==='share'){dobrado.editor.once('focus',quoteContent);}
if(sendTo==='facebook'){sendToFacebook=1;}
else if(sendTo==='twitter'){sendToTwitter=1;}
dobrado.log("Loading action...","info");$.post("/php/request.php",{request:"writer",mode:"showWebaction",action:action,actionUrl:url,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"writer action")){return;}
var webactionInfo=JSON.parse(response);$("#writer-webaction-info").html(webactionInfo.content);$("#writer-remove-action").button({icon:'ui-icon-closethick',showLabel:false}).click(removeActionExplicit);if(dobrado.reader){$("#writer-follow").button().click(dobrado.reader.addFeed);}});};dobrado.writer.showEditor=function(){function clearContent(){if(dobrado.editor.getData()===defaultText){dobrado.editor.setData('');}}
if(sendTo==='twitter'){sendToTwitter=1;}
dobrado.log('Loading action...','info');$.post('/php/request.php',{request:'writer',mode:'showWebaction',action:action,actionUrl:url,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'writer action')){return;}
var webactionInfo=JSON.parse(response);$('#writer-webaction-info').html(webactionInfo.content);$('#writer-remove-action').button({icon:'ui-icon-closethick',showLabel:false}).click(removeActionExplicit);if(dobrado.reader){$('#writer-follow').button().click(dobrado.reader.addFeed);}});};dobrado.writer.select=function(filename){$('#writer-photo-selected').append('<img src="'+filename+'">');};dobrado.writer.showEditor=function(){function clearContent(){if(dobrado.editor.getData()===defaultText){dobrado.editor.setData('');}}
if(dobrado.editMode){dobrado.closeEditor();}
$("#writer-content").parents("div").each(function(){if(/^dobrado-/.test($(this).attr("id"))){dobrado.current="#"+$(this).attr("id");return false;}});$(dobrado.current).data("label","writer");var editorCssProperties=["azimuth","background","background-attachment","background-color","background-image","background-position","background-repeat","background-size","caption-side","clear","clip","color","content","counter-increment","counter-reset","cue","cue-after","cue-before","cursor","direction","empty-cells","filter","font","font-family","font-size","font-style","font-variant","font-weight","letter-spacing","line-height","list-style","list-style-image","list-style-position","list-style-type","opacity","orphans","outline","outline-color","outline-style","outline-width","padding","padding-bottom","padding-left","padding-right","padding-top","page","page-break-after","page-break-before","page-break-inside","pause","pause-after","pause-before","pitch","pitch-range","play-during","quotes","richness","size","speak","speak-header","speak-numeral","speak-punctuation","speech-rate","stress","text-align","text-decoration","text-indent","text-transform","unicode-bidi","vertical-align","voice-family","volume","white-space","widows","word-spacing"];var css=".cke_editable { ";var current=$(dobrado.current);for(var i=0;i<editorCssProperties.length;i++){var property=editorCssProperties[i];var value=current.css(property);if(value){css+=property+": "+value+";";}}
css+="}";CKEDITOR.addCss(css);var content=$("#writer-content").text();$("#writer-content").val(content);dobrado.editor=CKEDITOR.replace('writer-content',{allowedContent:true,autoGrow_minHeight:$('#writer-content').height(),autoGrow_onStartup:true,disableNativeSpellChecker:false,enterMode:CKEDITOR.ENTER_BR,extraPlugins:'autogrow,extended',filebrowserBrowseUrl:'/php/browse.php',removePlugins:'elementspath,tableselection,tabletools,contextmenu,liststyle',resize_enabled:false,on:{focus:clearContent},toolbar:[['Undo','Redo','-','Bold','Italic','-','Link','Unlink','-','Image','Extended']]});$(".writer-post").button("option","disabled",false);};dobrado.writer.newModuleCallback=function(id,context){var data=dobrado.editor?dobrado.editor.getData():$("#writer-content").val();var content={data:data,dataOnly:false,title:$("#writer-title").val(),author:$("#writer-author").val(),category:$("#writer-tag-input").val(),enclosure:"",twitter:sendToTwitter,facebook:sendToFacebook,webactionType:webactionType,webactionUrl:webactionUrl};if(context==="post"){$.post("/php/content.php",{id:id,label:'post',content:JSON.stringify(content),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"writer callback")){return;}
$('#writer-content').parents('div').each(function(){if(/^dobrado-/.test($(this).attr('id'))){dobrado.current='#'+$(this).attr('id');return false;}});$(dobrado.current).data('label','writer');var editorCssProperties=['background','background-attachment','background-color','background-image','background-position','background-repeat','background-size','clear','color','direction','empty-cells','font','font-family','font-size','font-style','font-variant','font-weight','letter-spacing','line-height','list-style','list-style-image','list-style-position','list-style-type','margin','margin-left','margin-right','margin-top','margin-bottom','opacity','outline','outline-color','outline-style','outline-width','padding','padding-bottom','padding-left','padding-right','padding-top','size','text-align','text-decoration','text-indent','text-transform','white-space','word-spacing'];var css='.cke_editable { ';var current=$(dobrado.current);for(var i=0;i<editorCssProperties.length;i++){var property=editorCssProperties[i];var value=current.css(property);if(value){css+=property+': '+value+';';}}
css+='}';CKEDITOR.addCss(css);var content=$('#writer-content').text();$('#writer-content').val(content);dobrado.editor=CKEDITOR.replace('writer-content',{allowedContent:true,autoGrow_minHeight:$('#writer-content').height(),autoGrow_onStartup:true,disableNativeSpellChecker:false,enterMode:CKEDITOR.ENTER_BR,extraPlugins:'autogrow,extended',filebrowserBrowseUrl:'/php/browse.php',removePlugins:'elementspath,tableselection,tabletools,contextmenu,liststyle',resize_enabled:false,on:{focus:clearContent},toolbar:[['Undo','Redo','-','Bold','Italic','-','Link','Unlink','-','Image','Extended']]});$('.writer-post').button('option','disabled',false);};dobrado.writer.newModuleCallback=function(id,context){var data=dobrado.editor?dobrado.editor.getData():$('#writer-content').val();var enclosure=[];$('#writer-photo-selected > img').each(function(){enclosure.push($(this).attr('src'));});var content={data:data,dataOnly:false,title:$('#writer-title').val(),author:$('#writer-author').val(),category:$('#writer-tag-input').val(),enclosure:JSON.stringify(enclosure),twitter:sendToTwitter,webactionType:webactionType,webactionUrl:webactionUrl};if(context==='post'){$.post('/php/content.php',{id:id,label:'post',content:JSON.stringify(content),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'writer callback')){return;}
var formatted=JSON.parse(response);if(formatted.html){$(id).html(formatted.html);$(id).show();}
if(dobrado.editMode){var element=$(id+" .dobrado-editable").get(0);if(element){dobrado.inlineEditor(element);}}
if(dobrado.editMode){var element=$(id+' .dobrado-editable').get(0);if(element){dobrado.inlineEditor(element);}}
if(dobrado.editor){dobrado.editor.setData(defaultText);}
else{$("#writer-content").val(defaultText);}
hideOptions();removeAction(false);$.post("/php/request.php",{request:"post",action:"updated",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"writer post update")){return;}
var post=JSON.parse(response);if(post.status){setTimeout(function(){dobrado.log(post.status,'info');setTimeout(function(){$(".control .info").hide();},10000);},2000);}});});}
else if(context==="extended"){if(dobrado.reader){dobrado.reader.scrollback(webactionUrl,false);}
dobrado.current=id;$.post("/php/request.php",{id:id,label:'post',content:JSON.stringify(content),request:"extended",mode:"box",notify:false,url:location.href,token:dobrado.token},dobrado.extended.editor);}};dobrado.writer.reset=function(){if($(".writer").length!==0){$("#writer-content").val(defaultText);$(".writer-post").button("option","disabled",true);hideOptions();removeAction(true);}};}());
\ No newline at end of file
else{$('#writer-content').val(defaultText);}
hideOptions();removeAction(false);$.post('/php/request.php',{request:'post',action:'updated',url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'writer post update')){return;}
var post=JSON.parse(response);if(post.status){setTimeout(function(){dobrado.log(post.status,'info');setTimeout(function(){$('.control .info').hide();},10000);},2000);}});});}
else if(context==='extended'){if(dobrado.reader){dobrado.reader.scrollback(webactionUrl,false);}
dobrado.current=id;$.post('/php/request.php',{id:id,label:'post',content:JSON.stringify(content),request:'extended',mode:'box',notify:false,url:location.href,token:dobrado.token},dobrado.extended.editor);}};dobrado.writer.reset=function(){if($('.writer').length!==0){$('#writer-content').val(defaultText);$('.writer-post').button('option','disabled',true);hideOptions();removeAction(true);}};}());
\ No newline at end of file
......@@ -32,7 +32,6 @@ if (!this.dobrado.writer) {
// Set to zero to copy int type used by extended editor to assign values.
var sendToTwitter = 0;
var sendToFacebook = 0;
var webactionType = '';
var webactionUrl = '';
var defaultText = 'Write a new post...';
......@@ -44,59 +43,62 @@ if (!this.dobrado.writer) {
return;
}
$("#writer-content").click(function() {
$('#writer-content').click(function() {
// Extended editor isn't modal so don't allow editor changes when open.
if (!$(".extended").dialog("isOpen")) {
if (!$('.extended').dialog('isOpen')) {
dobrado.writer.showEditor();
}
});
$(".writer-post").button({ disabled: true }).click(function() {
dobrado.log("Creating post...", "info");
dobrado.createModule("writer", "post", "post");
$('.writer-post').button({ disabled: true }).click(function() {
dobrado.log('Creating post...', 'info');
dobrado.createModule('writer', 'post', 'post');
});
$('#writer-author').val(dobrado.readCookie('user'));
$('#writer-title').val('');
$('#writer-tag-input').val('');
$('#writer-tags').checkboxradio({ icon: false }).click(toggleTags);
$('.writer .menu').menu();
$('#writer-photo-browse').button().click(function() {
dobrado.createModule('browser', 'browser', 'writer');
});
$("#writer-author").val(dobrado.readCookie("user"));
$("#writer-title").val("");
$("#writer-tag-input").val("");
$("#writer-tags").checkboxradio({ icon: false }).click(toggleTags);
$(".writer .menu").menu();
// Writer module has a button to toggle reader module's settings.
$(".writer-edit-settings").button({
$('.writer-edit-settings').button({
icon: 'ui-icon-signal-diag', showLabel: false
}).click(function() {
$(".writer .designate").toggle();
$(".reader-settings").toggle();
$('.writer .designate').toggle();
$('.reader-settings').toggle();
});
$('#writer-designate-action').val('post').change(showDesignate);
$(".writer .submit-designate").button().click(designate);
$(".writer .submit-feed-title").button().click(feedTitle);
$(".writer-remove-title").button({
$('.writer .submit-designate').button().click(designate);
$('.writer .submit-feed-title').button().click(feedTitle);
$('.writer-remove-title').button({
icon: 'ui-icon-closethick', showLabel: false
}).click(removeTitle);
$(".writer-remove-author").button({
$('.writer-remove-author').button({
icon: 'ui-icon-closethick', showLabel: false
}).click(removeAuthor);
$(".writer-remove-twitter").button({
$('.writer-remove-twitter').button({
icon: 'ui-icon-closethick', showLabel: false
}).click(removeTwitter);
$(".writer-remove-facebook").button({
$('.writer-remove-photo').button({
icon: 'ui-icon-closethick', showLabel: false
}).click(removeFacebook);
$("#writer-remove-action").button({
}).click(removePhoto);
$('#writer-remove-action').button({
icon: 'ui-icon-closethick', showLabel: false
}).click(removeActionExplicit);
if (dobrado.reader) {
$("#writer-follow").button().click(dobrado.reader.addFeed);
$('#writer-follow').button().click(dobrado.reader.addFeed);
}
// If there are currently no posts on the page, add a post-comment wrapper
// div under the writer module so that new posts are placed correctly.
if ($(".post-comment").length === 0) {
$("<div></div>").addClass("post-comment").appendTo(".writer");
if ($('.post-comment').length === 0) {
$('<div></div>').addClass('post-comment').appendTo('.writer');
}
webactionType = $("#writer-action-type").html();
webactionType = $('#writer-action-type').html();
if (webactionType === 'like' || webactionType === 'reply') {
$('#writer-content').val('');
}
webactionUrl = $("#writer-action-url").attr("href");
webactionUrl = $('#writer-action-url').attr('href');
if (webactionType === 'share') {
shareFullText();
}
......@@ -111,45 +113,41 @@ if (!this.dobrado.writer) {
});
function hideMenu() {
$(".writer-menu-wrapper").hide();
$('.writer-menu-wrapper').hide();
}
function add() {
dobrado.hideOtherMenu("writer-menu-wrapper");
dobrado.toggleMenu("writer-menu-wrapper");
$("body").one("click", hideMenu);
dobrado.hideOtherMenu('writer-menu-wrapper');
dobrado.toggleMenu('writer-menu-wrapper');
$('body').one('click', hideMenu);
return false;
}
function showDesignate() {
var action = $("#writer-designate-action").val();
dobrado.log("Loading page for displaying " + action + ".", "info");
$.post("/php/request.php", { request: "writer",
mode: "showDesignate",
action: action,
url: location.href,
token: dobrado.token },
var action = $('#writer-designate-action').val();
dobrado.log('Loading page for displaying ' + action + '.', 'info');
$.post('/php/request.php',
{ request: 'writer', mode: 'showDesignate', action: action,
url: location.href, token: dobrado.token },
function(response) {
if (dobrado.checkResponseError(response, "writer showDesignate")) {
if (dobrado.checkResponseError(response, 'writer showDesignate')) {
return;
}
var designate = JSON.parse(response);
$("#writer-designate-input").val(designate.page);
$('#writer-designate-input').val(designate.page);
});
return false;
}
function designate() {
var action = $("#writer-designate-action").val();
dobrado.log("Updating page for displaying " + action + ".", "info");
$.post("/php/request.php", { request: "writer",
mode: "designate",
action: action,
designate: $("#writer-designate-input").val(),
url: location.href,
token: dobrado.token },
var action = $('#writer-designate-action').val();
dobrado.log('Updating page for displaying ' + action + '.', 'info');
$.post('/php/request.php',
{ request: 'writer', mode: 'designate', action: action,
designate: $('#writer-designate-input').val(),
url: location.href, token: dobrado.token },
function(response) {
if (dobrado.checkResponseError(response, "writer designate")) {
if (dobrado.checkResponseError(response, 'writer designate')) {
return;
}
});
......@@ -157,14 +155,13 @@ if (!this.dobrado.writer) {