1<#assign instanceid = themeDisplay.getPortletDisplay().getId()?keep_after("INSTANCE_") />
2
3<#-- Ricavo servizi utili in seguito -->
4<#-- Servizio utile per ricavare le categorie -->
5<#assign catLocalService = serviceLocator.findService("com.liferay.asset.kernel.service.AssetCategoryLocalService") />
6
7<#-- Servizi utili per ricavare le immagini dalla D&M -->
8<#assign dlFileEntryLocalService = serviceLocator.findService('com.liferay.document.library.kernel.service.DLFileEntryLocalService') />
9<#assign dlUtil = serviceLocator.findService('com.liferay.document.library.kernel.util.DLUtil') />
10<#assign dlAppService = serviceLocator.findService('com.liferay.document.library.kernel.service.DLAppService') />
11
12<#-- Funzioni utilita -->
13<#-- Ripulisco stringa da caratteri speciali -->
14<#function escapeExtraChar text>
15 <#return text?replace("\"",""", "r")?replace("'","’", "r")>
16</#function>
17
18<#-- Verifico se il primo elemento di una lista esiste -->
19<#function firstOfListNotEmpty list>
20 <#assign result = false />
21 <#if list?? && list?has_content && list.getSiblings()?has_content && list.getSiblings()?first.getData()?has_content>
22 <#assign result = true />
23 </#if>
24 <#return result>
25</#function>
26
27<#-- Verifico che la lista di elementi dell'asset siano journal article -->
28<#function isJournalArticle renderer>
29 <#return ("com.liferay.journal.model.JournalArticle" == renderer.getClassName() ) >
30</#function>
31<#function getElements renderer>
32 <#assign journalArticle = renderer.getArticle() />
33 <#assign document = saxReaderUtil.read(journalArticle.getContent()) />
34 <#assign rootElement = document.getRootElement() />
35 <#return rootElement.elements() >
36</#function>
37
38<#-- Macro per loggare gli errori -->
39<#macro logData data>
40 <#assign logFactory = staticUtil["com.liferay.portal.kernel.log.LogFactoryUtil"]/>
41 <#assign log = logFactory.getLog('NEWS')/>
42 ${log.info(data)}
43</#macro>
44
45<#-- gestione categorie -->
46<#if themeDisplay.getScopeGroup().isStagingGroup() == true>
47 <#assign currentGroup = themeDisplay.getLayout().getGroup().getLiveGroup() />
48<#else>
49 <#assign currentGroup = themeDisplay.getLayout().getGroup() />
50</#if>
51
52<#-- ricavo la lista di vocabolari esclusi, separati da virgola -->
53<#assign listaIdVocabolariEsclusiStr = "" />
54<#if validator.isNotNull(currentGroup.getExpandoBridge())>
55 <#if currentGroup.getExpandoBridge().hasAttribute("lista_vocabolari_esclusi")>
56 <#if currentGroup.getExpandoBridge().getAttribute("lista_vocabolari_esclusi")??>
57 <#assign listaIdVocabolariEsclusiStr = currentGroup.getExpandoBridge().getAttribute("lista_vocabolari_esclusi")/>
58 </#if>
59 </#if>
60</#if>
61
62<#assign listaIdVocabolariEsclusi = [] />
63<#if listaIdVocabolariEsclusiStr != "">
64 <#assign parts = (listaIdVocabolariEsclusiStr)?split(",") />
65 <#list parts as part>
66 <#if part?has_content>
67 <#assign listaIdVocabolariEsclusi = listaIdVocabolariEsclusi + [part] />
68 </#if>
69 </#list>
70</#if>
71
72<#-- Se il carattere indicato è il prefisso della categoria, indica che la stessa non deve essere mostrata a video, ma viene solo usata per scopi funzionali -->
73<#assign PREFIX_SERVICE_CATEGORY = "_" />
74
75<#-- Ricavo tutte le categorie associate ad un articolo a meno di quelle che hanno un prefisso "_" o il cui vocabolario appartiene alla lista di vocabolari esclusi -->
76<#function getSpecificCategoriesByArticlePrimKey articlePrimKey>
77 <#assign tmp = "" />
78 <#assign articleCatNames = catLocalService.getCategories("com.liferay.journal.model.JournalArticle", getterUtil.getLong(articlePrimKey)) />
79 <#if (articleCatNames?size > 0)>
80 <#list articleCatNames as category>
81 <#if !(listaIdVocabolariEsclusi?seq_contains(category.getVocabularyId()?trim)) && (category.name?substring(0,1) != PREFIX_SERVICE_CATEGORY) >
82 <#assign tmp = tmp + category.name + ", " />
83 </#if>
84 </#list>
85 <#assign tmp = tmp?keep_before_last(",") />
86 </#if>
87 <#return tmp>
88</#function>
89
90<#-- INIZIO ADT -->
91<#if !entries?has_content>
92 <#if !themeDisplay.isSignedIn()>
93 ${renderRequest.setAttribute("PORTLET_CONFIGURATOR_VISIBILITY", true)}
94 </#if>
95 <div class="alert alert-info">
96 <@liferay_ui["message"] key="there-are-no-results" />
97 </div>
98</#if>
99
100<#if entries?has_content>
101 <section class="ufficio-stampa-news">
102 <h3 class="sr-only">Notizie</h3>
103
104 <#assign contatore = 0 />
105
106 <#list entries as curEntry>
107 <#assign contatore = contatore + 1 />
108 <#assign entryIndex = curEntry?index />
109
110 <#assign renderer = curEntry.getAssetRenderer() />
111
112 <#-- verifico che sia un journal article -->
113 <#if isJournalArticle(renderer)>
114
115 <#-- ricavo il primekey -->
116 <#assign articlePrimKey = renderer.getArticle().getResourcePrimKey() />
117
118 <#-- ricavo il titolo -->
119 <#assign titolo = escapeExtraChar(curEntry.getTitle(locale)) />
120
121 <#-- ricavo la data di pubblicazione: corretto rispetto a codice 7.1 -->
122 <#assign dataPubblicazione = renderer.getArticle().getDisplayDate()?date />
123 <#if "it_IT" == locale>
124 <#assign dataPubblicazione = dateUtil.getDate(dataPubblicazione, "dd/MM/yyyy", locale) />
125 <#else>
126 <#assign dataPubblicazione = dateUtil.getDate(dataPubblicazione, "yyyy/MM/dd", locale) />
127 </#if>
128
129 <#-- ricavo la view url -->
130 <#assign viewUrl = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, curEntry) />
131 <#if assetLinkBehavior != "showFullContent">
132 <#assign viewUrl = renderer.getURLViewInContext(renderRequest, renderResponse, viewUrl) />
133 </#if>
134
135 <#-- inizializzo le variabili che uso -->
136 <#assign categoria = "", title = "", description = "", image = "" />
137
138 <#-- recupero l'elenco delle categorie da visualizzare -->
139 <#assign categoria = getSpecificCategoriesByArticlePrimKey( articlePrimKey ) />
140
141 <#-- recupero i dati dalla struttura dell'articolo -->
142 <#list getElements(renderer) as dynamicElement>
143 <#if "title" == dynamicElement.attributeValue("name")>
144 <#assign title = dynamicElement.element("dynamic-content").getText() />
145 <#assign title = title?trim />
146 <#elseif "image" == dynamicElement.attributeValue("name")>
147 <#assign imageJString = dynamicElement.element("dynamic-content").getText() />
148 <#if imageJString?? && imageJString?has_content>
149 <#assign imageJson = imageJString?eval />
150 <#assign dlFileEntry = dlFileEntryLocalService.getFileEntryByUuidAndGroupId(imageJson.uuid, imageJson.groupId?number) />
151 <#assign fileEntry = dlAppService.getFileEntry(dlFileEntry.fileEntryId) />
152 <#assign dlFile = dlUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), themeDisplay, "") />
153 <#assign image = dlFile />
154 </#if>
155 <#elseif "description" == dynamicElement.attributeValue("name")>
156 <#assign description = dynamicElement.element("dynamic-content").getText() />
157 <#assign description = description?trim />
158 <#assign description = htmlUtil.extractText(description) />
159 </#if>
160 </#list>
161
162 <#-- HTML -->
163 <article class="clearfix">
164
165 <#-- ricavo il titolo articolo perchè mi serve anche come title su immagine -->
166 <#assign titoloArticolo = titolo/>
167 <#if title != "">
168 <#assign titoloArticolo = title/>
169 </#if>
170
171 <#-- ricavo immagine campo obbligatorio -->
172 <#if validator.isNotNull(image) && image != "">
173 <#attempt>
174
175 <#-- a partire dal link, lo splitto e ricavo il secondo ed il 5 argomento che mi servono per il metodo successivo -->
176 <#assign versionId = dlFileEntry.getLatestFileVersion(true).getFileVersionId() />
177 <#assign formMap = dlFileEntry.getDDMFormValuesMap(versionId) />
178
179 <#assign alt = "", watermark_title = "", watermark_color = "", watermark_position = "" />
180
181 <#-- ricavo i metadata associati al tipo di documento, se esistono-->
182 <#list formMap?keys as formKey>
183 <#assign formValues = formMap[formKey].getDDMFormFieldValues() />
184 <#if formValues??>
185 <#list formValues as formValue>
186 <#if formValue.getName() == "alt">
187 <#assign alt = escapeExtraChar(formValue.getValue().getString(locale)) />
188 <#elseif formValue.getName() == "watermark_title">
189 <#assign watermark_title = escapeExtraChar(formValue.getValue().getString(locale)) />
190 <#elseif formValue.getName() == "watermark_color">
191 <#assign watermark_color = escapeExtraChar(formValue.getValue().getString(locale)) />
192 <#elseif formValue.getName() == "watermark_position">
193 <#assign watermark_position = escapeExtraChar(formValue.getValue().getString(locale)) />
194 </#if>
195 </#list>
196 </#if>
197 </#list>
198 <#-- se l'alt non è valorizzato nel tipo di documento, prendo il valore variabile titoloArticolo, valorizzata con titolo nativo o se esiste titolo news -->
199 <#if alt == "">
200 <#assign alt = titoloArticolo />
201 </#if>
202
203 <a href="${viewUrl}" title="leggi la notizia ${titoloArticolo}" id="watermark-img-${instanceid}-${entryIndex}"></a>
204
205 <script type="text/javascript">
206 watermark(["${image}"])
207 <#if watermark_position == "top_right">
208 .image(watermark.text.upperRight('${watermark_title}', '20px titillium-semibold', '${watermark_color}', 1.0))
209 <#elseif watermark_position == "top_left">
210 .image(watermark.text.upperLeft('${watermark_title}', '20px titillium-semibold', '${watermark_color}', 1.0))
211 <#elseif watermark_position == "bottom_left">
212 .image(watermark.text.lowerLeft('${watermark_title}', '20px titillium-semibold', '${watermark_color}', 1.0))
213 <#else>
214 .image(watermark.text.lowerRight('${watermark_title}', '20px titillium-semibold', '${watermark_color}', 1.0))
215 </#if>
216 .then(function(img) {
217 img.className="img-fluid";
218 img.alt = '${alt}';
219 document.getElementById("watermark-img-${instanceid}-${entryIndex}").appendChild(img);
220 });
221 </script>
222
223 <#recover>
224
225 </#attempt>
226 </#if>
227
228 <#-- inizio parte testo -->
229
230 <#-- visualizzo categoria -->
231 <#if categoria != "">
232 <p class="categoria">${categoria}</p>
233 </#if>
234
235 <#-- visualizzo titolo -->
236 <h4>
237 <a href="${viewUrl}" title="leggi la notizia ${titoloArticolo}">
238 ${titoloArticolo}
239 </a>
240 </h4>
241
242 <#-- visualizzo description troncato a 309 caratteri -->
243 <#if validator.isNotNull(description) && description != "">
244 <#assign descriptionlength = description?length />
245 <#if descriptionlength gt 309>
246 <#assign description = description?substring(0, 309) />
247 <p>${description}[...]</p>
248 <#else>
249 <div>${description}</div>
250 </#if>
251 </#if>
252
253 </article>
254 </#if>
255 </#list>
256 </section>
257</#if>