<?php
######################################################################
# ZW3B.Site v7.1.2 : The Web Sites Management System
# --------------------------------------------------------------------
#
# Copyright (c) 2022 by LAB3W : O.Romain Jaillet-ramey - (orj+php+api@lab3w.fr)
#
# Date Create : 2022/08/15
# Date Modify : 2022/09/15
#
# Web Domain : lab3w.fr
# Web Domain : lab3w.com
#
# Web Domain : zw3b.fr
# Web Domain : zw3b.tv
# Web Domain : zw3b.site
# Web Domain : zw3b.net
# Web Domain : zw3b.blog
#
# Web Domain : ipv01.net
# Web Domain : ipv10.net
#
# This module is to manage ---------------------------- :: Descripton
#
# This program is free software. You can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
######################################################################

//----------------------------------------------------------------
// INI Config

ini_set('track_errors','on');
ini_set('display_errors','on');
ini_set('default_charset''UTF-8');

// INI Config
//----------------------------------------------------------------

//----------------------------------------------------------------
// Caching system

# On cache
#header("Cache-Control: max-age=300");
#header("Pragma: cache, max-age=300, max-stale=600");

# No cache
header("Cache-control: private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");

// Caching system
//----------------------------------------------------------------

//----------------------------------------------------------------
// Header Security

header('X-Frame-Options: deny'); // allows not to load this page from another site via an iframe

// Header Security
//----------------------------------------------------------------

//----------------------------------------------------------------
// Library zw3bApiClient

include '/var/pro/web_apps/zw3bApiClient/7.1.2/zw3bApiClient.class.php';

// Library zw3bApiClient
//----------------------------------------------------------------

//-------------------------------------------------------------------------
// CONFIGURATION

$config = array();

//-------------------------------------------------------------------------
// BETA-TESTEURS (Wilcard)

$config['api_name'] = 'BETA-TESTERS';
$config['client_project']['name'] = 'ZW3B-API-BETA-TESTERS';

// CONFIGURATION
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
// APPEL DE L'API CLIENTe

$zw3bApiClient = new zw3bApiClient();

$my_client $zw3bApiClient->ClientModUsr($config);

// APPEL DE L'API CLIENTe
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
// APPEL TOOLS

$tools $my_client->tools();

// APPEL TOOLS
//-------------------------------------------------------------------------

//echo 'SERVER : <pre>'.print_r(($_SERVER),1).'</pre>';

//-------------------------------------------------------------------------

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n";
echo 
'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
echo 
'<head>'."\n";
echo 
'<title>ZW3B :-: API Client * Contents * Docs</title>'."\n";
echo 
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>'."\n";
echo 
'<meta http-equiv="cache-control" content="no-cache"/>'."\n";
echo 
'<meta http-equiv="Pragma" content="no-cache"/>'."\n\n";

echo 
'<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>'."\n";
//echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>'."\n";
echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.min.js" integrity="sha512-qzgd5cYSZcosqpzpn7zF2ZId8f/8CHmFKZ8j7mU4OUXTNRd5g+ZHBPsgKEwoqxCtdQvExE5LprwwPAgoicguNg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>'."\n\n";

echo 
'<script type="text/javascript" src="https://www.zw3b.site/sys/modules/reports/dmarc/skins/zw3b-site/js/dmarc-analysis-sortable.js"></script>'."\n";
echo 
'<link rel="stylesheet" type="text/css" href="https://www.zw3b.site/sys/modules/reports/dmarc/skins/zw3b-site/css/dmarc-analysis.css" />'."\n\n";

echo 
'<style>';

echo 
'
html, body {
    color: #000;
}
a {
    color: #000;
    text-decoration: underline;
}

a:hover {
    text-decoration: none;
}

a:visited {
   color: #000; 
}

a.pagination {
    text-decoration: none;
    display: inline-block;
    padding: 5px;
    border: 1px dotted #000;
    background-color: #EEE;
}
a.pagination:hover, a.pagination.actif {
    text-decoration: none;
    border: 1px solid #000;
    background-color: #DDD;
}

