<?php
require('configure.php');
require('db.php');

function in_2d_array($mixed_needle, $arr_haystack, $str_key)
{
	foreach( $arr_haystack as $n=>$arr_row )
	{
		if( $arr_row[$str_key] == $mixed_needle )
			return $n;
	}

	return false;
}

function process_quotes($static_str_input_string)
{
	return trim(str_replace('\'', '&#039;', str_replace('"', '&quot;', $static_str_input_string)));
}

function remove_quotes($static_str_input_string)
{
	return trim(str_replace('"', '', str_replace("'", '', $static_str_input_string)));
}

function check_gif_animated($static_str_img_file_name)
{
	if( !( $handle_file = @fopen($static_str_img_file_name, 'rb') ) )
        return false;

    //an animated gif contains multiple "frames", with each frame having a
    //header made up of:
    // * a static 4-byte sequence (\x00\x21\xF9\x04)
    // * 4 variable bytes
    // * a static 2-byte sequence (\x00\x2C)

    // We read through the file til we reach the end of the file, or we've found
    // at least 2 frame headers

    $uint_count = 0;
	$arr_matches = array();

    while( !feof($handle_file) && $uint_count < 2 )
	{
        $str_chunk = fread($handle_file, 1024 * 100); //read 100kb at a time
        $uint_count+=preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $str_chunk, $arr_matches);
    }

    fclose($handle_file);

	if( $uint_count > 1 )
		return true;
	else
		return false;
}
?>