function actionDefault()
 {
     // Get the data
     $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost');
     $this->setVar('processList', $db->getRecords('show processlist'));
     $this->setVar('status', $db->getRecords('show status'));
     $this->setVar('variables', $db->getRecords('show variables'));
     $this->setVar('version', $db->getServerVersion());
     $this->setVar('sqlcount', $db->getSqlCount());
     // Output the template
     $this->outputTemplate();
     // Test string escaping
     YDDebugUtil::dump($db->string("Pieter's Framework"), '$db->string');
     // Test timestamps
     YDDebugUtil::dump($db->getDate(), 'getDate()');
     YDDebugUtil::dump($db->getTime(), 'getTime()');
     YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )');
     YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )');
     YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->sqlString($db->getDate()), 'sqlString( getDate() )');
     YDDebugUtil::dump($db->sqlString($db->getTime()), 'sqlString( getTime() )');
     YDDebugUtil::dump($db->sqlString($db->getDate('__NOW__')), 'sqlString( getDate( \'__NOW__\' ) )');
     YDDebugUtil::dump($db->sqlString($db->getTime('__NOW__')), 'sqlString( getTime( \'__NOW__\' ) )');
     // Test errors
     YDDebugUtil::dump($db->getRecords('xx'), 'should return error');
     // Close the database connection
     $db->close();
 }
 function actionDefault()
 {
     // Get the database connections
     $db1 = YDDatabase::getInstance('mysql', 'ydweblog', 'root', '', 'localhost');
     $db2 = YDDatabase::getInstance('oracle', 'creodb_directeur', 'prinergy', 'araxi');
     $db3 = YDDatabase::getInstance('postgres', 'test_db', 'postgres', 'Ster4484', 'localhost');
     $db4 = YDDatabase::getInstance('sqlite', 'db_metadata.db');
     // Get the metadata
     $db1_meta = new YDDatabaseMetaData($db1);
     $db2_meta = new YDDatabaseMetaData($db2);
     $db3_meta = new YDDatabaseMetaData($db3);
     $db4_meta = new YDDatabaseMetaData($db4);
     // Get the list of tables
     YDDebugUtil::dump($db1_meta->getTables(), 'mysql - getTables');
     YDDebugUtil::dump($db2_meta->getTables(), 'oracle - getTables');
     YDDebugUtil::dump($db3_meta->getTables(), 'postgres - getTables');
     YDDebugUtil::dump($db4_meta->getTables(), 'sqlite - getTables');
     // Get the list of fields for a table
     YDDebugUtil::dump($db1_meta->getFields('ydw_items'), 'mysql - getFields');
     YDDebugUtil::dump($db2_meta->getFields('dbcs_jacket'), 'oracle - getFields');
     YDDebugUtil::dump($db3_meta->getFields(), 'postgres - getFields');
     YDDebugUtil::dump($db4_meta->getFields('notes'), 'sqlite - getFields');
     // Get the list of indexes for a table
     YDDebugUtil::dump($db1_meta->getIndexes('ydw_items'), 'mysql - getIndexes');
     YDDebugUtil::dump($db2_meta->getIndexes('dbcs_jacket'), 'oracle - getIndexes');
     YDDebugUtil::dump($db3_meta->getIndexes(), 'postgres - getIndexes');
     YDDebugUtil::dump($db4_meta->getIndexes('notes'), 'sqlite - getIndexes');
 }
 function actionDefault()
 {
     // Get the data
     $db = YDDatabase::getInstance('sqlite', 'database2.db');
     // Output the server version
     YDDebugUtil::dump($db->getServerVersion(), 'Version:');
     // Output some queries
     YDDebugUtil::dump($db->getRecords('select * from escalations'), 'escalations');
     YDDebugUtil::dump($db->getRecords('select * from sqlite_master'), 'sqlite_master');
     YDConfig::set('YD_DB_FETCHTYPE', YD_DB_FETCH_NUM);
     YDDebugUtil::dump($db->getRecords('select * from sqlite_master'), 'array - sqlite_master');
     YDConfig::set('YD_DB_FETCHTYPE', YD_DB_FETCH_ASSOC);
     // Test string escaping
     YDDebugUtil::dump($db->string("Pieter's Framework"), '$db->string');
     // Show number of queries
     YDDebugUtil::dump($db->getSqlCount(), 'Number of queries');
     // Test timestamps
     YDDebugUtil::dump($db->getDate(), 'getDate()');
     YDDebugUtil::dump($db->getTime(), 'getTime()');
     YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )');
     YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )');
     YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->sqlString($db->getDate()), 'sqlString( getDate() )');
     YDDebugUtil::dump($db->sqlString($db->getTime()), 'sqlString( getTime() )');
     YDDebugUtil::dump($db->sqlString($db->getDate('__NOW__')), 'sqlString( getDate( \'__NOW__\' ) )');
     YDDebugUtil::dump($db->sqlString($db->getTime('__NOW__')), 'sqlString( getTime( \'__NOW__\' ) )');
     // Test limits
     YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10));
     YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10, 25));
     // Test errors
     YDDebugUtil::dump($db->getRecords('xx'), 'should return error');
     // Close the database connection
     $db->close();
 }
 function actionDefault()
 {
     // Get the data
     $db = YDDatabase::getInstance('postgres', 'template1', 'pieter', 'kermit', 'yellowduck');
     // Output the server version
     YDDebugUtil::dump($db->getServerVersion(), 'Version:');
     // Output some queries
     YDDebugUtil::dump($db->getRecords('select now()'), 'select now();');
     // Test string escaping
     YDDebugUtil::dump($db->string("Pieter's Framework"), '$db->string');
     // Show number of queries
     YDDebugUtil::dump($db->getSqlCount(), 'Number of queries');
     // Test timestamps
     YDDebugUtil::dump($db->getDate(), 'getDate()');
     YDDebugUtil::dump($db->getTime(), 'getTime()');
     YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )');
     YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )');
     YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->sqlString($db->getDate()), 'sqlString( getDate() )');
     YDDebugUtil::dump($db->sqlString($db->getTime()), 'sqlString( getTime() )');
     YDDebugUtil::dump($db->sqlString($db->getDate('__NOW__')), 'sqlString( getDate( \'__NOW__\' ) )');
     YDDebugUtil::dump($db->sqlString($db->getTime('__NOW__')), 'sqlString( getTime( \'__NOW__\' ) )');
     // Test limits
     YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10));
     YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10, 25));
     // Test errors
     YDDebugUtil::dump($db->getRecords('xx'), 'should return error');
     // Close the database connection
     $db->close();
 }
 function actionDefault()
 {
     // Get the data
     $db = YDDatabase::getInstance('oracle', 'CREODB_STATLER', 'prinergy_rpt', 'prinergy_rpt');
     // Output the server version
     YDDebugUtil::dump($db->getServerVersion(), 'Version:');
     // Output some queries
     YDDebugUtil::dump($db->getRecords('select * from RPT_Customer_V'), 'RPT_Customer_V');
     // Output some queries
     YDDebugUtil::dump($db->getValue('select sysdate from dual'), 'sysdate');
     // Test string escaping
     YDDebugUtil::dump($db->escape("Pieter's Framework"), '$db->escape');
     // Show number of queries
     YDDebugUtil::dump($db->getSqlCount(), 'Number of queries');
     // Test timestamps
     YDDebugUtil::dump($db->getDate(), 'getDate()');
     YDDebugUtil::dump($db->getTime(), 'getTime()');
     YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )');
     YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )');
     YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->escapeSql($db->getDate()), 'escapeSql( getDate() )');
     YDDebugUtil::dump($db->escapeSql($db->getTime()), 'escapeSql( getTime() )');
     YDDebugUtil::dump($db->escapeSql($db->getDate('__NOW__')), 'escapeSql( getDate( \'__NOW__\' ) )');
     YDDebugUtil::dump($db->escapeSql($db->getTime('__NOW__')), 'escapeSql( getTime( \'__NOW__\' ) )');
     // Test limits
     YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10));
     YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10, 25));
     // Test errors
     YDDebugUtil::dump($db->getRecords('xx'), 'should return error');
     // Close the database connection
     $db->close();
 }
 function actionDefault()
 {
     // Get the data
     $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost');
     $this->template->assign('processList', $db->getRecords('show processlist'));
     $this->template->assign('status', $db->getRecords('show status'));
     $this->template->assign('variables', $db->getRecords('show variables'));
     $this->template->assign('version', $db->getServerVersion());
     $this->template->assign('sqlcount', $db->getSqlCount());
     // Output the template
     $this->template->display();
     // Test string escaping
     YDDebugUtil::dump($db->escape("Pieter's Framework"), '$db->escape');
     YDDebugUtil::dump($db->prepareSql('SELECT * FROM comments WHERE id = :1 and author = :2', 1, "Pieter's Author"), '$db->prepareSql');
     // Test timestamps
     YDDebugUtil::dump($db->getDate(), 'getDate()');
     YDDebugUtil::dump($db->getTime(), 'getTime()');
     YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )');
     YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )');
     YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->escapeSql($db->getDate()), 'escapeSql( getDate() )');
     YDDebugUtil::dump($db->escapeSql($db->getTime()), 'escapeSql( getTime() )');
     YDDebugUtil::dump($db->escapeSql($db->getDate('__NOW__')), 'escapeSql( getDate( \'__NOW__\' ) )');
     YDDebugUtil::dump($db->escapeSql($db->getTime('__NOW__')), 'escapeSql( getTime( \'__NOW__\' ) )');
     // Test limits
     YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10));
     YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10, 30));
     // Test errors
     YDDebugUtil::dump($db->getRecords('xx'), 'should return error');
     // Close the database connection
     $db->close();
 }
 function actionDefault()
 {
     // Get the data
     $db = YDDatabase::getInstance('sqlite', 'database2.db');
     // Output the server version
     YDDebugUtil::dump($db->getServerVersion(), 'Version:');
     // Output some queries
     YDDebugUtil::dump($db->getRecords('select * from escalations'), 'escalations');
     YDDebugUtil::dump($db->getRecords('select * from sqlite_master'), 'sqlite_master');
     // Test string escaping
     YDDebugUtil::dump($db->string("Pieter's Framework"), '$db->string');
     // Show number of queries
     YDDebugUtil::dump($db->getSqlCount(), 'Number of queries');
     // Test timestamps
     YDDebugUtil::dump($db->getDate(), 'getDate()');
     YDDebugUtil::dump($db->getTime(), 'getTime()');
     YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )');
     YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )');
     YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )');
     YDDebugUtil::dump($db->sqlString($db->getDate()), 'sqlString( getDate() )');
     YDDebugUtil::dump($db->sqlString($db->getTime()), 'sqlString( getTime() )');
     YDDebugUtil::dump($db->sqlString($db->getDate('__NOW__')), 'sqlString( getDate( \'__NOW__\' ) )');
     YDDebugUtil::dump($db->sqlString($db->getTime('__NOW__')), 'sqlString( getTime( \'__NOW__\' ) )');
     // Test errors
     YDDebugUtil::dump($db->getRecords('xx'), 'should return error');
     // Close the database connection
     $db->close();
 }
 function database_backup()
 {
     $this->YDRequest();
     // Get the data
     $this->db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost');
     // Create the YDMysqlDump object
     $this->dump = new YDMysqlDump($this->db);
 }
 function database_tree()
 {
     // Call the parent
     $this->YDRequest();
     // Get the database connection
     $db = YDDatabase::getInstance('mysql', 'tree_test', 'root', '', 'localhost');
     // Get the tree instance
     $this->tree = new YDDatabaseTree($db, 'nested_tree');
 }
