<?php
/*
* @name FirstChildRedirect
* @author Jason Coward <[email protected]>
* @modified-by Ryan Thrash <[email protected]>
* @license Public Domain
* @version 1.0
*
* This snippet redirects to the first child document of a folder in which this
* snippet is included within the content (e.g. [!FirstChildRedirect!]). This
* allows MODx folders to emulate the behavior of real folders since MODx
* usually treats folders as actual documents with their own content.
*
* Modified to make Doc ID a required parameter... now defaults to the current
* Page/Folder you call the snippet from.
*
* Modified to work with YAMS
*
* &docid=`12`
* Use the docid parameter to have this snippet redirect to the
* first child document of the specified document.
*/
$docid = (isset($docid))? $docid: $modx->documentIdentifier;
$children= $modx->getActiveChildren($docid, 'menuindex', 'ASC');
if (!$children === false) {
$firstChild= $children[0];
$firstChildUrl= $modx->makeUrl($firstChild['id']);
} else {
$firstChildUrl= $modx->makeUrl($modx->config['site_start']);
}
$lang = $modx->runSnippet('CurrentLanguage');
return $modx->sendRedirect('/'.$lang.$firstChildUrl);
?>
<?php
require_once( $modx->config['base_path'] . 'assets/modules/yams/class/yams.class.inc.php' );
// Get an instance of the yams class
/* @var $yams YAMS */
$yams = YAMS::GetInstance();
if ($yams->IsMultilingualDocument($modx->documentIdentifier)) {
$lang = $yams->GetCurrentLangId();
} else {
$lang = 'en';
}
return $lang;
?>
]]>