예제 #1
0
 public static function update()
 {
     // verify Csrf token
     if (Csrf::verify(Input::post('token')) === false) {
         Notifications::set('error', 'Invalid token');
         return false;
     }
     $post = Input::post(array('sitename', 'description', 'theme', 'twitter', 'home_page', 'posts_page', 'auto_published_comments', 'posts_per_page'));
     $errors = array();
     if (empty($post['sitename'])) {
         $errors[] = Lang::line('metadata.missing_sitename', 'You need a site sitename');
     }
     if (empty($post['description'])) {
         $errors[] = Lang::line('metadata.missing_sitedescription', 'You need a site description');
     }
     if (empty($post['theme'])) {
         $errors[] = Lang::line('metadata.missing_theme', 'You need a theme');
     }
     // auto publish comments
     $post['auto_published_comments'] = $post['auto_published_comments'] ? 1 : 0;
     // format posts per page, must be a whole number above 1 defaults to 10 if a invalid number is entered
     $post['posts_per_page'] = ($posts_per_page = intval($post['posts_per_page'])) > 0 ? $posts_per_page : 10;
     if (count($errors)) {
         Notifications::set('error', $errors);
         return false;
     }
     foreach ($post as $key => $value) {
         Db::update('meta', array('value' => $value), array('key' => $key));
     }
     Notifications::set('success', Lang::line('metadata.meta_success_updated', 'Your metadata has been updated'));
     return true;
 }
예제 #2
0
 public static function add()
 {
     // verify Csrf token
     if (Csrf::verify(Input::post('token')) === false) {
         Notifications::set('error', 'Invalid token');
         return false;
     }
     $post = Input::post(array('slug', 'name', 'title', 'content', 'redirect', 'status'));
     $errors = array();
     if (empty($post['name'])) {
         $errors[] = Lang::line('pages.missing_name', 'Please enter a name');
     }
     if (empty($post['title'])) {
         $errors[] = Lang::line('pages.missing_title', 'Please enter a title');
     }
     // check for duplicate slug
     $sql = "select id from pages where slug = ?";
     if (Db::row($sql, array($post['slug']))) {
         $errors[] = Lang::line('pages.duplicate_slug', 'A pages with the same slug already exists, please change your page slug.');
     }
     if (count($errors)) {
         Notifications::set('error', $errors);
         return false;
     }
     if (empty($post['slug'])) {
         $post['slug'] = $post['name'];
     }
     $post['slug'] = Str::slug($post['slug']);
     Db::insert('pages', $post);
     Notifications::set('success', Lang::line('pages.page_success_created', 'Your new page has been added'));
     return true;
 }
예제 #3
0
 public static function add()
 {
     // verify Csrf token
     if (Csrf::verify(Input::post('token')) === false) {
         Notifications::set('error', 'Invalid token');
         return false;
     }
     $post = Input::post(array('title', 'slug', 'created', 'description', 'html', 'css', 'js', 'status', 'field', 'comments'));
     $errors = array();
     $post['created'] = strtotime($post['created']);
     if ($post['created'] === false) {
         $errors[] = Lang::line('posts.invalid_date', 'Please enter a valid date');
     }
     if (empty($post['title'])) {
         $errors[] = Lang::line('posts.missing_title', 'Please enter a title');
     }
     if (empty($post['description'])) {
         $errors[] = Lang::line('posts.missing_description', 'Please enter a description');
     }
     if (empty($post['html'])) {
         $errors[] = Lang::line('posts.missing_html', 'Please enter your html');
     }
     // use title as fallback
     if (empty($post['slug'])) {
         $post['slug'] = $post['title'];
     }
     // format slug
     $post['slug'] = Str::slug($post['slug']);
     // check for duplicate slug
     $sql = "select id from posts where slug = ?";
     if (Db::row($sql, array($post['slug']))) {
         $errors[] = Lang::line('posts.duplicate_slug', 'A post with the same slug already exists, please change your post slug.');
     }
     if (count($errors)) {
         Notifications::set('error', $errors);
         return false;
     }
     $custom = array();
     if (is_array($post['field'])) {
         foreach ($post['field'] as $keylabel => $value) {
             list($key, $label) = explode(':', $keylabel);
             $custom[$key] = array('label' => $label, 'value' => $value);
         }
     }
     // remove from update
     unset($post['field']);
     $post['custom_fields'] = json_encode($custom);
     // set author
     $user = Users::authed();
     $post['author'] = $user->id;
     Db::insert('posts', $post);
     Notifications::set('success', Lang::line('posts.post_success_created', 'Your new post has been added'));
     return true;
 }
예제 #4
0
 public static function add()
 {
     // verify Csrf token
     if (Csrf::verify(Input::post('token')) === false) {
         Notifications::set('error', 'Invalid token');
         return false;
     }
     $post = Input::post(array('username', 'password', 'email', 'real_name', 'bio', 'status', 'role'));
     $errors = array();
     if (empty($post['username'])) {
         $errors[] = Lang::line('users.missing_username', 'Please enter a username');
     } else {
         if (static::find(array('username' => $post['username']))) {
             $errors[] = Lang::line('users.username_exists', 'Username is already being used');
         }
     }
     if (empty($post['password'])) {
         $errors[] = Lang::line('users.missing_password', 'Please enter a password');
     }
     if (filter_var($post['email'], FILTER_VALIDATE_EMAIL) === false) {
         $errors[] = Lang::line('users.invalid_email', 'Please enter a valid email address');
     }
     if (empty($post['real_name'])) {
         $errors[] = Lang::line('users.missing_name', 'Please enter a display name');
     }
     if (count($errors)) {
         Notifications::set('error', $errors);
         return false;
     }
     // encrypt password
     $post['password'] = Hash::make($post['password']);
     // format email
     $post['email'] = strtolower(trim($post['email']));
     // strip tags on real_name (http://osvdb.org/show/osvdb/79659)
     $post['real_name'] = strip_tags($post['real_name']);
     // add record
     Db::insert('users', $post);
     Notifications::set('success', Lang::line('users.user_success_created', 'A new user has been added'));
     return true;
 }