dolibarr 21.0.0-alpha
website.lib.php File Reference

Library for website module. More...

Go to the source code of this file.

Functions

 dolStripPhpCode ($str, $replacewith='')
 Remove PHP code part from a string.
 
 dolKeepOnlyPhpCode ($str)
 Keep only PHP code part from a HTML string page.
 
 dolWebsiteReplacementOfLinks ($website, $content, $removephppart=0, $contenttype='html', $containerid=0)
 Convert a page content to have correct links (based on DOL_URL_ROOT) into an html content.
 
 dolReplaceSmileyCodeWithUTF8 ($content)
 Converts smiley string into the utf8 sequence.
 
 dolWebsiteOutput ($content, $contenttype='html', $containerid=0)
 Render a string of an HTML content and output it.
 
 dolWebsiteIncrementCounter ($websiteid, $websitepagetype, $websitepageid)
 Increase the website counter of page access.
 
 redirectToContainer ($containerref, $containeraliasalt='', $containerid=0, $permanent=0, $parameters=array())
 Format img tags to introduce viewimage on img src.
 
 includeContainer ($containerref)
 Clean an HTML page to report only content, so we can include it into another page.
 
 getStructuredData ($type, $data=array())
 Return HTML content to add structured data for an article, news or Blog Post.
 
 getSocialNetworkHeaderCards ($params=null)
 Return HTML content to add as header card for an article, news or Blog Post or home page.
 
 getSocialNetworkSharingLinks ($socialnetworks='')
 Return HTML content to add structured data for an article, news or Blog Post.
 
 getNbOfImagePublicURLOfObject ($object)
 Return nb of images known into inde files for an object;.
 
 getImagePublicURLOfObject ($object, $no=1, $extName='')
 Return the public image URL of an object.
 
 getPublicFilesOfObject ($object)
 Return array with list of all public files of a given object.
 
 getPagesFromSearchCriterias ($type, $algo, $searchstring, $max=25, $sortfield='date_creation', $sortorder='DESC', $langcode='', $otherfilters=[], $status=1)
 Return list of containers object that match a criteria.
 
 getImageFromHtmlContent ($htmlContent, $imageNumber=1)
 Return the URL of an image found into a HTML content.
 
 getAllImages ($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks=0, $grabimages=1, $grabimagesinto='subpage')
 Download all images found into an external URL.
 
 getNewsDetailsById ($postId)
 Retrieves the details of a news post by its ID.
 

Detailed Description

Library for website module.

Definition in file website.lib.php.

Function Documentation

◆ dolKeepOnlyPhpCode()

dolKeepOnlyPhpCode ( $str)

Keep only PHP code part from a HTML string page.

Parameters
string$strString to clean
Returns
string Result string with php code only
See also
dolStripPhpCode(), checkPHPCode()

Definition at line 78 of file website.lib.php.

Referenced by run_sql().

◆ dolReplaceSmileyCodeWithUTF8()

dolReplaceSmileyCodeWithUTF8 ( $content)

Converts smiley string into the utf8 sequence.

Parameters
string$contentContent to replace
Returns
string Replacement of all smiley strings with their utf8 code
See also
dolWebsiteOutput()

Definition at line 233 of file website.lib.php.

Referenced by dolWebsiteOutput().

◆ dolStripPhpCode()

dolStripPhpCode ( $str,
$replacewith = '' )

Remove PHP code part from a string.

Parameters
string$strString to clean
string$replacewithString to use as replacement
Returns
string Result string without php code
See also
dolKeepOnlyPhpCode()

Definition at line 34 of file website.lib.php.

Referenced by dolWebsiteReplacementOfLinks(), and getStructuredData().

◆ dolWebsiteIncrementCounter()

dolWebsiteIncrementCounter ( $websiteid,
$websitepagetype,
$websitepageid )

Increase the website counter of page access.

Parameters
int$websiteidID of website
string$websitepagetypeType of page ('blogpost', 'page', ...)
int$websitepageidID of page
Returns
int Return integer <0 if KO, >0 if OK

Definition at line 453 of file website.lib.php.

References dol_getdate(), dol_mktime(), dol_now(), and getDolGlobalInt().

