From 19ed24a621b146c3fef69ed01d027a5979f6f967 Mon Sep 17 00:00:00 2001 From: Max Pozdeev Date: Sun, 7 Feb 2010 16:26:11 +0300 Subject: [PATCH] * corrected urls in get_mttinfo() and ajax requests * new name of session cookie --- src/ajax.js | 51 ++++++++++++++++++------------------ src/ajax.php | 2 +- src/common.php | 2 ++ src/index.php | 13 +++++---- src/init.php | 6 ++--- src/themes/default/index.php | 37 +++++++++++++------------- 6 files changed, 59 insertions(+), 52 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index aa8da33..49ae987 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -24,6 +24,7 @@ var page = {cur:'', prev:''}; var mytinytodo = { actions: {}, menus: {}, + mttUrl: '', addAction: function(action, proc) { @@ -74,7 +75,7 @@ function loadTasks(opts) var tag = filter.tag ? '&t='+encodeURIComponent(filter.tag) : ''; var nocache = '&rnd='+Math.random(); var setCompl = opts.setCompl != null ? '&setCompl=1' : ''; - $.getJSON('ajax.php?loadTasks&list='+curList.id+'&compl='+curList.showCompl+'&sort='+curList.sort+search+tag+'&tz='+tz()+setCompl+nocache, function(json){ + $.getJSON(mytinytodo.mttUrl+'ajax.php?loadTasks&list='+curList.id+'&compl='+curList.showCompl+'&sort='+curList.sort+search+tag+'&tz='+tz()+setCompl+nocache, function(json){ taskList = new Array(); taskOrder = new Array(); taskCnt.total = taskCnt.past = taskCnt.today = taskCnt.soon = 0; @@ -150,7 +151,7 @@ function submitNewTask(form) { if(form.task.value == '') return false; var nocache = '&rnd='+Math.random(); - $.post('ajax.php?newTask'+nocache, { list:curList.id, title: form.task.value, tz:tz(), tag:filter.tag }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?newTask'+nocache, { list:curList.id, title: form.task.value, tz:tz(), tag:filter.tag }, function(json){ if(!parseInt(json.total)) return; $('#total').text( parseInt($('#total').text()) + 1 ); taskCnt.total++; @@ -197,7 +198,7 @@ function deleteTask(id) return false; } var nocache = '&rnd='+Math.random(); - $.getJSON('ajax.php?deleteTask='+id+nocache, function(json){ + $.getJSON(mytinytodo.mttUrl+'ajax.php?deleteTask='+id+nocache, function(json){ if(!parseInt(json.total)) return; var item = json.list[0]; taskOrder.splice($.inArray(id,taskOrder), 1); @@ -215,7 +216,7 @@ function completeTask(id,ch) var compl = 0; if(ch.checked) compl = 1; var nocache = '&rnd='+Math.random(); - $.getJSON('ajax.php?completeTask='+id+'&compl='+compl+nocache, function(json){ + $.getJSON(mytinytodo.mttUrl+'ajax.php?completeTask='+id+'&compl='+compl+nocache, function(json){ if(!parseInt(json.total)) return; var item = json.list[0]; if(item.compl) $('#taskrow_'+id).addClass('task-completed'); @@ -264,7 +265,7 @@ function cancelTaskNote(id) function saveTaskNote(id) { var nocache = '&rnd='+Math.random(); - $.post('ajax.php?editNote='+id+nocache, {note: $('#notetext'+id).val()}, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?editNote='+id+nocache, {note: $('#notetext'+id).val()}, function(json){ if(!parseInt(json.total)) return; var item = json.list[0]; taskList[id].note = item.note; @@ -302,7 +303,7 @@ function showEditForm(isAdd) document.edittask.isadd.value = 1; if($('#task').val() != '') { - $.post('ajax.php?parseTaskStr'+'&rnd='+Math.random(), { list:curList.id, title: $('#task').val(), tz:tz(), tag:filter.tag }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?parseTaskStr'+'&rnd='+Math.random(), { list:curList.id, title: $('#task').val(), tz:tz(), tag:filter.tag }, function(json){ if(!json) return; document.edittask.task.value = json.title document.edittask.tags.value = json.tags; @@ -366,7 +367,7 @@ function saveTask(form) if(flag.needAuth && !flag.isLogged) return false; if(form.isadd.value != 0) return submitFullTask(form); var nocache = '&rnd='+Math.random(); - $.post('ajax.php?editTask='+form.id.value+nocache, { list:curList.id, tz:tz(), title: form.task.value, note:form.note.value, prio:form.prio.value, tags:form.tags.value, duedate:form.duedate.value }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?editTask='+form.id.value+nocache, { list:curList.id, tz:tz(), title: form.task.value, note:form.note.value, prio:form.prio.value, tags:form.tags.value, duedate:form.duedate.value }, function(json){ if(!parseInt(json.total)) return; var item = json.list[0]; changeTaskCnt(item, 0, taskList[item.id]); @@ -430,7 +431,7 @@ function orderChanged(event,ui) } } var nocache = '&rnd='+Math.random(); - $.post('ajax.php?changeOrder'+nocache, { order: s }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?changeOrder'+nocache, { order: s }, function(json){ }, 'json'); } @@ -492,7 +493,7 @@ function updateAccessStatus() function doAuth(form) { - $.post('ajax.php?rnd='+Math.random(), { login:1, password: form.password.value }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?rnd='+Math.random(), { login:1, password: form.password.value }, function(json){ form.password.value = ''; if(json.logged) { @@ -509,7 +510,7 @@ function doAuth(form) function logout() { - $.post('ajax.php?rnd='+Math.random(), { logout:1 }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?rnd='+Math.random(), { logout:1 }, function(json){ flag.isLogged = false; loadLists(0,1); }, 'json'); @@ -595,7 +596,7 @@ function prioClick(prio, el) function setTaskPrio(id, prio) { - $.getJSON('ajax.php?setPrio='+id+'&prio='+prio+'&rnd='+Math.random(), function(json){ + $.getJSON(mytinytodo.mttUrl+'ajax.php?setPrio='+id+'&prio='+prio+'&rnd='+Math.random(), function(json){ }); taskList[id].prio = prio; var $t = $('#taskrow_'+id); @@ -623,7 +624,7 @@ function setSort(v, init) if(!init) { changeTaskOrder(); - $.post('ajax.php?setSort'+'&rnd='+Math.random(), { list:curList.id, sort:curList.sort }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?setSort'+'&rnd='+Math.random(), { list:curList.id, sort:curList.sort }, function(json){ }, 'json'); } } @@ -679,7 +680,7 @@ function changeTaskOrder(id) function loadTags(callback) { - $.getJSON('ajax.php?tagCloud&list='+curList.id+'&rnd='+Math.random(), function(json){ + $.getJSON(mytinytodo.mttUrl+'ajax.php?tagCloud&list='+curList.id+'&rnd='+Math.random(), function(json){ if(!parseInt(json.total)) tagsList = []; else tagsList = json.cloud; var cloud = ''; @@ -807,7 +808,7 @@ function mttTabSelected(id, indx) $('#searchbar').hide(); } //if(tabLists[indx].published) - $('#rss_icon').find('a').attr('href', 'feed.php?list='+tabLists[indx].id); + $('#rss_icon').find('a').attr('href', mytinytodo.mttUrl+'feed.php?list='+tabLists[indx].id); mytinytodo.doAction('listSelected', tabLists[indx]); } curList = tabLists[indx]; @@ -883,7 +884,7 @@ function loadLists(onInit, updAccess) $('#searchbar').hide(); } var nocache = '&rnd='+Math.random(); - $.getJSON('ajax.php?loadLists'+nocache, function(json){ + $.getJSON(mytinytodo.mttUrl+'ajax.php?loadLists'+nocache, function(json){ tabLists = new Array(); var ti = ''; if(parseInt(json.total)) @@ -903,7 +904,7 @@ function loadLists(onInit, updAccess) curList = tabLists[0]; loadTasks(); //if(curList.published) - $('#rss_icon').find('a').attr('href', 'feed.php?list='+curList.id); + $('#rss_icon').find('a').attr('href', mytinytodo.mttUrl+'feed.php?list='+curList.id); if(flag.needAuth && !flag.isLogged) $('#bar_public').show(); } else { @@ -928,7 +929,7 @@ function addList() var r = prompt(lang.addList, lang.addListDefault); if(r == null) return; var nocache = '&rnd='+Math.random(); - $.post('ajax.php?'+nocache, { addList:1, name:r }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?'+nocache, { addList:1, name:r }, function(json){ if(!parseInt(json.total)) return; var item = json.list[0]; var i = tabLists.length; @@ -950,7 +951,7 @@ function renameCurList() var r = prompt(lang.renameList, dehtml(curList.name)); if(r == null || r == '') return; var nocache = '&rnd='+Math.random(); - $.post('ajax.php?'+nocache, { renameList:1, id:curList.id, name:r }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?'+nocache, { renameList:1, id:curList.id, name:r }, function(json){ if(!parseInt(json.total)) return; var item = json.list[0]; item.i = curList.i; @@ -966,7 +967,7 @@ function deleteCurList() if(!curList) return false; var r = confirm(lang.deleteList); if(!r) return; - $.post('ajax.php?'+'&rnd='+Math.random(), { deleteList:1, id:curList.id }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?'+'&rnd='+Math.random(), { deleteList:1, id:curList.id }, function(json){ if(!parseInt(json.total)) return; loadLists(); }, 'json'); @@ -1033,7 +1034,7 @@ function addEditTag(tag) function showSettings() { if(page.cur == 'settings') return false; - $('#page_ajax').load('settings.php?ajax=yes',null,function(){ + $('#page_ajax').load(mytinytodo.mttUrl+'settings.php?ajax=yes',null,function(){ showhide($('#page_ajax').addClass('mtt-page-settings'), $('#page_tasks')); page.prev = page.cur; page.cur = 'settings'; @@ -1054,7 +1055,7 @@ function saveSettings(frm) var params = { save:'ajax' }; $(frm).find("input:text,input:checked,select,:password").filter(":enabled").each(function() { params[this.name || '__'] = this.value; }); $(frm).find(":submit").attr('disabled','disabled').blur(); - $.post('settings.php?'+'&rnd='+Math.random(), params, function(json){ + $.post(mytinytodo.mttUrl+'settings.php?'+'&rnd='+Math.random(), params, function(json){ if(json.saved) { flashInfo(lang.settingsSaved); setTimeout('window.location.reload();', 1000); @@ -1066,7 +1067,7 @@ function submitFullTask(form) { if(flag.needAuth && !flag.isLogged) return false; var nocache = '&rnd='+Math.random(); - $.post('ajax.php?fullNewTask'+nocache, { list:curList.id, tag:filter.tag, title: form.task.value, note:form.note.value, prio:form.prio.value, tags:form.tags.value, duedate:form.duedate.value }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?fullNewTask'+nocache, { list:curList.id, tag:filter.tag, title: form.task.value, note:form.note.value, prio:form.prio.value, tags:form.tags.value, duedate:form.duedate.value }, function(json){ if(!parseInt(json.total)) return; form.task.value = ''; var item = json.list[0]; @@ -1088,7 +1089,7 @@ function publishCurList() { if(!curList) return false; var nocache = '&rnd='+Math.random(); - $.post('ajax.php?publishList'+nocache, { list:curList.id, publish:curList.published?0:1 }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?publishList'+nocache, { list:curList.id, publish:curList.published?0:1 }, function(json){ if(!parseInt(json.total)) return; curList.published = curList.published?0:1; if(curList.published) $('#btnPublish').addClass('mtt-item-checked'); @@ -1265,7 +1266,7 @@ function mttMenu(container, options) function moveTaskToList(taskId, listId) { if(curList.id == listId) return; - $.post('ajax.php?moveTask&rnd='+Math.random(), { id:taskId, from:curList.id, to:listId }, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?moveTask&rnd='+Math.random(), { id:taskId, from:curList.id, to:listId }, function(json){ if(!parseInt(json.total)) return; changeTaskCnt(taskList[taskId], -1) delete taskList[taskId]; @@ -1312,7 +1313,7 @@ function showCompletedToggle() function listOrderChanged(event, ui) { var order = $(this).sortable("serialize"); - $.post('ajax.php?changeListOrder'+'&rnd='+Math.random(), order, function(json){ + $.post(mytinytodo.mttUrl+'ajax.php?changeListOrder'+'&rnd='+Math.random(), order, function(json){ }, 'json'); } diff --git a/src/ajax.php b/src/ajax.php index b65396b..d0744f8 100644 --- a/src/ajax.php +++ b/src/ajax.php @@ -281,7 +281,7 @@ elseif(isset($_POST['login'])) } elseif(isset($_POST['logout'])) { - $_SESSION = array(); + unset($_SESSION['logged']); $t = array('logged' => 0); echo json_encode($t); exit; diff --git a/src/common.php b/src/common.php index 9de108a..4fb48fc 100644 --- a/src/common.php +++ b/src/common.php @@ -67,6 +67,8 @@ class Config 'mysql.user' => array('default'=>'user', 'type'=>'s'), 'mysql.password' => array('default'=>'', 'type'=>'s'), 'prefix' => array('default'=>'', 'type'=>'s'), + 'url' => array('default'=>'', 'type'=>'s'), + 'mtt_url' => array('default'=>'', 'type'=>'s'), 'title' => array('default'=>'', 'type'=>'s'), 'lang' => array('default'=>'en', 'type'=>'s'), 'password' => array('default'=>'', 'type'=>'s'), diff --git a/src/index.php b/src/index.php index 85a514c..22f13a7 100644 --- a/src/index.php +++ b/src/index.php @@ -42,15 +42,18 @@ function get_mttinfo($v) if(isset($_mttinfo[$v])) return $_mttinfo[$v]; switch($v) { - case 'template_uri': - $_mttinfo['template_uri'] = url_dir($_SERVER['REQUEST_URI']). 'themes/'. Config::get('template') . '/'; - return $_mttinfo['template_uri']; case 'template_url': - $_mttinfo['template_url'] = get_mttinfo('url'). 'themes/'. Config::get('template') . '/'; + $_mttinfo['template_url'] = get_mttinfo('mtt_url'). 'themes/'. Config::get('template') . '/'; return $_mttinfo['template_url']; case 'url': - $_mttinfo['url'] = 'http://'.$_SERVER['HTTP_HOST'] .($_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : ''). url_dir($_SERVER['REQUEST_URI']); + $_mttinfo['url'] = Config::get('url'); + if($_mttinfo['url'] == '') + $_mttinfo['url'] = 'http://'.$_SERVER['HTTP_HOST'] .($_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : ''). parse_url($url, PHP_URL_PATH); return $_mttinfo['url']; + case 'mtt_url': + $_mttinfo['mtt_url'] = Config::get('mtt_url'); + if($_mttinfo['mtt_url'] == '') $_mttinfo['mtt_url'] = url_dir($_SERVER['REQUEST_URI']); + return $_mttinfo['mtt_url']; case 'title': $_mttinfo['title'] = (Config::get('title') != '') ? htmlarray(Config::get('title')) : $lang->get('My Tiny Todolist'); return $_mttinfo['title']; diff --git a/src/init.php b/src/init.php index 6bb717e..9145e62 100644 --- a/src/init.php +++ b/src/init.php @@ -45,7 +45,8 @@ if($needAuth && !isset($dontStartSession)) ini_set('session.use_cookies', true); ini_set('session.use_only_cookies', true); - session_set_cookie_params(1209600, substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1)); #14 days session cookie lifetime + session_set_cookie_params(1209600, url_dir(Config::get('url')=='' ? $_SERVER['REQUEST_URI'] : Config::get('url'))); # 14 days session cookie lifetime + session_name('mtt-session'); session_start(); } @@ -57,14 +58,13 @@ function is_logged() function timestampToDatetime($timestamp, $tz) { - global $lang; $format = Config::get('dateformat') .' '. (Config::get('clock') == 12 ? 'g:i A' : 'H:i'); return formatTime($format, $timestamp, $tz); } function formatTime($format, $timestamp=0, $tz=null) { - global $lang; + $lang = Lang::instance(); if($timestamp == 0) $timestamp = time(); if(is_null($tz)) $tz = round(date('Z')/60); $newformat = strtr($format, array('F'=>'%1', 'M'=>'%2')); diff --git a/src/themes/default/index.php b/src/themes/default/index.php index 6ac7a00..54fba27 100644 --- a/src/themes/default/index.php +++ b/src/themes/default/index.php @@ -15,29 +15,30 @@ function datepickerformat() <?php mttinfo('title'); ?> - + - + - + - + - - - - - - + + + + + +