]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #119 from ArthurHoaro/js-link
authornodiscc <nodiscc@gmail.com>
Wed, 11 Mar 2015 18:17:13 +0000 (19:17 +0100)
committernodiscc <nodiscc@gmail.com>
Wed, 11 Mar 2015 18:17:13 +0000 (19:17 +0100)
allow 'javascript:' links sharing (bookmarklets)

1  2 
index.php

diff --combined index.php
index cda918df82c45a7dd56d90280eb7e8bc6a2e53d3,c87b944973b0ea150a3328a781b0e17bce3e03de..066058e617d651e01297abb2515b3573cd06fc50
+++ b/index.php
@@@ -178,14 -178,13 +178,14 @@@ function checkphpversion(
  function checkUpdate()
  {
      if (!isLoggedIn()) return ''; // Do not check versions for visitors.
 +    if (empty($GLOBALS['config']['ENABLE_UPDATECHECK'])) return ''; // Do not check if the user doesn't want to.
  
      // Get latest version number at most once a day.
      if (!is_file($GLOBALS['config']['UPDATECHECK_FILENAME']) || (filemtime($GLOBALS['config']['UPDATECHECK_FILENAME'])<time()-($GLOBALS['config']['UPDATECHECK_INTERVAL'])))
      {
          $version=shaarli_version;
 -        list($httpstatus,$headers,$data) = getHTTP('https://raw.githubusercontent.com/shaarli/Shaarli/master/shaarli_version.txt',2);
 -        if (strpos($httpstatus,'200 OK')!==false) $version=$data;
 +        list($httpstatus,$headers,$data) = getHTTP('https://raw.githubusercontent.com/shaarli/Shaarli/master/shaarli_version.php',2);
 +        if (strpos($httpstatus,'200 OK')!==false) $version=str_replace(' */ ?>','',str_replace('<?php /* ','',$data));
          // If failed, never mind. We don't want to bother the user with that.
          file_put_contents($GLOBALS['config']['UPDATECHECK_FILENAME'],$version); // touch file date
      }
@@@ -1463,7 -1462,6 +1463,7 @@@ function renderPage(
              $GLOBALS['disablejquery']=!empty($_POST['disablejquery']);
              $GLOBALS['privateLinkByDefault']=!empty($_POST['privateLinkByDefault']);
              $GLOBALS['config']['ENABLE_RSS_PERMALINKS']= !empty($_POST['enableRssPermalinks']);
 +            $GLOBALS['config']['ENABLE_UPDATECHECK'] = !empty($_POST['updateCheck']);
              writeConfig();
              echo '<script>alert("Configuration was saved.");document.location=\'?do=tools\';</script>';
              exit;
          $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces.
          $linkdate=$_POST['lf_linkdate'];
          $url = trim($_POST['lf_url']);
-         if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?'))
+         if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?') && !startsWith($url,'javascript:'))
              $url = 'http://'.$url;
          $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0),
                        'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags));
          if (isset($_GET['source']) && $_GET['source']=='bookmarklet') { echo '<script>self.close();</script>'; exit; }
          $returnurl = ( isset($_POST['returnurl']) ? $_POST['returnurl'] : '?' );
          $returnurl .= '#'.smallHash($linkdate);  // Scroll to the link which has been edited.
 +        if (strstr($returnurl, "do=addlink")) { $returnurl = '?'; } //if we come from ?do=addlink, set returnurl to homepage instead
          header('Location: '.$returnurl); // After saving the link, redirect to the page the user was on.
          exit;
      }
      {
          $url=$_GET['post'];
  
 -        // We remove the annoying parameters added by FeedBurner and GoogleFeedProxy (?utm_source=...)
 -        $i=strpos($url,'&utm_source='); if ($i!==false) $url=substr($url,0,$i);
 -        $i=strpos($url,'?utm_source='); if ($i!==false) $url=substr($url,0,$i);
 -        $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i);
 +
 +        // We remove the annoying parameters added by FeedBurner, GoogleFeedProxy, Facebook...
 +        $annoyingpatterns = array('/[\?&]utm_source=[^&]*/', '/[\?&]utm_campaign=[^&]*/', '/[\?&]utm_medium=[^&]*/', '/#xtor=RSS-[^&]*/', '/[\?&]fb_[^&]*/', '/[\?&]__scoop[^&]*/', '/#tk\.rss_all\?/', '/[\?&]action_ref_map=[^&]*/', '/[\?&]action_type_map=[^&]*/', '/[\?&]action_object_map=[^&]*/');
 +        foreach($annoyingpatterns as $pattern)
 +        {
 +            $url = preg_replace($pattern, "", $url);
 +        }
  
          $link_is_new = false;
          $link = $LINKSDB->getLinkFromUrl($url); // Check if URL is not already in database (in this case, we will edit the existing link)
@@@ -2129,8 -2123,11 +2129,8 @@@ function lazyThumbnail($url,$href=false
  
      $html='<a href="'.htmlspecialchars($t['href']).'">';
  
 -    // Lazy image (only loaded by JavaScript when in the viewport).
 -    if (!empty($GLOBALS['disablejquery'])) // (except if jQuery is disabled)
 -        $html.='<img class="lazyimage" src="'.htmlspecialchars($t['src']).'"';
 -    else
 -        $html.='<img class="lazyimage" src="#" data-original="'.htmlspecialchars($t['src']).'"';
 +    // Lazy image
 +    $html.='<img class="b-lazy" src="#" data-src="'.htmlspecialchars($t['src']).'"';
  
      if (!empty($t['width']))  $html.=' width="'.htmlspecialchars($t['width']).'"';
      if (!empty($t['height'])) $html.=' height="'.htmlspecialchars($t['height']).'"';
@@@ -2194,7 -2191,6 +2194,7 @@@ function install(
          $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(indexUrl()) : $_POST['title'] );
 +        $GLOBALS['config']['ENABLE_UPDATECHECK'] = !empty($_POST['updateCheck']);
          writeConfig();
          echo '<script>alert("Shaarli is now configured. Please enter your login/password and start shaaring your links!");document.location=\'?do=login\';</script>';
          exit;
@@@ -2363,7 -2359,6 +2363,7 @@@ function writeConfig(
      $config .= '$GLOBALS[\'disablejquery\']='.var_export($GLOBALS['disablejquery'],true).'; ';
      $config .= '$GLOBALS[\'privateLinkByDefault\']='.var_export($GLOBALS['privateLinkByDefault'],true).'; ';
      $config .= '$GLOBALS[\'config\'][\'ENABLE_RSS_PERMALINKS\']='.var_export($GLOBALS['config']['ENABLE_RSS_PERMALINKS'], true).'; ';
 +    $config .= '$GLOBALS[\'config\'][\'ENABLE_UPDATECHECK\']='.var_export($GLOBALS['config']['ENABLE_UPDATECHECK'], true).'; ';
      $config .= ' ?>';
      if (!file_put_contents($GLOBALS['config']['CONFIG_FILE'],$config) || strcmp(file_get_contents($GLOBALS['config']['CONFIG_FILE']),$config)!=0)
      {