예제 #1
0
 function actionSelector()
 {
     // Redirect to the main if no field in the url
     if (empty($_GET['field'])) {
         $this->forward('default');
     }
     // Get the list of images in the current directory
     $dir = new YDFSDirectory();
     // Start with no items
     $items = array();
     // Add the list of images to the template
     if ($_GET['tag'] == 'img') {
         $pattern = '*.jpg';
     }
     if ($_GET['tag'] == 'url') {
         $pattern = '*.php';
     }
     // Get the item list
     foreach ($dir->getContents($pattern) as $item) {
         array_push($items, $item->getBaseName());
     }
     // Add the items to the template
     $this->template->assign('items', $items);
     // Output the template
     $this->template->display('form_selector');
 }
예제 #2
0
 function actionEdit()
 {
     // Get the configuration
     $config = $this->getConfig();
     // 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 YDWeblogForm('configForm');
     // Add the fields
     $form->addElement('text', 'db_host', t('cfg_db_host'), array('class' => 'tfM'));
     $form->addElement('text', 'db_name', t('cfg_db_name'), array('class' => 'tfM'));
     $form->addElement('text', 'db_user', t('cfg_db_user'), array('class' => 'tfM'));
     $form->addElement('text', 'db_pass', t('cfg_db_pass'), array('class' => 'tfM'));
     $form->addElement('text', 'db_prefix', t('cfg_db_prefix'), array('class' => 'tfM'));
     $form->addElement('text', 'weblog_title', t('cfg_weblog_title'), array('class' => 'tfM'));
     $form->addElement('text', 'weblog_description', t('cfg_weblog_description'), array('class' => 'tfM'));
     $form->addElement('text', 'weblog_entries_fp', t('cfg_weblog_entries_fp'), array('class' => 'tfM'));
     $form->addElement('select', 'weblog_skin', t('cfg_weblog_skin'), array('class' => 'tfM', 'style' => 'width: 100%'), $skins);
     $form->addElement('select', 'weblog_language', t('cfg_weblog_language'), array('class' => 'tfM', 'style' => 'width: 100%'), $languages);
     $form->addElement('checkbox', 'email_new_comment', t('cfg_notification_email_comment'), array('class' => 'tfM'));
     $form->addElement('text', 'max_syndicated_items', t('cfg_rss_max_syndicated_items'), array('class' => 'tfM'));
     $form->addElement('submit', '_cmdSubmit', t('OK'), array('class' => 'button'));
     // Set the defaults
     $form->setDefaults($config);
     // Add the rules
     $form->addRule('db_host', 'required', t('err_db_host'));
     $form->addRule('db_name', 'required', t('err_db_name'));
     $form->addRule('db_user', 'required', t('err_db_user'));
     $form->addRule('weblog_title', 'required', t('err_weblog_title'));
     $form->addRule('weblog_entries_fp', 'required', t('err_weblog_entries_fp'));
     $form->addRule('weblog_entries_fp', 'numeric', t('err_weblog_entries_fp_num'));
     $form->addRule('max_syndicated_items', 'required', t('err_max_syndicated_items'));
     $form->addRule('max_syndicated_items', 'numeric', t('err_max_syndicated_items_num'));
     // Process the form
     if ($form->validate() === true) {
         // Get the form values
         $values = $form->getValues();
         // Save the config
         $this->saveConfig($values);
         // Redirect to the default acton
         $this->redirectToAction();
     }
     // Add it to the template
     $this->tpl->assignForm('form', $form);
     // Display the template
     $this->display();
 }
예제 #3
0
 function _deleteCacheFiles($pattern)
 {
     $dir = new YDFSDirectory(YD_DIR_TEMP);
     $filesToDelete = $dir->getContents($pattern, null);
     foreach ($filesToDelete as $file) {
         @unlink($file->getAbsolutePath());
     }
 }
