heiko-barth.de

// Aktuelle URL per Bookmarklet in DokuWiki speichern

Ich habe zwei Skripte erstellt, mit denen man die aktuell im Browser aufgerufene Seite und deren HTML-Titel per Bookmarklet in einer Wiki-Seite speichern kann.

Folgendes PHP-Skript muss angepasst auf dem Webserver hinterlegt werden:

bookmark.php
<?php
        # path to dokuwiki page
        $file = "/path/to/wiki/data/pages/bookmarks.txt";
 
        # ensure utf-8
        $url = iconv("UTF-8", "UTF-8//IGNORE", $_GET["url"]);
        $title = iconv("UTF-8", "UTF-8//IGNORE", $_GET["title"]);
 
        # dont break wiki syntax
        $search  = array('|', '[', ']');
        $replace = "-";
        $url = str_replace($search, $replace, $url);
        $title = str_replace($search, $replace, $title);
 
        # write to dokuwiki page
        if (file_put_contents($file, "\n  * [[" . $url . "|" . $title . "]]", FILE_APPEND | LOCK_EX) === false) {
                die("Error: Failed to add bookmark.");
        }
 
        # redirect back to source
        header("HTTP/1.1 302 Found");
        header("Location: " . $_GET["url"]);

Dieses Bookmarklet sendet die aktuelle URL und den HTML-Seitentitel an das auf dem Server hinterlegte PHP-Skript:

bookmarklet.js
javascript:(function(){location.href='http://example.com/bookmark.php?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)})()

http://example.com muss natürlich an die eigenen Bedürfnisse angepasst werden.

Leave a comment…



   ___    __ __   ___  ______  _____   ____   __  ___
  / _ \  / // /  / _ \/_  __/ / ___/  / __/  /  |/  /
 / ___/ / _  /  / , _/ / /   / /__   / _/   / /|_/ / 
/_/    /_//_/  /_/|_| /_/    \___/  /___/  /_/  /_/
  • E-Mail address will not be published.
  • Formatting:
    //italic//  __underlined__
    **bold**  ''preformatted''
  • Links:
    [[http://example.com]]
    [[http://example.com|Link Text]]
  • Quotation:
    > This is a quote. Don't forget the space in front of the text: "> "
  • Code:
    <code>This is unspecific source code</code>
    <code [lang]>This is specifc [lang] code</code>
    <code php><?php echo 'example'; ?></code>
    Available: html, css, javascript, bash, cpp, …
  • Lists:
    Indent your text by two spaces and use a * for
    each unordered list item or a - for ordered ones.
Web 2.0



RSS   RSS abonieren

Github   Github
QR Code