<?xml version="1.0" encoding="utf-8"?>

<list>
  <item type="dictionary">
    <dictionary>
      <item key="data"><![CDATA[## Script (Python) "manage_cachepurge"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=*** DO NOT DELETE OR MODIFY ***
##
# ################################################
# IMPORTANT NOTE: 
# 1. This Script needs an External Method
# cache_purge(url) purging the cached data
# 2. Please, modify line 26/27, if your 
# published URLs contain '/content'
# ################################################
request = container.REQUEST
RESPONSE = request.RESPONSE

msg = []
urls = []
ip_or_domain = context.getConfProperty('ASP.ip_or_domain','')
url = context.getHref2IndexHtml({'lang':request['lang'],'preview':''})

if len(ip_or_domain)>0 and url.find('/content')>-1:
	# url = ip_or_domain + url
	if ip_or_domain.find('/content') > 0:
		url = ip_or_domain + url.split('/content')[1]
	else:
		url = ip_or_domain + '/content' + url.split('/content')[1]
else:
	# strip protocol
	url = url.replace('https://','').replace('http://','')

# purge both http/https
for p in ['https://','http://']:
	u = p + url
	try:
		msg.append( context.cache_purge( u ) )
	except:
		msg.append( 'Error: nginx_purge %s' %u )

return '<br />'.join(msg)
]]>
      </item>
      <item key="description"></item>
      <item key="execution" type="int">1</item>
      <item key="icon_clazz"><![CDATA[icon-refresh fa fa-refresh]]></item>
      <item key="id"><![CDATA[manage_cachepurge]]></item>
      <item key="meta_type"><![CDATA[Script (Python)]]></item>
      <item key="meta_types" type="list">
        <list>
          <item><![CDATA[ZMSDocument]]></item>
          <item><![CDATA[ZMSFolder]]></item>
          <item><![CDATA[ZMS]]></item>
          <item><![CDATA[type(ZMSDocument)]]></item>
        </list>
      </item>
      <item key="name"><![CDATA[Cache-Purge]]></item>
      <item key="revision"><![CDATA[3.0.2]]></item>
      <item key="roles" type="list">
        <list>
          <item><![CDATA[ZMSAdministrator]]></item>
          <item><![CDATA[ZMSEditor]]></item>
        </list>
      </item>
      <item key="title"><![CDATA[Löscht den Cache Eintrag dieses Dokument-Knotens]]></item>
    </dictionary>
  </item>
  <item type="dictionary">
    <dictionary>
      <item key="data"><![CDATA[<!DOCTYPE html>
<html lang="en">
<!-- IMPORTANT: This script needs an External Method cache_purge(url) purging the cached data from file system -->
	<tal:block tal:content="structure python:here.zmi_html_head(here,request)">zmi_html_head</tal:block>
	<body class="zmi">
	<tal:block tal:content="structure python:here.zmi_body_header(here,request)">zmi_body_header</tal:block>

	<div id="zmi-tab">
		<tal:block tal:content="structure python:here.zmi_breadcrumbs(here,request)">zmi_breadcrumbs</tal:block>
		<div class="alert alert-success"
				tal:define="urls python:here.string_list(request.get('url_list',''))"
				tal:condition="python:request.get('btn','')=='purge' and len(urls)>0">
			<ol>
				<li tal:repeat="u urls" tal:content="python:here.cache_purge(u.replace('&','\&').split('#')[0])">u</li>
			</ol>
		</div>

		<form action="manage_cachepurge_list" method="post" class="form-horizontal form-initialized"
			tal:define="ip_or_domain python:here.getConfProperty('ASP.ip_or_domain',request.get('BASE0','').split('://')[1] );
				protocol python:here.getConfProperty('ASP.protocol',request.get('BASE0','').split('://')[0])">
			<div class="form-group row" tal:define="reset_preview python:request.set('preview',None)">
				<label class="col-sm-2 control-label" for="urlList"><span>URL List</span></label>
				<div class="col-sm-10">
					<textarea class="form-control url_list ger" id="url_list" name="url_list" rows="15" wrap="virtual"
						tal:attributes="placeholder python:'%s://%s'%(protocol,ip_or_domain)"
						><tal:block tal:condition="python:request.get('btn','')=='all_urls' or request.get('btn','')=='this_url'"
							tal:define="url python:here.getHref2IndexHtml({'lang':request.get('lang',here.getPrimaryLanguage()),'preview':''});
								url python:( ip_or_domain in url ) and url or ( protocol + '://' + ip_or_domain + url.split('/content')[1] )"
								tal:replace="python: len(url.split('index_'))>1 and '%s\n%s\n'%(url,url.split('index_')[0]) or '%s\n'%(url)">node url</tal:block
						><tal:block
							tal:condition="python:request.get('btn','')=='all_urls'"
							tal:repeat="ob python:here.filteredTreeNodes(request,here.PAGES,max_len=None)"
							><tal:block tal:define="url python:ob.getHref2IndexHtml({'lang':request.get('lang',here.getPrimaryLanguage()),'preview':''});
								url python:( ip_or_domain in url ) and url or ( protocol + '://' + ip_or_domain + url.split('/content')[1] )"
								tal:replace="python: len(url.split('index_'))>1 and '%s\n%s\n'%(url,url.split('index_')[0]) or '%s\n'%(url)">node url</tal:block
						></tal:block
					></textarea>
				</div>
			</div>
			<div class="form-group row" tal:define="reset_preview python:request.set('preview','preview')">
				<div class="controls save">
					<button type="submit" name="btn" class="btn btn-secondary" value="this_url" title="Write this URL into List">Get this URL</button>
					<button type="submit" name="btn" class="btn btn-warning" value="all_urls" title="Recursively write all dependent URLs into List">Get URLs recursivly</button>
					<button type="submit" name="btn" class="btn btn-primary" value="purge" title="Start Purging the listed URLs">Purge Listed URLs</button>
					<button type="submit" name="btn" class="btn btn-secondary" value="back" tal:content="python:here.getZMILangStr('BTN_CANCEL')">Cancel</button>
				</div>
			</div>
		</form>
	</div>
	<tal:block tal:content="structure python:here.zmi_body_footer(here,request)">zmi_body_footer</tal:block>
</body>
</html>]]>
      </item>
      <item key="description"></item>
      <item key="execution" type="int">0</item>
      <item key="icon_clazz"><![CDATA[icon-refresh fa fa-refresh]]></item>
      <item key="id"><![CDATA[manage_cachepurge_list]]></item>
      <item key="meta_type"><![CDATA[Page Template]]></item>
      <item key="meta_types" type="list">
        <list>
          <item><![CDATA[ZMS]]></item>
        </list>
      </item>
      <item key="name"><![CDATA[Cache-Purge (List)]]></item>
      <item key="revision"><![CDATA[3.0.0]]></item>
      <item key="roles" type="list">
        <list>
          <item><![CDATA[ZMSAdministrator]]></item>
          <item><![CDATA[ZMSEditor]]></item>
        </list>
      </item>
      <item key="title"><![CDATA[Liste von URLs aus dem Cache löschen]]></item>
    </dictionary>
  </item>
</list>