Joomla 1.5 SEOGenerator неправильно отображает некоторые буквы (например Р)

Тема в разделе "Общие вопросы SEO", создана пользователем Aps95, 08.06.2009.

  1. Offline

    Aps95 Недавно здесь

    Регистрация:
    09.05.2009
    Сообщения:
    13
    Симпатии:
    0
    Пол:
    Мужской
    При генерации description, SEOGenerator некоторые буквы ,Р в частности, записывает ввиде вопроса, на сайте всё нормально, Но description выглядит ужасно, нехватало, чтобы google это выдавал в раздачу. Как исправить?
     
  2.  
  3. Offline

    Viperies Недавно здесь

    Регистрация:
    07.09.2008
    Сообщения:
    18
    Симпатии:
    0
    Re: SEOGenerator Неправельно отображает некоторые буквы (Р в частности и другие) UTF-8

    Тема актуальна, такие же проблемы, а плагин нужный :(

    Вот сам код
    Код (PHP):
    1. <?php
    2. /**
    3. * @author MCTrading (http://www.finanzen-nachrichten.com)
    4. * This plugin will automatically generate Keywords and Meta Description tags from your content and title.
    5. * version 1.0
    6. */
    7.  
    8. // no direct access
    9. defined( '_JEXEC' ) or die( 'Restricted access' );
    10.  
    11. // Import library dependencies
    12. jimport('joomla.event.plugin');
    13.  
    14. class plgSystemSEOGenerator extends JPlugin
    15. {
    16.  
    17.     // Constructor
    18.     function plgSystemSEOGenerator( &$subject, $params )
    19.     {
    20.         parent::__construct( $subject, $params );
    21.     }
    22.  
    23.     function onAfterDispatch()
    24.     {
    25.         global $mainframe, $thebuffer;
    26.         $document =& JFactory::getDocument();
    27.         $docType = $document->getType();
    28.  
    29.         // only mod site pages that are html docs (no admin, install, etc.)
    30.         if (!$mainframe->isSite()) return ;
    31.         if ($docType != 'html') return ;
    32.  
    33.         // load plugin parameters
    34.         $plugin =& JPluginHelper::getPlugin('system', 'SEOGenerator');
    35.         $pluginParams = new JParameter( $plugin->params );
    36.        
    37.         $titOrder = $pluginParams->def('titorder', 0);
    38.         $fptitle = $pluginParams->def('fptitle','Home');
    39.         $fptitorder = $pluginParams->def('fptitorder', 0);
    40.         $pageTitle = $document->getTitle();
    41.         $sitename = $mainframe->getCfg('sitename');
    42.         $sep = str_replace('\\','',$pluginParams->def('separator','|')); //Sets and removes Joomla escape char bug.
    43.        
    44.         if ($this->isFrontPage()):
    45.             if ($fptitorder == 0):
    46.                 $newPageTitle = $fptitle . ' ' . $sep . ' ' . $sitename;
    47.             elseif ($fptitorder == 1):
    48.                 $newPageTitle = $sitename . ' ' . $sep . ' ' . $fptitle;
    49.             elseif ($fptitorder == 2):
    50.                 $newPageTitle = $fptitle;
    51.             elseif ($fptitorder == 3):
    52.                 $newPageTitle = $sitename;
    53.             endif;
    54.         else:
    55.             if ($titOrder == 0):
    56.                 $newPageTitle = $pageTitle . ' ' . $sep . ' ' . $sitename;
    57.             elseif ($titOrder == 1):
    58.                 $newPageTitle = $sitename . ' ' . $sep . ' ' . $pageTitle;
    59.             elseif ($titOrder == 2):
    60.                 $newPageTitle = $pageTitle;
    61.             endif;
    62.         endif;
    63.  
    64.        
    65.         // Set the Title
    66.         $document->setTitle ($newPageTitle);
    67.  
    68.     }
    69.  
    70.     function onPrepareContent( &$article, &$params, $limitstart )
    71.     {
    72.         global $mainframe;
    73.  
    74.         $document =& JFactory::getDocument();
    75.         $plugin =& JPluginHelper::getPlugin('system', 'SEOGenerator');
    76.         $pluginParams = new JParameter( $plugin->params );
    77.         $blackList = $pluginParams->def('blacklist', '');
    78.         $minLength = $pluginParams->def('lengthofword', '3' );
    79.         $count = $pluginParams->def('count', '20' );
    80.         $saveAll = $pluginParams->def('regenerateall',1);
    81.         $title = $article->title;
    82.         $thelength = $pluginParams->def('length', 200);
    83.         $thecontent = $article->text;
    84.         $fpdesc = $pluginParams->def('fpdesc', 0);
    85.         $credit = $pluginParams->def('credittag', 0);
    86.  
    87.         //Checks to see whether FP should use standard desc or auto-generated one.
    88.         if ($this->isFrontPage() && $fpdesc == 0) {
    89.             $document->setDescription($mainframe->getCfg('MetaDesc'));
    90.             return;
    91.         }
    92.        
    93.         //Bit of code to grab only the first content item in category list.
    94.         if ($document->getDescription() != '') {
    95.             if ($document->getDescription() != $mainframe->getCfg('MetaDesc')) return;
    96.         }
    97.        
    98.         // Clean things up and prepare auto-generated Meta Description tag.
    99.         $thecontent = $this->CleanText($thecontent);
    100.  
    101.        
    102.         // Truncate the string to the length parameter - rounding to nearest word
    103.         $thecontent = $thecontent . ' ';
    104.         $thecontent = substr($thecontent,0,$thelength);
    105.         $thecontent = substr($thecontent,0,strrpos($thecontent,' '));
    106.  
    107.         // Set the description
    108.         $document->setDescription($thecontent);
    109.  
    110.     // Set the keywords
    111.     $keywords = $this->generatekeywords($title, $blackList, $count, $minLength);
    112.     $document->setMetaData('keywords', $keywords);
    113.  
    114.  
    115.     // save the modified keywords for all postings
    116.         if ($saveAll == 0) {
    117.             $db =& JFactory::getDBO();
    118.                 $query = "SELECT `id`, `sectionid`, `catid`, `title`, `created_by_alias`, `created_by` FROM #__content";
    119.                 $db->setQuery($query);
    120.                 $rows =  $db->loadAssocList();
    121.                 foreach ( $rows as $row ) {
    122.                                
    123.                         // create the keywords for the article
    124.                         $title = $row['title'];
    125.                         $keywords = $this->generatekeywords($title, $blackList, $count, $minLength);
    126.                      
    127.                         $query = "UPDATE #__content SET `metakey` = '" . $keywords . "' WHERE `id` = " . $row['id'];
    128.                         $db->setQuery($query);
    129.                         $db->query();                                  
    130.                 }
    131.      }
    132.  
    133.  
    134.         // Set optional Generator tag for SEOGenerator credit.
    135.         if ($credit == 0) {
    136.             $document->setMetaData('generator', 'SEOGenerator (http://www.finanzen-nachrichten.com)');
    137.         }
    138.        
    139.     }
    140.  
    141.    
    142.     /* CleanText function scooped from JoomSEO plugin. Cheers guys. */
    143.     function CleanText($text) {
    144.         // remove any javascript - OLLY
    145.         // http://forum.joomla.org/index.php?topic=194800.msg1036857
    146.         $regex = "'<script[^>]*?>.*?</script>'si";
    147.         $text = preg_replace($regex, " ", $text);
    148.         $regex = "'<noscript[^>]*?>.*?</noscript>'si";
    149.         $text = preg_replace($regex, " ", $text);
    150.    
    151.         // convert html entities to chars
    152.         // this doesnt remove &nbsp; but converts it to ascii 160
    153.         // we handle that further down changing chr(160) to a space
    154.         //$text = html_entity_decode($text,ENT_QUOTES,'UTF-8');
    155.         if(( version_compare( phpversion(), '5.0' ) < 0 )) {
    156.         require_once(JPATH_SITE.DS.'libraries'.DS.'tcpdf'.DS.'html_entity_decode_php4.php');
    157.         $text = html_entity_decode_php4($text,ENT_QUOTES,'UTF-8');
    158.         }else{
    159.         $text = html_entity_decode($text,ENT_QUOTES,'UTF-8');
    160.         }
    161.         // strip any remaining html tags
    162.         $text = strip_tags($text);
    163.        
    164.         // remove any mambot codes
    165.         $regex = '(\{.*?\})';
    166.         $text = preg_replace($regex, " ", $text);
    167.        
    168.         // convert newlines and tabs to spaces
    169.         $text = str_replace(array("\r\n", "\r", "\n", "\t", chr(160)), " ", $text);
    170.        
    171.         // remove any extra spaces
    172.         while (strchr($text,"  ")) {
    173.             $text = str_replace("  ", " ",$text);
    174.         }
    175.        
    176.         // general sentence tidyup
    177.         for ($cnt = 1; $cnt < strlen($text); $cnt++) {
    178.             // add a space after any full stops or comma's for readability
    179.             // added as strip_tags was often leaving no spaces
    180.             if (($text{$cnt} == '.') || ($text{$cnt} == ',')) {
    181.                 if ($text{$cnt+1} != ' ') {
    182.                     $text = substr_replace($text, ' ', $cnt + 1, 0);
    183.                 }
    184.             }
    185.         }
    186.        
    187.         // remove quotes
    188.         $text = str_replace("\"", "", $text);
    189.  
    190.         return trim($text);
    191.     }
    192.    
    193.     function isFrontPage()
    194.     {
    195.         $menu = & JSite::getMenu();
    196.         if ($menu->getActive() == $menu->getDefault()) {
    197.             return true;
    198.         }
    199.         return false;
    200.     }
    201.  
    202.     function killTitleinBuffer ($buff, $tit)
    203.     {
    204.         $cleanTitle = $buff;
    205.         if (substr($buff, 0, strlen($tit)) == $tit) {
    206.             $cleanTitle = substr($buff, strlen($tit) + 1);
    207.         }
    208.         return $cleanTitle;
    209.     }
    210.  
    211.   // generate keywords
    212.   function generatekeywords($title, $blackList, $count, $minLength) {
    213.  
    214.       $title = preg_replace('/<[^>]*>/', ' ', $title); 
    215.       $title = preg_replace('/[\.;:|\'|\"|\`|\,|\(|\)|\-]/', ' ', $title); 
    216.       $titleArray = explode(" ", $title);
    217.       $titleArray = array_count_values(array_map('strtolower', $titleArray));
    218.    
    219.     $blackArray = explode(",", $blackList);
    220.    
    221.       foreach($blackArray as $blackWord){
    222.           if(isset($titleArray[trim($blackWord)]))
    223.               unset($titleArray[trim($blackWord)]);
    224.       }
    225.    
    226.       arsort($titleArray);
    227.    
    228.       $i = 1;
    229.    
    230.       foreach($titleArray as $word=>$instances){
    231.           if($i > $count)
    232.               break;
    233.           if(strlen(trim($word)) >= $minLength ) {
    234.               $keywords .= $word . ", ";
    235.               $i++;
    236.           }
    237.       }
    238.    
    239.       $keywords = rtrim($keywords, ", ");
    240.       return($keywords);
    241.   }
    242.    
    243. }


    Вот что получается с description

    Код (html):
    1. <meta name="description" content="� � Оригинальное название: Tripping the Rift: The Movie Премьера: 25 марта 2008 (мир) � ежиссер: Bernie Denk Сценарий: Марк Амато, Кен" />
     
    Последнее редактирование: 12.07.2009
  4. Offline

    oppo Недавно здесь

    Регистрация:
    02.08.2006
    Сообщения:
    9
    Симпатии:
    0
    Пол:
    Мужской
    Re: SEOGenerator Неправельно отображает некоторые буквы (Р в частности и другие) UTF-8

    бегло вижу $titleArray = array_count_values(array_map('strtolower', $titleArray));

    strtolower неврно работает при русских буквах +utf-8
     
  5. Offline

    Daily Недавно здесь

    Регистрация:
    11.11.2009
    Сообщения:
    1
    Симпатии:
    0
    Пол:
    Мужской
    Re: SEOGenerator Неправельно отображает некоторые буквы (Р в частности и другие) UTF-8

    А если strtolower заменить на mb_strtolower ? :D
     

Поделиться этой страницей

Загрузка...