Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: nouvelingenieur/Refresh
base: 4185d69f06
...
head fork: nouvelingenieur/Refresh
compare: 8442a9345b
  • 17 commits
  • 14 files changed
  • 0 commit comments
  • 2 contributors
205 APP/HelloPhoneGap/assets/www/html_entity_decode.js
View
@@ -0,0 +1,205 @@
+function html_entity_decode (string, quote_style) {
+ // http://kevin.vanzonneveld.net
+ // + original by: john (http://www.jd-tech.net)
+ // + input by: ger
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // + bugfixed by: Onno Marsman
+ // + improved by: marc andreu
+ // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // + input by: Ratheous
+ // + bugfixed by: Brett Zamir (http://brett-zamir.me)
+ // + input by: Nick Kolosov (http://sammy.ru)
+ // + bugfixed by: Fox
+ // - depends on: get_html_translation_table
+ // * example 1: html_entity_decode('Kevin & van Zonneveld');
+ // * returns 1: 'Kevin & van Zonneveld'
+ // * example 2: html_entity_decode('<');
+ // * returns 2: '<'
+ var hash_map = {},
+ symbol = '',
+ tmp_str = '',
+ entity = '';
+ tmp_str = string.toString();
+
+ if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
+ return false;
+ }
+
+ // fix & problem
+ // http://phpjs.org/functions/get_html_translation_table:416#comment_97660
+ delete(hash_map['&']);
+ hash_map['&'] = '&';
+
+ for (symbol in hash_map) {
+ entity = hash_map[symbol];
+ tmp_str = tmp_str.split(entity).join(symbol);
+ }
+ tmp_str = tmp_str.split(''').join("'");
+
+ return tmp_str;
+}
+
+
+function get_html_translation_table (table, quote_style) {
+ // http://kevin.vanzonneveld.net
+ // + original by: Philip Peterson
+ // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // + bugfixed by: noname
+ // + bugfixed by: Alex
+ // + bugfixed by: Marco
+ // + bugfixed by: madipta
+ // + improved by: KELAN
+ // + improved by: Brett Zamir (http://brett-zamir.me)
+ // + bugfixed by: Brett Zamir (http://brett-zamir.me)
+ // + input by: Frank Forte
+ // + bugfixed by: T.Wild
+ // + input by: Ratheous
+ // % note: It has been decided that we're not going to add global
+ // % note: dependencies to php.js, meaning the constants are not
+ // % note: real constants, but strings instead. Integers are also supported if someone
+ // % note: chooses to create the constants themselves.
+ // * example 1: get_html_translation_table('HTML_SPECIALCHARS');
+ // * returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
+ var entities = {},
+ hash_map = {},
+ decimal;
+ var constMappingTable = {},
+ constMappingQuoteStyle = {};
+ var useTable = {},
+ useQuoteStyle = {};
+
+ // Translate arguments
+ constMappingTable[0] = 'HTML_SPECIALCHARS';
+ constMappingTable[1] = 'HTML_ENTITIES';
+ constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
+ constMappingQuoteStyle[2] = 'ENT_COMPAT';
+ constMappingQuoteStyle[3] = 'ENT_QUOTES';
+
+ useTable = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
+ useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
+
+ if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
+ throw new Error("Table: " + useTable + ' not supported');
+ // return false;
+ }
+
+ entities['38'] = '&amp;';
+ if (useTable === 'HTML_ENTITIES') {
+ entities['160'] = '&nbsp;';
+ entities['161'] = '&iexcl;';
+ entities['162'] = '&cent;';
+ entities['163'] = '&pound;';
+ entities['164'] = '&curren;';
+ entities['165'] = '&yen;';
+ entities['166'] = '&brvbar;';
+ entities['167'] = '&sect;';
+ entities['168'] = '&uml;';
+ entities['169'] = '&copy;';
+ entities['170'] = '&ordf;';
+ entities['171'] = '&laquo;';
+ entities['172'] = '&not;';
+ entities['173'] = '&shy;';
+ entities['174'] = '&reg;';
+ entities['175'] = '&macr;';
+ entities['176'] = '&deg;';
+ entities['177'] = '&plusmn;';
+ entities['178'] = '&sup2;';
+ entities['179'] = '&sup3;';
+ entities['180'] = '&acute;';
+ entities['181'] = '&micro;';
+ entities['182'] = '&para;';
+ entities['183'] = '&middot;';
+ entities['184'] = '&cedil;';
+ entities['185'] = '&sup1;';
+ entities['186'] = '&ordm;';
+ entities['187'] = '&raquo;';
+ entities['188'] = '&frac14;';
+ entities['189'] = '&frac12;';
+ entities['190'] = '&frac34;';
+ entities['191'] = '&iquest;';
+ entities['192'] = '&Agrave;';
+ entities['193'] = '&Aacute;';
+ entities['194'] = '&Acirc;';
+ entities['195'] = '&Atilde;';
+ entities['196'] = '&Auml;';
+ entities['197'] = '&Aring;';
+ entities['198'] = '&AElig;';
+ entities['199'] = '&Ccedil;';
+ entities['200'] = '&Egrave;';
+ entities['201'] = '&Eacute;';
+ entities['202'] = '&Ecirc;';
+ entities['203'] = '&Euml;';
+ entities['204'] = '&Igrave;';
+ entities['205'] = '&Iacute;';
+ entities['206'] = '&Icirc;';
+ entities['207'] = '&Iuml;';
+ entities['208'] = '&ETH;';
+ entities['209'] = '&Ntilde;';
+ entities['210'] = '&Ograve;';
+ entities['211'] = '&Oacute;';
+ entities['212'] = '&Ocirc;';
+ entities['213'] = '&Otilde;';
+ entities['214'] = '&Ouml;';
+ entities['215'] = '&times;';
+ entities['216'] = '&Oslash;';
+ entities['217'] = '&Ugrave;';
+ entities['218'] = '&Uacute;';
+ entities['219'] = '&Ucirc;';
+ entities['220'] = '&Uuml;';
+ entities['221'] = '&Yacute;';
+ entities['222'] = '&THORN;';
+ entities['223'] = '&szlig;';
+ entities['224'] = '&agrave;';
+ entities['225'] = '&aacute;';
+ entities['226'] = '&acirc;';
+ entities['227'] = '&atilde;';
+ entities['228'] = '&auml;';
+ entities['229'] = '&aring;';
+ entities['230'] = '&aelig;';
+ entities['231'] = '&ccedil;';
+ entities['232'] = '&egrave;';
+ entities['233'] = '&eacute;';
+ entities['234'] = '&ecirc;';
+ entities['235'] = '&euml;';
+ entities['236'] = '&igrave;';
+ entities['237'] = '&iacute;';
+ entities['238'] = '&icirc;';
+ entities['239'] = '&iuml;';
+ entities['240'] = '&eth;';
+ entities['241'] = '&ntilde;';
+ entities['242'] = '&ograve;';
+ entities['243'] = '&oacute;';
+ entities['244'] = '&ocirc;';
+ entities['245'] = '&otilde;';
+ entities['246'] = '&ouml;';
+ entities['247'] = '&divide;';
+ entities['248'] = '&oslash;';
+ entities['249'] = '&ugrave;';
+ entities['250'] = '&uacute;';
+ entities['251'] = '&ucirc;';
+ entities['252'] = '&uuml;';
+ entities['253'] = '&yacute;';
+ entities['254'] = '&thorn;';
+ entities['255'] = '&yuml;';
+ }
+
+ if (useQuoteStyle !== 'ENT_NOQUOTES') {
+ entities['34'] = '&quot;';
+ }
+ if (useQuoteStyle === 'ENT_QUOTES') {
+ entities['39'] = '&#39;';
+ }
+ entities['60'] = '&lt;';
+ entities['62'] = '&gt;';
+
+
+ // ascii decimals to real symbols
+ for (decimal in entities) {
+ if (entities.hasOwnProperty(decimal)) {
+ hash_map[String.fromCharCode(decimal)] = entities[decimal];
+ }
+ }
+
+ return hash_map;
+}
3  APP/HelloPhoneGap/assets/www/index.html
View
@@ -3,7 +3,8 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Refresh</title>
-
+ <script src="sha1.js" type="text/javascript"></script>
+ <script src="html_entity_decode.js" type="text/javascript"></script>
<script src="lib/touch/sencha-touch.js" type="text/javascript"></script>
<script type="text/javascript" src="index.js"></script>
<link href="lib/touch/resources/css/sencha-touch.css" rel="stylesheet" type="text/css" />
257 APP/HelloPhoneGap/assets/www/index.js
View
@@ -1,3 +1,5 @@
+var form;
+var currentPanel;
Ext.setup({
icon: 'icon.png',
@@ -6,7 +8,6 @@ Ext.setup({
glossOnIcon: false,
onReady: function() {
-
// login panel
Ext.regModel('User', {
fields: [
@@ -25,10 +26,7 @@ Ext.setup({
var serverStore = new Ext.data.JsonStore({
data : [
- { server : 'master', title : 'Master'},
- { server : 'padawan', title : 'Student'},
- { server : 'teacher', title : 'Instructor'},
- { server : 'aid', title : 'Assistant'}
+ { server : 'http://refresh.nouvelingenieur.fr', title : 'Default'}
],
model : 'servers',
autoLoad : true,
@@ -37,7 +35,6 @@ Ext.setup({
var formBase = {
scroll: 'vertical',
- url : 'http://refresh.nouvelingenieur.fr/api/login.php',
standardSubmit : false,
items: [
{
@@ -51,7 +48,7 @@ Ext.setup({
},
items: [
{
- xtype: 'textfield',
+ xtype: 'emailfield',
name : 'EMAIL',
label: 'E-mail',
useClearIcon: false,
@@ -77,27 +74,45 @@ Ext.setup({
xtype: 'toolbar',
dock: 'bottom',
items: [
- {xtype: 'spacer'},
{
text: 'Reset',
handler: function() {
form.reset();
}
},
+ {xtype: 'spacer'},
{
text: 'Login',
- ui: 'confirm',
+ ui: 'action',
handler: function() {
Ext.util.JSONP.request({
- url: 'http://refresh.nouvelingenieur.fr/api/login.php',
+ url: form.getValues().SERVER_URL+'/api/login.php',
callbackKey: 'callback',
params: {
- EMAIL: form.getValues().EMAIL,
- PASSWORD: form.getValues().PASSWORD
+ EMAIL: SHA1(form.getValues().EMAIL),
+ PASSWORD: SHA1(form.getValues().PASSWORD)
},
callback: function(result) {
if (result.data.SUCCESS=='True') {
+ Ext.util.JSONP.request({
+ url: form.getValues().SERVER_URL+'/api/categories.php',
+ callbackKey: 'callback',
+ params: {
+ EMAIL: SHA1(form.getValues().EMAIL),
+ PASSWORD: SHA1(form.getValues().PASSWORD)
+ },
+ callback: function(result) {
+ var categoriesList = Array();
+ categoriesList.push({text: 'All categories', value: 0});
+ for(i=0;i<result.data.length ;i++){
+ categoriesList.push({text: html_entity_decode(result.data[i].CATEGORY_NAME), value: result.data[i].CATEOGRY_ID});
+ }
+ searchPanel.getDockedComponent(0).getComponent('categoryList').setOptions(categoriesList);
+ (formPost.items.get(1)).setOptions(categoriesList);
+ }
+ });
Ext.getCmp('thePanel').setActiveItem(1,{type:'slide',direction:'left'});
+ currentPanel = 1;
} else {
Ext.Msg.alert('Error', 'We were unable to connect to the server. Please, review the information entered.', Ext.emptyFn);
}
@@ -113,24 +128,37 @@ Ext.setup({
form = new Ext.form.FormPanel(formBase);
form.show();
+ // bottom bar
+ var buttonsSpecBottom = [
+ { ui: 'normal', text: 'Search' },
+ { ui: 'normal', text: 'Post'}
+ ]
- // idea panel
- var searchedString = '';
+ var tapHandler = function (btn, evt) {
+ switch(btn.text) {
+ case 'Search':
+ Ext.getCmp('thePanel').setActiveItem(1,{type:'slide',direction:'right'});
+ break;
+ case 'Post':
+ Ext.getCmp('thePanel').setActiveItem(3,{type:'slide',direction:'left'});
+ break;
+ }
+ }
- Ext.util.JSONP.request({
- url: 'http://refresh.nouvelingenieur.fr/api/categories.php',
- callbackKey: 'callback',
- params: {
+ var bottomBar = {
+ xtype: 'toolbar',
+ ui: 'dark',
+ dock: 'bottom',
+ layout: {
+ pack: 'justify',
+ align: 'center' // align center is the default
},
- callback: function(result) {
- var categoriesList = Array();
- categoriesList.push({text: 'All categories', value: 0});
- for(i=0;i<result.data.length ;i++){
- categoriesList.push({text: result.data[i].CATEGORY_NAME, value: result.data[i].CATEOGRY_ID});
- }
- searchPanel.getDockedComponent(0).getComponent('categoryList').setOptions(categoriesList);
- }
- });
+ items: buttonsSpecBottom,
+ defaults: { handler: tapHandler }
+ }
+
+ // idea panel
+ var searchedString = '';
// top search toolbar
var search_items = [{
@@ -154,17 +182,19 @@ Ext.setup({
// search button handler
handler: function() {
Ext.util.JSONP.request({
- url: 'http://refresh.nouvelingenieur.fr/api/ideas.php',
+ url: form.getValues().SERVER_URL+'/api/ideas.php',
callbackKey: 'callback',
params: {
q: searchPanel.getDockedComponent(0).getComponent('q').getValue(),
- c: searchPanel.getDockedComponent(0).getComponent('categoryList').getValue()
+ c: searchPanel.getDockedComponent(0).getComponent('categoryList').getValue(),
+ EMAIL: SHA1(form.getValues().EMAIL),
+ PASSWORD: SHA1(form.getValues().PASSWORD)
},
callback: function(result) {
searchedString = searchPanel.getDockedComponent(0).getComponent('q').getValue();
groupingBase.store.removeAll();
for(i=0;i<result.data.length ;i++){
- groupingBase.store.add([{ideaId:result.data[i].IDEA_ID, ideaCategoryId:result.data[i].IDEA_CATEGORY_ID, ideaName: result.data[i].IDEA_TITLE, ideaText: result.data[i].IDEA_TEXT, ideaAuthor: result.data[i].IDEA_AUTHOR, ideaDate: result.data[i].IDEA_DATE}]);
+ groupingBase.store.add([{ideaId:result.data[i].IDEA_ID, ideaCategoryId:result.data[i].IDEA_CATEGORY_ID, ideaName: result.data[i].IDEA_TITLE, ideaText: result.data[i].IDEA_TEXT, ideaAuthor: result.data[i].IDEA_AUTHOR, ideaDate: result.data[i].IDEA_DATE, ideaLikes: result.data[i].IDEA_POSITIVE_VOTES, ideaDislikes: result.data[i].IDEA_NEGATIVE_VOTES}]);
}
}
});
@@ -172,26 +202,29 @@ Ext.setup({
},
{
text: 'Back',
- ui: 'round',
+ ui: 'back',
hidden: true,
// search button handler
handler: function() {
this.setVisible(true);
Ext.getCmp('thePanel').setActiveItem(1,{type:'slide',direction:'right'});
+ currentPanel = 1;
}
}]
// top idea toolbar
var topIdeaToolbar = [{
text: 'Back',
- ui: 'round',
+ ui: 'back',
// search button handler
handler: function() {
this.setVisible(true);
Ext.getCmp('thePanel').setActiveItem(1,{type:'slide',direction:'right'});
+ currentPanel = 1;
}
}]
+
// idea data type
Ext.regModel('Idea', {
fields: ['ideaId', 'ideaCategoryId', 'ideaName', 'ideaText', 'ideaAuthor', 'ideaDate']
@@ -213,9 +246,9 @@ Ext.setup({
onItemDisclosure: {
scope: 'test',
handler: function(record, btn, index) {
- //alert('Disclose more info for ' + record.get('ideaName'));
Ext.getCmp('ideaPanel').update(record.data);
Ext.getCmp('thePanel').setActiveItem(2,{type:'slide',direction:'left'});
+ currentPanel = 2;
}
},
store: ideaStore
@@ -236,29 +269,175 @@ Ext.setup({
title: 'test2',
html: '<p></p>',
dockedItems: searchResultList
- }]
+ }, bottomBar]
});
// idea panel
+ var like = function() {
+ console.log('like');
+ Ext.util.JSONP.request({
+ url: 'http://free.worldweatheronline.com/feed/weather.ashx',
+ callbackKey: 'callback',
+ params: {
+ key: '23f6a0ab24185952101705',
+ },
+ callback: function(result) {
+ // update ratings
+ }
+ });
+ };
+
+ var dislike = function() {
+ console.log('dislike');
+ Ext.util.JSONP.request({
+ url: 'http://free.worldweatheronline.com/feed/weather.ashx',
+ callbackKey: 'callback',
+ params: {
+ key: '23f6a0ab24185952101705',
+ },
+ callback: function(result) {
+ // update ratings
+ }
+ });
+ };
+
+ var goToCommentPanel = function() {
+ // slide
+ console.log('goToCommentPanel');
+ };
+
+ var toolbar_icons = {
+ xtype: 'toolbar',
+ dock: 'bottom',
+ scroll: 'horizontal',
+ items: [
+ { iconMask: true, iconAlign: 'left', ui: 'round', text: 'Comment', iconCls: 'compose', handler: goToCommentPanel},
+ {xtype: 'spacer'},
+ { iconMask: true, iconAlign: 'left', ui: 'action-round', text: 'Like', iconCls: 'add', handler: like},
+ { iconMask: true, iconAlign: 'left', ui: 'action-round', text: 'Dislike', iconCls: 'delete', handler: dislike},
+ ]
+ }
+
var ideaPanel = new Ext.Panel({
- fullscreen: true,
id:'ideaPanel',
+ dockedItems: [toolbar_icons],
+ scroll: 'both',
+ tpl:'<div class="containerBox"><h1 id="ideaTitle">{ideaName}</h1> by {ideaAuthor} on {ideaDate}</h1><div>{ideaText}</div><div><ul><li>Likes: {ideaLikes}</li><li>Dislikes: {ideaDislikes}</li></ul></div></div>',
+ });
+
+ var ideaPanelAndComments = new Ext.Panel({
+ fullscreen: true,
+ id:'ideaPanelAndComments',
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: topIdeaToolbar
- }],
- scroll:'vertical',
- tpl:'<div class="containerBox"><h1 id="ideaTitle">{ideaName}</h1> by {ideaAuthor}, {ideaDate}</h1><div>{ideaText}</div></div>'
+ },ideaPanel],
+ scroll:'vertical'
+ });
+
+ // post panel
+ // bottom bar
+ var postButtonsSpecBottom = [
+ { ui: 'normal', text: 'Search' },
+ { ui: 'action', text: 'Post' }
+ ]
+
+ var postTapHandler = function (btn, evt) {
+ switch(btn.text) {
+ case 'Search':
+ Ext.getCmp('thePanel').setActiveItem(1,{type:'slide',direction:'right'});
+ currentPanel = 1;
+ break;
+ case 'Post':
+ Ext.util.JSONP.request({
+ url: form.getValues().SERVER_URL+'/api/post.php',
+ callbackKey: 'callback',
+ params: {
+ IDEA_TITLE: (formPost.items.get(0)).getValue(),
+ IDEA_TEXT: (formPost.items.get(2)).getValue(),
+ IDEA_CATEOGRY_ID: (formPost.items.get(1)).getValue(),
+ EMAIL: SHA1(form.getValues().EMAIL),
+ PASSWORD: SHA1(form.getValues().PASSWORD)
+ },
+ callback: function() {
+ }
+ });
+ break;
+ }
+ }
+
+ var postBottomBar = {
+ xtype: 'toolbar',
+ ui: 'dark',
+ dock: 'bottom',
+ layout: {
+ pack: 'justify',
+ align: 'center' // align center is the default
+ },
+ items: postButtonsSpecBottom,
+ defaults: { handler: postTapHandler }
+ }
+
+ //Form Panel
+ var formPost = new Ext.form.FormPanel({
+ id: 'formPost',
+ scroll: 'vertical',
+ items: [{
+ xtype: 'textfield',
+ id:'title',
+ name : 'title',
+ label: ' Idea',
+ required: true,
+ options: [
+ ]
+ },
+ {
+ xtype: 'selectfield',
+ name: 'Category',
+ id: 'categoryList2',
+ label: 'Category of the idea',
+ required: true,
+ options: [
+ ]
+ },
+ {
+ xtype: 'textareafield',
+ name: 'Text',
+ id: 'Text',
+ label: 'Description',
+ required: true,
+ options: [
+ ]
+ }]
+ });
+
+ var postPanel = new Ext.Panel({
+ id:'postPanel',
+ fullscreen: true,
+ items: [formPost],
+ dockedItems: [{
+ xtype: 'toolbar',
+ dock: 'top',
+ items: {
+ text: 'Back',
+ ui: 'back',
+ // search button handler
+ handler: function() {
+ Ext.getCmp('thePanel').setActiveItem(currentPanel,{type:'slide',direction:'right'});
+ }
+ }
+ }, postBottomBar]
});
+ // global panel
var panel = new Ext.Panel({
fullscreen: true,
id:'thePanel',
layout: 'card',
cardSwitchAnimation:'slide',
scroll:'vertical',
- items:[form, searchPanel, ideaPanel]
+ items:[form, searchPanel, ideaPanelAndComments, postPanel]
});
}
});
174 APP/HelloPhoneGap/assets/www/sha1.js
View
@@ -0,0 +1,174 @@
+/**
+*
+* Secure Hash Algorithm (SHA1)
+* http://www.webtoolkit.info/
+*
+**/
+
+function SHA1 (msg) {
+
+ function rotate_left(n,s) {
+ var t4 = ( n<<s ) | (n>>>(32-s));
+ return t4;
+ };
+
+ function lsb_hex(val) {
+ var str="";
+ var i;
+ var vh;
+ var vl;
+
+ for( i=0; i<=6; i+=2 ) {
+ vh = (val>>>(i*4+4))&0x0f;
+ vl = (val>>>(i*4))&0x0f;
+ str += vh.toString(16) + vl.toString(16);
+ }
+ return str;
+ };
+
+ function cvt_hex(val) {
+ var str="";
+ var i;
+ var v;
+
+ for( i=7; i>=0; i-- ) {
+ v = (val>>>(i*4))&0x0f;
+ str += v.toString(16);
+ }
+ return str;
+ };
+
+
+ function Utf8Encode(string) {
+ string = string.replace(/\r\n/g,"\n");
+ var utftext = "";
+
+ for (var n = 0; n < string.length; n++) {
+
+ var c = string.charCodeAt(n);
+
+ if (c < 128) {
+ utftext += String.fromCharCode(c);
+ }
+ else if((c > 127) && (c < 2048)) {
+ utftext += String.fromCharCode((c >> 6) | 192);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+ else {
+ utftext += String.fromCharCode((c >> 12) | 224);
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+
+ }
+
+ return utftext;
+ };
+
+ var blockstart;
+ var i, j;
+ var W = new Array(80);
+ var H0 = 0x67452301;
+ var H1 = 0xEFCDAB89;
+ var H2 = 0x98BADCFE;
+ var H3 = 0x10325476;
+ var H4 = 0xC3D2E1F0;
+ var A, B, C, D, E;
+ var temp;
+
+ msg = Utf8Encode(msg);
+
+ var msg_len = msg.length;
+
+ var word_array = new Array();
+ for( i=0; i<msg_len-3; i+=4 ) {
+ j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
+ msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
+ word_array.push( j );
+ }
+
+ switch( msg_len % 4 ) {
+ case 0:
+ i = 0x080000000;
+ break;
+ case 1:
+ i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
+ break;
+
+ case 2:
+ i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
+ break;
+
+ case 3:
+ i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8 | 0x80;
+ break;
+ }
+
+ word_array.push( i );
+
+ while( (word_array.length % 16) != 14 ) word_array.push( 0 );
+
+ word_array.push( msg_len>>>29 );
+ word_array.push( (msg_len<<3)&0x0ffffffff );
+
+
+ for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
+
+ for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
+ for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
+
+ A = H0;
+ B = H1;
+ C = H2;
+ D = H3;
+ E = H4;
+
+ for( i= 0; i<=19; i++ ) {
+ temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
+ E = D;
+ D = C;
+ C = rotate_left(B,30);
+ B = A;
+ A = temp;
+ }
+
+ for( i=20; i<=39; i++ ) {
+ temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
+ E = D;
+ D = C;
+ C = rotate_left(B,30);
+ B = A;
+ A = temp;
+ }
+
+ for( i=40; i<=59; i++ ) {
+ temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
+ E = D;
+ D = C;
+ C = rotate_left(B,30);
+ B = A;
+ A = temp;
+ }
+
+ for( i=60; i<=79; i++ ) {
+ temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
+ E = D;
+ D = C;
+ C = rotate_left(B,30);
+ B = A;
+ A = temp;
+ }
+
+ H0 = (H0 + A) & 0x0ffffffff;
+ H1 = (H1 + B) & 0x0ffffffff;
+ H2 = (H2 + C) & 0x0ffffffff;
+ H3 = (H3 + D) & 0x0ffffffff;
+ H4 = (H4 + E) & 0x0ffffffff;
+
+ }
+
+ var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
+
+ return temp.toLowerCase();
+
+}
BIN  APP/Refresh_team.xls
View
Binary file not shown
11 SITE/ajax.php
View
@@ -21,9 +21,14 @@
Contact : nicolas.seichepine.org/?action=contact
*/
+session_start();
+
include_once("config.php");
include_once("script_php/pages_secondlevel/actions.php");
+$privileges = user_privilege_level();
+$login = $_SESSION['login_c'];
+
// Demande
if (isset($_GET["action"]) && is_string($_GET["action"]))
@@ -36,7 +41,11 @@
{
// appel de la fonction post par Ajax
case "post":
- post($_POST['title'],$_POST['message'],$_POST['anonymization'],$_POST['category'],$_SESSION['login_c'],$valid=0,$output='JSON');
+ post($_POST['title'],$_POST['message'],$_POST['anonymization'],$_POST['category'],$login,$valid=0,$output='JSON');
+ break;
+
+ case "comments":
+ get_comments($_POST['thread_id'],$privileges,$login,$output='JSON');
break;
// Message d'erreur
57 SITE/api/get_comments.php
View
@@ -0,0 +1,57 @@
+<?php
+/*
+get_comments
+Retrieves the comment associated with an idea.
+
+File
+
+SITE/api/get_comments.php
+
+Input
+
+string EMAIL: sha1 crypted email of the user
+string PASSWORD: sha1 crypted password
+int IDEA_ID
+Output
+
+int comment_id: 12345
+string comment_text: 'This is my comment!'
+string comment_user_name: 'John'
+
+*/
+
+
+header('Content-type: application/json');
+
+include_once("./mysql_connect.php");
+
+/* INPUT */
+$EMAIL = set_value('EMAIL','');
+$PASSWORD = set_value('PASSWORD','');
+$IDEA_ID = set_value('IDEA_ID','');
+
+$result=@mysql_query(sprintf("SELECT user_id,is_valid,privileges FROM user WHERE hash_mail='%s' AND hash_pass='%s'",mysql_real_escape_string($EMAIL),mysql_real_escape_string($PASSWORD)));
+if (mysql_num_rows($result)!=0)
+ {
+
+
+ $action = get_comments($IDEA_ID,1,$EMAIL,$output='');
+
+ $array = $action->data;
+
+
+} else {
+
+ $array = array('SUCCESS' => 'False','MESSAGE' => _('Login Error: email and password do not match'));
+
+}
+
+array_walk_recursive($array, function(&$item, $key) {
+ if(is_string($item)) {
+ $item = htmlentities($item);
+ }
+});
+
+echo "Ext.util.JSONP.callback(".json_encode(array("data" => $array)).")";
+
+?>
31 SITE/api/ideas.php
View
@@ -20,6 +20,8 @@
string IDEA_TEXT : text of the idea
date IDEA_DATE : date of the posting of the idea
string IDEA_AUTHOR : name of the author if available
+integer IDEA_POSITIVE_VOTES : number of positive votes
+integer IDEA_NEGATIVE_VOTES : number of negative votes
*/
@@ -29,6 +31,13 @@
include_once("./mysql_connect.php");
/* INPUT */
+$EMAIL = set_value('EMAIL','');
+$PASSWORD = set_value('PASSWORD','');
+
+$result=@mysql_query(sprintf("SELECT user_id,is_valid,privileges FROM user WHERE hash_mail='%s' AND hash_pass='%s'",mysql_real_escape_string($EMAIL),mysql_real_escape_string($PASSWORD)));
+if (mysql_num_rows($result)!=0)
+ {
+
$q = set_value('q','');
$c = set_value('c',0);
@@ -55,15 +64,25 @@
}
/* OUTPUT */
-$sql = "SELECT
+$sql = "SELECT t.*,
+v.IDEA_POSITIVE_VOTES,
+v.IDEA_NEGATIVE_VOTES
+FROM
+(SELECT
thread_id as IDEA_ID,
category as IDEA_CATEOGRY_ID,
title as IDEA_TITLE,
text as IDEA_TEXT,
date as IDEA_DATE,
possibly_name as IDEA_AUTHOR
-FROM thread
-".$WHERE;
+FROM thread ".$WHERE.") as t
+INNER JOIN
+(SELECT
+thread_id as IDEA_ID,
+sum(vote) as IDEA_POSITIVE_VOTES,
+COUNT(*) - sum(vote) as IDEA_NEGATIVE_VOTES
+FROM vote GROUP BY thread_id ) as v
+ON t.IDEA_ID = v.IDEA_ID";
$result = $dbh->query($sql);
@@ -78,6 +97,12 @@
$item = htmlentities($item);
}
});
+
+} else {
+
+ $array = array('SUCCESS' => 'False','MESSAGE' => _('Login Error: email and password do not match'));
+
+}
echo "Ext.util.JSONP.callback(".json_encode(array("data" => $array)).")";
10 SITE/api/login.php
View
@@ -27,19 +27,19 @@
$SERVER_URL = set_value('SERVER_URL','http://refresh.nouvelingenieur.fr');
function authentification($EMAIL,$PASSWORD) {
- if ($PASSWORD=='') {
+ if ($PASSWORD==sha1('')) {
return array('SUCCESS' => 'False','MESSAGE' => _('Email missing'));
}
- if ($EMAIL=='') {
+ if ($EMAIL==sha1('')) {
return array('SUCCESS' => 'False','MESSAGE' => _('Password missing'));
}
- $hash_log=sha1($EMAIL);
- $hash_pass=sha1($PASSWORD);
+ $hash_log=$EMAIL;
+ $hash_pass=$PASSWORD;
$result=@mysql_query(sprintf("SELECT user_id,is_valid,privileges FROM user WHERE hash_mail='%s' AND hash_pass='%s'",mysql_real_escape_string($hash_log),mysql_real_escape_string($hash_pass)));
- if (!$result)
+ if (mysql_num_rows($result)==0)
{
return array('SUCCESS' => 'False','MESSAGE' => _('Email and password do not match'));
} else {
67 SITE/api/set_comment.php
View
@@ -0,0 +1,67 @@
+<?php
+/*
+Set Comment
+Comment an idea.
+
+File
+
+SITE/api/set_comment.php
+
+Input
+
+string EMAIL: sha1 crypted email of the user
+string PASSWORD: sha1 crypted password
+int IDEA_ID
+string COMMENT_TEXT
+Output
+
+*/
+
+
+header('Content-type: application/json');
+
+include_once("./mysql_connect.php");
+
+/* INPUT */
+$EMAIL = set_value('EMAIL','');
+$PASSWORD = set_value('PASSWORD','');
+$IDEA_ID = set_value('IDEA_ID','');
+$COMMENT_TEXT = set_value('COMMENT_TEXT','');
+
+$result=@mysql_query(sprintf("SELECT user_id,is_valid,privileges FROM user WHERE hash_mail='%s' AND hash_pass='%s'",mysql_real_escape_string($EMAIL),mysql_real_escape_string($PASSWORD)));
+if (mysql_num_rows($result)!=0)
+ {
+
+ $text_back=$COMMENT_TEXT;
+ $COMMENT_TEXT=mysql_real_escape_string($COMMENT_TEXT);
+ $rand_prop=mt_rand(0,65535);
+ $hash_prop=sha1($EMAIL.$rand_prop); // Anonymat relatif, car nombre d'adresses mails élèves dans l'école limité...
+
+ $chaine_conf=random_password(40);
+ $chaine_conf_hash=sha1($chaine_conf);
+
+ list($mail,$second_part)=explode("@",$EMAIL,2);
+ $name_print=mysql_real_escape_string($mail);
+
+ @mysql_query("INSERT INTO `comment` (`comment_id`,`thread_id`,`rand_prop`,`hash_prop`,`text`,`date`,`is_valid`,`already_mod`,`possibly_name`,`chaine_moderation`) VALUES (NULL,'$IDEA_ID','$rand_prop','$hash_prop','$COMMENT_TEXT',CURRENT_TIMESTAMP,1,1,'$name_print','$chaine_conf_hash')");
+
+ $array = array('SUCCESS' => 'True','MESSAGE' => _('Your comment was posted successfully'));
+
+} else {
+
+ $array = array('SUCCESS' => 'False','MESSAGE' => _('Login Error: email and password do not match'));
+
+}
+
+array_walk_recursive($array, function(&$item, $key) {
+ if(is_string($item)) {
+ $item = htmlentities($item);
+ }
+});
+
+
+
+
+echo "Ext.util.JSONP.callback(".json_encode(array("data" => $array)).")";
+
+?>
0  SITE/example_malsup.php → SITE/examples/example_malsup.php
View
File renamed without changes
77 SITE/examples/example_unrollcomments.php
View
@@ -0,0 +1,77 @@
+<?php
+
+/*
+ This examples illustrates the unroll comments function
+ sources:
+ - http://www.9lessons.info/2009/12/display-collapsed-comments-like.html
+ - http://jsfiddle.net/clemsos/HFqST/22/
+*/
+
+?>
+
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
+
+<style media="screen" type="text/css">
+.newsformcomment {
+ padding:10px;
+ border:solid 1px #ccc;
+ margin: 30px 5px;
+ width: 300px
+}
+</style>
+
+</head>
+
+
+<body>
+
+<a class='speccom' href="?action=comments&amp;order=0&amp;thread_id=27#a27">
+ <span class="newslinkcomment_roll">2 comments</span>
+ </a>
+
+
+<div class='loader'></div>
+
+<div class="newsformcomment">
+ <p>Here goes the comments</p>
+</div>
+
+
+ <script type="text/javascript">
+ // var BASE URL = 'http://refresh.org';
+ var ACTIONS_URL = '../ajax.php';
+
+ $('.speccom').click(function() {
+
+ var url = ACTIONS_URL + $(this).attr("href");
+
+ // show that is working
+ $('.loader').html('Loading posts from : ' + url);
+
+ // load posts
+ $.ajax(
+ {
+ url: url,
+ type: 'POST',
+ data: { thread_id: "27" },
+ success: function(rep)
+ {
+ var display = '<ul>';
+ var callback = jQuery.parseJSON(rep);
+ $.each(callback.DATA, function(key,comment) {
+ display = display + '<li>' + comment.text + ' - ' + comment.possibly_name + ' - ' + comment.date + '</li>';
+ });
+ display = display + '</ul>';
+ $('.newsformcomment').html(display);
+ }
+ });
+
+ return false;
+
+ });
+ </script>
+
+</body>
+</html>
64 SITE/script_php/pages_secondlevel/actions.php
View
@@ -25,6 +25,7 @@
include_once("tool.php");
include_once("errors.php");
include_once("votes.php");
+include_once("comments.php");
/**
* class for action functions
@@ -34,6 +35,7 @@ class action {
var $result = False; // Result of the action
var $warnings = array(); // list of generated warnings
var $successes = array(); // list of generated successes
+ var $data = array();
// set result
function set_result($result) {
@@ -66,7 +68,7 @@ function echo_successes() {
// display all results in JSON format
function output_result($output) {
- $array = array( 'RESULT' => $this->result, 'WARNINGS' => $this->warnings, 'SUCCESSES' => $this->successes );
+ $array = array( 'RESULT' => $this->result, 'WARNINGS' => $this->warnings, 'SUCCESSES' => $this->successes, 'DATA' => $this->data );
if ($output == 'JSON') {
echo json_encode($array);
@@ -164,5 +166,65 @@ function post($title,$message,$anonymization,$category,$login,$valid=0,$output='
return $action;
}
+
+/**
+ * returns a list of comments for a given thread id
+ *
+ */
+function get_comments($thread_id,$privileges,$login,$output='') {
+
+ $action = new action;
+ $action->set_result(False);
+
+ $escaped_threadid=mysql_real_escape_string($thread_id);
+ $escaped_name=mysql_real_escape_string($login);
+ $result=@mysql_query(sprintf("(SELECT C.comment_id,C.rand_prop,C.hash_prop,C.text,C.date,C.is_valid,C.already_mod,C.possibly_name,
+ SUM(V.vote) AS pro_vote, COUNT(V.vote) AS total_vote,
+ MAX(CAST(SHA1(CONCAT('%s',CAST(V.rand_prop AS CHAR))) AS CHAR)=V.hash_prop) AS my_vote,
+ MAX(CAST(SHA1(CONCAT('%s',CAST(V.rand_prop AS CHAR))) AS CHAR)=V.hash_prop AND V.vote) AS my_provote
+ FROM comment C, vote_comment V
+ WHERE C.thread_id='%s' AND V.comment_id=C.comment_id
+ GROUP BY C.comment_id,C.rand_prop,C.hash_prop,C.text,C.date,C.is_valid,C.already_mod,C.possibly_name)
+ UNION
+ (SELECT C.comment_id,C.rand_prop,C.hash_prop,C.text,C.date,C.is_valid,C.already_mod,C.possibly_name,
+ 0 AS pro_vote, 0 AS total_vote,0 AS my_vote, 0 AS my_provote
+ FROM comment C
+ WHERE C.thread_id='%s' AND C.comment_id<>ALL(SELECT comment_id FROM vote_comment))
+ ORDER BY date ASC",$escaped_name,$escaped_name,$escaped_threadid,$escaped_threadid));
+
+
+
+ if($result)
+ {
+ while($row=mysql_fetch_assoc($result))
+ {
+ $is_proprio=check_property($row["rand_prop"],$row["hash_prop"]);
+ $is_valid=$row["is_valid"];
+
+ if ($is_valid || $is_proprio || $privileges>3)
+ {
+ $comment = array();
+ $comment['comment_id'] = $row["comment_id"]; // comment id
+ $comment['is_proprio'] = check_property($row["rand_prop"],$row["hash_prop"]); // 1 if the current user has posted the comment, else 0
+ $comment['is_valid'] = $row["is_valid"]; // 1 if comment has been accepted, else 0
+ $comment['already_mod'] = $row["already_mod"]; // 1 if comment has already been moderated, else 0
+ $comment['date'] = $row['date']; // date the comment was posted
+ $comment['possibly_name'] = $row['possibly_name']; // name of the author if available
+ $comment['text'] = text_display_prepare(trim($row["text"])); // text of the comment
+ $comment['my_vote'] = $row['my_vote']; // 1 if current user has voted for it, else 0
+ $comment['my_provote'] = $row['my_provote']; // 1 if current user has voted +1, else 0
+ $comment['pro_vote'] = $row['total_vote']; // total of +1 votes
+ $comment['total_vote'] = $row['total_vote']; // total number of votes
+
+ $action->data[$row["comment_id"]] = $comment;
+
+ }
+ }
+ }
+
+ $action->output_result($output);
+ return $action;
+}
+
?>
8 SITE/script_php/pages_secondlevel/comments.php
View
@@ -772,7 +772,7 @@ function display_speccom($unique_mode,$ancre,$thread_id,$nb_comment,$roll) {
}
// display a comment with all its wrapper
-function display_comment($row,$is_logged,$privileges,$is_admin,$unique_mode) {
+function display_comment($row,$is_logged,$privileges,$unique_mode) {
$is_proprio=check_property($row["rand_prop"],$row["hash_prop"]);
$is_valid=$row["is_valid"];
@@ -1047,7 +1047,7 @@ function affichage_comments($thread_id,$moderation_mode=false,$unique_mode=false
{
// afficher les commentaires
- display_comment($row,$is_logged,$privileges,$is_admin,$unique_mode);
+ display_comment($row,$is_logged,$privileges,$unique_mode);
}
}
@@ -1110,6 +1110,10 @@ function affichage_comments($thread_id,$moderation_mode=false,$unique_mode=false
@mysql_free_result($result);
}
}
+ else
+ {
+ echo('<div class="warning">Vous ne disposez pas des droits n&eacute;cessaires</div>');
+ }
}
}

No commit comments for this range

Something went wrong with that request. Please try again.