Esempio n. 1
0
 function xht_substitute($subtext, $cur_elem = 0, $pre = '', $post = '')
 {
     global $charset;
     $regs = array();
     // for use with ereg()
     if (!api_ereg(XHT_SUBS2, $subtext, $regs) && !api_ereg(XHT_SUBS1, $subtext, $regs)) {
         return $pre . $subtext . $post;
     }
     $type = $regs[1];
     $text = $regs[2];
     $result = '';
     $subnum = FALSE;
     $subtext = isset($regs[3]) ? $regs[3] : '';
     if ($this->xht_dbgn) {
         $subnum = ++$this->xht_dbgn;
         $this->xht_dbgo .= '<!-- ' . XHT_LP . $type . $subnum . '+ ' . htmlspecialchars($text, ENT_QUOTES, $charset) . ' ' . XHT_RP . $this->_show_param() . " -->\n";
     }
     if ($type == 'D') {
         // Assign the value to parameter [key]
         $this->xht_param[$text] = $subtext;
         // used to be:          = $this->xht_substitute($subtext, $cur_elem);
     } elseif ($type == 'E') {
         $result = call_user_func($text, FALSE);
         // get cached result, if any
         if ($result === FALSE) {
             $result = $this->xht_substitute($subtext, $cur_elem);
             $result = call_user_func($text, $result);
             // allow to cache
         }
     } elseif ($type == 'R') {
         $rdepthn = 'rdepth' . ++$this->xht_param['rdepth'];
         $n = 0;
         $this->xht_param['number'] = '0';
         if (is_array($a = $this->_lang($text, $cur_elem))) {
             foreach ($a as $key => $value) {
                 $this->xht_param['number'] = (string) ++$n;
                 $this->xht_param[$rdepthn] = (string) $n;
                 $this->xht_param['key'] = $key;
                 $this->xht_param['value'] = $value;
                 $result .= $this->xht_substitute($subtext, $cur_elem);
             }
         } elseif (xht_is_assoclist($a)) {
             foreach (xht_explode_assoclist($a) as $key => $value) {
                 $this->xht_param['number'] = (string) ++$n;
                 $this->xht_param[$rdepthn] = (string) $n;
                 $this->xht_param['key'] = $key;
                 $this->xht_param['value'] = $value;
                 $result .= $this->xht_substitute($subtext, $cur_elem);
             }
         } elseif (!is_object($this->xht_xmldoc)) {
             $result = '? R Error: no XML doc has been assigned to xht_xmldoc';
         } else {
             $sub_elems = $this->xht_xmldoc->xmd_select_elements($text, $cur_elem);
             foreach ($sub_elems as $subElem) {
                 $this->xht_param['number'] = (string) ++$n;
                 $this->xht_param[$rdepthn] = (string) $n;
                 $result .= $this->xht_substitute($subtext, $subElem);
             }
         }
         // removed 2004/10/05: template_array (security)
         // added   2005/03/08: associative list (lang arrays deprecated)
         $this->xht_param['rdepth']--;
         // As there is only one ['number'] or one set ['key'] + ['value'],
         // using them in nested repeats may not have the desired result.
     } elseif ($type == 'T') {
         if (api_ereg('^(=|==|<=|<|!=|<>|>|>=) +([^ ]+) +(.*)$', $subtext, $regs)) {
             // Comparand= parameter value if set, else languagevar value
             $cmp1 = isset($this->xht_param[$text]) ? $this->xht_param[$text] : $this->_lang($text, $cur_elem);
             $cmp3 = isset($this->xht_param[$cmp3 = $regs[2]]) ? $this->xht_param[$cmp3] : $this->_lang($cmp3, $cur_elem);
             $cmp = strcmp($cmp1, $cmp3);
             $op = ' ' . $regs[1] . ' ';
             if ($subnum) {
                 $this->xht_dbgo .= '<!-- ' . XHT_LP . $type . $subnum . '  ' . htmlspecialchars($cmp1 . $op . $cmp3 . ' = ' . $cmp, ENT_QUOTES, $charset) . ' ' . XHT_RP . " -->\n";
             }
             // debugging output
             if ($cmp < 0 && api_strpos('  <= < != <> ', $op) || $cmp == 0 && api_strpos('  = == <= >= ', $op) || $cmp > 0 && api_strpos('  != <> > >= ', $op)) {
                 $result = $this->xht_substitute($regs[3], $cur_elem);
             }
             // else $result is empty
         } else {
             $result = $pre . $subtext . $post;
         }
     } else {
         if (api_strpos('CLPVX', $type) !== FALSE) {
             // used to be always
             $text = $this->xht_substitute($text, $cur_elem);
         }
         // nested escape
         if ($type == 'C') {
             // Call, e.g. {-C SUBTEMPLATE-}
             $result = $this->xht_fill_template($text, $cur_elem);
         } elseif ($type == 'H') {
             $result = htmlspecialchars($text, ENT_QUOTES, $charset);
         } elseif ($type == 'L') {
             $result = $this->_lang($text, $cur_elem);
         } elseif ($type == 'P') {
             $result = $this->xht_param[$text];
         } elseif ($type == 'U') {
             $result = urlencode($text);
         } elseif ($type == 'W') {
             $result = xht_htmlwchars($text);
         } elseif (!is_object($this->xht_xmldoc)) {
             $result = '? V/X Error: no XML doc has been assigned to xht_xmldoc';
         } else {
             if (api_ereg('^(.*)=/(.+)$', $text, $regs)) {
                 $path = $regs[1];
                 $text = $regs[2];
                 if (api_substr($path, -1) == '/') {
                     $path = api_substr($path, 0, -1);
                 }
                 if ($path) {
                     $cur_elem = $this->xht_xmldoc->xmd_select_single_element($path, $cur_elem);
                 }
                 $cur_elem = call_user_func($this->xht_resource, $cur_elem);
             }
             $result = $type == 'V' ? $this->xht_xmldoc->xmd_value($text, $cur_elem) : $this->xht_xmldoc->xmd_html_value($text, $cur_elem, 'xht_htmlwchars');
         }
     }
     if ($subnum) {
         $this->xht_dbgo .= '<!-- ' . XHT_LP . $type . $subnum . '- ' . htmlspecialchars(api_strlen($result) <= 60 ? $result . ' ' : api_substr($result, 0, 57) . '...', ENT_QUOTES, $charset) . XHT_RP . " -->\n";
     }
     return $result;
 }
