Beiträge: |
Hallo zusammen,
hier der versprochene Code, zu ändern in der Datei:
...opn2systemanypageadminimportdiradmin.php
function importdir () {
global $opnConfig, $opnTables;
// HTML-Verzeichnis
$verzeichnis = '';
get_var ('verzeichnis', $verzeichnis, 'form', _OOBJ_DTYPE_CLEAN);
// Kategorie = Verzeichnis
$catname = $verzeichnis;
// Absoluter Pfad
$pfad = $opnConfig['datasave']['anypage_data_url']['path'] . $verzeichnis;
// Rechte
$opnConfig['permission']->HasRights ('system/anypage', array (_ANYPAGE_PERM_IMPORTDIR, _PERM_ADMIN) );
// Kategorie schon vorhanden?
$anypage_page_cat_name = $opnConfig['opnSQL']->qstr ($catname);
$sql = 'SELECT id, name FROM ' . $opnTables['anypage_page_cat'] . ' WHERE (name=' . $anypage_page_cat_name . ')';
$result = $opnConfig['database']->Execute ($sql);
if (is_object ($result) ) {
$result_count = $result->RecordCount ();
} else {
$result_count = 0;
}
if ($result_count==0 )
{
// Save Kategorie Record
$anypage_page_cat_id = $opnConfig['opnSQL']->get_new_number ('anypage_page_cat', 'id');
$anypage_page_cat_text = $opnConfig['opnSQL']->qstr ('');
$anypage_page_cat_img = $opnConfig['opnSQL']->qstr ('');
$opnConfig['database']->Execute ('INSERT INTO ' . $opnTables['anypage_page_cat'] . " VALUES ($anypage_page_cat_id, $anypage_page_cat_name, $anypage_page_cat_text, $anypage_page_cat_img, 0)");
}
else
{
// AnyPageCatId
$anypage_page_cat_id = $result->fields['id'];
}
// Date
$date = Date ('m/d/Y/H/i');
$date_array = explode ('/', $date);
$myyear = $date_array[2];
$mymonth = $date_array[0];
$myday = $date_array[1];
$myhour = $date_array[3];
$mymin = $date_array[4];
$opnConfig['opndate']->setTimestamp ($myyear . '-' . $mymonth . '-' . $myday . ' ' . $myhour . ':' . $mymin . ':00');
$sqldate = '';
$opnConfig['opndate']->opnDataTosql ($sqldate);
// Filelist with out pictues
$noext = array('.jpg','.gif','.bmp','.ico');
$dateiliste = get_file_list ($pfad,$noext);
// File allready exist ?
if (count ($dateiliste) ) {
usort ($dateiliste, 'strcollcase');
$max = sizeof ($dateiliste);
for ($ii = 0; $ii< $max; $ii++) {
if ($dateiliste[$ii] != 'image') {
// PageName
$pagename = trim ($dateiliste[$ii]);
// load html-file
$html = getdateiany ($dateiliste[$ii], $pfad);
// PageTitle
$result = parse_html( $html, 'title');
$title = $result['content'][0];
if ($title ==''){
$title = $pagename;
}
// Parse Body
$result = parse_html( $html, 'body');
$body = $result['extended content'][0];
// lower all 'href' and 'src' Tags
$pattern = array('/href/i' , '/src/i');
$replace = array('href','src');
$body = preg_replace($pattern, $replace, $body);
// fix Links
$body = str_replace ("href="", "href="" . $opnConfig['opn_url'] . '/system/anypage/index.php?page=', $body);
$body = str_replace ("href="" . $opnConfig['opn_url'] . '/system/anypage/index.php?page=#', "href="" . $opnConfig['opn_url'] . '/system/anypage/index.php?page=' . $pagename . '#', $body);
$body = str_replace ("src="", "src="" . $opnConfig['datasave']['anypage_data_url']['url'] . '/' . $catname . '/', $body);
// Free PageId
$anypage_page_id = $opnConfig['opnSQL']->get_new_number ('anypage_page', 'id');
// Record Data
$anypage_page_pagename = $opnConfig['opnSQL']->qstr ($pagename,'pagename');
$anypage_page_title = $opnConfig['opnSQL']->qstr ($title,'title');
$anypage_page_footline = $opnConfig['opnSQL']->qstr ('');
$anypage_page_shortdesc = $opnConfig['opnSQL']->qstr ('');
$anypage_page_wpage = $opnConfig['opnSQL']->qstr ($body,'wpage');
$anypage_page_status = $opnConfig['opnSQL']->qstr ('V','status');
$anypage_page_lastmod = $opnConfig['opnSQL']->qstr ($sqldate,'lastmod');
$anypage_page_anypage_pos = $anypage_page_id;
$anypage_page_anypage_cat = $anypage_page_cat_id;
// page allready exist ?
$sql = 'SELECT id, title FROM ' . $opnTables['anypage_page'] . ' WHERE (title=' . $anypage_page_title . ')';
$result = $opnConfig['database']->Execute ($sql);
if (is_object ($result) ) {
$result_count = $result->RecordCount ();
} else {
$result_count = 0;
}
if ($result_count==0 )
{
// Save New Record
$sql = 'INSERT INTO ' . $opnTables['anypage_page'] . " VALUES ($anypage_page_id, $anypage_page_pagename, $anypage_page_title, $anypage_page_footline, $anypage_page_shortdesc, $anypage_page_wpage, $anypage_page_status, $anypage_page_lastmod, $anypage_page_anypage_pos, $anypage_page_anypage_cat, 0, 0, 0, 0)";
$opnConfig['database']->Execute ($sql);
$opnConfig['opnSQL']->UpdateBlobs ($opnTables['anypage_page'], 'id=' . $anypage_page_id);
}
else
{
// AnyPageId
$anypage_page_id = $result->fields['id'];
// Update Record
$sql = 'UPDATE ' . $opnTables['anypage_page'] . ' SET wpage=' . $anypage_page_wpage . ', lastmod=' . $anypage_page_lastmod . ' WHERE id=' . $anypage_page_id;
$opnConfig['database']->Execute ($sql);
$opnConfig['opnSQL']->UpdateBlobs ($opnTables['anypage_page'], 'id=' . $anypage_page_id);
}
}
}
}
}
function parse_html( $string_org, $token ) {
$string = $string_org;
$string = str_replace ("rn",'<r-e-p-l-a-c-e>',$string);
$string = str_replace ("n",'<r-e-p-l-a-c-e>',$string);
// siehe http://www.regex-tester.de
$pattern = '|<' . $token . '(.*)>(.*)</' . $token . '>|Uui';
$mat = preg_match_all ($pattern, $string , $matches, PREG_PATTERN_ORDER);
$arr = array();
// found token
if ($mat > 0)
{
// found more token
for ($i=0;$i < count($matches[0]);$i++)
{
// Ergebniss
$ret = trim ( $matches[2][$i] );
$arr['content'][$i] = trim ( str_replace ('<r-e-p-l-a-c-e>', "rn", $ret));
// Vorbelegen der anderen Array-Elemente
$arr['extended content'][$i] = $arr['content'][$i];
$arr['modifier'][$i] = '';
// Ergebniss mit text im ersten Token <Token xxx=yyy jjj=666> ...
if (strlen(trim ( $matches[1][$i] )) > 0)
{
// Modifier im Token
$arr['modifier'][$i] = trim($matches[1][$i]);
// Einfügen eines <div> mit Modifier
$ret = '<div ' . $matches[1][$i] . '><r-e-p-l-a-c-e>';
$ret .= trim ( $matches[2][$i] ) . '<r-e-p-l-a-c-e>';
$ret .= '</div>';
$arr['extended content'][$i] = trim ( str_replace ('<r-e-p-l-a-c-e>', "rn", $ret));
}
}
}
else
{
$tmp = str_replace ('>', ']', $string_org);
$tmp = str_replace ('<', '[', $tmp);
$tmp = 'NO MATCHING FOUND FOR : ' . $token . '<br>IN : ' . $tmp;
print($tmp);
$arr['content'][0] = '';
$arr['modifier'][0] = '';
$arr['extended content'][0] = '';
}
return $arr;
}
|