Commit f4f99559 authored by  JosephK's avatar JosephK

Intégration à la Framanav et mini accueil dans le bookmarklet

parent a54c5d1d
<?php
// remplacer http par https
define('URL_BASE', str_replace($_SERVER['DOCUMENT_ROOT'], 'http://'.$_SERVER['HTTP_HOST'], dirname($_SERVER['SCRIPT_FILENAME'])) );
define('TITLE', 'MyFrama');
......@@ -133,9 +132,32 @@ function create_account($account, $password, $email) {
);
writeConfig($GLOBALS, true, $account_path . '/data/config.php');
//------------------------------------------------------------------
}
//------------------------------------------------------------------
// ~~~~~~~~~~~~~~~~~~~~~~ 1. Bookmarklet ~~~~~~~~~~~~~~~~~~~~~~~~~~~
function encodeURIComponent($str) {
$revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
return strtr(rawurlencode($str), $revert);
}
$bm_src= ''; $bm_post = '';
if (isset($_GET['source']) && $_GET['source']=='bookmarklet') {
$bm_src = '&source=bookmarklet';
if (isset($_GET['post'])) {
$bm_url = encodeURIComponent($_GET['post']);
$bm_title = isset($_GET['title']) ? encodeURIComponent($_GET['title']) : '';
$bm_description = isset($_GET['description']) ? encodeURIComponent($_GET['description']) : '';
$bm_post = '&post='.$bm_url.'&title='.$bm_title.'&description='.$bm_description;
}
if(isset($_COOKIE['myframa']) && !empty($_COOKIE['myframa'])) {
$account = $_COOKIE['myframa'];
header('Location: u/' . $account . '?'.$bm_post.$bm_src);
}
}
// ~~~~~~~~~~~~~~~~~~~~~~ 2. Account ~~~~~~~~~~~~~~~~~~~~~~~~~~~
$test_values = true;
if (!is_writable(PATH_ACCOUNTS)) {
......@@ -145,7 +167,10 @@ if (!is_writable(PATH_ACCOUNTS)) {
// Handle account redirection.
$account = strtolower($_POST['subdomain_redirect']);
if (check_account_exists($account)) {
header('Location: u/' . $account . '?do=login' );
// Keep user account in a cookie
setcookie('myframa', $account, time()+365*24*60*60, dirname($_SERVER["SCRIPT_NAME"]).'/');
// Redirection
header('Location: u/' . $account . '?do=login'.$bm_post.$bm_src );
} else {
$error_redirection = 'Ce compte ne semble pas exister. Êtes-vous sûr du nom de votre compte&nbsp;?';
}
......@@ -182,14 +207,16 @@ if (!is_writable(PATH_ACCOUNTS)) {
$error = 'Ce compte semble déjà exister, veuillez choisir un autre nom de compte.';
$test_values = 'account';
} elseif (is_null($error)) {
// Everything is fine, we can redirect user to its new board!
header('Location: u/' . $account . '?do=login&username=' . $account . '&r');
// Keep user account in a cookie
setcookie('myframa', $account, time()+365*24*60*60, dirname($_SERVER["SCRIPT_NAME"]).'/');
// Everything is fine, we can redirect user to its new account!
header('Location: u/' . $account . '?do=login&first'.$bm_post.$bm_src);
}
}
// Tempfix redirect on shaarli's home when user logged in
if(isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], '?do=login')) {
header('Location: '.str_replace('?do=login', '', $_SERVER['HTTP_REFERER']));
header('Location: '.str_replace('?do=login', '?', $_SERVER['HTTP_REFERER']));
}
include 'layout.php';
This diff is collapsed.
......@@ -3,5 +3,10 @@
$t['Hide links descriptions'] = 'Masquer la description des liens';
$t['Show links descriptions'] = 'Afficher la description des liens';
$t['Close'] = 'Fermer';
$t['Cancel'] = 'Annuler';
$t['Your account has been successfully created. You can sign in now.'] = 'Votre compte MyFrama a bien été créé. Vous pouvez à présent vous y connecter.';
$t['Add this link'] = 'Ajouter ce lien';
$t['Edit this link'] = 'Modifier ce lien';
$t['See all my links'] = 'Voir tous mes liens';
$t['or'] = 'ou';
?>
\ No newline at end of file
......@@ -61,14 +61,51 @@ jQuery(document).ready(function(){
jQuery('#i18n, #myframa, #recovery, #tags_advanced').attr('disabled', 'true');
}
if(/\&source\=bookmarklet/i.test(window.location.href)) {
jQuery('#editlinkform').hide();
var editbtn = (jQuery('#editlink[name="delete_link"]').length == 1)
? '<?php echo t('Add this link');?>'
: '<?php echo t('Edit this link');?>';
var editlink = (jQuery('#lf_url').val().length > 40)
? jQuery('#lf_url').val().substring(0, 40)+'…'
: jQuery('#lf_url').val();
jQuery('#editlinkform').before(
'<div class="row" id="choose">'+
'<div class="col-md-12 text-center">'+
'<p class="text-center"><a href="javascript:void(0)" class="btn btn-warning btn-lg btn-block">'+
'<i class="fa fa-fw fa-star"></i> '+editbtn+
'<br><small>'+editlink+'</small>'+
'</a></p>'+
'<p><?php echo t('or');?></p>'+
'<p><a href="javascript:void(0)" class="btn btn-primary btn-lg btn-block">'+
'<i class="fa fa-fw fa-link"></i> <?php echo t('See all my links');?>'+
'</a></p>'+
'</div>'+
'</div>'
);
jQuery('#choose .btn-warning').on('click', function() {
jQuery('#choose').hide();
jQuery('#editlinkform').show();
});
jQuery('#choose .btn-primary').on('click', function() {
window.open(window.location.href.split('?')[0]);
self.close();
});
}
// Login MyFrama
if(/do=login/i.test(window.location.href)) {
// After registration
if(/do=login\&r/i.test(window.location.href)) {
if(/do=login\&first/i.test(window.location.href)) {
jQuery('#loginform').prepend('<div class="alert alert-info text-center"><button type="button" class="close" data-dismiss="alert" aria-label="<?php echo t('Close'); ?>"><span aria-hidden="true">&times;</span></button><b><?php echo t('Your account has been successfully created. You can sign in now.'); ?></b></div>');
jQuery('[name="returnurl"]').val('');
}
if(/\&source\=bookmarklet/i.test(window.location.href)) {
jQuery('.btn-success').before('<button class="btn btn-default pull-left" type="button" onclick="self.close();"><?php echo t('Cancel');?></button>');
}
<?php
if($GLOBALS['login'] == $account[count($account)-1]) {
echo "
......
<!DOCTYPE html>
<html>
<html {if="!empty($_GET['source']) && $_GET['source']=='bookmarklet'"}class="bookmarklet"{/if}>
<head>{include="includes"}
<link type="text/css" rel="stylesheet" href="../../inc/awesomplete.css" />
</head>
<body
{if="$link.title==''"}onload="document.linkform.lf_title.focus();"
{elseif="$link.description==''"}onload="document.linkform.lf_description.focus();"
{else}onload="document.linkform.lf_tags.focus();"{/if} >
{else}onload="document.linkform.lf_tags.focus();"{/if}
>
<div id="pageheader" class="row">
{if="$source !== 'firefoxsocialapi'"}
{include="page.header"}
......@@ -34,7 +35,7 @@
<p class="text-right">
<input type="submit" value="{'Save'|t}" name="save_edit" class="btn btn-success">
<input type="submit" value="{'Cancel'|t}" name="cancel_edit" class="btn btn-default">
<input type="submit" value="{'Cancel'|t}" name="cancel_edit" class="btn btn-default pull-left">
{if="!$link_is_new"}<input type="submit" value="{'Delete'|t}" name="delete_link" class="btn btn-danger" onClick="return confirmDeleteLink();">{/if}
<input type="hidden" name="token" value="{$token}">
{if="$http_referer"}<input type="hidden" name="returnurl" value="{$http_referer}">{/if}
......
......@@ -992,7 +992,7 @@ cite {
/************
* MyFrama *
************/
html, body {
html,body {
background: #eee;
}
......@@ -1304,4 +1304,39 @@ a.link-url:hover{ color: #333; }
/* Plugins admin */
#pluginsadmin {
padding-bottom:20px;
}
/* Bookmarklet */
html.bookmarklet,
html.bookmarklet body {
background: #fff;
}
.bookmarklet .ombre {
box-shadow:none;
}
.bookmarklet .home .ombre {
margin:0 auto;
}
.bookmarklet .home #registration,
.bookmarklet .home #login {
display:none;
}
.bookmarklet .row {
margin:0;
}
.bookmarklet #editlinkform {
padding-top:10px;
padding-bottom:0px;
}
.bookmarklet .home #registration h2,
.bookmarklet .home #login h2 {
text-align: center;
}
.bookmarklet #choose {
margin-top:20%;
}
\ No newline at end of file
jQuery(document).ready(function(){
// Bouton afficher/masquer la description
if(/do=daily|login/i.test(window.location.href) || !(/=/i.test(window.location.href))) {
jQuery('.sl-menu .list-inline.pull-right').prepend(
'<li><a id="descToggle" href="javascript:void(0);" title="Hide links descriptions">'+
'<i class="fa fa-fw fa-lg fa-toggle-on"></i><span class="sr-only">Hide links descriptions</span>'+
'</a></li>'
);
jQuery('#descToggle').click(
function(){
if(jQuery(this).children('i').hasClass('fa-toggle-on')) {
jQuery('.link-description').hide();
jQuery('#descToggle').attr('title', 'Show links descriptions');
jQuery('#descToggle').children('i').addClass('fa-toggle-off').removeClass('fa-toggle-on');
jQuery('#descToggle').children('.sr-only').text('Show links descriptions');
} else {
jQuery('.link-description').show();
jQuery('#descToggle').attr('title', 'Hide links descriptions');
jQuery('#descToggle').children('i').removeClass('fa-toggle-off').addClass('fa-toggle-on');
jQuery('#descToggle').children('.sr-only').text('Hide links descriptions');
}
}
);
}
// Mise en forme addlink_toolbar
jQuery('#addlink_toolbar form')
.wrapInner('<div class="input-group"></div>')
.addClass('col-sm-8 col-sm-offset-2');
jQuery('#addlink_toolbar input[type="submit"]')
.after(
'<span class="input-group-btn"><button class="btn btn-default" value="'+jQuery('.navbar a[href="?do=addlink"]').text()+'" type="submit">'+
'<i class="fa fa-fw fa-lg fa-plus text-success"></i> '+jQuery('.navbar a[href="?do=addlink"]').text()+
'</button></span>')
.remove();
jQuery('#addlink_toolbar input[type="text"]')
.addClass('form-control')
.attr('placeholder','http(s)://…');
if(/do=addlink|login/i.test(window.location.href) || !(/=/i.test(window.location.href))) {
jQuery('.navbar a[href="?do=addlink"]').parent().hide();
}
});
\ No newline at end of file
<?php
// Pré-remplissage Login
require_once str_replace('/tpl/frama/inc', '', dirname($_SERVER['SCRIPT_FILENAME'])) . '/data/config.php';
$account = explode('/', str_replace('/tpl/frama/inc', '', dirname($_SERVER['SCRIPT_FILENAME'])));
?>
jQuery(document).ready(function(){
// Bouton afficher/masquer la description
if(/do=daily|login/i.test(window.location.href) || !(/=/i.test(window.location.href))) {
jQuery('.sl-menu .list-inline.pull-right').prepend(
'<li><a id="descToggle" href="javascript:void(0);" title="Hide links descriptions">'+
'<i class="fa fa-fw fa-lg fa-toggle-on"></i><span class="sr-only">Hide links descriptions</span>'+
'</a></li>'
);
jQuery('#descToggle').click(
function(){
if(jQuery(this).children('i').hasClass('fa-toggle-on')) {
jQuery('.link-description').hide();
jQuery('#descToggle').attr('title', 'Show links descriptions');
jQuery('#descToggle').children('i').addClass('fa-toggle-off').removeClass('fa-toggle-on');
jQuery('#descToggle').children('.sr-only').text('Show links descriptions');
} else {
jQuery('.link-description').show();
jQuery('#descToggle').attr('title', 'Hide links descriptions');
jQuery('#descToggle').children('i').removeClass('fa-toggle-off').addClass('fa-toggle-on');
jQuery('#descToggle').children('.sr-only').text('Hide links descriptions');
}
}
);
}
// Mise en forme addlink_toolbar
jQuery('#addlink_toolbar form')
.wrapInner('<div class="input-group"></div>')
.addClass('col-sm-8 col-sm-offset-2');
jQuery('#addlink_toolbar input[type="submit"]')
.after(
'<span class="input-group-btn"><button class="btn btn-default" value="'+jQuery('.navbar a[href="?do=addlink"]').text()+'" type="submit">'+
'<i class="fa fa-fw fa-lg fa-plus text-success"></i> '+jQuery('.navbar a[href="?do=addlink"]').text()+
'</button></span>')
.remove();
jQuery('#addlink_toolbar input[type="text"]')
.addClass('form-control')
.attr('placeholder','http(s)://…');
if(/do=addlink|login/i.test(window.location.href) || !(/=/i.test(window.location.href))) {
jQuery('.navbar a[href="?do=addlink"]').parent().hide();
}
// Login MyFrama
if(/do=login/i.test(window.location.href)) {
// After registration
if(/do=login\&r/i.test(window.location.href)) {
jQuery('#loginform').prepend('<div class="alert alert-info text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><b>Votre compte MyFrama a bien été créé. Vous pouvez à présent vous y connecter.</b></div>');
jQuery('[name="returnurl"]').val('');
}
<?php
if($GLOBALS['login'] == $account[count($account)-1]) {
echo "
jQuery('#login').val('".$GLOBALS['login']."');";
}
?>
}
});
<!DOCTYPE html>
<html>
<html {if="!empty($_GET['source']) && $_GET['source']=='bookmarklet'"}class="bookmarklet"{/if}>
<head>{include="includes"}</head>
<body
{if="ban_canLogin()"}
......@@ -8,7 +8,8 @@
{else}
onload="document.loginform.password.focus();"
{/if}
{/if}>
{/if}
>
<div id="pageheader">
{include="page.header"}
</div>
......
{if="empty($_GET['source'])"}
<div id="footer" class="container text-center">
<strong><a href="https://github.com/shaarli/Shaarli">{'Shaarli'|t}</a></strong> - {'The personal, minimalist, super-fast, database free, bookmarking service<br>by the Shaarli community'|t} - <a href="doc/Home.html" rel="nofollow">{'Help/documentation'|t}</a>
{loop="$plugins_footer.text"}
{$value}
{/loop}
</div>
{/if}
{loop="$plugins_footer.endofpage"}
{$value}
......
<?php
setcookie("test_cookie", "test", time() + 3600, '/');
?>
<html>
<body>
<?php
if(count($_COOKIE) > 0) {
echo "Cookies are enabled.";
} else {
echo "Cookies are disabled.";
}
setcookie('myframa', 'test', time()+365*24*60*60, dirname($_SERVER["SCRIPT_NAME"]).'/');
print_r($_COOKIE);
?>
</body>
</html>
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