PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/lbak-user-tracking/php_includes/shortcodes.php

https://bitbucket.org/MaheshDhaduk/androidmobiles
PHP | 68 lines | 45 code | 9 blank | 14 comment | 5 complexity | 85ff78fe2f31ce4ea38590df056f9fdc MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /*
  3. * This function turns the arguments of a [checkout] tag into an associative
  4. * array.
  5. */
  6. function lbakut_process_shortcode($shortcode) {
  7. $split = preg_split('/"(\ |^)/i', $shortcode);
  8. $return = array();
  9. for ($i = 0; $i < sizeof($split); $i++) {
  10. $kvpair = explode("=", $split[$i]);
  11. $return[trim($kvpair[0])] = str_replace('"', '', $kvpair[1]);
  12. }
  13. return $return;
  14. }
  15. /*
  16. * Replaces the [checkout] short codes with their appropriate form code.
  17. */
  18. function lbakut_parse_shortcode($the_content) {
  19. global $wpdb;
  20. $options = lbakut_get_options();
  21. if ($options['stats_enable_shortcodes']) {
  22. $regex_pattern = '/\[lbakut(?:.*)\]/i';
  23. $regex_pattern_grouped = '/\[lbakut(.*)\]/i';
  24. $matches = array();
  25. //Match all instances of [checkout] and store them in $matches.
  26. preg_match_all($regex_pattern, $the_content, $matches);
  27. //If there are matches, execute following loop.
  28. if (sizeof($matches[0]) > 0) {
  29. //For each of the matches (it's $matches[0] because of how preg_match_all works)
  30. foreach ($matches[0] as $match) {
  31. //Get the arguments for the checkout tag as an associative array.
  32. $args = lbakut_process_shortcode(preg_replace($regex_pattern_grouped, '$1', $match));
  33. if (isset($args['type'])) {
  34. $title = $args['title'] ? $args['title'] : null;
  35. $width = $args['width'] ? $args['width'] : null;
  36. $height = $args['height'] ? $args['height'] : null;
  37. //Create image tag.script_name
  38. $replace = '<img src="'.lbakut_get_chart(lbakut_chart_type($args['type']), $title, $width, $height).'" />';
  39. //Replace the content with the appropriate code.
  40. $the_content = preg_replace($regex_pattern, $replace, $the_content, 1);
  41. }
  42. }
  43. }
  44. }
  45. //Return the content. NECESSARY.
  46. return $the_content;
  47. }
  48. function lbakut_chart_type($type) {
  49. switch ($type) {
  50. case 'browser': return '`browser_array`';
  51. break;
  52. case 'pageviews': return '`page_array`';
  53. break;
  54. case 'os': return '`platform_array`';
  55. break;
  56. default: return null;
  57. }
  58. }
  59. ?>