Advertisement
Guest User

shortcodes.php

a guest
Apr 28th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 37.41 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Theme Shortcodes Functions
  4. */
  5.  
  6.  
  7. /* ==================================================================================================
  8.    ==                                       ADMIN SETUP                                            ==
  9.    ================================================================================================== */
  10.  
  11. add_filter('the_excerpt', 'do_shortcode');
  12. add_filter('widget_text', 'do_shortcode');      // Enable shortcodes in widgets
  13.  
  14. // Clear paragraph tags around shortcodes
  15. if(!function_exists('shortcode_empty_paragraph_fix')) {
  16.     add_filter('the_content', 'shortcode_empty_paragraph_fix');
  17.     function shortcode_empty_paragraph_fix($content) {  
  18.         $array = array (
  19.             '<p>[' => '[',
  20.             ']</p>' => ']',
  21.             ']<br />' => ']'
  22.         );
  23.         $content = strtr($content, $array);
  24.         return $content;
  25.     }
  26. }
  27.  
  28. // Show shortcodes list in admin editor
  29. add_action('media_buttons','add_sc_select', 11);
  30. function add_sc_select(){
  31.  
  32.     $shortcodes_list = '<select id="sc_select"><option value="">&nbsp;*Select Shortcode*&nbsp;</option>';
  33.  
  34.     $shortcodes_list .= '<option value="'
  35.         . "[title style='1']Title text here[/title]"
  36.         . '">Title</option>';
  37.     $shortcodes_list .= '<option value="'
  38.         . "[line style='solid' top='10' bottom='10' width='100%' height='1' color='']"
  39.         . '">Line</option>';
  40.     $shortcodes_list .= '<option value="'
  41.         . "[infobox style='regular' static='1']Highlight text here[/infobox]"
  42.         . '">Infobox</option>';
  43.     $shortcodes_list .= '<option value="'
  44.         . "[image src='' width='190' height='145' title='' align='left' alt='']"
  45.         . '">Image</option>';
  46.     $shortcodes_list .= '<option value="'
  47.         . "[highlight color='white' backcolor='#ff0000']Highlighted text here[/highlight]"
  48.         . '">Highlight</option>';
  49.     $shortcodes_list .= '<option value="'
  50.         . "[quote style='1' cite='']Quoted text here[/quote]"
  51.         . '">Quote</option>';
  52.     $shortcodes_list .= '<option value="'
  53.         . "[tooltip title='Tooltip title']Marked text here[/tooltip]"
  54.         . '">Tooltip</option>';
  55.     $shortcodes_list .= '<option value="'
  56.         . "[dropcaps style='1']Dropcaps paragraph text here[/dropcaps]"
  57.         . '">Dropcaps</option>';
  58.     $shortcodes_list .= '<option value="'
  59.         . "[audio url='' controls='1']"
  60.         . '">Audio</option>';
  61.     $shortcodes_list .= '<option value="'
  62.         . "[video url='' width='480' height='270']"
  63.         . '">Video</option>';
  64.     $shortcodes_list .= '<option value="'
  65.         . "[section style='']Section inner text here[/section]"
  66.         . '">Section</option>';
  67.     $shortcodes_list .= '<option value="'
  68.         . "[columns count='2']
  69.         [column_item]Item 1 inner text here[/column_item]
  70.         [column_item]Item 2 inner text here[/column_item]
  71.         [/columns]"
  72.         . '">Columns</option>';
  73.     $shortcodes_list .= '<option value="'
  74.         . "[list style='regular']
  75.         [list_item]List Item 1 inner text here[/list_item]
  76.         [list_item]List Item 2 inner text here[/list_item]
  77.         [list_item]List Item 3 inner text here[/list_item]
  78.         [/list]"
  79.         . '">List</option>';
  80.     $shortcodes_list .= '<option value="'
  81.         . "[tabs tab_names='Tab 1|Tab 2|Tab 3' style='1' initial='1']
  82.         [tab]Tab 1 inner text here[/tab]
  83.         [tab]Tab 2 inner text here[/tab]
  84.         [tab]Tab 3 inner text here[/tab]
  85.         [/tabs]"
  86.         . '">Tabs</option>';
  87.     $shortcodes_list .= '<option value="'
  88.         . "[accordion style='1' initial='1']
  89.         [accordion_item title='Title 1']Item 1 inner text here[/accordion_item]
  90.         [accordion_item title='Title 2']Item 2 inner text here[/accordion_item]
  91.         [accordion_item title='Title 3']Item 3 inner text here[/accordion_item]
  92.         [/accordion]"
  93.         . '">Accordion</option>';
  94.     $shortcodes_list .= '<option value="'
  95.         . "[toggles initial='1']
  96.         [toggles_item title='Title 1']Item 1 inner text here[/toggles_item]
  97.         [toggles_item title='Title 2']Item 2 inner text here[/toggles_item]
  98.         [toggles_item title='Title 3']Item 3 inner text here[/toggles_item]
  99.         [/toggles]"
  100.         . '">Toggles</option>';
  101.     $shortcodes_list .= '<option value="'
  102.         . "[table]
  103.         Paste here table content, generated on one of many public internet resources, for example: http://www.impressivewebs.com/html-table-code-generator/ or http://html-tables.com/
  104.         [/table]"
  105.         . '">Table</option>';
  106.     $shortcodes_list .= '<option value="'."[googlemap address='' width='400' height='240']".'">Google Map</option>';   
  107.     $shortcodes_list .= '<option value="'."[contact_form title='Contact Form' description='']".'">Contact form</option>';  
  108.     $shortcodes_list .= '<option value="'."[hide selector='']".'">Hide block</option>';
  109.     $shortcodes_list .= '</select>';
  110.     echo $shortcodes_list;
  111. }
  112.  
  113. // Shortcodes list select handler
  114. add_action('admin_head', 'button_js');
  115. function button_js() {
  116.     echo '<script type="text/javascript">
  117.     jQuery(document).ready(function(){
  118.        jQuery("#sc_select").change(function() {
  119.               send_to_editor(jQuery("#sc_select :selected").val());
  120.               jQuery("#sc_select option:first-child").attr("selected", true);
  121.                   return false;
  122.         });
  123.     });
  124.     </script>';
  125. }  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. /* ==================================================================================================
  133.    ==                                       USERS SHORTCODES                                       ==
  134.    ================================================================================================== */
  135.  
  136.  
  137.  
  138. // ---------------------------------- [title] ---------------------------------------
  139.  
  140.  
  141. add_shortcode('title', 'sc_title');
  142.  
  143. /*
  144. [title id="unique_id" style="1-6"]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta[/title]
  145. */
  146. function sc_title($atts, $content=null){   
  147.     extract(shortcode_atts(array(
  148.         "id" => "",
  149.         "style" => "1"
  150.     ), $atts));
  151.     $style = min(6, max(1, $style));
  152.     return '<h' . $style . ($id ? ' id="' . $id . '"' : '') . ' class="sc_title sc_title_style_' . $style . '">' . do_shortcode($content) . '</h' . $style . '>';
  153. }
  154.  
  155. // ---------------------------------- [/title] ---------------------------------------
  156.  
  157.  
  158.  
  159. // ---------------------------------- [line] ---------------------------------------
  160.  
  161.  
  162. add_shortcode('line', 'sc_line');
  163.  
  164. /*
  165. [line id="unique_id" style="none|solid|dashed|dotted|double|groove|ridge|inset|outset" top="margin_in_pixels" bottom="margin_in_pixels" width="width_in_pixels_or_percent" height="line_thickness_in_pixels" color="line_color's_name_or_#rrggbb"]
  166. */
  167. function sc_line($atts, $content=null){
  168.     extract(shortcode_atts(array(
  169.         "id" => "",
  170.         "style" => "solid",
  171.         "color" => "",
  172.         "width" => "-1",
  173.         "height" => "-1",
  174.         "top" => "-1",
  175.         "bottom" => "-1"
  176.     ), $atts));
  177.     $ed = my_substr($width, -1)=='%' ? '%' : 'px';
  178.     $width = (int) str_replace('%', '', $width);
  179.     $w = $width >= 0 ? 'width:' . $width . $ed . ';' : '';
  180.     $h = $height >= 0 ? 'border-top-width:' . $height . 'px;' : '';
  181.     $t = $top >= 0 ? 'margin-top:' . $top . 'px;' : '';
  182.     $b = $bottom >= 0 ? 'margin-bottom:' . $bottom . 'px;' : '';
  183.     $s = $style != '' ? 'border-top-style:' . $style . ';' : '';
  184.     $c = $color != '' ? 'border-top-color:' . $color . ';' : '';
  185.     $rez = $w . $h . $t . $b . $s .$c;
  186.     $rez = $rez ? ' style="' . $rez . '"' : '';
  187.     return '<div' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_line' . ($style != '' ? ' sc_line_style_' . $style : '') . '"' . $rez . '></div>';
  188. }
  189.  
  190. // ---------------------------------- [/line] ---------------------------------------
  191.  
  192.  
  193.  
  194. // ---------------------------------- [infoboxes] ---------------------------------------
  195.  
  196.  
  197. add_shortcode('infobox', 'sc_infobox');
  198.  
  199. /*
  200. [infobox id="unique_id" style="regular|info|success|error|result" static="0|1"]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta[/infobox]
  201. */
  202. function sc_infobox($atts, $content=null){ 
  203.     extract(shortcode_atts(array(
  204.         "id" => "",
  205.         "style" => "regular",
  206.         "static" => "1"
  207.     ), $atts));
  208.     return '
  209.         <div' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_infobox sc_infobox_style_' . $style . ($static==0 ? ' sc_infobox_closeable' : '') . '"' . ($static==0 ? ' style="cursor:pointer"' : '') . '>
  210.             ' . do_shortcode($content) . '
  211.         </div>
  212.         ';
  213. }
  214.  
  215. // ---------------------------------- [/infoboxes] ---------------------------------------
  216.  
  217.  
  218.  
  219. // ---------------------------------- [highlight] ---------------------------------------
  220.  
  221.  
  222. add_shortcode('highlight', 'sc_highlight');
  223.  
  224. /*
  225. [highlight id="unique_id" color="fore_color's_name_or_#rrggbb" backcolor="back_color's_name_or_#rrggbb"]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta[/highlight]
  226. */
  227. function sc_highlight($atts, $content=null){   
  228.     extract(shortcode_atts(array(
  229.         "id" => "",
  230.         "color" => "",
  231.         "backcolor" => ""
  232.     ), $atts));
  233.     $c = $color != '' ? 'color:' . $color . ';' : '';
  234.     $b = $backcolor != '' ? 'background-color:' . $backcolor . ';' : '';
  235.     $rez = $c . $b;
  236.     $rez = $rez ? ' style="' . $rez . '"' : '';
  237.     return '<span' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_highlight"' . $rez . '>' . do_shortcode($content) . '</span>';
  238. }
  239.  
  240. // ---------------------------------- [/highlight] ---------------------------------------
  241.  
  242.  
  243.  
  244.  
  245.  
  246. // ---------------------------------- [image] ---------------------------------------
  247.  
  248.  
  249. add_shortcode('image', 'sc_image');
  250.  
  251. /*
  252. [image id="unique_id" src="image_url" width="width_in_pixels" height="height_in_pixels" title="image's_title" align="left|right" alt=""]
  253. */
  254. function sc_image($atts, $content=null){   
  255.     extract(shortcode_atts(array(
  256.         "id" => "",
  257.         "src" => "",
  258.         "title" => "",
  259.         "align" => "",
  260.         "width" => "-1",
  261.         "height" => "-1",
  262.         "alt" => ""
  263.     ), $atts));
  264.     $w = $width > 0 ? 'width:' . $width . 'px;' : '';
  265.     $h = $height > 0 ? 'height:' . $height . 'px;' : '';
  266.     $a = $align != '' ? 'float:' . $align . ';' : '';
  267.     $rez = $w . $h . $a;
  268.     $rez = $rez ? ' style="' . $rez . '"' : '';
  269.     return '
  270.         <figure' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_image ' . ($align ? ' sc_image_align_' . $align : '') . '"' . $rez . '>
  271.             <img src="' . $src . '" border="0"' . ($alt ? ' alt="' . $alt . '"' : '') . '/>
  272.             ' . (trim($title) ? '<figcaption>' . $title . '</figcaption>' : '') . '
  273.         </figure>
  274.     ';
  275. }
  276.  
  277. // ---------------------------------- [/image] ---------------------------------------
  278.  
  279.  
  280.  
  281.  
  282.  
  283. // ---------------------------------- [quote] ---------------------------------------
  284.  
  285.  
  286. add_shortcode('quote', 'sc_quote');
  287.  
  288. /*
  289. [quote id="unique_id" style="1|2" cite="url"]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta[/quote]
  290. */
  291. function sc_quote($atts, $content=null){   
  292.     extract(shortcode_atts(array(
  293.         "id" => "",
  294.         "style" => "1",
  295.         "cite" => ""
  296.     ), $atts));
  297.     $cite = $cite != '' ? ' cite="' . $cite . '"' : '';
  298.     $style = min(2, max(1, $style));
  299.     return ($style == 1 ? '<blockquote' : '<q' ) . ($id ? ' id="' . $id . '"' : '') . $cite . ' class="sc_quote sc_quote_style_' . $style . '"' . '>' .($style == 1 ? '<span class="quotes icon-quote-left"></span>' : '').do_shortcode($content) . ($style == 1 ? '</blockquote>' : '</q>');
  300. }
  301.  
  302. // ---------------------------------- [/quote] ---------------------------------------
  303.  
  304.  
  305.  
  306.  
  307.  
  308. // ---------------------------------- [tooltip] ---------------------------------------
  309.  
  310.  
  311. add_shortcode('tooltip', 'sc_tooltip');
  312.  
  313. /*
  314. [tooltip id="unique_id" title="Tooltip text here"]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta[/tooltip]
  315. */
  316. function sc_tooltip($atts, $content=null){ 
  317.     extract(shortcode_atts(array(
  318.         "id" => "",
  319.         "title" => ""
  320.     ), $atts));
  321.     return '<span' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_tooltip_parent">' . do_shortcode($content) . '<span class="sc_tooltip">' . $title . '</span></span>';
  322. }
  323.  
  324. // ---------------------------------- [/tooltip] ---------------------------------------
  325.  
  326.  
  327.                        
  328.  
  329.  
  330. // ---------------------------------- [dropcaps] ---------------------------------------
  331.  
  332. add_shortcode('dropcaps', 'sc_dropcaps');
  333.  
  334. //[dropcaps id="unique_id" style="1-3"]paragraph text[/dropcaps]
  335. function sc_dropcaps($atts, $content=null){
  336.     extract(shortcode_atts(array(
  337.         "id" => "",
  338.         "style" => "1"
  339.     ), $atts));
  340.     $style = min(3, max(1, $style));
  341.     return '<div' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_dropcaps sc_dropcaps_style_' . $style . '">'
  342.         . do_shortcode('<span class="sc_dropcap">' . my_substr($content, 0, 1) . '</span>' . my_substr($content, 1))
  343.         . '</div>';
  344. }
  345. // ---------------------------------- [/dropcaps] ---------------------------------------
  346.  
  347.  
  348.  
  349. // ---------------------------------- [audio] ---------------------------------------
  350.  
  351. add_shortcode("audio", "sc_audio");
  352.                        
  353. //[audio id="unique_id" url="http://webglogic.com/audio/AirReview-Landmarks-02-ChasingCorporate.mp3" controls="0|1"]
  354. function sc_audio($atts, $content = null) {
  355.     extract(shortcode_atts(array(
  356.         "id" => "",
  357.         "controls" => "",
  358.         "url" => '#'
  359.     ), $atts));
  360.    
  361.     return '<audio' . ($id ? ' id="' . $id . '"' : '') . ' src="' . $url . '" class="sc_audio" ' . ($controls == 1 ? ' controls="controls"' : '') . ' width="100%" height="60"></audio>';
  362. }
  363.  
  364. // ---------------------------------- [/audio] ---------------------------------------
  365.                        
  366.  
  367.  
  368. // ---------------------------------- [video] ---------------------------------------
  369.  
  370. add_shortcode("video", "sc_video");
  371.  
  372. //[video id="unique_id" url="http://player.vimeo.com/video/20245032?title=0&amp;byline=0&amp;portrait=0" width="" height=""]
  373. function sc_video($atts, $content = null) {
  374.     extract(shortcode_atts(array(
  375.         "id" => "",
  376.         "url" => '#',
  377.         "width" => '612',
  378.         "height" => '344'
  379.     ), $atts));
  380.     $width = max(10, (int) $width);
  381.     $height = max(10, (int) $height);
  382.     $url = getVideoPlayerURL($url);
  383.     return '<iframe' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_video" src="' . $url . '" width="' . $width . '" height="' . $height . '" frameborder="0" webkitAllowFullScreen="webkitAllowFullScreen" mozallowfullscreen="mozallowfullscreen" allowFullScreen="allowFullScreen"></iframe>';
  384. }
  385. // ---------------------------------- [/video] ---------------------------------------
  386.  
  387.  
  388.  
  389. // ---------------------------------- [section] ---------------------------------------
  390.  
  391.  
  392. add_shortcode('section', 'sc_section');
  393.  
  394. /*
  395. [section id="unique_id" style="class_name"]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta[/section]
  396. */
  397. function sc_section($atts, $content=null){ 
  398.     extract(shortcode_atts(array(
  399.         "id" => "",
  400.         "class" => "",
  401.         "style" => ""
  402.     ), $atts));
  403.     return '
  404.         <div' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_section' . ($class ? $class : '') . '"' . ($style ?  ' style="' . $style . '"' : '') . '>
  405.             ' . do_shortcode($content) . '
  406.         </div>
  407.     ';
  408. }
  409.  
  410. // ---------------------------------- [/section] ---------------------------------------
  411.  
  412.  
  413.  
  414.  
  415. // ---------------------------------- [columns] ---------------------------------------
  416.  
  417.  
  418. add_shortcode('columns', 'sc_columns');
  419.  
  420. /*
  421. [columns id="unique_id" count="number"]
  422.     [column_item id="unique_id" span="2 - number_columns"]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta, odio arcu vut natoque dolor ut, enim etiam vut augue. Ac augue amet quis integer ut dictumst? Elit, augue vut egestas! Tristique phasellus cursus egestas a nec a! Sociis et? Augue velit natoque, amet, augue. Vel eu diam, facilisis arcu.[/column_item]
  423.     [column_item]A pulvinar ut, parturient enim porta ut sed, mus amet nunc, in. Magna eros hac montes, et velit. Odio aliquam phasellus enim platea amet. Turpis dictumst ultrices, rhoncus aenean pulvinar? Mus sed rhoncus et cras egestas, non etiam a? Montes? Ac aliquam in nec nisi amet eros! Facilisis! Scelerisque in.[/column_item]
  424.     [column_item]Duis sociis, elit odio dapibus nec, dignissim purus est magna integer eu porta sagittis ut, pid rhoncus facilisis porttitor porta, et, urna parturient mid augue a, in sit arcu augue, sit lectus, natoque montes odio, enim. Nec purus, cras tincidunt rhoncus proin lacus porttitor rhoncus, vut enim habitasse cum magna.[/column_item]
  425.     [column_item]Nec purus, cras tincidunt rhoncus proin lacus porttitor rhoncus, vut enim habitasse cum magna. Duis sociis, elit odio dapibus nec, dignissim purus est magna integer eu porta sagittis ut, pid rhoncus facilisis porttitor porta, et, urna parturient mid augue a, in sit arcu augue, sit lectus, natoque montes odio, enim.[/column_item]
  426. [/columns]
  427. */
  428. $sc_columns_counter = 0;
  429. function sc_columns($atts, $content=null){ 
  430.     extract(shortcode_atts(array(
  431.         "id" => "",
  432.         "count" => "2"
  433.     ), $atts));
  434.     global $sc_columns_counter;
  435.     $sc_columns_counter = 0;
  436.     $count = max(1, min(5, (int) $count));
  437.     return '
  438.         <div' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_columns sc_columns_count_' . $count . '">
  439.             ' . do_shortcode($content).'
  440.         </div>
  441.     ';
  442. }
  443.  
  444.  
  445. add_shortcode('column_item', 'sc_column_item');
  446.  
  447. //[column_item]
  448. function sc_column_item($atts, $content=null) {
  449.     extract(shortcode_atts( array(
  450.         "id" => "",
  451.         "span" => "1"
  452.     ), $atts));
  453.     global $sc_columns_counter;
  454.     $sc_columns_counter++;
  455.     $span = max(1, min(4, (int) $span));
  456.     return '
  457.         <div' . ($id ? ' id="' . $id . '"' : '') . ' class="content'
  458.                     . ($sc_columns_counter % 2 == 1 ? ' odd' : ' even')
  459.                     . ($sc_columns_counter == 1 ? ' first' : '')
  460.                     . ($span > 1 ? ' span_'.$span : '')
  461.                     . '">
  462.             ' . do_shortcode($content) . '
  463.         </div>
  464.     ';
  465. }
  466.  
  467. // ---------------------------------- [/columns] ---------------------------------------
  468.  
  469.  
  470.  
  471. // ---------------------------------- [list] ---------------------------------------
  472.  
  473. add_shortcode('list', 'sc_list');
  474.  
  475. /*
  476. [list id="unique_id" style="regular|check|bad|star"]
  477.     [list_item id="unique_id" title="title_of_element"]Et adipiscing integer.[/list_item]
  478.     [list_item]A pulvinar ut, parturient enim porta ut sed, mus amet nunc, in.[/list_item]
  479.     [list_item]Duis sociis, elit odio dapibus nec, dignissim purus est magna integer.[/list_item]
  480.     [list_item]Nec purus, cras tincidunt rhoncus proin lacus porttitor rhoncus.[/list_item]
  481. [/list]
  482. */
  483. $sc_list_counter = 0;
  484. function sc_list($atts, $content=null){
  485.     extract(shortcode_atts(array(
  486.         "id" => "",
  487.         "style" => "regular"
  488.     ), $atts));
  489.     global $sc_list_counter;
  490.     $sc_list_counter = 0;
  491.     if (trim($style) == '') $style = 'regular';
  492.     return '
  493.         <ul' . ($id ? ' id="' . $id . '"' : '') . ($style!='' && $style!='default' ? ' class="sc_list sc_list_style_' . $style . '"' : ''). '>
  494.             ' . do_shortcode($content) . '
  495.         </ul>
  496.         ';
  497. }
  498.  
  499.  
  500. add_shortcode('list_item', 'sc_list_item');
  501.  
  502. //[list_item]
  503. function sc_list_item($atts, $content=null) {
  504.     extract(shortcode_atts( array(
  505.         "id" => "",
  506.         "title" => ""
  507.     ), $atts));
  508.     global $sc_list_counter;
  509.     $sc_list_counter++;
  510.     return '
  511.         <li' . ($id ? ' id="' . $id . '"' : '') . ' class="item' . ($sc_list_counter % 2 == 1 ? ' odd' : ' even') . ($sc_list_counter == 1 ? ' first' : '') . '"' . ($title ? ' title="' . $title . '"' : '') . '><span class="bullet"></span>
  512.             ' . do_shortcode($content)
  513.             . '
  514.         </li>
  515.     ';
  516. }
  517.  
  518. // ---------------------------------- [/list] ---------------------------------------
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527. // ---------------------------------- [tabs] ---------------------------------------
  528.  
  529. add_shortcode("tabs", "sc_tabs");
  530.  
  531. /*
  532. [tabs id="unique_id" tab_names="Planning|Development|Support" style="1|2" initial="1 - num_tabs"]
  533.     [tab]Randomised words which don't look even slightly believable. If you are going to use a passage. You need to be sure there isn't anything embarrassing hidden in the middle of text established fact that a reader will be istracted by the readable content of a page when looking at its layout.[/tab]
  534.     [tab]Fact reader will be distracted by the <a href="#" class="main_link">readable content</a> of a page when. Looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using content here, content here, making it look like readable English will uncover many web sites still in their infancy. Various versions have evolved over. There are many variations of passages of Lorem Ipsum available, but the majority.[/tab]
  535.     [tab]Distracted by the  readable content  of a page when. Looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using content here, content here, making it look like readable English will uncover many web sites still in their infancy. Various versions have  evolved over.  There are many variations of passages of Lorem Ipsum available.[/tab]
  536. [/tabs]
  537. */
  538. $sc_tab_counter = 0;
  539. function sc_tabs($atts, $content = null) {
  540.     extract(shortcode_atts(array(
  541.         "id" => "",
  542.         "tab_names" => "",
  543.         "style" => "1",
  544.         "initial" => "1"
  545.     ), $atts));
  546.  
  547.     global $sc_tab_counter;
  548.     $sc_tab_counter = 0;
  549.     $title_chunks = explode("|", $tab_names);
  550.     $style = max(1, min(2, (int) $style));
  551.     $initial = max(1, min(count($title_chunks), (int) $initial));
  552.    
  553.     $tabs_output = '
  554.         <div' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_tabs sc_tabs_style_' . $style . '">
  555.             <ul class="tab_names">';
  556.  
  557.     $titles_output = '';
  558.     for ($i = 0; $i < count($title_chunks); $i++) {
  559.         $classes = array('tab_name');
  560.         if ($i == 0) $classes[] = 'first';
  561.         else if ($i == count($title_chunks) - 1) $classes[] = 'last';
  562.         $class_str = join(' ', $classes);
  563.         $titles_output .= '
  564.                 <li' . ($class_str ? ' class="' . $class_str . '"' : '') . '><a href="#">' . $title_chunks[$i] . '</a></li>';
  565.     }
  566.  
  567.     $tabs_output .= $titles_output.'
  568.             </ul>
  569.             ' . do_shortcode($content) . '
  570.             <script type="text/javascript">
  571.                 jQuery(document).ready(function() {
  572.                     jQuery(\'div' . ($id ? '#' . $id : '') . '.sc_tabs_style_' . $style. '\').tabs(\'div.content\',
  573.                         {
  574.                             tabs: \'li.tab_name > a\',
  575.                             initialIndex : ' . ($initial - 1) . '
  576.                         }
  577.                     );
  578.                 });
  579.             </script>
  580.         </div>
  581.     ';
  582.     return $tabs_output;
  583. }
  584.  
  585.  
  586. add_shortcode("tab", "sc_tab");
  587.  
  588. //[tab id="tab_id"]
  589. function sc_tab($atts, $content = null) {
  590.     extract(shortcode_atts(array(
  591.         "id" => ""
  592.     ), $atts));
  593.     global $sc_tab_counter;
  594.     $sc_tab_counter++;
  595.     return '
  596.             <div' . ($id ? ' id="' . $id . '"' : '') . ' class="content' . ($sc_tab_counter % 2 == 1 ? ' odd' : ' even') . ($sc_tab_counter == 1 ? ' first' : '') . '">
  597.                 ' . do_shortcode($content) . '
  598.             </div>
  599.     ';
  600. }
  601.  
  602. // ---------------------------------- [/tabs] ---------------------------------------
  603.  
  604.  
  605.  
  606. // ---------------------------------- [accordion] ---------------------------------------
  607.  
  608.  
  609. add_shortcode('accordion', 'sc_accordion');
  610.  
  611. /*
  612. [accordion id="unique_id" style="1|2" initial="1 - num_elements"]
  613.     [accordion_item title="Et adipiscing integer, scelerisque pid"]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta, odio arcu vut natoque dolor ut, enim etiam vut augue. Ac augue amet quis integer ut dictumst? Elit, augue vut egestas! Tristique phasellus cursus egestas a nec a! Sociis et? Augue velit natoque, amet, augue. Vel eu diam, facilisis arcu.[/accordion_item]
  614.     [accordion_item title="A pulvinar ut, parturient enim porta ut sed"]A pulvinar ut, parturient enim porta ut sed, mus amet nunc, in. Magna eros hac montes, et velit. Odio aliquam phasellus enim platea amet. Turpis dictumst ultrices, rhoncus aenean pulvinar? Mus sed rhoncus et cras egestas, non etiam a? Montes? Ac aliquam in nec nisi amet eros! Facilisis! Scelerisque in.[/accordion_item]
  615.     [accordion_item title="Duis sociis, elit odio dapibus nec"]Duis sociis, elit odio dapibus nec, dignissim purus est magna integer eu porta sagittis ut, pid rhoncus facilisis porttitor porta, et, urna parturient mid augue a, in sit arcu augue, sit lectus, natoque montes odio, enim. Nec purus, cras tincidunt rhoncus proin lacus porttitor rhoncus, vut enim habitasse cum magna.[/accordion_item]
  616.     [accordion_item title="Nec purus, cras tincidunt rhoncus"]Nec purus, cras tincidunt rhoncus proin lacus porttitor rhoncus, vut enim habitasse cum magna. Duis sociis, elit odio dapibus nec, dignissim purus est magna integer eu porta sagittis ut, pid rhoncus facilisis porttitor porta, et, urna parturient mid augue a, in sit arcu augue, sit lectus, natoque montes odio, enim.[/accordion_item]
  617. [/accordion]
  618. */
  619. $sc_accordion_counter = 0;
  620. function sc_accordion($atts, $content=null){   
  621.     extract(shortcode_atts(array(
  622.         "id" => "",
  623.         "style" => "1",
  624.         "initial" => "1"
  625.     ), $atts));
  626.     global $sc_accordion_counter;
  627.     $sc_accordion_counter = 0;
  628.     $style = max(1, min(2, (int) $style));
  629.     $initial = max(1, (int) $initial);
  630.     return '
  631.         <div' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_accordion sc_accordion_style_' . $style . '" >
  632.             ' . do_shortcode($content) . '
  633.         </div>
  634.         <script type="text/javascript">
  635.             jQuery(document).ready(function() {
  636.                 jQuery(\'div' . ($id ? '#' . $id : '') . '.sc_accordion_style_' . $style . '\').tabs(\'div.item > div.content\', {
  637.                     tabs: \'h5.title > a\',
  638.                     effect : \'slide\',
  639.                     currentClose: true
  640.                     ' . ($initial!='' ? ', initialIndex : ' . ($initial-1) : '') . '
  641.                 });
  642.             });
  643.         </script>      
  644.     ';
  645. }
  646.  
  647.  
  648. add_shortcode('accordion_item', 'sc_accordion_item');
  649.  
  650. //[accordion_item]
  651. function sc_accordion_item($atts, $content=null) {
  652.     extract(shortcode_atts( array(
  653.         "id" => "",
  654.         "title" => ""
  655.     ), $atts));
  656.     global $sc_accordion_counter;
  657.     $sc_accordion_counter++;
  658.     return '
  659.         <div' . ($id ? ' id="' . $id . '"' : '') . ' class="item' . ($sc_accordion_counter % 2 == 1 ? ' odd' : ' even') . ($sc_accordion_counter == 1 ? ' first' : '') . '">
  660.             <h5 class="title"><a href="#"><span class="button"></span>' . $title . '</a></h5>
  661.             <div class="content">
  662.                 ' . do_shortcode($content) . '
  663.             </div>
  664.         </div>
  665.     ';
  666. }
  667.  
  668. // ---------------------------------- [/accordion] ---------------------------------------
  669.  
  670.  
  671.  
  672. // ---------------------------------- [toggles] ---------------------------------------
  673.  
  674.  
  675. add_shortcode('toggles', 'sc_toggles');
  676.  
  677. /*
  678. [toggles id="unique_id" initial="1 - num_elements"]
  679.     [toggles_item title="Et adipiscing integer, scelerisque pid"]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta, odio arcu vut natoque dolor ut, enim etiam vut augue. Ac augue amet quis integer ut dictumst? Elit, augue vut egestas! Tristique phasellus cursus egestas a nec a! Sociis et? Augue velit natoque, amet, augue. Vel eu diam, facilisis arcu.[/toggles_item]
  680.     [toggles_item title="A pulvinar ut, parturient enim porta ut sed"]A pulvinar ut, parturient enim porta ut sed, mus amet nunc, in. Magna eros hac montes, et velit. Odio aliquam phasellus enim platea amet. Turpis dictumst ultrices, rhoncus aenean pulvinar? Mus sed rhoncus et cras egestas, non etiam a? Montes? Ac aliquam in nec nisi amet eros! Facilisis! Scelerisque in.[/toggles_item]
  681.     [toggles_item title="Duis sociis, elit odio dapibus nec"]Duis sociis, elit odio dapibus nec, dignissim purus est magna integer eu porta sagittis ut, pid rhoncus facilisis porttitor porta, et, urna parturient mid augue a, in sit arcu augue, sit lectus, natoque montes odio, enim. Nec purus, cras tincidunt rhoncus proin lacus porttitor rhoncus, vut enim habitasse cum magna.[/toggles_item]
  682.     [toggles_item title="Nec purus, cras tincidunt rhoncus"]Nec purus, cras tincidunt rhoncus proin lacus porttitor rhoncus, vut enim habitasse cum magna. Duis sociis, elit odio dapibus nec, dignissim purus est magna integer eu porta sagittis ut, pid rhoncus facilisis porttitor porta, et, urna parturient mid augue a, in sit arcu augue, sit lectus, natoque montes odio, enim.[/toggles_item]
  683. [/toggles]
  684. */
  685. $sc_toggle_counter = 0;
  686. function sc_toggles($atts, $content=null){ 
  687.     extract(shortcode_atts(array(
  688.         "id" => "",
  689.         "initial" => ""
  690.     ), $atts));
  691.     global $sc_toggle_counter;
  692.     $sc_toggle_counter = 0;
  693.     $initial = max(1, (int) $initial);
  694.     return '
  695.         <div' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_toggles">
  696.             '
  697.             . do_shortcode($content)
  698.             . '
  699.         </div>
  700.         <script type="text/javascript">
  701.             jQuery(document).ready(function() {
  702.                 jQuery(\'div' . ($id ? '#' . $id : '') . '.sc_toggles\').tabs(\'div.item > div.content\', {
  703.                     tabs: \'h5.title > a\',
  704.                     effect : \'slide\',
  705.                     currentClose: true,
  706.                     anotherClose: false
  707.                     ' . ($initial!='' ? ', initialIndex : ' . ($initial-1) : '') . '
  708.                 });
  709.             });
  710.         </script>      
  711.     ';
  712. }
  713.  
  714.  
  715. add_shortcode('toggles_item', 'sc_toggles_item');
  716.  
  717. //[toggles_item]
  718. function sc_toggles_item($atts, $content=null) {
  719.     extract(shortcode_atts( array(
  720.         "id" => "",
  721.         "title" => ""
  722.     ), $atts));
  723.     global $sc_toggle_counter;
  724.     $sc_toggle_counter++;
  725.     return '
  726.         <div' . ($id ? ' id="' . $id . '"' : '') . ' class="item' . ($sc_toggle_counter % 2 == 1 ? ' odd' : ' even') . ($sc_toggle_counter == 1 ? ' first' : '') . '">
  727.             <h5 class="title"><a href="#"><span class="button"></span>' . $title . '</a></h5>
  728.             <div class="content">
  729.                 ' . do_shortcode($content) . '
  730.             </div>
  731.         </div>
  732.     ';
  733. }
  734.  
  735. // ---------------------------------- [/toggles] ---------------------------------------
  736.  
  737.  
  738.  
  739. // ---------------------------------- [table] ---------------------------------------
  740.  
  741.  
  742. add_shortcode('table', 'sc_table');
  743.  
  744. /*
  745. [table id="unique_id" style="regular"]
  746. Table content, generated on one of many public internet resources, for example: http://www.impressivewebs.com/html-table-code-generator/
  747. [/table]
  748. */
  749. function sc_table($atts, $content=null){   
  750.     extract(shortcode_atts(array(
  751.         "id" => "",
  752.         "style" => "regular"
  753.     ), $atts));
  754.     $content = str_replace(
  755.                 array('<p><table', 'table></p>', '><br />'),
  756.                 array('<table', 'table>', '>'),
  757.                 html_entity_decode($content, ENT_COMPAT, 'UTF-8'));
  758.     return '
  759.         <div' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_table sc_table_style_' . $style . '">
  760.             ' . do_shortcode($content) . '
  761.         </div>
  762.     ';
  763. }
  764.  
  765. // ---------------------------------- [/table] ---------------------------------------
  766.  
  767.  
  768.  
  769. // ---------------------------------- [Google maps] ---------------------------------------
  770.  
  771. add_shortcode("googlemap", "sc_google_map");
  772.  
  773. //[googlemap id="unique_id" address="your_address" width="width_in_pixels_or_percent" height="height_in_pixels"]
  774. function sc_google_map($atts, $content = null) {
  775.     extract(shortcode_atts(array(
  776.         "id" => "sc_googlemap",
  777.         "width" => "100%",
  778.         "height" => "170",
  779.         "address" => ""
  780.     ), $atts));
  781.  
  782.     $ed = my_substr($width, -1)=='%' ? '%' : 'px';
  783.     if ((int) $width < 100 && $ed != '%') $width='100%';
  784.     if ((int) $height < 50) $height='100';
  785.     $width = (int) str_replace('%', '', $width);
  786.     $w = $width >= 0 ? 'width:' . $width . $ed . ';' : '';
  787.     $h = $height >= 0 ? 'height:' . $height . 'px;' : '';
  788.     $rez = $w . $h;
  789.     $rez = $rez ? ' style="' . $rez . '"' : '';
  790.     $api_key = get_theme_option('google_api');
  791.     $prot = is_ssl()? 'https' : 'http';
  792.     wp_enqueue_script( 'googlemap', $prot.'://maps.google.com/maps/api/js'.($api_key ? '?key='.$api_key : ''), array(), null, true );  
  793.     wp_enqueue_script( 'googlemap_init', get_template_directory_uri().'/js/googlemap_init.js', array(), '1.0.0', true );
  794.     return '
  795.         <script type="text/javascript">
  796.             jQuery(document).ready(function(){
  797.                 googlemap_init(jQuery("#' . $id . '").get(0), "' . $address . '");
  798.             });
  799.         </script>
  800.         <div id="' . $id . '"' . $rez . ' class="sc_googlemap"></div>
  801.     ';
  802. }
  803. // ---------------------------------- [/Google maps] ---------------------------------------
  804.  
  805.  
  806.  
  807.  
  808.  
  809. // ---------------------------------- [Contact form] ---------------------------------------
  810.  
  811. add_shortcode("contact_form", "sc_contact_form");
  812.  
  813. //[contact_form id="unique_id" title="Contact Form" description="Mauris aliquam habitasse magna a arcu eu mus sociis? Enim nunc? Integer facilisis, et eu dictumst, adipiscing tempor ultricies, lundium urna lacus quis."]
  814. function sc_contact_form($atts, $content = null) {
  815.     extract(shortcode_atts(array(
  816.         "id" => "",
  817.         "title" => "Contact Form",
  818.         "description" => ""
  819.     ), $atts));
  820.     global $ajax_nonce, $ajax_url;
  821.     return '
  822.             <div ' . ($id ? ' id="' . $id . '"' : '') . 'class="sc_contact_form">
  823.                 '
  824.                 . ($title ? '<h3 class="title">' . $title . '</h3>' : '')
  825.                 . ($description ? '<span class="description">' . $description . '</span>' : '')
  826.                 .
  827.                 '
  828.                 <form' . ($id ? ' id="' . $id . '"' : '') . ' method="post" action="' . $ajax_url . '">
  829.                     <div class="field">
  830.                         <label for="sc_contact_form_username" class="required">' . __('Name', 'wpspace') . '</label>
  831.                         <input type="text" id="sc_contact_form_username" name="username">
  832.                    </div>
  833.                     <div class="field">
  834.                         <label for="sc_contact_form_email" class="required">' . __('Email', 'wpspace') . '</label>
  835.                         <input type="text" id="sc_contact_form_email" name="email">
  836.                    </div>
  837.                     <div class="field message">
  838.                         <label for="sc_contact_form_message" class="required">' . __('Your Message', 'wpspace') . '</label>
  839.                         <textarea id="sc_contact_form_message" name="message"></textarea>
  840.                    </div>
  841.                     <div class="button">
  842.                         <a href="#" class="enter"><span>' . __('Submit', 'wpspace') . '</span></a>
  843.                    </div>
  844.                 </form>
  845.                 <div class="result sc_infobox"></div>
  846.                 <script type="text/javascript">
  847.                     jQuery(document).ready(function() {
  848.                         jQuery(".sc_contact_form .enter").click(function(e){
  849.                             userSubmitForm();
  850.                             e.preventDefault();
  851.                             return false;
  852.                         });
  853.                     });
  854.                     function userSubmitForm(){
  855.                        
  856.                         var error = formValidate(jQuery(".sc_contact_form form"), {
  857.                             error_message_show: true,
  858.                             error_message_time: 5000,
  859.                             error_message_class: "sc_infobox sc_infobox_style_error",
  860.                             error_fields_class: "error_fields_class",
  861.                             exit_after_first_error: false,
  862.                             rules: [
  863.                                 {
  864.                                     field: "username",
  865.                                     min_length: { value: 1,  message: empt },
  866.                                     max_length: { value: 160, message: to_lng}
  867.                                 },
  868.                                 {
  869.                                     field: "email",
  870.                                     min_length: { value: 7,  message: empt_mail },
  871.                                     max_length: { value: 60, message: to_lng_mail},
  872.                                     mask: { value: "^([a-zA-Z0-9_\\-]+\\\.)*[a-zA-Z0-9_\\\-]+@[a-zA-Z0-9_\\-]+(\\\.[a-zA-Z0-9_\\-]+)*\\\.[a-zA-Z]{2,6}$", message: incor}
  873.                                 },
  874.                                 {
  875.                                     field: "message",
  876.                                     min_length: { value: 1,  message: mes_empt },
  877.                                     max_length: { value: 1600, message: to_lng_mes}
  878.                                 }
  879.                             ]
  880.                         });
  881.                         if (!error) {
  882.                             var user_name  = jQuery(".sc_contact_form #sc_contact_form_username").val();
  883.                             var user_email = jQuery(".sc_contact_form #sc_contact_form_email").val();
  884.                             var user_site  = jQuery(".sc_contact_form #sc_contact_form_site").val();
  885.                             var user_msg   = jQuery(".sc_contact_form #sc_contact_form_message").val();
  886.                             var data = {
  887.                                 action: "submit_contact_form",
  888.                                 nonce: "' . $ajax_nonce . '",
  889.                                 user_name: user_name,
  890.                                 user_email: user_email,
  891.                                 user_site: user_site,
  892.                                 user_msg: user_msg
  893.                             };
  894.                             jQuery.post("' . $ajax_url . '", data, userSubmitFormResponse, "text");
  895.                         }
  896.                     }
  897.                    
  898.                     function userSubmitFormResponse(response) {
  899.                         var rez = JSON.parse(response);
  900.                         jQuery(".sc_contact_form .result")
  901.                             .toggleClass("sc_infobox_style_error", false)
  902.                             .toggleClass("sc_infobox_style_success", false);
  903.                         if (rez.error == "") {
  904.                             jQuery(".sc_contact_form .result").addClass("sc_infobox_style_success").html("' . __('Your message has been sent.', 'wpspace') . '");
  905.                             setTimeout("jQuery(\'.sc_contact_form .result\').fadeOut(); jQuery(\'.sc_contact_form form\').get(0).reset();", 3000);
  906.                         } else {
  907.                             jQuery(".sc_contact_form .result").addClass("sc_infobox_style_error").html("' . __('Transmit failed!', 'wpspace').' " + rez.error);
  908.                         }
  909.                         jQuery(".sc_contact_form .result").fadeIn();
  910.                     }
  911.                 </script>
  912.             </div>
  913.     ';
  914. }
  915.  
  916.  
  917.  
  918. // Submit contact form
  919. add_action('wp_ajax_submit_contact_form', 'submit_contact_form_callback');
  920. add_action('wp_ajax_nopriv_submit_contact_form', 'submit_contact_form_callback');
  921.  
  922. function submit_contact_form_callback() {
  923.     global $_REQUEST;
  924.  
  925.     if ( !wp_verify_nonce( $_REQUEST['nonce'], 'ajax_nonce' ) )
  926.         die();
  927.  
  928.     $response = array('error'=>'');
  929.  
  930.     $user_name = my_substr($_REQUEST['user_name'], 0, 20);
  931.     $user_email = my_substr($_REQUEST['user_email'], 0, 40);
  932.     $user_msg = getShortString($_REQUEST['user_msg'], 1000);
  933.    
  934.     if (!($contact_email = get_theme_option('user_contact_email')))
  935.         $contact_email = get_theme_option('user_email');   
  936.    
  937.     if (trim($contact_email)!='') {
  938.         $subj = sprintf(__('Site %s - Contact form message from %s', 'wpspace'), get_bloginfo('site_name'), $user_name);
  939.         $msg = "
  940. Name: $user_name
  941. E-mail: $user_email
  942.  
  943. Message: $user_msg
  944.  
  945. ............ " . get_bloginfo('site_name') . " (" . home_url() . ") ............";
  946.    
  947.         $head = "Content-Type: text/plain; charset=\"utf-8\"\n"
  948.         . "X-Mailer: PHP/" . phpversion() . "\n"
  949.         . "Reply-To: $user_email\n"
  950.         . "To: $contact_email\n"
  951.         . "From: $user_name<". $user_email . ">\n"
  952.         . "Subject: $subj\n";
  953.        
  954.         $mail = get_theme_option('mail_function');
  955.         if (!@$mail($contact_email, $subj, $msg, $head)) {
  956.             $response['error'] = 'Error send message!';
  957.         }
  958.     } else
  959.             $response['error'] = 'Error send message!';
  960.  
  961.     echo json_encode($response);
  962.     die();
  963. }
  964. // ---------------------------------- [/Contact form] ---------------------------------------
  965.  
  966.  
  967.  
  968. // ---------------------------------- [hide] ---------------------------------------
  969.  
  970.  
  971. add_shortcode('hide', 'sc_hide');
  972.  
  973. /*
  974. [hide selector="unique_id"]
  975. */
  976. function sc_hide($atts, $content=null){
  977.     extract(shortcode_atts(array(
  978.         "selector" => ""
  979.     ), $atts));
  980.     $selector = trim(chop($selector));
  981.     return $selector == '' ? '' : '
  982.         <script type="text/javascript">
  983.             jQuery(document).ready(function() {
  984.                 jQuery("' . $selector . '").hide();
  985.             });
  986.         </script>      
  987.     ';
  988. }
  989. // ---------------------------------- [/hide] ---------------------------------------
  990. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement