From: Calin Burloiu Date: Tue, 12 Jul 2011 12:35:14 +0000 (+0300) Subject: site initialized; basic catalog lists videos X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?p=living-lab-site.git;a=commitdiff_plain;h=0b134deb6f1108155973436e3de7296a76a2d660 site initialized; basic catalog lists videos --- diff --git a/.gitignore b/.gitignore index 2d77a4e..51743a3 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ config.mk .512b .directory *.patch +application/logs/*.php +data/thumbs/* +data/torrents/* diff --git a/.htaccess b/.htaccess index cbdfca5..739f845 100644 --- a/.htaccess +++ b/.htaccess @@ -1,3 +1,11 @@ + + Order allow,deny + Deny from all + + + Order allow,deny + Deny from all + Order allow,deny Deny from all @@ -10,3 +18,7 @@ Order allow,deny Deny from all + +RewriteEngine on +RewriteCond $1 !^(index\.php|data|robots\.txt) +RewriteRule ^(.*)$ index.php/$1 [L] diff --git a/application/config/config.php b/application/config/config.php index 1ec6543..1402953 100755 --- a/application/config/config.php +++ b/application/config/config.php @@ -26,7 +26,7 @@ $config['base_url'] = ''; | variable so that it is blank. | */ -$config['index_page'] = 'index.php'; +$config['index_page'] = ''; /* |-------------------------------------------------------------------------- @@ -180,7 +180,7 @@ $config['directory_trigger'] = 'd'; // experimental not currently in use | your log files will fill up very fast. | */ -$config['log_threshold'] = 0; +$config['log_threshold'] = 4; /* |-------------------------------------------------------------------------- @@ -358,5 +358,3 @@ $config['rewrite_short_tags'] = FALSE; $config['proxy_ips'] = ''; -/* End of file config.php */ -/* Location: ./application/config/config.php */ diff --git a/application/config/database.php b/application/config/database.php index 24d611a..ab8a529 100755 --- a/application/config/database.php +++ b/application/config/database.php @@ -42,9 +42,9 @@ $active_group = 'default'; $active_record = TRUE; $db['default']['hostname'] = 'localhost'; -$db['default']['username'] = ''; -$db['default']['password'] = ''; -$db['default']['database'] = ''; +$db['default']['username'] = 'root'; +$db['default']['password'] = 'root'; +$db['default']['database'] = 'livinglab'; $db['default']['dbdriver'] = 'mysql'; $db['default']['dbprefix'] = ''; $db['default']['pconnect'] = TRUE; @@ -52,7 +52,7 @@ $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ''; $db['default']['char_set'] = 'utf8'; -$db['default']['dbcollat'] = 'utf8_general_ci'; +$db['default']['dbcollat'] = 'utf8_unicode_ci'; $db['default']['swap_pre'] = ''; $db['default']['autoinit'] = TRUE; $db['default']['stricton'] = FALSE; diff --git a/application/config/p2p-tube.php b/application/config/p2p-tube.php new file mode 100644 index 0000000..ac03043 --- /dev/null +++ b/application/config/p2p-tube.php @@ -0,0 +1,34 @@ +load->view('html_begin'); + $this->load->view('header'); + + $this->load->model('videos_model'); + $data['query'] = $this->videos_model->getVideosSummary(); + $this->load->view('catalog/index_view', $data); + + + $this->load->view('footer'); + $this->load->view('html_end'); + } +} + +/* End of file catalog.php */ +/* Location: ./application/controllers/catalog.php */ diff --git a/application/controllers/help.php b/application/controllers/help.php new file mode 100644 index 0000000..927480d --- /dev/null +++ b/application/controllers/help.php @@ -0,0 +1,18 @@ +load->helper('url'); + + $this->load->view('html_begin'); + $this->load->view('header'); + + $this->load->model('videos_model'); + $data['video'] = $this->videos_model->getVideo($id)->row(); + if ($name !== NULL && $data['video']->name != $name) + $data['video']->err = 'INVALID_NAME'; + + $this->load->view('video/watch_view', $data); + + $this->load->view('footer'); + $this->load->view('html_end'); + } +} + +/* End of file video.php */ +/* Location: ./application/controllers/video.php */ diff --git a/application/libraries/Content.class.php b/application/libraries/Content.class.php new file mode 100755 index 0000000..cc94490 --- /dev/null +++ b/application/libraries/Content.class.php @@ -0,0 +1,393 @@ +db = SingletonDB::connect(); + + // Get languages from DB. + if(!$this->db->query("SET NAMES 'utf8'")) throw new DBException('query'); + if( !($result = $this->db->query("SELECT * FROM `languages`")) ) + throw new DBException('query'); + while($row = $result->fetch_assoc()) + { + $this->languages[$row['code']]['name'] = $row['name']; + $this->languages[$row['code']]['img'] = $row['image']; + } + + // Set current language + // TODO: language + $matchedLang = DEFAULT_LANG;//$this->matchLanguage(); + if(isset($_GET['lang'])) + { + $lang = $this->processLangCode($_GET['lang']); + $this->lang = $lang; + if($lang != $matchedLang) + setcookie("lang", $lang, time() + 30*24*60*60); + else + setcookie("lang", $lang, time() - 3600); + } + else if(isset($_COOKIE['lang'])) + $this->lang = $this->processLangCode($_COOKIE['lang']); + else + $this->lang = $matchedLang; + + // Get content from DB, from common and specified namespace. + if( !($result = $this->db->query("SELECT * FROM `content` WHERE namespace = 'common' OR namespace = '" + . $namespace . "'")) ) + throw new DBException('query'); + while($row = $result->fetch_assoc()) + { + $this->content[$row['name']] = json_decode($row['value'], true); + } + + } + catch(DBException $e) { + echo $e->errorMessage(); + die(); + } + } + + // Verifies if the lang code exists in the database and if so it returns it + // in lower case. It not it returns the default language. + public function processLangCode($lang) + { + $lang = strtolower($lang); + if(isset($this->languages[$lang])) + return $lang; + else + return DEFAULT_LANG; + } + + public function getLanguages() + { + return $this->languages; + } + + public function getLanguage($code) + { + if(isset($this->languages[$code])) + return $this->languages[$code]; + else + return null; + } + + public function getCrtLanguage() + { + return $this->lang; + } + + public function getContent($name, $lang) + { + if(isset($this->content[$name])) + return $this->content[$name][$lang]; + else + return null; + } + + public function __get($name) + { + if(isset($this->content[$name])) + return $this->content[$name][$this->lang]; + else + return null; + } + + // Returns user's prefered language if the site supports it or english otherwise. + public function matchLanguage() + { + $pattern = '/^(?P[a-zA-Z]{2,8})'. + '(?:-(?P[a-zA-Z]{2,8}))?(?:(?:;q=)'. + '(?P\d\.\d))?$/'; + + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang) + { + $splits = array(); + + if (preg_match($pattern, $lang, $splits)) + { + $language = $splits['primarytag']; + if(isset($this->languages[$language])) + return $language; + } + else + return 'en'; + } + + return 'en'; + } + + public function isRowIncomplete($row) + { + $incomplete = ''; + + if(empty($row['name'])) + $incomplete .= 'n'; + if(empty($row['address'])) + $incomplete .= 'a'; + if(empty($row['developer'])) + $incomplete .= 'd'; + if(empty($row['chief_architect'])) + $incomplete .= '{ca}'; + if($row['whole_area'] == null || $row['whole_area'] == '0000') + $incomplete .= '{wa}'; + if(empty($row['height'])) + $incomplete .= 'h'; + if(empty($row['phase'])) + $incomplete .= '{ph}'; + if($row['year_begin'] == null) + $incomplete .= '{yb}'; + + $descriptions = json_decode($row['description'], true); + foreach($this->getLanguages() as $code => $value) + { + if(empty($descriptions[$code])) + $incomplete .= '{de}'; + } + + $images = json_decode($row['images'], true); + if(count($images) < 1) + $incomplete .= 'i'; + + return $incomplete; + } + + // Returns a list of buildings with a specified category as an + // associative array with ID keys. Every element has associated: + // name, year_begin, image (thumbnail). + public function getPortofolioSummary($category, $page, $checkIncomplete=false) + { + $portofolio = null; + + if(!$checkIncomplete) + $columns = "id, name, year_begin, images, category"; + else + $columns = "*"; + + $query = "SELECT ". $columns. " FROM `portofolio`"; + if($category != null) + $query .= " WHERE category = '". $category . "'"; + $query .= " ORDER BY year_begin DESC, name ASC"; + if($page != null) + $query .= " LIMIT ". ($page * PRJ_PER_PAGE) . ", " . PRJ_PER_PAGE; + $result = $this->db->query($query); + + while($row = $result->fetch_assoc()) + { + $portofolio[$row['id']]['name'] = $row['name']; + $portofolio[$row['id']]['year_begin'] = $row['year_begin']; + $images = json_decode($row['images'], true); + if(!$images) + $portofolio[$row['id']]['image'] = null; + else + $portofolio[$row['id']]['image'] = getThumbFileName($images[0]); + $portofolio[$row['id']]['category'] = $row['category']; + + if($checkIncomplete) + $portofolio[$row['id']]['incomplete'] = $this->isRowIncomplete($row); + } + + return $portofolio; + } + + // Returns 3 dictionaries representing projects from portofolio. + // Each dictionary has id as key and another dictionary as value with: + // name, year_begin, description, thumnail. + public function getPortofolioAds() + { + $portofolio = null; + + $query = "SELECT id, name, year_begin, description, images FROM `portofolio` ORDER BY RAND() LIMIT " + . P_ADS_COUNT; + $result = $this->db->query($query); + + while($row = $result->fetch_assoc()) + { + $portofolio[$row['id']]['name'] = $row['name']; + $portofolio[$row['id']]['year_begin'] = $row['year_begin']; + $images = json_decode($row['images'], true); + if(!$images) + $portofolio[$row['id']]['image'] = null; + else + $portofolio[$row['id']]['image'] = getThumbFileName($images[0]); + $descriptions = json_decode($row['description'], true); + $portofolio[$row['id']]['description'] = $descriptions[$this->lang]; + } + + return $portofolio; + } + + public function getPortofolioCardinality($category) + { + $query = "SELECT count(id) c FROM `portofolio` WHERE category = '". $category. "'"; + $result = $this->db->query($query); + + $row = $result->fetch_row(); + if($row) + return $row[0]; + } + + public function getRowNumber($id, $category) + { + $query = " +SELECT id id_t, name name_t, year_begin year_begin_t, ( + + SELECT COUNT( * ) + FROM `portofolio` + WHERE category = '". $category. "' + AND id <> id_t + AND (year_begin = year_begin_t AND name < name_t OR year_begin > year_begin_t) + ORDER BY year_begin DESC , name ASC +) pos +FROM `portofolio` +WHERE id = ". $id; + $result = $this->db->query($query); + + $row = $result->fetch_assoc(); + if($row) + return $row['pos']; + } + + // If fullInfo is true, information for all languages will be returned. + public function getProject($id, $fullInfo = false) + { + $result = $this->db->query( + "SELECT * from `portofolio` WHERE id = " . $id); + $row = $result->fetch_assoc(); + + if(!$row) + return null; + + $row['category_code'] = $row['category']; + switch($row['category_code']) + { + case 'office': + $row['category'] = $this->project_category_office; + break; + case 'residential': + $row['category'] = $this->project_category_residential; + break; + case 'hotel': + $row['category'] = $this->project_category_hotel; + break; + case 'industrial': + $row['category'] = $this->project_category_industrial; + break; + case 'commercial': + $row['category'] = $this->project_category_commercial; + break; + case 'restorations': + $row['category'] = $this->project_category_restorations; + break; + case 'hospitals': + $row['category'] = $this->project_category_category; + break; + default: // other + $row['category'] = $this->project_category_other; + break; + } + + // Translate NULL values. + if(!isset($project['whole_area']) || $project['whole_area'] == null) + $project['whole_area'] = ''; + if(!isset($project['year_begin']) || $project['year_begin'] == null) + $project['year_begin'] = ''; + if(!isset($project['year_end']) || $project['year_end'] == null) + $project['year_end'] = ''; + + $descriptions = json_decode($row['description'], true); + $row['description'] = $descriptions[$this->lang]; + if($fullInfo) + $row['descriptions'] = $descriptions; + + $images = json_decode($row['images'], true); + $row['images'] = $images; + + return $row; + } + + public static function insertProject($project) + { + try { + $db = SingletonDB::connect(); + + $db->query("SET NAMES 'utf8'"); + + $project['name'] = str_replace("'", "`", $project['name']); + $project['description'] = json_encode(str_replace("'", "`", $project['descriptions'])); + $project['images'] = json_encode($project['images']); + + $result = $db->query( + "INSERT INTO `portofolio` (name, category, address, developer, chief_architect, whole_area, height, phase, year_begin, year_end, description, images) + VALUES ('". $project['name']. "', '". $project['category_code']. "', '". $project['address']. "', '". $project['developer']. "', '". $project['chief_architect']. "', ". $project['whole_area']. ", '". $project['height']. "', '". $project['phase']. "', ". $project['year_begin']. ", ". $project['year_end']. ", '". $project['description']. "', '". $project['images']. "')"); + + if(!$result) + throw new DBException('query'); + } + catch(DBException $e) { + echo $e->errorMessage(); + die(); + } + } + + public static function updateProject($id, $project) + { + try { + $db = SingletonDB::connect(); + + $db->query("SET NAMES 'utf8'"); + + $project['name'] = str_replace("'", "`", $project['name']); + $project['description'] = json_encode(str_replace("'", "`", $project['descriptions'])); + $project['images'] = json_encode($project['images']); + + $query = "UPDATE `portofolio` SET name='". $project['name']. "', category='". $project['category_code']. "', address='". $project['address']. "', developer='". $project['developer']. "', chief_architect='". $project['chief_architect']. "', whole_area=". $project['whole_area']. ", height='". $project['height']. "', phase='". $project['phase']. "', year_begin=". $project['year_begin']. ", year_end=". $project['year_end']. ", description='". $project['description']. "', images='". $project['images']. "' WHERE id=". $id; + $result = $db->query($query); + + if(!$result) + throw new DBException('query'); + } + catch(DBException $e) { + echo $e->errorMessage(); + die(); + } + } + + public static function deleteProject($id, $project) + { + foreach($project['images'] as $image) + { + deleteImage($image); + } + + try { + $db = SingletonDB::connect(); + + $query = "DELETE FROM `portofolio` WHERE id=". $id; + $result = $db->query($query); + + if(!$result) + throw new DBException('query'); + } + catch(DBException $e) { + echo $e->errorMessage(); + die(); + } + } +} + +//$x = new Content('common'); +//echo $x->getRowNumber(56, 'residential'); +?> \ No newline at end of file diff --git a/application/libraries/Singleton_db.php b/application/libraries/Singleton_db.php new file mode 100644 index 0000000..e9c44c7 --- /dev/null +++ b/application/libraries/Singleton_db.php @@ -0,0 +1,35 @@ +load->database('default', TRUE); + } + + return self::$db; + } +} + +/* End of file Singleton_db.php */ +/* Location: ./application/libraries/Singleton_db.php */ diff --git a/application/models/videos_model.php b/application/models/videos_model.php new file mode 100644 index 0000000..b5ae2d7 --- /dev/null +++ b/application/models/videos_model.php @@ -0,0 +1,33 @@ +db === NULL) + { + $this->load->library('singleton_db'); + $this->db = $this->singleton_db->connect(); + } + } + + function getVideosSummary() + { + return $this->db->get('videos'); + } + + function getVideo($id, $name = NULL) + { + return $this->db->query('SELECT * from videos WHERE id = ?', $id); + } +} + +/* End of file videos_model.php */ +/* Location: ./application/models/videos_model.php */ diff --git a/application/views/catalog/index_view.php b/application/views/catalog/index_view.php new file mode 100644 index 0000000..de7d1df --- /dev/null +++ b/application/views/catalog/index_view.php @@ -0,0 +1,17 @@ +
+ result() as $video): + $img_src = sprintf("data/thumbs/%s_t%02d.jpg", $video->name, + $video->default_thumb); + $video_url = sprintf("video/watch/%d", $video->id); + ?> +
+ + +
title ?>
+
+
duration ?>
+
views . ' views' ?>
+ +
+ +
diff --git a/application/views/footer.php b/application/views/footer.php new file mode 100644 index 0000000..fdc45c6 --- /dev/null +++ b/application/views/footer.php @@ -0,0 +1,4 @@ + diff --git a/application/views/header.php b/application/views/header.php new file mode 100644 index 0000000..1743f0b --- /dev/null +++ b/application/views/header.php @@ -0,0 +1,4 @@ + diff --git a/application/views/html_begin.php b/application/views/html_begin.php new file mode 100644 index 0000000..9a2f70d --- /dev/null +++ b/application/views/html_begin.php @@ -0,0 +1,24 @@ + + + + + + + + +TODO + + + + + + + + + + + + + + diff --git a/application/views/html_end.php b/application/views/html_end.php new file mode 100644 index 0000000..9870926 --- /dev/null +++ b/application/views/html_end.php @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/application/views/tmp.php b/application/views/tmp.php new file mode 100644 index 0000000..7f10a77 --- /dev/null +++ b/application/views/tmp.php @@ -0,0 +1,26 @@ + + + + + + +Conforming XHTML 1.1 Template + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/application/views/video/watch_view.php b/application/views/video/watch_view.php new file mode 100644 index 0000000..8984694 --- /dev/null +++ b/application/views/video/watch_view.php @@ -0,0 +1,14 @@ +
+ + err) && $video->err == 'INVALID_NAME'): + $suggestion = site_url(sprintf("video/watch/%d/%s", $video->id, + $video->name)) + ?> +

Invalid URL .

+

Did you mean + ?

+ + +

title ?>

+ +
\ No newline at end of file