<?php
/**
 * Pro Super Slider
 *This program is free software: you can redistribute it and/or modify it under the terms
 *of the GNU General Public License as published by the Free Software Foundation,
 *either version 3 of the License, or (at your option) any later version.
 *
 *This program is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU General Public License for more details.
 *
 *You should have received a copy of the GNU General Public License
 *along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *@author ProJoom
 *@copyright (C) 2008 - 2012 ProJoom
 *@link http://www.projoom.com/extensions/pro-super-slider.html Official website
 **/
defined('_JEXEC') or die('Access denied!');
error_reporting(E_ALL ^ E_NOTICE);
global $mainframe; 
$cache_flush = 'w2b4u2w2c4';
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.path');
jimport('joomla.filesystem.archive');
$document = &JFactory::getDocument();
require_once (dirname(__file__) . DS . 'helper.php');
$pj_hlp = new pj_hlp();
$vscript = $params->get('vscript');
$nofl = $params->get('nofl');
$objalign = $params->get('objalign');
$nsswidth = $params->get('nsswidth');
$nssheight = $params->get('nssheight');
$nsslinecol = $params->get('nsslinecol');
$nssnumcol = $params->get('nssnumcol');
$nssbbgcol = $params->get('nssbbgcol');
$nssfont = $params->get('nssfont');
$nssprogcol = $params->get('nssprogcol');
$nssalpha = $params->get('nssalpha');
$nssshownav = $params->get('nssshownav');
$nssbutpos = $params->get('nssbutpos');
$nssspace = $params->get('nssspace');
$nssbpad = $params->get('nssbpad');
$nsstitsize = $params->get('nsstitsize');
$nssdescsize = $params->get('nssdescsize');
$nsstitcol = $params->get('nsstitcol');
$nsstitbld = $params->get('nsstitbld');
$nssdesccol = $params->get('nssdesccol');
$nssdescbld = $params->get('nssdescbld');
$nssfadespd = $params->get('nssfadespd');
$nssloop = $params->get('nssloop');
$tempvar = $params->get('nsscatid');
$tempvar2 = $params->get('nsscatsel');
$useasgal = $params->get('useasgal');
$globaldelay = $params->get('globaldelay');
$globallink = $params->get('globallink');
$globaltgt = $params->get('globaltgt');
$picdir = $params->get('picdir');
$limratio = $params->get('limratio');
$limitsz = $params->get('limitsz');
$limithgt = $params->get('limithgt');
$limitwdt = $params->get('limitwdt');
$nssmixed = $params->get('nssmixed');
$deldemo = $params->get('deldemo');
$debug_key = "";
$debug_key = JRequest::getVar('pj', '', 'get');
$pjurl = $params->get('pjurl');
if ($pjurl == '1') {
    $RURL = JURI::base();
} else {
    $RURL = JURI::base(true) . '/';
}
$pj_hlp->init($RURL);
$nofl = $pj_hlp->nofl($nofl);
if (!empty($tempvar)) {
    $catid = explode(",", $tempvar);
} else {
    if ($tempvar2 != 0) {
        $catid = explode(",", $tempvar2);
    }
}
$pj_hlp->setperms(JPATH_BASE . "/modules/mod_novass/engine");
$nsssort = $params->get('nsssort');
if ($nsssort == "rnd") {
    $rndmz = " ORDER BY RAND()";
} else {
    $rndmz = " ORDER BY ordering";
}
$compat = $pj_hlp->mode($vscript, 'mod_novass');
if ($deldemo == "yes") {
    $local_path = JPATH_BASE . "/modules/mod_novass";
    $pj_hlp->deldemo($local_path, 'mod_novass');
}
$nssshownav = ($nssshownav == 'enabled') ? "true" : "false";
$nsstitcol = str_replace('#', '', $nsstitcol);
$nssdesccol = str_replace('#', '', $nssdesccol);
$nsslinecol = str_replace('#', '', $nsslinecol);
$nssnumcol = str_replace('#', '', $nssnumcol);
$nssprogcol = str_replace('#', '', $nssprogcol);
$nssbbgcol = str_replace('#', '', $nssbbgcol);
$nsstitstart = '<font color="#' . $nsstitcol . '">';
$nsstitend = '</font>';
$nssdescstart = '<font color="#' . $nssdesccol . '">';
$nssdescend = '</font>';
if ($nssloop == 'yes') {
    $loop = "true";
} else {
    $loop = "false";
}
if ($useasgal == "yes") {
    $nssalpha = '0';
}
$err_m = "";
$file_number = "_" . $module->id;
$xmlfile = JPATH_BASE . "/modules/mod_novass/engine/nss$file_number.xml";
$playlist = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
$playlist .= '<xml>
<settings>
<line_color>0x' . $nsslinecol . '</line_color>
<num_color>0x' . $nssnumcol . '</num_color>
<bbg_color>0x' . $nssbbgcol . '</bbg_color>
<progress_color>0x' . $nssprogcol . '</progress_color>
<textBgAlpha>' . $nssalpha . '</textBgAlpha>
<ShowNavigation>' . $nssshownav . '</ShowNavigation>
<buttonPos>' . $nssbutpos . '</buttonPos>
<buttonSpace>' . $nssspace . '</buttonSpace>
<buttonPadding>' . $nssbpad . '</buttonPadding>
<textFont>' . $nssfont . '</textFont>
<titleTextSize>' . $nsstitsize . '</titleTextSize>
<infoTextSize>' . $nssdescsize . '</infoTextSize>
<imageFadeInSpeed>' . $nssfadespd . '</imageFadeInSpeed>
<bannerLooping>' . $loop . '</bannerLooping>
</settings><images>' . "\n";
if ($useasgal == "yes") {
    $f_list = $pj_hlp->folder_mode($picdir, $limratio, $limithgt, $limitwdt, $limitsz);
    if (empty($f_list)) {
        $f_list = array();
    }
    if (empty($globaldelay)) {
        $globaldelay = 1;
    }
    foreach ($f_list as $pic) {
        $folder[] = '<image><file>' . $RURL . $pic . '</file><title><![CDATA[]]></title><text><![CDATA[]]></text><url>' . $globallink . '</url><window>' . $globaltgt . '</window><timer>' . $globaldelay . '</timer></image>';
    }
    $gal_file_time = $pj_hlp->gal_file_time;
} else {
    if (!empty($catid)) {
        foreach ($catid as $id) {
            $id = trim($id);
            $query = "SELECT * FROM #__novass  WHERE catid=" . $id . " AND state = 1" . $rndmz;
            $db = &JFactory::getDBO();
            $db->setQuery($query);
            $fields = $db->loadObjectList();
            foreach ($fields as $nssinf) {
                $nssjpg = $nssinf->nssjpg;
                $nsstit = $nssinf->nsstit;
                $nssdesc = $nssinf->nssdesc;
                $nssurl = $nssinf->nssurl;
                $nssurl = explode('|', $nssurl);
                $nssurl = $nssurl[0];
                $nsstgt = ($nssinf->nsstgt) ? "_blank" : "_self";
                $nsstimer = $nssinf->nsstimer;

                if (empty($nsstimer)) {
                    $nsstimer = 1;
                }
                $ext_cat = pathinfo(JPATH_BASE . "/" . $nssjpg);
                $ext_cat = $ext_cat['extension'];
                if (preg_match('/\A(jpg)\Z/i', $ext_cat) || preg_match('/\A(gif)\Z/i', $ext_cat) || preg_match('/\A(png)\Z/i', $ext_cat) || preg_match('/\A(bmp)\Z/i', $ext_cat) || preg_match('/\A(jpeg)\Z/i', $ext_cat)) {
                    if (!file_exists(JPATH_BASE . "/" . $nssjpg)) {
                        $pj_hlp->error_files .= JPATH_BASE . "/" . $nssjpg . "<br/>";
                        $pj_hlp->error_num_files++;
                    } else {
                        $pj_hlp->good_files++;
                    }
                    $pj_hlp->total_files++;
                    if (is_numeric($nssurl)) {
                        $nssurl = $RURL . 'index.php?option=com_content&view=article&id=' . $nssurl;
                    }
                    $comp[] = '<image><file>' . $nssjpg . '</file><title><![CDATA[' . $nsstitstart . $nsstit . $nsstitend . ']]></title><text><![CDATA[' . $nssdescstart . $nssdesc . $nssdescend . ']]></text><url>' . $nssurl .
                        '</url><window>' . $nsstgt . '</window><timer>' . $nsstimer . '</timer></image>';
                } else {
                    $pj_hlp->total_files++;
                    $pj_hlp->wrong_format_files .= JPATH_BASE . "/" . $nssjpg . "<br/>";
                    $pj_hlp->wrong_format_num_files++;
                    $pj_hlp->error_files .= JPATH_BASE . "/" . $nssjpg . "<br/>";
                    $pj_hlp->error_num_files++;
                }
            }
        }
    }
    for ($i = 1; $i <= 40; $i++) {
        if ($i < 10) {
            $n = "0" . $i;
        } else {
            $n = $i;
        }
        ${"nss" . $n . "jpg"} = $params->get("nss" . $n . "jpg");
        ${"nss" . $n . "stjpg"} = $params->get("nss" . $n . "stjpg");
        ${"nss" . $n . "tit"} = $params->get("nss" . $n . "tit");
        ${"nss" . $n . "desc"} = $params->get("nss" . $n . "desc");
        ${"nss" . $n . "url"} = $params->get("nss" . $n . "url");
        ${"nss" . $n . "tgt"} = $params->get("nss" . $n . "tgt");
        ${"nss" . $n . "timer"} = $params->get("nss" . $n . "timer");

        if (empty(${"nss" . $n . "timer"})) {
            ${"nss" . $n . "timer"} = 1;
        }

        if (is_numeric(${"nss" . $n . "url"})) {
            ${"nss" . $n . "url"} = $RURL . 'index.php?option=com_content&view=article&id=' . ${"nss" . $n . "url"};
        }
        if (!empty(${"nss" . $n . "jpg"})) {
            $ext_bend = pathinfo(JPATH_BASE . "/" . ${"nss" . $n . "jpg"});
            $ext_bend = $ext_bend['extension'];
            if (preg_match('/\A(jpg)\Z/i', $ext_bend) || preg_match('/\A(gif)\Z/i', $ext_bend) || preg_match('/\A(png)\Z/i', $ext_bend) || preg_match('/\A(bmp)\Z/i', $ext_bend) || preg_match('/\A(jpeg)\Z/i', $ext_bend)) {
                if (!file_exists(JPATH_BASE . "/" . ${"nss" . $n . "jpg"})) {
                    $pj_hlp->error_files .= JPATH_BASE . "/" . ${"nss" . $n . "jpg"} . "<br/>";
                    $pj_hlp->error_num_files++;
                } else {
                    $pj_hlp->good_files++;
                }
                $pj_hlp->total_files++;
                $bend[] = '<image><file>' . ${"nss" . $n . "jpg"} . '</file><title><![CDATA[' . $nsstitstart . ${"nss" . $n . "tit"} . $nsstitend . ']]></title><text><![CDATA[' . $nssdescstart . ${"nss" . $n . "desc"
                    } . $nssdescend . ']]></text><url>' . ${"nss" . $n . "url"} . '</url><window>' . ${"nss" . $n . "tgt"} . '</window><timer>' . ${"nss" . $n . "timer"} . '</timer></image>';
            } else {
                $pj_hlp->total_files++;
                $pj_hlp->wrong_format_files .= JPATH_BASE . "/" . ${"nss" . $n . "jpg"} . "<br/>";
                $pj_hlp->wrong_format_num_files++;
                $pj_hlp->error_files .= JPATH_BASE . "/" . ${"nss" . $n . "jpg"} . "<br/>";
                $pj_hlp->error_num_files++;
            }
        } elseif (!empty(${"nss" . $n . "stjpg"})) {
            ${"nss" . $n . "stjpg"} = "images/pss/" . ${"nss" . $n . "stjpg"};
            $ext_bend_st = pathinfo(JPATH_BASE . "/" . ${"nss" . $n . "stjpg"});
            $ext_bend_st = $ext_bend_st['extension'];
            if (preg_match('/\A(jpg)\Z/i', $ext_bend_st) || preg_match('/\A(gif)\Z/i', $ext_bend_st) || preg_match('/\A(png)\Z/i', $ext_bend_st) || preg_match('/\A(bmp)\Z/i', $ext_bend_st) || preg_match('/\A(jpeg)\Z/i',
                $ext_bend_st)) {
                if (!file_exists(JPATH_BASE . "/" . ${"nss" . $n . "stjpg"})) {
                    $pj_hlp->error_files .= JPATH_BASE . "/" . ${"nss" . $n . "stjpg"} . "<br/>";
                    $pj_hlp->error_num_files++;
                } else {
                    $pj_hlp->good_files++;
                }
                $pj_hlp->total_files++;
                $bend[] = '<image><file>' . ${"nss" . $n . "stjpg"} . '</file><title><![CDATA[' . $nsstitstart . ${"nss" . $n . "tit"} . $nsstitend . ']]></title><text><![CDATA[' . $nssdescstart . ${"nss" . $n . "desc"
                    } . $nssdescend . ']]></text><url>' . ${"nss" . $n . "url"} . '</url><window>' . ${"nss" . $n . "tgt"} . '</window><timer>' . ${"nss" . $n . "timer"} . '</timer></image>';
            } else {
                $pj_hlp->total_files++;
                $pj_hlp->wrong_format_files .= JPATH_BASE . "/" . ${"nss" . $n . "stjpg"} . "<br/>";
                $pj_hlp->wrong_format_num_files++;
                $pj_hlp->error_files .= JPATH_BASE . "/" . ${"nss" . $n . "stjpg"} . "<br/>";
                $pj_hlp->error_num_files++;
            }
        }
    }
}
if ($useasgal == "yes") {
    $plarray = $folder;
    $sort_time = $gal_file_time;
} else {
    if ($nsssort != "rnd") {
        $nsssort = 'nosort';
    }
    $sort_time = 'empty';
    if ($nssmixed == "yes") {
        if (!empty($comp) && !empty($bend)) {
            $plarray = array_merge($comp, $bend);
        } elseif (!empty($comp)) {
            $plarray = $comp;
        } elseif (!empty($bend)) {
            $plarray = $bend;
        }
    } else {
        if (!empty($comp)) {
            $plarray = $comp;
        } elseif (!empty($bend)) {
            $plarray = $bend;
        }
    }
}

