Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Pars error i class missing
Forum PHP.pl > Forum > Przedszkole
lustfingers
Próbuje wdrożyć ten dodatek:

  1. <?php
  2.  
  3. if (!defined('_PS_VERSION_')) exit;
  4.  
  5. class TD_Shortcode extends Module {
  6. protected static $initialized = false;
  7.  
  8. public function __construct() {
  9. $this->name = 'td_shortcode';
  10. $this->tab = 'front_office_feature';
  11. $this->version = 1.0;
  12. $this->author = 'Tung Dao';
  13. $this->need_instance = 0;
  14.  
  15. parent::__construct();
  16.  
  17. $this->displayName = $this->l('Shortcode plugin for Prestashop CMS Content.');
  18. $this->description = $this->l('Supported: , [slide] and [module].');
  19.  
  20. // The module could be initialized multiple times, this guard make sure
  21. // the plugins only be registered with Smarty once.
  22. if (!self::$initialized) {
  23. global $smarty;
  24.  
  25. self::$initialized = true;
  26.  
  27. $smarty->registerPlugin('modifier',
  28. 'b', array($this, 'smarty_modifier_b'));
  29.  
  30. $smarty->registerPlugin('modifier',
  31. 'module', array($this, 'smarty_modifier_module'));
  32. }
  33. }
  34.  
  35. public function install() {
  36. if (parent::install() == false ||
  37. $this->registerHook('displayHeader') == false) {
  38. return false;
  39. }
  40.  
  41. return true;
  42. }
  43.  
  44. public function hookDisplayHeader() {}
  45.  
  46.  
  47. /**
  48.   * [b] shortcode
  49.   *
  50.   * Usage: [b]Some text
  51.   */
  52. public function smarty_modifier_b($content) {
  53. return preg_replace_callback('/\[b\](.*?)\[\/b\]/ism',
  54. array($this, 'render_b'), $content);
  55. }
  56.  
  57. protected function render_b($text) {
  58. return sprintf('<b>%s</b>', $text[1]);
  59. }
  60.  
  61.  
  62. /**
  63.   * [module] shortcode.
  64.   * Inspired by <a href="http://www.ecartservice.net/prestashop-articles/tired-of-hooks-try-a-plugin-prestashop-1-4/" target="_blank">http://www.ecartservice.net/prestashop-art...prestashop-1-4/</a>
  65.   *
  66.   * Usage: [module name="" hook="" ...]
  67.   */
  68. public function smarty_modifier_module($content) {
  69. return preg_replace_callback('/\[module(.*?)\](.*?)\[\/module\]/ism',
  70. array($this, 'render_module'), $content);
  71. }
  72.  
  73. protected function render_module($text) {
  74. global $cart, $cookie;
  75.  
  76. $params = $this->parse_shortcode_atts($text[2]);
  77. if (!isset($params['cookie']) OR !$params['cookie'])
  78. $params['cookie'] = $cookie;
  79. if (!isset($params['cart']) OR !$params['cart'])
  80. $params['cart'] = $cart;
  81. $params['altern'] = 1;
  82.  
  83. $output = '';
  84. $instance = Module::getInstanceByName($params['name']);
  85. if (is_callable(array($instance, 'hook'.$params['hook'])))
  86. $output = call_user_func(array($instance,'hook'.$params['hook']), $params);
  87.  
  88. return $output;
  89. }
  90.  
  91. protected function parse_shortcode_atts($text) {
  92. // Copied from Wordpress
  93. // <a href="https://core.trac.wordpress.org/browser/tags/3.9.1/src/wp-includes/shortcodes.php#L306" target="_blank">https://core.trac.wordpress.org/browser/tag...tcodes.php#L306</a>
  94. $atts = array();
  95. $pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
  96. $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
  97. if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
  98. foreach ($match as $m) {
  99. if (!empty($m[1]))
  100. $atts[strtolower($m[1])] = stripcslashes($m[2]);
  101. elseif (!empty($m[3]))
  102. $atts[strtolower($m[3])] = stripcslashes($m[4]);
  103. elseif (!empty($m[5]))
  104. $atts[strtolower($m[5])] = stripcslashes($m[6]);
  105. elseif (isset($m[7]) and strlen($m[7]))
  106. $atts[] = stripcslashes($m[7]);
  107. elseif (isset($m[8]))
  108. $atts[] = stripcslashes($m[8]);
  109. }
  110. } else {
  111. $atts = ltrim($text);
  112. }
  113. return $atts;
  114. }
  115. }


Jednak dostaje komunikat:

td_shortcode (parse error in /modules/td_shortcode/td_shortcode.php)
td_shortcode (class missing in /modules/td_shortcode/td_shortcode.php)

niestety bez podanych linii błędów, mógłby ktoś rzucić okiem na to?
Rysh
Dokumentacja prestashop:
Cytat
'name' attribute. This attributes serves as an internal identifier. The value MUST be the name of the module's folder. Do not use special characters or spaces, and keep it lower-case.
lustfingers
Masz na myśli podkreślnik?

zmieniłem na
  1. $this->name = 'tdshortcode';
oraz nazwę pliku i folderu, błąd nadal identyczny czyli:

  1. tdshortcode (parse error in /modules/tdshortcode/tdshortcode.php)
  2. tdshortcode (class missing in /modules/tdshortcode/tdshortcode.php)


Podbijam, czy ktoś może mi wskazać czy i gdzie jest błąd?
Pyton_000
Nazwa pliku, nazwa klasy oraz atrybut Name powinny być identyczne.
lustfingers
Dzięki.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.