Advertisement
rdusnr

Untitled

Sep 24th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 88.98 KB | None | 0 0
  1. <?php
  2. /**
  3. * Buddypress functions
  4. *
  5. * @package WordPress
  6. * @subpackage Sweetdate
  7. * @author SeventhQueen <themesupport@seventhqueen.com>
  8. * @since Sweetdate 1.0
  9. */
  10.  
  11. //Members Search fields values
  12. global $bp_search_fields;
  13. $bp_search_fields = sq_option( 'bp_search_form' );
  14.  
  15. /**
  16. * Pre-insert buddypress profile fields from theme options panel
  17. */
  18. if ( bp_is_active( 'xprofile' ) ) :
  19. add_action( "wp_ajax_bp_add_custom_fields", "bp_add_custom_fields" );
  20. endif;
  21.  
  22. global $bp_fields, $group2_args, $bp_fields_group2, $group4_args, $bp_fields_group4;
  23. //Base fields
  24. $bp_fields = array(
  25. 'birthday' => __( 'Birthday', 'kleo_framework' ),
  26. 'sex' => __( 'I am a', 'kleo_framework' ),
  27. 'looking_for' => __( 'Looking for a', 'kleo_framework' ),
  28. 'marital_status' => __( 'Marital status', 'kleo_framework' ),
  29. 'city' => __( 'City', 'kleo_framework' ),
  30. 'country' => __( 'Country', 'kleo_framework' ),
  31. );
  32.  
  33.  
  34. //Create new Lifestyle group
  35. $group2_args = array(
  36. 'name' => __( 'Lifestyle', 'kleo_framework' )
  37. );
  38. //field types
  39. $bp_fields_group2 = array(
  40. 'interests' => __( 'Interests', 'kleo_framework' ),
  41. 'vacation' => __( "Favorite Vacations Spot", 'kleo_framework' ),
  42. 'ideal_date' => __( "Ideal First Date", 'kleo_framework' ),
  43. 'looking_for' => __( "Looking for", 'kleo_framework' ),
  44. 'smoking' => __( "Smoking", 'kleo_framework' ),
  45. 'language' => __( "Language", 'kleo_framework' ),
  46. );
  47.  
  48. //Create new Looking for group
  49. $group4_args = array(
  50. 'name' => __( 'Looking for', 'kleo_framework' )
  51. );
  52. $bp_fields_group4 = array(
  53. 1 => __( 'The one thing I am most passionate about:', 'kleo_framework' ),
  54. 2 => __( "Things I am looking for in a person are:", 'kleo_framework' )
  55. );
  56.  
  57. function bp_add_custom_fields( $echo = true ) {
  58.  
  59. global $bp_fields, $group2_args, $bp_fields_group2, $group4_args, $bp_fields_group4;
  60.  
  61. //Birthday
  62. if ( ! xprofile_get_field_id_from_name( $bp_fields['birthday'] ) ) {
  63. xprofile_insert_field(
  64. array(
  65. 'field_group_id' => 1,
  66. 'name' => $bp_fields['birthday'],
  67. 'can_delete' => 1,
  68. 'field_order' => 2,
  69. 'is_required' => true,
  70. 'type' => 'datebox'
  71. )
  72. );
  73. }
  74.  
  75. //I am a
  76. if ( ! xprofile_get_field_id_from_name( $bp_fields['sex'] ) ) {
  77. $sex_list_id = xprofile_insert_field(
  78. array(
  79. 'field_group_id' => 1,
  80. 'name' => $bp_fields['sex'],
  81. 'can_delete' => 1,
  82. 'field_order' => 3,
  83. 'is_required' => true,
  84. 'type' => 'selectbox'
  85. )
  86. );
  87.  
  88. $sex_type = array( __( 'Man', 'kleo_framework' ), __( 'Woman', 'kleo_framework' ) );
  89.  
  90. foreach ( $sex_type as $i => $sex ) {
  91. xprofile_insert_field( array(
  92. 'field_group_id' => 1,
  93. 'parent_id' => $sex_list_id,
  94. 'type' => 'selectbox',
  95. 'name' => $sex,
  96. 'option_order' => $i + 1
  97. ) );
  98. }
  99.  
  100. }
  101.  
  102. //Looking for a
  103. if ( ! xprofile_get_field_id_from_name( $bp_fields['looking_for'] ) ) {
  104. $sex_list_id = xprofile_insert_field(
  105. array(
  106. 'field_group_id' => 1,
  107. 'name' => $bp_fields['looking_for'],
  108. 'can_delete' => 1,
  109. 'field_order' => 4,
  110. 'is_required' => true,
  111. 'type' => 'selectbox'
  112. )
  113. );
  114.  
  115. $sex_type = array( __( 'Woman', 'kleo_framework' ), __( 'Man', 'kleo_framework' ) );
  116.  
  117. foreach ( $sex_type as $i => $sex ) {
  118. xprofile_insert_field( array(
  119. 'field_group_id' => 1,
  120. 'parent_id' => $sex_list_id,
  121. 'type' => 'selectbox',
  122. 'name' => $sex,
  123. 'option_order' => $i + 1
  124. ) );
  125. }
  126.  
  127. }
  128.  
  129.  
  130. //Marital status
  131. if ( ! xprofile_get_field_id_from_name( $bp_fields['marital_status'] ) ) {
  132. $sex_list_id = xprofile_insert_field(
  133. array(
  134. 'field_group_id' => 1,
  135. 'name' => $bp_fields['marital_status'],
  136. 'can_delete' => 1,
  137. 'field_order' => 5,
  138. 'is_required' => true,
  139. 'type' => 'selectbox'
  140. )
  141. );
  142.  
  143. $sex_type = array(
  144. __( 'Single', 'kleo_framework' ),
  145. __( 'Living together', 'kleo_framework' ),
  146. __( 'Married', 'kleo_framework' ),
  147. __( 'Separated', 'kleo_framework' ),
  148. __( 'Divorced', 'kleo_framework' ),
  149. __( 'Widowed', 'kleo_framework' ),
  150. __( 'Prefer not to say', 'kleo_framework' )
  151. );
  152.  
  153. foreach ( $sex_type as $i => $sex ) {
  154. xprofile_insert_field( array(
  155. 'field_group_id' => 1,
  156. 'parent_id' => $sex_list_id,
  157. 'type' => 'selectbox',
  158. 'name' => $sex,
  159. 'option_order' => $i + 1
  160. ) );
  161. }
  162.  
  163. }
  164.  
  165. //City
  166. if ( ! xprofile_get_field_id_from_name( $bp_fields['city'] ) ) {
  167. xprofile_insert_field(
  168. array(
  169. 'field_group_id' => 1,
  170. 'name' => $bp_fields['city'],
  171. 'can_delete' => 1,
  172. 'field_order' => 6,
  173. 'is_required' => true,
  174. 'type' => 'textbox'
  175. )
  176. );
  177. }
  178.  
  179. //Country
  180. if ( ! xprofile_get_field_id_from_name( $bp_fields['country'] ) ) {
  181. $country_list_args = array(
  182. 'field_group_id' => 1,
  183. 'name' => $bp_fields['country'],
  184. 'description' => 'Please select your country',
  185. 'can_delete' => 1,
  186. 'field_order' => 7,
  187. 'is_required' => true,
  188. 'type' => 'selectbox',
  189. 'order_by' => 'default'
  190. );
  191.  
  192. $country_list_id = xprofile_insert_field( $country_list_args );
  193.  
  194. if ( $country_list_id ) {
  195.  
  196. $countries = array(
  197. "Afghanistan",
  198. "Albania",
  199. "Algeria",
  200. "Andorra",
  201. "Angola",
  202. "Antigua and Barbuda",
  203. "Argentina",
  204. "Armenia",
  205. "Australia",
  206. "Austria",
  207. "Azerbaijan",
  208. "Bahamas",
  209. "Bahrain",
  210. "Bangladesh",
  211. "Barbados",
  212. "Belarus",
  213. "Belgium",
  214. "Belize",
  215. "Benin",
  216. "Bhutan",
  217. "Bolivia",
  218. "Bosnia and Herzegovina",
  219. "Botswana",
  220. "Brazil",
  221. "Brunei",
  222. "Bulgaria",
  223. "Burkina Faso",
  224. "Burundi",
  225. "Cambodia",
  226. "Cameroon",
  227. "Canada",
  228. "Cape Verde",
  229. "Central African Republic",
  230. "Chad",
  231. "Chile",
  232. "China",
  233. "Colombi",
  234. "Comoros",
  235. "Congo (Brazzaville)",
  236. "Congo",
  237. "Costa Rica",
  238. "Cote d'Ivoire",
  239. "Croatia",
  240. "Cuba",
  241. "Cyprus",
  242. "Czech Republic",
  243. "Denmark",
  244. "Djibouti",
  245. "Dominica",
  246. "Dominican Republic",
  247. "East Timor (Timor Timur)",
  248. "Ecuador",
  249. "Egypt",
  250. "El Salvador",
  251. "Equatorial Guinea",
  252. "Eritrea",
  253. "Estonia",
  254. "Ethiopia",
  255. "Fiji",
  256. "Finland",
  257. "France",
  258. "Gabon",
  259. "Gambia, The",
  260. "Georgia",
  261. "Germany",
  262. "Ghana",
  263. "Greece",
  264. "Grenada",
  265. "Guatemala",
  266. "Guinea",
  267. "Guinea-Bissau",
  268. "Guyana",
  269. "Haiti",
  270. "Honduras",
  271. "Hungary",
  272. "Iceland",
  273. "India",
  274. "Indonesia",
  275. "Iran",
  276. "Iraq",
  277. "Ireland",
  278. "Israel",
  279. "Italy",
  280. "Jamaica",
  281. "Japan",
  282. "Jordan",
  283. "Kazakhstan",
  284. "Kenya",
  285. "Kiribati",
  286. "Korea, North",
  287. "Korea, South",
  288. "Kuwait",
  289. "Kyrgyzstan",
  290. "Laos",
  291. "Latvia",
  292. "Lebanon",
  293. "Lesotho",
  294. "Liberia",
  295. "Libya",
  296. "Liechtenstein",
  297. "Lithuania",
  298. "Luxembourg",
  299. "Macedonia",
  300. "Madagascar",
  301. "Malawi",
  302. "Malaysia",
  303. "Maldives",
  304. "Mali",
  305. "Malta",
  306. "Marshall Islands",
  307. "Mauritania",
  308. "Mauritius",
  309. "Mexico",
  310. "Micronesia",
  311. "Moldova",
  312. "Monaco",
  313. "Mongolia",
  314. "Morocco",
  315. "Mozambique",
  316. "Myanmar",
  317. "Namibia",
  318. "Nauru",
  319. "Nepal",
  320. "Netherlands",
  321. "New Zealand",
  322. "Nicaragua",
  323. "Niger",
  324. "Nigeria",
  325. "Norway",
  326. "Oman",
  327. "Pakistan",
  328. "Palau",
  329. "Panama",
  330. "Papua New Guinea",
  331. "Paraguay",
  332. "Peru",
  333. "Philippines",
  334. "Poland",
  335. "Portugal",
  336. "Qatar",
  337. "Romania",
  338. "Russia",
  339. "Rwanda",
  340. "Saint Kitts and Nevis",
  341. "Saint Lucia",
  342. "Saint Vincent",
  343. "Samoa",
  344. "San Marino",
  345. "Sao Tome and Principe",
  346. "Saudi Arabia",
  347. "Senegal",
  348. "Serbia and Montenegro",
  349. "Seychelles",
  350. "Sierra Leone",
  351. "Singapore",
  352. "Slovakia",
  353. "Slovenia",
  354. "Solomon Islands",
  355. "Somalia",
  356. "South Africa",
  357. "Spain",
  358. "Sri Lanka",
  359. "Sudan",
  360. "Suriname",
  361. "Swaziland",
  362. "Sweden",
  363. "Switzerland",
  364. "Syria",
  365. "Taiwan",
  366. "Tajikistan",
  367. "Tanzania",
  368. "Thailand",
  369. "Togo",
  370. "Tonga",
  371. "Trinidad and Tobago",
  372. "Tunisia",
  373. "Turkey",
  374. "Turkmenistan",
  375. "Tuvalu",
  376. "Uganda",
  377. "Ukraine",
  378. "United Arab Emirates",
  379. "United Kingdom",
  380. "United States",
  381. "Uruguay",
  382. "Uzbekistan",
  383. "Vanuatu",
  384. "Vatican City",
  385. "Venezuela",
  386. "Vietnam",
  387. "Yemen",
  388. "Zambia",
  389. "Zimbabwe"
  390. );
  391.  
  392. foreach ( $countries as $i => $country ) {
  393. xprofile_insert_field( array(
  394. 'field_group_id' => 1,
  395. 'parent_id' => $country_list_id,
  396. 'type' => 'selectbox',
  397. 'name' => $country,
  398. 'option_order' => $i + 1
  399. ) );
  400. }
  401. }
  402.  
  403.  
  404. }
  405.  
  406. global $wpdb;
  407.  
  408. //Create new Myself Summary group
  409. $group1_args = array(
  410. 'name' => __( 'Myself Summary', 'kleo_framework' )
  411. );
  412.  
  413. $group1_sql = "SELECT id FROM " . $wpdb->base_prefix . "bp_xprofile_groups WHERE name = '" . $group1_args['name'] . "'";
  414. $group1 = $wpdb->get_results( $group1_sql );
  415. if ( count( $group1 ) == 0 ) {
  416. $group1_id = xprofile_insert_field_group( $group1_args ); // group's ID
  417.  
  418. $bp_fields_group1 = array( 'about_me' => __( 'About me', 'kleo_framework' ) );
  419.  
  420.  
  421. //Myself Summary profile field
  422. if ( ! xprofile_get_field_id_from_name( $bp_fields_group1['about_me'] ) ) {
  423. xprofile_insert_field(
  424. array(
  425. 'field_group_id' => $group1_id,
  426. 'name' => $bp_fields_group1['about_me'],
  427. 'can_delete' => 1,
  428. 'field_order' => 1,
  429. 'is_required' => false,
  430. 'type' => 'textarea'
  431. )
  432. );
  433. }
  434. }
  435.  
  436. if ( ! get_group_id_by_name( $group4_args['name'] ) ) {
  437. $group4_id = xprofile_insert_field_group( $group4_args ); // group's ID
  438.  
  439.  
  440. //The one thing I am most passionate about:
  441. if ( ! xprofile_get_field_id_from_name( $bp_fields_group4[1] ) ) {
  442. xprofile_insert_field(
  443. array(
  444. 'field_group_id' => $group4_id,
  445. 'name' => $bp_fields_group4[1],
  446. 'can_delete' => 1,
  447. 'field_order' => 1,
  448. 'is_required' => false,
  449. 'type' => 'textarea'
  450. )
  451. );
  452. }
  453.  
  454. //Things I am looking for in a person are:
  455. if ( ! xprofile_get_field_id_from_name( $bp_fields_group4[2] ) ) {
  456. xprofile_insert_field(
  457. array(
  458. 'field_group_id' => $group4_id,
  459. 'name' => $bp_fields_group4[2],
  460. 'can_delete' => 1,
  461. 'field_order' => 1,
  462. 'is_required' => false,
  463. 'type' => 'textarea'
  464. )
  465. );
  466. }
  467.  
  468. }
  469.  
  470.  
  471. //Create new Lifestyle group
  472.  
  473. //Interests
  474. $group2_sql = "SELECT id FROM " . $wpdb->base_prefix . "bp_xprofile_groups WHERE name = '" . $group2_args['name'] . "'";
  475. $group2 = $wpdb->get_results( $group2_sql );
  476. if ( count( $group2 ) == 0 ) {
  477. $group2_id = xprofile_insert_field_group( $group2_args ); // group's ID
  478.  
  479.  
  480. //Interests profile field
  481. if ( ! xprofile_get_field_id_from_name( $bp_fields_group2['interests'] ) ) {
  482. $interest_id = xprofile_insert_field(
  483. array(
  484. 'field_group_id' => $group2_id,
  485. 'name' => $bp_fields_group2['interests'],
  486. 'can_delete' => 1,
  487. 'field_order' => 1,
  488. 'is_required' => false,
  489. 'type' => 'multiselectbox'
  490. )
  491. );
  492.  
  493. $interests_type = array(
  494. __( 'RV', 'kleo_framework' ),
  495. __( 'Art Enthusiast', 'kleo_framework' ),
  496. __( 'Billiards', 'kleo_framework' ),
  497. __( 'Horses/Equine', 'kleo_framework' ),
  498. __( 'Music', 'kleo_framework' ),
  499. __( 'Business', 'kleo_framework' ),
  500. __( 'Writing', 'kleo_framework' ),
  501. __( 'Snorkelling', 'kleo_framework' ),
  502. __( 'Tenis', 'kleo_framework' ),
  503. __( 'Gardening', 'kleo_framework' ),
  504. __( 'Dogs', 'kleo_framework' ),
  505. __( 'Cats', 'kleo_framework' ),
  506. __( 'Antiques', 'kleo_framework' ),
  507. __( 'Decorating', 'kleo_framework' ),
  508.  
  509.  
  510. );
  511.  
  512. foreach ( $interests_type as $i => $val ) {
  513. xprofile_insert_field( array(
  514. 'field_group_id' => $group2_id,
  515. 'parent_id' => $interest_id,
  516. 'type' => 'selectbox',
  517. 'name' => $val,
  518. 'option_order' => $i + 1
  519. ) );
  520. }
  521. }
  522.  
  523. //Favorite Vacations Spot
  524. if ( ! xprofile_get_field_id_from_name( $bp_fields_group2['vacation'] ) ) {
  525. xprofile_insert_field(
  526. array(
  527. 'field_group_id' => $group2_id,
  528. 'name' => $bp_fields_group2['vacation'],
  529. 'can_delete' => 1,
  530. 'field_order' => 2,
  531. 'is_required' => false,
  532. 'type' => 'textbox'
  533. )
  534. );
  535. }
  536.  
  537. //Ideal First Date
  538. if ( ! xprofile_get_field_id_from_name( $bp_fields_group2['ideal_date'] ) ) {
  539. xprofile_insert_field(
  540. array(
  541. 'field_group_id' => $group2_id,
  542. 'name' => $bp_fields_group2['ideal_date'],
  543. 'can_delete' => 1,
  544. 'field_order' => 3,
  545. 'is_required' => false,
  546. 'type' => 'textbox'
  547. )
  548. );
  549. }
  550.  
  551.  
  552. //Looking for
  553. if ( ! xprofile_get_field_id_from_name( $bp_fields_group2['looking_for'] ) ) {
  554. $looking_for_id = xprofile_insert_field(
  555. array(
  556. 'field_group_id' => $group2_id,
  557. 'name' => $bp_fields_group2['looking_for'],
  558. 'can_delete' => 1,
  559. 'field_order' => 4,
  560. 'is_required' => false,
  561. 'type' => 'multiselectbox'
  562. )
  563. );
  564.  
  565. $looking_for_type = array(
  566. __( 'Cyber Affair/Erotic Chat', 'kleo_framework' ),
  567. __( 'Serious Relationshiop', 'kleo_framework' ),
  568. __( 'Affair', 'kleo_framework' ),
  569. __( 'Just friends', 'kleo_framework' ),
  570.  
  571.  
  572. );
  573.  
  574. foreach ( $looking_for_type as $i => $val ) {
  575. xprofile_insert_field( array(
  576. 'field_group_id' => $group2_id,
  577. 'parent_id' => $looking_for_id,
  578. 'type' => 'selectbox',
  579. 'name' => $val,
  580. 'option_order' => $i + 1
  581. ) );
  582. }
  583.  
  584. }
  585.  
  586. //Language
  587. if ( ! xprofile_get_field_id_from_name( $bp_fields_group2['language'] ) ) {
  588. $language_id = xprofile_insert_field(
  589. array(
  590. 'field_group_id' => $group2_id,
  591. 'name' => $bp_fields_group2['language'],
  592. 'can_delete' => 1,
  593. 'field_order' => 6,
  594. 'is_required' => false,
  595. 'type' => 'multiselectbox'
  596. )
  597. );
  598.  
  599. $language_types = array(
  600. __( 'Bengali', 'kleo_framework' ),
  601. __( 'Cantonese', 'kleo_framework' ),
  602. __( 'Dutch/Africaans', 'kleo_framework' ),
  603. __( 'English', 'kleo_framework' ),
  604. __( 'French', 'kleo_framework' ),
  605. __( 'Farsi', 'kleo_framework' ),
  606. __( 'German', 'kleo_framework' ),
  607. __( 'Italian', 'kleo_framework' ),
  608. __( 'Javanese', 'kleo_framework' ),
  609. __( 'Korean', 'kleo_framework' ),
  610. __( 'Malay', 'kleo_framework' ),
  611. __( 'Punjabi', 'kleo_framework' ),
  612. __( 'Polish', 'kleo_framework' ),
  613. __( 'Portuguese', 'kleo_framework' ),
  614. __( 'Swahili', 'kleo_framework' ),
  615. __( 'Spanish', 'kleo_framework' ),
  616. __( 'Tamil', 'kleo_framework' ),
  617. __( 'Thai', 'kleo_framework' ),
  618. __( 'Turkish', 'kleo_framework' ),
  619. __( 'Vietnamese', 'kleo_framework' ),
  620. );
  621.  
  622. foreach ( $language_types as $i => $val ) {
  623. xprofile_insert_field( array(
  624. 'field_group_id' => $group2_id,
  625. 'parent_id' => $language_id,
  626. 'type' => 'selectbox',
  627. 'name' => $val,
  628. 'option_order' => $i + 1
  629. ) );
  630. }
  631.  
  632. }
  633.  
  634. //Smoking
  635. if ( ! xprofile_get_field_id_from_name( $bp_fields_group2['smoking'] ) ) {
  636. $smoking_id = xprofile_insert_field(
  637. array(
  638. 'field_group_id' => $group2_id,
  639. 'name' => $bp_fields_group2['smoking'],
  640. 'can_delete' => 1,
  641. 'field_order' => 5,
  642. 'is_required' => false,
  643. 'type' => 'selectbox'
  644. )
  645. );
  646.  
  647. $smoking_type = array(
  648. __( 'Never', 'kleo_framework' ),
  649. __( 'Casual smoker', 'kleo_framework' ),
  650. __( 'Daily smoker', 'kleo_framework' ),
  651. );
  652.  
  653. foreach ( $smoking_type as $i => $val ) {
  654. xprofile_insert_field( array(
  655. 'field_group_id' => $group2_id,
  656. 'parent_id' => $smoking_id,
  657. 'type' => 'selectbox',
  658. 'name' => $val,
  659. 'option_order' => $i + 1
  660. ) );
  661. }
  662.  
  663. }
  664.  
  665. }
  666.  
  667.  
  668. //Create new Physical group
  669. $group3_args = array(
  670. 'name' => __( 'Physical', 'kleo_framework' )
  671. );
  672.  
  673. //Physical
  674. $group3_sql = "SELECT id FROM " . $wpdb->base_prefix . "bp_xprofile_groups WHERE name = '" . $group3_args['name'] . "'";
  675. $group3 = $wpdb->get_results( $group3_sql );
  676. if ( count( $group3 ) == 0 ) {
  677. $group3_id = xprofile_insert_field_group( $group3_args ); // group's ID
  678.  
  679. //field types
  680. $bp_fields_group3 = array(
  681. 'height' => __( 'Height', 'kleo_framework' ),
  682. 'hair_color' => __( "Hair Color", 'kleo_framework' ),
  683. 'eye_color' => __( "Eye Color", 'kleo_framework' ),
  684. 'body_type' => __( "Body Type", 'kleo_framework' ),
  685. 'weight' => __( "Weight", 'kleo_framework' ),
  686. 'ethnicity' => __( "Ethnicity", 'kleo_framework' ),
  687. 'best_feature' => __( "Best Feature", 'kleo_framework' )
  688. );
  689.  
  690.  
  691. //Height
  692. if ( ! xprofile_get_field_id_from_name( $bp_fields_group3['height'] ) ) {
  693. xprofile_insert_field(
  694. array(
  695. 'field_group_id' => $group3_id,
  696. 'name' => $bp_fields_group3['height'],
  697. 'can_delete' => 1,
  698. 'field_order' => 1,
  699. 'is_required' => false,
  700. 'type' => 'textbox'
  701. )
  702. );
  703. }
  704.  
  705. //Weight
  706. if ( ! xprofile_get_field_id_from_name( $bp_fields_group3['weight'] ) ) {
  707. xprofile_insert_field(
  708. array(
  709. 'field_group_id' => $group3_id,
  710. 'name' => $bp_fields_group3['weight'],
  711. 'can_delete' => 1,
  712. 'field_order' => 1,
  713. 'is_required' => false,
  714. 'type' => 'textbox'
  715. )
  716. );
  717. }
  718.  
  719.  
  720. //Hair color
  721. if ( ! xprofile_get_field_id_from_name( $bp_fields_group3['hair_color'] ) ) {
  722. $hair_color_id = xprofile_insert_field(
  723. array(
  724. 'field_group_id' => $group3_id,
  725. 'name' => $bp_fields_group3['hair_color'],
  726. 'can_delete' => 1,
  727. 'field_order' => 2,
  728. 'is_required' => false,
  729. 'type' => 'selectbox'
  730. )
  731. );
  732.  
  733. $hair_color_type = array(
  734. __( 'Auburn', 'kleo_framework' ),
  735. __( 'Black', 'kleo_framework' ),
  736. __( 'Blond', 'kleo_framework' ),
  737. __( 'Brown', 'kleo_framework' ),
  738. __( 'Chestnut', 'kleo_framework' ),
  739. __( 'Gray/White', 'kleo_framework' ),
  740. );
  741.  
  742. foreach ( $hair_color_type as $i => $val ) {
  743. xprofile_insert_field( array(
  744. 'field_group_id' => $group3_id,
  745. 'parent_id' => $hair_color_id,
  746. 'type' => 'selectbox',
  747. 'name' => $val,
  748. 'option_order' => $i + 1
  749. ) );
  750. }
  751. }
  752.  
  753.  
  754. //Eye color
  755. if ( ! xprofile_get_field_id_from_name( $bp_fields_group3['eye_color'] ) ) {
  756. $eye_color_id = xprofile_insert_field(
  757. array(
  758. 'field_group_id' => $group3_id,
  759. 'name' => $bp_fields_group3['eye_color'],
  760. 'can_delete' => 1,
  761. 'field_order' => 3,
  762. 'is_required' => false,
  763. 'type' => 'selectbox'
  764. )
  765. );
  766.  
  767. $eye_color_type = array(
  768. __( 'Black', 'kleo_framework' ),
  769. __( 'Blue', 'kleo_framework' ),
  770. __( 'Brown', 'kleo_framework' ),
  771. __( 'Hazel', 'kleo_framework' ),
  772. __( 'Gray', 'kleo_framework' ),
  773. __( 'Green', 'kleo_framework' ),
  774. __( 'Music', 'kleo_framework' )
  775. );
  776.  
  777. foreach ( $eye_color_type as $i => $val ) {
  778. xprofile_insert_field( array(
  779. 'field_group_id' => $group3_id,
  780. 'parent_id' => $eye_color_id,
  781. 'type' => 'selectbox',
  782. 'name' => $val,
  783. 'option_order' => $i + 1
  784. ) );
  785. }
  786. }
  787.  
  788.  
  789. //Body type
  790. if ( ! xprofile_get_field_id_from_name( $bp_fields_group3['body_type'] ) ) {
  791. $body_type_id = xprofile_insert_field(
  792. array(
  793. 'field_group_id' => $group3_id,
  794. 'name' => $bp_fields_group3['body_type'],
  795. 'can_delete' => 1,
  796. 'field_order' => 4,
  797. 'is_required' => false,
  798. 'type' => 'selectbox'
  799. )
  800. );
  801.  
  802. $body_type_type = array(
  803. __( 'Apple', 'kleo_framework' ),
  804. __( 'Pear', 'kleo_framework' ),
  805. __( 'Athletic', 'kleo_framework' ),
  806. __( 'Hourglass', 'kleo_framework' ),
  807. __( 'Slender', 'kleo_framework' ),
  808. __( 'Inverted Triangle', 'kleo_framework' ),
  809. __( 'Tall', 'kleo_framework' ),
  810. __( 'Petite', 'kleo_framework' ),
  811. __( 'Slender', 'kleo_framework' )
  812.  
  813. );
  814.  
  815. foreach ( $body_type_type as $i => $val ) {
  816. xprofile_insert_field( array(
  817. 'field_group_id' => $group3_id,
  818. 'parent_id' => $body_type_id,
  819. 'type' => 'selectbox',
  820. 'name' => $val,
  821. 'option_order' => $i + 1
  822. ) );
  823. }
  824. }
  825.  
  826.  
  827. //Ethnicity type
  828. if ( ! xprofile_get_field_id_from_name( $bp_fields_group3['ethnicity'] ) ) {
  829. $ethnicity_id = xprofile_insert_field(
  830. array(
  831. 'field_group_id' => $group3_id,
  832. 'name' => $bp_fields_group3['ethnicity'],
  833. 'can_delete' => 1,
  834. 'field_order' => 5,
  835. 'is_required' => false,
  836. 'type' => 'selectbox'
  837. )
  838. );
  839.  
  840. $ethnicity_type = array(
  841. __( 'Caucasian', 'kleo_framework' ),
  842. __( 'Black', 'kleo_framework' ),
  843. __( 'Hispanic', 'kleo_framework' ),
  844. __( 'Middle Eastern', 'kleo_framework' ),
  845. __( 'Native American', 'kleo_framework' ),
  846. __( 'Asian', 'kleo_framework' ),
  847. __( 'Mixed Race', 'kleo_framework' ),
  848. __( 'Other Ethnicity', 'kleo_framework' )
  849. );
  850.  
  851. foreach ( $ethnicity_type as $i => $val ) {
  852. xprofile_insert_field( array(
  853. 'field_group_id' => $group3_id,
  854. 'parent_id' => $ethnicity_id,
  855. 'type' => 'selectbox',
  856. 'name' => $val,
  857. 'option_order' => $i + 1
  858. ) );
  859. }
  860. }
  861.  
  862.  
  863. //Best feature
  864. if ( ! xprofile_get_field_id_from_name( $bp_fields_group3['best_feature'] ) ) {
  865. xprofile_insert_field(
  866. array(
  867. 'field_group_id' => $group3_id,
  868. 'name' => $bp_fields_group3['best_feature'],
  869. 'can_delete' => 1,
  870. 'field_order' => 6,
  871. 'is_required' => false,
  872. 'type' => 'textbox'
  873. )
  874. );
  875. }
  876.  
  877. }
  878. if ( $echo ) {
  879. echo 'Import successful';
  880.  
  881. } else {
  882. return 'true';
  883. }
  884. die();
  885.  
  886. }
  887.  
  888. // -----------------------------------------------------------------------------
  889.  
  890.  
  891. /*
  892. * Copy bp-custom.php to plugins directory
  893. *
  894. */
  895. if ( ! get_option( 'kleo_framework' . "_bp_custom_" . SQUEEN_THEME_VERSION ) && ! file_exists( WP_PLUGIN_DIR . "/bp-custom.php" ) ) {
  896. if ( copy( FRAMEWORK_URL . "/inc/bp-custom.php", WP_PLUGIN_DIR . "/bp-custom.php" ) ) {
  897. add_option( 'kleo_framework' . "_bp_custom_" . SQUEEN_THEME_VERSION, 1 );
  898. }
  899. }
  900. // -----------------------------------------------------------------------------
  901.  
  902.  
  903. /*
  904. * Custom group search form
  905. *
  906. */
  907. if ( ! function_exists( 'bp_my_directory_groups_search_form' ) ) :
  908. function bp_my_directory_groups_search_form() {
  909.  
  910. $default_search_value = bp_get_search_default_text( 'groups' );
  911. $search_value = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
  912.  
  913. <form action="" method="get" id="search-groups-form" class="custom">
  914. <div class="row collapse">
  915. <div class="nine columns">
  916. <label><input type="text" name="s" id="groups_search"
  917. placeholder="<?php echo esc_attr( $search_value ) ?>"/></label>
  918. </div>
  919. <div class="three columns">
  920. <input class="button small radius secondary expand postfix" type="submit" id="groups_search_submit"
  921. name="groups_search_submit" value="<?php _e( 'Search', 'kleo_framework' ) ?>"/>
  922. </div>
  923. </div>
  924. </form>
  925.  
  926. <?php
  927. }
  928. endif;
  929.  
  930.  
  931. /*
  932. * Custom blogs search form
  933. *
  934. */
  935. if ( ! function_exists( 'bp_my_directory_blogs_search_form' ) ) :
  936. function bp_my_directory_blogs_search_form() {
  937.  
  938. $default_search_value = bp_get_search_default_text();
  939. $search_value = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
  940.  
  941. <form action="" method="get" id="search-blogs-form">
  942. <div class="row collapse">
  943. <div class="nine columns">
  944. <label><input type="text" name="s" id="blogs_search"
  945. placeholder="<?php echo esc_attr( $search_value ) ?>"/></label>
  946. </div>
  947. <div class="three columns">
  948. <input type="submit" id="blogs_search_submit" class="button small radius secondary expand postfix"
  949. name="blogs_search_submit" value="<?php _e( 'Search', 'kleo_framework' ) ?>"/>
  950. </div>
  951. </div>
  952. </form>
  953.  
  954. <?php
  955. }
  956. endif;
  957.  
  958.  
  959. if ( ! function_exists( 'bp_signup_password_value' ) ):
  960. function bp_signup_password_value() {
  961. echo bp_get_signup_password_value();
  962. }
  963.  
  964. function bp_get_signup_password_value() {
  965. $value = '';
  966. if ( isset( $_POST['signup_password'] ) ) {
  967. $value = $_POST['signup_password'];
  968. }
  969.  
  970. return apply_filters( 'bp_get_signup_password_value', $value );
  971. }
  972. endif;
  973.  
  974. if ( ! function_exists( 'bp_signup_password_confirm_value' ) ):
  975. function bp_signup_password_confirm_value() {
  976. echo bp_get_signup_password_confirm_value();
  977. }
  978.  
  979. function bp_get_signup_password_confirm_value() {
  980. $value = '';
  981. if ( isset( $_POST['signup_password_confirm'] ) ) {
  982. $value = $_POST['signup_password_confirm'];
  983. }
  984.  
  985. return apply_filters( 'bp_get_signup_password_confirm_value', $value );
  986. }
  987. endif;
  988.  
  989.  
  990. /*
  991. * Add Prev,Next links after breadcrumb if it is a profile page
  992. */
  993. function bp_add_profile_navigation() {
  994. if ( bp_is_user() ): ?>
  995.  
  996. <div class="three columns">
  997. <ul class="inline-list right">
  998. <li><?php _e( "Quick profile navigation", 'kleo_framework' ); ?> </li>
  999. <?php $prev = bp_prev_profile( bp_displayed_user_id() );
  1000. if ( $prev !== "#" ) : ?>
  1001. <li><a href="<?php echo $prev; ?>" title="<?php _e( "Previous profile", 'kleo_framework' ); ?>"><i
  1002. class="icon-chevron-left"></i></a></li><?php endif; ?>
  1003. <?php $next = bp_next_profile( bp_displayed_user_id() );
  1004. if ( $next !== "#" ) : ?>
  1005. <li><a href="<?php echo $next; ?>" title="<?php _e( "Next profile", 'kleo_framework' ); ?>"><i
  1006. class="icon-chevron-right"></i></a></li><?php endif; ?>
  1007. </ul>
  1008. </div>
  1009.  
  1010. <?php endif;
  1011.  
  1012. }
  1013.  
  1014. add_action( 'kleo_after_breadcrumb', 'bp_add_profile_navigation' );
  1015.  
  1016. /**
  1017. * Get next profile link
  1018. *
  1019. * @param int $current_id Displayer user ID
  1020. *
  1021. * @return string User link
  1022. */
  1023. if ( ! function_exists( 'bp_next_profile' ) ):
  1024. function bp_next_profile( $current_id ) {
  1025. global $wpdb;
  1026.  
  1027. $extra = '';
  1028. $obj = new stdClass();
  1029. do_action_ref_array( 'bp_pre_user_query_construct', array( &$obj ) );
  1030. if ( isset( $obj->query_vars ) && $obj->query_vars && $obj->query_vars['exclude'] && is_array( $obj->query_vars['exclude'] ) && ! empty( $obj->query_vars['exclude'] ) ) {
  1031. $extra = " AND us.ID NOT IN (" . implode( ",", $obj->query_vars['exclude'] ) . ")";
  1032. }
  1033.  
  1034. $sql = "SELECT MIN(us.ID) FROM " . $wpdb->base_prefix . "users us"
  1035. . " JOIN " . $wpdb->base_prefix . "bp_xprofile_data bp ON us.ID = bp.user_id"
  1036. . " JOIN " . $wpdb->base_prefix . "usermeta um ON um.user_id = us.ID"
  1037. . " WHERE um.meta_key = 'last_activity' AND us.ID > $current_id"
  1038. . $extra;
  1039.  
  1040. if ( $wpdb->get_var( $sql ) && $wpdb->get_var( $sql ) !== $current_id ) {
  1041. return bp_core_get_user_domain( $wpdb->get_var( $sql ) );
  1042. } else {
  1043. return '#';
  1044. }
  1045. }
  1046. endif;
  1047.  
  1048. /**
  1049. * Get previous profile link
  1050. *
  1051. * @param int $current_id Displayer user ID
  1052. *
  1053. * @return string User link
  1054. */
  1055. if ( ! function_exists( 'bp_prev_profile' ) ):
  1056. function bp_prev_profile( $current_id ) {
  1057. global $wpdb;
  1058.  
  1059. $extra = '';
  1060. $obj = new stdClass();
  1061. do_action_ref_array( 'bp_pre_user_query_construct', array( &$obj ) );
  1062. if ( isset( $obj->query_vars ) && $obj->query_vars && $obj->query_vars['exclude'] && is_array( $obj->query_vars['exclude'] ) && ! empty( $obj->query_vars['exclude'] ) ) {
  1063. $extra = " AND us.ID NOT IN (" . implode( ",", $obj->query_vars['exclude'] ) . ")";
  1064. }
  1065.  
  1066. $sql = "SELECT MAX(us.ID) FROM " . $wpdb->base_prefix . "users us"
  1067. . " JOIN " . $wpdb->base_prefix . "bp_xprofile_data bp ON us.ID = bp.user_id"
  1068. . " JOIN " . $wpdb->base_prefix . "usermeta um ON um.user_id = us.ID"
  1069. . " WHERE um.meta_key = 'last_activity' AND us.ID < $current_id"
  1070. . $extra;
  1071.  
  1072. if ( $wpdb->get_var( $sql ) && $wpdb->get_var( $sql ) !== $current_id ) {
  1073. return bp_core_get_user_domain( $wpdb->get_var( $sql ) );
  1074. } else {
  1075. return '#';
  1076. }
  1077. }
  1078. endif;
  1079.  
  1080. if ( ! function_exists( 'bp_get_online_users' ) ):
  1081. /**
  1082. * Return Buddypress online users
  1083. * @global object $wpdb
  1084. *
  1085. * @param string $value
  1086. *
  1087. * @return integer
  1088. */
  1089. function bp_get_online_users( $value = false, $field = false ) {
  1090. global $wpdb;
  1091. $match_ids = array();
  1092.  
  1093. /* If we want to get specific members */
  1094. if ( $value ) {
  1095.  
  1096. if ( ! $field ) {
  1097. $default_sex = get_profile_id_by_name( 'I am a' );
  1098. $sex = sq_option( 'bp_sex_field', $default_sex );
  1099. if ( $sex == 0 ) {
  1100. $sex = $default_sex;
  1101. }
  1102. } else {
  1103. if( is_numeric( $field ) ) {
  1104. $sex = $field;
  1105. } else {
  1106. $sex = get_profile_id_by_name( $field );
  1107. }
  1108. }
  1109.  
  1110. $where = " WHERE field_id = '" . $sex . "' AND value = '" . esc_sql( $value ) . "'";
  1111. $sql = "SELECT " . $wpdb->base_prefix . "bp_xprofile_data.user_id FROM " . $wpdb->base_prefix . "bp_xprofile_data
  1112. $where";
  1113.  
  1114. $match_ids = $wpdb->get_col( $sql );
  1115. if ( ! $match_ids ) {
  1116. $match_ids = array( 0 );
  1117. }
  1118. }
  1119. $i = 0;
  1120.  
  1121. if ( ! empty( $match_ids ) ) {
  1122. $include_members = '&include=' . join( ",", $match_ids );
  1123. } else {
  1124. $include_members = '';
  1125. }
  1126.  
  1127. if ( bp_has_members( 'user_id=0&type=online&per_page=99999999&populate_extras=0' . $include_members ) ) :
  1128. while ( bp_members() ) : bp_the_member();
  1129. $i ++;
  1130. endwhile;
  1131. endif;
  1132.  
  1133. return apply_filters( 'kleo_online_users_count', $i, $value );
  1134. }
  1135. endif;
  1136.  
  1137. if ( ! function_exists( 'bp_member_statistics' ) ):
  1138. /**
  1139. * @deprecated since 3.0
  1140. * @use sq_bp_member_stats
  1141. */
  1142. function bp_member_statistics( $field = false, $value = false, $online = false ) {
  1143. global $wpdb;
  1144.  
  1145. // If field not set, get Gender from theme options
  1146. if ( ! $field ) {
  1147. $field = 'I am a';
  1148. $db_field = sq_option( 'bp_sex_field' );
  1149. if ( $db_field ) {
  1150. $field_data = new BP_XProfile_Field( $db_field );
  1151. $field = $field_data->name;
  1152. }
  1153. }
  1154.  
  1155. $where = " WHERE name = '" . $field . "' AND value = '" . esc_sql( $value ) . "'";
  1156. $sql = "SELECT " . $wpdb->base_prefix . "bp_xprofile_data.user_id FROM " . $wpdb->base_prefix . "bp_xprofile_data
  1157. JOIN " . $wpdb->base_prefix . "bp_xprofile_fields ON " . $wpdb->base_prefix . "bp_xprofile_data.field_id = " . $wpdb->base_prefix . "bp_xprofile_fields.id
  1158. $where";
  1159.  
  1160. $match_ids = $wpdb->get_col( $sql );
  1161. if ( ! $online ) {
  1162. return count( $match_ids );
  1163. }
  1164.  
  1165. if ( ! $match_ids ) {
  1166. $match_ids = array( 0 );
  1167. }
  1168.  
  1169. if ( ! empty( $match_ids ) ) {
  1170. $include_members = '&include=' . join( ",", $match_ids );
  1171. } else {
  1172. $include_members = '';
  1173. }
  1174.  
  1175. $i = 0;
  1176. if ( bp_has_members( 'user_id=0&type=online&per_page=999999999&populate_extras=0' . $include_members ) ) :
  1177. while ( bp_members() ) : bp_the_member();
  1178. $i ++;
  1179. endwhile;
  1180. endif;
  1181.  
  1182. return apply_filters( 'bp_member_statistics', $i, $value );
  1183. }
  1184.  
  1185. endif;
  1186.  
  1187.  
  1188. if ( ! function_exists( 'sq_bp_member_stats' ) ) {
  1189. function sq_bp_member_stats( $field = false, $value = false, $online = false ) {
  1190. global $wpdb;
  1191.  
  1192. if ( $field && $value ) {
  1193. $where = " WHERE field_id = '" . $field . "' AND value = '" . esc_sql( $value ) . "'";
  1194. } else {
  1195. $where = '';
  1196. }
  1197. $sql = "SELECT " . $wpdb->base_prefix . "bp_xprofile_data.user_id FROM " . $wpdb->base_prefix . "bp_xprofile_data
  1198. JOIN " . $wpdb->base_prefix . "bp_xprofile_fields ON " . $wpdb->base_prefix . "bp_xprofile_data.field_id = " . $wpdb->base_prefix . "bp_xprofile_fields.id
  1199. $where";
  1200.  
  1201. $match_ids = $wpdb->get_col( $sql );
  1202. //var_dump( $match_ids );
  1203. if ( ! $online ) {
  1204. return count( array_unique( $match_ids ) );
  1205. }
  1206.  
  1207. if ( ! $match_ids ) {
  1208. $match_ids = array( 0 );
  1209. }
  1210.  
  1211. if ( ! empty( $match_ids ) ) {
  1212. $include_members = '&include=' . join( ",", $match_ids );
  1213. } else {
  1214. $include_members = '';
  1215. }
  1216.  
  1217. $i = 0;
  1218. if ( bp_has_members( 'user_id=0&type=online&per_page=999999999&populate_extras=0' . $include_members ) ) {
  1219. while ( bp_members() ) {
  1220. bp_the_member();
  1221. $i ++;
  1222. }
  1223. }
  1224.  
  1225. return apply_filters( 'sq_bp_member_stats', $i, $value );
  1226. }
  1227.  
  1228. }
  1229.  
  1230. /*-----------------------------------------------------------------------------------*/
  1231. /* Shortcode - Status icon
  1232. /*-----------------------------------------------------------------------------------*/
  1233.  
  1234. if ( ! function_exists( 'kleo_status_icon' ) ) {
  1235. function kleo_status_icon( $atts, $content = null ) {
  1236. $field = $value = $online = $type = $image = $subtitle = $class = $href = '';
  1237. extract( shortcode_atts( array(
  1238. 'field' => '',
  1239. 'value' => '',
  1240. 'online' => 'yes',
  1241. 'type' => 'total',
  1242. 'image' => '',
  1243. 'subtitle' => '',
  1244. 'class' => '',
  1245. 'href' => ''
  1246. ), $atts ) );
  1247.  
  1248. switch ( $type ) {
  1249. case 'total':
  1250. $image = ( $image == '' ) ? get_template_directory_uri() . '/assets/images/icons/steps/status_01.png' : $image;
  1251. $number = bp_get_total_member_count();
  1252. break;
  1253. case 'members_online':
  1254. $image = ( $image == '' ) ? get_template_directory_uri() . '/assets/images/icons/steps/status_02.png' : $image;
  1255. $number = bp_get_online_users();
  1256. break;
  1257. case 'women_online':
  1258. $image = ( $image == '' ) ? get_template_directory_uri() . '/assets/images/icons/steps/status_03.png' : $image;
  1259. $number = bp_get_online_users( "Woman" );
  1260. break;
  1261. case 'men_online':
  1262. $image = ( $image == '' ) ? get_template_directory_uri() . '/assets/images/icons/steps/status_04.png' : $image;
  1263. $number = bp_get_online_users( "Man" );
  1264. break;
  1265. case 'custom':
  1266. $image = ( $image == '' ) ? get_template_directory_uri() . '/assets/images/icons/steps/status_01.png' : $image;
  1267.  
  1268. $field = $field != '' ? $field : false;
  1269. $value = $value != '' ? $value : false;
  1270. $online = $online == 'yes' ? true : false;
  1271. $number = bp_member_statistics( $field, $value, $online );
  1272. break;
  1273.  
  1274. default:
  1275. if ( $type == 'Man' ) {
  1276. $image = ( $image == '' ) ? get_template_directory_uri() . '/assets/images/icons/steps/status_04.png' : $image;
  1277. } elseif ( $type == 'Woman' ) {
  1278. $image = ( $image == '' ) ? get_template_directory_uri() . '/assets/images/icons/steps/status_03.png' : $image;
  1279. } else {
  1280. $image = ( $image == '' ) ? get_template_directory_uri() . '/assets/images/icons/steps/status_01.png' : $image;
  1281. }
  1282. $number = bp_get_online_users( $type );
  1283. break;
  1284. }
  1285.  
  1286. $output = '<div class="status three columns mobile-one ' . $class . '">';
  1287. $output .= '<div data-animation="pulse" class="icon">';
  1288. if ( $href != '' ) {
  1289. $output .= '<a href="' . $href . '">';
  1290. }
  1291. $output .= '<img width="213" height="149" alt="" src="' . $image . '">';
  1292. if ( $href != '' ) {
  1293. $output .= '</a>';
  1294. }
  1295. $output .= '</div>';
  1296. $output .= '<ul class="block-grid">';
  1297. $output .= '<li class="title">' . $number . '</li>';
  1298. $output .= '<li class="subtitle">' . $subtitle . '</li>';
  1299. $output .= '</ul>';
  1300. $output .= '</div>';
  1301.  
  1302. return $output;
  1303. }
  1304.  
  1305. add_shortcode( 'kleo_status_icon', 'kleo_status_icon' );
  1306. }
  1307.  
  1308. /*-----------------------------------------------------------------------------------*/
  1309. /* Shortcodes
  1310. /*-----------------------------------------------------------------------------------*/
  1311.  
  1312. if ( ! function_exists( 'kleo_member_stats' ) ) {
  1313. $field = $value = $online = '';
  1314. function kleo_member_stats( $atts, $content = null ) {
  1315. $field = $value = $online = '';
  1316. extract( shortcode_atts( array(
  1317. 'field' => '',
  1318. 'value' => '',
  1319. 'online' => ''
  1320. ), $atts ) );
  1321.  
  1322. $field = $field != '' ? $field : false;
  1323. $value = $value != '' ? $value : false;
  1324. $online = $online == 'yes' ? true : false;
  1325.  
  1326. return bp_member_statistics( $field, $value, $online );
  1327. }
  1328.  
  1329. add_shortcode( 'kleo_member_stats', 'kleo_member_stats' );
  1330. }
  1331.  
  1332.  
  1333. if ( ! function_exists( 'kleo_total_members' ) ) {
  1334. function kleo_total_members( $atts, $content = null ) {
  1335. return bp_get_total_member_count();
  1336. }
  1337.  
  1338. add_shortcode( 'kleo_total_members', 'kleo_total_members' );
  1339. }
  1340.  
  1341. if ( ! function_exists( 'kleo_members_online' ) ) {
  1342. function kleo_members_online( $atts, $content = null ) {
  1343. $field_name = $field = '';
  1344. extract( shortcode_atts( array(
  1345. 'field_name' => false,
  1346. 'field' => false,
  1347. ), $atts ) );
  1348.  
  1349. return bp_get_online_users( $field, $field_name );
  1350. }
  1351.  
  1352. add_shortcode( 'kleo_members_online', 'kleo_members_online' );
  1353. }
  1354.  
  1355. if ( ! function_exists( 'kleo_women_online' ) ) {
  1356. function kleo_women_online( $atts, $content = null ) {
  1357. $field = '';
  1358. extract( shortcode_atts( array(
  1359. 'field' => 'Woman',
  1360. ), $atts ) );
  1361.  
  1362. return bp_get_online_users( $field );
  1363. }
  1364.  
  1365. add_shortcode( 'kleo_women_online', 'kleo_women_online' );
  1366. }
  1367.  
  1368. if ( ! function_exists( 'kleo_men_online' ) ) {
  1369. function kleo_men_online( $atts, $content = null ) {
  1370. $field = '';
  1371. extract( shortcode_atts( array(
  1372. 'field' => 'Man',
  1373. ), $atts ) );
  1374.  
  1375. return bp_get_online_users( $field );
  1376. }
  1377.  
  1378. add_shortcode( 'kleo_men_online', 'kleo_men_online' );
  1379. }
  1380.  
  1381.  
  1382. //Top members
  1383. if ( ! function_exists( 'kleo_top_members' ) ) {
  1384. function kleo_top_members( $atts, $content = null ) {
  1385. $number = $class = '';
  1386. extract( shortcode_atts( array(
  1387. 'number' => '6',
  1388. 'class' => ''
  1389. ), $atts ) );
  1390.  
  1391. $output = '
  1392.  
  1393. <div class="section-members ' . $class . '">
  1394. <div class="item-options" id="members-list-options">
  1395. <a href="' . bp_get_members_directory_permalink() . '" data-id="newest" class="members-switch">' . __( "Newest", 'kleo_framework' ) . '</a>
  1396. <a href="' . bp_get_members_directory_permalink() . '" data-id="active" class="selected members-switch">' . __( "Active", 'kleo_framework' ) . '</a>
  1397. <a href="' . bp_get_members_directory_permalink() . '" data-id="popular" class="members-switch">' . __( "Popular", 'kleo_framework' ) . '</a>
  1398. </div>';
  1399.  
  1400. $output .= '<ul class="item-list kleo-bp-active-members">';
  1401. if ( bp_has_members( bp_ajax_querystring( 'members' ) . '&type=active&max=' . $number. '&per_page='.$number ) ) :
  1402. while ( bp_members() ) : bp_the_member();
  1403. $output .= section_members_li();
  1404.  
  1405. endwhile;
  1406. endif;
  1407. $output .= '</ul>';
  1408.  
  1409. $output .= '<ul class="item-list kleo-bp-newest-members" style="display:none;">';
  1410. if ( bp_has_members( bp_ajax_querystring( 'members' ) . '&type=newest&max=' . $number. '&per_page' .$number ) ) :
  1411. while ( bp_members() ) : bp_the_member();
  1412. $output .= section_members_li( 'newest' );
  1413.  
  1414. endwhile;
  1415. endif;
  1416. $output .= '</ul>';
  1417.  
  1418. $output .= '<ul class="item-list kleo-bp-popular-members" style="display:none;">';
  1419. if ( bp_has_members( bp_ajax_querystring( 'members' ) . '&type=popular&max=' . $number. '&per_page' .$number ) ) :
  1420. while ( bp_members() ) : bp_the_member();
  1421. $output .= section_members_li( 'popular' );
  1422.  
  1423. endwhile;
  1424. endif;
  1425. $output .= '</ul>';
  1426.  
  1427. $output .= '</div><!--end section-members-->';
  1428.  
  1429. $output .= <<<JS
  1430. <script type="text/javascript">
  1431. jQuery(document).ready(function() {
  1432.  
  1433. jQuery(".members-switch").click(function() {
  1434. var bpMembersContext = jQuery(this).parent().parent();
  1435. var container = "ul.kleo-bp-"+jQuery(this).attr('data-id')+"-members";
  1436.  
  1437. jQuery("ul.item-list", bpMembersContext).hide();
  1438. jQuery(".members-switch").removeClass("selected");
  1439. jQuery(this).addClass("selected");
  1440. jQuery(container, bpMembersContext).show(0, function() {
  1441. jQuery(container+" li").hide().each(function (i) {
  1442. var delayInterval = 150; // milliseconds
  1443. jQuery(this).delay(i * delayInterval).fadeIn();
  1444. });
  1445. });
  1446. return false;
  1447. });
  1448. });
  1449.  
  1450. jQuery(function () {
  1451. if (!isMobile()) {
  1452. jQuery('.kleo-bp-active-members').hide();
  1453. jQuery('.section-members').one('inview', function (event, visible) {
  1454. if (visible) {
  1455. var container = ".kleo-bp-active-members";
  1456. jQuery(container).show(0, function() {
  1457. jQuery(container+" li").hide().each(function (i) {
  1458. var delayInterval = 150; // milliseconds
  1459. jQuery(this).delay(i * delayInterval).fadeIn();
  1460. });
  1461. });
  1462. }
  1463. });
  1464. }
  1465.  
  1466. });
  1467.  
  1468. </script>
  1469. JS;
  1470.  
  1471. return $output;
  1472.  
  1473. }
  1474.  
  1475. add_shortcode( 'kleo_top_members', 'kleo_top_members' );
  1476. }
  1477.  
  1478. //render member list item
  1479. function section_members_li( $type = 'active' ) {
  1480. $output =
  1481. '<li class="two columns mobile-two top-' . $type . '-members">
  1482. <div class="item-avatar">
  1483. <a href="' . bp_get_member_permalink() . '" title="' . bp_get_member_name() . '">' . bp_get_member_avatar( 'type=thumb&width=125&height=125' ) . '</a>
  1484. </div><!--end item-avatar-->
  1485. <div class="item">
  1486. <div class="item-title fn"><a href="' . bp_get_member_permalink() . '" title="' . bp_get_member_name() . '">' . bp_get_member_name() . '</a></div>
  1487. <div class="item-meta">
  1488. <span class="activity">';
  1489.  
  1490. switch ( $type ) {
  1491. case 'newest':
  1492. $output .= bp_get_member_registered();
  1493. break;
  1494.  
  1495. case 'popular':
  1496. $output .= bp_get_member_total_friend_count();
  1497. break;
  1498.  
  1499. case 'active':
  1500. default:
  1501. $output .= bp_get_member_last_active();
  1502. break;
  1503. }
  1504.  
  1505. $output .= '</span>
  1506. </div>
  1507. </div><!--end item-->
  1508. </li>';
  1509.  
  1510. return $output;
  1511. }
  1512.  
  1513. //Recent Groups
  1514. if ( ! function_exists( 'kleo_recent_groups' ) ) {
  1515. function kleo_recent_groups( $atts, $content = null ) {
  1516. $class = $max = '';
  1517. extract( shortcode_atts( array(
  1518. 'class' => '',
  1519. 'max' => 4
  1520. ), $atts ) );
  1521.  
  1522. $output = '';
  1523. if ( function_exists( 'bp_has_groups' ) && bp_has_groups( bp_ajax_querystring( 'groups' ) . "&type=active&max=" . apply_filters( 'kleo_recent_groups_max', $max ) ) ) :
  1524.  
  1525. $output .= '<div id="groups" class="' . $class . '">';
  1526. while ( bp_groups() ) : bp_the_group();
  1527. //$members_no = preg_replace('/\D/', '', bp_get_group_member_count());
  1528. global $groups_template;
  1529. $members_no = $groups_template->group->total_member_count;
  1530. $output .= '
  1531. <div class="six columns group-item">
  1532. <div class="five columns">
  1533. <div class="item-header-avatar">
  1534. <div class="circular-item" title="">
  1535. <small class="icon">' . __( "members", 'kleo_framework' ) . '</small>
  1536. <input type="text" value="' . $members_no . '" class="pinkCircle">
  1537. </div>
  1538. ' . bp_get_group_avatar( 'type=full&width=300&height=300' ) . '
  1539. </div>
  1540. </div>
  1541. <h4><a href="' . bp_get_group_permalink() . '">' . bp_get_group_name() . '</a></h4>
  1542. <p>' . char_trim( strip_tags( bp_get_group_description_excerpt() ), 60, '...' ) . '</p>
  1543. <p><a href="' . bp_get_group_permalink() . '">' . __( "View group", 'kleo_framework' ) . ' <i class="icon-caret-right"></i></a></p>
  1544. </div><!--end six-->';
  1545.  
  1546. endwhile;
  1547. $output .= '</div><div class="clear clearfix"></div>';
  1548.  
  1549. $output .= <<<JS
  1550. <script type="text/javascript">
  1551. jQuery(function () {
  1552. if (!isMobile()) {
  1553. jQuery(".item-header-avatar img").each(function (i) {
  1554. jQuery(this).attr('data-src' ,jQuery(this).attr('src'));
  1555. jQuery(this).attr('src', kleoFramework.blank_img);
  1556. });
  1557.  
  1558. jQuery('#groups').one('inview', function (event, visible) {
  1559. if (visible) {
  1560. var container = "#groups";
  1561.  
  1562. jQuery(container+" .item-header-avatar img").each(function (i) {
  1563. var element = jQuery(this);
  1564. var delayInterval = 250; // milliseconds
  1565. jQuery(this).delay(i * delayInterval).fadeOut(function() { element.attr('src' ,jQuery(this).attr('data-src')); element.fadeIn() });
  1566. });
  1567.  
  1568. }
  1569. });
  1570. }
  1571.  
  1572. });
  1573. </script>
  1574. JS;
  1575.  
  1576. endif;
  1577.  
  1578. return $output;
  1579. }
  1580.  
  1581. add_shortcode( 'kleo_recent_groups', 'kleo_recent_groups' );
  1582. }
  1583.  
  1584. //Members Shortcode
  1585. if ( ! function_exists( 'kleo_members' ) ) {
  1586. /**
  1587. * Display members list
  1588. *
  1589. * @param array $atts
  1590. * @param string $content
  1591. *
  1592. * @return string
  1593. */
  1594. function kleo_members( $atts, $content = null ) {
  1595. global $bp_results;
  1596. $show_filter = '';
  1597. extract( shortcode_atts( array(
  1598. 'show_filter' => 'no'
  1599. ), $atts ) );
  1600.  
  1601. $output = '<div class="search-result">';
  1602.  
  1603. if ( $show_filter == 'yes' ) {
  1604. $lead = '';
  1605. if ( isset( $_GET['bs'] ) && $bp_results['users'][0] != 0 ) {
  1606. $lead = __( "Your search returned", 'kleo_framework' ) . " " . count( $bp_results['users'] ) . " " . _n( 'member', 'members', count( $bp_results['users'] ), 'kleo_framework' );;
  1607. }
  1608.  
  1609. $output .= '<p class="lead">' . $lead . '</p>
  1610.  
  1611. <div class="item-list-tabs" role="navigation">
  1612. <ul>
  1613. <li class="selected" id="members-all"><a href="' . trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() ) . '">';
  1614. $output .= sprintf( __( 'All Members <span>%s</span>', 'buddypress' ), bp_get_total_member_count() ) . '</a></li>';
  1615.  
  1616. if ( is_user_logged_in() && bp_is_active( 'friends' ) && bp_get_total_friend_count( bp_loggedin_user_id() ) ) :
  1617.  
  1618. $output .= '<li id="members-personal"><a href="' . bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends/">' . sprintf( __( 'My Friends <span>%s</span>', 'buddypress' ), bp_get_total_friend_count( bp_loggedin_user_id() ) ) . '</a></li>';
  1619.  
  1620. endif;
  1621. $output .= '</ul>
  1622. </div><!-- .item-list-tabs -->';
  1623. }
  1624.  
  1625. $output .= '<div id="members-dir-list" class="members dir-list">
  1626. <!--Search List-->
  1627. <div class="search-list twelve">';
  1628. ob_start();
  1629. locate_template( array( 'members/members-loop.php' ), true );
  1630. $output .= ob_get_contents();
  1631. ob_end_clean();
  1632. $output .= '</div><!--end Search List-->
  1633. </div><!-- #members-dir-list --></div>';
  1634.  
  1635. return $output;
  1636. }
  1637.  
  1638. add_shortcode( 'kleo_members', 'kleo_members' );
  1639. }
  1640.  
  1641.  
  1642. //Members Carousel
  1643. if ( ! function_exists( 'kleo_members_carousel' ) ):
  1644. function kleo_members_carousel( $atts, $content = null ) {
  1645. $type = $image_size = $total = $width = $height = $class = '';
  1646. extract( shortcode_atts( array(
  1647. 'type' => apply_filters( 'kleo_bps_carousel_members_type', 'newest' ),
  1648. 'image_size' => 'thumb',
  1649. 'total' => sq_option( 'buddypress_perpage' ),
  1650. 'width' => '94',
  1651. 'height' => '94',
  1652. 'class' => ''
  1653. ), $atts ) );
  1654.  
  1655. $output = '<div class="kleo_members_carousel ' . $class . '">' .
  1656. '<p>' .
  1657. '<span class="right hide-for-small">' .
  1658. '<a href="#" class="profile-thumbs-prev"><i class="icon-circle-arrow-left icon-large"></i></a>&nbsp;' .
  1659. '<a href="#" class="profile-thumbs-next"><i class="icon-circle-arrow-right icon-large"></i></a>' .
  1660. '</span>' .
  1661. '</p>' .
  1662. '<div class="clearfix"></div>' .
  1663. '<div class="carousel-profiles responsive">' .
  1664. '<ul class="profile-thumbs">';
  1665.  
  1666. if ( bp_has_members( bp_ajax_querystring( 'members' ) . '&type=' . $type . '&per_page=' . $total ) ) :
  1667. while ( bp_members() ) : bp_the_member();
  1668. $output .= '<li><a href="' . bp_get_member_permalink() . '">' . bp_get_member_avatar( 'type=' . $image_size . '&width=' . $width . '&height=' . $height . '&class=' ) . '</a></li>';
  1669. endwhile;
  1670. endif;
  1671. $output .= '</ul>' .
  1672. '</div><!--end carousel-profiles-->' .
  1673. '</div>';
  1674.  
  1675. return $output;
  1676. }
  1677.  
  1678. add_shortcode( 'kleo_members_carousel', 'kleo_members_carousel' );
  1679. endif;
  1680.  
  1681. /* Register form shortcode */
  1682. if ( ! function_exists( 'kleo_register_form' ) ) {
  1683. function kleo_register_form( $atts, $content = null ) {
  1684. $profiles = $title = $details = '';
  1685. extract( shortcode_atts( array(
  1686. 'profiles' => 1,
  1687. 'title' => '',
  1688. 'details' => ''
  1689. ), $atts ) );
  1690.  
  1691. global $bp_reg_form_show_cols, $bp_reg_form_show_carousel, $bp_reg_form_title,
  1692. $bp_reg_form_details;
  1693.  
  1694. $bp_reg_form_show_cols = true;
  1695. $bp_reg_form_show_carousel = $profiles;
  1696. $bp_reg_form_title = $title;
  1697. $bp_reg_form_details = $details;
  1698.  
  1699. ob_start();
  1700. get_template_part( 'page-parts/home-register-form' );
  1701. $output = ob_get_contents();
  1702. ob_end_clean();
  1703.  
  1704. return $output;
  1705. }
  1706.  
  1707. add_shortcode( 'kleo_register_form', 'kleo_register_form' );
  1708. }
  1709.  
  1710.  
  1711. /* END SHORTCODES ------------------------------------------------------------*/
  1712.  
  1713. /**
  1714. * Buddypress AJAX Widget
  1715. *
  1716. */
  1717. function widget_ajax_groups() {
  1718. ?>
  1719. <script type="text/javascript">
  1720. /* Buddpress Groups widget */
  1721. jQuery(document).ready(function () {
  1722. jQuery(".widgets div#groups-list-options a").on("click", function () {
  1723. var a = this;
  1724. jQuery(a).addClass("loading");
  1725. jQuery(".widgets div#groups-list-options a").removeClass("selected");
  1726. jQuery(this).addClass("selected");
  1727. jQuery.post(
  1728. ajaxurl,
  1729. {
  1730. action: "widget_groups_list",
  1731. cookie: encodeURIComponent(document.cookie),
  1732. _wpnonce: jQuery("input#_wpnonce-groups").val(),
  1733. max_groups: jQuery("input#groups_widget_max").val(),
  1734. filter: jQuery(this).attr("id")
  1735. },
  1736. function (b) {
  1737. jQuery(a).removeClass("loading");
  1738. groups_wiget_response(b)
  1739. }
  1740. );
  1741. return false;
  1742. })
  1743. });
  1744. function groups_wiget_response(a) {
  1745. a = a.substr(0, a.length - 1);
  1746. a = a.split("[[SPLIT]]");
  1747. if (a[0] != "-1") {
  1748. jQuery(".widgets ul#groups-list").fadeOut(200, function () {
  1749. jQuery(".widgets ul#groups-list").html(a[1]);
  1750. jQuery(".widgets ul#groups-list").fadeIn(200)
  1751. })
  1752. } else {
  1753. jQuery(".widgets ul#groups-list").fadeOut(200, function () {
  1754. var b = "<p>" + a[1] + "</p>";
  1755. jQuery(".widgets ul#groups-list").html(b);
  1756. jQuery(".widgets ul#groups-list").fadeIn(200)
  1757. })
  1758. }
  1759. }
  1760.  
  1761. /* Buddpress Members widget */
  1762. jQuery(document).ready(function () {
  1763. jQuery(".widgets div#members-list-options a").on("click", function () {
  1764. var a = this;
  1765. jQuery(a).addClass("loading");
  1766. jQuery(".widgets div#members-list-options a").removeClass("selected");
  1767. jQuery(this).addClass("selected");
  1768. jQuery.post(ajaxurl, {
  1769. action: "widget_members",
  1770. cookie: encodeURIComponent(document.cookie),
  1771. _wpnonce: jQuery("input#_wpnonce-members").val(),
  1772. "max-members": jQuery("input#members_widget_max").val(),
  1773. filter: jQuery(this).attr("id")
  1774. }, function (b) {
  1775. jQuery(a).removeClass("loading");
  1776. member_wiget_response(b)
  1777. });
  1778. return false
  1779. })
  1780. });
  1781.  
  1782. function member_wiget_response(a) {
  1783. a = a.substr(0, a.length - 1);
  1784. a = a.split("[[SPLIT]]");
  1785. if (a[0] != "-1") {
  1786. jQuery(".widgets ul#members-list").fadeOut(200, function () {
  1787. jQuery(".widgets ul#members-list").html(a[1]);
  1788. jQuery(".widgets ul#members-list").fadeIn(200)
  1789. })
  1790. } else {
  1791. jQuery(".widgets ul#members-list").fadeOut(200, function () {
  1792. var b = "<p>" + a[1] + "</p>";
  1793. jQuery(".widgets ul#members-list").html(b);
  1794. jQuery(".widgets ul#members-list").fadeIn(200)
  1795. })
  1796. }
  1797. }
  1798.  
  1799.  
  1800. </script>
  1801. <?php
  1802. }
  1803.  
  1804. add_action( 'wp_footer', 'widget_ajax_groups' );
  1805.  
  1806.  
  1807. if ( ! function_exists( 'custom_bp_datebox' ) ):
  1808. /**
  1809. * Filter year field only to allow minimum 18 year old members
  1810. */
  1811. function custom_bp_datebox( $html, $type, $day, $month, $year, $field_id, $date ) {
  1812. $current_year = date( "Y" );
  1813. $allowed_year = $current_year - 18;
  1814. if ( $type == 'year' ) {
  1815.  
  1816. $html = '<option value=""' . selected( $year, '', false ) . '>----</option>';
  1817.  
  1818. for ( $i = $allowed_year; $i >= 1920; $i -- ) {
  1819. $html .= '<option value="' . $i . '"' . selected( $year, $i, false ) . '>' . $i . '</option>';
  1820. }
  1821. }
  1822.  
  1823. return $html;
  1824. }
  1825. endif;
  1826. add_filter( 'bp_get_the_profile_field_datebox', 'custom_bp_datebox', 10, 7 );
  1827.  
  1828.  
  1829. /***************************************************
  1830. * Frontend Profile pictures slider init
  1831. ***************************************************/
  1832. add_action( 'wp_footer', 'kleo_slider_js', 90 );
  1833.  
  1834. function kleo_slider_js() {
  1835. if ( ! bp_is_user() ) {
  1836. return;
  1837. }
  1838. ?>
  1839. <script type="text/javascript">
  1840. function loadSlider(sliderId, left, right) {
  1841. // Gallery carousel
  1842. jQuery("#" + sliderId).carouFredSel({
  1843. width: "100%",
  1844. auto: false,
  1845. scroll: 1,
  1846. swipe: {
  1847. onMouse: true,
  1848. onTouch: true
  1849. },
  1850. prev: {
  1851. button: "#" + left,
  1852. key: "left"
  1853. },
  1854. next: {
  1855. button: "#" + right,
  1856. key: "right"
  1857. }
  1858. });
  1859. }
  1860.  
  1861. jQuery(window).ready(function () {
  1862. // put here your slider ID
  1863. var sliderID = "gallery-carousel";
  1864.  
  1865. //load the slider on page load
  1866. loadSlider(sliderID, "stanga-prev", "dreapta-next");
  1867.  
  1868. //when someone calls the tab with the slider update the slider sizes
  1869. jQuery(".sliderEvent").on("click", function () {
  1870. jQuery(".mySlider").show();
  1871. loadSlider(sliderID, "stanga-prev", "dreapta-next");
  1872. });
  1873. });
  1874. </script>
  1875. <?php
  1876. }
  1877.  
  1878. /* -----------------------------------------------------------------------------
  1879. * END kleo_slider_js()
  1880. */
  1881.  
  1882.  
  1883. /**
  1884. * Return group ID by group name
  1885. * @global object $wpdb
  1886. *
  1887. * @param string $name
  1888. *
  1889. * @return integer
  1890. */
  1891. function get_group_id_by_name( $name ) {
  1892. global $wpdb, $bp;
  1893. if ( ! isset( $name ) ) {
  1894. return false;
  1895. }
  1896. $table_name = $bp->profile->table_name_groups;
  1897.  
  1898. return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$table_name} WHERE name = %s", $name ) );
  1899. }
  1900.  
  1901. // -----------------------------------------------------------------------------
  1902.  
  1903.  
  1904. /**
  1905. * Return profile field ID by profile name
  1906. * @global object $wpdb
  1907. *
  1908. * @param string $name
  1909. *
  1910. * @return integer
  1911. */
  1912. function get_profile_id_by_name( $name ) {
  1913. global $wpdb;
  1914. if ( ! isset( $name ) ) {
  1915. return false;
  1916. }
  1917.  
  1918. $sql = "SELECT id FROM " . $wpdb->base_prefix . "bp_xprofile_fields WHERE name = '" . $name . "'";
  1919.  
  1920. return $wpdb->get_var( $sql );
  1921. }
  1922.  
  1923. // -----------------------------------------------------------------------------
  1924.  
  1925. /* Load Buddypress city autocomplete */
  1926. if ( sq_option( 'bp_autocomplete', 0 ) == 1 ) {
  1927. locate_template( 'custom_buddypress/kleo-bp-city-auto.php', true );
  1928. }
  1929.  
  1930. /* Load Buddypress custom search */
  1931. locate_template( 'custom_buddypress/kleo-bp-search.php', true );
  1932.  
  1933.  
  1934. if ( ! function_exists( 'get_member_age' ) ):
  1935. /**
  1936. * Calculate member age based on date of birth
  1937. *
  1938. * @param int $id User id to get the age for
  1939. *
  1940. * @return string
  1941. */
  1942. function get_member_age( $id ) {
  1943. $default_age_field = get_profile_id_by_name( 'Birthday' );
  1944. $age_field = sq_option( 'bp_age_field', $default_age_field );
  1945. if ( $age_field == 0 ) {
  1946. $age_field = $default_age_field;
  1947. }
  1948.  
  1949. $age = '';
  1950.  
  1951. if ( bp_is_active( 'xprofile' ) && xprofile_get_field_data( $age_field, $id ) ) {
  1952. $birth = BP_XProfile_ProfileData::get_value_byid( $age_field, $id );
  1953.  
  1954. $field = new BP_XProfile_Field ( $age_field );
  1955.  
  1956. if ( $field->type == 'birthdate' ) {
  1957. if ( strtotime($birth) == false ) {
  1958. return strip_tags( $birth );
  1959. }
  1960. }
  1961. if ( ! empty( $birth ) ) {
  1962. $diff = time() - strtotime( $birth );
  1963. $age = floor( $diff / ( 365 * 60 * 60 * 24 ) );
  1964. }
  1965. }
  1966.  
  1967. return $age;
  1968. }
  1969. endif;
  1970.  
  1971.  
  1972. /* Show Age instead of Birthdate */
  1973. if ( sq_option( 'bp_birthdate_to_age', 0 ) == 1 ) {
  1974.  
  1975. add_filter( 'bp_get_the_profile_field_name', 'kleo_change_birth_to_age' );
  1976. add_action( 'bp_before_profile_edit_content', 'kleo_revert_birth_to_age' );
  1977. add_filter( 'bp_get_the_profile_field_value', 'kleo_get_field_value', 9, 3 );
  1978. remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value', 1, 2 );
  1979. remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value_by_type', 8, 2 );
  1980.  
  1981. }
  1982.  
  1983.  
  1984. function kleo_revert_birth_to_age() {
  1985.  
  1986. remove_filter( 'bp_get_the_profile_field_name', 'kleo_change_birth_to_age' );
  1987.  
  1988. }
  1989.  
  1990. function kleo_change_birth_to_age( $name ) {
  1991.  
  1992. if ( $name == __( 'Birthday', 'buddypress' ) ) {
  1993.  
  1994. $name = __( 'Age', 'buddypress' );
  1995.  
  1996. }
  1997.  
  1998. return $name;
  1999. }
  2000.  
  2001. if ( ! function_exists( 'kleo_get_field_value' ) ) {
  2002. function kleo_get_field_value( $value, $type, $field_id ) {
  2003.  
  2004. $value_to_return = $value;
  2005. $field = new BP_XProfile_Field( $field_id );
  2006.  
  2007. //our Age field
  2008. $default_age_field = get_profile_id_by_name( 'Birthday' );
  2009. $age_field = sq_option( 'bp_age_field', $default_age_field );
  2010. if ( $age_field == 0 ) {
  2011. $age_field = $default_age_field;
  2012. }
  2013.  
  2014. if ( $type == 'datebox' && $age_field == $field_id ) {
  2015. $value_to_return = floor( ( time() - strtotime( $value ) ) / 31556926 );
  2016. }
  2017.  
  2018. return $value_to_return;
  2019. }
  2020. }
  2021.  
  2022. // -----------------------------------------------------------------------------
  2023.  
  2024.  
  2025. /* Members meta on members listing */
  2026. add_action( 'bp_members_meta', 'render_bp_meta' );
  2027.  
  2028. if ( ! function_exists( 'render_bp_meta' ) ):
  2029. function render_bp_meta() {
  2030. global $kleo_config;
  2031. $output = array();
  2032.  
  2033. if ( get_member_age( bp_get_member_user_id() ) ) {
  2034. $output['age'] = apply_filters( 'kleo_bp_meta_after_age', get_member_age( bp_get_member_user_id() ) );
  2035. }
  2036. //fields to show
  2037. $fields_arr = $kleo_config['bp_members_loop_meta'];
  2038.  
  2039.  
  2040. //user private fields
  2041. $private_fields = array();
  2042. if ( function_exists( 'bp_xprofile_get_hidden_fields_for_user' ) ) {
  2043. $private_fields = bp_xprofile_get_hidden_fields_for_user( bp_get_member_user_id() );
  2044. }
  2045. if ( ! empty( $private_fields ) ) {
  2046. //get the fields ids that will be displayed on members list
  2047. if ( false === ( $fields_id_arr = get_transient( 'kleo_bp_meta_fields' ) ) ) {
  2048.  
  2049. $fields_id_arr = array();
  2050.  
  2051. foreach ( $fields_arr as $val ) {
  2052. if ( get_profile_id_by_name( $val ) ) {
  2053. $fields_id_arr[ $val ] = get_profile_id_by_name( $val );
  2054. }
  2055. }
  2056.  
  2057. set_transient( 'kleo_bp_meta_fields', $fields_id_arr, 60 * 60 * 12 );
  2058. }
  2059. if ( ! empty( $fields_id_arr ) ) {
  2060. //fields that will actually display
  2061. $show_fields = array_diff( $fields_id_arr, $private_fields );
  2062. if ( ! empty( $show_fields ) ) {
  2063. $fields_arr_inv = array_flip( $fields_id_arr );
  2064.  
  2065. foreach ( $show_fields as $key => $val ):
  2066. if ( @bp_get_member_profile_data( 'field=' . $fields_arr_inv[ $val ] ) ):
  2067. $output[] = bp_get_member_profile_data( 'field=' . $fields_arr_inv[ $val ] );
  2068. endif;
  2069. endforeach;
  2070. }
  2071. }
  2072. } else {
  2073. foreach ( $fields_arr as $key => $val ) {
  2074. if ( @bp_get_member_profile_data( 'field=' . $val ) ) {
  2075. $output[] = bp_get_member_profile_data( 'field=' . $val );
  2076. }
  2077. }
  2078. }
  2079.  
  2080. $output = apply_filters( 'kleo_bp_meta_fields', $output );
  2081. if ( is_array( $output ) ) {
  2082. $output_str = '<p class="date">' . implode( " / ", $output ) . '</p>';
  2083. } else {
  2084. $output_str = '';
  2085. }
  2086. echo '<div class="search-meta">';
  2087. echo apply_filters( 'kleo_bp_members_dir_name', '<h5 class="author"><a href="' . bp_get_member_permalink() . '">' . bp_get_member_name() . '</a></h5>' );
  2088. echo $output_str;
  2089. echo '</div>';
  2090. }
  2091. endif;
  2092.  
  2093. /**
  2094. * Removed the member name from 'render_bp_meta' action
  2095. * @since 3.0
  2096. */
  2097. add_filter( 'kleo_bp_members_dir_name', '__return_empty_string', 99 );
  2098.  
  2099.  
  2100. /* Members details on members listing */
  2101. add_action( 'bp_directory_members_item', 'render_bp_details' );
  2102.  
  2103. if ( ! function_exists( 'render_bp_details' ) ):
  2104. function render_bp_details() {
  2105. global $kleo_config;
  2106.  
  2107. if ( @bp_get_member_profile_data( 'field=' . apply_filters( 'kleo_bp_details_field', $kleo_config['bp_members_details_field'] ) ) ) {
  2108. echo '<p>' . word_trim( bp_get_member_profile_data( 'field=' . apply_filters( 'kleo_bp_details_field', $kleo_config['bp_members_details_field'] ) ), 50, '...' ) . '</p>';
  2109. }
  2110. }
  2111. endif;
  2112.  
  2113.  
  2114. if ( ! function_exists( 'compatibility_score' ) ) :
  2115. /**
  2116. * Calculate compatibility between members based on their profiles
  2117. *
  2118. * @param int|bool $userid1
  2119. * @param int|bool $userid2
  2120. *
  2121. * @return int
  2122. */
  2123. function compatibility_score( $userid1 = false, $userid2 = false ) {
  2124. global $kleo_config;
  2125.  
  2126. if ( $userid1 && $userid2 ) {
  2127. $score = $kleo_config['matching_fields']['starting_score'];
  2128.  
  2129. //Sex match
  2130. if ( ( isset( $kleo_config['matching_fields']['sex_match'] ) && $kleo_config['matching_fields']['sex_match'] == '1' )
  2131. || ! isset( $kleo_config['matching_fields']['sex_match'] )
  2132. ) {
  2133. $field1_u1 = xprofile_get_field_data( $kleo_config['matching_fields']['sex'], $userid1 );
  2134. $field12_u1 = xprofile_get_field_data( $kleo_config['matching_fields']['looking_for'], $userid1 );
  2135. $field1_u2 = xprofile_get_field_data( $kleo_config['matching_fields']['sex'], $userid2 );
  2136. $field12_u2 = xprofile_get_field_data( $kleo_config['matching_fields']['looking_for'], $userid2 );
  2137.  
  2138. if ( $field1_u1 == $field12_u2 && $field12_u1 == $field1_u2 ) {
  2139. $score += $kleo_config['matching_fields']['sex_percentage'];
  2140. } //if no sex match, return the score
  2141. else {
  2142. if ( ( isset( $kleo_config['matching_fields']['sex_mandatory'] ) && $kleo_config['matching_fields']['sex_mandatory'] == 1 ) || ! isset( $kleo_config['matching_fields']['sex_mandatory'] ) ) {
  2143. return $score;
  2144. }
  2145. }
  2146. }
  2147.  
  2148. //single fields match
  2149. if ( is_array( $kleo_config['matching_fields']['single_value'] ) ) {
  2150. foreach ( $kleo_config['matching_fields']['single_value'] as $key => $value ) {
  2151. if ( xprofile_get_field_data( $key, $userid1 )
  2152. && xprofile_get_field_data( $key, $userid2 )
  2153. && xprofile_get_field_data( $key, $userid1 ) == xprofile_get_field_data( $key, $userid2 )
  2154. ) {
  2155. $score += $value;
  2156. }
  2157. }
  2158. }
  2159.  
  2160. //multiple fields match
  2161. if ( is_array( $kleo_config['matching_fields']['multiple_values'] ) ) {
  2162. foreach ( $kleo_config['matching_fields']['multiple_values'] as $key => $value ) {
  2163. $field1 = xprofile_get_field_data( $key, $userid1 );
  2164. $field2 = xprofile_get_field_data( $key, $userid2 );
  2165. if ( $field1 && $field2 ) {
  2166. $intersect = array_intersect( (array) $field1, (array) $field2 );
  2167. if ( count( $intersect ) >= 1 ) {
  2168. $score += $value * count( $intersect );
  2169. }
  2170. }
  2171. }
  2172. }
  2173. if ( $score > 100 ) {
  2174. $score = 100;
  2175. }
  2176.  
  2177. return $score;
  2178. }
  2179. }
  2180. endif;
  2181.  
  2182. function kleo_bp_match_data() {
  2183. if ( sq_option( 'bp_match', 0 ) == 1 ) {
  2184.  
  2185. global $kleo_config;
  2186. $match_data = sq_option( 'bp_match_data' );
  2187.  
  2188. // var_dump($match_data);exit;
  2189.  
  2190. $kleo_config['matching_fields']['starting_score'] = (int) sq_option( 'bp_match_start_percent', 0 );
  2191.  
  2192. if ( sq_option( 'bp_comp_fields', 0 ) == 1 ) {
  2193. if ( sq_option( 'bp_comp_field1', '' ) != '' && sq_option( 'bp_comp_field2', '' ) != '' ) {
  2194. $kleo_config['matching_fields']['sex_match'] = 1;
  2195. $kleo_config['matching_fields']['sex'] = sq_option( 'bp_comp_field1', '' );
  2196. $kleo_config['matching_fields']['looking_for'] = sq_option( 'bp_comp_field2', '' );
  2197. $kleo_config['matching_fields']['sex_percentage'] = (int) sq_option( 'bp_comp_percent', 0 );
  2198. $kleo_config['matching_fields']['sex_mandatory'] = (int) sq_option( 'bp_comp_mandatory', 1 );
  2199.  
  2200.  
  2201. }
  2202.  
  2203. } else {
  2204. $kleo_config['matching_fields']['sex_match'] = 0;
  2205. }
  2206.  
  2207. $kleo_config['matching_fields']['single_value'] = array();
  2208. $kleo_config['matching_fields']['multiple_values'] = array();
  2209.  
  2210. if ( isset( $match_data['single'] ) && is_array( $match_data['single'] ) ) {
  2211.  
  2212. $single_match = array();
  2213.  
  2214. foreach ( $match_data['single'] as $single ) {
  2215. if ( isset( $match_data['percentages'][ $single ] ) ) {
  2216. $single_match[ $single ] = $match_data['percentages'][ $single ];
  2217. }
  2218. }
  2219. $kleo_config['matching_fields']['single_value'] = $single_match;
  2220. }
  2221.  
  2222. if ( isset( $match_data['multi'] ) && is_array( $match_data['multi'] ) ) {
  2223.  
  2224. $multi_match = array();
  2225.  
  2226. foreach ( $match_data['multi'] as $multi ) {
  2227. if ( isset( $match_data['percentages'][ $multi ] ) ) {
  2228. $multi_match[ $multi ] = $match_data['percentages'][ $multi ];
  2229. }
  2230. }
  2231. $kleo_config['matching_fields']['multiple_values'] = $multi_match;
  2232. }
  2233. //print_r($kleo_config['matching_fields']);
  2234. }
  2235. }
  2236.  
  2237. if ( ! is_admin() ) {
  2238. add_action( 'init', 'kleo_bp_match_data' );
  2239. }
  2240.  
  2241.  
  2242. /* Match compatibility hook */
  2243. add_action( 'kleo_bp_before_profile_name', 'kleo_bp_compatibility_match' );
  2244.  
  2245. if ( ! function_exists( 'kleo_bp_compatibility_match' ) ):
  2246. function kleo_bp_compatibility_match() {
  2247. global $bp;
  2248. if ( is_user_logged_in() && ! bp_is_my_profile() ):
  2249. echo '<div class="circular-item" title="' . __( "Compatibility match", 'kleo_framework' ) . '">';
  2250. echo '<small class="icon strong">' . __( "match", 'kleo_framework' ) . '</small>';
  2251. echo '<input type="text" value="' . compatibility_score( $bp->loggedin_user->id, bp_displayed_user_id() ) . '" class="greenCircle">';
  2252. echo '<span class="hearts"></span>';
  2253. echo '</div>';
  2254. endif;
  2255. }
  2256. endif;
  2257.  
  2258. /* Fix for embeded videos widescreen */
  2259. function kleo_fix_video() {
  2260. ?>
  2261. <script type="text/javascript">
  2262. jQuery(document).ready(function () {
  2263. jQuery('.activity-content .activity-inner iframe').each(function () {
  2264. if (!jQuery(this).parent().hasClass('flex-video')) {
  2265. jQuery(this).wrap('<div class="flex-video widescreen"></div>');
  2266. }
  2267. });
  2268. });
  2269. </script>
  2270. <?php
  2271. }
  2272.  
  2273. add_action( 'wp_footer', 'kleo_fix_video' );
  2274.  
  2275. /**
  2276. * Before carousel search form - ACTION
  2277. */
  2278. add_action( 'kleo_bps_before_carousel', 'kleo_before_carousel_text' );
  2279.  
  2280. if ( ! function_exists( 'kleo_before_carousel_text' ) ):
  2281. function kleo_before_carousel_text() {
  2282. echo '<strong>' . __( "Latest registered members", 'kleo_framework' ) . '</strong>';
  2283. }
  2284. endif;
  2285.  
  2286. /**
  2287. * Buttons on member page - ACTION
  2288. */
  2289. add_action( 'kleo_bp_header_actions', 'kleo_bp_member_buttons' );
  2290. if ( ! function_exists( 'kleo_bp_member_buttons' ) ):
  2291. function kleo_bp_member_buttons() {
  2292. ?>
  2293.  
  2294. <div class="two columns pull-two">
  2295. <div id="item-buttons">
  2296. <?php if ( ! is_user_logged_in() ) : ?>
  2297. <?php if ( bp_is_active( 'friends' ) ): ?>
  2298. <div id="friendship-button-<?php bp_displayed_user_id(); ?>"
  2299. class="generic-button friendship-button not_friends">
  2300. <a data-reveal-id="login_panel" class="has-tip tip-right friendship-button not_friends add"
  2301. data-width="350" rel="add" id="friend-<?php bp_displayed_user_id(); ?>"
  2302. title="<?php _e( "Please Login to Add Friend", 'kleo_framework' ); ?>"
  2303. href="#"><?php _e( "Add Friend", 'kleo_framework' ); ?></a>
  2304. </div>
  2305. <?php endif; ?>
  2306. <?php if ( bp_is_active( 'activity' ) ): ?>
  2307. <div id="post-mention" class="generic-button">
  2308. <a data-reveal-id="login_panel" class="has-tip tip-right activity-button mention"
  2309. data-width="350"
  2310. title="<?php _e( "Please Login to Send a public message", 'kleo_framework' ); ?>"
  2311. href="#"><?php _e( "Public Message", 'kleo_framework' ); ?></a>
  2312. </div>
  2313. <?php endif; ?>
  2314. <?php if ( bp_is_active( 'messages' ) ): ?>
  2315. <div id="send-private-message" class="generic-button">
  2316. <a data-reveal-id="login_panel" class="has-tip tip-right send-message" data-width="350"
  2317. title="<?php _e( "Please Login to Send a private message", 'kleo_framework' ); ?>"
  2318. href="#"><?php _e( "Private Message", 'kleo_framework' ); ?></a>
  2319. </div>
  2320. <?php endif; ?>
  2321. <?php else : ?>
  2322. <?php
  2323. /**
  2324. * Fires in the member header actions section.
  2325. *
  2326. * @since 1.2.6
  2327. */
  2328. do_action( 'bp_member_header_actions' );
  2329. ?>
  2330. <?php endif; ?>
  2331.  
  2332. </div><!-- #item-buttons -->
  2333. </div>
  2334. <?php
  2335. }
  2336. endif;
  2337.  
  2338. /* Load Buddypress profile tabs */
  2339. locate_template( 'custom_buddypress/class-bp-tabs.php', true );
  2340.  
  2341. /**
  2342. * Define what tabs to display next to user profile
  2343. */
  2344. global $bp_tabs;
  2345.  
  2346. $bp_tabs['looking-for'] = array(
  2347. 'type' => 'cite',
  2348. 'name' => apply_filters( 'kleo_extra_tab1', __( 'Looking for', 'kleo_framework' ) ),
  2349. 'group' => apply_filters( 'kleo_extra_tab1', __( 'Looking for', 'kleo_framework' ) ),
  2350. 'class' => 'citetab'
  2351. );
  2352.  
  2353. $bp_tabs['base'] = array(
  2354. 'type' => 'regular',
  2355. 'name' => apply_filters( 'kleo_extra_tab2', __( 'About me', 'kleo_framework' ) ),
  2356. 'group' => __( 'Base', 'kleo_framework' ),
  2357. 'class' => 'regulartab'
  2358. );
  2359.  
  2360. /* rtMedia tab - only if plugin installed */
  2361. if ( class_exists( 'RTMedia' ) ) {
  2362. $bp_tabs['rtmedia'] = array(
  2363. 'type' => 'rt_media',
  2364. 'name' => __( 'My photos', 'kleo_framework' ),
  2365. 'class' => 'mySlider'
  2366. );
  2367. } /* Bp-Album tab - only if plugin installed */
  2368. elseif ( function_exists( 'bpa_init' ) ) {
  2369. $bp_tabs['bp-album'] = array(
  2370. 'type' => 'bp_album',
  2371. 'name' => __( 'My photos', 'kleo_framework' ),
  2372. 'class' => 'mySlider'
  2373. );
  2374. }
  2375.  
  2376.  
  2377. /**
  2378. * Customise tabs according to Theme options - BP Tabs
  2379. *
  2380. * @since 2.8
  2381. */
  2382. function kleo_my_custom_tabs_data() {
  2383. if ( sq_option( 'bp_tabs', 0 ) == 1 && bp_is_active( 'xprofile' ) ) {
  2384. global $bp_tabs;
  2385. $bp_tabs = array();
  2386.  
  2387. $tabs_data = sq_option( 'bp_tabs_data' );
  2388.  
  2389. if ( ! empty( $tabs_data ) && ! empty( $tabs_data['fields'] ) ) {
  2390. foreach ( $tabs_data['fields'] as $tab ) {
  2391.  
  2392. if ( strpos( $tab, 'group' ) !== false ) {
  2393. $group_id = substr( $tab, 6 );
  2394.  
  2395. $group = xprofile_get_field_group( $group_id );
  2396.  
  2397. if ( $group ) {
  2398. $name = $group->name;
  2399.  
  2400. $label = isset( $tabs_data['labels'] ) && isset( $tabs_data['labels'][ $tab ] ) && $tabs_data['labels'][ $tab ] != '' ? $tabs_data['labels'][ $tab ] : $name;
  2401. $type = isset( $tabs_data['types'] ) && isset( $tabs_data['types'][ $tab ] ) && $tabs_data['types'][ $tab ] != '' ? $tabs_data['types'][ $tab ] : 'regular';
  2402.  
  2403. $bp_tabs[] = array(
  2404. 'type' => $type,
  2405. 'name' => __($label,'kleo_framework'),
  2406. 'group' => $name,
  2407. 'class' => $type . 'tab'
  2408. );
  2409. }
  2410. } else {
  2411. $label = isset( $tabs_data['labels'] ) && isset( $tabs_data['labels'][ $tab ] ) && $tabs_data['labels'][ $tab ] != '' ? $tabs_data['labels'][ $tab ] : __( 'My photos', 'kleo_framework' );
  2412. $class = in_array( $tab, array( 'rt_media', 'bp_album' ) ) ? 'mySlider' : '';
  2413.  
  2414. $bp_tabs[] = array(
  2415. 'type' => $tab,
  2416. 'name' => __($label,'kleo_framework'),
  2417. 'class' => $class
  2418. );
  2419. }
  2420.  
  2421. }
  2422. }
  2423. }
  2424.  
  2425.  
  2426. }
  2427.  
  2428. add_action( 'init', 'kleo_my_custom_tabs_data' );
  2429.  
  2430.  
  2431. /**
  2432. * Displays tabs next to user image
  2433. * @global array $bp_tabs
  2434. */
  2435. if ( ! function_exists( 'kleo_bp_profile_tabs' ) ):
  2436. function kleo_bp_profile_tabs() {
  2437. global $bp_tabs;
  2438.  
  2439. echo '<div class="seven columns">';
  2440. new BpMembersTabs( $bp_tabs );
  2441. echo '</div>';
  2442. }
  2443. endif;
  2444. add_action( 'bp_after_member_header', 'kleo_bp_profile_tabs', 2 );
  2445.  
  2446. /* Add a new activity stream when registering with Facebook */
  2447. if ( ! function_exists( 'gaf_fb_register_activity' ) ):
  2448. function gaf_fb_register_activity( $user_id ) {
  2449. global $bp;
  2450. if ( ! function_exists( 'bp_activity_add' ) ) {
  2451. return false;
  2452. }
  2453.  
  2454. $userlink = bp_core_get_userlink( $user_id );
  2455. bp_activity_add( array(
  2456. 'user_id' => $user_id,
  2457. 'action' => apply_filters( 'xprofile_fb_register_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
  2458. 'component' => 'xprofile',
  2459. 'type' => 'new_member'
  2460. ) );
  2461. }
  2462. endif;
  2463. add_action( 'fb_register_action', 'gaf_fb_register_activity' );
  2464.  
  2465.  
  2466. /* Show "Change photo" link over profile image */
  2467. if ( ! function_exists( 'kleo_bp_profile_photo_change' ) ):
  2468. function kleo_bp_profile_photo_change() {
  2469. if ( bp_is_my_profile() ) {
  2470. echo '<div class="profile-hover-link">';
  2471. echo '<a href="' . bp_loggedin_user_domain() . 'profile/change-avatar/#item-nav">';
  2472. _e( "Change photo", "kleo_framework" );
  2473. echo '</a></div>';
  2474.  
  2475. echo '<script type="text/javascript">
  2476. jQuery(document).ready(function() {
  2477. jQuery("#profile").hover(
  2478. function() {
  2479. jQuery(".image-hover img").fadeTo(200, 0.9);
  2480. jQuery(".image-hover .profile-hover-link").show();
  2481. },
  2482. function() {
  2483. jQuery(".image-hover img").fadeTo(200, 1);
  2484. jQuery(".image-hover .profile-hover-link").hide();
  2485. });
  2486. });
  2487. </script>';
  2488. }
  2489. }
  2490. endif;
  2491. add_action( 'kleo_bp_after_profile_image', 'kleo_bp_profile_photo_change' );
  2492.  
  2493. /* Language parameter in search form */
  2494. add_action( 'kleo_bp_search_add_data', 'kleo_translated_field' );
  2495. function kleo_translated_field() {
  2496. if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
  2497. echo "<input type='hidden' name='lang' value='" . ICL_LANGUAGE_CODE . "'/>";
  2498. }
  2499. }
  2500.  
  2501.  
  2502. if ( ! function_exists( 'kleo_bp_member_dir_view_button' ) ):
  2503. /**
  2504. * Render view profile button on members directory
  2505. */
  2506. function kleo_bp_member_dir_view_button() {
  2507. ?>
  2508. <a href="<?php bp_member_permalink(); ?>" class="small button radius secondary"><i
  2509. class="icon-angle-right"></i> <?php _e( "View profile", 'kleo_framework' ); ?></a>
  2510. <?php
  2511. }
  2512. endif;
  2513. add_action( 'bp_directory_members_item_last', 'kleo_bp_member_dir_view_button', 10 );
  2514.  
  2515.  
  2516. if ( ! function_exists( 'kleo_bp_member_dir_friend_button' ) ) {
  2517. /**
  2518. * Render add friend button on members directory
  2519. */
  2520. function kleo_bp_member_dir_friend_button() {
  2521. add_filter( 'bp_get_add_friend_button', 'kleo_change_profile_button' );
  2522. bp_add_friend_button( bp_get_member_user_id() );
  2523. }
  2524. }
  2525. if ( bp_is_active( 'friends' ) ) {
  2526. add_action( 'bp_directory_members_item_last', 'kleo_bp_member_dir_friend_button', 11 );
  2527. }
  2528. remove_action( 'bp_directory_members_actions', 'bp_member_add_friend_button' );
  2529.  
  2530. if ( ! function_exists( 'kleo_change_profile_button' ) ):
  2531. /**
  2532. * Change default BP button class and text next to profile in members directory
  2533. *
  2534. * @param array $button
  2535. *
  2536. * @return array
  2537. */
  2538. function kleo_change_profile_button( $button ) {
  2539. $is_friend = bp_is_friend( bp_get_member_user_id() );
  2540.  
  2541. if ( empty( $is_friend ) ) {
  2542. return false;
  2543. }
  2544.  
  2545. switch ( $is_friend ) {
  2546. case "pending":
  2547. case "is_friend":
  2548. $button['link_text'] = '<i class="icon-minus"></i>';
  2549. break;
  2550. default:
  2551. $button['link_text'] = '<i class="icon-plus"></i>';
  2552. break;
  2553. }
  2554.  
  2555. $button['link_class'] = 'button small secondary radius';
  2556.  
  2557. return $button;
  2558. }
  2559. endif;
  2560.  
  2561.  
  2562. /* User online */
  2563. if ( ! function_exists( 'kleo_is_user_online' ) ):
  2564. /**
  2565. * Check if a Buddypress member is online or not
  2566. * @global object $wpdb
  2567. *
  2568. * @param integer $user_id
  2569. * @param integer $time
  2570. *
  2571. * @return boolean
  2572. */
  2573. function kleo_is_user_online( $user_id, $time = 5 ) {
  2574. global $wpdb;
  2575. $sql = $wpdb->prepare( "
  2576. SELECT u.user_login FROM $wpdb->users u JOIN $wpdb->usermeta um ON um.user_id = u.ID
  2577. WHERE u.ID = %d
  2578. AND um.meta_key = 'last_activity'
  2579. AND DATE_ADD( um.meta_value, INTERVAL %d MINUTE ) >= UTC_TIMESTAMP()", $user_id, $time );
  2580. $user_login = $wpdb->get_var( $sql );
  2581. if ( isset( $user_login ) && $user_login != "" ) {
  2582. return true;
  2583. } else {
  2584. return false;
  2585. }
  2586. }
  2587. endif;
  2588.  
  2589. if ( ! function_exists( 'kleo_online_status' ) ) {
  2590. /**
  2591. * Render the html to show if a user is online or not
  2592. */
  2593. function kleo_online_status() {
  2594. if ( kleo_is_user_online( bp_get_member_user_id() ) ) {
  2595. echo '<span class="online"></span>';
  2596. } else {
  2597. echo '<span class="offline"></span>';
  2598. }
  2599. }
  2600.  
  2601. if ( sq_option( 'bp_online_status', 0 ) == 1 ) {
  2602. add_action( 'bp_members_inside_avatar', 'kleo_online_status', 9 );
  2603. }
  2604. }
  2605.  
  2606.  
  2607. //Buddypress SIDEBAR ACTION
  2608. add_action( 'wp_head', 'kleo_bp_layout' );
  2609. function kleo_bp_layout() {
  2610. if ( ! bp_is_blog_page() ) {
  2611. if ( bp_is_members_directory() ) {
  2612. $option = sq_option( 'bp_members_sidebar', 'no' );
  2613. } elseif ( bp_is_user() && 'default' != sq_option( 'bp_member_sidebar', 'default' ) ) {
  2614. $option = sq_option( 'bp_member_sidebar', 'default' );
  2615. } else {
  2616. $option = sq_option( 'buddypress_sidebar', 'right' );
  2617. }
  2618.  
  2619. switch ( $option ) {
  2620. case 'left':
  2621. remove_action( 'kleo_buddypress_before_content', 'kleo_buddypress_sidebar' );
  2622. remove_action( 'kleo_buddypress_after_content', 'kleo_buddypress_sidebar' );
  2623. add_action( 'kleo_buddypress_before_content', 'kleo_buddypress_sidebar' );
  2624. add_filter( 'kleo_buddypress_content_class', function() { return "eight"; } );
  2625. add_filter( 'kleo_sidebar_class', function() { return "four"; } );
  2626. break;
  2627. case 'right':
  2628. remove_action( 'kleo_buddypress_before_content', 'kleo_buddypress_sidebar' );
  2629. remove_action( 'kleo_buddypress_after_content', 'kleo_buddypress_sidebar' );
  2630. add_action( 'kleo_buddypress_after_content', 'kleo_buddypress_sidebar' );
  2631. add_filter( 'kleo_buddypress_content_class', function() { return "eight"; } );
  2632. add_filter( 'kleo_sidebar_class', function() { return "four"; } );
  2633. break;
  2634. case '3ll':
  2635. add_filter( 'kleo_buddypress_content_class', function() { return "six"; } );
  2636. add_filter( 'kleo_sidebar_class', function() { return "three"; } );
  2637. add_action( 'kleo_buddypress_before_content', 'kleo_buddypress_sidebar' );
  2638. add_action( 'kleo_buddypress_before_content', 'kleo_extra_sidebar' );
  2639. break;
  2640. case '3lr':
  2641. add_filter( 'kleo_buddypress_content_class', function() { return "six"; } );
  2642. add_filter( 'kleo_sidebar_class', function() { return "three"; } );
  2643. add_action( 'kleo_buddypress_before_content', 'kleo_buddypress_sidebar' );
  2644. add_action( 'kleo_buddypress_after_content', 'kleo_extra_sidebar' );
  2645. break;
  2646. case '3rr':
  2647. add_filter( 'kleo_buddypress_content_class', function() { return "six"; } );
  2648. add_filter( 'kleo_sidebar_class', function() { return "three"; } );
  2649. add_action( 'kleo_buddypress_after_content', 'kleo_buddypress_sidebar' );
  2650. add_action( 'kleo_buddypress_after_content', 'kleo_extra_sidebar' );
  2651. break;
  2652. case 'no':
  2653. remove_action( 'kleo_buddypress_before_content', 'kleo_sidebar' );
  2654. remove_action( 'kleo_buddypress_after_content', 'kleo_sidebar' );
  2655. add_filter( 'kleo_buddypress_content_class', function() { return "twelve"; } );
  2656. break;
  2657. default:
  2658. break;
  2659. }
  2660. }
  2661. }
  2662.  
  2663. //get buddypress sidebar
  2664. if ( ! function_exists( 'kleo_buddypress_sidebar' ) ) {
  2665. function kleo_buddypress_sidebar() {
  2666. get_sidebar( 'buddypress' );
  2667. }
  2668. }
  2669.  
  2670.  
  2671. /* Buddypress fix for Posting ordered list */
  2672. function kleo_fix_activity_ordered_list( $activity_allowedtags ) {
  2673. $activity_allowedtags['ol'] = array();
  2674.  
  2675. return $activity_allowedtags;
  2676. }
  2677.  
  2678. add_filter( 'bp_activity_allowed_tags', 'kleo_fix_activity_ordered_list' );
  2679.  
  2680.  
  2681. /* Terms and conditions - Register page */
  2682. add_action( 'bp_after_signup_profile_fields', 'kleo_bp_tos_register' );
  2683. //TOS in register page
  2684. function kleo_bp_tos_register() {
  2685. if ( sq_option( 'terms_page', '#' ) != "#" ) {
  2686. $checked = isset( $_POST['tos_register'] ) ? 'checked="checked"' : '';
  2687. $terms_page_id = sq_option( 'terms_page' );
  2688. /* WPML compatibility */
  2689. if ( function_exists( 'icl_object_id' ) ) {
  2690. $terms_page_id = icl_object_id( $terms_page_id, 'page', true );
  2691. }
  2692. $terms_link = get_permalink( $terms_page_id );
  2693. ?>
  2694. <p class="right">
  2695. <label><input name="tos_register" id="tos_register"<?php echo $checked; ?> type="checkbox"
  2696. class="tos_register" data-customforms="disabled">
  2697. <small>
  2698. <?php printf( __( 'I agree with the <a href="%s" target="_blank"><strong>terms and conditions</strong></a>.', 'kleo_framework' ), $terms_link ); ?>
  2699. </small>
  2700. </label>
  2701. </p>
  2702. <?php
  2703. }
  2704. }
  2705.  
  2706. /* Profile placeholder in menu */
  2707. add_filter( 'walker_nav_menu_start_el', 'kleo_bp_replace_placeholders' );
  2708.  
  2709. function kleo_bp_replace_placeholders( $output ) {
  2710.  
  2711. if ( strpos( $output, '##profile_link##' ) !== false ) {
  2712.  
  2713. if ( ! is_user_logged_in() ) {
  2714. return '';
  2715. }
  2716.  
  2717. $logged_in_link = bp_loggedin_user_domain( '/' );
  2718. $output = str_replace( '##profile_link##', $logged_in_link, $output );
  2719. }
  2720.  
  2721. return $output;
  2722. }
  2723.  
  2724.  
  2725. /* Buddypress cover compatibility */
  2726.  
  2727. function sweet_bp_cover_image_css( $settings = array() ) {
  2728. /**
  2729. * If you are using a child theme, use bp-child-css
  2730. * as the theme handel
  2731. */
  2732. $theme_handle = 'bp-parent-css';
  2733.  
  2734. /**
  2735. * You can choose to register it for Members and / or Groups by including (or not)
  2736. * the corresponding components in your feature's settings. In this example, we
  2737. * chose to register it for both components.
  2738. */
  2739. $components = array( 'groups', 'xprofile' );
  2740. $settings['components'] = $components;
  2741.  
  2742. $settings['theme_handle'] = $theme_handle;
  2743. $settings['width'] = 940;
  2744. $settings['height'] = 225;
  2745.  
  2746. /**
  2747. * Then you'll probably also need to use your own callback function
  2748. * @see the previous snippet
  2749. */
  2750. $settings['callback'] = 'sweet_default_cover_image';
  2751.  
  2752.  
  2753. return $settings;
  2754. }
  2755. add_filter( 'bp_before_xprofile_cover_image_settings_parse_args', 'sweet_bp_cover_image_css', 10, 1 );
  2756. add_filter( 'bp_before_groups_cover_image_settings_parse_args', 'sweet_bp_cover_image_css', 10, 1 );
  2757.  
  2758.  
  2759. /**
  2760. * Function to customize the display of the cover image
  2761. * @param array $params
  2762. *
  2763. * @return string|void
  2764. */
  2765. function sweet_default_cover_image( $params = array() ) {
  2766.  
  2767. if ( empty( $params ) || ( isset( $params['cover_image'] ) && ! $params['cover_image'] ) ) {
  2768. return;
  2769. }
  2770.  
  2771. /* Add body class for users with cover */
  2772. add_filter( 'body_class', 'sweet_bp_cover_add_body_class', 30 );
  2773.  
  2774. $cover_image = 'background-image: url(' . $params['cover_image'] . '); ' .
  2775. 'background-repeat: no-repeat; background-size: cover; background-position: center center !important;';
  2776.  
  2777. if ( bp_is_user() ) {
  2778.  
  2779. return '
  2780. /* Cover image */
  2781. body.buddypress.is-user-profile div#profile {
  2782. ' . $cover_image . '
  2783. }';
  2784. } else {
  2785. return '
  2786. /* Cover image */
  2787. body.buddypress #header-cover-image {
  2788. ' . $cover_image . '
  2789. }';
  2790. }
  2791. }
  2792.  
  2793. //inject custom class for profile pages
  2794. function sweet_bp_cover_add_body_class( $classes ) {
  2795. $classes[] = 'is-user-profile';
  2796.  
  2797. return $classes;
  2798. }
  2799.  
  2800.  
  2801. /* END COVER */
  2802.  
  2803.  
  2804. if ( ! function_exists( 'bp_groups_front_template_part' ) ) {
  2805. /**
  2806. * Output the contents of the current group's home page.
  2807. *
  2808. * You should only use this when on a single group page.
  2809. *
  2810. * @since 2.4.0
  2811. */
  2812. function bp_groups_front_template_part() {
  2813. $located = bp_groups_get_front_template();
  2814.  
  2815. if ( false !== $located ) {
  2816. $slug = str_replace( '.php', '', $located );
  2817.  
  2818. /**
  2819. * Let plugins adding an action to bp_get_template_part get it from here
  2820. *
  2821. * @param string $slug Template part slug requested.
  2822. * @param string $name Template part name requested.
  2823. */
  2824. do_action( 'get_template_part_' . $slug, $slug, false );
  2825.  
  2826. load_template( $located, true );
  2827.  
  2828. } else if ( bp_is_active( 'activity' ) ) {
  2829. bp_get_template_part( 'groups/single/activity' );
  2830.  
  2831. } else if ( bp_is_active( 'members' ) ) {
  2832. bp_groups_members_template_part();
  2833. }
  2834.  
  2835. return $located;
  2836. }
  2837. }
  2838.  
  2839.  
  2840. /* Display BuddyPress Member Types Filters in Members Directory */
  2841.  
  2842. add_action( 'bp_members_directory_member_types', 'kleo_bp_member_types_tabs' );
  2843. function kleo_bp_member_types_tabs() {
  2844. if ( ! bp_get_current_member_type() ) {
  2845. $member_types = bp_get_member_types( array(), 'objects' );
  2846. if ( $member_types ) {
  2847. foreach ( $member_types as $member_type ) {
  2848. if ( $member_type->has_directory == 1 ) {
  2849. echo '<li id="members-' . esc_attr( $member_type->name ) . '" class="bp-member-type-filter">';
  2850. echo '<a href="' . bp_get_members_directory_permalink() . 'type/' . $member_type->directory_slug . '/">' . sprintf( '%s <span>%d</span>', $member_type->labels['name'], kleo_bp_count_member_types( $member_type->name ) ) . '</a>';
  2851. echo '</li>';
  2852. }
  2853. }
  2854. }
  2855. }
  2856. }
  2857.  
  2858.  
  2859. add_filter( 'bp_modify_page_title', 'kleo_bp_members_type_directory_page_title', 9, 4 );
  2860. function kleo_bp_members_type_directory_page_title( $title, $original_title, $sep, $seplocation ) {
  2861. $member_type = bp_get_current_member_type();
  2862. if ( bp_is_directory() && $member_type ) {
  2863. $member_type = bp_get_member_type_object( $member_type );
  2864. if ( $member_type ) {
  2865. global $post;
  2866. $post->post_title = $member_type->labels['name'];
  2867. $title = $member_type->labels['name'] . " " . $sep . " " . $original_title;
  2868. }
  2869. }
  2870.  
  2871. return $title;
  2872. }
  2873.  
  2874.  
  2875. add_filter( 'bp_get_total_member_count', 'kleo_bp_get_total_member_count_member_type' );
  2876. function kleo_bp_get_total_member_count_member_type() {
  2877. $count = bp_core_get_active_member_count();
  2878. $member_type = bp_get_current_member_type();
  2879. if ( bp_is_directory() && $member_type ) {
  2880. $count = kleo_bp_count_member_types( $member_type );
  2881. }
  2882.  
  2883. return $count;
  2884. }
  2885.  
  2886.  
  2887. add_filter( 'bp_get_total_friend_count', 'kleo_bp_get_total_friend_count_member_type' );
  2888. function kleo_bp_get_total_friend_count_member_type() {
  2889. $user_id = get_current_user_id();
  2890. $count = friends_get_total_friend_count( $user_id );
  2891. $member_type = bp_get_current_member_type();
  2892. if ( bp_is_directory() && $member_type ) {
  2893. global $bp, $wpdb;
  2894. $friends = $wpdb->get_results( "SELECT count(1) as count FROM {$bp->friends->table_name} bpf
  2895. LEFT JOIN {$wpdb->term_relationships} tr ON (bpf.initiator_user_id = tr.object_id || bpf.friend_user_id = tr.object_id )
  2896. LEFT JOIN {$wpdb->terms} t ON t.term_id = tr.term_taxonomy_id
  2897. WHERE t.slug = '" . $member_type . "' AND (bpf.initiator_user_id = $user_id || bpf.friend_user_id = $user_id ) AND tr.object_id != $user_id AND bpf.is_confirmed = 1", ARRAY_A );
  2898. $count = 0;
  2899. if ( isset( $friends['0']['count'] ) && is_numeric( $friends['0']['count'] ) ) {
  2900. $count = $friends['0']['count'];
  2901. }
  2902. }
  2903.  
  2904. return $count;
  2905. }
  2906.  
  2907.  
  2908. function kleo_bp_count_member_types( $member_type = '' ) {
  2909. if ( ! bp_is_root_blog() ) {
  2910. switch_to_blog( bp_get_root_blog_id() );
  2911. }
  2912. global $wpdb;
  2913. $sql = array(
  2914. 'select' => "SELECT t.slug, tt.count FROM {$wpdb->term_taxonomy} tt LEFT JOIN {$wpdb->terms} t",
  2915. 'on' => 'ON tt.term_id = t.term_id',
  2916. 'where' => $wpdb->prepare( 'WHERE tt.taxonomy = %s', 'bp_member_type' ),
  2917. );
  2918. $members_count = $wpdb->get_results( join( ' ', $sql ) );
  2919. $members_count = wp_filter_object_list( $members_count, array( 'slug' => $member_type ), 'and', 'count' );
  2920. $members_count = array_values( $members_count );
  2921. if ( isset( $members_count[0] ) && is_numeric( $members_count[0] ) ) {
  2922. $members_count = $members_count[0];
  2923. } else {
  2924. $members_count = 0;
  2925. }
  2926. restore_current_blog();
  2927.  
  2928. return $members_count;
  2929. }
  2930.  
  2931.  
  2932. add_filter( 'bp_before_has_members_parse_args', 'kleo_bp_set_has_members_type_arg', 10, 1 );
  2933. function kleo_bp_set_has_members_type_arg( $args ) {
  2934. $member_type = bp_get_current_member_type();
  2935. $member_types = bp_get_member_types( array(), 'names' );
  2936. if ( isset( $args['scope'] ) && ! isset( $args['member_type'] ) && in_array( $args['scope'], $member_types ) ) {
  2937. if ( $member_type ) {
  2938. unset( $args['scope'] );
  2939. } else {
  2940. $args['member_type'] = $args['scope'];
  2941. }
  2942. }
  2943.  
  2944. return $args;
  2945. }
  2946.  
  2947. add_action( 'bp_before_member_header_meta', 'kleo_bp_profile_member_type_label' );
  2948. function kleo_bp_profile_member_type_label() {
  2949. $member_type = bp_get_member_type( bp_displayed_user_id() );
  2950. if ( empty( $member_type ) ) {
  2951. return;
  2952. }
  2953. $member_type_object = bp_get_member_type_object( $member_type );
  2954. if ( $member_type_object ) {
  2955. $member_type_label = '<p class="kleo_bp_profile_member_type_label">' . esc_html( $member_type_object->labels['singular_name'] ) . '</p>';
  2956. echo apply_filters( 'kleo_bp_profile_member_type_label', $member_type_label );
  2957. }
  2958. }
  2959.  
  2960. /*Make xprofile fields translable fix*/
  2961. if ( ! function_exists( 'make_x_profile_fields_name_translable' ) ):
  2962.  
  2963. function make_x_profile_fields_name_translable( $fieldname ) {
  2964. return __( $fieldname, 'kleo_framework' );
  2965. }
  2966.  
  2967. add_filter( 'bp_get_the_profile_field_name', 'make_x_profile_fields_name_translable' );
  2968.  
  2969. endif;
  2970.  
  2971.  
  2972. /* Render search form horizontal on members page */
  2973. add_action( 'kleo_bp_before_page', 'kleo_members_filter' );
  2974. if ( ! function_exists( 'kleo_members_filter' ) ) {
  2975. function kleo_members_filter() {
  2976. if ( ! bp_is_members_directory() ) {
  2977. return;
  2978. }
  2979. global $bp_search_fields;
  2980.  
  2981. if ( function_exists( 'kleo_bp_search_form_horizontal' ) && bp_is_active( 'xprofile' ) ) {
  2982. $mode = ( isset( $bp_search_fields['button_show'] ) && $bp_search_fields['button_show'] == 1 ) ? true : false;
  2983. kleo_bp_search_form_horizontal( $mode );
  2984. }
  2985. }
  2986. }
  2987.  
  2988. /* Members directory page title */
  2989. add_action( 'bp_before_directory_members_content', 'sweet_bp_members_title' );
  2990. function sweet_bp_members_title() {
  2991. global $bp_results;
  2992.  
  2993. $page_title = get_the_title();
  2994. $lead = '';
  2995. if ( isset( $_GET['bs'] ) && ! empty( $bp_results['users'] )
  2996. && ( ( isset( $bp_results['users'][0] ) && $bp_results['users'][0] != 0 ) || ! isset( $bp_results['users'][0] ) )
  2997. ) {
  2998. $page_title = __( 'Profile Search <span class="pink-text">results</span>', 'kleo_framework' );
  2999. $lead = __( "Your search returned", 'kleo_framework' ) . " " . count( $bp_results['users'] ) . " " . _n( 'member', 'members', count( $bp_results['users'] ), 'kleo_framework' );
  3000. }
  3001.  
  3002. echo '<h2>' . $page_title . '</h2>';
  3003. echo '<p class="lead">' . $lead . '</p>';
  3004. }
  3005.  
  3006. /* BuddyPress 3.0 compat */
  3007. if ( 'legacy' !== get_option( '_bp_theme_package_id' ) && false == apply_filters( 'bp_30_disable_compat', false ) ) {
  3008. update_option( '_bp_theme_package_id', 'legacy' );
  3009. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement