<commit_before><?php
/*
    Copyright (C) 2018 <NAME> (http://q37.info/contact/).

    This file is part of XDHq.

    XDHq is free software: you can redistribute it and/or
    modify it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    XDHq is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with XDHq If not, see <http://www.gnu.org/licenses/>.
*/

function getAtlas() {
 if (getenv("EPEIOS_SRC") === false) {
  $atlasPath = "phar://Atlas.phar/";
 } else {
  switch (strtoupper(substr(php_uname('s'), 0, 3))) {
  case "WIN":
   $epeiosPath = "h:\\hg\\epeios\\";
   break;
  case "LIN":
   $epeiosPath = "/home/csimon/hg/epeios/";
   break;
  case "DAR":
   $epeiosPath = "/Users/csimon/hg/epeios/";
   break;
  default:
   die("Unknown OS !!!\n");
   break;
  }

  $atlasPath = $epeiosPath . "tools/xdhq/Atlas/ZND/";
 }

 require $atlasPath . "Atlas.php";
}

getAtlas();

function getViewModeElements() {
 return ["Pattern", "CreateButton", "DescriptionToggling", "ViewNotes"];
}

function push($note, $id, $tree) {
 $tree .= "<Note";
 $tree .= " id=\"" . $id . "\">\n";

 foreach ((array) $note as $key => $value) {
  $tree .= "<" . $key . ">" . htmlspecialchars($value) . "</" . $key . ">\n";
 }

 return $tree . "</Note>";
}

function readAsset($path) {
 // Due to multi-threading constraints, a global variable can not be used here.
 return Atlas::readAsset($path, "notes");
}

class Notes extends Threaded {
 public $pattern = "";
 public $hideDescriptions = false;
 public $id = 0;
 public $notes = [
  // First one must be empty; it is used as buffer for new entries.
  [
   'title' => '',
   'description' => '',
  ],
  [
   'title' => 'Improve design',
   'description' => 'Tastes and colors... (aka &laquo;CSS aren&rsquo;t my cup of tea...&raquo;)',
  ],
  [
   'title' => 'Fixing bugs',
   'description' => 'There are bugs ? Really ?',
  ],
  [
   'title' => 'Implement new functionalities',
   'description' => "Although it&rsquo;s almost perfect..., isn&rsquo;t it ?",
  ],
 ];

 function handleDescriptions($dom) {
  if ($this->hideDescriptions) {
   $dom->disableElement("ViewDescriptions");
  } else {
   $dom->enableElement("ViewDescriptions");
  }
 }

 function displayList($dom) {
  $tree = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<XDHTML>\n";
  $i = 1; // 0 skipped, as it serves as buffer for the new ones.
  $contents = [];

  $tree .= "<Notes>\n";

  $count = count($this->notes);

  while ($i < $count) {
   if (strtolower(substr($this->notes[$i]['title'], 0, strlen($this->pattern))) === $this->pattern) {
    $tree = push($this->notes[$i], $i, $tree);
    $contents["Description." . $i] = $this->notes[$i]['description'];
   }
   $i++;
  }

  $tree .= "</Notes>\n";
  $tree .= "</XDHTML>";

  $dom->setLayoutXSL("Notes", $tree, "Notes.xsl");
  $dom->setContents($contents);
  $dom->enableElements(getViewModeElements());
 }

