PageRenderTime 55ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/Lotus/plugins/shortcode_generator.php

https://bitbucket.org/glix/familydentistry
PHP | 486 lines | 419 code | 60 blank | 7 comment | 14 complexity | 6e79466b82130f9ffa8e480c5873d4e4 MD5 | raw file
  1. <?php
  2. /*
  3. Begin Create Shortcode Generator Options
  4. */
  5. add_action('admin_menu', 'pp_shortcode_generator');
  6. function pp_shortcode_generator() {
  7. add_submenu_page('functions.php', 'Shortcode Generator', 'Shortcode Generator', 'manage_options', 'pp_shortcode_generator', 'pp_shortcode_generator_options');
  8. }
  9. function pp_shortcode_generator_options() {
  10. if (!current_user_can('manage_options')) {
  11. wp_die( __('You do not have sufficient permissions to access this page.') );
  12. }
  13. $plugin_url = get_bloginfo( 'stylesheet_directory' ).'/plugins/shortcode_generator';
  14. //Begin shortcode array
  15. $shortcodes = array(
  16. 'dropcap' => array(
  17. 'attr' => array(),
  18. 'desc' => array(),
  19. 'content' => TRUE,
  20. ),
  21. 'quote' => array(
  22. 'attr' => array(),
  23. 'desc' => array(),
  24. 'content' => TRUE,
  25. ),
  26. 'button' => array(
  27. 'attr' => array(
  28. 'href' => 'text',
  29. 'align' => 'select',
  30. 'bg_color' => 'text',
  31. 'text_color' => 'text',
  32. ),
  33. 'desc' => array(
  34. 'href' => 'Enter URL for button',
  35. 'align' => 'Button Alignment',
  36. 'bg_color' => 'Enter background color code ex. #000000',
  37. 'text_color' => 'Enter text color code ex. #ffffff',
  38. ),
  39. 'options' => array(
  40. 'left' => 'left',
  41. 'right' => 'right',
  42. 'center' => 'center',
  43. ),
  44. 'content' => TRUE,
  45. 'content_text' => 'Enter text on button',
  46. ),
  47. 'lightbox' => array(
  48. 'attr' => array(
  49. 'type' => 'select',
  50. 'title' => 'text',
  51. 'href' => 'text',
  52. 'youtube_id' => 'text',
  53. 'vimeo_id' => 'text',
  54. ),
  55. 'desc' => array(
  56. 'href' => 'Enter URL for button',
  57. 'align' => 'Button Alignment',
  58. 'bg_color' => 'Enter background color code ex. #000000',
  59. 'text_color' => 'Enter text color code ex. #ffffff',
  60. ),
  61. 'options' => array(
  62. 'image' => 'Image',
  63. 'iframe' => 'iFrame',
  64. 'youtube' => 'Youtube Video',
  65. 'vimeo' => 'Vimeo Video',
  66. ),
  67. 'content' => TRUE,
  68. 'content_text' => 'Enter content (can be normal text, HTML code or shortcode)',
  69. ),
  70. 'frame_left' => array(
  71. 'attr' => array(
  72. 'src' => 'text',
  73. 'href' => 'text',
  74. ),
  75. 'desc' => array(
  76. 'src' => 'Enter image URL',
  77. 'href' => 'Enter hyperlink URL for image',
  78. ),
  79. 'content' => TRUE,
  80. 'content_text' => 'Image Caption',
  81. ),
  82. 'frame_right' => array(
  83. 'attr' => array(
  84. 'src' => 'text',
  85. 'href' => 'text',
  86. ),
  87. 'desc' => array(
  88. 'src' => 'Enter image URL',
  89. 'href' => 'Enter hyperlink URL for image',
  90. ),
  91. 'content' => TRUE,
  92. 'content_text' => 'Image Caption',
  93. ),
  94. 'frame_center' => array(
  95. 'attr' => array(
  96. 'src' => 'text',
  97. 'href' => 'text',
  98. ),
  99. 'desc' => array(
  100. 'src' => 'Enter image URL',
  101. 'href' => 'Enter hyperlink URL for image',
  102. ),
  103. 'content' => TRUE,
  104. 'content_text' => 'Image Caption',
  105. ),
  106. 'one_half' => array(
  107. 'attr' => array(),
  108. 'desc' => array(),
  109. 'content' => TRUE,
  110. 'repeat' => 1,
  111. ),
  112. 'one_third' => array(
  113. 'attr' => array(),
  114. 'desc' => array(),
  115. 'content' => TRUE,
  116. 'repeat' => 2,
  117. ),
  118. 'one_fourth' => array(
  119. 'attr' => array(),
  120. 'desc' => array(),
  121. 'content' => TRUE,
  122. 'repeat' => 3,
  123. ),
  124. 'styled_box' => array(
  125. 'attr' => array(
  126. 'title' => 'text',
  127. 'color' => 'select',
  128. ),
  129. 'desc' => array(
  130. 'href' => 'Enter URL for button',
  131. 'color' => 'Select box color',
  132. ),
  133. 'options' => array(
  134. 'black' => 'Black',
  135. 'gray' => 'Gray',
  136. 'white' => 'White',
  137. 'blue' => 'Blue',
  138. 'yellow' => 'Yellow',
  139. 'red' => 'Red',
  140. 'orange' => 'Orange',
  141. 'green' => 'Green',
  142. 'pink' => 'Pink',
  143. 'purple' => 'Purple',
  144. ),
  145. 'content' => TRUE,
  146. 'content_text' => 'Enter Content',
  147. ),
  148. 'pp_gallery' => array(
  149. 'attr' => array(),
  150. 'desc' => array(),
  151. 'content' => TRUE,
  152. 'content_text' => htmlentities('Your Images (line by line) ex. <a href="image.jpg"><img src="image_small.jpg"/></a>'),
  153. ),
  154. 'map' => array(
  155. 'attr' => array(
  156. 'width' => 'text',
  157. 'height' => 'text',
  158. 'lat' => 'text',
  159. 'long' => 'text',
  160. 'zoom' => 'text',
  161. ),
  162. 'desc' => array(
  163. 'width' => 'Map width in pixels',
  164. 'height' => 'Map height in pixels',
  165. 'lat' => 'Map latitude <a href="http://www.tech-recipes.com/rx/5519/the-easy-way-to-find-latitude-and-longitude-values-in-google-maps/">Find here</a>',
  166. 'long' => 'Map longitude <a href="http://www.tech-recipes.com/rx/5519/the-easy-way-to-find-latitude-and-longitude-values-in-google-maps/">Find here</a>',
  167. 'zoom' => 'Enter zoom number (1-16)',
  168. ),
  169. 'content' => FALSE,
  170. 'options' => array(
  171. 1 => 'Open',
  172. 0 => 'Close',
  173. ),
  174. ),
  175. 'youtube' => array(
  176. 'attr' => array(
  177. 'width' => 'text',
  178. 'height' => 'text',
  179. 'video_id' => 'text',
  180. ),
  181. 'desc' => array(
  182. 'width' => 'Video width in pixels',
  183. 'height' => 'Video height in pixels',
  184. 'video_id' => 'Youtube video ID something like Js9Z8UQAA4E',
  185. ),
  186. 'content' => FALSE,
  187. ),
  188. 'vimeo' => array(
  189. 'attr' => array(
  190. 'width' => 'text',
  191. 'height' => 'text',
  192. 'video_id' => 'text',
  193. ),
  194. 'desc' => array(
  195. 'width' => 'Video width in pixels',
  196. 'height' => 'Video height in pixels',
  197. 'video_id' => 'Vimeo video ID something like 9380243',
  198. ),
  199. 'content' => FALSE,
  200. ),
  201. 'html5video' => array(
  202. 'attr' => array(
  203. 'width' => 'text',
  204. 'height' => 'text',
  205. 'poster' => 'text',
  206. 'mp4' => 'text',
  207. 'webm' => 'text',
  208. 'ogg' => 'text',
  209. ),
  210. 'desc' => array(
  211. 'width' => 'Video width in pixels',
  212. 'height' => 'Video height in pixels',
  213. 'poster' => 'Poster image for video',
  214. 'mp4' => 'Video URL in mp4 format',
  215. 'webm' => 'Video URL in mp4 webm',
  216. 'ogg' => 'Video URL in mp4 ogg',
  217. ),
  218. 'content' => FALSE,
  219. ),
  220. 'slideshow' => array(
  221. 'attr' => array(
  222. 'width' => 'text',
  223. 'height' => 'text',
  224. ),
  225. 'desc' => array(
  226. 'width' => 'Slideshow width in pixels',
  227. 'height' => 'Slideshow height in pixels',
  228. ),
  229. 'content' => TRUE,
  230. 'content_text' => htmlentities('Your Images URL (line by line) ex. /example/photo1.jpg'),
  231. ),
  232. 'nivoslide' => array(
  233. 'attr' => array(
  234. 'width' => 'text',
  235. 'height' => 'text',
  236. 'effect' => 'select',
  237. 'pauseTime' => 'text',
  238. ),
  239. 'options' => array(
  240. 'sliceDown' => 'sliceDown',
  241. 'sliceDownLeft' => 'sliceDownLeft',
  242. 'sliceUp' => 'sliceUp',
  243. 'sliceUpLeft' => 'sliceUpLeft',
  244. 'sliceUpDown' => 'sliceUpDown',
  245. 'sliceUpDownLeft' => 'sliceUpDownLeft',
  246. 'fold' => 'fold',
  247. 'fade' => 'fade',
  248. 'random' => 'random',
  249. ),
  250. 'desc' => array(
  251. 'width' => 'Slideshow width in pixels',
  252. 'height' => 'Slideshow height in pixels',
  253. 'effect' => 'The effect parameter can be any of the following',
  254. 'pauseTime' => 'Enter pause time for each slide (in seconds)',
  255. ),
  256. 'content' => TRUE,
  257. 'content_text' => htmlentities('Your Images URL (line by line) ex. /example/photo1.jpg'),
  258. ),
  259. );
  260. ?>
  261. <script>
  262. jQuery(document).ready(function(){
  263. jQuery('#shortcode_select').change(function() {
  264. var target = jQuery(this).val();
  265. jQuery('.rm_section').css('display', 'none');
  266. jQuery('#div_'+target).css('display', '');
  267. });
  268. jQuery('.code_area').click(function() {
  269. document.getElementById(jQuery(this).attr('id')).focus();
  270. document.getElementById(jQuery(this).attr('id')).select();
  271. });
  272. jQuery('.button').click(function() {
  273. var target = jQuery(this).attr('id');
  274. var gen_shortcode = '';
  275. gen_shortcode+= '['+target;
  276. if(jQuery('#'+target+'_attr_wrapper .attr').length > 0)
  277. {
  278. jQuery('#'+target+'_attr_wrapper .attr').each(function() {
  279. gen_shortcode+= ' '+jQuery(this).attr('name')+'="'+jQuery(this).val()+'"';
  280. });
  281. }
  282. gen_shortcode+= ']\n';
  283. if(jQuery('#'+target+'_content').length > 0)
  284. {
  285. gen_shortcode+= jQuery('#'+target+'_content').val()+'\n[/'+target+']\n';
  286. var repeat = jQuery('#'+target+'_content_repeat').val();
  287. for (count=1;count<=repeat;count=count+1)
  288. {
  289. if(count<repeat)
  290. {
  291. gen_shortcode+= '['+target+']\n';
  292. gen_shortcode+= jQuery('#'+target+'_content').val()+'\n[/'+target+']\n';
  293. }
  294. else
  295. {
  296. gen_shortcode+= '['+target+'_last]\n';
  297. gen_shortcode+= jQuery('#'+target+'_content').val()+'\n[/'+target+'_last]';
  298. }
  299. }
  300. }
  301. jQuery('#'+target+'_code').val(gen_shortcode);
  302. });
  303. });
  304. </script>
  305. <div class="wrap rm_wrap">
  306. <div class="header_wrap">
  307. <h2>Shortcode Generator</h2>
  308. For future updates follow me <a href="http://themeforest.net/user/peerapong">@themeforest</a> or <a href="http://twitter.com/ipeerapong">@twitter</a>
  309. </div><br/>
  310. <div style="padding:30px 20px 30px 20px;background:#fff">
  311. <?php
  312. if(!empty($shortcodes))
  313. {
  314. ?>
  315. <strong>Select Shortcode:</strong>
  316. <select id="shortcode_select">
  317. <option value="">---Select---</option>
  318. <?php
  319. foreach($shortcodes as $shortcode_name => $shortcode)
  320. {
  321. ?>
  322. <option value="<?php echo $shortcode_name; ?>"><?php echo $shortcode_name; ?></option>
  323. <?php
  324. }
  325. ?>
  326. </select>
  327. <?php
  328. }
  329. ?>
  330. <br/><br/>
  331. <?php
  332. if(!empty($shortcodes))
  333. {
  334. foreach($shortcodes as $shortcode_name => $shortcode)
  335. {
  336. ?>
  337. <div id="div_<?php echo $shortcode_name; ?>" class="rm_section" style="display:none">
  338. <div class="rm_title">
  339. <h3 style="margin-left:15px"><?php echo ucfirst($shortcode_name); ?></h3>
  340. <div class="clearfix"></div>
  341. </div>
  342. <div class="rm_input rm_text" style="padding-left:20px">
  343. <!-- img src="<?php echo $plugin_url.'/'.$shortcode_name.'.png'; ?>" alt=""/><br/><br/><br/ -->
  344. <?php
  345. if(isset($shortcode['content']) && $shortcode['content'])
  346. {
  347. if(isset($shortcode['content_text']))
  348. {
  349. $content_text = $shortcode['content_text'];
  350. }
  351. else
  352. {
  353. $content_text = 'Your Content';
  354. }
  355. ?>
  356. <strong><?php echo $content_text; ?>:</strong><br/>
  357. <input type="hidden" id="<?php echo $shortcode_name; ?>_content_repeat" value="<?php echo $shortcode['repeat']; ?>"/>
  358. <textarea id="<?php echo $shortcode_name; ?>_content" style="width:90%;height:70px" rows="3" wrap="off"></textarea><br/><br/>
  359. <?php
  360. }
  361. ?>
  362. <?php
  363. if(isset($shortcode['attr']) && !empty($shortcode['attr']))
  364. {
  365. ?>
  366. <div id="<?php echo $shortcode_name; ?>_attr_wrapper">
  367. <?php
  368. foreach($shortcode['attr'] as $attr => $type)
  369. {
  370. ?>
  371. <?php echo '<strong>'.ucfirst($attr).'</strong>: '.$shortcode['desc'][$attr]; ?><br/>
  372. <?php
  373. switch($type)
  374. {
  375. case 'text':
  376. ?>
  377. <input type="text" id="<?php echo $shortcode_name; ?>_text" style="width:90%" class="attr" name="<?php echo $attr; ?>"/>
  378. <?php
  379. break;
  380. case 'select':
  381. ?>
  382. <select id="<?php echo $shortcode_name; ?>_select" style="width:25%" class="attr" name="<?php echo $attr; ?>">
  383. <?php
  384. if(isset($shortcode['options']) && !empty($shortcode['options']))
  385. {
  386. foreach($shortcode['options'] as $select_key => $option)
  387. {
  388. ?>
  389. <option value="<?php echo $select_key; ?>"><?php echo $option; ?></option>
  390. <?php
  391. }
  392. }
  393. ?>
  394. </select>
  395. <?php
  396. break;
  397. }
  398. ?>
  399. <br/><br/>
  400. <?php
  401. } //end attr foreach
  402. ?>
  403. </div>
  404. <?php
  405. }
  406. ?>
  407. <br/>
  408. <input type="button" id="<?php echo $shortcode_name; ?>" value="Generate Shortcode" class="button"/>
  409. <br/><br/><br/>
  410. <strong>Shortcode:</strong><br/>
  411. <textarea id="<?php echo $shortcode_name; ?>_code" style="width:90%;height:70px" rows="3" readonly="readonly" class="code_area" wrap="off"></textarea>
  412. </div>
  413. </div>
  414. <?php
  415. } //end shortcode foreach
  416. }
  417. ?>
  418. </div>
  419. </div>
  420. <br style="clear:both"/>
  421. <?php
  422. }
  423. /*
  424. End Create Shortcode Generator Options
  425. */
  426. ?>