function actionEdit() { // Get the ID from the query string $id = $this->getIdFromQS(); // Create a new form $form = new YDWeblogForm('userForm'); // Add the elements $form->addElement('hidden', 'id', ''); if ($id == '-1') { $form->addElement('text', 'name', t('username'), array('class' => 'tfM')); } else { $form->addElement('text', 'name', t('username'), array('class' => 'tfM', 'disabled' => '')); } $form->addElement('text', 'email', t('useremail'), array('class' => 'tfM')); $form->addElement('password', 'password', t('password'), array('class' => 'tfM')); $form->addElement('submit', 'cmdSubmit', t('save'), array('class' => 'button')); // Apply filters $form->addFilter('__ALL__', 'trim'); $form->addFilters(array('name', 'email'), 'strip_html'); // Add the rules $form->addRule('email', 'required', t('req_useremail')); $form->addRule('email', 'email', t('req_useremail')); if ($id == '-1') { $form->addRule('name', 'required', t('err_username')); $form->addRule('password', 'required', t('req_loginpass')); } $form->addFormRule(array(&$this, 'checkUserCredentials')); // Set the defaults if ($id != '-1') { // Get the user data $user = $this->weblog->getUserByID($id); unset($user['password']); // Set the form defaults $form->setDefaults($user); // Add this to the template $this->tpl->assign('user_data', $user); } // Validate the form if ($form->validate() == true) { // Get the form values $values = $form->getValues(); // Save the userdata $this->weblog->saveUser($values); // Go to the default view $this->redirectToAction(); } // Add the form to the template $this->tpl->assignForm('form', $form); // Display the template $this->display(); }
function actionDefault() { // Get the ID from the query string $id = $this->getIdFromQS(); // Get the weblog details and go to the default view if none is matched $item = @$this->weblog->getPublicItemById($id); $this->redirectIfMissing($item); // Get the related items $related_items = $this->weblog->getRelatedItemsByItem(YDConfig::get('weblog_entries_fp', 5), $item); // Convert the list of images to a table of 3 columns $item['images_as_table'] = YDArrayUtil::convertToTable($item['images'], 3, true); // Get the comments $comments = $this->weblog->getComments($id); // Assign the variables to the template $this->tpl->assign('title', $item['title']); $this->tpl->assign('item', $item); $this->tpl->assign('related_items', $related_items); $this->tpl->assign('comments', $comments); // Create the comments form $form = new YDWeblogForm('comments', 'POST', YDTplModLinkItemRespond($item), '_self', array('id' => 'commentform')); // Add the fields $form->addElement('text', 'username', t('name')); $form->addElement('text', 'useremail', t('mail_not_published')); $form->addElement('text', 'userwebsite', t('website')); $elem =& $form->addElement('captcha', 'security_code', t('enter_security_code')); $form->addElement('textarea', 'comment', ''); $form->addElement('submit', 'cmdSubmit', t('submit_comment'), array('class' => 'button')); $form->addElement('hidden', 'item_id'); // Change the text position of the captcha element $elem->setTextPosition(true); // Set the defaults $defaults = array(); $defaults['item_id'] = $id; $defaults['username'] = empty($_COOKIE['YD_USER_NAME']) ? '' : $_COOKIE['YD_USER_NAME']; $defaults['useremail'] = empty($_COOKIE['YD_USER_EMAIL']) ? '' : $_COOKIE['YD_USER_EMAIL']; $defaults['userwebsite'] = empty($_COOKIE['YD_USER_WEBSITE']) ? '' : $_COOKIE['YD_USER_WEBSITE']; $form->setDefaults($defaults); // Set the 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('security_code', 'captcha', t('err_security_code_not_valid')); $form->addRule('comment', 'required', t('err_comment')); $form->addRule('comment', 'maxlength', t('err_comment_length'), YDConfig::get('max_comment_length', 1500)); $form->addRule('comment', 'maxhyperlinks', t('err_comment_links'), YDConfig::get('max_comment_links', 1)); // Add the filters $form->addFilters(array('username', 'useremail', 'userwebsite'), 'strip_html'); // Process the form if ($form->validate() === true) { // Post request, so check comment interval if ($this->weblog->inSpamAttack()) { die('<b>ERROR:</b> Comment interval exceeded. Refusing request.'); } else { $this->weblog->spamCheckMark(); } // Get the form values $values = $form->getValues(); // Simple spam protection if (!empty($values['userwebsite']) && strpos($values['userwebsite'], '.') === false) { $this->redirect(YDTplModLinkItem($item, '#comment-' . $comment_id)); } // Fix any faulty web addresses if (!empty($values['userwebsite']) && substr(strtolower($values['userwebsite']), 0, 7) != 'http://') { $values['userwebsite'] = 'http://' . $values['userwebsite']; } // Save the username, useremail and userwebsite setcookie('YD_USER_NAME', $values['username'], time() + 31536000, '/'); setcookie('YD_USER_EMAIL', $values['useremail'], time() + 31536000, '/'); setcookie('YD_USER_WEBSITE', $values['userwebsite'], time() + 31536000, '/'); // Add the values to the database $comment = $this->weblog->addComment($values); // Send an email if configured if ($comment['id'] > 0 && YDConfig::get('email_new_comment', true)) { // Include the YDEmail library YDInclude('YDEmail.php'); // Get the list of subscriptions $subscribers = $this->weblog->getCommentSubscribers($id); // Get the list of subscriptions $users = $this->weblog->getUsers(); // Add the comment to the email template $this->tpl->assign('eml_comment', $comment); // 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('*****@*****.**'); $eml->addBcc($item['user_email']); // Spam emails do not go to the subscribers if (strval($comment['is_spam']) == '0') { foreach ($subscribers as $subscriber) { $eml->addBcc($subscriber); } } // Email the item owners foreach ($users as $user) { $eml->addBcc($user['email'], $user['name']); } // Set the subject and body if (strval($comment['is_spam']) == '0') { $eml->setSubject(t('new_comment') . ': ' . strip_tags($item['title'])); $eml->setHtmlBody($this->fetch('comment_email')); } else { $eml->setSubject('[spam] ' . t('new_comment') . ': ' . strip_tags($item['title'])); $eml->setHtmlBody($this->fetch('comment_email_spam')); } // Send the email $eml->send(); } // Clear the cache $this->clearCache(); // Redirect to the item $this->redirect(YDTplModLinkItem($item, '#comment-' . $comment['id'])); } // Add the form to the template $this->tpl->assignForm('comments_form', $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 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('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('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')); // 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(); // 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(); }
function actionLogin() { // Redirect to default action if already logged in if ($this->isAuthenticated() == true || !is_null($this->user)) { $this->forward('default'); return; } // Create the login form $form = new YDWeblogForm('loginForm'); // Check if the login name exists if (!empty($_COOKIE['YD_USER_NAME'])) { $form->setDefaults(array('loginName' => $_COOKIE['YD_USER_NAME'])); } // Add the elements $form->addElement('text', 'loginName', t('username'), array('class' => 'tfS')); $form->addElement('password', 'loginPass', t('password'), array('class' => 'tfS')); $form->addElement('submit', 'cmdSubmit', t('login'), array('class' => 'button')); // Add the element rules $form->addRule('loginName', 'required', t('err_username')); $form->addRule('loginPass', 'required', t('err_password')); // Add the rules $form->addFormRule(array(&$this, 'checkLogin')); // Process the form if ($form->validate() == true) { // Get the form values $values = $form->getValues(); // Set the cookies setcookie('YD_USER_NAME', $values['loginName'], time() + 31536000, '/'); setcookie('YD_USER_PASS', md5($values['loginPass']), time() + 31536000, '/'); // Set the username $this->username = $values['loginName']; // Forward to the main manage page $this->redirect('index.php'); } // Add the form to the template $this->tpl->assignForm('form', $form); // Output the template $this->display('login'); }
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('wladmintextarea', 'body', t('item_body'), array('class' => 'tfM')); $form->addElement('wladmintextarea', '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('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['modified'] = gmmktime(); // Assign the values to the template $this->tpl->assign('item', $defaults); // Set the 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']; // If there is an ID, we do an edit if ($values['id']) { // Update the database $this->weblog->updateItem($values); } else { // Add it to the database $this->weblog->addItem($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 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('wladmintextarea', 'comment', t('comment'), array('class' => 'tfM')); $form->addElement('datetimeselect', 'created', t('created_on'), array('class' => 'tfM')); $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('useremail', 'email', t('err_email')); $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 there is something, set the defaults if ($id != -1) { // Get the comment by ID $defaults = $this->weblog->getCommentById($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') == '') { // Return to the default action $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 actionDefault() { // Get the table statistics $tables_size = 0; $tables = $this->weblog->db->getRecords('SHOW TABLE STATUS'); foreach ($tables as $key => $table) { $tables[$key] = array(); $tables[$key]['name'] = $table['name']; $tables[$key]['rows'] = intval($table['rows']); $tables[$key]['size'] = intval($table['data_length']) + intval($table['index_length']); $tables_size = $tables_size + $tables[$key]['size']; } $this->tpl->assign('tables', $tables); $this->tpl->assign('tables_size', $tables_size); // The backup types we have $bck_types = array(0 => t('bck_full') . '<br/>', 1 => t('bck_structure_only') . '<br/>', 2 => t('bck_data_only') . '<br/>'); // Create the backup form $form = new YDWeblogForm('dbBackupForm'); $form->addElement('text', 'bck_name', t('bck_name'), array('class' => 'tfM')); $form->addElement('checkbox', 'bck_gzip', t('gz_compress'), array('style' => 'border: none;')); $form->addElement('radio', 'bck_type', t('bck_type'), array('style' => 'border: none;'), $bck_types); $form->addElement('submit', '_cmdSubmit', t('backup'), array('class' => 'button')); $form->setDefaults(array('bck_name' => '%Y-%m-%d_%DBNAME', 'bck_gzip' => 1, 'bck_type' => 0)); // Add the rules $form->addRule('bck_name', 'required', t('err_bck_name')); // Add the filters $form->addFilters(array('bck_name'), 'strip_html'); // Validate the form if ($form->validate() == true) { // Create a backup object $bck = new YDMysqlDump($this->weblog->db); // Configure the backup $bck->displayComments(true); if ($form->getValue('bck_type') == '1') { $bck->displayDrops(true); $bck->displayStructure(true); $bck->displayData(false); } elseif ($form->getValue('bck_type') == '2') { $bck->displayDrops(false); $bck->displayStructure(false); $bck->displayData(true); } else { $bck->displayDrops(true); $bck->displayStructure(true); $bck->displayData(true); } // Get the backup data $bck_data = $bck->backup(); // Compress with GZip if ($form->getValue('bck_gzip') == 1) { $bck_data = gzencode($bck_data); } // The name of the backup $name = $form->getValue('bck_name'); $name = str_replace('%DBNAME', $this->weblog->db->_db, $name); $name = strftime($name, time()); // Add the extension to the name of the backup if ($form->getValue('bck_gzip') == 1) { $name .= '.sql.gz'; } else { $name .= '.sql'; } // Dump the data header('Content-Type: application/force-download; name="' . $name . '"'); header('Content-Disposition: attachment; filename="' . $name . ' "'); header('Cache-Control: public'); header('Content-Transfer-Encoding: binary'); echo $bck_data; die; } // Add the form to the template $this->tpl->assignForm('form', $form); // Display the template $this->display(); }
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 actionDefault() { // Get the ID from the query string $id = $this->getIdFromQS(); // Get the weblog details and go to the default view if none is matched $item = @$this->weblog->getItemById($id); $this->redirectIfMissing($item); // Convert the list of images to a table of 3 columns $item['images_as_table'] = YDArrayUtil::convertToTable($item['images'], 3, true); // Get the comments $comments = $this->weblog->getComments($id); // Add them to the template $this->tpl->assign('item', $item); $this->tpl->assign('comments', $comments); // Create the comments form $form = new YDWeblogForm('comments', 'POST', YDTplModLinkItemRespond($item), '_self', array('id' => 'commentform')); // Add the fields $form->addElement('text', 'username', t('name')); $form->addElement('text', 'useremail', t('mail_not_published')); $form->addElement('text', 'userwebsite', t('website')); $form->addElement('wlbbtextarea', 'comment', '', array('style' => 'width: 450px')); $form->addElement('submit', 'cmdSubmit', t('submit_comment'), array('id' => 'submit')); $form->addElement('hidden', 'item_id'); // Set the defaults $defaults = array(); $defaults['item_id'] = $id; $defaults['username'] = empty($_COOKIE['YD_USER_NAME']) ? '' : $_COOKIE['YD_USER_NAME']; $defaults['useremail'] = empty($_COOKIE['YD_USER_EMAIL']) ? '' : $_COOKIE['YD_USER_EMAIL']; $defaults['userwebsite'] = empty($_COOKIE['YD_USER_WEBSITE']) ? '' : $_COOKIE['YD_USER_WEBSITE']; $form->setDefaults($defaults); // Set the rules $form->addRule('username', 'required', t('err_name')); $form->addRule('username', 'not_email', t('err_name_email')); $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'); // Process the form if ($form->validate() === true) { // Get the form values $values = $form->getValues(); // Simple spam protection if (!empty($values['userwebsite']) && strpos($values['userwebsite'], '.') === false) { $this->redirect(YDTplModLinkItem($item, '#comment-' . $comment_id)); } // Fix any faulty web addresses if (!empty($values['userwebsite']) && substr(strtolower($values['userwebsite']), 0, 7) != 'http://') { $values['userwebsite'] = 'http://' . $values['userwebsite']; } // Save the username, useremail and userwebsite setcookie('YD_USER_NAME', $values['username'], time() + 31536000, '/'); setcookie('YD_USER_EMAIL', $values['useremail'], time() + 31536000, '/'); setcookie('YD_USER_WEBSITE', $values['userwebsite'], time() + 31536000, '/'); // Add the values to the database $comment_id = $this->weblog->addComment($values); // Send an email if configured if (YDConfig::get('email_new_comment', true)) { // Include the YDEmail library YDInclude('YDEmail.php'); // Get the list of subscriptions $subscribers = $this->weblog->getCommentSubscribers($id); // Add the comment to the email template $this->tpl->assign('eml_comment', $values); // 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('*****@*****.**'); $eml->addBcc($item['user_email']); foreach ($subscribers as $subscriber) { $eml->addBcc($subscriber); } $eml->setSubject('New comment: ' . strip_tags($item['title'])); $eml->setHtmlBody($this->fetch('comment_email')); $eml->send(); } // Clear the cache $this->clearCache(); // Redirect to the item $this->redirect(YDTplModLinkItem($item, '#comment-' . $comment_id)); } // Add the form to the template $this->tpl->assignForm('comments_form', $form); // Display the template $this->display(); }