Ejemplo n.º 1
0
function list_action()
{
    $postModel = new PostModel();
    $posts = $postModel->get_all_posts();
    $html = render_template("view/templates/list.php", array('posts' => $posts));
    return new Response($html);
}
Ejemplo n.º 2
0
function show_action($id)
{
    $model = new PostModel();
    $post = $model->get_post_by_id($id);
    $html = render_template('View/Templates/show.php', array('post' => $post));
    return $html;
    //require "View/Templates/show.php";
}
 public function findAllPosts()
 {
     $usersData = $this->storage->findAll();
     $result = [];
     foreach ($usersData as $data) {
         $user = new PostModel();
         $user->setId($data['id']);
         $user->setTitle($data['title']);
         $user->setContent($data['content']);
         $user->setAuthor($data['author']);
         $result[] = $user;
     }
     return $result;
 }
 public static function ActionDeletePost($id)
 {
     if (ModeratorModel::isModerator()) {
         PostModel::deletePost($id);
     }
     header('Location: ' . $_SERVER['HTTP_REFERER']);
 }
Ejemplo n.º 5
0
 public function get_total_posts()
 {
     $pdo = PostModel::connect_db();
     $sql_get = "SELECT count(*) FROM posts";
     $total = $pdo->query($sql_get)->fetchColumn();
     return $total;
 }
Ejemplo n.º 6
0
 public static function ActionMain($id)
 {
     $post = PostModel::getPostsById($id);
     $post['id'] = $id;
     $variables = ['template' => 'events.php', 'links' => ['slider.css', 'events.css'], 'scripts' => ['slider.js'], 'post' => $post, 'postCount' => PostModel::getPostsCount(), 'quizes' => PostModel::getQuizToPost($id)];
     $variables = array_merge_recursive(self::getMainVariables(), $variables);
     Template::render('template.php', $variables);
 }
Ejemplo n.º 7
0
 public static function ActionAddComment($postId)
 {
     if (UserModel::isUserLoggedIn() and isset($_POST['text'])) {
         $text = $_POST['text'];
         PostModel::addComment($postId, $text);
     }
     header("Location: " . $_SERVER['HTTP_REFERER']);
 }
Ejemplo n.º 8
0
 public function deleteAction()
 {
     if (!isset($_POST['postId'])) {
         return json_encode(["error" => "postId missing"]);
     }
     $postId = $_POST['postId'];
     PostModel::delete($this->pdo, $postId);
     return json_encode(["message" => "Supprimé !", "postId" => $postId]);
 }
Ejemplo n.º 9
0
 public function delete($type)
 {
     var_dump($this);
     die;
     PostMetaModel::load()->delete('Post_ID', Input::get('id'));
     UploadItemModel::load()->delete('Post_ID', Input::get('id'));
     PostModel::load($type)->delete('ID', Input::get('ID'));
     Session::set('SUCCESS', I18n::get('SYSTEM_CRUD_SUCCESS'));
     Redirect::to($this->project_url . "admin/read/post/{$type}/");
 }
Ejemplo n.º 10
0
 public function getPosts()
 {
     $this->array = array();
     $stmt = $this->mysqli->prepare("SELECT `Title`, `Text`, `Author`,`Description`, `Date` FROM " . self::$table);
     if (!$stmt) {
         throw new \Exception($this->mysqli->error);
     }
     $stmt->execute();
     $stmt->bind_result($title, $text, $author, $date);
     while ($stmt->fetch()) {
         $title = $this->parser->text($title);
         $author = $this->parser->text($author);
         $text = $this->parser->text($text);
         $description = $this->parser->text($description);
         $post = new PostModel($title, $text, $author, $description, $date);
         $this->array[$post->getUnique()] = $post;
     }
     return $this->array;
 }
Ejemplo n.º 11
0
 public function save()
 {
     $post = PostModel::get($this->post_id);
     $data = ['id' => $this->id, 'post_id' => $this->post_id, 'user_id' => $this->user_id, 'name' => $this->name, 'message' => $this->message, 'updated_at' => date(MYSQL_DATE_TIME)];
     $db = DB::instance();
     $this->id = $db->store($data, self::$table);
     $post->comment_count = self::getCommentCount($post);
     $post->save();
     return $this->id;
 }
