Code Snippets

Gallery 2 movie size fixing in bulk mode.

Author: 
Hossain Md. Reza Khan
Functionality: 

This is a small script to fix/update the movie size in gallery 2 project.

For security reason attached PHP files has .txt extension added. Please remove that before uploading to your server. OR, you can download the ZIPPED file 'gallerytools-v1.01.zip' and unzip them using any archiving utility like winzip/winrar/7zip.

Please note that, each time you have to clear the database cache after you run this script to update the movie size.

Language: 
PHP
Source Code: 
PHP Scripts are attached with this document. Look for them at the bottom of this article.
Please set the cofiguration values before using this script.
Both of the files has config variables.

g2_fixsize.php has following variables that needs to be set :
/**
 * Configuration
 * ==============================
 * Set your user name and password for current page.
 * 
 * Also update database information in the library file (g2_localibrary.php). 
 */
$USER_NAME = "Y0urUserName"; // User name to access this page functionality
$USER_PASSWORD = "pa88w0rd"; // Password for this username
 
$MOVIE_MIME_TYPE = "video/x-flv"; // set the mime type of the movie - FLV movie mime time is 'video/x-flv'
$FLASH_MOVIE_WIDTH  = 600; // Default width to be set
$FLASH_MOVIE_HEIGHT = 400; // Default height to be set
 
/* TABLE NAMES - Case Sensitive */
$DATA_ITEM_TABLE = "g2_DataItem"; // Please replace with your gallery data-item table name (with the prefix if used)
$MOVIE_ITEM_TABLE = "g2_MovieItem"; // Please replace with your gallery movie-item table name (with the prefix if used)


g2_fixsize.php has following variables that needs to be set (database related) :
/**
 * Database Config
 * -----------------------------
 * Please create a new user with only SELECT and UPDATE permission. (recommended but not necessary)
 * Set following values.
 */
$DATABASE_NAME = "userid_databasename"; // Name of your gallery2 database
$DATABASE_USER = "userid_username"; // Username of the database user who has access to the database
$DATABASE_PASS = "userdbpassword"; // Password for the above username
$DATABASE_HOST = "localhost"; // Host of database (usually it's `localhost`)
License: 
GPLv3 - http://www.gnu.org/licenses/gpl-3.0.txt
Free to use for any purposes.

Perl Utility Functions - Check integer, array item exists and more

Author: 
Hossain Md. Reza Khan
Functionality: 
These are some basic utility functions using perl.

Language: 
Perl
Source Code: 
# Utility Function
# Desc: To check if a value exists in the array of string elements.
# Param 1: value to check
# Param 2: array reference (where to check the value)
sub isExist($$) {
	my ($value, $array_ref) = @_;
	my $element;
	for $element (@{$array_ref}) {
		if($element eq $value){
			return 1;
		}
	}
	return 0;
} # end of function `isExist`
 
 
 
# Function Type: Utility
# Desc: Checks if passed parameter is a valid integer.
# Param 1: value to check
sub isValidID($){
	my $id = shift;
	if(defined $id && $id ne '')
	{
		if ($id =~ /^[1-9][0-9]*$/) {
	        return 1;
	    } else {
	        return 0;
	    }
	} else {
		return 0;
	}
} # end of isValidID()

Filter string before inserting to database.

Author: 
Hossain Md. Reza Khan
Functionality: 
This is a simple function which will filter any dangerous character from string before entering to database.

Sample Usage:

$sql = "INSERT INTO `comments` (`id`, `datetime`, `user_comment`) VALUES (NULL, '2006-11-09 11:13:56', '".prepareData($comment)."')";
 
// After that, execute the SQL query using your database function, eg
$status = mysql_query($sql);

 

Language: 
PHP
Source Code: 
/**
 * Prepade data for inserting to database or
 * other database related operation.
 *
 * @param string $textData 
 * @return string prepared text for database operation
 */
function prepareData($textData) {
	if (get_magic_quotes_gpc()) {
		// Magic Quote was ON - remove extra slashes
		$textData = stripslashes($textData);
	} else {
		// do nothing
	}
 
	// Prepare html data for database usage
	$preparedData = htmlentities($textData, ENT_QUOTES);
	return $preparedData;
}
License: 
Free for any purposes.

 

© Hossain Khan - Some rights reserved.
Creative Commons License This site is licensed under a Creative Commons Attribution-Noncommercial 2.5 License.