custom_functions.php
59.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
<?php
if ( ! function_exists( 'get_custom_header' ) ) {
// compatibility with versions of WordPress prior to 3.4.
add_custom_background();
} else {
add_theme_support( 'custom-background', apply_filters( 'et_custom_background_args', array() ) );
}
if (function_exists('add_post_type_support')) add_post_type_support( 'page', 'excerpt' );
add_theme_support( 'automatic-feed-links' );
add_action('init','et_activate_features');
function et_activate_features(){
/* activate shortcodes */
require_once(TEMPLATEPATH . '/epanel/shortcodes/shortcodes.php');
/* activate page templates */
require_once(TEMPLATEPATH . '/epanel/page_templates/page_templates.php');
/* import epanel settings */
require_once(TEMPLATEPATH . '/epanel/import_settings.php');
}
add_filter('widget_text', 'do_shortcode');
add_filter('the_excerpt', 'do_shortcode');
if ( ! function_exists( 'et_options_stored_in_one_row' ) ){
function et_options_stored_in_one_row(){
global $et_store_options_in_one_row;
return isset( $et_store_options_in_one_row ) ? (bool) $et_store_options_in_one_row : false;
}
}
/**
* Gets option value from the single theme option, stored as an array in the database
* if all options stored in one row.
* Stores the serialized array with theme options into the global variable on the first function run on the page.
*
* If options are stored as separate rows in database, it simply uses get_option() function.
*
* @param string $option_name Theme option name.
* @param string $default_value Default value that should be set if the theme option isn't set.
* @param string $used_for_object "Object" name that should be translated into corresponding "object" if WPML is activated.
* @return mixed Theme option value or false if not found.
*/
if ( ! function_exists( 'et_get_option' ) ){
function et_get_option( $option_name, $default_value = '', $used_for_object = '', $force_default_value = false ){
global $et_theme_options, $shortname;
if ( et_options_stored_in_one_row() ){
$et_theme_options_name = 'et_' . $shortname;
if ( ! isset( $et_theme_options ) ) $et_theme_options = get_option( $et_theme_options_name );
$option_value = isset ( $et_theme_options[$option_name] ) ? $et_theme_options[$option_name] : false;
} else {
$option_value = get_option( $option_name );
}
// option value might be equal to false, so check if the option is not set in the database
if ( ! isset( $et_theme_options[ $option_name ] ) && ( '' != $default_value || $force_default_value ) ) {
$option_value = $default_value;
}
if ( '' != $used_for_object && in_array( $used_for_object, array( 'page', 'category' ) ) && is_array( $option_value ) )
$option_value = et_generate_wpml_ids( $option_value, $used_for_object );
return $option_value;
}
}
if ( ! function_exists( 'et_update_option' ) ){
function et_update_option( $option_name, $new_value ){
global $et_theme_options, $shortname;
if ( et_options_stored_in_one_row() ){
$et_theme_options_name = 'et_' . $shortname;
if ( ! isset( $et_theme_options ) ) $et_theme_options = get_option( $et_theme_options_name );
$et_theme_options[$option_name] = $new_value;
$option_name = $et_theme_options_name;
$new_value = $et_theme_options;
}
update_option( $option_name, $new_value );
}
}
if ( ! function_exists( 'et_delete_option' ) ){
function et_delete_option( $option_name ){
global $et_theme_options, $shortname;
if ( et_options_stored_in_one_row() ){
$et_theme_options_name = 'et_' . $shortname;
if ( ! isset( $et_theme_options ) ) $et_theme_options = get_option( $et_theme_options_name );
unset( $et_theme_options[$option_name] );
update_option( $et_theme_options_name, $et_theme_options );
} else {
delete_option( $option_name );
}
}
}
add_filter('body_class','et_browser_body_class');
function et_browser_body_class($classes) {
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
if($is_lynx) $classes[] = 'lynx';
elseif($is_gecko) $classes[] = 'gecko';
elseif($is_opera) $classes[] = 'opera';
elseif($is_NS4) $classes[] = 'ns4';
elseif($is_safari) $classes[] = 'safari';
elseif($is_chrome) $classes[] = 'chrome';
elseif($is_IE) $classes[] = 'ie';
else $classes[] = 'unknown';
if($is_iphone) $classes[] = 'iphone';
return $classes;
}
/*this function allows for the auto-creation of post excerpts*/
if ( ! function_exists( 'truncate_post' ) ){
function truncate_post( $amount, $echo = true, $post = '' ) {
global $shortname;
if ( '' == $post ) global $post;
$post_excerpt = '';
$post_excerpt = apply_filters( 'the_excerpt', $post->post_excerpt );
if ( 'on' == et_get_option( $shortname . '_use_excerpt' ) && '' != $post_excerpt ) {
if ( $echo ) echo $post_excerpt;
else return $post_excerpt;
} else {
// get the post content
$truncate = $post->post_content;
// remove caption shortcode from the post content
$truncate = preg_replace('@\[caption[^\]]*?\].*?\[\/caption]@si', '', $truncate);
// apply content filters
$truncate = apply_filters( 'the_content', $truncate );
// decide if we need to append dots at the end of the string
if ( strlen( $truncate ) <= $amount ) {
$echo_out = '';
} else {
$echo_out = '...';
// $amount = $amount - 3;
}
// trim text to a certain number of characters, also remove spaces from the end of a string ( space counts as a character )
$truncate = rtrim( et_wp_trim_words( $truncate, $amount, '' ) );
// remove the last word to make sure we display all words correctly
if ( '' != $echo_out ) {
$new_words_array = (array) explode( ' ', $truncate );
array_pop( $new_words_array );
$truncate = implode( ' ', $new_words_array );
// append dots to the end of the string
$truncate .= $echo_out;
}
if ( $echo ) echo $truncate;
else return $truncate;
};
}
}
if ( ! function_exists( 'et_wp_trim_words' ) ){
function et_wp_trim_words( $text, $num_words = 55, $more = null ) {
if ( null === $more )
$more = __( '…' );
$original_text = $text;
$text = wp_strip_all_tags( $text );
$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
preg_match_all( '/./u', $text, $words_array );
$words_array = array_slice( $words_array[0], 0, $num_words + 1 );
$sep = '';
if ( count( $words_array ) > $num_words ) {
array_pop( $words_array );
$text = implode( $sep, $words_array );
$text = $text . $more;
} else {
$text = implode( $sep, $words_array );
}
return $text;
}
}
/*this function truncates titles to create preview excerpts*/
if ( ! function_exists( 'truncate_title' ) ){
function truncate_title( $amount, $echo = true, $post = '' ) {
if ( $post == '' ) $truncate = get_the_title();
else $truncate = $post->post_title;
if ( strlen( $truncate ) <= $amount ) $echo_out = '';
else $echo_out = '...';
$truncate = et_wp_trim_words( $truncate, $amount, '' );
if ( '' != $echo_out ) $truncate .= $echo_out;
if ( $echo )
echo $truncate;
else
return $truncate;
}
}
/*this function allows users to use the first image in their post as their thumbnail*/
if ( ! function_exists( 'et_first_image' ) ){
function et_first_image() {
global $post;
$img = '';
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
if ( isset($matches[1][0]) ) $img = $matches[1][0];
return trim($img);
}
}
/* this function gets thumbnail from Post Thumbnail or Custom field or First post image */
if ( ! function_exists( 'get_thumbnail' ) ) {
function get_thumbnail($width=100, $height=100, $class='', $alttext='', $titletext='', $fullpath=false, $custom_field='', $post='') {
if ( $post == '' ) global $post;
global $shortname;
$thumb_array['thumb'] = '';
$thumb_array['use_timthumb'] = true;
if ($fullpath) $thumb_array['fullpath'] = ''; //full image url for lightbox
$new_method = true;
if ( has_post_thumbnail( $post->ID ) ) {
$thumb_array['use_timthumb'] = false;
$et_fullpath = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
$thumb_array['fullpath'] = $et_fullpath[0];
$thumb_array['thumb'] = $thumb_array['fullpath'];
}
if ($thumb_array['thumb'] == '') {
if ($custom_field == '') $thumb_array['thumb'] = esc_attr( get_post_meta($post->ID, 'Thumbnail', $single = true) );
else {
$thumb_array['thumb'] = esc_attr( get_post_meta($post->ID, $custom_field, $single = true) );
if ($thumb_array['thumb'] == '') $thumb_array['thumb'] = esc_attr( get_post_meta($post->ID, 'Thumbnail', $single = true) );
}
if (($thumb_array['thumb'] == '') && ((et_get_option($shortname.'_grab_image')) == 'on')) {
$thumb_array['thumb'] = esc_attr( et_first_image() );
if ( $fullpath ) $thumb_array['fullpath'] = $thumb_array['thumb'];
}
#if custom field used for small pre-cropped image, open Thumbnail custom field image in lightbox
if ($fullpath) {
$thumb_array['fullpath'] = $thumb_array['thumb'];
if ($custom_field == '') $thumb_array['fullpath'] = apply_filters('et_fullpath', et_path_reltoabs(esc_attr($thumb_array['thumb'])));
elseif ( $custom_field <> '' && get_post_meta($post->ID, 'Thumbnail', $single = true) ) $thumb_array['fullpath'] = apply_filters( 'et_fullpath', et_path_reltoabs(esc_attr(get_post_meta($post->ID, 'Thumbnail', $single = true))) );
}
}
return $thumb_array;
}
}
/* this function prints thumbnail from Post Thumbnail or Custom field or First post image */
if ( ! function_exists( 'print_thumbnail' ) ) {
function print_thumbnail($thumbnail = '', $use_timthumb = true, $alttext = '', $width = 100, $height = 100, $class = '', $echoout = true, $forstyle = false, $resize = true, $post='', $et_post_id = '' ) {
if ( is_array( $thumbnail ) ){
extract( $thumbnail );
}
if ( $post == '' ) global $post, $et_theme_image_sizes;
$output = '';
$et_post_id = '' != $et_post_id ? (int) $et_post_id : $post->ID;
if ( has_post_thumbnail( $et_post_id ) ) {
$thumb_array['use_timthumb'] = false;
$image_size_name = $width . 'x' . $height;
$et_size = isset( $et_theme_image_sizes ) && array_key_exists( $image_size_name, $et_theme_image_sizes ) ? $et_theme_image_sizes[$image_size_name] : array( $width, $height );
$et_attachment_image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id( $et_post_id ), $et_size );
$thumbnail = $et_attachment_image_attributes[0];
} else {
$thumbnail_orig = $thumbnail;
$thumbnail = et_multisite_thumbnail( $thumbnail );
$cropPosition = '';
$allow_new_thumb_method = false;
$new_method = true;
$new_method_thumb = '';
$external_source = false;
$allow_new_thumb_method = !$external_source && $new_method && $cropPosition == '';
if ( $allow_new_thumb_method && $thumbnail <> '' ){
$et_crop = get_post_meta( $post->ID, 'et_nocrop', true ) == '' ? true : false;
$new_method_thumb = et_resize_image( et_path_reltoabs($thumbnail), $width, $height, $et_crop );
if ( is_wp_error( $new_method_thumb ) ) $new_method_thumb = '';
}
$thumbnail = $new_method_thumb;
}
if ( false === $forstyle ) {
$output = '<img src="' . esc_url( $thumbnail ) . '"';
if ($class <> '') $output .= " class='" . esc_attr( $class ) . "' ";
$dimensions = apply_filters( 'et_print_thumbnail_dimensions', " width='" . esc_attr( $width ) . "' height='" .esc_attr( $height ) . "'" );
$output .= " alt='" . esc_attr( strip_tags( $alttext ) ) . "'{$dimensions} />";
if ( ! $resize ) $output = $thumbnail;
} else {
$output = $thumbnail;
}
if ($echoout) echo $output;
else return $output;
}
}
if ( ! function_exists( 'et_new_thumb_resize' ) ){
function et_new_thumb_resize( $thumbnail, $width, $height, $alt='', $forstyle = false ){
global $shortname;
$new_method = true;
$new_method_thumb = '';
$external_source = false;
$allow_new_thumb_method = !$external_source && $new_method;
if ( $allow_new_thumb_method && $thumbnail <> '' ){
$et_crop = true;
$new_method_thumb = et_resize_image( $thumbnail, $width, $height, $et_crop );
if ( is_wp_error( $new_method_thumb ) ) $new_method_thumb = '';
}
$thumb = esc_attr( $new_method_thumb );
$output = '<img src="' . esc_url( $thumb ) . '" alt="' . esc_attr( $alt ) . '" width =' . esc_attr( $width ) . ' height=' . esc_attr( $height ) . ' />';
return ( !$forstyle ) ? $output : $thumb;
}
}
if ( ! function_exists( 'et_multisite_thumbnail' ) ){
function et_multisite_thumbnail( $thumbnail = '' ) {
// do nothing if it's not a Multisite installation or current site is the main one
if ( is_main_site() ) return $thumbnail;
# get the real image url
preg_match( '#([_0-9a-zA-Z-]+/)?files/(.+)#', $thumbnail, $matches );
if ( isset( $matches[2] ) ){
$file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $matches[2] );
if ( is_file( $file ) ) $thumbnail = str_replace( ABSPATH, trailingslashit( get_site_url( 1 ) ), $file );
else $thumbnail = '';
}
return $thumbnail;
}
}
if ( ! function_exists( 'et_is_portrait' ) ){
function et_is_portrait($imageurl, $post='', $ignore_cfields = false){
if ( $post == '' ) global $post;
if ( get_post_meta($post->ID,'et_disable_portrait',true) == 1 ) return false;
if ( !$ignore_cfields ) {
if ( get_post_meta($post->ID,'et_imagetype',true) == 'l' ) return false;
if ( get_post_meta($post->ID,'et_imagetype',true) == 'p' ) return true;
}
$imageurl = et_path_reltoabs(et_multisite_thumbnail($imageurl));
$et_thumb_size = @getimagesize($imageurl);
if ( empty($et_thumb_size) ) {
$et_thumb_size = @getimagesize( str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $imageurl ) );
if ( empty($et_thumb_size) ) return false;
}
$et_thumb_width = $et_thumb_size[0];
$et_thumb_height = $et_thumb_size[1];
$result = ($et_thumb_width < $et_thumb_height) ? true : false;
return $result;
}
}
if ( ! function_exists( 'et_path_reltoabs' ) ){
function et_path_reltoabs( $imageurl ){
if ( strpos(strtolower($imageurl), 'http://') !== false || strpos(strtolower($imageurl), 'https://') !== false ) return $imageurl;
if ( strpos( strtolower($imageurl), $_SERVER['HTTP_HOST'] ) !== false )
return $imageurl;
else {
$imageurl = esc_url( apply_filters( 'et_path_relative_image', site_url() . '/' ) . $imageurl );
}
return $imageurl;
}
}
if ( ! function_exists( 'in_subcat' ) ){
function in_subcat($blogcat,$current_cat='') {
$in_subcategory = false;
if (cat_is_ancestor_of($blogcat,$current_cat) || $blogcat == $current_cat) $in_subcategory = true;
return $in_subcategory;
}
}
if ( ! function_exists( 'show_page_menu' ) ){
function show_page_menu($customClass = 'nav clearfix', $addUlContainer = true, $addHomeLink = true){
global $shortname, $themename, $exclude_pages, $strdepth, $page_menu, $is_footer;
//excluded pages
if (et_get_option($shortname.'_menupages') <> '') $exclude_pages = implode(",", et_get_option($shortname.'_menupages'));
//dropdown for pages
$strdepth = '';
if (et_get_option($shortname.'_enable_dropdowns') == 'on') $strdepth = "depth=".et_get_option($shortname.'_tiers_shown_pages');
if ($strdepth == '') $strdepth = "depth=1";
if ($is_footer) { $strdepth="depth=1"; $strdepth2 = $strdepth; }
$page_menu = wp_list_pages("sort_column=".et_get_option($shortname.'_sort_pages')."&sort_order=".et_get_option($shortname.'_order_page')."&".$strdepth."&exclude=".$exclude_pages."&title_li=&echo=0");
if ($addUlContainer) echo('<ul class="'.$customClass.'">');
if (et_get_option($shortname . '_home_link') == 'on' && $addHomeLink) { ?>
<li <?php if (is_front_page() || is_home()) echo('class="current_page_item"') ?>><a href="<?php echo esc_url( home_url() ); ?>"><?php _e('Home',$themename); ?></a></li>
<?php };
echo $page_menu;
if ($addUlContainer) echo('</ul>');
}
}
if ( ! function_exists( 'show_categories_menu' ) ){
function show_categories_menu($customClass = 'nav clearfix', $addUlContainer = true){
global $shortname, $themename, $category_menu, $exclude_cats, $hide, $strdepth2, $projects_cat;
//excluded categories
if (et_get_option($shortname.'_menucats') <> '') $exclude_cats = implode(",", et_get_option($shortname.'_menucats'));
//hide empty categories
if (et_get_option($shortname.'_categories_empty') == 'on') $hide = '1';
else $hide = '0';
//dropdown for categories
$strdepth2 = '';
if (et_get_option($shortname.'_enable_dropdowns_categories') == 'on') $strdepth2 = "depth=".et_get_option($shortname.'_tiers_shown_categories');
if ($strdepth2 == '') $strdepth2 = "depth=1";
$args = "orderby=".et_get_option($shortname.'_sort_cat')."&order=".et_get_option($shortname.'_order_cat')."&".$strdepth2."&exclude=".$exclude_cats."&hide_empty=".$hide."&title_li=&echo=0";
$categories = get_categories( $args );
if ( !empty($categories) ) {
$category_menu = wp_list_categories($args);
if ($addUlContainer) echo('<ul class="'.$customClass.'">');
echo $category_menu;
if ($addUlContainer) echo('</ul>');
}
}
}
function head_addons(){
global $shortname, $default_colorscheme;
if ( apply_filters('et_get_additional_color_scheme',et_get_option($shortname.'_color_scheme')) <> $default_colorscheme ) { ?>
<link rel="stylesheet" href="<?php echo esc_url( get_template_directory_uri() . '/style-' . et_get_option($shortname.'_color_scheme') . '.css' ); ?>" type="text/css" media="screen" />
<?php };
if ( et_get_option($shortname.'_child_css') == 'on' && et_get_option($shortname.'_child_cssurl') <> '' ) { //Enable child stylesheet ?>
<link rel="stylesheet" href="<?php echo esc_url( et_get_option($shortname.'_child_cssurl') ); ?>" type="text/css" media="screen" />
<?php };
//prints the theme name, version in meta tag
if ( ! function_exists( 'get_custom_header' ) ){
// compatibility with versions of WordPress prior to 3.4.
$theme_info = get_theme_data(TEMPLATEPATH . '/style.css');
echo '<meta content="' . esc_attr( $theme_info['Name'] . ' v.' . $theme_info['Version'] ) . '" name="generator"/>';
} else {
$theme_info = wp_get_theme();
echo '<meta content="' . esc_attr( $theme_info->display('Name') . ' v.' . $theme_info->display('Version') ) . '" name="generator"/>';
}
if ( et_get_option( $shortname . '_custom_colors' ) == 'on' ) et_epanel_custom_colors_css();
};// end function head_addons()
add_action('wp_head','head_addons',7);
function integration_head(){
global $shortname;
if (et_get_option($shortname.'_integration_head') <> '' && et_get_option($shortname.'_integrate_header_enable') == 'on') echo( et_get_option($shortname.'_integration_head') );
};
add_action('wp_head','integration_head',12);
function integration_body(){
global $shortname;
if (et_get_option($shortname.'_integration_body') <> '' && et_get_option($shortname.'_integrate_body_enable') == 'on') echo( et_get_option($shortname.'_integration_body') );
};
add_action('wp_footer','integration_body',12);
/*this function gets page name by its id*/
if ( ! function_exists( 'get_pagename' ) ){
function get_pagename( $page_id )
{
$page_object = get_page( $page_id );
return apply_filters( 'the_title', $page_object->post_title, $page_id );
}
}
/*this function gets category name by its id*/
if ( ! function_exists( 'get_categname' ) ){
function get_categname( $cat_id )
{
return get_cat_name( $cat_id );
}
}
/*this function gets category id by its name*/
if ( ! function_exists( 'get_catId' ) ) {
function get_catId( $cat_name, $taxonomy = 'category' )
{
$cat_name_id = is_numeric( $cat_name ) ? (int) $cat_name : (int) get_cat_ID( html_entity_decode( $cat_name, ENT_QUOTES ) );
// wpml compatibility
if ( function_exists( 'icl_object_id' ) ) {
$cat_name_id = (int) icl_object_id( $cat_name_id, $taxonomy, true );
}
return $cat_name_id;
}
}
/*this function gets page id by its name*/
if ( ! function_exists( 'get_pageId' ) ){
function get_pageId( $page_name )
{
if ( is_numeric( $page_name ) ) {
$page_id = intval( $page_name );
} else {
$page_name = html_entity_decode( $page_name, ENT_QUOTES );
$page = get_page_by_title( $page_name );
$page_id = intval( $page->ID );
}
// wpml compatibility
if ( function_exists( 'icl_object_id' ) )
$page_id = (int) icl_object_id( $page_id, 'page', true );
return $page_id;
}
}
/**
* Transforms an array of posts, pages, post_tags or categories ids
* into corresponding "objects" ids, if WPML plugin is installed
*
* @param array $ids_array Posts, pages, post_tags or categories ids.
* @param string $type "Object" type.
* @return array IDs.
*/
if ( ! function_exists( 'et_generate_wpml_ids' ) ){
function et_generate_wpml_ids( $ids_array, $type ) {
if ( function_exists( 'icl_object_id' ) ){
$wpml_ids = array();
foreach ( $ids_array as $id ) {
$translated_id = icl_object_id( $id, $type, false );
if ( ! is_null( $translated_id ) ) $wpml_ids[] = $translated_id;
}
$ids_array = $wpml_ids;
}
return array_map( 'intval', $ids_array );
}
}
if ( ! function_exists( 'elegant_is_blog_posts_page' ) ){
function elegant_is_blog_posts_page() {
/**
* Returns true if static page is set in WP-Admin / Settings / Reading
* and Posts page is displayed
*/
static $et_is_blog_posts_cached = null;
if ( null === $et_is_blog_posts_cached ) {
$et_is_blog_posts_cached = (bool) is_home() && 0 !== intval( get_option( 'page_for_posts', '0' ) );
}
return $et_is_blog_posts_cached;
}
}
// Added for backwards compatibility
if ( ! function_exists( 'elegant_titles' ) ){
function elegant_titles() {
wp_title();
}
}
/*this function controls the meta titles display*/
if ( ! function_exists( 'elegant_titles_filter' ) ){
function elegant_titles_filter( $custom_title, $sep ) {
global $shortname, $themename;
$custom_title = '';
$sitename = get_bloginfo('name');
$site_description = get_bloginfo('description');
#if the title is being displayed on the homepage
if ( ( is_home() || is_front_page() ) && ! elegant_is_blog_posts_page() ) {
if ( 'on' === et_get_option( $shortname . '_seo_home_title' ) ) {
$custom_title = et_get_option( $shortname . '_seo_home_titletext' );
} else {
$seo_home_type = et_get_option( $shortname . '_seo_home_type' );
$seo_home_separate = et_get_option( $shortname . '_seo_home_separate' );
if ( $seo_home_type == 'BlogName | Blog description' ) {
$custom_title = $sitename . esc_html( $seo_home_separate ) . $site_description;
}
if ( $seo_home_type == 'Blog description | BlogName') {
$custom_title = $site_description . esc_html( $seo_home_separate ) . $sitename;
}
if ( $seo_home_type == 'BlogName only') {
$custom_title = $sitename;
}
}
}
#if the title is being displayed on single posts/pages
if ( ( ( is_single() || is_page() ) && ! is_front_page() ) || elegant_is_blog_posts_page() ) {
global $wp_query;
$postid = elegant_is_blog_posts_page() ? intval( get_option( 'page_for_posts' ) ) : $wp_query->post->ID;
$key = et_get_option($shortname.'_seo_single_field_title');
$exists3 = get_post_meta($postid, ''.$key.'', true);
if ( 'on' === et_get_option( $shortname . '_seo_single_title' ) && '' !== $exists3 ) {
$custom_title = $exists3;
} else {
$seo_single_type = et_get_option( $shortname . '_seo_single_type' );
$seo_single_separate = et_get_option( $shortname . '_seo_single_separate' );
$page_title = single_post_title( '', false );
if ( $seo_single_type == 'BlogName | Post title' ) {
$custom_title = $sitename . esc_html( $seo_single_separate ) . $page_title;
}
if ( $seo_single_type == 'Post title | BlogName' ) {
$custom_title = $page_title . esc_html( $seo_single_separate ) . $sitename;
}
if ( $seo_single_type == 'Post title only' ) {
$custom_title = $page_title;
}
}
}
#if the title is being displayed on index pages (categories/archives/search results)
if ( is_category() || is_archive() || is_search() || is_404() ) {
$page_title = '';
$seo_index_type = et_get_option( $shortname . '_seo_index_type' );
$seo_index_separate = et_get_option( $shortname . '_seo_index_separate' );
if ( is_category() || is_tag() || is_tax() ) {
$page_title = single_term_title( '', false );
} else if ( is_post_type_archive() ) {
$page_title = post_type_archive_title( '', false );
} else if ( is_author() ) {
$page_title = get_the_author_meta( 'display_name', get_query_var( 'author' ) );
} else if ( is_date() ) {
$page_title = __( 'Archives', $themename );
} else if ( is_search() ) {
$page_title = sprintf( __( 'Search results for "%s"', $themename ), esc_attr( get_search_query() ) );
} else if ( is_404() ) {
$page_title = __( '404 Not Found', $themename );
}
if ( $seo_index_type == 'BlogName | Category name' ) {
$custom_title = $sitename . esc_html( $seo_index_separate ) . $page_title;
}
if ( $seo_index_type == 'Category name | BlogName') {
$custom_title = $page_title . esc_html( $seo_index_separate ) . $sitename;
}
if ( $seo_index_type == 'Category name only') {
$custom_title = $page_title;
}
}
return wp_strip_all_tags( $custom_title );
}
}
add_filter( 'wp_title', 'elegant_titles_filter', 10, 2 );
/*this function controls the meta description display*/
if ( ! function_exists( 'elegant_description' ) ){
function elegant_description() {
// Don't use ePanel SEO if WordPress SEO or All In One SEO Pack plugins are active
if ( class_exists( 'WPSEO_Frontend' ) || class_exists( 'All_in_One_SEO_Pack' ) ) {
return;
}
global $shortname, $themename;
#homepage descriptions
if ( et_get_option($shortname.'_seo_home_description') == 'on' && ( ( is_home() || is_front_page() ) && ! elegant_is_blog_posts_page() ) ) {
echo '<meta name="description" content="' . esc_attr( et_get_option($shortname.'_seo_home_descriptiontext') ) .'" />';
}
#single page descriptions
if ( et_get_option($shortname.'_seo_single_description') == 'on' && ( is_single() || is_page() || elegant_is_blog_posts_page() ) ) {
global $wp_query;
if ( isset($wp_query->post->ID) || elegant_is_blog_posts_page() ) {
$postid = elegant_is_blog_posts_page() ? intval( get_option( 'page_for_posts' ) ) : $wp_query->post->ID;
}
$key2 = et_get_option($shortname.'_seo_single_field_description');
if ( isset($postid) ) $exists = get_post_meta($postid, ''.$key2.'', true);
if ( $exists !== '' ) {
echo '<meta name="description" content="' . esc_attr( $exists ) . '" />';
}
}
#index descriptions
$seo_index_description = et_get_option($shortname.'_seo_index_description');
if ( $seo_index_description == 'on' ) {
$description_added = false;
if ( is_category() ) {
remove_filter( 'term_description', 'wpautop' );
$cat = get_query_var( 'cat' );
$exists2 = category_description( $cat );
if ( $exists2 !== '' ) {
echo '<meta name="description" content="' . esc_attr( $exists2 ) . '" />';
$description_added = true;
}
}
if ( is_archive() && ! $description_added ) {
printf( '<meta name="description" content="%1$s" />',
esc_attr( sprintf( __( 'Currently viewing archives from %1$s', $themename ),
wp_title( '', false, '' )
) )
);
$description_added = true;
}
if ( is_search() && ! $description_added ) {
echo '<meta name="description" content="' . esc_attr( wp_title('',false,'') ) . '" />';
$description_added = true;
}
}
}
}
/*this function controls the meta keywords display*/
if ( ! function_exists( 'elegant_keywords' ) ){
function elegant_keywords() {
// Don't use ePanel SEO if WordPress SEO or All In One SEO Pack plugins are active
if ( class_exists( 'WPSEO_Frontend' ) || class_exists( 'All_in_One_SEO_Pack' ) ) {
return;
}
global $shortname;
#homepage keywords
if ( et_get_option($shortname.'_seo_home_keywords') == 'on' && ( ( is_home() || is_front_page() ) && ! elegant_is_blog_posts_page() ) ) {
echo '<meta name="keywords" content="' . esc_attr( et_get_option($shortname.'_seo_home_keywordstext') ) . '" />';
}
#single page keywords
if ( et_get_option($shortname.'_seo_single_keywords') == 'on' ) {
global $wp_query;
if ( isset( $wp_query->post->ID ) || elegant_is_blog_posts_page() ) {
$postid = elegant_is_blog_posts_page() ? intval( get_option( 'page_for_posts' ) ) : $wp_query->post->ID;
}
$key3 = et_get_option($shortname.'_seo_single_field_keywords');
if (isset($postid)) $exists4 = get_post_meta($postid, ''.$key3.'', true);
if ( isset($exists4) && $exists4 !== '' ) {
if ( is_single() || is_page() || elegant_is_blog_posts_page() ) echo '<meta name="keywords" content="' . esc_attr( $exists4 ) . '" />';
}
}
}
}
/*this function controls canonical urls*/
if ( ! function_exists( 'elegant_canonical' ) ){
function elegant_canonical() {
// Don't use ePanel SEO if WordPress SEO or All In One SEO Pack plugins are active
if ( class_exists( 'WPSEO_Frontend' ) || class_exists( 'All_in_One_SEO_Pack' ) ) {
return;
}
global $shortname;
#homepage urls
if ( et_get_option($shortname.'_seo_home_canonical') == 'on' && is_home() && ! elegant_is_blog_posts_page() ) {
echo '<link rel="canonical" href="'. esc_url( home_url() ).'" />';
}
#single page urls
if ( et_get_option($shortname.'_seo_single_canonical') == 'on' ) {
global $wp_query;
if ( isset( $wp_query->post->ID ) || elegant_is_blog_posts_page() ) {
$postid = elegant_is_blog_posts_page() ? intval( get_option( 'page_for_posts' ) ) : $wp_query->post->ID;
}
if ( ( is_single() || is_page() || elegant_is_blog_posts_page() ) && ! is_front_page() ) {
echo '<link rel="canonical" href="' . esc_url( get_permalink( $postid ) ) . '" />';
}
}
#index page urls
if ( et_get_option($shortname.'_seo_index_canonical') == 'on' ) {
$current_page_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if ( is_archive() || is_category() || is_search() ) echo '<link rel="canonical" href="'. esc_url( $current_page_url ).'" />';
}
}
}
add_action('wp_head','add_favicon');
function add_favicon(){
global $shortname;
$faviconUrl = et_get_option($shortname.'_favicon');
if ($faviconUrl <> '') echo('<link rel="shortcut icon" href="'.esc_url( $faviconUrl ).'" />');
}
add_action( 'init', 'et_create_images_temp_folder' );
function et_create_images_temp_folder(){
#clean et_temp folder once per week
if ( false !== $last_time = get_option( 'et_schedule_clean_images_last_time' ) ){
$timeout = 86400 * 7;
if ( ( $timeout < ( time() - $last_time ) ) && '' != get_option( 'et_images_temp_folder' ) ) et_clean_temp_images( get_option( 'et_images_temp_folder' ) );
}
if ( false !== get_option( 'et_images_temp_folder' ) ) return;
$uploads_dir = wp_upload_dir();
$destination_dir = ( false === $uploads_dir['error'] ) ? path_join( $uploads_dir['basedir'], 'et_temp' ) : null;
if ( ! wp_mkdir_p( $destination_dir ) ) update_option( 'et_images_temp_folder', '' );
else {
update_option( 'et_images_temp_folder', preg_replace( '#\/\/#', '/', $destination_dir ) );
update_option( 'et_schedule_clean_images_last_time', time() );
}
}
if ( ! function_exists( 'et_clean_temp_images' ) ){
function et_clean_temp_images( $directory ){
$dir_to_clean = @ opendir( $directory );
if ( $dir_to_clean ) {
while (($file = readdir( $dir_to_clean ) ) !== false ) {
if ( substr($file, 0, 1) == '.' )
continue;
if ( is_dir( $directory.'/'.$file ) )
et_clean_temp_images( path_join( $directory, $file ) );
else
@ unlink( path_join( $directory, $file ) );
}
closedir( $dir_to_clean );
}
#set last time cleaning was performed
update_option( 'et_schedule_clean_images_last_time', time() );
}
}
add_filter( 'update_option_upload_path', 'et_update_uploads_dir' );
function et_update_uploads_dir( $upload_path ){
#check if we have 'et_temp' folder within $uploads_dir['basedir'] directory, if not - try creating it, if it's not possible $destination_dir = null
$destination_dir = '';
$uploads_dir = wp_upload_dir();
$et_temp_dir = path_join( $uploads_dir['basedir'], 'et_temp' );
if ( is_dir( $et_temp_dir ) || ( false === $uploads_dir['error'] && wp_mkdir_p( $et_temp_dir ) ) ){
$destination_dir = $et_temp_dir;
update_option( 'et_schedule_clean_images_last_time', time() );
}
update_option( 'et_images_temp_folder', preg_replace( '#\/\/#', '/', $destination_dir ) );
return $upload_path;
}
if ( ! function_exists( 'et_resize_image' ) ){
function et_resize_image( $thumb, $new_width, $new_height, $crop ){
/*
* Fixes the issue with x symbol between width and height values in the filename.
* For instance, sports-400x400.jpg file results in 'image not found' in getimagesize() function.
*/
$thumb = str_replace( '%26%23215%3B', 'x', rawurlencode( $thumb ) );
$thumb = rawurldecode( $thumb );
if ( is_ssl() ) $thumb = preg_replace( '#^http://#', 'https://', $thumb );
$info = pathinfo($thumb);
$ext = $info['extension'];
$name = wp_basename($thumb, ".$ext");
$is_jpeg = false;
$site_uri = apply_filters( 'et_resize_image_site_uri', site_url() );
$site_dir = apply_filters( 'et_resize_image_site_dir', ABSPATH );
// If multisite, not the main site, WordPress version < 3.5 or ms-files rewriting is enabled ( not the fresh WordPress installation, updated from the 3.4 version )
if ( is_multisite() && ! is_main_site() && ( ! function_exists( 'wp_get_mime_types' ) || get_site_option( 'ms_files_rewriting' ) ) ) {
//Get main site url on multisite installation
switch_to_blog( 1 );
$site_uri = site_url();
restore_current_blog();
}
/*
* If we're dealing with an external image ( might be the result of Grab the first image function ),
* return original image url
*/
if ( false === strpos( $thumb, $site_uri ) )
return $thumb;
if ( 'jpeg' == $ext ) {
$ext = 'jpg';
$name = preg_replace( '#.jpeg$#', '', $name );
$is_jpeg = true;
}
$suffix = "{$new_width}x{$new_height}";
$destination_dir = '' != get_option( 'et_images_temp_folder' ) ? preg_replace( '#\/\/#', '/', get_option( 'et_images_temp_folder' ) ) : null;
$matches = apply_filters( 'et_resize_image_site_dir', array(), $site_dir );
if ( !empty($matches) ){
preg_match( '#'.$matches[1].'$#', $site_uri, $site_uri_matches );
if ( !empty($site_uri_matches) ){
$site_uri = str_replace( $matches[1], '', $site_uri );
$site_uri = preg_replace( '#/$#', '', $site_uri );
$site_dir = str_replace( $matches[1], '', $site_dir );
$site_dir = preg_replace( '#\\\/$#', '', $site_dir );
}
}
#get local name for use in file_exists() and get_imagesize() functions
$localfile = str_replace( apply_filters( 'et_resize_image_localfile', $site_uri, $site_dir, et_multisite_thumbnail($thumb) ), $site_dir, et_multisite_thumbnail($thumb) );
$add_to_suffix = '';
if ( file_exists( $localfile ) ) $add_to_suffix = filesize( $localfile ) . '_';
#prepend image filesize to be able to use images with the same filename
$suffix = $add_to_suffix . $suffix;
$destfilename_attributes = '-' . $suffix . '.' . strtolower( $ext );
$checkfilename = ( '' != $destination_dir && null !== $destination_dir ) ? path_join( $destination_dir, $name ) : path_join( dirname( $localfile ), $name );
$checkfilename .= $destfilename_attributes;
if ( $is_jpeg ) $checkfilename = preg_replace( '#.jpg$#', '.jpeg', $checkfilename );
$uploads_dir = wp_upload_dir();
$uploads_dir['basedir'] = preg_replace( '#\/\/#', '/', $uploads_dir['basedir'] );
if ( null !== $destination_dir && '' != $destination_dir && apply_filters('et_enable_uploads_detection', true) ){
$site_dir = trailingslashit( preg_replace( '#\/\/#', '/', $uploads_dir['basedir'] ) );
$site_uri = trailingslashit( $uploads_dir['baseurl'] );
}
#check if we have an image with specified width and height
if ( file_exists( $checkfilename ) ) return str_replace( $site_dir, trailingslashit( $site_uri ), $checkfilename );
$size = @getimagesize( $localfile );
if ( !$size ) return new WP_Error('invalid_image_path', __('Image doesn\'t exist'), $thumb);
list($orig_width, $orig_height, $orig_type) = $size;
#check if we're resizing the image to smaller dimensions
if ( $orig_width > $new_width || $orig_height > $new_height ){
if ( $orig_width < $new_width || $orig_height < $new_height ){
#don't resize image if new dimensions > than its original ones
if ( $orig_width < $new_width ) $new_width = $orig_width;
if ( $orig_height < $new_height ) $new_height = $orig_height;
#regenerate suffix and appended attributes in case we changed new width or new height dimensions
$suffix = "{$add_to_suffix}{$new_width}x{$new_height}";
$destfilename_attributes = '-' . $suffix . '.' . $ext;
$checkfilename = ( '' != $destination_dir && null !== $destination_dir ) ? path_join( $destination_dir, $name ) : path_join( dirname( $localfile ), $name );
$checkfilename .= $destfilename_attributes;
#check if we have an image with new calculated width and height parameters
if ( file_exists($checkfilename) ) return str_replace( $site_dir, trailingslashit( $site_uri ), $checkfilename );
}
#we didn't find the image in cache, resizing is done here
if ( ! function_exists( 'wp_get_image_editor' ) ) {
// compatibility with versions of WordPress prior to 3.5.
$result = image_resize( $localfile, $new_width, $new_height, $crop, $suffix, $destination_dir );
} else {
$et_image_editor = wp_get_image_editor( $localfile );
if ( ! is_wp_error( $et_image_editor ) ) {
$et_image_editor->resize( $new_width, $new_height, $crop );
// generate correct file name/path
$et_new_image_name = $et_image_editor->generate_filename( $suffix, $destination_dir );
do_action( 'et_resize_image_before_save', $et_image_editor, $et_new_image_name );
$et_image_editor->save( $et_new_image_name );
// assign new image path
$result = $et_new_image_name;
} else {
// assign a WP_ERROR ( WP_Image_Editor instance wasn't created properly )
$result = $et_image_editor;
}
}
if ( ! is_wp_error( $result ) ) {
// transform local image path into URI
if ( $is_jpeg ) $thumb = preg_replace( '#.jpeg$#', '.jpg', $thumb);
$site_dir = str_replace( '\\', '/', $site_dir );
$result = str_replace( '\\', '/', $result );
$result = str_replace( '//', '/', $result );
$result = str_replace( $site_dir, trailingslashit( $site_uri ), $result );
}
#returns resized image path or WP_Error ( if something went wrong during resizing )
return $result;
}
#returns unmodified image, for example in case if the user is trying to resize 800x600px to 1920x1080px image
return $thumb;
}
}
add_action( 'pre_get_posts', 'et_custom_posts_per_page' );
function et_custom_posts_per_page( $query = false ) {
global $shortname;
if ( is_admin() ) return;
if ( ! is_a( $query, 'WP_Query' ) || ! $query->is_main_query() ) return;
if ( $query->is_category ) {
$query->set( 'posts_per_page', (int) et_get_option( $shortname . '_catnum_posts', '10' ) );
} elseif ( $query->is_tag ) {
$query->set( 'posts_per_page', (int) et_get_option( $shortname . '_tagnum_posts', '10' ) );
} elseif ( $query->is_search ) {
if ( isset($_GET['et_searchform_submit']) ) {
$postTypes = array();
if ( !isset($_GET['et-inc-posts']) && !isset($_GET['et-inc-pages']) ) $postTypes = array('post');
if ( isset($_GET['et-inc-pages']) ) $postTypes = array('page');
if ( isset($_GET['et-inc-posts']) ) $postTypes[] = 'post';
$query->set( 'post_type', $postTypes );
if ( isset( $_GET['et-month-choice'] ) && $_GET['et-month-choice'] != 'no-choice' ) {
$et_year = substr($_GET['et-month-choice'],0,4);
$et_month = substr($_GET['et-month-choice'], 4, strlen($_GET['et-month-choice'])-4);
$query->set( 'year', absint($et_year) );
$query->set( 'monthnum', absint($et_month) );
}
if ( isset( $_GET['et-cat'] ) && $_GET['et-cat'] != 0 )
$query->set( 'cat', absint($_GET['et-cat']) );
}
$query->set( 'posts_per_page', (int) et_get_option( $shortname . '_searchnum_posts', '10' ) );
} elseif ( $query->is_archive ) {
$query->set( 'posts_per_page', (int) et_get_option( $shortname . '_archivenum_posts', '10' ) );
}
}
add_filter('pre_set_site_transient_update_themes', 'et_check_themes_updates');
function et_check_themes_updates( $update_transient ){
global $wp_version;
if ( !isset($update_transient->checked) ) return $update_transient;
else $themes = $update_transient->checked;
$send_to_api = array(
'action' => 'check_theme_updates',
'installed_themes' => $themes
);
$options = array(
'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
'body' => $send_to_api,
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url()
);
$last_update = new stdClass();
$theme_request = wp_remote_post( 'http://www.elegantthemes.com/api/api.php', $options );
if ( !is_wp_error($theme_request) && wp_remote_retrieve_response_code($theme_request) == 200 ){
$theme_response = unserialize( wp_remote_retrieve_body( $theme_request ) );
if ( !empty($theme_response) ) {
$update_transient->response = array_merge(!empty($update_transient->response) ? $update_transient->response : array(),$theme_response);
$last_update->checked = $themes;
$last_update->response = $theme_response;
}
}
$last_update->last_checked = time();
set_site_transient( 'et_update_themes', $last_update );
return $update_transient;
}
add_filter('site_transient_update_themes', 'et_add_themes_to_update_notification');
function et_add_themes_to_update_notification( $update_transient ){
$et_update_themes = get_site_transient( 'et_update_themes' );
if ( !is_object($et_update_themes) || !isset($et_update_themes->response) ) return $update_transient;
// Fix for warning messages on Dashboard / Updates page
if ( ! is_object( $update_transient ) ) {
$update_transient = new stdClass();
}
$update_transient->response = array_merge(!empty($update_transient->response) ? $update_transient->response : array(), $et_update_themes->response);
return $update_transient;
}
add_filter( 'default_hidden_meta_boxes', 'et_show_hidden_metaboxes', 10, 2 );
function et_show_hidden_metaboxes( $hidden, $screen ){
# make custom fields and excerpt meta boxes show by default
if ( 'post' == $screen->base || 'page' == $screen->base )
$hidden = array('slugdiv', 'trackbacksdiv', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
return $hidden;
}
add_filter('widget_title','et_widget_force_title');
function et_widget_force_title( $title ){
#add an empty title for widgets ( otherwise it might break the sidebar layout )
if ( $title == '' ) $title = ' ';
return $title;
}
//modify the comment counts to only reflect the number of comments minus pings
if( version_compare( phpversion(), '4.4', '>=' ) ) add_filter('get_comments_number', 'et_comment_count', 0);
function et_comment_count( $count ) {
if ( ! is_admin() ) {
global $id;
$get_comments = get_comments( array('post_id' => $id, 'status' => 'approve') );
$comments_by_type = separate_comments($get_comments);
return count($comments_by_type['comment']);
} else {
return $count;
}
}
add_action( 'admin_init', 'et_theme_check_clean_installation' );
function et_theme_check_clean_installation(){
add_action( 'admin_notices', 'et_theme_epanel_reminder' );
}
if ( ! function_exists( 'et_theme_epanel_reminder' ) ){
function et_theme_epanel_reminder(){
global $shortname, $themename, $current_screen;
if ( false === et_get_option( $shortname . '_logo' ) && 'appearance_page_core_functions' != $current_screen->id ){
printf( __('<div class="updated"><p>This is a fresh installation of %1$s theme. Don\'t forget to go to <a href="%2$s">ePanel</a> to set it up. This message will disappear once you have clicked the Save button within the <a href="%2$s">theme\'s options page</a>.</p></div>',$themename), wp_get_theme(), admin_url( 'themes.php?page=core_functions.php' ) );
}
}
}
add_filter( 'gettext', 'et_admin_update_theme_message', 20, 3 );
function et_admin_update_theme_message( $default_translated_text, $original_text, $domain ) {
global $themename;
$theme_page_message = 'There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>. <em>Automatic update is unavailable for this theme.</em>';
$updates_page_message = 'Update package not available.';
if ( is_admin() && $original_text === $theme_page_message ) {
return __( 'There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>. <em>Before you can update your Elegant Themes, you must first install the <a href="https://www.elegantthemes.com/members-area/documentation.html#updater" target="_blank">Elegant Updater Plugin</a> to authenticate your subscription.</em>', $themename );
}
if ( is_admin() && $original_text === $updates_page_message ){
return __( 'Before you can update your Elegant Themes, you must first install the <a href="https://www.elegantthemes.com/members-area/documentation.html#updater" target="_blank">Elegant Updater Plugin</a> to authenticate your subscription.', $themename );
}
return $default_translated_text;
}
add_filter( 'body_class', 'et_add_fullwidth_body_class' );
function et_add_fullwidth_body_class( $classes ){
$fullwidth_view = false;
if ( is_page_template('page-full.php') ) $fullwidth_view = true;
if ( is_page() || is_single() ){
$et_ptemplate_settings = get_post_meta( get_queried_object_id(),'et_ptemplate_settings',true );
$fullwidth = isset( $et_ptemplate_settings['et_fullwidthpage'] ) ? (bool) $et_ptemplate_settings['et_fullwidthpage'] : false;
if ( $fullwidth ) $fullwidth_view = true;
}
if ( is_single() && 'on' == get_post_meta( get_queried_object_id(), '_et_full_post', true ) ) $fullwidth_view = true;
$classes[] = apply_filters( 'et_fullwidth_view_body_class', $fullwidth_view ) ? 'et_fullwidth_view' : 'et_includes_sidebar';
return $classes;
}
function et_add_responsive_shortcodes_css(){
global $shortname;
if ( 'on' == et_get_option( $shortname . '_responsive_shortcodes', 'on' ) )
wp_enqueue_style( 'et-shortcodes-responsive-css', ET_SHORTCODES_DIR . '/css/shortcodes_responsive.css', false, ET_SHORTCODES_VERSION, 'all' );
}
/**
* Loads theme settings
*
*/
if ( ! function_exists( 'et_load_core_options' ) ) {
function et_load_core_options() {
global $shortname;
require_once( get_template_directory() . esc_attr( "/epanel/options_{$shortname}.php" ) );
}
}
/**
* Adds custom css option content to <head>
*
*/
function et_add_custom_css() {
global $shortname;
$custom_css = et_get_option( "{$shortname}_custom_css" );
if ( false === $custom_css || '' == $custom_css ) return;
/**
* The theme doesn't strip slashes from custom css, when saving to the database,
* so it does that before outputting the code on front-end
*/
echo '<style type="text/css" id="et-custom-css">' . "\n" . stripslashes( $custom_css ) . "\n" . '</style>';
}
add_action( 'wp_head', 'et_add_custom_css', 100 );
if ( ! function_exists( 'et_get_google_fonts' ) ) :
/**
* Returns the list of popular google fonts
*
*/
function et_get_google_fonts() {
$google_fonts = array(
'Open Sans' => array(
'styles' => '300italic,400italic,600italic,700italic,800italic,400,300,600,700,800',
'character_set' => 'latin,cyrillic-ext,greek-ext,greek,vietnamese,latin-ext,cyrillic',
'type' => 'sans-serif',
),
'Oswald' => array(
'styles' => '400,300,700',
'character_set' => 'latin,latin-ext',
'type' => 'sans-serif',
),
'Droid Sans' => array(
'styles' => '400,700',
'character_set' => 'latin',
'type' => 'sans-serif',
),
'Lato' => array(
'styles' => '400,100,100italic,300,300italic,400italic,700,700italic,900,900italic',
'character_set' => 'latin',
'type' => 'sans-serif',
),
'Open Sans Condensed' => array(
'styles' => '300,300italic,700',
'character_set' => 'latin,cyrillic-ext,latin-ext,greek-ext,greek,vietnamese,cyrillic',
'type' => 'sans-serif',
),
'PT Sans' => array(
'styles' => '400,400italic,700,700italic',
'character_set' => 'latin,latin-ext,cyrillic',
'type' => 'sans-serif',
),
'Ubuntu' => array(
'styles' => '400,300,300italic,400italic,500,500italic,700,700italic',
'character_set' => 'latin,cyrillic-ext,cyrillic,greek-ext,greek,latin-ext',
'type' => 'sans-serif',
),
'PT Sans Narrow' => array(
'styles' => '400,700',
'character_set' => 'latin,latin-ext,cyrillic',
'type' => 'sans-serif',
),
'Yanone Kaffeesatz' => array(
'styles' => '400,200,300,700',
'character_set' => 'latin,latin-ext',
'type' => 'sans-serif',
),
'Roboto Condensed' => array(
'styles' => '400,300,300italic,400italic,700,700italic',
'character_set' => 'latin,cyrillic-ext,latin-ext,greek-ext,cyrillic,greek,vietnamese',
'type' => 'sans-serif',
),
'Source Sans Pro' => array(
'styles' => '400,200,200italic,300,300italic,400italic,600,600italic,700,700italic,900,900italic',
'character_set' => 'latin,latin-ext',
'type' => 'sans-serif',
),
'Nunito' => array(
'styles' => '400,300,700',
'character_set' => 'latin',
'type' => 'sans-serif',
),
'Francois One' => array(
'styles' => '400',
'character_set' => 'latin,latin-ext',
'type' => 'sans-serif',
),
'Roboto' => array(
'styles' => '400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic',
'character_set' => 'latin,cyrillic-ext,latin-ext,cyrillic,greek-ext,greek,vietnamese',
'type' => 'sans-serif',
),
'Raleway' => array(
'styles' => '400,100,200,300,600,500,700,800,900',
'character_set' => 'latin',
'type' => 'sans-serif',
),
'Arimo' => array(
'styles' => '400,400italic,700italic,700',
'character_set' => 'latin,cyrillic-ext,latin-ext,greek-ext,cyrillic,greek,vietnamese',
'type' => 'sans-serif',
),
'Cuprum' => array(
'styles' => '400,400italic,700italic,700',
'character_set' => 'latin,latin-ext,cyrillic',
'type' => 'sans-serif',
),
'Play' => array(
'styles' => '400,700',
'character_set' => 'latin,cyrillic-ext,cyrillic,greek-ext,greek,latin-ext',
'type' => 'sans-serif',
),
'Dosis' => array(
'styles' => '400,200,300,500,600,700,800',
'character_set' => 'latin,latin-ext',
'type' => 'sans-serif',
),
'Abel' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'sans-serif',
),
'Droid Serif' => array(
'styles' => '400,400italic,700,700italic',
'character_set' => 'latin',
'type' => 'serif',
),
'Arvo' => array(
'styles' => '400,400italic,700,700italic',
'character_set' => 'latin',
'type' => 'serif',
),
'Lora' => array(
'styles' => '400,400italic,700,700italic',
'character_set' => 'latin',
'type' => 'serif',
),
'Rokkitt' => array(
'styles' => '400,700',
'character_set' => 'latin',
'type' => 'serif',
),
'PT Serif' => array(
'styles' => '400,400italic,700,700italic',
'character_set' => 'latin,cyrillic',
'type' => 'serif',
),
'Bitter' => array(
'styles' => '400,400italic,700',
'character_set' => 'latin,latin-ext',
'type' => 'serif',
),
'Merriweather' => array(
'styles' => '400,300,900,700',
'character_set' => 'latin',
'type' => 'serif',
),
'Vollkorn' => array(
'styles' => '400,400italic,700italic,700',
'character_set' => 'latin',
'type' => 'serif',
),
'Cantata One' => array(
'styles' => '400',
'character_set' => 'latin,latin-ext',
'type' => 'serif',
),
'Kreon' => array(
'styles' => '400,300,700',
'character_set' => 'latin',
'type' => 'serif',
),
'Josefin Slab' => array(
'styles' => '400,100,100italic,300,300italic,400italic,600,700,700italic,600italic',
'character_set' => 'latin',
'type' => 'serif',
),
'Playfair Display' => array(
'styles' => '400,400italic,700,700italic,900italic,900',
'character_set' => 'latin,latin-ext,cyrillic',
'type' => 'serif',
),
'Bree Serif' => array(
'styles' => '400',
'character_set' => 'latin,latin-ext',
'type' => 'serif',
),
'Crimson Text' => array(
'styles' => '400,400italic,600,600italic,700,700italic',
'character_set' => 'latin',
'type' => 'serif',
),
'Old Standard TT' => array(
'styles' => '400,400italic,700',
'character_set' => 'latin',
'type' => 'serif',
),
'Sanchez' => array(
'styles' => '400,400italic',
'character_set' => 'latin,latin-ext',
'type' => 'serif',
),
'Crete Round' => array(
'styles' => '400,400italic',
'character_set' => 'latin,latin-ext',
'type' => 'serif',
),
'Cardo' => array(
'styles' => '400,400italic,700',
'character_set' => 'latin,greek-ext,greek,latin-ext',
'type' => 'serif',
),
'Noticia Text' => array(
'styles' => '400,400italic,700,700italic',
'character_set' => 'latin,vietnamese,latin-ext',
'type' => 'serif',
),
'Judson' => array(
'styles' => '400,400italic,700',
'character_set' => 'latin',
'type' => 'serif',
),
'Lobster' => array(
'styles' => '400',
'character_set' => 'latin,cyrillic-ext,latin-ext,cyrillic',
'type' => 'cursive',
),
'Unkempt' => array(
'styles' => '400,700',
'character_set' => 'latin',
'type' => 'cursive',
),
'Changa One' => array(
'styles' => '400,400italic',
'character_set' => 'latin',
'type' => 'cursive',
),
'Special Elite' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Chewy' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Comfortaa' => array(
'styles' => '400,300,700',
'character_set' => 'latin,cyrillic-ext,greek,latin-ext,cyrillic',
'type' => 'cursive',
),
'Boogaloo' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Fredoka One' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Luckiest Guy' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Cherry Cream Soda' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Lobster Two' => array(
'styles' => '400,400italic,700,700italic',
'character_set' => 'latin',
'type' => 'cursive',
),
'Righteous' => array(
'styles' => '400',
'character_set' => 'latin,latin-ext',
'type' => 'cursive',
),
'Squada One' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Black Ops One' => array(
'styles' => '400',
'character_set' => 'latin,latin-ext',
'type' => 'cursive',
),
'Happy Monkey' => array(
'styles' => '400',
'character_set' => 'latin,latin-ext',
'type' => 'cursive',
),
'Passion One' => array(
'styles' => '400,700,900',
'character_set' => 'latin,latin-ext',
'type' => 'cursive',
),
'Nova Square' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Metamorphous' => array(
'styles' => '400',
'character_set' => 'latin,latin-ext',
'type' => 'cursive',
),
'Poiret One' => array(
'styles' => '400',
'character_set' => 'latin,latin-ext,cyrillic',
'type' => 'cursive',
),
'Bevan' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Shadows Into Light' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'The Girl Next Door' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Coming Soon' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Dancing Script' => array(
'styles' => '400,700',
'character_set' => 'latin',
'type' => 'cursive',
),
'Pacifico' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Crafty Girls' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Calligraffitti' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Rock Salt' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Amatic SC' => array(
'styles' => '400,700',
'character_set' => 'latin',
'type' => 'cursive',
),
'Leckerli One' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Tangerine' => array(
'styles' => '400,700',
'character_set' => 'latin',
'type' => 'cursive',
),
'Reenie Beanie' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Satisfy' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Gloria Hallelujah' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Permanent Marker' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Covered By Your Grace' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Walter Turncoat' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Patrick Hand' => array(
'styles' => '400',
'character_set' => 'latin,vietnamese,latin-ext',
'type' => 'cursive',
),
'Schoolbell' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
'Indie Flower' => array(
'styles' => '400',
'character_set' => 'latin',
'type' => 'cursive',
),
);
return apply_filters( 'et_google_fonts', $google_fonts );
}
endif;
if ( ! function_exists( 'et_get_websafe_font_stack' ) ) :
/**
* Determines a websafe font stack, using font type
*
*/
function et_get_websafe_font_stack( $type = 'sans-serif' ) {
$font_stack = '';
switch ( $type ) {
case 'sans-serif':
$font_stack = 'Helvetica, Arial, Lucida, sans-serif';
break;
case 'serif':
$font_stack = 'Georgia, "Times New Roman", serif';
break;
case 'cursive':
$font_stack = 'cursive';
break;
}
return $font_stack;
}
endif;
if ( ! function_exists( 'et_gf_attach_font' ) ) :
/**
* Attaches Google Font to given css elements
*
*/
function et_gf_attach_font( $et_gf_font_name, $elements ) {
$google_fonts = et_get_google_fonts();
printf( '%s { font-family: \'%s\', %s; }',
esc_html( $elements ),
esc_html( $et_gf_font_name ),
et_get_websafe_font_stack( $google_fonts[$et_gf_font_name]['type'] )
);
}
endif;
if ( ! function_exists( 'et_gf_enqueue_fonts' ) ) :
/**
* Enqueues Google Fonts
*
*/
function et_gf_enqueue_fonts( $et_gf_font_names ) {
global $shortname;
if ( ! is_array( $et_gf_font_names ) || empty( $et_gf_font_names ) ) return;
$google_fonts = et_get_google_fonts();
$protocol = is_ssl() ? 'https' : 'http';
foreach ( $et_gf_font_names as $et_gf_font_name ) {
$google_font_character_set = $google_fonts[$et_gf_font_name]['character_set'];
// By default, only latin and latin-ext subsets are loaded, all available subsets can be enabled in ePanel
if ( 'false' == et_get_option( "{$shortname}_gf_enable_all_character_sets", 'false' ) ) {
$latin_ext = '';
if ( false !== strpos( $google_fonts[$et_gf_font_name]['character_set'], 'latin-ext' ) )
$latin_ext = ',latin-ext';
$google_font_character_set = "latin{$latin_ext}";
}
$query_args = array(
'family' => sprintf( '%s:%s',
str_replace( ' ', '+', $et_gf_font_name ),
apply_filters( 'et_gf_set_styles', $google_fonts[$et_gf_font_name]['styles'], $et_gf_font_name )
),
'subset' => apply_filters( 'et_gf_set_character_set', $google_font_character_set, $et_gf_font_name ),
);
$et_gf_font_name_slug = strtolower( str_replace( ' ', '-', $et_gf_font_name ) );
wp_enqueue_style( 'et-gf-' . $et_gf_font_name_slug, esc_url( add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ) ), array(), null );
}
}
endif;