0) { $newloc = lookupPDFArticle($cid); if ($newloc != null) { $newloc = "http://scholarworks.iu.edu/journals/index.php/imh/article/view/" . $newloc; header("Location: $newloc"); } } /** INDIVIDUAL PAGES SAMPLE PURL: http://purl.dlib.indiana.edu/iudl/imh/VAA4025-107-1?pn=007 SAMPLE PHP: http://scholarworks.iu.edu/imh_purl/redirect.php?redirect=VAA4025-107-1?pn=007 SAMPLE TARGET: http://purl.dlib.indiana.edu/iudl/imh/screen/VAA4025-107-1-007 */ elseif (strlen($pn > 0)) { $newloc = "http://purl.dlib.indiana.edu/iudl/imh/screen/" . $url . "-" . $pn; //echo "Will redirect to " . $newloc; //exit(); header("Location: $newloc"); } /** ARTICLE (XML download) SAMPLE PURL: http://purl.dlib.indiana.edu/iudl/imh/encodedtext/VAA4025-107-1-a01 SAMPLE PHP: http://scholarworks.iu.edu/imh_purl/redirect.php?redirect=encodedtext/VAA4025-107-1-a01 SAMPLE OJS TARGET: http://scholarworks.iu.edu/journals/index.php/imh/article/download/12591/18852 */ elseif ($pieces[0] == "encodedtext") { $newloc = lookupArticle($pieces[1]); if ($newloc != null) { $newloc = "http://scholarworks.iu.edu/journals/index.php/imh/article/download/" . $newloc; //echo "Will redirect to " . $newloc; //exit(); header("Location: $newloc"); } } /** ARTICLE XML VIEW SAMPLE PURL: http://purl.dlib.indiana.edu/iudl/imh/VAA4025-107-1-a01 SAMPLE PHP: http://scholarworks.iu.edu/imh_purl/redirect.php?redirect=VAA4025-107-1-a01 SAMPLE OJS TARGET: http://scholarworks.iu.edu/journals/index.php/imh/article/view/12591/18852 */ elseif (strlen($url) == 17) { $newloc = lookupArticle($url); if ($newloc != null) { $newloc = "http://scholarworks.iu.edu/journals/index.php/imh/article/view/" . $newloc; //echo "Will redirect to " . $newloc; //exit(); header("Location: $newloc"); } } //if all else fails, redirect to overall IMH site else { header("Location: http://scholarworks.iu.edu/journals/index.php/imh/"); //echo "Will redirect to http://scholarworks.iu.edu/journals/index.php/imh/" . $newloc; //exit(); } ?> REDIRECT FAILED $line) { $pieces = explode(",", htmlspecialchars($line)); if ($pieces[0] == $url) { return $pieces[1] . "/" . $pieces[2]; } } return null; } //given a string such as VAA4025-107-1-a01 return the OJS equivalent for the PDF article(ex: 12591/18852) function lookupPDFArticle($url) { //read csv file $lines = file('http://scholarworks.iu.edu/imh_purl/imh_article_redirects.csv'); foreach ($lines as $line_num => $line) { $pieces = explode(",", htmlspecialchars($line)); if ($pieces[0] == $url) { return $pieces[1] . "/" . $pieces[3]; } } return null; } function startsWith($haystack, $needle) { $length = strlen($needle); return (substr($haystack, 0, $length) === $needle); } ?>