From ba0718dcd43ecb44e80d65307ed4d2dfda24c0b9 Mon Sep 17 00:00:00 2001 From: Seb Sauvage Date: Mon, 26 Sep 2011 17:36:42 +0200 Subject: Version 0.0.18 beta: - Changed: Nicer timezone selection patch by killruana. - New: You can now configure the title of your page. - New: New screen to configure title and timezone. - Corrected: New lines now appear correctly in the RSS feed descriptions. --- index.php | 202 +++++++++++++++++++++++++++++++++++++++++++++++------------- shaarli.css | 2 + 2 files changed, 162 insertions(+), 42 deletions(-) diff --git a/index.php b/index.php index af76ed9b..15582051 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,5 @@ '; - echo 'Shared links on '.$pageaddr.''.$pageaddr.''; + echo ''.htmlspecialchars($GLOBALS['title']).''.$pageaddr.''; echo 'Shared links'.$pageaddr.''."\n\n"; $i=0; $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys(). @@ -577,7 +580,7 @@ function showRSS() $rfc822date = linkdate2rfc822($link['linkdate']); echo ''.htmlspecialchars($link['title']).''.htmlspecialchars($link['url']).''.htmlspecialchars($link['url']).''; if (!HIDE_TIMESTAMPS || isLoggedIn()) echo ''.htmlspecialchars($rfc822date).''; - echo ''."\n"; + echo ''."\n"; $i++; } echo ''; @@ -703,7 +706,7 @@ HTML; $onload = 'onload="document.searchform.searchterm.focus();"'; $data = array('pageheader'=>$searchform,'body'=>templateLinkList(),'onload'=>$onload); templatePage($data); - exit; // Never remove this one ! + exit; // Never remove this one ! All operations below are reserved for logged in user. } // -------- All other functions are reserved for the registered user: @@ -717,6 +720,7 @@ HTML; $toolbar= <<
{$changepwd} + Configure your Shaarli - Change Title, timezone...

Rename/delete tags - Rename or delete a tag in all links.

Import - Import Netscape html bookmarks (as exported from Firefox, Chrome, Opera, delicious...)

Export - Export Netscape html bookmarks (which can be imported in Firefox, Chrome, Opera, delicious...)