code {
    background-color: #000;
    font-family: Consolas,"Andale Mono WT","Andale Mono","Lucida Console",Monaco,"Courier New",Courier,monospace, sans-serif;
    color: #BBB;
    padding: 2px 5px;
    font-size: 80%;
    border: 1px dashed #EEE;
}
pre {
    margin-top: 0;
    margin-bottom: 10px;
    margin-left: 0;
    border: 1px dotted #000;
    background-color: #888;
    /*padding-top: 10px;
    padding-bottom: 7px;
    padding-left: 10px;
    padding-right: 10px;
    */
    padding: 0;
    padding-left: 5px;
    padding-bottom: 7px;
    overflow: auto;
    font-family: Consolas,"Andale Mono WT","Andale Mono","Lucida Console",Monaco,"Courier New",Courier,monospace, sans-serif;
    color: #BBB;
    font-size: 100%;
}
pre.code{
    background-color:#000;
}
p.pcode {
    background-color:#000;
    color: #FFF;
    padding: 10px 5px;
    margin: 0;
    border-bottom: 1px dotted #888;
    font-family: Consolas,"Andale Mono WT","Andale Mono","Lucida Console",Monaco,"Courier New",Courier,monospace, sans-serif;

}

span.numero-de-ligne {
    padding: 0 10px 0px 0px;
    color: #FFF;
}
div.retirer-numeros-de-lignes {
    padding: 0 5px;
    font-size: 0.8em;
    margin-top: -10px;
}
span.link_nbr {
    padding: 0px 5px;
    min-width: 10px;
    min-height: 10px;
    display:inline-block;
    
    border-radius: 10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    
    -moz-box-shadow: -1px 1px 1px #AAA;
    -webkit-box-shadow: -1px 1px 1px #AAA;
    box-shadow: -1px 1px 1px #AAA;
    
    background-color: #EEE;
            
    border: 1px solid #AAA;
    
    text-align: center;
    font-size: 80%;
}

p.desc {
    padding: 20px;
    margin:  20px 0;
    border: 1px dotted #000;
    background-color: #EEE;
    font-size: 1.2em;
}
p.author {
    padding: 20px;
    margin:  20px 0;
    border: 1px dotted #000;
    font-size: 1.2em;
}
div.contents {
    font-size: 1.2em;
}
p.button a {
    display: block;
    float: none;
    padding: 20px 30px;
    margin: 10px;
    font-family: Impact, sans-serif;
    font-size: 150%;
    letter-spacing: 0.5px;
    background-color: transparent;
    border: 10px solid #333;
}
p.button.left {
    float: left;
}
p.button.right {
    float: right;
}
p.button a {
    color: #565656;
    text-decoration: none;
}
p.button a:hover {

}
hr {

}
hr.hr1 {

}
hr.hr2 {

}
hr.clear {
    margin-top: 15px;
    margin-bottom: 20px;
    border: 0;
    background-color: transparent;
    visibility: hidden;
    height: 0px;
    clear: both;
}
.redaction_en_cours {
    overflow: auto;
    padding: 30px 20px;
    margin-bottom: 0px;
    border: 2px dashed #888;
    background-color: transparent;
    font-weight: bold;
    color: #565656;
}
.googletranslate {
    float: right;
    margin-top: -50px;
    margin-right: 20px;
}
'
;

echo 
'</style>';

echo 
'<script>';
echo 
"
///////////////////////////////////////////////
//CACHE NUM LIGNE CODE
function hidenumbers(div) {
    if (!document.getElementsByTagName) return;
    var pre = document.getElementById(div);
    var spans = pre.getElementsByTagName('span');
    var i = 0;
    while (i < spans.length) {
        if (spans[i].className == 'numero-de-ligne') {
            spans[i].parentNode.removeChild(spans[i])
            // pre.removeChild(spans[i]);
        } else {
            i++;
        }
    }
}
//CACHE NUM LIGNE CODE
///////////////////////////////////////////////

"
;
echo 
'</script>';

echo 
'<link rel="shortcut icon" href="https://www.zw3b.site/skins/zw3b-site/css/img/zw3b-logo-20x20.png" />'."\n\n";
echo 
'</head>'."\n";

echo 
'<body>'."\n";

echo 
'<h1><a href="https://www.zw3b.fr">ZW3B</a> :-: <a href="https://api.zw3b.fr">API Client</a> * Contents * <a href="https://api.zw3b.fr/api-client-contents-docs.php">Docs</a> by LAB3W.<acronym title="O.Romain.Jaillet-ramey" lang="FR">ORJ</acronym></h1>'."\n";

echo 
'<p class="googletranslate"><a onclick="window.open(this.href); return false;" href="https://translate.google.com/translate?hl=auto&sl=fr&tl=en&u=http://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"].'&sandbox=0">Translate this page</a></p>';
//-------------------------------------------------------------------------

$my_client = ($my_client);
if(isset(
$my_client) && isset($my_client->authentification->client) && is_object($my_client->authentification->client))
{
    if(isset(
$my_client->authentification->client->name))
        echo 
'<p>Name : '.$my_client->authentification->client->name.'</p>'."\n";
        
        if(isset(
$my_client->authentification->project) && is_object($my_client->authentification->project) && isset($my_client->authentification->project->name))
            echo 
'<p>Project name : '.$my_client->authentification->project->name.'</p>'."\n";
}


