コード例 #1
0
 public function get_page_by_url()
 {
     global $sql, $smarty, $user;
     $url_temp = substr($_SERVER['REQUEST_URI'], 15);
     //ez csak localhost-on kell, mert ott bent van az easyaccessblog könyvtárban minden
     //die($url_temp);
     //die($_SERVER['REQUEST_URI']);
     if (substr_count($url_temp, '/') == 2) {
         $endpos = strpos($url_temp, '/', 1);
         $this->dir = substr($url_temp, 1, $endpos - 1);
         if ($this->dir == 'admin') {
             $this->admin = true;
         }
     } else {
         $this->dir = null;
     }
     if (strstr($url_temp, "?p=")) {
         $this->action = substr($url_temp, strpos($url_temp, "?p=") + 3);
         //ellenőrizzük van-e egyéb paraméter, mert akkor azt levágjuk
         if (strstr($this->action, '&')) {
             $endpos = strpos($this->action, '&', 1);
             $this->action = substr($this->action, 0, $endpos);
         }
     } else {
         //load simple index.php site
         if (!$this->is_admin()) {
             $this->action = 'default';
         } else {
             $this->action = 'default_admin';
         }
     }
     $this->file = $this->action;
     // login.php
     /*
     if (substr_count($_SERVER['REQUEST_URI'],'/')==2) {
     	$endpos = strpos($_SERVER['REQUEST_URI'], '/', 1);
     	$dir = substr($_SERVER['REQUEST_URI'], 1, $endpos-1);
     }
     */
     //$assoc_array = $sql->get_page($this->file, $this->dir);
     //die($this->dir . "h");
     if ($this->dir) {
         $this->p_user = new user();
         $this->p_user->set_user_data_by_name($this->dir);
     }
     $this->url = $this->action . '.tpl';
     //itt most lekérünk egyéb smarty adatokat -------------------------------------------------
     //default.tpl adatai (főoldali bejegyzések)
     //le kell kérni a userhez tartozó össszes (type=1) postot, dátum szerint csökkenő sorrendben
     //és ezeket átadni tömbben (a tömbben post objektumok legyenek)
     if ($this->action == 'default' && !$this->is_admin() && $this->p_user != null) {
         $post_list = $sql->assoc_array('select * from post where post_type = 1 and post_status = 2 and post_author = ' . $this->p_user->get_user_id() . (isset($_GET['tag']) ? ' and post_id in (select tp_post_id from tag_post where tp_tag_id = ' . $_GET['tag'] . ')' : '') . (isset($_GET['category']) ? ' and post_cat_id  = ' . $_GET['category'] : '') . ' order by post_date desc;');
         $post_array = array();
         foreach ($post_list as $key => $post_obj) {
             $new_post = new post();
             $new_post->set_post_data_by_id($post_obj['post_id']);
             $new_post->decode_content();
             $post_array[] = $new_post;
             //var_dump($post_obj);
         }
         $smarty->assign('post_list', $post_array);
     }
     //defaul.tpl vége
     //default.tpl admin esetén
     if ($this->action == 'default' && $this->is_admin()) {
         //do smthng
     }
     //default vége admin esetén
     //önálló bejegyzés megtekintése
     if ($this->action == 'view_post') {
         //ez azért kell mert ebben benne van a user ellenőrzés is; ha nem lenne, akkor bármelyik felhasználó blogjából meghívhatnánk bármelyik bejegyzést
         $post_id = $sql->single_variable("select post_id from post where post_id = " . $_GET['id'] . " and post_author = " . $this->p_user->get_user_id() . ";");
         $new_post = new post();
         $new_post->set_post_data_by_id($post_id);
         $new_post->decode_content();
         $smarty->assign('post', $new_post);
         //lekérjük a  bejegyzéshez tartozó kommenteket
         $comments = $sql->assoc_array('select com_id from comment where com_post = ' . $_GET['id'] . ' order by com_date desc;');
         $comment_array = array();
         foreach ($comments as $key => $com_obj) {
             $comment = new comment();
             $comment->set_com_data_by_id($com_obj['com_id']);
             $comment_array[] = $comment;
         }
         $smarty->assign('comment_list', $comment_array);
     }
     //bejegyzés megtekintésének vége
     //új bejegyzés létrehozása
     if ($this->action == 'edit_post') {
         //kategóriák lekérése
         $category_list = $sql->assoc_array('select * from category where cat_author = ' . $user->get_user_id());
         $category_array = array();
         foreach ($category_list as $key => $val) {
             $category = new category();
             foreach ($val as $key_inner => $value_inner) {
                 if ($key_inner == "cat_id") {
                     $category->set_cat_id($value_inner);
                 } elseif ($key_inner == "cat_name") {
                     $category->set_cat_name($value_inner);
                 } elseif ($key_inner == "cat_author") {
                     $category->set_cat_author($value_inner);
                 }
             }
             $category_array[] = $category;
         }
         $smarty->assign('category_list', $category_array);
         //kategóriák vége
     }
     //új bejegyzés vége
     //új oldal
     if ($this->action == 'edit_page') {
         //do nothing
     }
     //új oldal vége
     //meglévő bejegyzés szerkesztése
     if ($this->action == 'edit_post' && isset($_GET['id']) && !empty($_GET['id'])) {
         //lekérjük az összes post adatot
         $post_data = $sql->assoc_array('select * from post where post_id = ' . $_GET['id'] . ' and post_type = 1');
         foreach ($post_data[0] as $key => $data) {
             if ($key == 'post_content') {
                 $data = html_entity_decode($data);
             }
             $smarty->assign($key, $data);
         }
         //címkék lekérése
         $tag_array = $sql->assoc_array("select * from tag_post where tp_post_id = " . $_GET['id']);
         $tag_list = array();
         foreach ($tag_array as $key => $tag_obj) {
             $tag = new tag();
             foreach ($tag_obj as $_key => $value) {
                 if ($_key == 'tp_tag_id') {
                     $tag->set_tag_data_by_id($value);
                 }
             }
             $tag_list[] = $tag;
         }
         $smarty->assign('tag_list', $tag_list);
         //címkék vége
     }
     //meglévő bejegyzés szerkesztés vége
     //meglévő oldal szerkesztése
     if ($this->action == 'edit_page' && isset($_GET['id']) && !empty($_GET['id'])) {
         $page_data = $sql->assoc_array('select * from post where post_id = ' . $_GET['id']);
         foreach ($page_data[0] as $key => $data) {
             if ($key == 'post_content') {
                 $data = html_entity_decode($data);
             }
             $smarty->assign($key, $data);
         }
     }
     //meglévő oldal szerkesztése
     //korábbi bejegyzések --archive
     if ($this->action == "archive") {
         $archive_array = $sql->assoc_array('select * from post where post_type = 1 and post_author = ' . $user->get_user_id() . " order by post_date desc;");
         $post_list = array();
         foreach ($archive_array as $key => $post_obj) {
             $new_post = new post();
             foreach ($post_obj as $field => $obj_val) {
                 if ($field == "post_id") {
                     $new_post->set_post_data_by_id($obj_val);
                 }
             }
             $post_list[] = $new_post;
         }
         $smarty->assign('post_list', $post_list);
     }
     //korábbi bejegyzések vége
     //oldalak szerkesztése - pages
     if ($this->action == "pages") {
         $archive_array = $sql->assoc_array('select * from post where post_author = ' . $user->get_user_id() . " and post_type = 2 order by post_id asc;");
         $post_list = array();
         foreach ($archive_array as $key => $post_obj) {
             $new_post = new post();
             foreach ($post_obj as $field => $obj_val) {
                 if ($field == "post_id") {
                     $new_post->set_post_data_by_id($obj_val);
                 }
             }
             $post_list[] = $new_post;
         }
         $smarty->assign('post_list', $post_list);
     }
     //oldalak szerkesztése - vége
     //kategóriák
     if ($this->action == "category") {
         $category_array = $sql->assoc_array('select * from category where cat_author = ' . $user->get_user_id() . " order by cat_name asc;");
         $cat_list = array();
         foreach ($category_array as $key => $cat_obj) {
             $new_cat = new category();
             foreach ($cat_obj as $field => $obj_val) {
                 if ($field == "cat_id") {
                     $new_cat->set_cat_data_by_id($obj_val);
                 }
             }
             $cat_list[] = $new_cat;
         }
         $smarty->assign('cat_list', $cat_list);
     }
     //kategóriák vége
     //admin oldali kommentkezelés
     if ($this->action == "comment") {
         //le kell kérni az összes olyan bejegyzést, amihez tartozik komment, időrendben a bejegyzések, azon belül időrendben a kommentek
         $comments = $sql->assoc_array('SELECT post_id, com_id FROM `post` join `comment` on post_id = com_post WHERE post_author = 1 order by com_date desc');
         $comment_array = array();
         foreach ($comments as $key_obj => $com_obj) {
             foreach ($com_obj as $key => $value) {
                 //át kell adni smarty-ban  a post-ot, meg a commentet is
                 //ötlet: a com_post-ba rakjuk bele a post objektumot!
                 //sorrend: post_id, com_id
                 if ($key == "post_id") {
                     //itt állítjuk be a post objektumot
                     $post = new post();
                     $post->set_post_data_by_id($value);
                 } elseif ($key = "com_id") {
                     //itt hozzuk létre a komment objektumot, és belepakoljuk a post-ot, ami már létezik elvileg
                     $comment = new comment();
                     $comment->set_com_data_by_id($value);
                     //ez állítja be az előbb létrehozott postot
                     $comment->set_com_post($post);
                 }
             }
             $comment_array[] = $comment;
         }
         $smarty->assign('comment_list', $comment_array);
     }
     //admin oldali kommentkezelés vége
     //media
     if ($this->action == "images") {
         //lekéri a felhasználó összes media bejegyzését
         //dátum szerint csökkenő sorrendben
         //TODO: lehetne egy check() fv. ami lecsekkolja mi van a mappában, és updateli az adatbázist
         $media_array = $sql->assoc_array('SELECT * FROM media WHERE media_author = ' . $user->get_user_id() . ' ORDER BY media_date DESC;');
         $media_list = array();
         foreach ($media_array as $key => $media_obj) {
             $new_media = new media();
             $new_media->set_media_data_by_id($media_obj['media_id']);
             $media_list[] = $new_media;
         }
         $smarty->assign('media_list', $media_list);
     }
     //media end
     //közösségi oldalak beállítása
     if ($this->action == "social_media") {
         //hozzáadás: legördülő menüből a típus, value
         //felvettek megjelenítése: mindkettő szerkeszthető
         $sm_list = array();
         //bepakoljuk a tömbbe a meglévőket
         $sm_assoc_array = $sql->assoc_array('select * from social_media where sm_user = '******' order by sm_type asc;');
         foreach ($sm_assoc_array as $key => $value) {
             $sm_obj = new social_media();
             $sm_obj->set_sm_data_by_id($value['sm_id']);
             $sm_list[] = $sm_obj;
         }
         $smarty->assign('sm_list', $sm_list);
     }
     //közösségi oldal end
     //profil módosítás
     if ($this->action == "profile" || $this->action == "password") {
         $smarty->assign('user', $user);
     }
     //profil módosítás vége
     //menüszerkesztés
     if ($this->action == "menu") {
         $smarty->assign('user', $user);
         $menublocks_assoc_array = $sql->assoc_array('select * from menublock where mb_type in (1,2,3,4) and mb_user = '******' order by mb_type asc;');
         $mb_list = array();
         foreach ($menublocks_assoc_array as $mb_array) {
             $new_mb = new menublock($mb_array['mb_title'], $mb_array['mb_type'], $mb_array['mb_limit'], $user->get_user_id());
             $mb_list[] = $new_mb;
         }
         $text_array = array('Korábbi bejegyzéseket tartalmazó menü', 'Kommenteket tartalmazó blokk', 'Közösségi oldalakat tartalmazó blokk', 'Címkéket tartalmazó blokk');
         $limits = array(true, true, false, false);
         $smarty->assign('mb_list', $mb_list);
         $smarty->assign('text_array', $text_array);
         $smarty->assign('limits', $limits);
     }
     //menüszerkesztés vége
     //smarty adatok betöltésének vége ---------------------------------------------------------
 }