Ejemplo n.º 12
0
 public function actionIndex($current_page = 1)
 {
     $limit = 5;
     $this->view->title = "Блог";
     $user = UserModel::isAuthorized();
     $posts = PostModel::getPosts($limit, ($current_page - 1) * $limit);
     $total = PostModel::getPostCount();
     $pagination = new \Utils\Pagination($total, $limit, $current_page);
     return $this->view->htmlPage("index/index", compact("user", "posts", "pagination"));
 }
Ejemplo n.º 13
0
 public function delete()
 {
     if (!isset($_GET['id'])) {
         die("Please, specify id");
     }
     $id = $_GET['id'];
     $model = PostModel::model()->getById($id);
     if ($model->isNewRecord()) {
         die("Post with id {$id} is not found!");
     }
     $model->delete();
     $this->redirect('index');
 }
Ejemplo n.º 14
0
 /**
  * delete
  *
  * Delete attachment by id
  *
  * @param int $attachment_id ID of attachment
  */
 public function delete($attachment_id)
 {
     try {
         $postBO = $this->get($attachment_id);
         if (isset($postBO->attached_file) && $postBO->attached_file != "") {
             Utils::deleteFile($postBO->attached_file);
         }
         if (parent::delete($attachment_id)) {
             return TRUE;
         }
     } catch (Exception $e) {
     }
     return FALSE;
 }
Ejemplo n.º 15
0
 public function actionSaveComment($post_id)
 {
     $post = PostModel::get($post_id);
     $input = \System\Engine::getInput();
     $data = $input->getArray("data");
     $data = array_intersect_key($data, array_flip(["name", "message"]));
     $user = UserModel::isAuthorized();
     $data['post_id'] = $post_id;
     $data['message'] = strip_tags($data['message']);
     if ($user) {
         $data['user_id'] = $user->id;
     } else {
         $data['name'] = strip_tags($data['name']);
     }
     try {
         $comment = new PostCommentModel();
         $comment->setData($data);
         $comment->save();
         $this->redirect("/post/show/{$post->id}#comments");
     } catch (Exception $e) {
         $this->redirect("/post/show/{$post->id}#comments", $e->getMessage());
     }
 }
Ejemplo n.º 16
0
<?php

/**
 * @author asmalindi
 * @copyright 2011
 */
require "PostModel.php";
include "process.php";
$postM = new PostModel();
$post = new Post();
?>
<head>                           
<link href="menu.css" rel="stylesheet" type="text/css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.js"></script>
<script type="text/javascript" src="menu.js"></script>
<style type="text/css">
<!--
    body,
    html {
        margin:0;
        padding:0;
        color:#000;
        background:#a7a09a;
    }
    
    #wrap {
        width:750px;
        margin:0 auto;
        background:#99c;
    }
Ejemplo n.º 17
0
 public function viewPost()
 {
     $session = new SessionHelper();
     if ($this->_authCheck()) {
         // Instance used for data on page
         $user = new User();
         $postmodel = new PostModel();
         // Id of the top post
         $id = htmlspecialchars($_GET['id']);
         // Instance used for data on page
         $thispost = new Post($id);
         $replies = $postmodel->getRepliesTopPostById($id);
         // Increment the views file of this post
         if (file_exists(BASE_URI . 'views/' . $id . '.txt')) {
             $viewsfile = file_get_contents(BASE_URI . 'views/' . $id . '.txt');
             $viewsfile++;
             $handle = fopen(BASE_URI . 'views/' . $id . '.txt', "w");
             fwrite($handle, $viewsfile);
             fclose($handle);
         }
         // Load the views
         $page_title = h($thispost->title);
         include BASE_URI . 'app/view/user/template/header.php';
         include BASE_URI . 'app/view/post/post.php';
         if ($replies != false) {
             include_once BASE_URI . 'app/view/post/viewreply.php';
         }
         include BASE_URI . 'app/view/user/template/footer.php';
     } else {
         $this->viewLoginPage();
     }
 }
