The file recursion is working, there is still a problem with SEF, so I can'r fix the internal links yet. I've asked on opensef.org for help...here is the code which replaces the save function in administrator/components/com_typedcontent/admin.typedcontent.php (there is some issue with this board duplicating strings occasionally, hopefuly this wont mess it up:
function save( $option, $task ) {
global $database, $my, $mainframe;
// global $mosConfig_sef;
$ordering=1;
$mosConfig_sef = 0;
$nullDate = $database->getNullDate();
$menu = mosGetParam( $_POST, 'menu', 'mainmenu' );
$menuid = mosGetParam( $_POST, 'menuid', 0 );
$row = new mosContent( $database );
if (!$row->bind( $_POST )) {
echo "\n";
exit();
}
if (!$row->introtext) {
echo "\n";
}
echo $row->introtext.'
';
$dir = dirname($row->introtext );
$arrfiles = scan_Dir($dir);
foreach ($arrfiles as $file) {
// SETUP DATA
$row = new mosContent( $database );
if (!$row->bind( $_POST )) {
echo "\n";
exit();
}
// ID AND DATES
if ( $row->id ) {
$row->modified = date( 'Y-m-d H:i:s' );
$row->modified_by = $my->id;
} else {
$row->created = date( 'Y-m-d H:i:s' );
$row->created_by = $row->created_by ? $row->created_by : $my->id;
}
if (trim( $row->publish_down ) == 'Never') {
$row->publish_down = $nullDate;
}
// PARAMS
$params = mosGetParam( $_POST, 'params', '' );
if (is_array( $params )) {
$txt = array();
foreach ( $params as $k=>$v) {
$txt[] = "$k=$v";
}
}
$row->attribs = implode( "\n", $txt );
// TITLE
echo '
Loading file: '.$file.'
';
$page = file_get_contents($file);
$page = str_replace("\n", '', $page);
$page = str_replace("\r", '', $page);
$title = ExtractString($page,'
','');
if ($mytitle = '') $mytitle = $file;
$row->title = $title;
$row->title = ampReplace( $row->title );
$row->title_alias = $title;
$mainframe->appendPathWay($row->title);
// TEXT
echo '
title: '.$title.'
';
if ( $mosConfig_sef ) {
$path = sefRelToAbs("component/option,com_typedContent/".$title);
//$com_staticxt_url = "component/option,com_staticxt/".$title;
/* $pattern = "/".preg_quote($com_staticxt_url, "/")."([^\"\s]*=)/i";
preg_match_all($pattern, $pageContent ,$matches, PREG_OFFSET_CAPTURE);
$i=0;
$offset = intval($matches[1][$i][1]);
if ($offset > 0) {
$tmp = $matches[1][$i][0];
$tmp = str_replace('=', ',', $tmp);
$tmp = preg_replace('/(\?|&)/', '/', $tmp);
$pageContent = str_replace($matches[1][$i][0], $tmp, $pageContent);
$i++;
$offset = intval($matches[1][$i][1]);
}
*/
} else {
$path = "index.php?option=com_typedContent&id=".$row->id;
}
$page = preg_replace('/(.*)(?i)()/', '
'.'\2', $page); $page = preg_replace('/(?i)(<\/body>)(.*)/', ' |
', $page);
preg_replace( '/(?i)(\ssrc([\s\"=\']*))/', '\1'.$path, $page);
preg_replace( '/(?i)(<(table|th|td).*)(\sbackground([\s\"=\']*))/', '\1'.'\3'.$dir, $page);
preg_replace( '/(?i)(movie.*)(\svalue([\s\"=\']*))/', '\1'.'\2'.$path, $page);
$pattern = "/(?i)([^=\"\s]*?(\.css))(?=((?!(href=)))*?)(?=((?!(<(link).)))>?)/";
preg_replace( $pattern, $dir.'\1', $page);
$pattern = "/(?i)([^=\"\s]*?(\.(jp?g|gif|png)))(?=((?!(background=)))*?)(?=((?!(<(table|th|td).)))>?)/";
preg_replace( $pattern, $path.'\1', $page);
// code cleaner for xhtml transitional compliance
$page = str_replace( '
', '
', $page);
/*
if ($pathwayPatch == "X") {
if ( $mosConfig_sef ) {
$xtItem = "Itemid,".$Itemid."/xt_item,1/"; }
else {
$xtItem = "&Itemid=".$Itemid."&xt_item=1"; }
} else $xtItem = "";
*/
//$page = strip_tags($page);
// $page = html_entity_decode($page, ENT_NOQUOTES);
// echo $page;
$row->introtext = $page;
if (!$row->check()) {
echo "\n";
closedir($dir);
exit();
}
if (!$row->store()) {
echo "\n";
closedir($dir);
exit();
}
$row->checkin();
$query = "UPDATE #__content"
. "\n SET state = 1"
. "\n WHERE id = $row->id "
;
$database->setQuery( $query );
if (!$database->query()) {
echo "\n";
exit();
}
$ordering++;
AddToMenu($path, $title,$row->id, $ordering);
}
exit;
switch($task) {
case 'go2menu':
mosRedirect( 'index2.php?option=com_menus&menutype='. $menu );
break;
case 'go2menuitem':
mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $menuid );
break;
case 'menulink':
menuLink( $option, $row->id );
break;
case 'resethits':
resethits( $option, $row->id );
break;
case 'save':
$msg = 'Typed Content Item saved';
mosRedirect( 'index2.php?option='. $option, $msg );
break;
case 'apply':
default:
$msg = 'Changes to Typed Content Item saved';
mosRedirect( 'index2.php?option='. $option .'&task=edit&hidemainmenu=1&id='. $row->id, $msg );
break;
}
}
function scan_Dir($dir) {
$arrfiles = array();
$exts = array("htm", "html"); //"jpg$|\\.jpeg","png","bmp");
if (is_dir($dir)) {
if ($handle = opendir($dir)) {
chdir($dir);
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($file)) {
$arr = scan_Dir($file);
foreach ($arr as $value) {
$arrfiles[] = $dir."\\".$value;
}
} else {
foreach ($exts as $value) {
$testExt = "\.".$value."$";
if (eregi($testExt, $file)){
$arrfiles[] = $dir."\\".$file;
}
}
}
}
}
chdir("../");
}
closedir($handle);
}
return $arrfiles;
}
function ExtractString($str, $start, $end){
$str_low = strtolower($str);
$pos_start = strpos($str_low, $start);
$posoffset = $pos_start + strlen($start);
$pos_end = strpos($str_low, $end, (string) $posoffset);
if ( ($pos_start !== false) && ($pos_end !== false) ){
$pos1 = $pos_start + strlen($start);
$pos2 = $pos_end - $pos1;
return substr($str, $pos1, $pos2);
}
}
function AddToMenu($url, $title,$cid,$ordering){
global $database;
$myDebug = 0;
// $id = 10;
$menutype = 'other';
$menulink = 'index.php?option=com_content&task=view&id='.$cid;
$type = 'content_typed';
$browserNav = 0;
$title = substr($title, 0, 20) ; // min length?
$title = substr(addslashes($title), 0, 50);
if (strlen($title) == 20) {$title[18]='.'; $title[19]='.'; };
/*
if ($level+1>4) {
$componentid = 0;
$browserNav = 1;
}$content_id = $content_id++;
*/
$query = 'INSERT INTO `jos_menu` ( `id` , `menutype` , `name` , `link` , `type` , `published` , `parent` , `componentid` , `sublevel` , `ordering` , `checked_out` , `checked_out_time` , `pollid` , `browserNav` , `access` , `utaccess` , `params` ) '
. " VALUES ( 'NULL', '$menutype', '$title', '$menulink', 'content_typed', '1', '0', '$cid', '0', '$ordering', '0', '0000-00-00 00:00:00', '0', '$browserNav', '0', '3', '' );"
. ' ';
if ($myDebug) echo "query: $query
";
$database->setQuery( $query );
if (!$database->query()) {
echo "\n";
exit();
}
}
?>