Ejemplo n.º 1
0
 protected function _get_resource($justRefs = false, $resourceList = '', $xpath = '')
 {
     $asOptions = $xpath != '';
     $xpath = trim($xpath);
     $resourceList = $this->_parse_uri($resourceList, $xpath);
     $docList = array();
     foreach ($resourceList as $key4docList => $parsed) {
         $resList = array();
         switch ($parsed['scheme']) {
             case 'xml':
             case 'img':
                 switch ($parsed['scheme']) {
                     case 'xml':
                         if ($parsed['collection'] == '') {
                             $this->_get_collection_list(false, $this->_db_publish_path, &$resList);
                         } else {
                             $xml_resource = $this->_db_publish_path . $parsed['collection'] . DB_PATH_SEP;
                             if ($parsed['package'] == '') {
                                 $this->_get_collection_record(false, $xml_resource, &$resList[]);
                             } else {
                                 if (preg_match('/^(_\\w{3})|(\\w*_)$/', $parsed['package'], $preg_match)) {
                                     $this->_get_package_list(false, $xml_resource, &$resList, $preg_match[0]);
                                 } else {
                                     $package = preg_match('/\\.xml$/i', $parsed['package']) ? $parsed['package'] : $parsed['package'] . '.xml';
                                     $xml_resource .= $parsed['collection'] . DCTL_RESERVED_INFIX . $package;
                                     $this->_get_package_record(false, $xml_resource, &$resList[]);
                                     // per ritornare almeno la collezione, ma non mi pare coerente
                                     // 	          if (!$resList[0]['ref']) {
                                     // 	  									$xml_resource = $this->_db_publish_path.$parsed['collection'].DB_PATH_SEP;
                                     //             $this->_get_collection_record(true, $xml_resource, &$resList[]);
                                     // 	          };
                                 }
                             }
                             if ($parsed['locator'] != '' || $parsed['query'] != '' || $parsed['anchor'] != '' || $asOptions) {
                                 $packageList = $resList;
                                 unset($resList);
                                 $resList = array();
                                 foreach ($packageList as $key4package => $package) {
                                     $parsed_locator = $parsed['locator'];
                                     $parsed_query = $parsed['query'];
                                     $parsed_anchor = $parsed['anchor'];
                                     $xml_resource = $package['path'];
                                     $db_resource = '';
                                     $partial = false;
                                     $context = '';
                                     $context .= $parsed_locator == '' && $parsed_query == '' ? '/' : '';
                                     // per errore: un solo & !!!
                                     $context .= $parsed_locator != '' ? '/id("' . $parsed_locator . '")' : '';
                                     $context .= $parsed_query ? $parsed_query : '';
                                     $last_attr = '';
                                     $last_val = '';
                                     if (preg_match('/\\@(\\w+)' . WS . '*.?' . WS . '*=' . WS . '*"' . WS . '*(.*)' . WS . '*"' . WS . '*/', $context, $matches)) {
                                         $last_attr = $matches[count($matches) - 2];
                                         $last_val = $matches[count($matches) - 1];
                                     }
                                     $match = str_ireplace('*', '', $last_val);
                                     $tag = '';
                                     $absLevel = '';
                                     $startAt = '';
                                     $howMany = '';
                                     $upTo = '';
                                     $forced = false;
                                     $jolly = false;
                                     $withHierarchy = false;
                                     $withPage = false;
                                     $atPage = false;
                                     if (preg_match('/(\\$\\(*(.*)\\)*)/', $parsed_anchor, $matchesX)) {
                                         $parsed_anchor = preg_replace('/' . escapeshellcmd($matchesX[0]) . '/', '', $parsed_anchor);
                                         $extenders = explode('&', preg_replace('/[\\$\\(\\)]/', '', $matchesX[0]));
                                         $withHierarchy = array_search('hier', $extenders) !== FALSE;
                                         $withPage = array_search('page', $extenders) !== FALSE;
                                     }
                                     if ($asOptions) {
                                         if ($parsed_query != '') {
                                             if (preg_match('/^' . WS . '*\\@' . WS . '*(\\w+)' . WS . '*\\&*\\|*' . WS . '*\\=' . WS . '*\\".*\\"' . WS . '*$/', $context, $matchesX)) {
                                                 $forced = true;
                                                 $context = '//*[' . $context . ']';
                                             }
                                         }
                                         switch (true) {
                                             case preg_match('/^' . WS . '*(\\w*|\\.)' . WS . '*(\\@' . WS . '*\\"' . WS . '*((\\w|\\W|\\*)(?:\\+*)*)' . WS . '*(\\+*)' . WS . '*(.*)' . WS . '*\\"' . WS . '*(\\;' . WS . '*(\\-*\\d+)' . WS . '*)?)/', $parsed_anchor, $matches):
                                                 $tag = isset($matches[1]) ? $matches[1] : $tag;
                                                 $startAt = isset($matches[4]) ? $matches[4] : $startAt;
                                                 // era [3] prima di (?:\+*)
                                                 $upTo = isset($matches[4]) ? $matches[4] != '' ? escapeshellcmd($startAt) : '' : '';
                                                 $startAt = isset($matches[6]) ? $startAt . $matches[6] : $startAt;
                                                 $howMany = $startAt ? 1 : $startAt;
                                                 $howMany = isset($matches[8]) ? $matches[8] != '' ? intval($matches[8]) : $howMany : $howMany;
                                                 if ($tag == '') {
                                                     $tag = $last_attr;
                                                 }
                                                 $jolly = stripos($startAt, '*');
                                                 if ($jolly !== false) {
                                                     $startAt = substr($startAt, 0, $jolly);
                                                     $upTo = escapeshellcmd($startAt) . '.';
                                                     if (!isset($matches[8])) {
                                                         $howMany = '';
                                                     }
                                                     ++$jolly;
                                                 }
                                                 $justContent = $tag == '.';
                                                 if ($justContent) {
                                                     //$tag = './/text()[normalize-space(.) != ""][position() = 1]';
                                                     $tag = '.';
                                                 } else {
                                                     $tag = '@' . $tag;
                                                 }
                                                 $context .= '[lower-case(normalize-space(' . $tag . ')) >= "' . strtolower($startAt) . '"]';
                                                 if ($upTo != '') {
                                                     $context .= '[matches(normalize-space(' . $tag . '), "^' . $upTo . '", "msi")]';
                                                 }
                                                 if ($justContent) {
                                                     if ($jolly) {
                                                         $context .= '//text()[1]';
                                                         // cosi ritorna le iniziali ma non dioscoride
                                                     } else {
                                                         $context .= '';
                                                         // cosi ritorna dioscoride ma non le iniziali
                                                     }
                                                 } else {
                                                     $context .= '/' . $tag;
                                                 }
                                                 $startAt = 1;
                                                 break;
                                             default:
                                                 if ($parsed_query != '') {
                                                     if ($forced) {
                                                         $context .= '/@' . $matchesX[1];
                                                     }
                                                 } else {
                                                     $context .= $parsed_locator == '' ? 'tei:div[.//text()]' : '';
                                                 }
                                                 break;
                                         }
                                     } else {
                                         switch (true) {
                                             // #page : la <pb> precedente il nodo
                                             case preg_match('/^' . WS . '*(page)' . WS . '*/', $parsed_anchor, $matches):
                                                 $atPage = true;
                                                 break;
                                                 // #divX : la <div> di livello assoluto X che contiene il nodo
                                             // #divX : la <div> di livello assoluto X che contiene il nodo
                                             case preg_match('/^' . WS . '*(div)' . WS . '*(\\-*\\d+)/', $parsed_anchor, $matches):
                                                 $tag = isset($matches[1]) ? $matches[1] : $tag;
                                                 $absLevel = isset($matches[2]) ? abs(strval($matches[2])) : '';
                                                 $context .= '/ancestor-or-self::tei:' . $tag . '[count(ancestor::tei:' . $tag . ')=' . ($absLevel - 1) . ']' . '[child::text() or child::node()]';
                                                 break;
                                                 // #div : le <div> children del nodo
                                                 // #div@X
                                                 // #div@X;Z
                                             // #div : le <div> children del nodo
                                             // #div@X
                                             // #div@X;Z
                                             case preg_match('/^' . WS . '*(div)' . WS . '*($|\\@' . WS . '*(\\-*\\d+)' . WS . '*(\\;' . WS . '*(\\-*\\d+))?)/', $parsed_anchor, $matches):
                                                 $tag = isset($matches[1]) ? $matches[1] : $tag;
                                                 $startAt = isset($matches[3]) ? abs(intval($matches[3])) : $startAt;
                                                 $howMany = isset($matches[5]) ? intval($matches[5]) : ($startAt ? 1 : $startAt);
                                                 $context .= $parsed_locator != '' | $parsed_query != '' ? '/' : '';
                                                 $context .= 'tei:' . $tag . '[child::text() or child::node()]';
                                                 break;
                                                 // #pb : le <pb> children del nodo
                                                 // #pb@X
                                                 // #pb@X;Z
                                             // #pb : le <pb> children del nodo
                                             // #pb@X
                                             // #pb@X;Z
                                             case preg_match('/^' . WS . '*(pb)' . WS . '*($|\\@' . WS . '*(\\-*\\d+)' . WS . '*(\\;' . WS . '*(\\-*\\d+))?)/', $parsed_anchor, $matches):
                                                 $tag = isset($matches[1]) ? $matches[1] : $tag;
                                                 $startAt = isset($matches[3]) ? abs(intval($matches[3])) : $startAt;
                                                 $howMany = isset($matches[5]) ? intval($matches[5]) : ($startAt ? 1 : $startAt);
                                                 $context .= $parsed_locator != '' | $parsed_query != '' ? '/' : '';
                                                 $context .= '/tei:' . $tag . '[not(@ed = "fake")]';
                                                 break;
                                                 //
                                             //
                                             default:
                                                 if ($parsed_query != '') {
                                                 } else {
                                                     $context .= $parsed_locator == '' ? 'tei:div[child::text() or child::node()]' : '';
                                                 }
                                                 break;
                                         }
                                     }
                                     $xquery = '';
                                     if ($howMany < 0) {
                                         $howMany = PHP_INT_MAX;
                                     }
                                     if ($asOptions) {
                                         // from getOptions
                                         $xquery .= "\n" . ' let $e := for $node in ';
                                         $xquery .= "\n" . ' xmldb:document("';
                                         $xquery .= $xml_resource . '")//tei:text/*' . $context . ' ';
                                         // 													$xquery .= "\n".' let $chunk := ';
                                         // 													$xquery .= "\n".' if ($node instance of text()) then $node else $node//text() ';
                                         $xquery .= "\n" . ' return ';
                                         $xquery .= "\n" . ' if ($node/node()) ';
                                         $xquery .= "\n" . '  then ';
                                         // 													$xquery .= "\n".' ("<item><", node-name($node), for $att in $node/@* return (" ", node-name($att), "=&quot;", $att, "&quot;"), ">",';
                                         // 													$xquery .= "\n".' $chunk, "</", node-name($node), "></item>") ';
                                         // 													$xquery .= "\n".' element item { element {node-name($node)} {$node/@*, text {$chunk}} } ';
                                         $xquery .= "\n" . '  $node ';
                                         // <XXX>XXX</XXX>
                                         $xquery .= "\n" . '  else ';
                                         $xquery .= "\n" . '   let $what := if (/id($node)) then ';
                                         $xquery .= "\n" . '    tokenize(tokenize($node, "' . WS . '"), "' . WS . '") else ';
                                         // 													if ($jolly) {
                                         $xquery .= ' $node ';
                                         // 														} else {
                                         // 														$xquery .= "\n".' element {node-name($node)} {$node/@*, text {$chunk}} ';
                                         // 													};
                                         $xquery .= "\n" . '    for $item in distinct-values( ';
                                         $xquery .= "\n" . '     for $token in $what ';
                                         //													$xquery .= "\n".'     for $token in $node ';
                                         $xquery .= "\n" . '      let $include := if ($node/node() or (' . !$last_val . ') or name($node) != "' . $last_attr . '") then true() ';
                                         $xquery .= ' else contains($token, tokenize("' . $match . '", "' . WS . '")) ';
                                         $xquery .= "\n" . '      return if ($include) then $token else () ';
                                         $xquery .= "\n" . '    ) return ';
                                         if ($jolly) {
                                             $xquery .= ' lower-case(substring($item,1,' . $jolly . ')) ';
                                         } else {
                                             $xquery .= ' $item ';
                                         }
                                         $xquery .= "\n" . ' return ';
                                         if ($howMany) {
                                             $xquery .= "\n" . ' for $final in subsequence(';
                                         }
                                         // 													$xquery .= "\n".' if (matches($e, "<\w+")) then $e else for $x in distinct-values($e) order by $x return <item>{$x}</item> ';
                                         $xquery .= "\n" . '  for $x in distinct-values($e) order by $x return if (normalize-space($x) ne "") then element item {normalize-space($x)} else ()';
                                         if ($howMany) {
                                             $xquery .= ', ' . $startAt . ', ' . $howMany . ' ) return $final ';
                                         }
                                     } else {
                                         $xquery .= "\n" . ' let $base := xmldb:document("' . $xml_resource . '")//tei:text ';
                                         $xquery .= "\n" . ' for $node in ';
                                         if ($howMany) {
                                             $xquery .= ' subsequence(';
                                         }
                                         $xquery .= "\n" . ' $base/*';
                                         $xquery .= $context;
                                         $xquery .= ' ';
                                         if ($howMany) {
                                             $xquery .= ', ' . $startAt . ', ' . $howMany . ' ) ';
                                         }
                                         if ($justRefs) {
                                             $xquery .= "\n" . ' let $chunk := ';
                                             $xquery .= ' if (local-name($node) = "figure") then ';
                                             $xquery .= ' $node/tei:figDesc//text() else ';
                                             $xquery .= ' if (local-name($node) = "graphic") then ';
                                             $xquery .= ' $node/parent::tei:figure/tei:figDesc//text() else ';
                                             $xquery .= ' if ($node//text() != "") then ';
                                             $xquery .= ' $node//text() else ';
                                             ///*[not(self::tei:figDesc)]
                                             $xquery .= ' if ($node/parent::*//text() != "") then ';
                                             $xquery .= ' subsequence($node/parent::*//text(), 1)[. >> $node][position() < 5] else ';
                                             $xquery .= ' $node//text() ';
                                             if ($atPage) {
                                                 $xquery .= "\n" . ' let $node := tei:getPage($node, 2) ';
                                             }
                                             $xquery .= "\n" . ' let $nodeT := element {node-name($node)} {$node/@*, text {text:kwic-display($chunk, 80, $highlight, ())}} ';
                                             if ($withPage) {
                                                 $xquery .= "\n" . ' let $nodeT := functx:add-attributes($nodeT, xs:QName("synch"), tei:getPage($node, 1)) ';
                                             }
                                             $xquery .= "\n" . ' return ';
                                             if ($withHierarchy) {
                                                 $xquery .= "\n" . ' tei:getTree($node, $nodeT) ';
                                             } else {
                                                 $xquery .= "\n" . ' $nodeT ';
                                             }
                                         } else {
                                             $xquery .= "\n" . ' return ';
                                             $xquery .= "\n" . ' if (not($base/descendant::dctl:*[1])) ';
                                             $xquery .= "\n" . ' then tei:getPage($node, 0) ';
                                             $xquery .= "\n" . ' else tei:getBlock($node) ';
                                         }
                                     }
                                     // $this->_getDebug($parsed);
                                     // $this->_getDebug($context);
                                     // $this->_getDebug($xquery);
                                     if ($this->_debug && NOVEOPIU) {
                                         $xq = DCTL_TMP_PATH . 'xquery_dbg' . basename($xml_resource) . '.xq';
                                         @file_put_contents($xq, DCTL_XQUERY_BASE . str_ireplace('  ', ' ' . "\n" . ' ', $xquery));
                                     }
                                     $result = $this->_db->xquery(DCTL_XQUERY_BASE . $xquery);
                                     $gotError = $this->_db->getError();
                                     $resultXML = (array) $result["XML"];
                                     foreach ($resultXML as $node) {
                                         $node = preg_replace('/<pb.*ed\\s*=\\s*".*fake.*".*>/', '', $node);
                                         // strip out <pb ed="fake" />
                                         if ($withHierarchy) {
                                             $node = preg_replace('/(<div.*)xml:id(\\s*=\\s*".*".*>)/', '$1sameAs$2', $node);
                                             // strip out <pb ed="fake" />
                                         }
                                         $db_resource .= $node;
                                     }
                                     // $this->_getDebug($db_resource);
                                     $this->_get_package_record($justRefs, $xml_resource, &$resList[$key4package]);
                                     // 												$encoded_xquery = htmlentities($context, ENT_QUOTES, "UTF-8", false);
                                     // 												$encoded_xquery = xml_character_encode(htmlentities($context, ENT_NOQUOTES, "UTF-8", false));
                                     $encoded_xquery = htmlspecialchars($context);
                                     $resList[$key4package]['xquery'] = $encoded_xquery;
                                     if ($resList[$key4package]['ref'] != '') {
                                         if ($parsed_locator != '') {
                                             $resList[$key4package]['ref'] .= DB_PATH_SEP . $parsed_locator;
                                         }
                                     }
                                     // 											if (preg_match('/\w+/', $db_resource)) {
                                     //             $resList[$key4package]['check'] = preg_match_all('/\<\w+/', $db_resource, $matches);
                                     // 											};
                                     if ($gotError) {
                                         if ($this->_debug) {
                                             $this->_getDebug($gotError);
                                             // $this->_getDebug($context);
                                             // $this->_getDebug($xquery);
                                         }
                                         $resList[$key4package]['error'] = '<!--[CDATA[:' . "\n" . $gotError . ' in :' . "\n" . $xquery . "\n" . ']]-->';
                                     } else {
                                         if ($asOptions) {
                                             $resList[$key4package]['kind'] = "list";
                                             $resList[$key4package]['list'] = $db_resource;
                                         } else {
                                             $resList[$key4package]['kind'] = "tei";
                                             $resList[$key4package]['fragment'] = $db_resource;
                                         }
                                     }
                                 }
                             }
                         }
                         break;
                         // · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
                     // · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
                     case 'img':
                         $parsed['query'] = $parsed['locator'];
                         // | media -> img://coll-pippero.pdf, img://coll/pippero.pdf
                         $parsed['package'] = $parsed['collection'] . DCTL_RESERVED_INFIX . $parsed['package'];
                         $parsed['collection'] = '';
                         if ($parsed['query'] != '') {
                             $parsed['package'] .= DCTL_RESERVED_INFIX . $parsed['query'];
                             $parsed['query'] = '';
                         }
                         $resList[0]['kind'] = "media";
                         $resList[0]['ref'] = '';
                         $resList[0]['icon'] = '';
                         $resList[0]['file'] = '';
                         $hi = $this->_fs_publish_path . DCTL_MEDIA_BIG . $parsed['package'];
                         if (is_file($hi)) {
                             $lo = $this->_fs_publish_path . DCTL_MEDIA_SML . $parsed['package'];
                             if (!is_file($lo)) {
                                 makePreview(DCTL_MEDIA_SML, $hi);
                             }
                             $resList[0]['ref'] = $parsed['scheme'] . '://' . $parsed['package'];
                             $resList[0]['icon'] = $this->_web_publish_path . DCTL_MEDIA_SML . $parsed['package'];
                             $resList[0]['file'] = $this->_web_publish_path . DCTL_MEDIA_BIG . $parsed['package'];
                         }
                         break;
                 }
                 break;
             default:
                 $resList[0]['kind'] = "url";
                 $resList[0]['ref'] = $resource;
                 break;
         }
         $docList = array_merge($docList, $resList);
     }
     if (!$asOptions) {
         // wraps results
         return $this->_resources_to_xml($docList);
     } else {
         // raw results
         return $docList;
     }
 }
