Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Commit ac768a4

Browse files
committed
Initial commit
1 parent 5b97e7b commit ac768a4

8 files changed

+256
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Joomla Content - Automatic Intro Image plugin
2+
This is the Content - Automatic Intro Image plugin for Joomla 3.2+.
3+
4+
This plugin automatically create a resized version of the full size article image and set it as the intro image.Simply enable the plugin, set parameters and let blank the intro image field when saving the article.
5+
6+
See https://github.com/mattiaverga/JAutomaticIntroImage/wiki for more help.
7+
8+
## Changelog
9+
### v1.0
10+
* Initial release

automaticintroimage.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2016- Mattia Verga. All rights reserved.
4+
* @license GNU General Public License version 3, or later
5+
*/
6+
// no direct access
7+
defined( '_JEXEC' ) or die;
8+
9+
class plgContentAutomaticIntroImage extends JPlugin
10+
{
11+
/**
12+
* Load the language file on instantiation. Note this is only available in Joomla 3.1 and higher.
13+
* If you want to support 3.0 series you must override the constructor
14+
*
15+
* @var boolean
16+
* @since 3.1
17+
*/
18+
protected $autoloadLanguage = true;
19+
20+
/**
21+
* Automatic creation of resized intro image from article full image
22+
*
23+
* @param string $context The context of the content being passed to the
24+
plugin.
25+
* @param mixed $article A reference to the JTableContent object that is
26+
being saved which holds the article data.
27+
* @param boolean $isNew A boolean which is set to true if the content
28+
is about to be created.
29+
*
30+
* @return boolean True on success.
31+
*/
32+
public function onContentBeforeSave($context, $article, $isNew)
33+
{
34+
// Check if we're saving an article
35+
$allowed_contexts = array('com_content.article');
36+
37+
if (!in_array($context, $allowed_contexts))
38+
{
39+
return true;
40+
}
41+
42+
$images = json_decode($article->images);
43+
44+
// Return if full article image is not set or empty
45+
if (!isset($images->image_fulltext) or empty($images->image_fulltext))
46+
{
47+
return true;
48+
}
49+
50+
// Return if intro image is already set
51+
if (isset($images->image_intro) and !empty($images->image_intro))
52+
{
53+
return true;
54+
}
55+
56+
$width = $this->params->get('Width');
57+
$height = $this->params->get('Height');
58+
59+
// Create resized image
60+
$thumb = new Imagick(JPATH_ROOT . '/' . $images->image_fulltext);
61+
62+
$thumb->resizeImage($width,
63+
$height,
64+
Imagick::FILTER_LANCZOS,
65+
1,
66+
$this->params->get('MaintainAspectRatio')
67+
);
68+
69+
// Get real image dimensions if maintain aspect ratio was selected
70+
if ($this->params->get('MaintainAspectRatio') == 1)
71+
{
72+
$width = $thumb->getImageWidth();
73+
$height = $thumb->getImageHeight();
74+
}
75+
76+
// Set image intro name
77+
// {width} and {height} placeholders are changed to values
78+
$suffix = $this->params->get('Suffix');
79+
if (strpos($suffix, "{width}") !== false or
80+
strpos($suffix, "{height}") !== false)
81+
{
82+
$suffix = str_replace(array("{width}","{height}"),
83+
array($width,$height),
84+
$suffix);
85+
}
86+
$extension_pos = strrpos($images->image_fulltext, '.');
87+
$images->image_intro = substr($images->image_fulltext, 0, $extension_pos) .
88+
$suffix .
89+
substr($images->image_fulltext, $extension_pos);
90+
91+
// Copy Alt and Title fields
92+
if ($this->params->get('CopyAltTitle') == 1 and
93+
($images->image_fulltext_alt != "" or
94+
$images->image_fulltext_caption != ""))
95+
{
96+
$images->image_intro_alt = $images->image_fulltext_alt;
97+
$images->image_intro_caption = $images->image_fulltext_caption;
98+
}
99+
100+
// Write resized image if it doesn't exist
101+
// and set Joomla object values
102+
if (!file_exists(JPATH_ROOT . '/' . $images->image_intro))
103+
{
104+
$thumb->writeImage(JPATH_ROOT . '/' . $images->image_intro);
105+
}
106+
107+
$article->images = json_encode($images);
108+
109+
$thumb->destroy();
110+
111+
return true;
112+
}
113+
114+
}
115+
?>

