function actionEdit() { // Add a field for the last modified date/time $this->form->addElement('datetimeselect', 'modified', t('last_modified_on'), array('class' => 'tfM')); // Get the ID from the query string $id = $this->getIdFromQS(); // If there is something, set the defaults if ($id != -1) { // Get the page by ID $defaults = $this->weblog->getPageById($id); $defaults['body'] = YDTemplate_modifier_bbcode($defaults['body']); // Get the current date/time $defaults['modified'] = gmmktime(); // Add delete button with existing items $this->form->addElement('button', '_cmdDelete', t('delete'), array('class' => 'button', 'onClick' => 'return YDConfirmDeleteAndRedirect( \'' . addslashes($defaults['title']) . '\', \'' . YD_SELF_SCRIPT . '?do=delete&id=' . $defaults['id'] . '\' );')); // Assign the values to the template $this->tpl->assign('page', $defaults); // Set the defaults $this->form->setDefaults($defaults); } // Process the form if ($this->form->validate() === true) { // Get the form values $values = $this->form->getValues(); // Update the datetimes $values['created'] = $values['created']['timestamp']; $values['modified'] = $values['modified']['timestamp']; // If there is an ID, we do an edit if ($values['id']) { // Update the database $this->weblog->updatePage($values); } else { // Set the user $values['user_id'] = $this->user['id']; // Add it to the database $this->weblog->addPage($values); } // Redirect to the default acton $this->redirectToAction(); } // Add the form to the template $this->tpl->assignForm('form', $this->form); // Display the template $this->display(); }
function actionEdit() { // Get the list of categories $categories = $this->weblog->getCategoriesAsAssoc(); // Create the edit form $form = new YDWeblogForm('itemForm', 'POST', YD_SELF_SCRIPT . '?do=edit'); $form->addElement('text', 'title', t('item_title'), array('class' => 'tfM')); $form->addElement('textarea', 'body', t('item_body'), array('class' => 'tfM')); $form->addElement('textarea', 'body_more', t('item_body_more'), array('class' => 'tfM')); $form->addElement('select', 'category_id', t('category'), array('class' => 'tfM', 'style' => 'width: 100%'), $categories); $form->addElement('datetimeselect', 'created', t('created_on'), array('class' => 'tfM')); $form->addElement('datetimeselect', 'modified', t('last_modified_on'), array('class' => 'tfM')); $form->addElement('checkbox', 'is_draft', t('is_draft'), array('style' => 'border: none;')); $form->addElement('hidden', 'id'); $form->addElement('submit', '_cmdSubmit', t('OK'), array('class' => 'button')); // Add the form rules $form->addRule('title', 'required', t('err_item_title')); $form->addRule('body', 'required', t('err_item_body')); // Add the filters $form->addFilters(array('title'), 'strip_html'); // Get the ID from the query string $id = $this->getIdFromQS(); // If there is something, set the defaults if ($id != -1) { // Get the comment by ID $defaults = $this->weblog->getItemById($id); $defaults['body'] = YDTemplate_modifier_bbcode($defaults['body']); $defaults['body_more'] = YDTemplate_modifier_bbcode($defaults['body_more']); $defaults['modified'] = gmmktime(); // Add delete button with existing items $form->addElement('button', '_cmdDelete', t('delete'), array('class' => 'button', 'onClick' => 'return YDConfirmDeleteAndRedirect( \'' . addslashes($defaults['title']) . '\', \'' . YD_SELF_SCRIPT . '?do=delete&id=' . $defaults['id'] . '\' );')); // Assign the values to the template $this->tpl->assign('item', $defaults); // Set the defaults $form->setDefaults($defaults); } else { // Get the defaults $defaults = array(); $defaults['is_draft'] = YDConfig::get('dflt_is_draft', false); // Set the form defaults $form->setDefaults($defaults); } // Process the form if ($form->validate() === true) { // Get the form values $values = $form->getValues(); // Update the datetimes $values['created'] = $values['created']['timestamp']; $values['modified'] = $values['modified']['timestamp']; // Set the user $values['user_id'] = $this->user['id']; // Check if we need to publish or not $needs_publish_email = false; // If there is an ID, we do an edit if ($values['id']) { // Get the item by ID $item = $this->weblog->getItemByID($values['id']); // Check if the item changes from draft to published if ($item['is_draft'] && !$values['is_draft']) { // Remember this $needs_publish_email = true; // Update the created timestamp $values['created'] = time(); $values['modified'] = time(); } // Update the database $this->weblog->updateItem($values); } else { // Check if the item is draft or not if (!$values['is_draft']) { // Remember this $needs_publish_email = true; // Update the created timestamp $values['created'] = time(); $values['modified'] = time(); } // Add it to the database $this->weblog->addItem($values); } // Check if we need to send an email if ($needs_publish_email) { // Send an email if configured if (YDConfig::get('email_new_item', true)) { // Add the item ID $values['id'] = $this->weblog->db->getLastInsertID(); // Include the YDEmail library YDInclude('YDEmail.php'); // Get the list of subscriptions $subscribers = $this->weblog->getUsers(); // Add the comment to the email template $this->tpl->assign('item', $values); $this->tpl->assign('weblog_link', YDUrl::makeLinkAbsolute('../index.php')); $this->tpl->assign('item_link', YDTplModLinkWithID('../item.php', $values['id'])); // Create the email and send it $eml = new YDEmail(); if (!empty($item['user_email'])) { $eml->setFrom($item['user_email'], YDConfig::get('weblog_title', 'Untitled Weblog')); } else { $eml->setFrom('*****@*****.**', YDConfig::get('weblog_title', 'Untitled Weblog')); } $eml->setReplyTo('*****@*****.**'); foreach ($subscribers as $subscriber) { $eml->addBcc($subscriber['email'], $subscriber['name']); } $eml->setSubject(t('new_item') . ': ' . strip_tags($values['title'])); $eml->setHtmlBody($this->fetch(dirname(__FILE__) . '/../' . $this->dir_skins . $this->skin . '/item_email.tpl')); $eml->send(); } } // Redirect to the default action if ($values['is_draft']) { $this->redirect(YD_SELF_SCRIPT . '?filter=drafts'); } else { $this->redirectToAction(); } } // Add the form to the template $this->tpl->assignForm('form', $form); // Display the template $this->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 #_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 actionEdit() { // Create the edit form $form = new YDWeblogForm('commentForm', 'POST', YD_SELF_SCRIPT . '?do=edit'); $form->addElement('text', 'username', t('name'), array('class' => 'tfM')); $form->addElement('text', 'useremail', t('mail'), array('class' => 'tfM')); $form->addElement('text', 'userwebsite', t('website'), array('class' => 'tfM')); $form->addElement('textarea', 'comment', t('comment'), array('class' => 'tfM')); $form->addElement('datetimeselect', 'created', t('created_on'), array('class' => 'tfM')); $form->addElement('checkbox', 'is_spam', t('is_spam'), array('style' => 'border: none;')); $form->addElement('hidden', 'id'); $form->addElement('submit', '_cmdSubmit', t('OK'), array('class' => 'button')); // Add the form rules $form->addRule('username', 'required', t('err_name')); $form->addRule('username', 'not_email', t('err_name_email')); $form->addRule('username', 'maxlength', t('err_name_length'), 35); $form->addRule('useremail', 'email', t('err_email')); $form->addRule('useremail', 'required', t('err_email')); $form->addRule('userwebsite', 'httpurl', t('err_website')); $form->addRule('comment', 'required', t('err_comment')); // Add the filters $form->addFilters(array('username', 'useremail', 'userwebsite'), 'strip_html'); // Get the ID from the query string $id = $this->getIdFromQS(); if ($id == -1) { $id = $form->getValue('id'); if ($id == '') { $id = -1; } } // If there is something, set the defaults if ($id != -1) { // Get the comment by ID $defaults = $this->weblog->getCommentById($id); $defaults['comment'] = YDTemplate_modifier_bbcode($defaults['comment']); // Add delete button with existing items $form->addElement('button', '_cmdDelete', t('delete'), array('class' => 'button', 'onClick' => 'return YDConfirmDeleteAndRedirect( \'' . addslashes(smarty_modifier_truncate(trim(strip_tags($defaults['comment'])))) . '\', \'' . YD_SELF_SCRIPT . '?do=delete&id=' . $defaults['id'] . '\' );')); // Set the defaults $form->setDefaults($defaults); // Add the comment to the template $this->tpl->assign('comment', $defaults); } // Check if the comment exists if ($form->getValue('id') == '') { $this->redirectToAction(); } // Process the form if ($form->validate() === true) { // Get the form values $values = $form->getValues(); // Update the datetimes $values['created'] = $values['created']['timestamp']; // Update the database $this->weblog->updateComment($values); // Redirect to the default acton $this->redirectToAction(); } // Add the form to the template $this->tpl->assignForm('form', $form); // Display the template $this->display(); }
function initGalleryFeed() { // Get the weblog items $items = $this->weblog->getPublicItems(); // Initialize the feed $this->feed = new YDFeedCreator(); $this->feed->setTitle(YDConfig::get('weblog_title', 'Untitled Weblog') . ' - ' . t('archives_gallery')); $this->feed->setDescription(YDConfig::get('weblog_description', 'Untitled Weblog Description')); $this->feed->setLink(YDUrl::makeLinkAbsolute('index.php')); // Add the items foreach ($items as $item) { if (sizeof($item['images']) > 0) { $body = ''; foreach ($item['images'] as $image) { $body .= '<img src="' . YDTplModLinkThumb($image) . '"/> '; } $this->feed->addItem($item['title'], YDTplModLinkItemImages($item), YDTemplate_modifier_bbcode($body), YDTplModLinkItemImages($item)); } } }