Your IP : 216.73.216.222


Current Path : /var/www/iplanru/data/old/www/i-plan.ru/modules/mod_dn/
Upload File :
Current File : /var/www/iplanru/data/old/www/i-plan.ru/modules/mod_dn/helper.php

<?php
###################################################################################################
#  Display News  1.6.5 - Oct -2009 by bkomraz1@gmail.com
#  http://joomla.rjews.net
#  Based on Display News - Latest 1-3 [07 June 2004] by Rey Gigataras [stingrey]   www.stingrey.biz  mambo@stingrey.biz
#  @ Released under GNU/GPL License : http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
###################################################################################################


defined ( '_JEXEC' ) or die ( 'Restricted access' );

// loads module function file
require_once (JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php');
require_once (JPATH_LIBRARIES . DS . 'joomla' . DS . 'database' . DS . 'table' . DS . 'category.php');
require_once (JPATH_LIBRARIES . DS . 'joomla' . DS . 'database' . DS . 'table' . DS . 'section.php');
require_once (JPATH_LIBRARIES . DS . 'joomla' . DS . 'database' . DS . 'table' . DS . 'content.php');

class modDisplayNewsHelper {

        var $css_type = null;
        var $version = "Display News by BK 1.6.6";

   // Function to filter html code and special characters from text
   function dn_filter( $text ) {
      $text = strip_tags($text, /* exclude */ "<img>");
//      $text = preg_replace("'<script[^>]*>.*?</script>'si","",$text);
      $text = preg_replace("@<script[^>]*?>.*?</script>@si","",$text);
      $text = preg_replace('/{.+?}/','',$text);
      $text = preg_replace('/(( )|(&nbsp;))+/',' ',$text);
      // $text = preg_replace('/&amp;/',' ',$text);
      $text = preg_replace('/&quot;/',' ',$text);
      // $text = htmlspecialchars($text);
      return $text;
   }

   //  Function required to create set of Names, '' added
   function dn_set_name( $param ) {
          if ($param <> "") {
         $paramA = explode(",", $param);
         $a = "0";
         foreach ($paramA as $paramB) {
            $paramB = trim($paramB);
            $paramB = "'".addslashes($paramB)."'";
            $paramA[$a] = $paramB;
            $a++;
         }
         $param= implode(",", $paramA);
      }
          return $param;
   }
   //---------------------------------------------------------------------
   //  Functinality to allow text_hover to be blank by use if special character "#" entered
   //  If not then space added to the end of the variables
   function dn_hovertext( &$text ) {
      if ($text == "#") {
         $text = "";
      } else {
         $text .= " ";
      }
   }
   //---------------------------------------------------------------------


   // Function that limits title, intro or full to specified character or word length
        function dn_limit( &$text, $limit_type, $length_chars, $href ) {

                if ( $limit_type < 2 || !$length_chars ) {
                        return 0;
                }

                $titletext = "";
                $visiblelen = 0;
                $triger = 0;
                for($i=0;$i<strlen($text);$i++)
                {
                    $char=substr($text,$i,1);

                        if ($char == "<" || $char == ">") {
                                $triger ++;
                        }

                        if ( !$triger && ( ($limit_type == 2) || ($char == " ")) ) {
                                $visiblelen ++;
                        }

                        if ($visiblelen > $length_chars) {
                                break;
                        }

                        // UTF Lenght. should be added to string "as is"
                        // 0xC0-0xFD
                        if ((ord($char)>= 192) && (ord($char)<=253) ) {
                                $titletext = $titletext . $char;
                                for ($j=$i+1;$j<strlen($text);$j++) {
                                        $char=substr($text,$j,1);
                                        if ((ord($char)>= 128) && (ord($char)<=191) ) {
                                                $titletext = $titletext . $char;
                                                $i=$j;
                                        }
                                        else {
                                                break;
                                        }
                                }
                        } else {
                                $titletext = $titletext . $char;
                        }


                        if ($triger == 2) {
                                $triger = 0;
                        }


                }

                if ($visiblelen > $length_chars) {
                        $titletext = chop($titletext);
                        $titletext .= strlen($href) ? '<a href="'.$href.'">...</a>' : '...';
                        $title = $titletext;
                        $text = $title;
                        return 1;
                } else {
                        $title = $titletext;
                        $text = $title;
                        return 0;
                }

   }
   /**---------------------------------------------------------------------**/
   /*
   //  Functinality to convert Set Name to Set Id to be used by show_more
   function dn_name_id( $id, $name ) {
      global $database;
      if ( strchr($name, ",") ) {
         $id = "";
      } else {
         $database->setQuery("SELECT a.id"
         ."\n  FROM #__sections AS a"
         ."\n  WHERE a.title = '$name'");
         $id = $database->loadResult();
      }
      return $id;
   }
   */
   //---------------------------------------------------------------------
   //---------------------------------------------------------------------

        function dn_style_convert( $id ) {

                if ( ! $this->css_type )
                        return $id;

                $convert = array(
                        "dn-title"                              => array("content" => "contentpagetitle",                                       "table" => "",                  "latestnews" => ""),
                        // "dn-title_auto"              => array("content" => "contentpagetitle",       "table" => "sectiontableheader", "latestnews" => ""),
                        /**/"dn-whole"                          => array("content" => "",       "table" => "contentpane",            "latestnews" => ""),
                        /**/"dn-module_title"   => array("content" => "",      "table" => "sectiontableheader", "latestnews" => ""),
                        "dn-module_description" => array("content" => "contentdescription", "table" => "contentdescription", "latestnews" => ""),
                        "dn-each"               => array("content" => "contentpaneopen",                                        "table" => "sectiontableentry",  "latestnews" => ""),
                        /**/"dn-section"        => array("content" => "",      "table" => "",                    "latestnews" => ""),
                        /**/"dn-category"                       => array("content" => "",                                       "table" => "",                   "latestnews" => ""),
                        /**/"dn-date"                           => array("content" => "createdate",     "table" => "createdate", "latestnews" => "createdate"),
                        /**/"dn-author"                         => array("content" => "small",                          "table" => "",                   "latestnews" => "small"),
                        /**/"dn-head"                           => array("content" => "contentheading",         "table" => "",                   "latestnews" => "latestnews"),
                        "dn-hits"                               => array("content" => "",                                       "table" => "",                   "latestnews" => ""),
                        "dn-introtext"                  => array("content" => "",       "table" => "",                   "latestnews" => ""),
                        "dn-introtext-link"     => array("content" => "",      "table" => "",                    "latestnews" => ""),
                        "dn-fulltext"                   => array("content" => "",       "table" => "",                   "latestnews" => ""),
                        "dn-read_more"                  => array("content" => "readon",                         "table" => "readon",             "latestnews" => "readon"),
                        "dn"                                    => array("content" => "",                                       "table" => "",                   "latestnews" => "latestnews"),
                        "dn"                                    => array("content" => "",                                       "table" => "",                   "latestnews" => "latestnews"),
                        "arrow-dn"                              => array("content" => "",                                       "table" => "",                   "latestnews" => "latestnews"),
                        "list-dn"                               => array("content" => "",                                       "table" => "",                   "latestnews" => "latestnews"),
                        "dn-more"                               => array("content" => "",                                       "table" => "",                   "latestnews" => ""),
                        "dn-module_link"                => array("content" => "",                                       "table" => "",                   "latestnews" => "")
                );

                $result = $convert[$id][$this->css_type];
                return $result ? $result : "";

        }

        function dn_style( $id, $extra_style='',  $k = "" ) {
                $dnstyle=modDisplayNewsHelper::dn_style_convert($id)."${k}" ;
                return "class='${dnstyle}".$this->moduleclass_sfx." ".$extra_style."'";
        }

function imageResize($originalImage,$toWidth,$toHeight){

    // Get the original geometry and calculate scales
    $size = getimagesize($originalImage);
    if ( !$size || !$toWidth || !$toHeight ) {
        return;
    }
    list($width, $height) = $size;

        if ( $width <= $toWidth && $height <= $toHeight) {
                return " width=\"$width\" height=\"$height\" ";
        }

    $xscale=$width/$toWidth;
    $yscale=$height/$toHeight;

    // Recalculate new size with default ratio
    if ($yscale>$xscale){
        $new_width = round($width * (1/$yscale));
        $new_height = round($height * (1/$yscale));
    }
    else {
        $new_width = round($width * (1/$xscale));
        $new_height = round($height * (1/$xscale));
    }

        return " width=\"$new_width\" height=\"$new_height\" ";
}

function main(&$params)
{


global $mosConfig_lang, $mosConfig_mbf_content, $mainframe;


// $globalConfig = &JComponentHelper::getParams( 'com_content' );
// $globalConfig = &$mainframe->getParams('com_content');

static $globalConfig;
if (!isset($globalConfig) ) {
        $com_content = &JComponentHelper::getComponent( 'com_content' );
        $globalConfig = new JParameter($com_content->params);
}


//----- Parameters - Criteria ( 19 ) ------------------------------------------
$set_count = $params->get('set_count' ) ;
if ( !$set_count ) {
        $set_count = 1000000000;
}

$show_tooltips                  = $params->get( 'show_tooltips', 0 );
$set_date_today                 = $params->get( 'set_date_today', 0 );
// 5-10      5 - older than 5 days, newly than 10 days
// 5 newly than 5 days old
$set_date_range                 = $params->get( 'set_date_range', 0 );

$publish_up_spec = "";
if ( substr($set_date_range, 0, 1) == "p" ) {
                $set_date_newly = 0;
                $set_date_older = 0;
                $publish_up_spec = "p";
} else {
        $tokens = split("-", $set_date_range,2);
        if (count($tokens)==2) {
                $set_date_older = $tokens[0];
                $set_date_newly = $tokens[1];
        } else if ( count($tokens)==1 ) {
                $set_date_newly = $tokens[0];
                $set_date_older = 0;
        }
}

$set_date_month                 = $params->get( 'set_date_month', "" );
$set_date_year                  = $params->get( 'set_date_year', "");

$set_auto                       = $params->get( 'set_auto', 0 );
$set_auto_author                = $params->get( 'set_auto_author', 0);

// FIXME show_frontpage -> num value
$show_frontpage                 = $params->get( 'show_frontpage', "y" );

$set_category_id_extra       = $params->get( 'set_category_id_extra', 0);
//$set_category_id               = $params->get( 'set_category_id', 0);
if($params->get( 'manual', 0) == "0"){$set_category_id = $params->get( 'set_category_id', 0);}
else{
$set_category_id = $_GET['Itemid'];
if($params->get( 'categorytype', 0) == "0"){$set_category_id=$set_category_id+100;}

	}

$set_section_id_extra        = $params->get( 'set_section_id_extra', 0);
$set_section_id                 = $params->get( 'set_section_id', 0);

$set_article_id                 = $params->get( 'set_article_id', 0);

$set_author_id                  = $params->get( 'set_author_id', "");
$set_author_name                = $params->get( 'set_author_name', "");

$minus_leading                  = $params->get( 'minus_leading', 0 );
$hide_current                   = $params->get( 'hide_current', 0 );
//---------------------------------------------------------------------

//----- Parameters - Display ( 19 ) ------------------------------------------
$this->css_type = $params->get('css_type', "content" );
if ( $this->css_type == "dedicated" ) {
        $this->css_type = "";
}
$show_image = $params->get('image', 0);
$image_align = $params->get('image_align', 0);
// $image_valign = $params->get('image_valign', 0);
$image_margin = $params->get('image_margin', "");
$image_size = $params->get('image_size', "");
$image_scale = $params->get('image_scale', 1);
$image_width = $image_height = 150;
if ($image_size <> "") {
        $image_sizes = explode("x", $image_size);
        if ( isset($image_sizes[0]) && $image_sizes[0] > 0 ) {
                $image_width = $image_sizes[0];
        }
        if ( isset($image_sizes[1]) && $image_sizes[1] > 0 ) {
                $image_height = $image_sizes[1];
        } else {
                $image_height = $image_width;
        }
}
$image_scale = $params->get('image_scale', 1);
$image_num = $params->get('image_num', 0);
$link_image = $params->get('link_image', 0);

$show_title_auto = $params->get('show_title_auto' , 0 );
$use_modify_date = $params->get('use_modify_date', 0);
switch ($use_modify_date) {
        case 1:  $created = "modified"     ; break ;;
        case 2:  $created = "publish_up"   ; break ;;
        case 3:  $created = "publish_down" ; break ;;
        default: $created = "created"      ; break ;;
}
// $created = $use_modify_date ? "modified" : "created";

$show_more_auto = $params->get('show_more_auto', 0 );
//---------------------------------------------------------------------

//----- Parameters - Display Modifier ( 14 ) --------------------------------

$scroll_direction = $params->get('scroll_direction', "no");
$scroll_mouse_ctrl = $params->get('scroll_mouse_ctrl', "1");

$scroll_height = $params->get('scroll_height' , 100 );
$scroll_speed = $params->get('scroll_speed' , 1 );
$scroll_delay = $params->get('scroll_delay' , 30 );

$show_title_nextline = $params->get('show_title_nextline', 0 );

$filter_text = $params->get('filter_text' , 0 );
$length_limit_text = $params->get('length_limit_text' );

$filter_title = $params->get('filter_title' , 0 );
$length_limit_title = $params->get('length_limit_title' );

$format_date = $params->get('format_date', JText::_('DATE_FORMAT_LC1'));

$link_section = $params->get('link_section',   $globalConfig->get('link_section') );
$link_category = $params->get('link_category', $globalConfig->get('link_category') );

$link_titles = $params->get('link_titles', $globalConfig->get('link_titles') );
$link_text = $params->get('link_text' , 1 );
$format = $params->get('format', "%t<br>%s - %c<br>%d - %a<br>%p%i<br>%m<span class=\"article_separator\"> </span>");
$row_template = $params->get('row_template',
"(\$title_out.\$hits_out<>'' ? '<table><tr>' : '').
(\$title_out<>'' ? \"<td>\$title_out</td>\" : '').
(\$hits_out<>'' ? \"<td>(\$hits_out)</td>\" : '').
(\$title_out.\$hits_out<>'' ? '</tr></table>' : '').
(\$rate_out<>'' ? \"\$rate_out\" : '').
(\$sec_out<>'' ? \"\$sec_out\" : '').
(\$sec_out<>'' && \$cat_out<>'' ? '-' : '').
(\$cat_out<>'' ? \"\$cat_out\" : '').
(\$sec_out.\$cat_out<>'' ? '<br>' : '').
(\$author_out<>'' ? \"\$author_out\" : '' ).
(\$author_out<>'' && \$date_out<>'' ? ' - ' : '').
(\$date_out<>'' ? \"\$author_out\" : '').
(\$author_out.\$date_out<>'' ? '<br>' : '').
(\$img_out<>'' ? \"\$img_out\" : '').
(\$text_out<>'' ? \"\$text_out\" : '').
(\$readmore_out<>'' ? \"<br>\$readmore_out\" : '').
'<span class=\"article_separator\"> </span>'
" );


$use_rows_template = $params->get('use_rows_template', 1);

$module_template = $params->get('module_template', "( \$rows_out <> '' ?
(\$mod_title_out <> '' ? \"\$mod_title_out\" : '').
(\$mod_descr_out <> '' ? \"\$mod_descr_out\" : '' ).
\$mod_start_out.
\$rows_out.
\$mod_end_out.
(\$mod_automore_out <> '' ? \$mod_automore_out :'' )
: '' )
");

// $show_full_text = $params->get('show_full_text', 0);
$ordering = $params->get('ordering', "mostrecent");
$style = $params->get('style', "flat");

$show_readmore = $params->get('show_readmore', 2 );

$this->moduleclass_sfx = $params->get('moduleclass_sfx', "" );

//----- Parameters - Display Text ( 10 ) -------------------------------------
// Allows for multilingual customisation //
$text_module_description        = $params->get('text_module_description');
$text_readmore                          = $params->get('text_readmore');
$text_more                                      = $params->get('text_more', JText::_('More Articles...') );

//$text_title_auto_pre          = $params->get('text_title_auto_pre', "");
//$text_title_auto_suf          = $params->get('text_title_auto_suf', "");

$text_hover_section             = $params->get('text_hover_section', "");
$text_hover_category            = $params->get('text_hover_category', "");
$text_hover_title               = $params->get('text_hover_title', "");

$text_hover_readmore            = $params->get('text_hover_readmore', "");

$text_hover_more_section        = $params->get('text_hover_more_section', "");
$text_hover_more_category       = $params->get('text_hover_more_category', "");

$bottom_link_text = $params->get('bottom_link_text' );
$bottom_link_url = $params->get('bottom_link_url' );

$show_section  = $params->get('show_section', $globalConfig->get('show_section'));
$show_category = $params->get('show_category', $globalConfig->get('show_category'));
$show_date     = $params->get('show_date', ($use_modify_date == 1 ? $globalConfig->get('show_modify_date') : $globalConfig->get('show_create_date'))   );
$show_title    = $params->get('show_title', $globalConfig->get('show_title') );
$show_hits     = $params->get('show_hits', $globalConfig->get('show_hits') );
$show_author   = $params->get('show_author', $globalConfig->get('show_author'));
$show_text     = $params->get('show_text', 1);
$show_vote     = $params->get('show_vote', $globalConfig->get('show_vote') );

$plugins_disable   = $params->get('plugins_disable', 0 );
$set_column        = $params->get('set_column', 1 );
/* if (!$set_column) {
        $set_column = 1;
} */
$multi_column_order  = $params->get('multi_column_order', 0 );

//---------------------------------------------------------------------

//  Conflict Handler

/*
      $pf =0;

      for ( $i=0; $i < strlen( $format); $i += 1 ) {
            if ( $format[$i] == "%" ) {
               $pf = 1;
            } else {
               if ( $pf==1 ) {
                  $pf = 0;
                  switch ( $format[$i] ) {
                  case "s":
                     $show_section = 1;
                     break;
                  case "c":
                     $show_category = 1;
                     break;
                  case "d":
                     $show_date = 1;
                     break;
                  case "t":
                     $show_title = 1;
                     break;
                  case "h":
                     $show_hits = 1;
                     break;
                  case "a":
                     $show_author = 1;
                     break;
                  case "i":
                     $show_text = 1;
                     break;
                  case "r":
                     $show_vote = 1;
                     break;
                  case "%":
                     break;
                  default:
                  } // switch
               } // if ( pf
            } // if ( $format[i] == "%" )
      } // for

*/

$limit = "\n LIMIT $minus_leading, $set_count";

// 
if ($set_section_id_extra) {
	if ( !is_array($set_section_id) ) {
		$set_section_id = (array)$set_section_id;
	}

	$set_section_id = array_merge($set_section_id, explode( ',', $set_section_id_extra ));
 }

if ($set_category_id_extra) {
	if ( !is_array($set_category_id)) {
		$set_category_id = (array)$set_category_id;
	}

	$set_category_id = array_merge($set_category_id, explode( ',', $set_category_id_extra ));
 }

//---------------------------------------------------------------------

//---------------------------------------------------------------------

//  Functinality to allow text_hover to be blank by use if special character "#" entered
//  If not then space added to the end of the variables
modDisplayNewsHelper::dn_hovertext( $text_hover_section );
modDisplayNewsHelper::dn_hovertext( $text_hover_category );
modDisplayNewsHelper::dn_hovertext( $text_hover_title );
modDisplayNewsHelper::dn_hovertext( $text_hover_readmore );
modDisplayNewsHelper::dn_hovertext( $text_hover_more_section );
modDisplayNewsHelper::dn_hovertext( $text_hover_more_category );
modDisplayNewsHelper::dn_hovertext( $text_title_auto_pre );
modDisplayNewsHelper::dn_hovertext( $text_title_auto_suf );
//---------------------------------------------------------------------

// $blog = $section_link_blog ? "blog" : "";

$view = JRequest::getCmd('view');

$db             =& JFactory::getDBO();


// If { set_auto = y } then Module will automatically determine section/category id of current page and use this to control what news is dsiplayed
if ($set_auto) {

   if ($view == "section") {
                $temp                           = JRequest::getString('id');
                $temp                           = explode(':', $temp);
                $zsectionid         = $temp[0];
        $set_section_id     = $zsectionid;
        } elseif ($view == "category") {
                $temp                           = JRequest::getString('id');
                $temp                           = explode(':', $temp);
                $zcategoryid        = $temp[0];
        $set_category_id = $zcategoryid;
        } elseif ($view == "article") {
                $temp                           = JRequest::getString('id');
                $temp                           = explode(':', $temp);
        $zcontentid         = $temp[0];

                $temp = & JTable::getInstance( 'content' );
        $temp->load( $zcontentid );
        $set_category_id = $temp->catid;
        } else {
                return;
        }
}



// If { set_auto_author = y } then Module will automatically determine Author id of current page and use this to control what news is dsiplayed
if ($set_auto_author) {

    if ($view == "article") {
                $temp                           = JRequest::getString('id');
                $temp                           = explode(':', $temp);
        $zcontentid         = $temp[0];

                $result = null;
                $query = "SELECT created_by_alias, created_by, title FROM #__content WHERE id = '$zcontentid'";
                $db->setQuery($query);
                $result = $db->loadObject();

                switch ( $set_auto_author ) {
                case 1: // by article author
                        if ( $result->created_by_alias ) {
                                $set_author_name = $result->created_by_alias;
                        } else {
                                $db->setQuery("SELECT name FROM #__users WHERE id = ".$result->created_by );
                                $result = $db->loadObject();
                                $set_author_name = $result->name;
                        }
                        break;

                case 2: // by article name
                        $set_author_name = $result->title;
                        break;
                 }
        } else {
                return;
        }
}

if ($view == "article") {
                $temp                           = JRequest::getString('id');
                $temp                           = explode(':', $temp);
        $currcontentid      = $temp[0];
}



//---------------------------------------------------------------------

global $mainframe;
$config =& JFactory::getConfig();
$tzoffset = $config->getValue('config.offset');


//  Special variable used for management of different access levels
$access  = !$mainframe->getCfg( 'shownoauth' );

//  Handling required to create set Names, '' added
//---------------------------------------------------------------------

//  Special Handling to get $set_date_month to work correctly
if ($set_date_month != "") {
   if ($set_date_month == "0") {
      $set_date_month = date( "m", time()+$tzoffset*60*60 );
   }
}
//---------------------------------------------------------------------

//  Special Handling to get $set_date_year to work correctly
if ($set_date_year != "") {
   if ($set_date_year == 0) {
      $set_date_year = date( "Y", time()+$tzoffset*60*60 );
   }
}

//---------------------------------------------------------------------

######################################################################################################################################

//  Main Query & Array
switch ( $ordering ) {
case "mostread":
   $order_by = "a.hits DESC";
   break;
case "publish_up":
   $order_by = "a.publish_up DESC";
   break;
case "publish_down":
   $order_by = "publish_down_isnull asc, a.publish_down asc";
   break;
case "ordering":
   $order_by = "a.ordering ASC";
   break;
case "frontpageordering":
   $order_by = "b.ordering ASC";
   break;
case "title":
   $order_by = "a.title ASC";
   break;
case "mostold":
   $order_by = "created_isnull ASC, a.created ASC";
   break;
case "random":
   $order_by = "RAND()";
   break;
case "rating":
   $order_by = "(v.rating_sum / v.rating_count) DESC, v.rating_count DESC";
   break;
case "voting":
   $order_by = "v.rating_count DESC, (v.rating_sum / v.rating_count) DESC";
   break;
case "recentlymodified":
        $order_by = "a.modified DESC";
        break;
case "mostrecent":
default:
   $order_by = "a.created DESC";
}

$my =& JFactory::getUser();

$date =& JFactory::getDate();
$now = $date->toMySQL();
$nullDate = $db->getNullDate();


#modDisplayNewsHelper::dn_set_name( $set_section_id );
#modDisplayNewsHelper::dn_set_name( $set_category_id );
$set_author_name_for_select = modDisplayNewsHelper::dn_set_name( $set_author_name);


$query = "SELECT a.id ".
                ', CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug'.
                ', CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug'.
                ', a.attribs'.
($show_title ? ", a.title" : "" ).
($show_text  ? ", a.introtext as introtext" : "" ).
// (($show_text &&  $show_full_text) ? ", CONCAT(a.introtext, a.fulltext ) as text" : "" ).
( ($show_text > 1 || $show_readmore == 2 ) ? ", a.fulltext" : "" ).
                          ", a.sectionid ".
                          ", a.catid ".
($show_date   ? ", a.$created as created" : "" ).
($ordering == "publish_down" ? ', IF(publish_down = "0000-00-00 00:00:00", 1, 0) AS publish_down_isnull ' : '' ).
($ordering == "mostold"      ? ', IF(a.'.$created.' = "0000-00-00 00:00:00", 1, 0) AS created_isnull ' : '' ).
($show_author ? ', CASE WHEN CHAR_LENGTH(a.created_by_alias) THEN created_by_alias ELSE c.name END as author' : '' ).
($show_hits   ? ", a.hits" : "" ).
($show_image ? ", a.images" : "" )
.($show_vote ? ",round( v.rating_sum / v.rating_count ) AS rating, v.rating_count" : "" )

.( $show_more_auto || $show_section  || $show_category || $set_auto ?
                                        ', d.id as sec_id, d.title as sec_title, d.published as sec_published,
                                        cc.id as cat_id, cc.title as cat_title, cc.alias as cat_alias, cc.published as cat_published ' : '' )

.                                                               "\n FROM #__content AS a"
. ( ($show_frontpage == "n" || $show_frontpage == "only" ) ? "\n LEFT JOIN #__content_frontpage AS b ON b.content_id = a.id" : "" )
. ( ( $set_author_name<>"" || $show_author )            ? "\n JOIN #__users AS c ON c.id = a.created_by" : "" )
.                       "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
.           "\n INNER JOIN #__sections AS d ON d.id = a.sectionid"
   . ( ($show_vote || $ordering == "rating" || $ordering == "voting" ) ?
                                                                "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id" : "" )
   .                                                            "\n  WHERE (a.state = '1')"
   . ( ($publish_up_spec == "" )?       "\n  AND (a.publish_up = ".$db->Quote($nullDate)." OR a.publish_up <= ".$db->Quote($now)."  )" : "")
   . ( ($publish_up_spec == "p" )?      "\n  AND ( a.publish_up > ".$db->Quote($now)."  )" : "")
   .                                                            "\n  AND (a.publish_down = ".$db->Quote($nullDate)." OR a.publish_down >= ".$db->Quote($now)."  )"
   .                                                            "\n AND (d.published = '1')"
   .                                                            "\n AND (cc.published = '1')"
   . ($set_section_id ?         "\n   AND (a.sectionid IN (".(is_array($set_section_id) ? implode(",",$set_section_id) : $set_section_id) .") )" : '')
   . ( $set_category_id
                ?       "\n   AND (a.catid IN ( ".(is_array( $set_category_id ) ? implode(",",$set_category_id) : $set_category_id )." ) )" : '')
   . ($show_frontpage == "n" ?                                  "\n  AND (b.content_id IS NULL)" : '')
   . ($show_frontpage == "only" ?                               "\n  AND (b.content_id = a.id)" : '')
   . ($set_article_id ?                                         "\n  AND (a.id IN ($set_article_id) )" : '')
   . ($hide_current && $view == "article"?                      "\n  AND (a.id <> ($currcontentid) )" : '')
   . ($set_author_id <> "" ?                                            "\n  AND (a.created_by IN ($set_author_id) )" : '')
   . ($set_author_name <> "" ?                                  "\n  AND ((a.created_by_alias IN (".$set_author_name_for_select.")) OR
                                                                               ((a.created_by_alias = '' ) AND ( c.name IN (".$set_author_name_for_select."))) )" : '')
   . ($set_date_newly ?                                 "\n  AND (TO_DAYS(ADDDATE(NOW(), INTERVAL $tzoffset HOUR)) - TO_DAYS(ADDDATE($created, INTERVAL $tzoffset HOUR)) <= '$set_date_newly' )" : '')
   . ($set_date_older ?                                 "\n  AND (TO_DAYS(ADDDATE(NOW(), INTERVAL $tzoffset HOUR)) - TO_DAYS(ADDDATE($created, INTERVAL $tzoffset HOUR)) >= '$set_date_older' )" : '')

   . ($set_date_today ?                                         "\n   AND (TO_DAYS(ADDDATE(NOW(), INTERVAL $tzoffset HOUR)) = TO_DAYS(ADDDATE($created, INTERVAL $tzoffset HOUR)))" : '')
   . ($set_date_month ?                                         "\n  AND ($set_date_month = MONTH(ADDDATE($created, INTERVAL $tzoffset HOUR)))" : '')
   . ($set_date_year ?                                  "\n  AND ($set_date_year  = YEAR(ADDDATE($created, INTERVAL $tzoffset HOUR)))" : '')
   . ( isset($access) ? "\n AND a.access <= '".$my->get('gid')."'" : '' )
#******************************************#
//  This Controls the fact that this module displayes the Latest News first
   . "\n  ORDER BY $order_by"
#******************************************#
   . "\n $limit;"
;

$db =& JFactory::getDBO();



$db->setQuery( $query );

$rows = $db->loadObjectList();

######################################################################################################################################

   $mod_title_out = "";
   $mod_descr_out = "";
   $mod_start_out = "";
   $mod_end_out = "";
   $mod_automore_out = "";
   $rows_out = "";

   //  Error checker, that tests whether any data has resulted from the query
//  If not an Error message is displayed
if ($rows <> NULL) {

      // Code for displaying of individual items Section


        if ($show_more_auto ) {
      if  ( is_array($set_section_id) && !is_array( $set_category_id) )  {
         // $more_section = & JTable::getInstance( 'section' );
         // $more_section->load( $set_section_id_extra );
         $mod_automore_out .= "<span ".modDisplayNewsHelper::dn_style("dn-more").">";
         $mod_automore_out .= "<a href='".JRoute::_(ContentHelperRoute::getSectionRoute($rows[0]->sec_id))."' ".modDisplayNewsHelper::dn_style("dn-more")." ";
         if ( $show_tooltips ) {
                 $mod_automore_out .= "title=\"".htmlspecialchars($text_hover_more_section.$rows[0]->sec_title)."\"";
             }
         $mod_automore_out .= ">".$text_more."</a>";
         $mod_automore_out .= "</span>";
      } else if ( is_array($set_category_id) && !is_array($set_section_id) ) {
         // $more_category = & JTable::getInstance( 'category' );
         // $more_category->load( $set_category_id_extra );
                 $category->catslug = strlen( $rows[0]->cat_alias ) ?  $rows[0]->cat_id . ":" . $rows[0]->cat_alias : $rows[0]->cat_id;
                 $mod_automore_out .= "<span ".modDisplayNewsHelper::dn_style("dn-more").">";
         $mod_automore_out .= "<a href='".JRoute::_(ContentHelperRoute::getCategoryRoute($category->catslug, $rows[0]->sec_id))."' ".modDisplayNewsHelper::dn_style("dn-more")." ";
         if ( $show_tooltips ) {
                 $mod_automore_out .= "title=\"".htmlspecialchars($text_hover_more_category.$rows[0]->cat_title)."\"";
             }
         $mod_automore_out .= ">".$text_more."</a>";
         $mod_automore_out .= "</span>";
      }
   }


   //---------------------------------------------------------------------



   // If autotitle set to yes, displays an Auto Title preffix with the name of the section/category
   if ( $show_title_auto ) {

                /*if ($set_auto) {

                        if ($view == "section") {
                        ...........................
                                $set_section_id_extra;
                        } elseif ($view == "category") {
                        ..................
                                $set_category_id_extra;
                        } elseif ($view == "article") {
                        ...................
                                $set_category_id_extra;
                        }

                }
        ............
                if ($set_auto_author) {

                        if ($view == "article") {
                        .................................
                                        $set_author_name = $result->title;
                        }
                }
                 */

                $title_text = "";
                if ( $set_auto_author && $view == "article" ) {
                        $title_text = $text_title_auto_pre.$set_author_name.$text_title_auto_suf;
                } elseif ($set_auto) {
                        if ($view == "section") {
                                //$db->setQuery("SELECT a.title "
                                //."\n  FROM #__sections AS a"
                                //."\n  WHERE a.id=".$set_section_id_extra);
                                //$text_title_auto_mid = $db->loadResult();
                                $title_text = $text_title_auto_pre.($rows[0]->sec_title).$text_title_auto_suf;
                        } elseif ($view == "category" || $view == "article" ) {
                                //$db->setQuery("SELECT a.title FROM #__categories AS a WHERE a.id=$set_category_id_extra");
                                //$text_title_auto_mid = $db->loadResult();
                                $title_text = $text_title_auto_pre.($rows[0]->sec_title).$text_title_auto_suf;
                        }
                }

      $mod_title_out .= "<h3>";
      $mod_title_out .= $title_text;
      $mod_title_out .= "</h3>";
   }  //---------------------------------------------------------------------

      // Error check if more than one Sectionid entered (searches for , in parameter)
   //if ( strchr($set_section_id_extra, ",") ) {
   //   $set_section_id_extra = "";
   //}
   // Error check if more than one Categoryid entered (searches for , in parameter)
   //if ( strchr($set_category_id_extra, ",") ) {
   //   $set_category_id_extra = "";
   //}

   //---------------------------------------------------------------------



   if (strlen($text_module_description) > "0") {
      $mod_descr_out .= "\n \n";
      $mod_descr_out .= "<span ".modDisplayNewsHelper::dn_style("dn-module_description").">";
      $mod_descr_out .= "\n";
      $mod_descr_out .= $text_module_description;
      $mod_descr_out .= "\n </span>";
   }


   //---------------------------------------------------------------------

   $mod_start_out .= "\n<!-- START '".$this->version."' -->\n";

   // Activates scrolling text ability
   if ($scroll_direction != "no" ) {
	  $mod_start_out .= "\n \n";
	  $mod_start_out .= "<a href=\"index.php\">Все анонсы</a>";	  
      $mod_start_out .= "<marquee behavior='scroll' align='center'  direction='".$scroll_direction."'  height='".$scroll_height."' scrollamount='".$scroll_speed."' scrolldelay='".$scroll_delay."' truespeed ";
      if ( $scroll_mouse_ctrl ) {
        $mod_start_out .=  "onmouseover=this.stop() onmouseout=this.start() ";
      }
      $mod_start_out .=  " >";
   }  //---------------------------------------------------------------------


        switch ($style) {
        case 'flat':
                if ($set_column > 1) {
                        $mod_start_out .= "\n<table ".modDisplayNewsHelper::dn_style("dn-whole")."><tr>";
                } else {
                        $mod_start_out .= "\n<span".modDisplayNewsHelper::dn_style("dn-whole").">";
                }
                break;
        case 'flatarrow':
                if ($set_column > 1) {
                        $mod_start_out .= "\n<table ".modDisplayNewsHelper::dn_style("dn-whole")."><tr>";
                } else {
                        $mod_start_out .= "\n<span".modDisplayNewsHelper::dn_style("dn-whole").">";
                }
                break;
    case 'flatlist':
                if ($set_column > 1) {
                        $mod_start_out .= "\n<table ".modDisplayNewsHelper::dn_style("dn-whole")."><tr>";
                } else {
                        $mod_start_out .= "\n<span".modDisplayNewsHelper::dn_style("dn-whole").">";
                }
                break;
        default:
                $mod_start_out .= "\n<table ".modDisplayNewsHelper::dn_style("dn-whole").">";
        }

   switch ($style ) {
        case 'flat':
                if ($set_column > 1) {
                        $mod_end_out .= "</tr></table>"; // dn-whole
                } else {
                        $mod_start_out .= "\n</span>";
                }
                break;
   case 'flatarrow':
                if ($set_column > 1) {
                        $mod_end_out .= "</tr></table>";
                } else {
                        $mod_start_out .= "\n</span>";
                }
                break;
   case 'flatlist':
                if ($set_column > 1) {
                        $mod_end_out .=  "</tr></table>";
                } else {
                        $mod_start_out .= "\n</span>";
                }
                break;
        default:
                $mod_end_out .= '</table>';
   }

   if ($scroll_direction != "no" ) {
         $mod_end_out .= "</marquee>";
   }
   //---------------------------------------------------------------------

   $mod_end_out .= "\n";

   //---------------------------------------------------------------------

   //---------------------------------------------------------------------


   //
   if ( ($bottom_link_text <> NULL) && ($bottom_link_url <> NULL) ){
      $mod_end_out .= "<span ".modDisplayNewsHelper::dn_style("dn-module_link").">";
      $mod_end_out .= "<a href='".$bottom_link_url."' ".modDisplayNewsHelper::dn_style("dn-module_link")." ";
      if ( $show_tooltips ) {
              $mod_end_out .= "title='".$bottom_link_text."'";
          }
      $mod_end_out .= ">";
      $mod_end_out .= $bottom_link_text;
      $mod_end_out .= "</a>";
      $mod_end_out .= "</span>";
   }
   //---------------------------------------------------------------------

   //---------------------------------------------------------------------

}

   $mod_end_out .= "\n<!-- END '".$this->version."' -->\n";





   $rows_count = count($rows);

                                // $i = $i + $rows_count ;



   $vr = (int)(($rows_count+$set_column-1)/$set_column);

       if ( ($set_column > 1)  && ($style == 'vert') ) {
                $newrows = array();

                for ( $i = 0; $i < $vr; $i++ ) {
                        for ( $j = 0; $j < $set_column; $j++) {
                            // print ($i+$j*$vr);                              print "\n";
                                if ($i+$j*$vr < $rows_count) {
                                        $newrows[] = & $rows[$i+$j*$vr];
                                }

                        }
                }

                $rows = $newrows;
        }


   /*
    if ( ($set_column > 1)  && ($multi_column_order == 1) ) {
                $newrows = array();

                for ( $j = 0; $j < $set_column; $j++) {
                        for ( $i = 0; $i < $vr; $i++ ) {
                                if ($i*$set_column+$j < $rows_count) {
                                    echo "j=$j i=$i ".intval($i*$set_column+$j)."<br>";
                                        $newrows[] = & $rows[$i*$set_column+$j];
                                }
                        }
                }

                $rows = $newrows;
        }*/

   // Start of Loop //
   $k = 0;
   $r = 0;
   $c = 0;
   $v = 0;

   foreach ($rows as $row) {

      $r++;
          $v++;

          $sec_out =  "";
          $cat_out =  "";
          $date_out =  "";
          $author_out =  "";
          $title_out =  "";
          $hits_out =  "";
          $rate_out =  "";
          $text_out =  "";
          $readmore_out =  "";
          $title_text =  "";
          $img_out = "";
      $row_out = "";

          $row_start_out = "";
      // $row_start_out .= "\n\t";

        $aparams = new JParameter($row->attribs);


        $aroute = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid ));


        $row->text = "";
        if ( $show_text ) {
                if ( $show_text > 1 ) {
                    if ($aparams->get('show_intro', $globalConfig->get('show_intro'))) {
                                $row->text .= $row->introtext;
            }
            $row->text .= " ".$row->fulltext;
                } else {
                        $row->text .= $row->introtext;
                }
        }


    switch ($style) {
    case 'flat':
            if ($v == 1)  {
                        $c++;
                        if ($set_column > 1) {
                                $row_start_out .= "<td width=\"".(int)(100/$set_column)."%\" valign=\"top\" class=\"".( $c >1 ? "column_separator" : "" )."\" >";
                        }
                }
                $row_start_out .= "<div ".modDisplayNewsHelper::dn_style("dn-each", ( $this->css_type == "table" ) ? ($k+1) : "" )." >";
                break;
        case 'flatarrow':
            if ($v == 1)  {
                        $c++;
                        if ($set_column > 1) {
                                $row_start_out .= "<td width=\"".(int)(100/$set_column)."%\" valign=\"top\" class=\"".( $c > 1 ? "column_separator" : "" )."\" >";
                        }
                        $row_start_out .= "<ul>";

                }
                $row_start_out .= "<li ".modDisplayNewsHelper::dn_style("arrow-dn").">";
                break;
    case 'flatlist':
            if ($v == 1)  {
                        $c++;
                        if ($set_column > 1) {
                                $row_start_out .= "<td width=\"".(int)(100/$set_column)."%\" valign=\"top\"  class=\"".( $c > 1? "column_separator" : "" )."\">";
                        }
                        $row_start_out .= "<ol start=$r>";

                }
                $row_start_out .= "<li ".modDisplayNewsHelper::dn_style("list-dn").">";
                break;
        default:
                $c++;
            if ($c == 1) {
                        $row_start_out .= "<tr >";
                }
        $row_start_out .= "<td ".modDisplayNewsHelper::dn_style("dn-each", ( $c > 1 ? "column_separator" : "" ), ( $this->css_type == "table" ) ? ($k+1) : "" )." width=\"".(int)(100/$set_column)."%\""." valign=\"top\"".">";
        }


      // Start of Module Display for each News Item

      if ( $this->css_type == "table" ) {
              $k = 1 - $k;
          }

        if ( isset($mosConfig_jf_content) && $mosConfig_jf_content){
                  $row = JoomFish::translate( $row, 'content', $mosConfig_lang);
        }
      //---------------------------------------------------------------------


        // define the regular expression for the bot
      $regex = "{moscomment}";

       // perform the replacement
    if ( $show_text ) {
                $row->text = str_replace( $regex, '', $row->text );

                // Removes instances of {mospagebreak} from being displayed
                $row->text = str_replace( '{mospagebreak}', '', $row->text );
        }
      //---------------------------------------------------------------------

          if ( !$plugins_disable ) {
                $results = $mainframe->triggerEvent('onPrepareContent', array (&$row, &$aparams, 1));
          }
      //---------------------------------------------------------------------

      // Loads the section information into variable $section
      /*if ( $show_section  || $show_category ) {
         $section =& JTable::getInstance( 'section' );
         $section->load( $row->sectionid );
         //  Mambelfish Support
         if( $mosConfig_mbf_content ) {
                      $section = JoomFish::translate( $section, 'sections', $mosConfig_lang);
         }
      }

      // loads the category inion into variable $category
      if ( $show_category ) {
             $category = & JTable::getInstance( 'category' );
                 if ( $category ) {
             $category->load( $row->catid );
                 $category->catslug = strlen( $category->alias ) ?  $category->id . ":" . $category->alias : $category->id;
                 // CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug
         //  Mambelfish Support
         if( $mosConfig_mbf_content ) {
            $category = JoomFish::translate( $category, 'categories', $mosConfig_lang);
         }
                 }
      }
          */
      //---------------------------------------------------------------------


      //To show date item created, date mambot called
          $create_date = null;
      if ( ($show_date ) && (intval( $row->created ) <> NULL) ) {
         $create_date = JHTML::_('date', $row->created, $format_date );
      }
      //---------------------------------------------------------------------


      // Converts the user id number of the author to their name and loads this into the $author variable
      /*if ( $show_author ) {
         if ( $row->created_by_alias != '' )
                        $author = $row->created_by_alias;
         else {
                        $db->setQuery("SELECT a.name"
                        ."\n  FROM #__users AS a"
                        ."\n  LEFT JOIN #__content AS b ON a.id=b.created_by"
                        ."\n  WHERE a.id=".$row->created_by);
                        $author = $db->loadResult();
                 }
      }*/
      // Will check to see if item uses a created by alias, if it does, it loads this into the $author variable
      // however, if the item only has a created by value, it converts the user id number of the author to their name and loads this into the $author variable
      //---------------------------------------------------------------------





      if ($show_section ) {
         // $sec_out .= "\n\t\t";
         $sec_out .=  "<span ".modDisplayNewsHelper::dn_style("dn-section").">";
         if ($link_section ) {
            if ($row->sec_published == "1") {
               // $sec_out .=  "\n\t\t\t";
               // $sec_out .=  "<a href='".JRoute::_("index.php?option=com_content&task=${blog}section&id=$section->id".$_Itemid."")."' ".modDisplayNewsHelper::dn_style("dn-section")." ";
               $sec_out .=  "<a href='".JRoute::_(ContentHelperRoute::getSectionRoute($row->sec_id))."' ".modDisplayNewsHelper::dn_style("dn-section")." ";

               if ( $show_tooltips ) {
                       $sec_out .=  "title=\"".htmlspecialchars($text_hover_section.$row->sec_title)."\"";
                   }
               $sec_out .=  ">".$row->sec_title."</a>";
            } else {
               $sec_out .=  $row->sec_title;
            }
         } else {
            $sec_out .=  $row->sec_title;
         }
         $sec_out .=  "</span>";
      }
      //---------------------------------------------------------------------


      // Code for displaying of individual items Category
      if ($show_category ) {
         $cat_out .= "<span ".modDisplayNewsHelper::dn_style("dn-category").">";
         if ($link_category ) {
            if ($row->cat_published == "1") {
               $cat_out .= "<a href='".JRoute::_(ContentHelperRoute::getCategoryRoute($row->catslug, $row->sec_id))."' ".modDisplayNewsHelper::dn_style("dn-category")." ";
               if ( $show_tooltips ) {
                       $cat_out .= "title=\"".htmlspecialchars($text_hover_category.$row->cat_title)."\"";
                   }
               $cat_out .= ">".$row->cat_title."</a>";
            } else {
               $cat_out .= $row->cat_title;
            }
         } else {
            $cat_out .= $row->cat_title;
         }
         $cat_out .= "</span>";
      }  //---------------------------------------------------------------------


      // Code for displaying of individual items Date
	  
      if ( $create_date <> null && $show_date && ( ($show_date == 1)  || ($aparams->get('show_date', $globalConfig->get('show_date'))) ) )  {
         $date_out .= "<span ".modDisplayNewsHelper::dn_style("dn-date").">";
         $date_out .= $create_date;
         $date_out .= "</span>";
      }
      //---------------------------------------------------------------------


      // Code for displaying of individual items Author
      if ( $show_author && ( ($show_author == 1)  || ($aparams->get('show_author', $globalConfig->get('show_author'))) ) )  {
         $author_out .= "<span ".modDisplayNewsHelper::dn_style("dn-author").">";
         $author_out .= $row->author;
         $author_out .= "</span>";
      }
      //---------------------------------------------------------------------


      // Code for displaying of individual items Title
      if ($show_title ) {
         $title = $row->title;
         $title = JFilterOutput::ampReplace( $title );
         if ($filter_title ) {
            $title = modDisplayNewsHelper::dn_filter( $title );
                        modDisplayNewsHelper::dn_limit( $title, $filter_title, $length_limit_title, "" );
         }
         /*if ($show_title_nextline ) {
            $length = strlen($title);
            if ($length > $length_chars_title) {
               $titlefirstline = strtok($title, " ");
               $length = strlen($titlefirstline);
               while ($length < $length_chars_title) {
                  $titlefirstline .= " ";
                  $titlefirstline .= strtok(" ");
                  $length = strlen($titlefirstline);
               }
               $lengthfull = strlen($title);
               $titlesecondline = substr($title, $length, $lengthfull);
               $title = $titlefirstline."<br />".$titlesecondline;
            }
         }*/
         //  HTML for outputing of Title
         $title_out .= "<".( $this->css_type == "content" ? "h2" : "span" )." ".modDisplayNewsHelper::dn_style("dn-head").">";
         if ($link_titles ) {
            $title_out .= "<a href='".$aroute."' ".modDisplayNewsHelper::dn_style("dn-title")." ";
            if ( $show_tooltips ) {
                    $title_out .= "title=\"".htmlspecialchars($text_hover_title.$row->title)."\"";
                }
            $title_out .= ">".$title."</a>";
         } else {
            $title_out .= $title;
         }
         $title_out .= "</".( $this->css_type == "content" ? "h2" : "span" ).">";
      }
      //---------------------------------------------------------------------

      if ($show_hits ) {

         $hits_out .= "<span ".modDisplayNewsHelper::dn_style("dn-hits").">";
         $hits_out .= $row->hits;
         $hits_out .= "</span>";
      }

            //---------------------------------------------------------------------

      if ($show_vote ) {
                // look for images in template if available
                $img = '';
                $starImageOn    = JHTML::_('image.site',  'rating_star.png', '/images/M_images/' );
                $starImageOff   = JHTML::_('image.site',  'rating_star_blank.png', '/images/M_images/' );

                for ($i=0; $i < $row->rating; $i++) {
                        $img .= $starImageOn;
                }
                for ($i=$row->rating; $i < 5; $i++) {
                        $img .= $starImageOff;
                }

                $rate_out .= '<span class="content_rating">';
                $rate_out .= JText::_( 'User Rating' ) .':'. $img .'&nbsp;/&nbsp;';
                $rate_out .= intval( $row->rating_count );
                $rate_out .= "</span><br />";
      }



          $text="";

      // Code for displaying of individual items Intro Text
      if ($show_text ) {

        $text = $row->text;

                if (!$show_image) {
                        $text = preg_replace( '/<img[^>]*>/i', '', $text );
                }

                if ($show_image && $image_scale) {
                                $text = preg_replace( '/(<img[^>]*)(\s+width\s*=\s*["\']?\w+["\']?)([^>]*>)/i', '$1 $3', $text );
                                $text = preg_replace( '/(<img[^>]*)(\s+height\s*=\s*["\']?\w+["\?]?)([^>]*>)/i', '$1 $3', $text );
                                $text = preg_replace( '/(<img[^>]*\s+style\s*=\s*".*)(\s?width\s*:\s*\w+\s*[;]?)([^>]*>)/i', '$1 $3', $text );
                                $text = preg_replace( '/(<img[^>]*\s+style\s*=\s*".*)(\s?height\s*:\s*\w+\s*[;]?)([^>]*>)/i', '$1 $3', $text );
                                if ( $image_scale < 3 ) {
                                        $text = preg_replace( '/(<img[^>]*)(>)/i', '$1 '.( $image_scale == 1 ? "width=".$image_width : "height=".$image_height ).' $2', $text );
                                } else if ( $image_scale == 3 ) {
                                        $text = preg_replace_callback( '@(<img[^>]*\s+src\s*=\s*)(["\']*)([^"\']+)(["\']*)([^>]*>)@i',
                                                                create_function(
                                                                        // single quotes are essential here,
                                                                        // or alternative escape all $ as \$
                                                                        '$img',
                                                'return $img[1].$img[2].$img[3].$img[4]." ".modDisplayNewsHelper::imageResize($img[3],'.$image_width.','.$image_height.')." ".$img[5];'
                                                                ),
                                                                $text
                                                        );
                                }
                }



                if ($show_image && $image_align) {
                        $text = preg_replace( '/(<img[^>]*)(\s+align\s*=\s*["\']?\w+["\']?)([^>]*>)/i', '$1 $3', $text );
                        $text = preg_replace( '/(<img[^>]*\s+style\s*=\s*".*)(\s?float\s*:\s*\w+\s*[;]?)([^>]*>)/i', '$1 $3', $text );
                        $text = preg_replace( '/(<img[^>]*\s+style\s*=\s*".*)(\s?align\s*:\s*\w+\s*[;]?)([^>]*>)/i', '$1 $3', $text );

                        switch ($image_align) {
							case 2: $align="left"; break;
							case 3: $align="right"; break;
							case 4: $align="middle"; break;
							case 5: $align="top"; break;
							case 6: $align="bottom"; break;
                            case 7: $align = $r%2 ? "left"  : "right"; break;
                            case 8: $align = $r%2 ? "right" : "left "; break;
                        }
                        if ( $image_align >= 2) {
                                $text = preg_replace( '/(<img\s+[^>]*)(\/\s*>)/i', '$1 align="'.$align.'" $2', $text );
                        }
                }

                /* if ($show_image && $image_valign) {
                        $text = preg_replace( '/(<img[^>]*)(\s+valign\s*=\s*["\']?\w+["\']?)([^>]*>)/i', '$1 $3', $text );
                        $text = preg_replace( '/(<img[^>]*\s+style\s*=\s*".*)(\s?vertical-align\s*:\s*\w+\s*[;]?)([^>]*>)/i', '$1 $3', $text );

                        switch ($image_align) {
                                case 2: $valign="top"; break;
                            case 3: $valign="bottom"; break;
                                case 4: $valign="middle"; break;
                        }
                        if ( $image_align >= 2) {
                                $text = preg_replace( '/(<img\s+[^>]*)(\/\s*>)/i', '$1 valign="'.$valign.'" $2', $text );
                        }
                }*/
				
                if ($show_image && $image_margin<>"") {
					$text = preg_replace( '/(<img[^>]*)(\s+hspace\s*=\s*["\']?\w+["\']?)([^>]*>)/i', '$1 $3', $text );
					$text = preg_replace( '/(<img[^>]*\s+style\s*=\s*".*)(\s?margin[^:"]*\s*:\s*[^;"]*[;]?)([^>]*>)/i', '$1 $3', $text );
					// $text = preg_replace( '/(<img[^>]*\s+)((style\s*=\s*")([^"]*)(["]))+(.*[^>]*>)/i', '$1  $3 $4 $5 ', $text );

					
					$text = preg_replace( '/(<img[^>]*\s+)((style\s*=\s*["])([^"]*)(["]))([^>]*>)/i', 
						'$1 style="margin: '.$image_margin.'; $4 " $6', $text );
						// '$1 AAA="margin:'.$image_margin.'; $4" $6', $text );
					// $text = preg_replace( '/(<img\s+[^>]*)(>)/i', '${1} ; ${2}', $text );
                }

                if ($image_num) {
                        global $i;
                        $i = 0;

                        $text = preg_replace_callback( '/<img[^>]*>/i',
                                                create_function(
                                                        // single quotes are essential here,
                                                        // or alternative escape all $ as \$
                                                        '$img',
                                                        'global $i; $i ++; if ($i <= '.$image_num.') return $img[0];'
                                                ),
                                                $text
                                        );
                }

// $title_out .= "<a href='".JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid ))."' >".$title."</a>";

                if ( $show_image > 1 ) {
                        preg_match_all('/(?<img><img[^>]+>)/i',$text, $out);
                        $i = 0;
                        foreach ($out["img"] as $val) {
                                if ($link_image) {
                                        $img_out .= "<a href=".$aroute." >";
                                }
                                $img_out .= $val;
                                if ($link_image) {
                                        $img_out .= "</a>";
                                }
                                $i++;
                                if ( $image_num ) {
                                        if ( $i >= $image_num-1 ) {
                                                break;
                                        }
                                }
                        }

                        $text = preg_replace( '/<img[^>]*>/i', '', $text );
                }


                //$link1 = "<a href=".$aroute." >";
                //$link2 = "</a>";

                // $text ="";
                //foreach ($out["txt"] as $val) {
                //      $text .= $val;
                //}
                if ( $show_image && $link_image && !$link_text ) {

                        $text = preg_replace_callback( '/<img[^>]*>/i',
                                                create_function(
                                                        // single quotes are essential here,
                                                        // or alternative escape all $ as \$
                                                        '$img',
                                                        "return \"<a href=$aroute>\".\$img[0].\"</a>\";"
                                                ),
                                                $text
                                        );
                }

        $text = JFilterOutput::ampReplace($text);
                $text_limited = 0;
        if ($filter_text ) {
            $text = modDisplayNewsHelper::dn_filter( $text );
                $text_limited = modDisplayNewsHelper::dn_limit( $text, $filter_text, $length_limit_text,
                                                                        "" /* $show_readmore ? JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid )) : ""  */);
         }

         //  HTML for outputing of Intro Text
         $text_out = "<span ".modDisplayNewsHelper::dn_style("dn-introtext").">";
         if ($link_text ) {
            $text_out .= "<a href='".$aroute."' ".modDisplayNewsHelper::dn_style("dn-introtext-link")." ";

            if ( $show_tooltips ) {
                    $text_out .= "title=\"".htmlspecialchars($text_hover_title.$row->title)."\"";
                }
            $text_out .= ">";
         }

         if ($link_text ) {
                $text_out .= preg_replace( '/(<a\w+href\w*=[^>]*>)|(<\w*\/a\w*>)/i', '', $text );
         } else {
                $text_out .= $text;
         }
         if ($link_text ) {
            $text_out .= "</a>";
         }
         $text_out .= "</span>";
      }
      //---------------------------------------------------------------------

      // Code for displaying of individual items Read More link
      // $show_text && $show_full_text
        if ( ($show_readmore == 1) ||
             (($show_readmore == 2) && !$show_text ) ||
             (($show_readmore == 2) && $text_limited ) ||
             (($show_readmore == 2) && ( $filter_text < 2 ) && strlen( $row->fulltext ) && !($show_text > 1 ) )
            ) {
         // $readmore_out .= "<span ".modDisplayNewsHelper::dn_style("dn-read_more").">";

         $readmore_out .= "<a href='".$aroute."' ".modDisplayNewsHelper::dn_style("dn-read_more")." ";

         if ( $show_tooltips ) {
                 $readmore_out .= "title=\"".htmlspecialchars($text_hover_readmore.$row->title)."\"";
             }
         $readmore_out .= ">". ( $text_readmore != "" ? $text_readmore : ( $aparams->get('readmore') ? $aparams->get('readmore') : JText::_('Подробнее...') ) )."</a>";
         //$readmore_out .= "</span>";
      }
      //---------------------------------------------------------------------


                $read_more_shown = 1;

        if ( ! $use_rows_template ) {

                $read_more_shown = 0;
        $pf =0;
         for ( $i=0; $i < strlen( $format); $i += 1 ) {
            if ( $format[$i] == "%" ) {
               $pf = 1;
            } else {
               if ( $pf==1 ) {
                  $pf = 0;
                  switch ( $format[$i] ) {
                  case "s":
                     $row_out .= $sec_out;
                     break;
                  case "c":
                     $row_out .=  $cat_out;
                     break;
                  case "d":
                     $row_out .= $date_out;
                     break;
                  case "t":
                     $row_out .= $title_out;
                     break;
                  case "h":
                     $row_out .= $hits_out;
                     break;
                  case "a":
                     $row_out .= $author_out;
                     break;
                  case "p":
                     $row_out .= $img_out;
                     break;
                  case "i":
                     $row_out .= $text_out;
                     break;
                  case "r":
                     $row_out .= $rate_out;
                     break;
                  case "m":
                     $row_out .= $readmore_out;
                                         $read_more_shown = 1;
                     break;
                  case "%":
                     echo "%";
                     break;
                  default:
                  } // switch
               } else {
                  $row_out .= $format[$i];
               } // if ( pf
            } // if ( $format[i] == "%" )
            // echo $out;
         } // for
                } else {
						$css_type = $this->css_type;
                        eval("\$row_out = $row_template;");
                //eval("\$str = \"$str\";");
                }

                $row_end_out = "";

         // echo "rows_count=$rows_count r=$r set_column=$set_column c=$c <br>";

          if (!$read_more_shown) {
                        $row_end_out .= $readmore_out; // read more is not element of format, but should be printed at the end of each content entry
          }

      switch ($style) {
      case 'flat':
                // $row_end_out .= '<span class="article_separator">&nbsp;</span>';
                $row_end_out .= '</div>';
            if ( ($v == $vr) || ($rows_count - $r - 1  < $set_column - $c) ) {
                        $row_end_out .= "</td>";
                        $v = 0;
                }
                break;
      case 'flatlist':
        $row_end_out .= '</li>';
            if ( ($v == $vr) || ($rows_count - $r - 1 < $set_column - $c ) ) {
                        $row_end_out .= "</ol></td>";
                        $v = 0;
                }
                break;
          case 'flatarrow':
        $row_end_out .= '</li>';
            if ( ($v == $vr) || ($rows_count - $r - 1  < $set_column - $c) ) {
                        $row_end_out .= "</ul></td>";
                        $v = 0;
                }
                break;
          default:
        $row_end_out .= '</td>';
            if ($c == $set_column) {
                        $row_end_out .= "</tr>";
                        $c = 0;
                }
          }

/*
         ?>
                <table width="100%"  cellpadding="0" cellspacing="0">
                <tr>
                <?php
                        $divider = '';
                        if ($this->params->def('multi_column_order',0)) : // vert
                                for ($z = 0; $z < $set_column; $z ++) :
                                        if ($z > 0) : $divider = " column_separator"; endif; ?>
                                        <?php
                                                $rows = (int) ($set_count / $set_column);
                                                $cols = ($set_count % $set_column);
                                        ?>
                                        <td valign="top" width="<?php echo intval(100 / $set_column) ?>%" class="article_column<?php echo $divider ?>">
                                        <?php
                                        $loop = (($z < $cols)?1:0) + $rows;

                                        for ($y = 0; $y < $loop; $y ++) :
                                                $target = $i + ($y * $set_column) + $z;
                                                if ($target < $this->total && $target < ($set_count)) :
                                                        $this->item =& $this->getItem($target, $this->params);
                                                        echo $this->loadTemplate('item');
                                                endif;
                                        endfor;
                                                        ?></td>
                  <?php endfor;
                                                $i = $i + $set_count ;
                        else : // otherwise, order down columns, like old category blog
                                for ($z = 0; $z < $set_column; $z ++) :
                                        if ($z > 0) : $divider = " column_separator"; endif; ?>
                                        <td valign="top" width="<?php echo intval(100 / $set_column) ?>%" class="article_column<?php echo $divider ?>">
                                        <?php for ($y = 0; $y < ($set_count / $set_column); $y ++) :
                                        if ($i < $this->total && $i < ($set_count)) :
                                                $this->item =& $this->getItem($i, $this->params);
                                                echo $this->loadTemplate('item');
                                                $i ++;
                                        endif;
                                endfor; ?>
                                </td>
                <?php endfor;
                endif;?>
                </tr>
                </table>
<?php

          */


























          $rows_out .= $row_start_out;
      $rows_out .= $row_out;
          $rows_out .= $row_end_out;

          // echo "v=$v vr=$vr<br>";

   }
/*
        switch ($style) {
          case 'vert':
      case 'horiz':
      case 'flatlist':
          case 'flatarrow':
          default:
                while ( $c < $set_column) {
                        $c ++;
                        $rows_out .= "<td></td>";
                }
          }
*/

   // End of Loop //

   eval("\$out = $module_template;");

   echo $out;


   /* echo "".
   ( $mod_title_out <> '' ? "<h3>$mod_title_out</h3>" : '').
   ( $mod_descr_out <> '' ? "$mod_descr_out" : '' ).
   $mod_start_out.
   $rows_out.
   ( $mod_automore_out <> '' ? $mod_automore_out :'' ).
   $mod_end_out;*/



} // dn_main

}


?>