PageRenderTime 46ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/platform/core/library/library.shortcodes.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 193 lines | 96 code | 57 blank | 40 comment | 8 complexity | a5f498ebfbd8414ef0cb949ccaaef79b MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. // Make widgets process shortcodes
  3. add_filter('widget_text', 'do_shortcode');
  4. // LAYOUT //////////////////////////////////////////////////
  5. //Created a container for dynamic html layout
  6. // USAGE: [container id="mycontainer" class="myclass"] 'cboxes' see shortcode below [/container]
  7. function dynamic_container($atts, $content = null ) {
  8. //extract page name from the shortcode attributes
  9. extract(shortcode_atts(array( 'id' => 'container', 'class' => ''), $atts));
  10. //$content = remove_filter($content, 'wptexturize');
  11. $container = '<div style="width: 100%;" class="container">'.do_shortcode($content).'<div class="clear"></div></div>';
  12. return $container;
  13. }
  14. add_shortcode('container', 'dynamic_container');
  15. //Created a container for dynamic html layout
  16. // USAGE: [cbox width="50%" leftgutter="15px" rightgutter="0px"] html box content[/cbox]
  17. function dynamic_box($atts, $content = null ) {
  18. //extract page name from the shortcode attributes
  19. extract(shortcode_atts(array( 'width' => '30%', 'leftgutter' => '10px', 'rightgutter' => '0px'), $atts));
  20. $cbox = '<div class="cbox" style="float:left;width:'.$width.';"><div class="cbox_pad" style="margin: 0px '.$rightgutter.' 0px '.$leftgutter.'">'.do_shortcode($content).'</div></div>';
  21. return $cbox;
  22. }
  23. add_shortcode('cbox', 'dynamic_box');
  24. // GET POST FIELD BY OFFSET //////////////////////////////////////////////////
  25. // Get a post based on offset from the last post published (0 for last post)
  26. // USAGE: [postfeed field="post_title" offset="0" customfield="true" ]
  27. function get_postfeed($atts) {
  28. //extract page name from the shortcode attributes
  29. extract(shortcode_atts(array( 'field' => 'post_title', 'offset' => '0', 'customfield' => ""), $atts));
  30. //returns an array of objects
  31. $thepost = get_posts('numberposts=1&offset='.$offset);
  32. if($customfield == 'true'){
  33. $postfield = get_post_meta($thepost[0]->ID, $field, true);
  34. }else{
  35. $postfield = $thepost[0]->$field;
  36. }
  37. return $postfield;
  38. }
  39. add_shortcode('postfeed', 'get_postfeed');
  40. // GOOGLE CHARTS //////////////////////////////////////////////////
  41. // Gets Google charts
  42. // USAGE
  43. // [chart data="0,12,24,26,32,64,54,24,22,20,8,2,0,0,3" bg="F7F9FA" size="200x100" type="sparkline"]
  44. // [chart data="41.52,37.79,20.67,0.03" bg="F7F9FA" labels="Reffering+sites|Search+Engines|Direct+traffic|Other" colors="058DC7,50B432,ED561B,EDEF00" size="488x200" title="Traffic Sources" type="pie"]
  45. function chart_shortcode( $atts ) {
  46. extract(shortcode_atts(array(
  47. 'data' => '',
  48. 'colors' => '',
  49. 'size' => '400x200',
  50. 'bg' => 'ffffff',
  51. 'title' => '',
  52. 'labels' => '',
  53. 'advanced' => '',
  54. 'type' => 'pie'
  55. ), $atts));
  56. switch ($type) {
  57. case 'line' :
  58. $charttype = 'lc'; break;
  59. case 'xyline' :
  60. $charttype = 'lxy'; break;
  61. case 'sparkline' :
  62. $charttype = 'ls'; break;
  63. case 'meter' :
  64. $charttype = 'gom'; break;
  65. case 'scatter' :
  66. $charttype = 's'; break;
  67. case 'venn' :
  68. $charttype = 'v'; break;
  69. case 'pie' :
  70. $charttype = 'p3'; break;
  71. case 'pie2d' :
  72. $charttype = 'p'; break;
  73. default :
  74. $charttype = $type;
  75. break;
  76. }
  77. if ($title) $string .= '&chtt='.$title.'';
  78. if ($labels) $string .= '&chl='.$labels.'';
  79. if ($colors) $string .= '&chco='.$colors.'';
  80. $string .= '&chs='.$size.'';
  81. $string .= '&chd=t:'.$data.'';
  82. $string .= '&chf='.$bg.'';
  83. return '<img title="'.$title.'" src="http://chart.apis.google.com/chart?cht='.$charttype.''.$string.$advanced.'" alt="'.$title.'" />';
  84. }
  85. add_shortcode('chart', 'chart_shortcode');
  86. // GOOGLE MAPS //////////////////////////////////////////////////
  87. // you can use the default width and height
  88. // The only requirement is to add the address of the map
  89. // Example:
  90. // [googlemap address="san diego, ca"]
  91. // or with options
  92. // [googlemap width="200" height="200" address="4000 Ocean Blvd., San Diego, CA 92109"]
  93. function googleMaps($atts, $content = null) {
  94. extract(shortcode_atts(array(
  95. "width" => '480',
  96. "height" => '480',
  97. "address" => ''
  98. ), $atts));
  99. $src = "http://maps.google.com/maps?f=q&source=s_q&hl=en&q=".$address;
  100. return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'&amp;output=embed"></iframe>';
  101. }
  102. add_shortcode("googlemap", "googleMaps");
  103. // CONSTANTS
  104. //Function for getting template path
  105. // USAGE: [themeurl]
  106. function get_themeurl($atts){ return get_bloginfo('template_url'); }
  107. add_shortcode('themeurl', 'get_themeurl');
  108. // LINKS IN POSTS AND PAGES
  109. // Function for creating a link from a page name
  110. // USAGE : [link pagename="My Example Page" linktext="Link Text"]
  111. function create_pagelink($atts) {
  112. //extract page name from the shortcode attributes
  113. extract(shortcode_atts(array( 'pagename' => 'home', 'linktext' => ''), $atts));
  114. //convert the page name to a page ID
  115. $page = get_page_by_title($pagename);
  116. //use page ID to get the permalink for the page
  117. $link = get_permalink($page->ID);
  118. //create the link and output
  119. $pagelink = "<a href=\"".$link."\">".$linktext."</a>";
  120. return $pagelink;
  121. }
  122. add_shortcode('link', 'create_pagelink');
  123. // Return link in page based on Bookmark
  124. // USAGE : [bookmark id="21" text="Link Text"]
  125. function bookmark_link($atts) {
  126. //extract page name from the shortcode attributes
  127. extract(shortcode_atts(array( 'id' => '0', 'text' => ''), $atts));
  128. //convert the page name to a page ID
  129. $bookmark = get_bookmark($id);
  130. if(isset($text)) $ltext = $text;
  131. else $ltext = $bookmark->link_name;;
  132. $pagelink = "<a href=\"".$bookmark->link_url."\" target=\"".$bookmark->link_target."\">".$ltext."</a>";
  133. return $pagelink;
  134. }
  135. add_shortcode('bookmark', 'bookmark_link');
  136. ?>