PDA

Zobacz pełną wersję : Rozwijane menu boczne: sekcja -> kategorie artykułów



parsi
09-11-2012, 14:51
Szukałem modułu który pomoże mi zrobić menu rozwijane, w którym wyświetlały by się obecne na stronie kategorie z danej sekcji. Znalazłem moduł o nazwie SeCatordion.

Ustawilem w nim layout na "blog" i po kliknięciu w link otwieralo sie okno z błędem, poniewaz system dodawał na końcu adresu "$layout=blog". Usunąłem zatem w pliku .css: w linicje 192 wpis: ", $str_layout" a w linijce 293 wpis: ", $layout. "

Wszystko ładnie, poza tym, że moduł pobiera do menu wszystkie sekcje ze strony. Ja chciałbym, aby w menu była tylko jedna sekcja z kategoriami. Czy mógłbym prosić o wskazanie w których linijkach mam wpisać id sekcji, aby w menu była wyświetlana tylko ta jedna? Kod:


<?php
/*
* Module Secatordion 1.1 - Gestion de JoomFish
* @author Sylvain D. (http://geekspace.free.fr)
* @package SeCatordion
* @version 1.1 2011-05-12
* @license http://www.gnu.org/copyleft/gpl.html
* @copyright Copyright (C) 2011 Geek Space. All Rights Reserved.
*/
defined('_JEXEC') or die('Restricted access');
require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'h elpers'.DS.'route.php');

// Create ID
if (!isset($GLOBALS['secatacc'])) {
$GLOBALS['secatacc'] = 1;
} else {
$GLOBALS['secatacc']++;
}
// Module ID
$secataccid = '_' . $GLOBALS['secatacc'];

// Params
// For Module
$section_display_mode = $params->get('section_display_mode',1);
$counts = $params->get('counts',0);
$nbchr_substr = $params->get('nbchr_substr',0);
$category_order = $params->get('category_order',1);
$auto_height = ($params->get('auto_height',1) == 1)?'false':'true';
$secatordion_module_path = JURI::base().'modules/mod_secatordion/';
$auto_open = $params->get('auto_open',1);
$link_item = $params->get('link_item',0);

/*
// Category Ordering ************************************************** *****************************
if($category_order == 1){
$order = '';
}else{
$order = ',ordering'; // Attention ne pas oublier la virgule
}
*/

// Add CSS and Script ************************************************** **************************/
$document =& JFactory::getDocument();
$document->addStylesheet($secatordion_module_path.'css/secatacc-style.css');

if($params->get("load_jquery",1) == 1) {
$document->addScript($secatordion_module_path.'scripts/jquery-1.4.2.min.js');
}
if($params->get("load_jquery_ui",0) == 1) {
$document->addScript($secatordion_module_path.'scripts/jquery-ui-1.8.1.custom.min.js');
}
if($params->get("load_jquery_only_accordion",1) == 1) {
$document->addScript($secatordion_module_path.'scripts/jquery-ui-1.8.1.only-accordion.js');
}


$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$userId = (int) $user->get('id');
$aid = $user->get('aid', 0);
$contentConfig = &JComponentHelper::getParams( 'com_content' );
$access = !$contentConfig->get('shownoauth');
$nullDate = $db->getNullDate();
$date =& JFactory::getDate();
$now = $date->toMySQL();


$pageview = JRequest::getVar('view', '');
$pageid = JRequest::getVar('id', '');

$pageidarray = explode( '-', $pageid );
if(!is_int($pageidarray)) $pageidarray = explode( ':', $pageid );
$pageid = (int)$pageidarray[0];


if($pageview=="article") {
$sql = 'SELECT sectionid, catid ' .
' FROM #__content ' .
' WHERE ' .
' id = '.$pageid.
'';

$db->setQuery( $sql );
$section_and_cat_id = $db->loadObjectList();

$section_id=$section_and_cat_id[0]->sectionid;
$cat_id=$section_and_cat_id[0]->catid;
}
elseif($pageview=="category") {
$sql = 'SELECT section ' .
' FROM #__categories ' .
' WHERE ' .
' id = '.$pageid.
'';

$db->setQuery( $sql );
$sectionid = $db->loadObjectList();

$section_id=$sectionid[0]->section;
$cat_id=$pageid;
}
else {
$section_id=$pageid;
$cat_id=0;
}


/************************************************** ******/

