2016-10-06 15:57:01 +00:00
< ? php
2019-10-25 16:00:47 +00:00
2016-10-06 15:57:01 +00:00
/**
* Project :
* Contenido Content Management System
*
* Description :
* Contenido Content Functions
*
* Requirements :
* @ con_php_req 5.0
* @ con_notice Please add only stuff which is relevant for the frontend
* AND the backend . This file should NOT contain any backend editing
* functions to improve frontend performance :
*
*
* @ package Contenido Backend includes
* @ version 1.3 . 7
* @ author Timo A . Hummel
* @ copyright four for business AG < www . 4 fb . de >
* @ license http :// www . contenido . org / license / LIZENZ . txt
* @ link http :// www . 4 fb . de
* @ link http :// www . contenido . org
* @ since file available since contenido release <= 4.6
*
2019-07-03 11:58:28 +00:00
* $Id $ :
2016-10-06 15:57:01 +00:00
*/
2019-10-25 16:00:47 +00:00
if ( ! defined ( 'CON_FRAMEWORK' )) {
die ( 'Illegal call' );
2016-10-06 15:57:01 +00:00
}
/**
* Generates the code for one
* article
*
* @ param int $idcat Id of category
* @ param int $idart Id of article
* @ param int $lang Id of language
* @ param int $client Id of client
* @ param int $layout Layout - ID of alternate Layout ( if false , use associated layout )
*
* @ author Jan Lengowski < jan . lengowski @ 4 fb . de >
* @ copyright four for business AG < www . 4 fb . de >
*/
2019-10-25 16:00:47 +00:00
function conGenerateCode ( $idcat , $idart , $lang , $client , $layout = false ) {
global $frontend_debug , $_cecRegistry ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$debug = 0 ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( $debug )
echo " conGenerateCode( $idcat , $idart , $lang , $client , $layout );<br> " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
global $db , $db2 , $sess , $cfg , $code , $cfgClient , $client , $lang , $encoding ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( ! is_object ( $db2 ))
$db2 = new DB_ConLite ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
/* extract IDCATART */
$sql = " SELECT
2016-10-06 15:57:01 +00:00
idcatart
FROM
2019-10-25 16:00:47 +00:00
" . $cfg["tab"] [ " cat_art " ] . "
2016-10-06 15:57:01 +00:00
WHERE
2019-10-25 16:00:47 +00:00
idcat = '" . Contenido_Security::toInteger($idcat) . "' AND
idart = '" . Contenido_Security::toInteger($idart) . "' " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
$db -> next_record ();
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$idcatart = $db -> f ( " idcatart " );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
/* If neither the
article or the category is
configured , no code will be
created and an error occurs . */
$sql = " SELECT
2016-10-06 15:57:01 +00:00
a . idtplcfg AS idtplcfg
FROM
2019-10-25 16:00:47 +00:00
" . $cfg["tab"] [ " art_lang " ] . " AS a ,
" . $cfg["tab"] [ " art " ] . " AS b
2016-10-06 15:57:01 +00:00
WHERE
2019-10-25 16:00:47 +00:00
a . idart = '" . Contenido_Security::toInteger($idart) . "' AND
a . idlang = '" . Contenido_Security::escapeDB($lang, $db) . "' AND
2016-10-06 15:57:01 +00:00
b . idart = a . idart AND
2019-10-25 16:00:47 +00:00
b . idclient = '" . Contenido_Security::escapeDB($client, $db) . "' " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
$db -> next_record ();
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( $db -> f ( " idtplcfg " ) != 0 ) {
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
/* Article is configured */
$idtplcfg = $db -> f ( " idtplcfg " );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( $debug )
echo " configuration for article found: $idtplcfg <br><br> " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$a_c = array ();
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$sql2 = " SELECT
2016-10-06 15:57:01 +00:00
*
FROM
2019-10-25 16:00:47 +00:00
" . $cfg["tab"] [ " container_conf " ] . "
2016-10-06 15:57:01 +00:00
WHERE
2019-10-25 16:00:47 +00:00
idtplcfg = '" . Contenido_Security::toInteger($idtplcfg) . "'
2016-10-06 15:57:01 +00:00
ORDER BY
number ASC " ;
2019-10-25 16:00:47 +00:00
$db2 -> query ( $sql2 );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
while ( $db2 -> next_record ()) {
$a_c [ $db2 -> f ( " number " )] = $db2 -> f ( " container " );
}
} else {
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
/* Check whether category is
configured . */
$sql = " SELECT
2016-10-06 15:57:01 +00:00
a . idtplcfg AS idtplcfg
FROM
2019-10-25 16:00:47 +00:00
" . $cfg["tab"] [ " cat_lang " ] . " AS a ,
" . $cfg["tab"] [ " cat " ] . " AS b
2016-10-06 15:57:01 +00:00
WHERE
2019-10-25 16:00:47 +00:00
a . idcat = '" . Contenido_Security::toInteger($idcat) . "' AND
a . idlang = '" . Contenido_Security::escapeDB($lang, $db) . "' AND
2016-10-06 15:57:01 +00:00
b . idcat = a . idcat AND
2019-10-25 16:00:47 +00:00
b . idclient = '" . Contenido_Security::escapeDB($client, $db) . "' " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
$db -> next_record ();
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( $db -> f ( " idtplcfg " ) != 0 ) {
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
/* Category is configured ,
extract varstring */
$idtplcfg = $db -> f ( " idtplcfg " );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( $debug )
echo " configuration for category found: $idtplcfg <br><br> " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$a_c = array ();
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$sql2 = " SELECT
2016-10-06 15:57:01 +00:00
*
FROM
2019-10-25 16:00:47 +00:00
" . $cfg["tab"] [ " container_conf " ] . "
2016-10-06 15:57:01 +00:00
WHERE
2019-10-25 16:00:47 +00:00
idtplcfg = '" . Contenido_Security::toInteger($idtplcfg) . "'
2016-10-06 15:57:01 +00:00
ORDER BY
number ASC " ;
2019-10-25 16:00:47 +00:00
$db2 -> query ( $sql2 );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
while ( $db2 -> next_record ()) {
$a_c [ $db2 -> f ( " number " )] = $db2 -> f ( " container " );
}
} else {
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
/* Article nor Category
is configured . Creation of
Code is not possible . Write
Errormsg to DB . */
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( $debug )
echo " Neither CAT or ART are configured!<br><br> " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$code = '<html><body>No code was created for this art in this category.</body><html>' ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$sql = " SELECT * FROM " . $cfg [ " tab " ][ " code " ] . " WHERE idcatart=' " . Contenido_Security :: toInteger ( $idcatart ) . " ' AND idlang=' " . Contenido_Security :: escapeDB ( $lang , $db ) . " ' " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( $db -> next_record ()) {
$sql = " UPDATE " . $cfg [ " tab " ][ " code " ] . " SET code=' " . Contenido_Security :: escapeDB ( $code , $db ) . " ', idlang=' " . Contenido_Security :: escapeDB ( $lang , $db ) . " ', idclient=' " . Contenido_Security :: escapeDB ( $client , $db ) . " '
WHERE idcatart = '" . Contenido_Security::toInteger($idcatart) . "' AND idlang = '" . Contenido_Security::escapeDB($lang, $db) . "' " ;
$db -> query ( $sql );
} else {
$sql = " INSERT INTO " . $cfg [ " tab " ][ " code " ] . " (idcode, idcatart, code, idlang, idclient) VALUES (' " . Contenido_Security :: toInteger ( $db -> nextid ( $cfg [ " tab " ][ " code " ])) . " ', ' " . Contenido_Security :: toInteger ( $idcatart ) . " ',
'" . Contenido_Security::escapeDB($code, $db) . "' , '" . Contenido_Security::escapeDB($lang, $db) . "' , '" . Contenido_Security::escapeDB($client, $db) . "' ) " ;
$db -> query ( $sql );
}
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
return " 0601 " ;
}
}
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
/* Get IDLAY and IDMOD array */
$sql = " SELECT
2016-10-06 15:57:01 +00:00
a . idlay AS idlay ,
a . idtpl AS idtpl
FROM
2019-10-25 16:00:47 +00:00
" . $cfg["tab"] [ " tpl " ] . " AS a ,
" . $cfg["tab"] [ " tpl_conf " ] . " AS b
2016-10-06 15:57:01 +00:00
WHERE
2019-10-25 16:00:47 +00:00
b . idtplcfg = '" . Contenido_Security::toInteger($idtplcfg) . "' AND
2016-10-06 15:57:01 +00:00
b . idtpl = a . idtpl " ;
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
$db -> next_record ();
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$idlay = $db -> f ( " idlay " );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( $layout != false ) {
$idlay = $layout ;
}
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$idtpl = $db -> f ( " idtpl " );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( $debug )
echo " Using Layout: $idlay and Template: $idtpl for generation of code.<br><br> " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
/* List of used modules */
$sql = " SELECT
2016-10-06 15:57:01 +00:00
number ,
idmod
FROM
2019-10-25 16:00:47 +00:00
" . $cfg["tab"] [ " container " ] . "
2016-10-06 15:57:01 +00:00
WHERE
2019-10-25 16:00:47 +00:00
idtpl = '" . Contenido_Security::toInteger($idtpl) . "'
2016-10-06 15:57:01 +00:00
ORDER BY
number ASC " ;
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
while ( $db -> next_record ()) {
$a_d [ $db -> f ( " number " )] = $db -> f ( " idmod " );
}
$oLayout = new cApiLayout ( Contenido_Security :: toInteger ( $idlay ));
$raw_code = $oLayout -> getLayout ();
$code = AddSlashes ( $raw_code );
/* Create code for all containers */
if ( $idlay ) {
tplPreparseLayout ( $idlay , $raw_code );
$tmp_returnstring = tplBrowseLayoutForContainers ( $idlay , $raw_code );
$a_container = explode ( " & " , $tmp_returnstring );
foreach ( $a_container as $key => $value ) {
2020-02-15 12:48:23 +00:00
$sql = " SELECT output, template, name FROM " . $cfg [ " tab " ][ " mod " ] . " WHERE idmod=' " . $a_d [ $value ] . " ' " ;
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
$db -> next_record ();
if ( is_numeric ( $a_d [ $value ])) {
$thisModule = '<?php $cCurrentModule = ' . (( int ) $a_d [ $value ]) . '; ?>' ;
$thisContainer = '<?php $cCurrentContainer = ' . (( int ) $value ) . '; ?>' ;
}
/* dceModFileEdit (c)2009 www.dceonline.de */
if ( $cfg [ 'dceModEdit' ][ 'use' ]
&& ( $cfg [ 'dceModEdit' ][ 'allModsFromFile' ] == true
|| in_array (( int ) $a_d [ $value ], $cfg [ 'dceModEdit' ][ 'modsFromFile' ]))) {
cInclude ( 'classes' , 'contenido/class.module.php' );
2016-10-06 15:57:01 +00:00
$tmpModule = new cApiModule ;
$tmpModule -> loadByPrimaryKey ( $a_d [ $value ]);
2019-10-25 16:00:47 +00:00
$output = $thisModule . $thisContainer . $tmpModule -> get ( " output " );
2016-10-06 15:57:01 +00:00
unset ( $tmpModule );
} else {
2019-10-25 16:00:47 +00:00
$output = $thisModule . $thisContainer . $db -> f ( " output " );
2016-10-06 15:57:01 +00:00
}
/* dceModFileEdit (c)2009 www.dceonline.de */
2019-10-25 16:00:47 +00:00
$output = AddSlashes ( $output ) . " \n " ;
$template = $db -> f ( " template " );
$a_c [ $value ] = preg_replace ( " /(& \$ )/ " , " " , $a_c [ $value ]);
$tmp1 = preg_split ( " /&/ " , $a_c [ $value ]);
$varstring = array ();
foreach ( $tmp1 as $key1 => $value1 ) {
$tmp2 = explode ( " = " , $value1 );
foreach ( $tmp2 as $key2 => $value2 ) {
$varstring [ " $tmp2[0] " ] = $tmp2 [ 1 ];
}
}
$CiCMS_Var = '$C' . $value . 'CMS_VALUE' ;
$CiCMS_VALUE = '' ;
foreach ( $varstring as $key3 => $value3 ) {
$tmp = urldecode ( $value3 );
$tmp = str_replace ( " \ ' " , " ' " , $tmp );
$CiCMS_VALUE .= $CiCMS_Var . '[' . $key3 . ']="' . $tmp . '"; ' ;
$output = str_replace ( " \$ CMS_VALUE[ $key3 ] " , $tmp , $output );
$output = str_replace ( " CMS_VALUE[ $key3 ] " , $tmp , $output );
}
$output = str_replace ( " CMS_VALUE " , $CiCMS_Var , $output );
$output = str_replace ( " \$ " . $CiCMS_Var , $CiCMS_Var , $output );
$output = preg_replace ( " /(CMS_VALUE \ [)([0-9]*)( \ ])/i " , " " , $output );
if ( $frontend_debug [ " container_display " ] == true ) {
$fedebug .= " Container: CMS_CONTAINER[ $value ] " . '\\\\n' ;
}
if ( $frontend_debug [ " module_display " ] == true ) {
$fedebug .= " Modul: " . $db -> f ( " name " ) . '\\\\n' ;
}
if ( $frontend_debug [ " module_timing_summary " ] == true || $frontend_debug [ " module_timing " ] == true ) {
$fedebug .= 'Eval-Time: $modtime' . $value . '\\\\n' ;
$output = '<?php $modstart' . $value . ' = getmicrotime(); ?' . '>' . $output . '<?php $modend' . $value . ' = getmicrotime()+0.001; $modtime' . $value . ' = $modend' . $value . ' - $modstart' . $value . '; ?' . '>' ;
}
if ( $fedebug != " " ) {
$output = addslashes ( '<?php echo \'<img onclick="javascript:showmod' . $value . '();" src="' . $cfg [ 'path' ][ 'contenido_fullhtml' ] . 'images/but_preview.gif">\'; ?' . '>' . " <br> " ) . $output ;
$output = $output . addslashes ( '<?php echo \'<script language="javascript">function showmod' . $value . ' () { window.alert(\\\'\'. "' . addslashes ( $fedebug ) . '".\'\\\');} </script>\'; ?' . '>' );
}
if ( $frontend_debug [ " module_timing_summary " ] == true ) {
$output .= addslashes ( ' <?php $cModuleTimes["' . $value . '"] = $modtime' . $value . '; ?>' );
$output .= addslashes ( ' <?php $cModuleNames["' . $value . '"] = "' . addslashes ( $db -> f ( " name " )) . '"; ?>' );
}
/* Replace new containers */
$code = preg_replace ( " /<container( +)id= \\ \\ \" $value\\\\\ " ( .* ) > ( .* ) < \ / container >/ Uis " , " CMS_CONTAINER [ $value ] " , $code );
$code = preg_replace ( " /<container( +)id= \\ \\ \" $value\\\\\ " ( .* ) \ />/ i " , " CMS_CONTAINER [ $value ] " , $code );
$code = str_ireplace ( " CMS_CONTAINER[ $value ] " , " <?php $CiCMS_VALUE ?> \r \n " . $output , $code );
$fedebug = " " ;
}
}
/* Find out what kind of CMS_... Vars are in use */
$sql = " SELECT
2016-10-06 15:57:01 +00:00
*
FROM
2019-10-25 16:00:47 +00:00
" . $cfg["tab"] [ " content " ] . " AS A ,
" . $cfg["tab"] [ " art_lang " ] . " AS B ,
" . $cfg["tab"] [ " type " ] . " AS C
2016-10-06 15:57:01 +00:00
WHERE
A . idtype = C . idtype AND
A . idartlang = B . idartlang AND
2019-10-25 16:00:47 +00:00
B . idart = '" . Contenido_Security::toInteger($idart) . "' AND
B . idlang = '" . Contenido_Security::escapeDB($lang, $db) . "' " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
while ( $db -> next_record ()) {
$a_content [ $db -> f ( " type " )][ $db -> f ( " typeid " )] = $db -> f ( " value " );
}
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$sql = " SELECT idartlang, pagetitle FROM " . $cfg [ " tab " ][ " art_lang " ] . " WHERE idart=' " . Contenido_Security :: toInteger ( $idart ) . " ' AND idlang=' " . Contenido_Security :: escapeDB ( $lang , $db ) . " ' " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
$db -> next_record ();
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$idartlang = $db -> f ( " idartlang " );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$pagetitle = stripslashes ( $db -> f ( " pagetitle " ));
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( $pagetitle == '' ) {
2016-10-06 15:57:01 +00:00
CEC_Hook :: setDefaultReturnValue ( $pagetitle );
$pagetitle = CEC_Hook :: executeAndReturn ( 'Contenido.Content.CreateTitletag' );
2019-10-25 16:00:47 +00:00
}
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
/* replace all CMS_TAGS[] */
$sql = " SELECT type, code FROM " . $cfg [ " tab " ][ " type " ];
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$match = array ();
while ( $db -> next_record ()) {
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$tmp = preg_match_all ( " /( " . $db -> f ( " type " ) . " \ [+ \ d+ \ ])/i " , $code , $match );
$a_ [ strtolower ( $db -> f ( " type " ))] = $match [ 0 ];
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$success = array_walk ( $a_ [ strtolower ( $db -> f ( " type " ))], 'extractNumber' );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$search = array ();
$replacements = array ();
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
foreach ( $a_ [ strtolower ( $db -> f ( " type " ))] as $val ) {
eval ( $db -> f ( " code " ));
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$search [ $val ] = $db -> f ( " type " ) . " [ $val ] " ;
$replacements [ $val ] = $tmp ;
$keycode [ $db -> f ( " type " )][ $val ] = $tmp ;
}
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$code = str_ireplace ( $search , $replacements , $code );
}
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
/* add/replace title */
if ( $pagetitle != " " ) {
$code = preg_replace ( " /<title>.*?< \ /title>/is " , " { TITLE} " , $code , 1 );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( strstr ( $code , " { TITLE} " )) {
$code = str_ireplace ( " { TITLE} " , addslashes ( " <title> $pagetitle </title> " ), $code );
} else {
$code = str_ireplace_once ( " </head> " , addslashes ( " <title> " . $pagetitle . " </title> \n </head> " ), $code );
}
} else {
$code = str_replace ( '<title></title>' , '' , $code );
}
2016-10-06 15:57:01 +00:00
// metatags
$availableTags = conGetAvailableMetaTagTypes ();
2019-10-25 16:00:47 +00:00
$metatags = array ();
2016-10-06 15:57:01 +00:00
foreach ( $availableTags as $key => $value ) {
$metavalue = conGetMetaValue ( $idartlang , $key );
if ( strlen ( $metavalue ) > 0 ) {
//$metatags[$value["name"]] = array(array("attribute" => $value["fieldname"], "value" => $metavalue), ...);
2019-10-25 16:00:47 +00:00
$metatags [] = array ( $value [ " fieldname " ] => $value [ " name " ], 'content' => $metavalue );
2016-10-06 15:57:01 +00:00
}
}
2019-10-25 16:00:47 +00:00
2016-10-06 15:57:01 +00:00
// generator tag
$aVersion = explode ( '.' , $cfg [ 'version' ]);
$sCLVersion = $aVersion [ 0 ] . '.' . $aVersion [ 1 ];
2019-10-25 16:00:47 +00:00
$metatags [] = array ( 'name' => 'generator' , 'content' => 'CMS ConLite ' . $sCLVersion );
2016-10-06 15:57:01 +00:00
// charset/encoding tag
2019-10-25 16:00:47 +00:00
if ( getEffectiveSetting ( 'generator' , 'html5' , " false " ) == " true " ) {
2016-10-06 15:57:01 +00:00
$metatags [] = array ( 'charset' => $encoding [ $lang ]);
2019-10-25 16:00:47 +00:00
} else if ( getEffectiveSetting ( 'generator' , 'xhtml' , " false " ) == " true " ) {
$metatags [] = array ( 'http-equiv' => 'Content-Type' , 'content' => 'application/xhtml+xml; charset=' . $encoding [ $lang ]);
2016-10-06 15:57:01 +00:00
} else {
2019-10-25 16:00:47 +00:00
$metatags [] = array ( 'http-equiv' => 'Content-Type' , 'content' => 'text/html; charset=' . $encoding [ $lang ]);
2016-10-06 15:57:01 +00:00
}
2019-10-25 16:00:47 +00:00
2016-10-06 15:57:01 +00:00
// check chains
$_cecIterator = $_cecRegistry -> getIterator ( " Contenido.Content.CreateMetatags " );
2019-10-25 16:00:47 +00:00
if ( $_cecIterator -> count () > 0 ) {
2016-10-06 15:57:01 +00:00
$tmpMetatags = $metatags ;
2019-10-25 16:00:47 +00:00
if ( ! is_array ( $tmpMetatags )) {
2016-10-06 15:57:01 +00:00
$tmpMetatags = array ();
}
2019-10-25 16:00:47 +00:00
while ( $chainEntry = $_cecIterator -> next ()) {
2016-10-06 15:57:01 +00:00
$tmpMetatags = $chainEntry -> execute ( $tmpMetatags );
}
2019-10-25 16:00:47 +00:00
2016-10-06 15:57:01 +00:00
//added 2008-06-25 Timo Trautmann
//system metatags were merged to user meta tags
//and user meta tags were not longer replaced by system meta tags
/** @todo recode whole meta tag handling */
2019-10-25 16:00:47 +00:00
if ( is_array ( $tmpMetatags )) {
2016-10-06 15:57:01 +00:00
//check for all system meta tags if there is already a user meta tag
foreach ( $tmpMetatags as $aAutValue ) {
$bExists = false ;
//get name of meta tag for search
$sSearch = '' ;
if ( array_key_exists ( 'name' , $aAutValue )) {
$sSearch = $aAutValue [ 'name' ];
} else if ( array_key_exists ( 'http-equiv' , $aAutValue )) {
$sSearch = $aAutValue [ 'http-equiv' ];
}
//check if meta tag is already in list of user meta tags
if ( strlen ( $sSearch ) > 0 ) {
foreach ( $metatags as $aValue ) {
if ( array_key_exists ( 'name' , $aValue )) {
if ( $sSearch == $aValue [ 'name' ]) {
$bExists = true ;
break ;
}
} else if ( array_key_exists ( 'http-equiv' , $aAutValue )) {
if ( $sSearch == $aValue [ 'http-equiv' ]) {
$bExists = true ;
break ;
}
}
}
}
//add system meta tag if there is no user meta tag
if ( $bExists == false && strlen ( $aAutValue [ 'content' ]) > 0 ) {
array_push ( $metatags , $aAutValue );
}
}
}
2019-10-25 16:00:47 +00:00
}
$sMetatags = '' ;
foreach ( $metatags as $value ) {
if ( getEffectiveSetting ( 'generator' , 'html5' , " false " ) == " true " ) {
if ( $value [ 'name' ] == 'date' )
continue ;
}
if ( ! empty ( $value [ 'content' ])) {
$value [ 'content' ] = clHtmlEntityDecode ( $value [ 'content' ], ENT_QUOTES , strtoupper ( $encoding [ $lang ]));
$value [ 'content' ] = htmlspecialchars_decode ( $value [ 'content' ], ENT_QUOTES );
}
// build up metatag string
$oMetaTagGen = new cHTML5Meta ();
$oMetaTagGen -> updateAttributes ( $value );
/* HTML does not allow ID for meta tags */
$oMetaTagGen -> removeAttribute ( " id " );
/* Check if metatag already exists */
if ( preg_match ( '/(<meta(?:\s+)name(?:\s*)=(?:\s*)(?:\\\\"|\\\\\')(?:\s*)' . $value [ " name " ] . '(?:\s*)(?:\\\\"|\\\\\')(?:[^>]+)>\r?\n?)/i' , $code , $aTmetatagfound )) {
$code = str_replace ( $aTmetatagfound [ 1 ], $oMetaTagGen -> render () . " \n " , $code );
} else if ( array_key_exists ( " charset " , $value )
&& preg_match ( '/(<meta(?:\s+)charset(?:\s*)=(?:\s*)(?:\\\\"|\\\\\')(?:\s*)(.*)(?:\s*)(?:\\\\"|\\\\\')(?:\s*)(?:\s*|\/)(?:[\^\>]+)\r?\n?)/i' , $code , $aTmetatagfound )) {
$code = str_replace ( $aTmetatagfound [ 1 ], $oMetaTagGen -> render () . " \n " , $code );
2016-10-06 15:57:01 +00:00
} else {
2019-10-25 16:00:47 +00:00
$sMetatags .= $oMetaTagGen -> render () . " \n " ;
2016-10-06 15:57:01 +00:00
}
2019-10-25 16:00:47 +00:00
}
/* Add meta tags */
$code = str_ireplace_once ( " </head> " , $sMetatags . " </head> " , $code );
$code = str_ireplace_once ( " </html> " , " <!-- This website is powered by ConLite, the lightweight content management system. \n For more info and download visit www.conlite.org --> \n </html> " , $code );
/* write code into the database */
$date = date ( " Y-m-d H:i:s " );
if ( $layout == false ) {
$sql = " SELECT * FROM " . $cfg [ " tab " ][ " code " ] . " WHERE idcatart = ' " . Contenido_Security :: toInteger ( $idcatart ) . " ' AND idlang = ' " . Contenido_Security :: escapeDB ( $lang , $db ) . " ' " ;
$db -> query ( $sql );
if ( $db -> next_record ()) {
if ( $debug )
echo " UPDATED code for lang: $lang , client: $client , idcatart: $idcatart " ;
$sql = " UPDATE " . $cfg [ " tab " ][ " code " ] . " SET code=' " . Contenido_Security :: escapeDB ( $code , $db , false ) . " ', idlang=' " . Contenido_Security :: escapeDB ( $lang , $db ) . " ', idclient=' " . Contenido_Security :: escapeDB ( $client , $db ) . " '
WHERE idcatart = '" . Contenido_Security::toInteger($idcatart) . "' AND idlang = '" . Contenido_Security::escapeDB($lang, $db) . "' " ;
$db -> query ( $sql );
} else {
if ( $debug )
echo " INSERTED code for lang: $lang , client: $client , idcatart: $idcatart " ;
$sql = " INSERT INTO " . $cfg [ " tab " ][ " code " ] . " (idcode, idcatart, code, idlang, idclient) VALUES (' " . Contenido_Security :: toInteger ( $db -> nextid ( $cfg [ " tab " ][ " code " ])) . " ', ' " . Contenido_Security :: toInteger ( $idcatart ) . " ',
'" . Contenido_Security::escapeDB($code, $db, false) . "' , '" . Contenido_Security::escapeDB($lang, $db) . "' , '" . Contenido_Security::escapeDB($client, $db) . "' ) " ;
$db -> query ( $sql );
}
$sql = " UPDATE " . $cfg [ " tab " ][ " cat_art " ] . " SET createcode = '0' WHERE idcatart=' " . Contenido_Security :: toInteger ( $idcatart ) . " ' " ;
$db -> query ( $sql );
}
2016-10-06 15:57:01 +00:00
// execute CEC hook
$code = CEC_Hook :: executeAndReturn ( 'Contenido.Content.conGenerateCode' , $code );
2019-10-25 16:00:47 +00:00
return $code ;
2016-10-06 15:57:01 +00:00
}
/**
* Returns the idartlang for a given article and language
*
* @ deprecated since version 2.0 , use renamed conGetArtLang instead
* @ param $idart ID of the article
* @ param $idlang ID of the language
* @ return mixed idartlang of the article or false if nothing was found
*/
function getArtLang ( $idart , $idlang ) {
return conGetArtLang ( $idart , $idlang );
}
/**
* Returns the idartlang for a given article and language
*
* @ param $idart ID of the article
* @ param $idlang ID of the language
* @ return mixed idartlang of the article or false if nothing was found
*/
function conGetArtLang ( $iIdart , $iIdlang ) {
$oArtLangs = new cApiArticleLanguageCollection ();
$iRet = $oArtLangs -> getIdArtLang ( $iIdart , $iIdlang );
unset ( $oArtLangs ); // save mem
return $iRet ;
}
/**
* Returns all available meta tag types
*
* @ return array Array with available meta types
*/
function conGetAvailableMetaTagTypes () {
$oMetaTypes = new cApiMetaTypeCollection ();
$aRet = $oMetaTypes -> getAvailableMetaTypes ();
unset ( $oMetaTypes ); // save mem
return $aRet ;
}
/**
* Get the meta tag value for a specific article
*
* @ param int $idartlang
* @ param int $idmetatype
* @ return string tag value or empty string
*/
function conGetMetaValue ( $idartlang , $idmetatype ) {
2019-10-25 16:00:47 +00:00
if ( $idartlang == 0 )
return ;
2016-10-06 15:57:01 +00:00
$oMetaTags = new cApiMetaTagCollection ();
$oMetaTags -> setWhere ( 'idartlang' , Contenido_Security :: toInteger ( $idartlang ));
$oMetaTags -> setWhere ( 'idmetatype' , Contenido_Security :: toInteger ( $idmetatype ));
$oMetaTags -> query ();
2019-10-25 16:00:47 +00:00
if ( $oMetaTags -> count () > 0 ) {
2016-10-06 15:57:01 +00:00
$sRet = $oMetaTags -> next () -> get ( 'metavalue' );
} else {
$sRet = " " ;
}
unset ( $oMetaTags ); // save mem
return $sRet ;
}
/**
* Set the meta tag value for a specific article
*
* @ param $idartlang ID of the article
* @ param $idmetatype Metatype - ID
* @ param $value Value of the meta tag
*
* @ author Timo A . Hummel < Timo . Hummel @ 4 fb . de >
* @ copyright four for business AG 2003
*/
2019-10-25 16:00:47 +00:00
function conSetMetaValue ( $idartlang , $idmetatype , $value ) {
global $cfg ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$db = new DB_ConLite ;
$sql = " DELETE FROM " . $cfg [ " tab " ][ " meta_tag " ] . "
WHERE idartlang = '" . Contenido_Security::toInteger($idartlang) . "'
AND idmetatype = '" . Contenido_Security::toInteger($idmetatype) . "' " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$nextid = $db -> nextid ( $cfg [ " tab " ][ " meta_tag " ]);
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$sql = " INSERT INTO " . $cfg [ " tab " ][ " meta_tag " ] . " SET idartlang = ' " . Contenido_Security :: toInteger ( $idartlang ) . " ',
idmetatype = '" . Contenido_Security::toInteger($idmetatype) . "' ,
idmetatag = '" . Contenido_Security::toInteger($nextid) . "' ,
metavalue = '" . Contenido_Security::escapeDB($value, $db) . "' " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
}
2019-10-25 16:00:47 +00:00
/**
2016-10-06 15:57:01 +00:00
* ( re ) generate keywords for all articles of a given client ( with specified language )
* @ param $client Client
* @ param $lang Language of a client
* @ return void
*
* @ author Willi Man
* Created : 12.05 . 2004
* Modified : 13.05 . 2004
* @ copyright four for business AG 2003
*/
2019-10-25 16:00:47 +00:00
function conGenerateKeywords ( $client , $lang ) {
global $cfg ;
$db_art = new DB_ConLite ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$options = array ( " img " , " link " , " linktarget " , " swf " ); // cms types to be excluded from indexing
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$sql = " SELECT
2016-10-06 15:57:01 +00:00
a . idart , b . idartlang
FROM
2019-10-25 16:00:47 +00:00
" . $cfg["tab"] [ " art " ] . " AS a ,
" . $cfg["tab"] [ " art_lang " ] . " AS b
2016-10-06 15:57:01 +00:00
WHERE
a . idart = b . idart AND
2019-10-25 16:00:47 +00:00
a . idclient = " . Contenido_Security::escapeDB( $client , $db ) . " AND
b . idlang = " . Contenido_Security::escapeDB( $lang , $db );
$db_art -> query ( $sql );
$articles = array ();
while ( $db_art -> next_record ()) {
$articles [ $db_art -> f ( " idart " )] = $db_art -> f ( " idartlang " );
}
if ( count ( $articles ) > 0 ) {
foreach ( $articles as $artid => $article_lang ) {
$article_content = array ();
$article_content = conGetContentFromArticle ( $article_lang );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
if ( count ( $article_content ) > 0 ) {
$art_index = new Index ( $db_art );
$art_index -> lang = $lang ;
$art_index -> start ( $artid , $article_content , 'auto' , $options );
}
}
}
2016-10-06 15:57:01 +00:00
}
2019-10-25 16:00:47 +00:00
/**
2016-10-06 15:57:01 +00:00
* get content from article
* @ param $article_lang ArticleLanguageId of an article ( idartlang )
* @ return array Array with content of an article indexed by content - types
*
* @ author Willi Man
* Created : 12.05 . 2004
* Modified : 13.05 . 2004
* @ copyright four for business AG 2003
*/
2019-10-25 16:00:47 +00:00
function conGetContentFromArticle ( $article_lang ) {
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
global $cfg ;
$db_con = new DB_ConLite ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$sql = " SELECT
2016-10-06 15:57:01 +00:00
*
FROM
2019-10-25 16:00:47 +00:00
" . $cfg["tab"] [ " content " ] . " AS A ,
" . $cfg["tab"] [ " art_lang " ] . " AS B ,
" . $cfg["tab"] [ " type " ] . " AS C
2016-10-06 15:57:01 +00:00
WHERE
A . idtype = C . idtype AND
A . idartlang = B . idartlang AND
2019-10-25 16:00:47 +00:00
A . idartlang = '" . Contenido_Security::escapeDB($article_lang, $db_con) . "' " ;
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
$db_con -> query ( $sql );
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
while ( $db_con -> next_record ()) {
$a_content [ $db_con -> f ( " type " )][ $db_con -> f ( " typeid " )] = urldecode ( $db_con -> f ( " value " ));
}
2016-10-06 15:57:01 +00:00
2019-10-25 16:00:47 +00:00
return $a_content ;
2016-10-06 15:57:01 +00:00
}
2019-10-25 16:00:47 +00:00
2016-10-06 15:57:01 +00:00
?>