-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Simon Champion
committed
Nov 30, 2016
0 parents
commit 6fb9b2b
Showing
7 changed files
with
886 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
InlineTweet | ||
=========== | ||
|
||
This plugin allows you turn snippets of text in your page content into tweetable links. | ||
|
||
At the simplest level, simply add `{inlinetweet}...{/inlinetweet}` markers around a block of text in your CMS content, and it will be rendered as a link that when clicked opens a twitter window to let you to send a tweet with that text. | ||
|
||
There is more to it than that of course. Options and configuration are described below under 'Usage'. | ||
|
||
|
||
Version History | ||
---------------- | ||
|
||
* 1.0.0 | ||
|
||
|
||
Installation | ||
---------------- | ||
|
||
This is a standard Joomla plugin. Installation is via Joomla's extension manager. As with all plugins, remember that it must also be activated after being installed. | ||
|
||
|
||
Usage | ||
---------------- | ||
|
||
###Simple usage: | ||
|
||
When editing content for your site, if you want a piece of text to be tweetable, simply add `{inlinetweet}` the start of it and `{/inlinetweet}` to the end. The text between these markers will be rendered on your site as a tweetable link. | ||
|
||
Example: | ||
|
||
This is some content text on your site. {inlinetweet}This bit of it is a tweetable link.{/inlinetweet} And then we're back to normal text again. | ||
|
||
###Options: | ||
|
||
Inside the `{inlinetweet}` marker, you may add the following options: | ||
|
||
* *via* - Here you can specify a Twitter username that you want the tweet to be sent 'via'. Do not include the `@` symbol on the username. | ||
* *url* - This attribute allows you to override the URL that will be added to the tweet. By default it will be URL of the current page. | ||
* *hashtags* - This allows you to add some hashtags to the tweet. Note: comma-separated; no spaces; no `#` characters. | ||
|
||
Attributes are specified strictly in the form `attribute="value"`, with the values in double quotes. | ||
|
||
Example: | ||
|
||
Here is some content on your site. {inlinetweet via="jack" hashtags="random,stuff"}This bit is a tweetable link.{/inlinetweet} And back to normal text again. | ||
|
||
Obviously, you need to keep the overall length of your text plus tags, etc short enough to fit into a tweet. (if you make it too long, the plugin will work just fine and clicking the link will open the tweet page, but the user will have to edit the tweet down to an acceptable length before they can submit it) | ||
|
||
Note that a `url` value of a single dot (`url="."`) is interpreted as a request to use the current page. This is the default anyway, so is the same as not specifying the URL at all, unless you've set a fixed default URL in the configuration, see below. | ||
|
||
Another special value for `url` is a dash (`url="-"`). This indicates that the tweet should not have a URL at all. | ||
|
||
###Configuration | ||
|
||
In addition to being able to specify the above three options as arguments in the `{inlinetweet}` marker, the plugin also gives you the option to set default values for them all in the plugin configuration. Thus if you are going to have a lot of tweetable links on your site but you want them all to be sent via the same twitter username, then you could set the default value for 'via' in config and save yourself having to specify it on every twitter link. | ||
|
||
You can still override the defaults for a specific tweet link by using the attributes in the `{inlinetweet}` marker as described above. | ||
|
||
Please note, regarding the URL option: If you set a default value for the URL, it will override the default behaviour of using the current URL where the link is being displayed, and will instead give you a static URL that will be the same for all your tweet links. This feature may be useful for setting to a dash (`-`) if you know that you generally don't want URLs in your tweets, but setting to any other arbitrary fixed URL is unlikely to be useful so I recommend not setting this default value. It is there if you need it though. If you do set a default URL, you can always override it back to the 'current page' default by using `url="."` as described above. | ||
|
||
|
||
Motivation | ||
---------------- | ||
|
||
This is a PHP / Joomla-specific re-implementation of the [InlineTweet.js](https://github.com/ireade/inlinetweetjs) JavaScript library. The functionality of this plugin is broadly similar to the JS library, but the code was written from scratch and is not a copy of the JS code. | ||
|
||
Reasons for using this plugin rather than the JS library: | ||
|
||
- The JS library does not currently specify a license in its repository or documentation, meaning that people who care about these things (or whose legal departments care) cannot use it. | ||
- The plugin has the ability to specify defaults in the config, which isn't a feature in the JS library. | ||
- The JS library uses HTML `<span>` tags to activate the conversion. The plugin uses `{inlinetweet}` markers, which is more convenient in a WYSIWYG content editor. | ||
- The plugin renders the link server-side, before the page is sent rather than the on client. This will avoid any issues with visible jumps as the page updates after it has loaded. | ||
|
||
|
||
Todo List and Known Issues | ||
-------------------------- | ||
|
||
* Todo: Add config to make the twitter icon optional. | ||
* Todo: Allow the tweet text to be overridden. | ||
* Todo: Allow single quotes as well as double quotes for attribute values. | ||
* Issue: Things will break if your tweet text contains HTML or spans across the start or end of an HTML element. | ||
|
||
|
||
License | ||
---------------- | ||
As with all Joomla extensions and Joomla itself, this plugin is licensed under the GPLv2. The full license document should have been included with the source code. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!DOCTYPE html> | ||
<html><head><title></title></head><body></body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* @package Inlinetweet | ||
* @type Plugin (Content) | ||
* @version 1.0.0 | ||
* @author Simon Champion | ||
* @copyright (C) 2016 Simon Champion | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
**/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
class plgContentInlinetweet extends JPlugin | ||
{ | ||
public function onContentPrepare($context, &$article, &$params, $limitstart) | ||
{ | ||
$regex = '#\{inlinetweet(( [a-z]+=".*?")*)\}(.*?)\{\/inlinetweet\}#s'; | ||
|
||
$article->text = preg_replace_callback($regex, [$this, 'replace'], $article->text); | ||
} | ||
|
||
protected function replace($matches) | ||
{ | ||
list($whole, $argsString, $lastArg, $text) = $matches; | ||
|
||
$attributes = $this->processArgs($argsString); | ||
|
||
return trim($this->inlineTweetString($text, $attributes)); | ||
} | ||
|
||
/** | ||
* Set defaults for each attr from plugin config; override if arguments specified. | ||
* @return string the finished attributes string. | ||
*/ | ||
protected function processArgs($argsString) | ||
{ | ||
$attrs = [ | ||
"via" => $this->params['defaultVia'], | ||
"hashtags" => $this->params['defaultTags'], | ||
"url" => $this->params['defaultURL'], | ||
]; | ||
|
||
preg_match_all('#([a-z]+)="(.*?)"#', $argsString, $matches); | ||
foreach ($matches[1] as $pos=>$argName) { | ||
$argVal = $matches[2][$pos]; | ||
if (array_key_exists($argName, $attrs)) { | ||
$attrs[$argName] = $argVal; | ||
} | ||
} | ||
if ($attrs['url'] === '' || $attrs['url'] === '.') { | ||
$attrs['url'] = JURI::current(); | ||
} | ||
if ($attrs['url'] === '-') { | ||
$attrs['url'] = ''; | ||
} | ||
|
||
return $attrs; | ||
} | ||
|
||
protected function inlineTweetString($text, $attrs) | ||
{ | ||
$args = ''; | ||
foreach ($attrs as $key => $attr) { | ||
if ($attr) { | ||
$args .= "&{$key}=".htmlentities($attr); | ||
} | ||
} | ||
|
||
return <<<eof | ||
<a target="_blank" href="https://twitter.com/intent/tweet/?text={$text}{$args}"><span>{$text}</span><img src="/plugins/content/inlinetweet/assets/Twitter_Logo_Blue.png" style="width:1.6em;"></a> | ||
eof; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<extension version="3.0" type="plugin" group="content" method="upgrade"> | ||
<name>PLG_CONTENT_INLINETWEET_NAME</name> | ||
<version>1.0.0</version> | ||
<creationDate>December 2016</creationDate> | ||
<author>Simon Champion</author> | ||
<authorEmail>simon@simonchampion.net</authorEmail> | ||
<authorUrl></authorUrl> | ||
<copyright>(C) 2016 Simon Champion</copyright> | ||
<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license> | ||
<description>PLG_CONTENT_INLINETWEET_DESCRIPTION</description> | ||
|
||
<files> | ||
<filename>index.html</filename> | ||
<filename plugin="inlinetweet">inlinetweet.php</filename> | ||
<folder>assets</folder> | ||
</files> | ||
|
||
<languages> | ||
<language tag="en-GB">language/en-GB/en-GB.plg_content_inlinetweet.sys.ini</language> | ||
</languages> | ||
|
||
<config> | ||
<fields name="params"> | ||
<fieldset name="basic"> | ||
<field name="defaultURL" type="url" description="PLG_CONTENT_INLINETWEET_DEFAULTURL_DESC" label="PLG_CONTENT_INLINETWEET_DEFAULTURL_LABEL" default="" /> | ||
<field name="defaultVia" type="text" description="PLG_CONTENT_INLINETWEET_DEFAULTVIA_DESC" label="PLG_CONTENT_INLINETWEET_DEFAULTVIA_LABEL" default="" /> | ||
<field name="defaultTags" type="text" description="PLG_CONTENT_INLINETWEET_DEFAULTTAGS_DESC" label="PLG_CONTENT_INLINETWEET_DEFAULTTAGS_LABEL" default="" /> | ||
</fieldset> | ||
</fields> | ||
</config> | ||
</extension> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
; @package Inlinetweet | ||
; @language English | ||
; @version 1.0.0 | ||
; @author Simon Champion | ||
; @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
|
||
PLG_CONTENT_INLINETWEET_NAME="Inlinetweet" | ||
PLG_CONTENT_INLINETWEET_DESCRIPTION="This plugin allows you to make snippets of text on your site into tweetable links." | ||
PLG_CONTENT_INLINETWEET="Content - Inlinetweet" | ||
|
||
PLG_CONTENT_INLINETWEET_DEFAULTURL_DESC="Override the URL for your tweet links. Leave blank for tweets to take the URL of the page where they are called from. Set to a dash (-) for no URLs in your tweets." | ||
PLG_CONTENT_INLINETWEET_DEFAULTURL_LABEL="Default URL" | ||
|
||
PLG_CONTENT_INLINETWEET_DEFAULTVIA_DESC="Optional twitter username (without the @) to be appended to the tweet" | ||
PLG_CONTENT_INLINETWEET_DEFAULTVIA_LABEL="Default Via" | ||
|
||
PLG_CONTENT_INLINETWEET_DEFAULTTAGS_DESC="Optional hashtags to add to tweets (NB: comma-separated, no spaces or # signs)" | ||
PLG_CONTENT_INLINETWEET_DEFAULTTAGS_LABEL="Default Tags" |