$order = ',ordering'; // Attention ne pas oublier la virgule

$sql = 'SELECT cc.id, cc.title, cc.alias, cc.section, cc.ordering,' .
' s.title as sectitle'.
' FROM #__categories AS cc ' .
' INNER JOIN #__sections AS s ON s.id = cc.section' .
' WHERE ' .
' s.published = 1' .
' AND cc.published = 1' .
' ORDER BY s.ordering '.$order.
'';

// ' LIMIT 0,'.$counts.'';

$db->setQuery( $sql );
if (!$db->query()) {
echo $db->getErrorMsg();
return;
}
$load_items = $db->loadObjectList();


$actual_id_section=$load_items[0]->section;
$links_cat="";
$cpt=0;
$cpt_top_onglet=0;
$id_menu_to_open=0;
$acc=array();


// On définit le type de layout de la section
if($section_display_mode==1) {
$str_layout="default";
}
else {
$str_layout="blog";
}


for($i=0; $i<count($load_items); $i++) {

// Si c'est une section qu'on a pas encore rencontrée on crée un onglet...
if($load_items[$i]->section!=$actual_id_section) {

$temp_sectitle=$load_items[$i-1]->sectitle;
$jf_corr=get_jf_correspondance($load_items[$i-1]->section);
if(!empty($jf_corr)) $temp_sectitle=$jf_corr;

if($nbchr_substr!=0) {
$the_title=utf8_substr($temp_sectitle,0,$nbchr_sub str);
if(utf8_strlen($temp_sectitle)>$nbchr_substr) $the_title.="...";
}
else {
$the_title=$temp_sectitle;
}

$secatacc = array(
'title' => $the_title,
'introtext' =>$links_cat,
'id' =>$actual_id_section,
'id_cat_or_sec' => "secatacc".$secataccid."_".$actual_id_section,
'link' => convertLinkWithBlogMode(JRoute::_(ContentHelperRou te::getSectionRoute($actual_id_section)), "")
);
$acc[] = $secatacc;

// Comme c'est un nouvel onglet de Section, on réinitialise
$links_cat="";
$cpt=0;

if($actual_id_section==$section_id) {
$id_menu_to_open=$cpt_top_onglet;
}
$cpt_top_onglet++;
}



if($cpt<$counts || $counts==0) {

$my_slug_cat=$load_items[$i]->id."-".$load_items[$i]->alias;
$mymenulink=JRoute::_(ContentHelperRoute::getCateg oryRoute($my_slug_cat, $load_items[$i]->section));

$mymenulink=convertLinkWithBlogMode($mymenulink);

if($nbchr_substr!=0) {
$the_link=utf8_substr($load_items[$i]->title,0,$nbchr_substr);
if(utf8_strlen($load_items[$i]->title)>$nbchr_substr) $the_link.="...";
}
else {
$the_link=$load_items[$i]->title;
}

if($cat_id==$load_items[$i]->id) $article_class_name="mod_item_cat item_active_page";
else $article_class_name="mod_item_cat";

$links_cat.='<a href="'.$mymenulink.'" class="'.$article_class_name.'" id="cat_'.$load_items[$i]->id.'_sec_'.$load_items[$i]->section.'">'.$the_link.'</a><br/>
';
}

$cpt++;
$actual_id_section=$load_items[$i]->section;
}



$temp_sectitle=$load_items[$i-1]->sectitle;
$jf_corr=get_jf_correspondance($load_items[$i-1]->section);
if(!empty($jf_corr)) $temp_sectitle=$jf_corr;

if($nbchr_substr!=0) {
$the_title=utf8_substr($temp_sectitle,0,$nbchr_sub str);
if(utf8_strlen($temp_sectitle)>$nbchr_substr) $the_title.="...";
}
else {
$the_title=$temp_sectitle;
}

$secatacc = array(
'title' => $the_title,
'introtext' =>$links_cat,
'id' =>$actual_id_section,
'id_cat_or_sec' => "secatacc".$secataccid."_".$actual_id_section,
'link' => convertLinkWithBlogMode(JRoute::_(ContentHelperRou te::getSectionRoute($actual_id_section)), "")
);
$acc[] = $secatacc;

$links_cat="";
$cpt=0;

if($actual_id_section==$section_id) {
$id_menu_to_open=$cpt_top_onglet;
}
$cpt_top_onglet++;



