*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
]*src=")(medias\/)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
//
]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
//
]*src=")(\/?viewimage\.php)/', '\1'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
// action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
$content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
// Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart="
$content=preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
$content=preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
dol_syslog('dolWebsiteReplacementOfLinks end', LOG_DEBUG);
return $content;
}
/**
* Remove PHP code part from a string.
*
* @param string $str String to clean
* @param string $replacewith String to use as replacement
* @return string Result string without php code
* @see dolKeepOnlyPhpCode()
*/
function dolStripPhpCode($str, $replacewith = '')
{
$newstr = '';
//split on each opening tag
$parts = explode('', $part);
if (!empty($partlings))
{
//remove content before closing tag
if (count($partlings) > 1) $partlings[0] = '';
//append to out string
$newstr .= $replacewith.implode('', $partlings);
}
}
}
return $newstr;
}
/**
* Keep only PHP code part from a HTML string page.
*
* @param string $str String to clean
* @return string Result string with php code only
* @see dolStripPhpCode()
*/
function dolKeepOnlyPhpCode($str)
{
$newstr = '';
//split on each opening tag
$parts = explode('', $part, 2);
if (!empty($partlings))
{
$newstr .= $partlings[0].'?>';
}
else
{
$newstr .= $part.'?>';
}
}
}
return $newstr;
}
/**
* Render a string of an HTML content and output it.
* Used to ouput the page when viewed from server (Dolibarr or Apache).
*
* @param string $content Content string
* @param string $contenttype Content type
* @return void
* @see dolWebsiteReplacementOfLinks() for function used to replace content in the backoffice context when USEDOLIBARREDITOR is not on
*/
function dolWebsiteOutput($content, $contenttype='html')
{
global $db, $langs, $conf, $user;
global $dolibarr_main_url_root, $dolibarr_main_data_root;
dol_syslog("dolWebsiteOutput start (contenttype=".$contenttype." USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER')?'1':'')." USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR')?'1':'').')');
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor
{
// We remove the
]*src=")(medias\/)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
//
]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
//
]*src=")(\/?viewimage\.php)/', '\1'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
// action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
$content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
}
else // REPLACEMENT OF LINKS When page called from virtual host
{
$symlinktomediaexists=1;
// Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server
//
// become
//
$nbrep=0;
if (! $symlinktomediaexists)
{
$content=preg_replace('/('."\n";
}
elseif ($type == 'blogpost')
{
if ($websitepage->fk_user_creat > 0)
{
include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$tmpuser = new User($db);
$restmpuser = $tmpuser->fetch($websitepage->fk_user_creat);
if ($restmpuser > 0)
{
$ret = ''."\n";
$ret .= ''."\n";
}
}
}
elseif ($type == 'product')
{
$ret = ''."\n";
$ret.= ''."\n";
}
return $ret;
}
/**
* Return list of containers object that match a criteria
*
* @param string $type Type of container to search into (Example: 'page')
* @param string $algo Algorithm used for search (Example: 'meta' is searching into meta information like title and description, 'metacontent')
* @param string $searchstring Search string
* @param int $max Max number of answers
* @return string HTML content
*/
function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25)
{
global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers.
$error = 0;
$arrayresult = array('code'=>'', 'list'=>array());
if (! is_object($weblangs)) $weblangs = $langs;
if (empty($searchstring))
{
$error++;
$arrayresult['code']='KO';
$arrayresult['message']=$weblangs->trans("EmptySearchString");
}
elseif (dol_strlen($searchstring) < 2)
{
$weblangs->load("errors");
$error++;
$arrayresult['code']='KO';
$arrayresult['message']=$weblangs->trans("ErrorSearchCriteriaTooSmall");
}
elseif (! in_array($type, array('', 'page')))
{
$error++;
$arrayresult['code']='KO';
$arrayresult['message']='Bad value for parameter $type';
}
$searchdone = 0;
if (! $error && in_array($algo, array('meta', 'metacontent', 'content')))
{
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'website_page';
$sql.= " WHERE fk_website = ".$website->id;
if ($type) $sql.= " AND type_container = '".$db->escape($type)."'";
$sql.= " AND (";
$searchalgo = '';
if ($algo == 'meta' || $algo == 'metacontent')
{
$searchalgo.= ($searchalgo?' OR ':'')."title LIKE '%".$db->escape($searchstring)."%' OR description LIKE '%".$db->escape($searchstring)."%'";
$searchalgo.= ($searchalgo?' OR ':'')."keywords LIKE '".$db->escape($searchstring).",%' OR keywords LIKE '% ".$db->escape($searchstring)."%'"; // TODO Use a better way to scan keywords
}
if ($algo == 'metacontent' || $algo == 'content')
{
$searchalgo.= ($searchalgo?' OR ':'')."content LIKE '%".$db->escape($searchstring)."%'";
}
$sql.=$searchalgo;
$sql.= ")";
$sql.= $db->plimit($max);
$resql = $db->query($sql);
if ($resql)
{
$i = 0;
while (($obj = $db->fetch_object($resql)) && ($i < $max || $max == 0))
{
if ($obj->rowid > 0)
{
$tmpwebsitepage = new WebsitePage($db);
$tmpwebsitepage->fetch($obj->rowid);
if ($tmpwebsitepage->id > 0) $arrayresult['list'][]=$tmpwebsitepage;
}
$i++;
}
$arrayresult['code']='OK';
if (empty($arrayresult['list']))
{
$arrayresult['code']='KO';
$arrayresult['message']=$weblangs->trans("NoRecordFound");
}
}
else
{
$error++;
$arrayresult['code']=$db->lasterrno();
$arrayresult['message']=$db->lasterror();
}
$searchdone = 1;
}
if (! $searchdone)
{
$error++;
$arrayresult['code']='KO';
$arrayresult['message']='No supported algorithm found';
}
return $arrayresult;
}
/**
* Download all images found into page content $tmp.
* If $modifylinks is set, links to images will be replace with a link to viewimage wrapper.
*
* @param Website $object Object website
* @param WebsitePage $objectpage Object website page
* @param string $urltograb URL to grab (exemple: http://www.nltechno.com/ or http://www.nltechno.com/dir1/ or http://www.nltechno.com/dir1/mapage1)
* @param string $tmp Content to parse
* @param string $action Var $action
* @param string $modifylinks 0=Do not modify content, 1=Replace links with a link to viewimage
* @param int $grabimages 0=Do not grab images, 1=Grab images
* @param string $grabimagesinto 'root' or 'subpage'
* @return void
*/
function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks = 0, $grabimages = 1, $grabimagesinto = 'subpage')
{
global $conf;
$error=0;
dol_syslog("Call getAllImages with grabimagesinto=".$grabimagesinto);
$alreadygrabbed=array();
if (preg_match('/\/$/', $urltograb)) $urltograb.='.';
$urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1
// Search X in "img...src=X"
preg_match_all('/