generează-profilele-în-html.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * File name:
  4. *
  5. *
  6. * (C) Copyright 2013 Friedrich-Ebert-Stiftung (http://fes.ro)
  7. * Author: Tiberiu C. Turbureanu (tct@ceata.org)
  8. *
  9. * This file is part of the project funded by FES
  10. *
  11. * This is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. require_once 'utile.php';
  26. // Load the list of persons
  27. $xml = new DOMDocument();
  28. $xml->load('../20131013-consilieri.xml');
  29. $xpath = new DOMXpath($xml);
  30. $persons = $xpath->query("/xml/person");
  31. $pnames = new DOMDocument();
  32. $pnames->load('../numele-partidelor.xml');
  33. $xnames = new DOMXpath($pnames);
  34. // Load template for profiles
  35. $tpl = file_get_contents('../șabloane/profil.tpl');
  36. foreach($persons as $person)
  37. {
  38. // Copy template to page
  39. $page = $tpl;
  40. // Get index name
  41. $comname = $xpath->query("comname", $person)->item(0)->nodeValue;
  42. $surname = $xpath->query("surname", $person)->item(0)->nodeValue;
  43. $iname = $comname.'-'.$surname;
  44. $comnamep = $xpath->query("comnamep", $person)->item(0)->nodeValue;
  45. $surnamep = $xpath->query("surnamep", $person)->item(0)->nodeValue;
  46. $shortname = $comnamep.' '.$surnamep;
  47. $page = str_replace("<!-- iname -->", $iname, $page);
  48. // Load news page
  49. $news = file_get_contents('../consilieri/știri/'.$iname.'.html');
  50. $page = str_replace("<!-- news -->", $news, $page);
  51. // Load profile xml
  52. $xmla = new DOMDocument();
  53. $xmla->load('../profile/'.$iname.'.xml');
  54. $xpatha = new DOMXpath($xmla);
  55. $fullname = $xpatha->query("/xml/fullname")->item(0)->nodeValue;
  56. $comnamef = $xpatha->query("/xml/comname")->item(0)->nodeValue;
  57. $surnamef = $xpatha->query("/xml/surname")->item(0)->nodeValue;
  58. $birthdate = $xpatha->query("/xml/birthdate")->item(0)->nodeValue;
  59. if ($birthdate)
  60. {
  61. $age = intval((time() - strtotime($birthdate))/31536000);
  62. $age .= " de ani";
  63. $month = "";
  64. preg_match('/\.([0-9]+)\./', $birthdate, $month);
  65. $month = trim($month[0], ".");
  66. $month = $monthname1[$month];
  67. $birthdate = preg_replace('/\.(.*)\./', ' '.$month.' ', $birthdate);
  68. }
  69. else $age = "";
  70. $birthplace = $xpatha->query("/xml/birthplace")->item(0)->nodeValue;
  71. $occupation = $xpatha->query("/xml/occupation")->item(0)->nodeValue;
  72. $profession = $xpatha->query("/xml/profession")->item(0)->nodeValue;
  73. $party = $xpatha->query("/xml/party")->item(0)->nodeValue;
  74. $affiliation = $xpatha->query("/xml/affiliation")->item(0)->nodeValue;
  75. $sex = $xpatha->query("/xml/sex")->item(0)->nodeValue;
  76. $partyname = $xnames->query('//party[@id="'.strtolower($party).'"]')->item(0)->nodeValue;
  77. if ($party != $affiliation)
  78. $partyname .= ' ('.$xnames->query('//party[@id="'.strtolower($affiliation).'"]')->item(0)->nodeValue.')';
  79. if ($sex == "F")
  80. $sex = "feminin";
  81. else $sex = "masculin";
  82. $image = '../imagini/00-portrete/'.$iname.'.jpg';
  83. $placeholder = '../imagini/naught101-ProfilePlaceholderSuit.png';
  84. if (!file_exists($image))
  85. $image = $placeholder;
  86. $page = str_replace("<!-- comnamef -->", $comnamef, $page);
  87. $page = str_replace("<!-- surnamef -->", $surnamef, $page);
  88. $page = str_replace("<!-- fullname -->", $fullname, $page);
  89. $page = str_replace("<!-- shortname -->", $shortname, $page);
  90. $page = str_replace("<!-- birthdate -->", $birthdate, $page);
  91. $page = str_replace("<!-- birthplace -->", $birthplace, $page);
  92. $page = str_replace("<!-- occupation -->", $occupation, $page);
  93. $page = str_replace("<!-- profession -->", $profession, $page);
  94. $page = str_replace("<!-- party -->", $party, $page);
  95. $page = str_replace("<!-- partyname -->", $partyname, $page);
  96. $page = str_replace("<!-- affiliation -->", $affiliation, $page);
  97. $page = str_replace("<!-- sex -->", $sex, $page);
  98. $page = str_replace("<!-- image -->", $image, $page);
  99. $page = str_replace("<!-- age -->", $age, $page);
  100. $declarations = $xpatha->query("//declaration");
  101. $wealth = $interest = "";
  102. foreach($declarations as $declaration)
  103. {
  104. if ($declaration->getAttribute('type') == 'wealth')
  105. {
  106. if ($declaration->getAttribute('year') == '2012')
  107. $wealth .= '<li><a href="'.$declaration->getAttribute('file').'" target="_blank" class="extern">Declarația de început de mandat</a></li>';
  108. if ($declaration->getAttribute('year') == '2013')
  109. $wealth .= '<li><a href="'.$declaration->getAttribute('file').'" target="_blank" class="extern">Declarația pentru anul 2012</a></li>';
  110. }
  111. if ($declaration->getAttribute('type') == 'interest')
  112. {
  113. if ($declaration->getAttribute('year') == '2012')
  114. $interest .= '<li><a href="'.$declaration->getAttribute('file').'" target="_blank" class="extern">Declarația de început de mandat</a></li>';
  115. if ($declaration->getAttribute('year') == '2013')
  116. $interest .= '<li><a href="'.$declaration->getAttribute('file').'" target="_blank" class="extern">Declarația pentru anul 2012</a></li>';
  117. }
  118. }
  119. if ($wealth != "")
  120. $wealth = '<ul>'.$wealth.'</ul>';
  121. if ($interest != "")
  122. $interest = '<ul>'.$interest.'</ul>';
  123. $page = str_replace("<!-- wealth -->", $wealth, $page);
  124. $page = str_replace("<!-- interest -->", $interest, $page);
  125. $file = fopen('../consilieri/'.$iname.'.html', "w");
  126. fwrite($file, $page);
  127. fclose($file);
  128. }
  129. ?>