Problems with my Online Manga Viewer script

Discussion in 'HTML & Website Design' started by AntonyTycoon, Oct 22, 2010.

  1. #1
    I'm using the omv script on one of my sites but i'm unable to get it working since ive moved it to a new host, its working on my other sites but just not on this one. if anyone could help me with this please let me know, it should show up at www.fairytailepisode.com/manga

    ...........................................................................................
    Online Manga Viewer v1.4 (2008-10-13)
    -------------------


    History
    -------
    v1.4 (2008-10-13)
    - Added keyboard navigation feature.
    - Reduced page rendering time.
    v1.3 (2008-03-28)
    - Added chapter's title support.
    v1.2.1 (2008-02-04)
    - Added ability to automatically jump to the next chapter on the last page of the current chapter.
    v1.2 (2008-01-27)
    - Changed URL format.
    - Fixed border layout (it was not displayed in high resolutions).
    v1.1 (2008-01-07)
    - Improved CSS stylesheet.
    - Optimized the way of retreiving the list of uploaded mangas.
    - Fixed invalid XHTML code.
    - Cleaned up some PHP functions.
    v1.0 (2007-12-27)
    - Everything is new in this first version :)


    Requirements
    ------------
    - PHP version 4 or higher.
    - Apache Mod_Rewrite enabled.
    ..................................................................................

    Thanks for any help you can give me with this :)
     
    AntonyTycoon, Oct 22, 2010 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yeah, something is wrong. Checking the response header with Web Developer, it shows "500 Internal Server Error" at the end.
    
    Server: Apache
    X-Powered-By: PHP/5.2.14
    X-Pingback: http://www.fairytailepisode.com/xmlrpc.php
    Link: <http://wp.me/P12hXS-3M>; rel=shortlink
    Connection: close
    Content-Type: text/html; charset=UTF-8
    
    500 Internal Server Error
    
    Code (markup):
    Apache and PHP seem ok, so maybe mod_rewrite is not enabled. It could also be a problem with your .htaccess file, show us that if you can.
     
    Cash Nebula, Oct 22, 2010 IP
  3. AntonyTycoon

    AntonyTycoon Active Member

    Messages:
    235
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Options +FollowSymlinks
    
    RewriteEngine on
    
    RewriteRule ^mangas/([^/]+)/([^/]+)/$ - [F,L]
    RewriteRule ^mangas/([^/]+)/$ - [F,L]
    RewriteRule ^mangas(/?)$ - [F,L]
    
    RewriteRule ^([^/.]+)/([^/.]+)/([0-9]+)(/?)$ index.php?manga=$1&chapter=$2&page=$3 [L]
    RewriteRule ^([^/.]+)/([^/.]+)(/?)$ index.php?manga=$1&chapter=$2 [L]
    RewriteRule ^([^/.]+)(/?)$ index.php?manga=$1 [L]
    
    Code (markup):
    this is the .httaccess file hope it helps, thanks
     
    AntonyTycoon, Oct 22, 2010 IP
  4. damoolag

    damoolag Well-Known Member

    Messages:
    311
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Maybe the CONFIG file?
     
    damoolag, Oct 23, 2010 IP
  5. AntonyTycoon

    AntonyTycoon Active Member

    Messages:
    235
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Nope, its not that i checked that over 3 times, works fine.
     
    AntonyTycoon, Oct 24, 2010 IP
  6. damoolag

    damoolag Well-Known Member

    Messages:
    311
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #6
    please post the error/warning message here.
     
    damoolag, Oct 24, 2010 IP
  7. AntonyTycoon

    AntonyTycoon Active Member

    Messages:
    235
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #7
    Thats the thing, it just gives a 404 page error when you go to the directory where the manga should be. there are no warnings or errors to go on, im still not able to get it working and im getting quite a few emails off people missing the content, so i need to fix asap.
     
    AntonyTycoon, Oct 26, 2010 IP
  8. damoolag

    damoolag Well-Known Member

    Messages:
    311
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #8
    The problem is I can't solve something if I did not saw the code myself ^_^
     
    damoolag, Oct 26, 2010 IP
  9. AntonyTycoon

    AntonyTycoon Active Member

    Messages:
    235
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #9
    config.inc.php
    <?php
    
    // URL where the script is installed, it must end with a slash
    $omv_base_url = "http://www.fairytailepisode.com/manga/";
    
    // page title
    $omv_title = "Read Fairy Tail Manga Online For Free at FairytailEpisode.com";
    
    // supported image file types
    $omv_img_types = array("jpg", "jpeg", "png", "bmp", "gif");
    
    // chapters can be sorted by ascending or descending order
    $omv_chapters_sorting = SORT_ASC; // SORT_ASC or SORT_DESC
    
    // image auto-resizing
    $omv_img_resize = true; // true or false
    $omv_preferred_width = 800; // preferred width in pixels
    
    // stylesheet name
    $omv_theme = "default"; // theme's folder name
    
    ?>
    
    PHP:
    functions.inc.php
    <?php
    
    require_once("config.inc.php");
    
    
    function omv_encode($text) {
    	return str_replace(' ', '_', $text);
    }
    
    function omv_decode($encoded_text) {
    	return str_replace('_', ' ', $encoded_text);
    }
    
    function omv_get_mangas() {
    	$mangas = array();
    
    	$dirname = "mangas/";
    	$dir = @opendir($dirname);
    	if ($dir) {
    		while (($file = @readdir($dir)) !== false) {
    			if (is_dir($dirname . $file . '/') && ($file != ".") && ($file != "..")) {
    				$mangas[] = $file;
    			}
    		}
    		@closedir($dir);
    	}
    
    	sort($mangas);
    
    	return $mangas;
    }
    
    function omv_get_chapters($manga) {
    	global $omv_chapters_sorting;
    	$chapters = array();
    	$chapters_id = array();
    
    	$dirname = "mangas/$manga/";
    	$dir = @opendir($dirname);
    	if ($dir) {
    		while (($file = @readdir($dir)) !== false) {
    			if (is_dir($dirname . $file . '/') && ($file != ".") && ($file != "..")) {
    				$chapter = array();
    				$chapter["folder"] = $file;
    				$pos = strpos($file, '-');
    				if ($pos === false) {
    					$chapter["number"] = $file;
    				} else {
    					$chapter["number"] = trim(substr($file, 0, $pos - 1));
    					$chapter["title"] = trim(substr($file, $pos + 1));
    				}
    
    				$chapters_id[] = $chapter["number"];
    
    				$chapters[] = $chapter;
    			}
    		}
    		@closedir($dir);
    	}
    
    	array_multisort($chapters_id, $omv_chapters_sorting, $chapters);
    
    	return $chapters;
    }
    
    function omv_get_chapter_index($chapters, $chapter_number) {
    	$i = 0;
    	while (($i < count($chapters)) && ($chapters[$i]["number"] != $chapter_number)) $i++;
    
    	return ($i < count($chapters)) ? $i : -1;
    }
    
    function omv_get_pages($manga, $chapter) {
    	global $omv_img_types;
    	$pages = array();
    
    	$dirname = "mangas/$manga/$chapter/";
    	$dir = @opendir($dirname);
    	if ($dir) {
    		while (($file = @readdir($dir)) !== false) {
    			if (!is_dir($dirname . $file . '/')) {
    				$file_extension = strtolower(substr($file, strrpos($file, ".") + 1));
    				if (in_array($file_extension, $omv_img_types)) {
    					$pages[] = $file;
    				}
    			}
    		}
    		@closedir($dir);
    	}
    
    	sort($pages);
    
    	return $pages;
    }
    
    function omv_get_previous_page($manga_e, $chapter_number_e, $current_page, $previous_chapter) {
    	if ($current_page > 1) {
    		return $manga_e . '/' . $chapter_number_e . '/' . ($current_page - 1);
    	} else if ($previous_chapter) {
    		$pages = omv_get_pages(omv_decode($manga_e), $previous_chapter["folder"]);
    		return $manga_e . '/' . omv_encode($previous_chapter["number"]) . '/' . count($pages);
    	} else {
    		return null;
    	}
    }
    
    function omv_get_next_page($manga_e, $chapter_number_e, $current_page, $nb_pages, $next_chapter) {
    	if ($current_page < $nb_pages) {
    		return $manga_e . '/' . $chapter_number_e . '/' . ($current_page + 1);
    	} else if ($next_chapter) {
    		return $manga_e . '/' . omv_encode($next_chapter["number"]);
    	} else {
    		return null;
    	}
    }
    
    function omv_get_image_size($img) {
    	global $omv_img_resize, $omv_preferred_width;
    	$size = array();
    
    	$imginfo = getimagesize($img);
    	$size["width"] = intval($imginfo[0]);
    	$size["height"] = intval($imginfo[1]);
    
    	if ($omv_img_resize) {
    		if ($size["width"] > $omv_preferred_width) {
    			$size["height"] = intval($size["height"] * ($omv_preferred_width / $size["width"]));
    			$size["width"] = $omv_preferred_width;
    		}
    	}
    
    	return $size;
    }
    
    ?>
    
    PHP:
    index.php
    <?php
    
    require_once("config.inc.php");
    require_once("functions.inc.php");
    
    
    $theme = $omv_theme;
    
    $manga = null;
    $manga_escaped = null;
    
    $chapter = null;
    $chapter_number = null;
    $chapter_number_escaped = null;
    $previous_chapter = null;
    $next_chapter = null;
    
    $page = null;
    
    $description = "";
    $title = $omv_title;
    
    $mangas = omv_get_mangas();
    if (isset($_GET["manga"])) {
    	$manga_title = omv_decode($_GET["manga"]);
    	if (in_array($manga_title, $mangas)) {
    		$manga = $manga_title;
    		$manga_escaped = $_GET["manga"];
    	}
    }
    
    if ($manga) {
    	$description = "Read " . $manga . " Manga Online";
    	$title .= " - " . $manga;
    
    	$chapters = omv_get_chapters($manga);
    	if (isset($_GET["chapter"])) {
    		$chapter_number = omv_decode($_GET["chapter"]);
    		$index = omv_get_chapter_index($chapters, $chapter_number);
    		if ($index != -1) {
    			$chapter = $chapters[$index];
    			$chapter_number_escaped = $_GET["chapter"];
    			if ($omv_chapters_sorting == SORT_ASC) {
    				if ($index > 0) {
    					$previous_chapter = $chapters[$index - 1];
    				}
    				if ($index < (count($chapters) -  1)) {
    					$next_chapter = $chapters[$index + 1];
    				}
    			} else {
    				if ($index < (count($chapters) -  1)) {
    					$previous_chapter = $chapters[$index + 1];
    				}
    				if ($index > 0) {
    					$next_chapter = $chapters[$index - 1];
    				}
    			}
    		}
    	} else {
    		$chapter = $chapters[0];
    		$chapter_number = $chapters[0]["number"];
    		$chapter_number_escaped = omv_encode($chapter_number);
    		
    		if (count($chapters) > 1) {
    			if ($omv_chapters_sorting == SORT_ASC) {
    				$next_chapter = $chapters[1];
    			} else {
    				$previous_chapter = $chapters[1];
    			}
    		}
    	}
    
    	if ($chapter) {
    		$pages = omv_get_pages($manga, $chapter["folder"]);
    		if (isset($_GET["page"])) {
    			$_page = intval($_GET["page"]);
    			if (($_page >= 1) && ($_page <= count($pages))) {
    				$page = $_page;
    			}
    		} else if (count($pages) > 0) {
    			$page = 1;
    		}
    
    		$title .= " - Chapter " . $chapter_number;
    
    		if ($page) {
    			$title .= " - Page " . $page;
    		}
    	}
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    
    <head>
    <base href="<?php echo $omv_base_url ?>" />
    <meta name="Keywords" content="<?php echo str_replace(' ', ',', $description) ?>" />
    <meta name="Description" content="<?php echo $description ?>" />
    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
    <meta http-equiv="Content-Language" content="en" />
    <title><?php echo $title ?></title>
    <link rel="stylesheet" href="themes/<?php echo $theme ?>/omv.css" type="text/css" media="screen" />
    
    <script type="text/javascript">
    function change_manga(manga) {
    	if (manga != 0) {
    		document.location = "<?php echo $omv_base_url ?>" + manga;
    	}
    }
    
    function change_chapter(manga, chapter) {
    	if (manga != 0) {
    		document.location = "<?php echo $omv_base_url ?>" + manga + "/" + chapter;
    	}
    }
    
    function change_page(manga, chapter, page) {
    	if (manga != 0) {
    		document.location = "<?php echo $omv_base_url ?>" + manga + "/" + chapter + "/" + page;
    	}
    }
    </script>
    
    </head>
    
    <body>
    
    <div id="omv">
    
    <table>
    <tr class="line">
    <td class="up_left"><img src="themes/<?php echo $theme ?>/spacer.gif" alt="" /></td>
    <td class="up"></td>
    <td class="up_right"><img src="themes/<?php echo $theme ?>/spacer.gif" alt="" /></td>
    </tr>
    <tr>
    <td class="mid_left"></td>
    <td class="mid">
    <table>
    <tr>
    <td>
    <?php
    $omv_pager = "";
    
    $omv_pager .= "<div class=\"pager\">\n";
    
    $omv_pager .= "<span>Manga <select name=\"manga\" onchange=\"change_manga(this.value)\">";
    $omv_pager .= "<option value=\"0\">Select Manga Title...</option>";
    for ($i = 0; $i < count($mangas); $i++) {
    	$m = $mangas[$i];
    	$omv_pager .= "<option value=\"" . omv_encode($m) . "\"" . (($m == $manga) ? " selected=\"selected\"" : "") . ">" . $m . "</option>";
    }
    $omv_pager .= "</select></span>\n";
    
    if ($manga) {
    	if ($chapter) {
    		$omv_pager .= "<span>Chapter <select name=\"chapter\" onchange=\"change_chapter('$manga_escaped', this.value)\">";
    		for ($i = 0; $i < count($chapters); $i++) {
    			$cnumber = $chapters[$i]["number"];
    			$omv_pager .= "<option value=\"" . omv_encode($cnumber) . "\"" . (($cnumber == $chapter_number) ? " selected=\"selected\"" : "") . ">" . $cnumber . (isset($chapters[$i]["title"]) ? (" - " . $chapters[$i]["title"]) : "") . "</option>";
    		}
    		$omv_pager .= "</select></span>\n";
    
    		if ($page) {
    			$prevhtml = "";
    			if ($page <= 1) {
    				$prevhtml = "<img src=\"themes/$theme/no-previous.png\" alt=\"\" />";
    			} else {
    				$prevhtml = "<a href=\"$manga_escaped/$chapter_number_escaped/" . ($page - 1) . "\"><img src=\"themes/$theme/previous.png\" alt=\"Previous Page\" title=\"Previous Page\" /></a>";
    			}
    			$nexthtml = "";
    			if ($page >= count($pages)) {
    				$nexthtml = "<img src=\"themes/$theme/no-next.png\" alt=\"\" />";
    			} else {
    				$nexthtml = "<a href=\"$manga_escaped/$chapter_number_escaped/" . ($page + 1) . "\"><img src=\"themes/$theme/next.png\" alt=\"Next Page\" title=\"Next Page\" /></a>";
    			}
    
    			$omv_pager .= "<span>$prevhtml Page <select name=\"page\" onchange=\"change_page('$manga_escaped', '$chapter_number_escaped', this.value)\">";
    			for ($p = 1; $p <= count($pages); $p++) {
    				$omv_pager .= "<option value=\"" . $p . "\"" . (($p == $page) ? " selected=\"selected\"" : "") . ">#" . $p . "</option>";
    			}
    			$omv_pager .= "</select> of " . count($pages) . " $nexthtml</span>\n";
    		}
    	}
    }
    
    $omv_pager .= "</div>\n";
    
    echo $omv_pager;
    ?>
    </td>
    </tr>
    <tr>
    <td>
    <div class="ads">
    <!-- Begin Advertisement -->
    <img src="ads.png" alt="Ads" width="468" height="60" />
    <!-- End Advertisement -->
    </div>
    </td>
    </tr>
    <tr>
    <td><?php
    if ($manga) {
    	if ($chapter) {
    		if ($page) {
    			$img = "mangas/" . $manga . "/" . $chapter["folder"] . "/" . $pages[$page - 1];
    			$imgsize = omv_get_image_size($img);
    			$imghtml = "<img src=\"$img\" alt=\"\" width=\"" . $imgsize["width"] . "\" height=\"" . $imgsize["height"] . "\" class=\"picture\" />";
    			
    			$prev_page_path = omv_get_previous_page($manga_escaped, $chapter_number_escaped, $page, $previous_chapter);
    			$next_page_path = omv_get_next_page($manga_escaped, $chapter_number_escaped, $page, count($pages), $next_chapter);
    			
    			if ($next_page_path) {
    				$imghtml = "<a href=\"$next_page_path\">" . $imghtml . "</a>";
    			}
    			echo $imghtml;
    		} else {
    			echo "<div class=\"warn\">There is no selected page!</div>";
    		}
    	} else {
    		echo "<div class=\"warn\">There is no selected chapter!</div>";
    	}
    } else {
    	echo "<div class=\"warn\">Select a manga title to get started!</div>";
    }
    ?></td>
    </tr>
    <?php
    if ($manga && $chapter && $page) {
    ?>
    <tr>
    <td>
    <div class="ads">
    <!-- Begin Advertisement -->
    <img src="ads.png" alt="Ads" width="468" height="60" />
    <!-- End Advertisement -->
    </div>
    <script type="text/javascript">
    function omvKeyPressed(e) {
    	var keyCode = 0;
    	
    	if (navigator.appName == "Microsoft Internet Explorer") {
    		if (!e) {
    			var e = window.event;
    		}
    		if (e.keyCode) {
    			keyCode = e.keyCode;
    			if ((keyCode == 37) || (keyCode == 39)) {
    				window.event.keyCode = 0;
    			}
    		} else {
    			keyCode = e.which;
    		}
    	} else {
    		if (e.which) {
    			keyCode = e.which;
    		} else {
    			keyCode = e.keyCode;
    		}
    	}
    	
    	switch (keyCode) {
    <?php
    if ($prev_page_path) {
    ?>
    		case 37:
    		window.location = "<?php echo $omv_base_url . $prev_page_path ?>";
    		return false;
    		
    <?php
    }
    if ($next_page_path) {
    ?>
    		case 39:
    		window.location = "<?php echo $omv_base_url . $next_page_path ?>";
    		return false;
    		
    <?php
    }
    ?>
    		default:
    		return true;
    	}
    }
    document.onkeydown = omvKeyPressed;
    </script>
    </td>
    </tr>
    <tr>
    <td>
    <?php
    echo $omv_pager;
    ?>
    </td>
    </tr>
    <?php
    } else {
    ?>
    <tr>
    <td><br /></td>
    </tr>
    <?php
    }
    ?>
    </table>
    </td>
    <td class="mid_right"></td>
    </tr>
    <tr class="line">
    <td class="down_left"></td>
    <td class="down"></td>
    <td class="down_right"></td>
    </tr>
    </table>
    
    </div>
    
    <div class="w3c">
    <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid XHTML 1.1" width="88" height="31" /></a> 
    <a href="http://jigsaw.w3.org/css-validator/check?uri=referer"><img src="http://www.w3.org/Icons/valid-css.png" alt="Valid CSS 2.1" width="88" height="31" /></a> 
    </div>
    
    </body>
    
    </html>
    
    PHP:
    Thats pretty much all of the coding for the script, its installed at /manga, i just fail to see a problem myself.
     
    AntonyTycoon, Oct 26, 2010 IP
  10. damoolag

    damoolag Well-Known Member

    Messages:
    311
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #10
    I check the code and their ok. 404 Errors means it can't find the requested file/folder, I think the .htaccess is the one responsible.
     
    damoolag, Oct 27, 2010 IP
  11. AntonyTycoon

    AntonyTycoon Active Member

    Messages:
    235
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #11
    ive tried replacing the files of the htaccess script with fresh a fresh install and it doesnt make a difference, really cant se whats up with it lol
     
    AntonyTycoon, Oct 27, 2010 IP