/ Published in: PHP
This snippet returns a link to twitter for the user to tweet the current page. URL is TinyURLed automatically (and tinyurls are cached indefinitely in assets/cache/tweetthis.txt).
Simply paste code into a new snippet called "TweetThis". Call it like so:
[[TweetThis? &name=\`@DaveChild\` &text=\`Tweet This!\` &id=\`7\` ]]
All parameters are optional. ID defaults to current document.
Simply paste code into a new snippet called "TweetThis". Call it like so:
[[TweetThis? &name=\`@DaveChild\` &text=\`Tweet This!\` &id=\`7\` ]]
All parameters are optional. ID defaults to current document.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /** * @name TweetThis * @author Dave Child <[email protected]> * @license GPLv3 * @version 0.3 * * This snippet returns a link to twitter for the user to tweet the current * page. URL is sent through TinyURL automatically (TinyURLs are cached * indefinitely in assets/cache/tweetthis.txt). Link is given the class * "tweetthis". * * &name=`@DaveChild` * Pass through a name to the snippet. You can use your own Twitter ID by * prefixing the name with an @. Optional. * * &text=`Tweet This!` * Text to use for the link. Optional. * * &id=`7` * Document ID (defaults to current document). Optional. */ // --------------------------------------------------- // Check input variables // --------------------------------------------------- // --------------------------------------------------- // Get document information // --------------------------------------------------- $thisDoc = $modx->getPageInfo($id); // --------------------------------------------------- // Define getTinyUrl function // --------------------------------------------------- function getTinyUrl($id) { global $modx; $cacheFile = $modx->config['base_path'] . 'assets/cache/tweetthis.txt'; if ($tinyurls[$id]) { return $tinyurls[$id]; } } else { } $url = $modx->makeUrl($id, '', '', 'full'); if ($tinyurl) { $tinyurls[$id] = $tinyurl; } else { return $url; } return $tinyurl; } } // --------------------------------------------------- // Build link // --------------------------------------------------- $strTweetThis = '<a class="tweetthis" href="http://twitter.com/home?status=' . urlencode($thisDoc['pagetitle']); if ($name <> '') { } return $strTweetThis; ?>
URL: http://www.addedbytes.com