grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } // $feed = new SimplePie(); // $feed->set_cache_location('../files/_rss'); // $feed->set_cache_duration(3600); // $feed->set_feed_url('http://linuxfr.org/news.atom'); // $feed->force_feed(true); // // Initialize the whole SimplePie object. Read the feed, process it, parse it, cache it, and // // all that other good stuff. The feed's information will not be available to SimplePie before // // this is called. // $success = $feed->init(); // // // We'll make sure that the right content type and character encoding gets set automatically. // // This function will grab the proper character encoding, as well as set the content type to text/html. // $feed->handle_content_type(); // if ($feed->error()) // { // echo "ERROR"; // } else { // echo $feed->get_title(); // echo $feed->get_link(); // } /** * RSSFeed Class * * @since version 0.84 **/ class RSSFeed extends CommonDBTM { // From CommonDBTM public $dohistory = true; // For visibility checks protected $users = array(); protected $groups = array(); protected $profiles = array(); protected $entities = array(); static $rightname = 'rssfeed_public'; static function getTypeName($nb=0) { if (Session::haveRight('rssfeed_public',READ)) { return _n('RSS feed', 'RSS feed', $nb); } return _n('Personal RSS feed', 'Personal RSS feed', $nb); } static function canCreate() { return (Session::haveRight(self::$rightname, CREATE) || ($_SESSION['glpiactiveprofile']['interface'] != 'helpdesk')); } static function canView() { return (Session::haveRight('rssfeed_public', READ) || ($_SESSION['glpiactiveprofile']['interface'] != 'helpdesk')); } function canViewItem() { // Is my rssfeed or is in visibility return (($this->fields['users_id'] == Session::getLoginUserID()) || (Session::haveRight('rssfeed_public', READ) && $this->haveVisibilityAccess())); } function canCreateItem() { // Is my rssfeed return ($this->fields['users_id'] == Session::getLoginUserID()); } function canUpdateItem() { return (($this->fields['users_id'] == Session::getLoginUserID()) || (Session::haveRight('rssfeed_public', UPDATE) && $this->haveVisibilityAccess())); } /** * @since 0.85 * for personal rss feed **/ static function canUpdate() { return ($_SESSION['glpiactiveprofile']['interface'] != 'helpdesk'); } /** * @since 0.85 * for personal rss feed **/ static function canPurge() { return ($_SESSION['glpiactiveprofile']['interface'] != 'helpdesk'); } /** * @since version 0.85 * * @see CommonDBTM::canPurgeItem() **/ function canPurgeItem() { return (($this->fields['users_id'] == Session::getLoginUserID()) || (Session::haveRight(self::$rightname, PURGE) && $this->haveVisibilityAccess())); } function post_getFromDB() { // Users $this->users = RSSFeed_User::getUsers($this->fields['id']); // Entities $this->entities = Entity_RSSFeed::getEntities($this->fields['id']); // Group / entities $this->groups = Group_RSSFeed::getGroups($this->fields['id']); // Profile / entities $this->profiles = Profile_RSSFeed::getProfiles($this->fields['id']); } /** * @see CommonDBTM::cleanDBonPurge() **/ function cleanDBonPurge() { $class = new RSSFeed_User(); $class->cleanDBonItemDelete($this->getType(), $this->fields['id']); $class = new Entity_RSSFeed(); $class->cleanDBonItemDelete($this->getType(), $this->fields['id']); $class = new Group_RSSFeed(); $class->cleanDBonItemDelete($this->getType(), $this->fields['id']); $class = new Profile_RSSFeed(); $class->cleanDBonItemDelete($this->getType(), $this->fields['id']); } function countVisibilities() { return (count($this->entities) + count($this->users) + count($this->groups) + count($this->profiles)); } /** * Is the login user have access to rssfeed based on visibility configuration * * @return boolean **/ function haveVisibilityAccess() { // No public rssfeed right : no visibility check if (!self::canView()) { return false; } // Author if ($this->fields['users_id'] == Session::getLoginUserID()) { return true; } // Users if (isset($this->users[Session::getLoginUserID()])) { return true; } // Groups if (count($this->groups) && isset($_SESSION["glpigroups"]) && count($_SESSION["glpigroups"])) { foreach ($this->groups as $key => $data) { foreach ($data as $group) { if (in_array($group['groups_id'], $_SESSION["glpigroups"])) { // All the group if ($group['entities_id'] < 0) { return true; } // Restrict to entities if (Session::haveAccessToEntity($group['entities_id'], $group['is_recursive'])) { return true; } } } } } // Entities if (count($this->entities) && isset($_SESSION["glpiactiveentities"]) && count($_SESSION["glpiactiveentities"])) { foreach ($this->entities as $key => $data) { foreach ($data as $entity) { if (Session::haveAccessToEntity($entity['entities_id'], $entity['is_recursive'])) { return true; } } } } // Profiles if (count($this->profiles) && isset($_SESSION["glpiactiveprofile"]) && isset($_SESSION["glpiactiveprofile"]['id'])) { if (isset($this->profiles[$_SESSION["glpiactiveprofile"]['id']])) { foreach ($this->profiles[$_SESSION["glpiactiveprofile"]['id']] as $profile) { // All the profile if ($profile['entities_id'] < 0) { return true; } // Restrict to entities if (Session::haveAccessToEntity($profile['entities_id'], $profile['is_recursive'])) { return true; } } } } return false; } /** * Return visibility joins to add to SQL * * @param $forceall force all joins (false by default) * * @return string joins to add **/ static function addVisibilityJoins($forceall=false) { if (!self::canView()) { return ''; } // Users $join = " LEFT JOIN `glpi_rssfeeds_users` ON (`glpi_rssfeeds_users`.`rssfeeds_id` = `glpi_rssfeeds`.`id`) "; // Groups if ($forceall || (isset($_SESSION["glpigroups"]) && count($_SESSION["glpigroups"]))) { $join .= " LEFT JOIN `glpi_groups_rssfeeds` ON (`glpi_groups_rssfeeds`.`rssfeeds_id` = `glpi_rssfeeds`.`id`) "; } // Profiles if ($forceall || (isset($_SESSION["glpiactiveprofile"]) && isset($_SESSION["glpiactiveprofile"]['id']))) { $join .= " LEFT JOIN `glpi_profiles_rssfeeds` ON (`glpi_profiles_rssfeeds`.`rssfeeds_id` = `glpi_rssfeeds`.`id`) "; } // Entities if ($forceall || (isset($_SESSION["glpiactiveentities"]) && count($_SESSION["glpiactiveentities"]))) { $join .= " LEFT JOIN `glpi_entities_rssfeeds` ON (`glpi_entities_rssfeeds`.`rssfeeds_id` = `glpi_rssfeeds`.`id`) "; } return $join; } /** * Return visibility SQL restriction to add * * @return string restrict to add **/ static function addVisibilityRestrict() { $restrict = "`glpi_rssfeeds`.`users_id` = '".Session::getLoginUserID()."' "; if (!self::canView()) { return $restrict; } // Users $restrict .= " OR `glpi_rssfeeds_users`.`users_id` = '".Session::getLoginUserID()."' "; // Groups if (isset($_SESSION["glpigroups"]) && count($_SESSION["glpigroups"])) { $restrict .= " OR (`glpi_groups_rssfeeds`.`groups_id` IN ('".implode("','",$_SESSION["glpigroups"])."') AND (`glpi_groups_rssfeeds`.`entities_id` < 0 ".getEntitiesRestrictRequest(" OR", "glpi_groups_rssfeeds", '', '', true).")) "; } // Profiles if (isset($_SESSION["glpiactiveprofile"]) && isset($_SESSION["glpiactiveprofile"]['id'])) { $restrict .= " OR (`glpi_profiles_rssfeeds`.`profiles_id` = '".$_SESSION["glpiactiveprofile"]['id']."' AND (`glpi_profiles_rssfeeds`.`entities_id` < 0 ".getEntitiesRestrictRequest(" OR", "glpi_profiles_rssfeeds", '', '', true).")) "; } // Entities if (isset($_SESSION["glpiactiveentities"]) && count($_SESSION["glpiactiveentities"])) { // Force complete SQL not summary when access to all entities $restrict .= getEntitiesRestrictRequest("OR","glpi_entities_rssfeeds", '', '', true, true); } return '('.$restrict.')'; } /** * @param $field * @param $values * @param $options array **/ static function getSpecificValueToDisplay($field, $values, array $options=array()) { if (!is_array($values)) { $values = array($field => $values); } switch ($field) { case 'refresh_rate': return Html::timestampToString($values[$field], false); } return parent::getSpecificValueToDisplay($field, $values, $options); } /** * @param $field * @param $name (default '') * @param $values (default '') * @param $options array **/ static function getSpecificValueToSelect($field, $name='', $values='', array $options=array()) { if (!is_array($values)) { $values = array($field => $values); } $options['display'] = false; switch ($field) { case 'refresh_rate' : return Planning::dropdownState($name, $values[$field], false); } return parent::getSpecificValueToSelect($field, $name, $values, $options); } function getSearchOptions() { $tab = array(); $tab['common'] = __('Characteristics'); $tab[1]['table'] = $this->getTable(); $tab[1]['field'] = 'name'; $tab[1]['name'] = __('Name'); $tab[1]['datatype'] = 'itemlink'; $tab[1]['massiveaction'] = false; $tab[1]['forcegroupby'] = true; $tab[2]['table'] = 'glpi_users'; $tab[2]['field'] = 'name'; $tab[2]['name'] = __('Creator'); $tab[2]['datatype'] = 'dropdown'; $tab[2]['massiveaction'] = false; $tab[2]['right'] = 'all'; $tab[3]['table'] = $this->getTable(); $tab[3]['field'] = 'url'; $tab[3]['name'] = __('URL'); $tab[3]['datatype'] = 'string'; $tab[3]['massiveaction'] = false; $tab[4]['table'] = $this->getTable(); $tab[4]['field'] = 'is_active'; $tab[4]['name'] = __('Active'); $tab[4]['datatype'] = 'bool'; $tab[4]['massiveaction'] = true; $tab[6]['table'] = $this->getTable(); $tab[6]['field'] = 'have_error'; $tab[6]['name'] = __('Error'); $tab[6]['datatype'] = 'bool'; $tab[6]['massiveaction'] = true; $tab[7]['table'] = $this->getTable(); $tab[7]['field'] = 'max_items'; $tab[7]['name'] = __('Number of items displayed'); $tab[7]['datatype'] = 'number'; $tab[7]['min'] = 5; $tab[7]['max'] = 100; $tab[7]['step'] = 5; $tab[7]['toadd'] = array(1); $tab[7]['massiveaction'] = true; $tab[16]['table'] = $this->getTable(); $tab[16]['field'] = 'comment'; $tab[16]['name'] = __('Comments'); $tab[16]['datatype'] = 'text'; $tab[5]['table'] = $this->getTable(); $tab[5]['field'] = 'refresh_rate'; $tab[5]['name'] = __('Refresh rate'); $tab[5]['datatype'] = 'timestamp'; $tab[5]['min'] = HOUR_TIMESTAMP; $tab[5]['max'] = DAY_TIMESTAMP; $tab[5]['step'] = HOUR_TIMESTAMP; $tab[5]['toadd'] = array(5*MINUTE_TIMESTAMP, 15*MINUTE_TIMESTAMP, 30*MINUTE_TIMESTAMP, 45*MINUTE_TIMESTAMP); $tab[5]['display_emptychoice'] = false; $tab[5]['massiveaction'] = true; $tab[5]['searchtype'] = 'equals'; $tab[19]['table'] = $this->getTable(); $tab[19]['field'] = 'date_mod'; $tab[19]['name'] = __('Last update'); $tab[19]['datatype'] = 'datetime'; $tab[19]['massiveaction'] = false; $tab[121]['table'] = $this->getTable(); $tab[121]['field'] = 'date_creation'; $tab[121]['name'] = __('Creation date'); $tab[121]['datatype'] = 'datetime'; $tab[121]['massiveaction'] = false; // add objectlock search options $tab += ObjectLock::getSearchOptionsToAdd( get_class($this) ) ; return $tab; } /** * @see CommonGLPI::getTabNameForItem() **/ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { if (self::canView()) { $nb = 0; switch ($item->getType()) { case 'RSSFeed' : $showtab = array(1 => __('Content')); if (session::haveRight('rssfeed_public', UPDATE)) { if ($_SESSION['glpishow_count_on_tabs']) { $nb = $item->countVisibilities(); } $showtab[2] = self::createTabEntry(_n('Target','Targets', Session::getPluralNumber()), $nb); } return $showtab; } } return ''; } /** * @see CommonGLPI::defineTabs() **/ function defineTabs($options=array()) { $ong = array(); $this->addDefaultFormTab($ong); $this->addStandardTab(__CLASS__, $ong, $options); $this->addStandardTab('Log', $ong, $options); return $ong; } /** * @param $item CommonGLPI object * @param $tabnum (default 1) * @param $withtemplate (default 0) **/ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { switch ($item->getType()) { case 'RSSFeed' : switch ($tabnum) { case 1 : $item->showFeedContent(); return true; case 2 : $item->showVisibility(); return true; } } return false; } /** * @see CommonDBTM::prepareInputForAdd() **/ function prepareInputForAdd($input) { if ($feed = self::getRSSFeed($input['url'])) { $input['have_error'] = 0; $input['name'] = addslashes($feed->get_title()); if (empty($input['comment'])) { $input['comment'] = addslashes($feed->get_description()); } } else { $input['have_error'] = 1; $input['name'] = ''; } $input["name"] = trim($input["name"]); if (empty($input["name"])) { $input["name"] = __('Without title'); } return $input; } /** * @see CommonDBTM::prepareInputForAdd() **/ function prepareInputForUpdate($input) { if (empty($input['name']) && isset($input['url']) && ($feed = self::getRSSFeed($input['url']))) { $input['name'] = addslashes($feed->get_title()); if (empty($input['comment'])) { $input['comment'] = addslashes($feed->get_description()); } } return $input; } function pre_updateInDB() { // Set new user if initial user have been deleted if (($this->fields['users_id'] == 0) && ($uid = Session::getLoginUserID())) { $this->fields['users_id'] = $uid; $this->updates[] = "users_id"; } } function post_getEmpty() { $this->fields["name"] = __('New note'); $this->fields["users_id"] = Session::getLoginUserID(); $this->fields["refresh_rate"] = DAY_TIMESTAMP; $this->fields["max_items"] = 20; } /** * Print the rssfeed form * * @param $ID integer Id of the item to print * @param $options array of possible options: * - target filename : where to go when done. **/ function showForm($ID, $options=array()) { global $CFG_GLPI; // Test _rss cache directory. I permission trouble : unable to edit if (Toolbox::testWriteAccessToDirectory(GLPI_RSS_DIR) > 0) { echo "
".__('Error')."
"; echo "| ".$feed->get_title()." | "; foreach ($feed->get_items(0,$this->fields['max_items']) as $item) { $link = $item->get_permalink(); echo "||
|---|---|---|
| "; echo HTML::convDateTime($item->get_date('Y-m-d H:i:s')); echo " | "; if (!is_null($link)) { echo "".$item->get_title().''; } else { $item->get_title(); } echo " | "; $rand = mt_rand(); echo ""; echo Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($item->get_content())), 1000); echo ""; Html::showToolTip(Toolbox::unclean_html_cross_side_scripting_deep($item->get_content()), array('applyto' => "rssitem$rand", 'display' => true)); echo " |
$titre";
if (($personal && self::canCreate())
|| (!$personal && Session::haveRight('rssfeed_public', CREATE))) {
echo "";
echo "";
echo " ";
}
echo " | ||
|---|---|---|
| "; echo HTML::convDateTime($item->get_date('Y-m-d H:i:s')); echo " | ";
$link = $item->feed->get_permalink();
if (empty($link)) {
echo $item->feed->get_title();
} else {
echo "".$item->feed->get_title().'';
}
$link = $item->get_permalink();
// echo " "; // echo $item->get_title(); // echo " | ";
$rand = mt_rand();
echo " ";
if (!is_null($link)) {
echo "";
}
echo $item->get_title();
// echo Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($item->get_content())), 300);
if (!is_null($link)) {
echo "";
}
echo " ";
Html::showToolTip(Toolbox::unclean_html_cross_side_scripting_deep($item->get_content()),
array('applyto' => "rssitem$rand",
'display' => true));
echo " |
| "; $header_top .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header_end .= " | "; } $header_end .= "".__('Type')." | "; $header_end .= ""._n('Recipient', 'Recipients', Session::getPluralNumber())." | "; $header_end .= "
|---|---|---|
| "; Html::showMassiveActionCheckBox('RSSFeed_User',$data["id"]); echo " | "; } echo "".__('User')." | "; echo "".getUserName($data['users_id'])." | "; echo "
| "; Html::showMassiveActionCheckBox('Group_RSSFeed',$data["id"]); echo " | "; } echo "".__('Group')." | "; $names = Dropdown::getDropdownName('glpi_groups', $data['groups_id'],1); $entname = sprintf(__('%1$s %2$s'), $names["name"], Html::showToolTip($names["comment"], array('display' => false))); if ($data['entities_id'] >= 0) { $entname .= sprintf(__('%1$s / %2$s'), $entname, Dropdown::getDropdownName('glpi_entities', $data['entities_id'])); if ($data['is_recursive']) { //TRANS: R for Recursive $entname .= sprintf(__('%1$s %2$s'), $entname, "(".__('R').")"); } } echo "".$entname." | "; echo "
| "; Html::showMassiveActionCheckBox('Entity_RSSFeed',$data["id"]); echo " | "; } echo "".__('Entity')." | "; $names = Dropdown::getDropdownName('glpi_entities', $data['entities_id'],1); $tooltip = Html::showToolTip($names["comment"], array('display' => false)); $entname = sprintf(__('%1$s %2$s'), $names["name"], $tooltip); if ($data['is_recursive']) { $entname .= sprintf(__('%1$s %2$s'), $entname, "(".__('R').")"); } echo "".$entname." | "; echo "
| "; Html::showMassiveActionCheckBox('Profile_RSSFeed',$data["id"]); echo " | "; } echo ""._n('Profile', 'Profiles', 1)." | "; $names = Dropdown::getDropdownName('glpi_profiles',$data['profiles_id'],1); $tooltip = Html::showToolTip($names["comment"], array('display' => false)); $entname = sprintf(__('%1$s %2$s'), $names["name"], $tooltip); if ($data['entities_id'] >= 0) { $entname .= sprintf(__('%1$s / %2$s'), $entname, Dropdown::getDropdownName('glpi_entities', $data['entities_id'])); if ($data['is_recursive']) { $entname .= sprintf(__('%1$s %2$s'), $entname, "(".__('R').")"); } } echo "".$entname." | "; echo "