Ejemplo n.º 2
0
function createPreview($g_srcfile, $overwrite = TRUE, $forcedsize = 200, $imgcomp = 0)
{
    if (is_dir($g_srcfile)) {
        $handle = opendir($g_srcfile);
        while ($entry = readdir($handle)) {
            if (substr($entry, 0, 1) != '.') {
                if ($entry != basename(DCTL_MEDIA_SML) && $entry != basename(DCTL_MEDIA_MED)) {
                    createPreview($g_srcfile . SYS_PATH_SEP . $entry, $overwrite, $forcedsize, $imgcomp);
                }
            }
        }
    } else {
        makePreview(DCTL_MEDIA_SML, $g_srcfile, $overwrite, $forcedsize, $imgcomp);
        makePreview(DCTL_MEDIA_MED, $g_srcfile, $overwrite, $forcedsize * 2.5, $imgcomp);
    }
}
Ejemplo n.º 3
0
             $smarty->assign('news', $news);
             $smarty->assign('path', $template_dir . "/edit.tpl");
             $smarty->assign('domains', getDomainList());
         }
         break;
     }
 case 'add':
     if ($isallowed) {
         $smarty->assign('domains', getDomainList());
         $added = false;
         $smarty->assign('groups', $rights->getAllGroups());
         if (isset($_POST['save'])) {
             $title = $_POST['title'];
             $text = $_POST['text'];
             if ($text != '' && $title != '') {
                 $db->insert($table, array('title', 'text', 'preview', 'userid', 'timestamp', 'language', 'domainid'), array("'" . $title . "'", "'" . $text . "'", "'" . makePreview($text, 18) . "'", $login->currentUserID(), time(), "'" . $_POST['language'] . "'", (int) $_POST['domainid']));
                 $notify->add($lang->get('news'), $lang->get('news_added'));
                 // Circular mail
                 @($pm = $_POST['send_pm'] == 'true');
                 @($mail = $_POST['send_mail'] == 'true');
                 @($copy = $_POST['copy_to_me'] == 'true');
                 @($send_to = (int) $_POST['send_to']);
                 if ($send_to > -1) {
                     $subject = trim(replaceHtmlEntities($_POST['title']));
                     $message = trim($_POST['text']);
                     if ($message != '' && $subject != '') {
                         if ($send_to == 0) {
                             $list = $user->listUsers();
                         } else {
                             $list = $rights->getGroupMembers($send_to);
                         }