#1 22. 1. 2007 15:35

Sean.cz
Nový člen
Místo: Praha
Registrovaný: 18. 4. 2005
Příspěvky: 9
Web

Problém při tvorbě Texy Plugin pro b2evo 1.9.2

Rád bych změnil svůj redakční systém (nyní BLOG:CMS) a moc se mi líbí b2evo v aktuální verzi 1.9.2. Protože ale Texy! používám už od samého začátku, je pro mne problém v něm nepsat. A to je kámen úrazu, neboť starý Texy! plugin pro b2evo 0.9 již nefunguje (pravděpodobně kvůli zásadní změně v API pro pluginy).

Přesto bych rád přemigroval a tak jsem začal pracovat na úpravě pluginu pro b2evo verzi 1.9.2. Bohužel nejsem programátor a tak je to z mé strany spíše jen tušení souvislostí než koncepční práce, proto bych potřeboval radu, jak odstranit chyby.

Abych vás uvedl do problému:

  • ze souborů _texy.renderer.php a _texy.conf.php jsem vytvořil soubor _texy.plugin.php
  • kromě souboru _texy.plugin.php v adresáři plugins existuje adresář texy_plugin obsahující podadresáře cache a fshl a soubor texy-compact.php

Zde je zdrojový kód mého nefunkčního Texy! pluginu:

<?php

/*
 *   Texy! plugin for b2evolution
 *   ----------------------------
 *   http://www.texy.info
 *
 *   Copyright (c) David Grudl, 2005
 *
 *   This will allow you to type up items using Texy! (www.texy.info).
 *
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

/**
 * Includes:
 */
require_once dirname(__FILE__).'/texy_plugin/texy-compact.php';
require_once dirname(__FILE__).'/texy_plugin/fshl/fshl.php';


/**
 * @package plugins
 */
class texy_plugin extends Plugin
{
  var $code = 'b2Texy';
  var $name = 'Texy!';
  var $priority = 90;
  var $version = '1.9-dev';
  var $apply_rendering = 'opt-in';
  var $short_desc;
  var $long_desc;

  var $texy;
  var $cachePath;
  var $enableSmilies = false;
  var $enableFSHL    = true;

  /**
   * Init
   */
  function PluginInit( & $params )
  {
    $this->short_desc = T_('Texy! humane formatting');
    $this->long_desc = T_('No description available' );
    $this->cachePath = dirname(__FILE__) . '/texy_plugin/cache/';
    $this->texy = &new Texy();
    $this->texy->utf = true;

    # classes for left- or right- aligned images
    $this->texy->imageModule->leftClass   = 'left';
    $this->texy->imageModule->rightClass  = 'right';

    # definition for image root
    $this->texy->imageModule->root = '';
    $this->texy->imageModule->linkedRoot = '';
    $this->texy->headingModule->top = 1;

    if ($this->enableSmilies) {
      $this->texy->smiliesModule->allowed =  true;
      $this->texy->smiliesModule->root    =  ''; // ???
      $this->texy->smiliesModule->class   = 'smiley';
    }

    if ($this->enableFSHL && class_exists('fshlParser')) {
      $this->texy->blockModule->codeHandler = array(&$this, 'callbackSyntaxHighlight');
    }
  }


// -------------------------------------------------------------
  /**
   * Perform rendering
   *
   * @param string content to render (by reference) / rendered content
   * @param string Output format, see {@link format_to_output()}
   * @return boolean true if we can render something for the required output format
   */
  function RenderItemAsHtml( & $content, $format )
  {
    if( ! parent::RenderItemAsHtml( $content, $format ) ) {
      // We cannot render the required format
      return false;
    }

    $md5 = md5($content); // md5 is key for caching

    // check, if cached file exists
    $cacheFile = $this->cachePath . $md5 . '.html';
    $cache = is_file($cacheFile) ? unserialize(file_get_contents($cacheFile)) : null;
    if ($cache) {         // read from cache
      list($content, $this->texy->styleSheet) = $cache;

    } else {                           // doesn't exists
      $content = $this->texy->process($content);
      if (is_writable($this->cachePath))
        fwrite(fopen($cacheFile, 'w'),
          serialize( array($content, $this->texy->styleSheet) )
      );
    }
  }


  // this is user callback function for processing inlin `code` or block @code
  function callbackSyntaxHighlight(&$element)
  {
    $lang = strtoupper($element->lang);
    if ($lang == 'JAVASCRIPT') $lang = 'JS';

    if (in_array($lang, array('CPP', 'CSS', 'HTML', 'JAVA', 'PHP', 'JS', 'SQL'))) {
      $parser = new fshlParser($element->texy->utf ? 'HTML_UTF8' : 'HTML', P_TAB_INDENT);
      $element->setContent($parser->highlightString($lang, $element->content), true);
    }
  }

} // end class


/*
 nolog */
?>

Počáteční problémy se zcela úplně nefunkčním pluginem blokujícím použití modulu Plugins už jsem snad odstranil, narazil jsem ale na další problém a tady už začínám být se svými vědomostmi v koncích.

Při použití Texy! syntaxe v článku dostanu následující chybovou hlášku:

Warning: Missing argument 2 for renderitemashtml() in /www/snor/www/komunikatory/dev/plugins/_texy.plugin.php on line 80

Je to v definici funkce RenderItemAsHtml, bohužel nevím, co je špatně .. d8-\
Každopádně se zobrazí pouze zdrojový zápis v Texy! bez jakýchkoliv úprav .. d8-\

Prosím poraďte. Díky.

Offline

 

#2 2. 2. 2007 9:20

Sean.cz
Nový člen
Místo: Praha
Registrovaný: 18. 4. 2005
Příspěvky: 9
Web

Re: Problém při tvorbě Texy Plugin pro b2evo 1.9.2

Tak poroblémky s nefunkčností pluginu jsou diky pomoci z b2evo fora vyřešeny a funkční verze je k dispozici na Download stránce.

Offline

 

Zápatí

Reklama: Školení PHP | Magento