 function edit($dom, $id) {
  $this->id = intval($id);
  $dom->setLayout("Edit." . $id, readAsset("Note.html"));
  $dom->setContents(
   [
    "Title" => $this->notes[$this->id]['title'],
    "Description" => $this->notes[$this->id]['description'],<commit_msg>30/10/2018 22:46:12<commit_after><?php
/*
    Copyright (C) 2018 <NAME> (http://q37.info/contact/).

    This file is part of XDHq.

    XDHq is free software: you can redistribute it and/or
    modify it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    XDHq is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with XDHq If not, see <http://www.gnu.org/licenses/>.
*/

function getAtlas() {
 if (getenv("EPEIOS_SRC") === false) {
  $atlasPath = "phar://Atlas.phar/";
 } else {
  switch (strtoupper(substr(php_uname('s'), 0, 3))) {
  case "WIN":
   $epeiosPath = "h:\\hg\\epeios\\";
   break;
  case "LIN":
   $epeiosPath = "/home/csimon/hg/epeios/";
   break;
  case "DAR":
   $epeiosPath = "/Users/csimon/hg/epeios/";
   break;
  default:
   die("Unknown OS !!!\n");
   break;
  }

  $atlasPath = $epeiosPath . "tools/xdhq/Atlas/ZND/";
 }

 require $atlasPath . "Atlas.php";
}

getAtlas();

function getViewModeElements() {
 return ["Pattern", "CreateButton", "DescriptionToggling", "ViewNotes"];
}

function push($note, $id, &$tree) {
 $notes = $tree->xdhtml->notes;
 $notes->note = $tree->createElement( "Note" );
 $notes->note->setAttribute( "id", $id );

 foreach ((array)$note as $key => $value) {
  $item = $tree->createElement( $key );
  $item->nodeValue = htmlspecialchars( $value );
  $notes->note->appendChild( $item );
 }

  $notes->appendChild( $notes->note );
}

function readAsset($path) {
 // Due to multi-threading constraints, a global variable can not be used here.
 return Atlas::readAsset($path, "notes");
}

class Notes extends Threaded {
 public $pattern = "";
 public $hideDescriptions = false;
 public $id = 0;
 public $notes = [
  // First one must be empty; it is used as buffer for new entries.
  [
   'title' => '',
   'description' => '',
  ],
  [
   'title' => 'Improve design',
   'description' => 'Tastes and colors... (aka &laquo;CSS aren&rsquo;t my cup of tea...&raquo;)',
  ],
  [
   'title' => 'Fixing bugs',
   'description' => 'There are bugs ? Really ?',
  ],
  [
   'title' => 'Implement new functionalities',
   'description' => "Although it&rsquo;s almost perfect..., isn&rsquo;t it ?",
  ],
 ];

 function handleDescriptions($dom) {
  if ($this->hideDescriptions) {
   $dom->disableElement("ViewDescriptions");
  } else {
   $dom->enableElement("ViewDescriptions");
  }
 }

 function displayList($dom) {
  $tree = new DOMDocument( "1.0", "utf8" );
  $tree->xdhtml = $tree->CreateElement( "XDHTML");
  $tree->appendChild( $tree->xdhtml );
  $i = 1; // 0 skipped, as it serves as buffer for the new ones.
  $contents = [];

  $tree->xdhtml->notes = $tree->createElement( "Notes" );
  $tree->xdhtml->appendChild( $tree->xdhtml->notes );

  $count = count($this->notes);

  while ($i < $count) {
   if (strtolower(substr($this->notes[$i]['title'], 0, strlen($this->pattern))) === $this->pattern) {
    push($this->notes[$i], $i, $tree);
    $contents["Description." . $i] = $this->notes[$i]['description'];
   }
   $i++;
  }

  $dom->setLayoutXSL("Notes", $tree->saveXML(), "Notes.xsl");
  $dom->setContents($contents);
  $dom->enableElements(getViewModeElements());
 }

 function edit($dom, $id) {
  $this->id = intval($id);
  $dom->setLayout("Edit." . $id, readAsset("Note.html"));
  $dom->setContents(
   [
    "Title" => $this->notes[$this->id]['title'],
    "Description" => $this->notes[$this->id]['description'],
{'fraction_non_alphanumeric': 0.18809034907597535, 'fraction_numerical': 0.006297056810403833, 'mean_word_length': 3.521039603960396, 'pattern_counts': {'":': 6, '<': 20, '<?xml version=': 1, '>': 100, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4369357', 'n_tokens_mistral': 2559, 'n_tokens_neox': 2459, 'n_words': 665}