File: /home/centralexf/www/plugins/system/jazin.php
<?php
/**
* @version $Id: emailcloak.php 10110 2008-03-06 12:51:09Z instance $
* @package Joomla
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgSystemJAZin extends JPlugin
{
var $_db = null;
var $_listmenu = array();
var $_listsmenu = array();
var $_listmodule = null;
var $_params = null;
var $_listmenupbl = null;
var $_cid = array();
var $_menutype = '';
function plgSystemJAZin(& $subject, $config) {
parent::__construct($subject, $config);
}
function onAfterInitialise()
{
if(defined('_JA_ZIN_PLUGIN_')) return;
define('_JA_ZIN_PLUGIN_', 1);
// Get plugin info
$this->_db = JFactory::getDBO();
$plugin =& JPluginHelper::getPlugin('system', 'jazin');
$this->_params = new JParameter( $plugin->params );
//Init params for section
//num_leading_articles=".$this->_params->get('s_num_leading_articles')."\nnum_intro_articles=".$this->_params->get('s_num_intro_articles')."\nnum_columns=".$this->_params->get('s_num_columns')."\nnum_links=".$this->_params->get('s_num_links')."\norderby_pri=\norderby_sec=front\nshow_pagination=2\nshow_pagination_results=1\nshow_feed_link=1\nshow_noauth=0\nshow_title=1\nlink_titles=0\nshow_intro=1\nshow_section=0\nlink_section=0\nshow_category=0\nlink_category=0\nshow_author=1\nshow_create_date=1\nshow_modify_date=1\nshow_item_navigation=0\nshow_readmore=1\nshow_vote=0\nshow_icons=1\nshow_pdf_icon=1\nshow_print_icon=1\nshow_email_icon=1\nshow_hits=1\nfeed_summary=\npage_title=Welcome to the Frontpage\nshow_page_title=0\npageclass_sfx=\nmenu_image=-1\nsecure=0\n\n
$this->_sectionparams = new JParameter('');
$this->_sectionparams->set('num_leading_articles', $this->_params->get('s_num_leading_articles'));
$this->_sectionparams->set('num_intro_articles', $this->_params->get('s_num_intro_articles'));
$this->_sectionparams->set('num_columns', $this->_params->get('s_num_columns'));
$this->_sectionparams->set('num_links', $this->_params->get('s_num_links'));
//Init params for category
//num_leading_articles=".$this->_params->get('c_num_leading_articles')."\nnum_intro_articles=".$this->_params->get('c_num_intro_articles')."\nnum_columns=".$this->_params->get('c_num_columns')."\nnum_links=".$this->_params->get('c_num_links')."\norderby_pri=\norderby_sec=front\nshow_pagination=2\nshow_pagination_results=1\nshow_feed_link=1\nshow_noauth=0\nshow_title=1\nlink_titles=0\nshow_intro=1\nshow_section=0\nlink_section=0\nshow_category=0\nlink_category=0\nshow_author=1\nshow_create_date=1\nshow_modify_date=1\nshow_item_navigation=0\nshow_readmore=1\nshow_vote=0\nshow_icons=1\nshow_pdf_icon=1\nshow_print_icon=1\nshow_email_icon=1\nshow_hits=1\nfeed_summary=\npage_title=Welcome to the Frontpage\nshow_page_title=0\npageclass_sfx=\nmenu_image=-1\nsecure=0\n\n
$this->_catparams = new JParameter('');
$this->_catparams->set('num_leading_articles', $this->_params->get('c_num_leading_articles'));
$this->_catparams->set('num_intro_articles', $this->_params->get('c_num_intro_articles'));
$this->_catparams->set('num_columns', $this->_params->get('c_num_columns'));
$this->_catparams->set('num_links', $this->_params->get('c_num_links'));
//init group params
$this->_gparams = new JParameter('');
$this->_gparams->set('show_description', $this->_params->get('show_description'));
$this->_gparams->set('show_description_image', $this->_params->get('show_description_image'));
$this->_gparams->set('show_page_title', $this->_params->get('show_page_title'));
$this->_gparams->set('orderby_pri', $this->_params->get('orderby_pri'));
$this->_gparams->set('orderby_sec', $this->_params->get('orderby_sec'));
$this->_gparams->set('show_pagination', $this->_params->get('show_pagination'));
$this->_gparams->set('show_pagination_results', $this->_params->get('show_pagination_results'));
$this->_gparams->set('show_feed_link', $this->_params->get('show_feed_link'));
$this->_gparams->set('show_noauth', $this->_params->get('show_noauth'));
$this->_gparams->set('show_title', $this->_params->get('show_title'));
$this->_gparams->set('link_titles', $this->_params->get('link_titles'));
$this->_gparams->set('show_intro', $this->_params->get('show_intro'));
$this->_gparams->set('show_section', $this->_params->get('show_section'));
$this->_gparams->set('link_section', $this->_params->get('link_section'));
$this->_gparams->set('show_category', $this->_params->get('show_category'));
$this->_gparams->set('link_category', $this->_params->get('link_category'));
$this->_gparams->set('show_author', $this->_params->get('show_author'));
$this->_gparams->set('show_create_date', $this->_params->get('show_create_date'));
$this->_gparams->set('show_modify_date', $this->_params->get('show_modify_date'));
$this->_gparams->set('show_item_navigation', $this->_params->get('show_item_navigation'));
$this->_gparams->set('show_readmore', $this->_params->get('show_readmore'));
$this->_gparams->set('show_vote', $this->_params->get('show_vote'));
$this->_gparams->set('show_icons', $this->_params->get('show_icons'));
$this->_gparams->set('show_pdf_icon', $this->_params->get('show_pdf_icon'));
$this->_gparams->set('show_print_icon', $this->_params->get('show_print_icon'));
$this->_gparams->set('show_email_icon', $this->_params->get('show_email_icon'));
$this->_gparams->set('show_hits', $this->_params->get('show_hits'));
$this->_gparams->set('feed_summary', $this->_params->get('feed_summary'));
$this->_menutype = $this->_params->get('jazin_menutype', 'magazin');
//Check if the menutype is exist
$query = "select count(*) from #__menu_types where `menutype`='{$this->_menutype}'";
$this->_db->setQuery($query);
if(!$this->_db->loadResult()) {
$query = "insert into #__menu_types (`menutype`, `title`) values('{$this->_menutype}','{$this->_menutype}');";
$this->_db->setQuery($query);
$this->_db->query();
}
$this->_listmodule = $this->loadSections();
$this->loadJAZinMenu();
if($this->_listmodule){
$this->compMenu();
}
if($this->_params->get('jazin_update')) {
//Reset status for update parameter of the plugin
$this->_params->set('jazin_update', 0);
$query = "update #__plugins set `params`='".$this->_params->toString()."' where `folder`='system' and `element`='jazin'";
$this->_db->setQuery($query);
$this->_db->query();
foreach($this->_listmenu as $sid=>$jzm){
$query = "update #__menu set `params`='".$this->_sectionparams->toString().$this->_gparams->toString()."\nsectionid=$sid' where `id`=".$jzm->id;
$this->_db->setQuery($query);
$this->_db->query();
}
foreach($this->_listsmenu as $cid=>$jzsm){
$query = "update #__menu set `params`='".$this->_catparams->toString().$this->_gparams->toString()."\ncategoryid=$cid' where `id`=".$jzsm->id;
$this->_db->setQuery($query);
$this->_db->query();
}
}
}
function loadSections(){
$query = "SELECT `id`,`title`,`published` FROM #__sections WHERE `published`<>-2";
$this->_db->setQuery($query);
return $this->_db->loadObjectlist();
}
function loadJAZinMenu(){
$query = "SELECT name,id,published,parent,link,home FROM `#__menu` WHERE `menutype`='{$this->_menutype}' and `published`<>-2";
$this->_db->setQuery($query);
$listmenu = $this->_db->loadObjectlist();
foreach ($listmenu as $lm){
$urls = parse_url($lm->link);
$querystring = @ $urls['query'];
$output = null;
parse_str ($querystring,$output);
if (!$output) continue;
if ($lm->home) {
$this->_listmenu[0] = $lm;
}else if (isset($output['option']) && $output['option']=='com_content') {
if($output['view']=='section'){
$this->_listmenu[$output['id']] = $lm;
}
else if($output['view']=='category'){
$this->_listsmenu[$output['id']] = $lm;
}
}
}
}
function compMenu(){
$idp = array();
$idup = array();
$mid = array();
if($this->_params->get('jazin_home',1)) {
$mid[] = 0;
if(!isset($this->_listmenu[0])){
$query = "INSERT INTO #__menu (`menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `ordering`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home`) VALUES ";
$query .= "('{$this->_menutype}', 'Home', 'home', 'index.php?option=com_content&view=frontpage', 'component', 1, 0, 20, 0, 1, 0, '0000-00-00 00:00:00', 0, 0, 0, 0, 'num_leading_articles=".$this->_params->get('s_num_leading_articles')."\nnum_intro_articles=".$this->_params->get('s_num_intro_articles')."\nnum_columns=".$this->_params->get('s_num_columns')."\nnum_links=".$this->_params->get('s_num_links')."\norderby_pri=\norderby_sec=front\nshow_pagination=2\nshow_pagination_results=1\nshow_feed_link=1\nshow_noauth=0\nshow_title=1\nlink_titles=0\nshow_intro=1\nshow_section=0\nlink_section=0\nshow_category=0\nlink_category=0\nshow_author=1\nshow_create_date=1\nshow_modify_date=1\nshow_item_navigation=0\nshow_readmore=1\nshow_vote=0\nshow_icons=1\nshow_pdf_icon=1\nshow_print_icon=1\nshow_email_icon=1\nshow_hits=1\nfeed_summary=\npage_title=Welcome to the Frontpage\nshow_page_title=0\npageclass_sfx=\nmenu_image=-1\nsecure=0\n\n', 0, 0, 1)";
$this->_db->setQuery($query);
//echo $this->_db->getQuery();
$this->_db->query();
}
}
foreach($this->_listmodule as $m){
$secid = $m->id;
$mid[] = $secid;
if(!isset($this->_listmenu[$secid])){
$query = "INSERT INTO #__menu (`menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `ordering`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home`) VALUES ";
$query .= "('{$this->_menutype}', '".$m->title."', '".JFilterOutput::stringURLSafe($m->title)."', 'index.php?option=com_content&view=section&layout=blog&id=".$secid."', 'component', ".$m->published.", 0, 20, 0, 1, 0, '0000-00-00 00:00:00', 0, 0, 0, 0, '".$this->_sectionparams->toString()."', 0, 0, 0)";
$this->_db->setQuery($query);
$this->_db->query();
$insertid = $this->_db->insertid();
$listcategories = $this->getCategories($secid);
if($listcategories) $this->compCatmenu($listcategories,$insertid,$m->published);
}
else{
if(!$m->published && $this->_listmenu[$secid]->published) {
$idup[] = $this->_listmenu[$secid]->id;
}
$listcategories = $this->getCategories($secid);
if($listcategories) $this->compCatmenu($listcategories,$this->_listmenu[$secid]->id,$m->published);
}
}
if(count($idp)){
$query = "Update #__menu SET published = 1 WHERE (id IN (".implode(',',$idp).")) OR (parent IN (".implode(',',$idp)."))";
$this->_db->setQuery($query);
$this->_db->query();
}
if(count($idup)){
$query = "Update #__menu SET published = 0 WHERE (id IN (".implode(',',$idup).")) OR (parent IN (".implode(',',$idup)."))";
$this->_db->setQuery($query);
$this->_db->query();
}
$idd = array_diff(array_keys($this->_listmenu), $mid);
if(count($idd)){
$where = "";
foreach($idd as $d){
$where .= $this->_listmenu[$d]->id.",";
}
$where = ($where) ? substr($where,0,-1) : "";
$query = "DELETE FROM #__menu WHERE (id IN (".$where.")) OR (parent IN (".$where."))";
$this->_db->setQuery($query);
$this->_db->query();
}
$cidd = array_diff(array_keys($this->_listsmenu), $this->_cid);
if(count($cidd)){
$where = "";
foreach($cidd as $d){
$where .= $this->_listsmenu[$d]->id.",";
}
$where = ($where) ? substr($where,0,-1) : "";
$query = "DELETE FROM #__menu WHERE id IN (".$where.")";
$this->_db->setQuery($query);
$this->_db->query();
}
}
function getCategories($secid){
$query = "SELECT id,title,section FROM `#__categories` WHERE `section`='".$secid."' and `published`<>-2";
$this->_db->setQuery($query);
return $this->_db->loadObjectlist();
}
function compCatmenu($listcategories,$insertid,$published){
$query_v = "";
$query = "INSERT INTO #__menu (`menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `ordering`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home` ) VALUES ";
foreach($listcategories as $cat){
$this->_cid[] = $cat->id;
if(!(isset($this->_listsmenu[$cat->id]))){
$query_v .= "('{$this->_menutype}', '".$cat->title."', '".JFilterOutput::stringURLSafe($cat->title)."', 'index.php?option=com_content&view=category&layout=blog&id=".$cat->id."', 'component', ".$published.", ".$insertid.", 20, 1, 1, 0, '0000-00-00 00:00:00', 0, 0, 0, 0, '".$this->_catparams->toString()."', 0, 0, 0),";
}
}
if($query_v){
$query_v = substr($query_v, 0, -1);
$this->_db->setQuery($query.$query_v);
$this->_db->query();
}
}
}
?>