PageRenderTime 866ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_acymailing/extensions/plg_acymailing_tablecontents/tablecontents.php

https://github.com/srgg6701/auction-ruseasons
PHP | 240 lines | 195 code | 37 blank | 8 comment | 36 complexity | 345eecf1401cb6895d5783ee49e9c85c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-3-Clause, JSON
  1. <?php
  2. /**
  3. * @package AcyMailing for Joomla!
  4. * @version 4.1.0
  5. * @author acyba.com
  6. * @copyright (C) 2009-2013 ACYBA S.A.R.L. All rights reserved.
  7. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
  8. */
  9. defined('_JEXEC') or die('Restricted access');
  10. ?><?php
  11. defined('_JEXEC') or die('Restricted access');
  12. class plgAcymailingTablecontents extends JPlugin
  13. {
  14. var $noResult = array();
  15. function plgAcymailingTablecontents(&$subject, $config){
  16. parent::__construct($subject, $config);
  17. if(!isset($this->params)){
  18. $plugin = JPluginHelper::getPlugin('acymailing', 'tablecontents');
  19. $this->params = new JParameter( $plugin->params );
  20. }
  21. }
  22. function acymailing_getPluginType() {
  23. $onePlugin = new stdClass();
  24. $onePlugin->name = JText::_('ACY_TABLECONTENTS');
  25. $onePlugin->function = 'acymailingtablecontents_show';
  26. $onePlugin->help = 'plugin-tablecontents';
  27. return $onePlugin;
  28. }
  29. function acymailingtablecontents_show(){
  30. $contenttype = array();
  31. $contenttype[] = JHTML::_('select.option', '',JText::_('ACY_EXISTINGANCHOR'));
  32. for($i = 1;$i<6;$i++){
  33. $contenttype[] = JHTML::_('select.option', "|type:h".$i,'H'.$i);
  34. }
  35. $contenttype[] = JHTML::_('select.option', 'class',JText::_('CLASS_NAME'));
  36. $contentsubtype = array();
  37. $contentsubtype[] = JHTML::_('select.option', '',JText::_('ACY_NONE'));
  38. for($i = 1;$i<6;$i++){
  39. $contentsubtype[] = JHTML::_('select.option', "|subtype:h".$i,'H'.$i);
  40. }
  41. $contentsubtype[] = JHTML::_('select.option', 'class',JText::_('CLASS_NAME'));
  42. ?>
  43. <script language="javascript" type="text/javascript">
  44. <!--
  45. function updateTag(){
  46. var tag = '{tableofcontents';
  47. if(document.adminForm.contenttype.value){
  48. if(document.adminForm.contenttype.value == 'class'){
  49. document.adminForm.classvalue.style.display = '';
  50. tag += '|class:'+document.adminForm.classvalue.value;
  51. }else{
  52. document.adminForm.classvalue.style.display = 'none';
  53. tag += document.adminForm.contenttype.value;
  54. }
  55. }
  56. if(document.adminForm.contentsubtype.value){
  57. if(document.adminForm.contentsubtype.value == 'class'){
  58. document.adminForm.subclassvalue.style.display = '';
  59. tag += '|subclass:'+document.adminForm.subclassvalue.value;
  60. }else{
  61. document.adminForm.subclassvalue.style.display = 'none';
  62. tag += document.adminForm.contentsubtype.value;
  63. }
  64. }
  65. tag += '}';
  66. setTag(tag);
  67. }
  68. //-->
  69. </script>
  70. <table width="100%" class="adminform">
  71. <tr><td colspan="2"><?php echo JText::_('ACY_GENERATEANCHOR'); ?></td></tr>
  72. <tr><td><?php echo JText::sprintf('ACY_LEVEL',1)?></td><td><?php echo JHTML::_('select.genericlist', $contenttype, 'contenttype' , 'size="1" onchange="updateTag();"', 'value', 'text'); ?><input type="text" style="display:none" onchange="updateTag();" name="classvalue" /></td></tr>
  73. <tr><td><?php echo JText::sprintf('ACY_LEVEL',2)?></td><td><?php echo JHTML::_('select.genericlist', $contentsubtype, 'contentsubtype' , 'size="1" onchange="updateTag();"', 'value', 'text'); ?><input type="text" style="display:none" onchange="updateTag();" name="subclassvalue" /></td></tr>
  74. </table>
  75. <?php
  76. $doc = JFactory::getDocument();
  77. $doc->addScriptDeclaration("window.addEvent('domready', function(){ updateTag(); });");
  78. }
  79. function acymailing_replaceusertags(&$email,&$user,$send = true){
  80. if(isset($this->noResult[intval($email->mailid)])) return;
  81. $match = '#{tableofcontents(.*)}#Ui';
  82. $variables = array('body','altbody');
  83. $found = false;
  84. foreach($variables as $var){
  85. if(empty($email->$var)) continue;
  86. $found = preg_match_all($match,$email->$var,$results[$var]) || $found;
  87. if(empty($results[$var][0])) unset($results[$var]);
  88. }
  89. if(!$found){
  90. $this->noResult[intval($email->mailid)] = true;
  91. return;
  92. }
  93. $mailerHelper = acymailing_get('helper.mailer');
  94. $htmlreplace = array();
  95. $textreplace = array();
  96. foreach($results as $var => $allresults){
  97. foreach($allresults[0] as $i => $oneTag){
  98. if(isset($htmlreplace[$oneTag])) continue;
  99. $article = $this->_generateTable($allresults,$i,$email);
  100. $htmlreplace[$oneTag] = $article;
  101. $textreplace[$oneTag] = $mailerHelper->textVersion($article);
  102. }
  103. }
  104. $email->body = str_replace(array_keys($htmlreplace),$htmlreplace,$email->body);
  105. $email->altbody = str_replace(array_keys($textreplace),$textreplace,$email->altbody);
  106. }
  107. function _generateTable(&$results,$i,&$email){
  108. $arguments = explode('|',strip_tags($results[1][$i]));
  109. $tag = new stdClass();
  110. $tag->divider = $this->params->get('divider','br');
  111. $tag->before = '';
  112. $tag->after = '';
  113. $tag->subdivider = $this->params->get('divider','br');
  114. $tag->subbefore = '';
  115. $tag->subafter = '';
  116. for($i=1,$a=count($arguments);$i<$a;$i++){
  117. $args = explode(':',$arguments[$i]);
  118. if(isset($args[1])){
  119. $tag->$args[0] = $args[1];
  120. }else{
  121. $tag->$args[0] = true;
  122. }
  123. }
  124. if($tag->divider == 'br'){
  125. $tag->divider = '<br />';
  126. $tag->subbefore = $tag->subdivider = '<br /> - ';
  127. }elseif($tag->divider == 'space'){
  128. $tag->subdivider = ', ';
  129. $tag->divider = ' ';
  130. $tag->subbefore = ' ( ';
  131. $tag->subafter = ' ) ';
  132. }elseif($tag->divider == 'li'){
  133. $tag->subdivider = $tag->divider = '</li><li>';
  134. $tag->subbefore = $tag->before = '<ul><li>';
  135. $tag->subafter = $tag->after = '</li></ul>';
  136. }
  137. $this->updateMail = array();
  138. $this->links = array();
  139. $this->sublinks = array();
  140. $anchorLinks = $this->_findLinks($tag,$email);
  141. if(!empty($tag->subtype) || !empty($tag->subclass)){
  142. $anchorSubLinks = $this->_findLinks($tag,$email,true);
  143. if(empty($this->links)){
  144. $this->links = $this->sublinks; unset($this->sublinks);
  145. }
  146. }
  147. $links = $this->links;
  148. if(empty($links)) return '';
  149. if(!empty($this->updateMail)) $email->body = str_replace(array_keys($this->updateMail),$this->updateMail,$email->body);
  150. if(!empty($this->sublinks)){
  151. $sublinks = $this->sublinks;
  152. foreach($links as $ilink => $oneLink){
  153. $allsublinks = array();
  154. $from = $anchorLinks['pos'][$ilink];
  155. $to = empty($anchorLinks['pos'][$ilink+1]) ? 9999999999999 : $anchorLinks['pos'][$ilink+1];
  156. foreach($sublinks as $isublink => $oneSubLink){
  157. if($anchorSubLinks['pos'][$isublink] > $to) break;
  158. if($anchorSubLinks['pos'][$isublink] > $from) $allsublinks[] = $oneSubLink;
  159. }
  160. if(!empty($allsublinks)) $links[$ilink] = $links[$ilink].$tag->subbefore.implode($tag->subdivider,$allsublinks).$tag->subafter;
  161. }
  162. }
  163. $result = '<div class="tableofcontents">'.$tag->before.implode($tag->divider,$links).$tag->after.'</div>';
  164. if(file_exists(ACYMAILING_MEDIA.'plugins'.DS.'tablecontents.php')){
  165. ob_start();
  166. require(ACYMAILING_MEDIA.'plugins'.DS.'tablecontents.php');
  167. $result = ob_get_clean();
  168. }
  169. return $result;
  170. }
  171. function _findLinks(&$tag,&$email,$sub = false){
  172. if($sub){
  173. $varType = 'subtype';
  174. $varClass = 'subclass';
  175. $varLink = &$this->sublinks;
  176. }else{
  177. $varType = 'type';
  178. $varClass = 'class';
  179. $varLink = &$this->links;
  180. }
  181. if(!empty($tag->$varType)){
  182. preg_match_all('#<'.$tag->$varType.'[^>]*>((?!</ *'.$tag->$varType.'>).)*</ *'.$tag->$varType.'>#Uis',$email->body,$anchorresults);
  183. }elseif(!empty($tag->class)){
  184. preg_match_all('#<[^>]*class="'.$tag->$varClass.'"[^>]*>(<[^>]*>|[^<>])*</.*>#Uis',$email->body,$anchorresults);
  185. $tag->$varType = 'item';
  186. }else{
  187. preg_match_all('#<a[^>]*name="([^">]*)"[^>]*>((?!</ *a>).)*</ *a>#Uis',$email->body,$anchorresults);
  188. }
  189. if(empty($anchorresults)) return '';
  190. foreach($anchorresults[0] as $i => $oneContent){
  191. $anchorresults['pos'][$i] = strpos($email->body,$oneContent);
  192. $linktext = strip_tags($oneContent);
  193. if(empty($linktext)) continue;
  194. if(empty($tag->$varType)){
  195. $varLink[$i] = '<a href="#'.$anchorresults[1][$i].'" class="oneitem" >'.$linktext.'</a>';
  196. }else{
  197. $varLink[$i] = '<a href="#'.$tag->$varType.$i.'" class="oneitem oneitem'.$tag->$varType.'" >'.$linktext.'</a>';
  198. $this->updateMail[$oneContent] = $oneContent.'<a name="'.$tag->$varType.$i.'"></a>';
  199. }
  200. }
  201. return $anchorresults;
  202. }
  203. }//endclass