| Current Path : /home/purehotels/public_html/plugins/acymailing/komento/ |
| Current File : /home/purehotels/public_html/plugins/acymailing/komento/komento.php |
<?php
/**
* @copyright Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
defined('_JEXEC') or die('Restricted access');
class plgAcymailingKomento extends JPlugin
{
function __construct(&$subject, $config){
parent::__construct($subject, $config);
$this->name = 'komento';
$this->db = JFactory::getDBO();
if(!isset($this->params)){
$plugin = JPluginHelper::getPlugin('acymailing', $this->name);
$this->params = new acyParameter( $plugin->params );
}
//check if the component is installed
$this->component_installed = file_exists(JPATH_SITE.DS.'components'.DS.'com_komento') && ACYMAILING_J16;
}
function acymailing_getPluginType(){
$app = JFactory::getApplication();
if(!$this->component_installed || ($this->params->get('frontendaccess') == 'none' && !$app->isAdmin())) return;
$onePlugin = new stdClass();
$onePlugin->name = 'Komento';
$onePlugin->function = 'acymailing_'.$this->name.'_show';
$onePlugin->help = 'plugin-'.$this->name;
return $onePlugin;
}
function acymailing_komento_show(){
$config = acymailing_config();
if($config->get('version') < '4.9.0'){
acymailing_display('Please download and install the latest AcyMailing version otherwise this plugin will NOT work','error');
return;
}
$app = JFactory::getApplication();
$lang = JFactory::getLanguage();
$lang->load('com_komento',JPATH_SITE);
$pageInfo = new stdClass();
$pageInfo->filter = new stdClass();
$pageInfo->filter->order = new stdClass();
$pageInfo->limit = new stdClass();
$pageInfo->elements = new stdClass();
$paramBase = ACYMAILING_COMPONENT.'.'.$this->name;
$pageInfo->filter->order->value = $app->getUserStateFromRequest( $paramBase.".filter_order", 'filter_order','a.id','cmd' );
$pageInfo->filter->order->dir = $app->getUserStateFromRequest( $paramBase.".filter_order_Dir", 'filter_order_Dir','asc', 'word' );
if(strtolower($pageInfo->filter->order->dir) !== 'desc') $pageInfo->filter->order->dir = 'asc';
$pageInfo->search = $app->getUserStateFromRequest( $paramBase.".search", 'search', '', 'string' );
$pageInfo->search = JString::strtolower(trim($pageInfo->search));
$pageInfo->filter_type = $app->getUserStateFromRequest( $paramBase.".filter_type", 'filter_type','','int' );
$pageInfo->limit->value = $app->getUserStateFromRequest( $paramBase.'.list_limit', 'limit', $app->getCfg('list_limit'), 'int' );
$pageInfo->limit->start = $app->getUserStateFromRequest( $paramBase.'.limitstart', 'limitstart', 0, 'int' );
$pageInfo->contentfilter = $app->getUserStateFromRequest( $paramBase.".contentfilter", 'contentfilter','created','string' );
$pageInfo->contentorder = $app->getUserStateFromRequest( $paramBase.".contentorder", 'contentorder','id,DESC','string' );
$pageInfo->cols = $app->getUserStateFromRequest( $paramBase.".cols", 'cols','1','string' );
$pageInfo->pictheight = $app->getUserStateFromRequest( $paramBase.".pictheight", 'pictheight','150','string' );
$pageInfo->pictwidth = $app->getUserStateFromRequest( $paramBase.".pictwidth", 'pictwidth','150','string' );
$pageInfo->pict = $app->getUserStateFromRequest( $paramBase.".pict", 'pict','1','string' );
$pageInfo->pictauto = $app->getUserStateFromRequest( $paramBase.".autopict", 'autopict','1','string' );
$pageInfo->readmore = $app->getUserStateFromRequest( $paramBase.".readmore", 'readmore','1','string' );
$pageInfo->readmoreauto = $app->getUserStateFromRequest( $paramBase.".readmoreauto", 'readmoreauto','1','string' );
$pageInfo->wrap = $app->getUserStateFromRequest( $paramBase.".wrap", 'wrap','0','string' );
$pageInfo->clickable = $app->getUserStateFromRequest( $paramBase.".clickable", 'clickable','1','string' );
$pageInfo->clickableauto = $app->getUserStateFromRequest( $paramBase.".clickableauto", 'clickableauto','1','string' );
//the query's start
$query = 'SELECT SQL_CALC_FOUND_ROWS a.*, c.title AS contenttitle FROM #__komento_comments AS a JOIN #__content AS c ON a.cid = c.id ';
//search fields...
$searchFields = array('a.id','a.title','a.name');
//apply search fields
if(!empty($pageInfo->search)){
$searchVal = '\'%'.acymailing_getEscaped($pageInfo->search,true).'%\'';
$filters[] = implode(" LIKE $searchVal OR ",$searchFields)." LIKE ".$searchVal;
}
//Only comments on the Joomla articles, we'll add the other integrations in the future if it asked
$filters[] = 'component = "com_content"';
//only published content ?
if($this->params->get('displaycontent','all') == 'onlypub') $filters[] = 'a.published = 1';
//apply filters
if(!empty($filters)) $query .= ' WHERE ('.implode(') AND (',$filters).')';
//apply ordering
if(!empty($pageInfo->filter->order->value)) $query .= ' ORDER BY '.$pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
$this->db->setQuery($query,$pageInfo->limit->start,$pageInfo->limit->value);
//load results
$rows = $this->db->loadObjectList();
//yellow highlighting on search matches
if(!empty($pageInfo->search)) $rows = acymailing_search($pageInfo->search,$rows);
//pagination
$this->db->setQuery('SELECT FOUND_ROWS()');
$pageInfo->elements->total = $this->db->loadResult();
$pageInfo->elements->page = count($rows);
jimport('joomla.html.pagination');
$pagination = new JPagination( $pageInfo->elements->total, $pageInfo->limit->start, $pageInfo->limit->value );
//is this a Smart-Newsletter or a simple one ?
$type = JRequest::getString('type');
?>
<script language="javascript" type="text/javascript">
<!--
var selectedContents = new Array();
function applyContent(contentid,rowClass){
var tmp = selectedContents.indexOf(contentid)
if(tmp != -1){
window.document.getElementById('content'+contentid).className = rowClass;
delete selectedContents[tmp];
}else{
window.document.getElementById('content'+contentid).className = 'selectedrow';
selectedContents.push(contentid);
}
updateTag();
}
var selectedCat = new Array();
function applyAuto(catid,rowClass){
if(catid == 'all'){
if(window.document.getElementById('cat'+catid).className == 'selectedrow'){
window.document.getElementById('catall').className = rowClass;
}else{
window.document.getElementById('cat'+catid).className = 'selectedrow';
for(key in selectedCat)
{
if(!isNaN(key))
{
window.document.getElementById('cat'+key).className = rowClass;
delete selectedCat[key];
}
}
}
}else{
window.document.getElementById('catall').className = 'row0';
if(selectedCat[catid]){
window.document.getElementById('cat'+catid).className = rowClass;
delete selectedCat[catid];
}else{
window.document.getElementById('cat'+catid).className = 'selectedrow';
selectedCat[catid] = 'selectedone';
}
}
updateTagAuto();
}
function updateTag(){
var tag = '';
var otherinfo = '';
var tmp=0;
<?php
//add the fields the user wants to be displayed
?>
for(var i=0; i < document.adminForm.cbdisplay.length; i++){
if(!document.adminForm.cbdisplay[i].checked) continue;
if(tmp == 0){
tmp += 1;
otherinfo += "| display:" + document.adminForm.cbdisplay[i].value;
}else{
otherinfo += ", " + document.adminForm.cbdisplay[i].value;
}
}
<?php
//is the title clickable ?
?>
for(var i=0; i < document.adminForm.clickable.length; i++){
if(document.adminForm.clickable[i].checked && document.adminForm.clickable[i].value == '0'){
otherinfo += '| nolink';
}
}
<?php
//do we have to wrap the text ? (description for example...)
?>
if(document.adminForm.wrap.value && document.adminForm.wrap.value != 0 && !isNaN(document.adminForm.wrap.value)){
otherinfo += "| wrap:"+document.adminForm.wrap.value;
}
<?php
//do we have to add a "read more" button ?
?>
for(var i=0; i < document.adminForm.readmore.length; i++){
if(document.adminForm.readmore[i].checked && document.adminForm.readmore[i].value == '0'){
otherinfo += '| noreadmore';
}
}
<?php
//picture management
?>
for(var i=0; i < document.adminForm.pict.length; i++){
if(!document.adminForm.pict[i].checked) continue;
if(document.adminForm.pict[i].value != '1') otherinfo += '| pict:'+document.adminForm.pict[i].value;
if(document.adminForm.pict[i].value == 'resized'){
document.getElementById('pictsize').style.display = '';
if(document.adminForm.pictwidth.value) otherinfo += '| maxwidth:'+document.adminForm.pictwidth.value;
if(document.adminForm.pictheight.value) otherinfo += '| maxheight:'+document.adminForm.pictheight.value;
}else{
document.getElementById('pictsize').style.display = 'none';
}
}
for(var i in selectedContents){
if(selectedContents[i] && !isNaN(i)){
tag = tag + '{<?php echo $this->name; ?>:'+selectedContents[i]+otherinfo+'}<br />';
}
}
setTag(tag);
}
function updateTagAuto(){
var tag = '';
var otherinfo = '';
var tmp=0;
for(var i=0; i < document.adminForm.cbdisplayauto.length; i++){
if(!document.adminForm.cbdisplayauto[i].checked) continue;
if(tmp==0){
tmp+=1;
otherinfo += "| display:"+document.adminForm.cbdisplayauto[i].value;
}else{
otherinfo += ", "+document.adminForm.cbdisplayauto[i].value;
}
}
for(var i=0; i < document.adminForm.clickableauto.length; i++){
if (document.adminForm.clickableauto[i].checked && document.adminForm.clickableauto[i].value == '0'){
otherinfo += '| nolink';
}
}
if(document.adminForm.wrapauto.value && document.adminForm.wrapauto.value != 0 && !isNaN(document.adminForm.wrapauto.value)){
otherinfo += "| wrap:"+document.adminForm.wrapauto.value;
}
for(var i=0; i < document.adminForm.readmoreauto.length; i++){
if (document.adminForm.readmoreauto[i].checked && document.adminForm.readmoreauto[i].value == '0'){
otherinfo += '| noreadmore';
}
}
for(var i=0; i < document.adminForm.autopict.length; i++){
if(!document.adminForm.autopict[i].checked) continue;
if(document.adminForm.autopict[i].value != '1') otherinfo += '| pict:'+document.adminForm.autopict[i].value;
if(document.adminForm.autopict[i].value == 'resized'){
document.getElementById('pictsizeauto').style.display = '';
if(document.adminForm.pictwidthauto.value) otherinfo += '| maxwidth:'+document.adminForm.pictwidthauto.value;
if(document.adminForm.pictheightauto.value) otherinfo += '| maxheight:'+document.adminForm.pictheightauto.value;
}else{
document.getElementById('pictsizeauto').style.display = 'none';
}
}
<?php
//on how many columns do we have to display the contents ?
?>
if(document.adminForm.cols.value){
otherinfo += "| cols:"+document.adminForm.cols.value;
}
<?php
//limit the number of content displayed
?>
if(document.adminForm.max_article.value){
otherinfo += "| max:"+document.adminForm.max_article.value;
}
<?php
//with what order will we display the contents
?>
if(document.adminForm.contentorder.value){
otherinfo += "| order:"+document.adminForm.contentorder.value;
}
<?php if($type == 'autonews'){
//minimum number of content for the newsletter to be displayed...
?>
if(document.adminForm.min_article.value){
otherinfo += "| min:"+document.adminForm.min_article.value;
}
<?php
//filter the content : only newly created/modified
?>
if(document.adminForm.contentfilter && document.adminForm.contentfilter.value != 0){
otherinfo += "| filter:"+document.adminForm.contentfilter.value;
}
<?php }
//insert the tag
?>
tag = '{auto<?php echo $this->name; ?>:';
for(var icat in selectedCat){
if(selectedCat[icat] == 'selectedone'){
tag += icat+'-';
}
}
tag += otherinfo+'}<br />';
setTag(tag);
}
//-->
</script>
<?php
// yes/no for the options
$choice = array();
$choice[] = JHTML::_('select.option', "1", JText::_('JOOMEXT_YES'));
$choice[] = JHTML::_('select.option', "0", JText::_('JOOMEXT_NO'));
// picture options
$valImages = array();
$valImages[] = JHTML::_('select.option', "1", JText::_('JOOMEXT_YES'));
$valImages[] = JHTML::_('select.option', "resized", JText::_('RESIZED'));
$valImages[] = JHTML::_('select.option', "0", JText::_('JOOMEXT_NO'));
// here are the possible orderings
$ordering = array();
$ordering[] = JHTML::_('select.option', "id,DESC", JText::_('ACY_ID'));
$ordering[] = JHTML::_('select.option', "created,DESC", JText::_('CREATED_DATE'));
$ordering[] = JHTML::_('select.option', "modified,DESC", JText::_('MODIFIED_DATE'));
$ordering[] = JHTML::_('select.option', "title,ASC", JText::_('FIELD_TITLE'));
$ordering[] = JHTML::_('select.option', "rand", JText::_('ACY_RANDOM'));
// filter options
$contentfilter = array();
$contentfilter[] = JHTML::_('select.option', "0", JText::_('ACY_ALL'));
$contentfilter[] = JHTML::_('select.option', "created", JText::_('ONLY_NEW_CREATED'));
$contentfilter[] = JHTML::_('select.option', "modified", JText::_('ONLY_NEW_MODIFIED'));
// options for the Nb. columns dropdown (1 to 10)
$column = array();
for($i=1;$i<11;$i++){
$column[] = JHTML::_('select.option', "$i",$i);
}
$fieldsDisplay = array();
$fieldsDisplay[] = array('title' => 'title', 'label' => 'ACY_TITLE', 'checked' => 'yes');
$fieldsDisplay[] = array('title' => 'message', 'label' => 'COM_KOMENTO_COLUMN_COMMENT', 'checked' => 'yes');
$fieldsDisplay[] = array('title' => 'avatar', 'label' => 'ACY_IMAGE', 'checked' => '');
$fieldsDisplay[] = array('title' => 'name', 'label' => 'AUTHOR_NAME', 'checked' => 'yes');
$fieldsDisplay[] = array('title' => 'date', 'label' => 'CREATED_DATE', 'checked' => '');
$fieldsDisplay[] = array('title' => 'location', 'label' => 'ADDRESSCAPTION', 'checked' => '');
$tabs = acymailing_get('helper.acytabs');
echo $tabs->startPane( $this->name.'_tab');
// start the first tab
echo $tabs->startPanel( JText::_('TAG_ELEMENTS'), $this->name.'_listings');
?>
<br style="font-size:1px"/>
<table width="100%" class="adminform">
<tr>
<td nowrap="nowrap"><?php echo JText::_('DISPLAY');?></td>
<?php
$i = 1;
foreach($fieldsDisplay as $oneField){
if($i == 5){
echo '</tr><tr><td/>';
$i = 1;
}
echo '<td nowrap="nowrap"><input type="checkbox" name="cbdisplay" value="'.$oneField['title'].'" id="'.$oneField['title'].'" '.(($oneField['checked'] == 'yes') ? 'checked' : '').' onclick="updateTag();"/><label style="margin-left:5px" for="'.$oneField['title'].'">'.trim(JText::_($oneField['label']), ':').'</label></td>';
$i++;
}
while($i != 5){
echo '<td/>';
$i++;
}
?>
</tr>
<tr>
<td nowrap="nowrap"><?php echo JText::_('CLICKABLE_TITLE'); ?></td>
<td nowrap="nowrap" colspan="2"><?php echo JHTML::_('acyselect.radiolist', $choice, 'clickable' , 'size="1" onclick="updateTag();"', 'value', 'text', $pageInfo->clickable); ?></td>
<td nowrap="nowrap"><?php echo JText::_('JOOMEXT_READ_MORE'); ?></td>
<td nowrap="nowrap"><?php echo JHTML::_('acyselect.radiolist', $choice, 'readmore' , 'size="1" onclick="updateTag();"', 'value', 'text', $pageInfo->readmore); ?></td>
</tr>
<tr>
<td nowrap="nowrap" valign="top"><?php echo JText::_('DISPLAY_PICTURES'); ?></td>
<td nowrap="nowrap" colspan="2"><?php echo JHTML::_('acyselect.radiolist', $valImages, 'pict' , 'size="1" onclick="updateTag();"', 'value', 'text', $pageInfo->pict); ?>
<span id="pictsize" <?php if($pageInfo->pict != 'resized') echo 'style="display:none;"'; ?> ><br />
<?php echo JText::_('CAPTCHA_WIDTH') ?>
<input name="pictwidth" type="text" onchange="updateTag();" value="<?php echo $pageInfo->pictwidth; ?>" style="width:30px;" />
x <?php echo JText::_('CAPTCHA_HEIGHT') ?>
<input name="pictheight" type="text" onchange="updateTag();" value="<?php echo $pageInfo->pictheight; ?>" style="width:30px;" />
</span>
</td>
<td nowrap="nowrap" colspan="2" valign="top"><?php echo JText::sprintf('TRUNCATE_AFTER','<input type="text" name="wrap" style="width:50px" value="0" onchange="updateTag();"/>'); ?></td>
</tr>
</table>
<table>
<tr>
<td nowrap="nowrap" width="100%">
<input placeholder="<?php echo JText::_('ACY_SEARCH'); ?>" type="text" name="search" id="acymailingsearch" value="<?php echo $pageInfo->search;?>" class="text_area" onchange="document.adminForm.submit();" />
<button class="btn" onclick="this.form.submit();"><?php echo JText::_( 'JOOMEXT_GO' ); ?></button>
<button class="btn" onclick="document.getElementById('acymailingsearch').value='';this.form.submit();"><?php echo JText::_( 'JOOMEXT_RESET' ); ?></button>
</td>
</tr>
</table>
<table class="adminlist table table-striped table-hover" cellpadding="1" width="100%">
<thead>
<tr>
<th/>
<th class="title">
<?php
echo JHTML::_('grid.sort', JText::_( 'FIELD_TITLE').' ('.JText::_('COM_KOMENTO_COLUMN_COMMENT').')', 'a.title', $pageInfo->filter->order->dir,$pageInfo->filter->order->value );
?>
</th>
<th class="title">
<?php echo JHTML::_('grid.sort', JText::_( 'NAMECAPTION'), 'a.name', $pageInfo->filter->order->dir,$pageInfo->filter->order->value ); ?>
</th>
<th class="title">
<?php echo JHTML::_('grid.sort', JText::_( 'FIELD_TITLE').' ('.JText::_('COM_KOMENTO_ARTICLE_ID_TITLE').')', 'c.title', $pageInfo->filter->order->dir,$pageInfo->filter->order->value ); ?>
</th>
<th class="title titleid">
<?php
echo JHTML::_('grid.sort', JText::_( 'ACY_ID' ), 'a.id', $pageInfo->filter->order->dir, $pageInfo->filter->order->value );
?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5">
<?php
echo $pagination->getListFooter();
if(ACYMAILING_J30){
$paginationNb = array();
foreach(array(5,10,15,20,25,30,50,100) as $oneOption){
$paginationNb[] = JHTML::_('select.option', $oneOption, $oneOption);
}
$paginationNb[] = JHTML::_('select.option', 0,JText::_('ACY_ALL'));
echo 'Display #'.JHTML::_('select.genericlist', $paginationNb, 'limit' , 'size="1" style="width:60px" onchange="Joomla.submitform();"', 'value', 'text', $pageInfo->limit->value).'<br />';
}
echo $pagination->getResultsCounter();
?>
</td>
</tr>
</tfoot>
<tbody>
<?php
$k = 0;
if(!empty($rows)){
foreach($rows as $row){
?>
<tr id="content<?php echo $row->id; ?>" class="<?php echo "row$k"; ?>" onclick="applyContent(<?php echo $row->id.",'row$k'"?>);" style="cursor:pointer;">
<td class="acytdcheckbox"></td>
<td style="text-align:center;">
<?php
if(!empty($row->title)) echo $row->title;
else echo JText::_('ACY_NONE');
?>
</td>
<td style="text-align:center;">
<?php echo $row->name; ?>
</td>
<td style="text-align:center;">
<?php echo $row->contenttitle; ?>
</td>
<td style="text-align:center;">
<?php
echo $row->id;
?>
</td>
</tr>
<?php
// this enables to know if we have to set the line background grey or white
$k = 1-$k;
}
}
?>
</tbody>
</table>
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $pageInfo->filter->order->value; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $pageInfo->filter->order->dir; ?>" />
<?php
echo $tabs->endPanel();
// start category tab
echo $tabs->startPanel( JText::_('TAG_CATEGORIES'), $this->name.'_auto');
?>
<br style="font-size:1px"/>
<table width="100%" class="adminform">
<tr>
<?php
// what should we display ?
?>
<td nowrap="nowrap"><?php echo JText::_('DISPLAY');?></td>
<?php
$i = 1;
foreach($fieldsDisplay as $oneField){
if($i == 5){
echo '</tr><tr><td/>';
$i = 1;
}//TODO for the language, see icagenda
echo '<td nowrap="nowrap"><input type="checkbox" name="cbdisplayauto" value="'.$oneField['title'].'" id="'.$oneField['title'].'auto" '.(($oneField['checked'] == 'yes') ? 'checked' : '').' onclick="updateTagAuto();"/><label style="margin-left:5px" for="'.$oneField['title'].'auto">'.trim(JText::_($oneField['label']), ':').'</label></td>';
$i++;
}
while($i != 5){
echo '<td/>';
$i++;
}
?>
</tr>
<tr>
<td nowrap="nowrap"><?php echo JText::_('CLICKABLE_TITLE'); ?></td>
<td nowrap="nowrap" colspan="2"><?php echo JHTML::_('acyselect.radiolist', $choice, 'clickableauto' , 'size="1" onclick="updateTagAuto();"', 'value', 'text', $pageInfo->clickableauto); ?></td>
<td nowrap="nowrap"><?php echo JText::_('JOOMEXT_READ_MORE'); ?></td>
<td nowrap="nowrap"><?php echo JHTML::_('acyselect.radiolist', $choice, 'readmoreauto' , 'size="1" onclick="updateTagAuto();"', 'value', 'text', $pageInfo->readmoreauto); ?></td>
</tr>
<tr>
<td nowrap="nowrap" valign="top">
<?php echo JText::_('DISPLAY_PICTURES');?>
</td>
<td nowrap="nowrap" colspan="2"><?php echo JHTML::_('acyselect.radiolist', $valImages, 'autopict' , 'size="1" onclick="updateTagAuto();"', 'value', 'text', $pageInfo->pictauto); ?>
<span id="pictsizeauto" <?php if($pageInfo->pictauto != 'resized') echo 'style="display:none;"'; ?> ><br />
<?php echo JText::_('CAPTCHA_WIDTH') ?>
<input name="pictwidthauto" type="text" onchange="updateTagAuto();" value="<?php echo $pageInfo->pictwidth; ?>" style="width:30px;" />
x <?php echo JText::_('CAPTCHA_HEIGHT') ?>
<input name="pictheightauto" type="text" onchange="updateTagAuto();" value="<?php echo $pageInfo->pictheight; ?>" style="width:30px;" />
</span>
</td>
<td nowrap="nowrap" colspan="2" valign="top"><?php echo JText::sprintf('TRUNCATE_AFTER','<input type="text" name="wrapauto" style="width:50px" value="0" onchange="updateTagAuto();"/>'); ?></td>
</tr>
<tr>
<td nowrap="nowrap" nowrap="nowrap">
<?php echo JText::_('MAX_ARTICLE'); ?>
</td>
<td nowrap="nowrap" colspan="2">
<input type="text" name="max_article" style="width:50px" value="20" onchange="updateTagAuto();"/>
</td>
<td nowrap="nowrap">
<?php echo JText::_('ACY_ORDER'); ?>
</td>
<td nowrap="nowrap">
<?php echo JHTML::_('select.genericlist', $ordering, 'contentorder' , 'size="1" onchange="updateTagAuto();" style="width:100px;"', 'value', 'text', $pageInfo->contentorder); ?>
</td>
</tr>
<?php if($type == 'autonews'){ ?>
<tr>
<td nowrap="nowrap">
<?php echo JText::_('MIN_ARTICLE'); ?>
</td nowrap="nowrap">
<td nowrap="nowrap" colspan="2">
<input type="text" name="min_article" style="width:50px" value="1" onchange="updateTagAuto();"/>
</td>
<td>
<?php echo JText::_('FIELD_COLUMNS'); ?>
</td>
<td nowrap="nowrap">
<?php echo JHTML::_('select.genericlist', $column, 'cols' , 'size="1" onchange="updateTagAuto();" style="width:100px;"', 'value', 'text', $pageInfo->cols); ?>
</td>
</tr>
<tr>
<td nowrap="nowrap">
<?php echo JText::_('JOOMEXT_FILTER'); ?>
</td>
<td nowrap="nowrap" colspan="4">
<?php echo JHTML::_('select.genericlist', $contentfilter, 'contentfilter' , 'size="1" onchange="updateTagAuto();"', 'value', 'text', $pageInfo->contentfilter); ?>
</td>
</tr>
<?php }else{ ?>
<tr>
<td nowrap="nowrap">
<?php echo JText::_('FIELD_COLUMNS'); ?>
</td>
<td nowrap="nowrap" colspan="4">
<?php echo JHTML::_('select.genericlist', $column, 'cols' , 'size="1" onchange="updateTagAuto();" style="width:100px;"', 'value', 'text', $pageInfo->cols); ?>
</td>
</tr>
<?php } ?>
</table>
<!--====================================================================================LISTE CATEGORIES===========================================================================-->
<table class="adminlist table table-striped table-hover" cellpadding="1" width="100%">
<?php $k=0; ?>
<tr id="catall" class="<?php echo "row$k"; ?>" onclick="applyAuto('all','<?php echo "row$k" ?>');" style="cursor:pointer;">
<td class="acytdcheckbox"></td>
<td>
<?php
echo JText::_('ACY_ALL');
?>
</td>
</tr>
<?php
$this->_categories();
if(!empty($this->catvalues)){
foreach($this->catvalues as $oneCat){
if(empty($oneCat->value)) continue;
?>
<tr id="cat<?php echo $oneCat->value ?>" class="<?php echo "row$k"; ?>" onclick="applyAuto(<?php echo $oneCat->value ?>,'<?php echo "row$k" ?>');" style="cursor:pointer;">
<td class="acytdcheckbox"></td>
<td>
<?php
echo $oneCat->text;
?>
</td>
</tr>
<?php
$k = 1 - $k;
}
}
?>
</table>
<?php
echo $tabs->endPanel();
echo $tabs->endPane();
}
private function _categories(){
//select all cats
$this->db->setQuery('SELECT id, parent_id, title FROM #__categories WHERE extension = "com_content" ORDER BY id ASC');
$cats = $this->db->loadObjectList();
$this->cats = array();
if(!empty($cats)){
foreach($cats as $oneCat){
$this->cats[$oneCat->parent_id][] = $oneCat;
}
}
$this->catvalues = array();
$this->catvalues[] = JHTML::_('select.option', 0,JText::_('ACY_ALL'));
$this->_handleChildrens();
}
private function _handleChildrens($parent_id=1,$level=0){
if(empty($this->cats[$parent_id])) return;
foreach($this->cats[$parent_id] as $cat){
$this->catvalues[] = JHTML::_('select.option', $cat->id,str_repeat(" - - ",$level).$cat->title);
$this->_handleChildrens($cat->id,$level+1);
}
}
function acymailing_replacetags(&$email){
$this->_replaceAuto($email);
$this->_replaceOne($email);
}
private function _replaceOne(&$email){
$acypluginsHelper = acymailing_get('helper.acyplugins');
//load the tags
$tags = $acypluginsHelper->extractTags($email, $this->name);
if(empty($tags)) return;
$lang = JFactory::getLanguage();
$lang->load('com_komento', JPATH_SITE);
require_once JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php';
require_once JPATH_ROOT.DS.'components'.DS.'com_komento'.DS.'helpers'.DS.'helper.php';
$this->komentoCommentHelper = Komento::getHelper('comment');
$this->newslanguage = new stdClass();
if(!empty($email->language)){
$this->db->setQuery('SELECT lang_id, lang_code FROM #__languages WHERE sef = '.$this->db->quote($email->language).' LIMIT 1');
$this->newslanguage = $this->db->loadObject();
}
//Set the read more text or image
$this->readmore = empty($email->template->readmore) ? JText::_('JOOMEXT_READ_MORE') : '<img src="'.ACYMAILING_LIVE.$email->template->readmore.'" alt="'.JText::_('JOOMEXT_READ_MORE',true).'" />';
$tagsReplaced = array();
foreach($tags as $i => $oneTag){
if(isset($tagsReplaced[$i])) continue;
$tagsReplaced[$i] = $this->_replaceContent($oneTag);
}
$acypluginsHelper->replaceTags($email, $tagsReplaced, true);
}
private function _replaceContent(&$tag){
$acypluginsHelper = acymailing_get('helper.acyplugins');
$app = JFactory::getApplication();
// extract the fields selected
if(!empty($tag->display)){
$tag->display = explode(',',$tag->display);
foreach($tag->display as $i => $oneDisplay){
$oneDisplay = trim($oneDisplay);
$tag->$oneDisplay = true;
}
unset($tag->display);
}
// load content
$this->db->setQuery('SELECT a.*, CONCAT(b.id, ":", b.alias) AS completeid, CONCAT(c.id, ":", c.alias) AS completecat, u.email ' .
'FROM #__komento_comments AS a ' .
'JOIN #__content AS b ON a.cid = b.id ' .
'JOIN #__categories AS c ON b.catid = c.id ' .
'JOIN #__users AS u ON a.created_by = u.id ' .
'WHERE a.id = '.intval($tag->id).' LIMIT 1');
$content = $this->db->loadObject();
//In case of we could not load the article for any reason...
if(empty($content)){
if($app->isAdmin()) $app->enqueueMessage('The content "'.$tag->id.'" could not be loaded','notice');
return '';
}
$varFields = array();
foreach($content as $fieldName => $oneField){
$varFields['{'.$fieldName.'}'] = $oneField;
}
// create the link for the title and the read more button
$link = ContentHelperRoute::getArticleRoute($content->completeid,$content->completecat);
$link = acymailing_frontendLink($link);
$varFields['{link}'] = $link;
$result = '<div class="acymailing_content"><table cellspacing="0" cellpadding="0" border="0" width="100%">';
if(!empty($tag->avatar)){
$result .= '<tr><td valign="top" style="width:60px;"><img src="https://www.gravatar.com/avatar/'.md5(strtolower(trim($content->email))).'?d=mm&s=50" /></td><td valign="top"><table cellspacing="0" cellpadding="0" border="0" width="100%">';
}
// display the title
if(!empty($tag->name) && !empty($content->name)){
$result .= '<tr><td><h2 class="acymailing_title">';
if(empty($tag->nolink)) $result .= '<a href="'.$link.'">';
$result .= $content->name;
if(empty($tag->nolink)) $result .= '</a>';
$result .= '</h2></td></tr>';
}
if(!empty($tag->title) && !empty($content->title)) $result .= '<tr><td><h3>'.$content->title.'</h3></td></tr>';
// display the main text wraped or not
if(!empty($tag->message) && !empty($content->comment)){
$content->comment = nl2br($this->komentoCommentHelper->parseBBCode($content->comment));
$content->comment = preg_replace('#(<code .+</code>)#Uis', '', $content->comment);
$content->comment = preg_replace('#(<iframe [^>]* src="([^"]+)"[^>]*>[^<]*</iframe>)#Uis', '<a target="_blank" href="$2">$2</a>', $content->comment);
$result .= '<tr><td>'.$acypluginsHelper->wrapText($content->comment, $tag).'</td></tr>';
}
// display the category
if(!empty($tag->date) || (!empty($tag->location) && !empty($content->address))){
$result .= '<tr><td style="color: #888;font-size: 11px;">';
if(!empty($tag->date)) $result .= '<span class="komentocreated" style="padding-right:5px;">'.acymailing_getDate(acymailing_getTime($content->created), JText::_('DATE_FORMAT_LC2')).'</span>';
if(!empty($tag->location) && !empty($content->address)) $result .= '<span class="komentoaddress">'.JText::_('COM_KOMENTO_COMMENT_FROM').' <a href="http://maps.google.com/maps?z=15&q='.$content->latitude.','.$content->longitude.'" target="_blank">'.$content->address.'</a></span>';
$result .= '</td></tr>';
}
$varFields['{readmore}'] = '<a class="readmore_link" style="text-decoration:none;" target="_blank" href="'.$link.'"><span class="acymailing_readmore">'.$this->readmore.'</span></a>';
if(empty($tag->noreadmore)) $result .= '<tr><td>'.$varFields['{readmore}'].'</td></tr>';
if(!empty($tag->avatar)) $result .= '</table></td></tr>';
$result .= '</table></div>';
// load the custom template if exists
if(file_exists(ACYMAILING_MEDIA.'plugins'.DS.$this->name.'.php')){
ob_start();
require(ACYMAILING_MEDIA.'plugins'.DS.$this->name.'.php');
$result = ob_get_clean();
$result = str_replace(array_keys($varFields),$varFields,$result);
}
// always remove JS, there is no JS in newsletters...
$result = $acypluginsHelper->removeJS($result);
//resize or remove pictures
$result = $acypluginsHelper->managePicts($tag, $result);
return $result;
}
private function _replaceAuto(&$email){
$this->acymailing_generateautonews($email);
if(empty($this->tags)) return;
$acypluginsHelper = acymailing_get('helper.acyplugins');
$acypluginsHelper->replaceTags($email, $this->tags, true);
}
function acymailing_generateautonews(&$email){
$acypluginsHelper = acymailing_get('helper.acyplugins');
$time = time();
//load the tags
$tags = $acypluginsHelper->extractTags($email,'auto'.$this->name);
$return = new stdClass();
$return->status = true;
$return->message = '';
$this->tags = array();
if(empty($tags)) return $return;
foreach($tags as $oneTag => $parameter){
if(isset($this->tags[$oneTag])) continue;
$allcats = explode('-',$parameter->id);
$selectedArea = array();
foreach($allcats as $oneCat){
if(empty($oneCat)) continue;
$selectedArea[] = intval($oneCat);
}
$query = 'SELECT a.id FROM #__komento_comments AS a JOIN #__content AS b ON a.cid = b.id ';
$where = array();
// load only needed content
if(!empty($selectedArea)) $where[] = 'b.catid IN ('.implode(',',$selectedArea).')';
// filter results created or modified
if(!empty($parameter->filter) && !empty($email->params['lastgenerateddate'])){
if($parameter->filter == 'created'){
$where[] = 'a.created > \''.date( 'Y-m-d H:i:s',$email->params['lastgenerateddate'] - date('Z')).'\'';
}elseif($parameter->filter == 'modified'){
$where[] = 'a.created > \''.date( 'Y-m-d H:i:s',$email->params['lastgenerateddate'] - date('Z')).'\' OR a.modified > \''.date( 'Y-m-d H:i:s',$email->params['lastgenerateddate'] - date('Z')).'\'';
}
}
// Only published content
$where[] = 'a.published = 1';
if(!empty($parameter->sticked)) $where[] = 'a.sticked = 1';
if(!empty($parameter->nosticked)) $where[] = 'a.sticked = 0';
if(!empty($parameter->nochild)) $where[] = 'a.parent_id = 0';
// Apply filters
if(!empty($where)) $query .= ' WHERE ('.implode(') AND (',$where).')';
// Ordering
if(!empty($parameter->order)){
if($parameter->order == 'rand'){
$query .= ' ORDER BY rand()';
}else{
$ordering = explode(',',$parameter->order);
$query .= ' ORDER BY a.'.acymailing_secureField(trim($ordering[0])).' '.acymailing_secureField(trim($ordering[1]));
}
}
$start = '';
if(!empty($parameter->start)) $start = intval($parameter->start).',';
if(empty($parameter->max)) $parameter->max = 20;
//We add a limit for the preview otherwise we could break everything
$query .= ' LIMIT '.$start.(int) intval($parameter->max);
// load content IDs
$this->db->setQuery($query);
$allArticles = acymailing_loadResultArray($this->db);
// Check the number of results
if(!empty($parameter->min) && count($allArticles) < $parameter->min){
//We will not generate the Newsletter
$return->status = false;
$return->message = 'Not enough '.$this->name.' content for the tag '.$oneTag.' : '.count($allArticles).' / '.$parameter->min;
}
$stringTag = '';
if(!empty($allArticles)){
// If the user created its own template...
if(file_exists(ACYMAILING_MEDIA.'plugins'.DS.'auto'.$this->name.'.php')){
ob_start();
require(ACYMAILING_MEDIA.'plugins'.DS.'auto'.$this->name.'.php');
$stringTag = ob_get_clean();
}else{
//we insert the tags one after the other in a table as they are already sorted (using |cols parameter)
$arrayElements = array();
foreach($allArticles as $oneArticleId){
$args = array();
$args[] = $this->name.':'.$oneArticleId;
if(!empty($parameter->nolink)) $args[] = 'nolink';
if(!empty($parameter->noreadmore)) $args[] = 'noreadmore';
if(!empty($parameter->wrap)) $args[] = 'wrap:'.$parameter->wrap;
if(!empty($parameter->display)) $args[] = 'display:'.$parameter->display;
if(isset($parameter->pict)) $args[] = 'pict:'.$parameter->pict;
if(!empty($parameter->maxwidth)) $args[] = 'maxwidth:'.$parameter->maxwidth;
if(!empty($parameter->maxheight)) $args[] = 'maxheight:'.$parameter->maxheight;
$arrayElements[] = '{'.implode('|',$args).'}';
}
$stringTag = $acypluginsHelper->getFormattedResult($arrayElements,$parameter);
}
}
$this->tags[$oneTag] = $stringTag;
}
return $return;
}
}//endclass
?>