PageRenderTime 112ms CodeModel.GetById 21ms RepoModel.GetById 5ms app.codeStats 1ms

/util-functions.php

https://bitbucket.org/danhunsaker/idlx
PHP | 519 lines | 441 code | 36 blank | 42 comment | 93 complexity | 241bcd9f65f676645d499c42c10f7bfe MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, 0BSD, IPL-1.0, LGPL-2.0, GPL-3.0
  1. <?php
  2. include_once(dirname(__FILE__) . "/in-site-check.php");
  3. /** util-functions.php
  4. Provides basic utility functions for use throughout the IDLX Framework and any child projects.
  5. Designed with the capability to override anything defined here by simply defining it before this file is called.
  6. */
  7. define('IDLX_NS_URI', 'http://idlx.sourceforge.net/schema/2011/08/');
  8. if (!function_exists('collapse_multi_array')) {
  9. function collapse_multi_array (array $multi) {
  10. $collapsed = array();
  11. foreach ($multi as $key=>$val) {
  12. if (is_array($val)) {
  13. $val = collapse_multi_array($val);
  14. foreach ($val as $sub_key=>$sub_val) {
  15. $collapsed[$key.'-'.$sub_key] = $sub_val;
  16. }
  17. }
  18. else {
  19. $collapsed[$key] = $val;
  20. }
  21. }
  22. return $collapsed;
  23. }
  24. }
  25. if (!function_exists('get_mods')) {
  26. function get_mods ($mod_type) {
  27. $flist = scandir("mods/{$mod_type}/");
  28. $output = array();
  29. foreach ($flist as $fname) {
  30. // Skip UNIX-style hidden files, all directories, and any non-PHP files.
  31. if (substr($fname, 0, 1) == '.' || is_dir($fname) || substr($fname, -4) != '.php') continue;
  32. // error_log("util-functions.php - get_mods || Loading module [mods/{$mod_type}/{$fname}]");
  33. $class_name = include_once("mods/{$mod_type}/{$fname}"); // Module files will have to return(class_name); at their end.
  34. if (class_exists($class_name)) {
  35. // error_log("util-functions.php - get_mods || Class name [{$class_name}]");
  36. $output[$class_name::get_handler()] = new $class_name();
  37. }
  38. else { // But if they violate this rule, try to make things work anyway.
  39. error_log("util-functions.php - get_mods || Class name INVALID [{$class_name}] - add a return('Name_of_Class') to the end of [mods/{$mod_type}/{$fname}].");
  40. $class_name = "{$mod_type}_".substr($fname,0,-4);
  41. if (class_exists($class_name)) {
  42. // error_log("util-functions.php - get_mods || Retrying with class name [{$class_name}]");
  43. $output[$class_name::get_handler()] = new $class_name();
  44. }
  45. else error_log("util-functions.php - get_mods || Cannot determine class name [{$class_name}]");
  46. }
  47. }
  48. return $output;
  49. }
  50. }
  51. if (!function_exists('importFragment')) {
  52. function importFragment ($xml, DOMDocument $dom) {
  53. $frag = $dom->createDocumentFragment();
  54. $frag->appendXML($xml);
  55. foreach ($frag->childNodes as $node) {
  56. if ($node->nodeType != XML_ELEMENT_NODE) continue;
  57. if (empty($node->namespaceURI)) $node->setAttribute('xmlns', IDLX_NS_URI);
  58. }
  59. $frag_out = $frag->ownerDocument->saveXML($frag);
  60. $frag = $dom->createDocumentFragment();
  61. $frag->appendXML($frag_out);
  62. return $frag;
  63. }
  64. }
  65. if (!function_exists('send_to_siteroot')) {
  66. function send_to_siteroot ($message, $caller = 'in-site-check.php', $siteroot = null) {
  67. if ($siteroot === null) {
  68. $siteroot = strtr(dirname($_SERVER['SCRIPT_FILENAME']), array('\\' => '/', $_SERVER['DOCUMENT_ROOT'] => ''));
  69. }
  70. if (!in_array(substr($message, -1), array('.', '!', '?'))) $message .= '.';
  71. @error_log ("{$caller} || {$message} Redirecting to project root [{$siteroot}]. Doc requested [{$_SERVER['REQUEST_URI']}{$_SERVER['PATH_INFO']}?{$_SERVER['QUERY_STRING']}]");
  72. header('Location: '.$siteroot.'/');
  73. ob_end_clean();
  74. die();
  75. }
  76. }
  77. if (!function_exists('clean_whitespace_from_nodes')) {
  78. function clean_whitespace_from_nodes (DOMNode $dom) {
  79. if (!$dom->hasChildNodes()) {
  80. $dom->nodeValue = preg_replace(array('/^(\s)\s+/', "/(\s)\s+$/"), array('$1', '$1'), $dom->nodeValue);
  81. return $dom;
  82. }
  83. foreach ($dom->childNodes as $node) {
  84. $node = clean_whitespace_from_nodes ($node);
  85. if ($node->nodeType == XML_TEXT_NODE && $node->isWhitespaceInElementContent())
  86. $dom->removeChild($node);
  87. }
  88. return $dom;
  89. }
  90. }
  91. if (!function_exists('get_footer')) {
  92. function get_footer() {
  93. if (!need_ext('libxml')) return false;
  94. // Create a new DOMDocument. Things are cleaner this way.
  95. $dom = new DOMDocument();
  96. // The footer div
  97. $foot_node = $dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'div');
  98. $foot_node->setAttribute('class', 'footer');
  99. // The copyright span
  100. $copy_node = $dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'span', '&copy; 2011'.(date('Y') > 2011 ? '-'.date('Y') : '').' by ');
  101. $copy_node->setAttribute('id', 'copy');
  102. // The IDLX team (sf.net site) link
  103. $team_node = $dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'a', 'The IDLX Team');
  104. $team_node->setAttribute('href', 'http://idlx.sourceforge.net/');
  105. // The last bit of the copyright span
  106. $copy_node_2 = $dom->createTextNode('. Released under the GPL.');
  107. // The supporting technologies paragraph
  108. $para_node = $dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'p', 'The IDLX Framework would not be possible without the work of these projects:');
  109. $para_node->setAttribute('class', 'thanks');
  110. // A line break to force the images to their own line.
  111. $break_node = $dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'br');
  112. // Link to PHP home page
  113. $link_node_php = $dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'a');
  114. $link_node_php->setAttribute('href', 'http://www.php.net/');
  115. // PHP logo image
  116. $logo_node_php = $dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'img');
  117. $logo_node_php->setAttribute('src', 'images/php-med-trans.png');
  118. $logo_node_php->setAttribute('alt', 'PHP');
  119. // Link to Apache FOP home page
  120. $link_node_fop = $dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'a');
  121. $link_node_fop->setAttribute('href', 'http://xmlgraphics.apache.org/fop/');
  122. // Apache FOP logo image
  123. $logo_node_fop = $dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'img');
  124. $logo_node_fop->setAttribute('src', 'images/fop-logo.jpg');
  125. $logo_node_fop->setAttribute('alt', 'Apache FOP');
  126. // Link to Adobe Reader download page
  127. $link_node_pdf = $dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'a');
  128. $link_node_pdf->setAttribute('href', 'http://get.adobe.com/reader/');
  129. // Get Reader logo image
  130. $logo_node_pdf = $dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'img');
  131. $logo_node_pdf->setAttribute('src', 'images/get_adobe_reader.gif');
  132. $logo_node_pdf->setAttribute('alt', 'Adobe PDF');
  133. // Put the pieces together in the correct order
  134. $link_node_php->appendChild($logo_node_php);
  135. $link_node_fop->appendChild($logo_node_fop);
  136. $link_node_pdf->appendChild($logo_node_pdf);
  137. $para_node->appendChild($break_node);
  138. $para_node->appendChild($link_node_php);
  139. $para_node->appendChild($link_node_fop);
  140. $para_node->appendChild($link_node_pdf);
  141. $copy_node->appendChild($team_node);
  142. $copy_node->appendChild($copy_node_2);
  143. $foot_node->appendChild($copy_node);
  144. $foot_node->appendChild($para_node);
  145. // Send the result back to the caller
  146. return $foot_node;
  147. }
  148. }
  149. if (!function_exists('tidy_config')) {
  150. function tidy_config() {
  151. global $config;
  152. $ret = array (
  153. 'input-xml' => true,
  154. 'output-xml' => true,
  155. 'output-xhtml' => false,
  156. 'add-xml-space' => true,
  157. 'clean' => true,
  158. 'escape-cdata' => true,
  159. // 'hide-comments' => true,
  160. 'lower-literals' => true,
  161. 'preserve-entities' => true,
  162. 'indent' => true,
  163. 'indent-attributes' => false,
  164. 'indent-spaces' => 4,
  165. 'markup' => true,
  166. 'wrap' => 0,
  167. 'wrap-attributes' => false,
  168. 'newline' => 'LF',
  169. 'force-output' => true,
  170. );
  171. if (in_array('http://www.w3c.org/1999/xhtml/', $config['output'])) {
  172. $ret['output-xhtml'] = true;
  173. $ret['output-xml'] = false;
  174. }
  175. return $ret;
  176. }
  177. }
  178. if (!function_exists('process_iface')) {
  179. function process_iface($iface) {
  180. global $config, $idlxs_mods, $xuid_mods, $db, $rep_proc_mods, $rep_gen_mods, $uid, $auth, $proj_dir, $siteroot, $idlxroot;
  181. if (!need_ext('libxml')) return false;
  182. if (!need_ext('tidy')) return false;
  183. $if_dom = new DOMDocument();
  184. $if_dom->formatOutput = true;
  185. $if_dom->loadXML($iface);
  186. $footer = $if_dom->importNode(get_footer(), true);
  187. $if_dom->documentElement->appendChild($footer);
  188. $xp = new DOMXPath($if_dom);
  189. $xp->registerNamespace('idlx', IDLX_NS_URI);
  190. $nothingNew = false;
  191. while ($nothingNew == false) {
  192. $if_dom->formatOutput = true;
  193. $if_dom->normalizeDocument();
  194. // error_log("index.php || Begin processing pass [{$if_dom->saveXML()}]");
  195. $nothingNew = true;
  196. $iface_nodes = $xp->evaluate('//idlx:interface'); // Pull in any requested external Interfaces.
  197. error_log("index.php || Tag counts: interfaces [{$iface_nodes->length}]");
  198. if ($iface_nodes->length > 0) {
  199. $nothingNew = false;
  200. foreach ($iface_nodes as $node) {
  201. $iface_name = trim(utf8_decode($node->textContent));
  202. // error_log("index.php || Interface name [{$iface_name}]");
  203. $iface_contents = $db->get_iface_cname($iface_name);
  204. if ($iface_contents !== false) {
  205. // error_log("index.php || Importing external Interface [{$iface_name} || {$iface_contents}]");
  206. $import_dom = $node->ownerDocument->createDocumentFragment();
  207. $import_dom->appendXML($iface_contents);
  208. $node->parentNode->replaceChild($import_dom, $node);
  209. }
  210. else {
  211. error_log("index.php || Interface [{$iface_name}] not found; ignoring");
  212. $node->parentNode->removeChild($node);
  213. }
  214. }
  215. continue; // Restart processing to catch anything new.
  216. }
  217. $script_nodes = $xp->evaluate('//idlx:script'); // Locate and process any scripts.
  218. error_log("index.php || Tag counts: scripts [{$script_nodes->length}]");
  219. if ($script_nodes->length > 0) {
  220. $nothingNew = false;
  221. foreach ($script_nodes as $node) {
  222. $script_type = mb_strtolower(utf8_decode($node->attributes->getNamedItem('lang')->textContent));
  223. // error_log("index.php || Script type [{$script_type}]");
  224. if (isset($idlxs_mods[$script_type])) {
  225. $result = $idlxs_mods[$script_type]->run_script(utf8_decode($node->textContent));
  226. // error_log("index.php || Script output [{$result}]");
  227. $new_node = importFragment(utf8_encode(trim($result)), $node->ownerDocument);
  228. // error_log("index.php || Imported fragment [{$new_node->ownerDocument->saveXML($new_node)}]");
  229. $node->parentNode->replaceChild($new_node, $node);
  230. $node->ownerDocument->normalizeDocument();
  231. }
  232. else {
  233. error_log("index.php || No module loaded to handle [{$script_type}] scripts; ignoring");
  234. $node->parentNode->removeChild($node);
  235. }
  236. }
  237. continue; // Restart processing to catch anything new.
  238. }
  239. $report_nodes = $xp->evaluate('//idlx:report'); // Locate and process any reports.
  240. error_log("index.php || Tag counts: reports [{$report_nodes->length}]");
  241. if ($report_nodes->length > 0) {
  242. $nothingNew = false;
  243. foreach ($report_nodes as $node) { // Iterate through report nodes.
  244. $input_type = '';
  245. $input_file = '';
  246. $output_type = '';
  247. $output_style = '';
  248. $output_file = '';
  249. $link_text = mb_strtolower(utf8_decode($node->attributes->getNamedItem('id')->textContent));
  250. foreach ($node->childNodes as $childNode) { // Determine what type of report to generate, and how.
  251. if ($childNode->nodeType != XML_ELEMENT_NODE) continue;
  252. switch ($childNode->localName) {
  253. case 'input': // Specifies the report input parameters.
  254. // error_log("index.php || Processing report input node...");
  255. foreach ($childNode->childNodes as $inputChildNode) {
  256. if ($inputChildNode->nodeType != XML_ELEMENT_NODE) continue;
  257. switch ($inputChildNode->localName) {
  258. case 'format': // Indicates the format of the report definition file.
  259. $input_type = mb_strtolower(utf8_decode($inputChildNode->textContent));
  260. // error_log("index.php || Report input type [{$input_type}]");
  261. break;
  262. case 'description': // Indicates the name of the report definition file.
  263. $input_file = mb_strtolower(utf8_decode($inputChildNode->textContent));
  264. // error_log("index.php || Report input file [{$input_file}]");
  265. break;
  266. default: // Undefined node type. Ignore.
  267. error_log("index.php || Cannot process <{$inputChildNode->localName}> node; ignoring.");
  268. // $childNode->removeChild($inputChildNode);
  269. break;
  270. }
  271. }
  272. break;
  273. case 'output': // Specifies the report output parameters.
  274. // error_log("index.php || Processing report output node...");
  275. foreach ($childNode->childNodes as $outputChildNode) {
  276. if ($outputChildNode->nodeType != XML_ELEMENT_NODE) continue;
  277. switch ($outputChildNode->localName) {
  278. case 'format': // Indicates the format of the report output.
  279. $output_type = mb_strtolower(utf8_decode($outputChildNode->textContent));
  280. // error_log("index.php || Report output type [{$output_type}]");
  281. break;
  282. case 'return': // Indicates the return style of the report output.
  283. $output_style = mb_strtolower(utf8_decode($outputChildNode->textContent));
  284. // error_log("index.php || Report output style [{$output_style}]");
  285. break;
  286. case 'name': // Indicates the filename of the report output. May have different meanings in some return styles.
  287. $output_file = mb_strtolower(utf8_decode($outputChildNode->textContent));
  288. // error_log("index.php || Report output file [{$output_file}]");
  289. break;
  290. default: // Undefined node type. Ignore.
  291. error_log("index.php || Cannot process [{$outputChildNode->localName}] node; ignoring.");
  292. // $childNode->removeChild($outputChildNode);
  293. break;
  294. }
  295. }
  296. break;
  297. default: // Undefined node type. Ignore.
  298. error_log("index.php || Cannot process [{$childNode->localName}] node; ignoring.");
  299. // $node->removeChild($childNode);
  300. break;
  301. }
  302. }
  303. if (isset($rep_proc_mods[$input_type]) && isset($rep_gen_mods[$output_type])) { // Can't generate a report if we don't have modules for it.
  304. $report = $rep_gen_mods[$output_type]->generate($rep_proc_mods[$input_type]->process($input_file));
  305. if (empty($report) || $report === false) { // We want to replace the report node with the ReportGenerator output, but if there is none, we need to remove the node entirely.
  306. if (empty($report)) error_log("index.php || Report generated (responded with an empty string) [{$input_type}({$input_file}) => {$output_type}::{$output_style}({$output_file})]");
  307. else error_log("index.php || Report generator encountered an error [{$input_type}({$input_file}) => {$output_type}::{$output_style}({$output_file})]");
  308. if ($output_style == 'test') {
  309. $new_node = $node->ownerDocument->createElementNS('http://www.w3c.org/1999/xhtml/', 'p', 'Report generation failed. Test UNSAT.');
  310. $node->parentNode->replaceChild($new_node, $node);
  311. $node->ownerDocument->normalizeDocument();
  312. }
  313. else {
  314. $node->parentNode->removeChild($node);
  315. }
  316. }
  317. else { // The ReportGenerator returned a non-empty result - add it to the output.
  318. // error_log("index.php || Report generated (responded with report presentation) [{$input_type}({$input_file}) => {$output_type}::{$output_style}({$output_file})]");
  319. file_put_contents($proj_dir.'/reports/download/'.$output_file, $report);
  320. switch ($output_style) {
  321. case 'interface': // Output directly to the Interface (use $link_text as caption)
  322. $new_node = $node->ownerDocument->createElementNS('http://www.w3c.org/1999/xhtml/', 'object', 'Report generation succeeded. Download it ');
  323. $new_link_node = $new_node->ownerDocument->createElementNS('http://www.w3c.org/1999/xhtml/', 'a', 'here');
  324. $new_link_node->setAttribute('href', $siteroot.'/reports/download/'.$output_file);
  325. $new_node->appendChild($new_link_node);
  326. $new_text_node = $new_node->ownerDocument->createTextNode('. (Tried to display the report in the browser and failed. Check that your browser supports embedded PDFs.)');
  327. $new_node->appendChild($new_text_node);
  328. $new_node->setAttribute('data', $siteroot.'/reports/download/'.$output_file);
  329. $new_node->setAttribute('type', $output_type);
  330. $new_node->setAttribute('width', '600');
  331. $new_node->setAttribute('height', '825');
  332. break;
  333. case 'separate': // Output as download
  334. header('Location: '.$siteroot.'/reports/download/'.$output_file);
  335. $new_node = $node->ownerDocument->createElementNS('http://www.w3c.org/1999/xhtml/', 'p', 'Report generation succeeded. Your download should begin within the next few seconds.');
  336. break;
  337. case 'link': // Output as link (use $link_text as link text)
  338. $new_node = $node->ownerDocument->createElementNS('http://www.w3c.org/1999/xhtml/', 'p', 'Report generation succeeded. Download it ');
  339. $new_link_node = $new_node->ownerDocument->createElementNS('http://www.w3c.org/1999/xhtml/', 'a', 'here');
  340. $new_link_node->setAttribute('href', $siteroot.'/reports/download/'.$output_file);
  341. $new_node->appendChild($new_link_node);
  342. $new_text_node = $new_node->ownerDocument->createTextNode('.');
  343. $new_node->appendChild($new_text_node);
  344. break;
  345. case 'local': // Output as local file (not available in Interface)
  346. $new_node = $node->ownerDocument->createElementNS('http://www.w3c.org/1999/xhtml/', 'p', 'Report generation succeeded. Report saved in "/reports/download/" as "'.$output_file.'". Contact the site administrator for access.');
  347. break;
  348. case 'test': // Don't output the report anywhere; just test results.
  349. unlink($proj_dir.'/reports/download/'.$output_file);
  350. $new_node = $node->ownerDocument->createElementNS('http://www.w3c.org/1999/xhtml/', 'p', 'Report generation succeeded. Test SAT.');
  351. break;
  352. default: // Unknown value
  353. error_log("index.php || Report output style [{$output_style}] not understood.");
  354. $new_node = $node->ownerDocument->createElementNS('http://www.w3c.org/1999/xhtml/', 'p', 'Report display failed (unsupported display method). Have the site administrator check the error logs. Report saved in "/reports/download/" as "'.$output_file.'". Contact the site administrator for access.');
  355. break;
  356. }
  357. $node->parentNode->replaceChild($new_node, $node);
  358. $node->ownerDocument->normalizeDocument();
  359. }
  360. }
  361. else { // Clean up the report node so it doesn't clutter the output.
  362. error_log("index.php || Cannot generate report (missing one or more compatible modules) [{$input_type}({$input_file}) => {$output_type}::{$output_style}({$output_file})]");
  363. $node->parentNode->removeChild($node);
  364. }
  365. }
  366. continue; // Restart processing to catch anything new.
  367. }
  368. $db_nodes = $xp->evaluate('//idlx:table|//idlx:record|//idlx:field'); // Locate and process data nodes.
  369. error_log("index.php || Tag counts: db value selectors [{$db_nodes->length}]");
  370. if ($db_nodes->length > 0) {
  371. $nothingNew = false;
  372. $data_table = '';
  373. $data_record = '';
  374. $data_field = '';
  375. $data_alt = '';
  376. foreach ($db_nodes as $node) {
  377. $db_type = mb_strtolower(utf8_decode($node->localName));
  378. // error_log("index.php || Data node type [{$db_type}]");
  379. switch ($db_type) {
  380. case 'table':
  381. $data_table = utf8_decode($node->textContent);
  382. $node->parentNode->removeChild($node);
  383. break;
  384. case 'record':
  385. $data_record = utf8_decode($node->textContent);
  386. $node->parentNode->removeChild($node);
  387. break;
  388. case 'field':
  389. $data_field = utf8_decode($node->textContent);
  390. $data_alt = utf8_decode(@$node->attributes->getNamedItem('alt')->textContent);
  391. $data_alt = empty($data_alt) ? '::Undefined::' : $data_alt;
  392. $result = $db->get_data_value($data_table, $data_record, $data_field, $data_alt);
  393. $new_node = importFragment(utf8_encode(trim($result)), $node->ownerDocument);
  394. $node->parentNode->replaceChild($new_node, $node);
  395. $node->ownerDocument->formatOutput = true;
  396. $node->ownerDocument->preserveWhiteSpace = false;
  397. $node->ownerDocument->normalizeDocument();
  398. break;
  399. default:
  400. error_log("index.php || Could not interpret data node [{$db_type}]; ignoring.");
  401. $node->parentNode->removeChild($node);
  402. break;
  403. }
  404. }
  405. continue; // Restart processing to catch anything new.
  406. }
  407. // Locate and process XUID nodes.
  408. $xuid_xpath = '//*[namespace-uri()!="'.IDLX_NS_URI.'" and namespace-uri()!="'.implode('" and namespace-uri()!="', $config['output']).'" and namespace-uri()!=namespace-uri(parent::*)]';
  409. $xuid_nodes = $xp->evaluate($xuid_xpath);
  410. error_log("index.php || Tag counts: xuid blocks [{$xuid_nodes->length}]");
  411. if ($xuid_nodes->length > 0) {
  412. $nothingNew = false;
  413. foreach ($xuid_nodes as $node) {
  414. $xuid_type = mb_strtolower(utf8_decode($node->namespaceURI));
  415. error_log("index.php || XUID namespace URI [{$xuid_type} || {$node->nodeName}]");
  416. if (isset($xuid_mods[$xuid_type])) {
  417. $result = $xuid_mods[$xuid_type]->translate($node);
  418. $new_node = $node->ownerDocument->importNode($result, true);
  419. $node->parentNode->replaceChild($new_node, $node);
  420. }
  421. else {
  422. $node->parentNode->removeChild($node);
  423. }
  424. }
  425. continue; // Restart processing to catch anything new.
  426. }
  427. $logout_nodes = $xp->evaluate('//idlx:logout'); // Locate and handle any logout directives.
  428. error_log("index.php || Tag counts: logout directives [{$logout_nodes->length}]");
  429. if ($logout_nodes->length > 0) {
  430. if (!$auth->unauth()) {
  431. error_log("index.php || Logout failed. Check the code?");
  432. }
  433. header('Refresh: 5');
  434. $notice = $if_dom->createElementNS('http://www.w3c.org/1999/xhtml/', 'p', 'Successfully Logged Out');
  435. $notice->setAttribute('style', 'font-size: 24pt;');
  436. $notice_given = false;
  437. foreach ($logout_nodes as $node) {
  438. // error_log("index.php || Removing logout directive.");
  439. if (!$notice_given) {
  440. $node->parentNode->replaceChild($notice, $node);
  441. $notice_given = true;
  442. }
  443. else {
  444. $node->parentNode->removeChild($node);
  445. }
  446. }
  447. continue; // This is only here in case any new checks are added below; otherwise, it's redundant.
  448. }
  449. }
  450. if (isset($xuid_mods[IDLX_NS_URI])) {
  451. $if_dom = $xuid_mods[IDLX_NS_URI]->translate($if_dom);
  452. }
  453. $temp_dom = '';
  454. foreach ($if_dom->childNodes as $node)
  455. $temp_dom .= $if_dom->saveXML($node);
  456. $tidy = new tidy;
  457. return $tidy->repairString($temp_dom, tidy_config(), 'UTF8');
  458. }
  459. }
  460. if (!function_exists('die_deny')) {
  461. function die_deny($reason) {
  462. header ("HTTP/1.1 403 Forbidden");
  463. @error_log("util-functions.php die_deny || Ending execution [{$_SERVER['REQUEST_URI']}?{$_SERVER['QUERY_STRING']}{$_SERVER['PATH_INFO']} || {$reason}]");
  464. die ($reason);
  465. }
  466. }
  467. if (!function_exists('need_ext')) {
  468. function need_ext ($ext_name) {
  469. if (!extension_loaded($ext_name)) {
  470. $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
  471. if (ini_get('enable_dl') != 1) return false; // Cannot dynamically load extensions.
  472. return dl($prefix . $ext_name . PHP_SHLIB_SUFFIX); // Try loading and return success/fail to the caller.
  473. }
  474. else {
  475. return true; // Already loaded. Continue with your day.
  476. }
  477. }
  478. }
  479. ?>