Ejemplo n.º 18
0
 public function updateContent($countryBO)
 {
     if (isset($countryBO->postBO)) {
         $postBO = $countryBO->postBO;
         try {
             $sql = "UPDATE " . TABLE_POSTS . " ";
             $set = "SET ";
             $where = " WHERE " . TB_POST_COL_ID . " = :post_id;";
             $para_array = [];
             $para_array[":post_id"] = $postBO->ID;
             if (isset($countryBO->name)) {
                 $postBO->post_title = $countryBO->name;
                 $set .= " " . TB_POST_COL_POST_TITLE . " = :post_title,";
                 $para_array[":post_title"] = $postBO->post_title;
             }
             if (isset($countryBO->overview) || isset($countryBO->history) || isset($countryBO->weather) || isset($countryBO->passport_visa) || isset($countryBO->currency) || isset($countryBO->phone_internet_service) || isset($countryBO->transportation) || isset($countryBO->food_drink) || isset($countryBO->public_holiday) || isset($countryBO->predeparture_check_list)) {
                 $post_content = new stdClass();
                 if (isset($countryBO->overview)) {
                     $post_content->overview = $countryBO->overview;
                 }
                 if (isset($countryBO->history)) {
                     $post_content->history = $countryBO->history;
                 }
                 if (isset($countryBO->weather)) {
                     $post_content->weather = $countryBO->weather;
                 }
                 if (isset($countryBO->passport_visa)) {
                     $post_content->passport_visa = $countryBO->passport_visa;
                 }
                 if (isset($countryBO->currency)) {
                     $post_content->currency = $countryBO->currency;
                 }
                 if (isset($countryBO->phone_internet_service)) {
                     $post_content->phone_internet_service = $countryBO->phone_internet_service;
                 }
                 if (isset($countryBO->transportation)) {
                     $post_content->transportation = $countryBO->transportation;
                 }
                 if (isset($countryBO->food_drink)) {
                     $post_content->food_drink = $countryBO->food_drink;
                 }
                 if (isset($countryBO->public_holiday)) {
                     $post_content->public_holiday = $countryBO->public_holiday;
                 }
                 if (isset($countryBO->predeparture_check_list)) {
                     $post_content->predeparture_check_list = $countryBO->predeparture_check_list;
                 }
                 $postBO->post_content = json_encode($post_content);
                 $set .= " " . TB_POST_COL_POST_CONTENT . " = :post_content,";
                 $para_array[":post_content"] = $postBO->post_content;
             }
             if (isset($countryBO->name)) {
                 $postBO->post_name = Utils::createSlug($countryBO->name);
                 $set .= " " . TB_POST_COL_POST_NAME . " = :post_name,";
                 $para_array[":post_name"] = $postBO->post_name;
             }
             if (isset($postBO->image_weather_ids)) {
                 $image_weather_ids = json_decode($postBO->image_weather_ids);
             } else {
                 $image_weather_ids = array();
             }
             Model::autoloadModel("image");
             $imageModel = new ImageModel($this->db);
             if (isset($countryBO->image_weathers_upload)) {
                 $imageModel->is_create_thumb = true;
                 $imageModel->is_slider_thumb = true;
                 $imageModel->is_medium_large = true;
                 //                $imageModel->slider_thumb_crop = true;
                 $image_array_id = $imageModel->uploadImages("image_weathers");
                 if (!is_null($image_array_id) && is_array($image_array_id) && sizeof($image_array_id) != 0) {
                     $image_weather_ids = array_merge($image_weather_ids, $image_array_id);
                 } else {
                     return FALSE;
                 }
             }
             if (isset($countryBO->image_weather_delete_list) && $countryBO->image_weather_delete_list != "" && $countryBO->image_weather_delete_list != NULL) {
                 $image_weather_delete_array = explode(",", $countryBO->image_weather_delete_list);
                 if (count($image_weather_delete_array) > 0) {
                     foreach ($image_weather_delete_array as $image_delete_id) {
                         $image_weather_ids = array_diff($image_weather_ids, [$image_delete_id]);
                         //                            array_slice($image_weather_ids, $image_delete_id, 1);
                         //                            array_slice($image_weather_ids, $image_delete_id);
                     }
                 }
             }
             if (count($para_array) != 0) {
                 $set = substr($set, 0, strlen($set) - 1);
                 $sql .= $set . $where;
                 $sth = $this->db->prepare($sql);
                 $sth->execute($para_array);
                 Model::autoloadModel("post");
                 $postModel = new PostModel($this->db);
                 $image_weather_ids = json_encode($image_weather_ids);
                 if (isset($image_weather_ids) && $image_weather_ids != "") {
                     if (isset($postBO->image_weather_ids)) {
                         if (!$postModel->updateMetaInfoToDatabase($postBO->ID, "image_weather_ids", $image_weather_ids)) {
                             if (isset($imageModel) && isset($image_array_id)) {
                                 foreach ($image_array_id as $image_weather_id) {
                                     $imageModel->delete($image_weather_id);
                                 }
                             }
                             return FALSE;
                         } else {
                             //thanh cong xoa image bi tich bo
                             if (isset($imageModel) && isset($image_weather_delete_array)) {
                                 foreach ($image_weather_delete_array as $image_weather_id) {
                                     $imageModel->delete($image_weather_id);
                                 }
                             }
                         }
                     } else {
                         if (!$postModel->addMetaInfoToDatabase($postBO->ID, "image_weather_ids", $image_weather_ids)) {
                             if (isset($imageModel) && isset($image_array_id)) {
                                 foreach ($image_array_id as $image_weather_id) {
                                     $imageModel->delete($image_weather_id);
                                 }
                             }
                             return FALSE;
                         } else {
                             //thanh cong xoa image bi tich bo
                             if (isset($imageModel) && isset($image_weather_delete_array)) {
                                 foreach ($image_weather_delete_array as $image_weather_id) {
                                     $imageModel->delete($image_weather_id);
                                 }
                             }
                         }
                     }
                 }
                 return TRUE;
             }
         } catch (Exception $e) {
         }
     }
 }
