");
282 | thumbnail.click({
283 | option: this
284 | }, function(event) {
285 | return event.data.option.clicked();
286 | });
287 | thumbnail.append(image);
288 | if (this.opts.show_label) {
289 | thumbnail.append(jQuery("
").html(this.label()));
290 | }
291 | this.node.append(thumbnail);
292 | this.node.append('
');
293 |
294 | return this.node;
295 | };
296 |
297 | return ImagePickerOption;
298 |
299 | })();
300 |
301 | }).call(this);
302 |
--------------------------------------------------------------------------------
/assets/js/jasny-bootstrap.min.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * Jasny Bootstrap v3.1.3 (http://jasny.github.io/bootstrap)
3 | * Copyright 2012-2014 Arnold Daniels
4 | * Licensed under Apache-2.0 (https://github.com/jasny/bootstrap/blob/master/LICENSE)
5 | */
6 | if("undefined"==typeof jQuery)throw new Error("Jasny Bootstrap's JavaScript requires jQuery");+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}void 0===a.support.transition&&(a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one(a.support.transition.end,function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b()}))}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.state=null,this.placement=null,this.options.recalc&&(this.calcClone(),a(window).on("resize",a.proxy(this.recalc,this))),this.options.autohide&&a(document).on("click",a.proxy(this.autohide,this)),this.options.toggle&&this.toggle(),this.options.disablescrolling&&(this.options.disableScrolling=this.options.disablescrolling,delete this.options.disablescrolling)};b.DEFAULTS={toggle:!0,placement:"auto",autohide:!0,recalc:!0,disableScrolling:!0},b.prototype.offset=function(){switch(this.placement){case"left":case"right":return this.$element.outerWidth();case"top":case"bottom":return this.$element.outerHeight()}},b.prototype.calcPlacement=function(){function b(a,b){if("auto"===e.css(b))return a;if("auto"===e.css(a))return b;var c=parseInt(e.css(a),10),d=parseInt(e.css(b),10);return c>d?b:a}if("auto"!==this.options.placement)return void(this.placement=this.options.placement);this.$element.hasClass("in")||this.$element.css("visiblity","hidden !important").addClass("in");var c=a(window).width()/this.$element.width(),d=a(window).height()/this.$element.height(),e=this.$element;this.placement=c>=d?b("left","right"):b("top","bottom"),"hidden !important"===this.$element.css("visibility")&&this.$element.removeClass("in").css("visiblity","")},b.prototype.opposite=function(a){switch(a){case"top":return"bottom";case"left":return"right";case"bottom":return"top";case"right":return"left"}},b.prototype.getCanvasElements=function(){var b=this.options.canvas?a(this.options.canvas):this.$element,c=b.find("*").filter(function(){return"fixed"===a(this).css("position")}).not(this.options.exclude);return b.add(c)},b.prototype.slide=function(b,c,d){if(!a.support.transition){var e={};return e[this.placement]="+="+c,b.animate(e,350,d)}var f=this.placement,g=this.opposite(f);b.each(function(){"auto"!==a(this).css(f)&&a(this).css(f,(parseInt(a(this).css(f),10)||0)+c),"auto"!==a(this).css(g)&&a(this).css(g,(parseInt(a(this).css(g),10)||0)-c)}),this.$element.one(a.support.transition.end,d).emulateTransitionEnd(350)},b.prototype.disableScrolling=function(){var b=a("body").width(),c="padding-"+this.opposite(this.placement);if(void 0===a("body").data("offcanvas-style")&&a("body").data("offcanvas-style",a("body").attr("style")||""),a("body").css("overflow","hidden"),a("body").width()>b){var d=parseInt(a("body").css(c),10)+a("body").width()-b;setTimeout(function(){a("body").css(c,d)},1)}},b.prototype.show=function(){if(!this.state){var b=a.Event("show.bs.offcanvas");if(this.$element.trigger(b),!b.isDefaultPrevented()){this.state="slide-in",this.calcPlacement();var c=this.getCanvasElements(),d=this.placement,e=this.opposite(d),f=this.offset();-1!==c.index(this.$element)&&(a(this.$element).data("offcanvas-style",a(this.$element).attr("style")||""),this.$element.css(d,-1*f),this.$element.css(d)),c.addClass("canvas-sliding").each(function(){void 0===a(this).data("offcanvas-style")&&a(this).data("offcanvas-style",a(this).attr("style")||""),"static"===a(this).css("position")&&a(this).css("position","relative"),"auto"!==a(this).css(d)&&"0px"!==a(this).css(d)||"auto"!==a(this).css(e)&&"0px"!==a(this).css(e)||a(this).css(d,0)}),this.options.disableScrolling&&this.disableScrolling();var g=function(){"slide-in"==this.state&&(this.state="slid",c.removeClass("canvas-sliding").addClass("canvas-slid"),this.$element.trigger("shown.bs.offcanvas"))};setTimeout(a.proxy(function(){this.$element.addClass("in"),this.slide(c,f,a.proxy(g,this))},this),1)}}},b.prototype.hide=function(){if("slid"===this.state){var b=a.Event("hide.bs.offcanvas");if(this.$element.trigger(b),!b.isDefaultPrevented()){this.state="slide-out";var c=a(".canvas-slid"),d=(this.placement,-1*this.offset()),e=function(){"slide-out"==this.state&&(this.state=null,this.placement=null,this.$element.removeClass("in"),c.removeClass("canvas-sliding"),c.add(this.$element).add("body").each(function(){a(this).attr("style",a(this).data("offcanvas-style")).removeData("offcanvas-style")}),this.$element.trigger("hidden.bs.offcanvas"))};c.removeClass("canvas-slid").addClass("canvas-sliding"),setTimeout(a.proxy(function(){this.slide(c,d,a.proxy(e,this))},this),1)}}},b.prototype.toggle=function(){"slide-in"!==this.state&&"slide-out"!==this.state&&this["slid"===this.state?"hide":"show"]()},b.prototype.calcClone=function(){this.$calcClone=this.$element.clone().html("").addClass("offcanvas-clone").removeClass("in").appendTo(a("body"))},b.prototype.recalc=function(){if("none"!==this.$calcClone.css("display")&&("slid"===this.state||"slide-in"===this.state)){this.state=null,this.placement=null;var b=this.getCanvasElements();this.$element.removeClass("in"),b.removeClass("canvas-slid"),b.add(this.$element).add("body").each(function(){a(this).attr("style",a(this).data("offcanvas-style")).removeData("offcanvas-style")})}},b.prototype.autohide=function(b){0===a(b.target).closest(this.$element).length&&this.hide()};var c=a.fn.offcanvas;a.fn.offcanvas=function(c){return this.each(function(){var d=a(this),e=d.data("bs.offcanvas"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c);e||d.data("bs.offcanvas",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.offcanvas.Constructor=b,a.fn.offcanvas.noConflict=function(){return a.fn.offcanvas=c,this},a(document).on("click.bs.offcanvas.data-api","[data-toggle=offcanvas]",function(b){var c,d=a(this),e=d.attr("data-target")||b.preventDefault()||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,""),f=a(e),g=f.data("bs.offcanvas"),h=g?"toggle":d.data();b.stopPropagation(),g?g.toggle():f.offcanvas(h)})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.$element.on("click.bs.rowlink","td:not(.rowlink-skip)",a.proxy(this.click,this))};b.DEFAULTS={target:"a"},b.prototype.click=function(b){var c=a(b.currentTarget).closest("tr").find(this.options.target)[0];if(a(b.target)[0]!==c)if(b.preventDefault(),c.click)c.click();else if(document.createEvent){var d=document.createEvent("MouseEvents");d.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),c.dispatchEvent(d)}};var c=a.fn.rowlink;a.fn.rowlink=function(c){return this.each(function(){var d=a(this),e=d.data("bs.rowlink");e||d.data("bs.rowlink",e=new b(this,c))})},a.fn.rowlink.Constructor=b,a.fn.rowlink.noConflict=function(){return a.fn.rowlink=c,this},a(document).on("click.bs.rowlink.data-api",'[data-link="row"]',function(b){if(0===a(b.target).closest(".rowlink-skip").length){var c=a(this);c.data("bs.rowlink")||(c.rowlink(c.data()),a(b.target).trigger("click.bs.rowlink"))}})}(window.jQuery),+function(a){"use strict";var b=void 0!==window.orientation,c=navigator.userAgent.toLowerCase().indexOf("android")>-1,d="Microsoft Internet Explorer"==window.navigator.appName,e=function(b,d){c||(this.$element=a(b),this.options=a.extend({},e.DEFAULTS,d),this.mask=String(this.options.mask),this.init(),this.listen(),this.checkVal())};e.DEFAULTS={mask:"",placeholder:"_",definitions:{9:"[0-9]",a:"[A-Za-z]",w:"[A-Za-z0-9]","*":"."}},e.prototype.init=function(){var b=this.options.definitions,c=this.mask.length;this.tests=[],this.partialPosition=this.mask.length,this.firstNonMaskPos=null,a.each(this.mask.split(""),a.proxy(function(a,d){"?"==d?(c--,this.partialPosition=a):b[d]?(this.tests.push(new RegExp(b[d])),null===this.firstNonMaskPos&&(this.firstNonMaskPos=this.tests.length-1)):this.tests.push(null)},this)),this.buffer=a.map(this.mask.split(""),a.proxy(function(a){return"?"!=a?b[a]?this.options.placeholder:a:void 0},this)),this.focusText=this.$element.val(),this.$element.data("rawMaskFn",a.proxy(function(){return a.map(this.buffer,function(a,b){return this.tests[b]&&a!=this.options.placeholder?a:null}).join("")},this))},e.prototype.listen=function(){if(!this.$element.attr("readonly")){var b=(d?"paste":"input")+".mask";this.$element.on("unmask.bs.inputmask",a.proxy(this.unmask,this)).on("focus.bs.inputmask",a.proxy(this.focusEvent,this)).on("blur.bs.inputmask",a.proxy(this.blurEvent,this)).on("keydown.bs.inputmask",a.proxy(this.keydownEvent,this)).on("keypress.bs.inputmask",a.proxy(this.keypressEvent,this)).on(b,a.proxy(this.pasteEvent,this))}},e.prototype.caret=function(a,b){if(0!==this.$element.length){if("number"==typeof a)return b="number"==typeof b?b:a,this.$element.each(function(){if(this.setSelectionRange)this.setSelectionRange(a,b);else if(this.createTextRange){var c=this.createTextRange();c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select()}});if(this.$element[0].setSelectionRange)a=this.$element[0].selectionStart,b=this.$element[0].selectionEnd;else if(document.selection&&document.selection.createRange){var c=document.selection.createRange();a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length}return{begin:a,end:b}}},e.prototype.seekNext=function(a){for(var b=this.mask.length;++a<=b&&!this.tests[a];);return a},e.prototype.seekPrev=function(a){for(;--a>=0&&!this.tests[a];);return a},e.prototype.shiftL=function(a,b){var c=this.mask.length;if(!(0>a)){for(var d=a,e=this.seekNext(b);c>d;d++)if(this.tests[d]){if(!(c>e&&this.tests[d].test(this.buffer[e])))break;this.buffer[d]=this.buffer[e],this.buffer[e]=this.options.placeholder,e=this.seekNext(e)}this.writeBuffer(),this.caret(Math.max(this.firstNonMaskPos,a))}},e.prototype.shiftR=function(a){for(var b=this.mask.length,c=a,d=this.options.placeholder;b>c;c++)if(this.tests[c]){var e=this.seekNext(c),f=this.buffer[c];if(this.buffer[c]=d,!(b>e&&this.tests[e].test(f)))break;d=f}},e.prototype.unmask=function(){this.$element.unbind(".mask").removeData("inputmask")},e.prototype.focusEvent=function(){this.focusText=this.$element.val();var a=this.mask.length,b=this.checkVal();this.writeBuffer();var c=this,d=function(){b==a?c.caret(0,b):c.caret(b)};d(),setTimeout(d,50)},e.prototype.blurEvent=function(){this.checkVal(),this.$element.val()!==this.focusText&&this.$element.trigger("change")},e.prototype.keydownEvent=function(a){var c=a.which;if(8==c||46==c||b&&127==c){var d=this.caret(),e=d.begin,f=d.end;return f-e===0&&(e=46!=c?this.seekPrev(e):f=this.seekNext(e-1),f=46==c?this.seekNext(f):f),this.clearBuffer(e,f),this.shiftL(e,f-1),!1}return 27==c?(this.$element.val(this.focusText),this.caret(0,this.checkVal()),!1):void 0},e.prototype.keypressEvent=function(a){var b=this.mask.length,c=a.which,d=this.caret();if(a.ctrlKey||a.altKey||a.metaKey||32>c)return!0;if(c){d.end-d.begin!==0&&(this.clearBuffer(d.begin,d.end),this.shiftL(d.begin,d.end-1));var e=this.seekNext(d.begin-1);if(b>e){var f=String.fromCharCode(c);if(this.tests[e].test(f)){this.shiftR(e),this.buffer[e]=f,this.writeBuffer();var g=this.seekNext(e);this.caret(g)}}return!1}},e.prototype.pasteEvent=function(){var a=this;setTimeout(function(){a.caret(a.checkVal(!0))},0)},e.prototype.clearBuffer=function(a,b){for(var c=this.mask.length,d=a;b>d&&c>d;d++)this.tests[d]&&(this.buffer[d]=this.options.placeholder)},e.prototype.writeBuffer=function(){return this.$element.val(this.buffer.join("")).val()},e.prototype.checkVal=function(a){for(var b=this.mask.length,c=this.$element.val(),d=-1,e=0,f=0;b>e;e++)if(this.tests[e]){for(this.buffer[e]=this.options.placeholder;f++
c.length)break}else this.buffer[e]==c.charAt(f)&&e!=this.partialPosition&&(f++,d=e);return!a&&d+1=this.partialPosition)&&(this.writeBuffer(),a||this.$element.val(this.$element.val().substring(0,d+1))),this.partialPosition?e:this.firstNonMaskPos};var f=a.fn.inputmask;a.fn.inputmask=function(b){return this.each(function(){var c=a(this),d=c.data("bs.inputmask");d||c.data("bs.inputmask",d=new e(this,b))})},a.fn.inputmask.Constructor=e,a.fn.inputmask.noConflict=function(){return a.fn.inputmask=f,this},a(document).on("focus.bs.inputmask.data-api","[data-mask]",function(){var b=a(this);b.data("bs.inputmask")||b.inputmask(b.data())})}(window.jQuery),+function(a){"use strict";var b="Microsoft Internet Explorer"==window.navigator.appName,c=function(b,c){if(this.$element=a(b),this.$input=this.$element.find(":file"),0!==this.$input.length){this.name=this.$input.attr("name")||c.name,this.$hidden=this.$element.find('input[type=hidden][name="'+this.name+'"]'),0===this.$hidden.length&&(this.$hidden=a(' ').insertBefore(this.$input)),this.$preview=this.$element.find(".fileinput-preview");var d=this.$preview.css("height");"inline"!==this.$preview.css("display")&&"0px"!==d&&"none"!==d&&this.$preview.css("line-height",d),this.original={exists:this.$element.hasClass("fileinput-exists"),preview:this.$preview.html(),hiddenVal:this.$hidden.val()},this.listen()}};c.prototype.listen=function(){this.$input.on("change.bs.fileinput",a.proxy(this.change,this)),a(this.$input[0].form).on("reset.bs.fileinput",a.proxy(this.reset,this)),this.$element.find('[data-trigger="fileinput"]').on("click.bs.fileinput",a.proxy(this.trigger,this)),this.$element.find('[data-dismiss="fileinput"]').on("click.bs.fileinput",a.proxy(this.clear,this))},c.prototype.change=function(b){var c=void 0===b.target.files?b.target&&b.target.value?[{name:b.target.value.replace(/^.+\\/,"")}]:[]:b.target.files;if(b.stopPropagation(),0===c.length)return void this.clear();this.$hidden.val(""),this.$hidden.attr("name",""),this.$input.attr("name",this.name);var d=c[0];if(this.$preview.length>0&&("undefined"!=typeof d.type?d.type.match(/^image\/(gif|png|jpeg)$/):d.name.match(/\.(gif|png|jpe?g)$/i))&&"undefined"!=typeof FileReader){var e=new FileReader,f=this.$preview,g=this.$element;e.onload=function(b){var e=a(" ");e[0].src=b.target.result,c[0].result=b.target.result,g.find(".fileinput-filename").text(d.name),"none"!=f.css("max-height")&&e.css("max-height",parseInt(f.css("max-height"),10)-parseInt(f.css("padding-top"),10)-parseInt(f.css("padding-bottom"),10)-parseInt(f.css("border-top"),10)-parseInt(f.css("border-bottom"),10)),f.html(e),g.addClass("fileinput-exists").removeClass("fileinput-new"),g.trigger("change.bs.fileinput",c)},e.readAsDataURL(d)}else this.$element.find(".fileinput-filename").text(d.name),this.$preview.text(d.name),this.$element.addClass("fileinput-exists").removeClass("fileinput-new"),this.$element.trigger("change.bs.fileinput")},c.prototype.clear=function(a){if(a&&a.preventDefault(),this.$hidden.val(""),this.$hidden.attr("name",this.name),this.$input.attr("name",""),b){var c=this.$input.clone(!0);this.$input.after(c),this.$input.remove(),this.$input=c}else this.$input.val("");this.$preview.html(""),this.$element.find(".fileinput-filename").text(""),this.$element.addClass("fileinput-new").removeClass("fileinput-exists"),void 0!==a&&(this.$input.trigger("change"),this.$element.trigger("clear.bs.fileinput"))},c.prototype.reset=function(){this.clear(),this.$hidden.val(this.original.hiddenVal),this.$preview.html(this.original.preview),this.$element.find(".fileinput-filename").text(""),this.original.exists?this.$element.addClass("fileinput-exists").removeClass("fileinput-new"):this.$element.addClass("fileinput-new").removeClass("fileinput-exists"),this.$element.trigger("reset.bs.fileinput")},c.prototype.trigger=function(a){this.$input.trigger("click"),a.preventDefault()};var d=a.fn.fileinput;a.fn.fileinput=function(b){return this.each(function(){var d=a(this),e=d.data("bs.fileinput");e||d.data("bs.fileinput",e=new c(this,b)),"string"==typeof b&&e[b]()})},a.fn.fileinput.Constructor=c,a.fn.fileinput.noConflict=function(){return a.fn.fileinput=d,this},a(document).on("click.fileinput.data-api",'[data-provides="fileinput"]',function(b){var c=a(this);if(!c.data("bs.fileinput")){c.fileinput(c.data());var d=a(b.target).closest('[data-dismiss="fileinput"],[data-trigger="fileinput"]');d.length>0&&(b.preventDefault(),d.trigger("click.bs.fileinput"))}})}(window.jQuery);
--------------------------------------------------------------------------------
/assets/js/main.js:
--------------------------------------------------------------------------------
1 | var checkConfirm = 0;
2 |
3 | $('.confirm').on('click', function() {
4 | checkConfirm = 1;
5 | });
6 |
7 | $('form').on('submit', function() {
8 | if (checkConfirm == 1) {
9 | checkConfirm = 0;
10 | return confirm('Are you sure you want to proceed?');
11 | }
12 | });
13 |
14 | $('.confirmLink').on('click', function(e) {
15 | var check = confirm('Are you sure you want to proceed?');
16 | if (check){ } else {
17 | e.stopPropagation();
18 | e.preventDefault();
19 | }
20 | });
--------------------------------------------------------------------------------
/assets/js/mininotification.js:
--------------------------------------------------------------------------------
1 |
2 | $(function() {
3 | $.miniNotification = function(element, options) {
4 | var appendCloseButton, getHiddenCssProps, getVisibleCssProps, setState, state, wrapInnerElement,
5 | _this = this;
6 | this.defaults = {
7 | position: 'top',
8 | show: true,
9 | effect: 'slide',
10 | opacity: 0.95,
11 | time: 4000,
12 | showSpeed: 600,
13 | hideSpeed: 450,
14 | showEasing: '',
15 | hideEasing: '',
16 | innerDivClass: 'inner',
17 | closeButton: false,
18 | closeButtonText: 'close',
19 | closeButtonClass: 'close',
20 | hideOnClick: true,
21 | onLoad: function() {},
22 | onVisible: function() {},
23 | onHide: function() {},
24 | onHidden: function() {}
25 | };
26 | state = '';
27 | this.settings = {};
28 | this.$element = $(element);
29 | setState = function(_state) {
30 | return state = _state;
31 | };
32 | getHiddenCssProps = function() {
33 | var css, position;
34 | position = (_this.getSetting('effect')) === 'slide' ? 0 - _this.$element.outerHeight() : 0;
35 | css = {};
36 | if ((_this.getSetting('position')) === 'bottom') {
37 | css['bottom'] = position;
38 | } else {
39 | css['top'] = position;
40 | }
41 | if ((_this.getSetting('effect')) === 'fade') {
42 | css['opacity'] = 0;
43 | }
44 | return css;
45 | };
46 | getVisibleCssProps = function() {
47 | var css;
48 | css = {
49 | 'opacity': _this.getSetting('opacity')
50 | };
51 | if ((_this.getSetting('position')) === 'bottom') {
52 | css['bottom'] = 0;
53 | } else {
54 | css['top'] = 0;
55 | }
56 | return css;
57 | };
58 | wrapInnerElement = function() {
59 | _this.$elementInner = $('
', {
60 | 'class': _this.getSetting('innerDivClass')
61 | });
62 | return _this.$element.wrapInner(_this.$elementInner);
63 | };
64 | appendCloseButton = function() {
65 | var $closeButton;
66 | $closeButton = $(' ', {
67 | 'class': _this.getSetting('closeButtonClass'),
68 | 'html': _this.getSetting('closeButtonText')
69 | });
70 | _this.$element.children().append($closeButton);
71 | return $closeButton.bind('click', function() {
72 | return _this.hide();
73 | });
74 | };
75 | this.getState = function() {
76 | return state;
77 | };
78 | this.getSetting = function(settingKey) {
79 | return this.settings[settingKey];
80 | };
81 | this.callSettingFunction = function(functionName) {
82 | return this.settings[functionName](element);
83 | };
84 | this.init = function() {
85 | var _this = this;
86 | setState('hidden');
87 | this.settings = $.extend({}, this.defaults, options);
88 | if (this.$element.length) {
89 | wrapInnerElement();
90 | if (this.getSetting('closeButton')) {
91 | appendCloseButton();
92 | }
93 | this.$element.css(getHiddenCssProps()).css({
94 | display: 'inline'
95 | });
96 | if (this.getSetting('show')) {
97 | this.show();
98 | }
99 | if (this.getSetting('hideOnClick')) {
100 | return this.$element.bind('click', function() {
101 | if (_this.getState() !== 'hiding') {
102 | return _this.hide();
103 | }
104 | });
105 | }
106 | }
107 | };
108 | this.show = function() {
109 | var _this = this;
110 | if (this.getState() !== 'showing' && this.getState() !== 'visible') {
111 | setState('showing');
112 | this.callSettingFunction('onLoad');
113 | return this.$element.animate(getVisibleCssProps(), this.getSetting('showSpeed'), this.getSetting('showEasing'), function() {
114 | setState('visible');
115 | _this.callSettingFunction('onVisible');
116 | return setTimeout((function() {
117 | return _this.hide();
118 | }), _this.settings.time);
119 | });
120 | }
121 | };
122 | this.hide = function() {
123 | var _this = this;
124 | if (this.getState() !== 'hiding' && this.getState() !== 'hidden') {
125 | setState('hiding');
126 | this.callSettingFunction('onHide');
127 | return this.$element.animate(getHiddenCssProps(), this.getSetting('hideSpeed'), this.getSetting('hideEasing'), function() {
128 | setState('hidden');
129 | return _this.callSettingFunction('onHidden');
130 | });
131 | }
132 | };
133 | this.init();
134 | return this;
135 | };
136 | return $.fn.miniNotification = function(options) {
137 | return this.each(function() {
138 | var plugin;
139 | plugin = ($(this)).data('miniNotification');
140 | if (plugin === void 0) {
141 | plugin = new $.miniNotification(this, options);
142 | return ($(this)).data('miniNotification', plugin);
143 | } else {
144 | return plugin.show();
145 | }
146 | });
147 | };
148 | });
149 |
--------------------------------------------------------------------------------
/config.php:
--------------------------------------------------------------------------------
1 | parse($ua);
35 |
36 | // Add entry into track
37 |
38 |
39 |
40 | $_REQUEST['track_time'] = time();
41 | $_REQUEST['ip'] = $_SERVER['REMOTE_ADDR'];
42 |
43 | sql('track');
44 |
45 |
46 | // Add entry into user
47 |
48 | sql('user');
49 |
50 | exit;
51 | }
52 |
53 | function sql($table) {
54 |
55 | global $dbh;
56 | global $database;
57 |
58 | $data = array();
59 |
60 | foreach ($database[$table] as $field => $type) {
61 | if (!empty($_REQUEST[$field])) {
62 | $data[$field] = $_REQUEST[$field];
63 | } else {
64 | if (!empty($type[1])) {
65 | returnError("$field is required");
66 | exit;
67 | }
68 | }
69 | }
70 |
71 |
72 | $sql = 'insert into '.$table.' (';
73 |
74 | foreach ($data as $name => $value) {
75 | $sql .= '`'.$name.'`,';
76 | }
77 |
78 | $sql = substr($sql,0,-1);
79 |
80 | $sql .= ') values (';
81 |
82 | foreach ($data as $name => $value) {
83 | $sql .= ':'.$name.',';
84 | }
85 |
86 | $sql = substr($sql,0,-1);
87 |
88 | $sql .= ')';
89 |
90 | $sth = $dbh->prepare($sql);
91 | $sth->execute($data);
92 | echo $sql;
93 |
94 | }
95 |
96 | function get() {
97 | global $path;
98 | $client = $path[2];
99 | $site = $path[3];
100 | $name = $path[4];
101 |
102 | if ($name == 'ref') {
103 |
104 | $sth = $dbh->prepare("select ref from track where client = :client and site = :site order by id asc limit 1");
105 | $sth->execute($data);
106 | $ref = $statement->fetch();
107 |
108 | echo $ref;
109 |
110 | }
111 |
112 | exit;
113 | }
114 |
115 | function returnImage() {
116 |
117 | header("Content-type: image/gif");
118 | header("Content-Length: 42");
119 | header("Cache-Control: private, no-cache, no-cache=Set-Cookie, proxy-revalidate");
120 | header("Expires: Wed, 11 Jan 2000 12:59:00 GMT");
121 | header("Last-Modified: Wed, 11 Jan 2006 12:59:00 GMT");
122 | header("Pragma: no-cache");
123 |
124 | echo sprintf(
125 | '%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%',
126 | 71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59
127 | );
128 |
129 |
130 | ob_flush();
131 | flush();
132 | ob_end_flush();
133 | }
134 |
135 | function returnJSON() {
136 | $received = true;
137 | // print(json_encode($received));
138 | // ob_flush();
139 | // flush();
140 | // ob_end_flush();
141 | }
142 |
143 | function returnError($error) {
144 | echo(json_encode(array("error" => $error)));
145 |
146 | }
--------------------------------------------------------------------------------
/controllers/connect.php:
--------------------------------------------------------------------------------
1 | prepare("select * from accounts where companyid = ? and active = 1");
10 | $query->execute(array($_SESSION['user']['companyid']));
11 | $accounts = $query->fetchAll();
12 |
13 | foreach ($accounts as $no => $account) {
14 |
15 | if ($account['type'] == 'facebook') {
16 | $image = 'https://graph.facebook.com/'.$account['data1'].'/picture';
17 | $accounts[$no]['image'] = $image;
18 | }
19 |
20 | if ($account['type'] == 'twitter') {
21 | $image = $account['data4'];
22 | $accounts[$no]['image'] = $image;
23 | }
24 |
25 | }
26 |
27 | $template->set('accounts',$accounts);
28 | }
29 |
30 | function facebook() {
31 |
32 | global $template;
33 |
34 | $facebook = new Facebook(array('appId' => FB_APPID,'secret' => FB_APPSECRET));
35 | $user = $facebook->getUser();
36 |
37 | if ($user) {
38 | try {
39 |
40 | $pages = $facebook->api('/me/accounts');
41 | $template->set('pages',$pages);
42 |
43 | $permissions = $facebook->api("/me/permissions");
44 |
45 | $publish_actions = 0;
46 | $manage_pages = 0;
47 |
48 | foreach ($permissions['data'] as $permission) {
49 | if ($permission['permission'] == 'publish_actions') {
50 | $publish_actions = 1;
51 | }
52 | if ($permission['permission'] == 'manage_pages') {
53 | $manage_pages = 1;
54 | }
55 | }
56 |
57 | if ($publish_actions == 0 || $manage_pages == 0) {
58 | throw new Exception("Oops");
59 | }
60 |
61 |
62 | } catch (Exception $e) {
63 |
64 | $url = $facebook->getLoginUrl(array("scope" => "publish_actions,manage_pages"));
65 | header("Location: ".$url);
66 | exit;
67 | }
68 |
69 | } else {
70 | $url = $facebook->getLoginUrl(array("scope" => "publish_actions,manage_pages"));
71 | header("Location: ".$url);
72 | exit;
73 | }
74 |
75 | }
76 |
77 | function twitter() {
78 | global $template;
79 |
80 | $twitter = new TwitterOAuth(TWITTER_APIKEY, TWITTER_APISECRET);
81 | $request_token = $twitter->getRequestToken(BASE_URL."connect/twitter-callback");
82 |
83 | $_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
84 | $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
85 |
86 | switch ($twitter->http_code) {
87 | case 200:
88 | /* Build authorize URL and redirect user to Twitter. */
89 | $url = $twitter->getAuthorizeURL($token);
90 | header('Location: ' . $url);
91 | exit;
92 | default:
93 | $_SESSION['notification']['type'] = 'error';
94 | $_SESSION['notification']['message'] = 'Unable to connect to Twitter. Please try again later.';
95 | header("Location: ".BASE_URL."connect");
96 | exit;
97 | }
98 |
99 | }
100 |
101 |
102 | function twittercallback() {
103 |
104 | $twitter = new TwitterOAuth(TWITTER_APIKEY, TWITTER_APISECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
105 | $token = $twitter->getAccessToken($_REQUEST['oauth_verifier']);
106 |
107 | $account = $twitter->get('account/verify_credentials');
108 |
109 | header('Location: '.BASE_URL.'connect/add/twitter/'.base64_encode($token['user_id']).'/'.base64_encode($token['screen_name']).'/'.base64_encode($token['oauth_token']).'/'.base64_encode($token['oauth_token_secret']).'/'.base64_encode($account->profile_image_url_https));
110 | exit;
111 |
112 |
113 | }
114 |
115 | function add() {
116 | global $dbh;
117 | global $path;
118 |
119 | $type = $path[2];
120 |
121 | if ($type == 'facebook') {
122 |
123 | $query = $dbh->prepare("select * from accounts where companyid = ? and type = ? and data1 = ?");
124 | $query->execute(array($_SESSION['user']['companyid'],'facebook',base64_decode($path[3])));
125 | $existing = $query->fetch();
126 |
127 | if ($existing['id'] > 0) {
128 | $sql = "update accounts set active = ?, name = ?, data2 = ? where companyid = ? and type = ? and data1 = ?";
129 | $query = $dbh->prepare($sql);
130 | $query->execute(array(1,base64_decode($path[4]),base64_decode($path[5]),$_SESSION['user']['companyid'],'facebook',base64_decode($path[3])));
131 | } else {
132 | $sql = "insert into accounts (companyid,type,name,data1,data2,active) VALUES (?,?,?,?,?,?)";
133 | $query = $dbh->prepare($sql);
134 | $query->execute(array($_SESSION['user']['companyid'],'facebook',base64_decode($path[4]),base64_decode($path[3]),base64_decode($path[5]),1));
135 | }
136 | }
137 |
138 | if ($type == 'twitter') {
139 |
140 | $query = $dbh->prepare("select * from accounts where companyid = ? and type = ? and data1 = ?");
141 | $query->execute(array($_SESSION['user']['companyid'],'twitter',base64_decode($path[3])));
142 | $existing = $query->fetch();
143 |
144 | if ($existing['id'] > 0) {
145 | $sql = "update accounts set active = ?, name = ?, data2 = ?, data3 = ?, data4 = ? where companyid = ? and type = ? and data1 = ?";
146 | $query = $dbh->prepare($sql);
147 | $query->execute(array(1,base64_decode($path[4]),base64_decode($path[5]),base64_decode($path[6]),base64_decode($path[7]),$_SESSION['user']['companyid'],'twitter',base64_decode($path[3])));
148 | } else {
149 |
150 | $sql = "insert into accounts (companyid,type,name,data1,data2,data3,data4,active) VALUES (?,?,?,?,?,?,?,?)";
151 | $query = $dbh->prepare($sql);
152 | $query->execute(array($_SESSION['user']['companyid'],'twitter',base64_decode($path[4]),base64_decode($path[3]),base64_decode($path[5]),base64_decode($path[6]),base64_decode($path[7]),1));
153 |
154 | }
155 |
156 | }
157 |
158 | $_SESSION['notification']['type'] = 'success';
159 | $_SESSION['notification']['message'] = 'Account has been successfully added.';
160 |
161 | header("Location: ".BASE_URL."connect");
162 | exit;
163 |
164 | }
165 |
166 | function remove() {
167 | global $dbh;
168 | global $path;
169 |
170 | $accountId = intval($path[2]);
171 |
172 | $query = $dbh->prepare("update accounts set active = ? where companyid = ? and id = ?");
173 | $query->execute(array(0,$_SESSION['user']['companyid'],$accountId));
174 |
175 | $_SESSION['notification']['type'] = 'success';
176 | $_SESSION['notification']['message'] = 'Account has been successfully removed.';
177 |
178 | header("Location: ".BASE_URL."connect");
179 | exit;
180 | }
--------------------------------------------------------------------------------
/controllers/cron.php:
--------------------------------------------------------------------------------
1 | prepare("delete from suggestions");
8 | $query->execute();
9 |
10 |
11 | $twitter = new TwitterOAuth(TWITTER_APIKEY, TWITTER_APISECRET, TWITTER_TOKEN, TWITTER_SECRET);
12 |
13 | foreach ($suggestionLists as $list) {
14 |
15 | $tweets = $twitter->get('lists/statuses',array('slug'=>$list,'owner_screen_name'=>TWITTER_USERNAME,'count'=>'10'));
16 |
17 | foreach ($tweets as $tweet) {
18 | $id = $tweet->id_str;
19 | $text = $tweet->text;
20 | $via = $tweet->user->screen_name;
21 |
22 | if (!empty($tweet->entities->media[0]->media_url_https)) {
23 | $media = $tweet->entities->media[0]->media_url_https;
24 | $text = preg_replace('/(.*)\shttp:\/\/t\.co(.*?)$/', '$1', $text); // Remove last link
25 | } else {
26 | $media = '';
27 | }
28 |
29 | $r = array();
30 | $r[0] = $tweet->in_reply_to_status_id;
31 | $r[1] = $tweet->in_reply_to_status_id_str;
32 | $r[2] = $tweet->in_reply_to_user_id;
33 | $r[3] = $tweet->in_reply_to_user_id_str;
34 | $r[4] = $tweet->in_reply_to_screen_name;
35 |
36 | if (empty($r[0]) && empty($r[1]) && empty($r[2]) && empty($r[3]) && empty($r[4])) {
37 | $query = $dbh->prepare("insert ignore into suggestions (id,text,screen_name,media,list,record_created) values (?,?,?,?,?,?)");
38 | $query->execute(array($id,$text,$via,$media,$list,time()));
39 |
40 | }
41 | }
42 |
43 | }
44 |
45 | exit;
46 | }
47 |
48 | function post() {
49 | global $dbh;
50 |
51 | $query = $dbh->prepare("select accounts_queue.*, accounts.type, accounts.data1, accounts.data2, accounts.data3 from accounts_queue join accounts on accounts_queue.accountid = accounts.id where scheduled_time <= ? and (sent_time is null or sent_time = '') and accounts.active = 1 limit 10");
52 | $query->execute(array(time()));
53 | $posts = $query->fetchAll();
54 |
55 | foreach ($posts as $post) {
56 |
57 | $error = '';
58 |
59 | if ($post['type'] == 'facebook') {
60 |
61 | try {
62 |
63 | $params = array(
64 | "access_token" => $post['data2'],
65 | "message" => $post['message']
66 | );
67 |
68 | $facebook = new Facebook(array('appId' => FB_APPID,'secret' => FB_APPSECRET));
69 |
70 | if (!empty($post['image'])) {
71 | $params['url'] = $post['image'];
72 | $ret = $facebook->api('/'.$post['data1'].'/photos', 'POST', $params);
73 | } else {
74 |
75 | unset($matches);
76 |
77 | preg_match_all('!(http|ftp|scp)(s)?:\/\/[a-zA-Z0-9.?&_/]+!',$post['message'],$matches);
78 |
79 | $link = '';
80 |
81 | if (!empty($matches[0][0])) {
82 | $link = $matches[0][0];
83 | $params['link'] = $link;
84 | }
85 |
86 | $ret = $facebook->api('/'.$post['data1'].'/feed', 'POST', $params);
87 | }
88 |
89 | } catch(Exception $e) {
90 | $error = print_r($e,true);
91 | }
92 |
93 | }
94 |
95 | if ($post['type'] == 'twitter') {
96 | if (empty($post['image'])) {
97 | $twitter = new TwitterOAuth(TWITTER_APIKEY, TWITTER_APISECRET, $post['data2'], $post['data3']);
98 | $account = $twitter->get('account/verify_credentials');
99 | $status = $twitter->post('statuses/update', array('status' => $post['message']));
100 |
101 | if (!empty($status->errors[0]->message)) {
102 | $error = $status->errors[0]->message;
103 | }
104 |
105 | } else {
106 | $file = $post['image'];
107 |
108 | $params = array(
109 | 'media[]' => file_get_contents($file)
110 | );
111 |
112 | if (null !== $post['message']) {
113 | $params['status'] = $post['message'];
114 | }
115 |
116 | $tmhOAuth = new \tmhOAuth(array(
117 | 'user_agent' => 'SocialTurn',
118 | 'consumer_key' => TWITTER_APIKEY,
119 | 'consumer_secret' => TWITTER_APISECRET,
120 | 'token' => $post['data2'],
121 | 'secret' => $post['data3'],
122 | ));
123 |
124 | $response = $tmhOAuth->user_request(array(
125 | 'method' => 'POST',
126 | 'url' => $tmhOAuth->url("1.1/statuses/update_with_media"),
127 | 'params' => $params,
128 | 'multipart' => true
129 | ));
130 |
131 | if ($response == 200 && isset($tmhOAuth->response['response'])){
132 | $json = json_decode($tmhOAuth->response['response']);
133 | $lastTweetId = $json->id_str;
134 | }
135 |
136 | if (isset($tmhOAuth->response['response'])) {
137 | $json = json_decode($tmhOAuth->response['response']);
138 | if (isset($json->errors)) {
139 | $error = array();
140 | foreach ($json->errors as $err) {
141 | $error[] = '['.$err->code.'] '.$err->message;
142 | }
143 |
144 | $error = $err->message;
145 | }
146 | }
147 |
148 | }
149 | }
150 |
151 |
152 | $update = $dbh->prepare("update accounts_queue set sent_time = ?, error = ? where id = ?");
153 | $update->execute(array(time(),$error,$post['id']));
154 |
155 |
156 | }
157 |
158 | exit;
159 | }
160 |
--------------------------------------------------------------------------------
/controllers/helpers.php:
--------------------------------------------------------------------------------
1 | set('user',$user);
11 | return $helper->render();
12 | }
--------------------------------------------------------------------------------
/controllers/home.php:
--------------------------------------------------------------------------------
1 | set('noextra','1');
6 | }
7 |
8 | function permissions() {
9 | global $template;
10 | $template->set('noextra','1');
11 | }
12 |
13 | function noaccounts() {
14 | global $template;
15 | $template->set('noextra','1');
16 | }
--------------------------------------------------------------------------------
/controllers/social.php:
--------------------------------------------------------------------------------
1 | prepare("select accounts.* from accounts join users_accounts on accounts.id = users_accounts.accountid where users_accounts.companyid = ? and users_accounts.userid = ? and accounts.active = 1");
21 | $query->execute(array($_SESSION['user']['companyid'],$_SESSION['user']['loggedin']));
22 | $accounts = $query->fetchAll();
23 | } else {
24 | $query = $dbh->prepare("select * from accounts where companyid = ? and accounts.active = 1");
25 | $query->execute(array($_SESSION['user']['companyid']));
26 | $accounts = $query->fetchAll();
27 | }
28 |
29 | $currentpermission = 0;
30 |
31 | foreach ($accounts as $no => $account) {
32 |
33 | // If no account selected, redirect to first account
34 | if (empty($current)) {
35 | header("Location: ".BASE_URL."social/queue/".$account['id']);
36 | exit;
37 | }
38 |
39 | if ($account['type'] == 'facebook') {
40 | $image = 'https://graph.facebook.com/'.$account['data1'].'/picture';
41 | $accounts[$no]['image'] = $image;
42 | }
43 |
44 | if ($account['type'] == 'twitter') {
45 | $image = $account['data4'];
46 | $accounts[$no]['image'] = $image;
47 | }
48 |
49 | if ($current == $account['id']) {
50 | $accounts[$no]['current'] = 1;
51 | $currentpermission = 1;
52 | }
53 | }
54 |
55 | // If no account found, give a friendly error message
56 | if (empty($current)) {
57 | if ($_SESSION['user']['type'] == 1) {
58 | header("Location: ".BASE_URL."connect");
59 | exit;
60 | } else {
61 | header("Location: ".BASE_URL."oops/no-accounts");
62 | exit;
63 | }
64 | }
65 |
66 | // If no permission
67 | if (empty($currentpermission)) {
68 | header("Location: ".BASE_URL."oops/permissions");
69 | exit;
70 | }
71 |
72 | $template->set('current',$current);
73 | $template->set('accounts',$accounts);
74 |
75 | }
76 |
77 | function requeue($accountId) {
78 |
79 | global $dbh;
80 |
81 | $query = $dbh->prepare("select timezone from accounts_schedule where accountid = ? order by record_created desc limit 1");
82 | $query->execute(array($accountId));
83 | $timezone = $query->fetch();
84 |
85 | if (!empty($timezone['timezone'])) {
86 | $timezone = $timezone['timezone'];
87 | } else {
88 | $timezone = 0;
89 | }
90 |
91 | $query = $dbh->prepare("select * from accounts_schedule where accountid = ?");
92 | $query->execute(array($accountId));
93 | $schedule = $query->fetchAll();
94 |
95 | if (!empty($schedule)) {
96 |
97 | $days = array('','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
98 |
99 | $postTiming = array();
100 |
101 | foreach ($schedule as $s) {
102 | $day = strtotime($days[$s['day']].' this week');
103 | $day += ($s['time']*36);
104 |
105 | $day -= ($timezone*3600);
106 |
107 | if ($day >= time()) {
108 | $postTiming[] = $day;
109 | }
110 | }
111 |
112 | $postTimingWeek2 = array();
113 |
114 | foreach ($schedule as $s) {
115 | $day = strtotime($days[$s['day']].' next week');
116 | $day += ($s['time']*36);
117 |
118 | $day -= ($timezone*3600);
119 |
120 | if ($day >= time()) {
121 | $postTimingWeek2[] = $day;
122 | }
123 | }
124 |
125 | $timing = array();
126 | $week = 0;
127 |
128 | for ($i = 0;$i<100;$i++) {
129 | if (!empty($postTiming)) {
130 | $timing[] = array_shift($postTiming);
131 | } else {
132 | $timing[] = current($postTimingWeek2)+$week;
133 | next($postTimingWeek2);
134 | if (current($postTimingWeek2) == FALSE) {
135 | reset($postTimingWeek2);
136 | $week += 604800;
137 | }
138 | }
139 | }
140 |
141 | $query = $dbh->prepare("select accounts_queue.id from accounts_queue where accounts_queue.accountid = ? and scheduled_time <> 1 and (sent_time is null or sent_time = '') order by id asc limit 100");
142 | $query->execute(array($accountId));
143 | $queue = $query->fetchAll();
144 |
145 | if (!empty($queue)) {
146 |
147 | $query = "update accounts_queue set scheduled_time = case ";
148 |
149 | foreach ($queue as $post) {
150 | $query .= "when id = ".$post['id']." then ".array_shift($timing)." ";
151 | $ids[] = $post['id'];
152 | }
153 |
154 | $query .= "end where id IN (".implode(",",$ids).")";
155 | $query = $dbh->prepare($query);
156 | $query->execute();
157 |
158 | }
159 |
160 | }
161 |
162 | }
163 |
164 | function queue() {
165 | global $dbh;
166 | global $template;
167 | global $path;
168 |
169 | $accountId = intval($path[2]);
170 |
171 | $query = $dbh->prepare("select timezone from accounts_schedule where companyid = ? and accountid = ? order by record_created desc limit 1");
172 | $query->execute(array($_SESSION['user']['companyid'],$accountId));
173 | $timezone = $query->fetch();
174 |
175 | if (!empty($timezone['timezone'])) {
176 | $timezone = $timezone['timezone'];
177 | } else {
178 | $timezone = 0;
179 | }
180 |
181 | $query = $dbh->prepare("select accounts_queue.*, users.email from accounts_queue join users on accounts_queue.userid = users.id where accounts_queue.companyid = ? and accounts_queue.accountid = ? and ((scheduled_time <> 1 and (sent_time is null or sent_time = '')) or (error <> '')) order by id asc");
182 | $query->execute(array($_SESSION['user']['companyid'],$accountId));
183 | $queue = $query->fetchAll();
184 |
185 | $template->set('timezone',$timezone);
186 | $template->set('posts',$queue);
187 | }
188 |
189 | function queueremove() {
190 | global $dbh;
191 | global $template;
192 | global $path;
193 |
194 | $accountId = intval($path[2]);
195 |
196 | if (!empty($path[3])) {
197 | $postId = intval($path[3]);
198 | } else {
199 | $_SESSION['notification']['type'] = 'error';
200 | $_SESSION['notification']['message'] = 'Oops! Something went wrong.';
201 | header("Location: ".$_SERVER['HTTP_REFERER']);
202 | exit;
203 | }
204 |
205 | $query = $dbh->prepare("delete from accounts_queue where companyid = ? and accountid = ? and id = ? limit 1");
206 | $query->execute(array($_SESSION['user']['companyid'],$accountId, $postId));
207 | requeue($accountId);
208 |
209 | $_SESSION['notification']['type'] = 'success';
210 | $_SESSION['notification']['message'] = 'We have removed the post from the queue.';
211 | header("Location: ".$_SERVER['HTTP_REFERER']);
212 | exit;
213 |
214 |
215 | }
216 |
217 | function queueresend() {
218 | global $dbh;
219 | global $template;
220 | global $path;
221 |
222 | $accountId = intval($path[2]);
223 |
224 | if (!empty($path[3])) {
225 | $postId = intval($path[3]);
226 | } else {
227 | $_SESSION['notification']['type'] = 'error';
228 | $_SESSION['notification']['message'] = 'Oops! Something went wrong.';
229 | header("Location: ".$_SERVER['HTTP_REFERER']);
230 | exit;
231 | }
232 |
233 | $query = $dbh->prepare("update accounts_queue set error = '', scheduled_time = 0, sent_time = 0 where companyid = ? and accountid = ? and id = ? limit 1");
234 | $query->execute(array($_SESSION['user']['companyid'],$accountId, $postId));
235 | requeue($accountId);
236 |
237 | $_SESSION['notification']['type'] = 'success';
238 | $_SESSION['notification']['message'] = 'We have rescheduled the post. If you receive the error again, be sure to reconnect your account.';
239 | header("Location: ".$_SERVER['HTTP_REFERER']);
240 | exit;
241 |
242 |
243 | }
244 |
245 |
246 | function queuenow() {
247 | global $dbh;
248 | global $template;
249 | global $path;
250 |
251 | $accountId = intval($path[2]);
252 |
253 | if (!empty($path[3])) {
254 | $postId = intval($path[3]);
255 | } else {
256 | $_SESSION['notification']['type'] = 'error';
257 | $_SESSION['notification']['message'] = 'Oops! Something went wrong.';
258 | header("Location: ".$_SERVER['HTTP_REFERER']);
259 | exit;
260 | }
261 |
262 | $query = $dbh->prepare("update accounts_queue set scheduled_time = 1 where companyid = ? and accountid = ? and id = ? limit 1");
263 | $query->execute(array($_SESSION['user']['companyid'],$accountId, $postId));
264 | requeue($accountId);
265 |
266 | $_SESSION['notification']['type'] = 'success';
267 | $_SESSION['notification']['message'] = 'Your post is on its way!';
268 | header("Location: ".$_SERVER['HTTP_REFERER']);
269 | exit;
270 |
271 |
272 | }
273 |
274 | function manual(){
275 |
276 | }
277 |
278 | function suggestions() {
279 | global $dbh;
280 | global $template;
281 | global $path;
282 | global $suggestionLists;
283 |
284 | $accountId = intval($path[2]);
285 |
286 | $currentSuggestion = 'all';
287 |
288 | if (!empty($path[3]) && in_array($path[3],$suggestionLists)) {
289 | $currentSuggestion = $path[3];
290 | $query = $dbh->prepare("select * from suggestions where id not in (select suggestion_id from accounts_queue where accountid = ?) and list = ? order by id desc limit 25");
291 | $query->execute(array($accountId,$currentSuggestion));
292 | } else {
293 | $query = $dbh->prepare("select * from suggestions where id not in (select suggestion_id from accounts_queue where accountid = ?) order by id desc limit 25");
294 | $query->execute(array($accountId));
295 | }
296 |
297 | $suggestions = $query->fetchAll();
298 |
299 | $template->set('suggestions',$suggestions);
300 | $template->set('list',$suggestionLists);
301 | $template->set('currentSuggestion',$currentSuggestion);
302 |
303 | }
304 |
305 | function schedule() {
306 | global $dbh;
307 | global $template;
308 | global $path;
309 |
310 | $accountId = intval($path[2]);
311 |
312 | $query = $dbh->prepare("select timezone from accounts_schedule where companyid = ? and accountid = ? order by record_created desc limit 1");
313 | $query->execute(array($_SESSION['user']['companyid'],$accountId));
314 | $timezone = $query->fetch();
315 |
316 | if (!empty($timezone['timezone'])) {
317 | $timezone = $timezone['timezone'];
318 | } else {
319 | $timezone = 0;
320 | }
321 |
322 | $query = $dbh->prepare("select distinct day from accounts_schedule where companyid = ? and accountid = ?");
323 | $query->execute(array($_SESSION['user']['companyid'],$accountId));
324 | $d = $query->fetchAll();
325 |
326 | $days = array();
327 |
328 | foreach ($d as $day) {
329 | $days[$day['day']] = 1;
330 | }
331 |
332 | $query = $dbh->prepare("select distinct time from accounts_schedule where companyid = ? and accountid = ?");
333 | $query->execute(array($_SESSION['user']['companyid'],$accountId));
334 | $t = $query->fetchAll();
335 |
336 | $times = array();
337 |
338 | foreach ($t as $time) {
339 | if (strlen($time['time']) == 3) {
340 | $time['time'] = '0'.$time['time'];
341 | }
342 |
343 | $times[$time['time']] = 1;
344 | }
345 |
346 |
347 | $template->set('timezone',$timezone);
348 | $template->set('days',$days);
349 | $template->set('times',$times);
350 |
351 | }
352 |
353 | function scheduleupdate() {
354 |
355 | global $dbh;
356 | global $template;
357 | global $path;
358 |
359 | // $current is already verified in pre()
360 | $accountId = intval($path[2]);
361 |
362 | $query = $dbh->prepare("delete from accounts_schedule where companyid = ? and accountid = ?");
363 | $query->execute(array($_SESSION['user']['companyid'],$accountId));
364 |
365 | if (!empty($_POST['days'])) {
366 | foreach ($_POST['days'] as $day) {
367 | if (!empty($_POST['time'])) {
368 | foreach ($_POST['time'] as $time) {
369 |
370 | $query = $dbh->prepare("insert into accounts_schedule (companyid,accountid,userid,timezone,day,time,record_created) values (?,?,?,?,?,?,?)");
371 | $query->execute(array($_SESSION['user']['companyid'],$accountId,$_SESSION['user']['loggedin'],$_POST['timezone'],$day,$time,time()));
372 |
373 | }
374 | }
375 | }
376 | }
377 |
378 | requeue($accountId);
379 |
380 | $_SESSION['notification']['type'] = 'success';
381 | $_SESSION['notification']['message'] = 'Yay! All future posts will be scheduled accordingly.';
382 | header("Location: ".BASE_URL."social/schedule/".$accountId);
383 | exit;
384 |
385 | }
386 |
387 | function sent() {
388 |
389 | }
390 |
391 | function post() {
392 |
393 | global $dbh;
394 | global $path;
395 | // $current is already verified in pre()
396 | $accountId = intval($path[2]);
397 |
398 |
399 | if (empty($_POST['message'])) {
400 | $_SESSION['notification']['type'] = 'error';
401 | $_SESSION['notification']['message'] = 'Oops! You forgot to post an update. Be careful.';
402 | header("Location: ".$_SERVER['HTTP_REFERER']);
403 | exit;
404 | }
405 |
406 | $image = '';
407 |
408 | if (!empty($_FILES['image']['tmp_name'])) {
409 |
410 | if (isset($_FILES['image']['tmp_name'])) {
411 | $file = $_FILES['image']['tmp_name'];
412 | $storagePath = dirname(dirname(__FILE__)).'/images';
413 | $allowedMimes = array('image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'image/pjpeg');
414 |
415 | $fileName = upload($file, $storagePath, $allowedMimes);
416 | if (!$fileName) {
417 | $_SESSION['notification']['type'] = 'error';
418 | $_SESSION['notification']['message'] = 'Oops! Your image is not valid. Please double check.';
419 | header("Location: ".$_SERVER['HTTP_REFERER']);
420 | exit;
421 | } else {
422 | $image = BASE_URL.'images/'.$fileName;
423 | }
424 | }
425 |
426 | }
427 |
428 |
429 | if ($_SESSION['user']['type'] != 1) {
430 | $query = $dbh->prepare("select accounts.* from accounts join users_accounts on accounts.id = users_accounts.accountid where users_accounts.companyid = ? and users_accounts.userid = ?");
431 | $query->execute(array($_SESSION['user']['companyid'],$_SESSION['user']['loggedin']));
432 | $access = $query->fetchAll();
433 | } else {
434 | $query = $dbh->prepare("select * from accounts where companyid = ?");
435 | $query->execute(array($_SESSION['user']['companyid']));
436 | $access = $query->fetchAll();
437 | }
438 |
439 | foreach ($access as $account) {
440 | $present[] = $account['id'];
441 | $accountInfo[$account['id']] = $account;
442 | }
443 |
444 | if (empty($_POST['accounts'])) {
445 | $_POST['accounts'] = array($accountId);
446 | }
447 |
448 | if (!empty($_POST['media'])) {
449 | $image = $_POST['media'];
450 | }
451 |
452 |
453 | if (!empty($_POST['accounts'])) {
454 | foreach ($_POST['accounts'] as $account) {
455 | if (in_array($account,$present)) {
456 |
457 | $_SESSION['notification']['type'] = 'success';
458 |
459 | if ($_POST['when'] == 'now') {
460 | $_POST['when'] = 1;
461 | $_SESSION['notification']['message'] = 'Yay! Your update will be posted within a few minutes!';
462 | } else if ($_POST['when'] == 'queue') {
463 | $_POST['when'] = 0;
464 | $_SESSION['notification']['message'] = 'Yay! Your update is queued and will be posted as per your schedule.';
465 | }
466 |
467 | if (!empty($_POST['screen_name'])) {
468 | if (strlen($_POST['message'].' via @'.$_POST['screen_name']) <= 140) {
469 | $_POST['message'] = $_POST['message'].' via @'.$_POST['screen_name'];
470 | }
471 | }
472 |
473 | $sid = 0;
474 |
475 | if (!empty($_POST['suggestion_id'])) {
476 | $sid = $_POST['suggestion_id'];
477 | }
478 |
479 | $query = $dbh->prepare("insert into accounts_queue (companyid,accountid,userid,message,image,record_created,scheduled_time,suggestion_id) values (?,?,?,?,?,?,?,?)");
480 | $query->execute(array($_SESSION['user']['companyid'],$accountInfo[$account]['id'],$_SESSION['user']['loggedin'],$_POST['message'],$image,time(),$_POST['when'],$sid));
481 | requeue($accountInfo[$account]['id']);
482 |
483 | }
484 | }
485 | }
486 |
487 | header("Location: ".$_SERVER['HTTP_REFERER']);
488 | exit;
489 | }
490 |
--------------------------------------------------------------------------------
/controllers/team.php:
--------------------------------------------------------------------------------
1 | prepare("select * from users where active = 1 and companyid = ?");
10 | $query->execute(array($_SESSION['user']['companyid']));
11 | $users = $query->fetchAll();
12 |
13 | $template->set('users',$users);
14 | }
15 |
16 | function invite() {
17 |
18 | }
19 |
20 | function invited() {
21 | global $template;
22 | $email = $_POST['email'];
23 | $template->set('email',$email);
24 | }
25 |
26 | function manage(){
27 | global $template;
28 | global $path;
29 | global $dbh;
30 |
31 | $userId = intval($path[2]);
32 |
33 | $query = $dbh->prepare("select * from users where id = ? and active = 1 and companyid = ? and type <> 1");
34 | $query->execute(array($userId,$_SESSION['user']['companyid']));
35 | $user = $query->fetch();
36 |
37 | if (empty($user['id'])) {
38 | error404();
39 | }
40 |
41 | $query = $dbh->prepare("select * from accounts where companyid = ?");
42 | $query->execute(array($_SESSION['user']['companyid']));
43 | $accounts = $query->fetchAll();
44 |
45 | $template->set('accounts',$accounts);
46 |
47 |
48 | $query = $dbh->prepare("select accounts.* from accounts join users_accounts on accounts.id = users_accounts.accountid where users_accounts.companyid = ? and users_accounts.userid = ?");
49 | $query->execute(array($_SESSION['user']['companyid'],$userId));
50 | $access = $query->fetchAll();
51 |
52 | $present = array();
53 |
54 | foreach ($access as $account) {
55 | $present[] = $account['id'];
56 | }
57 |
58 | $template->set('present',$present);
59 |
60 | $template->set('user',$user);
61 | }
62 |
63 | function update() {
64 | global $template;
65 | global $path;
66 | global $dbh;
67 |
68 | // Are we updating the correct user?
69 |
70 | $userId = $_POST['id'];
71 |
72 | $query = $dbh->prepare("select * from users where id = ? and active = 1 and companyid = ? and type <> 1");
73 | $query->execute(array($userId,$_SESSION['user']['companyid']));
74 | $user = $query->fetch();
75 |
76 | if (empty($user['id'])) {
77 | error404();
78 | }
79 |
80 | if (!empty($_POST['role']) && $_POST['role'] > 1) {
81 | $sql = "update users set type = ? where id = ? and companyid = ?";
82 | $query = $dbh->prepare($sql);
83 | $query->execute(array($_POST['role'],$_POST['id'],$_SESSION['user']['companyid']));
84 | }
85 |
86 | $query = $dbh->prepare("delete from users_accounts where companyid = ? and userid = ?");
87 | $query->execute(array($_SESSION['user']['companyid'],$_POST['id']));
88 |
89 | if (!empty($_POST['accounts'])) {
90 | foreach ($_POST['accounts'] as $account) {
91 | $query = $dbh->prepare("insert into users_accounts (companyid,userid,accountid) values (?,?,?)");
92 | $query->execute(array($_SESSION['user']['companyid'],$_POST['id'],$account));
93 | }
94 | }
95 |
96 | if ($_POST['type'] == 'delete') {
97 | $sql = "update users set active = 0 where id = ? and companyid = ?";
98 | $query = $dbh->prepare($sql);
99 | $query->execute(array($_POST['id'],$_SESSION['user']['companyid']));
100 |
101 | $_SESSION['notification']['type'] = 'success';
102 | $_SESSION['notification']['message'] = $user['email'].' has been successfully removed.';
103 | } else {
104 | $_SESSION['notification']['type'] = 'success';
105 | $_SESSION['notification']['message'] = 'Yay! Permissions have been successfully modified for '.$user['email'];
106 | }
107 |
108 | header("Location: ".BASE_URL."team");
109 | exit;
110 | }
--------------------------------------------------------------------------------
/controllers/users.php:
--------------------------------------------------------------------------------
1 | set('noextra','1');
7 | $template->set('heading','login');
8 | $template->set('title','Login');
9 | }
10 |
11 | function validate() {
12 | global $dbh;
13 |
14 | $type = $_POST['type'];
15 | $email = $_POST['email'];
16 | $password = $_POST['password'];
17 | $code = '';
18 |
19 | if (!empty($_POST['code'])) {
20 | $code = $_POST['code'];
21 | }
22 |
23 | if (empty($_POST['email']) || empty($_POST['password'])) {
24 | $_SESSION['notification']['type'] = 'error';
25 | $_SESSION['notification']['message'] = 'Oops! Looks like you missed some details.';
26 | header("Location: ".$_SERVER['HTTP_REFERER']);
27 | exit;
28 | }
29 |
30 | if ($type == 'login') {
31 |
32 | $query = $dbh->prepare("select * from users where email = ? and password = ? and active = 1");
33 | $query->execute(array($email,hashPassword($password)));
34 | $account = $query->fetch();
35 |
36 | if (!empty($account['id'])) {
37 | $_SESSION['user']['loggedin'] = $account['id'];
38 | $_SESSION['user']['email'] = $account['email'];
39 | $_SESSION['user']['companyid'] = $account['companyid'];
40 | $_SESSION['user']['type'] = $account['type'];
41 |
42 | header("Location: ".BASE_URL);
43 | exit;
44 | } else {
45 | $_SESSION['notification']['type'] = 'error';
46 | $_SESSION['notification']['message'] = 'Oops! Looks like your login information is incorrect.';
47 | header("Location: ".$_SERVER['HTTP_REFERER']);
48 | exit;
49 | }
50 |
51 |
52 | } else if ($type == 'register') {
53 |
54 | if (!empty($_POST['name'])) {
55 | $name = $_POST['name'];
56 | } else {
57 | $_SESSION['notification']['type'] = 'error';
58 | $_SESSION['notification']['message'] = 'Looks like you forgot to enter your team\'s name.';
59 | header("Location: ".$_SERVER['HTTP_REFERER']);
60 | exit;
61 | }
62 |
63 | $query = $dbh->prepare("select * from users where email = ?");
64 | $query->execute(array($email));
65 | $account = $query->fetch();
66 |
67 | if (!empty($account['id'])) {
68 | $_SESSION['notification']['type'] = 'error';
69 | $_SESSION['notification']['message'] = 'Looks like you already have an account. Please use our forgot password facility.';
70 | header("Location: ".$_SERVER['HTTP_REFERER']);
71 | exit;
72 | }
73 |
74 | $sql = "INSERT INTO companies (name,plan,active) VALUES (?,?,?)";
75 | $query = $dbh->prepare($sql);
76 | $query->execute(array($name,1,1));
77 | $companyId = $dbh->lastInsertId();
78 |
79 | $sql = "INSERT INTO users (companyid,email,password,active,type) VALUES (?,?,?,?,?)";
80 | $query = $dbh->prepare($sql);
81 | $query->execute(array($companyId,$email,hashPassword($password),1,1));
82 |
83 | $_SESSION['user']['loggedin'] = $dbh->lastInsertId();
84 | $_SESSION['user']['email'] = $email;
85 | $_SESSION['user']['companyid'] = $companyId;
86 | $_SESSION['user']['type'] = 1;
87 |
88 |
89 | header("Location: ".BASE_URL);
90 | exit;
91 |
92 | } else if ($type == 'invite') {
93 |
94 | $query = $dbh->prepare("select * from users where email = ?");
95 | $query->execute(array($email));
96 | $account = $query->fetch();
97 |
98 | if (!empty($account['id'])) {
99 | $_SESSION['notification']['type'] = 'error';
100 | $_SESSION['notification']['message'] = 'Looks like you already have an account. We currently support only 1 team per email, sorry!';
101 | header('Location: '.$_SERVER['HTTP_REFERER']);
102 | exit;
103 | }
104 |
105 | $query = $dbh->prepare("select * from companies where sha1(concat(id,?)) = ?");
106 | $query->execute(array($email,$code));
107 | $company = $query->fetch();
108 |
109 | if (empty($company['id'])) {
110 | $_SESSION['notification']['type'] = 'error';
111 | $_SESSION['notification']['message'] = 'Looks like something has gone wrong. Please ask your team member to invite you again.';
112 | header('Location: '.$_SERVER['HTTP_REFERER']);
113 | exit;
114 | }
115 |
116 | $companyId = $company['id'];
117 |
118 | $sql = "INSERT INTO users (companyid,email,password,active,type) VALUES (?,?,?,?,?)";
119 | $query = $dbh->prepare($sql);
120 | $query->execute(array($companyId,$email,hashPassword($password),1,100));
121 |
122 | $_SESSION['user']['loggedin'] = $dbh->lastInsertId();
123 | $_SESSION['user']['email'] = $email;
124 | $_SESSION['user']['companyid'] = $companyId;
125 | $_SESSION['user']['type'] = 100;
126 |
127 |
128 | header("Location: ".BASE_URL);
129 | exit;
130 |
131 | }
132 |
133 | }
134 |
135 | function register() {
136 | global $template;
137 |
138 | $template->set('noextra','1');
139 |
140 | }
141 |
142 | function logout() {
143 | session_destroy();
144 | header("Location: ".BASE_URL);
145 | exit;
146 | }
147 |
148 | function invite() {
149 | global $template;
150 | global $path;
151 |
152 | $email = base64_decode($path[2]);
153 | $code = $path[3];
154 |
155 | if (empty($code) || empty($email)) {
156 | error404();
157 | }
158 |
159 | $template->set('code',$code);
160 | $template->set('email',$email);
161 | $template->set('noextra','1');
162 | $template->set('title',"You've been invited!");
163 | }
164 |
165 | function inform() {
166 | global $template;
167 | global $path;
168 |
169 | // EMAIL
170 |
171 | $template->set('noextra','1');
172 |
173 | }
--------------------------------------------------------------------------------
/db/1.txt:
--------------------------------------------------------------------------------
1 | CREATE TABLE `users_accounts` (
2 | `id` int(11) NOT NULL AUTO_INCREMENT,
3 | `companyid` int(11) DEFAULT NULL,
4 | `accountid` int(11) DEFAULT NULL,
5 | `userid` int(11) DEFAULT NULL,
6 | PRIMARY KEY (`id`)
7 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8
8 |
9 | CREATE TABLE `users` (
10 | `id` int(11) NOT NULL AUTO_INCREMENT,
11 | `companyid` int(11) DEFAULT NULL,
12 | `email` varchar(255) DEFAULT NULL,
13 | `password` varchar(255) DEFAULT NULL,
14 | `active` int(1) DEFAULT '0',
15 | `type` int(1) DEFAULT '0',
16 | `record_created` int(11) DEFAULT '0',
17 | PRIMARY KEY (`id`)
18 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8
19 |
20 | CREATE TABLE `suggestions` (
21 | `id` varchar(45) NOT NULL,
22 | `text` text,
23 | `screen_name` varchar(255) DEFAULT NULL,
24 | `media` text,
25 | `list` varchar(45) DEFAULT NULL,
26 | `record_created` int(11) DEFAULT NULL,
27 | PRIMARY KEY (`id`)
28 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8
29 |
30 | CREATE TABLE `companies` (
31 | `id` int(11) NOT NULL AUTO_INCREMENT,
32 | `email` varchar(255) DEFAULT NULL,
33 | `plan` int(11) DEFAULT NULL,
34 | `active` int(1) DEFAULT NULL,
35 | PRIMARY KEY (`id`)
36 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8
37 |
38 | CREATE TABLE `accounts_schedule` (
39 | `id` int(11) NOT NULL AUTO_INCREMENT,
40 | `companyid` int(11) DEFAULT NULL,
41 | `accountid` int(11) DEFAULT NULL,
42 | `userid` int(11) DEFAULT NULL,
43 | `timezone` varchar(45) DEFAULT NULL,
44 | `day` int(11) DEFAULT NULL,
45 | `time` int(11) DEFAULT NULL,
46 | `record_created` int(11) DEFAULT NULL,
47 | PRIMARY KEY (`id`)
48 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8
49 |
50 | CREATE TABLE `accounts_queue` (
51 | `id` int(11) NOT NULL AUTO_INCREMENT,
52 | `companyid` int(11) DEFAULT NULL,
53 | `accountid` int(11) DEFAULT NULL,
54 | `userid` int(11) DEFAULT NULL,
55 | `message` text,
56 | `image` text,
57 | `suggestion_id` varchar(50) DEFAULT '0',
58 | `scheduled_time` int(11) DEFAULT '0',
59 | `sent_time` int(11) DEFAULT '0',
60 | `error` text,
61 | `record_created` int(11) DEFAULT '0',
62 | PRIMARY KEY (`id`)
63 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8
64 |
65 | CREATE TABLE `accounts` (
66 | `id` int(11) NOT NULL AUTO_INCREMENT,
67 | `companyid` int(11) DEFAULT NULL,
68 | `type` enum('google','facebook','twitter') DEFAULT NULL,
69 | `name` varchar(255) DEFAULT NULL,
70 | `data1` text,
71 | `data2` text,
72 | `data3` text,
73 | `data4` text,
74 | `active` int(11) DEFAULT '0',
75 | `record_created` int(11) DEFAULT '0',
76 | PRIMARY KEY (`id`)
77 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8
78 |
79 |
80 |
--------------------------------------------------------------------------------
/db/2.txt:
--------------------------------------------------------------------------------
1 | ALTER TABLE `companies` CHANGE COLUMN `email` `name` VARCHAR(255) NULL DEFAULT NULL ;
2 |
--------------------------------------------------------------------------------
/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anantgarg/socialturn/a48c16cfcca89df4e5398698af39b14bc9b7de75/favicon.ico
--------------------------------------------------------------------------------
/images/index.htm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anantgarg/socialturn/a48c16cfcca89df4e5398698af39b14bc9b7de75/images/index.htm
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | render();
97 |
98 | } else {
99 | /* 404 error here */
100 | error404();
101 | }
102 | }
--------------------------------------------------------------------------------
/libraries/facebook/facebook.php:
--------------------------------------------------------------------------------
1 | initSharedSession();
65 |
66 | // re-load the persisted state, since parent
67 | // attempted to read out of non-shared cookie
68 | $state = $this->getPersistentData('state');
69 | if (!empty($state)) {
70 | $this->state = $state;
71 | } else {
72 | $this->state = null;
73 | }
74 |
75 | }
76 | }
77 |
78 | /**
79 | * Supported keys for persistent data
80 | *
81 | * @var array
82 | */
83 | protected static $kSupportedKeys =
84 | array('state', 'code', 'access_token', 'user_id');
85 |
86 | /**
87 | * Initiates Shared Session
88 | */
89 | protected function initSharedSession() {
90 | $cookie_name = $this->getSharedSessionCookieName();
91 | if (isset($_COOKIE[$cookie_name])) {
92 | $data = $this->parseSignedRequest($_COOKIE[$cookie_name]);
93 | if ($data && !empty($data['domain']) &&
94 | self::isAllowedDomain($this->getHttpHost(), $data['domain'])) {
95 | // good case
96 | $this->sharedSessionID = $data['id'];
97 | return;
98 | }
99 | // ignoring potentially unreachable data
100 | }
101 | // evil/corrupt/missing case
102 | $base_domain = $this->getBaseDomain();
103 | $this->sharedSessionID = md5(uniqid(mt_rand(), true));
104 | $cookie_value = $this->makeSignedRequest(
105 | array(
106 | 'domain' => $base_domain,
107 | 'id' => $this->sharedSessionID,
108 | )
109 | );
110 | $_COOKIE[$cookie_name] = $cookie_value;
111 | if (!headers_sent()) {
112 | $expire = time() + self::FBSS_COOKIE_EXPIRE;
113 | setcookie($cookie_name, $cookie_value, $expire, '/', '.'.$base_domain);
114 | } else {
115 | // @codeCoverageIgnoreStart
116 | self::errorLog(
117 | 'Shared session ID cookie could not be set! You must ensure you '.
118 | 'create the Facebook instance before headers have been sent. This '.
119 | 'will cause authentication issues after the first request.'
120 | );
121 | // @codeCoverageIgnoreEnd
122 | }
123 | }
124 |
125 | /**
126 | * Provides the implementations of the inherited abstract
127 | * methods. The implementation uses PHP sessions to maintain
128 | * a store for authorization codes, user ids, CSRF states, and
129 | * access tokens.
130 | */
131 |
132 | /**
133 | * {@inheritdoc}
134 | *
135 | * @see BaseFacebook::setPersistentData()
136 | */
137 | protected function setPersistentData($key, $value) {
138 | if (!in_array($key, self::$kSupportedKeys)) {
139 | self::errorLog('Unsupported key passed to setPersistentData.');
140 | return;
141 | }
142 |
143 | $session_var_name = $this->constructSessionVariableName($key);
144 | $_SESSION[$session_var_name] = $value;
145 | }
146 |
147 | /**
148 | * {@inheritdoc}
149 | *
150 | * @see BaseFacebook::getPersistentData()
151 | */
152 | protected function getPersistentData($key, $default = false) {
153 | if (!in_array($key, self::$kSupportedKeys)) {
154 | self::errorLog('Unsupported key passed to getPersistentData.');
155 | return $default;
156 | }
157 |
158 | $session_var_name = $this->constructSessionVariableName($key);
159 | return isset($_SESSION[$session_var_name]) ?
160 | $_SESSION[$session_var_name] : $default;
161 | }
162 |
163 | /**
164 | * {@inheritdoc}
165 | *
166 | * @see BaseFacebook::clearPersistentData()
167 | */
168 | protected function clearPersistentData($key) {
169 | if (!in_array($key, self::$kSupportedKeys)) {
170 | self::errorLog('Unsupported key passed to clearPersistentData.');
171 | return;
172 | }
173 |
174 | $session_var_name = $this->constructSessionVariableName($key);
175 | if (isset($_SESSION[$session_var_name])) {
176 | unset($_SESSION[$session_var_name]);
177 | }
178 | }
179 |
180 | /**
181 | * {@inheritdoc}
182 | *
183 | * @see BaseFacebook::clearAllPersistentData()
184 | */
185 | protected function clearAllPersistentData() {
186 | foreach (self::$kSupportedKeys as $key) {
187 | $this->clearPersistentData($key);
188 | }
189 | if ($this->sharedSessionID) {
190 | $this->deleteSharedSessionCookie();
191 | }
192 | }
193 |
194 | /**
195 | * Deletes Shared session cookie
196 | */
197 | protected function deleteSharedSessionCookie() {
198 | $cookie_name = $this->getSharedSessionCookieName();
199 | unset($_COOKIE[$cookie_name]);
200 | $base_domain = $this->getBaseDomain();
201 | setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
202 | }
203 |
204 | /**
205 | * Returns the Shared session cookie name
206 | *
207 | * @return string The Shared session cookie name
208 | */
209 | protected function getSharedSessionCookieName() {
210 | return self::FBSS_COOKIE_NAME . '_' . $this->getAppId();
211 | }
212 |
213 | /**
214 | * Constructs and returns the name of the session key.
215 | *
216 | * @see setPersistentData()
217 | * @param string $key The key for which the session variable name to construct.
218 | *
219 | * @return string The name of the session key.
220 | */
221 | protected function constructSessionVariableName($key) {
222 | $parts = array('fb', $this->getAppId(), $key);
223 | if ($this->sharedSessionID) {
224 | array_unshift($parts, $this->sharedSessionID);
225 | }
226 | return implode('_', $parts);
227 | }
228 | }
229 |
--------------------------------------------------------------------------------
/libraries/helper.class.php:
--------------------------------------------------------------------------------
1 | variables[$name] = $value;
11 | }
12 |
13 | /** Display Template **/
14 |
15 | function render() {
16 |
17 | $backtrace = debug_backtrace();
18 | $function = strtolower($backtrace[1]['function']);
19 |
20 | extract($this->variables);
21 |
22 | $contents = '';
23 |
24 | if (file_exists(ROOT . DS . 'views' . DS . 'helpers' . DS . $function . '.php')) {
25 | $filename = (ROOT . DS . 'views' . DS . 'helpers' . DS . $function . '.php');
26 |
27 | if (is_file($filename)) {
28 | ob_start();
29 | include $filename;
30 | $contents = ob_get_contents();
31 | ob_end_clean();
32 | }
33 | }
34 |
35 | $this->variables = array();
36 |
37 | return $contents;
38 |
39 | }
40 |
41 |
42 |
43 | }
44 |
45 | function getContent($filename) {
46 |
47 | return false;
48 | }
49 |
--------------------------------------------------------------------------------
/libraries/pagination.class.php:
--------------------------------------------------------------------------------
1 | '',
9 | 'perpage' => '',
10 | 'page' => '',
11 | 'total' => '',
12 | 'numlinks' => '5',
13 | 'nexttext' => '>',
14 | 'prevtext' => '<',
15 | 'focusedclass' => 'selected',
16 | 'delimiter' => '',
17 | 'lasttext' => '>>',
18 | 'firsttext' => '<<',
19 | 'order' => 'votes',
20 | 'search' => ''
21 | );
22 |
23 | function set($who,$what){
24 | $this->output = '';
25 | $this->options[$who] = $what;
26 | }
27 |
28 | function checkValues(){
29 | $errors = array();
30 | if($this->options['perpage']=='') $errors[] = 'Invalid perpage value';
31 | if($this->options['page']=='') $errors[] = 'Invalid page value';
32 | if($this->options['total']=='') $errors[] = 'Invalid total value';
33 | if($this->options['numlinks']=='') $errors[] = 'Invalid numlinks value';
34 | }
35 | function display($return = true){
36 | $this->checkValues();
37 | if($this->output=='') $this->generateOutput();
38 | if(!$return) echo $this->output;
39 | else return $this->output;
40 | }
41 | function generateOutput(){
42 | $elements = array();
43 | $num_pages = ceil($this->options['total']/$this->options['perpage']);
44 | $front_links = ceil($this->options['numlinks']/2);
45 | $end_links = floor($this->options['numlinks']/2);
46 | if($this->options['page'] > $num_pages){ $this->set('page',1); }
47 |
48 | $start_page = max(1,($this->options['page']-$front_links+1));
49 | $end_page = min($this->options['numlinks'] + $start_page-1,$num_pages);
50 |
51 | if($this->options['page'] > 1){
52 | if ($num_pages > 10) {
53 | $elements[] = $this->generate_link(1,$this->options['firsttext']);
54 | }
55 |
56 | $elements[] = $this->generate_link($this->options['page']-1,$this->options['prevtext']);
57 |
58 | }
59 |
60 | for($i=$start_page;$i<=$end_page;$i++){
61 | $elements[] = $this->generate_link($i);
62 | }
63 |
64 | if($this->options['page'] < $num_pages){
65 | $elements[] = $this->generate_link($this->options['page']+1,$this->options['nexttext']);
66 | if ($num_pages > 10) {
67 | $elements[] = $this->generate_link($num_pages,$this->options['lasttext']);
68 | }
69 | }
70 |
71 | $this->output = implode($this->options['delimiter'],$elements);
72 | }
73 | function generate_link($page,$label=''){
74 | $url = str_replace('%page%',$page,$this->options['urlscheme']);
75 | if($label=='') $label=$page;
76 | $html = "options['focusedclass']!='' && $page == $this->options['page'])?"class=\"{$this->options['focusedclass']}\" ":"")."href=\"{$url}\">{$label} ";
77 | return $html;
78 | }
79 |
80 | function displayOptions(){
81 | if ($this->options['search']!='') {
82 | $elements[] = $this->generate_seclink('relevance');
83 | }
84 | $elements[] = $this->generate_seclink('votes');
85 | $elements[] = $this->generate_seclink('newest');
86 | $elements[] = $this->generate_seclink('oldest');
87 | return implode($this->options['delimiter'],$elements);
88 |
89 | }
90 |
91 |
92 | function generate_seclink($label){
93 | $url = str_replace('%label%',$label,$this->options['urlscheme']);
94 | $html = "options['focusedclass']!='' && $label == $this->options['order'])?"class=\"{$this->options['focusedclass']}\" ":"")."href=\"{$url}\">{$label} ";
95 | return $html;
96 | }
97 | }
--------------------------------------------------------------------------------
/libraries/postmark.class.php:
--------------------------------------------------------------------------------
1 | to('address@example.com', 'Name')
18 | * ->subject('Subject')
19 | * ->messagePlain('Plaintext message')
20 | * ->tag('Test tag')
21 | * ->send();
22 | *
23 | * or:
24 | *
25 | * $email = new Mail_Postmark();
26 | * $email->to('address@example.com', 'Name')
27 | * ->subject('Subject')
28 | * ->messagePlain('Plaintext message')
29 | * ->tag('Test tag')
30 | * ->send();
31 | */
32 |
33 | class Mail_Postmark
34 | {
35 | const DEBUG_OFF = 0;
36 | const DEBUG_VERBOSE = 1;
37 | const DEBUG_RETURN = 2;
38 |
39 | private $_fromName;
40 | private $_fromAddress;
41 | private $_tag;
42 | private $_toName;
43 | private $_toAddress;
44 | private $_replyToName;
45 | private $_replyToAddress;
46 | private $_cc = array();
47 | private $_bcc = array();
48 | private $_subject;
49 | private $_messagePlain;
50 | private $_messageHtml;
51 | private $_debugMode = self::DEBUG_OFF;
52 |
53 | /**
54 | * Initialize
55 | */
56 | public function __construct()
57 | {
58 | $this->_default('POSTMARKAPP_MAIL_FROM_NAME', null);
59 | $this->_default('POSTMARKAPP_MAIL_FROM_ADDRESS', null);
60 | $this->_default('POSTMARKAPP_API_KEY', null);
61 | $this->from(POSTMARKAPP_MAIL_FROM_ADDRESS, POSTMARKAPP_MAIL_FROM_NAME)->messageHtml(null)->messagePlain(null);
62 | }
63 |
64 | /**
65 | * New e-mail
66 | * @return Mail_Postmark
67 | */
68 | public static function compose()
69 | {
70 | return new self();
71 | }
72 |
73 | /**
74 | * Turns debug output on
75 | * @param int $mode One of the debug constants
76 | * @return Mail_Postmark
77 | */
78 | public function &debug($mode = self::DEBUG_VERBOSE)
79 | {
80 | $this->_debugMode = $mode;
81 | return $this;
82 | }
83 |
84 | /**
85 | * Specify sender. Overwrites default From.
86 | * @param string $address E-mail address used in From
87 | * @param string $name Optional. Name used in From
88 | * @return Mail_Postmark
89 | */
90 | public function &from($address, $name = null)
91 | {
92 | $this->_fromAddress = $address;
93 | $this->_fromName = $name;
94 | return $this;
95 | }
96 |
97 | /**
98 | * Specify sender name. Overwrites default From name, but doesn't change address.
99 | * @param string $name Name used in From
100 | * @return Mail_Postmark
101 | */
102 | public function &fromName($name)
103 | {
104 | $this->_fromName = $name;
105 | return $this;
106 | }
107 |
108 | /**
109 | * You can categorize outgoing email using the optional Tag property.
110 | * If you use different tags for the different types of emails your
111 | * application generates, you will be able to get detailed statistics
112 | * for them through the Postmark user interface.
113 | * Only 1 tag per mail is supported.
114 | *
115 | * @param string $tag One tag
116 | * @return Mail_Postmark
117 | */
118 | public function &tag($tag)
119 | {
120 | $this->_tag = $tag;
121 | return $this;
122 | }
123 |
124 | /**
125 | * Specify receiver
126 | * @param string $address E-mail address used in To
127 | * @param string $name Optional. Name used in To
128 | * @return Mail_Postmark
129 | */
130 | public function &to($address, $name = null)
131 | {
132 | $this->_toAddress = $address;
133 | $this->_toName = $name;
134 | return $this;
135 | }
136 |
137 | /**
138 | * Specify reply-to
139 | * @param string $address E-mail address used in To
140 | * @param string $name Optional. Name used in To
141 | * @return Mail_Postmark
142 | */
143 | public function &replyTo($address, $name = null)
144 | {
145 | $this->_replyToAddress = $address;
146 | $this->_replyToName = $name;
147 | return $this;
148 | }
149 |
150 | /**
151 | * Add a CC address
152 | * @param string $address E-mail address used in CC
153 | * @param string $name Optional. Name used in CC
154 | * @return Mail_Postmark
155 | */
156 | public function &addCC($address, $name = null)
157 | {
158 | $this->_cc[] = (is_null($name) ? $address : "$name <$address>");
159 | return $this;
160 | }
161 |
162 | /**
163 | * Add a BCC address
164 | * @param string $address E-mail address used in BCC
165 | * @param string $name Optional. Name used in BCC
166 | * @return Mail_Postmark
167 | */
168 | public function &addBCC($address, $name = null)
169 | {
170 | $this->_bcc[] = (is_null($name) ? $address : "$name <$address>");
171 | return $this;
172 | }
173 |
174 | /**
175 | * Specify subject
176 | * @param string $subject E-mail subject
177 | * @return Mail_Postmark
178 | */
179 | public function &subject($subject)
180 | {
181 | $this->_subject = $subject;
182 | return $this;
183 | }
184 |
185 | /**
186 | * Add plaintext message. Can be used in conjunction with messageHtml()
187 | * @param string $message E-mail message
188 | * @return Mail_Postmark
189 | */
190 | public function &messagePlain($message)
191 | {
192 | $this->_messagePlain = $message;
193 | return $this;
194 | }
195 |
196 | /**
197 | * Add HTML message. Can be used in conjunction with messagePlain()
198 | * @param string $message E-mail message
199 | * @return Mail_Postmark
200 | */
201 | public function &messageHtml($message)
202 | {
203 | $this->_messageHtml = $message;
204 | return $this;
205 | }
206 |
207 | /**
208 | * Sends the e-mail. Prints debug output if debug mode is turned on
209 | * @return Mail_Postmark
210 | */
211 | public function &send()
212 | {
213 | if (is_null(POSTMARKAPP_API_KEY)) {
214 | throw new Exception('Postmark API key is not set');
215 | }
216 |
217 | if (is_null($this->_fromAddress)) {
218 | throw new Exception('From address is not set');
219 | }
220 |
221 | if (!isset($this->_toAddress)) {
222 | throw new Exception('To address is not set');
223 | }
224 |
225 | if (!$this->_validateAddress($this->_fromAddress)) {
226 | throw new Exception("Invalid from address '{$this->_fromAddress}'");
227 | }
228 |
229 | if (!$this->_validateAddress($this->_toAddress)) {
230 | throw new Exception("Invalid to address '{$this->_toAddress}'");
231 | }
232 |
233 | if (isset($this->_replyToAddress) && !$this->_validateAddress($this->_replyToAddress)) {
234 | throw new Exception("Invalid reply to address '{$this->_replyToAddress}'");
235 | }
236 |
237 | if (1 + count($this->_cc) + count($this->_bcc) > 20) {
238 | throw new Exception("Too many email recipients");
239 | }
240 |
241 | $data = $this->_prepareData();
242 | $headers = array(
243 | 'Accept: application/json',
244 | 'Content-Type: application/json',
245 | 'X-Postmark-Server-Token: ' . POSTMARKAPP_API_KEY
246 | );
247 |
248 | $ch = curl_init();
249 | curl_setopt($ch, CURLOPT_URL, 'http://api.postmarkapp.com/email');
250 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
251 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
252 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
253 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
254 |
255 | $return = curl_exec($ch);
256 |
257 | if ($this->_debugMode == self::DEBUG_VERBOSE) {
258 | echo "JSON: " . json_encode($data) . "\nHeaders: \n\t" . implode("\n\t", $headers) . "\nReturn:\n$return";
259 |
260 | } else if ($this->_debugMode == self::DEBUG_RETURN) {
261 | return array(
262 | 'json' => json_encode($data),
263 | 'headers' => $headers,
264 | 'return' => $return
265 | );
266 | }
267 |
268 | if (curl_error($ch) != '') {
269 | throw new Exception(curl_error($ch));
270 | }
271 |
272 | $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
273 |
274 | if (!$this->_isTwoHundred($httpCode)) {
275 | $message = json_decode($return)->Message;
276 | throw new Exception("Error while mailing. Postmark returned HTTP code $httpCode with message \"$message\"");
277 | }
278 |
279 | return $this;
280 | }
281 |
282 | /**
283 | * Prepares the data array
284 | */
285 | private function _prepareData()
286 | {
287 | $data = array(
288 | 'Subject' => $this->_subject
289 | );
290 |
291 | $data['From'] = is_null($this->_fromName) ? $this->_fromAddress : "{$this->_fromName} <{$this->_fromAddress}>";
292 | $data['To'] = is_null($this->_toName) ? $this->_toAddress : "{$this->_toName} <{$this->_toAddress}>";
293 |
294 | if (!is_null($this->_messageHtml)) {
295 | $data['HtmlBody'] = $this->_messageHtml;
296 | }
297 |
298 | if (!is_null($this->_messagePlain)) {
299 | $data['TextBody'] = $this->_messagePlain;
300 | }
301 |
302 | if (!is_null($this->_tag)) {
303 | $data['Tag'] = $this->_tag;
304 | }
305 |
306 | if (!is_null($this->_replyToAddress)) {
307 | $data['ReplyTo'] = is_null($this->_replyToName) ? $this->_replyToAddress : "{$this->_replyToName} <{$this->_replyToAddress}>";
308 | }
309 |
310 | if (!empty($this->_cc)) {
311 | $data['Cc'] = implode(',',$this->_cc);
312 | }
313 |
314 | if (!empty($this->_bcc)) {
315 | $data['Bcc'] = implode(',',$this->_bcc);
316 | }
317 |
318 | return $data;
319 | }
320 |
321 | /**
322 | * If a number is 200-299
323 | */
324 | private function _isTwoHundred($value)
325 | {
326 | return intval($value / 100) == 2;
327 | }
328 |
329 | /**
330 | * Defines a constant, if it isn't defined
331 | */
332 | private function _default($name, $default)
333 | {
334 | if (!defined($name)) {
335 | define($name, $default);
336 | }
337 | }
338 |
339 | /**
340 | * Validates an e-mailadress
341 | */
342 | private function _validateAddress($email)
343 | {
344 | // http://php.net/manual/en/function.filter-var.php
345 | return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
346 | }
347 | }
--------------------------------------------------------------------------------
/libraries/recaptcha.php:
--------------------------------------------------------------------------------
1 | $value )
50 | $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
51 |
52 | // Cut the last '&'
53 | $req=substr($req,0,strlen($req)-1);
54 | return $req;
55 | }
56 |
57 |
58 |
59 | /**
60 | * Submits an HTTP POST to a reCAPTCHA server
61 | * @param string $host
62 | * @param string $path
63 | * @param array $data
64 | * @param int port
65 | * @return array response
66 | */
67 | function _recaptcha_http_post($host, $path, $data, $port = 80) {
68 |
69 | $req = _recaptcha_qsencode ($data);
70 |
71 | $http_request = "POST $path HTTP/1.0\r\n";
72 | $http_request .= "Host: $host\r\n";
73 | $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
74 | $http_request .= "Content-Length: " . strlen($req) . "\r\n";
75 | $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
76 | $http_request .= "\r\n";
77 | $http_request .= $req;
78 |
79 | $response = '';
80 | if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
81 | die ('Could not open socket');
82 | }
83 |
84 | fwrite($fs, $http_request);
85 |
86 | while ( !feof($fs) )
87 | $response .= fgets($fs, 1160); // One TCP-IP packet
88 | fclose($fs);
89 | $response = explode("\r\n\r\n", $response, 2);
90 |
91 | return $response;
92 | }
93 |
94 |
95 |
96 | /**
97 | * Gets the challenge HTML (javascript and non-javascript version).
98 | * This is called from the browser, and the resulting reCAPTCHA HTML widget
99 | * is embedded within the HTML form it was called from.
100 | * @param string $pubkey A public key for reCAPTCHA
101 | * @param string $error The error given by reCAPTCHA (optional, default is null)
102 | * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
103 |
104 | * @return string - The HTML to be embedded in the user's form.
105 | */
106 | function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
107 | {
108 | if ($pubkey == null || $pubkey == '') {
109 | die ("To use reCAPTCHA you must get an API key from http://recaptcha.net/api/getkey ");
110 | }
111 |
112 | if ($use_ssl) {
113 | $server = RECAPTCHA_API_SECURE_SERVER;
114 | } else {
115 | $server = RECAPTCHA_API_SERVER;
116 | }
117 |
118 | $errorpart = "";
119 | if ($error) {
120 | $errorpart = "&error=" . $error;
121 | }
122 | return '
123 |
124 |
125 |
126 |
127 |
128 | ';
129 | }
130 |
131 |
132 |
133 |
134 | /**
135 | * A ReCaptchaResponse is returned from recaptcha_check_answer()
136 | */
137 | class ReCaptchaResponse {
138 | var $is_valid;
139 | var $error;
140 | }
141 |
142 |
143 | /**
144 | * Calls an HTTP POST function to verify if the user's guess was correct
145 | * @param string $privkey
146 | * @param string $remoteip
147 | * @param string $challenge
148 | * @param string $response
149 | * @param array $extra_params an array of extra variables to post to the server
150 | * @return ReCaptchaResponse
151 | */
152 | function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
153 | {
154 | if ($privkey == null || $privkey == '') {
155 | die ("To use reCAPTCHA you must get an API key from http://recaptcha.net/api/getkey ");
156 | }
157 |
158 | if ($remoteip == null || $remoteip == '') {
159 | die ("For security reasons, you must pass the remote ip to reCAPTCHA");
160 | }
161 |
162 |
163 |
164 | //discard spam submissions
165 | if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
166 | $recaptcha_response = new ReCaptchaResponse();
167 | $recaptcha_response->is_valid = false;
168 | $recaptcha_response->error = 'incorrect-captcha-sol';
169 | return $recaptcha_response;
170 | }
171 |
172 | $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/verify",
173 | array (
174 | 'privatekey' => $privkey,
175 | 'remoteip' => $remoteip,
176 | 'challenge' => $challenge,
177 | 'response' => $response
178 | ) + $extra_params
179 | );
180 |
181 | $answers = explode ("\n", $response [1]);
182 | $recaptcha_response = new ReCaptchaResponse();
183 |
184 | if (trim ($answers [0]) == 'true') {
185 | $recaptcha_response->is_valid = true;
186 | }
187 | else {
188 | $recaptcha_response->is_valid = false;
189 | $recaptcha_response->error = $answers [1];
190 | }
191 | return $recaptcha_response;
192 |
193 | }
194 |
195 | /**
196 | * gets a URL where the user can sign up for reCAPTCHA. If your application
197 | * has a configuration page where you enter a key, you should provide a link
198 | * using this function.
199 | * @param string $domain The domain where the page is hosted
200 | * @param string $appname The name of your application
201 | */
202 | function recaptcha_get_signup_url ($domain = null, $appname = null) {
203 | return "http://recaptcha.net/api/getkey?" . _recaptcha_qsencode (array ('domain' => $domain, 'app' => $appname));
204 | }
205 |
206 | function _recaptcha_aes_pad($val) {
207 | $block_size = 16;
208 | $numpad = $block_size - (strlen ($val) % $block_size);
209 | return str_pad($val, strlen ($val) + $numpad, chr($numpad));
210 | }
211 |
212 | /* Mailhide related code */
213 |
214 | function _recaptcha_aes_encrypt($val,$ky) {
215 | if (! function_exists ("mcrypt_encrypt")) {
216 | die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
217 | }
218 | $mode=MCRYPT_MODE_CBC;
219 | $enc=MCRYPT_RIJNDAEL_128;
220 | $val=_recaptcha_aes_pad($val);
221 | return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
222 | }
223 |
224 |
225 | function _recaptcha_mailhide_urlbase64 ($x) {
226 | return strtr(base64_encode ($x), '+/', '-_');
227 | }
228 |
229 | /* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
230 | function recaptcha_mailhide_url($pubkey, $privkey, $email) {
231 | if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
232 | die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
233 | "you can do so at http://mailhide.recaptcha.net/apikey ");
234 | }
235 |
236 |
237 | $ky = pack('H*', $privkey);
238 | $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
239 |
240 | return "http://mailhide.recaptcha.net/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
241 | }
242 |
243 | /**
244 | * gets the parts of the email to expose to the user.
245 | * eg, given johndoe@example,com return ["john", "example.com"].
246 | * the email is then displayed as john...@example.com
247 | */
248 | function _recaptcha_mailhide_email_parts ($email) {
249 | $arr = preg_split("/@/", $email );
250 |
251 | if (strlen ($arr[0]) <= 4) {
252 | $arr[0] = substr ($arr[0], 0, 1);
253 | } else if (strlen ($arr[0]) <= 6) {
254 | $arr[0] = substr ($arr[0], 0, 3);
255 | } else {
256 | $arr[0] = substr ($arr[0], 0, 4);
257 | }
258 | return $arr;
259 | }
260 |
261 | /**
262 | * Gets html to display an email address given a public an private key.
263 | * to get a key, go to:
264 | *
265 | * http://mailhide.recaptcha.net/apikey
266 | */
267 | function recaptcha_mailhide_html($pubkey, $privkey, $email) {
268 | $emailparts = _recaptcha_mailhide_email_parts ($email);
269 | $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
270 |
271 | return htmlentities($emailparts[0]) . "... @" . htmlentities ($emailparts [1]);
273 |
274 | }
275 |
276 |
277 | ?>
278 |
--------------------------------------------------------------------------------
/libraries/template.class.php:
--------------------------------------------------------------------------------
1 | _controller = $controller;
10 | $this->_action = $action;
11 | }
12 |
13 | /** Set Variables **/
14 |
15 | function set($name,$value) {
16 | $this->variables[$name] = $value;
17 | }
18 |
19 | function overrideController($controller) {
20 | $this->_controller = $controller;
21 | }
22 |
23 | function overrideAction($action) {
24 | $this->_action = $action;
25 | }
26 |
27 | /** Display Template **/
28 |
29 | function render() {
30 |
31 | global $path;
32 |
33 | extract($this->variables);
34 |
35 | $controller = $this->_controller;
36 | $action = $this->_action;
37 |
38 | if (empty($noheader)) {
39 |
40 |
41 | include (ROOT . DS . 'views' . DS . 'header.php');
42 |
43 | if (file_exists(ROOT . DS . 'views' . DS . $this->_controller . DS . 'header.php')) {
44 | include (ROOT . DS . 'views' . DS . $this->_controller . DS . 'header.php');
45 | }
46 | }
47 |
48 | if (file_exists(ROOT . DS . 'views' . DS . $this->_controller . DS . $this->_action . '.php')) {
49 | include (ROOT . DS . 'views' . DS . $this->_controller . DS . $this->_action . '.php');
50 | }
51 |
52 | if (empty($noheader)) {
53 |
54 | if (file_exists(ROOT . DS . 'views' . DS . $this->_controller . DS . 'footer.php')) {
55 | include (ROOT . DS . 'views' . DS . $this->_controller . DS . 'footer.php');
56 | }
57 |
58 | include (ROOT . DS . 'views' . DS . 'footer.php');
59 |
60 |
61 | }
62 | exit();
63 | }
64 |
65 | }
--------------------------------------------------------------------------------
/libraries/timeago.php:
--------------------------------------------------------------------------------
1 | = 60 && $difference<60*60)
28 | {
29 | $interval = "n";
30 | }
31 |
32 | // If difference is between 1 hour and 24 hours
33 | // hours is a good interval
34 | elseif($difference >= 60*60 && $difference<60*60*24)
35 | {
36 | $interval = "h";
37 | }
38 |
39 | // If difference is between 1 day and 7 days
40 | // days is a good interval
41 | elseif($difference >= 60*60*24 && $difference<60*60*24*7)
42 | {
43 | $interval = "d";
44 | }
45 |
46 | // If difference is between 1 week and 30 days
47 | // weeks is a good interval
48 | elseif($difference >= 60*60*24*7 && $difference <
49 | 60*60*24*30)
50 | {
51 | $interval = "ww";
52 | }
53 |
54 | // If difference is between 30 days and 365 days
55 | // months is a good interval, again, the same thing
56 | // applies, if the 29th February happens to exist
57 | // between your 2 dates, the function will return
58 | // the 'incorrect' value for a day
59 | elseif($difference >= 60*60*24*30 && $difference <
60 | 60*60*24*365)
61 | {
62 | $interval = "m";
63 | }
64 |
65 | // If difference is greater than or equal to 365
66 | // days, return year. This will be incorrect if
67 | // for example, you call the function on the 28th April
68 | // 2008 passing in 29th April 2007. It will return
69 | // 1 year ago when in actual fact (yawn!) not quite
70 | // a year has gone by
71 | elseif($difference >= 60*60*24*365)
72 | {
73 | $interval = "y";
74 | }
75 |
76 | // Based on the interval, determine the
77 | // number of units between the two dates
78 | // From this point on, you would be hard
79 | // pushed telling the difference between
80 | // this function and DateDiff. If the $datediff
81 | // returned is 1, be sure to return the singular
82 | // of the unit, e.g. 'day' rather 'days'
83 |
84 | switch($interval)
85 | {
86 | case "m":
87 | $months_difference = floor($difference / 60 / 60 / 24 /
88 | 29);
89 | while (mktime(date("H", $datefrom), date("i", $datefrom),
90 | date("s", $datefrom), date("n", $datefrom)+($months_difference),
91 | date("j", $dateto), date("Y", $datefrom)) < $dateto)
92 | {
93 | $months_difference++;
94 | }
95 | $datediff = $months_difference;
96 |
97 | // We need this in here because it is possible
98 | // to have an 'm' interval and a months
99 | // difference of 12 because we are using 29 days
100 | // in a month
101 |
102 | if($datediff==12)
103 | {
104 | $datediff--;
105 | }
106 |
107 | $res = ($datediff==1) ? "$datediff mnth" : "$datediff
108 | mnths";
109 | $res = datifyunix($datefrom);
110 | break;
111 |
112 | case "y":
113 | $datediff = floor($difference / 60 / 60 / 24 / 365);
114 | $res = ($datediff==1) ? "$datediff yr" : "$datediff
115 | yrs";
116 |
117 | $res = datifyunix($datefrom);
118 | break;
119 |
120 | case "d":
121 | $datediff = floor($difference / 60 / 60 / 24);
122 | $res = ($datediff==1) ? "$datediff day ago" : "$datediff
123 | days ago";
124 | break;
125 |
126 | case "ww":
127 | $datediff = floor($difference / 60 / 60 / 24 / 7);
128 | $res = ($datediff==1) ? "$datediff wk" : "$datediff
129 | wks";
130 | $res = datifyunix($datefrom);
131 | break;
132 |
133 | case "h":
134 | $datediff = floor($difference / 60 / 60);
135 | $res = ($datediff==1) ? "$datediff hr ago" : "$datediff
136 | hrs ago";
137 | break;
138 |
139 | case "n":
140 | $datediff = floor($difference / 60);
141 | $res = ($datediff==1) ? "$datediff min ago" :
142 | "$datediff mins ago";
143 | break;
144 |
145 | case "s":
146 | $datediff = $difference;
147 | $res = ($datediff==1) ? "$datediff sec ago" :
148 | "$datediff secs ago";
149 | break;
150 | }
151 | return $res;
152 | }
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 | function TimeHours($datefrom,$dateto=-1)
161 | {
162 | // Defaults and assume if 0 is passed in that
163 | // its an error rather than the epoch
164 |
165 | if($dateto==-1) { $dateto = time(); }
166 |
167 |
168 | // Calculate the difference in seconds betweeen
169 | // the two timestamps
170 | $difference = $dateto - $datefrom;
171 |
172 | if ($difference < 0 ) {
173 | return 'n/a';
174 | }
175 | // If difference is less than 60 seconds,
176 | // seconds is a good interval of choice
177 |
178 | if($difference < 60)
179 | {
180 | $interval = "s";
181 | }
182 |
183 | // If difference is between 60 seconds and
184 | // 60 minutes, minutes is a good interval
185 | elseif($difference >= 60 && $difference<60*60)
186 | {
187 | $interval = "n";
188 | }
189 |
190 | // If difference is between 1 hour and 24 hours
191 | // hours is a good interval
192 | elseif($difference >= 60*60 )
193 | {
194 | $interval = "h";
195 | }
196 |
197 | switch($interval)
198 | {
199 | case "m":
200 | $months_difference = floor($difference / 60 / 60 / 24 /
201 | 29);
202 | while (mktime(date("H", $datefrom), date("i", $datefrom),
203 | date("s", $datefrom), date("n", $datefrom)+($months_difference),
204 | date("j", $dateto), date("Y", $datefrom)) < $dateto)
205 | {
206 | $months_difference++;
207 | }
208 | $datediff = $months_difference;
209 |
210 | // We need this in here because it is possible
211 | // to have an 'm' interval and a months
212 | // difference of 12 because we are using 29 days
213 | // in a month
214 |
215 | if($datediff==12)
216 | {
217 | $datediff--;
218 | }
219 |
220 | $res = ($datediff==1) ? "$datediff mnth" : "$datediff
221 | mnths";
222 | break;
223 |
224 | case "y":
225 | $datediff = floor($difference / 60 / 60 / 24 / 365);
226 | $res = ($datediff==1) ? "$datediff yr" : "$datediff
227 | yrs";
228 | break;
229 |
230 | case "d":
231 | $datediff = floor($difference / 60 / 60 / 24);
232 | $res = ($datediff==1) ? "$datediff day" : "$datediff
233 | days";
234 | break;
235 |
236 | case "ww":
237 | $datediff = floor($difference / 60 / 60 / 24 / 7);
238 | $res = ($datediff==1) ? "$datediff wk" : "$datediff
239 | wks";
240 | break;
241 |
242 | case "h":
243 | $datediff = floor($difference / 60 / 60);
244 | $res = ($datediff==1) ? "$datediff hr" : "$datediff
245 | hrs";
246 | break;
247 |
248 | case "n":
249 | $datediff = floor($difference / 60);
250 | $res = ($datediff==1) ? "$datediff min" :
251 | "$datediff mins";
252 | break;
253 |
254 | case "s":
255 | $datediff = $difference;
256 | $res = ($datediff==1) ? "$datediff sec" :
257 | "$datediff secs";
258 | break;
259 | }
260 | return $res;
261 | }
262 |
--------------------------------------------------------------------------------
/libraries/twitter/twitter.php:
--------------------------------------------------------------------------------
1 | http_status; }
54 | function lastAPICall() { return $this->last_api_call; }
55 |
56 | /**
57 | * construct TwitterOAuth object
58 | */
59 | function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
60 | $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
61 | $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
62 | if (!empty($oauth_token) && !empty($oauth_token_secret)) {
63 | $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
64 | } else {
65 | $this->token = NULL;
66 | }
67 | }
68 |
69 |
70 | /**
71 | * Get a request_token from Twitter
72 | *
73 | * @returns a key/value array containing oauth_token and oauth_token_secret
74 | */
75 | function getRequestToken($oauth_callback) {
76 | $parameters = array();
77 | $parameters['oauth_callback'] = $oauth_callback;
78 | $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
79 | $token = OAuthUtil::parse_parameters($request);
80 | $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
81 | return $token;
82 | }
83 |
84 | /**
85 | * Get the authorize URL
86 | *
87 | * @returns a string
88 | */
89 | function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
90 | if (is_array($token)) {
91 | $token = $token['oauth_token'];
92 | }
93 | if (empty($sign_in_with_twitter)) {
94 | return $this->authorizeURL() . "?oauth_token={$token}";
95 | } else {
96 | return $this->authenticateURL() . "?oauth_token={$token}";
97 | }
98 | }
99 |
100 | /**
101 | * Exchange request token and secret for an access token and
102 | * secret, to sign API calls.
103 | *
104 | * @returns array("oauth_token" => "the-access-token",
105 | * "oauth_token_secret" => "the-access-secret",
106 | * "user_id" => "9436992",
107 | * "screen_name" => "abraham")
108 | */
109 | function getAccessToken($oauth_verifier) {
110 | $parameters = array();
111 | $parameters['oauth_verifier'] = $oauth_verifier;
112 | $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
113 | $token = OAuthUtil::parse_parameters($request);
114 | $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
115 | return $token;
116 | }
117 |
118 | /**
119 | * One time exchange of username and password for access token and secret.
120 | *
121 | * @returns array("oauth_token" => "the-access-token",
122 | * "oauth_token_secret" => "the-access-secret",
123 | * "user_id" => "9436992",
124 | * "screen_name" => "abraham",
125 | * "x_auth_expires" => "0")
126 | */
127 | function getXAuthToken($username, $password) {
128 | $parameters = array();
129 | $parameters['x_auth_username'] = $username;
130 | $parameters['x_auth_password'] = $password;
131 | $parameters['x_auth_mode'] = 'client_auth';
132 | $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
133 | $token = OAuthUtil::parse_parameters($request);
134 | $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
135 | return $token;
136 | }
137 |
138 | /**
139 | * GET wrapper for oAuthRequest.
140 | */
141 | function get($url, $parameters = array()) {
142 | $response = $this->oAuthRequest($url, 'GET', $parameters);
143 | if ($this->format === 'json' && $this->decode_json) {
144 | return json_decode($response);
145 | }
146 | return $response;
147 | }
148 |
149 | /**
150 | * POST wrapper for oAuthRequest.
151 | */
152 | function post($url, $parameters = array()) {
153 | $response = $this->oAuthRequest($url, 'POST', $parameters);
154 | if ($this->format === 'json' && $this->decode_json) {
155 | return json_decode($response);
156 | }
157 | return $response;
158 | }
159 |
160 | /**
161 | * DELETE wrapper for oAuthReqeust.
162 | */
163 | function delete($url, $parameters = array()) {
164 | $response = $this->oAuthRequest($url, 'DELETE', $parameters);
165 | if ($this->format === 'json' && $this->decode_json) {
166 | return json_decode($response);
167 | }
168 | return $response;
169 | }
170 |
171 | /**
172 | * Format and sign an OAuth / API request
173 | */
174 | function oAuthRequest($url, $method, $parameters) {
175 | if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
176 | $url = "{$this->host}{$url}.{$this->format}";
177 | }
178 | $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
179 | $request->sign_request($this->sha1_method, $this->consumer, $this->token);
180 | switch ($method) {
181 | case 'GET':
182 | return $this->http($request->to_url(), 'GET');
183 | default:
184 | return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
185 | }
186 | }
187 |
188 | /**
189 | * Make an HTTP request
190 | *
191 | * @return API results
192 | */
193 | function http($url, $method, $postfields = NULL) {
194 | $this->http_info = array();
195 | $ci = curl_init();
196 | /* Curl settings */
197 | curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
198 | curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
199 | curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
200 | curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
201 | curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
202 | curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
203 | curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
204 | curl_setopt($ci, CURLOPT_HEADER, FALSE);
205 |
206 | switch ($method) {
207 | case 'POST':
208 | curl_setopt($ci, CURLOPT_POST, TRUE);
209 | if (!empty($postfields)) {
210 | curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
211 | }
212 | break;
213 | case 'DELETE':
214 | curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
215 | if (!empty($postfields)) {
216 | $url = "{$url}?{$postfields}";
217 | }
218 | }
219 |
220 | curl_setopt($ci, CURLOPT_URL, $url);
221 | $response = curl_exec($ci);
222 | $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
223 | $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
224 | $this->url = $url;
225 | curl_close ($ci);
226 | return $response;
227 | }
228 |
229 | /**
230 | * Get the header info to store.
231 | */
232 | function getHeader($ch, $header) {
233 | $i = strpos($header, ':');
234 | if (!empty($i)) {
235 | $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
236 | $value = trim(substr($header, $i + 2));
237 | $this->http_header[$key] = $value;
238 | }
239 | return strlen($header);
240 | }
241 | }
242 |
--------------------------------------------------------------------------------
/libraries/uaparser.class.php:
--------------------------------------------------------------------------------
1 | regexes
42 | */
43 | public function __construct($customRegexesFile = null) {
44 |
45 | $regexesFile = ($customRegexesFile !== null) ? $customRegexesFile : dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'data/regexes.json';
46 | if (file_exists($regexesFile)) {
47 | $this->regexes = json_decode(file_get_contents($regexesFile));
48 | } else {
49 | $title = 'Error loading ua-parser';
50 | if ($customRegexesFile !== null) {
51 | $message = 'ua-parser can\'t find the custom regexes file you supplied ('.$customRegexesFile.'). Please make sure you have the correct path.';
52 | } else {
53 | $message = 'Please download the regexes.json file before using uaparser.php.';
54 | if ( php_sapi_name() == 'cli' ) {
55 | $message .= ' (php uaparser-cli.php -g)';
56 | }
57 | }
58 |
59 | throw new FileNotFound_Exception($message);
60 | }
61 | }
62 |
63 | /**
64 | * Sets up some standard variables as well as starts the user agent parsing process
65 | * @param string a user agent string to test, defaults to an empty string
66 | * @return object the result of the user agent parsing
67 | */
68 | public function parse($ua = '') {
69 |
70 | // build the default obj that will be returned
71 | $result = (object) array(
72 | 'ua' => (object) array(),
73 | 'os' => (object) array(),
74 | 'device' => (object) array(),
75 | 'toFullString' => '',
76 | 'uaOriginal' => $ua
77 | );
78 |
79 | // figure out the ua, os, and device properties if possible
80 | $result->ua = $this->uaParse($ua);
81 | $result->os = $this->osParse($ua);
82 | $result->device = $this->deviceParse($ua);
83 |
84 | // create a full string version based on the ua and os objects
85 | $result->toFullString = $this->toFullString($result->ua, $result->os);
86 |
87 | // log the results when testing
88 | if ($this->log) {
89 | $this->log($result);
90 | }
91 |
92 | return $result;
93 |
94 | }
95 |
96 | /**
97 | * Attempts to see if the user agent matches a user_agents_parsers regex from regexes.json
98 | * @param string a user agent string to test
99 | * @return object the result of the user agent parsing
100 | */
101 | public function uaParse($uaString = '') {
102 |
103 | // build the default obj that will be returned
104 | $ua = (object) array(
105 | 'family' => 'Other',
106 | 'major' => null,
107 | 'minor' => null,
108 | 'patch' => null,
109 | 'toString' => '',
110 | 'toVersionString' => ''
111 | );
112 |
113 | // run the regexes to match things up
114 | $uaRegexes = $this->regexes->user_agent_parsers;
115 | foreach ($uaRegexes as $uaRegex) {
116 |
117 | // tests the supplied regex against the user agent
118 | if (preg_match('/'.str_replace('/','\/',str_replace('\/','/',$uaRegex->regex)).'/i',$uaString,$matches)) {
119 |
120 | // Make sure matches are at least set to null or Other
121 | if (!isset($matches[1])) { $matches[1] = 'Other'; }
122 | if (!isset($matches[2])) { $matches[2] = null; }
123 | if (!isset($matches[3])) { $matches[3] = null; }
124 | if (!isset($matches[4])) { $matches[4] = null; }
125 |
126 | // ua name
127 | $ua->family = isset($uaRegex->family_replacement) ? str_replace('$1',$matches[1],$uaRegex->family_replacement) : $matches[1];
128 |
129 | // version properties
130 | $ua->major = isset($uaRegex->v1_replacement) ? $uaRegex->v1_replacement : $matches[2];
131 | $ua->minor = isset($uaRegex->v2_replacement) ? $uaRegex->v2_replacement : $matches[3];
132 | $ua->patch = isset($uaRegex->v3_replacement) ? $uaRegex->v3_replacement : $matches[4];
133 |
134 | // extra strings
135 | $ua->toString = $this->toString($ua);
136 | $ua->toVersionString = $this->toVersionString($ua);
137 |
138 | return $ua;
139 | }
140 |
141 | }
142 |
143 | return $ua;
144 |
145 | }
146 |
147 | /**
148 | * Attempts to see if the user agent matches an os_parsers regex from regexes.json
149 | * @param string a user agent string to test
150 | * @return object the result of the os parsing
151 | */
152 | public function osParse($uaString = '') {
153 |
154 | // build the default obj that will be returned
155 | $os = (object) array(
156 | 'family' => 'Other',
157 | 'major' => null,
158 | 'minor' => null,
159 | 'patch' => null,
160 | 'patch_minor' => null,
161 | 'toString' => '',
162 | 'toVersionString' => ''
163 | );
164 |
165 | // run the regexes to match things up
166 | $osRegexes = $this->regexes->os_parsers;
167 | foreach ($osRegexes as $osRegex) {
168 |
169 | if (preg_match('/'.str_replace('/','\/',str_replace('\/','/',$osRegex->regex)).'/i',$uaString,$matches)) {
170 |
171 | // Make sure matches are at least set to null or Other
172 | if (!isset($matches[1])) { $matches[1] = 'Other'; }
173 | if (!isset($matches[2])) { $matches[2] = null; }
174 | if (!isset($matches[3])) { $matches[3] = null; }
175 | if (!isset($matches[4])) { $matches[4] = null; }
176 | if (!isset($matches[5])) { $matches[5] = null; }
177 |
178 | // os name
179 | $os->family = isset($osRegex->os_replacement) ? $osRegex->os_replacement : $matches[1];
180 |
181 | // version properties
182 | $os->major = isset($osRegex->os_v1_replacement) ? $osRegex->os_v1_replacement : $matches[2];
183 | $os->minor = isset($osRegex->os_v2_replacement) ? $osRegex->os_v2_replacement : $matches[3];
184 | $os->patch = isset($osRegex->os_v3_replacement) ? $osRegex->os_v3_replacement : $matches[4];
185 | $os->patch_minor = isset($osRegex->os_v4_replacement) ? $osRegex->os_v4_replacement : $matches[5];
186 |
187 | // extra strings
188 | $os->toString = $this->toString($os);
189 | $os->toVersionString = $this->toVersionString($os);
190 |
191 | return $os;
192 | }
193 |
194 | }
195 |
196 | return $os;
197 |
198 | }
199 |
200 | /**
201 | * Attempts to see if the user agent matches a device_parsers regex from regexes.json
202 | * @param string a user agent string to test
203 | * @return object the result of the device parsing
204 | */
205 | public function deviceParse($uaString = '') {
206 |
207 | // build the default obj that will be returned
208 | $device = (object) array(
209 | 'family' => 'Other'
210 | );
211 |
212 | // run the regexes to match things up
213 | $deviceRegexes = $this->regexes->device_parsers;
214 | foreach ($deviceRegexes as $deviceRegex) {
215 |
216 | if (preg_match('/'.str_replace('/','\/',str_replace('\/','/',$deviceRegex->regex)).'/i',$uaString,$matches)) {
217 |
218 | // Make sure matches are at least set to null or Other
219 | if (!isset($matches[1])) { $matches[1] = 'Other'; }
220 |
221 | // device name
222 | $device->family = isset($deviceRegex->device_replacement) ? str_replace('$1',str_replace("_"," ",$matches[1]),$deviceRegex->device_replacement) : str_replace("_"," ",$matches[1]);
223 |
224 | return $device;
225 |
226 | }
227 |
228 | }
229 |
230 | return $device;
231 |
232 | }
233 |
234 | /**
235 | * Returns a string consisting of the family and full version number based on the provided type
236 | * @param object the object (ua or os) to be used
237 | * @return string the result of combining family and version
238 | */
239 | public function toString($obj) {
240 |
241 | $versionString = $this->toVersionString($obj);
242 | $string = !empty($versionString) ? $obj->family.' '.$versionString : $obj->family;
243 |
244 | return $string;
245 | }
246 |
247 | /**
248 | * Returns a string consisting of just the full version number based on the provided type
249 | * @param object the obj that contains version number bits
250 | * @return string the result of combining the version number bits together
251 | */
252 | public function toVersionString($obj) {
253 |
254 | $versionString = isset($obj->major) ? $obj->major : '';
255 | $versionString = isset($obj->minor) ? $versionString.'.'.$obj->minor : $versionString;
256 | $versionString = isset($obj->patch) ? $versionString.'.'.$obj->patch : $versionString;
257 | $versionString = isset($obj->patch_minor) ? $versionString.'.'.$obj->patch_minor : $versionString;
258 |
259 | return $versionString;
260 |
261 | }
262 |
263 | /**
264 | * Returns a string consistig of the family and full version number for both the browser and os
265 | * @param object the ua object
266 | * @param object the os object
267 | * @return string the result of combining family and version
268 | */
269 | public function toFullString($ua,$os) {
270 |
271 | $fullString = $this->toString($ua).'/'.$this->toString($os);
272 |
273 | return $fullString;
274 |
275 | }
276 |
277 | /**
278 | * Logs the user agent info
279 | */
280 | protected function log($data) {
281 | $jsonData = json_encode($data);
282 | $fp = fopen(dirname(__FILE__).DIRECTORY_SEPARATOR.'log/user_agents.log', 'a');
283 | fwrite($fp, $jsonData."\r\n");
284 | fclose($fp);
285 | }
286 |
287 | }
288 |
289 | class FileNotFound_Exception extends Exception {}
--------------------------------------------------------------------------------
/views/connect/facebook.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
Choose a Page
5 |
Connect any of your Facebook pages to add to SocialTurn.
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
26 |
27 |
28 |
29 |
30 |
Sorry, we are unable to find any pages associated with your account.
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/views/connect/index.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
Connect a Social Network
5 |
Share to many different places with SocialTurn and we make sure your posts look great everywhere. Click the 'Connect' buttons below to begin connecting your account to SocialPost:
6 |
7 |
8 |
9 |
10 |
27 |
28 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
55 |
56 | Connect
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
Connected Networks
70 |
Re-connect or delete your existing networks
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/views/footer.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
27 |
28 |
31 |
36 |
37 |
38 |
39 |
40 |
41 |
45 |
46 | Cancel
47 | Continue
48 |
49 |
50 |
51 |
52 |
53 |
63 |
64 |