wp-jalali - Version 3.5

Version Description

Download this release

Release Info

Developer mani_monaj
Plugin Icon 128x128 wp-jalali
Version 3.5
Comparing to
See all releases

Version 3.5

Files changed (5) hide show
  1. farsitype.js +378 -0
  2. mps-jalalidate35.php +1812 -0
  3. readme.txt +46 -0
  4. screenshot-1.png +0 -0
  5. wp-fa-logo.png +0 -0
farsitype.js ADDED
@@ -0,0 +1,378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ FARSI TYPE
3
+ This script developed to ease typing Farsi(Persian) in web forms where there is no Farsi Keyboard installed on a PC.Works with Internet Explorer, Gecko family (Mozilla/FireFox) and Opera.
4
+
5
+ Author : Kaveh Ahmadi
6
+ Author Contact : kaveh@ashoob.net
7
+ Version : 1.3.0
8
+
9
+ Copyright 2002-2007 Kaveh Ahmadi (email : kaveh@ashoob.net)
10
+ Special Thanks to Gonahkar (gonahkar.com), Mani Monajjemi (manionline.org) and Mazdak Aghakhani (mazdakam.com) for their support and their great ideas!
11
+
12
+ This program is free software; you can redistribute it and/or modify
13
+ it under the terms of the GNU General Public License as published by
14
+ the Free Software Foundation; either version 2 of the License, or
15
+ (at your option) any later version.
16
+
17
+ This program is distributed in the hope that it will be useful,
18
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ GNU General Public License for more details.
21
+
22
+ You should have received a copy of the GNU General Public License
23
+ along with this program; if not, write to the Free Software
24
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
+
26
+ > > > USAGE < < <
27
+
28
+ Step 0. Customize settings
29
+ Set ShowChangeLangButton, KeyBoardError, ChangeDir variables values with your own opinon!
30
+ ShowChangeLangButton // Show Change Language Button --> 0: Show / 1: Visible
31
+ KeyBoardError // the action when useres keyboard is farsi --> 0: Disable FarsiType / 1: Show Error
32
+ ChangeDir // change the input or textarea direction when language is change --> 0: No Action / 1: Change direction / 2: set Rtl/Ltr button
33
+
34
+ Step 1.
35
+ Include the "farsitype.js" file to your HTML <head> part (before </head>):
36
+ <script language="javascript" src="farsitype.js" type="text/javascript"></script>
37
+
38
+ Step 2.
39
+ Add "lang" attribute with value "fa" to any <input> or <textarea> tag which you want to have FarsiType enabled!
40
+ <input type="text" name="whatever" lang="fa" />
41
+ or
42
+ <textarea cols="30" rows="7" name="whatever" lang="fa"></textarea>
43
+ [Magic : only the lang="fa" is important for FarsiType!]
44
+ [As ver 1.2.1 , you can also use lang="fa-IR"]
45
+
46
+ Step 3. (OPTIONAL)
47
+ You can also add an enable/disable checkbox beside your form.
48
+ <input type="checkbox" id="disableFarsiType" />
49
+
50
+ Note : You can use F8 keybord button to switch languages instead of using the change language button.
51
+
52
+ > > > CHANFGELOG < < <
53
+
54
+ V 1.3.0
55
+ - Optional controls is added for users
56
+
57
+ V 1.2.1
58
+ - Comments clean up
59
+ - GPL Licence added
60
+ - lang = 'fa-IR' support added
61
+
62
+ V 1.2
63
+ - Opera full support added
64
+
65
+ V 1.1
66
+ - Some little Gecko fixes
67
+
68
+ > > > EXTRA < < <
69
+ Mozilla solving problem idea is from: http://forum.persiantools.com/showthread.php?p=667351
70
+ Auto Creation idea is from: http://ip.webkar.com/forums/index.php?act=ST&f=19&t=99
71
+ with a look at behdad.org/editor and blogfa.com farsi solutions!
72
+ */
73
+
74
+ // insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement() for Netscape 6/Mozilla by Thor Larholm me@jscript.dk
75
+ if(typeof HTMLElement!="undefined" && ! HTMLElement.prototype.insertAdjacentElement) {
76
+ HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode) {
77
+ switch (where) {
78
+ case 'beforeBegin':
79
+ this.parentNode.insertBefore(parsedNode,this)
80
+ break;
81
+ case 'afterBegin':
82
+ this.insertBefore(parsedNode,this.firstChild);
83
+ break;
84
+ case 'beforeEnd':
85
+ this.appendChild(parsedNode);
86
+ break;
87
+ case 'afterEnd':
88
+ if (this.nextSibling)
89
+ this.parentNode.insertBefore(parsedNode,this.nextSibling);
90
+ else
91
+ this.parentNode.appendChild(parsedNode);
92
+ break;
93
+ }
94
+ }
95
+
96
+ HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr) {
97
+ var r = this.ownerDocument.createRange();
98
+ r.setStartBefore(this);
99
+ var parsedHTML = r.createContextualFragment(htmlStr);
100
+ this.insertAdjacentElement(where,parsedHTML)
101
+ }
102
+
103
+ HTMLElement.prototype.insertAdjacentText = function (where,txtStr) {
104
+ var parsedText = document.createTextNode(txtStr)
105
+ this.insertAdjacentElement(where,parsedText)
106
+ }
107
+ }
108
+
109
+ var FarsiType =
110
+ {
111
+ // Farsi keyboard map based on Iran Popular Keyboard Layout
112
+ farsiKey : [
113
+ 32 , 33 , 34 , 35 , 36 , 37 , 1548 , 1711 ,
114
+ 41 , 40 , 215 , 43 , 1608 , 45 , 46 , 47 ,
115
+ 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 ,
116
+ 56 , 57 , 58 , 1705 , 44 , 61 , 46 , 1567 ,
117
+ 64 , 1616 , 1584 , 125 , 1609 , 1615 , 1609 , 1604 ,
118
+ 1570 , 247 , 1600 , 1548 , 47 , 8217 , 1583 , 215 ,
119
+ 1563 , 1614 , 1569 , 1613 , 1601 , 8216 , 123 , 1611 ,
120
+ 1618 , 1573 , 126 , 1580 , 1688 , 1670 , 94 , 95 ,
121
+ 1662 , 1588 , 1584 , 1586 , 1740 , 1579 , 1576 , 1604 ,
122
+ 1575 , 1607 , 1578 , 1606 , 1605 , 1574 , 1583 , 1582 ,
123
+ 1581 , 1590 , 1602 , 1587 , 1601 , 1593 , 1585 , 1589 ,
124
+ 1591 , 1594 , 1592 , 60 , 124 , 62 , 1617
125
+ ],
126
+ Type : true,
127
+ counter : 0,
128
+ ShowChangeLangButton : 1, // 0: Show / 1: Visible
129
+ KeyBoardError : 0, // 0: Disable FarsiType / 1: Show Error
130
+ ChangeDir : 2 // 0: No Action / 1: Do Rtl-Ltr / 2: Rtl-Ltr button
131
+ }
132
+
133
+ FarsiType.enable_disable = function(Dis) {
134
+ var invis, obj;
135
+
136
+ if (!Dis.checked) {
137
+ FarsiType.Type = true;
138
+ disable = false;
139
+ color = 'darkblue';
140
+ }
141
+ else {
142
+ FarsiType.Type = false;
143
+ disable = true;
144
+ color = '#ECE9D8';
145
+ }
146
+
147
+ if (FarsiType.ShowChangeLangButton == 1) {
148
+ for (var i=1; i<= FarsiType.counter; i++) {
149
+ obj = document.getElementById('FarsiType_button_' + i);
150
+ obj.disabled = disable;
151
+ obj.style.backgroundColor = color;
152
+ }
153
+ }
154
+ }
155
+
156
+ FarsiType.Disable = function(){
157
+ FarsiType.Type = false;
158
+ var Dis = document.getElementById('disableFarsiType')
159
+ if (Dis != null) {
160
+ Dis.checked = true;
161
+ }
162
+ if (FarsiType.ShowChangeLangButton == 1) {
163
+ for (var i=1; i<= FarsiType.counter; i++) {
164
+ obj = document.getElementById('FarsiType_button_' + i);
165
+ obj.disabled = true;
166
+ obj.style.backgroundColor = '#ECE9D8';
167
+ }
168
+ }
169
+ }
170
+
171
+ FarsiType.init = function() {
172
+
173
+ var Inputs = document.getElementsByTagName('INPUT');
174
+ for (var i=0; i<Inputs.length; i++) {
175
+ if (Inputs[i].type.toLowerCase() == 'text' && (Inputs[i].lang.toLowerCase() == 'fa' || Inputs[i].lang.toLowerCase() == 'fa-ir')) {
176
+ FarsiType.counter++;
177
+ new FarsiType.KeyObject(Inputs[i], FarsiType.counter);
178
+ }
179
+ }
180
+
181
+ var Areas = document.getElementsByTagName('TEXTAREA');
182
+ for (var i=0; i<Areas.length; i++) {
183
+ if (Areas[i].lang.toLowerCase() == 'fa' || Areas[i].lang.toLowerCase() == 'fa-ir') {
184
+ FarsiType.counter++;
185
+ new FarsiType.KeyObject(Areas[i], FarsiType.counter);
186
+ }
187
+ }
188
+
189
+ var Dis = document.getElementById('disableFarsiType')
190
+ if (Dis != null) {
191
+ FarsiType.enable_disable (Dis);
192
+ Dis.onclick = new Function( "FarsiType.enable_disable (this);" )
193
+ }
194
+ }
195
+
196
+ FarsiType.KeyObject = function(z,x) {
197
+
198
+ GenerateStr = "";
199
+ if (FarsiType.ShowChangeLangButton == 1) {
200
+ GenerateStr = GenerateStr + "<input type='button' id=FarsiType_button_"+x+" style='border: none; background-color:darkblue; font-size:11; color:white; font-family:tahoma; padding: 1px; margin: 1px; width: auto; height: auto;' value='FA' />&nbsp;";
201
+ }
202
+ if (FarsiType.ChangeDir == 2) {
203
+ GenerateStr = GenerateStr + "<input type='button' id=FarsiType_ChangeDir_"+x+" style='border: none; background-color:darkblue; font-size:11; color:white; font-family:tahoma; padding: 1px; margin: 1px; width: auto; height: auto;' value='RTL' />"
204
+ }
205
+ z.insertAdjacentHTML("afterEnd", GenerateStr);
206
+
207
+ if (FarsiType.ShowChangeLangButton == 1) {
208
+ z.bottelm = document.getElementById ('FarsiType_button_' + x);
209
+ z.bottelm.title = 'Change lang to english';
210
+ }
211
+ if (FarsiType.ChangeDir == 2) {
212
+ z.Direlm = document.getElementById ('FarsiType_ChangeDir_' + x);
213
+ }
214
+
215
+ z.farsi = true;
216
+ z.dir = "rtl";
217
+ z.align = "right";
218
+
219
+ z.style.textAlign = z.align;
220
+ z.style.direction = z.dir;
221
+
222
+ setSelectionRange = function(input, selectionStart, selectionEnd) {
223
+ input.focus()
224
+ input.setSelectionRange(selectionStart, selectionEnd)
225
+ }
226
+
227
+ ChangeDirection = function(e) {
228
+ if (z.dir == "rtl") {
229
+ z.dir = "ltr";
230
+ z.align = "left";
231
+ z.Direlm.value = "LTR";
232
+ z.Direlm.title = "Change direction: Right to Left"
233
+ }
234
+ else {
235
+ z.dir = "rtl";
236
+ z.align = "right";
237
+ z.Direlm.value = "RTL";
238
+ z.Direlm.title = "Change direction: Left to Right"
239
+ }
240
+ z.style.textAlign = z.align;
241
+ z.style.direction = z.dir;
242
+ z.focus();
243
+ }
244
+
245
+ ChangeLang = function(e) {
246
+ if (e == null) e = window.event;
247
+ var key = e.keyCode ? e.keyCode : e.charCode;
248
+
249
+ if (FarsiType.Type) {
250
+ if (key==119 || !key) {
251
+ if (z.farsi) {
252
+ z.farsi = false;
253
+ if (FarsiType.ShowChangeLangButton == 1) {
254
+ z.bottelm.value = "EN";
255
+ z.bottelm.title = 'Change lang to persian';
256
+ }
257
+ if (FarsiType.ChangeDir == 1) {
258
+ z.style.textAlign = "left";
259
+ z.style.direction = "ltr";
260
+ }
261
+ }
262
+ else {
263
+ z.farsi = true;
264
+ if (FarsiType.ShowChangeLangButton == 1) {
265
+ z.bottelm.value = "FA";
266
+ z.bottelm.title = 'Change lang to english';
267
+ }
268
+ if (FarsiType.ChangeDir == 1) {
269
+ z.style.textAlign = "right";
270
+ z.style.direction = "rtl";
271
+ }
272
+ }
273
+ z.focus();
274
+ }
275
+ }
276
+ }
277
+
278
+ Convert = function(e) {
279
+
280
+ if (FarsiType.Type) {
281
+
282
+ if (e == null) e = window.event;
283
+ eElement = (e.srcElement) ? e.srcElement : e.originalTarget;
284
+
285
+ var key = e.keyCode ? e.keyCode : e.charCode;
286
+ if (navigator.userAgent.toLowerCase().indexOf('opera')>-1) key = e.which;
287
+
288
+ if ( (e.charCode != null) && (e.charCode != key) ) return;
289
+ if (e.ctrlKey || e.altKey || e.metaKey || key == 13 || key == 27 || key == 8) return;
290
+
291
+ //check windows lang
292
+ if (key>128){
293
+ if (FarsiType.KeyBoardError == 0) {
294
+ FarsiType.Disable();
295
+ }
296
+ else {
297
+ alert("Please change your windows language to English");
298
+ return false;
299
+ }
300
+ }
301
+
302
+ // if Farsi
303
+ if (z.farsi && key > 31 && key < 128) {
304
+
305
+ //check CpasLock
306
+ if ( (key >= 65 && key <= 90) && !e.shiftKey ) {
307
+ alert("Caps Lock is On. To prevent entering farsi incorrectly, you should press Caps Lock to turn it off.");
308
+ return false;
309
+ }
310
+ else if ( (key >= 97 && key <= 122 ) && e.shiftKey ) {
311
+ alert("Caps Lock is On. To prevent entering farsi incorrectly, you should press Caps Lock to turn it off.");
312
+ return false;
313
+ }
314
+
315
+ // Shift-space -> ZWNJ
316
+ if (key == 32 && e.shiftKey)
317
+ key = 8204;
318
+ else
319
+ key = FarsiType.farsiKey[key-32];
320
+
321
+ // to farsi
322
+ try {
323
+ // IE
324
+ e.keyCode = key
325
+ }
326
+ catch(error) {
327
+ try {
328
+ // Gecko before
329
+ e.initKeyEvent("keypress", true, true, document.defaultView, false, false, true, false, 0, key, eElement);
330
+ }
331
+ catch(error) {
332
+ try {
333
+ // Gecko & Opera now
334
+ var nScrollTop = eElement.scrollTop;
335
+ var nScrollLeft = eElement.scrollLeft;
336
+ var nScrollWidth = eElement.scrollWidth;
337
+
338
+ replaceString = String.fromCharCode(key);
339
+
340
+ var selectionStart = eElement.selectionStart;
341
+ var selectionEnd = eElement.selectionEnd;
342
+ eElement.value = eElement.value.substring(0, selectionStart) + replaceString + eElement.value.substring(selectionEnd);
343
+ setSelectionRange(eElement, selectionStart + replaceString.length, selectionStart + replaceString.length);
344
+
345
+ var nW = eElement.scrollWidth - nScrollWidth;
346
+ if (eElement.scrollTop == 0) { eElement.scrollTop = nScrollTop }
347
+
348
+ e.preventDefault()
349
+ }
350
+ catch(error) {
351
+ // else no farsi type!
352
+ alert('Sorry! no FarsiType support')
353
+ FarsiType.Disable();
354
+ var Dis = document.getElementById('disableFarsiType')
355
+ if (Dis != null) {
356
+ Dis.disabled = true;
357
+ }
358
+ return false;
359
+ }
360
+ }
361
+ }
362
+ }
363
+ }
364
+ return true;
365
+ }
366
+
367
+ if (FarsiType.ShowChangeLangButton == 1) { z.bottelm.onmouseup = ChangeLang; }
368
+ if (FarsiType.ChangeDir == 2) { z.Direlm.onmouseup = ChangeDirection; }
369
+ z.onkeydown = ChangeLang;
370
+ z.onkeypress = Convert;
371
+ }
372
+
373
+ if (window.attachEvent) {
374
+ window.attachEvent('onload', FarsiType.init)
375
+ }
376
+ else if (window.addEventListener) {
377
+ window.addEventListener('load', FarsiType.init, false)
378
+ }
mps-jalalidate35.php ADDED
@@ -0,0 +1,1812 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Full Jalali Date & Persian Support Package for Wordpress
4
+ Plugin URI: http://www.wp-persian.com/wp-jalali/
5
+ Description: Full Jalali Date and Persian(Farsi) Support Package for wordpress, Full posts' and comments' dates convertion , Jalali Archive , Magic(Jalali/Gregorian) Calendar and Jalali/Gregorian Compaitables Permalinks, TinyMCE RTL/LTR activation, TinyMCE Persian Improvement, Cross browser Perisan keyboard support, Jalali Archive/Calendar widgets and Persian numbers, Great tool for Persian(Iranian) Users of WordPress, part of <a href="http://wp-persian.com" title="پروژه وردپرس فارسی">Persian Wordpress Project</a>.
6
+ Version: 3.5
7
+ Author: Vali Allah(Mani) Monajjemi
8
+ Author URI: http://www.manionline.org/
9
+ */
10
+
11
+ /* Copyright 2005-2007 Vali Allah[Mani] Monajjemi (email : mani.monajjemi@gmail.com)
12
+
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License as published by
15
+ the Free Software Foundation; either version 2 of the License, or
16
+ (at your option) any later version.
17
+
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
+ */
27
+
28
+ /*
29
+ Special Thanks to :
30
+ * Farsiweb.info for J2G and G2J Converstion Functions
31
+ * Milad Raastian (miladmovie.com) for JDF (jdf.farsiprojects.com)
32
+ * Nima Shyanfar (phpmystery.com) for Fast Farsi Number Conversion Method
33
+ * Gonahkar (gonahkar.com) for WP-Jalali widgets plugin (gonahkar.com/archives/2007/02/26/wp-jalali-widgets-plugin/ )
34
+ * Kaveh Ahmadi (ashoob.net/kaveh) for his valuable Farsi Keyboard Script (ashoob.net/farsitype)
35
+ * Ali Sattari(corelist.net) for great support
36
+ * WP-Persian group members (groups.google.com/group/wp-persian/topics)
37
+ */
38
+
39
+ define("MPS_JD_VER","3.5");
40
+
41
+ if (!function_exists('fetch_rss')) require_once (ABSPATH . WPINC . '/rss-functions.php');
42
+ if (!function_exists('error')) {
43
+ function error ($errormsg, $lvl=E_USER_WARNING) {
44
+ // append PHP's error message if track_errors enabled
45
+ if ( $php_errormsg ) {
46
+ $errormsg .= " ($php_errormsg)";
47
+ }
48
+ if ( MAGPIE_DEBUG ) {
49
+ trigger_error( $errormsg, $lvl);
50
+ }
51
+ else {
52
+ error_log( $errormsg, 0);
53
+ }
54
+
55
+ $notices = E_USER_NOTICE|E_NOTICE;
56
+ if ( $lvl&$notices ) {
57
+ $this->WARNING = $errormsg;
58
+ } else {
59
+ $this->ERROR = $errormsg;
60
+ }
61
+ }
62
+ }
63
+
64
+ define("_JDF_USE_PERSIANNUM","0");
65
+ define("_JDF_TZhours","0");
66
+ define("_JDF_TZminute","0");
67
+ define('_JDF_AM_LONG','قبل از ظهر');
68
+ define('_JDF_PM_LONG','بعد از ظهر');
69
+ define('_JDF_AM_SHORT','ق.ظ');
70
+ define('_JDF_PM_SHORT','ب.ظ');
71
+ define('_JDF_Sat_LONG','شنبه');
72
+ define('_JDF_Sun_LONG','یکشنبه');
73
+ define('_JDF_Mon_LONG','دوشنبه');
74
+ define('_JDF_Tue_LONG','سه شنبه');
75
+ define('_JDF_Wed_LONG','چهارشنبه');
76
+ define('_JDF_Thu_LONG','پنجشنبه');
77
+ define('_JDF_Fri_LONG','جمعه');
78
+ define('_JDF_Sat_SHORT','ش');
79
+ define('_JDF_Sun_SHORT','ی');
80
+ define('_JDF_Mon_SHORT','د');
81
+ define('_JDF_Tue_SHORT','س');
82
+ define('_JDF_Wed_SHORT','چ');
83
+ define('_JDF_Thu_SHORT','پ');
84
+ define('_JDF_Fri_SHORT','ج');
85
+ define('_JDF_Suffix','م');
86
+ define('_JDF_Far','فروردین');
87
+ define('_JDF_Ord','اردیبهشت');
88
+ define('_JDF_Kho','خرداد');
89
+ define('_JDF_Tir','تیر');
90
+ define('_JDF_Mor','مرداد');
91
+ define('_JDF_Sha','شهریور');
92
+ define('_JDF_Meh','مهر');
93
+ define('_JDF_Aba','آبان');
94
+ define('_JDF_Aza','آذر');
95
+ define('_JDF_Dey','دی');
96
+ define('_JDF_Bah','بهمن');
97
+ define('_JDF_Esf','اسفند');
98
+ define('_JDF_Num0','۰');
99
+ define('_JDF_Num1','۱');
100
+ define('_JDF_Num2','۲');
101
+ define('_JDF_Num3','۳');
102
+ define('_JDF_Num4','۴');
103
+ define('_JDF_Num5','۵');
104
+ define('_JDF_Num6','۶');
105
+ define('_JDF_Num7','۷');
106
+ define('_JDF_Num8','۸');
107
+ define('_JDF_Num9','۹');
108
+
109
+ $g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
110
+ $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
111
+ $j_month_name = array("", "فروردین", "اردیبهشت", "خرداد", "تیر",
112
+ "مرداد", "شهریور", "مهر", "آبان", "آذر",
113
+ "دی", "بهمن", "اسفند");
114
+ $j_day_name = array("یکشنبه","دوشنبه","سه شنبه","چهارشنبه","پنجشنبه","جمعه","شنبه");
115
+ $jday_abbrev = array("ی","د","س","چ","پ","ج","ش");
116
+
117
+ /* Menu Init */
118
+
119
+ define('MPS_JD_OPTIONS_NAME', "mps_jd_options"."_".MPS_JD_VER); // Name of the Option stored in the DB
120
+
121
+ function mps_jd_menu(){
122
+ /*
123
+ mps_jd_farsinum_XXX :: Toggle Persian numbers in dates
124
+ mps_jd_mcertl :: Toggle TinyMCE Editor RTL / LTR
125
+ mps_jd_jperma :: Toggle Jalali Permalinks on/off (For posts)
126
+
127
+ */
128
+ if(function_exists('add_options_page')) {
129
+ //add_options_page("تنظیمات وردپرس فارسی", "وردپرس فارسی", 10, __FILE__,'mps_jd_optionpage');
130
+ add_menu_page("تنظیمات وردپرس فارسی", "وردپرس فارسی", 10, __FILE__,'mps_jd_optionpage');
131
+ }
132
+
133
+ $mps_jd_optionsDB = get_option(MPS_JD_OPTIONS_NAME);
134
+
135
+ if (empty($mps_jd_optionsDB)) {
136
+ //echo "init";
137
+ $mps_jd_optionsDB['mps_jd_autodate'] = $mps_jd_autodate = true;
138
+ $mps_jd_optionsDB['mps_jd_farsinum_content'] = $mps_jd_farsinum_content = true;
139
+ $mps_jd_optionsDB['mps_jd_farsinum_comment'] = $mps_jd_farsinum_comment = true;
140
+ $mps_jd_optionsDB['mps_jd_farsinum_commentnum'] = $mps_jd_farsinum_commentnum = true;
141
+ $mps_jd_optionsDB['mps_jd_farsinum_title'] = $mps_jd_farsinum_title = true;
142
+ $mps_jd_optionsDB['mps_jd_farsinum_category'] = $mps_jd_farsinum_category = true;
143
+ $mps_jd_optionsDB['mps_jd_farsinum_date'] = $mps_jd_farsinum_date = true;
144
+ $mps_jd_optionsDB['mps_jd_mcertl'] = $mps_jd_mcertl = true;
145
+ $mps_jd_optionsDB['mps_jd_jperma'] = $mps_jd_jperma = true;
146
+ update_option(MPS_JD_OPTIONS_NAME,$mps_jd_optionsDB);
147
+ }
148
+ }
149
+
150
+ function mps_jd_optionpage(){
151
+ global $user_level;
152
+ global $j_day_name;
153
+
154
+ $_wp_version = get_bloginfo("version");
155
+
156
+ if ( $_wp_version < 2.1 ) {
157
+ get_currentuserinfo();
158
+ $enable_options = ($user_level >= 8);
159
+ } else {
160
+ $enable_options = current_user_can('manage_options');
161
+ }
162
+
163
+ if (!$enable_options) { //MUST BE ADMIN
164
+ ?>
165
+ <div class="wrap">
166
+ <h2>خطا</h2>
167
+ <br /><?php _e("<div style=\"color:#770000;\">شما دارای اختیارات کافی نمی باشید.</div>"); ?><br />
168
+ </div>
169
+ <?php
170
+ return;
171
+ }
172
+
173
+ if ( (isset($_POST['action'])) && ($_POST['action'] == 'update')) {
174
+ $mps_jd_optionsDB['mps_jd_autodate'] = $mps_jd_autodate = $_POST['mps_jd_autodate'];
175
+ $mps_jd_optionsDB['mps_jd_farsinum_content'] = $mps_jd_farsinum_content = $_POST['mps_jd_farsinum_content'];
176
+ $mps_jd_optionsDB['mps_jd_farsinum_comment'] = $mps_jd_farsinum_comment = $_POST['mps_jd_farsinum_comment'];
177
+ $mps_jd_optionsDB['mps_jd_farsinum_commentnum'] = $mps_jd_farsinum_commentnum = $_POST['mps_jd_farsinum_commentnum'];
178
+ $mps_jd_optionsDB['mps_jd_farsinum_title'] = $mps_jd_farsinum_title = $_POST['mps_jd_farsinum_title'];
179
+ $mps_jd_optionsDB['mps_jd_farsinum_category'] = $mps_jd_farsinum_category = $_POST['mps_jd_farsinum_category'];
180
+ $mps_jd_optionsDB['mps_jd_farsinum_date'] = $mps_jd_farsinum_date = $_POST['mps_jd_farsinum_date'];
181
+ $mps_jd_optionsDB['mps_jd_mcertl'] = $mps_jd_mcertl = $_POST['mps_jd_mcertl'];
182
+ $mps_jd_optionsDB['mps_jd_jperma'] = $mps_jd_jperma = $_POST['mps_jd_jperma'];
183
+ update_option(MPS_JD_OPTIONS_NAME,$mps_jd_optionsDB);
184
+ update_option('gmt_offset',$_POST['gmt_offset']);
185
+ update_option('date_format',$_POST['date_format']);
186
+ update_option('time_format',$_POST['time_format']);
187
+ update_option('start_of_week',$_POST['start_of_week']);
188
+ $mps_ERR = "تغییرات با موفقیت ثبت شد.";
189
+ }
190
+
191
+ $mps_jd_optionsDB = get_option(MPS_JD_OPTIONS_NAME);
192
+ $mps_jd_autodate = $mps_jd_optionsDB['mps_jd_autodate'];
193
+ $mps_jd_farsinum_content = $mps_jd_optionsDB['mps_jd_farsinum_content'];
194
+ $mps_jd_farsinum_comment = $mps_jd_optionsDB['mps_jd_farsinum_comment'];
195
+ $mps_jd_farsinum_commentnum = $mps_jd_optionsDB['mps_jd_farsinum_commentnum'];
196
+ $mps_jd_farsinum_title = $mps_jd_optionsDB['mps_jd_farsinum_title'];
197
+ $mps_jd_farsinum_category = $mps_jd_optionsDB['mps_jd_farsinum_category'];
198
+ $mps_jd_farsinum_date = $mps_jd_optionsDB['mps_jd_farsinum_date'];
199
+ $mps_jd_mcertl = $mps_jd_optionsDB['mps_jd_mcertl'];
200
+ $mps_jd_jperma = $mps_jd_optionsDB['mps_jd_jperma'];
201
+
202
+ if((isset($mps_ERR)) && (!empty($mps_ERR))) {
203
+ ?>
204
+ <br clear="all" />
205
+ <div id="message" class="updated fade" style="direction: rtl"><p><strong><?php _e($mps_ERR); ?></strong></p></div>
206
+ <?php
207
+ }
208
+ ?>
209
+
210
+ <?php
211
+ $logo_uri = get_settings('siteurl').'/wp-content/plugins/WP-Jalali/wp-fa-logo.png';
212
+ ?>
213
+
214
+ <div class="wrap" style="direction:rtl ">
215
+ <p style="text-align: center">
216
+ <a href="http://www.wp-persian.com" style="border: none" title="وردپرس فارسی"><img src="<?=$logo_uri?>" alt="Persian Wordpress Logo" width="300" height="70" border="0"/></a>
217
+ </p>
218
+ <h2>اخبار وردپرس فارسی</h2>
219
+ <h3>وبلاگ توسعه وردپرس فارسی</h3>
220
+
221
+ <?php
222
+ $rss = @fetch_rss('http://www.wp-persian.com/feed/');
223
+ if ( isset($rss->items) && 0 != count($rss->items) ) {
224
+ ?>
225
+ <?php
226
+ $rss->items = array_slice($rss->items, 0, 3);
227
+ foreach ($rss->items as $item ) {
228
+ ?>
229
+ <h4 dir="rtl" style="color: gray; margin-right: 25px; "><a href='<?php echo wp_filter_kses($item['link']); ?>'><?php echo wp_specialchars($item['title']); ?></a> &#8212; <?php printf(__('%s ago'), human_time_diff(strtotime($item['pubdate'], time() ) ) ); ?></h4>
230
+ <?php
231
+ }
232
+ }
233
+ ?>
234
+ <div id="planetnews">
235
+ <h3>سیاره وردپرس فارسی <a href="http://planet.wp-persian.com/">بیشتر »</a></h3>
236
+ <?php
237
+ $rss = @fetch_rss('http://planet.wp-persian.com/feed/');
238
+ if ( isset($rss->items) && 0 != count($rss->items) ) {
239
+ ?>
240
+
241
+ <ul>
242
+ <?php
243
+ $rss->items = array_slice($rss->items, 0, 10);
244
+ foreach ($rss->items as $item ) {
245
+
246
+ ?>
247
+ <li><?php echo wp_specialchars($item['dc']['creator']); ?> : <a href='<?php echo wp_filter_kses($item['link']); ?>'><?php echo wp_specialchars($item['title']); ?></a><?php// printf(__('%s ago'), human_time_diff(strtotime($item['pubdate'], time() ) ) ); ?></li>
248
+ <?php
249
+ }
250
+ ?>
251
+ </ul><br style="clear: both;"/>
252
+ <?php
253
+ }
254
+ ?>
255
+
256
+
257
+
258
+ <h2>تنظیمات وردپرس فارسی</h2>
259
+ <form method="post">
260
+ <input type="hidden" name="action" value="update" />
261
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform" border="0">
262
+ <tr valign="top">
263
+ <th width="33%" scope="row">تبدیل خودکار تاریخ نوشته ها و نظرات به تاریخ خورشیدی(شمسی)</th>
264
+ <td>
265
+ <select name="mps_jd_autodate" id="mps_jd_autodate">
266
+ <option value="1" <?=$mps_jd_autodate==true? 'selected=\"selected\"':'' ?>>فعال (پیشنهاد می شود)</option>
267
+ <option value="0" <?=$mps_jd_autodate==false?'selected=\"selected\"':'' ?>>غیر فعال</option>
268
+ </select>
269
+ </td>
270
+ </tr>
271
+ <tr valign="top">
272
+ <th width="33%" scope="row">نمایش ارقام فارسی</th>
273
+ <td>
274
+ <table border="0" cellpadding="2" cellspacing="2">
275
+ <tr>
276
+ <td>متن نوشته ها</td>
277
+ <td><input type="checkbox" name="mps_jd_farsinum_content" <?=$mps_jd_farsinum_content==true? 'checked=\"checked\"':'' ?> /></td>
278
+ <td>متن نظر ها</td>
279
+ <td><input type="checkbox" name="mps_jd_farsinum_comment" <?=$mps_jd_farsinum_comment==true? 'checked=\"checked\"':'' ?> /></td>
280
+ <td>تعداد نظر ها</td>
281
+ <td><input type="checkbox" name="mps_jd_farsinum_commentnum" <?=$mps_jd_farsinum_commentnum==true? 'checked=\"checked\"':'' ?> /></td>
282
+ </tr>
283
+ <tr>
284
+ <td>عنوان نوشته ها</td>
285
+ <td><input type="checkbox" name="mps_jd_farsinum_title" <?=$mps_jd_farsinum_title==true? 'checked=\"checked\"':'' ?> /></td>
286
+ <td>تاریخ ها</td>
287
+ <td><input type="checkbox" name="mps_jd_farsinum_date" <?=$mps_jd_farsinum_date==true? 'checked=\"checked\"':'' ?> /></td>
288
+ <td>فهرست رسته ها</td>
289
+ <td><input type="checkbox" name="mps_jd_farsinum_category" <?=$mps_jd_farsinum_category==true? 'checked=\"checked\"':'' ?> /></td>
290
+ </tr>
291
+ </table>
292
+
293
+ </td>
294
+ </tr>
295
+ <tr valign="top">
296
+ <th width="33%" scope="row">جهت ویرایشگر متنی صفحه نوشتن</th>
297
+ <td>
298
+ <select name="mps_jd_mcertl" id="mps_jd_mcertl">
299
+ <option value="1" <?=$mps_jd_mcertl==true? 'selected=\"selected\"':'' ?>>راست به چپ</option>
300
+ <option value="0" <?=$mps_jd_mcertl==false?'selected=\"selected\"':'' ?>>چپ به راست</option>
301
+ </select>
302
+ </td>
303
+ </tr>
304
+ <tr valign="top">
305
+ <th width="33%" scope="row">تبدیل خودکار تاریخ در آدرس (URI) نوشته ها</th>
306
+ <td>
307
+ <select name="mps_jd_jperma" id="mps_jd_jperma">
308
+ <option value="1" <?=$mps_jd_jperma==true? 'selected=\"selected\"':'' ?>>بله</option>
309
+ <option value="0" <?=$mps_jd_jperma==false?'selected=\"selected\"':'' ?>>خیر</option>
310
+ </select>
311
+ </td>
312
+ </tr>
313
+ </table>
314
+ <fieldset class="options">
315
+ <legend><?php _e('تنظیمات تاریخ و ساعت') ?></legend>
316
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
317
+ <tr>
318
+ <th scope="row" width="33%">ساعت به وقت <abbr title="Coordinated Universal Time">UTC</abbr>:</th>
319
+ <td><code>
320
+ <?php
321
+ $m = gmdate('YmdHis');
322
+ $gmt = mktime(substr($m,8,2),substr($m,10,2),substr($m,12,2),substr($m,4,2),substr($m,6,2),substr($m,0,4));
323
+
324
+
325
+ ?>
326
+ <?php echo jdate('l Y-m-d g:i:s a',$gmt); ?></code></td>
327
+ </tr>
328
+ <tr>
329
+ <th scope="row">اختلاف ساعت محلی :</th>
330
+ <td><input style="direction:rtl; text-align:left" name="gmt_offset" type="text" id="gmt_offset" size="2" value="<?php form_option('gmt_offset'); ?>" />
331
+ ساعت </td>
332
+ </tr>
333
+ <tr>
334
+ <th scope="row">&nbsp;</th>
335
+ <td>فرمت زیر مانند <a href="http://php.net/date">تابع <code>date()</code> PHP</a> می باشد. برای نمایش تغییرات این صفحه را به روز کنید.</td>
336
+ </tr>
337
+ <tr>
338
+ <th scope="row">فرمت تاریخ پیش فرض</th>
339
+ <td><input style="direction:rtl; text-align:left" name="date_format" type="text" id="date_format" size="30" value="<?php form_option('date_format'); ?>" /><br />
340
+ خروجی : <strong><?php echo jdate(get_settings('date_format'), $gmt + (get_settings('gmt_offset') * 3600)); ?></strong></td>
341
+ </tr>
342
+ <tr>
343
+ <th scope="row">فرمت زمان پیش فرض</th>
344
+ <td><input style="direction:rtl; text-align:left" name="time_format" type="text" id="time_format" size="30" value="<?php form_option('time_format'); ?>" /><br />
345
+ خروجی : <strong><?php echo jdate(get_settings('time_format'), $gmt + (get_settings('gmt_offset') * 3600)) ; ?></strong></td>
346
+ </tr>
347
+ <tr>
348
+ <th scope="row">روز شروع هفته در تقویم</th>
349
+ <td><select name="start_of_week" id="start_of_week">
350
+ <?php
351
+ for ($day_index = 0; $day_index <= 6; $day_index++) :
352
+ if ($day_index == get_settings('start_of_week')) $selected = " selected='selected'";
353
+ else $selected = '';
354
+ echo "\n\t<option value='$day_index' $selected>$j_day_name[$day_index]</option>";
355
+ endfor;
356
+ ?>
357
+ </select></td>
358
+ </tr>
359
+
360
+ </table>
361
+
362
+
363
+
364
+ <p class="submit">
365
+ <input type="submit" name="Submit" value="به روز رسانی &raquo;" />
366
+ </p>
367
+ </form>
368
+
369
+ <br />
370
+ </div><br />&nbsp;
371
+ <div id="wp-bookmarklet" class="wrap" style="direction:rtl; text-align:right">
372
+ <h3>پروژه وردپرس فارسی</h3>
373
+ <p>این افزونه، بخشی از <a href="http://www.wp-persian.com/">پروژه وردپرس فارسی</a> می باشد. برای اطلاعات بیشتر در مورد این پلاگ-این می توانید <a href="http://www.wp-persian.com/wp-jalali/">صفحه مخصوص این پلاگ-این</a> را مشاهده کنید.</p>
374
+ </div>
375
+
376
+
377
+ <?php
378
+
379
+ }
380
+
381
+ /* Farsiweb.info Jaladi/Gregorian Convertion Functions */
382
+
383
+ function div($a, $b)
384
+ {
385
+ return (int) ($a / $b);
386
+ }
387
+
388
+ function jalali_to_gregorian($j_y, $j_m, $j_d)
389
+ {
390
+ global $g_days_in_month;
391
+ global $j_days_in_month;
392
+
393
+ $jy = $j_y-979;
394
+ $jm = $j_m-1;
395
+ $jd = $j_d-1;
396
+
397
+ $j_day_no = 365*$jy + div($jy, 33)*8 + div($jy%33+3, 4);
398
+ for ($i=0; $i < $jm; ++$i)
399
+ $j_day_no += $j_days_in_month[$i];
400
+
401
+ $j_day_no += $jd;
402
+
403
+ $g_day_no = $j_day_no+79;
404
+
405
+ $gy = 1600 + 400*div($g_day_no, 146097); /* 146097 = 365*400 + 400/4 - 400/100 + 400/400 */
406
+ $g_day_no = $g_day_no % 146097;
407
+
408
+ $leap = true;
409
+ if ($g_day_no >= 36525) /* 36525 = 365*100 + 100/4 */
410
+ {
411
+ $g_day_no--;
412
+ $gy += 100*div($g_day_no, 36524); /* 36524 = 365*100 + 100/4 - 100/100 */
413
+ $g_day_no = $g_day_no % 36524;
414
+
415
+ if ($g_day_no >= 365)
416
+ $g_day_no++;
417
+ else
418
+ $leap = false;
419
+ }
420
+
421
+ $gy += 4*div($g_day_no, 1461); /* 1461 = 365*4 + 4/4 */
422
+ $g_day_no %= 1461;
423
+
424
+ if ($g_day_no >= 366) {
425
+ $leap = false;
426
+
427
+ $g_day_no--;
428
+ $gy += div($g_day_no, 365);
429
+ $g_day_no = $g_day_no % 365;
430
+ }
431
+
432
+ for ($i = 0; $g_day_no >= $g_days_in_month[$i] + ($i == 1 && $leap); $i++)
433
+ $g_day_no -= $g_days_in_month[$i] + ($i == 1 && $leap);
434
+ $gm = $i+1;
435
+ $gd = $g_day_no+1;
436
+
437
+ return array($gy, $gm, $gd);
438
+ }
439
+
440
+ function jcheckdate($j_m, $j_d, $j_y)
441
+ {
442
+ global $j_days_in_month;
443
+
444
+ if ($j_y < 0 || $j_y > 32767 || $j_m < 1 || $j_m > 12 || $j_d < 1 || $j_d >
445
+ ($j_days_in_month[$j_m-1] + ($j_m == 12 && !(($j_y-979)%33%4))))
446
+ return false;
447
+ return true;
448
+ }
449
+
450
+ function gregorian_week_day($g_y, $g_m, $g_d)
451
+ {
452
+ global $g_days_in_month;
453
+
454
+ $gy = $g_y-1600;
455
+ $gm = $g_m-1;
456
+ $gd = $g_d-1;
457
+
458
+ $g_day_no = 365*$gy+div($gy+3,4)-div($gy+99,100)+div($gy+399,400);
459
+
460
+ for ($i=0; $i < $gm; ++$i)
461
+ $g_day_no += $g_days_in_month[$i];
462
+ if ($gm>1 && (($gy%4==0 && $gy%100!=0) || ($gy%400==0)))
463
+ /* leap and after Feb */
464
+ ++$g_day_no;
465
+ $g_day_no += $gd;
466
+
467
+ return ($g_day_no + 5) % 7 + 1;
468
+ }
469
+
470
+ function jalali_week_day($j_y, $j_m, $j_d)
471
+ {
472
+ global $j_days_in_month;
473
+
474
+ $jy = $j_y-979;
475
+ $jm = $j_m-1;
476
+ $jd = $j_d-1;
477
+
478
+ $j_day_no = 365*$jy + div($jy, 33)*8 + div($jy%33+3, 4);
479
+
480
+ for ($i=0; $i < $jm; ++$i)
481
+ $j_day_no += $j_days_in_month[$i];
482
+
483
+ $j_day_no += $jd;
484
+
485
+ return ($j_day_no + 2) % 7 + 1;
486
+ }
487
+
488
+
489
+ function gregorian_to_jalali($g_y, $g_m, $g_d)
490
+ {
491
+ global $g_days_in_month;
492
+ global $j_days_in_month;
493
+
494
+ $gy = $g_y-1600;
495
+ $gm = $g_m-1;
496
+ $gd = $g_d-1;
497
+
498
+ $g_day_no = 365*$gy+div($gy+3,4)-div($gy+99,100)+div($gy+399,400);
499
+
500
+ for ($i=0; $i < $gm; ++$i)
501
+ $g_day_no += $g_days_in_month[$i];
502
+ if ($gm>1 && (($gy%4==0 && $gy%100!=0) || ($gy%400==0)))
503
+ /* leap and after Feb */
504
+ ++$g_day_no;
505
+ $g_day_no += $gd;
506
+
507
+ $j_day_no = $g_day_no-79;
508
+
509
+ $j_np = div($j_day_no, 12053);
510
+ $j_day_no %= 12053;
511
+
512
+ $jy = 979+33*$j_np+4*div($j_day_no,1461);
513
+
514
+ $j_day_no %= 1461;
515
+
516
+ if ($j_day_no >= 366) {
517
+ $jy += div($j_day_no-1, 365);
518
+ $j_day_no = ($j_day_no-1)%365;
519
+ }
520
+
521
+ for ($i = 0; $i < 11 && $j_day_no >= $j_days_in_month[$i]; ++$i) {
522
+ $j_day_no -= $j_days_in_month[$i];
523
+ }
524
+ $jm = $i+1;
525
+ $jd = $j_day_no+1;
526
+
527
+
528
+ return array($jy, $jm, $jd);
529
+ }
530
+
531
+ /* These 2 Functions are new Farsi Num convert implemented in ver 3,
532
+ Originally written by Nima Shyanfar , www.phpmystery.com
533
+ Thanx Nima ;)
534
+ */
535
+
536
+ function convertToFarsi($matches) {
537
+ $out = '';
538
+ if (isset($matches[1])) {
539
+ for ($i = 0; $i < strlen($matches[1]); $i++)
540
+ if (ereg("([0-9])",$matches[1][$i])) {
541
+ $out .= pack("C*", 0xDB, 0xB0 + $matches[1][$i]);
542
+ } else {
543
+ $out .= $matches[1][$i];
544
+ }
545
+
546
+ return $out;
547
+ }
548
+ return $matches[0];
549
+ }
550
+
551
+ function farsi_num($num,$fake = null,$fake2=null) {
552
+ return preg_replace_callback('/(?:&#\d{2,4};)|(\d+[\.\d]*)|<\s*[^>]+>/', 'convertToFarsi', $num);
553
+
554
+ }
555
+
556
+ /*
557
+ Jalali Date function by Milad Rastian (miladmovie AT yahoo DOT com)
558
+ jdf.farsiprojects.com
559
+ */
560
+
561
+
562
+ function jdate($type,$maket="now",$forcelatinnums=false)
563
+ {
564
+ $result="";
565
+ if($maket=="now"){
566
+ $year=date("Y");
567
+ $month=date("m");
568
+ $day=date("d");
569
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
570
+ $maket=jmaketime(date("h")+_JDF_TZhours,date("i")+_JDF_TZminute,date("s"),$jmonth,$jday,$jyear);
571
+ }else{
572
+ $maket+=_JDF_TZhours*3600+_JDF_TZminute*60;
573
+ $date=date("Y-m-d",$maket);
574
+ list( $year, $month, $day ) = preg_split ( '/-/', $date );
575
+
576
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
577
+ }
578
+
579
+ $need= $maket;
580
+ $year=date("Y",$need);
581
+ $month=date("m",$need);
582
+ $day=date("d",$need);
583
+ $i=0;
584
+ $skipnext = false;
585
+ while($i<strlen($type))
586
+ {
587
+ $subtype=substr($type,$i,1);
588
+
589
+ if ($skipnext) {
590
+ $result .= $subtype;
591
+ $skipnext = false;
592
+ $i++;
593
+ continue;
594
+ }
595
+
596
+
597
+ switch ($subtype)
598
+ {
599
+ case "A":
600
+ $result1=date("a",$need);
601
+ if($result1=="pm")
602
+ $result.=_JDF_PM_LONG;
603
+ else
604
+ $result.=_JDF_AM_LONG;
605
+ break;
606
+
607
+ case "a":
608
+ $result1=date("a",$need);
609
+ if($result1=="pm")
610
+ $result.=_JDF_PM_SHORT;
611
+ else
612
+ $result.=_JDF_AM_SHORT;
613
+ break;
614
+
615
+ case "d":
616
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
617
+ if($jday<10)
618
+ $result1="0".$jday;
619
+ else
620
+ $result1=$jday;
621
+
622
+ $result.=$result1;
623
+ break;
624
+
625
+ case "D":
626
+ $result1=date("D",$need);
627
+ if($result1=="Sat") $result1=_JDF_Sat_SHORT;
628
+ else if($result1=="Sun") $result1=_JDF_Sun_SHORT;
629
+ else if($result1=="Mon") $result1=_JDF_Mon_SHORT;
630
+ else if($result1=="Tue") $result1=_JDF_Tue_SHORT;
631
+ else if($result1=="Wed") $result1=_JDF_Wed_SHORT;
632
+ else if($result1=="Thu") $result1=_JDF_Thu_SHORT;
633
+ else if($result1=="Fri") $result1=_JDF_Fri_SHORT;
634
+ $result.=$result1;
635
+ break;
636
+
637
+ case"F":
638
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
639
+ $result.=monthname($jmonth);
640
+ break;
641
+
642
+ case "g":
643
+ $result1=date("g",$need);
644
+ $result.=$result1;
645
+ break;
646
+
647
+ case "G":
648
+ $result1=date("G",$need);
649
+ $result.=$result1;
650
+ break;
651
+
652
+ case "h":
653
+ $result1=date("h",$need);
654
+ $result.=$result1;
655
+ break;
656
+
657
+ case "H":
658
+ $result1=date("H",$need);
659
+ $result.=$result1;
660
+ break;
661
+
662
+ case "i":
663
+ $result1=date("i",$need);
664
+ $result.=$result1;
665
+ break;
666
+
667
+ case "j":
668
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
669
+ $result1=$jday;
670
+ $result.=$result1;
671
+ break;
672
+
673
+ case "l":
674
+ $result1=date("l",$need);
675
+ if($result1=="Saturday") $result1=_JDF_Sat_LONG;
676
+ else if($result1=="Sunday") $result1=_JDF_Sun_LONG;
677
+ else if($result1=="Monday") $result1=_JDF_Mon_LONG;
678
+ else if($result1=="Tuesday") $result1=_JDF_Tue_LONG;
679
+ else if($result1=="Wednesday") $result1=_JDF_Wed_LONG;
680
+ else if($result1=="Thursday") $result1=_JDF_Thu_LONG;
681
+ else if($result1=="Friday") $result1=_JDF_Fri_LONG;
682
+ $result.=$result1;
683
+ break;
684
+
685
+ case "m":
686
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
687
+ if($jmonth<10)
688
+ $result1="0".$jmonth;
689
+ else
690
+ $result1=$jmonth;
691
+ $result.=$result1;
692
+ break;
693
+
694
+ case "M":
695
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
696
+ $result.=monthname($jmonth);
697
+ break;
698
+
699
+ case "n":
700
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
701
+ $result1=$jmonth;
702
+ $result.=$result1;
703
+ break;
704
+
705
+ case "s":
706
+ $result1=date("s",$need);
707
+ $result.=$result1;
708
+ break;
709
+
710
+ case "S":
711
+ $result.=_JDF_Suffix;
712
+ break;
713
+
714
+ case "t":
715
+ $result.=lastday ($month,$day,$year);
716
+ break;
717
+
718
+ case "w":
719
+ $result1=date("w",$need);
720
+ $result.=$result1;
721
+ break;
722
+
723
+ case "y":
724
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
725
+ $result1=substr($jyear,2,4);
726
+ $result.=$result1;
727
+ break;
728
+
729
+ case "Y":
730
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
731
+ $result1=$jyear;
732
+ $result.=$result1;
733
+ break;
734
+
735
+ case "\\":
736
+ $result.='';
737
+ $skipnext = true;
738
+ break;
739
+
740
+ default:
741
+ $result.=$subtype;
742
+ }
743
+ $i++;
744
+ }
745
+
746
+ $mps_jd_optionsDB = get_option(MPS_JD_OPTIONS_NAME);
747
+ $mps_jd_farsinum_date = $mps_jd_optionsDB['mps_jd_farsinum_date'];
748
+
749
+ if ((!$forcelatinnums) && ($mps_jd_farsinum_date))
750
+ $result = farsi_num($result);
751
+
752
+ return $result;
753
+ }
754
+
755
+
756
+
757
+ function jmaketime($hour,$minute,$second,$jmonth,$jday,$jyear)
758
+ {
759
+ list( $year, $month, $day ) = jalali_to_gregorian($jyear, $jmonth, $jday);
760
+ $i=mktime((int) $hour,(int) $minute,(int) $second, (int) $month, (int) $day, (int) $year, 0);
761
+ return $i;
762
+ }
763
+
764
+
765
+ ///Find Day Begining Of Month
766
+ function mstart($month,$day,$year)
767
+ {
768
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
769
+ list( $year, $month, $day ) = jalali_to_gregorian($jyear, $jmonth, "1");
770
+ $timestamp=mktime(0,0,0,$month,$day,$year);
771
+ return date("w",$timestamp);
772
+ }
773
+
774
+ //Find Number Of Days In This Month
775
+ function lastday ($month,$day,$year)
776
+ {
777
+ $lastdayen=date("d",mktime(0,0,0,$month+1,0,$year));
778
+ list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
779
+ $lastdatep=$jday;
780
+ $jday=$jday2;
781
+ while($jday2!="1")
782
+ {
783
+ if($day<$lastdayen)
784
+ {
785
+ $day++;
786
+ list( $jyear, $jmonth, $jday2 ) = gregorian_to_jalali($year, $month, $day);
787
+ if($jdate2=="1") break;
788
+ if($jdate2!="1") $lastdatep++;
789
+ }
790
+ else
791
+ {
792
+ $day=0;
793
+ $month++;
794
+ if($month==13)
795
+ {
796
+ $month="1";
797
+ $year++;
798
+ }
799
+ }
800
+
801
+ }
802
+ return $lastdatep-1;
803
+ }
804
+
805
+ //translate number of month to name of month
806
+ function monthname($month)
807
+ {
808
+ $month_map = array(1 => _JDF_Far, 2 => _JDF_Ord, 3 => _JDF_Kho, 4 => _JDF_Tir
809
+ , 5 => _JDF_Mor, 6 => _JDF_Sha, 7 => _JDF_Meh, 8 => _JDF_Aba, 9 => _JDF_Aza
810
+ , 10 => _JDF_Dey, 11 => _JDF_Bah, 12 => _JDF_Esf);
811
+ return $month_map[(int) $month];
812
+ }
813
+
814
+
815
+ /* Wordpress Convert Functions */
816
+
817
+ function jmysql2date($dateformatstring, $mysqlstring, $translate = true) {
818
+ global $month, $weekday, $month_abbrev, $weekday_abbrev;
819
+ $m = $mysqlstring;
820
+ if ( empty($m) ) {
821
+ return false;
822
+ }
823
+ $i = mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4));
824
+
825
+ if ( -1 == $i || false == $i )
826
+ $i = 0;
827
+
828
+ $j = @jdate($dateformatstring, $i);
829
+ return $j;
830
+ }
831
+
832
+ function mps_maketimestamp($m) {
833
+ return mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4));
834
+ }
835
+
836
+
837
+ function comment_jdate($d='') {
838
+ global $comment;
839
+ $m = $comment->comment_date;
840
+ $timestamp = mps_maketimestamp($m);
841
+ if ('' == $d) {
842
+ echo jdate(get_settings('date_format'), $timestamp);
843
+ } else {
844
+ echo jdate($d, $timestamp);
845
+ }
846
+
847
+ }
848
+
849
+ function comment_jtime($d='') {
850
+ global $comment;
851
+ $m = $comment->comment_date;
852
+ $timestamp = mps_maketimestamp($m);
853
+ if ($d == '') {
854
+ echo jdate(get_settings('time_format'), $timestamp);
855
+ } else {
856
+ echo jdate($d, $timestamp);
857
+ }
858
+ }
859
+
860
+ function mps_the_jdate($input,$d='',$before='', $after='') {
861
+ global $id, $post, $day, $previousday, $newday;
862
+ $result = '';
863
+ if ($d == "") $d = get_settings('time_format');
864
+ //if ($day != $previousday) {
865
+ if (strlen($input) > 0) { //Because $previousday is overwritten before reaching here , nice trick ;)
866
+ $m = $post->post_date;
867
+ $timestamp = mps_maketimestamp($m);
868
+ $result .= $before;
869
+ $result .= jdate($d,$timestamp);
870
+ $result .= $after;
871
+ $previousday = $day;
872
+ }
873
+ return $result;
874
+ }
875
+
876
+ function mps_the_jtime($input,$d='') {
877
+ global $id, $post;
878
+ if (!empty($input)){
879
+ if ($d == "") $d = get_settings('time_format');
880
+ $m = $post->post_date;
881
+ $timestamp = mps_maketimestamp($m);
882
+ $the_time = jdate($d, $timestamp);
883
+ return $the_time;
884
+ }
885
+
886
+ }
887
+
888
+ function mps_comment_jdate($input, $d = '') {
889
+ global $comment;
890
+ $result = '';
891
+ $m = $comment->comment_date;
892
+ $timestamp = mps_maketimestamp($m);
893
+ if ( '' == $d )
894
+ $result = jdate(get_settings('date_format'), $timestamp);
895
+ else
896
+ $result = jdate($d, $timestamp);
897
+ return $result;
898
+ }
899
+
900
+ function mps_comment_jtime($input, $d = '') {
901
+ global $comment;
902
+ $result = '';
903
+ $m = $comment->comment_date;
904
+ $timestamp = mps_maketimestamp($m);
905
+ if ( '' == $d )
906
+ $result = jdate(get_settings('time_format'), $timestamp);
907
+ else
908
+ $result = jdate($d, $timestamp);
909
+ return $result;
910
+ }
911
+
912
+ function mps_the_jweekday($input) {
913
+ global $weekday, $id, $post;
914
+ $m = $post->post_date;
915
+ $timestamp = mps_maketimestamp($m);
916
+ $the_weekday = jdate('w', $timestamp);
917
+ return $the_weekday;
918
+ }
919
+
920
+
921
+ function mps_the_jweekday_date($input, $before, $after) {
922
+ global $weekday, $id, $post, $day, $previousweekday;
923
+ $the_weekday_date = '';
924
+ $m = $post->post_date;
925
+ $timestamp = mps_maketimestamp($m);
926
+ if (strlen($input) > 0) {
927
+ $the_weekday_date .= $before;
928
+ $the_weekday_date .= jdate('w', $timestamp);
929
+ $the_weekday_date .= $after;
930
+ }
931
+ return $the_weekday_date;
932
+ }
933
+
934
+
935
+ function mps_jalali_query($where) {
936
+
937
+ /* Wordpress 1.6+ */
938
+ global $wp_query;
939
+ global $j_days_in_month;
940
+
941
+ $m = $wp_query->query_vars['m'];
942
+ $hour = $wp_query->query_vars['hour'];
943
+ $minute = $wp_query->query_vars['minute'];
944
+ $second = $wp_query->query_vars['second'];
945
+ $year = $wp_query->query_vars['year'];
946
+ $monthnum = $wp_query->query_vars['monthnum'];
947
+ $day = $wp_query->query_vars['day'];
948
+
949
+ $j_monthnum = 1;
950
+ $j_day = 1;
951
+ $j_hour = 0;
952
+ $j_minute = 0;
953
+ $j_second = 0;
954
+ $j_monthnum_next = 1;
955
+ $j_day_next = 1;
956
+ $j_hour_next = 0;
957
+ $j_minute_next = 0;
958
+ $j_second_next = 0;
959
+ $j_doit = false;
960
+
961
+ if ($m != '') {
962
+ $m = '' . preg_replace('|[^0-9]|', '', $m);
963
+ $j_year = substr($m,0,4);
964
+ if ($j_year < 1700) { // Wow ! It's a Jalali Date!
965
+ $j_doit = true;
966
+ $j_year_next = $j_year + 1;
967
+
968
+ if (strlen($m)>5) {
969
+ $j_monthnum = substr($m, 4, 2);
970
+ $j_year_next = $j_year;
971
+ $j_monthnum_next = $j_monthnum + 1;
972
+ }
973
+
974
+ if (strlen($m)>7) {
975
+ $j_day = substr($m, 6, 2);
976
+ $j_monthnum_next = $j_monthnum;
977
+ $j_day_next = $j_day + 1;
978
+ }
979
+ if (strlen($m)>9) {
980
+ $j_hour = substr($m, 8, 2);
981
+ $j_day_next = $j_day;
982
+ $j_hour_next = $j_hour + 1;
983
+ }
984
+ if (strlen($m)>11) {
985
+ $j_minute = substr($m, 10, 2);
986
+ $j_hour_next = $j_hour;
987
+ $j_minute_next = $j_minute + 1;
988
+ }
989
+ if (strlen($m)>13) {
990
+ $j_second = substr($m, 12, 2);
991
+ $j_minute_next = $j_minute;
992
+ $j_second_next = $j_second + 1;
993
+ }
994
+ }
995
+ } else if (($year != '') && ($year < 1700)) {
996
+ $j_doit = true;
997
+ $j_year = $year;
998
+ $j_year_next = $j_year + 1;
999
+
1000
+ if ($monthnum != '') {
1001
+ $j_monthnum = $monthnum;
1002
+ $j_year_next = $j_year;
1003
+ $j_monthnum_next = $j_monthnum + 1;
1004
+ }
1005
+ if ($day != '') {
1006
+ $j_day = $day;
1007
+ $j_monthnum_next = $j_monthnum;
1008
+ $j_day_next = $j_day + 1;
1009
+ }
1010
+ if ($hour != '') {
1011
+ $j_hour = $hour;
1012
+ $j_day_next = $j_day;
1013
+ $j_hour_next = $j_hour + 1;
1014
+ }
1015
+ if ($minute != '') {
1016
+ $j_minute = $minute;
1017
+ $j_hour_next = $j_hour;
1018
+ $j_minute_next = $j_minute + 1;
1019
+ }
1020
+ if ($second != '') {
1021
+ $j_second = $second;
1022
+ $j_minute_next = $j_minute;
1023
+ $j_second_next = $j_second + 1;
1024
+ }
1025
+ }
1026
+
1027
+ if ($j_doit) {
1028
+ /* WP 1.5+ NEEDS THIS :: CLEANING PREV. TIMINGS*/
1029
+ $patterns = array("YEAR\(post_date\)='*[0-9]{4}'*","DAYOFMONTH\(post_date\)='*[0-9]{1,}'*"
1030
+ ,"MONTH\(post_date\)='*[0-9]{1,}'*","HOUR\(post_date\)='*[0-9]{1,}'*",
1031
+ "MINUTE\(post_date\)='*[0-9]{1,}'*","SECOND\(post_date\)='*[0-9]{1,}'*");
1032
+ foreach ($patterns as $pattern){
1033
+ $where = ereg_replace($pattern,"1=1",$where); // :D good idea ! isn't it ?
1034
+ }
1035
+ if ($j_second_next > 59) {
1036
+ $j_second_next = 0;
1037
+ $j_minute_next++;
1038
+ }
1039
+ if ($j_minute_next > 59) {
1040
+ $j_minute_next = 0;
1041
+ $j_hour_next++;
1042
+ }
1043
+ if ($j_hour_next > 23) {
1044
+ $j_hour_next = 0;
1045
+ $j_day_next++;
1046
+ }
1047
+ if ($j_day_next > $j_days_in_month[$j_monthnum-1]){
1048
+ $j_day_next = 1;
1049
+ $j_monthnum_next++;
1050
+ }
1051
+ if ($j_monthnum_next > 12) {
1052
+ $j_monthnum_next = 1;
1053
+ $j_year_next++;
1054
+ }
1055
+
1056
+ $g_startdate = date("Y:m:d 00:00:00",jmaketime($j_hour,$j_minute,$j_second,$j_monthnum,$j_day,$j_year));
1057
+ $g_enddate = date("Y:m:d 00:00:00",jmaketime($j_hour_next,$j_minute_next,$j_second_next,$j_monthnum_next,$j_day_next,$j_year_next));
1058
+
1059
+ $where .= " AND post_date >= '$g_startdate' AND post_date < '$g_enddate' ";
1060
+ }
1061
+ return $where;
1062
+ }
1063
+
1064
+ function mps_get_jarchives($type='', $limit='', $format='html', $before = '', $after = '', $show_post_count = false) {
1065
+ //Added in 3.5 for backward compability
1066
+ $_wp_version = get_bloginfo("version");
1067
+ if ($_wp_version >= 2.1) {
1068
+ $_query_add = " post_type='post' ";
1069
+ } else {
1070
+ $_query_add = " 1 = 1 "; // =)) 11-5-2007 0:38
1071
+ }
1072
+ global $month, $wpdb;
1073
+ global $j_month_name;
1074
+
1075
+ if ('' == $type) {
1076
+ $type = 'monthly';
1077
+ }
1078
+
1079
+ if ('' != $limit) {
1080
+ $limit = (int) $limit;
1081
+ $limit = ' LIMIT '.$limit;
1082
+ }
1083
+ // this is what will separate dates on weekly archive links
1084
+ $archive_week_separator = '&#8211;';
1085
+
1086
+ // archive link url
1087
+ $archive_link_m = get_settings('siteurl') . '/?m='; # monthly archive;
1088
+ $archive_link_p = get_settings('siteurl') . '/?p='; # post-by-post archive;
1089
+
1090
+ // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
1091
+ $archive_date_format_over_ride = 0;
1092
+
1093
+ // options for daily archive (only if you over-ride the general date format)
1094
+ $archive_day_date_format = 'Y/m/d';
1095
+
1096
+ // options for weekly archive (only if you over-ride the general date format)
1097
+ $archive_week_start_date_format = 'Y/m/d';
1098
+ $archive_week_end_date_format = 'Y/m/d';
1099
+
1100
+ if (!$archive_date_format_over_ride) {
1101
+ $archive_day_date_format = get_settings('date_format');
1102
+ $archive_week_start_date_format = get_settings('date_format');
1103
+ $archive_week_end_date_format = get_settings('date_format');
1104
+ }
1105
+
1106
+ $add_hours = intval(get_settings('gmt_offset'));
1107
+ $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
1108
+
1109
+ $now = current_time('mysql');
1110
+
1111
+ if ("monthly" == $type) {
1112
+ $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) as 'day',count(ID) as 'posts' FROM $wpdb->posts WHERE ".$_query_add." AND post_date < '$now' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC " . $limit);
1113
+ if ($arcresults) {
1114
+ $afterafter = $after;
1115
+ $len = count($arcresults)-1;
1116
+
1117
+ list($jal_startyear,$jal_startmonth,$jal_startday) = gregorian_to_jalali($arcresults[$len]->year,$arcresults[$len]->month,$arcresults[$len]->day);
1118
+ list($jal_endyear,$jal_endmonth,$jal_endday) = gregorian_to_jalali($arcresults[0]->year,$arcresults[0]->month,$arcresults[0]->day);
1119
+ //$jal_year = $jal_startyear;
1120
+ //$jal_month = $jal_startmonth;
1121
+ $jal_year = $jal_endyear;
1122
+ $jal_month = $jal_endmonth + 1;
1123
+ if ($jal_month > 12) {
1124
+ $jal_month = 1;
1125
+ $jal_year++;
1126
+ }
1127
+ while (jmaketime(0,0,0,$jal_month,1,$jal_year) >= jmaketime(0,0,0,$jal_startmonth,1,$jal_startyear)){
1128
+ $jal_nextmonth = $jal_month-1;
1129
+ $jal_nextyear = $jal_year;
1130
+ if ($jal_nextmonth < 1) {
1131
+ $jal_nextmonth = 12;
1132
+ $jal_nextyear--;
1133
+ }
1134
+ $gre_end = date("Y:m:d H:i:s",jmaketime(0,0,0,$jal_month,1,$jal_year));
1135
+ $gre_start = date("Y:m:d H:i:s",jmaketime(0,0,0,$jal_nextmonth,1,$jal_nextyear));
1136
+
1137
+ $jal_post_count = $wpdb->get_results("SELECT COUNT(id) as 'post_count' FROM $wpdb->posts WHERE ".$_query_add." AND post_date < '$now' AND post_status = 'publish' AND post_date >= '$gre_start' AND post_date < '$gre_end'");
1138
+ $jal_posts = $jal_post_count[0]->post_count;
1139
+ if ($jal_posts > 0){
1140
+
1141
+ $url = get_month_link($jal_nextyear, $jal_nextmonth);
1142
+
1143
+ $mps_jd_optionsDB = get_option(MPS_JD_OPTIONS_NAME);
1144
+ $mps_jd_farsinum_date = $mps_jd_optionsDB['mps_jd_farsinum_date'];
1145
+
1146
+ if ($mps_jd_farsinum_date) {
1147
+ $jal_year_text = farsi_num($jal_nextyear);
1148
+ $jal_posts = farsi_num($jal_posts);
1149
+ } else {
1150
+ $jal_year_text = $jal_nextyear;
1151
+ }
1152
+
1153
+ if ($show_post_count) {
1154
+ $text = sprintf('%s %s', $j_month_name[$jal_nextmonth], $jal_year_text);
1155
+ $after = '&nbsp;('.$jal_posts.')' . $afterafter;
1156
+ } else {
1157
+ $text = sprintf('%s %s', $j_month_name[$jal_nextmonth], $jal_year_text);
1158
+ }
1159
+ echo get_archives_link($url, $text, $format, $before, $after);
1160
+ }
1161
+ $jal_month = $jal_nextmonth;
1162
+ $jal_year = $jal_nextyear;
1163
+ }
1164
+ }
1165
+ } else if ("daily" == $type) {
1166
+ $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $wpdb->posts WHERE ".$_query_add." AND post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
1167
+ if ($arcresults) {
1168
+ foreach ($arcresults as $arcresult) {
1169
+ list($jal_year,$jal_month,$jal_dayofmonth) = gregorian_to_jalali($arcresult->year,$arcresult->month,$arcresult->dayofmonth);
1170
+ $url = get_day_link($jal_year, $jal_month, $jal_dayofmonth);
1171
+ //$date = sprintf("%d-%02d-%02d 00:00:00", $jal_year, $jal_month, $jal_dayofmonth);
1172
+ //$text = mysql2date($archive_day_date_format, $date);
1173
+ $date = jmaketime(0,0,0,$jal_month,$jal_dayofmonth,$jal_year);
1174
+ $text = jdate($archive_day_date_format,$date);
1175
+ echo get_archives_link($url, $text, $format, $before, $after);
1176
+ }
1177
+ }
1178
+ } elseif ('postbypost' == $type) {
1179
+ $arcresults = $wpdb->get_results("SELECT ID, post_date, post_title FROM $wpdb->posts WHERE ".$_query_add." AND post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
1180
+ if ($arcresults) {
1181
+ foreach ($arcresults as $arcresult) {
1182
+ if ($arcresult->post_date != '0000-00-00 00:00:00') {
1183
+ $url = get_permalink($arcresult->ID);
1184
+ $arc_title = $arcresult->post_title;
1185
+ if ($arc_title) {
1186
+ $text = strip_tags($arc_title);
1187
+ } else {
1188
+ $text = $arcresult->ID;
1189
+ }
1190
+ echo get_archives_link($url, $text, $format, $before, $after);
1191
+ }
1192
+ }
1193
+ }
1194
+ }
1195
+ }
1196
+
1197
+ function wp_get_jarchives($args = '') {
1198
+ parse_str($args, $r);
1199
+ if (!isset($r['type'])) $r['type'] = '';
1200
+ if (!isset($r['limit'])) $r['limit'] = '';
1201
+ if (!isset($r['format'])) $r['format'] = 'html';
1202
+ if (!isset($r['before'])) $r['before'] = '';
1203
+ if (!isset($r['after'])) $r['after'] = '';
1204
+ if (!isset($r['show_post_count'])) $r['show_post_count'] = false;
1205
+ mps_get_jarchives($r['type'], $r['limit'], $r['format'], $r['before'], $r['after'], $r['show_post_count']);
1206
+ }
1207
+
1208
+
1209
+ function get_jcalendar() {
1210
+ global $wpdb, $m, $monthnum, $year, $timedifference, $month, $day, $posts;
1211
+ global $j_month_name , $j_day_name , $jday_abbrev;
1212
+
1213
+ if (!$posts) {
1214
+ $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
1215
+ if (!$gotsome)
1216
+ return;
1217
+ }
1218
+
1219
+ $week_begins = intval(get_settings('start_of_week'));
1220
+ $add_hours = intval(get_settings('gmt_offset'));
1221
+ $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
1222
+
1223
+ $input_is_gregorian = false;
1224
+
1225
+ if (!empty($monthnum) && !empty($year)) {
1226
+ $thismonth = ''.zeroise(intval($monthnum), 2);
1227
+ $thisyear = ''.intval($year);
1228
+ } elseif (!empty($m)) {
1229
+ $calendar = substr($m, 0, 6);
1230
+ $thisyear = ''.intval(substr($m, 0, 4));
1231
+ if (strlen($m) < 6) {
1232
+ $thismonth = '01';
1233
+ } else {
1234
+ $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
1235
+ }
1236
+ } else {
1237
+ $input_is_gregorian = true;
1238
+ $thisyear = gmdate('Y', current_time('timestamp') + get_settings('gmt_offset') * 3600);
1239
+ $thismonth = gmdate('m', current_time('timestamp') + get_settings('gmt_offset') * 3600);
1240
+ $thisday = gmdate('d', current_time('timestamp') + get_settings('gmt_offset') * 3600);
1241
+ }
1242
+
1243
+ if ($input_is_gregorian) {
1244
+ list($jthisyear,$jthismonth,$jthisday) = gregorian_to_jalali($thisyear,$thismonth,$thisday);
1245
+ $unixmonth = jmaketime(0, 0 , 0, $jthismonth, 1, $jthisyear);
1246
+ } else {
1247
+ $unixmonth = jmaketime(0, 0 , 0, $thismonth, 1, $thisyear);
1248
+ $jthisyear = $thisyear;
1249
+ $jthismonth = $thismonth;
1250
+
1251
+ }
1252
+
1253
+
1254
+
1255
+ $jnextmonth = $jthismonth + 1;
1256
+ $jnextyear = $jthisyear;
1257
+ if ($jnextmonth > 12) {
1258
+ $jnextmonth = 1;
1259
+ $jnextyear++;
1260
+ }
1261
+ //This is so important to change the table dir to RTL and keep it
1262
+ echo '<table id="wp-calendar" style="direction: rtl">
1263
+ <caption>' . $j_month_name[(int) $jthismonth ] . ' ' . jdate('Y', $unixmonth) . '</caption>
1264
+ <thead>
1265
+ <tr>';
1266
+
1267
+ $day_abbrev = $weekday_initial;
1268
+
1269
+ $myweek = array();
1270
+
1271
+ for ($wdcount=0; $wdcount<=6; $wdcount++) {
1272
+ $myweek[]=$jday_abbrev[($wdcount+$week_begins)%7];
1273
+ }
1274
+
1275
+ foreach ($myweek as $wd) {
1276
+ echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">" . $wd . '</th>';
1277
+ }
1278
+
1279
+ echo '
1280
+ </tr>
1281
+ </thead>
1282
+
1283
+ <tfoot>
1284
+ <tr>';
1285
+ $g_startdate = date("Y:m:d H:i:s",jmaketime(0,0,0,$jthismonth,1,$jthisyear));
1286
+ $g_enddate = date("Y:m:d H:i:s",jmaketime(0,0,0,$jnextmonth,1,$jnextyear));
1287
+ $prev = $wpdb->get_results("SELECT count(id) AS prev FROM $wpdb->posts
1288
+ WHERE post_date < '$g_startdate'
1289
+ AND post_status = 'publish'
1290
+ AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
1291
+
1292
+ $next = $wpdb->get_results("SELECT count(id) AS next FROM $wpdb->posts
1293
+ WHERE post_date > '$g_enddate'
1294
+ AND post_status = 'publish'
1295
+ AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
1296
+ if ($prev[0][0] != 0) $is_prev = true; else $is_prev = false;
1297
+ if ($next[0][0] != 0) $is_next = true; else $is_next = false;
1298
+
1299
+ if ($is_prev) {
1300
+ $previous_month = $jthismonth - 1;
1301
+ $previous_year = $jthisyear;
1302
+ if ($previous_month == 0) {
1303
+ $previous_month = 12;
1304
+ $previous_year --;
1305
+ }
1306
+ }
1307
+ if ($is_next) {
1308
+ $next_month = $jthismonth + 1;
1309
+ $next_year = $jthisyear;
1310
+ if ($next_month == 13) {
1311
+ $next_month = 1;
1312
+ $next_year ++;
1313
+ }
1314
+ }
1315
+
1316
+ if ($is_prev) {
1317
+ echo "\n\t\t".'<td abbr="' . $j_month_name[previous_month] . '" colspan="3" id="prev"><a href="' .
1318
+ get_month_link($previous_year, $previous_month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $j_month_name[$previous_month], jdate('Y', jmaketime(0, 0 , 0, $previous_month, 1, $previous_year))) . '">&laquo; ' . $j_month_name[$previous_month] . '</a></td>';
1319
+ } else {
1320
+ echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
1321
+ }
1322
+
1323
+
1324
+ echo "\n\t\t".'<td class="pad">&nbsp;</td>';
1325
+
1326
+ if ($is_next) {
1327
+ echo "\n\t\t".'<td abbr="' . $j_month_name[$next_month] . '" colspan="3" id="next"><a href="' .
1328
+ get_month_link($next_year, $next_month) . '" title="View posts for ' . $j_month_name[$next_month] . ' ' .
1329
+ jdate('Y', jmaketime(0, 0 , 0, $next_month, 1, $next_year)) . '">' . $j_month_name[$next_month] . ' &raquo;</a></td>';
1330
+ } else {
1331
+ echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
1332
+ }
1333
+
1334
+ echo '
1335
+ </tr>
1336
+ </tfoot>
1337
+
1338
+ <tbody>
1339
+ <tr>';
1340
+
1341
+ $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date),MONTH(post_date),YEAR(post_date)
1342
+ FROM $wpdb->posts WHERE 1=1
1343
+ AND post_date > '$g_startdate' AND post_date < '$g_enddate'
1344
+ AND post_status = 'publish'
1345
+ AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
1346
+ if ($dayswithposts) {
1347
+ foreach ($dayswithposts as $daywith) {
1348
+ //$daywithpost[] = $daywith[0];
1349
+ $daywithpost[] = jdate("j",mktime(0,0,0,$daywith[1],$daywith[0],$daywith[2]),true);
1350
+ }
1351
+ } else {
1352
+ $daywithpost = array();
1353
+ }
1354
+
1355
+ if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') ||
1356
+ strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') ||
1357
+ strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari')) {
1358
+ $ak_title_separator = "\n";
1359
+ } else {
1360
+ $ak_title_separator = ', ';
1361
+ }
1362
+
1363
+ $ak_titles_for_day = array();
1364
+ $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom, MONTH(post_date) as month, YEAR(post_date) as year "
1365
+ ."FROM $wpdb->posts "
1366
+ ."WHERE post_date > '$g_startdate' AND post_date < '$g_enddate' "
1367
+ ."AND 1=1 "
1368
+ ."AND post_date < '".current_time('mysql')."' "
1369
+ ."AND post_status = 'publish'"
1370
+ );
1371
+
1372
+
1373
+
1374
+ if ($ak_post_titles) {
1375
+ $i = 0;
1376
+ while ($ak_post_titles[$i]){
1377
+ $ak_post_titles[$i] -> dom = jdate("j",mktime(0,0,0,$ak_post_titles[$i] ->month,$ak_post_titles[$i] ->dom,$ak_post_titles[$i] ->year),true);
1378
+ $i++;
1379
+ }
1380
+ foreach ($ak_post_titles as $ak_post_title) {
1381
+ if (empty($ak_titles_for_day['day_'.$ak_post_title->dom])) {
1382
+ $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
1383
+ }
1384
+ if (empty($ak_titles_for_day["$ak_post_title->dom"])) { // first one
1385
+ $ak_titles_for_day["$ak_post_title->dom"] = str_replace('"', '&quot;', wptexturize($ak_post_title->post_title));
1386
+ } else {
1387
+ $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . str_replace('"', '&quot;', wptexturize($ak_post_title->post_title));
1388
+ }
1389
+ }
1390
+ }
1391
+
1392
+ // See how much we should pad in the beginning
1393
+ $pad = calendar_week_mod(jdate('w', $unixmonth,true)-$week_begins);
1394
+ if (0 != $pad) echo "\n\t\t".'<td colspan="'.$pad.'" class="pad">&nbsp;</td>';
1395
+
1396
+ $daysinmonth = intval(jdate('t', $unixmonth,true));
1397
+ for ($day = 1; $day <= $daysinmonth; ++$day) {
1398
+ list($thiyear,$thismonth,$thisday) = jalali_to_gregorian($jthisyear,$jthismonth,$day);
1399
+ if (isset($newrow) && $newrow)
1400
+ echo "\n\t</tr>\n\t<tr>\n\t\t";
1401
+ $newrow = false;
1402
+ if ($thisday == gmdate('j', (time() + (get_settings('gmt_offset') * 3600))) && $thismonth == gmdate('m', time()+(get_settings('gmt_offset') * 3600)) && $thisyear == gmdate('Y', time()+(get_settings('gmt_offset') * 3600)))
1403
+ echo '<td id="today">';
1404
+ else
1405
+ echo '<td>';
1406
+
1407
+ $mps_jd_optionsDB = get_option(MPS_JD_OPTIONS_NAME);
1408
+ $mps_jd_farsinum_date = $mps_jd_optionsDB['mps_jd_farsinum_date'];
1409
+
1410
+ if ($mps_jd_farsinum_date)
1411
+ $day_text = farsi_num($day);
1412
+ else
1413
+ $day_text = $day;
1414
+
1415
+ if (in_array($day, $daywithpost)) { // any posts today?
1416
+ echo '<a href="' . get_day_link($jthisyear, $jthismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day_text</a>";
1417
+ } else {
1418
+ echo $day_text;
1419
+ }
1420
+ echo '</td>';
1421
+
1422
+ if (6 == calendar_week_mod(date('w', jmaketime(0, 0 , 0, $jthismonth, $day, $jthisyear))-$week_begins))
1423
+ $newrow = true;
1424
+ }
1425
+
1426
+ $pad = 7 - calendar_week_mod(date('w', jmaketime(0, 0 , 0, $jthismonth, $day, $jthisyear))-$week_begins);
1427
+ if ($pad != 0 && $pad != 7)
1428
+ echo "\n\t\t".'<td class="pad" colspan="'.$pad.'">&nbsp;</td>';
1429
+
1430
+ echo "\n\t</tr>\n\t</tbody>\n\t</table>";
1431
+
1432
+ }
1433
+
1434
+ function mps_calendar() {
1435
+ global $m,$year;
1436
+
1437
+ if ($m != '') {
1438
+ $m = '' . preg_replace('|[^0-9]|', '', $m);
1439
+ $i_year = substr($m,0,4);
1440
+ } else if ($year != '') {
1441
+ $i_year = $year;
1442
+ }
1443
+
1444
+ if ($i_year > 1700) get_calendar(); else get_jcalendar();
1445
+
1446
+ }
1447
+
1448
+ function _get_permalink($id = 0) {
1449
+ $rewritecode = array(
1450
+ '%year%',
1451
+ '%monthnum%',
1452
+ '%day%',
1453
+ '%hour%',
1454
+ '%minute%',
1455
+ '%second%',
1456
+ '%postname%',
1457
+ '%post_id%',
1458
+ '%category%',
1459
+ '%author%',
1460
+ '%pagename%'
1461
+ );
1462
+
1463
+ $post = &get_post($id);
1464
+ if ( $post->post_status == 'static' )
1465
+ return get_page_link($post->ID);
1466
+ elseif ($post->post_status == 'object')
1467
+ return get_subpost_link($post->ID);
1468
+
1469
+ $permalink = get_settings('permalink_structure');
1470
+
1471
+ if ( '' != $permalink && 'draft' != $post->post_status ) {
1472
+ $unixtime = strtotime($post->post_date);
1473
+
1474
+ $category = '';
1475
+ if ( strstr($permalink, '%category%') ) {
1476
+ $cats = get_the_category($post->ID);
1477
+ $category = $cats[0]->category_nicename;
1478
+ if ( $parent=$cats[0]->category_parent )
1479
+ $category = get_category_parents($parent, FALSE, '/', TRUE) . $category;
1480
+ }
1481
+
1482
+ $authordata = get_userdata($post->post_author);
1483
+ $author = $authordata->user_nicename;
1484
+ $rewritereplace =
1485
+ array(
1486
+ date('Y', $unixtime),
1487
+ date('m', $unixtime),
1488
+ date('d', $unixtime),
1489
+ date('H', $unixtime),
1490
+ date('i', $unixtime),
1491
+ date('s', $unixtime),
1492
+ $post->post_name,
1493
+ $post->ID,
1494
+ $category,
1495
+ $author,
1496
+ $post->post_name,
1497
+ );
1498
+ return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink), $post);
1499
+ } else { // if they're not using the fancy permalink option
1500
+ $permalink = get_settings('home') . '/?p=' . $post->ID;
1501
+ return apply_filters('post_link', $permalink, $post);
1502
+ }
1503
+ }
1504
+
1505
+ function get_jpermalink($old_perma,$post) {
1506
+ global $wpdb;
1507
+
1508
+ $rewritecode = array(
1509
+ '%year%',
1510
+ '%monthnum%',
1511
+ '%day%',
1512
+ '%hour%',
1513
+ '%minute%',
1514
+ '%second%',
1515
+ '%postname%',
1516
+ '%post_id%',
1517
+ '%category%',
1518
+ '%author%',
1519
+ '%pagename%'
1520
+ );
1521
+
1522
+ if ( $post->post_status == 'static' )
1523
+ return get_page_link($post->ID);
1524
+ elseif ($post->post_status == 'object')
1525
+ return get_subpost_link($post->ID);
1526
+
1527
+
1528
+ $permalink = get_settings('permalink_structure');
1529
+
1530
+ if ( '' != $permalink && 'draft' != $post->post_status ) {
1531
+ $unixtime = strtotime($post->post_date);
1532
+
1533
+ $category = '';
1534
+ if ( strstr($permalink, '%category%') ) {
1535
+ $cats = get_the_category($post->ID);
1536
+ $category = $cats[0]->category_nicename;
1537
+ if ( $parent=$cats[0]->category_parent )
1538
+ $category = get_category_parents($parent, FALSE, '/', TRUE) . $category;
1539
+ }
1540
+
1541
+ $authordata = get_userdata($post->post_author);
1542
+ $author = $authordata->user_nicename;
1543
+ $rewritereplace =
1544
+ array(
1545
+ jdate('Y', $unixtime,true),
1546
+ jdate('m', $unixtime,true),
1547
+ jdate('d', $unixtime,true),
1548
+ jdate('H', $unixtime,true),
1549
+ jdate('i', $unixtime,true),
1550
+ jdate('s', $unixtime,true),
1551
+ $post->post_name,
1552
+ $post->ID,
1553
+ $category,
1554
+ $author,
1555
+ $post->post_name,
1556
+ );
1557
+ return get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink);
1558
+ } else { // if they're not using the fancy permalink option
1559
+ $permalink = get_settings('home') . '/?p=' . $post->ID;
1560
+ return $permalink;
1561
+ }
1562
+ }
1563
+
1564
+ function mps_comments_number($input){
1565
+ $input = farsi_num($input);
1566
+ return $input;
1567
+ }
1568
+
1569
+ function mps_fixmonthnames() {
1570
+ global $month;
1571
+ $month['01'] = "فروردین";
1572
+ $month['02'] = "اردیبهشت";
1573
+ $month['03'] = "خرداد";
1574
+ $month['04'] = "تیر";
1575
+ $month['05'] = "مرداد";
1576
+ $month['06'] = "شهریور";
1577
+ $month['07'] = "مهر";
1578
+ $month['08'] = "آبان";
1579
+ $month['09'] = "آذر";
1580
+ $month['10'] = "دی";
1581
+ $month['11'] = "بهمن";
1582
+ $month['12'] = "اسفند";
1583
+
1584
+ }
1585
+
1586
+ function mps_fixmonthnames_restore() {
1587
+ global $month;
1588
+ $month['01'] = __('January');
1589
+ $month['02'] = __('February');
1590
+ $month['03'] = __('March');
1591
+ $month['04'] = __('April');
1592
+ $month['05'] = __('May');
1593
+ $month['06'] = __('June');
1594
+ $month['07'] = __('July');
1595
+ $month['08'] = __('August');
1596
+ $month['09'] = __('September');
1597
+ $month['10'] = __('October');
1598
+ $month['11'] = __('November');
1599
+ $month['12'] = __('December');
1600
+ }
1601
+
1602
+ function mps_fixtitle($title, $sep=null){
1603
+ global $month,$j_month_name;
1604
+ global $wp_query;
1605
+
1606
+ $m = $wp_query->query_vars['m'];
1607
+
1608
+ if ($m != '') {
1609
+ $m = '' . preg_replace('|[^0-9]|', '', $m);
1610
+ $year = substr($m,0,4);
1611
+ } else {
1612
+ $year = $wp_query->query_vars['year'];
1613
+ }
1614
+
1615
+ if ((isset($year)) && ($year < 1700) && (is_archive())) {
1616
+ unset($j_month_name[0]);
1617
+ $g_months_name = array();
1618
+ foreach ($month as $key=>$val){
1619
+ $g_month_name[(int) $key] = $val;
1620
+ }
1621
+
1622
+ $title = str_replace($g_month_name, $j_month_name, $title);
1623
+ }
1624
+
1625
+ return $title;
1626
+ }
1627
+
1628
+ function mps_fixMCEdir(){
1629
+ echo "directionality : \"rtl\" ,";
1630
+ }
1631
+
1632
+ function mps_mce_pretext($input=null){
1633
+ $_nbsp = "&nbsp;";
1634
+ $_p = "<p dir=\"rtl\">".$_nbsp."</p>";
1635
+ return (strlen($input)==0?$_p:$input);
1636
+ }
1637
+
1638
+ function mps_mce_plugins($input){
1639
+ $input[] = "directionality";
1640
+ return $input;
1641
+ }
1642
+
1643
+ function mps_mce_buttons($input){
1644
+ $new_buttons = array();
1645
+ if (!in_array("rtl",$input)) {
1646
+ $new_buttons = array("separator","ltr","rtl");
1647
+ }
1648
+ return array_merge($input,$new_buttons);
1649
+ }
1650
+
1651
+ function widget_mps_calendar_init() {
1652
+ if ( !function_exists('mps_calendar') )
1653
+ return;
1654
+
1655
+ if ( !function_exists('register_sidebar_widget') )
1656
+ return;
1657
+
1658
+ function mps_calendar_widget($args) {
1659
+ extract($args);
1660
+ $options = get_option('mps_calendar_widget');
1661
+ $title = $options['title'];
1662
+ echo $before_widget;
1663
+ echo $before_title . $title . $after_title;
1664
+ mps_calendar();
1665
+ echo $after_widget;
1666
+ }
1667
+
1668
+ function widget_mps_calendar_control() {
1669
+
1670
+ $options = get_option('mps_calendar_widget');
1671
+ if ( !is_array($options) )
1672
+ $options = array('title'=>'');
1673
+ if ( $_POST['mps_calendar_submit'] ) {
1674
+ $options['title'] = strip_tags(stripslashes($_POST['mps_calendar_title']));
1675
+ update_option('mps_calendar_widget', $options);
1676
+ }
1677
+ $title = htmlspecialchars($options['title'], ENT_QUOTES);
1678
+ ?>
1679
+ <p style="text-align:right; direction:rtl"><label for="mps_calendar_title">عنوان: <input style="width: 200px;" id="mps_calendar_title" name="mps_calendar_title" type="text" value="<?php echo $title; ?>" /></label></p>
1680
+ <input type="hidden" id="mps_calendar_submit" name="mps_calendar_submit" value="1" />
1681
+ <?php
1682
+ }
1683
+
1684
+ register_sidebar_widget('Jalali Calendar','mps_calendar_widget');
1685
+ register_widget_control('Jalali Calendar', 'widget_mps_calendar_control', 250, 100);
1686
+ }
1687
+
1688
+ function widget_jarchive_init() {
1689
+ if ( !function_exists('wp_get_jarchives') )
1690
+ return;
1691
+
1692
+ if ( !function_exists('register_sidebar_widget') )
1693
+ return;
1694
+
1695
+ function jarchive_widget($args) {
1696
+ extract($args);
1697
+ $options = get_option('jarchive_widget');
1698
+ $title = $options['title'];
1699
+ if (!isset($options['type'])) {
1700
+ $type="monthly";
1701
+ } else {
1702
+ $type = $options['type'];
1703
+ }
1704
+ $show_post_count = ($options['show_post_count'] == '1') ? "1" : "0"; // More Safer Way
1705
+ echo $before_widget;
1706
+ echo $before_title . $title . $after_title;
1707
+ echo '<ul>';
1708
+ wp_get_jarchives("type=$type"."&show_post_count=".$show_post_count);
1709
+ echo '</ul>';
1710
+ echo $after_widget;
1711
+ }
1712
+
1713
+ function widget_jarchive_control() {
1714
+
1715
+ $options = get_option('jarchive_widget');
1716
+ if ( !is_array($options) )
1717
+ $options = array('title'=>'');
1718
+ if ( $_POST['jarchive_submit'] ) {
1719
+ $options['title'] = strip_tags(stripslashes($_POST['jarchive_title']));
1720
+ $options['type'] = strip_tags(stripslashes($_POST['jarchive_type']));
1721
+ $options['show_post_count'] = strip_tags(stripslashes($_POST['jarchive_show_post_count']));
1722
+ update_option('jarchive_widget', $options);
1723
+ }
1724
+ $title = htmlspecialchars($options['title'], ENT_QUOTES);
1725
+ $type = htmlspecialchars($options['type'], ENT_QUOTES);
1726
+
1727
+ if (empty($options['type']))
1728
+ $options['type'] = 'monthly';
1729
+ ?>
1730
+ <div dir="rtl" align="justify">
1731
+ <p style="text-align:right"><label for="jarchive_title">عنوان: <input style="width: 200px;" id="jarchive_title" name="jarchive_title" type="text" value="<?php echo $title; ?>" /></label></p>
1732
+ <input name="jarchive_type" type="radio" value="monthly" id="monthly" <?=$options['type']=='monthly' ? 'checked=\"checked\"':'' ?> /> <label for="monthly">ماهیانه</label><br />
1733
+ <input name="jarchive_type" type="radio" value="daily" id="daily" <?=$options['type']=='daily' ? 'checked=\"checked\"':'' ?> /> <label for="daily">روزانه</label><br />
1734
+ <input name="jarchive_type" type="radio" value="postbypost" id="postbypost" <?=$options['type']=='postbypost' ? 'checked=\"checked\"':'' ?> /> <label for="postbypost">نوشته به نوشته</label><br /><br />
1735
+ <input name="jarchive_show_post_count" type="checkbox" value="1" id="show_post_count" <?=$options['show_post_count']=='1' ? 'checked=\"checked\"':'' ?> /> <label for="show_post_count">نمایش تعداد نوشته ها (فقط برای بایگانی ماهیانه)</label>
1736
+ <input type="hidden" id="jarchive_submit" name="jarchive_submit" value="1" />
1737
+ </div>
1738
+ <?php
1739
+ }
1740
+
1741
+ register_sidebar_widget('Jalali Archive','jarchive_widget');
1742
+ register_widget_control('Jalali Archive', 'widget_jarchive_control', 300, 150);
1743
+ }
1744
+
1745
+ function mps_farsikeyboard() {
1746
+ /* Simple API for adding farsitype.js to themes */
1747
+ if (!file_exists(dirname(__FILE__) . '/farsitype.js') ) return;
1748
+ $script_uri = get_settings('siteurl').'/wp-content/plugins/WP-Jalali/farsitype.js';
1749
+ echo "<script language=\"javascript\" src=\"$script_uri\" type=\"text/javascript\"></script>";
1750
+
1751
+ }
1752
+
1753
+
1754
+ $_wp_version = get_bloginfo("version");
1755
+
1756
+ add_action('admin_menu', 'mps_jd_menu');
1757
+
1758
+ if ($_wp_version < 2) {
1759
+ add_action('init', 'mps_fixmonthnames');
1760
+ add_action('wp_head', 'mps_fixmonthnames_restore');
1761
+ } else {
1762
+ add_filter('wp_title', 'mps_fixtitle',2);
1763
+
1764
+ //$richedit = ( 'true' != get_user_option('rich_editing') ) ? false : true;
1765
+ $richedit = true;
1766
+
1767
+ if ($richedit) {
1768
+ add_filter("mce_plugins","mps_mce_plugins");
1769
+ add_filter("mce_buttons","mps_mce_buttons");
1770
+
1771
+ $mps_jd_optionsDB = get_option(MPS_JD_OPTIONS_NAME);
1772
+ $mps_jd_mcertl = $mps_jd_optionsDB['mps_jd_mcertl'];
1773
+ if ((isset($mps_jd_mcertl) && ($mps_jd_mcertl == true))) {
1774
+ add_action('mce_options','mps_fixMCEdir');
1775
+ //add_filter("richedit_pre","mps_mce_pretext");
1776
+ /* The above line commented because of unknown bug of TinyMCE in FireFox */
1777
+ }
1778
+ }
1779
+ }
1780
+
1781
+ add_filter("posts_where","mps_jalali_query");
1782
+
1783
+ $mps_jd_optionsDB = get_option(MPS_JD_OPTIONS_NAME);
1784
+
1785
+ $mps_jd_autodate = $mps_jd_optionsDB['mps_jd_autodate'];
1786
+ $mps_jd_farsinum_content = $mps_jd_optionsDB['mps_jd_farsinum_content'];
1787
+ $mps_jd_farsinum_comment = $mps_jd_optionsDB['mps_jd_farsinum_comment'];
1788
+ $mps_jd_farsinum_commentnum = $mps_jd_optionsDB['mps_jd_farsinum_commentnum'];
1789
+ $mps_jd_farsinum_title = $mps_jd_optionsDB['mps_jd_farsinum_title'];
1790
+ $mps_jd_farsinum_category = $mps_jd_optionsDB['mps_jd_farsinum_category'];
1791
+ $mps_jd_jperma = $mps_jd_optionsDB['mps_jd_jperma'];
1792
+
1793
+ if ($mps_jd_autodate) {
1794
+ add_filter("the_date","mps_the_jdate",10,4);
1795
+ add_filter("the_time","mps_the_jtime",10,4);
1796
+ add_filter("get_comment_date","mps_comment_jdate",10,2); //works only in wp > 1.5.1
1797
+ add_filter("get_comment_time","mps_comment_jtime",10,2); //works only in wp > 1.5.1
1798
+ add_filter("the_weekday","mps_the_jweekday");
1799
+ add_filter("the_weekday_date","mps_the_jweekday_date",10,3);
1800
+ }
1801
+
1802
+ if ($mps_jd_farsinum_content) add_filter("the_content","farsi_num",10);
1803
+ if ($mps_jd_farsinum_comment) add_filter("comment_text","farsi_num",10);
1804
+ if ($mps_jd_farsinum_commentnum) add_filter("comments_number","farsi_num",10);
1805
+ if ($mps_jd_farsinum_title) add_filter("the_title","farsi_num",10,3);
1806
+ if ($mps_jd_farsinum_category) add_filter("wp_list_categories","farsi_num",10,1);
1807
+
1808
+ if ($mps_jd_jperma) add_filter("post_link","get_jpermalink",10,2);
1809
+
1810
+ add_action('widgets_init', 'widget_jarchive_init');
1811
+ add_action('widgets_init', 'widget_mps_calendar_init');
1812
+ ?>
readme.txt ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WP-Jalali ===
2
+ Contributors: mani_monaj
3
+ Donate link: http://www.wishlistr.com/mani_monaj/
4
+ Tags: Persian, Farsi, Jalali, Date, Calendar, i18n, l10n
5
+ Requires at least: 1.5.2
6
+ Tested up to: 2.3-Alpha
7
+ Stable tag: 3.5
8
+
9
+ Turn you Wordpress into a full featured Persian (Iranian) Blogging Platform.
10
+
11
+ == Description ==
12
+
13
+ This plug-in is a "Full Jalali (خورشیدی - شمسی) Date and Persian (Farsi) (فارسی)" Support Package for wordpress. This plug-in with listed features is a great tool for Iranian users of Wordpress.
14
+
15
+ * Full posts' and comments' dates' conversion.
16
+ * Jalali (Monthly and Daily) Archive template tag.
17
+ * Magic (Jalali/Gregorian) Calendar template tag.
18
+ * Jalali/Gregorian compatible permalinks.
19
+ * TinyMCE (Wordpress Editor) Persian improvements.
20
+ * Cross browser Persian keyboard support for themes' comment forms.
21
+ * Jalali Archive/Calendar **fully customized widgets**.
22
+ * Auto Persian numbers conversion.
23
+ * Fully customizable through specific Wordpress admin page.
24
+
25
+ This plug-in is now part of [Persian Wordpress Project](http://www.wp-persian.com/ "پروژه وردپرس فارسی")
26
+
27
+ == Installation ==
28
+
29
+ 1. Extract the downloaded archive into `wp-jalali` folder. If you downloaded the .zip archive it **contains** the `wp-jalali` folder.
30
+ 2. Upload `wp-jalali` to the `/wp-content/plugins/` directory of your wordpress installation.
31
+ 3. If you are using older versions of this plug-in, you must deactivate first through the 'Plugins' menu in Wordpress admin.
32
+ 4. Activate the plug-in through the 'Plugins' menu in Wordpress admin.
33
+
34
+ == Frequently Asked Questions ==
35
+
36
+ = Where can I find more information and documentation about the plug-in? =
37
+
38
+ You can read complete documentations on the [plug-in documentation page](http://codex.wp-persian.com/index.php/%D9%BE%D9%84%D8%A7%DA%AF%DB%8C%D9%86_%D9%88%D8%B1%D8%AF%D9%BE%D8%B1%D8%B3_%D9%81%D8%A7%D8%B1%D8%B3%DB%8C) in Persian (فارسی).
39
+
40
+ = What is Wordpress Persian Project (پروژه وردپرس فارسی) =
41
+
42
+ Just take a look at [this page](http://www.wp-persian.com/en/about/).
43
+
44
+ == Screenshots ==
45
+
46
+ 1. Persian Wordpress Admin Page
screenshot-1.png ADDED
Binary file
wp-fa-logo.png ADDED
Binary file