◆ dolWebsiteOutput()

dolWebsiteOutput ( $content,
$contenttype = 'html',
$containerid = 0 )

Render a string of an HTML content and output it.

Used to output the page when viewed from a server (Dolibarr or Apache).

Parameters
string$contentContent string
string$contenttypeContent type
int$containeridContenair id
Returns
void
See also
dolWebsiteReplacementOfLinks() for function used to replace content in the backoffice context.

Definition at line 284 of file website.lib.php.

References dol_syslog(), dolReplaceSmileyCodeWithUTF8(), and getDolGlobalString().

◆ dolWebsiteReplacementOfLinks()

dolWebsiteReplacementOfLinks ( $website,
$content,
$removephppart = 0,
$contenttype = 'html',
$containerid = 0 )

Convert a page content to have correct links (based on DOL_URL_ROOT) into an html content.

It replaces also dynamic content with '...php...' Used to output the page on the Preview from backoffice.

Parameters
Website$websiteWeb site object
string$contentContent to replace
int$removephppart0=Replace PHP sections with a PHP badge. 1=Remove completely PHP sections.
string$contenttypeContent type
int$containeridContenair id
Returns
string html content
See also
dolWebsiteOutput() for function used to replace content in a web server context

Definition at line 123 of file website.lib.php.

References dol_syslog(), and dolStripPhpCode().

◆ getAllImages()

getAllImages ( $object,
$objectpage,
$urltograb,
& $tmp,
& $action,
$modifylinks = 0,
$grabimages = 1,
$grabimagesinto = 'subpage' )

Download all images found into an external URL.

It using a text regex parsing solution, not a DOM analysis. If $modifylinks is set, links to images will be replace with a link to viewimage wrapper. To extract an URL from a HTML text content, see instead getImageFromHtmlContent().