Esempio n. 2
0
 function mdo_add_breadcrump_nav()
 {
     global $interbreadcrumb, $langFormats;
     $regs = array();
     // for use with ereg()
     $docurl = api_get_self();
     // should be .../main/xxx/yyy.php
     if (ereg('^(.+[^/\\.]+)/[^/\\.]+/[^/\\.]+.[^/\\.]+$', $docurl, $regs)) {
         $docurl = $regs[1] . '/document/document.php';
     }
     $interbreadcrumb[] = array('url' => $docurl, "name" => get_lang('MdCallingTool'));
     if ($docpath = $this->mdo_path) {
         $docpath = substr($docpath, 0, strrpos($docpath, '/'));
         if (strlen($docpath) > 1) {
             $interbreadcrumb[] = array('url' => $docurl . '?curdirpath=' . urlencode($docpath) . ($this->mdo_group ? '&gidReq=' . $this->mdo_group : ''), "name" => htmlspecialchars(substr($docpath, strrpos($docpath, '/') + 1)));
         }
     }
     // Complete assoclist $langFormats from mime types
     require_once api_get_path(LIBRARY_PATH) . 'xht.lib.php';
     require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
     $sep = $langFormats[0] ? $langFormats[0] : ":";
     $arrFormats = xht_explode_assoclist($langFormats);
     foreach (DocumentManager::file_get_mime_type(TRUE) as $format) {
         if (!isset($arrFormats[$format])) {
             $langFormats .= ",, " . $format . $sep . $format;
         }
     }
     if (!isset($arrFormats["inode/directory"])) {
         $langFormats .= ",, inode/directory" . $sep . "inode/directory";
     }
     if (substr($langFormats, 0, 3) == ",, ") {
         $langFormats = $sep . substr($langFormats, 3);
     }
 }