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

/apps/commodoro/functions.inc.php

https://github.com/noveopiu/dCTL
PHP | 2834 lines | 2616 code | 45 blank | 173 comment | 521 complexity | 819d7e203f56a1582c538bd794c7fdca 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 dctl_segmentize($theString) {
  5. $resultText = '::';
  6. $theArray = explode(DISTINCT_SEP2, $theString);
  7. $hash = array();
  8. foreach($theArray as $idx=>$theLine) {
  9. $thisLine = $theArray{$idx};
  10. if ($thisLine != '') {
  11. $theValues = explode(DISTINCT_SEP, $thisLine);
  12. $theCantoLabel = $theValues[0];
  13. $theCanto = intval(substr($theValues[1], 1));
  14. $theOctave = intval($theValues[2]);
  15. $theSegmentStart = intval($theValues[3]);
  16. $theSegmentEnd = intval($theValues[4]);
  17. $theOctaveCount = intval($theValues[5]);
  18. if ((($theSegmentStart == 1) && ($theSegmentEnd == $theOctaveCount)) || ($theOctaveCount == 0) || ($theSegmentStart == 0) || ($theSegmentEnd == 0)) {
  19. $theVerse = '';
  20. } else {
  21. if ($theSegmentStart != $theSegmentEnd) {
  22. $theVerse = ', vv.'.$theSegmentStart.'-'.$theSegmentEnd;
  23. } else {
  24. $theVerse = ', v.'.$theSegmentStart;
  25. };
  26. };
  27. $hash[$idx]['c'] = $theCanto;
  28. $hash[$idx]['l'] = $theCantoLabel;
  29. $hash[$idx]['o'] = $theOctave;
  30. $hash[$idx]['v'] = $theVerse;
  31. };
  32. };
  33. $idx = count($hash)-1;
  34. while (isset($hash[$idx-1])) {
  35. if ($hash[$idx]['c'] != $hash[$idx-1]['c'])
  36. $resultText = '; '.$hash[$idx]['l'].$resultText;
  37. --$idx;
  38. };
  39. return $resultText;
  40. };
  41. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  42. function SimpleXMLElementObj_into_xml($xml_parent, $xml_children, $linkingNode= "linkingNode" , $child_count = 0 , $simplexml = false ){
  43. if(!$simplexml) {
  44. $simplexml = $xml_parent->addChild($linkingNode);
  45. }else{
  46. $simplexml = $xml_parent[$child_count];
  47. }
  48. $child_count = 0;
  49. foreach($xml_children->children() as $k => $v) {
  50. if($simplexml->$k){
  51. $child_count++;
  52. }
  53. if($v->children()) {
  54. $simplexml->addChild($k);
  55. SimpleXMLElementObj_into_xml($simplexml->$k, $v, '', $child_count, true);
  56. }else{
  57. $simplexml->addChild($k, $v);
  58. }
  59. }
  60. return $simplexml;
  61. };
  62. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  63. function simplexml_append(SimpleXMLElement $parent, SimpleXMLElement $new_child){
  64. $node1 = dom_import_simplexml($parent);
  65. $dom_sxe = dom_import_simplexml($new_child);
  66. $node2 = $node1->ownerDocument->importNode($dom_sxe, true);
  67. $node1->appendChild($node2);
  68. };
  69. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  70. function simplexml_insert(SimpleXMLElement $parent, SimpleXMLElement $new_child){
  71. $node1 = dom_import_simplexml($parent);
  72. $dom_sxe = dom_import_simplexml($new_child);
  73. $node2 = $node1->ownerDocument->importNode($dom_sxe, true);
  74. $node1->parentNode->insertBefore($node2, $node1);
  75. };
  76. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  77. function generateId($random_id_length = 10) {
  78. //generate a random id encrypt it and store it in $rnd_id
  79. $rnd_id = crypt(uniqid(rand(),1));
  80. //to remove any slashes that might have come
  81. $rnd_id = strip_tags(stripslashes($rnd_id));
  82. //Removing any . or / and reversing the string
  83. $rnd_id = str_replace(".","",$rnd_id);
  84. $rnd_id = strrev(str_replace("/","",$rnd_id));
  85. //finally I take the first $random_id_length characters from the $rnd_id
  86. return substr($rnd_id,0,$random_id_length);
  87. };
  88. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  89. function getNiceId ($id, $niceId) {
  90. if (! preg_match('/^p\d{3}/', $id)) {
  91. $id = $niceId.'_'.$id;
  92. };
  93. return $id;
  94. };
  95. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  96. function ajax_deleteLink($id1='', $id2='', $label='', $what='', $overwrite=TRUE) {
  97. $resultText = '';
  98. $resultOK = '';
  99. $resultKO = '';
  100. $collection_id = '';
  101. switch ($what) {
  102. case 'lnk':
  103. $collection_id = explode('-', $id1);
  104. break;
  105. case 'map':
  106. $collection_id = explode('/',str_ireplace('xml://','',$id2));
  107. break;
  108. };
  109. $collection_id = $collection_id [0];
  110. if ($collection_id != '') {
  111. $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
  112. switch ($what) {
  113. case 'lnk':
  114. $thePath .= DCTL_FILE_LINKER;
  115. break;
  116. case 'map':
  117. $thePath .= DCTL_FILE_MAPPER;
  118. break;
  119. default:
  120. $resultKO .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  121. break;
  122. };
  123. if (is_file($thePath)) {
  124. $file_content = file_get_contents($thePath);
  125. $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
  126. $text_head = substr($file_content,0,stripos($file_content,'%BEGIN%')).'%BEGIN% -->';
  127. $text_foot = '<!-- '.substr($file_content,stripos($file_content,'%END%'));
  128. $dom = new DOMDocument('1.0', 'UTF-8');
  129. $dom->preserveWhiteSpace = false;
  130. forceUTF8($thePath);
  131. if ($dom->load($thePath, DCTL_XML_LOADER)) {
  132. $xpath = new DOMXPath($dom);
  133. switch ($id2) {
  134. case '': // elimina un collegamento intero
  135. $query = 'id("'.$id1.'")';
  136. $entries = $xpath->query($query);
  137. foreach ($entries as $entry) {
  138. $entry->parentNode->removeChild($entry);
  139. };
  140. break;
  141. default: // elimina un id
  142. $query = 'id("'.$id1.'")';
  143. $entries = $xpath->query($query);
  144. foreach ($entries as $entry) {
  145. $target = $entry->getAttribute('target');
  146. $target = str_ireplace($id2,'',$target);
  147. if (substr_count($target,'://')<2) { // elimina un collegamento intero
  148. $entry->parentNode->removeChild($entry);
  149. } else {
  150. $entry->setAttribute('target', $target);
  151. };
  152. };
  153. break;
  154. };
  155. if ($resultKO == '') {
  156. $file_content = $dom->saveXML();
  157. $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
  158. $from = stripos($file_content,'%BEGIN%')+strlen('%BEGIN% -->');
  159. $to = stripos($file_content,'%END%')-strlen('<-- ') - $from -1;
  160. $text_content = substr($file_content,$from,$to);
  161. $file_content = $text_head.$text_content.$text_foot;
  162. if ($overwrite) {
  163. doBackup($thePath);
  164. if (file_put_contents($thePath, forceUTF8($file_content), LOCK_EX) === false) {
  165. $resultKO .= 'Impossibile scrivere il file "'.basename($thePath).'"';
  166. } else {
  167. @chmod($thePath, CHMOD);
  168. $resultOK .= 'Modifica eseguita con successo ("'.$label.'")';
  169. };
  170. } else {
  171. $resultOK .= 'Simulazione eseguita con successo ("'.$label.'")';
  172. };
  173. };
  174. } else {
  175. $resultKO .= 'Impossibile leggere il file "'.basename($thePath).'"';
  176. };
  177. } else {
  178. $resultKO .= 'Impossibile trovare "'.basename($thePath).'"';
  179. };
  180. } else {
  181. $resultKO .= 'Impossibile trovare la collection...';
  182. };
  183. if ($resultKO !='') {
  184. $resultText .= '<span class="error">'.cleanWebString($resultKO).'</span>';
  185. } else {
  186. $resultText .= '<span class="ok">'.cleanWebString($resultOK).'</span>';
  187. };
  188. return $resultText;
  189. };
  190. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  191. function ajax_saveLink($selector = 'new', $id1='', $id2='', $label='', $what='', $overwrite=TRUE) {
  192. $resultText = '';
  193. $resultOK = '';
  194. $resultKO = '';
  195. $collection_id = explode('/',str_ireplace('xml://','',$id1));
  196. $collection_id = $collection_id [0];
  197. if ($collection_id != '') {
  198. $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
  199. switch ($what ) {
  200. case 'lnk':
  201. $thePath .= DCTL_FILE_LINKER;
  202. break;
  203. case 'map':
  204. $thePath .= DCTL_FILE_MAPPER;
  205. break;
  206. default:
  207. $resultKO .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  208. break;
  209. };
  210. if (is_file($thePath)) {
  211. switch ($selector) {
  212. case 'new':
  213. case 'add':
  214. case 'mod':
  215. case 'ovw':
  216. $file_content = file_get_contents($thePath);
  217. $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
  218. $text_head = substr($file_content,0,stripos($file_content,'%BEGIN%')).'%BEGIN% -->';
  219. $text_foot = '<!-- '.substr($file_content,stripos($file_content,'%END%'));
  220. $dom = new DOMDocument('1.0', 'UTF-8');
  221. $dom->preserveWhiteSpace = false;
  222. forceUTF8($thePath);
  223. if ($dom->load($thePath, DCTL_XML_LOADER)) {
  224. $xpath = new DOMXPath($dom);
  225. switch ($selector) {
  226. case 'new':
  227. $type = 'link';
  228. $thisID = $collection_id.'-'.generateId();
  229. $head = $label;
  230. $query = 'id("placeholder")';
  231. $entries = $xpath->query($query);
  232. foreach ($entries as $entry) {
  233. $newNode = $dom->createElement('ref', $head);
  234. $newNode = $entry->parentNode->insertBefore($newNode,$entry);
  235. $newNode->setAttribute('xml:id',$thisID);
  236. $newNode->setAttribute('type',$type);
  237. $newNode->setAttribute('n',$label);
  238. $newNode->setAttribute('target',$id1.' '.$id2);
  239. $newNode = $dom->createComment(' ');
  240. $newNode = $entry->parentNode->insertBefore($newNode,$entry);
  241. };
  242. break;
  243. case 'add':
  244. $query = 'id("'.$id2.'")';
  245. $entries = $xpath->query($query);
  246. foreach ($entries as $entry) {
  247. $target = $entry->getAttribute('target');
  248. if (stripos($target, $id1)=== FALSE) {
  249. $entry->setAttribute('target', $id1.' '.$target);
  250. } else {
  251. $resultKO .= 'L\'ID "'.$id1.'" è gia nel collegamento';
  252. };
  253. };
  254. break;
  255. case 'mod':
  256. $query = 'id("'.$id2.'")';
  257. $entries = $xpath->query($query);
  258. foreach ($entries as $entry) {
  259. $entry->setAttribute('n', $label);
  260. if ((string)$entry->nodeValue =='') $entry->nodeValue = $label;
  261. };
  262. break;
  263. case 'ovw':
  264. $query = 'id("'.$id2.'")';
  265. $entries = $xpath->query($query);
  266. foreach ($entries as $entry) {
  267. $entry->setAttribute('n', $label);
  268. $entry->setAttribute('target',$id1);
  269. if ((string)$entry->nodeValue == '') $entry->nodeValue = $label;
  270. };
  271. break;
  272. };
  273. if ($resultKO == '') {
  274. $file_content = $dom->saveXML();
  275. $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
  276. $from = stripos($file_content,'%BEGIN%')+strlen('%BEGIN% -->');
  277. $to = stripos($file_content,'%END%')-strlen('<-- ') - $from -1;
  278. $text_content = substr($file_content,$from,$to);
  279. $file_content = $text_head.$text_content.$text_foot;
  280. if ($overwrite) {
  281. doBackup($thePath);
  282. if (file_put_contents($thePath, forceUTF8($file_content), LOCK_EX) === false) {
  283. $resultKO .= 'Impossibile scrivere il file "'.basename($thePath).'"';
  284. } else {
  285. @chmod($thePath, CHMOD);
  286. $resultOK .= 'Modifica eseguita con successo ("'.$label.'")';
  287. };
  288. } else {
  289. $resultOK .= 'Simulazione eseguita con successo ("'.$label.'")';
  290. };
  291. };
  292. } else {
  293. $resultKO .= 'Impossibile leggere il file "'.basename($thePath).'"';
  294. };
  295. break;
  296. default:
  297. $resultKO .= '?'.$selector.'?';
  298. break;
  299. };
  300. } else {
  301. $resultKO .= 'Impossibile trovare "'.basename($thePath).'"';
  302. };
  303. } else {
  304. $resultKO .= 'Impossibile trovare la collection...';
  305. };
  306. if ($resultKO !='') {
  307. $resultText .= '<span class="error">'.cleanWebString($resultKO).'</span>';
  308. } else {
  309. $resultText .= '<span class="ok">'.cleanWebString($resultOK).'</span>';
  310. };
  311. return $resultText;
  312. };
  313. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  314. function ajax_loadImageMap ($selector = 1, $id='', $uri='', $img='', $dim=array(), $coord=array(), $what='') {
  315. $resultText = '';
  316. if (is_array($coord)) {
  317. $resultText .= '$(\':input[name=xml_id2]\').addClass(\'active\').val(\''.$uri.'@'.implode(',', $coord).'\');';
  318. } else{
  319. $coord = array('0','0','0','0');
  320. $resultText .= '$(\':input[name=xml_id2]\').removeClass(\'active\').val(\'\');';
  321. };
  322. $resultText .= '$(\'img#img_edit\')';
  323. if ($id == '') {
  324. $resultText .= '.imgAreaSelect({disable:true, hide:true})';
  325. } else {
  326. $resultText .= '.attr(\'dbg\',\'1\')';
  327. $resultText .= '.unbind(\'load\')';
  328. $resultText .= '.load(function() {';
  329. $resultText .= 'if ($(\'img#img_edit\').attr(\'dbg\')) {';
  330. $resultText .= '$(\'img#img_edit\').removeAttr(\'dbg\');';
  331. $resultText .= 'var hRatio = $(\'img#img_edit\').width()/'.$dim[0].';';
  332. $resultText .= 'var vRatio = $(\'img#img_edit\').height()/'.$dim[1].';';
  333. $resultText .= '$(\'img#img_edit\').imgAreaSelect({enable:true, hide:true, x1:0, y1:0, x2:0, y2:0, outerOpacity: 0.17, imageWidth:'.$dim[0].', imageHeight:'.$dim[1].'});';
  334. $resultText .= '$(\'img#img_edit\').imgAreaSelect({x1:'.$coord[0].'*hRatio, y1:'.$coord[1].'*vRatio, x2:'.$coord[2].'*hRatio, y2:'.$coord[3].'*vRatio, onSelectEnd: function (img, selection) {
  335. $(\':input[name=xml_id2]\').val(\''.$uri.'@\'+selection.x1+\',\'+selection.y1+\',\'+selection.x2+\',\'+selection.y2).addClass(\'active\');
  336. }
  337. });';
  338. $resultText .= '};';
  339. $resultText .= '})';
  340. };
  341. $resultText .= '.attr(\'src\', \''.$img.'\')';
  342. return $resultText;
  343. };
  344. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  345. function ajax_loadImageList ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
  346. $resultText = '';
  347. switch ($what ) {
  348. case 'lnk':
  349. break;
  350. case 'map':
  351. $resultText .= '<script>';
  352. $resultText .= '$(\'img#img_edit\').attr(\'src\', \'\').imgAreaSelect({disable:true, hide:true});';
  353. $resultText .= '</script>';
  354. break;
  355. default:
  356. $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  357. break;
  358. };
  359. $resultText .= '<ul class="simpleTree">';
  360. $resultText .= '<li class="root">';
  361. $basePath = DCTL_PROJECT_PATH;
  362. $basePath .= $collection_id.SYS_PATH_SEP;
  363. getCollectionRecord($basePath, &$collectionRecord);
  364. $resultText .= '<span class="text">'.$collectionRecord['collection_full'].'</span>';
  365. $resultText .= '<ul>';
  366. $resultText .= '<li class="line"/>';
  367. $resultText .= '<li class="folder-open-last">';
  368. $basePath .= $package_id.SYS_PATH_SEP;
  369. getPackageRecord($basePath, &$packageRecord);
  370. $resultText .= '<span class="text">'.$packageRecord['package_full'].'</span>';
  371. $basePath .= SYS_PATH_SEP.$part_id;
  372. getPartRecord($basePath, &$partRecord);
  373. $resultText .= '<ul>';
  374. $resultText .= '<li class="line"/>';
  375. $resultText .= '<li class="folder-open-last">';
  376. $resultText .= '<span class="text">'.cleanWebString($partRecord['part_short'].': '.$partRecord['part_work'], FIELD_STRING_LENGTH).'</span>';
  377. $resultText .= '<ul>';
  378. $basePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$part_id;
  379. if(getImageList($basePath, &$imageList)>0) {
  380. foreach ($imageList['path'] as $key=>$fPath) {
  381. getImageRecord($fPath, &$imageRecord, $imageList['image_short'][$key]);
  382. $resultText .= '<li class="line"/>';
  383. $resultText .= '<li class="doc'.(($key+1)==count($imageList['path'])?'-last':'').'">';
  384. // carica IMG
  385. $img = ajax_loadImage($collection_id.SYS_PATH_SEP.DCTL_MEDIA_BIG.$imageRecord['image_id'], $dim, $what);
  386. if ($img) {
  387. $mapped = ajax_loadLinkList($selector, $collection_id, $package_id, $part_id, $item_id, $what);
  388. $mapped = preg_match('/(.*)\?(.*)\#(.*)\@(.*)/', $mapped, $matches);
  389. if ($mapped) {
  390. $uri = $matches[3];
  391. } else {
  392. $uri = 'img://'.$imageRecord['image_id'];
  393. };
  394. $coord = '';
  395. $mapped = $mapped && ($item_id != '');
  396. if ($mapped) {
  397. $mapped = (basename($img) == basename($uri));
  398. $coord = explode(',', $matches[4]);
  399. };
  400. if ($mapped) {
  401. $resultText .= '<span class="active">';
  402. $resultText .= cleanWebString($imageRecord['image_work'].': '.$imageRecord['image_short'], FIELD_STRING_LENGTH);
  403. } else {
  404. $resultText .= '<span class="text">';
  405. $resultText .= '<a href="javascript:void(0);" onclick="';
  406. $resultText .= '$(this).parents(\'ul\').find(\'.active\').removeClass(\'active\');';
  407. $resultText .= '$(this).parent().addClass(\'active\');';
  408. $resultText .= ajax_loadImageMap($selector, $item_id, $uri, $img, $dim, $coord, $what);
  409. $resultText .= ';" title="#">';
  410. $resultText .= cleanWebString($imageRecord['image_work'].': '.$imageRecord['image_short'], FIELD_STRING_LENGTH);
  411. $resultText .= '</a>';
  412. };
  413. } else {
  414. $resultText .= '<em>Not found: ';
  415. $resultText .= cleanWebString($imageRecord['image_work'].': '.$imageRecord['image_short'], FIELD_STRING_LENGTH);
  416. $resultText .= '</em>';
  417. };
  418. $resultText .= '</span>';
  419. $resultText .= '</li>';
  420. };
  421. $resultText .= '<script>';
  422. $resultText .= '$(\'#xml_tree2 .simpleTree\').find(\'.active\').parents(\'ul\').find(\'li span a\').each(function() {
  423. $(this).parent().replaceWith($(this).text());
  424. });';
  425. $resultText .= '</script>';
  426. } else {
  427. $resultText .= '<li class="doc-last"><i>nessuna figure</i></li>';
  428. };
  429. $resultText .= '</ul>';
  430. $resultText .= '</li>';
  431. $resultText .= '</ul>';
  432. $resultText .= '</li>';
  433. $resultText .= '</ul>';
  434. $resultText .= '</li>';
  435. $resultText .= '</ul>';
  436. return $resultText;
  437. };
  438. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  439. function ajax_loadLinkList ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what = '') {
  440. $fullItem = 'xml://'.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$item_id;
  441. $resultText = '';
  442. $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
  443. switch ($what) {
  444. case 'lnk':
  445. $thePath .= DCTL_FILE_LINKER;
  446. break;
  447. case 'map':
  448. $thePath .= DCTL_FILE_MAPPER;
  449. break;
  450. default:
  451. $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  452. break;
  453. };
  454. if (is_file($thePath)) {
  455. forceUTF8($thePath);
  456. $simplexml = simplexml_load_file($thePath, 'SimpleXMLElement', DCTL_XML_LOADER);
  457. $namespaces = $simplexml->getDocNamespaces();
  458. foreach ($namespaces as $nsk=>$ns) {
  459. if ($nsk == '') $nsk = 'tei';
  460. $simplexml->registerXPathNamespace($nsk, $ns);
  461. };
  462. $simplexml = simplexml_load_string(str_ireplace('xml:id','id',$simplexml->asXML()), 'SimpleXMLElement');
  463. // $s1=' '.$fullItem.' ';
  464. // $s2=$fullItem.' ';
  465. // $s3=' '.$fullItem;
  466. // $resultXML = $simplexml->xpath('//*[contains(@target,\''.$s1.'\') or contains(@target,\''.$s2.'\') or @target=\''.$fullItem.'\']');
  467. $fullItem = preg_replace('/(\.\d\d\d)/','.001',$fullItem);
  468. $resultXML = $simplexml->xpath('//*[contains(@target,\''.$fullItem.'\') and substring(substring-after(@target,\''.$fullItem.'\'),1,1) != "."]');
  469. if (count($resultXML)>0) {
  470. switch ($what) {
  471. case 'lnk': {
  472. $resultText .= '<ul class="simpleTree">';
  473. $resultText .= '<li class="root">Collegamenti';
  474. $resultText .= '<ul>';
  475. foreach($resultXML as $n=>$link) {
  476. $attrs = $link->attributes();
  477. $label = $attrs['n'];
  478. $resultText .= '<li>';
  479. $resultText .= '<span class="text" onclick="';
  480. // carica ID
  481. $resultText .= '$(\':input[name=xml_lnk'.$selector.']\').addClass(\'active\').attr({value:\''.$label.'\'});';
  482. $resultText .= '$(\':input[name=xml_lnk'.$selector.'id]\').addClass(\'active\').attr({value:\''.$attrs['id'].'\'});';
  483. $resultText .= '">';
  484. $resultText .= cleanWebString(stripslashes($attrs['n']), 40).'&#160;</span>';
  485. $resultText .= '&#160;&#160;<img src="'.DCTL_IMAGES.'edit.gif" alt="edit" onclick="editLink(this, \''.$fullItem.'\',\''.$attrs['id'].'\', \''.$label.'\', \''.$what.'\')" />';
  486. if ($selector==2) {
  487. $resultText .= '&#160;&#160;<img src="'.DCTL_IMAGES.'published_no.png" alt="delete" onclick="deleteLink(\''.$attrs['id'].'\',\'\',\''.$label.'\', \''.$what.'\')" />';
  488. };
  489. $resultText .= '<ul>';
  490. foreach(explode(' ',$link['target']) as $k=>$v) {
  491. if ($v!=''){
  492. $parsed = explode(SYS_PATH_SEP,$v);
  493. $lnk_coll =$parsed[2];
  494. switch (count($parsed)) {
  495. case 4: // xml://_coll_/_id_ => linker
  496. $lnk_pack = '';
  497. $lnk_part = '';
  498. $lnk_item = $parsed[3];
  499. break;
  500. case 5: // xml://_coll_/_pack_/_id_ => package
  501. $lnk_pack = $parsed[3];
  502. $lnk_part = array();
  503. if(preg_match('/\d\d\d/',$parsed[4],$lnk_part)) {
  504. $lnk_part = str_ireplace('$',$lnk_part[0],DCTL_PACKAGE_BODY);
  505. };
  506. $lnk_item = $parsed[4];
  507. break;
  508. };
  509. $resultText .= '<li>';
  510. $resultText .= '<span class="text">';
  511. $resultText .= '<a href="javascript:void(0);" onclick="';
  512. // carica XML
  513. $resultText .= '$(\'#xml_chunk\').load(\'indexAjax.php\', {action:\'ajax_loadChunk\', collection_id:\''.$lnk_coll.'\', package_id:\''.$lnk_pack.'\', part_id:\''.$lnk_part.'\', item_id:\''.$lnk_item.'\', what:\''.$what.'\'});';
  514. $resultText .= '" title="#">'.cleanWebString(str_ireplace('xml://'.$lnk_coll.SYS_PATH_SEP,'',$v)).'</a>';
  515. $resultText .= '</span>';
  516. if ($v == $fullItem) {
  517. if ($selector==1) {
  518. $fullItem2 = 'xml://'.$lnk_coll.SYS_PATH_SEP.$lnk_pack.SYS_PATH_SEP.$lnk_item;
  519. $resultText .= '&#160;&#160;<img src="'.DCTL_IMAGES.'published_no.png" alt="" onclick="deleteLink(\''.$attrs['id'].'\',\''.$fullItem2.'\',\''.$label.'\', \''.$what.'\')" />';
  520. };
  521. };
  522. $resultText .= '</li>';
  523. };
  524. };
  525. $resultText .= '</ul>';
  526. $resultText .= '</li>';
  527. };
  528. $resultText .= '</ul>';
  529. $resultText .= '</li>';
  530. $resultText .= '</ul>';
  531. };
  532. break;
  533. case 'map': {
  534. foreach($resultXML as $n=>$link) {
  535. $attrs = $link->attributes();
  536. foreach(explode(' ',$link['target']) as $k=>$v) {
  537. if ($v != '') {
  538. if ($v != $fullItem) {
  539. $resultText = $attrs['id'].'?'.$attrs['n'].'#'.$v; // id ? label # uri @ map
  540. };
  541. };
  542. };
  543. };
  544. };
  545. break;
  546. default:
  547. $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  548. break;
  549. };
  550. };
  551. };
  552. return $resultText;
  553. };
  554. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  555. function ajax_loadId ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
  556. $resultText = '';
  557. $resultText .= '<a href="javascript:void(0);" onclick="';
  558. $resultText .= '$(\'#xml_chunk\').load(\'indexAjax.php\', {action:\'ajax_loadChunk\', selector:\''.$selector.'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$part_id.'\', item_id:\''.$item_id.'\', what:\''.$what.'\'});';
  559. $resultText .= '" title="#">';
  560. $fullItem = 'xml://'.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$item_id;
  561. $resultText .= cleanWebString($fullItem);
  562. $resultText .= '</a>';
  563. return $resultText;
  564. };
  565. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  566. function ajax_loadChunk ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
  567. $resultText = '';
  568. $fullItem = $collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$part_id;
  569. $thePath = DCTL_PROJECT_PATH.$fullItem;
  570. // $resultText .= '<div class="lineH2">'.htmlentities($collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$part_id.SYS_PATH_SEP.$item_id,ENT_QUOTES,'UTF-8').'</div>';
  571. if (is_file($thePath)) {
  572. forceUTF8($thePath);
  573. $simplexml = simplexml_load_file($thePath, 'asPrettyXMLElement', DCTL_XML_LOADER);
  574. $namespaces = $simplexml->getDocNamespaces();
  575. foreach ($namespaces as $nsk=>$ns) {
  576. if ($nsk == '') $nsk = 'tei';
  577. $simplexml->registerXPathNamespace($nsk, $ns);
  578. };
  579. $resultXML = $simplexml->xpath('id("'.$item_id.'")');
  580. if (count($resultXML)>0) {
  581. $high = 'xml:id=&quot;'.$item_id.'&quot;';
  582. $xxml = htmlentities($resultXML[0]->asPrettyXML(1),ENT_QUOTES,'UTF-8');
  583. $resultText .= '<pre>'.str_ireplace($high,'<span class="highlight">'.$high.'</span>', $xxml).'</pre>';
  584. } else {
  585. $resultText .= '<span class="error">Non trovo ID '.$item_id.'...</span>';
  586. };
  587. } else {
  588. $resultText .= '<span class="error">Non trovo '.$fullItem.'...</span>';
  589. };
  590. return $resultText;
  591. };
  592. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  593. function ajax_loadImage ($fullItem='', &$dim=array(), $what='') {
  594. $resultText = '';
  595. $thePath = DCTL_PROJECT_PATH.$fullItem;
  596. if (is_file($thePath)) {
  597. $dim = getimagesize($thePath);
  598. $thePath = str_ireplace(DCTL_PROJECT_PATH, HOST_BASE_PATH.'data'.WEB_PATH_SEP.'dctl-project'.WEB_PATH_SEP, $thePath);
  599. $resultText .= $thePath;
  600. } else {
  601. $resultText .= '';
  602. };
  603. return $resultText;
  604. };
  605. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  606. function ajax_loadTree ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
  607. $resultText = '';
  608. if (DCTL_EXT_IMT) {
  609. } else {
  610. switch ($what ) {
  611. case 'lnk':
  612. break;
  613. case 'map':
  614. $resultText .= '<script>';
  615. $resultText .= '$(\'img#img_edit\').attr(\'src\', \'\').imgAreaSelect({disable:true, hide:true});';
  616. $resultText .= '$(\':input[name=xml_id1]\').removeClass(\'active\').val(\'\');';
  617. $resultText .= '$(\':input[name=xml_id2]\').removeClass(\'active\').val(\'\');';
  618. $resultText .= '$(\':input[name=xml_label]\').removeClass(\'active\').val(\'\');';
  619. $resultText .= '$(\':input[name=xml_lnk1id]\').removeClass(\'active\').val(\'\');';
  620. $resultText .= '$(\'#xml_tree2\').html(\'\');';
  621. $resultText .= '</script>';
  622. break;
  623. default:
  624. $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  625. break;
  626. };
  627. };
  628. // BEGIN
  629. $basePath = DCTL_PROJECT_PATH;
  630. $collectionPath = $basePath.$collection_id.SYS_PATH_SEP;
  631. if ($collection_id == '') {
  632. /*
  633. // ALL COLLECTIONS
  634. $resultText .= '<ul>';
  635. getCollectionList($basePath, &$collectionList);
  636. foreach ($collectionList['path'] as $key=>$fPath) {
  637. getCollectionRecord($fPath, &$collectionRecord);
  638. $resultText .= '<li>';
  639. $resultText .= '<span class="text">'.cleanWebString($collectionRecord['collection_short'].' - '.$collectionRecord['collection_work'], FIELD_STRING_LENGTH).'</span>';
  640. $resultText .= '<ul class="ajax">';
  641. $resultText .= '<li>{url:indexAjax.php?action=ajax_loadTree&amp;selector='.$selector.'&amp;collection_id='.$collectionRecord['collection_id'].'}</li>';
  642. $resultText .= '</ul>';
  643. $resultText .= '</li>';
  644. };
  645. $resultText .= '</ul>';
  646. */
  647. } else {
  648. if ($package_id=='') {
  649. $resultText .= '<ul class="simpleTree">';
  650. getCollectionRecord($collectionPath, &$collectionRecord);
  651. $resultText .= '<li class="root">';
  652. $resultText .= '<span class="text">'.$collectionRecord['collection_full'].'</span>';
  653. };
  654. $basePath = $collectionPath;
  655. $packagePath = $basePath.$package_id.SYS_PATH_SEP;
  656. // ONE COLLECTION
  657. if ($package_id == '') {
  658. // ALL PACKAGES
  659. $resultText .= '<ul>';
  660. getPackageList($basePath, &$packageList);
  661. foreach ($packageList['path'] as $key=>$fPath) {
  662. getPackageRecord($fPath, &$packageRecord);
  663. $resultText .= '<li>';
  664. $resultText .= '<span class="text">'.$packageRecord['package_full'].'</span>';
  665. $resultText .= '<ul class="ajax">';
  666. $resultText .= '<li>{url:indexAjax.php?action=ajax_loadTree&amp;selector='.$selector.'&amp;collection_id='.$collection_id.'&amp;package_id='.$packageRecord['package_id'].'&amp;what='.$what.'}</li>';
  667. $resultText .= '</ul>';
  668. $resultText .= '</li>';
  669. };
  670. $resultText .= '</ul>';
  671. } else {
  672. // ONE PACKAGE
  673. $basePath = $packagePath;
  674. $partPath = $basePath.$part_id.SYS_PATH_SEP;
  675. if ($part_id == '') {
  676. // ALL PARTS
  677. $resultText .= '<ul>';
  678. getPartList($basePath, &$partList);
  679. foreach ($partList['path'] as $key=>$fPath) {
  680. getPartRecord($fPath, &$partRecord);
  681. $resultText .= '<li>';
  682. if (DCTL_EXT_IMT && $what=='map') {
  683. $resultText .= '<span class="text"><a href="javascript:void(0);" onclick="';
  684. $resultText .= 'doProgress();$.post(\'indexAjax.php\',{action:\'ajax_loadTree\', selector:\''.$selector.'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$partRecord['part_id'].'\', what:\''.$what.'\'},';
  685. $resultText .= ' function('.DCTL_EXT_IMT_CBP.'){ commdodoro_initializeIMT('.DCTL_EXT_IMT_CBP.'); killProgress();});';
  686. $resultText .= '">'.cleanWebString($partRecord['part_short'].': '.$partRecord['part_work'], FIELD_STRING_LENGTH). '&#160;</a></span>';
  687. } else {
  688. $resultText .= '<span class="text" onclick="doProgress();$(this).next().load(\'indexAjax.php\',{action:\'ajax_loadTree\', selector:\''.$selector.'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$partRecord['part_id'].'\', what:\''.$what.'\'},function(){
  689. $(\'#xml_tree'.$selector.' .simpleTree\').get(0).setTreeNodes(this, false);
  690. killProgress();
  691. }).insertAfter(this);">'.cleanWebString($partRecord['part_short'].': '.$partRecord['part_work'], FIELD_STRING_LENGTH). '&#160;</span>';
  692. $resultText .= '<img src="'.DCTL_IMAGES.'refresh.gif" class="refresh" alt="(refresh)" onclick="doProgress();$(this).next().load(\'indexAjax.php\',{action:\'ajax_loadTree\', selector:\''.$selector.'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$partRecord['part_id'].'\', what:\''.$what.'\'},function(){
  693. $(\'#xml_tree'.$selector.' .simpleTree\').get(0).setTreeNodes(this, false);
  694. killProgress();
  695. }).insertAfter(this);" />';
  696. $resultText .= '<ul class="ajax">';
  697. $resultText .= '<li>{url:indexAjax.php?action=ajax_loadTree&amp;selector='.$selector.'&amp;collection_id='.$collection_id.'&amp;package_id='.$package_id.'&amp;part_id='.$partRecord['part_id'].'&amp;what='.$what.'}</li>';
  698. $resultText .= '</ul>';
  699. };
  700. $resultText .= '</li>';
  701. };
  702. $resultText .= '</ul>';
  703. } else {
  704. $basePath = $partPath;
  705. $itemPath = $basePath.$item_id.SYS_PATH_SEP;
  706. // ONE PART
  707. if ($item_id == '') {
  708. // ALL ITEMS
  709. if (DCTL_EXT_IMT && $what=='map') {
  710. $resultText .= '<?xml version="1.0" encoding="UTF-8"?>';
  711. $resultText .= '<dctl_ext_init>';
  712. $resultText .= '<xml>';
  713. if(getItemList($basePath, &$itemList, $what)>0) {
  714. $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP.DCTL_FILE_MAPPER;
  715. if (is_file($thePath)) {
  716. forceUTF8($thePath);
  717. $simplexml = simplexml_load_file($thePath, 'SimpleXMLElement', DCTL_XML_LOADER);
  718. $namespaces = $simplexml->getDocNamespaces();
  719. foreach ($namespaces as $nsk=>$ns) {
  720. if ($nsk == '') $nsk = 'tei';
  721. $simplexml->registerXPathNamespace($nsk, $ns);
  722. };
  723. $simplexml = simplexml_load_string(str_ireplace('xml:id','id',$simplexml->asXML()), 'SimpleXMLElement');
  724. foreach ($itemList['path'] as $key=>$fPath) {
  725. $uri = 'xml://'.$collection_id.'/'.$package_id.'/'.$itemList['item_id'][$key];
  726. $content = $itemList['item_short'][$key];
  727. $ref = '';
  728. $target = '';
  729. $label = '';
  730. $fullItem = $uri;
  731. $fullItem = preg_replace('/(\.\d\d\d)/','.001',$fullItem);
  732. $resultXML = $simplexml->xpath('//*[contains(@target,\''.$fullItem.'\') and substring(substring-after(@target,\''.$fullItem.'\'),1,1) != "."]');
  733. if (count($resultXML)>0) {
  734. foreach($resultXML as $n=>$link) {
  735. $attrs = $link->attributes();
  736. foreach(explode(' ',$link['target']) as $k=>$v) {
  737. if ($v != '') {
  738. if ($v != $fullItem) {
  739. $ref = $attrs['id'];
  740. $target = $v;
  741. $label = $attrs['n'];
  742. };
  743. };
  744. };
  745. };
  746. };
  747. $resultText .= '<a';
  748. $resultText .= ' r="'.$ref.'"';
  749. $resultText .= ' s="'.$uri.'"';
  750. $resultText .= ' t="'.$target.'"';
  751. $resultText .= ' l="'.$label.'"';
  752. $resultText .= ' c="'.$content.'"';
  753. $resultText .= ' />';
  754. };
  755. } else {
  756. dump('ERRORE');
  757. };
  758. };
  759. $resultText .= '</xml>';
  760. $resultText .= '<img>';
  761. if(getImageList($basePath, &$imageList)>0) {
  762. $key = 0;
  763. if (isset($imageList['path'][$key])) {
  764. $uri = 'img://'.$imageList['image_id'][$key];
  765. $url = DCTL_EXT_URL.'/indexAjax.php?&amp;action=get_file&amp;collection_id='.$collection_id.'&amp;url='.DCTL_MEDIA_MED.$imageList['image_id'][$key];
  766. $label = $imageList['image_short'][$key];
  767. $resultText .= '<a';
  768. $resultText .= ' s="'.$uri.'"';
  769. $resultText .= ' u="'.$url.'"';
  770. $resultText .= ' l="'.$label.'"';
  771. $resultText .= ' />';
  772. };
  773. };
  774. $resultText .= '</img>';
  775. $resultText .= '<cb';
  776. $resultText .= ' u="'.DCTL_EXT_IMT_CB.'"';
  777. $resultText .= ' p="'.DCTL_EXT_IMT_CBP.'"';
  778. $resultText .= ' />';
  779. $resultText .= '</dctl_ext_init>';
  780. $resultText = base64_encode($resultText); //base64_encode
  781. } else {
  782. $resultText .= '<script>';
  783. switch ($what) {
  784. case 'lnk':
  785. break;
  786. case 'map':
  787. $resultText .= '$(\'#xml_tree'.($selector+1).'\').load(\'indexAjax.php\', {action:\'ajax_loadImageList\', selector:\''.($selector+1).'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$part_id.'\', what:\''.$what.'\'});';
  788. break;
  789. default:
  790. $resultText .= 'alert(\'ERROR: CASE UNIMPLEMENTED IN ...'.__FUNCTION__.'\');';
  791. break;
  792. };
  793. $resultText .= '</script>';
  794. if(getItemList($basePath, &$itemList, $what)>0) {
  795. $resultText .= '<ul>';
  796. foreach ($itemList['path'] as $key=>$fPath) {
  797. getItemRecord($fPath, &$itemRecord, $itemList['item_short'][$key]);
  798. $resultText .= '<li>';
  799. $resultText .= '<span class="text">';
  800. if ($itemRecord['item_id'] != '') {
  801. $resultText .= '<a href="javascript:void(0);" onclick="';
  802. // carica XML
  803. $resultText .= '$(\'#xml_chunk\').load(\'indexAjax.php\', {action:\'ajax_loadChunk\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$part_id.'\', item_id:\''.$itemRecord['item_short'].'\', what:\''.$what.'\'});';
  804. // carica ID
  805. $resultText .= '$(\':input[name=xml_id'.$selector.']\').addClass(\'active\').attr({value:\''.'xml://'.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$itemRecord['item_short'].'\'});';
  806. switch ($what) {
  807. case 'lnk':
  808. // carica LINK
  809. $resultText .= '$(\'#xml_lnk'.$selector.'\').load(\'indexAjax.php\', {action:\'ajax_loadLinkList\', selector:\''.$selector.'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$part_id.'\', item_id:\''.$itemRecord['item_short'].'\', what:\''.$what.'\'}, function(){$(\'#xml_lnk'.$selector.' .simpleTree\').simpleTree({activeLeaf: false}); });';
  810. $resultText .= '" title="#">';
  811. $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
  812. break;
  813. case 'map':
  814. $mapped = ajax_loadLinkList($selector, $collection_id, $package_id, $part_id, $itemRecord['item_id'], $what);
  815. $mapped = preg_match('/(.*)\?(.*)\#(.*)\@(.*)/', $mapped, $matches);
  816. if ($mapped) {
  817. $ref = $matches[1];
  818. $label = $matches[2];
  819. } else {
  820. $ref = '';
  821. $label = $itemRecord['item_work'];
  822. };
  823. $resultText .= '$(\':input[name=xml_label]\').removeClass(\'active\').val(\''.str_ireplace('&apos;', "\\'", $label).'\');';
  824. $resultText .= '$(\':input[name=xml_id2]\').removeClass(\'active\').val(\'\');';
  825. $resultText .= '$(\':input[name=xml_lnk1id]\').addClass(\'active\').attr({value:\''.$ref.'\'});';
  826. $resultText .= '$(\'#xml_tree'.($selector+1).'\').load(\'indexAjax.php\', {action:\'ajax_loadImageList\', selector:\''.($selector+1).'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$part_id.'\', item_id:\''.$itemRecord['item_short'].'\', what:\''.$what.'\'}';
  827. if ($mapped) {
  828. $uri = $matches[3];
  829. $img = str_ireplace('img://', $collection_id.SYS_PATH_SEP.DCTL_MEDIA_BIG, $uri);
  830. $coord = explode(',', $matches[4]);
  831. $resultText .= ', function () {';
  832. $img = ajax_loadImage($img, $dim, $what);
  833. $resultText .= ajax_loadImageMap($selector, $itemRecord['item_id'], $uri, $img, $dim, $coord, $what);
  834. $resultText .= '}';
  835. };
  836. $resultText .= ');';
  837. $resultText .= '" title="#">';
  838. if ($mapped) {
  839. $resultText .= '<span class="dctl_ok">';
  840. $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
  841. $resultText .= '</span>';
  842. $resultText .= '&#160;&#160;<img src="'.DCTL_IMAGES.'published_no.png" alt="delete" onclick="deleteLink(\''.$matches[1].'\',\''.$matches[3].'@'.$matches[4].'\',\''.$matches[2].'\', \''.$what.'\')" />';
  843. } else {
  844. $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
  845. };
  846. break;
  847. default:
  848. $resultText .= 'alert(\'ERROR: CASE UNIMPLEMENTED IN ...'.__FUNCTION__.'\');';
  849. $resultText .= '" title="#">';
  850. $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
  851. break;
  852. };
  853. $resultText .= '</a>';
  854. } else {
  855. $resultText .= '<em class="dctl_ko">';
  856. $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
  857. $resultText .= '</em>';
  858. };
  859. $resultText .= '</span>';
  860. $resultText .= '</li>';
  861. };
  862. $resultText .= '</ul>';
  863. } else {
  864. $resultText .= '<li><i>nessun id</i></li>';
  865. };
  866. };
  867. } else {
  868. $resultText .= 'UNIMPLEMENTED';
  869. };
  870. };
  871. };
  872. if (DCTL_EXT_IMT && $what=='map') {
  873. // nothing
  874. } else {
  875. $resultText .= '</li>';
  876. $resultText .= '</ul>';
  877. };
  878. };
  879. return $resultText;
  880. };
  881. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  882. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  883. function isImage($mime,$ext) {
  884. if (
  885. ($mime=="image/gif")||
  886. ($mime=="image/jpeg")||
  887. ($mime=="image/jpg")||
  888. ($mime=="image/pjpeg")||
  889. ($mime=="image/png")||
  890. ($ext=="jpg")||
  891. ($ext=="jpeg")||
  892. ($ext=="png")||
  893. ($ext=="gif") ) {
  894. return true;
  895. } else {
  896. return false;
  897. };
  898. };
  899. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  900. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  901. function getMIME($file) {
  902. //If mime magic is installed
  903. if (function_exists("mime_content_type")) {
  904. $mime=mime_content_type($file);
  905. } else {
  906. $mime=image2MIME($file);
  907. if($mime==false) $mime="text/plain";
  908. }
  909. return strtolower($mime);
  910. };
  911. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  912. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  913. function image2MIME($file) {
  914. $fh=fopen($file,"r");
  915. if ($fh) {
  916. $start4=fread($fh,4);
  917. $start3=substr($start4,0,3);
  918. if ($start4=="\x89PNG") {
  919. return "image/png";
  920. } elseif ($start3=="GIF") {
  921. return "image/gif";
  922. } elseif ($start3=="\xFF\xD8\xFF") {
  923. return "image/jpeg";
  924. } elseif ($start4=="hsi1") {
  925. return "image/jpeg";
  926. } else {
  927. return false;
  928. }
  929. unset($start3);
  930. unset($start4);
  931. fclose($fh);
  932. } else {
  933. return false;
  934. }
  935. }
  936. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  937. function putEdit ($param = '') {
  938. $resultText = '';
  939. if (DCTL_USER_IS_EDITOR) {
  940. $resultText .= '<a onclick="javascript:doProgress();" class="edit" href="'.$_SERVER['PHP_SELF'].'?';
  941. foreach ($_REQUEST as $k=>$v) {
  942. if ($k == $param) $v = 'true';
  943. $resultText .= $k."=".$v."&amp;";
  944. };
  945. $param .= '=';
  946. if (stripos($param, $resultText) === false) $resultText .= $param.'true';
  947. $resultText .= '" title="modifica">';
  948. $resultText .= '&#160;<img src="'.DCTL_IMAGES.'application_form_edit.png" alt="(edit icon)" />';
  949. $resultText .= '&#160;Modifica dati</a>';
  950. };
  951. return $resultText;
  952. }
  953. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  954. function putOpenCloseLevel ($id, $loc4msg, $more=false, $label, &$resultMsg='') {
  955. $resultText = '';
  956. $isThis = ($loc4msg == $id) || $more;
  957. $resultText .= '<h3>';
  958. $resultText .= '<a class="toggler" onclick="toggleVisibility(this,\''.$id.'\');" title="'.TOOLTIP_TOGGLE.'">';
  959. $resultText .= '<img src="'.DCTL_IMAGES;
  960. if ($isThis) {
  961. $resultText .= 'collapse.gif';
  962. } else {
  963. $resultText .= 'expand.gif';
  964. };
  965. $resultText .= '" alt="(open/close level)" />&#160;';
  966. $resultText .= $label.'</a></h3>';
  967. $resultText .= '<div id="'.$id.'" class="';
  968. if ($isThis) {
  969. $resultText .= 'un';
  970. } else {
  971. $resultText .= '_hidden';
  972. };
  973. $resultText .= '">';
  974. if ($loc4msg == $id) {
  975. $resultText .= $resultMsg;
  976. }
  977. return $resultText;
  978. };
  979. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  980. function putOpenLevel ($id, $loc4msg, $more=false, $label, &$resultMsg='') {
  981. $resultText = '';
  982. $isThis = ($loc4msg == $id) || $more;
  983. $resultText .= '<h3>';
  984. $resultText .= '&#160;';
  985. $resultText .= $label.'</h3>';
  986. $resultText .= '<div id="'.$id.'" class="';
  987. $resultText .= '">';
  988. if ($loc4msg == $id) {
  989. $resultText .= $resultMsg;
  990. }
  991. return $resultText;
  992. };
  993. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  994. function getModel ($originalPath) {
  995. $sourcePath = $originalPath;
  996. $filePath = str_ireplace(DCTL_PROJECT_PATH, '', $sourcePath);
  997. $zip = new zipfile();
  998. $zipdir = SYS_PATH_SEP;
  999. $zip->add_dir($zipdir);
  1000. addToZip(DCTL_SETTINGS, $zip, $zipdir);
  1001. $zipdir = SYS_PATH_SEP;
  1002. $source = DCTL_PROJECT_PATH;
  1003. foreach(explode(SYS_PATH_SEP, $filePath) as $item) {
  1004. $source .= $item;
  1005. $zipdir .= $item;
  1006. if (is_dir($source)) {
  1007. $source .= SYS_PATH_SEP;
  1008. $zipdir .= SYS_PATH_SEP;
  1009. $zip->add_dir($zipdir);
  1010. $item = $source.DCTL_FILE_HEADER;
  1011. if (is_file($item)) {
  1012. addToZip($item, $zip, $zipdir);
  1013. };
  1014. // $item = $source.DCTL_MEDIA_SML;
  1015. // if (is_dir($item)) {
  1016. // addToZip($item, $zip, $zipdir);
  1017. // };
  1018. };
  1019. };
  1020. $zipdir = dirname($zipdir).SYS_PATH_SEP;
  1021. if (is_dir($source)) {
  1022. if ((stripos(DCTL_MEDIA_SML, $source) === FALSE) && (stripos(DCTL_MEDIA_MED, $source) === FALSE)) {
  1023. addToZip($source, $zip, $zipdir);
  1024. };
  1025. } else {
  1026. if (is_file($source)) {
  1027. $item = $source;
  1028. addToZip($item, $zip, $zipdir);
  1029. };
  1030. };
  1031. $filePath = dirname($originalPath).SYS_PATH_SEP.str_ireplace(SYS_PATH_SEP, '#', $filePath).'.zip';
  1032. $fd = fopen ($filePath, "wb");
  1033. $out = fwrite ($fd, $zip->file());
  1034. fclose ($fd);
  1035. @chmod($filePath, CHMOD);
  1036. return $filePath;
  1037. };
  1038. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1039. function getListNameForField ($theFields, $theSelected) {
  1040. global $COLLECTION_FIELDS;
  1041. global $PACKAGE_FIELDS;
  1042. $resultText = '';
  1043. switch ($theFields) {
  1044. case $COLLECTION_FIELDS:
  1045. switch ($theSelected) {
  1046. case 'collection_resp':
  1047. $resultText = DCTL_LIST_RESP;
  1048. break;
  1049. };
  1050. break;
  1051. case $PACKAGE_FIELDS:
  1052. switch ($theSelected) {
  1053. case 'package_encoder':
  1054. $resultText = DCTL_LIST_RESP;
  1055. break;
  1056. case 'source_lang':
  1057. $resultText = DCTL_LIST_LANG;
  1058. break;
  1059. case 'source_genre':
  1060. $resultText = DCTL_LIST_GENRE;
  1061. break;
  1062. case 'reference_lang':
  1063. $resultText = DCTL_LIST_LANG;
  1064. break;
  1065. case 'reference_genre':
  1066. $resultText = DCTL_LIST_GENRE;
  1067. break;
  1068. };
  1069. break;
  1070. };
  1071. return $resultText ;
  1072. };
  1073. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1074. function getTextClassList ($theList='', $theObject='') {
  1075. $resultText = '';
  1076. if ($theList != '') {
  1077. if ($theObject != '') {
  1078. $simplexml = '';
  1079. if (is_file(DCTL_SETTINGS_TEXTCLASS)) {
  1080. $resultText .= '<br />Aggiungi:<select onchange="javascript:addContent(\''.$theObject.'\', this.value);">';
  1081. $resultText .= '<option value="" selected="selected" />';
  1082. forceUTF8(DCTL_SETTINGS_TEXTCLASS);
  1083. $simplexml = simplexml_load_file(DCTL_SETTINGS_TEXTCLASS, 'SimpleXMLElement', DCTL_XML_LOADER);
  1084. $simplexml = $simplexml->asXML();
  1085. $simplexml = str_ireplace('xml:', '', $simplexml);
  1086. $simplexml = simplexml_load_string($simplexml, 'SimpleXMLElement', DCTL_XML_LOADER);
  1087. $resultXML = $simplexml->xpath('//classCode[@scheme="'.$theList.'"]/term');
  1088. foreach ($resultXML as $k=>$v) {
  1089. $id = strval($v['id']);
  1090. $name = strval($v->eg);
  1091. $resultText .= '<option value="'.$id.'">'.$name.SYS_DBL_SPACE.'</option>';
  1092. };
  1093. $resultText .= '</select>';
  1094. };
  1095. };
  1096. };
  1097. return $resultText ;
  1098. };
  1099. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1100. function getManagementOfImages ($fDivX, $labelX, $collection_id, $itemName, $loc4msg, &$fCount, $resultMsg) {
  1101. global $EXTENSION_ALLOWED;
  1102. global $EXTENSION_TEXT;
  1103. global $EXTENSION_GRAPHIC;
  1104. $resultText = '';
  1105. $array_estensioni_ammesse = $EXTENSION_ALLOWED;
  1106. $basename = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
  1107. $regexp = '[';
  1108. foreach($array_estensioni_ammesse as $k=>$v) {
  1109. if ($k >0) $regexp .= ' | ';
  1110. $regexp .= $v;
  1111. };
  1112. $regexp .= ']';
  1113. $dPath = $basename.DCTL_MEDIA_SML;
  1114. if (!is_dir($dPath)) mkdir($dPath, CHMOD);
  1115. @chmod($dPath, CHMOD);
  1116. $dPath = $basename.DCTL_MEDIA_MED;
  1117. if (!is_dir($dPath)) mkdir($dPath, CHMOD);
  1118. @chmod($dPath, CHMOD);
  1119. $dPath = $basename.DCTL_MEDIA_BIG;
  1120. if (!is_dir($dPath)) mkdir($dPath, CHMOD);
  1121. @chmod($dPath, CHMOD);
  1122. $dPath = $basename.DCTL_MEDIA_BIG;
  1123. $variants = array();
  1124. $handle = opendir($dPath);
  1125. while ($entry = readdir($handle)) {
  1126. if (substr($entry, 0, 1) != '.') {
  1127. $variants[] = $entry;
  1128. };
  1129. };
  1130. $variants = array_values(preg_grep('/.*'.$regexp.'/', $variants));
  1131. $idx = count($variants);
  1132. sort($variants);
  1133. $fDiv0 = str_ireplace('$', '', $fDivX);
  1134. $label0 = str_ireplace('$', '', $labelX);
  1135. //putOpenCloseLevel
  1136. $resultText .= putOpenLevel($fDiv0, $loc4msg, false, 'Gestione '.$label0.' di "'.$itemName.'" ('.$idx.')', &$resultMsg);
  1137. $resultText .= '<table>';
  1138. $resultText .= '<thead>';
  1139. $resultText .= '<tr>';
  1140. $resultText .= '<th class="label">operazione</th>';
  1141. $resultText .= '<th>azione</th>';
  1142. $resultText .= '<th>risultato</th>';
  1143. $resultText .= '</tr>';
  1144. $resultText .= '</thead>';
  1145. $resultText .= '<tbody>';
  1146. /* CARICA UNA IMMAGINE */
  1147. $dPath = $basename.DCTL_MEDIA_BIG;
  1148. $resultText .= '<tr>';
  1149. $resultText .= '<td>Carica un nuovo file ...</td>';
  1150. $resultText .= '<td>';
  1151. $resultText .= '<form id="form'.$fDiv0.'" action="'.$_SERVER['SCRIPT_NAME'].'" method="'.DCTL_FORM_METHOD_POST.'" enctype="'.DCTL_FORM_ENCTYPE_POST.'">';
  1152. $resultText .= '<fieldset>';
  1153. $resultText .= '<input type="file" id="multi_file_upload" name="FILE'.$fCount.'" size="50" />';
  1154. $resultText .= '<input type="hidden" name="PATH" value="'.$dPath.'" />';
  1155. $resultText .= '<input type="hidden" name="posx" value="'.$fDiv0.'" />';
  1156. $resultText .= '<input type="hidden" name="ext" value="img" />';
  1157. $resultText .= SYS_DBL_SPACE.SYS_DBL_SPACE.'<input type="submit" name="upload" value="invia" />';
  1158. $resultText .= '<br /><strong>File da caricare</strong> (max 10): <div id="files_list"></div>
  1159. <script>
  1160. var multi_selector = new MultiSelector(document.getElementById("files_list"), 10);
  1161. multi_selector.addElement(document.getElementById("multi_file_upload") );
  1162. </script>
  1163. ';
  1164. $resultText .= '<input type="hidden" name="collection_id" value="'.$collection_id.'" />';
  1165. $resultText .= '</fieldset>';
  1166. $resultText .= '</form>';
  1167. $resultText .= '</td>';
  1168. $resultText .= '<td>&#160;</td>';
  1169. $resultText .= '</tr>';
  1170. /* VISUALIZZA LE ANTEPRIME */
  1171. $dPath = $basename.DCTL_MEDIA_BIG;
  1172. $resultText .= '<tr>';
  1173. $resultText .= '<td>Visualizza l\'anteprima di un file...<br /><br />';
  1174. $resultText .= '<form action="">';
  1175. $resultText .= '<fieldset>';
  1176. $resultText .= '<input type="text" id="mediaFilter" value="-trova-" onkeyup="var vFilter=this.value;
  1177. $(\'#mediaList li\').removeClass(\'found\');
  1178. var index = $(\'#mediaList li\').index($(\'#mediaList a\').filter(function(node){return ((this.text.toLowerCase().indexOf(vFilter)>=0)&&(vFilter!=\'\'))}).parent().addClass(\'found\'));
  1179. " />';
  1180. $resultText .= '</fieldset>';
  1181. $resultText .= '</form>';
  1182. $resultText .= '</td>';
  1183. $resultText .= '<td colspan="2">';
  1184. if (is_dir($dPath)) {
  1185. $resultText .= '<ul id="mediaList" class="trueContainer';
  1186. if (true) $resultText .= '2';
  1187. $resultText .= '">';
  1188. // $resultText .= '<script type="text/javascript" src="../js/imager.js"></script>';
  1189. // $resultText .= '<div id="motioncontainer" style="position:relative;overflow:hidden;">';
  1190. // $resultText .= '<div id="motiongallery" style="position:absolute;left:0;top:0;white-space: nowrap;">';
  1191. // $resultText .= '<span id="trueContainer">';
  1192. $tail = '';
  1193. $dPath2 = $dPath; //$dPath2 = str_ireplace(DCTL_MEDIA_SML, DCTL_MEDIA_BIG, $dPath);
  1194. $files = scandir($dPath2);
  1195. $filePattern = '/-('.WS.'*)(.*)('.WS.'*)=('.WS.'*)$('.WS.'*)-/';
  1196. if ($dPath != '') {
  1197. $entries = array();
  1198. $handle = opendir($dPath);
  1199. while ($entry = readdir($handle)) {
  1200. if (substr($entry, 0, 1) != '.') {
  1201. $entries[] = $entry;
  1202. };
  1203. };
  1204. sort($entries);
  1205. foreach($entries as $entry) {
  1206. $ext = strtolower(substr($entry, -3, 3));
  1207. if (in_array($ext, $array_estensioni_ammesse)) {
  1208. $labelval = str_ireplace('$', $entry, $filePattern);
  1209. $labelx = array_values(preg_grep($labelval, $files));
  1210. if (count($labelx)>0) {
  1211. $label = $labelx[0];
  1212. $labelx = preg_split('/('.WS.'*)=('.WS.'*)/', $label, -1);
  1213. $label = str_ireplace('-', '', $labelx[0]);
  1214. } else {
  1215. $label = $entry;
  1216. };
  1217. if ($label != $entry) {
  1218. if (substr($label, 0, strlen($collection_id)) != $collection_id) {
  1219. $label = $collection_id.'-'.$label;
  1220. };
  1221. rename($dPath.$entry, $dPath.$label);

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