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(); }