Ejemplo n.º 19
0
 public function updateContent($attractionBO)
 {
     if (isset($attractionBO->postBO)) {
         $postBO = $attractionBO->postBO;
         try {
             $sql = "UPDATE " . TABLE_POSTS . " ";
             $set = "SET ";
             $where = " WHERE " . TB_POST_COL_ID . " = :post_id;";
             $para_array = [];
             $para_array[":post_id"] = $postBO->ID;
             if (isset($attractionBO->name)) {
                 $postBO->post_title = $attractionBO->name;
                 $set .= " " . TB_POST_COL_POST_TITLE . " = :post_title,";
                 $para_array[":post_title"] = $postBO->post_title;
             }
             if (isset($attractionBO->post_content_1) || isset($attractionBO->post_content_2)) {
                 $post_content = new stdClass();
                 if (isset($attractionBO->post_content_1)) {
                     $post_content->post_content_1 = $attractionBO->post_content_1;
                 }
                 if (isset($attractionBO->post_content_2)) {
                     $post_content->post_content_2 = $attractionBO->post_content_2;
                 }
                 $postBO->post_content = json_encode($post_content);
                 $set .= " " . TB_POST_COL_POST_CONTENT . " = :post_content,";
                 $para_array[":post_content"] = $postBO->post_content;
             }
             if (isset($attractionBO->name)) {
                 $postBO->post_name = Utils::createSlug($attractionBO->name);
                 $set .= " " . TB_POST_COL_POST_NAME . " = :post_name,";
                 $para_array[":post_name"] = $postBO->post_name;
             }
             if (isset($postBO->image_ids)) {
                 $image_ids = json_decode($postBO->image_ids);
             } else {
                 $image_ids = array();
             }
             Model::autoloadModel("image");
             $imageModel = new ImageModel($this->db);
             if (isset($attractionBO->images_upload)) {
                 $imageModel->is_create_thumb = true;
                 $imageModel->is_slider_thumb = true;
                 $imageModel->is_large = true;
                 //                $imageModel->slider_thumb_crop = true;
                 $image_array_id = $imageModel->uploadImages("images");
                 if (!is_null($image_array_id) && is_array($image_array_id) && sizeof($image_array_id) != 0) {
                     $image_ids = array_merge($image_ids, $image_array_id);
                 } else {
                     return FALSE;
                 }
             }
             if (isset($attractionBO->image_delete_list) && $attractionBO->image_delete_list != "" && $attractionBO->image_delete_list != NULL) {
                 $image_delete_array = explode(",", $attractionBO->image_delete_list);
                 if (count($image_delete_array) > 0) {
                     foreach ($image_delete_array as $image_delete_id) {
                         $image_ids = array_diff($image_ids, [$image_delete_id]);
                         //                            array_slice($image_ids, $image_delete_id, 1);
                     }
                 }
             }
             if (count($para_array) != 0) {
                 $set = substr($set, 0, strlen($set) - 1);
                 $sql .= $set . $where;
                 $sth = $this->db->prepare($sql);
                 $sth->execute($para_array);
                 Model::autoloadModel("post");
                 $postModel = new PostModel($this->db);
                 $image_ids = json_encode($image_ids);
                 if (isset($image_ids) && $image_ids != "") {
                     if (isset($postBO->image_ids)) {
                         if (!$postModel->updateMetaInfoToDatabase($postBO->ID, "image_ids", $image_ids)) {
                             if (isset($imageModel) && isset($image_array_id)) {
                                 foreach ($image_array_id as $image_id) {
                                     $imageModel->delete($image_id);
                                 }
                             }
                             return FALSE;
                         } else {
                             //thanh cong xoa image bi tich bo
                             if (isset($imageModel) && isset($image_delete_array)) {
                                 foreach ($image_delete_array as $image_id) {
                                     $imageModel->delete($image_id);
                                 }
                             }
                         }
                     } else {
                         if (!$postModel->addMetaInfoToDatabase($postBO->ID, "image_ids", $image_ids)) {
                             if (isset($imageModel) && isset($image_array_id)) {
                                 foreach ($image_array_id as $image_id) {
                                     $imageModel->delete($image_id);
                                 }
                             }
                             return FALSE;
                         } else {
                             //thanh cong xoa image bi tich bo
                             if (isset($imageModel) && isset($image_delete_array)) {
                                 foreach ($image_delete_array as $image_id) {
                                     $imageModel->delete($image_id);
                                 }
                             }
                         }
                     }
                 }
                 return TRUE;
             }
         } catch (Exception $e) {
         }
     }
 }
