We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23478
    • 133 Posts
    Bonjour Olivier
    Quote from: Olivier at Oct 30, 2006, 04:58 AM

    Je dois avouer que je n’ai pas compris ton problème. huh
    désolé, j’ai (encore) été trop rapide...
    je n’ai pas utilisé ton code, j’en étais resté au code "ListRelated" (je ne sais plus quelle version) fourni avec MODx...
    sur une page où j’avais beaucoup de tags, ListRelated a sorti une longue liste de liens...
    comme il n’y avait pas d’espace entre les <li> mais des espaces à l’intérieur des noms, ben les retours à la ligne se faisaient à l’intérieur des noms des pages... ce que je ne trouvais pas beau.
    Je voulais simplement vous donner la petite astuce que j’ai utilisé : remplacer les espaces par des &nbsp; pour ce qui est à l’intérieur des <li>..</li> de façon à ce que ces blocs apparaissent non coupés. (et rajouter un espace après le </li>)

    J’ai fourni le code de la version originale... bien sur il faut l’adapter pour (tout) ce que vous affichez dans votre version wink
      • 20488
      • 353 Posts
      Ok, cela dit ton problème, si je ne m’abuse, doit plus provenir d’une erreur de mise en page CSS que d’un bug du snippet. wink
        • 4295
        • 98 Posts
        Oliveir, merci de votre réponse. Au commencement j’ai pensé que les &LR_selectDocs posaient le problème parce qu’aucun résultat n’a été retourné. Mais maintenant je suspecte que le problème soit avec &LR_selectDocsWithChildren.

        Quand j’indique un document ou un *folder* avec des &LR_selectDocs les résultats semblent corrects. Mais quand je choisis un *folder* de récipient avec les documents et le *folders* d’enfants pour rechercher, alors le *no* résulte. Y compris LR_selectDocsWithChildren=1 le paramètre ne fonctionne pas pour moi. Puis erreur ci-dessous.

        PHP error debug
          Error: 	array_merge() [function.array-merge]: Argument #1 is not an array	 
          Error type/ Nr.: 	Warning - 2	 
          File: 	/Users/blahblah/Sites/manager/includes/document.parser.class.inc.php(730) : eval()'d code	 
          Line: 	220

          • 20488
          • 353 Posts
          Bullrat,

          pourrais tu m’indiquer ta ligne de code ?

          par exemple :

          [!ListRelated?&LR_selectDocs=`1,2,3` &LR_selectDocsWithChildren=`1` !]

          I think you can write in english... I think the moderators will not be angry, especially if this problem is quickly fixed ... I’ll translate your issue in french in this forum. wink
            • 4295
            • 98 Posts
            Here you go. Thanks.
            When I try with &LR_selectDocsWithChildren=`1`
            then I get an error as if it can't search children within folders.
            
            [!ListRelated? &LR_selectDocs=`126` &LR_contentParagraph=`introtext` &LR_sortBy=`date` &LR_sortDir=`DESC` &LR_skipUnpublished=`1` &LR_skipDeleted=`1` &LR_title=`Some title for testing`!]
              • 20488
              • 353 Posts
              Traduction du message de bullrat pour les non anglophones

              Lorsque j’essaye avec &LR_selectDocsWithChildren=`1`alors j’ai une erreur. Comme si il ne pouvait chercher les documents enfants contenus dans le répertoire


              Réponse en français (i can translate if you want)
              Hum... cela me paraît étrange puisque cela fonctionne chez moi :/
              Essaye peut être de faire ceci :
              - ouvrir le snippet
              - rechercher la ligne suivante :
              $relatives = $modx->dbQuery($relatedSql);

              - rajouter cette ligne avant
              die($relatedSql );
              (attention, cela risque de casser ton site, tu dois donc tester ceci sur une page qui n’est pas visible par les internautes...)
              - Si tu ne comprends pas la phrase qui a été générée (de type "SELECT ..."), tu peux la poster ici, je regarderai pourquoi tu as cette erreur. wink


              Exemple chez moi :

              [tt]SELECT content.id,content.pagetitle,content.description,content.longtitle,content.introtext, IF(content.pub_date > 0, content.pub_date, content.createdon) AS date, COUNT(keywords.id) as total_kw FROM `modx`.modx_site_content AS content, `modx`.modx_keyword_xref AS xref, `modx`.modx_site_keywords AS keywords WHERE keywords.keyword IN (’hello’,’world’) AND content.id IN(4557) AND (content.deleted=0) AND (content.published) AND xref.keyword_id = keywords.id AND content.hidemenu = 0 AND content.id = xref.content_id AND content.id != 48 GROUP BY content.id ORDER BY total_kw DESC, date DESC LIMIT 10;[/tt]
              ++



                • 4295
                • 98 Posts
                [tt]Any significance to the format difference in the SELECTs
                of yours = content.id IN(4557) and mine = (content.id IN(126))

                SELECT content.id,content.pagetitle,content.description,content.longtitle,content.introtext, IF(content.pub_date > 0, content.pub_date, content.createdon) AS date, COUNT(keywords.id) as total_kw FROM `blah_modx`.modx_site_content AS content, `blah_modx`.modx_keyword_xref AS xref, `blah_modx`.modx_site_keywords AS keywords WHERE keywords.keyword IN (’Finder’) AND (content.id IN(126)) AND (content.deleted=0) AND (content.published) AND xref.keyword_id = keywords.id AND content.hidemenu = 0 AND content.id = xref.content_id AND content.id != 90 GROUP BY content.id ORDER BY total_kw DESC, date DESC LIMIT 10;[/tt]

                The above is when I don't use &LR_selectDocsWithChildren=`1`
                When I do use &LR_selectDocsWithChildren=`1` then I get this error instead
                
                « MODx Parse Error »
                MODx encountered the following error while attempting to parse the requested resource:
                « PHP Parse Error »
                 
                PHP error debug
                  Error: 	array_merge() [function.array-merge]: Argument #1 is not an array	 
                  Error type/ Nr.: 	Warning - 2	 
                  File: 	/Users/blahblah/Sites/manager/includes/document.parser.class.inc.php(730) : eval()'d code	 
                  Line: 	220
                
                  • 20488
                  • 353 Posts
                  Any significance to the format difference in the SELECTs
                  of yours = content.id IN(4557) and mine = (content.id IN(126))

                  I don’t think so. Maybe try to copy/paste the latest source code in the first post of this topic.
                  VF
                  La différence de format dans ton select et le mien a-t-il une signification ?
                  Réponse:
                  Je ne pense pas. Essaye peut être de copier/coller le dernier code source dans le premier post de ce topic.


                  Excuse moi, je vais te demander des question relativement simples, mais c’est juste pour voir si c’est réellement un bug :

                  - Quel est le numéro de document qui appelle le snippet ? (Je suppose que c’est le 90)
                  - Ton document 126 est il un répertoire ?
                  - Si c’est le cas, celui-ci a t-il des documents children qui sont publiés et non supprimés ?
                  - Y a t il des documents qui ont pour mot clé ’finder’ dans ce répertoire ?
                  - Quelle version de modX utilises-tu ?

                  Merci wink
                    • 4295
                    • 98 Posts
                    - Quel est le numéro de document qui appelle le snippet ? (Je suppose que c'est le 90)
                    Yes, 90
                    
                    - Ton document 126 est il un répertoire ?
                    Yes 126 is a répertoire (if that means "folder")
                    
                    - Si c'est le cas, celui-ci a t-il des documents children qui sont publiés et non supprimés ?
                    Yes, there are published children inside
                    
                    - Y a t il des documents qui ont pour mot clé 'finder' dans ce répertoire ?
                    Yes, "Finder"
                    
                    - Quelle version de modX utilises-tu  ?
                    0.9.5 beta 5
                    
                      • 20488
                      • 353 Posts
                      Okay je crois (et j’espère) avoir vu le bug wink, essaye de mettre à jour le snippet avec le code suivant :

                      <?php
                      // --------------------
                      // Snippet: ListRelated
                      // --------------------
                      // Version: 0.9.2 ModXfied by mr_go
                      // Date: 2006.04.07
                      // Originaly made by
                      // [email protected]
                      // Modxifed by [email protected]
                      // Then by mr_go
                      // added the option to set the in menu option
                      // This snippet was designed to show a list of pages that are
                      // related based on specified keywords, or those used in the
                      // current page
                      //
                      
                      
                      // Configuration Settings
                      
                         // LR_keywords [ string ]
                         // This is a comma separated list of keywords that can be set
                         // from the snippet parameter ONLY. Ex:
                         // [[ListRelated?LR_keywords=fun,functional,good stuff]]
                         // If no snippet variable is set, related pages will be found
                         // based on the host page's keywords.
                      
                         // $maxRelated [ int ]
                         // The maximum number of related pages you want to have. Can also
                         // be set/overridden as the snippet variable "LR_max" as in:
                         // [[ListRelated?LR_max=5]]
                         $maxRelated = 10;
                      
                         // $relatedListTitle [ string ]
                         // Give your related list of links a title if you desire- otherwise
                         // set as an empty string ''. Can also be declared in snippet call
                         // with "LR_title" like:
                         // [[ListRelated?LR_title=Other links you might like]]
                         $relatedListTitle = 'Et aussi...';
                      
                         // $removeNewlines [ true | false ]
                         // As always, with lists, it's best NOT to have new lines and whitespace
                         // with IE. For debugging and reading source code, set to false, for live
                         // implementation and styling, try setting to true.
                         $removeNewlines = true;
                         
                         // $sortBy [ 'date' | 'pagetitle' ]
                         // Field you would like to sort by. Options include:
                         // date       dates will be sorted by pub_date if it exists, else createdon
                         // pagetitle  page title
                         // Can also be set in snippet call with $LR_sortBy (see example under $sortDir)
                         $sortBy = 'date';
                         
                         // $sortDir [ 'ASC' | 'DESC' ]
                         // Choose to sort in ascending (ASC) or descending (DESC) order. Can be set
                         // in snippet call with $LR_sortDir:
                         // [[ListRelated??LR_sortBy=date&LR_sortDir=DESC]]
                         $sortDir = 'DESC';
                      
                         // $showhidemenu [ 0 | 1 ]
                         // Must we hide the documents that are set to hide in menu
                         // when set to 0 it wil NOT show the documents that are marked as hide in menu
                         $showhidemenu = 0;
                         
                         // LR_skipPages [ string ]
                         // Must we skip some pages (given by page#1,page#2,page#3..) e.g: [[ListRelated? &LR_skipPages='21,45,51']]
                         // Default value : ''
                         // $skipPages = "";
                         
                         // LR_skipDeleted [0 | 1]
                         // Default value : 0
                         // Must we skip deleted pages
                         
                         // LR_skipUncacheable [0 | 1]
                         // Default value : 0
                         // Must we skip pages that are not cacheable
                         
                          // LR_skipUnsearchable [0 | 1]
                          // Default value : 0
                          // Must we skip pages that are not searchable
                      	
                      	// LR_skipFolder [0 | 1]
                          // Default value : 0 
                          // Must we skip pages that are marked as folder
                      	
                      	// LR_skipUnpublished [0 | 1]
                          // Default value : 0
                          // Must we skip pages that are not published
                      	
                      	
                      	// LR_label [string]
                          // Default value : 'pagetitle'
                      	// Content of the title attribute for <a> anchor must be a field label of the prefix_site_content table 
                      	// e.g = [[ListRelated? &LR_label='title']]
                      	
                      	
                      	// LR_titleAttribute [string]
                          // Default value : 'longtitle'
                      	// Content of the title attribute for <a> anchor must be a field label of the prefix_site_content table 
                      	// e.g = [[ListRelated? &LR_titleAttribute='description']]
                      
                      	
                      	/*LR_contentParagraph [ string ]
                      	// Content of the <p> tag if mentioned. 
                      	// Default value : '' 
                      	// Content of contentParagraph must be a field label of the prefix_site_content table
                      	// e.g = [[ListRelated? &LR_contentOption='description']]
                      	*/
                      
                      	/*LR_selectDocs [ string ]
                      	// Default value : '' 
                      	// Must we intergrate only pages found in the list e.g = [[ListRelated? &LR_onlyDocs='5,51']]
                      	*/
                      	
                      	
                      	/*LR_selectDocsWithChildren [ 0 | 1 ]
                      	// Default value : 1; 
                      	// If we are in LR_selectDocs mod search, must we include children (recursive).
                      	*/
                      
                      // Styles
                      
                         // .LR_listTitle     class for list title
                         // .LR_linksList     class for ul element
                         // .LR_description   class for p element
                      
                      // ***********************************
                      // END CONFIG SETTINGS
                      // THE REST SHOULD TAKE CARE OF ITSELF
                      // ***********************************
                      
                      // assign IE variable
                      $newline = ($removeNewlines)? '':"\n";
                      
                      // assign appropriate default or passed variables
                      $maxRelated = (isset($LR_max))? $LR_max : $maxRelated;
                      $relatedListTitle = (isset($LR_title))? $LR_title : $relatedListTitle ;
                      $sortBy = (isset($LR_sortBy))? $LR_sortBy: $sortBy ;
                      $sortDir = (isset($LR_sortDir))? $LR_sortDir :$sortDir ;
                      $querySkipPages = (isset($LR_skipPages) && ($LR_skipPages!='') )? " AND (NOT(content.id IN(".$LR_skipPages."))) " : "" ;
                      $queryOnlyPages =  (isset($LR_selectDocs) && ($LR_selectDocs!=''))? " AND (content.id IN(".$LR_selectDocs.")) " : "" ; 
                      
                      $querySkipDeleted = (isset($LR_skipDeleted) && ($LR_skipDeleted))? " AND (content.deleted=0) " : "" ;
                      $querySkipUnCacheable = (isset($LR_skipUncacheable) && ($LR_skipUncacheable))? " AND (content.cacheable) " : "" ;
                      $querySkipUnSearchable = (isset($LR_skipUnsearchable) && ($LR_skipUnsearchable))? " AND (content.searchable) " : "" ;
                      $querySkipUnPublished = (isset($LR_skipUnpublished) && ($LR_skipUnpublished))? " AND (content.published) " : "" ;
                      $querySkipFolder =  (isset($LR_skipFolder) && ($LR_skipFolder))? " AND (NOT content.isfolder) " : "" ; 
                      
                      $complete_select_query = array("content.id", "content.pagetitle", "content.description", "content.longtitle");
                      $choosenLabel = 'pagetitle';
                      $choosenTitleAttribute = 'longtitle';
                      $choosenContentParagraph = '';
                      
                      // assign appropriate displayed values AND query select options
                      if(isset($LR_label))
                      {
                      $choosenLabel = $LR_label;
                      	if(!in_array("content.".$LR_label,$complete_select_query))
                      		array_push($complete_select_query,"content.".$LR_label);
                      }
                      
                      
                      if(isset($LR_titleAttribute))
                      {
                      	$choosenTitleAttribute = $LR_titleAttribute;
                      	if(!in_array("content.".$LR_titleAttribute,$complete_select_query))
                      		array_push($complete_select_query,"content.".$LR_titleAttribute);
                      }
                      
                      if(isset($LR_contentParagraph))
                      {
                      	$choosenContentParagraph = $LR_contentParagraph;
                      	if(!in_array("content.".$LR_contentParagraph,$complete_select_query))
                      		array_push($complete_select_query,"content.".$LR_contentParagraph);
                      	
                      }
                      
                      $choosenContentParagraph = (isset($LR_contentParagraph))? $LR_contentParagraph :'';
                      
                      // Make array of keywords from snippet or from current page. Snippet
                      // variables have priority.
                      
                      if (isset($LR_keywords)){
                        $kArray= explode(",",$LR_keywords);
                      } else {
                        $kArray = $modx->getKeywords();
                      }
                      
                      
                      if(!function_exists('getRecursiveAllChildren'))
                      {
                      	function getRecursiveAllChildren($modXObject,$idDoc,$arrayChildren = array())
                      	  {
                         	
                      	 array_push($arrayChildren,$idDoc); 
                      	 $arrayDocChild  = $modXObject->getAllChildren($idDoc);
                      	 
                      	 foreach($arrayDocChild as $id=>$val)
                      		 $arrayChildren = getRecursiveAllChildren($modXObject,$val['id'],$arrayChildren);
                      		
                      	 return($arrayChildren);
                      	  }
                      }
                        
                       
                      
                      
                      
                      
                      
                      // if there are keywords, make the list
                      $relatedOutput = '';
                      if ($kArray){
                        $keyString = '';
                        foreach ($kArray as $key){
                          $keyString .= "'".$key."',";
                        }
                        $keyString = substr($keyString,0,strlen($keyString)-1);
                      
                        // make sql statement for retreiving similar pages
                        $pre= $modx->dbConfig['dbase'].".".$modx->dbConfig['table_prefix'];

                      $all_custom_queries = "";
                      if (($LR_selectDocs!='') && isset($LR_selectDocsWithChildren) && ($LR_selectDocsWithChildren))
                      {
                      $arraySelectedDocs = explode(',',trim($LR_selectDocs));
                      $arrayAllChildren = array();
                      foreach($arraySelectedDocs as $arrayVal)
                      {
                      $arrayAllChildren = array_unique(array_merge($arrayAllChildren,getRecursiveAllChildren($modx,$arrayVal),array($arrayVal)));
                      }

                      $queryIn = "AND content.id IN(".implode(",",$arrayAllChildren).") ";
                      $all_custom_queries = $queryIn." ".$querySkipFolder." ".$querySkipDeleted." ".$querySkipUnCacheable." ".$querySkipUnSearchable." ".$querySkipUnPublished." ".$querySkipPages;

                      }
                      else
                      $all_custom_queries = $queryOnlyPages." ".$querySkipFolder." ".$querySkipDeleted." ".$querySkipUnCacheable." ".$querySkipUnSearchable." ".$querySkipUnPublished." ".$querySkipPages;



                      $complete_select_query = implode(',',$complete_select_query);
                      $relatedSql = "SELECT ".$complete_select_query.",
                      IF(content.pub_date > 0, content.pub_date, content.createdon) AS date,
                      COUNT(keywords.id) as total_kw
                      FROM
                      ".$pre."site_content AS content,
                      ".$pre."keyword_xref AS xref,
                      ".$pre."site_keywords AS keywords
                      WHERE keywords.keyword IN (".$keyString.")
                      $all_custom_queries
                      AND xref.keyword_id = keywords.id
                      AND content.hidemenu = ".$showhidemenu."
                      AND content.id = xref.content_id
                      AND content.id != ".$modx->documentObject['id']."
                      GROUP BY content.id
                      ORDER BY total_kw DESC, ". $sortBy . ' ' . $sortDir ."
                      LIMIT ".$maxRelated.";";


                      $relatives = $modx->dbQuery($relatedSql);
                      $relativeCount = $modx->recordCount($relatives);
                      $relArray = array();
                      for($i=0;$i<$relativeCount;$i++) {
                      array_push($relArray,$modx->fetchRow($relatives));
                      }

                      $getAttribute = "id,$choosenLabel,$goodTitleAttribute";
                      $getAttribute .=($choosenContentParagraph!='')? $choosenContentParagraph:"";


                      // start output if we have results
                      if ($relativeCount){
                      $relatedOutput .= ($relatedListTitle )?'<span class="LR_listTitle">' . $relatedListTitle . '</span>' : '' ;
                      $relatedOutput .= '<ul class="LR_linksList">'.$newline;
                      for ($li=0;$li<$relativeCount;$li++){
                      $goodLabel = $relArray[$li][$choosenLabel];
                      $goodTitleAttribute = $relArray[$li][$choosenTitleAttribute];
                      $goodContentParagraph = (($choosenContentParagraph!='')&& isset($relArray[$li][$choosenContentParagraph])) ? '<p class="LR_description">'.$relArray[$li][$choosenContentParagraph].'</p>':'';
                      $relatedOutput .= '<li><a href=[~' . $relArray[$li]['id'] . '~] title="' .$goodTitleAttribute. '">' .$goodLabel. '</a>'.$goodContentParagraph.'</li>'.$newline;
                      }
                      $relatedOutput .='</ul>'.$newline;
                      }
                      }

                      return $relatedOutput;
                      ?>
                      <br /><br />Est ce que cela fonctionne maintenant ?<br /><br />