automaticintroimage.xml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<extension version="3.2" type="plugin" group="content" method="upgrade">
3+
<name>Content - Automatic Intro Image</name>
4+
<author>Mattia Verga</author>
5+
<creationDate>23 October 2016</creationDate>
6+
<copyright>Copyright (C) 2016 Mattia Verga. All rights reserved.</copyright>
7+
<license>GNU General Public License version 3 or later.</license>
8+
<authorEmail>mattia.verga@tiscali.it</authorEmail>
9+
<version>1.0</version>
10+
<description>PLG_CONTENT_AUTOMATICINTROIMAGE_XML_DESCRIPTION</description>
11+
<files>
12+
<filename plugin="automaticintroimage">automaticintroimage.php</filename>
13+
<filename>index.html</filename>
14+
<folder>language</folder>
15+
</files>
16+
<languages>
17+
<language tag="en-GB">language/en-GB/en-GB.plg_content_automaticintroimage.ini</language>
18+
<language tag="en-GB">language/en-GB/en-GB.plg_content_automaticintroimage.sys.ini</language>
19+
<language tag="it-IT">language/it-IT/it-IT.plg_content_automaticintroimage.ini</language>
20+
<language tag="it-IT">language/it-IT/it-IT.plg_content_automaticintroimage.sys.ini</language>
21+
</languages>
22+
<config>
23+
<fields name="params">
24+
25+
<fieldset name="basic">
26+
<field name="Width" type="number"
27+
default="320"
28+
description="PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_WIDTH_DESCRIPTION"
29+
label="PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_WIDTH_LABEL"
30+
filter="integer"
31+
min="10"
32+
max="2000"
33+
size="4"
34+
required="1"
35+
/>
36+
37+
<field name="Height" type="number"
38+
default="240"
39+
description="PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_HEIGHT_DESCRIPTION"
40+
label="PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_HEIGHT_LABEL"
41+
filter="integer"
42+
min="10"
43+
max="2000"
44+
size="4"
45+
required="1"
46+
/>
47+
48+
<field name="MaintainAspectRatio" type="radio"
49+
default="1"
50+
description="PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_RATIO_DESCRIPTION"
51+
label="PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_RATIO_LABEL"
52+
>
53+
<option value="0">PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_NO</option>
54+
<option value="1">PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_YES</option>
55+
</field>
56+
57+
<field name="CopyAltTitle" type="radio"
58+
default="1"
59+
description="PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_TEXT_DESCRIPTION"
60+
label="PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_TEXT_LABEL"
61+
>
62+
<option value="0">PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_NO</option>
63+
<option value="1">PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_YES</option>
64+
</field>
65+
66+
<field name="Suffix" type="text"
67+
default="_thumb"
68+
description="PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_SUFFIX_DESCRIPTION"
69+
label="PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_SUFFIX_LABEL"
70+
required="1"
71+
/>
72+
73+
74+
</fieldset>
75+
76+
</fields>
77+
</config>
78+
</extension>

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<html><body></body></html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; Mattia Verga
2+
; Copyright (C) 2016. All rights reserved.
3+
; License GNU General Public License version 2 or later.
4+
; Note : All ini files need to be saved as UTF-8
5+
6+
PLG_CONTENT_AUTOMATICINTROIMAGE="Content - Automatic Intro Image"
7+
PLG_CONTENT_AUTOMATICINTROIMAGE_XML_DESCRIPTION="This plugin automatically create a resized version of the full size article image and set it as the intro image.<BR/>Simply enable the plugin, set parameters and let blank the intro image field when saving the article."
8+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_WIDTH_LABEL="Width of resized image"
9+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_WIDTH_DESCRIPTION="Set the width of the resized image. If 'maintain aspect ratio' option is selected, this value will act as the max width of the resized image."
10+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_HEIGHT_LABEL="Height of resized image"
11+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_HEIGHT_DESCRIPTION="Set the height of the resized image. If 'maintain aspect ratio' option is selected, this value will act as the max height of the resized image."
12+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_RATIO_LABEL="Maintain aspect ratio"
13+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_RATIO_DESCRIPTION="If selected, width and height will be resized proportionally."
14+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_TEXT_LABEL="Copy text"
15+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_TEXT_DESCRIPTION="If selected, the 'Alt' and 'Title' fields of the full article image will be copied in intro image fields."
16+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_SUFFIX_LABEL="Suffix of resized image"
17+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_SUFFIX_DESCRIPTION="This will be the suffix applied to the resized image."
18+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_YES="Yes"
19+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_NO="No"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
; Mattia Verga
2+
; Copyright (C) 2016. All rights reserved.
3+
; License GNU General Public License version 2 or later.
4+
; Note : All ini files need to be saved as UTF-8
5+
6+
PLG_CONTENT_AUTOMATICINTROIMAGE="Content - Automatic Intro Image"
7+
PLG_CONTENT_AUTOMATICINTROIMAGE_XML_DESCRIPTION="This plugin automatically create a resized version of the full size article image and set it as the intro image.<BR/>Simply enable the plugin, set parameters and let blank the intro image field when saving the article."
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; Mattia Verga
2+
; Copyright (C) 2016. All rights reserved.
3+
; License GNU General Public License version 2 or later.
4+
; Note : All ini files need to be saved as UTF-8
5+
6+
PLG_CONTENT_AUTOMATICINTROIMAGE="Content - Automatic Intro Image"
7+
PLG_CONTENT_AUTOMATICINTROIMAGE_XML_DESCRIPTION="Questo plugin crea automaticamente un'immagine ridimensionata a partire dall'immagine articolo esteso impostata per l'articolo.<BR/>Basta abilitare il plugin, selezionare l impostazioni e lasciare non compilata il campo 'Immagine introduttiva' durante il salvataggio dell'articolo."
8+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_WIDTH_LABEL="Larghezza immagine"
9+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_WIDTH_DESCRIPTION="Imposta la larghezza dell'immagine ridimensionata. Se è abilitata l'opzione 'Mantieni proporzioni', questo valore sarà la massima larghezza che l'immagine ridimensionata potrà assumere."
10+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_HEIGHT_LABEL="Altezza immagine"
11+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_HEIGHT_DESCRIPTION="Imposta l'altezza dell'immagine ridimensionata. Se è abilitata l'opzione 'Mantieni proporzioni', questo valore sarà la massima altezza che l'immagine ridimensionata potrà assumere."
12+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_RATIO_LABEL="Mantieni proporzioni"
13+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_RATIO_DESCRIPTION="Se abilitata, l'immagine verrà ridimensionata mantenendo le proporzioni dell'immagine originale."
14+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_TEXT_LABEL="Copia testo"
15+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_TEXT_DESCRIPTION="Se abilitata, verranno copiati nell'immagine introduttiva il testo alternativo e la didascalia impostati per l'immagine articolo esteso."
16+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_SUFFIX_LABEL="Suffisso dell'immagine ridimensionata"
17+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_SUFFIX_DESCRIPTION="Questo sarà il suffisso applicato all'immagine ridimensionata."
18+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_YES=""
19+
PLG_CONTENT_AUTOMATICINTROIMAGE_PARAM_NO="No"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
; Mattia Verga
2+
; Copyright (C) 2016. All rights reserved.
3+
; License GNU General Public License version 2 or later.
4+
; Note : All ini files need to be saved as UTF-8
5+
6+
PLG_CONTENT_AUTOMATICINTROIMAGE="Content - Automatic Intro Image"
7+
PLG_CONTENT_AUTOMATICINTROIMAGE_XML_DESCRIPTION="Questo plugin crea automaticamente un'immagine ridimensionata a partire dall'immagine articolo esteso impostata per l'articolo.<BR/>Basta abilitare il plugin, selezionare l impostazioni e lasciare non compilata il campo 'Immagine introduttiva' durante il salvataggio dell'articolo."

0 commit comments

Comments
 (0)