public static function control_nav_actions() { if (!isset($_REQUEST['action']) && !isset($_REQUEST['feeds'])) { return; } if (@count(@$_REQUEST['feeds']) > 0 && strlen($_REQUEST['action']) > 0) { global $ESS_Notices; $count_action = 0; foreach ($_REQUEST['feeds'] as $feed_id) { if (intval($feed_id) > 0) { $count_action++; switch ($_REQUEST['action']) { default: $action = __('have been updated', 'dbem'); break; case 'active': $action = __('have been activated', 'dbem'); break; case 'deleted': $action = __('have been deleted', 'dbem'); break; case 'full_deleted': $action = __('have been definitively removed', 'dbem'); break; case 'update_cron': $action = __('have its daily update reactualized', 'dbem'); break; } if ($_REQUEST['action'] == 'active' || $_REQUEST['action'] == 'deleted') { ESS_Database::add(array('feed_id' => $feed_id, 'feed_status' => strtoupper($_REQUEST['action']))); } else { if ($_REQUEST['action'] == 'full_deleted') { ESS_Database::delete(array('feed_status' => ESS_Database::FEED_STATUS_DELETED, 'feed_id' => $feed_id)); } else { if ($_REQUEST['action'] == 'update_cron') { $feed_mode = @$_REQUEST['feed_mode_' . $feed_id] == 'on' ? ESS_Database::FEED_MODE_CRON : ESS_Database::FEED_MODE_STANDALONE; ESS_Database::add(array('feed_id' => $feed_id, 'feed_mode' => $feed_mode)); } } } } } $ESS_Notices->add_confirm(sprintf(__("%d rows %s.", 'dbem'), $count_action, $action)); } }
public static function save($feed_url, $feed_update_daily = 'on') { $feed_url = strtr(str_replace('&push=1', '', str_replace('&download=1', '', urldecode(esc_html($feed_url)))), array("<" => "<", ">" => ">", """ => '""', "'" => "'", "&" => "&")); if (!is_user_logged_in() && $feed_update_daily != 'on') { return; } $feed_update_daily = !isset($feed_update_daily) ? 'off' : 'on'; global $ESS_Notices; if (ESS_Import::is_feed_valid($feed_url)) { $RESULT_ = ESS_Import::get_feed_content($feed_url); //dd( $feed_url, $RESULT_ ); if (strlen(@$RESULT_['error']) <= 0 || @$RESULT_['error'] == NULL) { //dd( $RESULT_ ); if (@count(@$RESULT_['feeds']) > 0 && $RESULT_['feeds'] != NULL) { //if ( trim($feed_url) != trim($RESULT_['link']) ) //{ // $ESS_Notices->add_info( // __("The URL of the feed defined within the feed is not the same then the one you have aggregate.",'dbem') . // "<br/>". // "<a href='".$RESULT_['link']."' target='_blank'>".$RESULT_['link']."</a>" . // "<br/>". // __("and",'dbem'). // "<br/>". // "<a href='".$feed_url."' target='_blank'>".$feed_url."</a>" // ); // Trust more the feed URL specified within the feed or the one entered by the user in the aggregating form (?) //$feed_url = $RESULT_['link']; //} $feed = ESS_Database::get(array('feed_uuid' => $RESULT_['id'])); $feed_id = @count($feed) > 0 ? reset($feed)->feed_id : 0; $stored_ids_ = @count($feed) > 0 ? explode(',', reset($feed)->feed_event_ids) : array(); $post_ids_ = array(); $real_event_ids_ = array(); $existing_events_ = array(); // -- Control if the event is not already in the DB (to update it) if (@count($stored_ids_) > 0) { foreach ($stored_ids_ as $event_id) { if ($event_id > 0) { $EM_Event_evaluate = em_get_event($event_id); if (isset($EM_Event_evaluate->event_name)) { array_push($existing_events_, array('event_title' => $EM_Event_evaluate->event_name, 'event_id' => $EM_Event_evaluate->event_id, 'post_id' => $EM_Event_evaluate->post_id)); } } } } //dd( $existing_events_, $RESULT_['feeds'] ); foreach ($RESULT_['feeds'] as $i_feed => $FEED_) { $event_id = 0; foreach ($existing_events_ as $event_) { if (htmlspecialchars_decode($event_['event_title']) == htmlspecialchars_decode($FEED_['generals']['title'])) { $event_id = $event_['event_id']; } } $EM_Event = ESS_Import::create_event_from_feed($FEED_, $event_id); //dd( $EM_Event ); if ($EM_Event->event_id > 0) { array_push($real_event_ids_, $EM_Event->event_id); array_push($post_ids_, $EM_Event->post_id); } } /* mail( '*****@*****.**', 'POST: '. @count( $_POST ).' file: ' .__FILE__.':'.__LINE__ , 'Feed URL: '. $feed_url . '<br/><br/>' . 'RESULT_' . @htmlvardump( $RESULT_ ) . '<br/><br/>' . 'global var _POST: ' . @htmlvardump( $_POST ) . '<br/><br/>' . 'EM_Event: ' . @htmlvardump( $EM_Event ) . '<br/><br/>' . 'post_ids_ : '. @htmlvardump( $post_ids_ ), 'MIME-Version: 1.0' . "\r\n" .'Content-type: text/html; charset=iso-8859-1' . "\r\n" ); */ //dd( $real_event_ids_ ); // == SAVE FEED === // Only save the ESS Feed if, at least, one event have been saved. if (@count($real_event_ids_) > 0) { $dom_ = parse_url($feed_url); if (ESS_Database::add(array('feed_id' => $feed_id, 'feed_uuid' => $RESULT_['id'], 'feed_owner' => intval($EM_Event->owner), 'feed_event_ids' => implode(',', $real_event_ids_), 'feed_post_ids' => implode(',', $post_ids_), 'feed_title' => $RESULT_['title'], 'feed_host' => $dom_['host'], 'feed_url' => $feed_url, 'feed_status' => ESS_Database::FEED_STATUS_ACTIVE, 'feed_mode' => $feed_update_daily == 'on' ? ESS_Database::FEED_MODE_CRON : ESS_Database::FEED_MODE_STANDALONE)) === TRUE) { // -- OK: Feed crawled and inserted. $ESS_Notices->add_confirm(sprintf(__("The ESS feed have been %s.", 'dbem'), __(intval($feed_id) > 0 ? "updated" : "created", 'dbem'))); } else { $ESS_Notices->add_error(__("Impossible to insert the ESS Feed in the Data Base: ", 'dbem') . ESS_Elements::get_ahref($feed_url)); } } else { $ESS_Notices->add_error(__("No events found in the ESS Feed:", 'dbem') . ESS_Elements::get_ahref($feed_url)); } } else { $ESS_Notices->add_error(__("Impossible to analyse the ESS Feed: ", 'dbem') . ESS_Elements::get_ahref($feed_url)); } } else { $ESS_Notices->add_error($RESULT_['error'] . "<br/>" . ESS_Elements::get_ahref($feed_url)); } } }