$js_settings = "

var id_sec_opened".$secataccid."=".$acc[$id_menu_to_open]["id"].";

var ".chr(36)."j".$secataccid." = jQuery.noConflict();
".chr(36)."j".$secataccid."(document).ready(function(){
".chr(36)."j".$secataccid."('#secatacc".$secataccid."').accordion({
active:true,
alwaysOpen:true,
autoHeight: ".$auto_height.",
icons:{'header':'secatacc-closed','headerSelected':'secatacc-opened'}
});

";

if($auto_open==1 && $cat_id!=0) {

$js_settings.= "
id_sec_opened".$secataccid."=".$acc[$id_menu_to_open]["id"].";
".chr(36)."j".$secataccid."( '#secatacc".$secataccid."' ).accordion( 'option', 'active', ".$id_menu_to_open." );";
}

if($link_item==1) {

for ($k=0; $k<count($acc); $k++) {
$js_settings.= "
".chr(36)."j".$secataccid."('#secatacc".$secataccid."_".$acc[$k]["id"]."').click(function() {

if(id_sec_opened".$secataccid."==".$acc[$k]["id"].") window.location.href='".$acc[$k]["link"]."';
id_sec_opened".$secataccid."=".$acc[$k]["id"].";

});
";
}
}

$js_settings.= "
});
";



$document->addScriptDeclaration($js_settings);




function convertLinkWithBlogMode($link){

$tab_to_count=explode("layout",$link);
//echo count($tab_to_count)."<br/>";
if(!empty($layout)) {
if(count($tab_to_count)<2) {
//echo $mymenulink."<br>";
//echo 'layout='.$str_layout."<br>";
$link.='&layout='.$layout;
//echo $mymenulink."<br><br>";
}
else {
//echo $mymenulink."<br>";
//echo 'layout='.$str_layout."<br>";
$link=str_replace("layout=default", 'layout='.$layout, $link);
$link=str_replace("layout=blog", 'layout='.$layout, $link);
//echo $mymenulink."<br><br>";
}
}

//$new_link=str_replace("&amp;","&",$link);
$new_link=str_replace("&","&amp;",$link);

return $new_link;

}




function get_jf_correspondance($id_section) {
$db=& JFactory::getDBO();
$document =& JFactory::getDocument();

// On vérifie si JoomFish est déjŕ installé
$query="SHOW TABLE STATUS LIKE '%_jf_content'";
$db ->setQuery($query);
$nb_table= $db ->loadObjectList();

//Si Joomfish n'est pas installé...
if(empty($nb_table)) return "";

$query='
SELECT value FROM #__jf_content AS jf
INNER JOIN #__languages AS lang
ON jf.language_id = lang.id
WHERE lang.code="'.$document->language.'"
AND jf.reference_id='.$id_section.'
AND jf.reference_field = "title"
AND jf.reference_table="sections"
';
$db ->setQuery($query);
$lang= $db ->loadObjectList();

return $lang[0]->value;
}


// Get Layout
require(JModuleHelper::getLayoutPath('mod_secatord ion'));
?>

washingtonplx
12-11-2012, 13:16
Spróbuj zastąpić $id_section konkretnym id sekcji np "2"

parsi
14-11-2012, 15:01
Zmieniłem tą część kod gdzie są "$id_section":


function get_jf_correspondance($id_section) {
$db=& JFactory::getDBO();
$document =& JFactory::getDocument();

// On vérifie si JoomFish est déjŕ installé
$query="SHOW TABLE STATUS LIKE '%_jf_content'";
$db ->setQuery($query);
$nb_table= $db ->loadObjectList();

//Si Joomfish n'est pas installé...
if(empty($nb_table)) return "";

$query='
SELECT value FROM #__jf_content AS jf
INNER JOIN #__languages AS lang
ON jf.language_id = lang.id
WHERE lang.code="'.$document->language.'"
AND jf.reference_id='.$id_section.'
AND jf.reference_field = "title"
AND jf.reference_table="sections"
';
$db ->setQuery($query);
$lang= $db ->loadObjectList();

return $lang[0]->value;
}

na taki:


