From 136dad5a15dcdfe334947c8de962846da407ecf1 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Sat, 4 Jun 2011 16:33:57 +0200 Subject: [PATCH] #3: supporting other filenames than index.html --- wordpress/plugins/owark/owark.php | 35 ++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/wordpress/plugins/owark/owark.php b/wordpress/plugins/owark/owark.php index b64bbb7..8a7b895 100644 --- a/wordpress/plugins/owark/owark.php +++ b/wordpress/plugins/owark/owark.php @@ -430,8 +430,8 @@ if (!class_exists("Owark")) { $home_url = home_url(); $loc = ""; - if( ($pos = strpos($link->arc_location, '/wp-content/plugins/owark/')) !== FALSE ) - $loc = substr($link->arc_location, $pos); + if( ($pos = strpos($link->arc_location, '/archives')) !== FALSE ) + $loc = '/wp-content/plugins/owark' . substr($link->arc_location, $pos); $arc_loc = home_url() . $loc; echo 'Open Web Archive archive of url}\">{$link->url}."; echo "
This snapshot has been taken on {$link->arc_date} for the website {$blog_title} which contains a link to this page and has saved a copy to be displayed in the page ever disappears."; echo '
'; - $file_location = '.'.$loc.'/index.html'; - $f = fopen($file_location, "r"); - echo fread($f, filesize($file_location)); - fclose($f); - echo '
'; - } + + $dir = opendir('.'.$loc); + $filename = false; + while (false !== ($file = readdir($dir))) { + if ('.html' === substr($file, strlen($file) - 5)) { + $filename = $file; + break; + } + } + closedir($dir); + + if ($filename) { + $file_location = '.'.$loc.'/' . $filename; + $f = fopen($file_location, "r"); + echo fread($f, filesize($file_location)); + fclose($f); + echo ''; + + } + } /** * Check if we've got something to archive @@ -478,7 +492,8 @@ if (!class_exists("Owark")) { if ($url != NULL) { $date = date('c'); - $path = dirname(__FILE__).'/archives/'. str_replace('%2F', '/', urlencode(preg_replace('/https?:\/\//', '', $url->final_url))) . '/' . $date; + $relpath = '/archives/'. str_replace('%2F', '/', urlencode(preg_replace('/https?:\/\//', '', $url->final_url))) . '/' . $date; + $path = dirname(__FILE__).$relpath; //mkdir($path, $recursive=true); $output = array(); @@ -490,7 +505,7 @@ if (!class_exists("Owark")) { 'url' => $url->final_url, 'status' => $status, 'arc_date' => $date, - 'arc_location' => $path)); + 'arc_location' => $relpath)); if ($occurrences > 0) { wp_schedule_single_event(time() + 90, 'owark_schedule_event', array('occurrences' => $occurrences - 1));