| 1 |
<?php |
| 2 |
|
| 3 |
defined('ABSPATH') || exit; |
| 4 |
|
| 5 |
/** |
| 6 |
* Module Name: Portfolio |
| 7 |
* Description: Display portfolio custom post type |
| 8 |
*/ |
| 9 |
class TB_Portfolio_Module extends Themify_Builder_Component_Module {//deprecated |
| 10 |
const SLUG='portfolio'; |
| 11 |
public static function init():void { |
| 12 |
/////////////////////////////////////// |
| 13 |
// Load Post Type |
| 14 |
/////////////////////////////////////// |
| 15 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 16 |
if (!Themify_Builder_Model::is_plugin_active('themify-portfolio-post/themify-portfolio-post.php')) { |
| 17 |
add_filter('themify_metabox/fields/themify-meta-boxes', array(__CLASS__, 'cpt_meta_boxes'), 100); // requires low priority so that it loads after theme's metaboxes |
| 18 |
if (!shortcode_exists('themify_portfolio_posts')) { |
| 19 |
add_shortcode('themify_portfolio_posts', array(__CLASS__, 'do_shortcode')); |
| 20 |
} |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
public static function is_available():bool{ |
| 25 |
return Themify_Builder_Model::is_cpt_active(self::SLUG); |
| 26 |
} |
| 27 |
|
| 28 |
public static function get_module_name():string { |
| 29 |
add_filter( 'themify_builder_active_vars', [ __CLASS__, 'builder_active_enqueue' ] ); |
| 30 |
return __('Portfolio', 'themify'); |
| 31 |
} |
| 32 |
|
| 33 |
public static function get_module_icon():string { |
| 34 |
return 'briefcase'; |
| 35 |
} |
| 36 |
|
| 37 |
public static function get_js_css():array { |
| 38 |
return array( |
| 39 |
'css' => array('post' => 'post') |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
public static function get_json_file():array{ |
| 44 |
return ['f'=>THEMIFY_BUILDER_URI.'/json/'.self::SLUG.'.json','v'=>THEMIFY_VERSION]; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
public static function builder_active_enqueue(array $vars ):array { |
| 49 |
$vars['addons'][THEMIFY_BUILDER_URI . '/js/editor/deprecated/'.self::SLUG.'.js']=THEMIFY_VERSION; |
| 50 |
return $vars; |
| 51 |
} |
| 52 |
|
| 53 |
public static function get_metabox() { |
| 54 |
/** Portfolio Meta Box Options */ |
| 55 |
return array( |
| 56 |
// Featured Image Size |
| 57 |
Themify_Builder_Model::$featured_image_size, |
| 58 |
// Image Width |
| 59 |
Themify_Builder_Model::$image_width, |
| 60 |
// Image Height |
| 61 |
Themify_Builder_Model::$image_height, |
| 62 |
// Hide Title |
| 63 |
array( |
| 64 |
'name' => 'hide_post_title', |
| 65 |
'title' => __('Hide Post Title', 'themify'), |
| 66 |
'description' => '', |
| 67 |
'type' => 'dropdown', |
| 68 |
'meta' => array( |
| 69 |
array('value' => 'default', 'name' => '', 'selected' => true), |
| 70 |
array('value' => 'yes', 'name' => __('Yes', 'themify')), |
| 71 |
array('value' => 'no', 'name' => __('No', 'themify')) |
| 72 |
) |
| 73 |
), |
| 74 |
// Unlink Post Title |
| 75 |
array( |
| 76 |
'name' => 'unlink_post_title', |
| 77 |
'title' => __('Unlink Post Title', 'themify'), |
| 78 |
'description' => __('Unlink post title (it will display the post title without link)', 'themify'), |
| 79 |
'type' => 'dropdown', |
| 80 |
'meta' => array( |
| 81 |
array('value' => 'default', 'name' => '', 'selected' => true), |
| 82 |
array('value' => 'yes', 'name' => __('Yes', 'themify')), |
| 83 |
array('value' => 'no', 'name' => __('No', 'themify')) |
| 84 |
) |
| 85 |
), |
| 86 |
// Hide Post Date |
| 87 |
array( |
| 88 |
'name' => 'hide_post_date', |
| 89 |
'title' => __('Hide Post Date', 'themify'), |
| 90 |
'description' => '', |
| 91 |
'type' => 'dropdown', |
| 92 |
'meta' => array( |
| 93 |
array('value' => 'default', 'name' => '', 'selected' => true), |
| 94 |
array('value' => 'yes', 'name' => __('Yes', 'themify')), |
| 95 |
array('value' => 'no', 'name' => __('No', 'themify')) |
| 96 |
) |
| 97 |
), |
| 98 |
// Hide Post Meta |
| 99 |
array( |
| 100 |
'name' => 'hide_post_meta', |
| 101 |
'title' => __('Hide Post Meta', 'themify'), |
| 102 |
'description' => '', |
| 103 |
'type' => 'dropdown', |
| 104 |
'meta' => array( |
| 105 |
array('value' => 'default', 'name' => '', 'selected' => true), |
| 106 |
array('value' => 'yes', 'name' => __('Yes', 'themify')), |
| 107 |
array('value' => 'no', 'name' => __('No', 'themify')) |
| 108 |
) |
| 109 |
), |
| 110 |
// Hide Post Image |
| 111 |
array( |
| 112 |
'name' => 'hide_post_image', |
| 113 |
'title' => __('Hide Featured Image', 'themify'), |
| 114 |
'description' => '', |
| 115 |
'type' => 'dropdown', |
| 116 |
'meta' => array( |
| 117 |
array('value' => 'default', 'name' => '', 'selected' => true), |
| 118 |
array('value' => 'yes', 'name' => __('Yes', 'themify')), |
| 119 |
array('value' => 'no', 'name' => __('No', 'themify')) |
| 120 |
) |
| 121 |
), |
| 122 |
// Unlink Post Image |
| 123 |
array( |
| 124 |
'name' => 'unlink_post_image', |
| 125 |
'title' => __('Unlink Featured Image', 'themify'), |
| 126 |
'description' => __('Display the Featured Image without link', 'themify'), |
| 127 |
'type' => 'dropdown', |
| 128 |
'meta' => array( |
| 129 |
array('value' => 'default', 'name' => '', 'selected' => true), |
| 130 |
array('value' => 'yes', 'name' => __('Yes', 'themify')), |
| 131 |
array('value' => 'no', 'name' => __('No', 'themify')) |
| 132 |
) |
| 133 |
), |
| 134 |
// External Link |
| 135 |
Themify_Builder_Model::$external_link, |
| 136 |
// Lightbox Link |
| 137 |
Themify_Builder_Model::$lightbox_link |
| 138 |
); |
| 139 |
} |
| 140 |
|
| 141 |
public static function do_shortcode($atts) { |
| 142 |
|
| 143 |
$atts = shortcode_atts(array( |
| 144 |
'id' => '', |
| 145 |
'title' => 'yes', |
| 146 |
'unlink_title' => 'no', |
| 147 |
'image' => 'yes', // no |
| 148 |
'image_w' => '', |
| 149 |
'image_h' => '', |
| 150 |
'display' => 'none', // excerpt, content |
| 151 |
'post_meta' => 'yes', // yes |
| 152 |
'post_date' => 'yes', // yes |
| 153 |
'more_link' => false, // true goes to post type archive, and admits custom link |
| 154 |
'more_text' => __('More →', 'themify'), |
| 155 |
'limit' => 4, |
| 156 |
'category' => 0, // integer category ID |
| 157 |
'order' => 'DESC', // ASC |
| 158 |
'orderby' => 'date', // title, rand |
| 159 |
'style' => '', // grid3, grid2 |
| 160 |
'sorting' => 'no', // yes |
| 161 |
'page_nav' => 'no', // yes |
| 162 |
'paged' => '0', // internal use for pagination, dev: previously was 1 |
| 163 |
// slider parameters |
| 164 |
'autoplay' => '', |
| 165 |
'effect' => '', |
| 166 |
'timeout' => '', |
| 167 |
'speed' => '' |
| 168 |
), $atts); |
| 169 |
|
| 170 |
$module = array( |
| 171 |
'module_ID' => self::SLUG.'-' . rand(0, 10000), |
| 172 |
'mod_name' => self::SLUG, |
| 173 |
'mod_settings' => array( |
| 174 |
'mod_title_portfolio' => '', |
| 175 |
'layout_portfolio' => $atts['style'], |
| 176 |
'category_portfolio' => $atts['category'], |
| 177 |
'post_per_page_portfolio' => $atts['limit'], |
| 178 |
'offset_portfolio' => '', |
| 179 |
'order_portfolio' => $atts['order'], |
| 180 |
'orderby_portfolio' => $atts['orderby'], |
| 181 |
'display_portfolio' => $atts['display'], |
| 182 |
'hide_feat_img_portfolio' => $atts['image'] === 'yes' ? 'no' : 'yes', |
| 183 |
'image_size_portfolio' => '', |
| 184 |
'img_width_portfolio' => $atts['image_w'], |
| 185 |
'img_height_portfolio' => $atts['image_h'], |
| 186 |
'unlink_feat_img_portfolio' => 'no', |
| 187 |
'hide_post_title_portfolio' => $atts['title'] === 'yes' ? 'no' : 'yes', |
| 188 |
'unlink_post_title_portfolio' => $atts['unlink_title'], |
| 189 |
'hide_post_date_portfolio' => $atts['post_date'] === 'yes' ? 'no' : 'yes', |
| 190 |
'hide_post_meta_portfolio' => $atts['post_meta'] === 'yes' ? 'no' : 'yes', |
| 191 |
'hide_page_nav_portfolio' => $atts['page_nav'] === 'no' ? 'yes' : 'no', |
| 192 |
'animation_effect' => '', |
| 193 |
'css_portfolio' => '' |
| 194 |
) |
| 195 |
); |
| 196 |
|
| 197 |
return self::retrieve_template('template-blog.php', $module, THEMIFY_BUILDER_TEMPLATES_DIR, '', false); |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* Render plain content for static content. |
| 202 |
* |
| 203 |
* @param array $module |
| 204 |
* @return string |
| 205 |
*/ |
| 206 |
public static function get_static_content(array $module):string { |
| 207 |
return ''; // no static content for dynamic content |
| 208 |
} |
| 209 |
|
| 210 |
public static function get_translatable_text_fields( $module ) : array { |
| 211 |
return [ 'mod_title_portfolio' ]; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
TB_Portfolio_Module::init(); //deprecated |
| 217 |
|