@@ -739,16 +743,10 @@ HTML; // Make sure old password is correct. $oldhash = sha1($_POST['oldpassword'].$GLOBALS['login'].$GLOBALS['salt']); if ($oldhash!=$GLOBALS['hash']) { echo ''; exit; } - // Save new password - $salt=sha1(uniqid('',true).'_'.mt_rand()); // Salt renders rainbow-tables attacks useless. - $hash = sha1($_POST['setpassword'].$GLOBALS['login'].$salt); - $config=''; - if (!file_put_contents(CONFIG_FILE,$config) || strcmp(file_get_contents(CONFIG_FILE),$config)!=0) - { - echo ''; - exit; - } + $GLOBALS['salt'] = sha1(uniqid('',true).'_'.mt_rand()); // Salt renders rainbow-tables attacks useless. + $GLOBALS['hash'] = sha1($_POST['setpassword'].$GLOBALS['login'].$GLOBALS['salt']); + writeConfig(); echo ''; exit; } @@ -767,6 +765,43 @@ HTML; exit; } } + + // -------- User wants to change configuration + if (startswith($_SERVER["QUERY_STRING"],'do=configure')) + { + if (!empty($_POST['title']) ) + { + if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away ! + $tz = 'UTC'; + if (!empty($_POST['continent']) && !empty($_POST['city'])) + if (isTZvalid($_POST['continent'],$_POST['city'])) + $tz = $_POST['continent'].'/'.$_POST['city']; + $GLOBALS['timezone'] = $tz; + $GLOBALS['title']=$_POST['title']; + writeConfig(); + echo ''; + exit; + } + else + { + $token = getToken(); + $title = htmlspecialchars( empty($GLOBALS['title']) ? '' : $GLOBALS['title'] , ENT_QUOTES); + list($timezone_form,$timezone_js) = templateTZform($GLOBALS['timezone']); + $timezone_html=''; if ($timezone_form!='') $timezone_html='Timezone:'.$timezone_form.''; + $changepwdform= << + + +{$timezone_html} + +
Page title:
+ +HTML; + $data = array('pageheader'=>$changepwdform,'body'=>'','onload'=>'onload="document.configform.title.focus();"'); + templatePage($data); + exit; + } + } // -------- User wants to rename a tag or delete it if (startswith($_SERVER["QUERY_STRING"],'do=changetag')) @@ -838,9 +873,10 @@ HTML; if (isset($_POST['save_edit'])) { if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away ! + $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces. $linkdate=$_POST['lf_linkdate']; $link = array('title'=>trim($_POST['lf_title']),'url'=>trim($_POST['lf_url']),'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0), - 'linkdate'=>$linkdate,'tags'=>trim($_POST['lf_tags'])); + 'linkdate'=>$linkdate,'tags'=>$tags); if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title. $LINKSDB[$linkdate] = $link; $LINKSDB->savedb(); // save to disk @@ -1252,17 +1288,18 @@ JS; if (!empty($_GET['searchtags'])) $feedurl.='&searchtags='.$_GET['searchtags']; elseif (!empty($_GET['searchterm'])) $feedurl.='&searchterm='.$_GET['searchterm']; + $title = htmlspecialchars( $GLOBALS['title'] ); echo << -{$open}Shaarli - Let's shaare your links... +{$title} {$jsincludes} {$newversion} @@ -1285,39 +1322,104 @@ function install() if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) { - $tz=(empty($_POST['settimezone']) ? 'UTC':$_POST['settimezone']); + $tz = 'UTC'; + if (!empty($_POST['continent']) && !empty($_POST['city'])) + if (isTZvalid($_POST['continent'],$_POST['city'])) + $tz = $_POST['continent'].'/'.$_POST['city']; + $GLOBALS['timezone'] = $tz; // Everything is ok, let's create config file. - $salt=sha1(uniqid('',true).'_'.mt_rand()); // Salt renders rainbow-tables attacks useless. - $hash = sha1($_POST['setpassword'].$_POST['setlogin'].$salt); - $config=''; - if (!file_put_contents(CONFIG_FILE,$config) || strcmp(file_get_contents(CONFIG_FILE),$config)!=0) - { - echo ''; - exit; - } + $GLOBALS['login'] = $_POST['setlogin']; + $GLOBALS['salt'] = sha1(uniqid('',true).'_'.mt_rand()); // Salt renders rainbow-tables attacks useless. + $GLOBALS['hash'] = sha1($_POST['setpassword'].$GLOBALS['login'].$GLOBALS['salt']); + $GLOBALS['title'] = (empty($_POST['title']) ? 'Shared links on '.htmlspecialchars(serverUrl().$_SERVER['SCRIPT_NAME']) : $_POST['title'] ); + writeConfig(); echo ''; exit; - } - // Display config form: - $timezoneselect=''; - if (function_exists('timezone_identifiers_list')) // because of old php version (5.1) which can be found on free.fr - { - $timezones=''; - foreach(timezone_identifiers_list() as $tz) $timezones.='\n"; - $timezoneselect='Timezone:

'; } + + // Display config form: + list($timezone_form,$timezone_js) = templateTZform(); + $timezone_html=''; if ($timezone_form!='') $timezone_html='Timezone:'.$timezone_form.''; echo <<Shaarli - Configuration -

Shaarli - Shaare your links...

-It looks like it's the first time you run Shaarli. Please chose a login/password and a timezone:
-
-Login:

Password:

-{$timezoneselect} -
+Shaarli - Configuration${timezone_js} +

Shaarli - Shaare your links...