示例#10
0
 function index()
 {
     // Initialize the parent class
     $this->YDRequest();
     // Initialize the template object
     $this->template = new YDTemplate();
     // Make the database connection
     $this->db = YDDatabase::getInstance($GLOBALS['db']['type'], $GLOBALS['db']['name'], $GLOBALS['db']['user'], $GLOBALS['db']['pass'], $GLOBALS['db']['host']);
 }
 function database_objecttree()
 {
     // Call the parent
     $this->YDRequest();
     // Get the database connection
     $db = YDDatabase::getInstance('mysql', 'tree_test', 'root', '', 'localhost');
     // Get the tree instance
     $this->tree = new YDDatabaseObjectTree('nested_tree', $db);
     // register extra column
     $this->tree->registerField('title', true);
 }
 function YDWeblogAPI()
 {
     // Initialize the parent
     $this->YDBase();
     // Get the database connection
     $this->db = YDDatabase::getInstance('mysql', YDConfig::get('db_name', 'YDWeblog'), YDConfig::get('db_user', 'root'), YDConfig::get('db_pass', ''), YDConfig::get('db_host', 'localhost'));
     // Add any missing body_more field
     $fields = $this->db->getValuesByName('show fields from ' . YDConfig::get('db_prefix', '') . 'items', 'field');
     if (!in_array('body_more', $fields)) {
         $this->db->executeSql('ALTER TABLE ' . YDConfig::get('db_prefix', '') . 'items ADD body_more LONGTEXT AFTER body');
     }
 }
 function database_tree()
 {
     // Call the parent
     $this->YDRequest();
     // Get the database connection
     $db = YDDatabase::getInstance('mysql', 'tree_test', 'root', '', 'localhost');
     // Get the tree instance
     $this->tree = new YDDatabaseTree($db, 'nested_tree');
     // Add some fields
     $this->tree->addField('t2.category');
     // Add a join table
     $this->tree->addJoinTable('JOIN category t2 ON t1.cat_id = t2.id');
 }
 function actionDefault()
 {
     // Get the database connection
     $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost');
     // Get the records
     $recordset = $db->getRecords('show status');
     // Close the database connection
     $db->close();
     // Create the YDRecordSet object
     $recordset = new YDRecordSet($recordset, -1, null);
     // Setup the template
     $this->template->assign('recordset', $recordset);
     // Display the template
     $this->template->display();
 }
 function actionDefault()
 {
     // Check if the template is cached
     if (!$this->tpl->is_cached(YD_SELF_SCRIPT)) {
         // Make some extensive database calls
         $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost');
         $db->connect();
         $this->tpl->assign('processList', $db->getRecords('show processlist'));
         $this->tpl->assign('status', $db->getRecords('show status'));
         $this->tpl->assign('variables', $db->getRecords('show variables'));
         $this->tpl->assign('version', $db->getServerVersion());
         $this->tpl->assign('sqlcount', $db->getSqlCount());
         // Indicate the template was not cached
         echo 'not cached';
     }
     // Display the template
     $this->tpl->display('tplcache.tpl', YD_SELF_SCRIPT);
 }
 function actionDefault()
 {
     // Get the pagesize and current page from the query string
     $page = @$_GET['page'];
     $size = @$_GET['size'];
     // Get the database connection
     $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost');
     // Get the records
     $recordset = $db->getRecords('show status');
     // Close the database connection
     $db->close();
     // Create the YDRecordSet object
     $recordset = new YDRecordSet($recordset, $page, $size);
     // Setup the template
     $this->template->assign('recordset', $recordset);
     // Display the template
     $this->template->display();
 }
