<?php
/* This file is part of Madcollector.
* Madcollector created by Thomas Andrieu,
* Developped by Thomas Andrieu.
* Madcollector is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
* Madcollector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
function disable_magic_quotes()
{
if (get_magic_quotes_gpc()) {
$_SERVER = stripslashes_array($_SERVER);
$_GET = stripslashes_array($_GET);
$_POST = stripslashes_array($_POST);
$_COOKIE = stripslashes_array($_COOKIE);
$_FILES = stripslashes_array($_FILES);
$_ENV = stripslashes_array($_ENV);
$_REQUEST = stripslashes_array($_REQUEST);
$HTTP_SERVER_VARS = stripslashes_array($HTTP_SERVER_VARS);
$HTTP_GET_VARS = stripslashes_array($HTTP_GET_VARS);
$HTTP_POST_VARS = stripslashes_array($HTTP_POST_VARS);
$HTTP_COOKIE_VARS = stripslashes_array($HTTP_COOKIE_VARS);
$HTTP_POST_FILES = stripslashes_array($HTTP_POST_FILES);
$HTTP_ENV_VARS = stripslashes_array($HTTP_ENV_VARS);
if (isset($_SESSION)) { #These are unconfirmed (?)
$_SESSION = stripslashes_array($_SESSION, '');
$HTTP_SESSION_VARS = stripslashes_array($HTTP_SESSION_VARS, '');
}
}
}
function mad_echo($hookname,$content)
{
global $madPluginManager;
$beforehooktable = $madPluginManager->get_plugin_before_hook($hookname);
for($i=0;$i<sizeOf($beforehooktable);$i++)
{
$content = call_user_func($beforehooktable[$i], $content);
}
$hooktable = $madPluginManager->get_plugin_hook($hookname);
for($i=0;$i<sizeOf($hooktable);$i++)
{
$content = call_user_func($hooktable[$i], $content);
}
$afterhooktable = $madPluginManager->get_plugin_after_hook($hookname);
for($i=0;$i<sizeOf($afterhooktable);$i++)
{
$content = call_user_func($afterhooktable[$i], $content);
}
echo $content;
}
function use_globalfilters()
{
global $madPluginManager;
$globalfilters = $madPluginManager->get_globalfilters();
for($i=0;$i<sizeOf($globalfilters);$i++)
{
$content = ob_get_contents();
$content = call_user_func($globalfilters[$i],$content);
}
echo $content;
}
function mad_date($date)
{
$lang=$_SESSION['lang'];
if($date==null)
$date = time();
else $date = strtotime($date);
if($date=="") return "";
switch($lang)
{
case "fr" :
return date("d/m/Y",$date);
break;
default :
return date("F jS, Y",$date);
break;
}
}
function pagination($page, $redirect, $nbPages)
{
global $compteurpagination;
$compteurpagination++;
if(!($nbPages<1))
{
global $locales;
$content = '<form action="'.$redirect.'" method="GET" name="pagination_page_select'.$compteurpagination.'">'.$locales["Browse_Page"].": \n";
$get_keys = array_keys($_GET);
for($i=0;$i<sizeOf($get_keys);$i++)
{
if($get_keys[$i] !="page") $content .= "<input type=\"hidden\" name=\"".$get_keys[$i]."\" value=\"".$_GET[$get_keys[$i]]."\"/>";
}
$content.= '<select name="page" >.$compteurpagination.'.submit();">';
for($i = 0; $i<$nbPages; $i++)
{
$content.= "<option value=\"".($i+1)."\"";
if($page==($i+1)) $content.= ' selected="selected"';
$content.= ">".($i+1)."</option>";
}
$content .= '</select><input type="submit" name="pagination_page_submit" value="OK" style="display:none;"/></form>'."\n";
return $content;
}
}
function pagination_letter($redirect)
{
global $locales,$letter;
$content = '<form action="'.$redirect.'" method="GET" name="pagination_letter_select">'.$locales["Browse_Letter"].": \n";
$get_keys = array_keys($_GET);
for($i=0;$i<sizeOf($get_keys);$i++)
{
if($get_keys[$i] !="letter") $content .= "<input type=\"hidden\" name=\"".$get_keys[$i]."\" value=\"".$_GET[$get_keys[$i]]."\"/>";
}
$content.= '<select name="letter" >;
$content.= "<option value=\"%\"";
if($letter=="[0-9]") $content.= ' selected="selected"';
$content.=">#</option>";
for($i='A';$i!="AA"; $i++)
{
$content.= "<option value=\"".$i."\"";
if(strtoupper($letter)==$i) $content.= ' selected="selected"';
$content.= ">".$i."</option>";
}
$content.= "<option value=\".\"";
if($letter==".") $content.= ' selected="selected"';
$content.=">".$locales["All"]."</option>";
$content .= '</select><input type="submit" name="pagination_letter_submit" value="OK" style="display:none;"/></form>'."\n";
return $content;
}
function display_items_per_page()
{
global $locales,$nbrEnregPage;
echo '<div id="form_nb_page"><form method="get" action="index.php">'.$locales["Items_Per_Page"].' : ';
foreach($_GET as $key=>$value)
if(($key != "page")&&($key != "enreg"))
echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
echo '<input type="text" name="enreg" value="'.$nbrEnregPage.'" size="3"/><input type="submit" name="submitEnreg" value="'.$locales["Send"].'"/></form></div>';
}
function parse_content($contenuXML,$tagName)
{
$retour = "";
$backup_retour = "";
if($contenuXML=="")
{
return "";
}
$dom = new DOMDocument();
if(!$dom->loadXML($contenuXML))
return "";
$noeuds = $dom->getElementsByTagName($tagName);
for($i=0; $i < $noeuds->length; $i++)
{
$noeud_loop = $noeuds->item($i);
if($noeud_loop->getAttribute("lang")==$_SESSION["lang"])
$retour = $noeud_loop->nodeValue;
if($noeud_loop->getAttribute("lang")=="en")
$backup_retour = $noeud_loop->nodeValue;
}
if($retour != "")
return $retour;
else return $backup_retour;
}
function addXML_content($contenuXML,$tagName,$rootName,$addValue)
{
$addValue = htmlspecialchars(nl2br($addValue));
$dom = new DOMDocument();
$node_found=false;
$my_encoding = mb_detect_encoding($addValue);
if($my_encoding != "UTF-8")
utf8_encode($addValue);
if($contenuXML != "")
{
if(!$dom->loadXML($contenuXML))
return $contenuXML;
$noeuds = $dom->getElementsByTagName($tagName);
$rootNodeList = $dom->getElementsByTagName($rootName);
$rootNode = $rootNodeList->item(0);
$node_found=false;
for($i=0; $i < $noeuds->length; $i++)
{
$noeud_loop = $noeuds->item($i);
if($noeud_loop->getAttribute("lang")==$_SESSION["lang"])
{
$noeud_loop->nodeValue = $addValue;
$node_found=true;
}
}
}
else
{
$node = $dom->createElement($rootName);
$rootNode = $dom->appendChild($node);
}
if(!$node_found)
{
$node = $dom->createElement($tagName,$addValue);
$new_node = $rootNode->appendChild($node);
$new_node->setAttribute("lang", $_SESSION["lang"]);
}
return $dom->saveXML();
}
function stripslashes_array($data) {
if (is_array($data)){
foreach ($data as $key => $value){
$data[$key] = stripslashes_array($value);
}
return $data;
}else{
return stripslashes($data);
}
}
function select_month($issue_month)
{
global $locales;
$retour = '<option value=""></option>\n';
foreach ($locales["months"] as $key => $value){
$retour .= '<option value="'.$key.'"';
if($issue_month==$key) $retour .= ' selected="selected"';
$retour .= '>'.$value.'</option>\n';}
return $retour;
}
function select_year($issue_year)
{
$retour = '<option value=""></option>\n';
$myYear=(date("Y")+1);
for ($i=1900;$i<$myYear;$i++){
$retour .= '<option value="'.$i.'"';
if($issue_year==$i) $retour .= ' selected="selected"';
$retour .= '>'.$i.'</option>\n';}
return $retour;
}
function mad_strip($input_text)
{
$temp = preg_replace ( array(
'@<script[^>]*?.*?</script>@siu',
'@<script[^>]*?.*?/>@siu',
'@<object[^>]*?.*?</object>@siu',
'@<embed[^>]*?.*?</embed>@siu',
'@<applet[^>]*?.*?</applet>@siu',
'@<noframes[^>]*?.*?</noframes>@siu',
'@<noscript[^>]*?.*?</noscript>@siu',
'@<form[^>]*?.*?</form>@siu',
'@<input[^>]*?.*?>@siu',
'@<noembed[^>]*?.*?</noembed>@siu',),
array(
'','', '', '', '', '', '', '', '', ''),$input_text
);
return $temp;
}
function get_languages(){
$languages = array();
if($fp = fopen("locales/lc.locales","r"))
{
while (!feof($fp))
{
$ligne = fgets($fp, 4096);
if (preg_match("/^(.+):(.+)$/", $ligne, $regs)) {
$languages[$regs[1]] = $regs[2];
}
}
fclose($fp);
}
return $languages;
}
function language_selector(){
global $lang, $locales;
echo '<form method="get" name="language_select" action="index.php">';
$get_keys = array_keys($_GET);
for($i=0;$i<sizeOf($get_keys);$i++)
{
if($get_keys[$i] != "lang")
echo "<input type=\"hidden\" name=\"".$get_keys[$i]."\" value=\"".$_GET[$get_keys[$i]]."\"/>";
}
echo '<select name="lang" label="'.$locales["Language"].'">';
if($fp = fopen("locales/lc.locales","r"))
{
while (!feof($fp))
{
$ligne = fgets($fp, 4096);
if (preg_match("/^(.+):(.+)$/", $ligne, $regs)) {
echo "<option value=\"".$regs[1]."\"";
if($regs[1]==$lang) echo " selected=\"selected\"";
echo ">".$regs[2]."</option>";
}
}
fclose($fp);
}
echo '</optgroup></select><input type="submit" value="OK" style="display:none;"/></form>';
}
function search_input(){
global $locales;
if(!isset($_GET["search"])) $_GET["search"] = "";
echo "<p>".$locales["Menu_Search"]." : </p>\n" ;
echo '<form method="get" action="index.php"><input type="text" name="search" value="'.$_GET["search"].'"/><input type="hidden" name="rub" value="search"/><input type="submit" value="'.$locales["Search"].'" class="submit"/></form>';
}
function vote_form($id_series,$issue,$id_story,$popularity,$votes)
{
global $locales;
echo '<div id="story_vote_'.$id_story.'"';
if((isset($_COOKIE["story_voted"][$id_series][$issue][$id_story]))&&(($_COOKIE["story_voted"][$id_series][$issue][$id_story]!="")))
echo ' class="voted"';
echo '>';
if($votes>0)
echo $locales["Popularity"]." : ".round(100*$popularity/$votes)."% (".$votes." ".$locales["Votes"].")";
if(((!isset($_COOKIE["story_voted"][$id_series][$issue][$id_story]))||(($_COOKIE["story_voted"][$id_series][$issue][$id_story]=="")))&&(isset($_SESSION['id_user'])))
{
if($votes>0)
echo "<br/>\n";
echo $locales["Vote"].' : <a href="javascript:story_vote(\''.$id_series.'\',\''.$issue.'\',\''.$id_story.'\',\'increase\')"><img alt="+" src="'.THEME.'/images/thumbsup.gif" style="border:0px;"/></a><a href="javascript:story_vote(\''.$id_series.'\',\''.$issue.'\',\''.$id_story.'\',\'decrease\')"><img alt="-" src="'.THEME.'/images/thumbsdown.gif" style="border:0px;"/></a>';
}
echo '</div>';
}
function create_thumbnail($file,$destination)
{
global $error_messages,$locales;
$tmp_file = $file['tmp_name'];
if( !is_uploaded_file($tmp_file) )
{
array_push($error_messages,$locales["ErrMsg_NoFile_Uploaded"]);
return;
}
$type_file = $file['type'];
if( !strstr($type_file, 'jpg') && !strstr($type_file, 'jpeg') && !strstr($type_file, 'bmp') && !strstr($type_file, 'gif') )
{
array_push($error_messages,$locales["ErrMsg_NoImage_File"]);
return;
}
// on copie le fichier dans le dossier de destination
$name_file = $file['name'];
$check_extensions = get_loaded_extensions();
if(in_array("gd",$check_extensions))
{
switch($type_file)
{
case "image/gif" :
$new_im=imagecreatefromgif($tmp_file);
break;
case "image/jpeg" :
$new_im=imagecreatefromjpeg($tmp_file);
break;
}
$nouvelle_image=imagecreatetruecolor(imagesx($new_im),imagesy($new_im));
imagecopyresized($nouvelle_image,$new_im,0,0,0,0,imagesx($new_im),imagesy($new_im),imagesx($new_im),imagesy($new_im));
imagejpeg($nouvelle_image,COVER.$destination);
// Start the thumbnail generation
$n_width=80; // Fix the width of the thumb nail image
$n_height=120; // Fix the height of the thumb nail image
$im=imagecreatefromjpeg(COVER.$destination);
$width=imagesx($im);
$height=imagesy($im);
$newimage=imagecreatetruecolor($n_width,$n_height);
imagecopyresized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
imagejpeg($newimage,PREVIEWCOVER.$destination);
}
// End of JPG thumbnail creation
}
?>