// Update database from cache function update_db( $skin_id ) { // 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; } } // 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 if ( include_once ( SITE_ROOT . 'templates/' . $skin_id . '/cache/' . $file ) ) { // Get class name $classname = str_replace( 'skin_', '', $file ); $classname = str_replace( '.php', '', $classname ); // Setup class if ( ! $this->$classname = new $classname() ) { // Check debug status if ( $this->conf['debug'] == 1 ) { // Show error trigger_error( 'The class ' . $classname . ' could not be created.', E_USER_ERROR ); // Return false return false; } else { // Return false return false; } } // 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 $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 ); // Create template bit if ( ! $this->create_template_bit( '', $set_id, $name, $hr_name, $content ) ) { //print 'Error setting up ' . $name . '
'; } } } else { // 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; }