PageRenderTime 60ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/apps/_shared/functions.inc.php

https://github.com/noveopiu/dCTL
PHP | 1931 lines | 1576 code | 131 blank | 224 comment | 256 complexity | 449c515a25cac808eadcf49d10b35a13 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. if (!defined('_INCLUDE')) die('"'.__FILE__.'" not executable... me, i abort.');
  3. /* - - - - - - - - - - - - - - - - - */
  4. function xml_character_encode($string, $trans='') {
  5. $trans = (is_array($trans)) ? $trans : get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
  6. foreach ($trans as $k=>$v)
  7. $trans[$k]= "&#".ord($k).";";
  8. return strtr($string, $trans);
  9. };
  10. /* - - - - - - - - - - - - - - - - - */
  11. function fixLabel($label) {
  12. return trim(addslashes(preg_replace('/'.WS.'+/', ' ',$label)));
  13. };
  14. /* - - - - - - - - - - - - - - - - - */
  15. function loadXML($thePath) {
  16. if (is_file($thePath)) {
  17. forceUTF8($thePath);
  18. $simplexml = simplexml_load_file($thePath, 'SimpleXMLElement', DCTL_XML_LOADER);
  19. $namespaces = $simplexml->getDocNamespaces();
  20. foreach ($namespaces as $nsk=>$ns) {
  21. if ($nsk == '') $nsk = 'tei';
  22. $simplexml->registerXPathNamespace($nsk, $ns);
  23. };
  24. $xml_resource = simplexml_load_string($simplexml->asXML()); // NO => , 'SimpleXMLElement', DCTL_XML_LOADER
  25. //$xml_resource = str_ireplace('xml:id','id',$xml_resource);
  26. } else {
  27. die('<div class="error">! cannot SIMPLEXML load resource: '.$thePath.'</div>');
  28. };
  29. return $xml_resource;
  30. };
  31. /* - - - - - - - - - - - - - - - - - */
  32. function checkUTF8Encoding ( $string, $string_encoding ) {
  33. $fs = $string_encoding == 'UTF-8' ? 'UTF-32' : $string_encoding;
  34. $ts = $string_encoding == 'UTF-32' ? 'UTF-8' : $string_encoding;
  35. return $string === mb_convert_encoding ( mb_convert_encoding ( $string, $fs, $ts ), $ts, $fs );
  36. };
  37. /* - - - - - - - - - - - - - - - - - */
  38. function encodeToUTF8($string) {
  39. return mb_convert_encoding($string, "UTF-8", mb_detect_encoding($string, "UTF-8, ISO-8859-1, ISO-8859-15", true));
  40. };
  41. /* - - - - - - - - - - - - - - - - - */
  42. function forceUTF8 ($fullsrc, $fPath="", $dumpIt=true) {
  43. if (is_file($fullsrc)) {
  44. $fPath = $fullsrc;
  45. $content = file_get_contents($fullsrc);
  46. $src = dirname($fullsrc).SYS_PATH_SEP.basename($fullsrc);
  47. } else {
  48. $content = $fullsrc;
  49. $src = substr($fullsrc, 0, 30);
  50. };
  51. $encoding = mb_detect_encoding($content, 'UTF-8, ISO-8859-1, ASCII, UTF-7', true);
  52. $contentUTF8 = $content;
  53. // TEST #1
  54. switch ($encoding) {
  55. case 'UTF-8':
  56. break;
  57. default:
  58. $contentUTF8 = iconv($encoding, "UTF-8", $content);
  59. // if (is_file($fullsrc)) {
  60. if ($dumpIt) dump('#1) UTF-8 warning in "'.$src.'" '.($fPath?('('.basename($fPath).')'):'').': seems to be '.$encoding.'... please check and fix!');
  61. // $chown = fileowner($fullsrc);
  62. // $chgrp = filegroup($fullsrc);
  63. // $@chmod = fileperms($fullsrc);
  64. // file_put_contents($fullsrc, $content);
  65. // chown($fullsrc, $chown);
  66. // chgrp($fullsrc, $chgrp);
  67. // @chmod($fullsrc, $CHMOD);
  68. // };
  69. break;
  70. };
  71. // TEST #2
  72. // if (! checkUTF8Encoding($content, 'UTF-8')) {
  73. // dump('#2) UTF-8 warning in "'.$src.'" '.($fPath?('('.basename($fPath).')'):'').': seems to be '.$encoding.'... please check and fix!');
  74. // }
  75. return $contentUTF8;
  76. };
  77. /* - - - - - - - - - - - - - - - - - */
  78. /* - - - - - - - - - - - - - - - - - */
  79. function checkEncoding ( $string, $string_encoding ) {
  80. $fs = $string_encoding == 'UTF-8' ? 'UTF-32' : $string_encoding;
  81. $ts = $string_encoding == 'UTF-32' ? 'UTF-8' : $string_encoding;
  82. return $string === mb_convert_encoding ( mb_convert_encoding ( $string, $fs, $ts ), $ts, $fs );
  83. };
  84. /* - - - - - - - - - - - - - - - - - */
  85. /* - - - - - - - - - - - - - - - - - */
  86. function charset_decode_utf_8 ($string) {
  87. /* Only do the slow convert if there are 8-bit characters */
  88. /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
  89. if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string))
  90. return $string;
  91. // decode three byte unicode characters
  92. $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e",
  93. "'&#'.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 + (ord('\\3')-128)).';'",
  94. $string);
  95. // decode two byte unicode characters
  96. $string = preg_replace("/([\300-\337])([\200-\277])/e",
  97. "'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",
  98. $string);
  99. return $string;
  100. }
  101. /* - - - - - - - - - - - - - - - - - */
  102. /* - - - - - - - - - - - - - - - - - */
  103. function uc_first($string) {
  104. // if (preg_match('/abitator/', $string)) dump($string);
  105. return strval(ucfirst($string));
  106. };
  107. /* - - - - - - - - - - - - - - - - - */
  108. /* - - - - - - - - - - - - - - - - - */
  109. function untag($string, $tag) {
  110. $tmpval = array();
  111. $preg = "|<$tag( .*?)?>(.*?)</$tag>|s";
  112. preg_match_all($preg, $string, $tags);
  113. foreach ($tags[2] as $tmpcont){
  114. $tmpval[] = $tmpcont;
  115. };
  116. return $tmpval;
  117. };
  118. /* - - - - - - - - - - - - - - - - - */
  119. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  120. // * ARCHIVES *
  121. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  122. /* - - - - - - - - - - - - - - - - - */
  123. function stripNamespaces (&$theText) {
  124. $theText = str_ireplace('xmlns:'.XMLDB_TEI_NS, '', $theText);
  125. $theText = str_ireplace(XMLDB_TEI_NS, '', $theText);
  126. $theText = str_ireplace(XMLDB_TEI_NS2, '', $theText);
  127. $theText = str_ireplace('xmlns:'.XMLDB_DCTL_NS, '', $theText);
  128. $theText = str_ireplace(XMLDB_DCTL_NS, '', $theText);
  129. $theText = str_ireplace(XMLDB_DCTL_NS2, '', $theText);
  130. $theText = str_ireplace('xmlns:'.XMLDB_DYN_NS, '', $theText);
  131. $theText = str_ireplace(XMLDB_DYN_NS, '', $theText);
  132. $theText = str_ireplace('xmlns:'.XMLDB_EXSLT_NS, '', $theText);
  133. $theText = str_ireplace(XMLDB_EXSLT_NS, '', $theText);
  134. $theText = str_ireplace('xmlns:'.XMLDB_PHP_NS, '', $theText);
  135. $theText = str_ireplace(XMLDB_PHP_NS, '', $theText);
  136. $theText = str_ireplace('xmlns:'.XMLDB_STR_NS, '', $theText);
  137. $theText = str_ireplace(XMLDB_STR_NS, '', $theText);
  138. };
  139. /* - - - - - - - - - - - - - - - - - */
  140. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  141. function dctl_xmldb_disconnect ($exist = FALSE, $forceClose = false) {
  142. if ($exist) {
  143. $exist->disconnect($forceClose);
  144. };
  145. };
  146. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  147. function dctl_xmldb_connect ($mode = 'query', $persistent = false) {
  148. //
  149. $persistent = false; // force to check if eXist works fine without pid
  150. //
  151. $exist = FALSE;
  152. require_once(str_replace(SYS_PATH_SEP_DOUBLE,SYS_PATH_SEP,dirname(__FILE__).SYS_PATH_SEP).'..'.SYS_PATH_SEP.'_shared'.SYS_PATH_SEP.'exist-api.inc.php');
  153. try {
  154. if ($mode == 'admin') {
  155. $wsdl_url=XMLDB_HOST.':'.XMLDB_PORT.'/exist/services/Admin?wsdl';
  156. $u = DCTL_XMLDB_USER_ADMIN;
  157. $p = DCTL_XMLDB_PSWD_ADMIN;
  158. } else {
  159. $wsdl_url=XMLDB_HOST.':'.XMLDB_PORT.'/exist/services/Query?wsdl';
  160. $u = DCTL_XMLDB_USER;
  161. $p = DCTL_XMLDB_PSWD;
  162. };
  163. $exist = false;
  164. if (url_exists($wsdl_url)) {
  165. /* if ($mode == 'admin') { */
  166. /* $exist = new existAdmin(DCTL_XMLDB_USER, DCTL_XMLDB_PSWD, $wsdl_url); */
  167. /* } else { */
  168. $exist = new exist($u, $p, $wsdl_url, $persistent);
  169. /* }; */
  170. $exist->setDebug(false);
  171. $exist->connect($mode);
  172. } else {
  173. echo('<span class="error">Can\'t find URL {'.$wsdl_url.'}</span><br />');
  174. };
  175. } catch (Exception $e) {
  176. echo('<span class="error">Can\'t connect to xmldb engine... {'.$e.'}</span><br />');
  177. };
  178. return $exist;
  179. };
  180. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  181. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  182. function url_exists($url) {
  183. if($url == NULL) return false;
  184. if (function_exists('curl_init')) {
  185. $ch = curl_init($url);
  186. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  187. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  188. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  189. $data = curl_exec($ch);
  190. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  191. curl_close($ch);
  192. } else {
  193. $httpcode = 200 * (file_get_contents($url,null,null,0,10) != false);
  194. };
  195. if($httpcode>=200 && $httpcode<300){
  196. return true;
  197. } else {
  198. return false;
  199. }
  200. };
  201. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  202. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  203. function dctl_sql_connect ($db_name, $new=true) {
  204. $URL = ''; // default
  205. switch($db_name) {
  206. case DCTL_DB_NAME:
  207. $URL = MYSQL_HOST_PN.':'.MYSQL_PORT_PN;
  208. break;
  209. case DCTL_DB_ICONCLASS:
  210. $URL = MYSQL_HOST_IC.':'.MYSQL_PORT_IC;
  211. break;
  212. };
  213. try {
  214. $connection = mysql_connect($URL, DCTL_SQL_USER, DCTL_SQL_PSWD, $new);
  215. } catch (Exception $e) {
  216. die('<span class="error">Can\'t connect to sql engine... {'.$e.'}</span><br />');
  217. };
  218. try {
  219. mysql_select_db($db_name, $connection);
  220. } catch (Exception $e) {
  221. die('<span class="error">Can\'t connect to database "'.$db_name.'"... {'.$e.'}</span><br />');
  222. };
  223. return $connection;
  224. };
  225. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  226. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  227. // * GENERAL PURPOSES *
  228. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  229. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  230. function doBackup ($fPath) {
  231. if (is_file($fPath)) {
  232. $dPath = dirname($fPath).SYS_PATH_SEP.DCTL_RESERVED_PREFIX.'bkp';
  233. if(!is_dir($dPath)) mkdir($dPath, CHMOD);
  234. @chmod($dPath, CHMOD);
  235. $fName = basename($fPath);
  236. $fExt = substr($fName, -4, 4);
  237. $fBase = substr($fName, 0, strlen($fName)-4);
  238. $fPath2 = $dPath.SYS_PATH_SEP.$fBase.'.'.date('ymdhms').'.'.DCTL_USER_ID.$fExt;
  239. copy($fPath, $fPath2);
  240. @chmod($fPath2, CHMOD);
  241. };
  242. };
  243. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  244. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  245. function checkIfLocked ($fPath, &$who, &$content) {
  246. $isLocked = FALSE;
  247. $who = '';
  248. $content = array();
  249. $dPath = dirname($fPath);
  250. $handle = opendir($dPath);
  251. while ($entry = readdir($handle)) {
  252. if (substr($entry, 0, 1) != '.') {
  253. $content[] = $dPath.SYS_PATH_SEP.$entry;
  254. };
  255. };
  256. $content = array_values(preg_grep('/x-.*'.basename($fPath).'/', $content));
  257. $isLocked = count($content) == 1;
  258. if ($isLocked) {
  259. $who = preg_split('/-/', basename($content[0]));
  260. $who = $who[1];
  261. };
  262. return $isLocked;
  263. };
  264. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  265. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  266. function makePreview ($theLocation, $g_srcfile, $overwrite=TRUE, $forcedsize=200, $imgcomp=0) {
  267. if (file_exists($g_srcfile)) {
  268. global $EXTENSION_PREVIEW;
  269. $g_imgcomp = 100-$imgcomp;
  270. $g_fw = $forcedsize;
  271. $g_fh = $forcedsize;
  272. $g_srcpath = dirname(dirname(dirname($g_srcfile))).SYS_PATH_SEP.$theLocation;
  273. if(!is_dir($g_srcpath)) mkdir($g_srcpath, CHMOD);
  274. @chmod($g_srcpath, CHMOD);
  275. $g_srcname = basename($g_srcfile);
  276. $g_dstfile = $g_srcpath.SYS_PATH_SEP.$g_srcname;
  277. if ($overwrite || (!file_exists($g_dstfile))) {
  278. $ext = strtolower(substr($g_srcname, -3, 3));
  279. if (in_array($ext, $EXTENSION_PREVIEW)) {
  280. $g_is=getimagesize($g_srcfile);
  281. if (($g_is[0]>$g_fw) || ($g_is[1]>$g_fh)) {
  282. if (($g_is[0]-$g_fw) >= ($g_is[1]-$g_fh)) {
  283. $g_iw=$g_fw;
  284. $g_ih=($g_fw/$g_is[0])*$g_is[1];
  285. } else {
  286. $g_ih=$g_fh;
  287. $g_iw=($g_ih/$g_is[1])*$g_is[0];
  288. };
  289. switch ($ext) {
  290. case 'jpg':
  291. $img_src=imagecreatefromjpeg($g_srcfile);
  292. break;
  293. case 'gif':
  294. $img_src=imagecreatefromgif($g_srcfile);
  295. break;
  296. case 'png':
  297. $img_src=imagecreatefrompng($g_srcfile);
  298. break;
  299. };
  300. $img_dst=imagecreatetruecolor($g_iw,$g_ih);
  301. imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]);
  302. imagejpeg($img_dst, $g_dstfile, $g_imgcomp);
  303. imagedestroy($img_dst);
  304. } else {
  305. copy($g_srcfile, $g_dstfile);
  306. @chmod($g_dstfile, CHMOD);
  307. };
  308. } else {
  309. $file_icon = DCTL_IMAGES.'file-'.$ext.'.gif';
  310. if (!is_file($file_icon)) $file_icon = DCTL_IMAGES.'file-unknown.gif';
  311. copy($file_icon, $g_dstfile.'.gif');
  312. @chmod($g_dstfile, CHMOD);
  313. };
  314. };
  315. };
  316. };
  317. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  318. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  319. function createPreview ($g_srcfile, $overwrite=TRUE, $forcedsize=200, $imgcomp=0) {
  320. if (is_dir($g_srcfile)) {
  321. $handle = opendir($g_srcfile);
  322. while ($entry = readdir($handle)) {
  323. if (substr($entry, 0, 1) != '.') {
  324. if (($entry != basename(DCTL_MEDIA_SML)) && ($entry != basename(DCTL_MEDIA_MED))) {
  325. createPreview ($g_srcfile.SYS_PATH_SEP.$entry, $overwrite, $forcedsize, $imgcomp);
  326. };
  327. };
  328. };
  329. } else {
  330. makePreview (DCTL_MEDIA_SML, $g_srcfile, $overwrite, $forcedsize, $imgcomp);
  331. makePreview (DCTL_MEDIA_MED, $g_srcfile, $overwrite, $forcedsize*2.5, $imgcomp);
  332. };
  333. };
  334. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  335. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  336. function dircopy ($srcdir, $dstdir, &$files=array()) {
  337. if(!is_dir($dstdir)) mkdir($dstdir, CHMOD);
  338. @chmod($dstdir, CHMOD);
  339. $handle = opendir($srcdir);
  340. while ($entry = readdir($handle)) {
  341. if (substr($entry, 0, 1) != '.') {
  342. $fullsrc = $srcdir.SYS_PATH_SEP.$entry;
  343. $fulldst = $dstdir.SYS_PATH_SEP.$entry;
  344. if (is_dir ($fullsrc)) {
  345. if(!is_dir($fulldst)) mkdir($fulldst, CHMOD);
  346. @chmod($fulldst, CHMOD);
  347. dircopy ($fullsrc, $fulldst, &$files);
  348. } else {
  349. if (is_file($fullsrc)) {
  350. copy($fullsrc, $fulldst);
  351. @chmod($fulldst, CHMOD);
  352. };
  353. $files[] = $entry;
  354. };
  355. };
  356. };
  357. @chmod($dstdir, CHMOD);
  358. };
  359. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  360. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  361. function require_here ($file) {
  362. if(is_file($file)) {
  363. $phpCode=implode("", file($file));
  364. ob_start();
  365. eval('?>'.$phpCode);
  366. $returnText = ob_get_contents();
  367. ob_end_clean();
  368. } else {
  369. $returnText = '<span class="error">File not found: '.basename($file).'</span>';
  370. };
  371. return $returnText;
  372. };
  373. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  374. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  375. function hardFlush(&$text = '') {
  376. if ($text != '') {
  377. if (strlen($text)<256) $text = str_pad($text,256);
  378. // make sure output buffering is off before we start it
  379. // this will ensure same effect whether or not ob is enabled already
  380. while (ob_get_level()) {
  381. ob_end_flush();
  382. };
  383. // start output buffering
  384. if (ob_get_length() === false) {
  385. ob_start();
  386. };
  387. echo '<li>'.$text.'</li>';
  388. ob_flush();
  389. flush();
  390. $text = '';
  391. };
  392. };
  393. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  394. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  395. function cleanUpIndentation($theText) {
  396. $theText = preg_replace('/<(\w+)>('.WS.'*)<\/(\w+)>/', '<$1 />', $theText);
  397. $theText = preg_replace('/('.WS.'{2,})/', '$1', $theText);
  398. $theText = preg_replace('/'.WS.'*\/>/', ' />', $theText);
  399. $theText = preg_replace('/'.WS.'+/', ' ', $theText);
  400. $theText = preg_replace('/>'.WS.'*</', '> <', $theText);
  401. return $theText;
  402. };
  403. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  404. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  405. function normalize($string) {
  406. $n_string = $string;// $n_string = strtolower($string);
  407. $n_string = preg_replace('/[^a-zA-Z0-9._\-]/', '', $n_string);// remove all unwanted chars
  408. return trim($n_string);
  409. };
  410. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  411. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  412. function my_strtoupper ($output)
  413. {
  414. // Convert accented characters to their ASCII counterparts...
  415. $output = strtr(utf8_decode($output),
  416. "\xA1\xAA\xBA\xBF".
  417. "\xC0\xC1\xC2\xC3\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF".
  418. "\xD0\xD1\xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD".
  419. "\xE0\xE1\xE2\xE3\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF".
  420. "\xF0\xF1\xF2\xF3\xF4\xF5\xF8\xF9\xFA\xFB\xFD\xFF",
  421. "!ao?AAAAACEEEEIIIIDNOOOOOUUUYaaaaaceeeeiiiidnooooouuuyy");
  422. // ...and ligatures too
  423. $output = makeUTF8(strtr($output, array("\xC4"=>"Ae", "\xC6"=>"AE", "\xD6"=>"Oe",
  424. "\xDC"=>"Ue", "\xDE"=>"TH", "\xDF"=>"ss", "\xE4"=>"ae", "\xE6"=>"ae",
  425. "\xF6"=>"oe", "\xFC"=>"ue", "\xFE"=>"th")));
  426. $output = strtoupper($output);
  427. return $output;
  428. }
  429. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  430. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  431. function my_soundex ($WordString, $LengthOption=0)
  432. {
  433. $SoundExLen = $LengthOption;
  434. if($SoundExLen > 10) {
  435. $SoundExLen = 10;
  436. }
  437. if($SoundExLen < 4) {
  438. $SoundExLen = 4;
  439. }
  440. if(!$WordString) {
  441. return "";
  442. }
  443. # Clean and tidy
  444. #
  445. // $WordString = strtoupper($WordString);
  446. $WordString = my_strtoupper($WordString);
  447. $WordStr = $WordString;
  448. $WordStr = preg_replace ('/[^A-Z]/si', ' ', $WordStr); # replace non-chars with space
  449. $WordStr = preg_replace ('/^'.WS.'/s', '', $WordStr); # remove leading space
  450. $WordStr = preg_replace ('/'.WS.'$/s', '', $WordStr); # remove trailing space
  451. # Some of our own improvements
  452. $WordStr = preg_replace ('/DG/s', '', $WordStr); # Change DG to G
  453. $WordStr = preg_replace ('/GH/s', 'H', $WordStr); # Change GH to H
  454. $WordStr = preg_replace ('/KN/s', 'N', $WordStr); # Change KN to N
  455. $WordStr = preg_replace ('/GN/s', 'N', $WordStr); # Change GN to N
  456. $WordStr = preg_replace ('/MB/s', 'M', $WordStr); # Change MB to M
  457. $WordStr = preg_replace ('/PH/s', 'F', $WordStr); # Change PH to F
  458. $WordStr = preg_replace ('/TCH/s', 'CH', $WordStr); # Change TCH to CH
  459. $WordStr = preg_replace ('/MP([STZ])/s', 'M$1', $WordStr); # MP if follwd by S|T|Z
  460. $WordStr = preg_replace ('/^PS/s', 'S', $WordStr); # Change leading PS to S
  461. $WordStr = preg_replace ('/^PF/s', 'F', $WordStr); # Change leading PF to F
  462. # Done here because the
  463. # above improvements could
  464. # change this first letter
  465. #
  466. $FirstLetter = substr($WordStr,0,1);
  467. # in case 1st letter is
  468. # an H or W and we're in
  469. # CensusOption = 1
  470. # (add test for 'H'/'W' v1.0c djr)
  471. #
  472. if($FirstLetter == "H" | $FirstLetter == "W") {
  473. $TmpStr = substr($WordStr,1);
  474. $WordStr = "-$TmpStr";
  475. }
  476. # Begin Classic SoundEx
  477. #
  478. $WordStr = preg_replace ('/[AEIOUYHW]/s', '0', $WordStr);
  479. $WordStr = preg_replace ('/[BPFV]/s' ,'1', $WordStr);
  480. $WordStr = preg_replace ('/[CSGJKQXZ]/s', '2', $WordStr);
  481. $WordStr = preg_replace ('/[DT]/s', '3', $WordStr);
  482. $WordStr = preg_replace ('/L/s', '4', $WordStr);
  483. $WordStr = preg_replace ('/[MN]/s', '5', $WordStr);
  484. $WordStr = preg_replace ('/R/s', '6', $WordStr);
  485. # Remove extra equal adjacent digits
  486. #
  487. $WSLen = strlen($WordStr);
  488. $LastChar = '';
  489. # v1.0c rmv: $TmpStr = "-"; # rplc skipped 1st char
  490. $TmpStr = '';
  491. for($i = 0; $i < $WSLen; $i++) { # v1.0c now org-0
  492. $CurChar = substr($WordStr, $i, 1);
  493. if($CurChar == $LastChar) {
  494. $TmpStr .= ' ';
  495. }
  496. else {
  497. $TmpStr .= $CurChar;
  498. $LastChar = $CurChar;
  499. }
  500. }
  501. $WordStr = $TmpStr;
  502. $WordStr = substr($WordStr,1); # Drop first ltr code
  503. $WordStr = preg_replace ('/'.WS.'/s', '', $WordStr); # remove spaces
  504. $WordStr = preg_replace ('/0/s', '', $WordStr); # remove zeros
  505. $WordStr .= "0000000000"; # pad w/0s on rght
  506. $WordStr = "$FirstLetter$WordStr"; # Add 1st ltr of wrd
  507. $WordStr = substr($WordStr,0,$SoundExLen); # size to taste
  508. return $WordStr;
  509. }
  510. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  511. /* - - - - - - - - - - - - - - - - - */
  512. function cleanWebString ($theMixed, $theLength=0, $theSpacer='') {
  513. $theResult = '';
  514. $theMixed = (array) $theMixed;
  515. foreach ($theMixed as $theString) {
  516. $theString = (string) $theString;
  517. if ($theString != '') {
  518. $theString = strip_html($theString);
  519. $theString = preg_replace('/'.WS.''.WS.'+/', ' ', $theString);
  520. $theString = preg_replace('/\"/', '&quot;', $theString);
  521. $theString = preg_replace('/\'/', '&apos;', $theString);
  522. $theString = preg_replace('/\>/', '&gt;', $theString);
  523. $theString = preg_replace('/\</', '&lt;', $theString);
  524. $theString = trim($theString);
  525. if ($theLength > 0) {
  526. $add = '';
  527. if ($theLength < strlen($theString)) {
  528. $add = '...';
  529. };
  530. $theString = substr($theString, 0, $theLength).$add;
  531. };
  532. if ($theString != '') {
  533. if ($theResult != '') {
  534. $theResult .= '. ';
  535. };
  536. $theString = makeSafeEntities($theString);
  537. //
  538. // $theString = str_ireplace('<','&lt;',$theString);
  539. // $theString = str_ireplace('>','&gt;',$theString);
  540. //
  541. $theResult .= $theString;
  542. };
  543. };
  544. };
  545. return $theResult;
  546. };
  547. /* - - - - - - - - - - - - - - - - - */
  548. /* - - - - - - - - - - - - - - - - - */
  549. function strip_html($text, $theSpacer='') {
  550. $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
  551. '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
  552. '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
  553. '@<!['.WS.'\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
  554. );
  555. $text = preg_replace($search, $theSpacer, $text);
  556. return $text;
  557. };
  558. /* - - - - - - - - - - - - - - - - - */
  559. /* - - - - - - - - - - - - - - - - - */
  560. // Convert str to UTF-8 (if not already), then convert that to HTML named entities.
  561. // and numbered references. Compare to native htmlentities() function.
  562. // Unlike that function, this will skip any already existing entities in the string.
  563. // mb_convert_encoding() doesn't encode ampersands, so use makeAmpersandEntities to convert those.
  564. // mb_convert_encoding() won't usually convert to illegal numbered entities (128-159) unless
  565. // there's a charset discrepancy, but just in case, correct them with correctIllegalEntities.
  566. function makeSafeEntities($str, $convertTags = 0, $encoding = "") {
  567. if (is_array($arrOutput = $str)) {
  568. foreach (array_keys($arrOutput) as $key)
  569. $arrOutput[$key] = makeSafeEntities($arrOutput[$key],$encoding);
  570. return $arrOutput;
  571. }
  572. else if (strlen($str)>0) {
  573. $str = makeUTF8($str,$encoding);
  574. $str = mb_convert_encoding($str,"HTML-ENTITIES","UTF-8");
  575. $str = makeAmpersandEntities($str);
  576. if ($convertTags)
  577. $str = makeTagEntities($str);
  578. $str = correctIllegalEntities($str);
  579. return $str;
  580. }
  581. }
  582. /* - - - - - - - - - - - - - - - - - */
  583. /* - - - - - - - - - - - - - - - - - */
  584. // Compare to native utf8_encode function, which will re-encode text that is already UTF-8
  585. function makeUTF8($str,$encoding = "") {
  586. if (strlen($str)>0) {
  587. if (empty($encoding) && isUTF8($str))
  588. $encoding = "UTF-8";
  589. if (empty($encoding))
  590. $encoding = mb_detect_encoding($str,'UTF-8, ISO-8859-1');
  591. if (empty($encoding))
  592. $encoding = "ISO-8859-1"; // if charset can't be detected, default to ISO-8859-1
  593. return $encoding == "UTF-8" ? $str : @mb_convert_encoding($str,"UTF-8",$encoding);
  594. };
  595. return '';
  596. }
  597. /* - - - - - - - - - - - - - - - - - */
  598. /* - - - - - - - - - - - - - - - - - */
  599. // Much simpler UTF-8-ness checker using a regular expression created by the W3C:
  600. // Returns true if $string is valid UTF-8 and false otherwise.
  601. // From http://w3.org/International/questions/qa-forms-UTF-8.html
  602. function isUTF8($str) {
  603. return preg_match('%^(?:
  604. [\x09\x0A\x0D\x20-\x7E] // ASCII
  605. | [\xC2-\xDF][\x80-\xBF] // non-overlong 2-byte
  606. | \xE0[\xA0-\xBF][\x80-\xBF] // excluding overlongs
  607. | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} // straight 3-byte
  608. | \xED[\x80-\x9F][\x80-\xBF] // excluding surrogates
  609. | \xF0[\x90-\xBF][\x80-\xBF]{2} // planes 1-3
  610. | [\xF1-\xF3][\x80-\xBF]{3} // planes 4-15
  611. | \xF4[\x80-\x8F][\x80-\xBF]{2} // plane 16
  612. )*$%xs', $str);
  613. }
  614. /* - - - - - - - - - - - - - - - - - */
  615. /* - - - - - - - - - - - - - - - - - */
  616. // Convert ampersands to named or numbered entities.
  617. // Use regex to skip any that might be part of existing entities.
  618. function makeAmpersandEntities($str, $useNamedEntities = 1) {
  619. return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/m", $useNamedEntities ? "&amp;" : "&#38;", $str);
  620. }
  621. /* - - - - - - - - - - - - - - - - - */
  622. /* - - - - - - - - - - - - - - - - - */
  623. // Convert illegal HTML numbered entities in the range 128 - 159 to legal couterparts
  624. function correctIllegalEntities($str) {
  625. $chars = array(
  626. 128 => '&#8364;',
  627. 130 => '&#8218;',
  628. 131 => '&#402;',
  629. 132 => '&#8222;',
  630. 133 => '&#8230;',
  631. 134 => '&#8224;',
  632. 135 => '&#8225;',
  633. 136 => '&#710;',
  634. 137 => '&#8240;',
  635. 138 => '&#352;',
  636. 139 => '&#8249;',
  637. 140 => '&#338;',
  638. 142 => '&#381;',
  639. 145 => '&#8216;',
  640. 146 => '&#8217;',
  641. 147 => '&#8220;',
  642. 148 => '&#8221;',
  643. 149 => '&#8226;',
  644. 150 => '&#8211;',
  645. 151 => '&#8212;',
  646. 152 => '&#732;',
  647. 153 => '&#8482;',
  648. 154 => '&#353;',
  649. 155 => '&#8250;',
  650. 156 => '&#339;',
  651. 158 => '&#382;',
  652. 159 => '&#376;');
  653. foreach (array_keys($chars) as $num)
  654. $str = str_replace("&#".$num.";", $chars[$num], $str);
  655. return $str;
  656. }
  657. /* - - - - - - - - - - - - - - - - - */
  658. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  659. function dump ($text='** HERE **', $class='') {
  660. $returnText = '';
  661. $returnText .= '<div style="background:white;color:red;border:1px dotted red;';
  662. $returnText .= 'right:1.0em;z-index:10000;width:98%;overflow:auto;';
  663. $returnText .= 'word-wrap:break-word;height:auto;background:transparent;';
  664. $returnText .= 'padding:3px;font-size:9px;position:relative;top:0;left:1.0em">';
  665. $backtrace = debug_backtrace();
  666. $text = preg_replace('/\n/', '<br />', htmlentities(((string) serialize($text)), ENT_QUOTES, "utf-8")).'<br />';//htmlentities(nl2br((string) serialize($text))); // var_export($text,true) | print_r($text,true) | serialize($text)
  667. if ($class != '') {
  668. $returnText = '<span class="'.$class.'">'.$returnText.'</span>';
  669. };
  670. $returnText .= $text;
  671. foreach ($backtrace as $k=>$v) {
  672. $file = (isset($backtrace[$k]['file'])) ? $backtrace[$k]['file']: '???';
  673. $returnText .= basename(dirname($file)).SYS_PATH_SEP.basename($file).' :: ';
  674. if (isset($backtrace[$k+1])) $returnText .= $backtrace[$k+1]['function'];
  675. $line = (isset($backtrace[$k]['line'])) ? $backtrace[$k]['line']: '???';
  676. $returnText .= ' @ '.$line.'<br />';
  677. };
  678. $returnText .= '</div>';
  679. echo $returnText;
  680. };
  681. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  682. /* - - - - - - - - - - - - - - - - - */
  683. function dctl_getPHPvar($theVar) {
  684. $thePHP = 'echo '.$theVar.';';
  685. ob_start();
  686. eval($thePHP);
  687. $returnText = ob_get_contents();
  688. ob_end_clean();
  689. return $returnText;
  690. };
  691. /* - - - - - - - - - - - - - - - - - */
  692. /* - - - - - - - - - - - - - - - - - */
  693. function dctl_getCurrentLanguage () {
  694. global $curr_lang;
  695. return strval($curr_lang);
  696. };
  697. /* - - - - - - - - - - - - - - - - - */
  698. /* - - - - - - - - - - - - - - - - - */
  699. function dctl_getLocalized($item) {
  700. global $curr_lang;
  701. global $string;
  702. if (isset($string[$curr_lang][$item])) {
  703. return strval($string[$curr_lang][$item]);
  704. } else {
  705. return strval('[?'.$item.'?]');
  706. };
  707. };
  708. /* - - - - - - - - - - - - - - - - - */
  709. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  710. class zipfile {
  711. var $datasec = array(); // array to store compressed data
  712. var $ctrl_dir = array(); // central directory
  713. var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; //end of Central directory record
  714. var $old_offset = 0;
  715. function add_dir($name)
  716. // adds "directory" to archive - do this before putting any files in directory!
  717. // $name - name of directory... like this: "path/"
  718. // ...then you can add files using add_file with names like "path/file.txt"
  719. {
  720. $name = str_replace("\\", "/", $name);
  721. $fr = "\x50\x4b\x03\x04";
  722. $fr .= "\x0a\x00"; // ver needed to extract
  723. $fr .= "\x00\x00"; // gen purpose bit flag
  724. $fr .= "\x00\x00"; // compression method
  725. $fr .= "\x00\x00\x00\x00"; // last mod time and date
  726. $fr .= pack("V",0); // crc32
  727. $fr .= pack("V",0); //compressed filesize
  728. $fr .= pack("V",0); //uncompressed filesize
  729. $fr .= pack("v", strlen($name) ); //length of pathname
  730. $fr .= pack("v", 0 ); //extra field length
  731. $fr .= $name;
  732. // end of "local file header" segment
  733. // no "file data" segment for path
  734. // "data descriptor" segment (optional but necessary if archive is not served as file)
  735. $fr .= pack("V",0); //crc32
  736. $fr .= pack("V",0); //compressed filesize
  737. $fr .= pack("V",0); //uncompressed filesize
  738. // add this entry to array
  739. $this->datasec[] = $fr;
  740. $new_offset = strlen(implode("", $this->datasec));
  741. // ext. file attributes mirrors MS-DOS directory attr byte, detailed
  742. // at http://support.microsoft.com/support/kb/articles/Q125/0/19.asp
  743. // now add to central record
  744. $cdrec = "\x50\x4b\x01\x02";
  745. $cdrec .="\x00\x00"; // version made by
  746. $cdrec .="\x0a\x00"; // version needed to extract
  747. $cdrec .="\x00\x00"; // gen purpose bit flag
  748. $cdrec .="\x00\x00"; // compression method
  749. $cdrec .="\x00\x00\x00\x00"; // last mod time & date
  750. $cdrec .= pack("V",0); // crc32
  751. $cdrec .= pack("V",0); //compressed filesize
  752. $cdrec .= pack("V",0); //uncompressed filesize
  753. $cdrec .= pack("v", strlen($name) ); //length of filename
  754. $cdrec .= pack("v", 0 ); //extra field length
  755. $cdrec .= pack("v", 0 ); //file comment length
  756. $cdrec .= pack("v", 0 ); //disk number start
  757. $cdrec .= pack("v", 0 ); //internal file attributes
  758. $ext = "\x00\x00\x10\x00";
  759. $ext = "\xff\xff\xff\xff";
  760. $cdrec .= pack("V", 16 ); //external file attributes - 'directory' bit set
  761. $cdrec .= pack("V", $this->old_offset ); //relative offset of local header
  762. $this->old_offset = $new_offset;
  763. $cdrec .= $name;
  764. // optional extra field, file comment goes here
  765. // save to array
  766. $this->ctrl_dir[] = $cdrec;
  767. }
  768. function add_file($data, $name)
  769. // adds "file" to archive
  770. // $data - file contents
  771. // $name - name of file in archive. Add path if your want
  772. {
  773. $name = str_replace("\\", "/", $name);
  774. //$name = str_replace("\\", "\\\\", $name);
  775. $fr = "\x50\x4b\x03\x04";
  776. $fr .= "\x14\x00"; // ver needed to extract
  777. $fr .= "\x00\x00"; // gen purpose bit flag
  778. $fr .= "\x08\x00"; // compression method
  779. $fr .= "\x00\x00\x00\x00"; // last mod time and date
  780. $unc_len = strlen($data);
  781. $crc = crc32($data);
  782. $zdata = gzcompress($data);
  783. $zdata = substr( substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug
  784. $c_len = strlen($zdata);
  785. $fr .= pack("V",$crc); // crc32
  786. $fr .= pack("V",$c_len); //compressed filesize
  787. $fr .= pack("V",$unc_len); //uncompressed filesize
  788. $fr .= pack("v", strlen($name) ); //length of filename
  789. $fr .= pack("v", 0 ); //extra field length
  790. $fr .= $name;
  791. // end of "local file header" segment
  792. // "file data" segment
  793. $fr .= $zdata;
  794. // "data descriptor" segment (optional but necessary if archive is not served as file)
  795. $fr .= pack("V",$crc); //crc32
  796. $fr .= pack("V",$c_len); //compressed filesize
  797. $fr .= pack("V",$unc_len); //uncompressed filesize
  798. // add this entry to array
  799. $this->datasec[] = $fr;
  800. $new_offset = strlen(implode("", $this->datasec));
  801. // now add to central directory record
  802. $cdrec = "\x50\x4b\x01\x02";
  803. $cdrec .="\x00\x00"; // version made by
  804. $cdrec .="\x14\x00"; // version needed to extract
  805. $cdrec .="\x00\x00"; // gen purpose bit flag
  806. $cdrec .="\x08\x00"; // compression method
  807. $cdrec .="\x00\x00\x00\x00"; // last mod time & date
  808. $cdrec .= pack("V",$crc); // crc32
  809. $cdrec .= pack("V",$c_len); //compressed filesize
  810. $cdrec .= pack("V",$unc_len); //uncompressed filesize
  811. $cdrec .= pack("v", strlen($name) ); //length of filename
  812. $cdrec .= pack("v", 0 ); //extra field length
  813. $cdrec .= pack("v", 0 ); //file comment length
  814. $cdrec .= pack("v", 0 ); //disk number start
  815. $cdrec .= pack("v", 0 ); //internal file attributes
  816. $cdrec .= pack("V", 32 ); //external file attributes - 'archive' bit set
  817. $cdrec .= pack("V", $this->old_offset ); //relative offset of local header
  818. $this->old_offset = $new_offset;
  819. $cdrec .= $name;
  820. // optional extra field, file comment goes here
  821. // save to central directory
  822. $this->ctrl_dir[] = $cdrec;
  823. }
  824. function file() { //
  825. $data = implode("", $this->datasec);
  826. $ctrldir = implode("", $this->ctrl_dir);
  827. return
  828. $data.
  829. $ctrldir.
  830. $this->eof_ctrl_dir.
  831. pack("v", sizeof($this->ctrl_dir)). // total # of entries "on this disk"
  832. pack("v", sizeof($this->ctrl_dir)). // total # of entries overall
  833. pack("V", strlen($ctrldir)). // size of central dir
  834. pack("V", strlen($data)). // offset to start of central dir
  835. "\x00\x00"; // .zip file comment length
  836. }
  837. }
  838. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  839. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  840. function addToZip($item, &$zip, $zipdir="") {
  841. if (is_dir($item)) {
  842. $zipdir .= basename($item).SYS_PATH_SEP;
  843. $zip->add_dir($zipdir);
  844. $handle = opendir($item);
  845. while ($entry = readdir($handle)) {
  846. if (substr($entry, 0, 1) != '.') {
  847. addToZip($item.SYS_PATH_SEP.$entry, &$zip, $zipdir);
  848. };
  849. };
  850. } else {
  851. if (is_file($item)) {
  852. if (strtolower(substr($item, -4, 4)) != '.zip') {
  853. $handle = fopen($item, "r");
  854. $contents = fread($handle, filesize($item));
  855. fclose($handle);
  856. $zip->add_dir($zipdir);
  857. $zip->add_file($contents,$zipdir.basename($item));
  858. };
  859. };
  860. };
  861. };
  862. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  863. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  864. class asPrettyXMLElement extends SimpleXMLElement {
  865. /**
  866. * Outputs this element as pretty XML to increase readability.
  867. *
  868. * @param int $level (optional) The number of spaces to use for
  869. * indentation, defaults to 1
  870. * @return string The XML output
  871. * @access public
  872. */
  873. public function asPrettyXML($level = 1) {
  874. // get an array containing each XML element
  875. $xml = explode("\n", preg_replace('/>'.WS.'*</', ">\n<", preg_replace('/('.WS.')'.WS.'+/','$1',$this->asXML())));
  876. // hold current indentation level
  877. $indent = 0;
  878. // hold the XML segments
  879. $pretty = array();
  880. // shift off opening XML tag if present
  881. if (count($xml) && preg_match('/^<\?'.WS.'*xml/', $xml[0])) {
  882. $pretty[] = array_shift($xml);
  883. };
  884. foreach ($xml as $el) {
  885. if (preg_match('/^<([\w])+[^>\/]*>$/U', $el)) {
  886. // opening tag, increase indent
  887. $pretty[] = str_repeat(' ', $indent) . $el;
  888. $indent += $level;
  889. } else {
  890. if (preg_match('/^<\/.+>$/', $el)) {
  891. // closing tag, decrease indent
  892. $indent -= $level;
  893. };
  894. if ($indent<0) $indent = 0;
  895. $pretty[] = str_repeat(' ', $indent) . $el;
  896. };
  897. };
  898. return implode("\n", $pretty);
  899. }
  900. };
  901. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  902. /* - - - - - - - - - - - - - - - - - */
  903. function get_currentpath() {
  904. global $area;
  905. global $curr_area;
  906. global $curr_lang;
  907. global $other_lang;
  908. global $string;
  909. $location = "";
  910. $prev_step = "";
  911. $steps = explode (".", $curr_area);
  912. foreach ($steps as $this_step) {
  913. if ($location != '') {
  914. $location .= ":";
  915. $prev_step .= ".";
  916. };
  917. if (stripos($area['url'][$prev_step.$this_step], '.php') !==FALSE) {
  918. $php_script = $area['url'][$prev_step.$this_step];
  919. } else {
  920. $php_script = 'index.php';
  921. };
  922. $prev_step .= $this_step;
  923. $thisURL = DCTL_REQUEST_URI;
  924. $thisURL = str_ireplace(basename($_SERVER['PHP_SELF']),$php_script,$thisURL);
  925. $thisURL = str_ireplace('area='.$curr_area,'area='.$prev_step,$thisURL);
  926. if (stripos($thisURL,'.php?') === false) {
  927. $thisURL = str_ireplace('.php', '.php?', $thisURL);
  928. };
  929. if (XMLDB_PATH_BASE_TMP) {
  930. if (stripos($thisURL,'temp=') === false) {
  931. $thisURL .= "&amp;temp=true";
  932. };
  933. };
  934. $otherURL = str_ireplace('lang='.$curr_lang,'lang='.$other_lang,$thisURL);
  935. $location .= "<a href=\"".$thisURL."\" class=\"small\" title=\"".strtolower($area[$curr_lang][$prev_step])."\">".strtolower($area[$curr_lang][$prev_step])."</a>";
  936. };
  937. if ($curr_lang != $other_lang) {
  938. $location .= " <a href=\"".$otherURL."\" class=\"small\" title=\"".$string[$other_lang]['language_version']."\">";
  939. $location .= "(".strtoupper($other_lang).")</a>";
  940. } else {
  941. $location .= " ()";
  942. };
  943. return $location;
  944. };
  945. /* - - - - - - - - - - - - - - - - - */
  946. /* - - - - - - - - - - - - - - - - - */
  947. function wctl_loader(&$text_result, $f_content, $option="", $putBR=TRUE, $DEBUG=FALSE) {
  948. global $string;
  949. $text_done = false;
  950. if ($f_content != '') {
  951. if (stripos($f_content, 'sitemap') !== false) {
  952. global $area;
  953. global $curr_area;
  954. global $curr_lang;
  955. $content = '';
  956. $content .= '<?xml version="1.0" encoding="UTF-8" ?>';
  957. $content .= '<!DOCTYPE wctl SYSTEM "'.DCTL_SITEMAP_DTDS.'">';
  958. $content .= '<wctl>';
  959. $content .= '<wctl_page>';
  960. $content .= '<wctl_caption>'.$area[$curr_lang]['00'].'</wctl_caption>';
  961. $content .= '<wctl_title>www.ctl.sns.it</wctl_title>';
  962. $content .= '<wctl_summary />';
  963. $content .= '<wctl_text>';
  964. foreach($area[$curr_lang] as $key=>$what) {
  965. if ($key != '00') {
  966. $length = strlen($key);
  967. $level = intval($length/2);
  968. for ($i=1; $i<=$length; $i++) $content .= "&#160;";
  969. $tag_b ='';
  970. $tag_e ='';
  971. // $what = ucwords($what);
  972. switch ($level) {
  973. case '1':
  974. $tag_b ='<br /><strong>';
  975. $tag_e ='</strong>';
  976. break;
  977. case '2':
  978. $tag_b ='<em>';
  979. $tag_e ='</em>';
  980. break;
  981. default:
  982. $level = 0;
  983. break;
  984. };
  985. $content .= $tag_b."<a href=\"".$_SERVER['PHP_SELF']."?lang=".$curr_lang."&amp;area=".$key."\" title=\"\">";
  986. $content .= '<img src="'.DCTL_IMAGES.'map_l'.$level.'.gif" alt="(open level)" />'.$what.'</a>'.$tag_e.'<br />';
  987. };
  988. };
  989. $content .= '</wctl_text>';
  990. $content .= '<wctl_note />';
  991. $content .= '<wctl_icon />';
  992. $content .= '</wctl_page>';
  993. $content .= '</wctl>';
  994. $f_handle = fopen($f_content, "wb");
  995. fwrite($f_handle, $content);
  996. fclose($f_handle);
  997. @chmod($f_content, CHMOD);
  998. };
  999. forceUTF8($f_content);
  1000. if (!($xml = simplexml_load_file($f_content, 'SimpleXMLElement', DCTL_XML_LOADER))) {
  1001. $text_result .= "<b class='wctl_error'>".$f_content."</b> : not valid or couldn't open xml file...";
  1002. $text_done = false;
  1003. };
  1004. // hack to work around php 5.0's problems with default namespaces and xpath()
  1005. $xml['xmlns'] = '';
  1006. $htop = 16;
  1007. switch ($option) {
  1008. case CMS_VIEWMODE_PROJ: // PROGETTI
  1009. $text_result .= '<div id="wctl_icon01"><img id="wctl_preview01" src="'.WEB_WCTL_ICONS.'camillo.gif" alt="(preview icon)" height="250" /></div>';
  1010. $text_result .= "<div id=\"wctl_summary01\">&#160;</div>";
  1011. $text_result .= '<a class="go_top" href="#top" title=""><img src="'.DCTL_IMAGES.'up.gif" alt="(go top icon)" height="'.$htop.'" /></a>';
  1012. break;
  1013. case CMS_VIEWMODE_LIST: // ATTIVITA
  1014. $text_result .= '<a class="go_top" href="#top" title=""><img src="'.DCTL_IMAGES.'up.gif" alt="(go top icon)" height="'.$htop.'" /></a>';
  1015. break;
  1016. default: // PAGE
  1017. break;
  1018. };
  1019. if ($putBR) $text_result .= '<br />';
  1020. $text_result .= wctl_loader_recurse ($option, $xml, '');
  1021. if ($putBR) $text_result .= '<br />';
  1022. $text_done = true;
  1023. };
  1024. return $text_done;
  1025. };
  1026. /* - - - - - - - - - - - - - - - - - */
  1027. /* - - - - - - - - - - - - - - - - - */
  1028. function wctl_loader_recurse ($option, $child, $name_father='') {
  1029. global $curr_area;
  1030. $text2parse = '';
  1031. $icon = array();
  1032. foreach($child->children() as $name=>$children) {
  1033. $id = $children['id'];
  1034. switch ($option) {
  1035. case CMS_VIEWMODE_PROJ:
  1036. switch ($name) {
  1037. case 'wctl_list':
  1038. $text2parse .= "<div class=\"wctl_section01\">";
  1039. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1040. $text2parse .= "</div>";
  1041. break;
  1042. case 'wctl_head':
  1043. $text2parse .= "<div class=\"wctl_head01\">";
  1044. $text2parse .= node_copy ($children->asXML(), $name);
  1045. $text2parse .= "</div>";
  1046. break;
  1047. case 'wctl_item':
  1048. $text2parse .= "<div class=\"wctl_item01\">";
  1049. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1050. $text2parse .= "</div>";
  1051. break;
  1052. case 'wctl_title':
  1053. $title = node_copy ($children->asXML(), $name);
  1054. break;
  1055. case 'wctl_summary':
  1056. $summary = node_copy ($children->asXML(), $name);
  1057. break;
  1058. case 'wctl_icon':
  1059. if ($children !='') $icon = $children;
  1060. break;
  1061. case 'wctl_link':
  1062. $link = $children;
  1063. $text2parse .= "<div class=\"wctl_title01\">";
  1064. $text2parse .= "<a href=\"".$link."\" ";
  1065. $text2parse .= "onmouseover=\"javascript: document.getElementById('wctl_preview01').src='".WEB_WCTL_ICONS.$icon."'; ";
  1066. $text2parse .= "document.getElementById('wctl_summary01').firstChild.nodeValue='".makeSafeEntities($summary)."';\" ";
  1067. $text2parse .= "onmouseout=\"javascript:document.getElementById('wctl_preview01').src='".WEB_WCTL_ICONS."camillo.gif'; ";
  1068. $text2parse .= "document.getElementById('wctl_summary01').firstChild.nodeValue='&#160;';\" ";
  1069. $text2parse .= "title=\"".$icon."\">";
  1070. $text2parse .= $title;
  1071. $text2parse .= "</a>";
  1072. $text2parse .= "</div>";
  1073. break;
  1074. default:
  1075. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1076. break;
  1077. };
  1078. $text2parse .= "\n";
  1079. break;
  1080. case CMS_VIEWMODE_LIST:
  1081. switch ($name) {
  1082. case 'wctl_list':
  1083. $text2parse .= "<div ";
  1084. if ($id != '') $text2parse .= "id=\"".$id."\" ";
  1085. $text2parse .= "class=\"wctl_section02\">";
  1086. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1087. $text2parse .= "</div>";
  1088. break;
  1089. case 'wctl_head':
  1090. $text2parse .= "<div class=\"wctl_head02\">";
  1091. $text2parse .= node_copy ($children->asXML(), $name);
  1092. $text2parse .= "</div>";
  1093. break;
  1094. case 'wctl_item':
  1095. $text2parse .= "<div ";
  1096. if ($id != '') $text2parse .= "id=\"".$id."\" ";
  1097. $text2parse .= "class=\"wctl_item02\">";
  1098. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1099. $text2parse .= "</div>";
  1100. break;
  1101. case 'wctl_caption':
  1102. $caption = node_copy ($children->asXML(), $name);
  1103. break;
  1104. case 'wctl_title':
  1105. $title = node_copy ($children->asXML(), $name);
  1106. break;
  1107. case 'wctl_summary':
  1108. $summary = node_copy ($children->asXML(), $name);
  1109. break;
  1110. case 'wctl_text':
  1111. $text = node_copy ($children->asXML(), $name);
  1112. break;
  1113. case 'wctl_note':
  1114. $note = node_copy ($children->asXML(), $name);
  1115. break;
  1116. case 'wctl_icon':
  1117. if ($children !='') $icon[] = $children;
  1118. break;
  1119. case 'wctl_summary':
  1120. $summary = node_copy ($children->asXML(), $name);
  1121. break;
  1122. case 'wctl_link':
  1123. $link = node_copy ($children->asXML(), $name);
  1124. if ($caption!='') {
  1125. $text2parse .= "<div class=\"wctl_caption02\">";
  1126. $text2parse .= $caption;
  1127. $text2parse .= "</div>";
  1128. };
  1129. for ($ic=0; $ic<count($icon); $ic++) {
  1130. $text2parse .= "<div class=\"wctl_icon02\">";
  1131. $f_hires = str_ireplace("_pw","", $icon[$ic]);
  1132. if (is_file(WEB_WCTL_ICONS.$f_hires) && ($f_hires != $icon[$ic])) {
  1133. $text2parse .= "<a class=\"link_pop\" title=\"(open image in a new window)\"
  1134. href=\"".WEB_WCTL_ICONS.$f_hires."\">";
  1135. } else {
  1136. $f_hires = '';
  1137. };
  1138. $text2parse .= '<img src="'.WEB_WCTL_ICONS.$icon[$ic].'" alt="(preview)" />';
  1139. if ($f_hires) {
  1140. $text2parse .= "</a>";
  1141. };
  1142. $text2parse .= "</div>";
  1143. };
  1144. $text2parse .= "<div class=\"wctl_title02\">";
  1145. if ($children != '' ) {
  1146. $text2parse .= "<a class=\"link_int\" href=\"".$link."\" >";
  1147. $text2parse .= $title;
  1148. $text2parse .= "</a>";
  1149. } else {
  1150. $text2parse .= $title;
  1151. };
  1152. $text2parse .= "</div>";
  1153. if ($summary!='') {
  1154. $text2parse .= "<div class=\"wctl_summary02\">";
  1155. $text2parse .= $summary;
  1156. $text2parse .= "</div>";
  1157. };
  1158. if ($text!='') {
  1159. $text2parse .= "<div class=\"wctl_text02\">";
  1160. $text2parse .= $text;
  1161. $text2parse .= "</div>";
  1162. };
  1163. if ($note!='') {
  1164. $text2parse .= "<div class=\"wctl_note02\">";
  1165. $text2parse .= $note;
  1166. $text2parse .= "</div>";
  1167. };
  1168. break;
  1169. default:
  1170. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1171. break;
  1172. };
  1173. $text2parse .= "\n";
  1174. break;
  1175. case CMS_VIEWMODE_THUMB:
  1176. switch ($name) {
  1177. case 'wctl_list':
  1178. $text2parse .= "<div class=\"spacer\"> </div>";
  1179. $text2parse .= "<div ";
  1180. if ($id != '') $text2parse .= "id=\"".$id."\" ";
  1181. $text2parse .= "class=\"wctl_section03\">";
  1182. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1183. $text2parse .= "</div>";
  1184. $text2parse .= "<div class=\"spacer\"> </div>";
  1185. break;
  1186. case 'wctl_head':
  1187. $text2parse .= "<div class=\"wctl_head03\">";
  1188. $text2parse .= node_copy ($children->asXML(), $name);
  1189. $text2parse .= "</div>";
  1190. break;
  1191. case 'wctl_item':
  1192. $text2parse .= "<div ";
  1193. if ($id != '') $text2parse .= "id=\"".$id."\" ";
  1194. $text2parse .= "class=\"wctl_item03\">";
  1195. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1196. $text2parse .= "</div>";
  1197. break;
  1198. case 'wctl_caption':
  1199. $caption = node_copy ($children->asXML(), $name);
  1200. break;
  1201. case 'wctl_icon':
  1202. if ($children !='') $icon[] = $children;
  1203. break;
  1204. case 'wctl_link':
  1205. $link = node_copy ($children->asXML(), $name);
  1206. for ($ic=0; $ic<count($icon); $ic++) {
  1207. $text2parse .= "<div class=\"wctl_icon03\">";
  1208. $f_hires = str_ireplace("_pw","", $icon[$ic]);
  1209. if (is_file(WEB_WCTL_ICONS.$f_hires) && ($f_hires != $icon[$ic])) {
  1210. $text2parse .= "<a class=\"link_pop\" title=\"(open image in a new window)\"
  1211. href=\"".WEB_WCTL_ICONS.$f_hires."\">";
  1212. } else {
  1213. $f_hires = '';
  1214. };
  1215. $text2parse .= '<img src="'.WEB_WCTL_ICONS.$icon[$ic].'" alt="(preview)" />';
  1216. if ($f_hires) {
  1217. $text2parse .= "</a>";
  1218. };
  1219. $text2parse .= "<br /><span class=\"wctl_caption03\">";
  1220. $text2parse .= $caption;
  1221. $text2parse .= "</span>";
  1222. };
  1223. $text2parse .= "</div>";
  1224. break;
  1225. default:
  1226. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1227. break;
  1228. };
  1229. $text2parse .= "\n";
  1230. break;
  1231. case CMS_VIEWMODE_PAGE: // PAGE
  1232. switch ($name) {
  1233. case 'wctl_page':
  1234. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1235. break;
  1236. case 'wctl_caption':
  1237. if ($children) {
  1238. $text2parse .= "<div class=\"wctl_caption99\">";
  1239. $text2parse .= node_copy ($children->asXML(), $name);
  1240. $text2parse .= "</div>";
  1241. };
  1242. break;
  1243. case 'wctl_title':
  1244. if ($children) {
  1245. $text2parse .= "<div class=\"wctl_title99\">";
  1246. $text2parse .= node_copy ($children->asXML(), $name);
  1247. $text2parse .= "</div>";
  1248. };
  1249. break;
  1250. case 'wctl_summary':
  1251. if ($children) {
  1252. $text2parse .= "<div class=\"wctl_summary99\">";
  1253. $text2parse .= node_copy ($children->asXML(), $name);
  1254. $text2parse .= "</div>";
  1255. };
  1256. break;
  1257. case 'wctl_text':
  1258. $text = node_copy ($children->asXML(), $name);
  1259. break;
  1260. case 'wctl_note':
  1261. $note = "";
  1262. if ($children) {
  1263. $note = node_copy ($children->asXML(), $name);
  1264. };
  1265. break;
  1266. case 'wctl_icon':
  1267. if ($children) {
  1268. $text2parse .= '<div class="wctl_icon99"><img src="'.WEB_WCTL_ICONS.$children.'" alt="(preview)" />';
  1269. $text2parse .= "</div>";
  1270. };
  1271. if ($text != '') {
  1272. $text2parse .= "<div class=\"wctl_text99\">";
  1273. $text2parse .= $text;
  1274. $text2parse .= "</div>";
  1275. };
  1276. if ($note != '') {
  1277. $text2parse .= "<div class=\"wctl_note99\">";
  1278. $text2parse .= $note;
  1279. $text2parse .= "</div>";
  1280. };
  1281. break;
  1282. };
  1283. $text2parse .= "\n";
  1284. break;
  1285. case CMS_VIEWMODE_NEWS: // BACHECA
  1286. switch ($name) {
  1287. case 'wctl_list':
  1288. $text2parse .= "<div ";
  1289. if ($id != '') $text2parse .= "id=\"".$id."\" ";
  1290. $text2parse .= "class=\"wctl_section04\">";
  1291. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1292. $text2parse .= "</div>";
  1293. break;
  1294. case 'wctl_head':
  1295. $text2parse .= "<div class=\"wctl_head04\">";
  1296. $text2parse .= node_copy ($children->asXML(), $name);
  1297. $text2parse .= "</div>";
  1298. break;
  1299. case 'wctl_item':
  1300. $text2parse .= "<div ";
  1301. if ($id != '') {
  1302. switch ($id) {
  1303. case 'drag01':
  1304. $text2parse .= "style=\"position:relative;top:0px;left:50px;\" ";
  1305. break;
  1306. case 'drag02':
  1307. $text2parse .= "style=\"position:relative;top:-130px;left:320px;\" ";
  1308. break;
  1309. case 'drag03':
  1310. $text2parse .= "style=\"position:relative;top:-200px;left:20px;\" ";
  1311. break;
  1312. case 'drag04':
  1313. $text2parse .= "style=\"position:relative;top:-350px;left:280px;\" ";
  1314. break;
  1315. case 'drag05':
  1316. $text2parse .= "style=\"position:relative;top:-400px;left:50px;\" ";
  1317. break;
  1318. case 'drag06':
  1319. $text2parse .= "style=\"position:relative;top:-550px;left:320px;\" ";
  1320. break;
  1321. };
  1322. if ($id != '') $text2parse .= "id=\"".$id."\" ";
  1323. $text2parse .= "class=\"wctl_item04_drag\">";
  1324. } else {
  1325. if ($id != '') $text2parse .= "id=\"".$id."\" ";
  1326. $text2parse .= "class=\"wctl_item02\">";
  1327. };
  1328. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1329. $text2parse .= "</div>";
  1330. break;
  1331. case 'wctl_title':
  1332. $title = node_copy ($children->asXML(), $name);
  1333. break;
  1334. case 'wctl_text':
  1335. $text = node_copy ($children->asXML(), $name);
  1336. break;
  1337. case 'wctl_link':
  1338. $link = node_copy ($children->asXML(), $name);
  1339. $text2parse .= "<div class=\"wctl_title04\">";
  1340. if ($children != '' ) {
  1341. $text2parse .= "<a class=\"link_int\" href=\"".$link."\" >";
  1342. $text2parse .= $title;
  1343. $text2parse .= "</a>";
  1344. } else {
  1345. $text2parse .= $title;
  1346. };
  1347. $text2parse .= "<div class=\"wctl_text04\">";
  1348. $text2parse .= $text;
  1349. $text2parse .= "</div>";
  1350. $text2parse .= "</div>";
  1351. break;
  1352. default:
  1353. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1354. break;
  1355. };
  1356. $text2parse .= "\n";
  1357. break;
  1358. default: // ...
  1359. switch ($name) {
  1360. case 'wctl_list':
  1361. $text2parse .= "<div class=\"wctl_section\">";
  1362. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1363. $text2parse .= "</div>";
  1364. break;
  1365. case 'wctl_head':
  1366. $text2parse .= "<div class=\"wctl_head\">";
  1367. $text2parse .= node_copy ($children->asXML(), $name);
  1368. $text2parse .= "</div>";
  1369. break;
  1370. case 'wctl_item':
  1371. $text2parse .= "<div class=\"wctl_item\">";
  1372. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1373. $text2parse .= "</div>";
  1374. break;
  1375. case 'wctl_title':
  1376. $text2parse .= "<div class=\"wctl_title\">";
  1377. $text2parse .= node_copy ($children->asXML(), $name);
  1378. $text2parse .= "</div>";
  1379. break;
  1380. case 'wctl_summary':
  1381. $text2parse .= "<div class=\"wctl_summary\">";
  1382. $text2parse .= node_copy ($children->asXML(), $name);
  1383. $text2parse .= "</div>";
  1384. break;
  1385. case 'wctl_text':
  1386. $text2parse .= "<div class=\"wctl_text\">";
  1387. $text2parse .= node_copy ($children->asXML(), $name);
  1388. $text2parse .= "</div>";
  1389. break;
  1390. case 'wctl_note':
  1391. $text2parse .= "<div class=\"wctl_note\">";
  1392. $text2parse .= node_copy ($children->asXML(), $name);
  1393. $text2parse .= "</div>";
  1394. break;
  1395. case 'wctl_icon':
  1396. if ($children !='') $text2parse .= '<div class="wctl_icon"><img src="'.WEB_WCTL_ICONS.$children.'" alt="(preview)" />';
  1397. $text2parse .= "</div>";
  1398. break;
  1399. case 'wctl_link':
  1400. $text2parse .= "<a href=\"".$children."\">";
  1401. $text2parse .= "&gt;&gt;";
  1402. $text2parse .= "</a>";
  1403. break;
  1404. case 'wctl_page':
  1405. $text2parse .= wctl_loader_recurse ($option, $children, $name);
  1406. break;
  1407. default:
  1408. wctl_loader_recurse ($option, $children, $name);
  1409. break;
  1410. };
  1411. $text2parse .= "\n";
  1412. break;
  1413. };
  1414. };
  1415. return parse_command($text2parse);
  1416. };
  1417. /* */
  1418. /* - - - - - - - - - - - - - - - - - */
  1419. function array_multi_search($p_needle, $p_haystack) {
  1420. if (! is_array ($p_haystack)) {
  1421. return false;
  1422. };
  1423. $key = array_search ($p_needle, $p_haystack) ;
  1424. if (! ($key === false)) {
  1425. return $key;
  1426. };
  1427. foreach ($p_haystack as $row) {
  1428. $key = array_multi_search ($p_needle, $row);
  1429. if (! ($key === false)) {
  1430. return $key;
  1431. };
  1432. };
  1433. return false;
  1434. };
  1435. /* - - - - - - - - - - - - - - - - - */
  1436. /* - - - - - - - - - - - - - - - - - */
  1437. function array_multi_search_getKey($p_needle, $p_haystack, $key1=0) {
  1438. if (! is_array ($p_haystack)) {
  1439. return false;
  1440. };
  1441. $key = array_search ($p_needle, $p_haystack) ;
  1442. if ($key !== false) {
  1443. return $key1;
  1444. };
  1445. foreach ($p_haystack as $key1=>$row) {
  1446. $key = array_multi_search_getKey ($p_needle, $row, $key1);
  1447. if ($key !== false) {
  1448. return $key1;
  1449. };
  1450. };
  1451. return false;
  1452. };
  1453. /* - - - - - - - - - - - - - - - - - */
  1454. /* - - - - - - - - - - - - - - - - - */
  1455. function parse_command ($text2parse) {
  1456. global $area;
  1457. global $area_c;
  1458. global $area_a;
  1459. global $area;
  1460. global $curr_area;
  1461. global $curr_lang;
  1462. global $string;
  1463. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1464. do {
  1465. $PHP_SELF = $_SERVER['PHP_SELF'];
  1466. $has_command1 = stripos($text2parse, '$[');
  1467. if ($has_command1 !== false) {
  1468. $has_command2 = stripos($text2parse, ']$');
  1469. if ($has_command2 !== false) {
  1470. $token = substr($text2parse, $has_command1, $has_command2-$has_command1+2);
  1471. $what = substr($token,2,strlen($token)-4);
  1472. $prefix0 = explode(':', $what);
  1473. $what = $prefix0[count($prefix0)-1];
  1474. $prefix = $prefix0[0];
  1475. if ($prefix != $what) {
  1476. $prev_prefix = basename(dirname($PHP_SELF));
  1477. $PHP_SELF = str_ireplace($prev_prefix.SYS_PATH_SEP, $prefix.SYS_PATH_SEP, $PHP_SELF);
  1478. require_once(str_replace(SYS_PATH_SEP_DOUBLE,SYS_PATH_SEP,dirname(__FILE__).SYS_PATH_SEP).DCTL_DATA_PATH.$prefix.SYS_PATH_SEP.'config.inc.php');
  1479. switch ($prefix) {
  1480. case WEB_WCTL_NAME:
  1481. $key = array_multi_search ($what, $area_c);
  1482. break;
  1483. case WEB_DCTL_NAME:
  1484. $key = array_multi_search ($what, $area_a);
  1485. break;
  1486. };
  1487. } else {
  1488. $key = array_multi_search ($what, $area);
  1489. };
  1490. if (!(stripos($what, '.php')) === false) {
  1491. $replace = $what;
  1492. } else {
  1493. $replace = $PHP_SELF;
  1494. };
  1495. $replace .= "?lang=".$curr_lang."&amp;area=".$key;
  1496. if (XMLDB_PATH_BASE_TMP) {
  1497. $replace .= "&amp;temp=true";
  1498. };
  1499. $text2parse = str_replace($token, $replace, $text2parse);
  1500. };
  1501. };
  1502. } while ($has_command1 && $has_command2);
  1503. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1504. do {
  1505. $has_command1 = stripos($text2parse, '${');
  1506. if (!($has_command1 === false)) {
  1507. $has_command2 = stripos($text2parse, '}$');
  1508. if (!($has_command2 === false)) {
  1509. $token = substr($text2parse, $has_command1, $has_command2-$has_command1+2);
  1510. $what = substr($token,2,strlen($token)-4);
  1511. $replace = '';
  1512. switch ($what) {
  1513. case 'newsletter':
  1514. $email = '';
  1515. if (isSet($_REQUEST['email'])) {
  1516. $email = $_REQUEST['email'];
  1517. };
  1518. if (!(stripos($email, '@')) === false) {
  1519. require_once(str_replace('//','/',dirname(__FILE__).'/').'../_shared'.SYS_PATH_SEP.'config.inc.php');
  1520. require_once(str_replace(SYS_PATH_SEP_DOUBLE, SYS_PATH_SEP, dirname(__FILE__).SYS_PATH_SEP).'./config.inc.php');
  1521. $connection = dctl_sql_connect(WEB_NEWSLETTER);
  1522. if ($connection) {
  1523. $email = addslashes($email);
  1524. $email = trim($email);
  1525. $query = "SELECT * FROM news_address WHERE email = '$email'";
  1526. $result = mysql_query($query);
  1527. if (mysql_num_rows($result) != false) {
  1528. $replace .= "<br /><strong class=\"thankyou\">".$string[$curr_lang]['mail_yetrecorded']." (".$email.")...</strong>";
  1529. } else {
  1530. $query = "INSERT INTO news_address (id, email) VALUES (NULL, '$email')";
  1531. $result = mysql_query($query);
  1532. if (mysql_affected_rows() == 1) {
  1533. $replace .= "<br /><strong class=\"thankyou\">".$string[$curr_lang]['mail_ok']."...</strong>";
  1534. } else {
  1535. $replace .= "<br /><strong class=\"thankyou\">".$string[$curr_lang]['mail_not']." (".$email.")...</strong>";
  1536. };
  1537. };
  1538. mysql_close($connection);
  1539. } else {
  1540. $replace .= "<br /><strong class=\"thankyou\">".$string[$curr_lang]['mail_nosrv']."...</strong></em>";
  1541. };
  1542. } else {
  1543. $replace .= '<form id="newsletter" action="'.$_SERVER['PHP_SELF'].'" method="'.DCTL_FORM_METHOD.'" enctype="'.DCTL_FORM_ENCTYPE.'">';
  1544. $replace .= "<fieldset>";
  1545. $replace .= "<input class=\"small\" type=\"text\" size=\"20\" name=\"email\" value=\"(e-mail)\" />";
  1546. $replace .= "<label class=\"small\">";
  1547. $replace .= "<a class=\"small\" href=\"javascript:submitform('newsletter');\"> -&gt; ".$string[$curr_lang]['mail_sign']."</a>";
  1548. $replace .= "</label>";
  1549. $replace .= "<input type=\"hidden\" name=\"area\" value=\"".$curr_area."\" />";
  1550. $replace .= "<input type=\"hidden\" name=\"lang\" value=\"".$curr_lang."\" />";
  1551. $replace .= "</fieldset></form>";
  1552. };
  1553. break;
  1554. };
  1555. $text2parse = str_replace($token, $replace, $text2parse);
  1556. };
  1557. };
  1558. } while ($has_command1 && $has_command2);
  1559. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1560. return $text2parse;
  1561. };
  1562. /* - - - - - - - - - - - - - - - - - */
  1563. /* - - - - - - - - - - - - - - - - - */
  1564. function node_copy ($value, $strip) {
  1565. $strip_s = "<".$strip.">";
  1566. $strip_e1 = "<".$strip."/>";
  1567. $strip_e2 = "<".$strip." />";
  1568. $strip_e3 = "</".$strip.">";
  1569. $strip_e4 = "</ ".$strip.">";
  1570. $text = $value;
  1571. $text = str_ireplace($strip_s, "", $text);
  1572. $text = str_ireplace($strip_e1, "", $text);
  1573. $text = str_ireplace($strip_e2, "", $text);
  1574. $text = str_ireplace($strip_e3, "", $text);
  1575. $text = str_ireplace($strip_e4, "", $text);
  1576. return $text;
  1577. };
  1578. /* - - - - - - - - - - - - - - - - - */
  1579. /* - - - - - - - - - - - - - - - - - */
  1580. // Convert str to UTF-8 (if not already), then convert to HTML numbered decimal entities.
  1581. // If selected, it first converts any illegal chars to safe named (and numbered) entities
  1582. // as in makeSafeEntities(). Unlike mb_convert_encoding(), mb_encode_numericentity() will
  1583. // NOT skip any already existing entities in the string, so use a regex to skip them.
  1584. function makeAllEntities($str, $useNamedEntities = 0, $encoding = "") {
  1585. if (is_array($str)) {
  1586. foreach ($str as $s)
  1587. $arrOutput[] = makeAllEntities($s,$encoding);
  1588. return $arrOutput;
  1589. }
  1590. else if (strlen($str)>0) {
  1591. $str = makeUTF8($str,$encoding);
  1592. if ($useNamedEntities)
  1593. $str = mb_convert_encoding($str,"HTML-ENTITIES","UTF-8");
  1594. $str = makeTagEntities($str,$useNamedEntities);
  1595. // Fix backslashes so they don't screw up following mb_ereg_replace
  1596. // Single quotes are fixed by makeTagEntities() above
  1597. $str = mb_ereg_replace('\\\\',"&#92;", $str);
  1598. mb_regex_encoding("UTF-8");
  1599. $str = mb_ereg_replace("(?>(&(?:[a-z]{0,4}\w{2,3};|#\d{2,5};)))|(\S+?)",
  1600. "'\\1'.mb_encode_numericentity('\\2',array(0x0,0x2FFFF,0,0xFFFF),'UTF-8')", $str, "ime");
  1601. $str = correctIllegalEntities($str);
  1602. return $str;
  1603. }
  1604. }
  1605. /* - - - - - - - - - - - - - - - - - */
  1606. /* - - - - - - - - - - - - - - - - - */
  1607. // Convert common characters to named or numbered entities
  1608. function makeTagEntities($str, $useNamedEntities = 1) {
  1609. // Note that we should use &apos; for the single quote, but IE doesn't like it
  1610. $arrReplace = $useNamedEntities ? array('&#39;','&quot;','&lt;','&gt;') : array('&#39;','&#34;','&#60;','&#62;');
  1611. return str_replace(array("'",'"','<','>'), $arrReplace, $str);
  1612. }
  1613. /* - - - - - - - - - - - - - - - - - */
  1614. /* - - - - - - - - - - - - - - - - - */
  1615. function fixID ($n_string) {
  1616. $n_string = preg_replace('/[^a-zA-Z0-9_\-]/', '', $n_string);// remove all unwanted chars
  1617. return trim($n_string);
  1618. };
  1619. /* - - - - - - - - - - - - - - - - - */
  1620. /* - - - - - - - - - - - - - - - - - */
  1621. /**
  1622. * Perform a simple text replace
  1623. * This should be used when the string does not contain HTML
  1624. * (off by default)
  1625. */
  1626. define('STR_HIGHLIGHT_SIMPLE', 1);
  1627. /**
  1628. * Only match whole words in the string
  1629. * (off by default)
  1630. */
  1631. define('STR_HIGHLIGHT_WHOLEWD', 2);
  1632. /**
  1633. * Case sensitive matching
  1634. * (off by default)
  1635. */
  1636. define('STR_HIGHLIGHT_CASESENS', 4);
  1637. /**
  1638. * Overwrite links if matched
  1639. * This should be used when the replacement string is a link
  1640. * (off by default)
  1641. */
  1642. define('STR_HIGHLIGHT_STRIPLINKS', 8);
  1643. /**
  1644. * Highlight a string in text without corrupting HTML tags
  1645. *
  1646. * @author Aidan Lister <aidan@php.net>
  1647. * @version 3.1.1
  1648. * @link http://aidanlister.com/repos/v/function.str_highlight.php
  1649. * @param string $text Haystack - The text to search
  1650. * @param array|string $needle Needle - The string to highlight
  1651. * @param bool $options Bitwise set of options
  1652. * @param array $highlight Replacement string
  1653. * @return Text with needle highlighted
  1654. */
  1655. function str_highlight($text, $needle, $options = null, $highlight = null, $start = "<strong>", $end = "</strong>", &$refs) {
  1656. $text = preg_replace('/'.WS.''.WS.'+/', ' ', $text);
  1657. $refs = array();
  1658. // Default highlighting
  1659. if ($highlight === null) {
  1660. $highlight = $start.'\1'.$end;
  1661. }
  1662. // Select pattern to use
  1663. if ($options & STR_HIGHLIGHT_SIMPLE) {
  1664. $pattern = '#(%s)#';
  1665. $sl_pattern = '#(%s)#';
  1666. } else {
  1667. $pattern = '#(?!<.*?)(%s)(?![^<>]*?>)#';
  1668. $sl_pattern = '#<a'.WS.'(?:.*?)>(%s)</a>#';
  1669. }
  1670. // Case sensitivity
  1671. if (!($options & STR_HIGHLIGHT_CASESENS)) {
  1672. $pattern .= 'i';
  1673. $sl_pattern .= 'i';
  1674. }
  1675. $needle = $needle;
  1676. foreach ($needle as $needle_s) {
  1677. $needle_s = preg_quote($needle_s);
  1678. // Escape needle with optional whole word check
  1679. if ($options & STR_HIGHLIGHT_WHOLEWD) {
  1680. $needle_s = '\b' . $needle_s . '\b';
  1681. }
  1682. // Strip links
  1683. if ($options & STR_HIGHLIGHT_STRIPLINKS) {
  1684. $sl_regex = sprintf($sl_pattern, $needle_s);
  1685. $text = preg_replace($sl_regex, '\1', $text);
  1686. }
  1687. $regex = sprintf($pattern, $needle_s);
  1688. $highlight2 = $highlight;
  1689. $highlight2 = str_ireplace('_TITLE_', $needle_s, $highlight2);
  1690. $text = preg_replace($regex, $highlight2, $text);
  1691. while (stripos($text, '_ID_') !== FALSE) {
  1692. $thisID = 'H-'.md5(uniqid(rand(), true));
  1693. $text = preg_replace('/_ID_/', fixID($thisID), $text, 1);
  1694. $refs[$needle_s][] = $thisID;
  1695. };
  1696. }
  1697. return $text;
  1698. }
  1699. /* - - - - - - - - - - - - - - - - - */
  1700. /* - - - - - - - - - - - - - - - - - */
  1701. function replaceValueInURLajax ($theItem, $theNext, $theAnchor='') {
  1702. $URLs['doc'] = $_REQUEST['doc'];
  1703. $URLs[$theItem] = $theNext;
  1704. return http_build_query($URLs);
  1705. };
  1706. /* - - - - - - - - - - - - - - - - - */
  1707. /* - - - - - - - - - - - - - - - - - */
  1708. function replaceValueInURL ($theURL, $theItem, $theNext, $theAnchor='') {
  1709. if(true) {
  1710. return ($theURL);
  1711. } else {
  1712. if (DVLP_USE_PAGINATION) {
  1713. $params0 = explode('&',$theURL);
  1714. $params = preg_grep('/'.$theItem.'=(.*)/', $params0, PREG_GREP_INVERT);
  1715. $params[] = $theItem.'='.$theNext;
  1716. $params[] = 'posx='.$theAnchor;
  1717. $thisURL = implode('&',$params);
  1718. $load = array_values(preg_grep('/doc=(.*)/', $params));
  1719. $load2 = str_ireplace(XMLDB_PATH_BASE, '', $load[0]);
  1720. $load2 = str_ireplace('doc=','',$load2);
  1721. $collection_id = dirname($load2);
  1722. $package_id = str_ireplace('.xml', '', basename($load2));
  1723. $result = '';
  1724. $result .='javascript: indexAjax(\'load_package\', \''.DCTL_EXPLORER_1.'\', \''.$collection_id.'\', \''.$package_id.'\'';
  1725. $result .=', \'url='.$theNext.SYS_PATH_SEP.$theAnchor.'\'';
  1726. foreach ($params as $param) {
  1727. $result .= ', \''.$param.'\'';
  1728. };
  1729. $result .= ');';
  1730. return strval($result);
  1731. } else {
  1732. return '#'.$theNext;
  1733. };
  1734. };
  1735. };
  1736. /* - - - - - - - - - - - - - - - - - */
  1737. /* - - - - - - - - - - - - - - - - - */
  1738. function get_value_from_url($curr_what, $where) {
  1739. $result = false;
  1740. foreach($where as $key => $value) {
  1741. if(is_array($value)) {
  1742. $result = array_get_value($curr_what, $value);
  1743. } else {
  1744. if (!(stripos($value, $curr_what) === false)) {
  1745. $result = str_ireplace($curr_what.'=', '', $value);
  1746. };
  1747. };
  1748. };
  1749. if ($result) {
  1750. return (string) $result;
  1751. };
  1752. };
  1753. /* - - - - - - - - - - - - - - - - - */
  1754. /* - - - - - - - - - - - - - - - - - */
  1755. function multexplode($spacer,$string) {
  1756. if (strlen($spacer)<1) {
  1757. return($string);
  1758. } else {
  1759. $trenn=array_shift($spacer);
  1760. $string=explode($trenn,$string);
  1761. while (list($key,$val) = each($string)) {
  1762. $string[$key]=multexplode($spacer,$val);
  1763. };
  1764. return($string);
  1765. };
  1766. };
  1767. /* - - - - - - - - - - - - - - - - - */
  1768. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1769. function validate_xml($xml_path) {
  1770. $message = true;
  1771. if (is_file($xml_path)) {
  1772. libxml_use_internal_errors(true);
  1773. $dom = new DOMDocument('1.0', 'UTF-8');
  1774. $dom->resolveExternals = true;
  1775. $dom->substituteEntities = true;
  1776. $dom->validateOnParse = true;
  1777. $dom->load($xml_path);
  1778. $errors = libxml_get_errors();
  1779. if (strlen($errors)<1) {
  1780. return true;
  1781. } else {
  1782. $message = '';
  1783. foreach($errors as $error) {
  1784. $message .= $error->message.' at line '.$error->line.':<br />';
  1785. };
  1786. };
  1787. return $message;
  1788. };
  1789. return $message;
  1790. };
  1791. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1792. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1793. /* NO ?> IN FILE .INC */