Esempio n. 1
0
 public static function convertInterwikiLinks($content)
 {
     $masks = sfConfig::get('app_nahoWikiPlugin_interwiki_links', array('[[%name% %title%]]', '[[%name%]]'));
     $pcre_masks = array('name' => '[a-z]+>' . nahoWikiPagePeer::pageNameFormat() . '(?:#[A-Za-z0-9_\\-]+)?', 'title' => '.*?');
     $replaces = self::extractLinkReplacements($content, $masks, $pcre_masks);
     // Complete the replacements array
     $interwiki = sfConfig::get('app_nahoWikiPlugin_interwiki', array());
     $web_root = sfContext::getInstance()->getRequest()->getRelativeUrlRoot();
     $dir_root = sfConfig::get('sf_web_dir');
     $plugin_dir = '/nahoWikiPlugin/images/';
     foreach ($replaces as &$replace) {
         list($key, $name) = explode('>', $replace['name'], 2);
         if (isset($interwiki[$key])) {
             $replace['link'] = $interwiki[$key] . rawurlencode($name);
             if ($replace['link']) {
                 $replace['alttext'] = $key;
                 $key = strtolower($key);
                 if (is_file($dir_root . ($image = $plugin_dir . 'interwiki/' . $key . '.png'))) {
                     $replace['image'] = $web_root . $image;
                 } elseif (is_file($dir_root . ($image = $plugin_dir . 'interwiki/' . $key . '.gif'))) {
                     $replace['image'] = $web_root . $image;
                 } elseif (is_file($dir_root . ($image = $plugin_dir . 'interwiki/' . $key . '.jpg'))) {
                     $replace['image'] = $web_root . $image;
                 } else {
                     $replace['image'] = $web_root . $plugin_dir . 'interwiki.png';
                 }
             }
             if (!$replace['title']) {
                 $replace['title'] = $name;
             }
         }
     }
     $link_model = sfConfig::get('app_nahoWikiPlugin_interwiki_link_model', '[![%alttext%](%image%) %title%](%link%)');
     return self::makeLinkReplacements($content, $replaces, $link_model);
 }