PageRenderTime 92ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/nonus/framework/types/ctPostTypeBase.class.php

https://github.com/alniko009/magic
PHP | 252 lines | 170 code | 32 blank | 50 comment | 9 complexity | db64b30f968acffb0dae544a2f7074f9 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. require_once 'ctTypeBase.class.php';
  3. /**
  4. * Post type handler
  5. * @author hc
  6. */
  7. class ctPostTypeBase extends ctTypeBase {
  8. /**
  9. * Slug option name
  10. */
  11. const OPTION_SLUG = 'post_index_slug';
  12. /**
  13. * Initializes events
  14. * @return mixed|void
  15. */
  16. public function init() {
  17. add_action("admin_init", array($this, "addMetaBox"));
  18. /** @var $NHP_Options NHP_Options */
  19. global $NHP_Options;
  20. //add options listener for license
  21. add_action('nhp-opts-options-validate-' . $NHP_Options->args['opt_name'], array($this, 'handleSlugOptionSaved'));
  22. }
  23. /**
  24. * Adds meta box
  25. */
  26. public function addMetaBox() {
  27. wp_register_script('ct.post',CT_THEME_ADMIN_ASSETS_URI.'/js/post.js',array('jquery'));
  28. wp_enqueue_script('ct.post');
  29. add_meta_box("post-gallery-meta", __("Gallery format settings", 'ct_theme'), array($this, "postGalleryMeta"), "post", "normal", "high");
  30. add_meta_box("post-link-meta", __("Link format settings", 'ct_theme'), array($this, "postLinkMeta"), "post", "normal", "high");
  31. add_meta_box("post-quote-meta", __("Quote format settings", 'ct_theme'), array($this, "postQuoteMeta"), "post", "normal", "high");
  32. add_meta_box("post-video-meta", __("Video format settings", 'ct_theme'), array($this, "postVideoMeta"), "post", "normal", "high");
  33. add_meta_box("post-audio-meta", __("Audio format settings", 'ct_theme'), array($this, "postAudioMeta"), "post", "normal", "high");
  34. add_action('save_post', array($this, 'saveDetails'));
  35. }
  36. /**
  37. * Gets hook name
  38. * @return string
  39. */
  40. protected function getHookBaseName() {
  41. return 'ct_post';
  42. }
  43. /**
  44. * Returns permalink slug
  45. * @return string
  46. */
  47. protected function getPermalinkSlug() {
  48. // Rewriting Permalink Slug
  49. $permalink_slug = ct_get_option('post_index_slug', 'post');
  50. if (empty($permalink_slug)) {
  51. $permalink_slug = 'post';
  52. }
  53. return $permalink_slug;
  54. }
  55. /**
  56. * Draws post gallery format settings
  57. */
  58. public function postGalleryMeta() {
  59. global $post;
  60. $custom = get_post_custom($post->ID);
  61. $displayMethod = isset($custom['display_method'][0]) ? $custom['display_method'][0] : 'image';
  62. $revolution_slider = isset($custom['revolution_slider'][0]) ? $custom['revolution_slider'][0] : '';
  63. if ($supportsRevolutionSlider = function_exists('rev_slider_shortcode')) {
  64. global $wpdb;
  65. $slides = $wpdb->get_results("SELECT * FROM ".GlobalsRevSlider::$table_sliders);
  66. }
  67. ?>
  68. <p>
  69. <label for="display_method"><?php _e('Show portfolio item as', 'ct_theme')?>: </label>
  70. <select class="ct-toggler" id="display_method" name="display_method">
  71. <option data-group=".display" data-toggle=".ct-toggable.gallery" value="gallery" <?php echo selected('gallery', $displayMethod)?>><?php _e("Gallery", 'ct_theme')?></option>
  72. <?php if ($supportsRevolutionSlider): ?>
  73. <option data-group=".display" data-toggle=".ct-toggable.revolution-slider" value="revolution-slider" <?php echo selected('revolution-slider', $displayMethod)?>><?php _e("Revolution slider gallery", 'ct_theme')?></option>
  74. <?php endif;?>
  75. </select>
  76. </p>
  77. <p class="howto"><?php _e("You can use the post images gallery. If the Revolution Slider module is installed, you can also use it to create your custom gallery.", 'ct_theme')?></p>
  78. <?php if ($supportsRevolutionSlider): ?>
  79. <p class="ct-toggable revolution-slider display">
  80. <label for="revolutionSlider"><?php _e('Revolution slider', 'ct_theme')?>: </label>
  81. <select id="revolutionSlider" name="revolution_slider">
  82. <?php foreach ($slides as $slide): ?>
  83. <option <?php echo selected($slide->alias, $revolution_slider)?> value="<?php echo $slide->alias?>"><?php echo $slide->title?></option>
  84. <?php endforeach;?>
  85. </select>
  86. </p>
  87. <p class="howto ct-toggable revolution-slider display"><?php _e("Choose your revolution slider gallery", 'ct_theme')?></p>
  88. <?php endif; ?>
  89. <?php
  90. }
  91. /**
  92. * Draws post link format settings
  93. */
  94. public function postLinkMeta() {
  95. global $post;
  96. $custom = get_post_custom($post->ID);
  97. $link = isset($custom["link"][0]) ? $custom["link"][0] : "";
  98. ?>
  99. <p>
  100. <label for="link"><?php _e('Link', 'ct_theme')?>: </label>
  101. <input type="text" id="link" class="regular-text" name="link" value="<?php echo $link; ?>"/>
  102. </p>
  103. <p class="howto"><?php _e("Input your link. Example: http://www.google.com", 'ct_theme')?></p>
  104. <?php
  105. }
  106. /**
  107. * Draws post quote format settings
  108. */
  109. public function postQuoteMeta() {
  110. global $post;
  111. $custom = get_post_custom($post->ID);
  112. $quote = isset($custom["quote"][0]) ? $custom["quote"][0] : "";
  113. ?>
  114. <p>
  115. <label for="quote"><?php _e('Quote', 'ct_theme')?>: </label>
  116. <textarea id="quote" class="regular-text" name="quote" cols="100" rows="10"><?php echo $quote; ?></textarea>
  117. </p>
  118. <p class="howto"><?php _e("Quote content", 'ct_theme')?></p>
  119. <?php
  120. }
  121. /**
  122. * Draws post video format settings
  123. */
  124. public function postVideoMeta() {
  125. global $post;
  126. $custom = get_post_custom($post->ID);
  127. $videoM4V = isset($custom["videoM4V"][0]) ? $custom["videoM4V"][0] : "";
  128. $videoOGV = isset($custom["videoOGV"][0]) ? $custom["videoOGV"][0] : "";
  129. $videoDirect = isset($custom["videoDirect"][0]) ? $custom["videoDirect"][0] : "";
  130. $videoCode = isset($custom["videoCode"][0]) ? $custom["videoCode"][0] : "";
  131. ?>
  132. <p>
  133. <label for="videoM4V"><?php _e('M4V File URL', 'ct_theme')?>: </label>
  134. <input type="text" id="videoM4V" class="regular-text" name="videoM4V" value="<?php echo $videoM4V; ?>"/>
  135. </p>
  136. <p class="howto"><?php _e("The URL to the .m4v video file", 'ct_theme')?></p>
  137. <p>
  138. <label for="videoOGV"><?php _e('OGV File URL', 'ct_theme')?>: </label>
  139. <input type="text" id="videoOGV" class="regular-text" name="videoOGV" value="<?php echo $videoOGV; ?>"/>
  140. </p>
  141. <p class="howto"><?php _e("The URL to the .ogv video file", 'ct_theme')?></p>
  142. <p>
  143. <label for="videoDirect"><?php _e('Direct video URL', 'ct_theme')?>: </label>
  144. <input type="text" id="videoDirect" class="regular-text" name="videoDirect" value="<?php echo $videoDirect; ?>"/>
  145. </p>
  146. <p class="howto"><?php _e("Direct movie link to embed movie from popular services like Youtube, Vimeo, Dailymotion", 'ct_theme')?></p>
  147. <p>
  148. <label for="videoCode"><?php _e('Embedded Code', 'ct_theme')?>: </label>
  149. <textarea id="videoCode" class="regular-text" name="videoCode" cols="100" rows="10"><?php echo $videoCode; ?></textarea>
  150. </p>
  151. <p class="howto"><?php _e("You can use any custom embed code.", 'ct_theme')?></p>
  152. <?php
  153. }
  154. /**
  155. * Draws post video format settings
  156. */
  157. public function postAudioMeta() {
  158. global $post;
  159. $custom = get_post_custom($post->ID);
  160. $audioMP3 = isset($custom["audioMP3"][0]) ? $custom["audioMP3"][0] : "";
  161. $audioOGA = isset($custom["audioOGA"][0]) ? $custom["audioOGA"][0] : "";
  162. $audioPoster = isset($custom["audioPoster"][0]) ? $custom["audioPoster"][0] : "";
  163. $audioPosterHeight = isset($custom["audioPosterHeight"][0]) ? $custom["audioPosterHeight"][0] : "";
  164. ?>
  165. <p>
  166. <label for="audioMP3"><?php _e('MP3 File URL', 'ct_theme')?>: </label>
  167. <input type="text" id="audioMP3" class="regular-text" name="audioMP3" value="<?php echo $audioMP3; ?>"/>
  168. </p>
  169. <p class="howto"><?php _e("The URL to the .mp3 audio file", 'ct_theme')?></p>
  170. <p>
  171. <label for="audioOGA"><?php _e('OGA File URL', 'ct_theme')?>: </label>
  172. <input type="text" id="audioOGA" class="regular-text" name="audioOGA" value="<?php echo $audioOGA; ?>"/>
  173. </p>
  174. <p class="howto"><?php _e("The URL to the .oga, .ogg audio file", 'ct_theme')?></p>
  175. <p>
  176. <label for="audioPoster"><?php _e('Poster URL', 'ct_theme')?>: </label>
  177. <input type="text" id="audioPoster" class="regular-text" name="audioPoster" value="<?php echo $audioPoster; ?>"/>
  178. </p>
  179. <p class="howto"><?php _e("The URL to the poster file", 'ct_theme')?></p>
  180. <p>
  181. <label for="audioPosterHeight"><?php _e('Poster height', 'ct_theme')?>: </label>
  182. <input type="text" id="audioPosterHeight" class="regular-text" name="audioPosterHeight" value="<?php echo $audioPosterHeight; ?>"/>
  183. </p>
  184. <p class="howto"><?php _e("The height of the poster", 'ct_theme')?></p>
  185. <?php
  186. }
  187. public function saveDetails() {
  188. global $post;
  189. $fields = array('link', 'quote', 'videoM4V', 'videoOGV', 'videoDirect', 'videoCode', 'audioMP3', 'audioOGA', 'audioPoster', 'audioPosterHeight');
  190. foreach ($fields as $field) {
  191. if (isset($_POST[$field])) {
  192. update_post_meta($post->ID, $field, $_POST[$field]);
  193. }
  194. }
  195. }
  196. /**
  197. * Handles rebuild
  198. */
  199. public function handleSlugOptionSaved($newValues) {
  200. $currentSlug = $this->getPermalinkSlug();
  201. //rebuild rewrite if new slug
  202. if (isset($newValues[self::OPTION_SLUG]) && ($currentSlug != $newValues[self::OPTION_SLUG])) {
  203. $this->callHook('pre_slug_option_saved', array('current_slug' => $currentSlug, 'new_slug' => $newValues[self::OPTION_SLUG]));
  204. //clean rewrite to refresh it
  205. delete_option('rewrite_rules');
  206. }
  207. }
  208. /**
  209. * Gets display method for portfolio
  210. * @param array $meta - post meta
  211. * @return null|string
  212. */
  213. public static function getMethodFromMeta($meta) {
  214. $method = isset($meta['display_method']) ? $meta['display_method'][0] : null;
  215. if (!$method) {
  216. $method = '';
  217. }
  218. return $method ? $method : 'gallery';
  219. }
  220. }