if(isset(
$my_client->authentification->message))
{
    echo 
'<p>';
    echo 
''.$my_client->authentification->message.' - ';
    if(isset(
$my_client->authentification->reason) && is_object($my_client->authentification->reason) && isset($my_client->authentification->reason->status))
        echo 
'<span>'.$my_client->authentification->reason->status.' - '.$my_client->authentification->reason->text.'</span>';
        echo 
'</p>'."\n";
}

//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
$languages_auth = array('FR''EN''ES''AR');

$langue = isset($_GET['l']) && !empty($_GET['l']) && in_array(strToUpper($_GET['l']), $languages_auth) ? $_GET['l']  : 'FR';

if(isset(
$_GET['id']) && !empty($_GET['id']))
{
    
$content = new zw3bApiClientModContents($my_client);
    
    
$doc $content->docs()->get(array(
        
'cid' => $_GET['id'],
        
'l' => $langue
        
)
    );
    
    
$read_doc json_decode($doc);
    
    echo 
'<h2>'.$read_doc->tree->tree_filariane.', <a title="Permalink : '.$read_doc->content->doc->data->content_url.'" href="'.$read_doc->content->doc->data->content_url.'" onclick="window.open(this.href); return false;">'.$read_doc->content->doc->data->content_title.'</a></h2>'."\n";
    
    echo 
'<p class="desc">'.$read_doc->content->doc->data->content_desc.'</p>'."\n";
    echo 
'<p class="author">Author : '.$read_doc->user->pseudonym.'</p>'."\n";

    
//echo 'CONTENT<pre>'.print_r(($read_doc),1).'</pre>';
    
    
echo '<div class="contents">'.$tools->link_replace_callback($read_doc->content->doc->data->content_text).'</div>';
    
    echo 
'<hr /><br /><br />'."\n";
    
    
}
else {

    
$contents = new zw3bApiClientModContents($my_client);
    
    
$nbr 10;
    
    
$offset = isset($_GET['p']) && !empty($_GET['p']) ? $nbr $_GET['p'] - $nbr 0;
    
$nombre = isset($_GET['p']) ? $nbr $nbr;
    
    
$docs $contents->docs()->lst(array(
        
'offset' => $offset,
        
'limit' => $nombre,
        
'l' => $langue
        
)
    );
    
    
$read_docs json_decode($docs);

    
//echo 'CONTENTS<pre>'.print_r(($read_docs),1).'</pre>';
    
    
if(isset($read_docs->contents->docs->items) && is_array($read_docs->contents->docs->items)):
    
        echo 
'<h2>CONTENTs</h2>'."\n";
        
        echo 
'<h3>Liste des <a href="https://www.zw3b.fr" title="ZW3B :-: The Web XXI">ZW3B</a> docs ('.$read_docs->contents->docs->count.')</h3>'."\n";
        
        
$pages ceil($read_docs->contents->docs->count $nbr);
        
        echo 
'Pages ('.$pages.') : ';
        for(
$p=1$p <= $pages$p++):
        echo 
'<a class="pagination '.(isset($_GET['p']) && $_GET['p'] == $p 'actif' null).'" href="?p='.$p.'">'.$p.'</a>'.($p $pages ' | ' '');
        endfor;
        
        foreach(
$read_docs->contents->docs->items as $doc):
        
            echo 
'<div class="item">'."\n";
            
//echo '<h4><a href="?id='.$doc->content_cid.'">DOC ID</a> : '.$doc->tree->tree_filariane.' : <a href="'.$doc->content_url.'">'.$doc->content_title.'</a></h4>'."\n";
            
echo '<h4>'.$doc->tree->tree_filariane.' <a href="?id='.$doc->content_cid.'">'.$doc->content_title.'</a></h4>'."\n";
            echo 
'<p class="desc">'.$doc->content_description.'</p>'."\n";
            echo 
'</div>'."\n";
            
            echo 
'<hr />'."\n";
    
        endforeach;
        
        echo 
'Pages ('.$pages.') : ';
        for(
$p=1$p <= $pages$p++):
            echo 
'<a class="pagination '.(isset($_GET['p']) && $_GET['p'] == $p 'actif' null).'" href="?p='.$p.'">'.$p.'</a>'.($p $pages ' | ' '');
        endfor;
        
        echo 
'<hr /><br /><br />'."\n";
        
    endif;
    
}

//-------------------------------------------------------------------------

?>