Wiki zdrojový kód pre VelocityMacros
Naposledy upravil Admin-metais MetaIS 2024/10/30 11:04
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{velocity output="false"}} | ||
2 | #set ($LONG_MAX_VALUE = $mathtool.pow(2,63)) | ||
3 | #set ($licensorId = 'com.xwiki.licensing:application-licensing-licensor-api') | ||
4 | #set ($licensingConfigDoc = $xwiki.getDocument('Licenses.Code.LicensingConfig')) | ||
5 | #set ($storeBuyURL = $licensingConfigDoc.storeBuyURL) | ||
6 | #set ($storeAccessURL = $licensingConfigDoc.storeAccessURL) | ||
7 | #set ($ownerObj = $licensingConfigDoc.getObject('Licenses.Code.LicensingOwnerClass')) | ||
8 | #set ($userCount = $services.licensing.licensor.userCount) | ||
9 | |||
10 | #macro (getPaidExtensions) | ||
11 | #set ($paidExtensionsByNamespace = $services.extension.installed.getBackwardDependencies($licensorId)) | ||
12 | #set ($paidExtensions = $collectiontool.set) | ||
13 | #foreach ($paidExtensionsOnNamespace in $paidExtensionsByNamespace.values()) | ||
14 | #set ($discard = $paidExtensions.addAll($paidExtensionsOnNamespace)) | ||
15 | #end | ||
16 | #end | ||
17 | |||
18 | #macro (getVisiblePaidExtensions) | ||
19 | #getPaidExtensions | ||
20 | #set ($visiblePaidExtensions = $collectiontool.set) | ||
21 | #foreach ($paidExtension in $paidExtensions) | ||
22 | ## Filter out the paid extensions that are dependencies of other paid extensions (because the license of a paid | ||
23 | ## extension should cover its paid dependencies). | ||
24 | #isRequiredBy($paidExtension $paidExtensions) | ||
25 | #if (!$isRequiredBy) | ||
26 | #set ($discard = $visiblePaidExtensions.add($paidExtension)) | ||
27 | #end | ||
28 | #end | ||
29 | #end | ||
30 | |||
31 | #macro (isRequiredBy $installedExtension $extensions) | ||
32 | #set ($isRequiredBy = false) | ||
33 | #set ($backwardDependencies = $collectiontool.queue) | ||
34 | #addBackwardDependencies($installedExtension $backwardDependencies) | ||
35 | ## We can't iterate the queue while modifying it and we can't write a "while" loop in Velocity so we're forced to | ||
36 | ## rely on a range loop (limiting the number of backward dependencies that we analyze). | ||
37 | #foreach ($i in [0..1000]) | ||
38 | #set ($backwardDependency = $backwardDependencies.poll()) | ||
39 | #if ($backwardDependency) | ||
40 | #if ($extensions.contains($backwardDependency)) | ||
41 | #set ($isRequiredBy = true) | ||
42 | #break | ||
43 | #else | ||
44 | #addBackwardDependencies($backwardDependency $backwardDependencies) | ||
45 | #end | ||
46 | #else | ||
47 | #break | ||
48 | #end | ||
49 | #end | ||
50 | #end | ||
51 | |||
52 | #macro (addBackwardDependencies $installedExtension $backwardDependencies) | ||
53 | #set ($backwardDependenciesSet = $collectiontool.set) | ||
54 | #set ($discard = $backwardDependenciesSet.addAll($backwardDependencies)) | ||
55 | #set ($backwardDependenciesByNamespace = $services.extension.installed.getBackwardDependencies($installedExtension.id)) | ||
56 | #foreach ($backwardDependenciesOnNamespace in $backwardDependenciesByNamespace.values()) | ||
57 | #foreach ($backwardDependency in $backwardDependenciesOnNamespace) | ||
58 | #if ($backwardDependenciesSet.add($backwardDependency)) | ||
59 | #set ($discard = $backwardDependencies.add($backwardDependency)) | ||
60 | #end | ||
61 | #end | ||
62 | #end | ||
63 | #end | ||
64 | |||
65 | #macro (getLicensesAdminSectionURL) | ||
66 | ## We target the main wiki explicitly because licenses are managed globally. | ||
67 | #if ($xwiki.exists($services.model.createDocumentReference($xcontext.mainWikiName, 'XWiki', 'ConfigurableClass'))) | ||
68 | $xwiki.getURL($services.model.createDocumentReference($xcontext.mainWikiName, 'XWiki', 'XWikiPreferences'), | ||
69 | 'admin', 'editor=globaladmin§ion=Licenses')## | ||
70 | #else | ||
71 | ## Fall-back in case the Administration Application is not installed. | ||
72 | $xwiki.getURL($services.model.createDocumentReference($xcontext.mainWikiName, 'Licenses', 'WebHome'))## | ||
73 | #end | ||
74 | #end | ||
75 | |||
76 | #macro (getInstanceIdFormField) | ||
77 | <dt> | ||
78 | <label for="instanceId">$services.localization.render('licensor.ownerDetails.instanceId.label')</label> | ||
79 | <span class="xHint">$services.localization.render('licensor.ownerDetails.instanceId.hint')</span> | ||
80 | </dt> | ||
81 | <dd> | ||
82 | #getInstanceIdInput(false) | ||
83 | </dd> | ||
84 | #end | ||
85 | |||
86 | #macro (getInstanceIdInput $hidden) | ||
87 | #set ($type = 'text') | ||
88 | #if ($hidden) | ||
89 | #set ($type = 'hidden') | ||
90 | #end | ||
91 | <input type="$type" name="instanceId" id="instanceId" value="${services.instance.getInstanceId()}" readonly /> | ||
92 | #end | ||
93 | |||
94 | #macro (getOwnerFormFields) | ||
95 | #foreach ($prop in $ownerObj.properties) | ||
96 | <dt> | ||
97 | <label for="${prop.name}">$services.localization.render("licensor.ownerDetails.${prop.name}.label")</label> | ||
98 | #set ($hintTranslationKey = "licensor.ownerDetails.${prop.name}.hint") | ||
99 | #set ($hint = $services.localization.render($hintTranslationKey)) | ||
100 | #if ($hint != $hintTranslationKey) | ||
101 | <span class="xHint">$!escapetool.xml($hint)</span> | ||
102 | #end | ||
103 | </dt> | ||
104 | #set ($inputType = 'text') | ||
105 | #if ($prop.name == 'email') | ||
106 | #set ($inputType = 'email') | ||
107 | #end | ||
108 | <dd><input type="$inputType" name="${prop.name}" id="${prop.name}" value="$!{prop.value}" /></dd> | ||
109 | #end | ||
110 | #end | ||
111 | |||
112 | #macro (displayOwnerDetailsForm) | ||
113 | {{html clean=false}} | ||
114 | <form id="ownerDetails" target="_blank" class="xform half" action="${storeBuyURL}" method="post"> | ||
115 | <fieldset class="header"> | ||
116 | <legend>$services.localization.render('licensor.ownerDetails.heading')</legend> | ||
117 | <p>$services.localization.render('licensor.ownerDetails.hint')</p> | ||
118 | <input type="hidden" name="form_token" value="$!escapetool.xml($services.csrf.token)" /> | ||
119 | <dl> | ||
120 | #getOwnerFormFields | ||
121 | #getInstanceIdFormField | ||
122 | </dl> | ||
123 | </fieldset> | ||
124 | </form> | ||
125 | {{/html}} | ||
126 | #end | ||
127 | |||
128 | #macro (licenseButton $licenseType $cssClass $iconName $key $jsonData) | ||
129 | #set ($jsonData.licenseType = $licenseType) | ||
130 | #set ($label = $escapetool.xml($services.localization.render("licensor.${key}License.label"))) | ||
131 | <a href="#$escapetool.xml($key)" class="action licenseButton licenseButton-$escapetool.xml($key)" | ||
132 | data-button="$escapetool.xml($jsontool.serialize($jsonData))" title="$label"> | ||
133 | <span class="action-icon"><span class="fa fa-$iconName"></span></span>## | ||
134 | <span class="action-label">$label</span> | ||
135 | </a> | ||
136 | #end | ||
137 | |||
138 | #macro (autoUpgradeButton $extensionId) | ||
139 | #set ($licensingConfigDoc = $xwiki.getDocument('Licenses.Code.LicensingConfig')) | ||
140 | #set ($autoUpgradesObj = $licensingConfigDoc.getObject('Licenses.Code.AutomaticUpgradesClass')) | ||
141 | #set ($isAutoUpgrade = $autoUpgradesObj.getValue('allowlist').contains($extensionId)) | ||
142 | #set ($upgradeL10nKey = "#if ($isAutoUpgrade)prevent#{else}allow#end") | ||
143 | <div class="btn-group"> | ||
144 | <form target="_blank" class="xform half"> | ||
145 | <input type="hidden" name="form_token" value="$!escapetool.xml($services.csrf.token)" /> | ||
146 | <input type="hidden" name="extensionId" value="$!escapetool.xml($extensionId)" /> | ||
147 | <input type="hidden" name="autoUpgrade" value="$!escapetool.xml($isAutoUpgrade)" /> | ||
148 | <a href="#autoUpgrade" class="action licenseButton-autoUpgrade" title="$escapetool.xml( | ||
149 | $services.localization.render("licensor.moreActions.autoUpgrade.${upgradeL10nKey}"))" > | ||
150 | <span class="action-icon #if ($isAutoUpgrade)isAutoUpgrade#end"> | ||
151 | <span class="fa fa-cloud-download"></span>## | ||
152 | </span><span class="action-label">$escapetool.xml( | ||
153 | $services.localization.render('licensor.moreActions.autoUpgrade.label')) | ||
154 | </span> | ||
155 | </a> | ||
156 | </form> | ||
157 | </div> | ||
158 | #end | ||
159 | |||
160 | #macro(feedbackButton $extension) | ||
161 | #set ($licensingConfigDoc = $xwiki.getDocument('Licenses.Code.LicensingConfig')) | ||
162 | #set ($jsonData = { | ||
163 | 'featureId': $extension.id.id, | ||
164 | 'extensionVersion': $extension.id.version.toString(), | ||
165 | 'storeFeedbackURL': $licensingConfigDoc.storeFeedbackURL | ||
166 | }) | ||
167 | #licenseButton('' 'primary' 'comment' 'feedback' $jsonData) | ||
168 | #end | ||
169 | |||
170 | #macro (getLicenseActions $license $extension $actions) | ||
171 | ## Use the JSON format in order to be parsable in JavaScript. | ||
172 | #set ($jsonData = { | ||
173 | 'featureId': $extension.id.id, | ||
174 | 'extensionVersion': $extension.id.version.toString(), | ||
175 | 'userCount': $userCount | ||
176 | }) | ||
177 | #if (!$license || $license.expirationDate == 0) | ||
178 | ## No license available. | ||
179 | #set ($discard = $actions.add("#licenseButton('PAID' 'success' 'shopping-cart' 'paid' $jsonData)")) | ||
180 | #set ($discard = $actions.add("#licenseButton('TRIAL' 'primary' 'hourglass-start' 'trial' $jsonData)")) | ||
181 | #elseif ($license.type == 'FREE') | ||
182 | #set ($discard = $actions.add("#licenseButton('PAID' 'success' 'shopping-cart' 'paid' $jsonData)")) | ||
183 | #elseif ($license.type == 'TRIAL') | ||
184 | #set ($discard = $actions.add("#licenseButton('PAID' 'success' 'shopping-cart' 'paid' $jsonData)")) | ||
185 | #set ($discard = $actions.add("#licenseButton('TRIAL' 'primary' 'hourglass-end' 'extendTrial' $jsonData)")) | ||
186 | #elseif ($license.type == 'PAID') | ||
187 | #set ($discard = $actions.add("#licenseButton('PAID' 'success' 'shopping-cart' 'extendPaid' $jsonData)")) | ||
188 | #end | ||
189 | #end | ||
190 | |||
191 | #macro (licenseActions $license $extension) | ||
192 | #set ($actions = []) | ||
193 | ## Pull the resources needed by license actions. | ||
194 | #set ($discard = $services.icon.use('Font Awesome')) | ||
195 | #getLicenseActions($license $extension $actions) | ||
196 | <div class="licenseActions container-fluid"> | ||
197 | <div class="row"> | ||
198 | $stringtool.join($actions, '') | ||
199 | </div> | ||
200 | <div class="row"> | ||
201 | #autoUpgradeButton($extension.id.id) | ||
202 | #feedbackButton($extension) | ||
203 | </div> | ||
204 | </div> | ||
205 | #end | ||
206 | |||
207 | #macro(webmecanikForm $webmecanikID) | ||
208 | <div class="webmecanikForm"> | ||
209 | <input type="hidden" name="webmecanikID" value="${webmecanikID}"> | ||
210 | ## This is the recommended way for automatically inserting a form from Webmecanik using Mautic. | ||
211 | <script type="text/javascript" src="\/\/news.xwiki.com/form/generate.js?id=${webmecanikID}"></script> | ||
212 | </div> | ||
213 | #end | ||
214 | |||
215 | #macro(feedbackForm) | ||
216 | {{html clean="false" wiki="true"}} | ||
217 | <div class="modal fade" id="feedbackFormModal" tabindex="-1" role="dialog" aria-labelledby="feedbackFormModal-label"> | ||
218 | <div class="modal-dialog" role="document"> | ||
219 | <div class="modal-content"> | ||
220 | <div class="modal-header"> | ||
221 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
222 | <span aria-hidden="true">×</span> | ||
223 | </button> | ||
224 | <div class="modal-title" id="feedbackFormModal-label"> | ||
225 | $escapetool.xml($services.localization.render('licensor.feedbackLicense.title')) | ||
226 | </div> | ||
227 | </div> | ||
228 | <div class="modal-body"> | ||
229 | ## This is the Pro Apps feedback form ID from Webmecanik. | ||
230 | #set ($webmecanikID = '89') | ||
231 | #webmecanikForm($webmecanikID) | ||
232 | </div> | ||
233 | </div> | ||
234 | </div> | ||
235 | </div> | ||
236 | {{/html}} | ||
237 | #end | ||
238 | {{/velocity}} |