/apps/commodoro/functions.inc.php
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
- <?php
- if (!defined('_INCLUDE')) die('"'.__FILE__.'" not executable... me, i abort.');
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function dctl_segmentize($theString) {
- $resultText = '::';
- $theArray = explode(DISTINCT_SEP2, $theString);
- $hash = array();
- foreach($theArray as $idx=>$theLine) {
- $thisLine = $theArray{$idx};
- if ($thisLine != '') {
- $theValues = explode(DISTINCT_SEP, $thisLine);
- $theCantoLabel = $theValues[0];
- $theCanto = intval(substr($theValues[1], 1));
- $theOctave = intval($theValues[2]);
- $theSegmentStart = intval($theValues[3]);
- $theSegmentEnd = intval($theValues[4]);
- $theOctaveCount = intval($theValues[5]);
- if ((($theSegmentStart == 1) && ($theSegmentEnd == $theOctaveCount)) || ($theOctaveCount == 0) || ($theSegmentStart == 0) || ($theSegmentEnd == 0)) {
- $theVerse = '';
- } else {
- if ($theSegmentStart != $theSegmentEnd) {
- $theVerse = ', vv.'.$theSegmentStart.'-'.$theSegmentEnd;
- } else {
- $theVerse = ', v.'.$theSegmentStart;
- };
- };
- $hash[$idx]['c'] = $theCanto;
- $hash[$idx]['l'] = $theCantoLabel;
- $hash[$idx]['o'] = $theOctave;
- $hash[$idx]['v'] = $theVerse;
- };
- };
- $idx = count($hash)-1;
- while (isset($hash[$idx-1])) {
- if ($hash[$idx]['c'] != $hash[$idx-1]['c'])
- $resultText = '; '.$hash[$idx]['l'].$resultText;
- --$idx;
- };
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function SimpleXMLElementObj_into_xml($xml_parent, $xml_children, $linkingNode= "linkingNode" , $child_count = 0 , $simplexml = false ){
- if(!$simplexml) {
- $simplexml = $xml_parent->addChild($linkingNode);
- }else{
- $simplexml = $xml_parent[$child_count];
- }
- $child_count = 0;
- foreach($xml_children->children() as $k => $v) {
- if($simplexml->$k){
- $child_count++;
- }
- if($v->children()) {
- $simplexml->addChild($k);
- SimpleXMLElementObj_into_xml($simplexml->$k, $v, '', $child_count, true);
- }else{
- $simplexml->addChild($k, $v);
- }
- }
- return $simplexml;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function simplexml_append(SimpleXMLElement $parent, SimpleXMLElement $new_child){
- $node1 = dom_import_simplexml($parent);
- $dom_sxe = dom_import_simplexml($new_child);
- $node2 = $node1->ownerDocument->importNode($dom_sxe, true);
- $node1->appendChild($node2);
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function simplexml_insert(SimpleXMLElement $parent, SimpleXMLElement $new_child){
- $node1 = dom_import_simplexml($parent);
- $dom_sxe = dom_import_simplexml($new_child);
- $node2 = $node1->ownerDocument->importNode($dom_sxe, true);
- $node1->parentNode->insertBefore($node2, $node1);
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function generateId($random_id_length = 10) {
- //generate a random id encrypt it and store it in $rnd_id
- $rnd_id = crypt(uniqid(rand(),1));
- //to remove any slashes that might have come
- $rnd_id = strip_tags(stripslashes($rnd_id));
- //Removing any . or / and reversing the string
- $rnd_id = str_replace(".","",$rnd_id);
- $rnd_id = strrev(str_replace("/","",$rnd_id));
- //finally I take the first $random_id_length characters from the $rnd_id
- return substr($rnd_id,0,$random_id_length);
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function getNiceId ($id, $niceId) {
- if (! preg_match('/^p\d{3}/', $id)) {
- $id = $niceId.'_'.$id;
- };
- return $id;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function ajax_deleteLink($id1='', $id2='', $label='', $what='', $overwrite=TRUE) {
- $resultText = '';
- $resultOK = '';
- $resultKO = '';
- $collection_id = '';
- switch ($what) {
- case 'lnk':
- $collection_id = explode('-', $id1);
- break;
- case 'map':
- $collection_id = explode('/',str_ireplace('xml://','',$id2));
- break;
- };
- $collection_id = $collection_id [0];
- if ($collection_id != '') {
- $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
- switch ($what) {
- case 'lnk':
- $thePath .= DCTL_FILE_LINKER;
- break;
- case 'map':
- $thePath .= DCTL_FILE_MAPPER;
- break;
- default:
- $resultKO .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
- break;
- };
- if (is_file($thePath)) {
- $file_content = file_get_contents($thePath);
- $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
- $text_head = substr($file_content,0,stripos($file_content,'%BEGIN%')).'%BEGIN% -->';
- $text_foot = '<!-- '.substr($file_content,stripos($file_content,'%END%'));
- $dom = new DOMDocument('1.0', 'UTF-8');
- $dom->preserveWhiteSpace = false;
- forceUTF8($thePath);
- if ($dom->load($thePath, DCTL_XML_LOADER)) {
- $xpath = new DOMXPath($dom);
- switch ($id2) {
- case '': // elimina un collegamento intero
- $query = 'id("'.$id1.'")';
- $entries = $xpath->query($query);
- foreach ($entries as $entry) {
- $entry->parentNode->removeChild($entry);
- };
- break;
- default: // elimina un id
- $query = 'id("'.$id1.'")';
- $entries = $xpath->query($query);
- foreach ($entries as $entry) {
- $target = $entry->getAttribute('target');
- $target = str_ireplace($id2,'',$target);
- if (substr_count($target,'://')<2) { // elimina un collegamento intero
- $entry->parentNode->removeChild($entry);
- } else {
- $entry->setAttribute('target', $target);
- };
- };
- break;
- };
- if ($resultKO == '') {
- $file_content = $dom->saveXML();
- $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
- $from = stripos($file_content,'%BEGIN%')+strlen('%BEGIN% -->');
- $to = stripos($file_content,'%END%')-strlen('<-- ') - $from -1;
- $text_content = substr($file_content,$from,$to);
- $file_content = $text_head.$text_content.$text_foot;
- if ($overwrite) {
- doBackup($thePath);
- if (file_put_contents($thePath, forceUTF8($file_content), LOCK_EX) === false) {
- $resultKO .= 'Impossibile scrivere il file "'.basename($thePath).'"';
- } else {
- @chmod($thePath, CHMOD);
- $resultOK .= 'Modifica eseguita con successo ("'.$label.'")';
- };
- } else {
- $resultOK .= 'Simulazione eseguita con successo ("'.$label.'")';
- };
- };
- } else {
- $resultKO .= 'Impossibile leggere il file "'.basename($thePath).'"';
- };
- } else {
- $resultKO .= 'Impossibile trovare "'.basename($thePath).'"';
- };
- } else {
- $resultKO .= 'Impossibile trovare la collection...';
- };
- if ($resultKO !='') {
- $resultText .= '<span class="error">'.cleanWebString($resultKO).'</span>';
- } else {
- $resultText .= '<span class="ok">'.cleanWebString($resultOK).'</span>';
- };
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function ajax_saveLink($selector = 'new', $id1='', $id2='', $label='', $what='', $overwrite=TRUE) {
- $resultText = '';
- $resultOK = '';
- $resultKO = '';
- $collection_id = explode('/',str_ireplace('xml://','',$id1));
- $collection_id = $collection_id [0];
- if ($collection_id != '') {
- $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
- switch ($what ) {
- case 'lnk':
- $thePath .= DCTL_FILE_LINKER;
- break;
- case 'map':
- $thePath .= DCTL_FILE_MAPPER;
- break;
- default:
- $resultKO .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
- break;
- };
- if (is_file($thePath)) {
- switch ($selector) {
- case 'new':
- case 'add':
- case 'mod':
- case 'ovw':
- $file_content = file_get_contents($thePath);
- $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
- $text_head = substr($file_content,0,stripos($file_content,'%BEGIN%')).'%BEGIN% -->';
- $text_foot = '<!-- '.substr($file_content,stripos($file_content,'%END%'));
- $dom = new DOMDocument('1.0', 'UTF-8');
- $dom->preserveWhiteSpace = false;
- forceUTF8($thePath);
- if ($dom->load($thePath, DCTL_XML_LOADER)) {
- $xpath = new DOMXPath($dom);
- switch ($selector) {
- case 'new':
- $type = 'link';
- $thisID = $collection_id.'-'.generateId();
- $head = $label;
- $query = 'id("placeholder")';
- $entries = $xpath->query($query);
- foreach ($entries as $entry) {
- $newNode = $dom->createElement('ref', $head);
- $newNode = $entry->parentNode->insertBefore($newNode,$entry);
- $newNode->setAttribute('xml:id',$thisID);
- $newNode->setAttribute('type',$type);
- $newNode->setAttribute('n',$label);
- $newNode->setAttribute('target',$id1.' '.$id2);
- $newNode = $dom->createComment(' ');
- $newNode = $entry->parentNode->insertBefore($newNode,$entry);
- };
- break;
- case 'add':
- $query = 'id("'.$id2.'")';
- $entries = $xpath->query($query);
- foreach ($entries as $entry) {
- $target = $entry->getAttribute('target');
- if (stripos($target, $id1)=== FALSE) {
- $entry->setAttribute('target', $id1.' '.$target);
- } else {
- $resultKO .= 'L\'ID "'.$id1.'" è gia nel collegamento';
- };
- };
- break;
- case 'mod':
- $query = 'id("'.$id2.'")';
- $entries = $xpath->query($query);
- foreach ($entries as $entry) {
- $entry->setAttribute('n', $label);
- if ((string)$entry->nodeValue =='') $entry->nodeValue = $label;
- };
- break;
- case 'ovw':
- $query = 'id("'.$id2.'")';
- $entries = $xpath->query($query);
- foreach ($entries as $entry) {
- $entry->setAttribute('n', $label);
- $entry->setAttribute('target',$id1);
- if ((string)$entry->nodeValue == '') $entry->nodeValue = $label;
- };
- break;
- };
- if ($resultKO == '') {
- $file_content = $dom->saveXML();
- $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
- $from = stripos($file_content,'%BEGIN%')+strlen('%BEGIN% -->');
- $to = stripos($file_content,'%END%')-strlen('<-- ') - $from -1;
- $text_content = substr($file_content,$from,$to);
- $file_content = $text_head.$text_content.$text_foot;
- if ($overwrite) {
- doBackup($thePath);
- if (file_put_contents($thePath, forceUTF8($file_content), LOCK_EX) === false) {
- $resultKO .= 'Impossibile scrivere il file "'.basename($thePath).'"';
- } else {
- @chmod($thePath, CHMOD);
- $resultOK .= 'Modifica eseguita con successo ("'.$label.'")';
- };
- } else {
- $resultOK .= 'Simulazione eseguita con successo ("'.$label.'")';
- };
- };
- } else {
- $resultKO .= 'Impossibile leggere il file "'.basename($thePath).'"';
- };
- break;
- default:
- $resultKO .= '?'.$selector.'?';
- break;
- };
- } else {
- $resultKO .= 'Impossibile trovare "'.basename($thePath).'"';
- };
- } else {
- $resultKO .= 'Impossibile trovare la collection...';
- };
- if ($resultKO !='') {
- $resultText .= '<span class="error">'.cleanWebString($resultKO).'</span>';
- } else {
- $resultText .= '<span class="ok">'.cleanWebString($resultOK).'</span>';
- };
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function ajax_loadImageMap ($selector = 1, $id='', $uri='', $img='', $dim=array(), $coord=array(), $what='') {
- $resultText = '';
- if (is_array($coord)) {
- $resultText .= '$(\':input[name=xml_id2]\').addClass(\'active\').val(\''.$uri.'@'.implode(',', $coord).'\');';
- } else{
- $coord = array('0','0','0','0');
- $resultText .= '$(\':input[name=xml_id2]\').removeClass(\'active\').val(\'\');';
- };
- $resultText .= '$(\'img#img_edit\')';
- if ($id == '') {
- $resultText .= '.imgAreaSelect({disable:true, hide:true})';
- } else {
- $resultText .= '.attr(\'dbg\',\'1\')';
- $resultText .= '.unbind(\'load\')';
- $resultText .= '.load(function() {';
- $resultText .= 'if ($(\'img#img_edit\').attr(\'dbg\')) {';
- $resultText .= '$(\'img#img_edit\').removeAttr(\'dbg\');';
- $resultText .= 'var hRatio = $(\'img#img_edit\').width()/'.$dim[0].';';
- $resultText .= 'var vRatio = $(\'img#img_edit\').height()/'.$dim[1].';';
- $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].'});';
- $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) {
- $(\':input[name=xml_id2]\').val(\''.$uri.'@\'+selection.x1+\',\'+selection.y1+\',\'+selection.x2+\',\'+selection.y2).addClass(\'active\');
- }
- });';
- $resultText .= '};';
- $resultText .= '})';
- };
- $resultText .= '.attr(\'src\', \''.$img.'\')';
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function ajax_loadImageList ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
- $resultText = '';
- switch ($what ) {
- case 'lnk':
- break;
- case 'map':
- $resultText .= '<script>';
- $resultText .= '$(\'img#img_edit\').attr(\'src\', \'\').imgAreaSelect({disable:true, hide:true});';
- $resultText .= '</script>';
- break;
- default:
- $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
- break;
- };
- $resultText .= '<ul class="simpleTree">';
- $resultText .= '<li class="root">';
- $basePath = DCTL_PROJECT_PATH;
- $basePath .= $collection_id.SYS_PATH_SEP;
- getCollectionRecord($basePath, &$collectionRecord);
- $resultText .= '<span class="text">'.$collectionRecord['collection_full'].'</span>';
- $resultText .= '<ul>';
- $resultText .= '<li class="line"/>';
- $resultText .= '<li class="folder-open-last">';
- $basePath .= $package_id.SYS_PATH_SEP;
- getPackageRecord($basePath, &$packageRecord);
- $resultText .= '<span class="text">'.$packageRecord['package_full'].'</span>';
- $basePath .= SYS_PATH_SEP.$part_id;
- getPartRecord($basePath, &$partRecord);
- $resultText .= '<ul>';
- $resultText .= '<li class="line"/>';
- $resultText .= '<li class="folder-open-last">';
- $resultText .= '<span class="text">'.cleanWebString($partRecord['part_short'].': '.$partRecord['part_work'], FIELD_STRING_LENGTH).'</span>';
- $resultText .= '<ul>';
- $basePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$part_id;
- if(getImageList($basePath, &$imageList)>0) {
- foreach ($imageList['path'] as $key=>$fPath) {
- getImageRecord($fPath, &$imageRecord, $imageList['image_short'][$key]);
- $resultText .= '<li class="line"/>';
- $resultText .= '<li class="doc'.(($key+1)==count($imageList['path'])?'-last':'').'">';
- // carica IMG
- $img = ajax_loadImage($collection_id.SYS_PATH_SEP.DCTL_MEDIA_BIG.$imageRecord['image_id'], $dim, $what);
- if ($img) {
- $mapped = ajax_loadLinkList($selector, $collection_id, $package_id, $part_id, $item_id, $what);
- $mapped = preg_match('/(.*)\?(.*)\#(.*)\@(.*)/', $mapped, $matches);
- if ($mapped) {
- $uri = $matches[3];
- } else {
- $uri = 'img://'.$imageRecord['image_id'];
- };
- $coord = '';
- $mapped = $mapped && ($item_id != '');
- if ($mapped) {
- $mapped = (basename($img) == basename($uri));
- $coord = explode(',', $matches[4]);
- };
- if ($mapped) {
- $resultText .= '<span class="active">';
- $resultText .= cleanWebString($imageRecord['image_work'].': '.$imageRecord['image_short'], FIELD_STRING_LENGTH);
- } else {
- $resultText .= '<span class="text">';
- $resultText .= '<a href="javascript:void(0);" onclick="';
- $resultText .= '$(this).parents(\'ul\').find(\'.active\').removeClass(\'active\');';
- $resultText .= '$(this).parent().addClass(\'active\');';
- $resultText .= ajax_loadImageMap($selector, $item_id, $uri, $img, $dim, $coord, $what);
- $resultText .= ';" title="#">';
- $resultText .= cleanWebString($imageRecord['image_work'].': '.$imageRecord['image_short'], FIELD_STRING_LENGTH);
- $resultText .= '</a>';
- };
- } else {
- $resultText .= '<em>Not found: ';
- $resultText .= cleanWebString($imageRecord['image_work'].': '.$imageRecord['image_short'], FIELD_STRING_LENGTH);
- $resultText .= '</em>';
- };
- $resultText .= '</span>';
- $resultText .= '</li>';
- };
- $resultText .= '<script>';
- $resultText .= '$(\'#xml_tree2 .simpleTree\').find(\'.active\').parents(\'ul\').find(\'li span a\').each(function() {
- $(this).parent().replaceWith($(this).text());
- });';
- $resultText .= '</script>';
- } else {
- $resultText .= '<li class="doc-last"><i>nessuna figure</i></li>';
- };
- $resultText .= '</ul>';
- $resultText .= '</li>';
- $resultText .= '</ul>';
- $resultText .= '</li>';
- $resultText .= '</ul>';
- $resultText .= '</li>';
- $resultText .= '</ul>';
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function ajax_loadLinkList ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what = '') {
- $fullItem = 'xml://'.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$item_id;
- $resultText = '';
- $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
- switch ($what) {
- case 'lnk':
- $thePath .= DCTL_FILE_LINKER;
- break;
- case 'map':
- $thePath .= DCTL_FILE_MAPPER;
- break;
- default:
- $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
- break;
- };
- if (is_file($thePath)) {
- forceUTF8($thePath);
- $simplexml = simplexml_load_file($thePath, 'SimpleXMLElement', DCTL_XML_LOADER);
- $namespaces = $simplexml->getDocNamespaces();
- foreach ($namespaces as $nsk=>$ns) {
- if ($nsk == '') $nsk = 'tei';
- $simplexml->registerXPathNamespace($nsk, $ns);
- };
- $simplexml = simplexml_load_string(str_ireplace('xml:id','id',$simplexml->asXML()), 'SimpleXMLElement');
- // $s1=' '.$fullItem.' ';
- // $s2=$fullItem.' ';
- // $s3=' '.$fullItem;
- // $resultXML = $simplexml->xpath('//*[contains(@target,\''.$s1.'\') or contains(@target,\''.$s2.'\') or @target=\''.$fullItem.'\']');
- $fullItem = preg_replace('/(\.\d\d\d)/','.001',$fullItem);
- $resultXML = $simplexml->xpath('//*[contains(@target,\''.$fullItem.'\') and substring(substring-after(@target,\''.$fullItem.'\'),1,1) != "."]');
- if (count($resultXML)>0) {
- switch ($what) {
- case 'lnk': {
- $resultText .= '<ul class="simpleTree">';
- $resultText .= '<li class="root">Collegamenti';
- $resultText .= '<ul>';
- foreach($resultXML as $n=>$link) {
- $attrs = $link->attributes();
- $label = $attrs['n'];
- $resultText .= '<li>';
- $resultText .= '<span class="text" onclick="';
- // carica ID
- $resultText .= '$(\':input[name=xml_lnk'.$selector.']\').addClass(\'active\').attr({value:\''.$label.'\'});';
- $resultText .= '$(\':input[name=xml_lnk'.$selector.'id]\').addClass(\'active\').attr({value:\''.$attrs['id'].'\'});';
- $resultText .= '">';
- $resultText .= cleanWebString(stripslashes($attrs['n']), 40).' </span>';
- $resultText .= '  <img src="'.DCTL_IMAGES.'edit.gif" alt="edit" onclick="editLink(this, \''.$fullItem.'\',\''.$attrs['id'].'\', \''.$label.'\', \''.$what.'\')" />';
- if ($selector==2) {
- $resultText .= '  <img src="'.DCTL_IMAGES.'published_no.png" alt="delete" onclick="deleteLink(\''.$attrs['id'].'\',\'\',\''.$label.'\', \''.$what.'\')" />';
- };
- $resultText .= '<ul>';
- foreach(explode(' ',$link['target']) as $k=>$v) {
- if ($v!=''){
- $parsed = explode(SYS_PATH_SEP,$v);
- $lnk_coll =$parsed[2];
- switch (count($parsed)) {
- case 4: // xml://_coll_/_id_ => linker
- $lnk_pack = '';
- $lnk_part = '';
- $lnk_item = $parsed[3];
- break;
- case 5: // xml://_coll_/_pack_/_id_ => package
- $lnk_pack = $parsed[3];
- $lnk_part = array();
- if(preg_match('/\d\d\d/',$parsed[4],$lnk_part)) {
- $lnk_part = str_ireplace('$',$lnk_part[0],DCTL_PACKAGE_BODY);
- };
- $lnk_item = $parsed[4];
- break;
- };
- $resultText .= '<li>';
- $resultText .= '<span class="text">';
- $resultText .= '<a href="javascript:void(0);" onclick="';
- // carica XML
- $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.'\'});';
- $resultText .= '" title="#">'.cleanWebString(str_ireplace('xml://'.$lnk_coll.SYS_PATH_SEP,'',$v)).'</a>';
- $resultText .= '</span>';
- if ($v == $fullItem) {
- if ($selector==1) {
- $fullItem2 = 'xml://'.$lnk_coll.SYS_PATH_SEP.$lnk_pack.SYS_PATH_SEP.$lnk_item;
- $resultText .= '  <img src="'.DCTL_IMAGES.'published_no.png" alt="" onclick="deleteLink(\''.$attrs['id'].'\',\''.$fullItem2.'\',\''.$label.'\', \''.$what.'\')" />';
- };
- };
- $resultText .= '</li>';
- };
- };
- $resultText .= '</ul>';
- $resultText .= '</li>';
- };
- $resultText .= '</ul>';
- $resultText .= '</li>';
- $resultText .= '</ul>';
- };
- break;
- case 'map': {
- foreach($resultXML as $n=>$link) {
- $attrs = $link->attributes();
- foreach(explode(' ',$link['target']) as $k=>$v) {
- if ($v != '') {
- if ($v != $fullItem) {
- $resultText = $attrs['id'].'?'.$attrs['n'].'#'.$v; // id ? label # uri @ map
- };
- };
- };
- };
- };
- break;
- default:
- $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
- break;
- };
- };
- };
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function ajax_loadId ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
- $resultText = '';
- $resultText .= '<a href="javascript:void(0);" onclick="';
- $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.'\'});';
- $resultText .= '" title="#">';
- $fullItem = 'xml://'.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$item_id;
- $resultText .= cleanWebString($fullItem);
- $resultText .= '</a>';
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function ajax_loadChunk ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
- $resultText = '';
- $fullItem = $collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$part_id;
- $thePath = DCTL_PROJECT_PATH.$fullItem;
- // $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>';
- if (is_file($thePath)) {
- forceUTF8($thePath);
- $simplexml = simplexml_load_file($thePath, 'asPrettyXMLElement', DCTL_XML_LOADER);
- $namespaces = $simplexml->getDocNamespaces();
- foreach ($namespaces as $nsk=>$ns) {
- if ($nsk == '') $nsk = 'tei';
- $simplexml->registerXPathNamespace($nsk, $ns);
- };
- $resultXML = $simplexml->xpath('id("'.$item_id.'")');
- if (count($resultXML)>0) {
- $high = 'xml:id="'.$item_id.'"';
- $xxml = htmlentities($resultXML[0]->asPrettyXML(1),ENT_QUOTES,'UTF-8');
- $resultText .= '<pre>'.str_ireplace($high,'<span class="highlight">'.$high.'</span>', $xxml).'</pre>';
- } else {
- $resultText .= '<span class="error">Non trovo ID '.$item_id.'...</span>';
- };
- } else {
- $resultText .= '<span class="error">Non trovo '.$fullItem.'...</span>';
- };
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function ajax_loadImage ($fullItem='', &$dim=array(), $what='') {
- $resultText = '';
- $thePath = DCTL_PROJECT_PATH.$fullItem;
- if (is_file($thePath)) {
- $dim = getimagesize($thePath);
- $thePath = str_ireplace(DCTL_PROJECT_PATH, HOST_BASE_PATH.'data'.WEB_PATH_SEP.'dctl-project'.WEB_PATH_SEP, $thePath);
- $resultText .= $thePath;
- } else {
- $resultText .= '';
- };
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function ajax_loadTree ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
- $resultText = '';
- if (DCTL_EXT_IMT) {
- } else {
- switch ($what ) {
- case 'lnk':
- break;
- case 'map':
- $resultText .= '<script>';
- $resultText .= '$(\'img#img_edit\').attr(\'src\', \'\').imgAreaSelect({disable:true, hide:true});';
- $resultText .= '$(\':input[name=xml_id1]\').removeClass(\'active\').val(\'\');';
- $resultText .= '$(\':input[name=xml_id2]\').removeClass(\'active\').val(\'\');';
- $resultText .= '$(\':input[name=xml_label]\').removeClass(\'active\').val(\'\');';
- $resultText .= '$(\':input[name=xml_lnk1id]\').removeClass(\'active\').val(\'\');';
- $resultText .= '$(\'#xml_tree2\').html(\'\');';
- $resultText .= '</script>';
- break;
- default:
- $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
- break;
- };
- };
- // BEGIN
- $basePath = DCTL_PROJECT_PATH;
- $collectionPath = $basePath.$collection_id.SYS_PATH_SEP;
- if ($collection_id == '') {
- /*
- // ALL COLLECTIONS
- $resultText .= '<ul>';
- getCollectionList($basePath, &$collectionList);
- foreach ($collectionList['path'] as $key=>$fPath) {
- getCollectionRecord($fPath, &$collectionRecord);
- $resultText .= '<li>';
- $resultText .= '<span class="text">'.cleanWebString($collectionRecord['collection_short'].' - '.$collectionRecord['collection_work'], FIELD_STRING_LENGTH).'</span>';
- $resultText .= '<ul class="ajax">';
- $resultText .= '<li>{url:indexAjax.php?action=ajax_loadTree&selector='.$selector.'&collection_id='.$collectionRecord['collection_id'].'}</li>';
- $resultText .= '</ul>';
- $resultText .= '</li>';
- };
- $resultText .= '</ul>';
- */
- } else {
- if ($package_id=='') {
- $resultText .= '<ul class="simpleTree">';
- getCollectionRecord($collectionPath, &$collectionRecord);
- $resultText .= '<li class="root">';
- $resultText .= '<span class="text">'.$collectionRecord['collection_full'].'</span>';
- };
- $basePath = $collectionPath;
- $packagePath = $basePath.$package_id.SYS_PATH_SEP;
- // ONE COLLECTION
- if ($package_id == '') {
- // ALL PACKAGES
- $resultText .= '<ul>';
- getPackageList($basePath, &$packageList);
- foreach ($packageList['path'] as $key=>$fPath) {
- getPackageRecord($fPath, &$packageRecord);
- $resultText .= '<li>';
- $resultText .= '<span class="text">'.$packageRecord['package_full'].'</span>';
- $resultText .= '<ul class="ajax">';
- $resultText .= '<li>{url:indexAjax.php?action=ajax_loadTree&selector='.$selector.'&collection_id='.$collection_id.'&package_id='.$packageRecord['package_id'].'&what='.$what.'}</li>';
- $resultText .= '</ul>';
- $resultText .= '</li>';
- };
- $resultText .= '</ul>';
- } else {
- // ONE PACKAGE
- $basePath = $packagePath;
- $partPath = $basePath.$part_id.SYS_PATH_SEP;
- if ($part_id == '') {
- // ALL PARTS
- $resultText .= '<ul>';
- getPartList($basePath, &$partList);
- foreach ($partList['path'] as $key=>$fPath) {
- getPartRecord($fPath, &$partRecord);
- $resultText .= '<li>';
- if (DCTL_EXT_IMT && $what=='map') {
- $resultText .= '<span class="text"><a href="javascript:void(0);" onclick="';
- $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.'\'},';
- $resultText .= ' function('.DCTL_EXT_IMT_CBP.'){ commdodoro_initializeIMT('.DCTL_EXT_IMT_CBP.'); killProgress();});';
- $resultText .= '">'.cleanWebString($partRecord['part_short'].': '.$partRecord['part_work'], FIELD_STRING_LENGTH). ' </a></span>';
- } else {
- $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(){
- $(\'#xml_tree'.$selector.' .simpleTree\').get(0).setTreeNodes(this, false);
- killProgress();
- }).insertAfter(this);">'.cleanWebString($partRecord['part_short'].': '.$partRecord['part_work'], FIELD_STRING_LENGTH). ' </span>';
- $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(){
- $(\'#xml_tree'.$selector.' .simpleTree\').get(0).setTreeNodes(this, false);
- killProgress();
- }).insertAfter(this);" />';
- $resultText .= '<ul class="ajax">';
- $resultText .= '<li>{url:indexAjax.php?action=ajax_loadTree&selector='.$selector.'&collection_id='.$collection_id.'&package_id='.$package_id.'&part_id='.$partRecord['part_id'].'&what='.$what.'}</li>';
- $resultText .= '</ul>';
- };
- $resultText .= '</li>';
- };
- $resultText .= '</ul>';
- } else {
- $basePath = $partPath;
- $itemPath = $basePath.$item_id.SYS_PATH_SEP;
- // ONE PART
- if ($item_id == '') {
- // ALL ITEMS
- if (DCTL_EXT_IMT && $what=='map') {
- $resultText .= '<?xml version="1.0" encoding="UTF-8"?>';
- $resultText .= '<dctl_ext_init>';
- $resultText .= '<xml>';
- if(getItemList($basePath, &$itemList, $what)>0) {
- $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP.DCTL_FILE_MAPPER;
- if (is_file($thePath)) {
- forceUTF8($thePath);
- $simplexml = simplexml_load_file($thePath, 'SimpleXMLElement', DCTL_XML_LOADER);
- $namespaces = $simplexml->getDocNamespaces();
- foreach ($namespaces as $nsk=>$ns) {
- if ($nsk == '') $nsk = 'tei';
- $simplexml->registerXPathNamespace($nsk, $ns);
- };
- $simplexml = simplexml_load_string(str_ireplace('xml:id','id',$simplexml->asXML()), 'SimpleXMLElement');
- foreach ($itemList['path'] as $key=>$fPath) {
- $uri = 'xml://'.$collection_id.'/'.$package_id.'/'.$itemList['item_id'][$key];
- $content = $itemList['item_short'][$key];
- $ref = '';
- $target = '';
- $label = '';
- $fullItem = $uri;
- $fullItem = preg_replace('/(\.\d\d\d)/','.001',$fullItem);
- $resultXML = $simplexml->xpath('//*[contains(@target,\''.$fullItem.'\') and substring(substring-after(@target,\''.$fullItem.'\'),1,1) != "."]');
- if (count($resultXML)>0) {
- foreach($resultXML as $n=>$link) {
- $attrs = $link->attributes();
- foreach(explode(' ',$link['target']) as $k=>$v) {
- if ($v != '') {
- if ($v != $fullItem) {
- $ref = $attrs['id'];
- $target = $v;
- $label = $attrs['n'];
- };
- };
- };
- };
- };
- $resultText .= '<a';
- $resultText .= ' r="'.$ref.'"';
- $resultText .= ' s="'.$uri.'"';
- $resultText .= ' t="'.$target.'"';
- $resultText .= ' l="'.$label.'"';
- $resultText .= ' c="'.$content.'"';
- $resultText .= ' />';
- };
- } else {
- dump('ERRORE');
- };
- };
- $resultText .= '</xml>';
- $resultText .= '<img>';
- if(getImageList($basePath, &$imageList)>0) {
- $key = 0;
- if (isset($imageList['path'][$key])) {
- $uri = 'img://'.$imageList['image_id'][$key];
- $url = DCTL_EXT_URL.'/indexAjax.php?&action=get_file&collection_id='.$collection_id.'&url='.DCTL_MEDIA_MED.$imageList['image_id'][$key];
- $label = $imageList['image_short'][$key];
- $resultText .= '<a';
- $resultText .= ' s="'.$uri.'"';
- $resultText .= ' u="'.$url.'"';
- $resultText .= ' l="'.$label.'"';
- $resultText .= ' />';
- };
- };
- $resultText .= '</img>';
- $resultText .= '<cb';
- $resultText .= ' u="'.DCTL_EXT_IMT_CB.'"';
- $resultText .= ' p="'.DCTL_EXT_IMT_CBP.'"';
- $resultText .= ' />';
- $resultText .= '</dctl_ext_init>';
- $resultText = base64_encode($resultText); //base64_encode
- } else {
- $resultText .= '<script>';
- switch ($what) {
- case 'lnk':
- break;
- case 'map':
- $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.'\'});';
- break;
- default:
- $resultText .= 'alert(\'ERROR: CASE UNIMPLEMENTED IN ...'.__FUNCTION__.'\');';
- break;
- };
- $resultText .= '</script>';
- if(getItemList($basePath, &$itemList, $what)>0) {
- $resultText .= '<ul>';
- foreach ($itemList['path'] as $key=>$fPath) {
- getItemRecord($fPath, &$itemRecord, $itemList['item_short'][$key]);
- $resultText .= '<li>';
- $resultText .= '<span class="text">';
- if ($itemRecord['item_id'] != '') {
- $resultText .= '<a href="javascript:void(0);" onclick="';
- // carica XML
- $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.'\'});';
- // carica ID
- $resultText .= '$(\':input[name=xml_id'.$selector.']\').addClass(\'active\').attr({value:\''.'xml://'.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$itemRecord['item_short'].'\'});';
- switch ($what) {
- case 'lnk':
- // carica LINK
- $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}); });';
- $resultText .= '" title="#">';
- $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
- break;
- case 'map':
- $mapped = ajax_loadLinkList($selector, $collection_id, $package_id, $part_id, $itemRecord['item_id'], $what);
- $mapped = preg_match('/(.*)\?(.*)\#(.*)\@(.*)/', $mapped, $matches);
- if ($mapped) {
- $ref = $matches[1];
- $label = $matches[2];
- } else {
- $ref = '';
- $label = $itemRecord['item_work'];
- };
- $resultText .= '$(\':input[name=xml_label]\').removeClass(\'active\').val(\''.str_ireplace(''', "\\'", $label).'\');';
- $resultText .= '$(\':input[name=xml_id2]\').removeClass(\'active\').val(\'\');';
- $resultText .= '$(\':input[name=xml_lnk1id]\').addClass(\'active\').attr({value:\''.$ref.'\'});';
- $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.'\'}';
- if ($mapped) {
- $uri = $matches[3];
- $img = str_ireplace('img://', $collection_id.SYS_PATH_SEP.DCTL_MEDIA_BIG, $uri);
- $coord = explode(',', $matches[4]);
- $resultText .= ', function () {';
- $img = ajax_loadImage($img, $dim, $what);
- $resultText .= ajax_loadImageMap($selector, $itemRecord['item_id'], $uri, $img, $dim, $coord, $what);
- $resultText .= '}';
- };
- $resultText .= ');';
- $resultText .= '" title="#">';
- if ($mapped) {
- $resultText .= '<span class="dctl_ok">';
- $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
- $resultText .= '</span>';
- $resultText .= '  <img src="'.DCTL_IMAGES.'published_no.png" alt="delete" onclick="deleteLink(\''.$matches[1].'\',\''.$matches[3].'@'.$matches[4].'\',\''.$matches[2].'\', \''.$what.'\')" />';
- } else {
- $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
- };
- break;
- default:
- $resultText .= 'alert(\'ERROR: CASE UNIMPLEMENTED IN ...'.__FUNCTION__.'\');';
- $resultText .= '" title="#">';
- $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
- break;
- };
- $resultText .= '</a>';
- } else {
- $resultText .= '<em class="dctl_ko">';
- $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
- $resultText .= '</em>';
- };
- $resultText .= '</span>';
- $resultText .= '</li>';
- };
- $resultText .= '</ul>';
- } else {
- $resultText .= '<li><i>nessun id</i></li>';
- };
- };
- } else {
- $resultText .= 'UNIMPLEMENTED';
- };
- };
- };
- if (DCTL_EXT_IMT && $what=='map') {
- // nothing
- } else {
- $resultText .= '</li>';
- $resultText .= '</ul>';
- };
- };
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function isImage($mime,$ext) {
- if (
- ($mime=="image/gif")||
- ($mime=="image/jpeg")||
- ($mime=="image/jpg")||
- ($mime=="image/pjpeg")||
- ($mime=="image/png")||
- ($ext=="jpg")||
- ($ext=="jpeg")||
- ($ext=="png")||
- ($ext=="gif") ) {
- return true;
- } else {
- return false;
- };
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function getMIME($file) {
- //If mime magic is installed
- if (function_exists("mime_content_type")) {
- $mime=mime_content_type($file);
- } else {
- $mime=image2MIME($file);
- if($mime==false) $mime="text/plain";
- }
- return strtolower($mime);
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function image2MIME($file) {
- $fh=fopen($file,"r");
- if ($fh) {
- $start4=fread($fh,4);
- $start3=substr($start4,0,3);
- if ($start4=="\x89PNG") {
- return "image/png";
- } elseif ($start3=="GIF") {
- return "image/gif";
- } elseif ($start3=="\xFF\xD8\xFF") {
- return "image/jpeg";
- } elseif ($start4=="hsi1") {
- return "image/jpeg";
- } else {
- return false;
- }
- unset($start3);
- unset($start4);
- fclose($fh);
- } else {
- return false;
- }
- }
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function putEdit ($param = '') {
- $resultText = '';
- if (DCTL_USER_IS_EDITOR) {
- $resultText .= '<a onclick="javascript:doProgress();" class="edit" href="'.$_SERVER['PHP_SELF'].'?';
- foreach ($_REQUEST as $k=>$v) {
- if ($k == $param) $v = 'true';
- $resultText .= $k."=".$v."&";
- };
- $param .= '=';
- if (stripos($param, $resultText) === false) $resultText .= $param.'true';
- $resultText .= '" title="modifica">';
- $resultText .= ' <img src="'.DCTL_IMAGES.'application_form_edit.png" alt="(edit icon)" />';
- $resultText .= ' Modifica dati</a>';
- };
- return $resultText;
- }
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function putOpenCloseLevel ($id, $loc4msg, $more=false, $label, &$resultMsg='') {
- $resultText = '';
- $isThis = ($loc4msg == $id) || $more;
- $resultText .= '<h3>';
- $resultText .= '<a class="toggler" onclick="toggleVisibility(this,\''.$id.'\');" title="'.TOOLTIP_TOGGLE.'">';
- $resultText .= '<img src="'.DCTL_IMAGES;
- if ($isThis) {
- $resultText .= 'collapse.gif';
- } else {
- $resultText .= 'expand.gif';
- };
- $resultText .= '" alt="(open/close level)" /> ';
- $resultText .= $label.'</a></h3>';
- $resultText .= '<div id="'.$id.'" class="';
- if ($isThis) {
- $resultText .= 'un';
- } else {
- $resultText .= '_hidden';
- };
- $resultText .= '">';
- if ($loc4msg == $id) {
- $resultText .= $resultMsg;
- }
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function putOpenLevel ($id, $loc4msg, $more=false, $label, &$resultMsg='') {
- $resultText = '';
- $isThis = ($loc4msg == $id) || $more;
- $resultText .= '<h3>';
- $resultText .= ' ';
- $resultText .= $label.'</h3>';
- $resultText .= '<div id="'.$id.'" class="';
- $resultText .= '">';
- if ($loc4msg == $id) {
- $resultText .= $resultMsg;
- }
- return $resultText;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function getModel ($originalPath) {
- $sourcePath = $originalPath;
- $filePath = str_ireplace(DCTL_PROJECT_PATH, '', $sourcePath);
- $zip = new zipfile();
- $zipdir = SYS_PATH_SEP;
- $zip->add_dir($zipdir);
- addToZip(DCTL_SETTINGS, $zip, $zipdir);
- $zipdir = SYS_PATH_SEP;
- $source = DCTL_PROJECT_PATH;
- foreach(explode(SYS_PATH_SEP, $filePath) as $item) {
- $source .= $item;
- $zipdir .= $item;
- if (is_dir($source)) {
- $source .= SYS_PATH_SEP;
- $zipdir .= SYS_PATH_SEP;
- $zip->add_dir($zipdir);
- $item = $source.DCTL_FILE_HEADER;
- if (is_file($item)) {
- addToZip($item, $zip, $zipdir);
- };
- // $item = $source.DCTL_MEDIA_SML;
- // if (is_dir($item)) {
- // addToZip($item, $zip, $zipdir);
- // };
- };
- };
- $zipdir = dirname($zipdir).SYS_PATH_SEP;
- if (is_dir($source)) {
- if ((stripos(DCTL_MEDIA_SML, $source) === FALSE) && (stripos(DCTL_MEDIA_MED, $source) === FALSE)) {
- addToZip($source, $zip, $zipdir);
- };
- } else {
- if (is_file($source)) {
- $item = $source;
- addToZip($item, $zip, $zipdir);
- };
- };
- $filePath = dirname($originalPath).SYS_PATH_SEP.str_ireplace(SYS_PATH_SEP, '#', $filePath).'.zip';
- $fd = fopen ($filePath, "wb");
- $out = fwrite ($fd, $zip->file());
- fclose ($fd);
- @chmod($filePath, CHMOD);
- return $filePath;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function getListNameForField ($theFields, $theSelected) {
- global $COLLECTION_FIELDS;
- global $PACKAGE_FIELDS;
- $resultText = '';
- switch ($theFields) {
- case $COLLECTION_FIELDS:
- switch ($theSelected) {
- case 'collection_resp':
- $resultText = DCTL_LIST_RESP;
- break;
- };
- break;
- case $PACKAGE_FIELDS:
- switch ($theSelected) {
- case 'package_encoder':
- $resultText = DCTL_LIST_RESP;
- break;
- case 'source_lang':
- $resultText = DCTL_LIST_LANG;
- break;
- case 'source_genre':
- $resultText = DCTL_LIST_GENRE;
- break;
- case 'reference_lang':
- $resultText = DCTL_LIST_LANG;
- break;
- case 'reference_genre':
- $resultText = DCTL_LIST_GENRE;
- break;
- };
- break;
- };
- return $resultText ;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function getTextClassList ($theList='', $theObject='') {
- $resultText = '';
- if ($theList != '') {
- if ($theObject != '') {
- $simplexml = '';
- if (is_file(DCTL_SETTINGS_TEXTCLASS)) {
- $resultText .= '<br />Aggiungi:<select onchange="javascript:addContent(\''.$theObject.'\', this.value);">';
- $resultText .= '<option value="" selected="selected" />';
- forceUTF8(DCTL_SETTINGS_TEXTCLASS);
- $simplexml = simplexml_load_file(DCTL_SETTINGS_TEXTCLASS, 'SimpleXMLElement', DCTL_XML_LOADER);
- $simplexml = $simplexml->asXML();
- $simplexml = str_ireplace('xml:', '', $simplexml);
- $simplexml = simplexml_load_string($simplexml, 'SimpleXMLElement', DCTL_XML_LOADER);
- $resultXML = $simplexml->xpath('//classCode[@scheme="'.$theList.'"]/term');
- foreach ($resultXML as $k=>$v) {
- $id = strval($v['id']);
- $name = strval($v->eg);
- $resultText .= '<option value="'.$id.'">'.$name.SYS_DBL_SPACE.'</option>';
- };
- $resultText .= '</select>';
- };
- };
- };
- return $resultText ;
- };
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function getManagementOfImages ($fDivX, $labelX, $collection_id, $itemName, $loc4msg, &$fCount, $resultMsg) {
- global $EXTENSION_ALLOWED;
- global $EXTENSION_TEXT;
- global $EXTENSION_GRAPHIC;
- $resultText = '';
- $array_estensioni_ammesse = $EXTENSION_ALLOWED;
- $basename = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
- $regexp = '[';
- foreach($array_estensioni_ammesse as $k=>$v) {
- if ($k >0) $regexp .= ' | ';
- $regexp .= $v;
- };
- $regexp .= ']';
- $dPath = $basename.DCTL_MEDIA_SML;
- if (!is_dir($dPath)) mkdir($dPath, CHMOD);
- @chmod($dPath, CHMOD);
- $dPath = $basename.DCTL_MEDIA_MED;
- if (!is_dir($dPath)) mkdir($dPath, CHMOD);
- @chmod($dPath, CHMOD);
- $dPath = $basename.DCTL_MEDIA_BIG;
- if (!is_dir($dPath)) mkdir($dPath, CHMOD);
- @chmod($dPath, CHMOD);
- $dPath = $basename.DCTL_MEDIA_BIG;
- $variants = array();
- $handle = opendir($dPath);
- while ($entry = readdir($handle)) {
- if (substr($entry, 0, 1) != '.') {
- $variants[] = $entry;
- };
- };
- $variants = array_values(preg_grep('/.*'.$regexp.'/', $variants));
- $idx = count($variants);
- sort($variants);
- $fDiv0 = str_ireplace('$', '', $fDivX);
- $label0 = str_ireplace('$', '', $labelX);
- //putOpenCloseLevel
- $resultText .= putOpenLevel($fDiv0, $loc4msg, false, 'Gestione '.$label0.' di "'.$itemName.'" ('.$idx.')', &$resultMsg);
- $resultText .= '<table>';
- $resultText .= '<thead>';
- $resultText .= '<tr>';
- $resultText .= '<th class="label">operazione</th>';
- $resultText .= '<th>azione</th>';
- $resultText .= '<th>risultato</th>';
- $resultText .= '</tr>';
- $resultText .= '</thead>';
- $resultText .= '<tbody>';
- /* CARICA UNA IMMAGINE */
- $dPath = $basename.DCTL_MEDIA_BIG;
- $resultText .= '<tr>';
- $resultText .= '<td>Carica un nuovo file ...</td>';
- $resultText .= '<td>';
- $resultText .= '<form id="form'.$fDiv0.'" action="'.$_SERVER['SCRIPT_NAME'].'" method="'.DCTL_FORM_METHOD_POST.'" enctype="'.DCTL_FORM_ENCTYPE_POST.'">';
- $resultText .= '<fieldset>';
- $resultText .= '<input type="file" id="multi_file_upload" name="FILE'.$fCount.'" size="50" />';
- $resultText .= '<input type="hidden" name="PATH" value="'.$dPath.'" />';
- $resultText .= '<input type="hidden" name="posx" value="'.$fDiv0.'" />';
- $resultText .= '<input type="hidden" name="ext" value="img" />';
- $resultText .= SYS_DBL_SPACE.SYS_DBL_SPACE.'<input type="submit" name="upload" value="invia" />';
- $resultText .= '<br /><strong>File da caricare</strong> (max 10): <div id="files_list"></div>
- <script>
- var multi_selector = new MultiSelector(document.getElementById("files_list"), 10);
- multi_selector.addElement(document.getElementById("multi_file_upload") );
- </script>
- ';
- $resultText .= '<input type="hidden" name="collection_id" value="'.$collection_id.'" />';
- $resultText .= '</fieldset>';
- $resultText .= '</form>';
- $resultText .= '</td>';
- $resultText .= '<td> </td>';
- $resultText .= '</tr>';
- /* VISUALIZZA LE ANTEPRIME */
- $dPath = $basename.DCTL_MEDIA_BIG;
- $resultText .= '<tr>';
- $resultText .= '<td>Visualizza l\'anteprima di un file...<br /><br />';
- $resultText .= '<form action="">';
- $resultText .= '<fieldset>';
- $resultText .= '<input type="text" id="mediaFilter" value="-trova-" onkeyup="var vFilter=this.value;
- $(\'#mediaList li\').removeClass(\'found\');
- var index = $(\'#mediaList li\').index($(\'#mediaList a\').filter(function(node){return ((this.text.toLowerCase().indexOf(vFilter)>=0)&&(vFilter!=\'\'))}).parent().addClass(\'found\'));
- " />';
- $resultText .= '</fieldset>';
- $resultText .= '</form>';
- $resultText .= '</td>';
- $resultText .= '<td colspan="2">';
- if (is_dir($dPath)) {
- $resultText .= '<ul id="mediaList" class="trueContainer';
- if (true) $resultText .= '2';
- $resultText .= '">';
- // $resultText .= '<script type="text/javascript" src="../js/imager.js"></script>';
- // $resultText .= '<div id="motioncontainer" style="position:relative;overflow:hidden;">';
- // $resultText .= '<div id="motiongallery" style="position:absolute;left:0;top:0;white-space: nowrap;">';
- // $resultText .= '<span id="trueContainer">';
- $tail = '';
- $dPath2 = $dPath; //$dPath2 = str_ireplace(DCTL_MEDIA_SML, DCTL_MEDIA_BIG, $dPath);
- $files = scandir($dPath2);
- $filePattern = '/-('.WS.'*)(.*)('.WS.'*)=('.WS.'*)$('.WS.'*)-/';
- if ($dPath != '') {
- $entries = array();
- $handle = opendir($dPath);
- while ($entry = readdir($handle)) {
- if (substr($entry, 0, 1) != '.') {
- $entries[] = $entry;
- };
- };
- sort($entries);
- foreach($entries as $entry) {
- $ext = strtolower(substr($entry, -3, 3));
- if (in_array($ext, $array_estensioni_ammesse)) {
- $labelval = str_ireplace('$', $entry, $filePattern);
- $labelx = array_values(preg_grep($labelval, $files));
- if (count($labelx)>0) {
- $label = $labelx[0];
- $labelx = preg_split('/('.WS.'*)=('.WS.'*)/', $label, -1);
- $label = str_ireplace('-', '', $labelx[0]);
- } else {
- $label = $entry;
- };
- if ($label != $entry) {
- if (substr($label, 0, strlen($collection_id)) != $collection_id) {
- $label = $collection_id.'-'.$label;
- };
- rename($dPath.$entry, $dPath.$label);
- …
Large files files are truncated, but you can click here to view the full file