From 1d5a16a1d4d0cda21fe18bdfddbf12bbbbe58466 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 18 Apr 2015 16:09:57 +0000 Subject: [PATCH] # added sanity check on user settigs taken from the session/cookie data # added revision navigator in the code folder view. # added etag/last-modified to user icon retrieval. # fixed various css issues --- codepot/README | 4 +- codepot/src/codepot/controllers/user.php | 31 ++- codepot/src/codepot/models/loginmodel.php | 6 + codepot/src/codepot/models/usermodel.php | 4 +- codepot/src/codepot/views/code_blame.php | 15 +- codepot/src/codepot/views/code_file.php | 25 +- codepot/src/codepot/views/code_folder.php | 27 ++- codepot/src/codepot/views/code_revision.php | 15 +- codepot/src/codepot/views/graph_main.php | 6 +- codepot/src/codepot/views/project_catalog.php | 11 +- codepot/src/codepot/views/site_home.php | 22 +- codepot/src/css/code.css | 228 ++---------------- codepot/src/css/common.css | 198 +++++++-------- codepot/src/css/project.css | 8 - codepot/src/css/site.css | 34 --- codepot/src/css/wiki.css | 26 -- 16 files changed, 247 insertions(+), 413 deletions(-) diff --git a/codepot/README b/codepot/README index 1dcf8455..c0361ae9 100644 --- a/codepot/README +++ b/codepot/README @@ -223,8 +223,8 @@ LICENSE CodeIgniter 1.7.2 See src/system/license.txt Google code prettify Apache License 2.0 JavaScript Creole 1.0 Wiki Markup Parser See src/js/creole.js - jQuery JavaScript Library v1.4.2 See http://jquery.org/license - jQuery UI 1.8 MIT or GPL + jQuery JavaScript Library v1.11.2 MIT See http://jquery.org/license + jQuery UI 1.9.2 MIT See http://jquery.org/license PHPGraphLib MIT CLOC 1.62 GPL Flot https://github.com/flot/flot/blob/master/LICENSE.txt diff --git a/codepot/src/codepot/controllers/user.php b/codepot/src/codepot/controllers/user.php index 84e0bc10..4169bec2 100644 --- a/codepot/src/codepot/controllers/user.php +++ b/codepot/src/codepot/controllers/user.php @@ -199,12 +199,18 @@ class User extends Controller } } + // + // make sure that these field also exist in the database + // also change the sanity check in LoginModel/getUser() + // if you add/delete fields to the settings object. + // $settings->code_hide_line_num = $this->input->post('code_hide_line_num'); $settings->code_hide_metadata = $this->input->post('code_hide_metadata'); - $settings->icon_name = $icon_fname; - $settings->uploaded_icon_name = $uploaded_fname; - if ($this->users->storeSettings ($login['id'], $settings) === FALSE) + /* $uploaded_fname will be renamed to this name in users->storeSettings() */ + $settings->icon_name = $icon_fname; + + if ($this->users->storeSettings ($login['id'], $settings, $uploaded_fname) === FALSE) { @unlink (CODEPOT_USERICON_DIR . '/' . $uploaded_fname); $data['message'] = 'DATABASE ERROR'; @@ -249,6 +255,25 @@ class User extends Controller if ($userid_len > 0) { $icon_path = CODEPOT_USERICON_DIR . '/' . $userid . '.png'; + + $stat = @stat($icon_path); + if ($stat !== FALSE) + { + $etag = sprintf ('%x-%x-%x-%x', $stat['dev'], $stat['ino'], $stat['size'], $stat['mtime']); + $lastmod = gmdate ('D, d M Y H:i:s', $stat['mtime']); + + header ('Last-Modified: ' . $lastmod . ' GMT'); + header ('Etag: ' . $etag); + + if ((isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) || + (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $stat['mtime'])) + { + header('Not Modified', true, 304); + flush (); + return; + } + } + $icon_size = @filesize ($icon_path); if (@file_exists($icon_path) === TRUE && ($icon_size = @filesize($icon_path)) !== FALSE && diff --git a/codepot/src/codepot/models/loginmodel.php b/codepot/src/codepot/models/loginmodel.php index fc8eca82..b83a648b 100644 --- a/codepot/src/codepot/models/loginmodel.php +++ b/codepot/src/codepot/models/loginmodel.php @@ -43,6 +43,12 @@ class LoginModel extends Model { $settings = @unserialize ($settings); if ($settings === FALSE) $settings = NULL; + + // Sanity check on the session/cookie data + // See Controller/User->settings() for required fields. + if (!isset($settings->code_hide_line_num)) $settings->code_hide_line_num = ''; + if (!isset($settings->code_hide_metadata)) $settings->code_hide_metadata = ''; + if (!isset($settings->icon_name)) $settings->icon_name = ''; } } diff --git a/codepot/src/codepot/models/usermodel.php b/codepot/src/codepot/models/usermodel.php index c18247e2..f7900f01 100644 --- a/codepot/src/codepot/models/usermodel.php +++ b/codepot/src/codepot/models/usermodel.php @@ -33,7 +33,7 @@ class UserModel extends Model return $result[0]; } - function storeSettings ($userid, $settings) + function storeSettings ($userid, $settings, $uploaded_icon_name) { $icon_name_set = strlen($settings->icon_name) > 0; @@ -74,7 +74,7 @@ class UserModel extends Model if ($icon_name_set) { - if (@rename (CODEPOT_USERICON_DIR . '/' . $settings->uploaded_icon_name, + if (@rename (CODEPOT_USERICON_DIR . '/' . $uploaded_icon_name, CODEPOT_USERICON_DIR . '/' . $settings->icon_name) === FALSE) { $this->db->trans_rollback (); diff --git a/codepot/src/codepot/views/code_blame.php b/codepot/src/codepot/views/code_blame.php index 57d7a5dc..15751a1c 100644 --- a/codepot/src/codepot/views/code_blame.php +++ b/codepot/src/codepot/views/code_blame.php @@ -176,7 +176,14 @@ print anchor ("code/fetch/{$project->id}/${xpar}{$revreq}", $this->lang->line('D
id}/${xpar}/{$file['prev_rev']}", '<<'); - printf ('%s: %s', $this->lang->line('Revision'), $file['created_rev']); + print ' '; + + // anchor to the revision history at the root directory + print anchor ( + "code/revision/{$project->id}/!/{$file['created_rev']}", + sprintf("%s %s", $this->lang->line('Revision'), $file['created_rev']) + ); + if (!empty($file['created_tag'])) { print ' '; @@ -184,6 +191,7 @@ print anchor ("code/fetch/{$project->id}/${xpar}{$revreq}", $this->lang->line('D print htmlspecialchars($file['created_tag']); print (''); } + print ' '; print anchor ("code/blame/{$project->id}/${xpar}/{$file['next_rev']}", '>>'); print ' | '; @@ -254,7 +262,10 @@ if ($login['settings'] != NULL &&
lang->line('CODE_COMMIT') ?>
-lang->line('CODE_MSG_COMMITTED_BY_ON'), $file['last_author'], $file['time']); ?> +
    +
  • lang->line('CODE_MSG_COMMITTED_BY_ON'), $file['last_author'], $file['time']); ?>
  • +
