Commit d9a751ee authored by Malcolm Blaney's avatar Malcolm Blaney

Improved feed information shown in Reader module discovery dialog.

Added a default follow user and page to the Start module. Added
some more css resets to create.php. SimplePie discovery will now
push microformats feed to the start of the list.
parent 8ede2d78
Pipeline #36165774 passed with stage
in 1 minute and 12 seconds
......@@ -86,7 +86,8 @@ class Browser extends Base {
if (in_array(strtolower($type), ['gif', 'jpeg', 'jpg', 'png'])) {
$name .= '_thumb.' . $type;
if (file_exists($this->PublicDirectory($name))) {
if (in_array($name, $_SESSION['browser-rotated'])) {
if (isset($_SESSION['browser-rotated']) &&
in_array($name, $_SESSION['browser-rotated'])) {
$updated = '?updated=' . time();
}
$thumbnail = '<img title = "' . $filename . '" ' .
......
......@@ -467,6 +467,8 @@ class Reader extends Base {
'"",".reader-discovered label","float","none"',
'"",".reader-discovered button","margin-top","20px"',
'"",".reader-discovered-add","float","right"',
'"",".reader-discovered-feed-url","color","#aaaaaa"',
'"",".reader-discovered-feed-url","font-size","0.8em"',
'"",".h-card .ui-icon.ui-icon-person","display",' .
'"inline-block"'];
$this->AddSiteStyle($site_style);
......@@ -595,10 +597,18 @@ class Reader extends Base {
$discovered = '<p>Multiple feeds were found on this page.<br>' .
'Please select the ones you would like to subscribe to:</p>';
for ($i = 0; $i < count($all_feeds); $i++) {
$feed_id = 'reader-discovered-feed-' . $i;
// Select the first feed by default.
$checked = $i === 0 ? ' checked="checked"' : '';
$discovered_id = 'reader-discovered-feed-' . $i;
$discovered_url = $all_feeds[$i]->url;
$discovered_title = $this->FeedTitle($all_feeds[$i]->body);
$display = $discovered_title === '' ? $discovered_url :
$discovered_title . ' <span class="reader-discovered-feed-url">[' .
$discovered_url . ']</span>';
$discovered .= '<div class="form-spacing">' .
'<input type="checkbox" id="' . $feed_id . '">' .
'<label for="' . $feed_id . '">' . $all_feeds[$i]->url . '</label>'.
'<input type="checkbox" id="' . $discovered_id . '"' .
'value="' . $discovered_url . '"' . $checked . '>' .
'<label for="' . $discovered_id . '">' . $display . '</label>' .
'</div>';
}
$discovered .= '<button class="reader-discovered-cancel">cancel</button>'.
......@@ -900,6 +910,34 @@ class Reader extends Base {
return $content;
}
private function FeedTitle($content) {
// First try parsing content for microformats.
$h_feed = [];
$mf = Mf2\parse($content);
foreach ($mf['items'] as $mf_item) {
if (!isset($mf_item['type'])) continue;
if (in_array('h-feed', $mf_item['type'])) {
$h_feed = $mf_item;
break;
}
if (isset($mf_item['children'][0]['type']) &&
in_array('h-feed', $mf_item['children'][0]['type'])) {
$h_feed = $mf_item['children'][0];
break;
}
}
if (isset($h_feed['properties']['name'][0])) {
return $h_feed['properties']['name'][0];
}
// Otherwise try parsing as xml.
$xml = simplexml_load_string($content);
if (isset($xml->channel->title)) return $xml->channel->title;
return '';
}
private function Following($target) {
$following = false;
$target = trim($target, ' /');
......
......@@ -220,14 +220,14 @@ class Start extends Base {
private function PageCreated($page) {
$created = true;
$mysqli = connect_db();
$query = 'SELECT box_id FROM modules WHERE user = "'.$this->owner.'" '.
'AND page = "'.$page.'"';
$query = 'SELECT box_id FROM modules WHERE user = "' . $this->owner . '" ' .
'AND page = "' . $page . '"';
if ($result = $mysqli->query($query)) {
$created = $result->num_rows !== 0;
$result->close();
}
else {
$this->Log('Start->PageCreated: '.$mysqli->error);
$this->Log('Start->PageCreated: ' . $mysqli->error);
}
$mysqli->close();
return $created;
......@@ -315,10 +315,19 @@ class Start extends Base {
}
$mysqli->close();
if ($id !== 0) {
$xml_url = $this->user->config->Secure() ? 'https://' : 'http://';
$xml_url .= $this->user->config->ServerName() . '/' .
$this->user->name . '/index.php?page=blog';
$reader->Factory('AddFeed', [$id, $xml_url, true]);
$scheme = $this->user->config->Secure() ? 'https://' : 'http://';
$server = $this->user->config->ServerName();
$feed = $scheme . $server .
$this->Url('', 'blog', $this->user->name);
$reader->Factory('AddFeed', [$id, $feed, true]);
// Also add a default follow for this server if set.
$follow_user = $this->Substitute('start-follow-user');
$follow_page = $this->Substitute('start-follow-page');
if ($follow_user !== '' && $follow_page !== '') {
$feed = $scheme . $server .
$this->Url('', $follow_page, $follow_user);
$reader->Factory('AddFeed', [$id, $feed, true]);
}
}
}
}
......
......@@ -32,9 +32,9 @@ if(pageChanged||($(window).scrollTop()<200&&elapsed>tenMinutes)){reset(true);}
else{if($('.reader-settings .feed-item').length<=5){$('.writer .designate').show();$('.reader-settings').show();}
newFeedEvents();dobrado.notify('feed',dobrado.reader.update);}});function feedSettings(){$('#reader-feed-input').keypress(function(event){if(event.keyCode!==13){return;}
event.preventDefault();dobrado.reader.addFeed();});$('.reader-add-feed').button().click(dobrado.reader.addFeed);$('.remove-feed-item').button({icon:'ui-icon-closethick',showLabel:false}).click(removeFeed);$('#reader-toggle-import').checkboxradio({icon:false}).click(function(){$('#reader-file-import').parent().toggle();});$('#reader-file-import').change(importFile);if($('.feed-text.added').length!==0){$('.feed-text.added').get(0).scrollIntoView();setTimeout(function(){$('.feed-text.added').removeClass('added');},5000);}}
function importFile(){function addImportedFeed(){var xmlUrl=importList[importCount].xmlUrl;var last=importCount===importList.length-1;var text='<br><span class="reader-imported-feed-'+importCount+'">Adding: <b>'+importList[importCount].title+'</b> (<a href="'+
function importFile(){function addImportedFeed(){var xmlUrl=importList[importCount].xmlUrl;var last=importCount===importList.length-1;var text='<br><span class="reader-imported-feed-'+importCount+'">Adding: <b>'+importList[importCount].title+'</b> <span class="reader-discovered-feed-url">[<a href="'+
importList[importCount].htmlUrl+'">'+
importList[importCount].htmlUrl+'</a>) ... </span>';$('.reader-discovered').append(text);$.post('/php/request.php',{id:'#'+$('.reader').attr('id'),request:'reader',action:'addImport',last:last,force:true,xmlUrl:xmlUrl,url:location.href,token:dobrado.token},function(response){if(!response){dobrado.log('No response to reader addImport call.','error');return;}
importList[importCount].htmlUrl+'</a>]</span> ... </span>';$('.reader-discovered').append(text);$.post('/php/request.php',{id:'#'+$('.reader').attr('id'),request:'reader',action:'addImport',last:last,force:true,xmlUrl:xmlUrl,url:location.href,token:dobrado.token},function(response){if(!response){dobrado.log('No response to reader addImport call.','error');return;}
var reader=JSON.parse(response);if(!reader){dobrado.log('Cannot interpret response to reader addImport call.','error');return;}
if(reader.done){$('.reader-discovered').append('ok');}
if(reader.error){$('.reader-discovered').append('<i>'+reader.error+'</i>');}
......@@ -86,10 +86,10 @@ if(reader.settings){$('.reader-settings').html(reader.settings);feedSettings();}
if($('.reader-settings .feed-item').length<=5){$('.writer .designate').show();$('.reader-settings').show();}
newFeedEvents();if(dobrado.localStorage){localStorage.reader=reader.content;localStorage.readerUpdate=update;localStorage.readerPage=location.href;}
if(notify){dobrado.notify('feed',dobrado.reader.update);}});}
dobrado.reader.addFeed=function(xmlUrl,force,multiple){function addDiscoveredFeed(){var discovered=[];$('.reader-discovered input:checked').each(function(index){discovered.push($(this).siblings('label').text());});if(discovered.length===1){dobrado.reader.addFeed(discovered[0],true);}
dobrado.reader.addFeed=function(xmlUrl,force,multiple){function addDiscoveredFeed(){var discovered=[];$('.reader-discovered input:checked').each(function(index){discovered.push($(this).val());});if(discovered.length===1){dobrado.reader.addFeed(discovered[0],true);}
else if(discovered.length>1){dobrado.reader.addFeed(JSON.stringify(discovered),true,true);}}
dobrado.log('Adding feed...','info');if(!force){xmlUrl=$('#reader-feed-input').val();}
var action=multiple?'addMultiple':'add';$.post('/php/request.php',{id:'#'+$('.reader').attr('id'),request:'reader',action:action,xmlUrl:xmlUrl,force:force,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'reader addFeed')){return;}
if(!force){xmlUrl=$('#reader-feed-input').val();}
if(xmlUrl==='')return;dobrado.log('Adding feed...','info');var action=multiple?'addMultiple':'add';$.post('/php/request.php',{id:'#'+$('.reader').attr('id'),request:'reader',action:action,xmlUrl:xmlUrl,force:force,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'reader addFeed')){return;}
$('#writer-webaction-info').html('');var reader=JSON.parse(response);if(reader.discovered){$('.reader-discovered').html(reader.discovered).dialog('open');$('.reader-discovered-cancel').button().click(function(){$('.reader-discovered').dialog('close');});$('.reader-discovered-add').button().click(addDiscoveredFeed);return;}
if($('.reader-discovered').dialog('isOpen')){$('.reader-discovered').dialog('close');}
if(reader.content){$('.reader-content').html(reader.content);}
......
......@@ -137,18 +137,15 @@ if (!this.dobrado.reader) {
var xmlUrl = importList[importCount].xmlUrl;
var last = importCount === importList.length - 1;
var text = '<br><span class="reader-imported-feed-' + importCount +
'">Adding: <b>' + importList[importCount].title + '</b> (<a href="' +
importList[importCount].htmlUrl + '">' +
importList[importCount].htmlUrl + '</a>) ... </span>';
'">Adding: <b>' + importList[importCount].title +
'</b> <span class="reader-discovered-feed-url">[<a href="' +
importList[importCount].htmlUrl + '">' +
importList[importCount].htmlUrl + '</a>]</span> ... </span>';
$('.reader-discovered').append(text);
$.post('/php/request.php', { id: '#' + $('.reader').attr('id'),
request : 'reader',
action: 'addImport',
last: last,
force: true,
xmlUrl: xmlUrl,
url: location.href,
token: dobrado.token },
$.post('/php/request.php',
{ id: '#' + $('.reader').attr('id'), request : 'reader',
action: 'addImport', last: last, force: true, xmlUrl: xmlUrl,
url: location.href, token: dobrado.token },
function(response) {
// Handle our own errors here so we can display them in the dialog.
if (!response) {
......@@ -311,12 +308,10 @@ if (!this.dobrado.reader) {
function removeFeed() {
dobrado.log('Removing feed...', 'info');
$.post('/php/request.php', { id: '#' + $('.reader').attr('id'),
request : 'reader',
action: 'remove',
xmlUrl: $(this).siblings('a').prop('href'),
url: location.href,
token: dobrado.token },
$.post('/php/request.php',
{ id: '#' + $('.reader').attr('id'), request : 'reader',
action: 'remove', xmlUrl: $(this).siblings('a').prop('href'),
url: location.href, token: dobrado.token },
function(response) {
if (dobrado.checkResponseError(response, 'reader remove')) {
return;
......@@ -353,12 +348,10 @@ if (!this.dobrado.reader) {
// if a message isn't currently shown.
dobrado.log('Checking reader updates...', 'info');
}
$.post('/php/request.php', { id: '#' + $('.reader').attr('id'),
request: 'reader',
update: update,
action: action,
url: location.href,
token: dobrado.token },
$.post('/php/request.php',
{ id: '#' + $('.reader').attr('id'), request: 'reader',
update: update, action: action,
url: location.href, token: dobrado.token },
function(response) {
if (dobrado.checkResponseError(response, 'reader ' + update)) {
return;
......@@ -413,11 +406,9 @@ if (!this.dobrado.reader) {
dobrado.log('Loading feeds...', 'info');
// Remove old content so the change doesn't flash on load.
$('.reader-content').html('');
$.post('/php/request.php', { id: '#' + $('.reader').attr('id'),
request: 'reader',
action: 'reset',
url: location.href,
token: dobrado.token },
$.post('/php/request.php',
{ id: '#' + $('.reader').attr('id'), request: 'reader',
action: 'reset', url: location.href, token: dobrado.token },
function(response) {
if (dobrado.checkResponseError(response, 'reader reset')) {
return;
......@@ -463,7 +454,7 @@ if (!this.dobrado.reader) {
function addDiscoveredFeed() {
var discovered = [];
$('.reader-discovered input:checked').each(function(index) {
discovered.push($(this).siblings('label').text());
discovered.push($(this).val());
});
if (discovered.length === 1) {
dobrado.reader.addFeed(discovered[0], true);
......@@ -473,20 +464,19 @@ if (!this.dobrado.reader) {
}
}
dobrado.log('Adding feed...', 'info');
// Need to set xmlUrl if not called from addDiscovered feed, otherwise the
// parameter is assigned the click event data.
if (!force) {
xmlUrl = $('#reader-feed-input').val();
}
if (xmlUrl === '') return;
dobrado.log('Adding feed...', 'info');
var action = multiple ? 'addMultiple' : 'add';
$.post('/php/request.php', { id: '#' + $('.reader').attr('id'),
request : 'reader',
action: action,
xmlUrl: xmlUrl,
force: force,
url: location.href,
token: dobrado.token },
$.post('/php/request.php',
{ id: '#' + $('.reader').attr('id'), request : 'reader',
action: action, xmlUrl: xmlUrl, force: force,
url: location.href, token: dobrado.token },
function(response) {
if (dobrado.checkResponseError(response, 'reader addFeed')) {
return;
......
......@@ -352,9 +352,14 @@ function create_site_style() {
'"","img","max-width","100%"',
'"","img","height","auto"',
'"","img","border-style","none"',
'"",".photo-hidden img","display","none"',
'"",".photo-list img","width","45%"',
'"",".photo-list img","margin-right","10px"',
'"","input[type=text]","padding","4px"',
'"","input[type=text]","border","1px solid #aaaaaa"',
'"","input[type=text]","border-radius","3px"',
'"","input[type=text]:focus","border-color","#32a3cf"',
'"","input[type=password]","padding","4px"',
'"","input[type=password]","border","1px solid #aaaaaa"',
'"","input[type=password]","border-radius","3px"',
'"","input[type=password]:focus","border-color","#32a3cf"',
'"",".form-spacing","margin-top","4px"',
'"",".form-spacing","margin-bottom","4px"',
'"",".form-spacing","clear","both"',
......@@ -401,6 +406,9 @@ function create_site_style() {
'"background-image","url(\"/images/extended.png\")"',
'"",".cke_skin_kama a.cke_button_extended .cke_icon",' .
'"background-position","center"',
'"",".photo-hidden img","display","none"',
'"",".photo-list img","width","45%"',
'"",".photo-list img","margin-right","10px"',
'"",".ui-sortable-placeholder","height","50px"',
'"",".ui-sortable-placeholder","border",' .
'"4px dashed #828282"',
......
......@@ -1670,10 +1670,10 @@ class SimplePie
$self = $locate->get_rel_link('self');
$this->store_links($file, $hub, $self);
}
// Push the current file onto all_discovered feeds so the user can
// be shown this as one of the options.
// Push the current file onto the front of all_discovered feeds so
// the user can be shown this as the first option.
if (isset($this->all_discovered_feeds)) {
$this->all_discovered_feeds[] = $file;
array_unshift($this->all_discovered_feeds, $file);
}
}
else
......
......@@ -170,7 +170,8 @@ class Extended extends Base {
// The module is added for the 'admin' user here, for all other
// users it is added when their account is created.
$this->AddToAdmin('extended');
$site_style = ['"",".style-rule","margin","0.3em"',
$site_style = ['"",".style-editor .form-spacing","margin-top","0"',
'"",".style-rule","margin","0.3em"',
'"",".style-rule input[type=text]","height","25px"',
'"",".style-rule input[type=text]","width","200px"',
'"",".style-property","color","#828282"',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment