/** * Display the feed editor. * * @param int $fid feed id (0 for new feeds) * @param string $type type of feed, e.g. 'article' * @return string HTML for the feed editor * */ function editfeed($fid = 0, $type = '') { global $_CONF, $_TABLES, $LANG33, $LANG_ADMIN, $MESSAGE; if ($fid > 0) { $result = DB_query("SELECT *,UNIX_TIMESTAMP(updated) AS date FROM {$_TABLES['syndication']} WHERE fid = '{$fid}'"); $A = DB_fetchArray($result); $fid = $A['fid']; } if ($fid == 0) { if (!empty($type)) { // set defaults $A['fid'] = $fid; $A['type'] = $type; $A['topic'] = '::all'; $A['header_tid'] = 'none'; $A['format'] = 'RSS-2.0'; $A['limits'] = $_CONF['rdf_limit']; $A['content_length'] = $_CONF['rdf_storytext']; $A['title'] = $_CONF['site_name']; $A['description'] = $_CONF['site_slogan']; $A['feedlogo'] = ''; $A['filename'] = ''; $A['charset'] = $_CONF['default_charset']; $A['language'] = $_CONF['rdf_language']; $A['is_enabled'] = 1; $A['updated'] = ''; $A['update_info'] = ''; $A['date'] = time(); } else { return COM_refresh($_CONF['site_admin_url'] . '/syndication.php'); } } $retval = ''; $token = SEC_createToken(); $feed_template = COM_newTemplate($_CONF['path_layout'] . 'admin/syndication'); $feed_template->set_file('editor', 'feededitor.thtml'); $start_block = COM_startBlock($LANG33[24], '', COM_getBlockTemplate('_admin_block', 'header')); $start_block .= SEC_getTokenExpiryNotice($token); $feed_template->set_var('start_feed_editor', $start_block); $feed_template->set_var('end_block', COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'))); $feed_template->set_var('lang_feedtitle', $LANG33[25]); $feed_template->set_var('lang_enabled', $LANG33[19]); $feed_template->set_var('lang_format', $LANG33[17]); $feed_template->set_var('lang_limits', $LANG33[26]); $feed_template->set_var('lang_content_length', $LANG33[27]); $feed_template->set_var('lang_clen_explain', $LANG33[28]); $feed_template->set_var('lang_description', $LANG33[29]); $feed_template->set_var('lang_feedlogo', $LANG33[49]); $feed_template->set_var('lang_feedlogo_explain', $LANG33[50]); $feed_template->set_var('lang_filename', $LANG33[16]); $feed_template->set_var('lang_updated', $LANG33[30]); $feed_template->set_var('lang_type', $LANG33[15]); $feed_template->set_var('lang_charset', $LANG33[31]); $feed_template->set_var('lang_language', $LANG33[32]); $feed_template->set_var('lang_topic', $LANG33[33]); if ($A['header_tid'] == 'all') { $feed_template->set_var('all_selected', 'selected="selected"'); } elseif ($A['header_tid'] == 'none') { $feed_template->set_var('none_selected', 'selected="selected"'); } $feed_template->set_var('lang_header_all', $LANG33[43]); $feed_template->set_var('lang_header_none', $LANG33[44]); $feed_template->set_var('lang_header_topic', $LANG33[45]); $feed_template->set_var('header_topic_options', COM_topicList('tid,topic', $A['header_tid'], 1, true)); $feed_template->set_var('lang_save', $LANG_ADMIN['save']); $feed_template->set_var('lang_cancel', $LANG_ADMIN['cancel']); if ($A['fid'] > 0) { $delbutton = '<input type="submit" value="' . $LANG_ADMIN['delete'] . '" name="mode"%s' . XHTML . '>'; $jsconfirm = ' onclick="return confirm(\'' . $MESSAGE[76] . '\');"'; $feed_template->set_var('delete_option', sprintf($delbutton, $jsconfirm)); $feed_template->set_var('delete_option_no_confirmation', sprintf($delbutton, '')); } $feed_template->set_var('feed_id', $A['fid']); $feed_template->set_var('feed_title', $A['title']); $feed_template->set_var('feed_description', $A['description']); $feed_template->set_var('feed_logo', $A['feedlogo']); $feed_template->set_var('feed_content_length', $A['content_length']); $feed_template->set_var('feed_filename', $A['filename']); $feed_template->set_var('feed_type', $A['type']); if ($A['type'] == 'article') { $feed_template->set_var('feed_type_display', $LANG33[55]); } else { $feed_template->set_var('feed_type_display', ucwords($A['type'])); } $feed_template->set_var('feed_charset', $A['charset']); $feed_template->set_var('feed_language', $A['language']); if ($A['is_enabled'] == 1 && !empty($A['updated'])) { $nicedate = COM_getUserDateTimeFormat($A['date']); $feed_template->set_var('feed_updated', $nicedate[0]); } else { $feed_template->set_var('feed_updated', $LANG_ADMIN['na']); } $formats = find_feedFormats(); $selection = '<select name="format">' . LB; foreach ($formats as $f) { // if one changes this format below ('name-version'), also change parsing // in COM_siteHeader. It uses explode( "-" , $string ) $selection .= '<option value="' . $f['name'] . '-' . $f['version'] . '"'; if ($A['format'] == $f['name'] . '-' . $f['version']) { $selection .= ' selected="selected"'; } $selection .= '>' . ucwords($f['name'] . ' ' . $f['version']) . '</option>' . LB; } $selection .= '</select>' . LB; $feed_template->set_var('feed_format', $selection); $limits = $A['limits']; $hours = false; if (substr($A['limits'], -1) == 'h') { $limits = substr($A['limits'], 0, -1); $hours = true; } $selection = '<select name="limits_in">' . LB; $selection .= '<option value="0"'; if (!$hours) { $selection .= ' selected="selected"'; } $selection .= '>' . $LANG33[34] . '</option>' . LB; $selection .= '<option value="1"'; if ($hours) { $selection .= ' selected="selected"'; } $selection .= '>' . $LANG33[35] . '</option>' . LB; $selection .= '</select>' . LB; $feed_template->set_var('feed_limits', $limits); $feed_template->set_var('feed_limits_what', $selection); if ($A['type'] == 'article') { $options = get_articleFeeds(); } else { $result = DB_query("SELECT pi_enabled FROM {$_TABLES['plugins']} WHERE pi_name='{$A['type']}'"); if ($result) { $P = DB_fetchArray($result); if ($P['pi_enabled'] == 0) { echo COM_refresh($_CONF['site_admin_url'] . '/syndication.php?msg=80'); exit; } } $options = PLG_getFeedNames($A['type']); } $selection = '<select name="topic">' . LB; foreach ($options as $o) { $selection .= '<option value="' . $o['id'] . '"'; if ($A['topic'] == $o['id']) { $selection .= ' selected="selected"'; } $selection .= '>' . $o['name'] . '</option>' . LB; } $selection .= '</select>' . LB; $feed_template->set_var('feed_topic', $selection); if ($A['is_enabled'] == 1) { $feed_template->set_var('is_enabled', 'checked="checked"'); } else { $feed_template->set_var('is_enabled', ''); } $feed_template->set_var('gltoken_name', CSRF_TOKEN); $feed_template->set_var('gltoken', $token); $retval .= $feed_template->finish($feed_template->parse('output', 'editor')); return $retval; }
/** * Save feed. * * @param array $A * @return string HTML redirect on success or feed editor + error message * */ function savefeed($A) { global $_CONF, $_TABLES, $LANG33; foreach ($A as $name => $value) { $A[$name] = COM_stripslashes($value); } if (isset($A['is_enabled']) && $A['is_enabled'] == 'on') { $A['is_enabled'] = 1; } else { $A['is_enabled'] = 0; } // Make sure correct format returned and correct file extenstion $A['filename'] = COM_sanitizeFilename($A['filename'], true); $file_parts = pathinfo($A['filename']); $A['filename'] = ''; // Clear out filename. If it doesn't get recreated then we know there is an error if (!empty($file_parts['filename'])) { $formats = find_feedFormats(); foreach ($formats as $f) { if ($A['format'] == $f['name'] . '-' . $f['version']) { switch ($f['name']) { case 'Atom': if (!in_array(@$file_parts['extension'], array('atm', 'xml'))) { $file_parts['extension'] = 'xml'; } $A['filename'] = $file_parts['filename'] . '.' . $file_parts['extension']; break; case 'RSS': if (!in_array(@$file_parts['extension'], array('rss', 'xml'))) { $file_parts['extension'] = 'rss'; } $A['filename'] = $file_parts['filename'] . '.' . $file_parts['extension']; break; case 'RDF': $A['filename'] = $file_parts['filename'] . '.rdf'; break; } } } } if (empty($A['title']) || empty($A['description']) || empty($A['filename'])) { $retval = COM_showMessageText($LANG33[39], $LANG33[38]) . editfeed($A['fid'], $A['type']); $retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG33[38])); return $retval; } $result = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['syndication']} WHERE filename = '{$A['filename']}' AND (fid <> '{$A['fid']}')"); $C = DB_fetchArray($result); if ($C['count'] > 0) { $retval = COM_showMessageText($LANG33[51], $LANG33[52]) . editfeed($A['fid'], $A['type']); $retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG33[52])); return $retval; } if ($A['limits'] <= 0) { $retval = COM_showMessageText($LANG33[40], $LANG33[38]) . editfeed($A['fid'], $A['type']); $retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG33[38])); return $retval; } if ($A['limits_in'] == 1) { $A['limits'] .= 'h'; } // we can compensate if these are missing ... if (!empty($A['charset'])) { $A['charset'] = preg_replace('/[^0-9a-zA-Z_\\-]/', '', $A['charset']); } if (empty($A['charset'])) { $A['charset'] = $_CONF['default_charset']; if (empty($A['charset'])) { $A['charset'] = 'UTF-8'; } } if (!empty($A['language'])) { $A['language'] = preg_replace('/[^0-9a-zA-Z_\\.\\-]/', '', $A['language']); } if (empty($A['language'])) { $A['language'] = $_CONF['rdf_language']; if (empty($A['language'])) { $A['language'] = $_CONF['locale']; } } if (!empty($A['content_length'])) { $A['content_length'] = intval($A['content_length'], 10); } if (empty($A['content_length']) || $A['content_length'] < 0) { $A['content_length'] = 0; } foreach ($A as $name => $value) { $A[$name] = DB_escapeString($value); } DB_save($_TABLES['syndication'], 'fid,type,topic,header_tid,format,limits,content_length,title,description,feedlogo,filename,charset,language,is_enabled,updated,update_info', "{$A['fid']},'{$A['type']}','{$A['topic']}','{$A['header_tid']}','{$A['format']}','{$A['limits']}',{$A['content_length']},'{$A['title']}','{$A['description']}','{$A['feedlogo']}','{$A['filename']}','{$A['charset']}','{$A['language']}',{$A['is_enabled']},'0000-00-00 00:00:00',NULL"); if ($A['fid'] == 0) { $A['fid'] = DB_insertId(); } if ($A['is_enabled'] == 1) { SYND_updateFeed($A['fid']); } else { deleteFeedFile($A['filename']); } return COM_refresh($_CONF['site_admin_url'] . '/syndication.php?msg=58'); }