/admin/admin-options-home.php

https://github.com/loualvarez/Franklin-Street-Theme · PHP · 186 lines · 143 code · 36 blank · 7 comment · 24 complexity · 38378d41b7d656760e34cedf7e23f91e MD5 · raw file

  1. <?php
  2. // default data for first run
  3. $franklin_defaults = array(
  4. 'title' => 'Section Title',
  5. 'caption' => 'Section Caption',
  6. 'num_posts' => 10
  7. );
  8. ?>
  9. <div class="wrap">
  10. <div id="icon-options-general" class="icon32"><br /></div>
  11. <h2><?php _e('Franklin Street - Home Page Sections', 'franklinstreet'); ?></h2>
  12. <?php
  13. $franklin_updated = false;
  14. if ( !empty( $_POST ) && wp_verify_nonce( $_POST['franklin_key'], 'franklin_update_home_sections' ) )
  15. {
  16. $franklin_content_sections = array();
  17. foreach( $_POST as $key => $value )
  18. {
  19. $keyflag = 'franklin-display-type-';
  20. if( substr( $key, 0, strlen( $keyflag ) ) == $keyflag )
  21. {
  22. // find our ID flag
  23. $franklin_section_flag = substr( $key, strlen( $keyflag ), strlen( $key ) );
  24. // since we're piggybacking some WP core functionality, the
  25. // post categories have a slightly different ID depending on what was first
  26. if( $franklin_section_flag == 'default' )
  27. {
  28. $franklin_post_category_flag = '';
  29. }
  30. else
  31. {
  32. $franklin_post_category_flag = '-' . $franklin_section_flag;
  33. }
  34. // add our data
  35. $franklin_content_sections[] = array(
  36. 'display_type' => $_POST['franklin-display-type-' . $franklin_section_flag],
  37. 'title' => $_POST['franklin-section-title-' . $franklin_section_flag],
  38. 'caption' => $_POST['franklin-section-caption-' . $franklin_section_flag],
  39. 'num_posts' => intval( $_POST['franklin-section-num-posts-' . $franklin_section_flag] ),
  40. 'categories' => $_POST['post_category' . $franklin_post_category_flag]
  41. );
  42. }
  43. }
  44. update_option( '_franklin_street_home_sections', $franklin_content_sections );
  45. $franklin_updated = true;
  46. }
  47. // we need to pull our existing sections, if present
  48. $franklin_street_sections = get_option( '_franklin_street_home_sections' );
  49. // if there's nothing, we'll set our defaults
  50. if( empty( $franklin_street_sections ) )
  51. {
  52. $franklin_street_sections[] = array(
  53. 'display_type' => 'one_up_reg',
  54. 'title' => '',
  55. 'caption' => '',
  56. 'num_posts' => '',
  57. 'categories' => array(),
  58. 'default' => true
  59. );
  60. }
  61. ?>
  62. <?php if( $franklin_updated ) : ?>
  63. <div class="message updated">
  64. <p><strong>Franklin Street</strong> home page sections updated.</p>
  65. </div>
  66. <!-- /message -->
  67. <?php endif ?>
  68. <h3><?php _e('Content Sections', 'franklinstreet'); ?></h3>
  69. <form action="" method="post">
  70. <?php wp_nonce_field( 'franklin_update_home_sections', 'franklin_key' ); ?>
  71. <div id="franklin-content-sections">
  72. <?php foreach( $franklin_street_sections as $franklin_street_section_id => $franklin_street_section ) : ?>
  73. <div class="franklin-content-section franklin-group<?php if( isset( $franklin_street_section['default'] ) ) : ?> franklin-content-section-default<?php endif ?>" id="franklin-street-section-<?php echo $franklin_street_section_id; ?>">
  74. <span class="franklin-handle"></span>
  75. <a class="franklin-content-section-delete" href="#">X</a>
  76. <div class="franklin-display-type">
  77. <label for="franklin-display-type-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>"><?php _e('Display Type:', 'franklinstreet'); ?></label>
  78. <select name="franklin-display-type-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>" id="franklin-display-type-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>">
  79. <option<?php if( $franklin_street_section['display_type'] == 'franklin_street_loop' ) : ?> selected="selected"<?php endif ?> value="franklin_street_loop"><?php _e('Franklin Street Loop', 'franklinstreet'); ?></option>
  80. <option<?php if( $franklin_street_section['display_type'] == 'one_up_reg' ) : ?> selected="selected"<?php endif ?> value="one_up_reg"><?php _e('One Up (Regular)', 'franklinstreet'); ?></option>
  81. <option<?php if( $franklin_street_section['display_type'] == 'one_up_lg' ) : ?> selected="selected"<?php endif ?> value="one_up_lg"><?php _e('One Up (Large)', 'franklinstreet'); ?></option>
  82. <option<?php if( $franklin_street_section['display_type'] == 'two_up' ) : ?> selected="selected"<?php endif ?> value="two_up"><?php _e('Two Up', 'franklinstreet'); ?></option>
  83. <option<?php if( $franklin_street_section['display_type'] == 'four_up' ) : ?> selected="selected"<?php endif ?> value="four_up"><?php _e('Four Up', 'franklinstreet'); ?></option>
  84. <option<?php if( $franklin_street_section['display_type'] == 'right_aside' ) : ?> selected="selected"<?php endif ?> value="right_aside"><?php _e('Right Aside', 'franklinstreet'); ?></option>
  85. <option<?php if( $franklin_street_section['display_type'] == 'default_loop' ) : ?> selected="selected"<?php endif ?> value="default_loop"><?php _e('Default Loop', 'franklinstreet'); ?></option>
  86. </select>
  87. </div>
  88. <!-- /franklin-display-type -->
  89. <div class="franklin-meta franklin-group">
  90. <div class="franklin-meta franklin-fields">
  91. <ul>
  92. <li class="franklin-section-title">
  93. <label for="franklin-section-title-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>"><?php _e('Section Title', 'franklinstreet'); ?></label>
  94. <input type="text" name="franklin-section-title-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>" id="franklin-section-title-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>" value="<?php echo !isset( $franklin_street_section['default'] ) ? stripslashes( $franklin_street_section['title'] ) : $franklin_defaults['title']; ?>" />
  95. </li>
  96. <li class="franklin-section-caption">
  97. <label for="franklin-section-caption-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>"><?php _e('Section Caption', 'franklinstreet'); ?></label>
  98. <textarea name="franklin-section-caption-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>" id="franklin-section-caption-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>"><?php echo !isset( $franklin_street_section['default'] ) ? stripslashes( $franklin_street_section['caption'] ) : $franklin_defaults['caption']; ?></textarea>
  99. </li>
  100. <li class="franklin-section-num-posts">
  101. <label for="franklin-section-num-posts-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>"><?php _e('Number of Posts', 'franklinstreet'); ?></label>
  102. <input type="text" name="franklin-section-num-posts-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>" id="franklin-section-num-posts-<?php echo ( isset( $franklin_street_section['default'] ) ? 'default' : $franklin_street_section_id ); ?>" value="<?php echo !isset( $franklin_street_section['default'] ) ? stripslashes( $franklin_street_section['num_posts'] ) : $franklin_defaults['num_posts']; ?>" />
  103. </li>
  104. </ul>
  105. </div>
  106. <!-- /franklin-meta- franklin-fields -->
  107. <div class="franklin-meta franklin-categories categorydiv">
  108. <p><?php _e('Categories to Display', 'franklinstreet'); ?></p>
  109. <div class="tabs-panel">
  110. <ul class="categorychecklist">
  111. <?php wp_terms_checklist( ) ?>
  112. </ul>
  113. </div>
  114. <!-- /tabs-panel -->
  115. <!-- in order to keep things WP standard, we're going to auto-check via jQuery -->
  116. <script type="text/javascript">
  117. jQuery(document).ready(function(){
  118. <?php foreach( $franklin_street_section['categories'] as $category ) : ?>
  119. jQuery('#franklin-street-section-<?php echo $franklin_street_section_id; ?> ul.categorychecklist input').each(function(){
  120. if(jQuery(this).val()==<?php echo $category; ?>){
  121. jQuery(this).attr('checked', true);
  122. }
  123. })
  124. <?php endforeach; ?>
  125. });
  126. </script>
  127. <ul class="franklin-group">
  128. <li><a class="button franklin-select" href="#"><?php _e('Select All', 'franklinstreet'); ?></a></li>
  129. <li><a class="button franklin-deselect" href="#"><?php _e('Deselect All', 'franklinstreet'); ?></a></li>
  130. </ul>
  131. </div>
  132. <!-- /franklin-meta- franklin-categories -->
  133. </div>
  134. <!-- /franklin-meta franklin-group -->
  135. </div>
  136. <!-- /franklin-content-section -->
  137. <?php endforeach; ?>
  138. </div>
  139. <!-- /franklin-content-sections -->
  140. <div id="franklin-add-content-section">
  141. <a href="#"><?php _e('Add New Section', 'franklinstreet'); ?></a>
  142. </div>
  143. <!-- /franklin-add-content-section -->
  144. <div id="franklin-save">
  145. <p class="submit">
  146. <input type="submit" class="button-primary" value="<?php _e('Save', 'franklinstreet'); ?>" />
  147. </p>
  148. </div>
  149. </form>
  150. </div>