Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make link shortcodes paired/enclosing, fix https://github.com/MozillaCZ/mozilla-latest-version/issues/23 #25

Merged
merged 1 commit into from
Jul 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ There are currently four shortcodes added by this plugin. And three more additio

### Shortcodes
* `[mozilla-latest-version product=product]` - the latest version number of the specified _product_
These URL shortcodes below work also as [enclosing](https://codex.wordpress.org/Shortcode_API#Enclosing_vs_self-closing_shortcodes). Using `[shortcode]...[/shortcode]` will produce HTML link `<a href="URL">...</a>` instead of an URL string.
* `[mozilla-latest-download-url product=product platform=platform]` - download URL of the latest version of the specified _product_ for _platform_
* `[mozilla-latest-langpack-url product=product platform=platform]` - download URL of the latest langpack (.xpi) for the specified _product_ and _platform_ (not available for `fennec`)
* `[mozilla-latest-changelog-url product=product]` - changelog page URL for the latest version of the specified _product_
* `[mozilla-latest-requirements-url product=product]` - requirements page URL for the latest version of the specified _product_

#### Shortcodes for easier migration from the [Mozilla.sk CMS Plugin](https://github.com/MozillaCZ/mozsk-cms).
The Mozilla.sk CMS plugin shortcodes work as [self-closing](https://codex.wordpress.org/Shortcode_API#Enclosing_vs_self-closing_shortcodes) only.
* `[moz-download-version app=product]` = `[mozilla-latest-version product=product]`
* `[moz-download-url app=product platform=platform]` = `[mozilla-latest-download-url product=product platform=platform]`
* `[moz-download-rn app=product]` = `[mozilla-latest-changelog-url product=product]`
Expand Down
4 changes: 4 additions & 0 deletions classes/Mozlv_Settings_Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,16 @@ private function main_howto() {
<p class="description">All URLs (where posible) will contain the language code specified above.</p>
<ul>
<li><code>[mozilla-latest-version product=<em>product</em>]</code> - the latest version number of the specified <em>product</em></li>
</ul>
<p class="description">These URL shortcodes below work also as <a href="https://codex.wordpress.org/Shortcode_API#Enclosing_vs_self-closing_shortcodes" target="_blank">enclosing</a>. Using <code>[shortcode]...[/shortcode]</code> will produce HTML link <code>&lt;a href="URL"&gt;...&lt;/a&gt;</code> instead of an URL string.</p>
<ul>
<li><code>[mozilla-latest-download-url product=<em>product</em> platform=<em>platform</em>]</code> - download URL of the latest version of the specified <em>product</em> for <em>platform</em></li>
<li><code>[mozilla-latest-langpack-url product=<em>product</em> platform=<em>platform</em>]</code> - download URL of the latest langpack (.xpi) for the specified <em>product</em> and <em>platform</em> (not available for <code>fennec</code>)</li>
<li><code>[mozilla-latest-changelog-url product=<em>product</em>]</code> - changelog page URL for the latest version of the specified <em>product</em></li>
<li><code>[mozilla-latest-requirements-url product=<em>product</em>]</code> - requirements page URL for the latest version of the specified <em>product</em></li>
</ul>
<h4>Shortcodes for easier migration from the Mozilla.sk CMS Plugin</h4>
<p class="description">The Mozilla.sk CMS plugin shortcodes work as <a href="https://codex.wordpress.org/Shortcode_API#Enclosing_vs_self-closing_shortcodes" target="_blank">self-closing</a> only.</p>
<ul>
<li><code>[moz-download-version app=<em>product</em>]</code> = <code>[mozilla-latest-version product=<em>product</em>]</code></li>
<li><code>[moz-download-url app=<em>product</em> platform=<em>platform</em>]</code> = <code>[mozilla-latest-download-url product=<em>product</em> platform=<em>platform</em>]</code></li>
Expand Down
40 changes: 28 additions & 12 deletions classes/Mozlv_Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,60 +28,60 @@ public function get_latest_version( $atts ) {
* Returns latest product download URL in channel for platform.
*
* @param array $atts shortcode attributes
* @return string product download URL
* @return string product download URL or <a> link
*/
public function get_latest_download_URL( $atts ) {
public function get_latest_download_URL( $atts, $content = NULL ) {
$atts = self::mozlv_atts( $atts );
$product_class = Mozlv_Product_Factory::get_product( $atts['product'] );
if ( $product_class == NULL ) {
return;
}
return htmlspecialchars( $product_class->get_latest_download_URL( $atts['channel'], $atts['platform'] ) );
return self::return_link( $product_class->get_latest_download_URL( $atts['channel'], $atts['platform'] ), $content );
}

/**
* Returns latest product language pack download URL in channel for platform.
*
* @param array $atts shortcode attributes
* @return string product language pack download URL
* @return string product language pack download URL or <a> link
*/
public function get_latest_langpack_URL( $atts ) {
public function get_latest_langpack_URL( $atts, $content = NULL ) {
$atts = self::mozlv_atts( $atts );
$product_class = Mozlv_Product_Factory::get_product( $atts['product'] );
if ( $product_class == NULL ) {
return;
}
return htmlspecialchars( $product_class->get_latest_langpack_URL( $atts['channel'], $atts['platform'] ) );
return self::return_link( $product_class->get_latest_langpack_URL( $atts['channel'], $atts['platform'] ), $content );
}

/**
* Returns latest product changelog URL in channel for platform.
*
* @param array $atts shortcode attributes
* @return string product changelog URL
* @return string product changelog URL or <a> link
*/
public function get_latest_changelog_URL( $atts ) {
public function get_latest_changelog_URL( $atts, $content = NULL ) {
$atts = self::mozlv_atts( $atts );
$product_class = Mozlv_Product_Factory::get_product( $atts['product'] );
if ( $product_class == NULL ) {
return;
}
return htmlspecialchars( $product_class->get_latest_changelog_URL( $atts['channel'], $atts['platform'] ) );
return self::return_link( $product_class->get_latest_changelog_URL( $atts['channel'], $atts['platform'] ), $content );
}

/**
* Returns latest product system requirements URL in channel for platform.
*
* @param array $atts shortcode attributes
* @return string product system requirements URL
* @return string product system requirements URL or <a> link
*/
public function get_latest_requirements_URL( $atts ) {
public function get_latest_requirements_URL( $atts, $content = NULL ) {
$atts = self::mozlv_atts( $atts );
$product_class = Mozlv_Product_Factory::get_product( $atts['product'] );
if ( $product_class == NULL ) {
return;
}
return htmlspecialchars( $product_class->get_latest_requirements_URL( $atts['channel'], $atts['platform'] ) );
return self::return_link( $product_class->get_latest_requirements_URL( $atts['channel'], $atts['platform'] ), $content );
}

/**
Expand Down Expand Up @@ -161,6 +161,22 @@ private function mozsk_atts( $atts ) {
return $atts;
}

/**
* Return shortcode URL or link.
*
* @param string $url shortcode output URL
* @param string $content shortcode content
* @return string shortcode URL or <a> link (if $content present)
*/
private function return_link( $url, $content = NULL ) {
$url = htmlspecialchars( $url );
if ( $content == NULL ) {
return $url;
} else {
return sprintf( '<a href="%1$s">%2$s</a>', $url, do_shortcode( $content ) );
}
}

/**
* Returns the Mozlv_Shortcode singleton instance.
*/
Expand Down