All pastes #637077 Raw Edit

Something

public text v1 · immutable
#637077 ·published 2007-07-28 14:47 UTC
rendered paste body
	
	// Update database from cache
	function update_db( $skin_id )
	{
		print 'In update DB function<br />';
		// Setup debugging
		$debug = '';
		// Check if cache directory exists
		if ( !is_dir ( SITE_ROOT . 'templates/' . $skin_id . '/cache/' ) )
		{
			// Check for debug mode
			if ( $this->conf['debug'] == 1 )
			{
				// No template directory, trigger error
				trigger_error( 'The template directory ' . SITE_ROOT . 'templates/' . $skin_id . '/cache/ does not exist.', E_USER_ERROR );
				// Return false
				return false;
			}
			else
			{
				// Return false
				return false;
			}
		}
		
		print 'Opening directory...<br />';
		// Open directory
		if ( $handle = opendir ( SITE_ROOT . 'templates/' . $skin_id . '/cache/' ) )
		{
			// Clear template tables
			//$empty = $this->system->DB->empty_table( 'template_bits' );
			//$empty = $this->system->DB->empty_table( 'template_sets' ); 
			// Loop through files in directory
			while ( false !== ( $file = readdir ( $handle ) ) ) 
			{
				// Check if filename contains skin_ and .php
				if ( ( strpos ( $file, 'skin_' ) !== false ) and ( strpos ( $file, '.php' ) !== false ) )
				{
					// Include file
					print 'Including ' . SITE_ROOT . 'templates/' . $skin_id . '/cache/' . $file . '<br />';
					if ( include_once ( SITE_ROOT . 'templates/' . $skin_id . '/cache/' . $file ) )
					{
						print 'File included.<br />';
						// Get class name
						$classname = str_replace( 'skin_', '', $file );
						$classname = str_replace( '.php', '', $classname );
						// Setup human readable name
						$hr_name = str_replace( '_', ' ', $classname );
						$hr_name = ucwords( $hr_name );
						$hr_name = str_replace( 'Acp', 'ACP', $hr_name );
						// Create template set
						print 'Creating template set: ' . $hr_name . '<br />';
						$this->create_template_set( $skin_id, $classname, $hr_name );
						// Get ID of last created template set
						$sql = $this->system->DB->build_select_query( 
													array ( 'id' ),
													array ( 'template_sets' ),
													array ( ),
													1,
													array ( 'id' => 'DESC' )
												  );
						// Query database
						$query = $this->system->DB->query( $sql );
						// Get data
						$data = $this->system->DB->return_data( $query );
						// Setup ID
						$set_id = $data['id'];
						// Setup array of template bits
						$bits = $this->$classname->bits;
						// Loop through array of template bits
						foreach ( $bits as $name => $hr_name )
						{
							// Get content
							$content = $this->$classname->$name();
							// Trim content
							$content = trim( $content );
							print 'Creating template bit: ' . $hr_name . '<br />';
							// Create template bit
							if ( ! $this->create_template_bit( '', $set_id, $name, $hr_name, $content ) )
							{
								//print 'Error setting up ' . $name . '<br />';
							}							
						}
					}
					else
					{	
						print 'Include failed.';
						// Show error
						if ( $this->conf['debug'] == '1' )
						{
							// Trigger error
							trigger_error( 'There was an error including the template file ' . SITE_ROOT . 'templates/' . $skin_id . '/cache/' . $file, E_USER_WARNING );
							// Return false
							return false;
						}
						else
						{
							// Return false
							return false;
						}
					}
				}
			}
		}
		else
		{
			// Check for debug mode
			if ( $this->conf['debug'] == 1 )
			{
				// Show error message
				trigger_error( 'Opening the directory ' . SITE_ROOT . 'templates/' . $skin_id . '/cache/ failed. Please check you have the correct permissions.', E_USER_NOTICE );
				// Return false
				return false;
			}
			else
			{
				// Return false
				return false;
			}
		}
		// Return true
		return true;
	}