PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/wp-content/themes/extinct/prologue-projects/functions-sidebars.php

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 734 lines | 617 code | 114 blank | 3 comment | 114 complexity | 8fa876a9cfd84f45ca092cf0be854da2 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. function pp_generate_sidebars()
  3. {
  4. register_sidebar( array(
  5. 'name' => 'All - Top',
  6. 'id' => 'pp-sidebar-top',
  7. 'before_widget' => '<li id="%1$s" class="widget pp-sidebar-top %2$s">',
  8. 'after_widget' => '</li>',
  9. 'before_title' => '<h3 class="widgettitle">',
  10. 'after_title' => '</h3>'
  11. ) );
  12. register_sidebar( array(
  13. 'name' => 'Home',
  14. 'id' => 'pp-home-sidebar',
  15. 'before_widget' => '<li id="%1$s" class="widget pp-home-sidebar %2$s">',
  16. 'after_widget' => '</li>',
  17. 'before_title' => '<h3 class="widgettitle">',
  18. 'after_title' => '</h3>'
  19. ) );
  20. register_sidebar( array(
  21. 'name' => 'Single post page',
  22. 'id' => 'pp-single-sidebar',
  23. 'before_widget' => '<li id="%1$s" class="widget pp-single-sidebar %2$s">',
  24. 'after_widget' => '</li>',
  25. 'before_title' => '<h3 class="widgettitle">',
  26. 'after_title' => '</h3>'
  27. ) );
  28. register_sidebar( array(
  29. 'name' => 'Project (default)',
  30. 'id' => 'pp-project-sidebar-default',
  31. 'before_widget' => '<li id="%1$s" class="widget pp-project-sidebar pp-project-sidebar-all %2$s">',
  32. 'after_widget' => '</li>',
  33. 'before_title' => '<h3 class="widgettitle">',
  34. 'after_title' => '</h3>'
  35. ) );
  36. $options = pp_get_options();
  37. if ( $options['project_sidebars'] && $projects = pp_get_projects() ) {
  38. foreach ( $projects as $project ) {
  39. register_sidebar( array(
  40. 'name' => 'Project - ' . $project->name,
  41. 'id' => 'pp-project-sidebar-' . $project->cat_ID,
  42. 'before_widget' => '<li id="%1$s" class="widget pp-project-sidebar pp-project-sidebar-' . $project->cat_ID . ' %2$s">',
  43. 'after_widget' => '</li>',
  44. 'before_title' => '<h3 class="widgettitle">',
  45. 'after_title' => '</h3>'
  46. ) );
  47. }
  48. }
  49. register_sidebar( array(
  50. 'name' => 'Author (default)',
  51. 'id' => 'pp-author-sidebar-default',
  52. 'before_widget' => '<li id="%1$s" class="widget pp-author-sidebar pp-author-sidebar-all %2$s">',
  53. 'after_widget' => '</li>',
  54. 'before_title' => '<h3 class="widgettitle">',
  55. 'after_title' => '</h3>'
  56. ) );
  57. // Todo: cache the author array
  58. $authors = array();
  59. if ( $options['author_sidebars'] && $users = get_users_of_blog() ) {
  60. foreach ( $users as $user ) {
  61. $user_object = new WP_User( $user->user_id );
  62. if ( !$user_object->has_cap( 'publish_posts' ) ) {
  63. continue;
  64. }
  65. $authors[] = $user;
  66. }
  67. }
  68. foreach ( $authors as $author ) {
  69. register_sidebar( array(
  70. 'name' => 'Author - ' . $author->display_name,
  71. 'id' => 'pp-author-sidebar-' . $author->user_id,
  72. 'before_widget' => '<li id="%1$s" class="widget pp-author-sidebar pp-author-sidebar-' . $author->user_id . ' %2$s">',
  73. 'after_widget' => '</li>',
  74. 'before_title' => '<h3 class="widgettitle">',
  75. 'after_title' => '</h3>'
  76. ) );
  77. }
  78. register_sidebar( array(
  79. 'name' => 'All - Bottom',
  80. 'id' => 'pp-sidebar-bottom',
  81. 'before_widget' => '<li id="%1$s" class="widget pp-sidebar-bottom %2$s">',
  82. 'after_widget' => '</li>',
  83. 'before_title' => '<h3 class="widgettitle">',
  84. 'after_title' => '</h3>'
  85. ) );
  86. }
  87. class PP_Widget_Project_Tree
  88. {
  89. var $options;
  90. function PP_Widget_Project_Tree()
  91. {
  92. if ( !$this->options = get_option( 'pp_widget_project_tree' ) ) {
  93. $this->options = array();
  94. }
  95. add_action( 'widgets_init', array( $this, 'init' ) );
  96. }
  97. function init()
  98. {
  99. $widget_options = array(
  100. 'classname' => 'pp-widget-project-tree',
  101. 'description' => __( 'Display projects in a navigable tree', 'prologue-projects' )
  102. );
  103. $control_options = array(
  104. 'height' => 350,
  105. 'id_base' => 'pp-widget-project-tree'
  106. );
  107. if ( !count($this->options) ) {
  108. $options = array(-1 => false);
  109. } else {
  110. $options = $this->options;
  111. }
  112. foreach ( $options as $instance => $option ) {
  113. wp_register_sidebar_widget(
  114. 'pp-widget-project-tree-' . $instance,
  115. __('Project Tree', 'prologue-projects'),
  116. array($this, 'display'),
  117. $widget_options,
  118. array( 'number' => $instance )
  119. );
  120. wp_register_widget_control(
  121. 'pp-widget-project-tree-' . $instance,
  122. __('Project Tree', 'prologue-projects'),
  123. array($this, 'control'),
  124. $control_options,
  125. array( 'number' => $instance )
  126. );
  127. }
  128. }
  129. function display( $args, $instance = false )
  130. {
  131. if ( is_array( $instance ) ) {
  132. $instance = $instance['number'];
  133. }
  134. if ( !$instance || !is_numeric( $instance ) || 1 > $instance ) {
  135. return;
  136. }
  137. extract( $args );
  138. $parent_type = $this->options[$instance]['parent'] ? $this->options[$instance]['parent'] : 'all';
  139. $parent_id = ( pp_is_project() && $parent_type == 'sub') ? pp_get_project_data( 0, 'id' ) : 0;
  140. if ( $parent_id === false ) {
  141. return;
  142. }
  143. $categories = pp_get_projects( $parent_id );
  144. if ( !$categories ) {
  145. return;
  146. }
  147. $walker = new Walker_Category();
  148. echo $before_widget;
  149. if ( $parent_type == 'sub' && $parent_id !== 0 ) {
  150. $title = __( 'Sub-projects', 'prologue-projects' );
  151. } else {
  152. $title = __( 'Projects', 'prologue-projects' );
  153. }
  154. $title = $this->options[$instance]['title'] ? $this->options[$instance]['title'] : $title;
  155. echo $before_title;
  156. echo $title;
  157. echo $after_title;
  158. echo '<ul>';
  159. echo call_user_func_array( array( &$walker, 'walk' ), array( $categories, 0, array( 'style' => 'list' ) ) );
  160. echo '</ul>';
  161. echo $after_widget;
  162. }
  163. function control( $instance = false )
  164. {
  165. if ( is_array( $instance ) ) {
  166. $instance = $instance['number'];
  167. }
  168. if ( !$instance || !is_numeric($instance) || 1 > $instance ) {
  169. $instance = '%i%';
  170. }
  171. $options = $this->options;
  172. if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['pp_widget_project_tree'] ) ) {
  173. foreach ( $_POST['pp_widget_project_tree'] as $_instance => $_value ) {
  174. if ( !$_value ) {
  175. continue;
  176. }
  177. $options[$_instance]['title'] = strip_tags( stripslashes( $_POST['pp_widget_project_tree'][$_instance]['title'] ) );
  178. $parent = $_POST['pp_widget_project_tree'][$_instance]['parent'];
  179. if ( in_array( $parent, array('all', 'sub') ) ) {
  180. $options[$_instance]['parent'] = $parent;
  181. } else {
  182. $options[$_instance]['parent'] = 'all';
  183. }
  184. }
  185. if ( $this->options != $options ) {
  186. $this->options = $options;
  187. update_option('pp_widget_project_tree', $this->options);
  188. }
  189. }
  190. $options['%i%']['title'] = '';
  191. $options['%i%']['parent'] = '';
  192. $title = attribute_escape( stripslashes( $options[$instance]['title'] ) );
  193. if ( !$options[$instance]['parent'] ) {
  194. $options[$instance]['parent'] = 'all';
  195. }
  196. $parent = array( 'all' => '', 'sub' => '' );
  197. $parent[$options[$instance]['parent']] = ' selected="selected"';
  198. if ( !$project_category_id = pp_get_category_id( 'projects' ) ) {
  199. ?>
  200. <p>
  201. <?php _e( 'You must select and save the "projects" category in the project settings.', 'prologue-projects' ); ?>
  202. </p>
  203. <?php
  204. } else {
  205. ?>
  206. <p>
  207. <label for="pp_widget_project_tree_title_<?php echo $instance; ?>">
  208. <?php _e('Title:', 'prologue-projects'); ?>
  209. <input class="widefat" id="pp_widget_project_tree_title_<?php echo $instance; ?>" name="pp_widget_project_tree[<?php echo $instance; ?>][title]" type="text" value="<?php echo $title; ?>" />
  210. </label>
  211. </p>
  212. <p>
  213. <label for="pp_widget_project_tree_parent_<?php echo $instance; ?>">
  214. <?php _e('Show:', 'prologue-projects'); ?><br />
  215. <select id="pp_widget_project_tree_parent_<?php echo $instance; ?>" name="pp_widget_project_tree[<?php echo $instance; ?>][parent]">
  216. <option value="all"<?php echo $parent['all']; ?>><?php _e('All projects', 'prologue-projects'); ?></option>
  217. <option value="sub"<?php echo $parent['sub']; ?>><?php _e('The current projects sub-projects', 'prologue-projects'); ?></option>
  218. </select>
  219. </label>
  220. </p>
  221. <input type="hidden" id="pp_widget_project_tree_submit" name="pp_widget_project_tree[<?php echo $instance; ?>][submit]" value="1" />
  222. <?php
  223. }
  224. }
  225. }
  226. class PP_Widget_Project_Team
  227. {
  228. var $options;
  229. function PP_Widget_Project_Team()
  230. {
  231. if ( !$this->options = get_option( 'pp_widget_project_team' ) ) {
  232. $this->options = array();
  233. }
  234. add_action( 'widgets_init', array( $this, 'init' ) );
  235. }
  236. function init()
  237. {
  238. $widget_options = array(
  239. 'classname' => 'pp-widget-project-team',
  240. 'description' => __( 'Display all project team members in the current project', 'prologue-projects' )
  241. );
  242. $control_options = array(
  243. 'height' => 350,
  244. 'id_base' => 'pp-widget-project-team'
  245. );
  246. if ( !count($this->options) ) {
  247. $options = array(-1 => false);
  248. } else {
  249. $options = $this->options;
  250. }
  251. foreach ( $options as $instance => $option ) {
  252. wp_register_sidebar_widget(
  253. 'pp-widget-project-team-' . $instance,
  254. __('Project Team', 'prologue-projects'),
  255. array($this, 'display'),
  256. $widget_options,
  257. array( 'number' => $instance )
  258. );
  259. wp_register_widget_control(
  260. 'pp-widget-project-team-' . $instance,
  261. __('Project Team', 'prologue-projects'),
  262. array($this, 'control'),
  263. $control_options,
  264. array( 'number' => $instance )
  265. );
  266. }
  267. }
  268. function display( $args, $instance = false )
  269. {
  270. if ( is_array( $instance ) ) {
  271. $instance = $instance['number'];
  272. }
  273. if ( !$instance || !is_numeric( $instance ) || 1 > $instance ) {
  274. return;
  275. }
  276. extract( $args );
  277. echo $before_widget;
  278. $title = $this->options[$instance]['title'] ? $this->options[$instance]['title'] : __( 'Project Team', 'prologue-projects' );
  279. echo $before_title;
  280. echo $title;
  281. echo $after_title;
  282. $data = pp_get_project_data( $category_id );
  283. if ( $members = pp_get_project_members( $data['id'] ) ) {
  284. if ( count( $members ) ) {
  285. echo '<ul id="pp-project-team-list-' . attribute_escape( $data['slug'] ) . '" class="pp-project-team-list">' . "\n";
  286. foreach ( $members as $member ) {
  287. echo "\t" . '<li><a href="' . attribute_escape( get_author_posts_url( $member['user_id'], $member['user_nicename'] ) ) . '">';
  288. echo get_avatar($member['user_id'], 16);
  289. echo $member['display_name'] . '</a>';
  290. if ( $member['project_role'] ) {
  291. echo ' - <span class="role">' . wp_specialchars( $member['project_role'] ) . '</span>';
  292. }
  293. echo '</li>' . "\n";
  294. }
  295. echo '</ul>' . "\n";
  296. }
  297. } else {
  298. echo '<p class="empty">' . __( 'No team members assigned', 'prologue-projects' ) . '</p>' . "\n";
  299. }
  300. echo $after_widget;
  301. }
  302. function control( $instance = false )
  303. {
  304. if ( is_array( $instance ) ) {
  305. $instance = $instance['number'];
  306. }
  307. if ( !$instance || !is_numeric($instance) || 1 > $instance ) {
  308. $instance = '%i%';
  309. }
  310. $options = $this->options;
  311. if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['pp_widget_project_team'] ) ) {
  312. foreach ( $_POST['pp_widget_project_team'] as $_instance => $_value ) {
  313. if ( !$_value ) {
  314. continue;
  315. }
  316. $options[$_instance]['title'] = strip_tags( stripslashes( $_POST['pp_widget_project_team'][$_instance]['title'] ) );
  317. }
  318. if ( $this->options != $options ) {
  319. $this->options = $options;
  320. update_option('pp_widget_project_team', $this->options);
  321. }
  322. }
  323. $options['%i%']['title'] = '';
  324. $title = attribute_escape( stripslashes( $options[$instance]['title'] ) );
  325. ?>
  326. <p>
  327. <label for="pp_widget_project_team_title_<?php echo $instance; ?>">
  328. <?php _e('Title:', 'prologue-projects'); ?>
  329. <input class="widefat" id="pp_widget_project_team_title_<?php echo $instance; ?>" name="pp_widget_project_team[<?php echo $instance; ?>][title]" type="text" value="<?php echo $title; ?>" />
  330. </label>
  331. </p>
  332. <input type="hidden" id="pp_widget_project_team_submit" name="pp_widget_project_team[<?php echo $instance; ?>][submit]" value="1" />
  333. <?php
  334. }
  335. }
  336. class PP_Widget_Featured_Project
  337. {
  338. var $options;
  339. function PP_Widget_Featured_Project()
  340. {
  341. if ( !$this->options = get_option( 'pp_widget_featured_project' ) ) {
  342. $this->options = array();
  343. }
  344. add_action( 'widgets_init', array( $this, 'init' ) );
  345. }
  346. function init()
  347. {
  348. $widget_options = array(
  349. 'classname' => 'pp-widget-featured-project',
  350. 'description' => __( 'Display the description of the currently featured project', 'prologue-projects' )
  351. );
  352. $control_options = array(
  353. 'height' => 350,
  354. 'id_base' => 'pp-widget-featured-project'
  355. );
  356. if ( !count($this->options) ) {
  357. $options = array(-1 => false);
  358. } else {
  359. $options = $this->options;
  360. }
  361. foreach ( $options as $instance => $option ) {
  362. wp_register_sidebar_widget(
  363. 'pp-widget-featured-project-' . $instance,
  364. __('Featured Project', 'prologue-projects'),
  365. array($this, 'display'),
  366. $widget_options,
  367. array( 'number' => $instance )
  368. );
  369. wp_register_widget_control(
  370. 'pp-widget-featured-project-' . $instance,
  371. __('Featured Project', 'prologue-projects'),
  372. array($this, 'control'),
  373. $control_options,
  374. array( 'number' => $instance )
  375. );
  376. }
  377. }
  378. function display( $args, $instance = false )
  379. {
  380. if ( is_array( $instance ) ) {
  381. $instance = $instance['number'];
  382. }
  383. if ( !$instance || !is_numeric( $instance ) || 1 > $instance ) {
  384. return;
  385. }
  386. extract( $args );
  387. if ( !$featured_project_id = pp_get_option( 'featured_project' ) ) {
  388. return;
  389. }
  390. if ( !$featured_project = pp_get_project_data( $featured_project_id ) ) {
  391. return;
  392. }
  393. echo $before_widget;
  394. $title = $this->options[$instance]['title'] ? $this->options[$instance]['title'] : __( 'Featured Project', 'prologue-projects' );
  395. echo $before_title;
  396. echo $title;
  397. echo $after_title;
  398. echo '<h4><a href="' . get_category_link( $featured_project_id ) . '">';
  399. pp_project_name( $featured_project_id );
  400. echo '</a></h4>';
  401. pp_project_logo( $featured_project_id );
  402. pp_project_description( $featured_project_id );
  403. if ( $this->options[$instance]['show_team'] ) {
  404. echo '<div class="pp-clear"></div>';
  405. if ( $members = pp_get_project_members( $featured_project['id'] ) ) {
  406. if ( count( $members ) ) {
  407. echo '<ul id="pp-project-team-list-' . $featured_project['slug'] . '" class="pp-featured-project-team-list">' . "\n";
  408. foreach ( $members as $member ) {
  409. echo "\t" . '<li><a href="' . attribute_escape( get_author_posts_url( $member['user_id'], $member['user_nicename'] ) ) . '">';
  410. echo get_avatar($member['user_id'], 16);
  411. echo $member['display_name'] . '</a>';
  412. if ( $member['project_role'] ) {
  413. echo ' - <span class="role">' . ($member['project_role']) . '</span>';
  414. }
  415. echo '</li>' . "\n";
  416. }
  417. echo '</ul>' . "\n";
  418. }
  419. } else {
  420. echo '<p class="empty">' . __( 'No team members assigned', 'prologue-projects' ) . '</p>' . "\n";
  421. }
  422. }
  423. echo '<p class="go-link"><a href="' . get_category_link( $featured_project_id ) . '">' . __( '&raquo; Visit project', 'prologue-projects' ) . '</a></p>';
  424. echo '<div class="pp-clear"></div>';
  425. echo $after_widget;
  426. }
  427. function control( $instance = false )
  428. {
  429. if ( is_array( $instance ) ) {
  430. $instance = $instance['number'];
  431. }
  432. if ( !$instance || !is_numeric($instance) || 1 > $instance ) {
  433. $instance = '%i%';
  434. }
  435. $options = $this->options;
  436. if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['pp_widget_featured_project'] ) ) {
  437. foreach ( $_POST['pp_widget_featured_project'] as $_instance => $_value ) {
  438. if ( !$_value ) {
  439. continue;
  440. }
  441. $options[$_instance]['title'] = strip_tags( stripslashes( $_POST['pp_widget_featured_project'][$_instance]['title'] ) );
  442. if ( isset( $_POST['pp_widget_featured_project'][$_instance]['show_team'] ) && $_POST['pp_widget_featured_project'][$_instance]['show_team'] ) {
  443. $options[$_instance]['show_team'] = 1;
  444. } else {
  445. $options[$_instance]['show_team'] = 0;
  446. }
  447. }
  448. if ( $this->options != $options ) {
  449. $this->options = $options;
  450. update_option('pp_widget_featured_project', $this->options);
  451. }
  452. }
  453. $options['%i%']['title'] = '';
  454. $options['%i%']['show_team'] = '';
  455. $title = attribute_escape( stripslashes( $options[$instance]['title'] ) );
  456. if ( $options[$instance]['show_team'] ) {
  457. $show_team_checked = ' checked="checked"';
  458. }
  459. ?>
  460. <p>
  461. <label for="pp_widget_featured_project_title_<?php echo $instance; ?>">
  462. <?php _e('Title:', 'prologue-projects'); ?>
  463. <input class="widefat" id="pp_widget_featured_project_title_<?php echo $instance; ?>" name="pp_widget_featured_project[<?php echo $instance; ?>][title]" type="text" value="<?php echo $title; ?>" />
  464. </label>
  465. </p>
  466. <p>
  467. <label for="pp_widget_featured_project_show_team_<?php echo $instance; ?>">
  468. <?php _e('Show project team', 'prologue-projects'); ?>
  469. <input type="checkbox" id="pp_widget_featured_project_show_team_<?php echo $instance; ?>" name="pp_widget_featured_project[<?php echo $instance; ?>][show_team]" value="1"<?php echo $show_team_checked; ?> />
  470. </label>
  471. </p>
  472. <input type="hidden" id="pp_widget_featured_project_submit" name="pp_widget_featured_project[<?php echo $instance; ?>][submit]" value="1" />
  473. <?php
  474. }
  475. }
  476. class PP_Widget_User_Projects
  477. {
  478. var $options;
  479. function PP_Widget_User_Projects()
  480. {
  481. if ( !$this->options = get_option( 'pp_widget_user_projects' ) ) {
  482. $this->options = array();
  483. }
  484. add_action( 'widgets_init', array( $this, 'init' ) );
  485. }
  486. function init()
  487. {
  488. $widget_options = array(
  489. 'classname' => 'pp-widget-user-projects',
  490. 'description' => __( 'Displays the current user\'s projects', 'prologue-projects' )
  491. );
  492. $control_options = array(
  493. 'height' => 350,
  494. 'id_base' => 'pp-widget-user-projects'
  495. );
  496. if ( !count($this->options) ) {
  497. $options = array(-1 => false);
  498. } else {
  499. $options = $this->options;
  500. }
  501. foreach ( $options as $instance => $option ) {
  502. wp_register_sidebar_widget(
  503. 'pp-widget-user-projects-' . $instance,
  504. __('User Projects', 'prologue-projects'),
  505. array($this, 'display'),
  506. $widget_options,
  507. array( 'number' => $instance )
  508. );
  509. wp_register_widget_control(
  510. 'pp-widget-user-projects-' . $instance,
  511. __('User Projects', 'prologue-projects'),
  512. array($this, 'control'),
  513. $control_options,
  514. array( 'number' => $instance )
  515. );
  516. }
  517. }
  518. function display( $args, $instance = false )
  519. {
  520. if ( is_array( $instance ) ) {
  521. $instance = $instance['number'];
  522. }
  523. if ( !$instance || !is_numeric( $instance ) || 1 > $instance ) {
  524. return;
  525. }
  526. extract( $args );
  527. global $is_author, $author_id;
  528. if ( !$is_author || !$author_id ) {
  529. return;
  530. }
  531. if ( !$user = new WP_User( $author_id ) ) {
  532. return;
  533. }
  534. echo $before_widget;
  535. $title_name = trim( $user->display_name );
  536. if ( !$title_name ) {
  537. $title_name = __( 'This User\'s Projects', 'prologue-projects' );
  538. } else {
  539. if ( substr( $title_name, '-1' ) === 's' ) {
  540. $title_name .= "'";
  541. } else {
  542. $title_name .= "'s";
  543. }
  544. $title = sprintf( __( '%s Projects', 'prologue-projects' ), $title_name );
  545. }
  546. $title = $this->options[$instance]['title'] ? $this->options[$instance]['title'] : $title;
  547. $first_name = trim($user->first_name);
  548. if ( !$first_name ) {
  549. $empty = __( 'This user is not a member of any project teams', 'prologue-projects' );
  550. } else {
  551. $empty = sprintf( __( '%s is not a member of any project teams', 'prologue-projects' ), wp_specialchars( $first_name ) );
  552. }
  553. echo $before_title;
  554. echo $title;
  555. echo $after_title;
  556. if ( $projects = pp_get_user_projects( $author_id ) ) {
  557. echo '<ul id="pp-user-project-list-' . attribute_escape( $user->user_nicename ) . '" class="pp-user-project-list">' . "\n";
  558. foreach ( $projects as $project_id => $role ) {
  559. echo "\t" . '<li>' . pp_get_project_data( $project_id, 'link' );
  560. if ( $role ) {
  561. echo ' - <span class="role">' . wp_specialchars( $role ) . '</span>';
  562. }
  563. echo '</li>' . "\n";
  564. }
  565. echo '</ul>' . "\n";
  566. } else {
  567. echo '<p class="empty">' . $empty . '</p>' . "\n";
  568. }
  569. echo $after_widget;
  570. }
  571. function control( $instance = false )
  572. {
  573. if ( is_array( $instance ) ) {
  574. $instance = $instance['number'];
  575. }
  576. if ( !$instance || !is_numeric($instance) || 1 > $instance ) {
  577. $instance = '%i%';
  578. }
  579. $options = $this->options;
  580. if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['pp_widget_user_projects'] ) ) {
  581. foreach ( $_POST['pp_widget_user_projects'] as $_instance => $_value ) {
  582. if ( !$_value ) {
  583. continue;
  584. }
  585. $options[$_instance]['title'] = strip_tags( stripslashes( $_POST['pp_widget_user_projects'][$_instance]['title'] ) );
  586. }
  587. if ( $this->options != $options ) {
  588. $this->options = $options;
  589. update_option('pp_widget_user_projects', $this->options);
  590. }
  591. }
  592. $options['%i%']['title'] = '';
  593. $title = attribute_escape( stripslashes( $options[$instance]['title'] ) );
  594. if ( !$project_category_id = pp_get_category_id( 'projects' ) ) {
  595. ?>
  596. <p>
  597. <?php _e( 'You must select and save the "projects" category in the project settings.', 'prologue-projects' ); ?>
  598. </p>
  599. <?php
  600. } else {
  601. ?>
  602. <p>
  603. <label for="pp_widget_user_projects_title_<?php echo $instance; ?>">
  604. <?php _e('Title:', 'prologue-projects'); ?>
  605. <input class="widefat" id="pp_widget_user_projects_title_<?php echo $instance; ?>" name="pp_widget_user_projects[<?php echo $instance; ?>][title]" type="text" value="<?php echo $title; ?>" />
  606. </label>
  607. </p>
  608. <input type="hidden" id="pp_widget_user_projects_submit" name="pp_widget_user_projects[<?php echo $instance; ?>][submit]" value="1" />
  609. <?php
  610. }
  611. }
  612. }
  613. // Generate sidebars
  614. pp_generate_sidebars();
  615. // Register widgets
  616. new PP_Widget_Project_Tree();
  617. new PP_Widget_Project_Team();
  618. new PP_Widget_Featured_Project();
  619. new PP_Widget_User_Projects();
  620. ?>