25 if (!defined(
'NOSESSION')) define(
'NOSESSION',
'1');
27 $sapi_type = php_sapi_name();
28 $script_file = basename(__FILE__);
32 if (substr($sapi_type, 0, 3) ==
'cgi') {
33 echo
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
38 define(
'EVEN_IF_ONLY_LOGIN_ALLOWED', 1);
42 $mode = empty($argv[1]) ?
'' : $argv[1];
43 $websiteref = empty($argv[2]) ?
'' : $argv[2];
44 $joomlaserverinfo = empty($argv[3]) ?
'' : $argv[3];
45 $image =
'image/__WEBSITE_KEY__/images/stories/dolibarr.png';
47 $max = (!isset($argv[4]) || (empty($argv[4]) && $argv[4] !==
'0')) ?
'10' : $argv[4];
48 $excludeid = (empty($argv[5]) ?
'' : $argv[5]);
49 $forcelang = (empty($argv[6]) ?
'' : $argv[6]);
51 if (empty($argv[3]) || !in_array($argv[1], array(
'test',
'confirm')) || empty($websiteref)) {
52 print '***** '.$script_file.
' *****'.
"\n";
53 print "Usage: $script_file (test|confirm) website login:pass@serverjoomla/tableprefix/databasejoomla [nbmaxrecord]\n";
55 print "Load joomla news and create them into Dolibarr database (if they don't alreay exist).\n";
59 require $path.
"../../htdocs/master.inc.php";
60 include_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
61 include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
62 include_once DOL_DOCUMENT_ROOT.
'/core/lib/website2.lib.php';
66 $joomlaserverinfoarray = preg_split(
'/(:|@|\/)/', $joomlaserverinfo);
67 $joomlalogin = $joomlaserverinfoarray[0];
68 $joomlapass = $joomlaserverinfoarray[1];
69 $joomlahost = $joomlaserverinfoarray[2];
70 $joomlaprefix = $joomlaserverinfoarray[3];
71 $joomladatabase = $joomlaserverinfoarray[4];
76 $result = $website->fetch(0, $websiteref);
78 print 'Error, web site '.$websiteref.
' not found'.
"\n";
81 $websiteid = $website->id;
84 $dbjoomla =
getDoliDBInstance(
'mysqli', $joomlahost, $joomlalogin, $joomlapass, $joomladatabase, $joomlaport);
87 dol_print_error($dbjoomla,
"host=".$joomlahost.
", port=".$joomlaport.
", user=".$joomlalogin.
", databasename=".$joomladatabase.
", ".$dbjoomla->error);
91 $sql =
'SELECT c.id, c.title, c.alias, c.created, c.introtext, `fulltext`, c.metadesc, c.metakey, c.language, c.created, c.publish_up, u.username FROM '.$joomlaprefix.
'_content as c';
92 $sql .=
' LEFT JOIN '.$joomlaprefix.
'_users as u ON u.id = c.created_by';
93 $sql .=
' WHERE featured = 1';
94 $sql .=
' AND c.id NOT IN ('.$excludeid.
')';
95 $sql .=
' ORDER BY publish_up ASC';
96 $resql = $dbjoomla->query($sql);
103 $blogpostheader = file_get_contents($path.
'blogpost-header.txt');
104 if ($blogpostheader ===
false) {
105 print "Error: Failed to load file content of 'blogpost-header.txt'\n";
108 $blogpostfooter = file_get_contents($path.
'blogpost-footer.txt');
109 if ($blogpostfooter ===
false) {
110 print "Error: Failed to load file content of 'blogpost-footer.txt'\n";
118 $i = 0; $nbimported = 0; $nbalreadyexists = 0;
119 while ($obj = $dbjoomla->fetch_object(
$resql)) {
123 $alias = $obj->alias;
124 $title = $obj->title;
130 if ($blogpostheader) $htmltext .= $blogpostheader.
"\n";
131 $htmltext .=
'<section id="mysectionnewsintro" contenteditable="true">'.
"\n";
132 $htmltext .= $obj->introtext;
133 $htmltext .=
'</section>'.
"\n";
134 if ($obj->fulltext) {
135 $htmltext .=
'<section id="mysectionnewscontent" contenteditable="true">'.
"\n";
136 $htmltext .=
'<br>'.
"\n".
'<hr>'.
"\n".
'<br>'.
"\n";
137 $htmltext .= $obj->fulltext;
138 $htmltext .=
"</section>";
140 if ($blogpostfooter) $htmltext .=
"\n".$blogpostfooter;
142 $language = ($forcelang ? $forcelang : ($obj->language && $obj->language !=
'*' ? $obj->language :
'en'));
143 $keywords = $obj->metakey;
144 $author_alias = $obj->username;
146 $date_creation = $dbjoomla->jdate($obj->publish_up);
148 print '#'.$i.
' id='.$id.
' '.$title.
' lang='.$language.
' keywords='.$keywords.
' importid='.$importid.
"\n";
150 $sqlinsert =
'INSERT INTO '.MAIN_DB_PREFIX.
'website_page(fk_website, pageurl, aliasalt, title, description, keywords, content, status, type_container, lang, import_key, image, date_creation, author_alias)';
151 $sqlinsert .=
" VALUES(".$websiteid.
", '".$db->escape($alias).
"', '', '".$db->escape($title).
"', '".$db->escape($description).
"', '".$db->escape($keywords).
"', ";
152 $sqlinsert .=
" '".$db->escape($htmltext).
"', '1', 'blogpost', '".$db->escape($language).
"', '".$db->escape($importid).
"', '".$db->escape($image).
"', '".$db->idate($date_creation).
"', '".$db->escape($author_alias).
"')";
153 print $sqlinsert.
"\n";
155 $result = $db->query($sqlinsert);
157 print 'ERROR: '.$db->lasterrno.
": ".$sqlinsert.
"\n";
158 if ($db->lasterrno !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
164 $pageid = $db->last_insert_id(MAIN_DB_PREFIX.
'website_page');
167 global $dolibarr_main_data_root;
168 $pathofwebsite = $dolibarr_main_data_root.
'/website/'.$websiteref;
169 $filetpl = $pathofwebsite.
'/page'.$pageid.
'.tpl.php';
171 $websitepage->fetch($pageid);
175 print "Insert done - pageid = ".$pageid.
"\n";
179 if ($max && $i >= $max) {
180 print 'Nb max of record ('.$max.
') reached. We stop now.'.
"\n";
186 if ($mode ==
'confirm' && !$error) {
188 print $nbalreadyexists.
" page(s) already exists.\n";
189 print $nbimported.
" page(s) imported with importid=".$importid.
"\n";
192 print "Rollback (mode=test)\n";
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
dol_now($mode= 'auto')
Return date for now.
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
Save content of a page on disk (page name is generally ID_of_page.php).
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.