function get_jf_correspondance() {

$id_section=2;
$db=& JFactory::getDBO();
$document =& JFactory::getDocument();

// On vérifie si JoomFish est déjŕ installé
$query="SHOW TABLE STATUS LIKE '%_jf_content'";
$db ->setQuery($query);
$nb_table= $db ->loadObjectList();

//Si Joomfish n'est pas installé...
if(empty($nb_table)) return "";

$query="
SELECT value FROM #__jf_content AS jf
INNER JOIN #__languages AS lang
ON jf.language_id = lang.id
WHERE lang.code='".$document->language."'
AND jf.reference_id='".$id_section."'
AND jf.reference_field = 'title'
AND jf.reference_table='sections'
";
$db ->setQuery($query);
$lang= $db ->loadObjectList();

return $lang[0]->value;
}
$a = get_jf_correspondance();

Niestety nadal w module wyświetlają się kategorie artykułów z dwóch sekcji. Jeśli to coś pomoże to podaję link: www.hobbycafe.pl . Moduł po prawej stronie o nazwie SeCatordion.

washingtonplx
16-11-2012, 12:20
Nie mam za bardzo czasu, więc na szybko coś napisze. Chcesz aby wyświetliły się kategorie z sekcji na której jesteś ? trzeba wiec pobrać id sekcji,nie wiem jak w joomli najłatwiej można to pobrać poza samą sekcją np. module, więc wyciągnę id z adresu za pomocą kodu:

$url= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$var=explode('section&id=',$url);
$var=explode('&',$var[1]);
następnie trzeba porównać czy wyświetlane kategorie z sekcji mają takie same id jak sekcja na której jesteśmy.

if ($var[0] == $item->id)
to wszytko trzeba dodać do pliku modules\mod_sections\tmpl\default.php
oryginał:

<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<ul class="sections<?php echo $params->get('moduleclass_sfx'); ?>"><?php
foreach ($list as $item) :
?>
<li>
<a href="<?php echo JRoute::_(ContentHelperRoute::getSectionRoute($ite m->id)); ?>">
<?php echo $item->title;?></a>
</li>
<?php endforeach; ?>
</ul>

gotowy:

<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<ul class="sections<?php echo $params->get('moduleclass_sfx'); ?>"><?php


$url= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$var=explode('section&id=',$url);
$var=explode('&',$var[1]);

foreach ($list as $item) :

if ($var[0] == $item->id) {
?>
<li>


<a href="<?php echo JRoute::_(ContentHelperRoute::getSectionRoute($ite m->id)); ?>">
<?php echo $item->title;?></a>
</li>
<?php
}
endforeach; ?>
</ul>
Wyświetli Ci się tylko sekcja na której jesteś, ale tylko w sekcji! jeśli przejdziesz do kategorii lub artykułu w module będzie nic. Żeby wyświetlało w kategoriach i artykule trzeba by pobrać jakoś id sekcji z artykułu/ kategorii, może zna ktoś szybki sposób? bo inaczej z adresu trzeba tym razem pobrać id kategorii/ artykułu następnie z bazy danych wyciągnąć id sekcji do której jest przypisany artykuł. Nie sprawdzałem tego i może nie działać:


$var_kategoria=explode('view=category&id=',$url);
$var_kategoria=explode(':the-cms', $var_kategoria[1]);
$kategoria = $var_kategoria[0];

$var_artykul=explode('article&id=',$url);
$var_artykul=explode(':', $var_artykul[1]);
$artykul = $var_artykul[0];




$pointer = mysql_query("SELECT section FROM jos_categories WHERE id = '".$kategoria."'");
$p = mysql_fetch_assoc($pointer);
$kategoria_idsekcja = $p['section'];

$pointer2 = mysql_query("SELECT sectionid FROM jos_content WHERE id = '".$artykul."'");
$p2 = mysql_fetch_assoc($pointer2);
$artykul_idsekcja = $p2['sectionid'];



tak wygląda cały kod:

<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<ul class="sections<?php echo $params->get('moduleclass_sfx'); ?>"><?php


$url= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$var=explode('section&id=',$url);
$var=explode('&',$var[1]);


$var_kategoria=explode('view=category&id=',$url);
$var_kategoria=explode(':the-cms', $var_kategoria[1]);
$kategoria = $var_kategoria[0];

$var_artykul=explode('article&id=',$url);
$var_artykul=explode(':', $var_artykul[1]);
$artykul = $var_artykul[0];




$pointer = mysql_query("SELECT section FROM jos_categories WHERE id = '".$kategoria."'");
$p = mysql_fetch_assoc($pointer);
$kategoria_idsekcja = $p['section'];