+It looks like it's the first time you run Shaarli. Please configure it:
+
+ + + +{$timezone_html} + + +
Login:
Password:
Page title:
+
HTML; exit; } +// Generates the timezone selection form and javascript. +// Input: (optional) current timezone (can be 'UTC/UTC'). It will be pre-selected. +// Output: array(html,js) +// Example: list($htmlform,$js) = templateTZform('Europe/Paris'); // Europe/Paris pre-selected. +// Returns array('','') if server does not support timezones list. (eg. php 5.1 on free.fr) +function templateTZform($ptz=false) +{ + if (function_exists('timezone_identifiers_list')) // because of old php version (5.1) which can be found on free.fr + { + // Try to split the provided timezone. + if ($ptz==false) { $l=timezone_identifiers_list(); $ptz=$l[0]; } + $spos=strpos($ptz,'/'); $pcontinent=substr($ptz,0,$spos); $pcity=substr($ptz,$spos+1); + + // Display config form: + $timezone_form = ''; + $timezone_js = ''; + // The list is in the forme "Europe/Paris", "America/Argentina/Buenos_Aires"... + // We split the list in continents/cities. + $continents = array(); + $cities = array(); + foreach(timezone_identifiers_list() as $tz) + { + if ($tz=='UTC') $tz='UTC/UTC'; + $spos = strpos($tz,'/'); + if ($spos) + { + $continent=substr($tz,0,$spos); $city=substr($tz,$spos+1); + $continents[$continent]=1; + if (!isset($cities[$continent])) $cities[$continent]=array(); + $cities[$continent].=''; + } + } + $continents_html = ''; + $continents = array_keys($continents); + foreach($continents as $continent) + $continents_html.=''; + $cities_html = $cities[$pcontinent]; + $timezone_form = "Continent:

"; + $timezone_form .= "City:

"; + $timezone_js = "" ; + return array($timezone_form,$timezone_js); + } + return array('',''); +} + +// Tells if a timezone is valid or not. +// If not valid, returns false. +// If system does not support timezone list, returns false. +function isTZvalid($continent,$city) +{ + $tz = $continent.'/'.$city; + if (function_exists('timezone_identifiers_list')) // because of old php version (5.1) which can be found on free.fr + { + if (in_array($tz, timezone_identifiers_list())) // it's a valid timezone ? + return true; + } + return false; +} + + // Webservices (for use with jQuery/jQueryUI) // eg. index.php?ws=tags&term=minecr function processWS() @@ -1357,6 +1459,22 @@ function processWS() } } +// Re-write configuration file according to globals. +// Requires some $GLOBALS to be set (login,hash,salt,title). +// If the config file cannot be saved, an error message is dislayed and the user is redirected to "Tools" menu. +// (otherwise, the function simply returns.) +function writeConfig() +{ + if (is_file(CONFIG_FILE) && !isLoggedIn()) die('You are not authorized to alter config.'); // Only logged in user can alter config. + $config=''; + if (!file_put_contents(CONFIG_FILE,$config) || strcmp(file_get_contents(CONFIG_FILE),$config)!=0) + { + echo ''; + exit; + } +} + // Invalidate caches when the database is changed or the user logs out. // (eg. tags cache). function invalidateCaches() diff --git a/shaarli.css b/shaarli.css index 8dd8b14a..5a977439 100644 --- a/shaarli.css +++ b/shaarli.css @@ -61,6 +61,8 @@ border-bottom:1px solid #aaa; border-right:1px solid #aaa; } #newversion { background-color: #FFFFA0; color:#000; position:absolute; top:0;right:0; padding:2 7 2 7; font-size:9pt;} #cloudtag { padding-left:10%; padding-right:10%; } #cloudtag a { color:black; text-decoration:none; } +#installform td { font-size: 10pt; padding:10 5 10 5; } +#configform td { color:#ccc; font-size: 10pt; padding:10 5 10 5; } /* Minimal customisation for jQuery widgets */ .ui-autocomplete { background-color:#fff; padding-left:5px;} -- cgit v1.2.3