$playlist .= $pj_hlp->sort($nsssort, $plarray, $sort_time);
$playlist .= '</images></xml>';
if ($debug_key == "dbgpss") {
    echo $pj_hlp->debug('Pro Super Slider', 'mod_novass', 'yes', $document);
    return;
}
if (!@JFile::write($xmlfile, $playlist)) {
    printf('<div style="background-color: red;">
<center><span style="font-size: small; color: white;"><strong>Unable to create <span STYLE="color: yellow">
' . str_replace(JPATH_BASE, "", $xmlfile) . '</span> configuration file. <br/>
<a target="_blank" href="http://www.projoom.com/knowledgebase/article/warning_touch()_[function.touch]_unable_to_create_file.html">Click here</a> for more information.</strong></span></center></div>');
}
$nssrnd = 'pss' . $file_number . '_' . rand(100, 9000);
$onthefly = '#al' . $nssrnd . '{
text-align: ' . $objalign . ';
}';
$document->addStyleDeclaration($onthefly);
$xmlcfg = "nss$file_number";
$nssflash = $RURL . 'modules/mod_novass/engine/nss.swf?' . $nssrnd;
if ($compat == 'yes') {
    $novassoutput = '<div id="al' . $nssrnd . '">
	<object style="outline:none;" type="application/x-shockwave-flash" id="' . $nssrnd . '" data="' . $nssflash . '" width="' . $nsswidth . '" height="' . $nssheight . '">
	<param name="movie" value="' . $nssflash . '" />
	<param name="flashvars" value="uid=' . $xmlcfg . '" />
	<param name="wmode" value="transparent" />
	<param name="allowscriptaccess" value="always">
	<param name="base" value="' . $RURL . '" />
	<p>' . $nofl . '</p>
	</object></div>';
} else {
    $novassoutput = "<div id=\"al$nssrnd\"><div id=\"$nssrnd\">$nofl</div>
	<script type=\"text/javascript\">
	var flashvars = { uid: \"$xmlcfg\", showVersionInfo: \"false\"};
	var params = { base: \"$RURL\", wmode: \"transparent\",allowscriptaccess:\"always\" };
	var attributes = { style: \"outline:none;\" };
	swfobject.embedSWF(\"$nssflash\", \"$nssrnd\", \"$nsswidth\", \"$nssheight\", \"9.0.0\", \"\", flashvars, params, attributes);
	</script></div>";
}
echo $novassoutput;
?>
