PageRenderTime 57ms CodeModel.GetById 22ms 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

Large files files are truncated, but you can click here to view the full file

  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, $c

Large files files are truncated, but you can click here to view the full file