public function get_time($format = 'U', $time = 'now', $timezone = null) { static $i = 1; $timezone = !empty($timezone) ? new \DateTimeZone($timezone) : $this->timezone; $time_convert = (int) $time; if (empty($time_convert)) { $obj = new \DateTime($time, $timezone); } else { $obj = new \DateTime(null, $timezone); $obj->setTimestamp($time_convert); } /* if (is_int($time)) { $obj = new \DateTime(null, new \DateTimeZone($timezone)); $obj->setTimestamp($time); } else { try { $obj = new \DateTime($time, new \DateTimeZone($timezone)); } catch (\Exception $e) { $caught = true; $obj = new \DateTime(null, new \DateTimeZone($timezone)); $obj->setTimestamp($time); } } */ $result = $obj->format($format); if ($i > 200 && isset($caught)) { \Cibulka::Plugin('base')->Dump($time, $result); } $i++; return $result; }
protected function translate_value($timestamp, $format = 'Y/m/d H:i') { if (empty($timestamp)) { return null; } $result = \Cibulka::Theme('Date')->get_time($timestamp, $format); return $result; }
public function get_field_output_default($field_i, $group_item_i) { $attrs = $this->get_attrs($field_i, $group_item_i, true); $value = $this->get_value($field_i, $group_item_i); $input = \Cibulka::Base('HTML', 'input', $attrs, true); $result = $this->get_common_wrap($input, $field_i, $group_item_i); return $result; }
protected function get_separator_str($separator) { if ($this->is_dev()) { $separator[2] = \Cibulka::Base('HTML', 'p', array('class' => 'description'), false, $this->get_glue_key(null) . ' / ' . $this->get_glue(null)); } $result = parent::get_separator_str($separator); return $result; }
public function get_field_output_default($field_i, $group_item_i) { $attrs = $this->get_attrs($field_i, $group_item_i, true); $value = $this->get_value($field_i, $group_item_i); $attrs['value'] = !empty($value) ? $value : $this->config['args']['default_f']; $input = \Cibulka::Base('HTML', 'input', $attrs, true); $result = $this->get_common_wrap($input, $field_i, $group_item_i); return $result; }
protected function get_edit_link($term_id) { if (empty($term_id)) { return null; } $url = get_edit_term_link($term_id, $this->config['args']['taxonomy']); $result = \Cibulka::Base('HTML', 'a', array('target' => '_blank', 'href' => $url, 'class' => 'edit-link'), false, 'Upravit termín'); return $result; }
protected function get_edit_link($post_id) { if (empty($post_id)) { return null; } $url = get_edit_post_link($post_id); $result = \Cibulka::Base('HTML', 'a', array('target' => '_blank', 'href' => $url, 'class' => 'edit-link'), false, 'Upravit článek'); return $result; }
public function get_value($field_i = null, $group_i = null, $name = false) { if (!$this->is_excerpt()) { return parent::get_value($field_i, $group_i); } global $post; $excerpt = \Cibulka::Base('Post_Excerpt', $post->ID, false, false); return $excerpt; }
public function get_html_noresp($media_id, $size = null, array $attrs = array(), $square = false, $use_fallback = false) { $img_src = wp_get_attachment_image_url($media_id, $size); if (empty($img_src)) { $result = $use_fallback ? call_user_func_array(array($this, 'get_html_fallback'), func_get_args()) : false; return $result; } $attrs = array_merge(array('src' => $img_src), $attrs); $result = \Cibulka::Base('HTML', 'img', $attrs, true); return $result; }
public function get_field_output_default($field_i, $group_item_i) { $attrs = $this->get_attrs($field_i, $group_item_i, true); $value = $this->get_value($field_i, $group_item_i); $attrs['value'] = !empty($value) ? $value : $this->config['args']['default']; $input = '<div class="l-table range-table">'; $input .= \Cibulka::Base('HTML', 'span', array('id' => $this->get_id($field_i, $group_item_i) . '__cur', 'class' => 'l-cell range-table__val'), false, $attrs['value']); $input .= \Cibulka::Base('HTML', 'span', array('id' => $this->get_id($field_i, $group_item_i) . '__min', 'class' => 'l-cell'), false, $attrs['min']); $input .= \Cibulka::Base('HTML', 'span', array('class' => 'l-cell'), false, \Cibulka::Base('HTML', 'input', $attrs, true)); $input .= \Cibulka::Base('HTML', 'span', array('id' => $this->get_id($field_i, $group_item_i) . '__max', 'class' => 'l-cell'), false, $attrs['max']); $input .= '</div>'; $result = $this->get_common_wrap($input, $field_i, $group_item_i); return $result; }
protected function get_option($option_key, $option_val, $value) { $attrs = array('value' => $option_val); $default = $this->config['args']['default']; $is_selected = false; if ($option_val === false) { $attrs['disabled'] = 'disabled'; } if (!$is_selected && (!empty($value) && $value == $option_val || empty($value) && $default == $option_val)) { $attrs['selected'] = 'selected'; $is_selected = true; } $attrs['data-default'] = $default == $option_val; $result = \Cibulka::Base('HTML', 'option', $attrs, false, $option_key); return $result; }
protected function get_option(array $attrs, $value, $k, $v, $default, $i, $checked = 0) { $result = ''; if ($i > 1) { $attrs['id'] .= '__' . $i; } $label = \Cibulka::Base('HTML', 'label', array('for' => $attrs['id'], 'class' => 'cibulka-radio js-increment-attrs l-row')); if (is_bool($checked) && $checked || $this->is_checked($value, $default, $v)) { $attrs['checked'] = 'checked'; } $attrs['data-default'] = $default == $v; $result .= $label->start(); $result .= '<span class="cibulka-radio__txt l-cell l-pad-r">' . $k . '</span><span class="cibulka-radio__button l-cell">'; $result .= \Cibulka::Base('HTML', 'input', array_replace($attrs, array('type' => 'radio', 'value' => $v, 'class' => 'radio-button js-increment-attrs')), true); $result .= '</span>' . $label->end(); return $result; }
protected function get_option(array $attrs, $value, $k, $v, $default, $i, $checked = 0) { if ($v === '%text%') { if (!empty($value)) { $checked = !in_array($value, $this->config['args']['values']); $v = $checked ? $value : $v; $disabled = $checked; } else { $checked = false; $is_custom = false; $disabled = 'disabled'; } $result = parent::get_option($attrs, $value, $k, $v, $default, $i, $checked); $result .= \Cibulka::Base('HTML', 'input', array('type' => 'text', 'disabled' => $disabled, 'class' => 'radio-text', 'value' => $checked ? $value : '')); } else { $result = parent::get_option($attrs, $value, $k, $v, $default, $i, $checked); } return $result; }
public function get_field_output_default($field_i, $group_item_i) { $result = ''; $txt_attrs = $this->get_attrs($field_i . '_autocomplete', $group_item_i, true); $txt_attrs['type'] = 'text'; $txt_attrs['class'] .= ' cibulka-autocomplete'; $txt_attrs['value'] = $this->translate_value($this->get_value($field_i, $group_item_i)); $txt_attrs = array_replace($txt_attrs, $this->get_txt_attrs($field_i, $group_item_i)); $input_txt = \Cibulka::Base('HTML', 'input', $txt_attrs, true); $hide_attrs = $this->get_attrs($field_i, $group_item_i, true); $hide_attrs['type'] = $this->is_dev() ? 'text' : 'hidden'; $hide_attrs['class'] .= ' autocomplete--target'; $hide_attrs['value'] = $this->get_value($field_i, $group_item_i); $input_hide = \Cibulka::Base('HTML', 'input', $hide_attrs, true); if ($this->config['args']['print_link']) { $print_link = $this->get_edit_link($hide_attrs['value']); } else { $print_link = null; } $result = $this->get_common_wrap($input_txt . $input_hide . $print_link, $field_i, $group_item_i); return $result; }
/** * Init PRINT and SUBMIT hooks. */ public function init() { // Init fields etc. parent::init(); // Print add_action($this->config['hooks']['print'], array($this, 'print_form')); // Submit add_action('admin_post_nopriv_' . $this->config['hooks']['submit'], array($this, 'submit')); add_action('admin_post_' . $this->config['hooks']['submit'], array($this, 'submit')); if (!empty($this->config['templates']['session'])) { \Cibulka::Base('register_session_var', 'cibulka_form', $this->config['templates']['session']); } /* $i = 1; add_filter('wp_redirect_status', function($status, $location) use ($i) { if ($i > 1) { \Cibulka\dump("redirect loop?"); } update_option($status, $location); $i++; return $status; }, 11, 2); */ }
}); // Last.fm // ----------------------------------------------------------------- $dic['Last_FM'] = $dic->factory(function () { $lf_api = LASTFM_API_KEY; $lf_api_s = LASTFM_API_S; $lastfm = new \Dandelionmood\LastFm\LastFm($lf_api, $lf_api_s); return $lastfm; }); // Twitter | Import // ----------------------------------------------------------------- $dic['Twitter_To_WP'] = $dic->factory(function ($id, $type, array $args, $post_handler_name = null) use($dic) { $wp_meta = \Cibulka::Plugin('base')->get('_WP_Meta'); $wp_meta_tax = \Cibulka::Plugin('base')->get('_WP_Meta_Tax'); $wp_cron = \Cibulka::Plugin('base')->get('_WP_Cron'); $wp_option = \Cibulka::Plugin('base')->get("_WP_Option"); if (empty($post_handler_name)) { $post_handler_name = __NAMESPACE__ . "\\ToWP\\Post"; } $post = new $post_handler_name($wp_meta, $wp_meta_tax); $twitter_getter = $dic->get("Twitter_" . ucfirst($type), $args); $import = new ToWP\Import($id, $twitter_getter, $wp_cron, $wp_option, $post); return $import; }); // ========================================================================= // Plugin // ========================================================================= $base = \Cibulka\Plugin\Base\Plugin::make(); $plugin = Plugin::make(__FILE__, '0.0.1', $dic, $base->get('Asset_Register'), $base->raw('URL')); \Cibulka\Plugin\Base\dic\app::add('Social', $plugin); $plugin->init();
$url = \Cibulka::Base('URL')->get_plugin_url('Forms', 'assets-dist/css/vanilla.css'); \Cibulka::Base('Assets_Admin')->register_style('forms-vanilla', $url, array('xdan-datetimepicker')); \Cibulka::Base('Assets_Admin')->enqueue_style('forms-vanilla'); // ===================================================================== // Javascript // ===================================================================== // $url = \Cibulka::Base('URL')->get_plugin_url('Forms', 'node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.js'); $url = \Cibulka::Base('URL')->get_plugin_url('Forms', 'assets-dist/vendor-fix/jquery.datetimepicker.full.min.js'); \Cibulka::Base('Assets_Admin')->register_script('xdan-datetimepicker', $url, array('jquery')); $url = \Cibulka::Base('URL')->get_plugin_url('Forms', 'assets-dist/js/vanilla.js'); \Cibulka::Base('Assets_Admin')->register_script('forms-vanilla', $url, array('jquery-ui-autocomplete', 'xdan-datetimepicker')); \Cibulka::Base('Assets_Admin')->enqueue_script('forms-vanilla', null, 10, true); // ===================================================================== // Ajax calls // ===================================================================== \Cibulka::Base('WP_Ajax')->add_ajax_call('cibulka_forms_autocomplete', function () { $result = array(); $search_term = $_POST['search']; $query = $_POST['query']; $is_term = isset($_POST['is_term']) && $_POST['is_term']; $query = array_map(function ($v) use($search_term) { // Replace search term $v = str_replace('%search%', $search_term, $v); // Fix "false" as string if ($v === 'false' || $v === '0') { $v = false; } return $v; }, $query); if ($is_term) { $terms = get_terms($query);
$data = json_decode(file_get_contents($url), true); return $data; }, 0); return $result; }; $plugin['Assets_Front'] = function () { return new Assets\WP_Asset_Manager('wp_enqueue_scripts'); }; $plugin['Assets_Admin'] = function () { return new Assets\WP_Asset_Manager('admin_enqueue_scripts'); }; $plugin['Assets_Login'] = function () { return new Assets\WP_Asset_Manager('login_enqueue_scripts'); }; $plugin['WP_Ajax'] = function () { $view = \Cibulka::Base('View'); return new Assets\WP_Ajax($view); }; /** * Init Require.js workflow. * * @param obj $asset_manager - Front, Admin or Login asset manager. * @param obj $base_url - Base URL. Can't be in r.js for some reason, so needs to be added to config later ....... * @param string $main_url_dev - URL for script in development. ['assets-dev/js/main.js'] * @param string $main_url_dist - URL for script in production. ['assets-dist/js/main.js'] * @param string $require_js_url - URL of Require.js dependency. * @param string $js_config - Require.js config - shared between Require.js and R.js build process. * @param callable $condition - Enqueue condtion. * @param bool $dist - Force environment. TRUE, if production. */ $plugin['Require_JS'] = $plugin->factory(function ($asset_manager, $base_url, $main_url_dev, $main_url_dist, $requirejs_url, array $js_config, $condition = null, $dist = false) {
<?php /** * @link http://cibulka.me * * @wordpress-plugin * Plugin Name: CIBULKA | Api * Plugin URI: http://cibulka.me * Description: Wordpress APIs. * Version: 0.0.1 * Author: Petr Cibulka * Author URI: http://cibulka.me/ * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt */ namespace Cibulka\Plugin\Api; if (!defined('ABSPATH')) { die; } add_action('muplugins_loaded', function () { $plugin = new Plugin(__FILE__); include 'plugin/get.php'; \Cibulka::add_plugin('Api', $plugin); $plugin->init(); }, 11);
} if (empty($desc)) { $desc = get_bloginfo('description'); } $desc = trim($desc, '„”"" '); if ($limit) { $desc = \Cibulka::Base('limit_words', $desc, $limit); } return $desc; }; $plugin['meta_pic'] = function ($placeholder = null) { $pic = false; if (is_single()) { global $post; if (has_post_thumbnail($post->ID)) { $image_arr = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large'); $pic = $image_arr[0]; } } if (empty($pic) && !empty($placeholder)) { $pic = $placeholder; } return $pic; }; /** * @link http://opensearch.nichabi.com/ */ $plugin['meta_search'] = function ($name = null) { $obj = \Cibulka::Base('HTML', 'link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml', 'href' => '/opensearch.xml', 'name' => !empty($name) ? $name : get_bloginfo('name')), true, null, null); return $obj; };
namespace Cibulka\Plugin\Base; $plugin['URL'] = function (array $config_filter = null, $use_filter = true) { $obj = new Routes\URL($config_filter); $obj->use_filter($use_filter); return $obj; }; $plugin['under_construction'] = function ($template, $slug = null, $is_test = false) { if (!$is_test || WP_ENV == 'staging') { add_action('cibulka/top', function () use($template, $slug) { if (is_user_logged_in()) { return; } $url = wp_login_url(\Cibulka::Base('URL')->get_front_url('')); \Cibulka::Base('View')->print_template($template, $slug, array('login_url' => $url)); exit; }); } }; $plugin['main_query_cpt'] = function (array $cpt) { add_action('pre_get_posts', function ($query) use($cpt) { if (!is_admin() && !is_singular() && $query->is_main_query()) { $query->set('post_type', $cpt); } }, 11); }; $plugin['add_query_var'] = $plugin->factory(function ($var_names, $callback, $priority = 11) { add_filter('query_vars', function ($vars) use($var_names) { foreach ((array) $var_names as $var_name) { $vars[] = $var_name;
* @link https://dev.twitter.com/rest/public * */ $plugin['Twitter'] = function () { $obj = new \Abraham\TwitterOAuth\TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET); // \Cibulka\dump($obj); return $obj; }; $plugin['Google_Places'] = $plugin->factory(function () { $key = GOOGLE_API_KEY; $obj = new Get\Google_Places_Get($key); return $obj; }); /** * @link https://github.com/dandelionmood/php-lastfm * @link http://www.last.fm/fr/api/show/artist.getInfo */ $plugin['Last_Fm'] = function () { $obj = new \Dandelionmood\LastFm\LastFm(LASTFM_API_KEY, LASTFM_API_SECRET); return $obj; }; $plugin['get_youtube_id'] = $plugin->factory(function ($url) { $q = array('v'); parse_str(parse_url($url, PHP_URL_QUERY), $q); $v_id = !empty($q['v']) ? $q['v'] : false; return $v_id; }); $plugin['To_Transient'] = $plugin->factory(function ($transient_name, $getter, $expiration) { $transient = \Cibulka::Base('WP_Transient'); return $transient->read($transient_name, $getter, $expiration); });
protected function print_template($template_name, $data = null) { $template_path = $this->config['templates'][$template_name]; $data = !empty($data) ? $data : $this; if ($template = $this->view->get_theme_template($template_path, null)) { $this->view->print_template($template_path, null, $data); } else { $this->view->print_template_plugin(\Cibulka::Forms()->get_plugin_info('file'), $template_path, null, $data, true); } }
<?php $attrs = $data->get_attrs(true); $fields = $data->get_fields(); $form = \Cibulka::Base('HTML', 'form', $attrs); ?> <?php echo $form->start(); ?> <?php foreach ($fields as $id => $field) { ?> <p class="l-mb--1-2"> <?php echo $field->get_field_output(); ?> </p> <?php } ?> <button type="submit" class="button t-base">Send message</button> <?php echo $form->end();
namespace Cibulka\Plugin\Base; $plugin['CSS_Grid'] = function ($show = null) { if ($show === null) { $show = WP_ENV === 'development' ? true : false; } $obj = new HTML\CSS_Grid('debug-grid', 'debug-grid-handle', $show); return $obj; }; $plugin['HTML'] = $plugin->factory(function ($name, array $attrs = array(), $self_close = null, $content = null) { $html = new HTML\HTML($name, $attrs, $self_close, $content); return $html; }); $plugin['_Theme_Image'] = function () { $url_obj = \Cibulka::Base('URL'); try { $theme_config = \Cibulka::Theme('Theme_Config'); $breakpoints = $theme_config['theme']['breakpoints']; $sizes = $theme_config['theme']['img']; } catch (\Exception $e) { throw new \Exception("Theme must define Theme_Config with buildconfig.json content!"); } $obj = new HTML\Srcset($breakpoints, $sizes, $url_obj); return $obj; }; // - NOTE: Intentionally NOT a factory. $plugin['Theme_Image'] = function ($filename, array $sizes, array $attrs = null, array $allowed_sizes = null, $src = null) { $obj = \Cibulka::Base('_Theme_Image'); $obj->set_data($filename, $sizes, $attrs, $allowed_sizes, $src); return $obj; };
protected function show_notice($data, $notice_template) { \Cibulka::Base('View')->print_template($notice_template, null, $data); }
} add_filter('document_title_parts', function (array $title) { if (is_single() && 'post' !== get_post_type()) { global $post; $post_type = get_post_type_object(get_post_type()); $title['title'] = $post_type->labels->singular_name . ': ' . get_the_title($post->ID); } return $title; }, 11, 3); }; $plugin['Clean'] = function () { return new Setup\WP_Clean(); }; $plugin['init_image_sizes'] = function () { try { $theme_config = \Cibulka::Theme('Theme_Config'); } catch (\Exception $e) { return false; } foreach ($theme_config["theme"]["img"] as $k => $size) { $crop = isset($size["crop"]) && $size['crop']; add_image_size($k, $size['width'], $size['height'], $crop); } }; $plugin['init_wp_noorig_image'] = function () { add_filter('wp_calculate_image_srcset', function ($sources) { ksort($sources); array_pop($sources); return $sources; }); };
* @wordpress-plugin * Plugin Name: CIBULKA | Base * Plugin URI: http://cibulka.me * Description: Basic dependency for all Cibulka's plugin. Should be included as MU-Plugin (but can work both ways). * Version: 0.0.1 * Author: Petr Cibulka * Author URI: http://cibulka.me/ * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt */ namespace Cibulka\Plugin\Base; if (!defined('ABSPATH')) { die; } $plugin = new Plugin(__FILE__); include 'plugin/json.php'; include 'plugin/content.php'; include 'plugin/routes.php'; include 'plugin/setup.php'; include 'plugin/crud.php'; include 'plugin/assets.php'; include 'plugin/html.php'; include 'plugin/parsers.php'; include 'plugin/templates.php'; include 'plugin/wp_post.php'; include 'plugin/locale.php'; include 'plugin/utils.php'; include 'plugin/meta.php'; \Cibulka::add_plugin('Base', $plugin); $plugin->init();
protected function get_repeatable_button($add_or_remove, $field_i, $group_item_i, $do_table_line = false) { $repeatable = $this->config['args']['repeatable']; if (!$repeatable || is_int($repeatable)) { return null; } $result = ''; $total = $this->get_glue($group_item_i); if ($do_table_line) { $table_line_suffix = $this->is_group() ? 'group' : 'single'; $table_line_class = implode(' ', array('repeatable-wrap-' . $add_or_remove, 'repeatable-wrap-' . $add_or_remove . '--' . $table_line_suffix)); $result .= '<tr><td class="td-sep td-pad ' . $table_line_class . '" colspan="2">'; } $button_attrs = array('href' => '#', 'data-glue-id' => $this->is_group() ? $this->get_glue_key(null) : $this->get_glue_key($group_item_i), 'data-is-group' => $this->is_group()); $button_class = array('repeatable-button'); if ($add_or_remove === 'remove') { $button_txt = '×'; $button_attrs['data-target'] = $this->is_group() ? $this->get_id(null, empty($group_item_i) ? 1 : $group_item_i) : $this->get_id_wrap($field_i, $group_item_i); $button_class[] = 'repeatable-button--remove js-increment-attrs'; if ($this->is_in_group() && $this->get_repeatable()) { $button_class[] = 'js-repeatable-in-group'; } } else { $button_txt = '+'; $button_class[] = 'repeatable-button--add'; } $button_attrs['class'] = implode(' ', $button_class); $result .= \Cibulka::Base('HTML', 'a', $button_attrs, false, $button_txt); if ($do_table_line) { $result .= '</td></tr>'; } return $result; }
public function remove_word($post_id) { if (!in_array(get_post_type($post_id), $this->post_types)) { return $post_id; } $do_word = get_post_meta($post_id, 'remove_word_formatting', true) === 'ano'; if (!$do_word) { return $post_id; } $content = get_post_field('post_content', $post_id); if (empty($content)) { return $post_id; } $dom = \Cibulka::Base('DOMDocument'); $dom->loadHTML($content); $dom->unwrap($this->els); // Remove unnecessary elements $dom->remove_attrs($this->attrs); // Remove attributes $content = $dom->get_content(); if (empty($content)) { return false; } $result = array('ID' => $post_id, 'post_content' => $content); remove_action('save_post', array($this, 'remove_word'), 12); $result = wp_update_post($result); add_action('save_post', array($this, 'remove_word'), 12, 1); update_post_meta($post_id, 'remove_word_formatting', 'ne'); return $result; }