diff options
Diffstat (limited to 'admin/newPost.php')
| -rw-r--r-- | admin/newPost.php | 159 |
1 files changed, 159 insertions, 0 deletions
| diff --git a/admin/newPost.php b/admin/newPost.php new file mode 100644 index 0000000..eb6b4e0 --- /dev/null +++ b/admin/newPost.php | |||
| @@ -0,0 +1,159 @@ | |||
| 1 | <?php | ||
| 2 | /* | ||
| 3 | 444444444 | ||
| 4 | 4::::::::4 | ||
| 5 | 4:::::::::4 | ||
| 6 | 4::::44::::4 | ||
| 7 | 4::::4 4::::4 Four Island | ||
| 8 | 4::::4 4::::4 | ||
| 9 | 4::::4 4::::4 Written and maintained by Starla Insigna | ||
| 10 | 4::::444444::::444 | ||
| 11 | 4::::::::::::::::4 admin/newPost.php | ||
| 12 | 4444444444:::::444 | ||
| 13 | 4::::4 Please do not use, reproduce or steal the | ||
| 14 | 4::::4 contents of this file without explicit | ||
| 15 | 4::::4 permission from Hatkirby. | ||
| 16 | 44::::::44 | ||
| 17 | 4::::::::4 | ||
| 18 | 4444444444 | ||
| 19 | */ | ||
| 20 | |||
| 21 | if (!defined('S_INCLUDE_FILE')) {define('S_INCLUDE_FILE',1);} | ||
| 22 | |||
| 23 | require('headerproc.php'); | ||
| 24 | |||
| 25 | $category = 'posts'; | ||
| 26 | $pageaid = 'newpost'; | ||
| 27 | |||
| 28 | $template = new FITemplate('admin/writePost'); | ||
| 29 | |||
| 30 | if (isset($_GET['submit'])) | ||
| 31 | { | ||
| 32 | if (empty($_POST['title'])) | ||
| 33 | { | ||
| 34 | $errors[] = array( 'field' => 'title', | ||
| 35 | 'text' => 'Title is a required field'); | ||
| 36 | } | ||
| 37 | |||
| 38 | if (empty($_POST['text'])) | ||
| 39 | { | ||
| 40 | $errors[] = array( 'field' => 'text', | ||
| 41 | 'text' => 'The content of a blog post cannot be empty'); | ||
| 42 | } | ||
| 43 | |||
| 44 | if (empty($_POST['tags'])) | ||
| 45 | { | ||
| 46 | $errors[] = array( 'field' => 'tags', | ||
| 47 | 'text' => 'Tags is a required field'); | ||
| 48 | } | ||
| 49 | |||
| 50 | if ( | ||
| 51 | (strpos($_POST['tags'], ',') === 0) || | ||
| 52 | (strrpos($_POST['tags'], ',') === strlen($_POST['tags'])-1) || | ||
| 53 | (strpos($_POST['tags'], ',,') !== FALSE) | ||
| 54 | ) | ||
| 55 | { | ||
| 56 | $errors[] = array( 'field' => 'tags', | ||
| 57 | 'text' => 'Blank tags are not allowed'); | ||
| 58 | } | ||
| 59 | |||
| 60 | if (empty($_POST['type'])) | ||
| 61 | { | ||
| 62 | $errors[] = array( 'field' => 'type', | ||
| 63 | 'text' => 'Type is a required field'); | ||
| 64 | } | ||
| 65 | |||
| 66 | if (isset($errors)) | ||
| 67 | { | ||
| 68 | $template->adds_block('ISERROR',array('exi'=>1)); | ||
| 69 | |||
| 70 | $eid = 0; | ||
| 71 | foreach ($errors as $error) | ||
| 72 | { | ||
| 73 | $template->adds_block('ERROR', array( 'ID' => $eid, | ||
| 74 | 'TEXT' => $error['text'])); | ||
| 75 | $template->add('IS' . strtoupper($error['field']) . 'ERROR', ' error'); | ||
| 76 | $template->adds_block(strtoupper($error['field']) . 'ERROR', array( 'ID' => $eid, | ||
| 77 | 'TEXT' => $error['text'])); | ||
| 78 | |||
| 79 | $eid++; | ||
| 80 | } | ||
| 81 | |||
| 82 | $template->add('TITLE', 'Write New Post'); | ||
| 83 | $template->add('ACTION', '/admin/newPost.php?submit='); | ||
| 84 | } else { | ||
| 85 | $tags = explode(',', $_POST['tags']); | ||
| 86 | |||
| 87 | if ($_POST['type'] == 'draft') | ||
| 88 | { | ||
| 89 | $insdraft = "INSERT INTO drafts (title,author,text,slug) VALUES (\"" . mysql_real_escape_string($_POST['title']) . "\",\"" . getSessionUsername() . "\",\"" . mysql_real_escape_string($_POST['text']) . "\",\"" . generateSlug($_POST['title'],'updates') . "\")"; | ||
| 90 | $insdraft2 = mysql_query($insdraft); | ||
| 91 | |||
| 92 | $id = mysql_insert_id(); | ||
| 93 | $type = 'drafts'; | ||
| 94 | addTags($id, $tags, 'draft'); | ||
| 95 | } else if ($_POST['type'] == 'instant') | ||
| 96 | { | ||
| 97 | $id = postBlogPost($_POST['title'], getSessionUsername(), $tags, $_POST['text']); | ||
| 98 | $type = 'updates'; | ||
| 99 | } else { | ||
| 100 | if ($_POST['type'] == 'article') | ||
| 101 | { | ||
| 102 | $getpending = "SELECT * FROM pending ORDER BY id DESC LIMIT 0,1"; | ||
| 103 | $getpending2 = mysql_query($getpending); | ||
| 104 | $getpending3 = mysql_fetch_array($getpending2); | ||
| 105 | if (isset($getpending3['id']) === FALSE) | ||
| 106 | { | ||
| 107 | $id = 50; | ||
| 108 | } else { | ||
| 109 | $id = $getpending3['id']+1; | ||
| 110 | } | ||
| 111 | } else if ($_POST['type'] == 'high') | ||
| 112 | { | ||
| 113 | $getpending = "SELECT * FROM pending ORDER BY id ASC LIMIT 0,1"; | ||
| 114 | $getpending2 = mysql_query($getpending); | ||
| 115 | $getpending3 = mysql_fetch_array($getpending2); | ||
| 116 | if (isset($getpending3['id']) === FALSE) | ||
| 117 | { | ||
| 118 | $id = 50; | ||
| 119 | } else { | ||
| 120 | $id = $getpending3['id']-1; | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | $inspending = "INSERT INTO pending (id,title,author,text,slug) VALUES (" . $id . ",\"" . mysql_real_escape_string($_POST['title']) . "\",\"" . getSessionUsername() . "\",\"" . mysql_real_escape_string($_POST['text']) . "\",\"" . generateSlug($_POST['title'],'updates') . "\")"; | ||
| 125 | $inspending2 = mysql_query($inspending); | ||
| 126 | |||
| 127 | $type = 'pending'; | ||
| 128 | addTags($id, $tags, 'pending'); | ||
| 129 | } | ||
| 130 | |||
| 131 | if ($type == 'updates') | ||
| 132 | { | ||
| 133 | $getpost = "SELECT * FROM updates WHERE id = " . $id; | ||
| 134 | $getpost2 = mysql_query($getpost); | ||
| 135 | $getpost3 = mysql_fetch_array($getpost2); | ||
| 136 | |||
| 137 | $url = '/blog/' . $getpost3['slug'] . '/'; | ||
| 138 | } else { | ||
| 139 | $url = '/viewPost.php?type=' . $type . '&id=' . $id; | ||
| 140 | } | ||
| 141 | |||
| 142 | $template->add('ACTION', '/admin/editPost.php?type=' . $type . '&id=' . $id . '&submit='); | ||
| 143 | $template->adds_block('FLASH', array('TEXT' => 'Your post has been sucessfully created. <a href="' . $url . '">View post</a>.')); | ||
| 144 | $template->add('TITLE', 'Edit Post'); | ||
| 145 | if ($type != 'drafts') $template->add('TAGSDISABLED', ' readonly="readonly"'); | ||
| 146 | } | ||
| 147 | |||
| 148 | $template->add('TITLEVALUE', $_POST['title']); | ||
| 149 | $template->add('TEXTVALUE', $_POST['text']); | ||
| 150 | $template->add('TAGSVALUE', $_POST['tags']); | ||
| 151 | $template->add(strtoupper($_POST['type']) . 'SELECTED', ' checked="checked"'); | ||
| 152 | } else { | ||
| 153 | $template->add('TITLE', 'Write New Post'); | ||
| 154 | $template->add('ACTION', '/admin/newPost.php?submit='); | ||
| 155 | } | ||
| 156 | |||
| 157 | $template->display(); | ||
| 158 | |||
| 159 | ?> | ||
