PageRenderTime 45ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/system/sliders/helpers/replace.php

https://gitlab.com/che234/adn
PHP | 862 lines | 639 code | 192 blank | 31 comment | 86 complexity | 28f99e1c5aec2b1bc494fc44a5fbe896 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Sliders
  4. * @version 6.0.2
  5. *
  6. * @author Peter van Westen <info@regularlabs.com>
  7. * @link http://www.regularlabs.com
  8. * @copyright Copyright © 2016 Regular Labs All Rights Reserved
  9. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
  10. */
  11. defined('_JEXEC') or die;
  12. class PlgSystemSlidersHelperReplace
  13. {
  14. var $helpers = array();
  15. var $params = null;
  16. var $context = '';
  17. public function __construct()
  18. {
  19. require_once __DIR__ . '/helpers.php';
  20. $this->helpers = PlgSystemSlidersHelpers::getInstance();
  21. $this->params = $this->helpers->getParams();
  22. // Tag character start and end
  23. list($tag_start, $tag_end) = $this->getTagCharacters(true);
  24. // Break/paragraph start and end tags
  25. $this->params->breaks_start = RLTags::getRegexSurroundingTagPre(array('div', 'p', 'span', 'h[0-6]'));
  26. $this->params->breaks_end = RLTags::getRegexSurroundingTagPost(array('div', 'p', 'span', 'h[0-6]'));
  27. $breaks_start = $this->params->breaks_start;
  28. $breaks_end = $this->params->breaks_end;
  29. $inside_tag = RLTags::getRegexInsideTag();
  30. $this->params->tag_delimiter = ($this->params->tag_delimiter == 'space') ? RLTags::getRegexSpaces() : '=';
  31. $delimiter = $this->params->tag_delimiter;
  32. $sub_id = '(?:-[a-zA-Z0-9-_]+)?';
  33. $this->params->regex = '#'
  34. . '(?P<pre>' . $breaks_start . ')'
  35. . $tag_start . '(?P<tag>'
  36. . $this->params->tag_open . 's?' . '(?P<setid>' . $sub_id . ')' . $delimiter . '(?P<data>' . $inside_tag . ')'
  37. . '|/' . $this->params->tag_close . $sub_id
  38. . ')' . $tag_end
  39. . '(?P<post>' . $breaks_end . ')'
  40. . '#s';
  41. $this->params->regex_end = '#'
  42. . '(?P<pre>' . $breaks_start . ')'
  43. . $tag_start . '/' . $this->params->tag_close . $sub_id . $tag_end
  44. . '(?P<post>' . $breaks_end . ')'
  45. . '#s';
  46. $this->params->regex_link = '#'
  47. . $tag_start . $this->params->tag_link . $sub_id . $delimiter . '(?P<id>' . $inside_tag . ')' . $tag_end
  48. . '(?P<text>.*?)'
  49. . $tag_start . '/' . $this->params->tag_link . $tag_end
  50. . '#s';
  51. $this->ids = array();
  52. $this->matches = array();
  53. $this->allitems = array();
  54. $this->setcount = 0;
  55. $this->setMainParameters();
  56. }
  57. private function setMainParameters()
  58. {
  59. $this->mainclass = trim('rl_sliders nn_sliders accordion panel-group ' . $this->params->mainclass);
  60. }
  61. public function replaceTags(&$string, $area = 'article', $context = '')
  62. {
  63. if (!is_string($string) || $string == '')
  64. {
  65. return;
  66. }
  67. $this->context = $context;
  68. // Check if tags are in the text snippet used for the search component
  69. if (strpos($context, 'com_search.') === 0)
  70. {
  71. $limit = explode('.', $context, 2);
  72. $limit = (int) array_pop($limit);
  73. $string_check = substr($string, 0, $limit);
  74. if (
  75. strpos($string_check, $this->params->tag_character_start . $this->params->tag_open) === false
  76. && strpos($string_check, $this->params->tag_character_start . $this->params->tag_link) === false
  77. )
  78. {
  79. return;
  80. }
  81. }
  82. // allow in component?
  83. if (RLProtect::isRestrictedComponent(isset($this->params->disabled_components) ? $this->params->disabled_components : array(), $area))
  84. {
  85. $this->helpers->get('protect')->protect($string);
  86. $this->handlePrintPage($string);
  87. RLProtect::unprotect($string);
  88. return;
  89. }
  90. if (
  91. strpos($string, $this->params->tag_character_start . $this->params->tag_open) === false
  92. && strpos($string, $this->params->tag_character_start . $this->params->tag_link) === false
  93. )
  94. {
  95. // Links with #slider-name or &slider=slider-name
  96. $this->replaceLinks($string);
  97. return;
  98. }
  99. $this->helpers->get('protect')->protect($string);
  100. list($pre_string, $string, $post_string) = RLText::getContentContainingSearches(
  101. $string,
  102. array(
  103. $this->params->tag_character_start . $this->params->tag_open,
  104. $this->params->tag_character_start . $this->params->tag_link,
  105. ),
  106. array(
  107. $this->params->tag_character_start . '/' . $this->params->tag_close . $this->params->tag_character_end,
  108. $this->params->tag_character_start . '/' . $this->params->tag_link . $this->params->tag_character_end,
  109. )
  110. );
  111. if (JFactory::getApplication()->input->getInt('print', 0))
  112. {
  113. // Replace syntax with general html on print pages
  114. $this->handlePrintPage($string);
  115. $string = $pre_string . $string . $post_string;
  116. RLProtect::unprotect($string);
  117. return;
  118. }
  119. $sets = $this->getSets($string);
  120. $this->initSets($sets);
  121. // Tag syntax: {slider ...}
  122. $this->replaceSyntax($string, $sets);
  123. // Closing tag: {/slider}
  124. $this->replaceClosingTag($string);
  125. // Links with #slider-name or &slider=slider-name
  126. $this->replaceLinks($string);
  127. // Link tag {sliderlink ...}
  128. $this->replaceLinkTag($string);
  129. $string = $pre_string . $string . $post_string;
  130. RLProtect::unprotect($string);
  131. }
  132. private function handlePrintPage(&$string)
  133. {
  134. if (substr($this->params->regex, -1) != 'u' && @preg_match($this->params->regex . 'u', $string))
  135. {
  136. $this->params->regex .= 'u';
  137. }
  138. preg_match_all($this->params->regex, $string, $matches, PREG_SET_ORDER);
  139. if (!empty($matches))
  140. {
  141. foreach ($matches as $match)
  142. {
  143. $tag = RLText::cleanTitle($match['data'], false, false);
  144. $this->setTagValues($item, $tag);
  145. $title = isset($item->title) ? trim($item->title) : 'Slider';
  146. $title = preg_replace('#<\?h[0-9](\s[^>]* )?>#', '', $title);
  147. $replace = '<' . $this->params->title_tag . ' class="rl_sliders-title nn_sliders-title">'
  148. . $title
  149. . '</' . $this->params->title_tag . '>';
  150. $string = str_replace($match['0'], $replace, $string);
  151. }
  152. }
  153. preg_match_all($this->params->regex_end, $string, $matches, PREG_SET_ORDER);
  154. if (!empty($matches))
  155. {
  156. foreach ($matches as $match)
  157. {
  158. $string = str_replace($match['0'], '', $string);
  159. }
  160. }
  161. if (substr($this->params->regex_link, -1) != 'u' && @preg_match($this->params->regex_link . 'u', $string))
  162. {
  163. $this->params->regex_link .= 'u';
  164. }
  165. preg_match_all($this->params->regex_link, $string, $matches, PREG_SET_ORDER);
  166. if (!empty($matches))
  167. {
  168. foreach ($matches as $match)
  169. {
  170. $href = RLText::getURI($match['id']);
  171. $link = '<a href="' . $href . '">' . $match['text'] . '</a>';
  172. $string = str_replace($match['0'], $link, $string);
  173. }
  174. }
  175. }
  176. public function getSets(&$string, $only_basic_details = false)
  177. {
  178. if (substr($this->params->regex, -1) != 'u' && @preg_match($this->params->regex . 'u', $string))
  179. {
  180. $this->params->regex .= 'u';
  181. }
  182. preg_match_all($this->params->regex, $string, $matches, PREG_SET_ORDER);
  183. if (empty($matches))
  184. {
  185. return array();
  186. }
  187. $sets = array();
  188. $setids = array();
  189. foreach ($matches as $match)
  190. {
  191. if (substr($match['tag'], 0, 1) == '/')
  192. {
  193. array_pop($setids);
  194. continue;
  195. }
  196. end($setids);
  197. $item = new stdClass;
  198. // Set the values from the tag
  199. $tag = RLText::cleanTitle($match['data'], false, false);
  200. $this->setTagValues($item, $tag);
  201. if ($only_basic_details)
  202. {
  203. if (!isset($sets['basic']))
  204. {
  205. $sets['basic'] = array();
  206. }
  207. $sets['basic'][] = $item;
  208. continue;
  209. }
  210. $item->orig = $match['0'];
  211. $item->setid = trim(str_replace('-', '_', $match['setid']));
  212. if (empty($setids) || current($setids) != $item->setid)
  213. {
  214. $this->setcount++;
  215. $setids[$this->setcount . '.'] = $item->setid;
  216. }
  217. $item->set = str_replace('__', '_', array_search($item->setid, array_reverse($setids)) . $item->setid);
  218. if (!isset($sets[$item->set]))
  219. {
  220. $sets[$item->set] = array();
  221. }
  222. list($item->pre, $item->post) = RLTags::cleanSurroundingTags(
  223. array($match['pre'], $match['post']),
  224. array('div', 'p', 'span', 'h[0-6]')
  225. );
  226. $sets[$item->set][] = $item;
  227. }
  228. return $sets;
  229. }
  230. private function getParent(&$sets, $item, $prev_item, $setid, $prev_setid)
  231. {
  232. if (!$prev_item)
  233. {
  234. return '';
  235. }
  236. if (count($sets[$item->set]))
  237. {
  238. $last_item = end($sets[$item->set]);
  239. reset($sets[$item->set]);
  240. return $last_item->parent;
  241. }
  242. if ($prev_setid != $setid)
  243. {
  244. $sets[$prev_item->set][$prev_item->id]->children[] = $item->set;
  245. return $prev_item->set . $prev_item->id;
  246. }
  247. return '';
  248. }
  249. private function initSets(&$sets)
  250. {
  251. $urlitem = JFactory::getApplication()->input->get('slider');
  252. $itemcount = 0;
  253. foreach ($sets as $set_id => $items)
  254. {
  255. $opened_by_default = '';
  256. foreach ($items as $i => $item)
  257. {
  258. $item->title = isset($item->title) ? trim($item->title) : 'Slider';
  259. $item->title_full = $item->title;
  260. if (isset($item->{'title-opened'}) || isset($item->{'title-closed'}))
  261. {
  262. $title_closed = isset($item->{'title-closed'}) ? $item->{'title-closed'} : $item->title;
  263. $title_opened = isset($item->{'title-opened'}) ? $item->{'title-opened'} : $item->title;
  264. // Set main title to the title-opened, otherwise to title-closed
  265. $item->title = $title_opened ?: ($title_closed ?: $item->title);
  266. // place the title-opened and title-closed in css controlled spans
  267. $item->title_full = '<span class="rl_sliders-title-inactive nn_sliders-title-inactive">' . $title_closed . '</span>'
  268. . '<span class="rl_sliders-title-active nn_sliders-title-active">' . $title_opened . '</span>';
  269. }
  270. $item->haslink = preg_match('#<a [^>]*>.*?</a>#usi', $item->title);
  271. $item->title = RLText::cleanTitle($item->title, true);
  272. $item->title = $item->title ?: RLText::getAttribute('title', $item->title_full);
  273. $item->title = $item->title ?: RLText::getAttribute('alt', $item->title_full);
  274. $item->alias = RLText::createAlias(isset($item->alias) ? $item->alias : $item->title);
  275. $item->alias = $item->alias ?: 'slider';
  276. $item->id = $this->createId($item->alias);
  277. $item->set = (int) $set_id;
  278. $item->count = $i + 1;
  279. $set_keys = array(
  280. 'class', 'title_tag', 'onclick',
  281. );
  282. foreach ($set_keys as $key)
  283. {
  284. $item->{$key} = isset($item->{$key})
  285. ? $item->{$key}
  286. : (isset($this->params->{$key}) ? $this->params->{$key} : '');
  287. }
  288. $item->matches = RLText::createUrlMatches(array($item->id, $item->title));
  289. $item->matches[] = ++$itemcount . '';
  290. $item->matches[] = $item->set . '.' . ($i + 1);
  291. $item->matches[] = $item->set . '-' . ($i + 1);
  292. $item->matches = array_unique($item->matches);
  293. $item->matches = array_diff($item->matches, $this->matches);
  294. $this->matches = array_merge($this->matches, $item->matches);
  295. if ($this->itemIsOpen($item, $urlitem, $i == 0))
  296. {
  297. $opened_by_default = $i;
  298. }
  299. // Will be set after all items are checked based on the $opened_by_default id
  300. $item->open = false;
  301. $sets[$set_id][$i] = $item;
  302. $this->allitems[] = $item;
  303. }
  304. $this->setOpenItem($sets[$set_id], $opened_by_default);
  305. }
  306. }
  307. private function itemIsOpen($item, $urlitem, $is_first = false)
  308. {
  309. if ($item->haslink)
  310. {
  311. return false;
  312. }
  313. if (!empty($item->close))
  314. {
  315. return false;
  316. }
  317. if (isset($item->open))
  318. {
  319. return $item->open;
  320. }
  321. if ($urlitem && in_array($urlitem, $item->matches))
  322. {
  323. return true;
  324. }
  325. if ($is_first)
  326. {
  327. return true;
  328. }
  329. return false;
  330. }
  331. private function setOpenItem(&$items, $opened_by_default = '')
  332. {
  333. if ($opened_by_default === '')
  334. {
  335. return;
  336. }
  337. $opened_by_default = (int) $opened_by_default;
  338. while ($items[$opened_by_default]->haslink)
  339. {
  340. $opened_by_default++;
  341. }
  342. if (!isset($items[$opened_by_default]))
  343. {
  344. return;
  345. }
  346. $items[$opened_by_default]->open = true;
  347. }
  348. private function setTagValues(&$item, $string)
  349. {
  350. $values = $this->getTagValues($string);
  351. $item = (object) array_merge((array) $item, (array) $values);
  352. }
  353. private function getTagValues($string)
  354. {
  355. // Fix some different old syntaxes
  356. $string = str_replace(
  357. array(
  358. '|alias:',
  359. ),
  360. array(
  361. '|alias=',
  362. ),
  363. $string
  364. );
  365. $known_boolean_keys = array(
  366. 'open', 'active', 'opened', 'default',
  367. 'close', 'inactive', 'closed',
  368. 'scroll', 'noscroll',
  369. 'nooutline', 'outline_handles', 'outline_content', 'color_inactive_handles',
  370. );
  371. // Get the values from the tag
  372. $values = RLTags::getValuesFromString($string, 'title', $known_boolean_keys);
  373. $key_aliases = array(
  374. 'title' => array('name'),
  375. 'title-opened' => array('title-open', 'title-active'),
  376. 'title-closed' => array('title-close', 'title-inactive'),
  377. 'open' => array('active', 'opened', 'default'),
  378. 'close' => array('inactive', 'closed'),
  379. 'access' => array('accesslevels', 'accesslevel'),
  380. 'usergroup' => array('usergroups'),
  381. );
  382. RLTags::replaceKeyAliases($values, $key_aliases);
  383. if (!empty($values->close))
  384. {
  385. $values->open = false;
  386. unset($values->close);
  387. }
  388. return $values;
  389. }
  390. private function replaceSyntax(&$string, $sets)
  391. {
  392. if (!preg_match($this->params->regex_end, $string))
  393. {
  394. return;
  395. }
  396. foreach ($sets as $items)
  397. {
  398. $this->replaceSyntaxItemList($string, $items);
  399. }
  400. }
  401. private function replaceSyntaxItemList(&$string, $items)
  402. {
  403. $first = key($items);
  404. end($items);
  405. foreach ($items as $i => &$item)
  406. {
  407. $this->replaceSyntaxItem($string, $item, $items, ($i == $first));
  408. }
  409. }
  410. private function replaceSyntaxItem(&$string, $item, $items, $first = 0)
  411. {
  412. $s = '#' . preg_quote($item->orig, '#') . '#';
  413. if (@preg_match($s . 'u', $string))
  414. {
  415. $s .= 'u';
  416. }
  417. if (!preg_match($s, $string, $match))
  418. {
  419. return;
  420. }
  421. $html = array();
  422. $html[] = $item->post;
  423. $html[] = $item->pre;
  424. $html[] = $this->getPreHtml($items, $first);
  425. if (!in_array($this->context, array('com_search.search', 'com_finder.indexer')))
  426. {
  427. $html[] = '<div class="' . $this->getItemClass($item) . '">';
  428. $html[] = '<a id="rl_sliders-scrollto_' . $item->id . '" class="anchor rl_sliders-scroll nn_sliders-scroll"></a>';
  429. $html[] = '<div class="accordion-heading panel-heading">';
  430. $html[] = $this->getSliderTitle($item, $items);
  431. $html[] = '</div>';
  432. $body_class = 'accordion-body rl_sliders-body nn_sliders-body collapse';
  433. if ($item->open)
  434. {
  435. $body_class .= ' in';
  436. }
  437. $html[] = '<div class="' . $body_class . '" id="' . $item->id . '">';
  438. $html[] = '<div class="accordion-inner panel-body">';
  439. }
  440. $html[] = '<' . $item->title_tag . ' class="rl_sliders-title nn_sliders-title">'
  441. . preg_replace('#<\?h[0-9](\s[^>]* )?>#', '', $item->title_full)
  442. . '</' . $item->title_tag . '>';
  443. $html = implode("\n", $html);
  444. $string = RLText::strReplaceOnce($match['0'], $html, $string);
  445. }
  446. private function getItemClass($item)
  447. {
  448. $class = array('accordion-group panel rl_sliders-group nn_sliders-group');
  449. if ($item->open)
  450. {
  451. $class[] = 'active';
  452. }
  453. if (!empty($item->mode))
  454. {
  455. $class[] = $item->mode == 'hover' ? 'hover' : 'click';
  456. }
  457. $class[] = trim($item->class);
  458. return trim(implode(' ', $class));
  459. }
  460. private function getPreHtml($items, $first = 0)
  461. {
  462. if (!$first)
  463. {
  464. return '</div></div></div>';
  465. }
  466. $class = $this->mainclass;
  467. if (!empty($items['0']->mainclass))
  468. {
  469. $class .= ' ' . $items['0']->mainclass;
  470. }
  471. return '<div class="' . $class . '" id="set-rl_sliders-' . $items['0']->set . '">'
  472. . '<a id="rl_sliders-scrollto_' . $items['0']->set . '" class="anchor rl_sliders-scroll nn_sliders-scroll"></a>';
  473. }
  474. private function getSliderTitle($item, $items)
  475. {
  476. if ($item->haslink)
  477. {
  478. return $item->title_full;
  479. }
  480. $class = 'accordion-toggle rl_sliders-toggle nn_sliders-toggle';
  481. $onclick = '';
  482. $html = array();
  483. $html[] = '<a href="' . RLText::getURI($item->id) . '" class="' . $class . '"' . $onclick
  484. . ' data-toggle="collapse" data-id="' . $item->id . '" data-parent="#set-rl_sliders-' . $items['0']->set . '"'
  485. . '><span class="rl_sliders-toggle-inner nn_sliders-toggle-inner">';
  486. $html[] = $item->title_full;
  487. $html[] = '</span></a>';
  488. return implode("\n", $html);
  489. }
  490. private function replaceClosingTag(&$string)
  491. {
  492. preg_match_all($this->params->regex_end, $string, $matches, PREG_SET_ORDER);
  493. if (empty($matches))
  494. {
  495. return;
  496. }
  497. foreach ($matches as $match)
  498. {
  499. $html = '</div></div></div></div>';
  500. list($pre, $post) = RLTags::cleanSurroundingTags(array($match['pre'], $match['post']));
  501. $html = $pre . $html . $post;
  502. $string = RLText::strReplaceOnce($match['0'], $html, $string);
  503. }
  504. }
  505. private function replaceLinks(&$string)
  506. {
  507. // Links with #slider-name
  508. $this->replaceAnchorLinks($string);
  509. // Links with &slider=slider-name
  510. $this->replaceUrlLinks($string);
  511. }
  512. private function replaceAnchorLinks(&$string)
  513. {
  514. preg_match_all(
  515. '#(?P<link><a\s[^>]*href="(?P<url>([^"]*)?)\#(?P<id>[^"]*)"[^>]*>)(?P<text>.*?)</a>#si',
  516. $string,
  517. $matches,
  518. PREG_SET_ORDER
  519. );
  520. if (empty($matches))
  521. {
  522. return;
  523. }
  524. $this->replaceLinksMatches($string, $matches);
  525. }
  526. private function replaceUrlLinks(&$string)
  527. {
  528. preg_match_all(
  529. '#(?P<link><a\s[^>]*href="(?P<url>[^"]*)(?:\?|&(?:amp;)?)tab=(?P<id>[^"\#&]*)(?:\#[^"]*)?"[^>]*>)(?P<text>.*?)</a>#si',
  530. $string,
  531. $matches,
  532. PREG_SET_ORDER
  533. );
  534. if (empty($matches))
  535. {
  536. return;
  537. }
  538. $this->replaceLinksMatches($string, $matches);
  539. }
  540. private function replaceLinksMatches(&$string, $matches)
  541. {
  542. $uri = JUri::getInstance();
  543. $current_urls = array();
  544. $current_urls[] = $uri->toString(array('path'));
  545. $current_urls[] = $uri->toString(array('scheme', 'host', 'path'));
  546. $current_urls[] = $uri->toString(array('scheme', 'host', 'port', 'path'));
  547. foreach ($matches as $match)
  548. {
  549. $link = $match['link'];
  550. if (
  551. strpos($link, 'data-toggle=') !== false
  552. || strpos($link, 'onclick=') !== false
  553. || strpos($link, 'rl_sliders-link') !== false
  554. || strpos($link, 'rl_tabs-toggle-sm') !== false
  555. || strpos($link, 'rl_tabs-link') !== false
  556. )
  557. {
  558. continue;
  559. }
  560. $url = $match['url'];
  561. if (strpos($url, 'index.php/') === 0)
  562. {
  563. $url = '/' . $url;
  564. }
  565. if (strpos($url, 'index.php') === 0)
  566. {
  567. $url = JRoute::_($url);
  568. }
  569. if ($url != '' && !in_array($url, $current_urls))
  570. {
  571. continue;
  572. }
  573. $id = $match['id'];
  574. if (!$this->stringHasItem($string, $id))
  575. {
  576. // This is a link to a normal anchor or other element on the page
  577. // Remove the prepending obsolete url and leave the hash
  578. // $string = str_replace('href="' . $match['url'] . '#' . $id . '"', 'href="#' . $id . '"', $string);
  579. continue;
  580. }
  581. $attribs = $this->getLinkAttributes($id);
  582. // Combine attributes with original
  583. $attribs = RLText::combineAttributes($link, $attribs);
  584. $html = '<a ' . $attribs . '><span class="rl_sliders-link-inner nn_sliders-link-inner">' . $match['text'] . '</span></a>';
  585. $string = str_replace($match['0'], $html, $string);
  586. }
  587. }
  588. private function replaceLinkTag(&$string)
  589. {
  590. if (substr($this->params->regex_link, -1) != 'u' && @preg_match($this->params->regex_link . 'u', $string))
  591. {
  592. $this->params->regex_link .= 'u';
  593. }
  594. preg_match_all($this->params->regex_link, $string, $matches, PREG_SET_ORDER);
  595. if (empty($matches))
  596. {
  597. return;
  598. }
  599. foreach ($matches as $match)
  600. {
  601. $this->replaceLinkTagMatch($string, $match);
  602. }
  603. }
  604. private function replaceLinkTagMatch(&$string, $match)
  605. {
  606. $id = RLText::createAlias($match['id']);
  607. if (!$this->stringHasItem($string, $id))
  608. {
  609. $id = $this->findItemByMatch($match['id']);
  610. }
  611. if (!$this->stringHasItem($string, $id))
  612. {
  613. $html = '<a href="' . RLText::getURI($id) . '">' . $match['text'] . '</a>';
  614. $string = RLText::strReplaceOnce($match['0'], $html, $string);
  615. return;
  616. }
  617. $html = '<a ' . $this->getLinkAttributes($id) . '>'
  618. . '<span class="rl_sliders-link-inner nn_sliders-link-inner">' . $match['text'] . '</span>'
  619. . '</a>';
  620. $string = RLText::strReplaceOnce($match['0'], $html, $string);
  621. }
  622. private function findItemByMatch($id)
  623. {
  624. foreach ($this->allitems as $item)
  625. {
  626. if (!in_array($id, $item->matches))
  627. {
  628. continue;
  629. }
  630. return $item->id;
  631. }
  632. return $id;
  633. }
  634. private function getLinkAttributes($id)
  635. {
  636. return 'href="' . RLText::getURI($id) . '"'
  637. . ' class="rl_sliders-link rl_sliders-link-' . $id . ' nn_sliders-link nn_sliders-link-' . $id . '"'
  638. . ' data-id="' . $id . '"';
  639. }
  640. private function stringHasItem(&$string, $id)
  641. {
  642. return (strpos($string, 'data-toggle="collapse" data-id="' . $id . '"') !== false);
  643. }
  644. private function createId($alias)
  645. {
  646. $id = $alias;
  647. $i = 1;
  648. while (in_array($id, $this->ids))
  649. {
  650. $id = $alias . '-' . ++$i;
  651. }
  652. $this->ids[] = $id;
  653. return $id;
  654. }
  655. public function getTagCharacters($quote = false)
  656. {
  657. if (!isset($this->params->tag_character_start))
  658. {
  659. list($this->params->tag_character_start, $this->params->tag_character_end) = explode('.', $this->params->tag_characters);
  660. }
  661. $start = $this->params->tag_character_start;
  662. $end = $this->params->tag_character_end;
  663. if ($quote)
  664. {
  665. $start = preg_quote($start, '#');
  666. $end = preg_quote($end, '#');
  667. }
  668. return array($start, $end);
  669. }
  670. }