Search:
Template:Directories > Template:XsysPrStore

Template:XsysPrStore

    Table of contents
    No headers
    /* 
    //    Copyright (C) 2010 - www.intertesto.com - www.fitzcarraldo.it
    //    Author: gianluca.sabena@intertesto.com - adrian.policarp@fitzcarraldo.it
    //
    //    This program is free software: you can redistribute it and/or modify
    //    it under the terms of the GNU General Public License  http://www.gnu.org/licenses/gpl-2.0.html
    //    
    // ------ Docs ----------------------
    // This script query and render page properties in a specific path. See XsysPrEdit()
    // ------------------ Config ----------------------------------------
    */
    var extradata = $extradata ?? []; /* list of extradata value to add to listglobal (pagedata, firstparagraph, firstimage,commentsnumber)*/
    var inputs = $fields ?? [ ]; /* list of maps - configure form fields - see XsysPrEdit()*/ 
    var prlist = $prlist ?? ["formdata"]; /* list - list of properties name to extract (Attention: field must be presents in all properties) */
    var getsearch = $getsearch ?? []; /* list of 4 values, the same passed to wiki.getsearch() */
    var pathsearch = $pathsearch ?? []; /*  string|list - page path where looking for properties (if last char is an asterisk * the first subpage level is append) */
    var isrenderhtml =  $isrenderhtml ?? true; /* render field based on type, add some html */
    var output = string.tolower($output ?? "table-simp"); /* div | table-simp | table-ext | map */
    var listorderby = $listorderby ?? ""; /*passed to list.orderby before store data */
    var firstSelectValue = "---null-select---"; /* value saved as first option in a html drop down menu */
    var cachestoreid = $cachestoreid ?? string.join(prlist,"-"); /* name id to use with webcache.store */
    var cachettl = $cachettl ?? 86400; /* time for the cache to live in seconds */
    var filtername = $filtername ?? ""; /* filter output based o a fieldname */
    var filtervalue = $filtervalue ?? ""; /* filter this value of filtername */
    var cache = {};
    var debug = false; // mus be exactly true or false
    if (user.name == 'wikiadmin') let debug = true;
    
    /* ------------------- init ----------------------------------------- */
    var fieldvalues = list.collect(inputs,'field');
    var pl = {}; var errors = ""; var listglobal = []; var mapsingle= {};
    if (typeof(pathsearch) == 'string') let pathsearch = [pathsearch];
    
    if (#pathsearch > 0 ) {
      foreach (var searchpagepath in pathsearch ) {
        var path = "";
        if (string.startswith(searchpagepath,'/')) let searchpagepath = string.remove(searchpagepath,0,1);
        if (string.endswith(searchpagepath,'/')) let path = string.remove(searchpagepath,#searchpagepath-1,1);
        else if (string.endswith(searchpagepath,'/*')) let path = string.remove(searchpagepath,#searchpagepath-2,2);
        else let path = searchpagepath;
        var t = wiki.getpage(path);
        let pl ..= {(t.name):t};
        if (string.endswith(searchpagepath,'/*')) let pl ..= t.subpages;
        else let pl ..= {(t.name):t};
      }
    } else if (#getsearch > 0 ){
      let pl = wiki.getsearch(getsearch[0],getsearch[1],getsearch[2],getsearch[3]);
    }
    
    /* ------------------- Extract ----------------------------------------- */
      foreach (var p in pl) {
        foreach (var property in prlist) {
          var properties=[];
          if (#p.properties[property].text > 0){
            let properties = json.parse(p.properties[property].text );
          }
          foreach (var data in properties) {
            if ( p.path > 0) { 
              let listsingle = [];
              let mapsingle = {  };
              let mapsingle ..= { 'pageid' : p.id };
              if (list.contains(extradata,'pagedata') ) {
                let mapsingle ..= { 'pageuri' : p.uri };
                let mapsingle ..= { 'pagetitle' : p.title };
                let mapsingle ..= { 'pagedate' : p.date };
                let mapsingle ..= { 'pagename' : p.name };
                let mapsingle ..= { 'pageauthor' : p.author.name }; 
              }
              if (list.contains(extradata,'firstparagraph')) {
                var t = xml.list(p.xml,"//p[not(@class)]/text()",nil,true);
                var out="";
                foreach(var i in t) {
                  if(#string.trim(i)>0 && #out==0) let out = i;
                }
                let mapsingle ..= { 'firstparagraph' : out};
              }
              if (list.contains(extradata,'firstimage')) {
                var firstimage = string.match(string.tolower(xml.text(p.xml,'/page/content/body[1]',nil,true)),'(/@api/[^.]+(.png|.jpg|.jpeg|.gif))');
                let mapsingle ..= {'firstimage':firstimage};
              }
              if (list.contains(extradata,'commentsnumber')) {
                let mapsingle ..= {'commentsnumber':#p.comments};
              }
              foreach ( var input in inputs where (#data[input.field] >0 && data[input.field]!=firstSelectValue ) ) {
                  let mapsingle ..= { (input.field) : data[input.field] };
              }
            }
            let listglobal ..= [mapsingle];
          }
        } 
      } 
    if (#filtername >0 ) let listglobal = list.select(listglobal,"$['syscheckfilter']==true");
    if(#listglobal>0) let listglobal = list.orderby(listglobal, listorderby);
    let cache = {data:listglobal, user:user.name, date:date.Format(date.now, "s"), pagepath:page.path, query:string.join(pathsearch,"-")..string.join(getsearch,"-")};
    var d = webcache.store(cachestoreid,cache,cachettl);
    
    
    
    

    Files (0)

     

    Comments (0)

    You must login to post a comment.