Ejemplo n.º 20
0
 /**
  *  When an User updates his profile, we need to 
  *  make sure that every post written by him is also
  *  updated with his name and username.
  *
  *  @return void
  */
 function after_update()
 {
     $post = new PostModel();
     $post->updateAuthorInfo($this->getID());
 }
Ejemplo n.º 21
0
 public function update_action($id)
 {
     $postModel = new PostModel();
     $postModel->update_row($id);
     $posts = $postModel->get_all_rows();
     $html = $this->render_template("view/templates/admin.php", array('posts' => $posts));
     return new Response($html);
 }
Ejemplo n.º 22
0
<?php

if (!empty($atts) && is_array($atts)) {
    $nb = 5;
    if (array_key_exists($atts, 'nb')) {
        if (is_numeric($atts['nb'])) {
            $nb = $atts['nb'];
        }
    }
    if (array_key_exists($atts, 'type')) {
        switch ($atts['type']) {
            case "post":
                $p = PostModel::all($nb);
                break;
            case "gallery":
                $p = GalleryModel::all($nb);
                break;
            case "product":
                $p = ProductModel::all($nb);
                break;
            default:
                $p = PostModel::all($nb);
        }
    }
}
?>

@include('partials.home.slider', [
    'post' => $p
])
Ejemplo n.º 23
0
 public function deleteTopPost()
 {
     $postid = htmlspecialchars($_GET['id']);
     $session = new SessionHelper();
     $user = new User();
     $post = new Post($postid);
     $postmodel = new PostModel();
     $categorymodel = new CategoryModel();
     $category = new Category($post->category_id);
     // Only an admin or the moderator of this category may delete a toppost
     if ($user->role == 1 || $user->id == $category->moderator_id) {
         // This method will remove child posts (replies) as well
         if ($postmodel->deleteTopPost($postid)) {
             $session->setMessage('Post removed', 4);
             redirectTo('index.php?c=user&a=viewdashboard');
         } else {
             $session->setMessage('Post not removed', 3);
             redirectTo('index.php?c=user&a=viewdashboard');
         }
     } else {
         $session->setMessage('You are not an admin or you are not the moderator of this category', 2);
         redirectTo('index.php?c=user&a=viewdashboard');
     }
 }
Ejemplo n.º 24
0
 public function LivePost($param)
 {
     $data = parent::LivePostProcess($param);
     if ($param['export'] == "html") {
         $this->render($param['render'], $data, '');
     } else {
         if ($param['export'] == "json") {
             return $data;
         } else {
             return false;
         }
     }
 }
Ejemplo n.º 25
0
 public function controller_get_total_posts()
 {
     $postmodel = new PostModel();
     $total = $postmodel->get_total_posts();
     return $total;
 }
Ejemplo n.º 26
0
PostModel::drop();
AuthorModel::drop();
/* This should be done just once */
ActiveMongo::install();
/* Create a new author
 * The property country is not defined
 * as an AuthorModel property, but it will
 * be saved. 
 */