示例#17
0
 function index()
 {
     // Initialize the parent class
     $this->YDRequest();
     // Make the database connection
     $this->db = YDDatabase::getInstance($GLOBALS['db']['type'], $GLOBALS['db']['name'], $GLOBALS['db']['user'], $GLOBALS['db']['pass'], $GLOBALS['db']['host']);
     // Create the add form
     $this->form = new YDForm('addEntryForm');
     // Add the elements
     $this->form->addElement('text', 'notetitle', 'Title:');
     $this->form->addElement('textarea', 'notecontents', 'Contents:');
     $this->form->addElement('submit', '_cmdSubmit', 'Save');
     // Apply filters
     $this->form->addFilter('NoteTitle', 'trim');
     $this->form->addFilter('NoteContents', 'trim');
     // Add a rule
     $this->form->addRule('notetitle', 'required', 'Title is required');
     $this->form->addRule('notecontents', 'required', 'Contents is required');
 }
 function actionDefault()
 {
     // Get the pagesize and current page from the query string
     $page = @$_GET['page'];
     $size = @$_GET['size'];
     // Get the database connection
     $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost');
     // Get the records
     $recordset = $db->getRecordsAsSet('show status', $page, $size);
     // Alter the URL
     $url =& $recordset->getUrl();
     $url->setQueryVar('test', 'val');
     // Close the database connection
     $db->close();
     // Setup the template
     $this->template->assign('recordset', $recordset);
     // Display the template
     $this->template->display();
 }
 function YDWeblogAPI()
 {
     // Initialize the parent
     $this->YDBase();
     // Get the database connection
     $this->db = YDDatabase::getInstance('mysql', YDConfig::get('db_name', 'YDWeblog'), YDConfig::get('db_user', 'root'), YDConfig::get('db_pass', ''), YDConfig::get('db_host', 'localhost'));
     // Add any missing body_more field
     $fields = $this->db->getValuesByName('show fields from #_items', 'field');
     if (!in_array('body_more', $fields)) {
         $this->db->executeSql('ALTER TABLE #_items ADD body_more LONGTEXT AFTER body');
     }
     // Get the list of indexes
     $indexes = $this->db->getValuesByName('show keys from #_users', 'key_name');
     if (in_array('email', $indexes)) {
         $this->db->executeSql('ALTER TABLE #_users DROP INDEX email');
     }
     if (!in_array('name', $indexes)) {
         $this->db->executeSql('ALTER TABLE #_users ADD UNIQUE name (name)');
     }
 }
 function YDWeblogAPI()
 {
     // Initialize the parent
     $this->YDBase();
     // Get the database connection
     $this->db = YDDatabase::getInstance('mysql', YDConfig::get('db_name', 'YDWeblog'), YDConfig::get('db_user', 'root'), YDConfig::get('db_pass', ''), YDConfig::get('db_host', 'localhost'));
     // Get a link to the database metadata
     $this->dbmeta = new YDDatabaseMetaData($this->db);
     // Upgrade the schema if needed
     $this->upgradeSchemaIfNeeded();
     // The array that will hold the image metadata
     $this->imagemetadata = null;
     // Delete spam comments older than 7 days
     $sql = 'DELETE FROM #_comments WHERE is_spam = 1 AND created < (unix_timestamp()-604800)';
     $this->db->executeSql($sql);
     // Delete the old IP numbers from spam check
     $comment_interval = YDConfig::get('comment_interval', 10);
     if ($comment_interval != '' && is_numeric($comment_interval)) {
         $sql = 'DELETE FROM #_spamcheck WHERE lastvisit < (unix_timestamp()-' . $comment_interval . ')';
         $this->db->executeSql($sql);
     }
     // Cleanup the bad behaviour table part 1
     $sql = 'DELETE FROM #_bad_behavior WHERE DATE_SUB( `date`, INTERVAL 1 day ) < DATE_SUB( CURDATE(), INTERVAL 1 day ) AND request_method = \'GET\' AND `key` = \'00000000\'';
     $this->db->executeSql($sql);
     // Cleanup the bad behaviour table part 2
     $sql = 'DELETE FROM #_bad_behavior WHERE DATE_SUB( `date`, INTERVAL 7 day ) < DATE_SUB( CURDATE(), INTERVAL 7 day )';
     $this->db->executeSql($sql);
     // Check against akismet if a key is there
     if (YDConfig::get('akismet_key', '') != '') {
         // Include the YDAkismet addon
         include_once YD_DIR_HOME_ADD . '/YDAkismet/YDAkismet.php';
         // Get the URL of the weblog
         $weblog_url = dirname(YDRequest::getCurrentUrl(true)) . '/';
         // Initialize YDAkismet
         $this->akismet = new YDAkismet($weblog_url, YDConfig::get('akismet_key', ''));
     } else {
         // No akismet
         $this->akismet = null;
     }
 }
 function setDatabase()
 {
     $this->__db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost');
 }
 /**
  *  This function will return a YDDatabaseDriver instance for the named database instance. If no instance is
  *  given, the one with the name "default" will be used. You can use database instance objects too.
  *
  *  @param $name    (optional) The name or object of the database instance. Defaults to "default".
  *
  *  @returns    An instance of YDDatabaseDriver
  *
  *  @static
  */
 function getNamedInstance($name = 'default')
 {
     // Check if name is a YDDatabaseDriver object
     if (is_object($name)) {
         return $name;
     }
     // Check if the global array exists
     YDDatabase::_initNamedInstances();
     // Trigger an error if the named instance doesn't exist.
     if (!array_key_exists(strtolower($name), $GLOBALS['YD_DB_INSTANCES'])) {
         trigger_error('The named database instance "' . $name . '" is not defined.', YD_ERROR);
     }
     // Get the parameters
     $params = $GLOBALS['YD_DB_INSTANCES'][strtolower($name)];
     // Return the right named instance
     return YDDatabase::getInstance($params[0], $params[1], $params[2], $params[3], $params[4]);
 }
 function actionDefault()
 {
     // Check for the config file
     if (is_file(dirname(__FILE__) . '/include/config.php')) {
         $this->redirectToAction('error');
     }
     // Get the list of skins
     $dir = new YDFSDirectory(dirname(__FILE__) . '/' . $this->dir_skins);
     $items = $dir->getContents('!.*', '', array('YDFSDirectory'));
     $skins = array();
     foreach ($items as $item) {
         $skins[$item] = $item;
     }
     // Get the list of languages
     $dir = new YDFSDirectory(dirname(__FILE__) . '/include/languages/');
     $items = $dir->getContents('language_*.php', '', array('YDFSFile'));
     $languages = array();
     foreach ($items as $item) {
         $item = substr($item, 9, -4);
         $languages[$item] = $item;
     }
     // Create the configuration form
     $form = new YDForm('configForm');
     // Add the fields
     $form->addElement('text', 'db_host', 'Database host', array('class' => 'tfM'));
     $form->addElement('text', 'db_name', 'Database name', array('class' => 'tfM'));
     $form->addElement('text', 'db_user', 'Database user', array('class' => 'tfM'));
     $form->addElement('password', 'db_pass', 'Database password', array('class' => 'tfM'));
     $form->addElement('text', 'db_prefix', 'Database table prefix', array('class' => 'tfM'));
     $form->addElement('text', 'weblog_title', 'Weblog title', array('class' => 'tfM'));
     $form->addElement('text', 'weblog_description', 'Weblog description', array('class' => 'tfM'));
     $form->addElement('select', 'weblog_skin', 'Weblog skin', array('class' => 'tfM', 'style' => 'width: 100%'), $skins);
     $form->addElement('select', 'weblog_language', 'Weblog language', array('class' => 'tfM', 'style' => 'width: 100%'), $languages);
     $form->addElement('text', 'name', 'User name', array('class' => 'tfM'));
     $form->addElement('text', 'email', 'User email', array('class' => 'tfM'));
     $form->addElement('password', 'password', 'Password', array('class' => 'tfM'));
     $form->addElement('submit', '_cmdSubmit', 'Install', array('class' => 'button'));
     // Add the rules
     $form->addRule('db_host', 'required', 'Database host is required');
     $form->addRule('db_name', 'required', 'Database name is required');
     $form->addRule('db_user', 'required', 'Database user is required');
     $form->addRule('weblog_title', 'required', 'Weblog title is required');
     $form->addRule('name', 'required', 'User name is required');
     $form->addRule('email', 'email', 'User email is required');
     $form->addRule('password', 'required', 'Password is required');
     $form->addFormRule(array(&$this, 'checkInstallParams'));
     // Set the defaults
     $form->setDefault('db_host', 'localhost');
     $form->setDefault('db_name', 'ydweblog');
     $form->setDefault('db_user', 'root');
     $form->setDefault('db_prefix', 'ydw_');
     $form->setDefault('weblog_title', 'My Weblog');
     $form->setDefault('weblog_description', 'Description of my Weblog');
     // Process the form
     if ($form->validate() === true) {
         // Get the form values
         $values = $form->getValues();
         // Connect to the database
         $db = YDDatabase::getInstance('mysql', $values['db_name'], $values['db_user'], $values['db_pass'], $values['db_host']);
         // Create the tables
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'categories;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'categories ( id int(11) NOT NULL auto_increment, title varchar(255) NOT NULL default \'\', created int(11) default NULL, modified int(11) default NULL, PRIMARY KEY  (id) ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'comments;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'comments (
                   id int(11) NOT NULL auto_increment,
                   item_id int(11) NOT NULL default \'1\',
                   username varchar(255) NOT NULL default \'\',
                   useremail varchar(255) NOT NULL default \'\',
                   userwebsite varchar(255) default NULL,
                   userip varchar(20) default NULL,
                   comment longtext NOT NULL,
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   KEY item_id (item_id)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'items;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'items (
                   id int(11) NOT NULL auto_increment,
                   category_id int(11) default \'1\',
                   user_id int(11) NOT NULL default \'1\',
                   title varchar(255) NOT NULL default \'\',
                   body longtext NOT NULL,
                   body_more longtext NOT NULL,
                   num_comments int(11) NOT NULL default \'0\',
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   KEY category_id (category_id),
                   KEY user_id (user_id)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'links;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'links (
                   id int(11) NOT NULL auto_increment,
                   title varchar(255) NOT NULL default \'\',
                   url varchar(255) NOT NULL default \'\',
                   num_visits int(11) default \'0\',
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   UNIQUE KEY url (url)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'pages;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'pages (
                   id int(11) NOT NULL auto_increment,
                   user_id int(11) NOT NULL default \'1\',
                   title varchar(255) NOT NULL default \'\',
                   body longtext,
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   KEY user_id (user_id)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'statistics;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'statistics (
                   id int(11) NOT NULL auto_increment,
                   date date NOT NULL default \'0000-00-00\',
                   uri varchar(255) NOT NULL default \'0\',
                   browser varchar(10) NOT NULL default \'\',
                   platform varchar(10) NOT NULL default \'\',
                   hits int(11) NOT NULL default \'0\',
                   PRIMARY KEY  (id)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'statistics_init;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'statistics_init (
                   created varchar(10) NOT NULL default \'\'
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'users;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'users (
                   id int(11) NOT NULL auto_increment,
                   name varchar(255) NOT NULL default \'\',
                   email varchar(255) NOT NULL default \'\',
                   password varchar(50) default NULL,
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   UNIQUE KEY email (email)
                 ) TYPE=MyISAM;');
         $db->executeInsert($values['db_prefix'] . 'statistics_init', array('created' => $db->getDate('__NOW__')));
         // Include the weblog API
         YDInclude(dirname(__FILE__) . '/include/YDWeblogAPI.php');
         // Save the config file
         YDWeblogSaveConfig($values);
         // Include the config file
         YDInclude(dirname(__FILE__) . '/include/config.php');
         // Create the weblog object
         $weblog = new YDWeblogAPI();
         // Add the user
         $user = array();
         $user['name'] = $values['name'];
         $user['email'] = $values['email'];
         $user['password'] = $values['password'];
         $weblog->saveUser($user);
         // Add a category
         $category = array();
         $category['title'] = 'General';
         $weblog->addCategory($category);
         // Create a first post
         $item = array();
         $item['category_id'] = 1;
         $item['user_id'] = 1;
         $item['title'] = 'Your first post';
         $item['body'] = 'Welcome to your weblog';
         $item['body_more'] = 'Your extended body';
         $weblog->addItem($item);
         // Create a second post
         $item = array();
         $item['category_id'] = 1;
         $item['user_id'] = 1;
         $item['title'] = 'Your second post';
         $item['body'] = 'Without an extended body';
         $item['created'] = time() + 100;
         $weblog->addItem($item);
         // Add a comment
         $comment = array();
         $comment['item_id'] = 1;
         $comment['username'] = '******';
         $comment['useremail'] = '*****@*****.**';
         $comment['userwebsite'] = YD_FW_HOMEPAGE;
         $comment['comment'] = 'A first comment';
         $weblog->addComment($comment);
         // Add a sample page
         $page = array();
         $page['user_id'] = 1;
         $page['title'] = 'Your first page';
         $page['body'] = 'The contents of your first page';
         $weblog->addPage($page);
         // Add a link
         $link = array();
         $link['title'] = 'Yellow Duck Framework';
         $link['url'] = 'http://ydframework.berlios.de/';
         $weblog->addLink($link);
         // Redirect to the finish action
         $this->redirectToAction('finish');
     }
     // Add it to the template
     $this->tpl->assignForm('form', $form);
     // Display the template
     $this->tpl->display();
 }
 function actionDefault()
 {
     // Database instance
     $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost');
     // Instantiate the class
     $q = YDDatabaseQuery::getInstance($db);
     $r = $q->reserved;
     // Select action
     $q->select();
     // Additional options
     $q->options(array('DISTINCT'));
     // Add a table to the query
     // It returns the table alias if defined
     $u = $q->from('user');
     // Select expressions
     $q->expression("id", '', true);
     // quote reserved
     $q->expression("name", 'user_name', true);
     // quote reserved
     $q->expression("SUM( " . $r . "value" . $r . " )", 'total');
     // Add a where statement
     $q->openWhere();
     $q->where($r . "id" . $r . "= 144");
     // Add another where statement inside the above statement
     $q->openWhere('OR');
     $q->where($r . "name" . $r . " LIKE 'David%'");
     $q->where($r . "id" . $r . " > 13");
     $q->closeWhere();
     // optional
     $q->closeWhere();
     // optional
     // Add a group by clause
     $q->group("id", true, true);
     // DESC and quote reserved
     // Add ordering
     $q->order("name", false, true);
     // ASC and quote reserved
     $q->order("total", true, true);
     // DESC and quote reserved
     // Add a having clause
     $q->having($r . "total" . $r . " > 100");
     // Add a limit
     $q->limit(100);
     // Add an offset
     $q->offset(50);
     // Show the SQL statement
     YDDebugUtil::dump($q->getQuery());
     // Reset the contents of the query
     $q->reset();
     // ------------------------------------------------------------
     // Select query
     $q->select();
     // Add table with alias 'u'
     $u = $q->from('user', 'u');
     // Add select expressions for this table
     // The expr method is an alias of the expression method
     $q->expr('id', '', true);
     $q->expr('name', '', true);
     // Add a left join
     $g = $q->join('LEFT', 'group', "g");
     // Specify the fields to use for the join
     $q->on("{$u}.group_id = {$g}.id");
     // Add the joined fields
     $q->expr("{$g}.id", 'gid', true);
     $q->expr("{$g}.name", 'group_name', true);
     // Add an inner join
     $a = $q->join('INNER', 'attach', "a");
     // Specify the fields to use for the join
     $q->on("{$g}.attach_id = {$a}.id");
     // Open a group
     $q->openOn('OR');
     // Specify more fields to use for the join group
     $q->on("{$a}.size > 150");
     $q->on("{$a}.status = 3");
     // Add some more fields
     $q->expr("{$a}.id", 'aid', true);
     $q->expr("{$a}.name", 'attach_name', true);
     // Add a where clause
     $q->where("{$g}.id = 144");
     // Add ordering
     $q->order("{$a}.name", false, true);
     // Add a limit
     $q->limit(50);
     // Show the SQL statement
     YDDebugUtil::dump($q->getQuery());
     // Reset the query
     $q->reset();
     // ------------------------------------------------------------
     // Delete query
     $q->delete();
     // Add a table
     $q->from('user');
     // Specify the where clause
     $q->where("id = 144");
     // Show the SQL statement
     YDDebugUtil::dump($q->getQuery());
     // Reset the query
     $q->reset();
     // ------------------------------------------------------------
     $values = array('name' => "David O'Connor\r\nThe Great", 'email' => '*****@*****.**', 'admin' => 1, 'purple' => null);
     // Insert query
     $q->insert();
     // Add a table
     // The into method is an alias of the from method
     $q->into('user');
     // Set the values
     $q->values($values);
     // Add the where clause
     $q->where("id = 144");
     // Show the SQL statement
     YDDebugUtil::dump($q->getQuery());
     // Reset the query
     $q->reset();
     // ------------------------------------------------------------
     // Update query
     $q->update();
     // Add a table
     // The table method is an alias of the from method
     $q->table('user');
     // Set the values
     // The set method is an alias of the values method
     $q->set($values);
     // Add the where clause
     $q->where("id = 144");
     // Show the SQL statement
     YDDebugUtil::dump($q->getQuery());
 }
 /**
  *  This function initializes the SimpleCMS package. It performs the following items:
  *      - Create a new global array under $GLOBALS['YD_SIMPLECMS']
  *      - Adds a database connection under $GLOBALS['YD_SIMPLECMS']['db']
  *      - Adds a language array under $GLOBALS['YD_SIMPLECMS']['languages']
  *      - Adds a module manager instance under $GLOBALS['YD_SIMPLECMS']['moduleManager']
  *      - Adds a array under $GLOBALS['YD_SIMPLECMS']['adminMenu'] to keep track of the admin menu
  *      - Adds a null value under $GLOBALS['YD_SIMPLECMS']['user'] to keep track of the current user
  *      - Stores the current scope in $GLOBALS['YD_SIMPLECMS']['scope']
  *
  *  Even if you call this function multiple times, the initialization will only be done once.
  *
  *  @todo
  *      Negotiate the language and put it as an array under $GLOBALS['YD_SIMPLECMS']['languages']
  *
  *  @todo
  *      Language settings should be specific for each scope
  *
  *  @static
  */
 function initialize()
 {
     // Check if the initialization is already done or not
     if (!isset($GLOBALS[YD_SIMPLECMS_PACKAGE_NAME]) || !is_array($GLOBALS[YD_SIMPLECMS_PACKAGE_NAME])) {
         // Create the array
         $GLOBALS[YD_SIMPLECMS_PACKAGE_NAME] = array();
         $settings =& $GLOBALS[YD_SIMPLECMS_PACKAGE_NAME];
         // Setup the database connection
         YDConfig::set('YD_DB_TABLEPREFIX', YDConfig::get('db_prefix'));
         $settings['db'] = YDDatabase::getInstance('mysql', YDConfig::get('db_name'), YDConfig::get('db_user'), YDConfig::get('db_pass'), YDConfig::get('db_host'));
         // The global list with admin menu
         $settings['adminMenu'] = array();
         // The current user
         $settings['currentUser'] = null;
         // The module manager instance
         $settings['moduleManager'] = new YDSimpleCMSModuleManager();
         $settings['moduleManager']->loadAllModules();
         // Set the default scope
         $settings['scope'] = YD_SIMPLECMS_SCOPE_PUBLIC;
         // Get the site Id
         $settings['siteId'] = YDConfig::get('YD_SIMPLECMS_SITEID', 'SAMPLESITE');
         // Create a browser information object
         $settings['browserInfo'] = new YDBrowserInfo();
         $browserInfo =& $settings['browserInfo'];
         //                // -- Negotiate the language --
         //                // Set the list of languages and the default language
         //                $language = YDConfig::get( 'site_default_lang', '' );
         //                $languages = array();
         //
         //                // Get the current URL
         //                $url = new YDUrl( YDRequest::getNormalizedCurrentUrl() );
         //
         //                // Get the list of languages
         //                foreach ( array_slice( YDConfig::get( 'site_languages', array() ), 0, 4 ) as $key=>$lang ) {
         //                    if ( ! empty( $lang[0] ) ) {
         //                        $lang[0] = strtolower( $lang[0] );
         //                        $url->setQueryVar( 'lang', $lang[0] );
         //                        $languages[ $lang[0] ] = array(
         //                            'name' => $lang[1], 'idx' => $key + 1, 'code' => $lang[0], 'url' => $url->getUrl(),
         //                        );
         //                    }
         //                }
         //
         //                // Get the current language
         //                $languages = array_keys( $languages );
         //                $lang = $browserInfo->getLanguage( $languages );
         //                $languageCookieName = YD_SIMPLECMS_PACKAGE_NAME . '_' . YDSimpleCms::getSiteId() . '_LANG';
         //                if ( YDRequest::getCookie( $languageCookieName, '', $languages ) != '' ) {
         //                    $lang = YDRequest::getCookie( $languageCookieName, '', $languages );
         //                }
         //                //if ( $this->getQueryStringParameter( 'lang', '', $languages ) != '' ) {
         //                //    $lang = $this->getQueryStringParameter( 'lang', '', $languages );
         //                //}
         //                $lang = strtolower( $lang );
         //
         //                // Set the right locale
         //                YDLocale::set( $lang );
         //
         //                //YDDebugUtil::dump( $language, 'language' );
         //YDDebugUtil::dump( $languages, 'languages' );
     }
 }
    }
}
// Include the standard modules
YDInclude('YDUrl.php');
YDInclude('YDUtil.php');
YDInclude('YDForm.php');
YDInclude('YDBBCode.php');
YDInclude('YDTemplate.php');
YDInclude('YDDatabase.php');
YDInclude('YDFileSystem.php');
YDInclude('YDFormElements/YDFormElement_BBTextArea.php');
// Include other libraries
YDInclude(dirname(__FILE__) . '/YDWeblogAPI.php');
YDInclude(dirname(__FILE__) . '/YDWeblogRequest.php');
// Check if the weblog application is locked or not
$db = YDDatabase::getInstance('mysql', YDConfig::get('db_name', 'YDWeblog'), YDConfig::get('db_user', 'root'), YDConfig::get('db_pass', ''), YDConfig::get('db_host', 'localhost'));
$tables = $db->getRecords('show tables');
$table_field_name = 'tables_in_' . strtolower(YDConfig::get('db_name', 'YDWeblog'));
foreach ($tables as $table) {
    if (strtolower($table[$table_field_name]) == YDConfig::get('db_prefix', '') . 'locked') {
        die('Weblog application is being updated. Please come again later.');
    }
}
// Set the right locale
$language = YDConfig::get('weblog_language', 'en');
$language = empty($language) ? 'en' : $language;
YDLocale::set($language);
// The t function used for translations
function t($t)
{
    // Return empty string when param is missing
 function sqlObject()
 {
     $this->db = $db = YDDatabase::getInstance('mysql', DB_BASE, DB_USER, DB_PASS, DB_HOST);
     // Fetch as an associative array
     YDConfig::set('YD_DB_FETCHTYPE', YD_DB_FETCH_ASSOC);
 }
示例#28
0
<?php

// Init the framework
include_once dirname(__FILE__) . '/../../../YDFramework2/YDF2_init.php';
YDInclude('YDRequest.php');
YDInclude('YDTemplate.php');
YDInclude('YDDatabase.php');
YDInclude('YDDatabaseObject.php');
// Database connection
$GLOBALS['YDDBOBJ_CONN'] = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost');
// Data objects paths
YDConfig::set('YD_DBOBJECT_PATH', dirname(__FILE__));
class YDDatabaseObjectRequest extends YDRequest
{
    function YDDatabaseObjectRequest()
    {
        $this->YDRequest();
        $this->template = new YDTemplate();
        $this->template->assign('YD_DEBUG', YDConfig::get('YD_DEBUG'));
    }
    function actionDefault()
    {
        $this->template->display();
    }
}