예제 #4
0
 function actionSelector()
 {
     // Redirect to the main if no field in the url
     if (empty($_GET['field'])) {
         $this->forward('default');
     }
     // Get the list of images in the current directory
     $dir = new YDFSDirectory();
     // Add the list of images to the template
     if ($_GET['tag'] == 'img') {
         $this->setVar('items', $dir->getContents('*.jpg'));
     }
     if ($_GET['tag'] == 'url') {
         $this->setVar('items', $dir->getContents('*.php'));
     }
     // Output the template
     $this->outputTemplate('form_selector');
 }
 function actionDefault()
 {
     // Get the directory object for the current directory
     $dir = new YDFSDirectory(dirname(__FILE__));
     // Directorties in the directory
     YDDebugUtil::dump($dir->getContents('', null, array('YDFSDirectory')), '$dir->getContents( \'\', null, array( \'YDFSDirectory\' ) )');
     YDDebugUtil::dump($dir->getContents('', '', array('YDFSDirectory')), '$dir->getContents( \'\', \'\', array( \'YDFSDirectory\' ) )');
     // Files in the directory
     YDDebugUtil::dump($dir->getContents('', null, array('YDFSFile')), '$dir->getContents( \'\', null, array( \'YDFSFile\' ) )');
     YDDebugUtil::dump($dir->getContents('', '', array('YDFSFile')), '$dir->getContents( \'\', \'\', array( \'YDFSFile\' ) )');
     // Images in the directory
     YDDebugUtil::dump($dir->getContents('', null, array('YDFSImage')), '$dir->getContents( \'\', null, array( \'YDFSImage\' ) )');
     YDDebugUtil::dump($dir->getContents('', '', array('YDFSImage')), '$dir->getContents( \'\', \'\', array( \'YDFSImage\' ) )');
     // Images in the directory
     YDDebugUtil::dump($dir->getContents('', null, 'YDFSImage'), '$dir->getContents( \'\', null, \'YDFSImage\' )');
     YDDebugUtil::dump($dir->getContents('', '', 'YDFSImage'), '$dir->getContents( \'\', \'\', \'YDFSImage\' )');
     // Images and directories in the directory
     YDDebugUtil::dump($dir->getContents('', null, array('YDFSImage', 'YDFSDirectory')), '$dir->getContents( \'\', null, array( \'YDFSImage\', \'YDFSDirectory\' ) )');
     YDDebugUtil::dump($dir->getContents('', '', array('YDFSImage', 'YDFSDirectory')), '$dir->getContents( \'\', \'\', array( \'YDFSImage\', \'YDFSDirectory\' ) )');
 }
 function actionDefault()
 {
     // Get the pagesize and current page from the query string
     $page = @$_GET['page'];
     $size = @$_GET['size'];
     // Get the list of files in the current directory
     $dir = new YDFSDirectory();
     $files = $dir->getContents('*.*', null, 'YDFSFile');
     // Create the YDRecordSet object
     $recordset = new YDRecordSet($files, $page, $size);
     // Setup the template
     $this->template->assign('recordset', $recordset);
     // Display the template
     $this->template->display();
 }
 function _fixItem($item, $order = 'created desc, title')
 {
     // Return false if no item
     if (!$item) {
         return $item;
     }
     // Get the item indexes for the indicated weblog (cached to minimize the number of SQL queries)
     $cacheName = 'YD_CACHE_WEBLOG_ITEMIDS_' . md5(strtolower($order));
     if (!isset($GLOBALS[$cacheName])) {
         $sql = $this->_prepareQuery('SELECT id FROM ' . YDConfig::get('db_prefix', '') . 'items', $order);
         $item_ids = $this->db->getValuesByName($sql, 'id');
         $GLOBALS[$cacheName] = $item_ids;
     }
     // Get the ID of the previous and the next item
     $pos = array_search($item['id'], $GLOBALS[$cacheName]);
     $item['newer_id'] = $pos == 0 ? false : $GLOBALS[$cacheName][$pos - 1];
     $item['older_id'] = $pos == sizeof($GLOBALS[$cacheName]) - 1 ? false : $GLOBALS[$cacheName][$pos + 1];
     // Add the year, month and yearmonth fields
     $item['yearmonth'] = ucwords(strftime('%B %Y', $item['created']));
     $item['month'] = ucwords(strftime('%B', $item['created']));
     $item['year'] = ucwords(strftime('%Y', $item['created']));
     // Get the list of images related to this item
     $imgPath = dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads') . '/item_' . $item['id'] . '/';
     // Get the list of pictures if any
     if (is_dir($imgPath)) {
         // Get a handle to the directory
         $dir = new YDFSDirectory(dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads') . '/item_' . $item['id'] . '/');
         // Get the list of files
         $images = $dir->getContents(array('!index.html', '!index.php', '!m_*.*', '!s_*.*'), null, array('YDFSImage'));
         // Make the relative path for each file
         foreach ($images as $key => $image) {
             // Generate the thumbnails if not there yet
             if (!is_file($dir->getAbsolutePath() . '/s_' . $image->getBasename())) {
                 $image->saveThumbnail(48, 48, $dir->getAbsolutePath() . '/s_' . $image->getBasename());
             }
             if (!is_file($dir->getAbsolutePath() . '/m_' . $image->getBasename())) {
                 $image->saveThumbnail(100, 100, $dir->getAbsolutePath() . '/m_' . $image->getBasename());
             }
             // Set the relative path
             $dir_uploads = dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads');
             $dir_uploads = new YDFSDirectory($dir_uploads);
             $image->relative_path = str_replace($dir_uploads->getAbsolutePath(), '', $image->getAbsolutePath());
             // Update the backslashes
             $image->relative_path = str_replace('\\', '/', $image->relative_path);
             // Remove the leading slash
             if (substr($image->relative_path, 0, 1) == '/') {
                 $image->relative_path = substr($image->relative_path, 1);
             }
             // Make links to the thumbnails
             $image->relative_path_s = dirname($image->relative_path) . '/s_' . basename($image->relative_path);
             $image->relative_path_m = dirname($image->relative_path) . '/m_' . basename($image->relative_path);
             // Update the original image
             $images[$key] = $image;
         }
         // Add it to the item
         $item['images'] = $images;
     } else {
         // No images for this item
         $item['images'] = array();
     }
     // Get the count of images
     $item['num_images'] = sizeof($item['images']);
     // Return the fixed item
     return $item;
 }
 /**
  *  This function will list all the files in this directory, but will also recurse into the subdirectories.
  *
  *	@param $pattern	(optional) Pattern to which the files should match. If you want multiple items, you can also
  *					pass them as an array. If the pattern is prefixed with an exclamation mark, the files that
  *					match this pattern will not be included in the result.
  *	@param $class	(optional) If you specify a not null value for this option, this function will return the
  *					items in the directory as the indicated class. If an empty string is given, it will return
  *					the list of filenames instead of objects.
  *	@param $classes	(optional) An array with the classes to include. Standard, it includes YDFSImage and
  *					YDFSFile classes. If you only need a single class, you can also specify it as a string.
  *  @param $sort_by_date (optional) Sorts the items by date. Default is false.
  *  @param $sort_order    (optional) Whether the sort direction is ascending or descending. Default is "ASC".
  *
  *	@returns	Array of YDFile objects for the files that match the pattern.
  */
 function getFilesRecursively($pattern = '', $class = null, $classes = array('YDFSFile', 'YDFSImage'), $sort_by_date = false, $sort_order = 'asc')
 {
     $files = array();
     foreach ($this->_getSubdirectories($this->_path) as $dir) {
         $dir = new YDFSDirectory($dir);
         $files = array_merge($files, $dir->getContents($pattern, $class, $classes, $sort_by_date, $sort_order));
     }
     return $files;
 }
예제 #9
0
 function getImages($as_class = true)
 {
     // Get the list of files
     $dir = new YDFSDirectory($this->dir_rel);
     $images = @$dir->getContents(array('!index.html', '!index.php'), null, array('YDFSImage'), true, 'desc');
     // Make the relative path for each file
     foreach ($images as $key => $image) {
         // Set the relative path
         $image->relative_path = str_replace($dir->getAbsolutePath(), '', $image->getAbsolutePath());
         // Update the backslashes
         $image->relative_path = str_replace('\\', '/', $image->relative_path);
         // Remove the leading slash
         if (substr($image->relative_path, 0, 1) == '/') {
             $image->relative_path = substr($image->relative_path, 1);
         }
         // Update the original image
         $images[$key] = $image;
     }
     // Convert to a plain array if needed
     if ($as_class === false) {
         foreach ($images as $key => $image) {
             $images[$key] = $image->relative_path;
         }
     }
     // Return the list
     return $images;
 }
 function _fixItem($item, $order = 'created desc, title')
 {
     // Return false if no item
     if (!$item) {
         return $item;
     }
     // Get the item indexes for the indicated weblog (cached to minimize the number of SQL queries)
     $cacheName = 'YD_CACHE_WEBLOG_ITEMIDS_' . md5(strtolower($order));
     if (!isset($GLOBALS[$cacheName])) {
         $sql = $this->_prepareQuery('SELECT id FROM #_items', $order);
         $item_ids = $this->db->getValuesByName($sql, 'id');
         $GLOBALS[$cacheName] = $item_ids;
     }
     // Get the ID of the previous and the next item
     $pos = array_search($item['id'], $GLOBALS[$cacheName]);
     $item['newer_id'] = $pos == 0 ? false : $GLOBALS[$cacheName][$pos - 1];
     $item['older_id'] = $pos == sizeof($GLOBALS[$cacheName]) - 1 ? false : $GLOBALS[$cacheName][$pos + 1];
     // Add the year, month and yearmonth fields
     $item['yearmonth'] = ucwords(strftime('%B %Y', $item['created']));
     $item['month'] = ucwords(strftime('%B', $item['created']));
     $item['year'] = ucwords(strftime('%Y', $item['created']));
     // Get the list of images related to this item
     $imgPath = dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads') . '/item_' . $item['id'] . '/';
     // Get the list of pictures if any
     if (is_dir($imgPath)) {
         // Get a handle to the directory
         $dir = new YDFSDirectory(dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads') . '/item_' . $item['id'] . '/');
         // Get the list of files
         $images = $dir->getContents(array('!index.html', '!index.php', '!m_*.*', '!s_*.*'), null, array('YDFSImage'));
         // Make the relative path for each file
         foreach ($images as $key => $image) {
             // Generate the thumbnails if not there yet
             if (!is_file($dir->getAbsolutePath() . '/s_' . $image->getBasename())) {
                 $image->saveThumbnail(48, 48, $dir->getAbsolutePath() . '/s_' . $image->getBasename());
             }
             if (!is_file($dir->getAbsolutePath() . '/m_' . $image->getBasename())) {
                 $image->saveThumbnail(100, 100, $dir->getAbsolutePath() . '/m_' . $image->getBasename());
             }
             // Set the relative path
             $dir_uploads = dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads');
             $dir_uploads = new YDFSDirectory($dir_uploads);
             $image->relative_path = str_replace($dir_uploads->getAbsolutePath(), '', $image->getAbsolutePath());
             // Update the backslashes
             $image->relative_path = ltrim(str_replace('\\', '/', $image->relative_path), '/');
             // Merge the title and description if any
             $image = $this->getItemImageMetaData($image);
             // Create the full title, including item title, image title and description if any
             $image->full_description = $item['title'] . ' » ' . $image->title;
             if ($image->description) {
                 $image->full_description .= '<p class="img_description">' . YDTemplate_modifier_bbcode($image->description) . '</p>';
             }
             $image->full_description_html = htmlspecialchars($image->full_description, ENT_QUOTES);
             // Make links to the thumbnails
             $image->relative_path_s = dirname($image->relative_path) . '/s_' . basename($image->relative_path);
             $image->relative_path_m = dirname($image->relative_path) . '/m_' . basename($image->relative_path);
             // Add the thumbnails as objects
             $image->relative_path_s_obj = new YDFSImage($dir_uploads->getAbsolutePath() . '/' . $image->relative_path_s);
             $image->relative_path_m_obj = new YDFSImage($dir_uploads->getAbsolutePath() . '/' . $image->relative_path_m);
             // Update the original image
             $images[$key] = $image;
         }
         // Add it to the item
         $item['images'] = $images;
     } else {
         // No images for this item
         $item['images'] = array();
     }
     // Fix the image paths
     if (strtolower(basename(dirname(YD_SELF_FILE))) != 'manage') {
         $uploads = YDConfig::get('dir_uploads', 'uploads');
         $item['body'] = str_replace('../' . $uploads, $uploads, $item['body']);
         $item['body_more'] = str_replace('../' . $uploads, $uploads, $item['body_more']);
     }
     // Get the count of images
     $item['num_images'] = sizeof($item['images']);
     // Return the fixed item
     return $item;
 }
 function actionUpdate()
 {
     // Check if a software update is going on
     YDDatabaseTools::checkLockDb();
     // Download the needed files
     foreach ($this->changed_files as $file => $action) {
         if ($action != 'D') {
             $this->updateDb->downloadFile($file);
         }
     }
     // Lock the weblog application
     YDDatabaseTools::lockDb();
     // Install the new files
     foreach ($this->changed_files as $file => $action) {
         YDUpdateTools::installFile($file, $action);
     }
     // Update the init file
     if ($this->updateDb->isUpdated('%YD_WEBLOG_HOME%/include/YDWeblog_init.php')) {
         YDUpdateTools::replaceInFile('%YD_WEBLOG_HOME%/include/YDWeblog_init.php', '\'/../../../YDFramework2/YDF2_init.php\' );', '\'/YDFramework2/YDF2_init.php\' );');
     }
     // Update the database if needed
     foreach ($this->changed_files as $file => $action) {
         if (YDStringUtil::startsWith(YDUpdateTools::shortPath($file), '%YD_WEBLOG_HOME%/include/dbupdates/')) {
             YDDatabaseTools::installDbUpdate($file);
         }
     }
     // Save the new version number
     $this->updateDb->saveVersionNumber();
     // Unlock the weblog application
     YDDatabaseTools::unlockDb();
     // Delete the downloaded files
     YDUpdateLog::info('Cleaning up the file downloads...');
     foreach ($this->changed_files as $file => $action) {
         @unlink(YDUpdateTools::tempPath($file));
     }
     // Clear the weblog cache
     YDUpdateLog::info('Clearing the weblog cache...');
     $cachePatterns = array(YD_WEBLOG_CACHE_PREFIX . '*.' . YD_WEBLOG_CACHE_SUFFIX, YD_TMP_PRE . 'N_*.*', '*.wch', '*.tpl.php', YD_TMP_PRE . 'U_*.upd');
     $dir = new YDFSDirectory(YD_DIR_TEMP);
     foreach ($cachePatterns as $pattern) {
         $filesToDelete = $dir->getContents($pattern, null);
         foreach ($filesToDelete as $file) {
             @unlink($file->getAbsolutePath());
         }
     }
     // Show a message
     echo '</p><p class="title">Software is now updated to version ' . $this->updateDb->getLastRevision() . '</p>';
 }
예제 #12
0
 function _getFileList($pattern)
 {
     $dir = new YDFSDirectory(YD_DIR_TEMP);
     return $dir->getContents($pattern, null);
 }
예제 #13
0
 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();
 }
 /**
  *  This function deletes a file or an array of files using a pattern
  *  from the target directory.
  *
  *  @param  $files  The file pattern or an array of file patterns
  *                  relative to the target directory.
  *
  *  @returns     An array with the results.
  */
 function deleteFileByPattern($files)
 {
     if (!is_array($files)) {
         $files = array($files);
     }
     $res = array();
     foreach ($files as $key => $pattern) {
         // Get the directory out of the pattern
         $pattern = str_replace('/', YDPath::getDirectorySeparator(), $pattern);
         $pattern = str_replace('\\', YDPath::getDirectorySeparator(), $pattern);
         $pos = strrpos($pattern, YDPath::getDirectorySeparator());
         $dir = '';
         if ($pos) {
             $dir = substr($pattern, 0, $pos + 1);
             $pattern = substr($pattern, $pos + 1, strlen($pattern) - $pos);
         }
         // Get the files based on the pattern
         $d = new YDFSDirectory(YDPath::join($this->_target_dir, $dir));
         $fs = $d->getContents($pattern, '', 'YDFSFile');
         // Delete the files
         foreach ($fs as $file) {
             $res = array_merge($res, $this->deleteFile(YDPath::join($dir, $file)));
         }
     }
     return $res;
 }
예제 #15
0
 function actionEdit()
 {
     // Get the configuration
     $config = $this->getConfig();
     // Get the list of skins
     $dir = new YDFSDirectory(dirname(__FILE__) . '/../' . $this->dir_skins);
     $items = $dir->getContents(null, '', 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 YDWeblogForm('configForm');
     // Add the fields
     $form->addElement('text', 'db_host', t('cfg_db_host'), array('class' => 'tfM'));
     $form->addElement('text', 'db_name', t('cfg_db_name'), array('class' => 'tfM'));
     $form->addElement('text', 'db_user', t('cfg_db_user'), array('class' => 'tfM'));
     $form->addElement('password', 'db_pass', t('cfg_db_pass'), array('class' => 'tfM'));
     $form->addElement('text', 'db_prefix', t('cfg_db_prefix'), array('class' => 'tfM'));
     $form->addElement('text', 'weblog_title', t('cfg_weblog_title'), array('class' => 'tfM'));
     $form->addElement('text', 'weblog_description', t('cfg_weblog_description'), array('class' => 'tfM'));
     $form->addElement('text', 'weblog_entries_fp', t('cfg_weblog_entries_fp'), array('class' => 'tfM'));
     $form->addElement('select', 'weblog_skin', t('cfg_weblog_skin'), array('class' => 'tfM', 'style' => 'width: 100%'), $skins);
     $form->addElement('select', 'weblog_language', t('cfg_weblog_language'), array('class' => 'tfM', 'style' => 'width: 100%'), $languages);
     $form->addElement('checkbox', 'include_debug_info', t('cfg_include_debug_info'), array('style' => 'border: none;'));
     $form->addElement('text', 'google_analytics', t('cfg_weblog_google_analytics'), array('class' => 'tfM'));
     $form->addElement('text', 'weblog_title', t('cfg_weblog_title'), array('class' => 'tfM'));
     $form->addElement('text', 'max_img_size_x', t('cfg_max_img_size'), array('class' => 'tfXS'));
     $form->addElement('text', 'max_img_size_y', t('cfg_max_img_size'), array('class' => 'tfXS'));
     $form->addElement('checkbox', 'email_new_comment', t('cfg_notification_email_comment'), array('style' => 'border: none;'));
     $form->addElement('checkbox', 'email_new_item', t('cfg_notification_email_item'), array('style' => 'border: none;'));
     $form->addElement('text', 'max_syndicated_items', t('cfg_rss_max_syndicated_items'), array('class' => 'tfM'));
     $form->addElement('checkbox', 'use_cache', t('cfg_use_cache_comment'), array('style' => 'border: none;'));
     $form->addElement('checkbox', 'friendly_urls', t('cfg_friendly_urls'), array('style' => 'border: none;'));
     $form->addElement('checkbox', 'dflt_is_draft', t('is_draft'), array('style' => 'border: none;'));
     $form->addElement('textarea', 'blocked_ips', t('cfg_blocked_ips'), array('class' => 'tfMNoMCE'));
     $form->addElement('text', 'akismet_key', t('cfg_akismet_key'), array('class' => 'tfM'));
     $form->addElement('text', 'comment_interval', t('cfg_comment_interval'), array('class' => 'tfM'));
     $form->addElement('text', 'max_comment_length', t('max_comment_length'), array('class' => 'tfM'));
     $form->addElement('text', 'max_comment_links', t('max_comment_links'), array('class' => 'tfM'));
     $form->addElement('submit', '_cmdSubmit', t('OK'), array('class' => 'button'));
     // Set the defaults
     $form->setDefaults($config);
     // Add the rules
     $form->addRule('db_host', 'required', t('err_db_host'));
     $form->addRule('db_name', 'required', t('err_db_name'));
     $form->addRule('db_user', 'required', t('err_db_user'));
     $form->addRule('weblog_title', 'required', t('err_weblog_title'));
     $form->addRule('weblog_entries_fp', 'required', t('err_weblog_entries_fp'));
     $form->addRule('weblog_entries_fp', 'numeric', t('err_weblog_entries_fp_num'));
     $form->addRule('max_syndicated_items', 'required', t('err_max_syndicated_items'));
     $form->addRule('max_syndicated_items', 'numeric', t('err_max_syndicated_items_num'));
     $form->addRule('comment_interval', 'numeric', t('err_comment_interval_num'));
     $form->addRule('max_comment_length', 'numeric', t('err_max_comment_length'));
     $form->addRule('max_comment_links', 'numeric', t('err_max_comment_links'));
     // Add the filters
     $form->addFilters(array('db_host', 'db_name', 'db_user', 'db_prefix', 'weblog_title', 'weblog_description'), 'strip_html');
     // Process the form
     if ($form->validate() === true) {
         // Get the form values
         $values = $form->getValues();
         // Format the list of blocked IP numbers
         $values['blocked_ips'] = YDFormatStringWithListValues($values['blocked_ips']);
         // Save the config
         YDWeblogSaveConfig($values);
         // Redirect to the default acton
         $this->redirectToAction();
     }
     // Add it to the template
     $this->tpl->assignForm('form', $form);
     // Display the template
     $this->display();
 }
 /**
  *  This private function returns all filenames of a directory
  *
  *  @returns    Array of filenames, eg: array( 'default' => 'Default', 'orange' => ... )
  */
 function __getFiles($dir)
 {
     YDInclude('YDFileSystem.php');
     // init directories
     $directories = array();
     // init template directory
     $dir = new YDFSDirectory($dir);
     // compute directories array
     foreach ($dir->getContents('!.*', '', 'YDFSDirectory') as $d) {
         $directories[$d] = $d;
     }
     return $directories;
 }