$author = new AuthorModel();
$author->username = "******";
$author->name = "Cesar Rodas";
$author->country = "PY";
$author->save();
/* Add one blog post */
$post = new PostModel();
$post->uri = "/hello-world";
$post->title = "Hello World";
$post->author = $author->getID();
/* add one comment */
$post->add_comment("testing", "*****@*****.**", "testing comment");
$post->save();
/* add another comment */
$post->add_comment("testing", "*****@*****.**", "cool post");
$post->save();
for ($i = 0; $i < 1000; $i++) {
    /* Add another post */
    $post->reset();
    /* reet the post object */
    $post->uri = "/" . uniqid();
    $post->title = "Yet another post ({$i})";
Ejemplo n.º 27
0
 public function delete($post_id)
 {
     try {
         $internalflightBO = $this->get($post_id);
         if ($internalflightBO != NULL) {
             if (parent::delete($post_id)) {
                 if (isset($internalflightBO->city_id)) {
                     $this->deleteRelationship($post_id, $internalflightBO->city_id);
                 }
                 if (isset($internalflightBO->country_id)) {
                     $this->deleteRelationship($post_id, $internalflightBO->country_id);
                 }
                 if (isset($internalflightBO->image_id)) {
                     Model::autoloadModel("image");
                     $imageModel = new ImageModel($this->db);
                     $imageModel->delete($internalflightBO->image_id);
                 }
                 return TRUE;
             }
         }
     } catch (Exception $e) {
     }
     return FALSE;
 }
Ejemplo n.º 28
0
 public function loop()
 {
     Asset::add('masonry', 'js/masonry.pkgd.min.js', false, '1.0', false, 'script');
     return View::make('partials.product.loop', ['posts' => PostModel::all()])->render();
 }
Ejemplo n.º 29
0
function rest_post()
{
    include "serverconfig.php";
    include "./image_test/dbconfig.php";
    $debug_msg = '';
    // echo "saveHTMLFile filename: ".$_FILES ['html_file'] ['name'];
    if (!isset($_FILES['html_file'])) {
        $debug_msg = "업로드 파일 존재하지 않음";
        return $debug_msg;
    }
    if ($_FILES['html_file']['error'] > 0) {
        switch ($_FILES['html_file']['error']) {
            case 1:
                $debug_msg = "php.ini 파일의 upload_max_filesize 설정값을 초과함(업로드 최대용량 초과)";
                return $debug_msg;
            case 2:
                $debug_msg = "Form에서 설정된 MAX_FILE_SIZE 설정값을 초과함(업로드 최대용량 초과)";
                return $debug_msg;
            case 3:
                $debug_msg = "파일 일부만 업로드 됨";
                return $debug_msg;
            case 4:
                $debug_msg = "업로드된 파일이 없음";
                return $debug_msg;
            case 6:
                $debug_msg = "사용가능한 임시폴더가 없음";
                return $debug_msg;
            case 7:
                $debug_msg = "디스크에 저장할수 없음";
                return $debug_msg;
            case 8:
                $debug_msg = "파일 업로드가 중지됨";
                return $debug_msg;
            default:
                $debug_msg = "시스템 오류가 발생";
                return $debug_msg;
        }
        // switch
    }
    $ableExt = array('html');
    $path = pathinfo($_FILES['html_file']['name']);
    $ext = strtolower($path['extension']);
    if (!in_array($ext, $ableExt)) {
        $debug_msg = "허용되지 않는 확장자입니다.";
        return $debug_msg;
    }
    $mysqli = new mysqli($dbhost, $dbusr, $dbpass, $dbname);
    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }
    // $create_table = "CREATE TABLE if not exists posts (
    // id int auto_increment,
    // user_id varchar(30),
    // title varchar(100),
    // upload_filename varchar(100),
    // db_filename varchar(100),
    // filepath varchar(100),
    // filesize int(8),
    // file_type VARCHAR(40),
    // upload_date DATETIME DEFAULT CURRENT_TIMESTAMP,
    // thumb_img_path varchar(100),
    // category varchar(20),
    // rank float,
    // PRIMARY KEY (id)
    // );";
    // $mysqli->query ( $create_table );
    do {
        // 6. 새로운 파일명 생성(마이크로타임과 확장자 이용)
        $time = explode(' ', microtime());
        $fileName = $time[1] . substr($time[0], 2, 6) . '.' . strtoupper($ext);
        // 중요 이미지의 경우 웹루트(www) 밖에 위치할 것을 권장(예제 편의상 아래와 같이 설정)
        $filePath = 'http://localhost:8080/web_test/image_test/upload_html/';
        // $_SERVER ['DOCUMENT_ROOT'] . '/web_test/image_test/upload_html/';
        $fileServerPath = $_SERVER['DOCUMENT_ROOT'] . '/web_test/image_test/upload_html/';
        if (!is_dir($fileServerPath)) {
            @mkdir($fileServerPath);
        }
        // 7. 생성한 파일명이 DB내에 존재하는지 체크
        $query = sprintf("SELECT no FROM image_files WHERE db_filename = '%s'", $fileName);
        $result = $mysqli->query($query);
        if ($result === NULL) {
            break;
        }
        // 생성한 파일명이 중복하는 경우 새로 생성해서 체크를 반복(동시저장수가 대량이 아닌경우 중복가능 희박)
    } while ($result != NULL && $result->num_rows > 0);
    // db에 저장할 정보 가져옴
    $upload_filename = $_FILES['html_file']['name'];
    //$mysqli->real_escape_string ( $_FILES ['html_file'] ['name'] );
    $file_size = $_FILES['html_file']['size'];
    $file_type = $_FILES['html_file']['type'];
    // set time to Seoul.
    date_default_timezone_set("Asia/Seoul");
    $upload_date = date("Y-m-d H:i:s");
    // create and save thumbnail
    $thumbPath = 'http://localhost:8080/web_test/image_test/thumbnails/';
    $thumb_url = isset($_POST['thumb_img_url']) ? $_POST['thumb_img_url'] : null;
    $thumbimagename = save_thumbnail($thumb_url);
    // 	$mysqli->autocommit ( false );
    // 	$query = sprintf ( "INSERT INTO posts
    // 		(user_id, title, upload_filename,db_filename,filepath,filesize,file_type,upload_date,thumb_img_path,category)
    // 		VALUES ('%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s')", $_POST ["user_id"], $_POST ["title"], $upload_filename, $fileName, $filePath, $file_size, $file_type, $upload_date, $thumbimagename, $_POST ["category"] );
    // 	$mysqli->query ( $query );
    $insert_id = NULL;
    if (move_uploaded_file($_FILES['html_file']['tmp_name'], $fileServerPath . $fileName)) {
        $post = new PostModel();
        $post->prepareDb();
        $post->user_id = $_POST["user_id"];
        $post->title = $_POST["title"];
        $post->upload_filename = $upload_filename;
        $post->db_filename = $fileName;
        $post->filepath = $filePath;
        $post->filesize = $file_size;
        $post->file_type = $file_type;
        $post->upload_date = $upload_date;
        $post->thumb_img_path = $thumbimagename;
        $post->category = $_POST["category"];
        $result = $post->save();
        $insert_id = $result['id'];
    }
    // 	if ($mysqli->error) {
    // 		echo "Failed to insert posts db: (" . $mysqli->error . ") ";
    // 	}
    // 	$insert_id = $mysqli->insert_id;
    // 	if ($mysqli->affected_rows > 0) {
    // 		// 9. 업로드 파일을 새로 만든 파일명으로 변경 및 이동
    // 		if (move_uploaded_file ( $_FILES ['html_file'] ['tmp_name'], $fileServerPath . $fileName )) {
    // 			$mysqli->commit ();
    // 		} else {
    // 			$mysqli->rollback ();
    // 			$debug_msg = "업로드 실패";
    // 			return $debug_msg;
    // 		} // if
    // 	}
    $html_saving_info = array("id" => $insert_id);
    // 	$mysqli->close ();
    if (isset($_POST['images_name'])) {
        $html_saving_info['ret_detail'] = insert_post_images($insert_id, $_POST['images_name']);
    }
    $html_saving_info['ret_val'] = "success";
    return $html_saving_info;
}
Ejemplo n.º 30
0
<?php

/**
 * @author asmalindi
 * @copyright 2011
 */
require "PostModel.php";
$postM = new PostModel();
//$categorie = new Categorie();
include "process.php";
?>
<head>
<link href="menu.css" rel="stylesheet" type="text/css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.js"></script>
<script type="text/javascript" src="menu.js"></script>
<style type="text/css">
<!--
    body,
    html {
        margin:0;
        padding:0;
        color:#000;
        background:#a7a09a;
    }
    
    #wrap {
        width:750px;
        margin:0 auto;
        background:#99c;
    }