All pastes #2047717 Raw Edit

mr. Lambert

public php v1 · immutable
#2047717 ·published 2011-04-18 11:45 UTC
rendered paste body
<?phpclass VRoom{    public function __construct(){    }    /**     * Installs textures, objects or meshes, depending on the type specified     *     * @param   array $arrTextures     * @param   int   $clientId     * @param   int   $intType = 0(texture), 1(mesh), 2(object)     *     * @return boolean     */    public function installTextures( $arrTextures, $clientId, $intType ){        $arrTextures = (!is_array( $arTextures ) ? array() : $arrTextures );        if(!ctype_digit($clientId)){            die('Invalid Client Id');        }        switch ($intType){            case 0:                $sqlLoc = 'textures';                $insName = 'textureName';                $insLoc = 'textureLoc';                break;            case 1:                $sqlLoc = 'mesh';                $insName = 'meshName';                $insLoc = 'meshLoc';                break;            case 2:                $sqlLoc = 'objects';                $insName = 'objName';                $insLoc = 'objLoc';                break;            default:;        }        $blOut = false;        foreach($arrTextures as $strTexture => $strLocation){            $strSql = mysql_query(sprintf(                            'INSERT INTO `%s`                                (`%s`,`%s`)                             VALUES                                ( \'%s\',\'%s\')                             WHERE `client_id`=%d',                        $sqlLoc,                        $insName,                        $insLoc,                        $strTexture,                        $strLocation,                        $clientId));            //Change the .jpg to the Mesh/Texture file            $strPattern = '#([A-Za-z0-9_-]*.?)\.jpg/#si';            if(preg_match($strPattern, $strTextureName, $arrMatches)){                if(is_file($arrMatches[0])){                    return true;                }else{                   die($strTextureName . ' is an invalid file');                }            }            //If installed, echo Installed [TextureName] + return true            if($strSql){                printf('Installed %s', $strTexture);                $blOut = true;            }else{                die('An Error Occured:'. "\n\r" . mysql_error() . "\n\r Or the location was incorrect");            }        }        //Speed things up        unset( $strSql, $strPattern, $strLocation, $strTexture, $arrTextures );        return $blOut;    }    /**     * Retrieves the textures from the database according to the limit, Client ID and type     *     * @param int $intLimit     * @param int $clientId     * @param int $intType     *     * @return array     */    protected function getTextures( $intLimit, $clientId, $intType ){        if(!ctype_digit($intLimit)){            $intLimit = 0;        }        $arrOut = array();        switch ($intType){            case 0:                $sqlLoc = 'textures';                $insName = 'textureName';                $insLoc = 'textureLoc';                break;            case 1:                $sqlLoc = 'mesh';                $insName = 'meshName';                $insLoc = 'meshLoc';                break;            case 2:                $sqlLoc = 'objects';                $insName = 'objName';                $insLoc = 'objLoc';                break;            default:;        }                $strSql = mysql_query(sprintf(                    'SELECT `%s`,`%s`                     FROM `%s`                     INNER JOIN `textures` on `textures`.`clientId` = `mesh`.`clientId`                     INNER JOIN `objects` on `objects`.clientId` = `textures`.`clientId`                     ORDER BY `textures`.`textureId` DESC                     WHERE `clientId` = %d                     LIMIT %d',                $insName,                $insLoc,                $sqlLoc,                $clientId,                $intLimit));        while($arrRow = mysql_fetch_assoc($strSql)){            foreach($arrRow as $strRow){                $arrOut['textureName'] = $strRow['textureLoc'];            }        }        //Loads the next function with populated results        $this->loadTextures( $arrOut );    }    /**     * Gets the textures so can be AJAX'd     *     * @param array $arrTextures     * @return boolean     */    public function loadTextures( $arrTextures ){        $blOut = false;        //Makes sure the textures are loaded as an array        $arrTextures = ( !is_array($arrTextures) ? array() : $arrTextures );                    foreach($arrTextures as $strTextureName => $strLocation){                        //change jpg to texture format <-- Don't you just love regex xD            $strPattern = '#([A-Za-z0-9_-]*.?)\.jpg/#si';            if(preg_match($strPattern, $strTextureName, $arrMatches)){                if(is_file($arrMatches[0])){                    return true;                }else{                   die($strTextureName . ' is an invalid file');                }                            }           }                //Speed things up        unset( $arrTextures, $strTextureName, $strLocation, $strPattern );                return $blOut;            }}?>