/** * Set up or upgrade the plugin * * @package Tina-MVC * @subpackage Core * @param boolean $upgrading * @return void */ function plugin_activate($upgrading) { $tina_mvc_app_settings = new \stdClass(); if (PHP_VERSION_ID < 50306) { activation_error('Tina MVC for Wordpress requires PHP 5 >= 5.3.6', E_USER_ERROR); exit; } if (file_exists($f = \TINA_MVC\plugin_folder() . '/user_apps/default/app_settings.php')) { include $f; } elseif (file_exists($f = \TINA_MVC\plugin_folder() . '/user_apps/default/app_settings_sample.php')) { include $f; } /** * If multisite look for other settings files */ if (is_multisite()) { $saved_setting = $tina_mvc_app_settings->multisite_app_cascade; $blogname = \TINA_MVC\get_multisite_blog_name(); /** * Check for app_settings files */ if (file_exists($f = \TINA_MVC\plugin_folder() . "/user_apps/multisite/{$blogname}/app_settings.php")) { include $f; } elseif ($saved_setting and file_exists($f = \TINA_MVC\plugin_folder() . '/user_apps/default/app_settings.php')) { include $f; } $tina_mvc_app_settings->multisite_app_cascade = $saved_setting; } if (empty($tina_mvc_app_settings)) { activation_error('Failed to find a app_settings.php or app_settings_sample.php file', E_USER_ERROR); exit; } // create controller pages $tina_mvc_pages = array(); foreach ($tina_mvc_app_settings->tina_mvc_pages as $p) { // does the page exist...? $the_page = get_page_by_path($p['page_name']); // \TINA_MVC\prd( $the_page ); $tina_mvc_request = $p['page_name']; if (empty($the_page)) { // Create post object $_p = array(); $_p['post_title'] = $p['page_title']; // check if we need to set a parent page. $parent_page_id = 0; // default $slash_pos = strrpos($p['page_name'], '/'); // is there a path or just a name? if ($slash_pos !== FALSE) { $the_parent_page_name = substr($p['page_name'], 0, $slash_pos); $p['page_name'] = substr($p['page_name'], $slash_pos + 1, strlen($p['page_name']) - ($slash_pos + 1)); if ($the_parent_page_name) { $parent_page = get_page_by_path($the_parent_page_name); $parent_page_id = $parent_page->ID; } } $_p['post_parent'] = $parent_page_id; $_p['post_name'] = $p['page_name']; $_p['post_content'] = default_controller_page_content(); $_p['post_status'] = $p['page_status']; $_p['post_type'] = 'page'; // MENu order? $menu_order = 0; // default if (array_key_exists('menu_order', $p)) { $menu_order = intval($p['menu_order']); } $_p['menu_order'] = $menu_order; $_p['comment_status'] = 'closed'; $_p['comment_count '] = 0; $_p['ping_status'] = 'closed'; $_p['post_category'] = array(1); // Insert the post into the database $the_page_id = wp_insert_post($_p); } else { $the_page_id = $the_page->ID; //make sure the page is not trashed... $the_page->post_status = $p['page_status']; $the_page_id = wp_update_post($the_page); } // get the page in case Wordpress messed with the page_name $_p = get_page($the_page_id); // for storing in the options table $page_name = $_p->post_name; $page_id = $_p->ID; $page_data = array('page_title' => $_p->post_title, 'page_name' => $page_name, 'page_id' => $page_id, 'tina_mvc_request' => $tina_mvc_request); // handy to have them for later... $tina_mvc_pages[$page_name] = $page_data; $tina_mvc_pages[$page_id] = $page_data; } $tina_mvc_app_settings->tina_mvc_pages = $tina_mvc_pages; delete_option('tina_mvc_settings'); add_option('tina_mvc_settings', $tina_mvc_app_settings, '', 'yes'); /** * The hourly cron functionality */ if ($tina_mvc_app_settings->enable_hourly_cron) { wp_schedule_event(time() + 30, 'hourly', 'tina_mvc_cron_hook'); } if (file_exists(\TINA_MVC\app_folder() . '/install_remove/tina_mvc_app_install.php')) { include \TINA_MVC\app_folder() . '/install_remove/tina_mvc_app_install.php'; if (function_exists('tina_mvc_app_install')) { tina_mvc_app_install(); } } delete_option('tina_mvc_plugin_active'); add_option('tina_mvc_plugin_active', 1, '', 'yes'); }
/** * Checks if we have any bootstrap scripts to be run * * Scripts live in the user_apps folder in bootstrap. Every PHP file (except index.php) in the directory * (but not subdirectories), is included and a PHP function named the same as the filename * is called. * * This allows you to do things like use wp_enqueue_script() with shortcodes and * widgets, or to use other Wordpress action hooks. The functions will be called on * every page load, not just with Tina MVC pages, so use sparingly. * * This feature can be disabled in tina_mvc_app_settings.php * * @param integer $check_init_bootstrap set to true to check the app_init_bootstrap folder instead */ public function do_bootstrap_funcs($check_init_bootstrap = FALSE) { if ($check_init_bootstrap) { $folder = TINA_MVC\app_folder() . '/init_bootstrap'; } else { $folder = TINA_MVC\app_folder() . '/tina_mvc_bootstrap'; } $files = scandir($folder); foreach ($files as $file) { $file = strtolower($file); if (!in_array($file, array('.', '..', 'index.php')) and strpos($file, '.php') !== FALSE) { include "{$folder}/{$file}"; $function = str_replace('.php', '', $file); if (function_exists($function)) { call_user_func($function); } } } }