+
lang->line('Message') ?>
diff --git a/codepot/src/codepot/views/code_file.php b/codepot/src/codepot/views/code_file.php
index a7552ec3..dccec44c 100644
--- a/codepot/src/codepot/views/code_file.php
+++ b/codepot/src/codepot/views/code_file.php
@@ -213,7 +213,14 @@ $this->load->view (
 
 	id}/${xpar}/{$file['prev_rev']}", '<<');
-		printf ('%s: %s', $this->lang->line('Revision'), $file['created_rev']);
+		print ' ';
+
+		// anchor to the revision history at the root directory
+		print anchor (
+			"code/revision/{$project->id}/!/{$file['created_rev']}",
+			sprintf("%s %s", $this->lang->line('Revision'), $file['created_rev'])
+		);
+
 		if (!empty($file['created_tag']))
 		{
 			print ' ';
@@ -221,6 +228,8 @@ $this->load->view (
 			print htmlspecialchars($file['created_tag']);
 			print ('');
 		}
+
+		print ' ';
 		print anchor ("code/file/{$project->id}/${xpar}/{$file['next_rev']}", '>>');
 
 		print ' | ';
@@ -229,6 +238,11 @@ $this->load->view (
 	lang->line('Metadata')?>
 
+
+
+
+
+
lang->line('CODE_COMMIT') ?>
-lang->line('CODE_MSG_COMMITTED_BY_ON'), $file['last_author'], $file['time']); ?> +
    +
  • lang->line('CODE_MSG_COMMITTED_BY_ON'), $file['last_author'], $file['time']); ?>
  • +
