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; }
}); // 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();
*/ $plugin['Post_Tax'] = function () { return new Setup\WP_Post_Tax(); }; $plugin['Srcset'] = function () { $breakpoints = \Cibulka::Plugin('base')->Get('Theme_Config')['breakpoints']; $obj = new HTML() / Srcset($breakpoints); return $obj; }; $plugin['Picture'] = function () { throw new \Exception("Not ready yet!"); }; $plugin['Thumbnail'] = function () { $wp_sizes = \Cibulka::Plugin('base')->Get('Theme_Config')['wp_sizes']; $srcset = \Cibulka::Plugin('base')->Get('Srcset'); $theme_support = \Cibulka::Plugin('base')->Get('Theme_Support'); $obj = new Setup\WP_Thumbnail($wp_sizes, $srcset, $theme_support); return $obj; }; $plugin['wp_title_init'] = function ($sep_custom = ' | ', $legacy = false) { add_action('after_setup_theme', function () { add_theme_support('title-tag'); }); if (!empty($sep)) { add_filter('document_title_separator', function ($sep) use($sep_custom) { return $sep_custom; }, 10, 1); } add_filter('document_title_parts', function (array $title) { if (is_single() && 'post' !== get_post_type()) { global $post;
global $paged, $page; $title .= get_bloginfo('name'); $site_description = get_bloginfo('description', 'display'); if ($site_description && (is_home() || is_front_page())) { $title = "{$title} {$sep} {$site_description}"; } if ($paged >= 2 || $page >= 2) { $title = "Page " . max($paged, $page) . " {$sep} {$title}"; } return $title; }; $dic['_Srcset'] = $dic->factory(function ($use_picture = false) { // Theme config $theme_config = \Cibulka::Plugin('theme')->Theme_Config(); // URL $url = \Cibulka::Plugin('base')->raw('URL'); // Available image sizes $wp_sizes = $theme_config['img']; // Breakpoints $breakpoints = $theme_config['breakpoints']; $class = $use_picture ? 'Picture' : 'Srcset'; $class = __NAMESPACE__ . "\\Builders\\{$class}"; return new $class($url, $wp_sizes, $breakpoints); }); $dic['Srcset__Asset'] = $dic->factory(function ($filename, $alt, array $sizes, array $attrs = array()) use($dic) { $srcset = $dic->get('_Srcset'); $srcset->set_asset($filename, $alt, $sizes, $attrs); return $srcset; }); $dic['Srcset__Upload'] = $dic->factory(function ($id, $alt, array $sizes, array $attrs = array()) use($dic) { $srcset = $dic->get('_Srcset');
protected function create_after($diff, $time, $now) { $tomo = $this->time->get_time('U', 'tomorrow'); $tomo2 = $this->time->get_time('U', 'tomorrow + 1 day'); $tomo3 = $this->time->get_time('U', 'tomorrow + 2 days'); \Cibulka::Plugin('base')->Dump($now); // Today if ($diff <= $tomo - $now) { $num = 0; $unit = 'day'; } elseif ($diff <= $tomo2 - $now) { $num = 1; $unit = 'day'; } elseif ($diff <= $tomo3 - $now) { $num = 2; $unit = 'day'; } else { return $time; } return $this->time->say_after($num, $unit); }