ShareThis

From Jimbojw.com

Jump to: navigation, search
<?php //

This is a MediaWiki Extension. For more information about it, see the documentation in ShareThis Extension.

Important! Unless otherwise specified, this extension is released under The MIT License. If you choose to install it, you do so at your own risk and discretion.

/*
 * ShareThis.php - Provides links to popular social bookmarking and news sources.
 * @authors Jim R. Wilson
 * @version 0.1.1
 * @copyright Copyright (C) 2007 Jim R. Wilson
 * @license The MIT License - http://www.opensource.org/licenses/mit-license.php 
 * -----------------------------------------------------------------------
 * Description:
 *     This is a MediaWiki extension which adds links to popular social bookmarking and news sources.
 * Requirements:
 *     This extension is made to work with MediaWiki 1.6.x, 1.8.x, 1.9.x, 1.10.x on PHP 4.x, 5.x or higher.
 * Installation:
 *     1. Drop this script (ShareThis.php) in $IP/extensions
 *         Note: $IP is your MediaWiki install dir.
 *     2. Enable the extension by adding this line to your LocalSettings.php:
 *            require_once('extensions/ShareThis.php');
 * Configuration (optional):
 *     If you'd like to see the "Share This" portlet in the sidebar, add the following to your LocalSettings.php:
 *            $wgShowShareThisSidebar = true;
 * Usage:
 *     Once installed, you may utilize ShareThis by adding the following flag in the article text:
 *         <sharethis />
 *     Note: Typically this would be placed towards the end of the article text.
 * Version Notes:
 *     version 0.1.1:
 *         Added system message for use when extending toolbox - minor.
 *     version 0.1:
 *         Initial release.
 * -----------------------------------------------------------------------
 * Copyright (c) 2007 Jim R. Wilson
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy 
 * of this software and associated documentation files (the "Software"), to deal 
 * in the Software without restriction, including without limitation the rights to 
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 
 * the Software, and to permit persons to whom the Software is furnished to do 
 * so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all 
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
 * OTHER DEALINGS IN THE SOFTWARE. 
 * -----------------------------------------------------------------------
 */
 
# Confirm MW environment (huge wrapper)
if (defined('MEDIAWIKI')) {
 
define('SHARETHIS_VERSION','0.1.1');
 
# Credits
$wgExtensionCredits['parserhook'][] = array(
    'name'=>'ShareThis',
    'author'=>'Jim R. Wilson wilson.jim.r at gmail.com',
    'url'=>'http://jimbojw.com/wiki/index.php?title=ShareThis',
    'description'=>'Provides links to popular social bookmarking and news sources.',
    'version'=>SHARETHIS_VERSION
);
 
# Build list of social sites (can be modified in LocalSettings)
$wgShareThisSiteList = array(
    'BlogMarks' => 'http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=$1&amp;title=$2',
    'del.icio.us' => 'http://del.icio.us/post?url=$1&amp;title=$2',
    'digg' => 'http://digg.com/submit?phase=2&amp;url=$1&amp;title=$2',
    'Fark' => 'http://cgi.fark.com/cgi/fark/edit.pl?new_url=$1&amp;new_comment=$2&amp;linktype=',
    'Furl' => 'http://www.furl.net/storeIt.jsp?u=$1&amp;t=$2',
    'Newsvine' => 'http://www.newsvine.com/_tools/seed&amp;save?u=$1&amp;h=$2',
    'reddit' => 'http://reddit.com/submit?url=$1&amp;title=$2',
    'Segnalo' => 'http://segnalo.com/post.html.php?url=$1&amp;title=$2',
    'Simpy' => 'http://www.simpy.com/simpy/LinkAdd.do?href=$1&amp;title=$2',
    'Slashdot' => 'http://slashdot.org/bookmark.pl?url=$1&amp;title=$2',
    'smarking' => 'http://smarking.com/editbookmark/?url=$1&amp;title=$2',
    'Spurl' => 'http://www.spurl.net/spurl.php?url=$1&amp;title=$2',
    'Wists' => 'http://wists.com/r.php?c=&amp;r=$1&amp;title=$2'
);
 
# Add Extension Functions
$wgExtensionFunctions[] = 'wfShareThisExtensionSetup';
 
# Sets up the ShareThis parser hook and global messages
function wfShareThisExtensionSetup() {
    global $wgParser, $wgMessageCache;
    $wgParser->setHook('sharethis', 'wfShareThisParserHook');
    $wgMessageCache->addMessage('share-this-sidebar-header', 'Share This!');
    $wgMessageCache->addMessage('share-this-toolbox-escape-html',
        '</ul></div></div>' .
        '<div class="portlet" id="p-sharethis">' .
        '<h5>$1</h5>' .
        '<div class="pBody"><ul>'
    );
}
 
/**
 * Parser hook for the <sharethis /> tag extension.
 */
function wfShareThisParserHook($text, $params, &$parser) {
 
    global $wgShareThisSiteList, $wgTitle, $wgStylePath;
    
    $output = '';
    uksort($wgShareThisSiteList, 'strcasecmp');
    foreach ($wgShareThisSiteList as $name=>$url) {
        $url = str_replace('$1', urlencode($wgTitle->getFullURL()), $url);
        $url = str_replace('$2', urlencode($wgTitle->getText()), $url);
        $output .= 
            "<a href='$url' title='Add to $name'>" .
            "<img src='".$wgStylePath."/common/images/sharethis/$name.png' alt='Add to $name'/></a>"; 
    }
    
    return $output;
}
 
# Add hook for Monobook sidebar integration
$wgHooks['MonoBookTemplateToolboxEnd'][] = 'wfInsertShareThisSidebar';
 
/**
 * Injects ShareThis links into the sidebar (hooks MonoBookTemplateToolboxEnd).
 * Note: This must be activiated by setting $wgShowShareThisSidebar = true in Localsettings
 */
function wfInsertShareThisSidebar($template) {
 
    global $wgShowShareThisSidebar, $wgShareThisSiteList, $wgTitle, $wgStylePath;
 
    # Short-circuit if sidebar has not been activiated.
    if (!$wgShowShareThisSidebar) return true;
 
    # Close out the MonoBook toolbox and create a new "sharethis" portlet
    echo(
        wfMsgForContent(
            'share-this-toolbox-escape-html', 
            wfMsgForContent('share-this-sidebar-header')
        )
    );
 
    # Display the links
    uksort($wgShareThisSiteList, 'strcasecmp');
    foreach ($wgShareThisSiteList as $name=>$url) {
        $url = str_replace('$1', urlencode($wgTitle->getFullURL()), $url);
        $url = str_replace('$2', urlencode($wgTitle->getText()), $url);
        echo(
            "<li id='t-".strtolower(str_replace('.','',$name))."'>" .
            "<a href='$url' title='Add to $name'>" .
            "<img src='$wgStylePath/common/images/sharethis/$name.png' alt='Add to $name'/> " .
            "$name</a></li>"
        );
 
    }
    return true;
}
 
} # Closing MW Environment wrapper
//