PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_acymailing/plugins/plg_acymailing_tagcontent/tagcontent.php

https://github.com/linkatic/Cultunet
PHP | 750 lines | 744 code | 0 blank | 6 comment | 154 complexity | 1eb1ece98e8daf6791562ca319ee0bd3 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2009-2010 ACYBA SARL - All rights reserved.
  4. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
  5. */
  6. defined('_JEXEC') or die('Restricted access');
  7. ?>
  8. <?php
  9. class plgAcymailingTagcontent extends JPlugin
  10. {
  11. function plgAcymailingTagcontent(&$subject, $config){
  12. parent::__construct($subject, $config);
  13. if(!isset($this->params)){
  14. $plugin =& JPluginHelper::getPlugin('acymailing', 'tagcontent');
  15. $this->params = new JParameter( $plugin->params );
  16. }
  17. }
  18. function acymailing_getPluginType() {
  19. if($this->params->get('frontendaccess') == 'none') return;
  20. $onePlugin = null;
  21. $onePlugin->name = JText::_('JOOMLA_CONTENT');
  22. $onePlugin->function = 'acymailingtagcontent_show';
  23. $onePlugin->help = 'plugin-tagcontent';
  24. return $onePlugin;
  25. }
  26. function acymailingtagcontent_show(){
  27. $app =& JFactory::getApplication();
  28. $pageInfo = null;
  29. $paramBase = ACYMAILING_COMPONENT.'.tagcontent';
  30. $pageInfo->filter->order->value = $app->getUserStateFromRequest( $paramBase.".filter_order", 'filter_order', 'a.id','cmd' );
  31. $pageInfo->filter->order->dir = $app->getUserStateFromRequest( $paramBase.".filter_order_Dir", 'filter_order_Dir', 'desc', 'word' );
  32. $pageInfo->search = $app->getUserStateFromRequest( $paramBase.".search", 'search', '', 'string' );
  33. $pageInfo->search = JString::strtolower( $pageInfo->search );
  34. $pageInfo->filter_cat = $app->getUserStateFromRequest( $paramBase.".filter_cat", 'filter_cat','','int' );
  35. $pageInfo->contenttype = $app->getUserStateFromRequest( $paramBase.".contenttype", 'contenttype','|type:intro','string' );
  36. $pageInfo->author = $app->getUserStateFromRequest( $paramBase.".author", 'author','','string' );
  37. $pageInfo->titlelink = $app->getUserStateFromRequest( $paramBase.".titlelink", 'titlelink','|link','string' );
  38. $pageInfo->lang = $app->getUserStateFromRequest( $paramBase.".lang", 'lang','','string' );
  39. $pageInfo->limit->value = $app->getUserStateFromRequest( $paramBase.'.list_limit', 'limit', $app->getCfg('list_limit'), 'int' );
  40. $pageInfo->limit->start = $app->getUserStateFromRequest( $paramBase.'.limitstart', 'limitstart', 0, 'int' );
  41. $db =& JFactory::getDBO();
  42. $searchFields = array('a.id','a.title','a.alias','a.created_by','b.name','b.username');
  43. if(!empty($pageInfo->search)){
  44. $searchVal = '\'%'.$db->getEscaped($pageInfo->search,true).'%\'';
  45. $filters[] = implode(" LIKE $searchVal OR ",$searchFields)." LIKE $searchVal";
  46. }
  47. if(!empty($pageInfo->filter_cat)){
  48. $filters[] = "a.catid = ".$pageInfo->filter_cat;
  49. }
  50. if($this->params->get('displayart','all') == 'onlypub'){
  51. $filters[] = "a.state = 1";
  52. }
  53. if($this->params->get('frontendaccess') == 'author'){
  54. $my = JFactory::getUser();
  55. $filters[] = "a.created_by = ".intval($my->id);
  56. }
  57. $whereQuery = '';
  58. if(!empty($filters)){
  59. $whereQuery = ' WHERE ('.implode(') AND (',$filters).')';
  60. }
  61. $query = 'SELECT SQL_CALC_FOUND_ROWS a.id,a.title,a.alias,a.catid,a.sectionid,b.name,b.username,a.created_by FROM '.acymailing::table('content',false).' as a';
  62. $query .=' LEFT JOIN `#__users` AS b ON b.id = a.created_by';
  63. if(!empty($whereQuery)) $query.= $whereQuery;
  64. if(!empty($pageInfo->filter->order->value)){
  65. $query .= ' ORDER BY '.$pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
  66. }
  67. $db->setQuery($query,$pageInfo->limit->start,$pageInfo->limit->value);
  68. $rows = $db->loadObjectList();
  69. if(!empty($pageInfo->search)){
  70. $rows = acymailing::search($pageInfo->search,$rows);
  71. }
  72. $db->setQuery('SELECT FOUND_ROWS()');
  73. $pageInfo->elements->total = $db->loadResult();
  74. $pageInfo->elements->page = count($rows);
  75. jimport('joomla.html.pagination');
  76. $pagination = new JPagination( $pageInfo->elements->total, $pageInfo->limit->start, $pageInfo->limit->value );
  77. jimport('joomla.html.pane');
  78. $tabs =& JPane::getInstance('tabs');
  79. echo $tabs->startPane( 'joomlacontent_tab');
  80. echo $tabs->startPanel( JText::_( 'JOOMLA_CONTENT' ), 'joomlacontent_content');
  81. ?>
  82. <br style="font-size:1px"/>
  83. <script language="javascript" type="text/javascript">
  84. <!--
  85. var selectedContents = new Array();
  86. function applyContent(contentid,rowClass){
  87. if(selectedContents[contentid]){
  88. window.document.getElementById('content'+contentid).className = rowClass;
  89. delete selectedContents[contentid];
  90. }else{
  91. window.document.getElementById('content'+contentid).className = 'selectedrow';
  92. selectedContents[contentid] = 'content';
  93. }
  94. updateTag();
  95. }
  96. function updateTag(){
  97. var tag = '';
  98. var otherinfo = '';
  99. for(var i=0; i < document.adminForm.contenttype.length; i++){
  100. if (document.adminForm.contenttype[i].checked){ otherinfo += document.adminForm.contenttype[i].value; }
  101. }
  102. for(var i=0; i < document.adminForm.titlelink.length; i++){
  103. if (document.adminForm.titlelink[i].checked){ otherinfo += document.adminForm.titlelink[i].value; }
  104. }
  105. for(var i=0; i < document.adminForm.author.length; i++){
  106. if (document.adminForm.author[i].checked){ otherinfo += document.adminForm.author[i].value; }
  107. }
  108. if(window.document.getElementById('jflang') && window.document.getElementById('jflang').value != ''){
  109. otherinfo += '|lang:';
  110. otherinfo += window.document.getElementById('jflang').value;
  111. }
  112. for(var i in selectedContents){
  113. if(selectedContents[i] == 'content'){
  114. tag = tag + '{joomlacontent:'+i+otherinfo+'}<br/>';
  115. }
  116. }
  117. setTag(tag);
  118. }
  119. //-->
  120. </script>
  121. <table width="100%" class="adminform">
  122. <tr>
  123. <td>
  124. <?php echo JText::_('DISPLAY');?>
  125. </td>
  126. <td colspan="2">
  127. <?php $contentType = acymailing::get('type.content'); echo $contentType->display('contenttype',$pageInfo->contenttype);?>
  128. </td>
  129. <td>
  130. <?php $jflanguages = acymailing::get('type.jflanguages');
  131. $jflanguages->onclick = 'onchange="updateTag();"';
  132. echo $jflanguages->display('lang',$pageInfo->lang); ?>
  133. </td>
  134. </tr>
  135. <tr>
  136. <td>
  137. <?php echo JText::_('CLICKABLE_TITLE'); ?>
  138. </td>
  139. <td>
  140. <?php $titlelinkType = acymailing::get('type.titlelink'); echo $titlelinkType->display('titlelink',$pageInfo->titlelink);?>
  141. </td>
  142. <td>
  143. <?php echo JText::_('AUTHOR_NAME'); ?>
  144. </td>
  145. <td>
  146. <?php $authorname = acymailing::get('type.authorname'); echo $authorname->display('author',$pageInfo->author);?>
  147. </td>
  148. </tr>
  149. </table>
  150. <table>
  151. <tr>
  152. <td width="100%">
  153. <?php echo JText::_( 'JOOMEXT_FILTER' ); ?>:
  154. <input type="text" name="search" id="acymailingsearch" value="<?php echo $pageInfo->search;?>" class="text_area" onchange="document.adminForm.submit();" />
  155. <button onclick="this.form.submit();"><?php echo JText::_( 'JOOMEXT_GO' ); ?></button>
  156. <button onclick="document.getElementById('acymailingsearch').value='';this.form.submit();"><?php echo JText::_( 'JOOMEXT_RESET' ); ?></button>
  157. </td>
  158. <td nowrap="nowrap">
  159. <?php $articleType = acymailing::get('type.articlescat'); echo $articleType->display('filter_cat',$pageInfo->filter_cat);?>
  160. </td>
  161. </tr>
  162. </table>
  163. <table class="adminlist" cellpadding="1" width="100%">
  164. <thead>
  165. <tr>
  166. <th class="title">
  167. <?php echo JHTML::_('grid.sort', JText::_( 'FIELD_TITLE'), 'a.title', $pageInfo->filter->order->dir,$pageInfo->filter->order->value ); ?>
  168. </th>
  169. <th class="title">
  170. <?php echo JHTML::_('grid.sort', JText::_( 'ACY_AUTHOR'), 'b.name', $pageInfo->filter->order->dir,$pageInfo->filter->order->value ); ?>
  171. </th>
  172. <th class="title titleid">
  173. <?php echo JHTML::_('grid.sort', JText::_( 'ACY_ID' ), 'a.id', $pageInfo->filter->order->dir, $pageInfo->filter->order->value ); ?>
  174. </th>
  175. </tr>
  176. </thead>
  177. <tfoot>
  178. <tr>
  179. <td colspan="5">
  180. <?php echo $pagination->getListFooter(); ?>
  181. <?php echo $pagination->getResultsCounter(); ?>
  182. </td>
  183. </tr>
  184. </tfoot>
  185. <tbody>
  186. <?php
  187. $k = 0;
  188. for($i = 0,$a = count($rows);$i<$a;$i++){
  189. $row =& $rows[$i];
  190. ?>
  191. <tr id="content<?php echo $row->id?>" class="<?php echo "row$k"; ?>" onclick="applyContent(<?php echo $row->id.",'row$k'"?>);" style="cursor:pointer;">
  192. <td>
  193. <?php
  194. $text = '<b>'.JText::_('ALIAS',true).': </b>'.$row->alias;
  195. echo acymailing::tooltip($text, $row->title, '', $row->title);
  196. ?>
  197. </td>
  198. <td>
  199. <?php
  200. if(!empty($row->name)){
  201. $text = '<b>'.JText::_('NAME',true).' : </b>'.$row->name;
  202. $text .= '<br/><b>'.JText::_('USERNAME',true).' : </b>'.$row->username;
  203. $text .= '<br/><b>'.JText::_('ID',true).' : </b>'.$row->created_by;
  204. echo acymailing::tooltip($text, $row->name, '', $row->name);
  205. }
  206. ?>
  207. </td>
  208. <td align="center">
  209. <?php echo $row->id; ?>
  210. </td>
  211. </tr>
  212. <?php
  213. $k = 1-$k;
  214. }
  215. ?>
  216. </tbody>
  217. </table>
  218. <input type="hidden" name="boxchecked" value="0" />
  219. <input type="hidden" name="filter_order" value="<?php echo $pageInfo->filter->order->value; ?>" />
  220. <input type="hidden" name="filter_order_Dir" value="<?php echo $pageInfo->filter->order->dir; ?>" />
  221. <?php
  222. echo $tabs->endPanel();
  223. echo $tabs->startPanel( JText::_( 'TAG_CATEGORIES' ), 'joomlacontent_auto');
  224. $query = 'SELECT a.id as catid, b.id as secid, a.title as category, b.title as section from '.acymailing::table('categories',false).' as a ';
  225. $query .= 'INNER JOIN '.acymailing::table('sections',false).' as b on a.section = b.id ORDER BY b.ordering,a.ordering';
  226. $db->setQuery($query);
  227. $rows = $db->loadObjectList();
  228. $type = JRequest::getString('type');
  229. ?>
  230. <br style="font-size:1px"/>
  231. <script language="javascript" type="text/javascript">
  232. <!--
  233. var selectedCategories = new Array();
  234. function applyAutoContent(secid,catid,rowClass){
  235. if(selectedCategories[secid] && selectedCategories[secid][catid]){
  236. window.document.getElementById('content_sec'+secid+'_cat'+catid).className = rowClass;
  237. delete selectedCategories[secid][catid];
  238. }else{
  239. if(!selectedCategories[secid]) selectedCategories[secid] = new Array();
  240. if(secid == 0){
  241. for(var isec in selectedCategories){
  242. for(var icat in selectedCategories[isec]){
  243. if(selectedCategories[isec][icat] == 'content'){
  244. window.document.getElementById('content_sec'+isec+'_cat'+icat).className = 'row0';
  245. delete selectedCategories[isec][icat];
  246. }
  247. }
  248. }
  249. }else{
  250. if(selectedCategories[0] && selectedCategories[0][0]){
  251. window.document.getElementById('content_sec0_cat0').className = 'row0';
  252. delete selectedCategories[0][0];
  253. }
  254. if(catid == 0){
  255. for(var icat in selectedCategories[secid]){
  256. if(selectedCategories[secid][icat] == 'content'){
  257. window.document.getElementById('content_sec'+secid+'_cat'+icat).className = 'row0';
  258. delete selectedCategories[secid][icat];
  259. }
  260. }
  261. }else{
  262. if(selectedCategories[secid][0]){
  263. window.document.getElementById('content_sec'+secid+'_cat0').className = 'row0';
  264. delete selectedCategories[secid][0];
  265. }
  266. }
  267. }
  268. window.document.getElementById('content_sec'+secid+'_cat'+catid).className = 'selectedrow';
  269. selectedCategories[secid][catid] = 'content';
  270. }
  271. updateAutoTag();
  272. }
  273. function updateAutoTag(){
  274. tag = '{autocontent:';
  275. for(var isec in selectedCategories){
  276. for(var icat in selectedCategories[isec]){
  277. if(selectedCategories[isec][icat] == 'content'){
  278. if(icat != 0){
  279. tag += 'cat'+icat+'-';
  280. }else{
  281. tag += 'sec'+isec+'-';
  282. }
  283. }
  284. }
  285. }
  286. if(document.adminForm.min_article && document.adminForm.min_article.value && document.adminForm.min_article.value!=0){ tag += '|min:'+document.adminForm.min_article.value; }
  287. if(document.adminForm.max_article.value && document.adminForm.max_article.value!=0){ tag += '|max:'+document.adminForm.max_article.value; }
  288. if(document.adminForm.contentorder.value){ tag += document.adminForm.contentorder.value; }
  289. if(document.adminForm.contentfilter && document.adminForm.contentfilter.value){ tag += document.adminForm.contentfilter.value; }
  290. if(document.adminForm.meta_article && document.adminForm.meta_article.value){ tag += '|meta:'+document.adminForm.meta_article.value; }
  291. for(var i=0; i < document.adminForm.contenttypeauto.length; i++){
  292. if (document.adminForm.contenttypeauto[i].checked){ tag += document.adminForm.contenttypeauto[i].value; }
  293. }
  294. for(var i=0; i < document.adminForm.titlelinkauto.length; i++){
  295. if (document.adminForm.titlelinkauto[i].checked){ tag += document.adminForm.titlelinkauto[i].value; }
  296. }
  297. for(var i=0; i < document.adminForm.authorauto.length; i++){
  298. if (document.adminForm.authorauto[i].checked){ tag += document.adminForm.authorauto[i].value; }
  299. }
  300. if(window.document.getElementById('jflangauto') && window.document.getElementById('jflangauto').value != ''){
  301. tag += '|lang:';
  302. tag += window.document.getElementById('jflangauto').value;
  303. }
  304. tag += '}';
  305. setTag(tag);
  306. }
  307. //-->
  308. </script>
  309. <table width="100%" class="adminform">
  310. <tr>
  311. <td>
  312. <?php echo JText::_('DISPLAY');?>
  313. </td>
  314. <td colspan="2">
  315. <?php $contentType = acymailing::get('type.content'); $contentType->onclick = "updateAutoTag();"; echo $contentType->display('contenttypeauto','|type:intro');?>
  316. </td>
  317. <td>
  318. <?php $jflanguages = acymailing::get('type.jflanguages');
  319. $jflanguages->onclick = 'onchange="updateAutoTag();"';
  320. $jflanguages->id = 'jflangauto';
  321. echo $jflanguages->display('langauto'); ?>
  322. </td>
  323. </tr>
  324. <tr>
  325. <td>
  326. <?php echo JText::_('CLICKABLE_TITLE'); ?>
  327. </td>
  328. <td>
  329. <?php $titlelinkType = acymailing::get('type.titlelink'); $titlelinkType->onclick = "updateAutoTag();"; echo $titlelinkType->display('titlelinkauto','|link');?>
  330. </td>
  331. <td>
  332. <?php echo JText::_('AUTHOR_NAME'); ?>
  333. </td>
  334. <td>
  335. <?php $authorname = acymailing::get('type.authorname'); $authorname->onclick = "updateAutoTag();"; echo $authorname->display('authorauto','');?>
  336. </td>
  337. </tr>
  338. <tr>
  339. <td>
  340. <?php echo JText::_('MAX_ARTICLE'); ?>
  341. </td>
  342. <td>
  343. <input name="max_article" size="10" value="" onchange="updateAutoTag();"/>
  344. </td>
  345. <td>
  346. <?php echo JText::_('ACY_ORDER'); ?>
  347. </td>
  348. <td>
  349. <?php $ordertype = acymailing::get('type.contentorder'); $ordertype->onclick = "updateAutoTag();"; echo $ordertype->display('contentorder','|order:id'); ?>
  350. </td>
  351. </tr>
  352. <?php if($this->params->get('metaselect')){ ?>
  353. <tr>
  354. <td>
  355. <?php echo JText::_('META_KEYWORDS'); ?>
  356. </td>
  357. <td colspan="3">
  358. <input name="meta_article" size="50" value="" onchange="updateAutoTag();"/>
  359. </td>
  360. </tr>
  361. <?php } ?>
  362. <?php if($type == 'autonews') { ?>
  363. <tr>
  364. <td>
  365. <?php echo JText::_('MIN_ARTICLE'); ?>
  366. </td>
  367. <td>
  368. <input name="min_article" size="10" value="1" onchange="updateAutoTag();"/>
  369. </td>
  370. <td>
  371. <?php echo JText::_('FILTER'); ?>
  372. </td>
  373. <td>
  374. <?php $filter = acymailing::get('type.contentfilter'); $filter->onclick = "updateAutoTag();"; echo $filter->display('contentfilter','|filter:created'); ?>
  375. </td>
  376. </tr>
  377. <?php } ?>
  378. </table>
  379. <table class="adminlist" cellpadding="1" width="100%">
  380. <thead>
  381. <tr>
  382. <th class="title">
  383. <?php echo JText::_( 'SECTION'); ?>
  384. </th>
  385. <th class="title">
  386. <?php echo JText::_( 'CATEGORY'); ?>
  387. </th>
  388. </tr>
  389. </thead>
  390. <tbody>
  391. <?php
  392. $k = 0;
  393. ?>
  394. <tr id="content_sec0_cat0" class="<?php echo "row$k"; ?>" onclick="applyAutoContent(0,0,'<?php echo "row$k" ?>');" style="cursor:pointer;">
  395. <td style="font-weight: bold;">
  396. <?php
  397. echo JText::_('ALL');
  398. ?>
  399. </td>
  400. <td style="text-align:center;font-weight: bold;">
  401. <?php
  402. echo JText::_('ALL');
  403. ?>
  404. </td>
  405. </tr>
  406. <?php
  407. $k = 1-$k;
  408. $currentSection = '';
  409. for($i = 0,$a = count($rows);$i<$a;$i++){
  410. $row =& $rows[$i];
  411. if($currentSection != $row->section){
  412. ?>
  413. <tr id="content_sec<?php echo $row->secid ?>_cat0" class="<?php echo "row$k"; ?>" onclick="applyAutoContent(<?php echo $row->secid ?>,0,'<?php echo "row$k" ?>');" style="cursor:pointer;">
  414. <td style="font-weight: bold;">
  415. <?php
  416. echo $row->section;
  417. ?>
  418. </td>
  419. <td style="text-align:center;font-weight: bold;">
  420. <?php
  421. echo JText::_('ALL');
  422. ?>
  423. </td>
  424. </tr>
  425. <?php
  426. $k = 1-$k;
  427. $currentSection = $row->section;
  428. }
  429. ?>
  430. <tr id="content_sec<?php echo $row->secid ?>_cat<?php echo $row->catid?>" class="<?php echo "row$k"; ?>" onclick="applyAutoContent(<?php echo $row->secid ?>,<?php echo $row->catid ?>,'<?php echo "row$k" ?>');" style="cursor:pointer;">
  431. <td>
  432. </td>
  433. <td>
  434. <?php
  435. echo $row->category;
  436. ?>
  437. </td>
  438. </tr>
  439. <?php
  440. $k = 1-$k;
  441. }
  442. ?>
  443. </tbody>
  444. </table>
  445. <?php
  446. echo $tabs->endPanel();
  447. echo $tabs->endPane();
  448. }
  449. function acymailing_replacetags(&$email){
  450. $this->_replaceAuto($email);
  451. $this->_replaceArticles($email);
  452. }
  453. function _replaceArticles(&$email){
  454. $match = '#{joomlacontent:(.*)}#Ui';
  455. $variables = array('subject','body','altbody');
  456. $found = false;
  457. foreach($variables as $var){
  458. if(empty($email->$var)) continue;
  459. $found = preg_match_all($match,$email->$var,$results[$var]) || $found;
  460. if(empty($results[$var][0])) unset($results[$var]);
  461. }
  462. if(!$found) return;
  463. require_once JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php';
  464. $this->mailerHelper = acymailing::get('helper.mailer');
  465. $htmlreplace = array();
  466. $textreplace = array();
  467. $subjectreplace = array();
  468. foreach($results as $var => $allresults){
  469. foreach($allresults[0] as $i => $oneTag){
  470. if(isset($htmlreplace[$oneTag])) continue;
  471. $article = $this->_replaceContent($allresults,$i);
  472. $htmlreplace[$oneTag] = $article->html;
  473. $textreplace[$oneTag] = $article->text;
  474. $subjectreplace[$oneTag] = strip_tags($article->html);
  475. }
  476. }
  477. $email->body = str_replace(array_keys($htmlreplace),$htmlreplace,$email->body);
  478. $email->altbody = str_replace(array_keys($textreplace),$textreplace,$email->altbody);
  479. $email->subject = str_replace(array_keys($subjectreplace),$subjectreplace,$email->subject);
  480. }
  481. function _replaceContent(&$results,$i){
  482. $arguments = explode('|',strip_tags($results[1][$i]));
  483. $tag = null;
  484. $tag->id = (int) $arguments[0];
  485. for($i=1,$a=count($arguments);$i<$a;$i++){
  486. $args = explode(':',$arguments[$i]);
  487. if(isset($args[1])){
  488. $tag->$args[0] = $args[1];
  489. }else{
  490. $tag->$args[0] = true;
  491. }
  492. }
  493. $query = 'SELECT a.*,b.name as authorname, c.alias as catalias, c.title as cattitle, s.alias as secalias, s.title as sectitle FROM '.acymailing::table('content',false).' as a ';
  494. $query .= 'LEFT JOIN '.acymailing::table('users',false).' as b ON a.created_by = b.id ';
  495. $query .= ' LEFT JOIN '.acymailing::table('categories',false).' AS c ON c.id = a.catid ';
  496. $query .= ' LEFT JOIN '.acymailing::table('sections',false).' AS s ON s.id = a.sectionid ';
  497. $query .= 'WHERE a.id = '.$tag->id.' LIMIT 1';
  498. $db =& JFactory::getDBO();
  499. $db->setQuery($query);
  500. $article = $db->loadObject();
  501. $result = null;
  502. $result->text = '';
  503. $result->html = '';
  504. if(empty($article)){
  505. $app =& JFactory::getApplication();
  506. if($app->isAdmin()){
  507. $app->enqueueMessage('The article "'.$tag->id.'" could not be loaded','notice');
  508. }
  509. return $result;
  510. }
  511. if(!empty($tag->lang)){
  512. $langid = (int) substr($tag->lang,strpos($tag->lang,',')+1);
  513. if(!empty($langid)){
  514. $query = "SELECT reference_field, value FROM `#__jf_content` WHERE `published` = 1 AND `reference_table` = 'content' AND `language_id` = $langid AND `reference_id` = ".$tag->id;
  515. $db->setQuery($query);
  516. $translations = $db->loadObjectList();
  517. if(!empty($translations)){
  518. foreach($translations as $oneTranslation){
  519. if(!empty($oneTranslation->value)){
  520. $translatedfield = $oneTranslation->reference_field;
  521. $article->$translatedfield = $oneTranslation->value;
  522. }
  523. }
  524. }
  525. }
  526. }
  527. $completeId = $article->id;
  528. $completeCat = $article->catid;
  529. $completeSec = $article->sectionid;
  530. if(!empty($article->alias)) $completeId.=':'.$article->alias;
  531. if(!empty($article->catalias)) $completeCat .= ':'.$article->catalias;
  532. if(!empty($article->secalias)) $completeSec .= ':'.$article->secalias;
  533. $link = ContentHelperRoute::getArticleRoute($completeId,$completeCat,$completeSec);
  534. if(!empty($tag->lang)) $link.= (strpos($link,'?') ? '&' : '?') . 'lang='.substr($tag->lang, 0,strpos($tag->lang,','));
  535. $link = acymailing::frontendLink($link);
  536. $styleTitle = '';
  537. $styleTitleEnd = '';
  538. if($tag->type != "title"){
  539. $styleTitle = '<h2 class="acymailing_title">';
  540. $styleTitleEnd = '</h2>';
  541. }
  542. if(empty($tag->notitle)){
  543. if(!empty($tag->link)){
  544. $result->html .= '<a href="'.$link.'" ';
  545. if($tag->type != "title") $result->html .= 'style="text-decoration:none" name="content-'.$article->id.'" ';
  546. $result->html .= 'target="_blank" >'.$styleTitle.$article->title.$styleTitleEnd.'</a>';
  547. $result->text .= $article->title.' ( '.$link.' )';
  548. }else{
  549. $result->html .= $styleTitle.$article->title.$styleTitleEnd;
  550. $result->text .= $article->title;
  551. }
  552. }
  553. if(!empty($tag->author)){
  554. $authorName = empty($article->created_by_alias) ? $article->authorname : $article->created_by_alias;
  555. $result->html .= $authorName.'<br/>';
  556. $result->text .= "\n".$authorName;
  557. }
  558. if($tag->type != "title"){
  559. if($this->params->get('removejs','yes') == 'yes'){
  560. $article->introtext = $this->_removeJS($article->introtext);
  561. $article->fulltext = $this->_removeJS($article->fulltext);
  562. }
  563. if($this->params->get('removepictures','never') == 'always'){
  564. $article->introtext = $this->_removePictures($article->introtext);
  565. $article->fulltext = $this->_removePictures($article->fulltext);
  566. }elseif($this->params->get('removepictures','never') == 'intro' AND $tag->type == "intro"){
  567. $article->introtext = $this->_removePictures($article->introtext);
  568. }
  569. if($tag->type == "intro"){
  570. $forceReadMore = false;
  571. $wordwrap = $this->params->get('wordwrap',0);
  572. if(!empty($wordwrap)){
  573. $newintrotext = strip_tags($article->introtext,'<br><img>');
  574. $numChar = strlen($newintrotext);
  575. if($numChar > $wordwrap){
  576. $stop = strlen($newintrotext);
  577. for($i=$wordwrap;$i<$numChar;$i++){
  578. if($newintrotext[$i] == " "){
  579. $stop = $i;
  580. $forceReadMore = true;
  581. break;
  582. }
  583. }
  584. $article->introtext = substr($newintrotext,0,$stop).'...';
  585. }
  586. }
  587. }
  588. if(empty($article->fulltext) OR $tag->type != "text"){
  589. $result->html .= $article->introtext;
  590. $result->text .= "\n".$this->mailerHelper->textVersion($article->introtext);
  591. }
  592. if($tag->type == "intro"){
  593. if(!empty($article->fulltext) OR $forceReadMore){
  594. $result->html .= '<a style="text-decoration:none;" target="_blank" href="'.$link.'"><span class="acymailing_readmore">'.JText::_('JOOMEXT_READ_MORE').'</span></a>';
  595. $result->text .= "\n".JText::_('JOOMEXT_READ_MORE').'( '.$link.' )';
  596. }
  597. }elseif(!empty($article->fulltext)){
  598. $result->html .= '<br/>'.$article->fulltext;
  599. $result->text .= "\n".$this->mailerHelper->textVersion($article->fulltext);
  600. }
  601. $result->html = '<div class="acymailing_content">'.$result->html.'</div>';
  602. $result->text .= "\n"."\n";
  603. }
  604. if(file_exists(ACYMAILING_TEMPLATE.'plugins'.DS.'tagcontent_html.php')){
  605. ob_start();
  606. require(ACYMAILING_TEMPLATE.'plugins'.DS.'tagcontent_html.php');
  607. $result->html = ob_get_clean();
  608. }
  609. if(file_exists(ACYMAILING_TEMPLATE.'plugins'.DS.'tagcontent_text.php')){
  610. ob_start();
  611. require(ACYMAILING_TEMPLATE.'plugins'.DS.'tagcontent_text.php');
  612. $result->text = ob_get_clean();
  613. }
  614. return $result;
  615. }
  616. function _replaceAuto(&$email){
  617. $this->acymailing_generateautonews($email);
  618. if(!empty($this->tags)){
  619. $email->body = str_replace(array_keys($this->tags),$this->tags,$email->body);
  620. if(!empty($email->altbody)) $email->altbody = str_replace(array_keys($this->tags),$this->tags,$email->altbody);
  621. foreach($this->tags as $tag => $result){
  622. $email->subject = str_replace($tag,strip_tags(str_replace('</tr><tr>',' | ',$result)),$email->subject);
  623. }
  624. }
  625. }
  626. function acymailing_generateautonews(&$email){
  627. $return = null;
  628. $return->status = true;
  629. $return->message = '';
  630. $time = time();
  631. $match = '#{autocontent:(.*)}#Ui';
  632. $variables = array('subject','body','altbody');
  633. $found = false;
  634. foreach($variables as $var){
  635. if(empty($email->$var)) continue;
  636. $found = preg_match_all($match,$email->$var,$results[$var]) || $found;
  637. if(empty($results[$var][0])) unset($results[$var]);
  638. }
  639. if(!$found) return $return;
  640. $this->tags = array();
  641. $db =& JFactory::getDBO();
  642. foreach($results as $var => $allresults){
  643. foreach($allresults[0] as $i => $oneTag){
  644. if(isset($this->tags[$oneTag])) continue;
  645. $arguments = explode('|',strip_tags($allresults[1][$i]));
  646. $allcats = explode('-',$arguments[0]);
  647. $parameter = null;
  648. for($i=1;$i<count($arguments);$i++){
  649. $args = explode(':',$arguments[$i]);
  650. $arg0 = $args[0];
  651. if(isset($args[1])){
  652. $parameter->$arg0 = $args[1];
  653. }else{
  654. $parameter->$arg0 = true;
  655. }
  656. }
  657. $selectedArea = array();
  658. foreach($allcats as $oneCat){
  659. $sectype = substr($oneCat,0,3);
  660. $num = substr($oneCat,3);
  661. if(empty($num)) continue;
  662. if($sectype=='cat'){
  663. $selectedArea[] = 'catid = '.(int) $num;
  664. }elseif($sectype=='sec'){
  665. $selectedArea[] = 'sectionid = '.(int) $num;
  666. }
  667. }
  668. $query = 'SELECT id FROM `#__content`';
  669. $where = array();
  670. if(!empty($selectedArea)){
  671. $where[] = implode(' OR ',$selectedArea);
  672. }
  673. if(!empty($parameter->filter) AND !empty($email->params['lastgenerateddate'])){
  674. $condition = '`publish_up` >\''.date( 'Y-m-d H:i:s',$email->params['lastgenerateddate'] - date('Z')).'\'';
  675. $condition .= ' OR `created` >\''.date( 'Y-m-d H:i:s',$email->params['lastgenerateddate'] - date('Z')).'\'';
  676. if($parameter->filter == 'modify'){
  677. $condition .= ' OR `modified` > \''.date( 'Y-m-d H:i:s',$email->params['lastgenerateddate'] - date('Z')).'\'';
  678. }
  679. $where[] = $condition;
  680. }
  681. if(!empty($parameter->meta)){
  682. $allMetaTags = explode(',',$parameter->meta);
  683. $metaWhere = array();
  684. foreach($allMetaTags as $oneMeta){
  685. if(empty($oneMeta)) continue;
  686. $metaWhere[] = "`metakey` LIKE '%".$db->getEscaped($oneMeta,true)."%'";
  687. }
  688. if(!empty($metaWhere)) $where[] = implode(' OR ',$metaWhere);
  689. }
  690. $where[] = '`publish_up` < \'' .date( 'Y-m-d H:i:s',$time - date('Z')).'\'';
  691. $where[] = '`publish_down` > \''.date( 'Y-m-d H:i:s',$time - date('Z')).'\' OR `publish_down` = 0';
  692. $where[] = 'state = 1';
  693. if(isset($parameter->access)){
  694. $where[] = 'access <= '.intval($parameter->access);
  695. }else{
  696. if($this->params->get('contentaccess','registered') == 'registered') $where[] = 'access <= 1';
  697. elseif($this->params->get('contentaccess','registered') == 'public') $where[] = 'access = 0';
  698. }
  699. $query .= ' WHERE ('.implode(') AND (',$where).')';
  700. if(!empty($parameter->order)){
  701. $ordering = explode(',',$parameter->order);
  702. $query .= ' ORDER BY `'.acymailing::secureField($ordering[0]).'` '.acymailing::secureField($ordering[1]);
  703. }
  704. if(!empty($parameter->max)) $query .= ' LIMIT '.(int) $parameter->max;
  705. elseif(empty($email->params['lastgenerateddate'])) $query .= ' LIMIT 20';
  706. $db->setQuery($query);
  707. $allArticles = $db->loadResultArray();
  708. if(!empty($parameter->min) AND count($allArticles)< $parameter->min){
  709. $return->status = false;
  710. $return->message = 'Not enough articles for the tag '.$oneTag.' : '.count($allArticles).' / '.$parameter->min.' between '.acymailing::getDate($email->params['lastgenerateddate']).' and '.acymailing::getDate($time);
  711. }
  712. $stringTag = '';
  713. if(!empty($allArticles)){
  714. if(file_exists(ACYMAILING_TEMPLATE.'plugins'.DS.'autocontent.php')){
  715. ob_start();
  716. require(ACYMAILING_TEMPLATE.'plugins'.DS.'autocontent.php');
  717. $stringTag = ob_get_clean();
  718. }else{
  719. $stringTag .= '<table>';
  720. foreach($allArticles as $oneArticleId){
  721. $stringTag .= '<tr><td>';
  722. $args = array();
  723. $args[] = 'joomlacontent:'.$oneArticleId;
  724. if(!empty($parameter->type)) $args[] = 'type:'.$parameter->type;
  725. if(!empty($parameter->link)) $args[] = 'link';
  726. if(!empty($parameter->author)) $args[] = 'author';
  727. if(!empty($parameter->lang)) $args[] = 'lang:'.$parameter->lang;
  728. if(!empty($parameter->notitle)) $args[] = 'notitle';
  729. $stringTag .= '{'.implode('|',$args).'}';
  730. $stringTag .= '</td></tr>';
  731. }
  732. $stringTag .= '</table>';
  733. }
  734. }
  735. $this->tags[$oneTag] = $stringTag;
  736. }
  737. }
  738. return $return;
  739. }
  740. function _removePictures($text){
  741. $return = preg_replace('#< *img[^>]*>#Ui','',$text);
  742. $return = preg_replace('#< *div[^>]*class="jce_caption"[^>]*>[^<]*(< *div[^>]*>[^<]*<\/div>)*[^<]*<\/div>#Ui','',$return);
  743. return $return;
  744. }
  745. function _removeJS($text){
  746. $text = preg_replace("#(onmouseout|onmouseover|onclick|onfocus|onload|onblur) *= *\"(?:(?!\").)*\"#iU",'',$text);
  747. $text = preg_replace("#< *script(?:(?!< */ *script *>).)*< */ *script *>#isU",'',$text);
  748. return $text;
  749. }
  750. }//endclass