lang->line('Message') ?>
@@ -319,11 +335,6 @@ if (array_key_exists('properties', $file) && count($file['properties']) > 0)
 
-
-
-
-
-
diff --git a/codepot/src/codepot/views/code_folder.php b/codepot/src/codepot/views/code_folder.php index ab7c807c..c7453f88 100644 --- a/codepot/src/codepot/views/code_folder.php +++ b/codepot/src/codepot/views/code_folder.php @@ -30,7 +30,6 @@ - /wiki/show/id?>/", - "/wiki/attachment0/id?>/" + codepot_merge_path("", "/wiki/show/id?>/"), + codepot_merge_path("", "/wiki/attachment0/id?>/") ); prettyPrint(); @@ -201,7 +200,9 @@ $(function () { //setTimeout (show_progress, 1000); var ajax_req = $.ajax ({ - url: '/graph/folder_loc_json/id?>/converter->AsciiToHex($headpath)?>', + url: codepot_merge_path ( + "", + "/graph/folder_loc_json/id; ?>/converter->AsciiToHex($headpath)?>"), context: document.body, success: show_loc_graph }); @@ -390,13 +391,25 @@ $this->load->view ( print ' | '; } - printf ('%s: %s', $this->lang->line('Revision'), $file['created_rev']); + $xpar = $this->converter->AsciiTohex ($headpath); + print anchor ("code/file/{$project->id}/${xpar}/{$prev_revision}", '<<'); + print ' '; + + // anchor to the revision history at the root directory + print anchor ( + "code/revision/{$project->id}/!/{$file['created_rev']}", + sprintf("%s %s", $this->lang->line('Revision'), $file['created_rev']) + ); + if (!empty($file['created_tag'])) { print ' '; printf ('%s', htmlspecialchars($file['created_tag'])); } + print ' '; + print anchor ("code/file/{$project->id}/${xpar}/{$next_revision}", '>>'); + if ($file_count > 0) { print ' | '; @@ -561,7 +574,11 @@ $this->load->view ( print '
'; print $this->lang->line('CODE_COMMIT'); print '
'; + print ''; print '
'; print $this->lang->line('Message'); diff --git a/codepot/src/codepot/views/code_revision.php b/codepot/src/codepot/views/code_revision.php index 57951270..50abcd1f 100644 --- a/codepot/src/codepot/views/code_revision.php +++ b/codepot/src/codepot/views/code_revision.php @@ -182,13 +182,6 @@ $(function() { function render_wiki() { - creole_render_wiki ( - "code_revision_mainarea_result_msg_text", - "code_revision_mainarea_result_msg", - "/wiki/show/id?>/", - "" - ); - @@ -330,7 +323,9 @@ $history = $file['history'];
id}/${xpar}/{$prev_revision}", '<<'); - printf ('%s: %s', $this->lang->line('Revision'), $history['rev']); + print ' '; + + printf ('%s %s', $this->lang->line('Revision'), $history['rev']); if (!empty($history['tag'])) { print ' '; @@ -338,6 +333,8 @@ $history = $file['history']; print htmlspecialchars($history['tag']); print (''); } + + print ' '; print anchor ("code/revision/{$project->id}/${xpar}/{$next_revision}", '>>'); if ($can_edit) @@ -369,7 +366,7 @@ $history = $file['history'];
-
diff --git a/codepot/src/codepot/views/graph_main.php b/codepot/src/codepot/views/graph_main.php index e03d9a33..f6170917 100644 --- a/codepot/src/codepot/views/graph_main.php +++ b/codepot/src/codepot/views/graph_main.php @@ -460,8 +460,10 @@ $this->load->view (