The module operates with images attached to elements of other modules. The module consists of two parts: the part of the hook and the work of the module in the administrative part.
Подключаемая часть – файл modules/images/images.inc.php. В нем описан класс
Images_inc. В модуле к объекту класса можно обратиться через переменную $this->diafan->_images
. Экземпляр класса создается при первом вызове
переменной.
array get (string $variation, integer $element_id, string $module_name, string $element_type, integer $site_id, string $alt, [integer $param_id = 0], [integer $count = 0], [string $link_to = ''], [string $tmpcode = '']) – Получает изображения, прикрепленные к элементу модуля.
Example:
// get 2 images attached to the goods,
// image link leads to a larger copy of the image,
// in the module "Online shop" in the file modules/shop/shop.model.php
$images = $this->diafan->_images->get("medium", $id, "shop", "element", $site_id, "Название товара", false, 2, "large");
// output the files in the module template
// in the file modules/shop/views/shop.view.id.php
foreach($images as $img)
{
echo '<a href="'.BASE_PATH_HREF.$img["link"].'">'
.'<img src="'.$img["src"].'" width="'.$img["width"]
.'" height="'.$img["height"]
.'" alt="'.$img["alt"].'" title="'.$img["title"].'">'
.'</a> ';
}
All combinations of the image contained in the array $img["vs"]
for each image files in the loop. The array keys are the tags of combinations specified in the module settings.
Example:
// output all images "preview" tagged
foreach($images as $img)
{
echo '<img src="'.$img["vs"]["preview"].'">';
}
Consider how this can be used in the module template.
Example:
In the settings of the module "Online shop" for products in the list of image combinations ("Generate images size") has created three combinations, created system and tagged "large", "medium", "preview". The webmaster has created an additional combination of the image in the interface "Images settings". In the settings of the module he added that the combination and tagged "new". Settings applied to images already uploaded.
Now in the template product card modules/shop/views/shop.view.id.php he may apply to the new image size as follows:
// loop on all loaded images
foreach ($result["img"] as $img)
{
// outputs image, tagged "medium"
echo '<img src="'.$img["src"].'" width="'.$img["width"].'" height="'.$img["height"].'" alt="'.$img["alt"].'" title="'.$img["title"].'">';
// outputs image, tagged "large"
echo '<img src="'.BASE_PATH.$img["link"].'">';
// outputs image, tagged "new"
echo '<img src="'.$img["vs"]["new"].'">';
}
As can be seen from the example the image size (width "width" and height "height") are defined only for the image tag labeled "medium". If you specify these attributes for any other size of the image, the image will simply be expanded or shrunk by the specified size of the browser, which could result in a distorted display.
In this example, the variable $img["link"]
contains a reference to the size of the tag labeled "large". In the list of products that may contain of the variable is a reference to the product card (if not removed all of the images). Therefore, a relative link and it should be used together with the constants BASE_PATH
or BASE_PATH_HREF
.
In all other modules of the template image data presented in the same format. If the outputs of the card, the images recorded in pemerennuyu $result["img"]
. When outputting the image in the list of items, then $result
replace the name of a variable that contains data about the element in the cycle. For example, the list of goods is a variable $row
. For a list of categories of a variable $cat
, for sub-categories list is a variable $child
.
It is in the module "Online shop" in the item card there is a variable $img["preview"]
, which contains a reference to the size of the image "preview", if it exists in the module settings. In this case, you can still add the conclusion of this combitation:
// if in the settings define combitation tagged "preview"
if($result["preview_images"])
{
// loop on all loaded images
foreach ($result["img"] as $img)
{
// outputs image, tagged "preview"
echo '<img src="'.$img["preview"].'">';
}
}
array prepare (integer $element_id, string $module_name, [string $element_type = 'element'], [integer $param_id = 0]) – Запоминает данные об элементах, которым нужно вывести прикрепленные изображения.
Example:
// in this example will be done 3 SQL-queries to db to get images for all identified ads
$ids = array(3, 5, 7);
foreach($ids as $id)
{
$images[$id] = $this->diafan->_images->get('medium', $id, 'ab', 'element', 5, "Объявление", false, 2, "large");
}
Example:
// in this example will be done 1 SQL-query to db to get images for all identified ads
$ids = array(3, 5, 7);
foreach($ids as $id)
{
$this->diafan->_images->prepare($id, 'ab');
}
foreach($ids as $id)
{
$images[$id] = $this->diafan->_images->get('medium', $id, 'ab', 'element', 5, "Объявление", false, 2, "large");
}
void delete (integer|array $element_ids, string $module_name, [string $element_type = 'element'], [integer $param_id = false]) – Удаляет прикрепленные изображения.
Example:
// delete all images attached to category ID=3 in the module "Files"
$this->diafan->_images->delete(3, "files", "cat");
// delete all images attached to categories ID=3,5,6 in the module "Files"
$this->diafan->_images->delete(array(3, 5, 6), "files", "cat");
void delete_row (array $row) – Удаляет одно изображение.
Example:
// get data on image ID=3
$row = DB::query_fetch_array("SELECT * FROM {images} WHERE id=3");
// delete image
$this->diafan->_images->delete_row($row);
void delete_module (string $module_name) – Удаляет все изображения модуля.
Example:
// delete image attached to all ads and ads categories
$this->diafan->_images->delete_module('ab');
mixed upload (integer $element_id, string $module_name, string $element_type, integer $site_id, sting $tmpfile, string $new_name, [boolean $handle = false], [integer $param_id = 0], [string $tmpcode = '']) – Загружает прикрепленные изображения.
Example:
try
{
// upload image to brand ID=5 in the module "Online shop" attached to site page ID=3
$this->diafan->_images->upload(5, 'shop', 'brand', 3, $_FILES["images"], 'proizvoditel_oop');
}
catch(Exception $e)
{
// loading error message
echo $e->getMessage();
}
void get_variation_image (string $file_name, string $module_name, array $variation, integer $folder_num, [boolean $handle = false], [boolean $after_selectarea = false]) – Применяет вариант к изображению.
Example:
// get data to images combination, which will be used to image
$variation = DB::query_fetch_array("SELECT * FROM {images_variations} WHERE id=5");
// generate image copy in getting combination
$this->diafan->_images->get_variation_image("izobrazhenie_tovara.jpg", "shop", $variation, 0);
In the file of module settings (modules/модуль/admin/модуль.admin.config.php) and in the file of editing elements of the module (modules/модуль/admin/модуль.admin.php) you must add the parameter
'images'
:
Example:
public $variables = array(
'main' => array(
'images' => 'module',
…
),
…
);
The administrative part of the module identifies options images, which are then used in the module settings and visual editor.
Combinations of images have the following properties:
Image settings are specified in the module settings, which are attached to the image. You must define the following parameters of the module:
Use image – allows you to enable / disable image loading.
Generate image size – the size of the image set in the module "Images" and tag latin characters to an image on the site. It must be given in two sizes: a preview of the images in the list (medium tag) and the full image (tag large). The parameter is displayed if the option is checked "Use Image".
Display images in the list – parameter accepts values:
Use images for categories – allows you to enable / disable image loading categories.
Generate image size for categories – image sizes defined in the module "Izobarazheniya 'and tag Latin characters to an image on the site. It must be given in two sizes: a preview of the image in the list of categories (tag medium) and the full image (tag large). The parameter is displayed if the option is checked "Use images for categories."
Display images in categories list – parameter accepts values:
Apply settings to earlier uploaded images – it allows you to convert the size of already uploaded images. The button is required if change the image size setting. The parameter is displayed if the option is checked "Use Image".
Use animation when increasing images – setting adds a JavaScript code, you can activate the animation by increasing the image. The parameter is displayed if the option is checked "Use Image".
Maximum size of uploaded files – this parameter indicates the maximum size of uploaded files, installed in the hosting settings. The parameter is displayed if the option is checked "Use Image".
{images} – Attached images
{images_editor_folders} – Папки изображений в плагине для визуального редактора
{images_variations} – Варианты загрузки изображений
modules/images/admin/images.admin.php – Редактирование вариантов генерирования изображений;
modules/images/admin/images.admin.action.php – Обработка POST-запросов при работе с изображениями в административной части;
modules/images/admin/images.admin.inc.php – Connecting the module to the administrative part of other modules;
modules/images/admin/images.admin.view.php – Шаблон вывода изображений в административной части;
modules/images/admin/js/images.admin.inc.config.js – Подключение модуля к настройкам других модулей, JS-сценарий;
modules/images/admin/js/images.admin.inc.js – Connecting the module to the administrative part of other modules, JS-сценарий;
modules/images/admin/js/images.admin.js – Редактирование вариантов генерирования изображений, JS-сценарий;
modules/images/images.editor.php – Плагин для визуального редактора;
modules/images/images.editor.css – Плагин для визуального редактора, CSS;
modules/images/images.inc.php – Подключение для работы с прикрепленными изображениями;
modules/images/images.install.php – Module installation;
modules/images/js/images.editor.js – Плагин для визуального редактора, JS-сценарий.