/**
  * Simple fonction de get pour tester les URL significatives
  */
 public function get($dest, $parameters, $mode)
 {
     $toReturn = new CopixUrlHandlerGetResponse();
     if ($dest['module'] == 'copixtest' && $dest['group'] == 'google') {
         $toReturn->externUrl = 'http://www.google.fr';
         return $toReturn;
     }
     if (isset($parameters['var'])) {
         $toReturn->path = array_merge($dest, array('var' => CopixUrl::escapeSpecialChars($parameters['var'])));
         unset($parameters['var']);
     }
     $toReturn->vars = $parameters;
     return $toReturn;
 }
 /**
  * Recupère les éléments de l'URL
  *
  * @param $dest
  * @param $parameters
  * @param $mode
  * @return StdClass object
  */
 public function get($dest, $parameters, $mode)
 {
     if ($mode == 'none') {
         return false;
     } else {
         $toReturn = new stdClass();
         if (isset($parameters['wsname'])) {
             $toReturn->path = array_merge($dest, array('wsname' => CopixUrl::escapeSpecialChars($parameters['wsname'])));
             unset($parameters['wsname']);
         } else {
             $toReturn->path = $dest;
         }
         $toReturn->vars = $parameters;
         return $toReturn;
     }
 }
예제 #3
0
 public function cleanCode(&$content, $title = "")
 {
     $content = preg_replace('/<</', '&laquo;', $content);
     $content = preg_replace('/>>/', '&raquo;', $content);
     $content = preg_replace('/\\(c\\)/', '&copy;', $content);
     $content = preg_replace('/\\(r\\)/', '&reg;', $content);
     $content = preg_replace('/¿/', '&iquest;', $content);
     //money
     $content = preg_replace('/€/', '&euro;', $content);
     $content = preg_replace('/¥/', '&yen;', $content);
     $content = preg_replace('/¢/', '&cent;', $content);
     $content = preg_replace('/£/', '&pound;', $content);
     //arrows
     $content = preg_replace('/-->/', '&rarr;', $content);
     $content = preg_replace('/<--/', '&larr;', $content);
     $content = preg_replace('/<->/', '&harr;', $content);
     $content = preg_replace('/==>/', '&rArr;', $content);
     $content = preg_replace('/<==/', '&lArr;', $content);
     $content = preg_replace('/<=>/', '&hArr;', $content);
     //math
     //$content = preg_replace('/`(.*?)`/', '&\\1;', $content);
     $content = preg_replace('/=</', '&le;', $content);
     $content = preg_replace('/>=/', '&ge;', $content);
     $content = preg_replace('/!=/', '&ne;', $content);
     $content = preg_replace('/~=/', '&cong;', $content);
     //remove tags
     $content = str_replace('<', '_lower_', $content);
     $content = str_replace('>', '_greater_', $content);
     //now replace _lower_ and _greater_ codes...
     $content = str_replace('_lower_', '&lt;', $content);
     $content = str_replace('_greater_', '&gt;', $content);
     //recreate some tags
     $content = str_replace('_end_strike_', "</del>", $content);
     $content = str_replace('_strike_', "<del>", $content);
     //rule
     $content = preg_replace('/\\n*\\-{4}\\n*/', "<hr />", $content);
     //code
     $content = preg_replace('/\'\'(.*?)\'\'/', "<code>\\1</code>", $content);
     //links
     $links = array();
     preg_match_all('/\\[\\[(.*?)\\]\\]/', $content, $links);
     $foundlinks = $links[1];
     $i = 0;
     foreach ($foundlinks as $foundlink) {
         //seek if we have | to set caption
         $elem = explode("|", $foundlink);
         $link = $elem[0];
         $caption = isset($elem[1]) ? $elem[1] : $elem[0];
         $style = "wiki_exists";
         //anchors
         $anchor = explode("#", $link);
         $link = strlen($anchor[0]) ? $anchor[0] : $title;
         if (isset($anchor[1])) {
             $anchor = $anchor[1];
         } else {
             $anchor = "";
         }
         //is it an external link ?
         if (!preg_match('/http:/', $link)) {
             //no, so i think this is a wiki link
             //page exists ?
             $parts = explode('/', $link);
             $heading = '';
             $lang = '';
             if (count($parts) == 3) {
                 $heading = $parts[0];
                 $link = $parts[1];
             } elseif (count($parts) == 2) {
                 $heading = $parts[0];
                 $link = $parts[1];
             }
             $dao = _ioDao('wikipages');
             $res = $dao->findBy(_daoSp()->startGroup()->addCondition('title_wiki', "=", CopixUrl::escapeSpecialChars($link))->addCondition('heading_wiki', '=', $heading)->endGroup());
             if (!$res) {
                 $style = "wiki_no_exists";
             } else {
                 $anchor = preg_replace("/[^a-zA-Z0-9]/", $this->anchor_separator, $anchor);
             }
             $link = _url('wiki||show', array('title' => $link, 'heading' => $heading));
         }
         $link .= isset($anchor) && strlen($anchor) ? "#" . $anchor : "";
         //now, replace link
         $link = "<a href=\"" . $link . "\" title=\"" . $caption . "\" class=\"{$style}\">{$caption}</a>";
         //link has "//" but this is used for italic... so we have to
         //change it for now... see end function to restore links
         $link = str_replace("//", "_double_slashes_", $link);
         $content = str_replace($links[0][$i], $link, $content);
         $i++;
     }
     //images
     $images = array();
     preg_match_all('/\\{\\{(.*?)\\}\\}/', $content, $images);
     $foundimages = $images[1];
     $i = 0;
     foreach ($foundimages as $foundimg) {
         $elem = explode(":", $foundimg);
         if ($elem[0] == "file") {
             //case of file
             $class = "wiki_dl_file";
             $image = "<a href=\"" . _url('wiki|file|getfile', array('title' => $elem[1])) . "\" title=\"" . $elem[1] . "\" class=\"{$class}\">" . $elem[1] . "</a>";
         } else {
             $elem = explode("|", $foundimg);
             $foundimg = $elem[0];
             $width = isset($elem[1]) ? $elem[1] : "";
             $align = isset($elem[2]) ? $elem[2] : "";
             $disp = "";
             //is it an external link ?
             if (preg_match('/http:/', $foundimg)) {
                 $alt = explode("/", $foundimg);
                 $alt = $alt[count($alt) - 1];
                 $alt = explode('.', $alt);
                 $alt = $alt[0];
                 if ($width) {
                     //$disp = '<a href="' . $foundimg . '" target="_blank" title="' . _i18n ("wiki|wiki.show.fullsize") . '">(-)</a>';
                     $icon = "<img src=\"" . _resource('img/tools/loupe.png') . "\" alt=\"download\"/>";
                     $disp = '<a href="' . $foundimg . '" target="_blank" title="' . _i18n("wiki|wiki.show.fullsize") . '">' . $icon . '</a>';
                     $disp = "<span style=\"height:15px;margin-left: -15px;\">{$disp}</span>";
                 }
             } else {
                 //no, so i think this is a wiki link
                 $alt = $foundimg;
                 $foundimg = _url('wiki|file|getFile', array('title' => $alt, 'size' => $width));
                 $_foundimg = _url('wiki|file|getFile', array('title' => $alt));
                 //$_foundimg="javascript:WikiSeeImage('$_foundimg','$alt')";
                 $_foundimg = '<a href="' . $_foundimg . '" rel="lightbox[' . $title . ']" title="' . $alt . '">';
                 if ($width) {
                     $icon = "<img src=\"" . _resource("img/tools/loupe.png") . "\" alt=\"download\" style=\"z-index: 99\" />";
                     $disp = $_foundimg . $icon . "</a>";
                     $disp = "<span style=\"height:20px;margin-left: -15px;\">{$disp}</span>";
                 }
                 if (function_exists("gd_info")) {
                     $width = "";
                     //because gd resized image
                 }
             }
             if (strlen($align) > 0) {
                 $align = ' align="' . $align . '"';
             }
             if (strlen($width) > 0) {
                 $width = ' width="' . $width . '"';
             }
             $image = "";
             $image = "<span style=\"display: inline\">";
             $image .= '<img name="wiki_image" src="' . $foundimg . '"' . $width . $align . ' alt="' . $alt . '" />';
             $image .= $disp . "</span>";
         }
         $content = str_replace($images[0][$i], $image, $content);
         $i++;
     }
     //footnotes
     preg_match_all('/\\(\\((.*?)\\)\\)/', $content, $fn);
     $fns = $fn[1];
     $i = count($this->footnotes);
     $j = 0;
     foreach ($fns as $footnote) {
         $this->footnotes[] = $footnote;
         $content = str_replace($fn[0][$j], "<a href=\"#wiki_footnotes\" title=\"{$footnote}\"><sup>" . ($i + 1) . "</sup></a>", $content);
         $i++;
         $j++;
     }
     //other
     $content = preg_replace('/\\*{2}(.*?)\\*{2}/', "<strong>\\1</strong>", $content);
     $content = str_replace("http://", "_URI_STRING_", $content);
     $content = preg_replace('/\\/{2}(.*?)\\/{2}/', "<em>\\1</em>", $content);
     $content = str_replace("_URI_STRING_", "http://", $content);
     $content = preg_replace('/_{2}(.*?)_{2}/', "<u>\\1</u>", $content);
     //sup
     $content = preg_replace('/(.+?)\\^\\((.+?)\\)/', '\\1<sup>\\2</sup>', $content);
     $content = preg_replace('/sqrt\\((.+?)\\)/', ' &radic;<span style="text-decoration: overline">\\1</span>', $content);
     //last modification:
     //$content = preg_replace("/(\s)+/", "\\1", $content);
     $content = str_replace("<br>", "<br />", $content);
     $content = preg_replace('/<h(\\d)><br \\/>/', "<h\\1>", $content);
     $content = str_replace("_double_slashes_", "//", $content);
 }
 public function testEscapeSpecialChars()
 {
     $pString = 'àéïöùy';
     $this->assertEquals(CopixUrl::escapeSpecialChars($pString), 'aeiouy');
     $this->assertEquals(CopixUrl::escapeSpecialChars('Une ville du sud'), 'Une_ville_du_sud');
     $this->assertEquals(CopixUrl::escapeSpecialChars('Une ville / Un Village'), 'Une_ville__Un_Village');
     $this->assertEquals(CopixUrl::escapeSpecialChars('Une ville / Un Village', true), 'Une_ville_Un_Village');
 }