publish.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. <?php
  2. date_default_timezone_set('Europe/Bucharest');
  3. error_reporting(-1);
  4. ini_set('display_errors', '1');
  5. $nest = "";
  6. $type = "pagini";
  7. define("HOSTNAME", "ceata.org");
  8. // Verify file argument.
  9. if (isset($argv[1]) && $argv[1] == '-a')
  10. {
  11. $all = get_all_files("tpl");
  12. foreach ($all as $file)
  13. {
  14. if ($file == "") continue;
  15. $file = $file.".tpl";
  16. $type = get_type($file);
  17. echo ucfirst($type).": ".$file."\n";
  18. publish($file, $type);
  19. }
  20. update_sitemap();
  21. }
  22. else if (isset($argv[1]) && $argv[1] == '-h')
  23. {
  24. update_sitemap();
  25. }
  26. else if (isset($argv[1]))
  27. {
  28. // Verify file name argument.
  29. if (substr($argv[1], -4) != ".tpl")
  30. {
  31. echo "Eroare: nu a fost specificat argumentul cu fișierul .tpl. Utilizare: php publish.php <fișier.tpl>\n";
  32. die();
  33. }
  34. // TODO: Filename should not start with '/' (should be relative)
  35. // TODO: Check if the file exists
  36. $type = get_type($argv[1]);
  37. // Publish or update the article.
  38. publish($argv[1], $type);
  39. }
  40. // else if(isset($argv[1]) && $argv[1] == '-all')
  41. // {
  42. // // Get all articles templates.
  43. // $articles = glob("*.tpl");
  44. // // Publish or update all articles.
  45. // foreach ($articles as $article)
  46. // {
  47. // // Publish or update the article.
  48. // publish($article);
  49. // }
  50. // }
  51. else
  52. {
  53. echo "Eroare: nu a fost specificat argumentul cu fișierul .tpl. Utilizare: php publish.php <fișier.tpl>\n";
  54. die();
  55. }
  56. function get_all_files($ext)
  57. {
  58. return explode("\n", shell_exec("find . -path ./templates -prune -o -name \"*.".$ext."\" -print | sed -e 's/\.".$ext."//g' | sort | sed -e \"s/\.\///g\""));
  59. }
  60. function get_type($file)
  61. {
  62. $type = "pagini";
  63. $pos = strpos($file, "news");
  64. if ($pos !== false && $pos == 0)
  65. $type = "news";
  66. else
  67. {
  68. $pos = strpos($file, "events");
  69. if ($pos !== false && $pos == 0)
  70. $type = "events";
  71. }
  72. return $type;
  73. }
  74. function get_news_brief($file)
  75. {
  76. $city = get_text($file, "city");
  77. $country = get_text($file, "country");
  78. $date = get_text($file, "date");
  79. $brief = get_text($file, "brief");
  80. $rodate = rodate($date);
  81. $brief = $city.", ".$country." -- ".$rodate[0].", ".$rodate[1]." -- ".$brief;
  82. return $brief;
  83. }
  84. function get_event_brief($file)
  85. {
  86. $date = get_text($file, "date");
  87. $hours = get_text($file, "hours");
  88. $city = get_text($file, "city");
  89. $country = get_text($file, "country");
  90. $room = get_text($file, "room");
  91. $host = get_text($file, "host");
  92. $address = get_text($file, "address");
  93. $brief = get_text($file, "brief");
  94. $rodate = rodate($date);
  95. $brief = $city.", ".$country." -- ".$rodate[0].", ".$rodate[1].", orele ".$hours." -- ".$room.", ".$host.", ".lcfirst($address).". ".$brief;
  96. return $brief;
  97. }
  98. function get_brief($file, $type)
  99. {
  100. $brief = "";
  101. if (!strcmp($type, "news"))
  102. {
  103. $brief = get_news_brief($file);
  104. }
  105. else if (!strcmp($type, "events"))
  106. {
  107. $brief = get_event_brief($file);
  108. }
  109. return $brief;
  110. }
  111. function get_event_details($file)
  112. {
  113. $date = get_text($file, "date");
  114. $rodate = rodate($date);
  115. $hours = get_text($file, "hours");
  116. $city = get_text($file, "city");
  117. $country = get_text($file, "country");
  118. $room = get_text($file, "room");
  119. $host = get_text($file, "host");
  120. $address = get_text($file, "address");
  121. $brief = get_text($file, "brief");
  122. $contactname = get_text($file, "contactname");
  123. $contactmail = tomail(get_text($file, "contactmail"));
  124. $contactphone = get_text($file, "contactphone");
  125. $details = "<table class=\"detalii\">";
  126. $details .= "<tr><th>Data</th><td>".$rodate[1]."</td></tr>";
  127. $details .= "<tr><th>Orele</th><td>".$hours."</td></tr>";
  128. $details .= "<tr><th>Orașul</th><td>".$city.", ".$country."</td></tr>";
  129. $details .= "<tr><th>Sala</th><td>".$room."</td></tr>";
  130. $details .= "<tr><th>Gazda</th><td>".$host."</td></tr>";
  131. $details .= "<tr><th>Adresa</th><td>".$address."</td></tr>";
  132. if ($contactname)
  133. {
  134. $details .= "<tr><th>Coordonator</th><td>";
  135. $details .= "<table class=\"contact\">";
  136. $details .= "<tr><td>".$contactname."</td></tr>";
  137. if ($contactmail)
  138. $details .= "<tr><td>".$contactmail."</td></tr>";
  139. if ($contactphone)
  140. $details .= "<tr><td>".$contactphone."</td></tr>";
  141. $details .= "</table>";
  142. $details .= "</td></tr>";
  143. }
  144. $details .= "<tr><th>Calendar</th><td>vCal, iCal</td></tr>";
  145. $details .= "</table>";
  146. return $details;
  147. }
  148. function get_press_release($file)
  149. {
  150. $press = get_text($file, "pressrelease");
  151. if ($press)
  152. $press = "Pentru mai multe informații, vă invităm să citiți <a href=\"/news/".$press."\">comunicatul oficial</a>.";
  153. return $press;
  154. }
  155. function get_content($file, $type)
  156. {
  157. $content = get_html($file, "content");
  158. if (!strcmp($type, "events"))
  159. {
  160. $details = get_event_details($file);
  161. $press = get_press_release($file);
  162. $report = get_html($file, "report");
  163. if ($report)
  164. $report = "<h3 id='raport'>Raportul evenimentului</h3>".$report;
  165. $content = $details.$content.$report.$press;
  166. }
  167. return $content;
  168. }
  169. function get_press_contact($file, $type)
  170. {
  171. $press = "";
  172. if (!strcmp($type, "news"))
  173. {
  174. $press = "<h3>Contact pentru presă</h3>";
  175. }
  176. else if (!strcmp($type, "events"))
  177. {
  178. $press = "<h3>Coordonatorul evenimentului</h3>";
  179. }
  180. $contactname = get_text($file, "contactname");
  181. $contactfunc = get_text($file, "contactfunc");
  182. $contactmail = tomail(get_text($file, "contactmail"));
  183. $contactphone = get_text($file, "contactphone");
  184. if ($contactname)
  185. {
  186. $press .= "<p>";
  187. $press .= $contactname."<br />";
  188. if ($contactfunc)
  189. $press .= $contactfunc.", Fundația Ceata<br />";
  190. if ($contactmail)
  191. $press .= $contactmail."<br />";
  192. if ($contactphone)
  193. $press .= $contactphone."<br />";
  194. $press .= "</p>";
  195. }
  196. else
  197. $press = "";
  198. return $press;
  199. }
  200. /**
  201. * Publish function.
  202. *
  203. * Publishes a post by creating a HTML file of the post and update the news page.
  204. *
  205. * @param $file
  206. * File name of the article content.
  207. */
  208. function publish($file, $type)
  209. {
  210. global $news_templates_path;
  211. $nested_level = substr_count($file, '/');
  212. $nested = str_repeat("../", $nested_level);
  213. // Read header template.
  214. $article = read_template("templates/header.ro.tpl");
  215. if (strcmp($type, "pagini"))
  216. {
  217. // Read content template.
  218. $article .= read_template("templates/article.ro.tpl");
  219. $brief = get_brief($file, $type);
  220. // Update the published date.
  221. $article = str_replace("<!-- brief -->", $brief, $article);
  222. $press_contact = get_press_contact($file, $type);
  223. // Update the the press contact.
  224. $article = str_replace("<!-- press -->", $press_contact, $article);
  225. }
  226. else
  227. {
  228. $article .= read_template("templates/page.ro.tpl");
  229. }
  230. // Read the article.
  231. $article .= read_template("templates/footer.ro.tpl");
  232. // Read footer template.
  233. $article_content = read_template($file);
  234. // Get the article data.
  235. $title = get_text($file, "title");
  236. $content = get_content($file, $type);
  237. // Update the the site title.
  238. $article = str_replace("<!-- site-title -->", $title . " &mdash; Fundația Ceata &mdash; Ceata eliberează artele și tehnologiile actuale", $article);
  239. // Update the the title.
  240. $article = str_replace("<!-- title -->", $title, $article);
  241. $article = str_replace("<!-- breadcrumbs -->", get_breadcrumbs($file), $article);
  242. // Update the the content.
  243. $article = str_replace("<!-- content -->", $content, $article);
  244. // Update the article style path.
  245. $article = str_replace("stylesheet\" href=\"", "stylesheet\" href=\"".$nested, $article);
  246. // Update the article favicon.
  247. $article = str_replace("shortcut icon\" href=\"", "shortcut icon\" href=\"".$nested, $article);
  248. // Update the article images path.
  249. // TODO: fix this if needed
  250. // $article = str_replace("<img src=\"", "<img src=\"", $article);
  251. // Get the article file name without extention.
  252. $filename = substr_replace($file,"",-4);
  253. if (file_exists($filename.".html"))
  254. {
  255. update_sitemap();
  256. }
  257. // Create or update the article.
  258. create_page($filename.".html", $article);
  259. echo "-- ".$filename.".html - articol publicat/actualizat.\n";
  260. if (strcmp($type, "pagini"))
  261. {
  262. // Generate feed from published articles.
  263. generate_feed($type);
  264. // Generate news page.
  265. generate_news_page($type);
  266. }
  267. }
  268. function get_breadcrumbs($file)
  269. {
  270. $trail = "";
  271. $count = 0;
  272. $breadcrumbs = "<li><a href='/'>Prima pagină</a></li>";
  273. $file = strtok($file, ".");
  274. $lvls = substr_count($file, "/");
  275. $parent = strtok($file, "/");
  276. while ($parent)
  277. {
  278. $trail .= $parent;
  279. $title = "";
  280. if (file_exists($trail.".ro.tpl"))
  281. $title = get_text($trail.".ro.tpl", "title");
  282. else if (is_link($trail.".ro.html"))
  283. {
  284. $count++;
  285. $trail .= "/";
  286. $parent = strtok("/");
  287. continue;
  288. }
  289. else if (file_exists($trail.".ro.html"))
  290. $title = ucfirst($trail);
  291. else $title = "Pagină necunoscută";
  292. if ($count < $lvls)
  293. $breadcrumbs .= "<li> &raquo; <a href='"."/".$trail.".ro.html'>".$title."</a></li>";
  294. else
  295. $breadcrumbs .= "<li> &raquo; ".$title."</li>";
  296. $trail .= "/";
  297. $count++;
  298. $parent = strtok("/");
  299. }
  300. return $breadcrumbs;
  301. }
  302. function update_sitemap()
  303. {
  304. // Read header template.
  305. $article = read_template("templates/header.ro.tpl");
  306. $article .= read_template("templates/page.ro.tpl");
  307. // Read the footer template.
  308. $article .= read_template("templates/footer.ro.tpl");
  309. $title = "Planul sitului";
  310. // Update the the site title.
  311. $article = str_replace("<!-- site-title -->", $title . " &mdash; Fundația Ceata &mdash; Ceata eliberează artele și tehnologiile actuale", $article);
  312. // Update the the title.
  313. $article = str_replace("<!-- title -->", $title, $article);
  314. $all = get_all_files("html");
  315. $content = "<ul>";
  316. $last = "";
  317. $level = 1;
  318. // TODO: fix sitemap links indentation
  319. foreach ($all as $file)
  320. {
  321. if ($file == "" || is_link($file.".html")) continue;
  322. /* echo "Părinte: ".get_parent($file).".ro =? ".$last." ???\n"; */
  323. if ($last != "" && get_parent($file).'.ro' == $last)
  324. {
  325. $content .= "<ul>";
  326. $level++;
  327. }
  328. else
  329. {
  330. $uplevels = get_uplevels($last, get_common_parent($file, $last));
  331. for ($i = 0; $i < $uplevels && $level > 1; $i++)
  332. {
  333. $content .= "</ul>";
  334. $level--;
  335. }
  336. }
  337. if ($file == "news.ro" ||
  338. $file == "events.ro" ||
  339. $file == "sitemap.ro" ||
  340. $file == "index.ro"
  341. )
  342. {
  343. $title = str_replace("-", " ", ucfirst($file));
  344. }
  345. else
  346. {
  347. $article_content = read_template($file.".tpl");
  348. // Get the article data.
  349. $title = get_text($file.".tpl", "title");
  350. }
  351. $content .= "<li><a href=\"/".$file.".html\">".$title."</a></li>";
  352. $last = $file;
  353. }
  354. $content .= "</ul>";
  355. // Update the the content.
  356. $article = str_replace("<!-- content -->", $content, $article);
  357. $sitemap = "sitemap.ro.html";
  358. // Create or update the article.
  359. create_page($sitemap, $article);
  360. echo "-- ".$sitemap." - pagină publicată/actualizată.\n";
  361. }
  362. function get_parent($file)
  363. {
  364. $parent = "";
  365. $pos = strrpos($file, "/");
  366. if ($pos !== false)
  367. {
  368. $parent = substr($file, 0, $pos);
  369. }
  370. return $parent;
  371. }
  372. function get_common_parent($file1, $file2)
  373. {
  374. $found = strpos("/".$file2, "/".get_parent($file1));
  375. while ($found === false)
  376. {
  377. $file1 = get_parent($file1);
  378. $found = strpos("/".$file2, "/".get_parent($file1));
  379. }
  380. return get_parent($file1);
  381. }
  382. function get_uplevels($file, $path)
  383. {
  384. $uplevels = 0;
  385. $level1 = substr_count($file, '/');
  386. $level2 = substr_count($path, '/');
  387. $uplevels = $level1 - $level2;
  388. if ($path != "" && strpos($file, $path) !== false)
  389. $uplevels--;
  390. return $uplevels;
  391. }
  392. /*
  393. * Get the text field function.
  394. *
  395. * Get the field from article in the original source. The source is a HTML
  396. * formatted '.tpl' file.
  397. *
  398. * @param $file
  399. * The original article content file (a '.tpl' file).
  400. *
  401. * @param $field
  402. * The field from the original article content file (a '.tpl' file).
  403. *
  404. * @return
  405. * Returns a string contaning the requested field.
  406. */
  407. function get_text($file, $field)
  408. {
  409. // Create dom object.
  410. $doc = new DOMDocument();
  411. // Load oricinal article.
  412. $doc->loadHTMLFile($file);
  413. // Get article field.
  414. $element = $doc->getElementById($field);
  415. if ($element == NULL)
  416. return "";
  417. $text = $element->textContent;
  418. return $text;
  419. }
  420. function get_tag_value($file, $field)
  421. {
  422. // Create dom object.
  423. $doc = new DOMDocument();
  424. // Load oricinal article.
  425. $doc->loadHTMLFile($file);
  426. // Get article field.
  427. $elements = $doc->getElementsByTagName($field);
  428. $element = $elements->item(0);
  429. if ($element == NULL)
  430. return "";
  431. $text = $element->textContent;
  432. return $text;
  433. }
  434. /*
  435. * Get the content function.
  436. *
  437. * Get the content of a field from the original source. The source is a HTML
  438. * formatted '.tpl' file.
  439. *
  440. * @param $file
  441. * The original field content file (a '.tpl' file).
  442. *
  443. * @param $field
  444. * The field from the original article file (a '.tpl' file).
  445. *
  446. * @return
  447. * Returns a string contaning the field content.
  448. */
  449. function get_html($file, $field)
  450. {
  451. // Create dom object.
  452. $doc = new DOMDocument('1.0', 'UTF-8');
  453. // Load oricinal article.
  454. $doc->loadHTMLFile($file);
  455. // Get article content.
  456. $element = $doc->getElementById($field);
  457. if ($element == NULL)
  458. return "";
  459. $content = get_inner_html($element);
  460. return $content;
  461. }
  462. /**
  463. * Read template function.
  464. *
  465. * Reads the content of a page template.
  466. *
  467. * @param $template_file
  468. * A string, template file name.
  469. */
  470. function read_template($template_file)
  471. {
  472. // Get template content.
  473. $template_content = file_get_contents($template_file);
  474. /* if ($template_content == FALSE) */
  475. /* { */
  476. /* echo "N-am găsit ".$template_file."\n"; */
  477. /* } */
  478. /* else echo "Am găsit ".$template_file."\n"; */
  479. return $template_content;
  480. }
  481. /**
  482. * Create page function.
  483. *
  484. * Creates or update a HTML page.
  485. *
  486. * @param $page_name
  487. * A string, page file name.
  488. *
  489. * @param $content
  490. * A string, page content.
  491. */
  492. function create_page($page_name, $content)
  493. {
  494. // Open file for writing.
  495. $file = fopen($page_name,"w");
  496. // Write content to file.
  497. fwrite($file, $content);
  498. fclose($file);
  499. }
  500. /**
  501. * Truncate text function.
  502. *
  503. * Truncates a text.
  504. *
  505. * @param $text
  506. * Text to be truncated.
  507. * @param $max_text_length
  508. * The length of truncated text.
  509. * @param $append
  510. * String to append to the end of truncated text (such as '...').
  511. * @param $strip
  512. * Strip tags or not.
  513. *
  514. * @return
  515. * Truncated text or an empty string.
  516. */
  517. function truncate_text($text, $text_length, $append = "", $strip = TRUE)
  518. {
  519. // Verify text.
  520. if ( empty($text) ) return '';
  521. // Verify wether to strip tags.
  522. if ($strip)
  523. {
  524. // Strip tags.
  525. $text = strip_tags($text);
  526. }
  527. if (strlen($text) > $text_length)
  528. {
  529. // Get the the substring of legn $text_length.
  530. $text = mb_substr($text, 0, $text_length, 'UTF-8');
  531. // Add $append string.
  532. $text .= " ".$append;
  533. }
  534. return $text;
  535. }
  536. /**
  537. * Generate freed function.
  538. *
  539. * Creates or updates the RSS file from the list published articles.
  540. *
  541. * @param $limit
  542. * Number of feeds.
  543. */
  544. function generate_feed($type, $limit = 10)
  545. {
  546. // Get the list of articles templates.
  547. $articles = glob($type."/*.tpl");
  548. // Create articles list.
  549. foreach ($articles as $article)
  550. {
  551. $list[$article] = get_text($article, "date");
  552. }
  553. // Sort articles by descending date.
  554. arsort($list);
  555. // Limit the number of articles.
  556. $list = array_slice($list, 0, $limit);
  557. $rss = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
  558. $rss .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"
  559. xmlns:georss="http://www.georss.org/georss">'."\n";
  560. $rss .= '<channel>'."\n";
  561. $rss .= '<title>'.ucfirst($type).' — Fundația Ceata — Ceata eliberează artele și tehnologiile actuale</title>'."\n";
  562. $rss .= '<link>http://ceata.org/'.$type.'</link>'."\n";
  563. $rss .= '<description>
  564. Ceata eliberează artele și tehnologiile actuale</description>'."\n";
  565. $rss .= '<language>ro</language>'."\n";
  566. $rss .= '<ttl>480</ttl>'."\n";
  567. foreach($list as $key => $article)
  568. {
  569. $rss .= '<item>'."\n";
  570. $rss .= '<title><![CDATA['.get_text($key, "title").']]></title>'."\n";
  571. $rss .= '<description><![CDATA['
  572. .get_brief($key, $type).']]></description>'."\n";
  573. $rss .= '<pubDate>'
  574. .gmdate(DATE_RSS, strtotime(get_text($key, "date"))).'</pubDate>'."\n";
  575. // Get the article file name without extention.
  576. $filename = substr_replace($key,"",-4);
  577. $rss .= '<link>http://'.HOSTNAME.'/'.$filename.'.html</link>'."\n";
  578. $rss .= '</item>';
  579. }
  580. $rss .= '</channel>'."\n";
  581. $rss .= '</rss>'."\n";
  582. create_page($type.'.ro.rss', $rss);
  583. echo "-- ".$type.".ro.rss - flux de RSS creat/actualizat.\n";
  584. }
  585. /**
  586. * Generate news page function.
  587. *
  588. * Creates or updates the nwes page.
  589. *
  590. */
  591. function generate_news_page($type)
  592. {
  593. // Get the list of articles templates.
  594. $articles = glob($type."/*.tpl");
  595. // Create articles list.
  596. foreach ($articles as $article)
  597. {
  598. $list[$article] = get_text($article, "date");
  599. }
  600. // Sort articles by descending date.
  601. arsort($list);
  602. $news_page_content = "";
  603. foreach($list as $key => $article)
  604. {
  605. $article = '<li class="">';
  606. // Get the article file name without extention.
  607. $filename = substr_replace($key,"",-4);
  608. $rodate = rodate(get_text($key, "date"));
  609. $article .= '<a href="/'.$filename.'.html" class="titlu">'
  610. .get_text($key, "title").'</a>';
  611. $article .= '<span class="data">'
  612. .$rodate[1].'</span>';
  613. $article .= '<div class="rezumat"><p>'.get_brief($key, $type).'</p></div>';
  614. $article .= '</li> <!-- .aerisit -->';
  615. $news_page_content .= $article;
  616. }
  617. // Read header template.
  618. $news_page = read_template("templates/header.ro.tpl");
  619. // Read content template.
  620. $news_page .= read_template("templates/".$type.".ro.tpl");
  621. // Read footer template.
  622. $news_page .= read_template("templates/footer.ro.tpl");
  623. // Update the the site title.
  624. $news_page = str_replace("<!-- site-title -->", ucfirst($type)." &mdash; Fundația Ceata &mdash; Ceata eliberează artele și tehnologiile actuale", $news_page);
  625. // Update the content.
  626. $news_page = str_replace("<!-- news list -->", $news_page_content, $news_page);
  627. $news_page = str_replace("<!-- breadcrumbs -->", get_breadcrumbs($type.".html"), $news_page);
  628. create_page($type.'.ro.html', $news_page);
  629. echo "-- ".$type.".ro.html - pagină de știri publicată/actualizată.\n";
  630. }
  631. function get_inner_html($node)
  632. {
  633. $innerHTML = '';
  634. $children = $node->childNodes;
  635. foreach ($children as $child)
  636. {
  637. $innerHTML .= $child->ownerDocument->saveXML($child);
  638. }
  639. return $innerHTML;
  640. }
  641. function tomail($address)
  642. {
  643. // TODO: what if the address iș empty?
  644. return "<a href=\"mailto:".$address."\">".$address."</a>";
  645. }
  646. function rodate($date)
  647. {
  648. $time = strtotime(substr($date, 2));
  649. $strdate = strftime(('%A %d %B %Y'), $time);
  650. $rodate = _rodate($strdate);
  651. return $rodate;
  652. }
  653. function _rodate($strdate)
  654. {
  655. $day = strtok($strdate, " ");
  656. switch ($day)
  657. {
  658. case "Monday":
  659. $day = "luni";
  660. break;
  661. case "Tuesday":
  662. $day = "marți";
  663. break;
  664. case "Wednesday":
  665. $day = "miercuri";
  666. break;
  667. case "Thursday":
  668. $day = "joi";
  669. break;
  670. case "Friday":
  671. $day = "vineri";
  672. break;
  673. case "Saturday":
  674. $day = "sâmbătă";
  675. break;
  676. case "Sunday":
  677. $day = "duminică";
  678. }
  679. $dayn = ltrim(strtok(" "), "0");
  680. $month = strtok(" ");
  681. switch ($month)
  682. {
  683. case "January":
  684. $month = "ianuarie";
  685. break;
  686. case "February":
  687. $month = "februarie";
  688. break;
  689. case "March":
  690. $month = "martie";
  691. break;
  692. case "April":
  693. $month = "aprilie";
  694. break;
  695. case "May":
  696. $month = "mai";
  697. break;
  698. case "June":
  699. $month = "iunie";
  700. break;
  701. case "July":
  702. $month = "iulie";
  703. break;
  704. case "August":
  705. $month = "august";
  706. break;
  707. case "September":
  708. $month = "septembrie";
  709. break;
  710. case "October":
  711. $month = "octombrie";
  712. break;
  713. case "November":
  714. $month = "noiembrie";
  715. break;
  716. case "December":
  717. $month = "decembrie";
  718. }
  719. $year = strtok(" ");
  720. $daydate[0] = $day;
  721. $daydate[1] = $dayn . " " . $month . " " . $year;
  722. return $daydate;
  723. }
  724. ?>