/blog/wp-content/themes/Insignia/lib/shortcodes/widgets.php

https://bitbucket.org/bsnowman/classyblog · PHP · 574 lines · 453 code · 85 blank · 36 comment · 23 complexity · 468cc8d7f03f3fa20d196d754788e3fe MD5 · raw file

  1. <?php
  2. /**
  3. *
  4. */
  5. class alliWidgets {
  6. /**
  7. *
  8. */
  9. function twitter( $atts = null ) {
  10. if( $atts == 'generator' ) {
  11. $numbers = range(1,20);
  12. foreach( $numbers as $val )
  13. $number[$val] = $val;
  14. $option = array(
  15. 'name' => __( 'Twitter', ALLI_ADMIN_TEXTDOMAIN ),
  16. 'value' => 'twitter',
  17. 'options' => array(
  18. array(
  19. 'name' => __( 'Username', ALLI_ADMIN_TEXTDOMAIN ),
  20. 'desc' => __( 'Paste your twitter username here. You can find your username by going to your settings page within twitter.', ALLI_ADMIN_TEXTDOMAIN ),
  21. 'id' => 'id',
  22. 'default' => '',
  23. 'type' => 'text'
  24. ),
  25. array(
  26. 'name' => __( 'Count', ALLI_ADMIN_TEXTDOMAIN ),
  27. 'desc' => __( 'Select how many tweets you want to be displayed.', ALLI_ADMIN_TEXTDOMAIN ),
  28. 'id' => 'number',
  29. 'default' => '',
  30. 'options' => $number,
  31. 'type' => 'select'
  32. ),
  33. 'shortcode_has_atts' => true,
  34. )
  35. );
  36. return $option;
  37. }
  38. $defaults = array(
  39. 'id' => '',
  40. 'number' => '1',
  41. 'title' => ' '
  42. );
  43. if( isset( $atts['count'] ) )
  44. $atts['number'] = $atts['count'];
  45. if( isset( $atts['username'] ) )
  46. $atts['id'] = $atts['username'];
  47. if( empty( $atts['id'] ) )
  48. $atts['id'] = alli_get_setting( 'twitter_id' );
  49. $atts = wp_parse_args( $atts, $defaults );
  50. $instance = http_build_query( $atts );
  51. $args = array( 'widget_name' => 'AlliaseW_Twitter_Widget', 'instance' => $instance );
  52. $widget = new alliWidgets();
  53. return $widget->_widget_generator( $args );
  54. }
  55. /**
  56. *
  57. */
  58. function flickr( $atts = null ) {
  59. if( $atts == 'generator' ) {
  60. $numbers = range(1,20);
  61. foreach( $numbers as $val )
  62. $number[$val] = $val;
  63. $option = array(
  64. 'name' => __( 'Flickr', ALLI_ADMIN_TEXTDOMAIN ),
  65. 'value' => 'flickr',
  66. 'options' => array(
  67. array(
  68. 'name' => __( 'Flickr id (<a target="_blank" href="http://idgettr.com/">idGettr</a>)', ALLI_ADMIN_TEXTDOMAIN ),
  69. 'desc' => __( 'Set your Flickr ID here. You can use the idGettr service to easily find your ID.', ALLI_ADMIN_TEXTDOMAIN ),
  70. 'id' => 'id',
  71. 'default' => '',
  72. 'type' => 'text'
  73. ),
  74. array(
  75. 'name' => __( 'Count', ALLI_ADMIN_TEXTDOMAIN ),
  76. 'desc' => __( 'Select how many flickr images you wish to display.', ALLI_ADMIN_TEXTDOMAIN ),
  77. 'id' => 'count',
  78. 'default' => '',
  79. 'options' => $number,
  80. 'type' => 'select'
  81. ),
  82. array(
  83. 'name' => __( 'Size', ALLI_ADMIN_TEXTDOMAIN ),
  84. 'desc' => __( 'Set the size of your flickr images.<br /><br />Each setting will display differently so try and experiment with them to find which one suits you best.', ALLI_ADMIN_TEXTDOMAIN ),
  85. 'id' => 'size',
  86. 'default' => '',
  87. 'options' => array(
  88. 's' => __('Square', ALLI_ADMIN_TEXTDOMAIN ),
  89. 't' => __('Thumbnail', ALLI_ADMIN_TEXTDOMAIN ),
  90. 'm' => __('Medium', ALLI_ADMIN_TEXTDOMAIN )
  91. ),
  92. 'type' => 'select'
  93. ),
  94. array(
  95. 'name' => __('Display', ALLI_ADMIN_TEXTDOMAIN ),
  96. 'desc' => __( 'Select whether you want your latest images to display or a random selection.', ALLI_ADMIN_TEXTDOMAIN ),
  97. 'id' => 'display',
  98. 'default' => '',
  99. 'options' => array(
  100. 'latest' => __('Latest', ALLI_ADMIN_TEXTDOMAIN ),
  101. 'random' => __('Random', ALLI_ADMIN_TEXTDOMAIN )
  102. ),
  103. 'type' => 'select'
  104. ),
  105. 'shortcode_has_atts' => true,
  106. )
  107. );
  108. return $option;
  109. }
  110. $defaults = array(
  111. 'id' => '44071822@N08',
  112. 'number' => '9',
  113. 'display' => 'latest',
  114. 'size' => 's',
  115. 'title' => ' '
  116. );
  117. $atts = wp_parse_args( $atts, $defaults );
  118. $instance = http_build_query( $atts );
  119. $args = array( 'widget_name' => 'AlliaseW_Flickr_Widget', 'instance' => $instance );
  120. $widget = new alliWidgets();
  121. return $widget->_widget_generator( $args );
  122. }
  123. /**
  124. *
  125. */
  126. function recent_posts( $atts = null ) {
  127. if( $atts == 'generator' ) {
  128. $numbers = range(1,20);
  129. foreach( $numbers as $val )
  130. $number[$val] = $val;
  131. $option = array(
  132. 'name' => __( 'Recent Posts', ALLI_ADMIN_TEXTDOMAIN ),
  133. 'value' => 'recent_posts',
  134. 'options' => array(
  135. array(
  136. 'name' => __( 'Number', ALLI_ADMIN_TEXTDOMAIN ),
  137. 'desc' => __( 'Select the number of posts you wish to display.', ALLI_ADMIN_TEXTDOMAIN ),
  138. 'id' => 'number',
  139. 'default' => '',
  140. 'options' => $number,
  141. 'type' => 'select'
  142. ),
  143. array(
  144. 'name' => __( 'Thumbnail', ALLI_ADMIN_TEXTDOMAIN ),
  145. 'desc' => __( 'Choose whether you want thumbnails to display alongside your posts. The thumbnail uses the featured image of your post.', ALLI_ADMIN_TEXTDOMAIN ),
  146. 'id' => 'disable_thumb',
  147. 'default' => '',
  148. 'options' => array(
  149. '0' => __( 'Yes', ALLI_ADMIN_TEXTDOMAIN ),
  150. '1' => __( 'No', ALLI_ADMIN_TEXTDOMAIN )
  151. ),
  152. 'type' => 'select'
  153. ),
  154. 'shortcode_has_atts' => true,
  155. )
  156. );
  157. return $option;
  158. }
  159. $defaults = array(
  160. 'number' => '',
  161. 'disable_thumb' => '',
  162. 'title' => ' '
  163. );
  164. $atts = wp_parse_args( $atts, $defaults );
  165. $instance = http_build_query( $atts );
  166. $args = array( 'widget_name' => 'AlliaseW_RecentPost_Widget', 'instance' => $instance );
  167. $widget = new alliWidgets();
  168. return $widget->_widget_generator( $args );
  169. }
  170. /**
  171. *
  172. */
  173. function popular_posts( $atts = null ) {
  174. if( $atts == 'generator' ) {
  175. $numbers = range(1,20);
  176. foreach( $numbers as $val )
  177. $number[$val] = $val;
  178. $option = array(
  179. 'name' => __( 'Popular Posts', ALLI_ADMIN_TEXTDOMAIN ),
  180. 'value' => 'popular_posts',
  181. 'options' => array(
  182. array(
  183. 'name' => __( 'Number', ALLI_ADMIN_TEXTDOMAIN ),
  184. 'desc' => __( 'Select the number of posts you wish to display.', ALLI_ADMIN_TEXTDOMAIN ),
  185. 'id' => 'number',
  186. 'default' => '',
  187. 'options' => $number,
  188. 'type' => 'select'
  189. ),
  190. array(
  191. 'name' => __( 'Thumbnail', ALLI_ADMIN_TEXTDOMAIN ),
  192. 'desc' => __( 'Choose whether you want thumbnails to display alongside your posts. The thumbnail uses the featured image of your post.', ALLI_ADMIN_TEXTDOMAIN ),
  193. 'id' => 'disable_thumb',
  194. 'default' => '',
  195. 'options' => array(
  196. '0' => __( 'Yes', ALLI_ADMIN_TEXTDOMAIN ),
  197. '1' => __( 'No', ALLI_ADMIN_TEXTDOMAIN )
  198. ),
  199. 'type' => 'select'
  200. ),
  201. 'shortcode_has_atts' => true,
  202. )
  203. );
  204. return $option;
  205. }
  206. $defaults = array(
  207. 'number' => '',
  208. 'disable_thumb' => '',
  209. 'title' => ' '
  210. );
  211. $atts = wp_parse_args( $atts, $defaults );
  212. $instance = http_build_query( $atts );
  213. $args = array( 'widget_name' => 'AlliaseW_PopularPost_Widget', 'instance' => $instance );
  214. $widget = new alliWidgets();
  215. return $widget->_widget_generator( $args );
  216. }
  217. /**
  218. *
  219. */
  220. function contact_info( $atts = null ) {
  221. if( $atts == 'generator' ) {
  222. $option = array(
  223. 'name' => __( 'Contact Info', ALLI_ADMIN_TEXTDOMAIN ),
  224. 'value' => 'contact_info',
  225. 'options' => array(
  226. array(
  227. 'name' => __( 'Name', ALLI_ADMIN_TEXTDOMAIN ),
  228. 'desc' => __( 'Type in your name.', ALLI_ADMIN_TEXTDOMAIN ),
  229. 'id' => 'name',
  230. 'default' => '',
  231. 'type' => 'text'
  232. ),
  233. array(
  234. 'name' => __( 'Phone', ALLI_ADMIN_TEXTDOMAIN ),
  235. 'desc' => __( 'Type in your phone number.', ALLI_ADMIN_TEXTDOMAIN ),
  236. 'id' => 'phone',
  237. 'default' => '',
  238. 'type' => 'text'
  239. ),
  240. array(
  241. 'name' => __( 'Email', ALLI_ADMIN_TEXTDOMAIN ),
  242. 'desc' => __( 'Type in your email address.', ALLI_ADMIN_TEXTDOMAIN ),
  243. 'id' => 'email',
  244. 'default' => '',
  245. 'type' => 'text'
  246. ),
  247. array(
  248. 'name' => __( 'Address', ALLI_ADMIN_TEXTDOMAIN ),
  249. 'desc' => __( 'Type in your address.', ALLI_ADMIN_TEXTDOMAIN ),
  250. 'id' => 'address',
  251. 'default' => '',
  252. 'type' => 'text'
  253. ),
  254. array(
  255. 'name' => __( 'City', ALLI_ADMIN_TEXTDOMAIN ),
  256. 'desc' => __( 'Type in your city.', ALLI_ADMIN_TEXTDOMAIN ),
  257. 'id' => 'city',
  258. 'default' => '',
  259. 'type' => 'text'
  260. ),
  261. array(
  262. 'name' => __( 'State', ALLI_ADMIN_TEXTDOMAIN ),
  263. 'desc' => __( 'Type in your state.', ALLI_ADMIN_TEXTDOMAIN ),
  264. 'id' => 'state',
  265. 'default' => '',
  266. 'type' => 'text'
  267. ),
  268. array(
  269. 'name' => __( 'Zip', ALLI_ADMIN_TEXTDOMAIN ),
  270. 'desc' => __( 'Type in your zip.', ALLI_ADMIN_TEXTDOMAIN ),
  271. 'id' => 'zip',
  272. 'default' => '',
  273. 'type' => 'text'
  274. ),
  275. 'shortcode_has_atts' => true,
  276. )
  277. );
  278. return $option;
  279. }
  280. $defaults = array(
  281. 'name' => '',
  282. 'address' => '',
  283. 'city' => '',
  284. 'state' => '',
  285. 'zip' => '',
  286. 'phone' => '',
  287. 'email' => '',
  288. 'title' => ' '
  289. );
  290. $atts = wp_parse_args( $atts, $defaults );
  291. $instance = http_build_query( $atts );
  292. $args = array( 'widget_name' => 'AlliaseW_Contact_Widget', 'instance' => $instance );
  293. $widget = new alliWidgets();
  294. return $widget->_widget_generator( $args );
  295. }
  296. /**
  297. *
  298. */
  299. function comments( $atts = null ) {
  300. if( $atts == 'generator' ) {
  301. $numbers = range(1,20);
  302. foreach( $numbers as $val )
  303. $number[$val] = $val;
  304. $option = array(
  305. 'name' => __( 'Comments', ALLI_ADMIN_TEXTDOMAIN ),
  306. 'value' => 'comments',
  307. 'options' => array(
  308. array(
  309. 'name' => __( 'Number', ALLI_ADMIN_TEXTDOMAIN ),
  310. 'desc' => __( 'Select the number of comments you wish to display.', ALLI_ADMIN_TEXTDOMAIN ),
  311. 'id' => 'number',
  312. 'default' => '',
  313. 'options' => $number,
  314. 'type' => 'select'
  315. ),
  316. 'shortcode_has_atts' => true,
  317. )
  318. );
  319. return $option;
  320. }
  321. $defaults = array(
  322. 'title' => ' ',
  323. 'number' => '5'
  324. );
  325. $atts = wp_parse_args( $atts, $defaults );
  326. $instance = http_build_query( $atts );
  327. $args = array( 'widget_name' => 'WP_Widget_Recent_Comments', 'instance' => $instance );
  328. $widget = new alliWidgets();
  329. return $widget->_widget_generator( $args );
  330. }
  331. /**
  332. *
  333. */
  334. function tags( $atts = null ) {
  335. if( $atts == 'generator' ) {
  336. $option = array(
  337. 'name' => __( 'Tags', ALLI_ADMIN_TEXTDOMAIN ),
  338. 'value' => 'tags',
  339. 'options' => array(
  340. array(
  341. 'name' => __( 'Taxonomy', ALLI_ADMIN_TEXTDOMAIN ),
  342. 'desc' => __( 'Select whether you wish to display categories or tags.', ALLI_ADMIN_TEXTDOMAIN ),
  343. 'id' => 'taxonomy',
  344. 'default' => '',
  345. 'options' => array(
  346. 'post_tag' => __( 'Post Tags', ALLI_ADMIN_TEXTDOMAIN ),
  347. 'category' => __( 'Category', ALLI_ADMIN_TEXTDOMAIN )
  348. ),
  349. 'type' => 'select'
  350. ),
  351. 'shortcode_has_atts' => true,
  352. )
  353. );
  354. return $option;
  355. }
  356. $defaults = array(
  357. 'title' => ' ',
  358. 'taxonomy' => 'post_tag'
  359. );
  360. $atts = wp_parse_args( $atts, $defaults );
  361. $instance = http_build_query( $atts );
  362. $args = array( 'widget_name' => 'WP_Widget_Tag_Cloud', 'instance' => $instance );
  363. $widget = new alliWidgets();
  364. return $widget->_widget_generator( $args );
  365. }
  366. /**
  367. *
  368. */
  369. function rss( $atts = null ) {
  370. if( $atts == 'generator' ) {
  371. $numbers = range(1,20);
  372. foreach( $numbers as $val ) {
  373. $number[$val] = $val;
  374. }
  375. $option = array(
  376. 'name' => __( 'Rss', ALLI_ADMIN_TEXTDOMAIN ),
  377. 'value' => 'rss',
  378. 'options' => array(
  379. array(
  380. 'name' => __( 'RSS feed URL ', ALLI_ADMIN_TEXTDOMAIN ),
  381. 'desc' => __( 'Paste the URL to your feed. For example if you are using feedburner then you would paste something like this,<br /><br />http://feeds.feedburner.com/username', ALLI_ADMIN_TEXTDOMAIN ),
  382. 'id' => 'url',
  383. 'default' => '',
  384. 'type' => 'text'
  385. ),
  386. array(
  387. 'name' => __( 'How many items would you like to display?', ALLI_ADMIN_TEXTDOMAIN ),
  388. 'desc' => __( 'Select the number of RSS items you wish to display.', ALLI_ADMIN_TEXTDOMAIN ),
  389. 'id' => 'items',
  390. 'default' => '',
  391. 'options' => $number,
  392. 'type' => 'select'
  393. ),
  394. array(
  395. 'name' => __( 'Show Summary', ALLI_ADMIN_TEXTDOMAIN ),
  396. 'desc' => __( 'Check this if you wish to display a summary of the item.', ALLI_ADMIN_TEXTDOMAIN ),
  397. 'id' => 'show_summary',
  398. 'options' => array( '1' => __( 'Show Summary', ALLI_ADMIN_TEXTDOMAIN )),
  399. 'default' => '',
  400. 'type' => 'checkbox'
  401. ),
  402. array(
  403. 'name' => __( 'Show Author', ALLI_ADMIN_TEXTDOMAIN ),
  404. 'desc' => __( 'Check if you wish to display the author of the item.', ALLI_ADMIN_TEXTDOMAIN ),
  405. 'id' => 'show_author',
  406. 'options' => array( '1' => __( 'Show Author', ALLI_ADMIN_TEXTDOMAIN )),
  407. 'default' => '',
  408. 'type' => 'checkbox'
  409. ),
  410. array(
  411. 'name' => __( 'Show Date', ALLI_ADMIN_TEXTDOMAIN ),
  412. 'desc' => __( 'Check if you wish to display the date of the item.', ALLI_ADMIN_TEXTDOMAIN ),
  413. 'id' => 'show_date',
  414. 'options' => array( '1' => __( 'Show Date', ALLI_ADMIN_TEXTDOMAIN )),
  415. 'default' => '',
  416. 'type' => 'checkbox'
  417. ),
  418. 'shortcode_has_atts' => true,
  419. )
  420. );
  421. return $option;
  422. }
  423. $defaults = array(
  424. 'title' => ' ',
  425. 'url' => '',
  426. 'items' => 3,
  427. 'error' => false,
  428. 'show_summary' => 0,
  429. 'show_author' => 0,
  430. 'show_date' => 0
  431. );
  432. $atts = wp_parse_args( $atts, $defaults );
  433. $instance = http_build_query( $atts );
  434. $args = array( 'widget_name' => 'WP_Widget_RSS', 'instance' => $instance );
  435. $widget = new alliWidgets();
  436. return $widget->_widget_generator( $args );
  437. }
  438. /**
  439. *
  440. */
  441. function search( $atts = null ) {
  442. if( $atts == 'generator' ) {
  443. $option = array(
  444. 'name' => __( 'Search', ALLI_ADMIN_TEXTDOMAIN ),
  445. 'value' => 'search'
  446. );
  447. return $option;
  448. }
  449. $defaults = array( 'title' => ' ' );
  450. $atts = wp_parse_args( $atts, $defaults );
  451. $instance = http_build_query( $atts );
  452. $args = array( 'widget_name' => 'WP_Widget_Search', 'instance' => $instance );
  453. $widget = new alliWidgets();
  454. return $widget->_widget_generator( $args );
  455. }
  456. /**
  457. *
  458. */
  459. function _widget_generator( $args = array() ) {
  460. global $wp_widget_factory;
  461. $widget_name = esc_html( $args['widget_name'] );
  462. ob_start();
  463. the_widget( $widget_name, $args['instance'], array( 'before_title' => '', 'after_title' => '', 'widget_id' => '-1' ) );
  464. $out = ob_get_contents();
  465. ob_end_clean();
  466. return $out;
  467. }
  468. /**
  469. *
  470. */
  471. function _options( $class ) {
  472. $shortcode = array();
  473. $class_methods = get_class_methods( $class );
  474. foreach( $class_methods as $method ) {
  475. if( $method[0] != '_' ) {
  476. $shortcode[] = call_user_func(array( &$class, $method ), $atts = 'generator' );
  477. }
  478. }
  479. $options = array(
  480. 'name' => __( 'Widget', ALLI_ADMIN_TEXTDOMAIN ),
  481. 'desc' => __( 'Select which widget shortcode you would like to use.', ALLI_ADMIN_TEXTDOMAIN ),
  482. 'value' => 'widget',
  483. 'options' => $shortcode,
  484. 'shortcode_has_types' => true
  485. );
  486. return $options;
  487. }
  488. }
  489. ?>