<th> <?php eps_get_ordered_filter('url_to', 'Redirect To'); ?> </th> <th class="redirect-small"> <?php eps_get_ordered_filter('count', 'Hits'); ?> </th> <th class="redirect-actions">Actions</th> </tr> <tr id="eps-redirect-add" style="display:none"><td colspan="5"><a href="#" id="eps-redirect-new"><span>+</span></a></td></tr> <?php echo EPS_Redirects::get_inline_edit_entry(); echo EPS_Redirects::list_redirects(); ?> </table> <div class="right"> <?php do_action('eps_redirects_panels_right'); ?> </div> <div class="left"> <?php do_action('eps_redirects_panels_left'); ?> </div> </div>
/** * * _upload * * This function handles the upload of CSV files, in accordance to the upload method specified. * * @return html string * @author epstudios * */ private function _upload() { $new_redirects = array(); $counter = array('new' => 0, 'updated' => 0, 'skipped' => 0, 'errors' => 0, 'total' => 0); $mimes = array('text/csv', 'text/tsv', 'text/plain', 'application/csv', 'text/comma-separated-values', 'application/excel', 'application/vnd.ms-excel', 'application/vnd.msexcel', 'text/anytext', 'application/octet-stream', 'application/txt'); ini_set('auto_detect_line_endings', TRUE); if (!in_array($_FILES['eps_redirect_upload_file']['type'], $mimes)) { $this->add_admin_message(sprintf("WARNING: Not a valid CSV file - the Mime Type '%s' is wrong! No new redirects have been added.", $_FILES['eps_redirect_upload_file']['type']), "error"); return false; } // open the file. if (($handle = fopen($_FILES['eps_redirect_upload_file']['tmp_name'], "r")) !== FALSE) { $counter['total'] = 1; while (($redirect = fgetcsv($handle, 0, ",")) !== FALSE) { $redirect = array_filter($redirect); if (empty($redirect)) { continue; } $args = count($redirect); if ($args > 4 || $args < 2) { // Bad line. Too many/few arguments. $this->add_admin_message(sprintf("WARNING: Encountered a badly formed entry in your CSV file on line %d (we skipped it).", $counter['total']), "error"); $counter['errors']++; continue; } $status = isset($redirect[0]) ? $redirect[0] : false; $url_from = isset($redirect[1]) ? $redirect[1] : false; $url_to = isset($redirect[2]) ? $redirect[2] : false; $count = isset($redirect[3]) ? $redirect[3] : false; switch (strtolower($status)) { case '404': $status = 404; break; case '302': $status = 302; break; case 'off': case 'no': case 'inactive': $status = 'inactive'; break; default: $status = 301; break; } // If the user supplied a post_id, is it valid? If so, use it! if ($url_to && ($post_id = url_to_postid($url_to))) { $url_to = $post_id; } // new redirect! $new_redirect = array('id' => false, 'url_from' => $url_from, 'url_to' => $url_to, 'type' => is_numeric($url_to) ? 'post' : 'url', 'status' => $status, 'count' => $count); array_push($new_redirects, $new_redirect); $counter['total']++; } fclose($handle); // close file. } if ($new_redirects) { $save_redirects = array(); foreach ($new_redirects as $redirect) { // Decide how to handle duplicates: switch (strtolower($_POST['eps_redirect_upload_method'])) { case 'skip': if (!EPS_Redirects::redirect_exists($redirect)) { $save_redirects[] = $redirect; $counter['new']++; } else { $counter['skipped']++; } break; case 'update': if ($entry = EPS_Redirects::redirect_exists($redirect)) { $redirect['id'] = $entry->id; $counter['updated']++; $save_redirects[] = $redirect; } else { $save_redirects[] = $redirect; $counter['new']++; } break; default: $save_redirects[] = $redirect; $counter['new']++; break; } } if (!empty($save_redirects)) { EPS_Redirects::_save_redirects($save_redirects); } $this->add_admin_message(sprintf("SUCCCESS: %d New Redirects, %d Updated, %d Skipped, %d Errors. (Attempted to import %d redirects).", $counter['new'], $counter['updated'], $counter['skipped'], $counter['errors'], $counter['total']), "updated"); } else { $this->add_admin_message("WARNING: Something's up. No new redirects were added, please review your CSV file.", "error"); } ini_set('auto_detect_line_endings', FALSE); }