function micro_news_html_page_add_new() { //notify user if there is db update required kush_micronews_check_dbupdate(); $dbver = get_option('kush_mn_db_version', '0'); $what = ''; if (isset($_POST['k_mn_hidden']) && $_POST['k_mn_hidden'] == 'Y') { if (get_option('kush_mn_parse_html') == 'false') { $title = sanitize($_POST['k_mn_title']); $content = nl2br(sanitize($_POST['k_mn_content'])); //nl2br will convert any new line character to br tag respectively $link = sanitize($_POST['k_mn_link']); } else { $title = $_POST['k_mn_title']; $content = $_POST['k_mn_content']; $link = $_POST['k_mn_link']; } if (empty($_POST['k_mn_cat']) == false) { $cat = $_POST['k_mn_cat']; } else { $cat = "default"; } global $wpdb; $table_name = $wpdb->prefix . "kushmicronews"; $query = "INSERT INTO `{$table_name}` (`time`,`name`,`text`,`url`,`category`) VALUES ('" . date('Y-m-d H:i:s') . "','{$title}','{$content}','{$link}','{$cat}');"; if ($dbver == '0' || $dbver == '1.0' || $dbver == '') { //database without category column, to overwrite query string $query = "INSERT INTO `{$table_name}` (`time`,`name`,`text`,`url`) VALUES ('" . date('Y-m-d H:i:s') . "','{$title}','{$content}','{$link}');"; } if ($title != '') { $rows_affected = $wpdb->query($query); if ($rows_affected == true) { ?> <div class="updated"><p><strong><?php _e('New Post Added.'); ?> </strong></p></div>'<?php } } else { $what = 'Don\'t you think atleast title is necessary.'; } } ?> <div class="wrap"> <div class="icon32" id="icon-tools"> <br /> </div> <h2>Micro News Add New Post</h2> <?php if ($what != '') { echo '<h3>' . $what . '</h3>'; } ?> <form method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?> " id="add-micro-news"> <div> <div class="row"> <label for="k_mn_title">Title:</label> <input type="text" name="k_mn_title" placeholder="Title of News"/> </div> <div class="row"> <label for="k_mn_content">Content:</label> <textarea name="k_mn_content" placeholder="Excerpt">.</textarea> </div> <div class="row"> <label for="k_mn_link">Link:</label> <input type="text" name="k_mn_link" placeholder="Link Reference"/> </div> <?php if ($dbver != '0' && $dbver != '1.0' && $dbver != '') { ?> <div class="row"> <label for="k_mn_cat">Category Key:</label> <!-- <input type="text" name="k_mn_cat" placeholder="Category Key:" value="default"/> --> <select name="k_mn_cat"> <option value="default" selected>Default</option> <option value="cata">CatA</option> <option value="catb">CatB</option> <option value="catc">CatC</option> <option value="catd">CatD</option> </select> </div> <?php } ?> <input type="hidden" name="k_mn_hidden" value="Y"> <div class="row"> <input type="submit" value="<?php _e('Add New'); ?> " class="button-primary"/> </div> </div> </form> <div id="kush-micro-news-buyaredbull"> If you found this plugin useful and want to support its development then please consider <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4BFA297YJX5QN" target="_blank">buying</a> it or you can make my <a href="http://www.amazon.in/gp/registry/wishlist/CDMUYYAWCCDF/ref=cm_wl_huc_view" target="_blank">amazon wish</a> come true. Decide price yourself by how useful it is for you and don't forget to <a href="http://wordpress.org/support/view/plugin-reviews/kush-micro-news" target="_blank">rate</a>. Thanks. </div> </div> <?php }
function kush_micro_news_output_admin() { //this will check if update required kush_micronews_check_dbupdate(); global $wpdb; $table_name = $wpdb->prefix . "kushmicronews"; $what = ''; if (isset($_POST['nTitle']) & empty($_POST['nTitle']) === false) { if (get_option('kush_mn_parse_html') == 'false') { $title = sanitize($_POST['nTitle']); $id = sanitize($_POST['nId']); $content = sanitize($_POST['nContent']); $link = sanitize($_POST['nLink']); $cat = isset($_POST['nCat']) ? trim($_POST['nCat']) : ''; } else { $title = $_POST['nTitle']; $id = $_POST['nId']; $content = $_POST['nContent']; $link = $_POST['nLink']; $cat = isset($_POST['nCat']) ? trim($_POST['nCat']) : ''; } //different query if cat column is not present if ($cat == "") { $query = "UPDATE `{$table_name}` SET `name`='{$title}' , `text`='{$content}' , `url`='{$link}', `time`='" . date('Y-m-d H:i:s') . "' WHERE `id`='{$id}';"; } else { $query = "UPDATE `{$table_name}` SET `name`='{$title}' , `text`='{$content}' , `category`='{$cat}', `url`='{$link}', `time`='" . date('Y-m-d H:i:s') . "' WHERE `id`='{$id}';"; } $chk = $wpdb->query($query); if ($chk) { $what = 'Updated Sucessfully.'; } else { $what = 'Serious Error Occured :O'; } } if (isset($_POST['dId'])) { $id = sanitize($_POST['dId']); $query = "DELETE FROM {$table_name} WHERE `id`='{$id}';"; $chk = $wpdb->query($query); if ($chk) { $what = 'Deleted Sucessfully.'; } else { $what = 'Serious Error Occured :O'; } } if (is_admin()) { ?> <?php $totalpage = $wpdb->get_var("SELECT COUNT(id) FROM `{$table_name}`;"); $perpage = 10; $totalpage = ceil($totalpage / $perpage); $page = isset($_GET['pgno']) ? (int) $_GET['pgno'] : 1; $start = ($page - 1) * $perpage; $rows = $wpdb->get_results("SELECT * FROM `{$table_name}` ORDER BY `time` DESC LIMIT {$start},{$perpage};"); ?> <div class="wrap"> <h3></h3> <div class="icon32" id="icon-edit"> <br /> </div> <h2>Micro News Posts</h2> <?php if ($what != '') { echo '<div class="updated"><p>' . $what . '</p></div>'; } ?> <div id="micro-news-board" class="clearfix widefat"> <?php $i = 1; foreach ($rows as $row) { ?> <div class="wrapNews" data-id="<?php echo $row->id; ?> "> <span class="number"><?php echo $i; $i++; ?> ) </span> <h2 class="title" id="mn-title-<?php echo $row->id; ?> "> <?php echo $row->name; ?> </h2> <div class="text" id="mn-text-<?php echo $row->id; ?> "> <?php echo $row->text; ?> </div> <div class="container-admin-meta-link"> <span> <strong>on</strong> <?php $date = strtotime($row->time); echo date('d M Y', $date); ?> </span> | <?php if (empty($row->category) == false) { echo '<strong> Category key: </strong><span id="mn-cat-' . $row->id . '">' . $row->category . '</span> | '; } ?> <strong>Reference Link: </strong><span id="mn-link-<?php echo $row->id; ?> "><?php echo $row->url; ?> </a></span> </div> <input type="button" value="Edit" class="button-primary editB" data-id="mn-edit-<?php echo $row->id; ?> "/> <input type="button" value="X" class="button-primary closeB" /> <input type="button" value="Delete" class="button-primary delB"/> </div> <hr> <?php } //for each loop ?> </div> </div> <?php //micro news ends if ($totalpage >= 1 && $page < $totalpage) { ?> <ul class="micro-news-post-nav"><li style="border:0;">Page : </li> <?php for ($z = 1; $z <= $totalpage; $z++) { if ($z != $page) { echo '<li ><a href="?page=micro-news&pgno=' . $z . '">' . $z . '</a></li>'; } } } if ($page != 1) { echo '<li><a href="?page=micro-news&pgno=1">Home</a></li>'; } } // if closed ?> </ul> <?php }