/** * Create a duplicate from a posts' instance */ function duplicate_post_create_duplicate($post, $status = '') { $new_post_author = $this->duplicate_post_get_current_user(); $new_post_status = $status; if (empty($new_post_status)) { $new_post_status = $post->post_status; } $new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'pinged' => $post->pinged, 'post_author' => $new_post_author->ID, 'post_content' => $post->post_content, 'post_date' => $post->post_date, 'post_date_gmt' => get_gmt_from_date($post->post_date), 'post_excerpt' => $post->post_excerpt, 'post_parent' => $post->post_parent, 'post_password' => $post->post_password, 'post_status' => $new_post_status, 'post_title' => $post->post_title, 'post_type' => $post->post_type, 'to_ping' => $post->to_ping); $new_post_id = wp_insert_post($new_post); $edit_event_url = esc_attr(admin_url("post.php?post={$new_post_id}&action=edit")); $message = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf(__('<p>The event <strong>%s</strong> was cloned succesfully. <a href="%s">Edit cloned event</a></p>', AI1EC_PLUGIN_NAME), $post->post_title, $edit_event_url)); $message->set_message_type('updated'); $this->admin_notice_helper->add_renderable_children($message); // If you have written a plugin which uses non-WP database tables to save // information about a post you can hook this action to dupe that data. if ($post->post_type == 'page' || function_exists('is_post_type_hierarchical') && is_post_type_hierarchical($post->post_type)) { do_action('dp_duplicate_page', $new_post_id, $post); } else { do_action('dp_duplicate_post', $new_post_id, $post); } delete_post_meta($new_post_id, '_dp_original'); add_post_meta($new_post_id, '_dp_original', $post->ID); // If the copy gets immediately published, we have to set a proper slug. if ($new_post_status == 'publish' || $new_post_status == 'future') { $post_name = wp_unique_post_slug($post->post_name, $new_post_id, $new_post_status, $post->post_type, $post->post_parent); $new_post = array(); $new_post['ID'] = $new_post_id; $new_post['post_name'] = $post_name; // Update the post into the database wp_update_post($new_post); } return $new_post_id; }
/** * If it is detected that current theme is in legacy format, generate a * dashboard notice. */ public function generate_notice_if_legacy_theme_installed($display_now = false) { $theme = Ai1ec_Meta::get_option('ai1ec_template', AI1EC_DEFAULT_THEME_NAME); // Save directory separator to more concise variable name. $slash = DIRECTORY_SEPARATOR; $errors = array(); // ========================== // = Wrong style.css format = // ========================== // Check if a theme has a style.css file containing something besides a CSS // comment. try { $style = Ai1ec_Less_Factory::create_less_file_instance('..' . $slash . 'style'); $css = file_get_contents($style->locate_exact_file_to_load_in_theme_folders()); } catch (Ai1ec_File_Not_Found $e) { // File not found; no legacy theme code available to detect, so return. return; } $css = $this->remove_comments_and_space($css); if ($css) { $errors[] = sprintf(__('In your theme folder, <code>%s</code>, the file <code>%sstyle.css</code> should now be used only for metadata information (name, author, etc.).', AI1EC_PLUGIN_NAME) . ' ' . __('We detected custom CSS rules in that file. Those should be removed from <code>%sstyle.css</code> and placed in the file <code>%scss%soverride.css</code>.', AI1EC_PLUGIN_NAME), $theme, $slash, $slash, $slash, $slash); } // ========================== // = Required files missing = // ========================== // Check if the theme is missing any of the files that are in Gamma (which // includes the minimum files). $gamma_files = $this->_get_file_listing(AI1EC_THEMES_ROOT . $slash . 'gamma', '#' . $slash . '\\.|^' . $slash . 'functions\\.php$#i'); $theme_files = $this->_get_file_listing($this->active_template_path()); $diff = array_diff($gamma_files, $theme_files); if ($diff) { $errors[] = sprintf(__('Your theme folder <code>%s</code> is missing one or more required files: <code>%s</code>. Please copy these files from the skeleton theme folder, <code>gamma</code>, into the same relative location under <code>%s</code>.', AI1EC_PLUGIN_NAME), $theme, implode('</code>, <code>', $diff), $theme); } if ($errors) { // =============================================================== // = Additional checks for modified page templates and other CSS = // =============================================================== // Now that we've established that the theme is outdated, make certain // recommendations to the user based on the below checks. // If they also have overridden page templates. These *must* be updated. $vortex_php = $this->_get_file_listing(AI1EC_THEMES_ROOT . '/' . AI1EC_DEFAULT_THEME_NAME, '#^' . $slash . '(functions|index)\\.php$#i', '#\\.php$#i'); $theme_php = $this->_get_file_listing($this->active_template_path(), '#^' . $slash . '(functions|index)\\.php$#i', '#\\.php$#i'); $php_in_common = array_intersect($vortex_php, $theme_php); if ($php_in_common) { $errors[] = sprintf(__('We detected one or more custom templates files in your theme folder, <code>%s</code>:', AI1EC_PLUGIN_NAME) . ' ' . '<blockquote><code>' . implode('</code>, <code>', $php_in_common) . '</code></blockquote>' . __('These templates’ originals have changed significantly since these were copied from <code>%s</code>, and the new versions include numerous enhancements. <strong>Your theme’s outdated templates will likely cause your calendar to malfunction.</strong>', AI1EC_PLUGIN_NAME) . ' ' . __('We recommend you back up your templates and remove them from <code>%s</code>. Try using your calendar, and if changes are needed, copy the latest version of the template from <code>%s</code> to <code>%s</code> and then make your revisions.', AI1EC_PLUGIN_NAME), $theme, AI1EC_DEFAULT_THEME_NAME, $theme, AI1EC_DEFAULT_THEME_NAME, $theme); } // Check for overridden CSS. These must also be updated. $vortex_css = array($slash . 'less' . $slash . 'style.less', $slash . 'less' . $slash . 'calendar.less', $slash . 'less' . $slash . 'event.less', $slash . 'css' . $slash . 'style.css', $slash . 'css' . $slash . 'calendar.css', $slash . 'css' . $slash . 'event.css'); $theme_css = $this->_get_file_listing($this->active_template_path(), '#^' . $slash . 'style\\.css$#i', '#\\.(css|less)$#i'); $css_in_common = array_intersect($vortex_css, $theme_css); if ($css_in_common) { $errors[] = sprintf(__('We detected one or more custom CSS or LESS files in your theme folder, <code>%s</code>, that will override the corresponding original in %s:', AI1EC_PLUGIN_NAME) . '<blockquote><code>' . implode('</code>, <code>', $css_in_common) . '</code></blockquote>' . __('The originals have changed significantly since these were copied from <code>%s</code>, and the new versions include numerous enhancements. <strong>Your theme’s outdated CSS/LESS files will likely cause your calendar to be displayed incorrectly.</strong>', AI1EC_PLUGIN_NAME) . ' ' . __('We recommend you back up the affected CSS/LESS files and remove them from <code>%s</code>. Try using your calendar and if changes are needed, place your custom CSS rules in <code>%scss%soverride.css</code> (or custom LESS rules in <code>%sless%soverride.less</code>).', AI1EC_PLUGIN_NAME), $theme, AI1EC_DEFAULT_THEME_NAME, AI1EC_DEFAULT_THEME_NAME, $theme, $slash, $slash, $slash, $slash); } // Display final report. $message = Ai1ec_Helper_Factory::create_admin_message_instance('<p>' . __("You are using a calendar theme that should be updated to the new conventions:", AI1EC_PLUGIN_NAME) . '</p><ol><li>' . implode('</li><li>', $errors) . '</li></ol><p>' . sprintf(__('<strong>Note:</strong> After modifying any of your theme’s CSS or LESS files, you <em>must</em> click <strong>Events</strong> > <strong>Theme Options</strong> > <strong>Save Options</strong> to refresh the compiled CSS used in the front-end.', AI1EC_PLUGIN_NAME) . '</p><p>' . __('You can learn more from our <a href="%s" target="_blank">Help Desk article</a>.', AI1EC_PLUGIN_NAME), 'http://help.time.ly/customer/portal/articles/803082') . '</p>', __("All-in-One Event Calendar Warning: Calendar theme is in legacy format", AI1EC_PLUGIN_NAME)); if (true === $display_now) { $message->render(); } else { $aie1c_admin_notices_helper = Ai1ec_Admin_Notices_Helper::get_instance(); $aie1c_admin_notices_helper->add_renderable_children($message); } } }
/** * apply_delta method * * Attempt to parse and apply given database tables definition, as a delta. * Some validation is made prior to calling DB, and fields/indexes are also * checked for consistency after sending queries to DB. * * NOTICE: only "CREATE TABLE" statements are handled. Others will, likely, * be ignored, if passed through this method. * * @param string|array $query Single or multiple queries to perform on DB * * @return bool Success * * @throws Ai1ec_Database_Error In case of any error */ public function apply_delta($query) { if (!function_exists('dbDelta')) { require_once ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'upgrade.php'; } $success = false; try { $this->_schema_delta = array(); $queries = $this->_prepare_delta($query); $result = dbDelta($queries); $success = $this->_check_delta(); } catch (Ai1ec_Database_Error $failure) { $message = Ai1ec_Helper_Factory::create_admin_message_instance('<p>' . __('Database update has failed. Please make sure, that database user, defined in <em>wp-config.php</em> has permissions, to make changes (<strong>ALTER TABLE</strong>) to the database.', AI1EC_PLUGIN_NAME) . '</p>', __('Plug-in disabled due to unrecoverable database update error', AI1EC_PLUGIN_NAME)); $this->get_notices_helper()->add_renderable_children($message); if (!function_exists('deactivate_plugins')) { require ABSPATH . 'wp-admin/includes/plugin.php'; } deactivate_plugins(AI1EC_PLUGIN_BASENAME, true); } return $success; }
/** * Update the less variables on the DB and recompile the CSS * * @param array $variables * @param boolean $resetting are we resetting or updating variables? */ private function update_variables_and_compile_css(array $variables, $resetting) { $no_parse_errors = $this->invalidate_cache($variables, true); if ($no_parse_errors) { $this->db_adapter->write_data_to_config(Ai1ec_Lessphp_Controller::DB_KEY_FOR_LESS_VARIABLES, $variables); $message = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf('<p>' . __("Theme options were updated successfully. <a href='%s'>Visit site</a>", AI1EC_PLUGIN_NAME) . '</p>', get_site_url())); if (true === $resetting) { $message = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf('<p>' . __("Theme options were successfully reset to their default values. <a href='%s'>Visit site</a>", AI1EC_PLUGIN_NAME) . '</p>', get_site_url())); } $message->set_message_type('updated'); $this->admin_notices_helper->add_renderable_children($message); } }
/** * Handle request - perform variables initialization and inner routing * * @return bool OAuth success status */ public function handle_request() { $result = false; $message = NULL; try { $this->_provider = $this->get_provider(); $result = $this->authorize(); } catch (Ai1ec_Oauth_Exception $exception) { // @RELEASE $this->_log->error( 'OAuth failure: ' . $exception->getMessage() ); $result = false; $message = $exception->getMessage(); } $renderable = NULL; if ($result) { $renderable = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf(__('You have successfully linked your account with <strong>%s</strong>.', AI1EC_PLUGIN_NAME), $this->_provider->get_name()), __('External Service linked', AI1EC_PLUGIN_NAME)); $renderable->set_message_type('updated'); } else { $renderable = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf(__('There was a failure linking your account with <strong>%s</strong>: %s.', AI1EC_PLUGIN_NAME), $this->_provider->get_name(), $message), __('External Service linking error', AI1EC_PLUGIN_NAME)); $renderable->set_message_type('error'); } Ai1ec_Deferred_Rendering_Helper::get_instance()->add_renderable_children($renderable); return ai1ec_redirect(admin_url(AI1EC_SETTINGS_BASE_URL)); }