$pointer2 = mysql_query("SELECT sectionid FROM jos_content WHERE id = '".$artykul."'");
$p2 = mysql_fetch_assoc($pointer2);
$artykul_idsekcja = $p2['sectionid'];

foreach ($list as $item) :

if ($var[0] == $item->id or $item->id == $kategoria_idsekcja or $item->id == $artykul_idsekcja) {
?>
<li>


<a href="<?php echo JRoute::_(ContentHelperRoute::getSectionRoute($ite m->id)); ?>">
<?php echo $item->title;?></a>
</li>
<?php
}
endforeach; ?>
</ul>
napisz czy działa ?

EDIT:ehh, zapomniałem :/ jest jeszcze inny sposób, można dodać w module dodatkowe pole które uzupełniałoby się w panelu admina, stworzyłbyś dwa moduły jeden z id "X" sekcji a drugi z id "Y" sekcji. Jeśli nic nie wyjdzie z tego co napisałem to zrobimy drugim sposobem.

parsi
16-11-2012, 16:45
Podmieniłem default.php w modules najpierw na ten pierwszy kod, a potem na ten drugi, ale nadal moduł wyświetla wszystkie sekcje. Niekoniecznie chodzi mi aby wyświetlała się sekcja na której jestem. Ma się wyświetlać sekcja o id=2. I tylko ona.

washingtonplx
16-11-2012, 18:04
oO mój Boże, ale zrobiłem błąd! nie ten co trzeba edytowałem plik... :/ jak to się mówi "gdy się człowiek spieszy, to się diabeł cieszy"
Prawidłowy kod w modules\mod_secatordion\tmpl:


<?php
/*
* Module Secatordion 1.1 - Gestion de JoomFish
* @author Sylvain D. (http://geekspace.free.fr)
* @package SeCatordion
* @version 1.1 2011-05-12
* @license http://www.gnu.org/copyleft/gpl.html
* @copyright Copyright (C) 2011 Geek Space. All Rights Reserved.
*/
defined('_JEXEC') or die('Restricted access'); ?>
<?php


$url= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$var=explode('section&id=',$url);
$var=explode('&',$var[1]);


$var_kategoria=explode('view=category&id=',$url);
$var_kategoria=explode(':the-cms', $var_kategoria[1]);
$kategoria = $var_kategoria[0];

$var_artykul=explode('article&id=',$url);
$var_artykul=explode(':', $var_artykul[1]);
$artykul = $var_artykul[0];




$pointer = mysql_query("SELECT section FROM jos_categories WHERE id = '".$kategoria."'");
$p = mysql_fetch_assoc($pointer);
$kategoria_idsekcja = $p['section'];

$pointer2 = mysql_query("SELECT sectionid FROM jos_content WHERE id = '".$artykul."'");
$p2 = mysql_fetch_assoc($pointer2);
$artykul_idsekcja = $p2['sectionid'];
?>


<div id="secatacc<?php echo $secataccid; ?>" class="secatacc">
<?php foreach ($acc as $secatacc):
if ($var[0] == $secatacc['id'] or $secatacc['id'] == $kategoria_idsekcja or $secatacc['id'] == $artykul_idsekcja) {


?>

<a class="secatacc-title" id="<?php echo $secatacc['id_cat_or_sec'] ?>"><?php echo $secatacc['title']; ?></a>
<div>
<div>
<span><?php echo $secatacc['introtext'] ?></span><br/>
</div>
</div>
<?php
}
endforeach;?>
</div>
<div id="specialegeekinsertion_secatordion"><br/><a href="http://geekspace.free.fr" >Module Joomla par geekspace.free.fr</a></div>
<script type="text/javascript">document.getElementById("specialegeekinsertion_secatordion").style.display="none";document.getElementById("specialegeekinsertion_secatordion").style.visibility="hidden";</script>

sorry za pomyłkę, działa na 100% :)
ewentualnie zamiast
if ($var[0] == $secatacc['id'] or $secatacc['id'] == $kategoria_idsekcja or $secatacc['id'] == $artykul_idsekcja) możesz dać tylko :
if ($secatacc['id'] == "2")

parsi
21-11-2012, 17:36
Wielkie dzięki, działa :)
Przyda się zapewne wielu innym osobom , ktore będą chciały zrobić menu oparte o sekcje :)