Skip to content

Commit b260c9c

Browse files
init commit
0 parents  commit b260c9c

6 files changed

+117
-0
lines changed

.project

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>maximages</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
</buildSpec>
9+
<natures>
10+
<nature>com.aptana.projects.webnature</nature>
11+
<nature>com.aptana.editor.php.phpNature</nature>
12+
</natures>
13+
</projectDescription>

_config/extensions.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
Name: maximages-extensions
3+
---
4+
Page:
5+
extensions:
6+
- ObjectImagesExtension

code/ObjectImagesExtension.php

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
class ObjectImagesExtension extends DataExtension {
3+
4+
private static $db = array(
5+
'Sorter' => 'Enum("SortOrder, Title, Name, ID")'
6+
);
7+
8+
private static $many_many = array(
9+
'Images' => 'Image'
10+
);
11+
12+
private static $many_many_extraFields = array(
13+
'Images' => array('SortOrder' => 'Int')
14+
);
15+
16+
public function updateCMSFields(FieldList $fields) {
17+
// Use SortableUploadField instead of UploadField!
18+
$limit = 20;
19+
$uploadClass = (class_exists("SortableUploadField") && $this->owner->Sorter == "SortOrder") ? "SortableUploadField" : "UploadField";
20+
$imageField = $uploadClass::create('Images', _t("Object.IMAGESUPLOADLABEL", "Images"));
21+
$imageField->setDescription(_t("Object.IMAGESUPLOADLIMIT","Images count limit: " . $limit));
22+
$imageField->setConfig('allowedMaxFileNumber', $limit);
23+
$imageField->setFolderName('Uploads/'.$this->owner->ClassName.'/'.$this->owner->ID);
24+
25+
$dropdownSorter = DropdownField::create('Sorter', _t("Object.IMAGESSORTER", "Sort imags by: "))->setSource($this->owner->dbObject('Sorter')->enumValues());
26+
27+
if ($this->owner->Sorter == "SortOrder") {
28+
$message =(class_exists("SortableUploadField")) ? _t("Object.IMAGESUPLOADHEADING", "<span style='color: green'>Sort images by draging thumbnail</span>") : _t("Object.IMAGESUPLOADHEADINGWRONG", "<span style='color: red'>Sorting images by draging thumbnails (SortOrder) not allowed. Missing module SortabeUploadField.</span>");
29+
} else {
30+
$message = _t("Object.IMAGESSORTERNOTICE", "Correct image sorting is visible on frontend only (if Sort by = Title, ID, Name)");
31+
}
32+
33+
$fields->addFieldToTab('Root.Images', HeaderField::create('ImagesNotice', $message)->setHeadingLevel(4));
34+
$fields->addFieldToTab('Root.Images', $dropdownSorter);
35+
$fields->addFieldToTab('Root.Images', $imageField);
36+
}
37+
38+
public function SortedImages(){
39+
return $this->owner->Images()->Sort($this->owner->Sorter);
40+
}
41+
42+
public function MainImage() {
43+
return $this->owner->Images()->Sort($this->owner->Sorter)->limit(1)->First();
44+
}
45+
46+
}
47+
48+
// EOF

composer.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "webmaxsk/maximages",
3+
"description": "Simple image gallery for any dataobject",
4+
"type": "silverstripe-module",
5+
"license": "BSD-3-Clause",
6+
"keywords": ["silverstripe", "gallery", "photos", "images"],
7+
"authors": [
8+
{
9+
"name": "Pali Ondras",
10+
"email": "ondras@webmax.sk"
11+
}
12+
],
13+
"require":
14+
{
15+
"silverstripe/framework": "3.1.*",
16+
"silverstripe/cms": "3.1.*",
17+
"bummzack/sortablefile": "*"
18+
},
19+
"suggest": {
20+
"heyday/silverstripe-optimisedimage": "*",
21+
"jonom/focuspoint": "*"
22+
}
23+
}

templates/MaxImagesBlockGrid.ss

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<%-- This template is based on zub foundation's block grid --%>
2+
<%-- Nondefault example: <% include MaxImagesBlockGrid classes="small-block-grid-5",noBorder=true %> --%>
3+
<% if SortedImages %>
4+
$addEffect("fancybox","gallery")
5+
<ul class="<% if classes %>$classes<% else %>small-block-grid-3<% end_if %>">
6+
<% loop SortedImages %>
7+
<li>
8+
<a class="gallery<% if not noBorder %> th<% end_if %>" href="$Full.Link" data-fancybox-group="gallery-$Top.ID" title="$Title">
9+
<img src="$Thumb.Link">
10+
</a>
11+
</li>
12+
<% end_loop %>
13+
</ul>
14+
<% end_if %>

templates/MaxImagesOrbit.ss

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<%-- This template is based on zub foundation's cleaing box --%>
2+
<%-- Nondefault example: <% include MaxImagesOrbit noBorder=true,showOnlyOne=true %> --%>
3+
<% if SortedImages %>
4+
<ul class="clearing-thumbs<% if $showOnlyOne %> clearing-feature<% end_if %>" data-clearing>
5+
<% loop SortedImages %>
6+
<li<% if showOnlyOne && First %> class="clearing-featured-img"<% end_if %>>
7+
<a <% if not noBorder %>class="th" <% end_if %>href="$Full.Link">
8+
<img data-caption="$Title" src="$CroppedImage(182,100).Link">
9+
</a>
10+
</li>
11+
<% end_loop %>
12+
</ul>
13+
<% end_if %>

0 commit comments

Comments
 (0)