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'); }
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(); }
function actionDefault() { // Get the file object for the current file $file = new YDFSFile(__FILE__); // Dump the object echo __FILE__; YDDebugUtil::dump($file); // Dump the object echo '<br>Basename: ' . $file->getBasename(); echo '<br>Extension: ' . $file->getExtension(); echo '<br>Path: ' . $file->getPath(); echo '<br>LastModified: ' . $file->getLastModified(); echo '<br>File size: ' . $file->getSize(); // Get the contents YDDebugUtil::dump($file->getContents(), '$file->getContents()'); // Get the partial contents YDDebugUtil::dump($file->getContents(2, 3), '$file->getContents( 2, 3 )'); // Create a dummy file $dir = new YDFSDirectory('.'); $file = $dir->createFile('dummy.txt', 'initial contents'); // Update the contents $file->setContents('new contents'); // Get the contents YDDebugUtil::dump($file->getContents(), '$file->getContents() after update'); // Append the contents $file->setContents(YD_CRLF . 'appended contents', true); // Get the contents YDDebugUtil::dump($file->getContents(), '$file->getContents() after append'); // Delete the file $file->delete(); // Get the file object for the current file $file = new YDFSFile('nofile.php'); }
function _deleteCacheFiles($pattern) { $dir = new YDFSDirectory(YD_DIR_TEMP); $filesToDelete = $dir->getContents($pattern, null); foreach ($filesToDelete as $file) { @unlink($file->getAbsolutePath()); } }
function actionAdd() { // We return to the default action $action = 'default'; // Process the form if ($this->form->validate()) { // Move the uploaded file $file = $this->form->getElement('image'); if ($file->isUploaded()) { // Get the new filename $filename = YDStringUtil::stripSpecialCharacters($file->getBaseName()); // Move the upload if (!is_dir($this->dir_rel)) { @mkdir($this->dir_rel); } @$file->moveUpload($this->dir_rel, $filename); // Convert it to an object $fileObj = new YDFSFile($this->dir_rel . $file->getBaseName()); // Check if it's a ZIP file if (strtolower($fileObj->getExtension() == 'zip')) { // Include the unzip library include YD_DIR_HOME . '/3rdparty/zip/unzip.lib.php'; // Convert it to a ZIP object $zip = new SimpleUnzip($fileObj->getAbsolutePath()); // Get the directory as a path $dir = new YDFSDirectory($this->dir_rel); // Extract the images foreach ($zip->Entries as $entry) { // Save it as a filee $entryFile = $dir->createFile($entry->Name, $entry->Data); // Delete it if it's not an image if (!$entryFile->isImage()) { @unlink($entryFile->getAbsolutePath()); } else { $entryFile = $this->weblog->resizeUploadedImage($entryFile); } } } // Check if it's an image if (!$fileObj->isImage()) { @unlink($fileObj->getAbsolutePath()); } else { $fileObj = $this->weblog->resizeUploadedImage($fileObj); } // Delete the thumbnails @unlink($this->dir_rel . 's_' . $file->getBaseName()); @unlink($this->dir_rel . 'm_' . $file->getBaseName()); } } // Redirect to the list view $this->redirect(YD_SELF_SCRIPT . '?id=' . $this->item['id']); }
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 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'); }
/** * 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; }
/** * Function to emulate the fnmatch function from UNIX which is not available on all servers. * * @remark * This function is a reformatted version of the function found on: * http://www.php.net/manual/en/function.fnmatch.php#31353 * * @param $pattern Pattern to match the file against. * @param $file File name that needs to be checked. * * @return Boolean indicating if the file matched the pattern or not. * * @internal */ function _match($pattern, $file) { // Loop over the characters of the pattern for ($i = 0; $i < strlen($pattern); $i++) { // Character is a * if ($pattern[$i] == '*') { for ($c = $i; $c < max(strlen($pattern), strlen($file)); $c++) { if (YDFSDirectory::_match(substr($pattern, $i + 1), substr($file, $c))) { return true; } } return false; } // Pattern is a [ if ($pattern[$i] == '[') { $letter_set = array(); for ($c = $i + 1; $c < strlen($pattern); $c++) { if ($pattern[$c] != ']') { array_push($letter_set, $pattern[$c]); } else { break; } } foreach ($letter_set as $letter) { if (YDFSDirectory::_match($letter . substr($pattern, $c + 1), substr($file, $i))) { return true; } } return false; } // Pattern is a ? if ($pattern[$i] == '?') { continue; } // Pattern not the same as the file character if ($pattern[$i] != $file[$i]) { return false; } } // All the rest returns positive return true; }
/** * This function will save the XML data to the specified file. * * @remark * The default format is "RSS2.0". If you specify no argument indicating the requested format, the "RSS2.0" * format will be used. * * @param $path The path to save the XML data to. * @param $format (optional) The format in which the items should be converted. */ function saveXml($path, $format = 'RSS2.0') { // Get the XML data $xml = $this->toXml($format); // Get the directory information $dir = new YDFSDirectory(YDPath::getDirectoryName($path)); // Create the file $dir->createFile(YDPath::getFileName($path), $xml); }
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; }
/** * Function to recursively delete a directory. * * @param $dirname Directory to be removed. * * @return Boolean indicating if the directory could be deleted or not. * * @internal */ function _delete($dirname) { // Simple delete for a file if (is_file($dirname)) { return unlink($dirname); } // Loop through the folder $dir = dir($dirname); while (false !== ($entry = $dir->read())) { // Skip pointers if ($entry == '.' || $entry == '..') { continue; } // Deep delete directories if (is_dir("{$dirname}/{$entry}")) { YDFSDirectory::_delete("{$dirname}/{$entry}"); } else { unlink("{$dirname}/{$entry}"); } } // Clean up $dir->close(); return rmdir($dirname); }
/** * Function to get the contents of the URL. It will get the contents using Gzip compression if possible in * order to save bandwidth. It uses the HTTP Client class from Simon Willison to do the dirty work. * * More information about the HTTP client class can be found on: http://scripts.incutio.com/httpclient/ * * If it fails to retrieve the data, it will raise a fatal error. * * By default, it will cache the downloaded data based on the etag and last-modified headers. The cache files * are stored in the temp directory of the Yellow Duck framework and have the extension "wch". You can delete * these automatically as they will be recreated on the fly if needed. * * For configuring the cache, there are two configuration variables you can redefine if needed: * YD_HTTP_CACHE_TIMEOUT: the lifetime of the cache in seconds (default: 3600). * YD_HTTP_CACHE_USEHEAD: if a HEAD HTTP request should be used to verify the cache validity (default: 1). * * @param $cache (optional) Indicate if the web content should be cached or not. By default, caching is * turned on. * @param $fail (optional) Whether to fail or not if the contents cannot be downloaded. Defaults to true. * * @returns Returns the contents of the URL. */ function getContents($cache = true, $fail = true) { // Check if caching is enabled $cacheFName = null; // Check the cache if ($cache == true) { // Include the filesystem library include_once YD_DIR_HOME_CLS . '/YDFileSystem.php'; // Check if we need to use the HTTP HEAD function if (YDConfig::get('YD_HTTP_CACHE_USEHEAD') == 1) { // Get the headers $headers = $this->getHeaders(); // Check if we have etag or last modified if (isset($headers['etag']) || isset($headers['last-modified'])) { $cacheFName = $this->getUrl(); if (isset($headers['etag'])) { $cacheFName .= $headers['etag']; } if (isset($headers['last-modified'])) { $cacheFName .= $headers['last-modified']; } if (isset($headers['content-length'])) { $cacheFName .= $headers['content-length']; } $cacheFName = YD_TMP_PRE . 'W_' . md5($cacheFName) . '.wch'; $cacheFName = YD_DIR_TEMP . '/' . $cacheFName; } } // If the cache filename is null, use the default one if ($cacheFName == null) { $cacheFName = YD_DIR_TEMP . '/' . YD_TMP_PRE . 'W_' . md5($this->getUrl()) . '.wch'; } // Use the cache file if any if (is_file($cacheFName)) { $file = new YDFSFile($cacheFName); $cacheValidTime = $file->getLastModified() + YDConfig::get('YD_HTTP_CACHE_TIMEOUT'); if (time() < $cacheValidTime) { return $file->getContents(); } } } // Create a new HTTP client $client = $this->_getHttpClient(); // Now send the request $result = @$client->doRequest(); // Check if there was a result if ($result == false) { if ($fail) { trigger_error('Failed to retrieve the data from the url "' . $this->getUrl() . '". ' . $client->getError(), YD_ERROR); } else { return false; } } else { $data = @$client->getContent(); } // Check if caching is enabled if ($cache == true) { // Save the cached data if ($cacheFName != null) { $dir = new YDFSDirectory(YD_DIR_TEMP); $dir->createFile($cacheFName, $data); } } // Return the data return $data; }
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>'; }
function _getFileList($pattern) { $dir = new YDFSDirectory(YD_DIR_TEMP); return $dir->getContents($pattern, null); }
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() { // 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; }
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 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(); }