mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
FIX must use getUrlContent to get external url in RSS module
This commit is contained in:
parent
d9108362ba
commit
44cb9dca67
|
|
@ -41,7 +41,6 @@ if (!$user->admin) {
|
|||
accessforbidden();
|
||||
}
|
||||
|
||||
$def = array();
|
||||
$lastexternalrss = 0;
|
||||
$action = GETPOST('action', 'aZ09');
|
||||
|
||||
|
|
@ -56,6 +55,7 @@ $sql .= " WHERE ".$db->decrypt('name')." LIKE 'EXTERNAL_RSS_URLRSS_%'";
|
|||
//print $sql;
|
||||
$result = $db->query($sql); // We can't use SELECT MAX() because EXTERNAL_RSS_URLRSS_10 is lower than EXTERNAL_RSS_URLRSS_9
|
||||
if ($result) {
|
||||
$reg = array();
|
||||
while ($obj = $db->fetch_object($result)) {
|
||||
preg_match('/([0-9]+)$/i', $obj->name, $reg);
|
||||
if ($reg[1] && $reg[1] > $lastexternalrss) {
|
||||
|
|
@ -70,7 +70,7 @@ if ($action == 'add' || GETPOST("modify")) {
|
|||
$external_rss_title = "external_rss_title_".GETPOST("norss", 'int');
|
||||
$external_rss_urlrss = "external_rss_urlrss_".GETPOST("norss", 'int');
|
||||
|
||||
if (!empty($_POST[$external_rss_urlrss])) {
|
||||
if (GETPOST($external_rss_urlrss, 'alpha')) {
|
||||
$boxlabel = '(ExternalRSSInformations)';
|
||||
//$external_rss_url = "external_rss_url_" . GETPOST("norss");
|
||||
|
||||
|
|
@ -95,13 +95,17 @@ if ($action == 'add' || GETPOST("modify")) {
|
|||
$sql .= " VALUES ('box_external_rss.php','".$db->escape(GETPOST("norss", 'int').' ('.GETPOST($external_rss_title, 'alpha')).")')";
|
||||
if (!$db->query($sql)) {
|
||||
dol_print_error($db);
|
||||
$err++;
|
||||
$error++;
|
||||
}
|
||||
//print $sql;exit;
|
||||
}
|
||||
|
||||
$result1 = dolibarr_set_const($db, "EXTERNAL_RSS_TITLE_".GETPOST("norss", 'int'), GETPOST($external_rss_title, 'alpha'), 'chaine', 0, '', $conf->entity);
|
||||
if ($result1) {
|
||||
$result2 = dolibarr_set_const($db, "EXTERNAL_RSS_URLRSS_".GETPOST("norss", 'int'), GETPOST($external_rss_urlrss, 'alpha'), 'chaine', 0, '', $conf->entity);
|
||||
$consttosave = "EXTERNAL_RSS_URLRSS_".GETPOST("norss", 'int');
|
||||
$urltosave = GETPOST($external_rss_urlrss, 'alpha');
|
||||
$result2 = dolibarr_set_const($db, $consttosave, $urltosave, 'chaine', 0, '', $conf->entity);
|
||||
//var_dump($result2);exit;
|
||||
}
|
||||
|
||||
if ($result1 && $result2) {
|
||||
|
|
@ -258,14 +262,14 @@ if ($resql) {
|
|||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print "<td width=\"100px\">".$langs->trans("Title")."</td>";
|
||||
print "<td><input type=\"text\" class=\"flat minwidth300\" name=\"external_rss_title_".$idrss."\" value=\"".dol_escape_htmltag($conf->global->$keyrsstitle)."\"></td>";
|
||||
print '<td class="titlefield">'.$langs->trans("Title")."</td>";
|
||||
print '<td><input type="text" class="flat minwidth300" name="external_rss_title_'.$idrss.'" value="'.dol_escape_htmltag($conf->global->$keyrsstitle).'"></td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print "<td>".$langs->trans("URL")."</td>";
|
||||
print "<td><input type=\"text\" class=\"flat minwidth300\" name=\"external_rss_urlrss_".$idrss."\" value=\"".dol_escape_htmltag($conf->global->$keyrssurl)."\"></td>";
|
||||
print '<td><input type="text" class="flat minwidth300" name="external_rss_urlrss_'.$idrss.'" value="'.dol_escape_htmltag($conf->global->$keyrssurl).'"></td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
|
||||
|
|
@ -307,7 +311,7 @@ if ($resql) {
|
|||
// Active
|
||||
$active = _isInBoxList($idrss, $boxlist) ? 'yes' : 'no';
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->trans('WidgetEnabled').'</td>';
|
||||
print '<td>'.$langs->trans('WidgetAvailable').'</td>';
|
||||
print '<td>'.yn($active).'</td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ class RssParser
|
|||
* @param string $urlRSS Url to parse
|
||||
* @param int $maxNb Max nb of records to get (0 for no limit)
|
||||
* @param int $cachedelay 0=No cache, nb of seconds we accept cache files (cachedir must also be defined)
|
||||
* @param string $cachedir Directory where to save cache file
|
||||
* @param string $cachedir Directory where to save cache file (For example $conf->externalrss->dir_temp)
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function parser($urlRSS, $maxNb = 0, $cachedelay = 60, $cachedir = '')
|
||||
|
|
@ -189,6 +189,7 @@ class RssParser
|
|||
global $conf;
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
|
||||
|
||||
$rss = '';
|
||||
$str = ''; // This will contain content of feed
|
||||
|
|
@ -225,21 +226,10 @@ class RssParser
|
|||
$str = file_get_contents($newpathofdestfile);
|
||||
} else {
|
||||
try {
|
||||
ini_set("user_agent", "Dolibarr ERP-CRM RSS reader");
|
||||
ini_set("max_execution_time", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
|
||||
ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
|
||||
|
||||
$opts = array('http'=>array('method'=>"GET"));
|
||||
if (!empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) {
|
||||
$opts['http']['timeout'] = $conf->global->MAIN_USE_CONNECT_TIMEOUT;
|
||||
$result = getURLContent($this->_urlRSS, 'GET', '', 1, array(), array('http', 'https'), 0);
|
||||
if (!empty($result['content'])) {
|
||||
$str = $result['content'];
|
||||
}
|
||||
if (!empty($conf->global->MAIN_PROXY_USE)) {
|
||||
$opts['http']['proxy'] = 'tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
|
||||
}
|
||||
//var_dump($opts);exit;
|
||||
$context = stream_context_create($opts);
|
||||
|
||||
$str = file_get_contents($this->_urlRSS, false, $context);
|
||||
} catch (Exception $e) {
|
||||
print 'Error retrieving URL '.$this->_urlRSS.' - '.$e->getMessage();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user