Parameters
Website$objectObject website
WebsitePage$objectpageObject website page
string$urltograbURL to grab (example: https://www.nltechno.com/ or s://www.nltechno.com/dir1/ or https://www.nltechno.com/dir1/mapage1)
string$tmpContent to parse
string$actionVar $action
int<0,1>$modifylinks 0=Do not modify content, 1=Replace links with a link to viewimage
int<0,1>$grabimages 0=Do not grab images, 1=Grab images
'root'|'subpage'$grabimagesinto 'root' or 'subpage'
Returns
void

Definition at line 1388 of file website.lib.php.

References $object, dol_mkdir(), dol_syslog(), dolChmod(), getRootURLFromURL(), getURLContent(), and setEventMessages().

◆ getImageFromHtmlContent()

getImageFromHtmlContent ( $htmlContent,
$imageNumber = 1 )

Return the URL of an image found into a HTML content.

To get image from an external URL to download first, see getAllImages()

Parameters
string$htmlContentHTML content
int$imageNumberThe position of image. 1 by default = first image found
Returns
string URL of image or '' if not foud
See also
getImagePublicURLOfObject()

Definition at line 1339 of file website.lib.php.

Referenced by build_rssfile().

◆ getImagePublicURLOfObject()

getImagePublicURLOfObject ( $object,
$no = 1,
$extName = '' )

Return the public image URL of an object.

For example, you can get the public image URL of a product (image that is shared).

Parameters
Object$objectObject
int$noNumero of image (if there is several images. 1st one by default)
string$extNameExtension to differentiate thumb file name ('', '_small', '_mini')
Returns
string HTML img content or '' if no image found
See also
getNbOfImagePublicURLOfObject(), getPublicFilesOfObject(), getImageFromHtmlContent()

Definition at line 1038 of file website.lib.php.

References $object, and getListOfPossibleImageExt().

◆ getNbOfImagePublicURLOfObject()

getNbOfImagePublicURLOfObject ( $object)

Return nb of images known into inde files for an object;.

Parameters
Object$objectObject
Returns
int HTML img content or '' if no image found
See also
getImagePublicURLOfObject()

Definition at line 1000 of file website.lib.php.

References $object, and getListOfPossibleImageExt().

◆ getNewsDetailsById()

getNewsDetailsById ( $postId)

Retrieves the details of a news post by its ID.

Parameters
string$postIdThe ID of the news post to retrieve.
Returns
array<string,mixed>|int<-1,-1> Return array if OK, -1 if KO

Definition at line 1539 of file website.lib.php.

◆ getPagesFromSearchCriterias()

getPagesFromSearchCriterias ( $type,
$algo,
$searchstring,
$max = 25,
$sortfield = 'date_creation',
$sortorder = 'DESC',
$langcode = '',
$otherfilters = [],
$status = 1 )

Return list of containers object that match a criteria.

WARNING: This function can be used by websites.

Parameters
string$typeType of container to search into (Example: '', 'page', 'blogpost', 'page,blogpost', ...)
string$algoAlgorithm used for search (Example: 'meta' is searching into meta information like title and description, 'content', 'sitefiles', or any combination 'meta,content,sitefiles')
string$searchstringSearch string
int$maxMax number of answers
string$sortfieldSort Fields
'DESC'|'ASC'$sortorder Sort order ('DESC' or 'ASC')
string$langcodeLanguage code ('' or 'en', 'fr', 'es', ...)
array<string,mixed>$otherfilters Other filters
int<-1,1>$status 0 or 1, or -1 for both
Returns
array{list?:WebsitePage[],code?:string,message?:string} Array with results of search

Definition at line 1172 of file website.lib.php.

◆ getPublicFilesOfObject()

getPublicFilesOfObject ( $object)

Return array with list of all public files of a given object.

Parameters
Object$objectObject
Returns
array<array{filename:string,position:int,url:string}> List of public files of object
See also
getImagePublicURLOfObject()

Definition at line 1112 of file website.lib.php.

References $object, and getListOfPossibleImageExt().

◆ getSocialNetworkHeaderCards()

getSocialNetworkHeaderCards ( $params = null)

Return HTML content to add as header card for an article, news or Blog Post or home page.

Parameters
?array<string,mixed>$params Array of parameters
Returns
string HTML content

Definition at line 868 of file website.lib.php.

◆ getSocialNetworkSharingLinks()

getSocialNetworkSharingLinks ( $socialnetworks = '')

Return HTML content to add structured data for an article, news or Blog Post.

Parameters
string$socialnetworks'' or list of social networks
Returns
string HTML content

Definition at line 944 of file website.lib.php.

References dol_escape_htmltag().

◆ getStructuredData()

getStructuredData ( $type,
$data = array() )

Return HTML content to add structured data for an article, news or Blog Post.

Use the json-ld format. Example: <?php getStructureData('blogpost'); ?> <?php getStructureData('software', array('name'=>'Name', 'os'=>'Windows', 'price'=>10)); ?>

Parameters
string$type'blogpost', 'product', 'software', 'organization', 'qa', ...
array<string,mixed>$data Array of data parameters for structured data
Returns
string HTML content

Definition at line 660 of file website.lib.php.

References dol_escape_json(), dol_print_date(), dol_string_nohtmltag(), and dolStripPhpCode().

◆ includeContainer()

includeContainer ( $containerref)

Clean an HTML page to report only content, so we can include it into another page.

It outputs content of file sanitized from html and body part.

Parameters
string$containerrefPath to file to include (must be a page from website root. Example: 'mypage.php' means 'mywebsite/mypage.php')
Returns
void

Definition at line 602 of file website.lib.php.

◆ redirectToContainer()

redirectToContainer ( $containerref,
$containeraliasalt = '',
$containerid = 0,
$permanent = 0,
$parameters = array() )

Format img tags to introduce viewimage on img src.

Parameters
string$contentContent string
Returns
void
See also
dolWebsiteOutput() Make a redirect to another container.
Parameters
string$containerrefRef of container to redirect to (Example: 'mypage' or 'mypage.php').
string$containeraliasaltRef of alternative aliases to redirect to.
int$containeridId of container.
int<0,1>$permanent 0=Use temporary redirect 302, 1=Use permanent redirect 301
array<string,mixed>$parameters Array of parameters to append to the URL.
Returns
void

Definition at line 519 of file website.lib.php.

References setEventMessages().