We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21272
    • 21 Posts
    Приветствую.

    Есть такой замечательный сниппет, но он отображает только соседние документы (дочерние документы активной папки), подскажите как сделать что бы можно было "путешествовать" по соседним родителям..

    Т.е. Есть такое меню.
    --Главная папка
    ---Под папка
    ------Документ
    ------Документ
    ---Под папка
    -----Документ
    -----Документ

    Сейчас сниппет "ходит" только по документам, а хотелось бы еще и по Под папкам.
    Подскажите, пожалуйста, как дописать пару дополнительных плейсхолдеров для под папок?
    Привожу код сниппета:
    <?php
    /*
     * **************************
     * Snippet: PrevJumpNext
     * By: Jeroen Bosch modded by OncleBen31 modded by Aaron Heinrich
     * Date: May 2006 - July 2008
     * version: 0.4 (based on the PrevNext v0.9)
     * **************************
     *
     * DESCRIPTION
     *
     * Generates links to navigate between documents in a directory.
     * Highly configurable. It can display :
     *  - 'Showing article x of x'
     *  - 'Prev' and 'Next' links with or without document titles
     *  - 'First' and 'Last' links.
     *  - 'Index' link to parent folder
     *  - A select to jump quickly to a document
     *
     *  Can output links or generate the following placeholders: 
     *  - [+PJN_first+] : the first document
     *  - [+PJN_prev+] : the previous document
     *  - [+PJN_jump+] : the droplist to jump to the selectionned document
     *  - [+PJN_index+] : the link to retern to the index page
     *  - [+PJN_next+] : the next document
     *  - [+PJN_last+] : the last document
     *
     * PARAMETERS
     *
     * - startID : Int: id of document folder to start from (default: parent document id);
     * - sortBy : String : Document variable to sort items by. 'menuindex' or 'id' or 'createdon', etc...  (default: createdon);
     * - sortHow : [ASC|DESC] : Sort order? 'ASC' or 'DESC' (default ASC);
     * - displayTitle : Boolean : Display document titles instead of &prevText and &nextText (default true);
     * - displayFixed : Boolean : Show 'first' and 'last' links (default false);
     * - usePlaceHolder : Boolean : Generate placeholders and do not output html : [+PJN_first+] , [+PJN_prev+] , [+PJN_jump+] , [+PJN_index+] , [+PJN_next+] , [+PJN_index+]  (default false);
     * - useJump : Boolean : Replace the index link by the select list when NOT using the placeholders (default false);
     * - indexDocumentID : Int : ID of the document linked as "index". (default &startID);
     * - displayNoPrevNext : Boolean : Display &noPrevNextText in place of "previous" and "next" when there is no previous or next item (default false);
     * - noPrevNextText : String : Text to display if there is no Prev or Next item and &displayNoPrevNext == 1 :(default "No more records");
     * - indexText : String : Title for "index" item (default "Index");
     * - jumpText : String : Title for select list (default :"Please Select");
     * - firstText : String : Title for "first" link (default "First");
     * - prevText : String : Title for "previous" item when $displayTitle is set to false (default "Prev");
     * - nextText : String : Title for "next" item when $displayTitle is set to false (default "Next");
     * - lastText : String : Title for "last" item (default "Last");
     * - exclude : Array : Comma-separated list of document IDs to exclude from navigation (default [empty])
     * - separator : String : Inserted between items (default " | ");
     * - displayIndex : Boolean: display index menu item (default true);
     * - firstSymbol : String : Prefixed to "First" menu item (default [empty]);
     * - prevSymbol : String : Prefixed to "Previous" menu item (default [empty]);
     * - nextSymbol : String : Suffixed to "Next" menu item (default [empty]);
     * - lastSymbol : String : Prefixed to "Last" menu item (default [empty]);
     * - displayTotal : Boolean : Show "Showing article X of Y" item (default true);
     * - recordTypeName : String : Name of records type for "Total" item.  E.g. (if = "article") "Showing article 3 of 25" (default "article");
     * - includeFolders : Boolean : include folder documents in the menu (default true);
     * - maxTitleChars : Int : Truncate document titles to this number of characters (default 0 [=display entire title]
     *
     * OUTPUT
     *
     *  Menu items are not wrapped in an enclosing element. Output is anchor elements with semantic class names E.G.:
     *  <a href="url" class="previous">Previous Title</a> | <a href="url" class="index">Index</a> | <a href="url" class="next">Next Title</a>
     *  Class names are: total, currentNumber, totalNumber, first, previous, index, next, last
     *
     * EXAMPLE CALLS :
     *
     * [[PrevJumpNext? sortBy=`menuindex` &sortHow=`ASC` &displayTitle=`1`]]
     * 
     * [[PrevJumpNext? &sortBy=`pub_date` &usePlaceHolder=true &indexDocumentID=`84` &firstText=`First` &lastText=`Last` &prevText=`Previous` &nextText=`Next` &indexText=`List of Articles` &jumpText=`Quick Access` &displayNoPrevNext=`1` &noPrevNextText=`It's the end`]]
     * with these place holders in the document [+PJN_first+] [+PJN_prev+] [+PJN_jump+] [+PJN_index+] [+PJN_next+] [+PJN_last+]
     */
    
    // Settings
    if(!isset($startID)){
        $startID = $modx->documentObject['parent'];
    }
    if(!isset($sortBy)){
        $sortBy = 'createdon';
    }
    if(!isset($sortHow)){
        $sortHow = 'ASC';
    }
    if(!isset($displayTitle)){
        $displayTitle = 1;
    }
    if(!isset($titleMaxChars)){
        $titleMaxChars = 0;
    }
    if(!isset($displayFixed)){
        $displayFixed = 0;
    }
    if(!isset($usePlaceHolder)){
    	$usePlaceHolder = 0;
    }
    if(!isset($useJump)){
    	$useJump=false;
    }
    if(!isset($indexDocumentID)){
    	$indexDocumentID=$modx->documentObject['parent'];
    }
    if(!isset($displayNoPrevNext)){
    	$displayNoPrevNext=0;
    }
    if(!isset($noPrevNextText)){
    	$noPrevNextText="No more records";
    }
    if(!isset($indexText)){
    	$indexText="Index";
    }
    if(!isset($jumpText)){
    	$jumpText="Please Select";
    }
    if(!isset($firstText)){
    	$firstText="First";
    }
    if(!isset($prevText)){
    	$prevText="Prev";
    }
    if(!isset($nextText)){
    	$nextText="Next";
    }
    if(!isset($lastText)){
    	$lastText="Last";
    }
    if(!isset($exclude)){
    	$exclude=array();
    } else {
    	$exclude = split(",",$exclude);
    }
    if(!isset($separator)){
    	$separator=" | ";
    }
    if(!isset($displayIndex)){
    	$displayIndex=1;
    }
    if(!isset($firstSymbol)){
    	$firstSymbol="";
    }
    if(!isset($lastSymbol)){
    	$lastSymbol="";
    }
    if(!isset($prevSymbol)){
    	$prevSymbol="";
    }
    if(!isset($nextSymbol)){
    	$nextSymbol="";
    }
    if(!isset($displayTotal)){
    	$displayTotal=1;
    }
    if(!isset($recordTypeName)){
    	$recordTypeName="record";
    }
    if(!isset($includeFolders)){
    	$includeFolders=1;
    }
    
    $id = $modx->documentIdentifier;
    $fields='id,pagetitle,isfolder,hidemenu'; // what fields do you want to know
    $children = $modx->getActiveChildren($startID, $sortBy, $sortHow, $fields);
    $y = 1;
    // sorting the documents, giving them a sequential and searchable index
    foreach ($children as $child) {
       if (!in_array($child['id'],$exclude) && !$child['hidemenu'] && !in_array($child['id'],$exclude) && ($includeFolders == 1 || $child['isfolder'] == 0)) {
        	$my_array[$y] = $child;
        	if ($my_array[$y]['id']==$id) {
        	    $current=$y; // The current page has number $y in the array
        	}
           $y++;
        }
    }
    $prev = $current-1;
    $next = $current+1;
    $limit = $y;
    
    // ////// Construction of the elements
    
    $PJN_totalPlaceHolder = "Showing " . $recordTypeName . " <span class='currentNumber'>" . $current . "</span> of <span class='totalNumber'>" . $limit . "</span>\n";
    
    // First item
    $PJN_firstPlaceHolder = "<a href='[~".$my_array[1]['id']."~]' class='first'>".$firstSymbol.$firstText."</a>" ;
    
    // Prev item
    if($prev > 0 && $displayTitle==false){
    	$PJN_prevPlaceHolder = "<a href='[~".$my_array[$prev]['id']."~]' class='previous'>".$prevSymbol.$prevText."</a>";
    } elseif($prev > 0 && $displayTitle==true) {
        $prevTitle = ($maxTitleChars > 0) ? substr($my_array[$prev]['pagetitle'],0,$maxTitleChars) . "..." : $my_array[$prev]['pagetitle'];
    	$PJN_prevPlaceHolder = "<a href='[~".$my_array[$prev]['id']."~]' class='previous'>".$prevSymbol.$prevTitle."</a>";
    } elseif($prev == 0 && $displayNoPrevNext == true) {
    	$PJN_prevPlaceHolder = $noPrevNextText;
    }
    // Select List
    $PJN_jumpPlaceHolder = '<form action="" name="jump" id="jump">
    <select name="myjumpbox"
     onchange="location.href=jump.myjumpbox.options[selectedIndex].value">
    	 <option selected="selected">'.$jumpText;
    foreach ($my_array as $my_page) {
         $jumpTitle = ($maxTitleChars > 0) ? substr($my_page['pagetitle'],0,$maxTitleChars) . "..." : $my_page['pagetitle'];
    	 $PJN_jumpPlaceHolder .= '    <option value="[~'.$my_page['id'].'~]">'.$jumpTitle.'</option>';
    	}
    $PJN_jumpPlaceHolder .= '</select></form>';
    
    // Index item
    $PJN_indexPlaceHolder = "<a href='[~".$indexDocumentID."~]' class='index'>".$indexText."</a>";
    
    // Next item
    if($next < $limit && $displayTitle==false){
    	$PJN_nextPlaceHolder = "<a href='[~".$my_array[$next]['id']."~]' class='next'>".$nextText.$nextSymbol."</a>";
    } elseif($next < $limit && $displayTitle==true) {
    	$nextTitle = ($maxTitleChars > 0) ? substr($my_array[$next]['pagetitle'],0,$maxTitleChars) . "...".$nextSymbol : $my_array[$next]['pagetitle'].$nextSymbol;
           $PJN_nextPlaceHolder ="<a href='[~".$my_array[$next]['id']."~]' class='next'>".$nextTitle."</a>";
    } elseif($next == $limit && $displayNoPrevNext == true) {
    	$PJN_nextPlaceHolder = $noPrevNextText;
    
    }
    
    // Last item
    $PJN_lastPlaceHolder = "<a href='[~".$my_array[$limit-1]['id']."~]' class='last'>".$lastText.$lastSymbol."</a>";
    
    // //////// Output commputing modded by Oncleben31 modded by Aaron Heinrich
    
    if ($usePlaceHolder==false) {
    
    	// Here starts the output
    	$output = "";
    
    	if ($displayTotal) {
    		$output .= "<span class=\"total\">" . $PJN_totalPlaceHolder . "</span>\n";
    
    	}
    
    	if($displayFixed==true && $prev-1>0) {
    		$output .= $PJN_firstPlaceHolder.$separator . "\n";
    	}
    
        	if ($prev>0 || $displayNoPrevNext == true) {
    	     $output .= $PJN_prevPlaceHolder; 
                if ($displayIndex ==1  || $useJump==1 || $next < $limit ) {
                     $output .= $separator;
                }
    	}
    	if($useJump) {
    		$output .= $PJN_jumpPlaceHolder;
    		if ($next < $limit || $displayNoPrevNext == true) {
                  $output .= $separator;
            }
            $output .= "\n";
    	} elseif ($displayIndex == 1) {
    		$output .= $PJN_indexPlaceHolder;
                    if ($next < $limit || $displayNoPrevNext == true)  {
                            $output .= $separator;
                    }
            }
    		$output .=  "\n";
            if ($next < $limit || $displayNoPrevNext == true) {
    	      $output .= $PJN_nextPlaceHolder;
              if ($displayFixed == true && $next+1 < $limit) {
                         $output .= $separator;
    	      }
    	      $output .= "\n";
            }
    
    	if($displayFixed==true && $next+1 < $limit) {
    		$output .= $PJN_lastPlaceHolder;
    		$output .= "\n";
    	}
    	return $output;
    }
    else {
    	// Set PlaceHolder
    	$modx->setPlaceholder('PJN_total',$PJN_totalPlaceHolder);
    	$modx->setPlaceholder('PJN_first',$PJN_firsPlaceHolder);
    	$modx->setPlaceholder('PJN_prev',$PJN_prevPlaceHolder);
    	$modx->setPlaceholder('PJN_jump',$PJN_jumpPlaceHolder);
    	$modx->setPlaceholder('PJN_index',$PJN_indexPlaceHolder);
    	$modx->setPlaceholder('PJN_next',$PJN_nextPlaceHolder);
    	$modx->setPlaceholder('PJN_last',$PJN_lastPlaceHolder);
    }
    ?>
      • 782
      • 37 Posts
      Вот мне как раз тоже интересно это.
      как осуществить переход
      <<предыдущий следующий>>
      по всем документам в выбранных подпапках?
      очень нужно решение. Может кто-то сможет ответить.
        • 1611
        • 591 Posts
        Нужно заменить в этом куске:

        $id = $modx->documentIdentifier;
        $fields=’id,pagetitle,isfolder,hidemenu’; // what fields do you want to know
        $children = $modx->getActiveChildren($startID, $sortBy, $sortHow, $fields);

        функцию getActiveChildren на getDocuments только нужно согласовать ее по параметрам вот дока: http://wiki.modxcms.com/index.php/API:getDocuments
        и далее нужно вместо одного id передать массив тех id папок из которых тебе нужно выбрать документы.
          • 1611
          • 591 Posts
          Ага... похоже придется еще и формат вывода согласовывать.

          Ну как вариант можно сделать вызов getActiveChildren в цикле и далее накапливать результат в одной переменной. (Хотя это плохо по запросам к базе)