function get_feed($feed_url, $credit) { $source = file_get_contents($feed_url); $feed = new SimpleXmlElement($source); if (!empty($feed->channel->item)) { foreach ($feed->channel->item as $entry) { $descriptionA = $entry->children('content', true); $descriptionB = $entry->description; if (!empty($descriptionA)) { $content = $descriptionA; } elseif (!empty($descriptionB)) { $content = preg_replace('#<br\\s*/?>#i', "\n", $descriptionB); } else { return $str = '<li>Can not read the feed content.</li>'; } $time = new DateTime($entry->pubDate); $timestamp = $time->format("Y-m-d H:i:s"); $time = strtotime($timestamp); $tags = $entry->category; $title = rtrim($entry->title, ' \\,\\.\\-'); $title = ltrim($title, ' \\,\\.\\-'); $user = $_SESSION[config("site.url")]['user']; $url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \\-\\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($title))); if ($credit == 'yes') { $source = $entry->link; } else { $source = null; } migrate($title, $time, $tags, $content, $url, $user, $source); } } else { return $str = '<li>Unsupported feed.</li>'; } }
ini_set('display_errors', 1); ini_set('error_reporting', E_ALL); ini_set('error_prepend_string', null); ini_set('error_append_string', null); } include_once dirname(__FILE__) . '/framework/class.unix.inc'; include_once dirname(__FILE__) . '/framework/frame.class.inc'; include_once dirname(__FILE__) . "/ressources/class.postgres.inc"; include_once dirname(__FILE__) . '/ressources/class.users.menus.inc'; include_once dirname(__FILE__) . '/ressources/class.mysql.inc'; include_once dirname(__FILE__) . '/ressources/class.os.system.inc'; $GLOBALS["DEBUG"] = false; $GLOBALS["FORCE"] = false; $GLOBALS["VERBOSE"] = false; if ($argv[1] == "--migrate") { migrate(); exit; } if ($argv[1] == "--purge") { purge(); exit; } function migrate() { $q = new mysql(); $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidtime = "/etc/artica-postfix/pids/exec.suricata.hourly.migrate.time"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid);
/** * Create table * * Create table based on $this->rs array * and $this->rt array * * @param array assoc array with optional type strings * @return boolean TRUE on success, FALSE if failed * @author bochoven **/ function create_table() { // Check if we instantiated this table before if (isset($GLOBALS['tables'][$this->tablename])) { return TRUE; } // Check if table exists and is up-to-date try { $dbh = $this->getdbh(); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // Check if table exists $this->prepare("SELECT * FROM " . $this->enquote($this->tablename) . " LIMIT 1"); // Existing table, is it up-to date? if (conf('allow_migrations')) { if ($this->get_schema_version() !== $this->schema_version) { try { require_once conf('application_path') . 'helpers/database_helper.php'; migrate($this); $model_name = get_class($this); alert('Migrated ' . $model_name . ' to version ' . $this->schema_version); } catch (Exception $e) { error("Migration error: {$this->tablename}: " . $e->getMessage()); // Rollback any open transaction try { $dbh->rollBack(); } catch (Exception $e2) { } } } } } catch (Exception $e) { // If the prepare fails, the table does not exist. // Get columns $columns = array(); foreach ($this->rs as $name => $val) { // Determine type automagically $type = $this->get_type($val); // Or set type from type array $columns[$name] = isset($this->rt[$name]) ? $this->rt[$name] : $type; } // Set primary key $columns[$this->pkname] = 'INTEGER PRIMARY KEY'; // Table options, override per driver $tbl_options = ''; // Driver specific options switch ($this->get_driver()) { case 'sqlite': $columns[$this->pkname] .= ' AUTOINCREMENT'; break; case 'mysql': $columns[$this->pkname] .= ' AUTO_INCREMENT'; $tbl_options = conf('mysql_create_tbl_opts'); break; } // Compile columns sql $sql = ''; foreach ($columns as $name => $type) { $sql .= $this->enquote($name) . " {$type},"; } $sql = rtrim($sql, ','); try { $dbh->exec(sprintf("CREATE TABLE %s (%s) %s", $this->enquote($this->tablename), $sql, $tbl_options)); // Set indexes $this->set_indexes(); // Store schema version in migration table $migration = new Migration($this->tablename); $migration->version = $this->schema_version; $migration->save(); alert("Created table '{$this->tablename}' version {$this->schema_version}"); } catch (Exception $e) { $dbh->exec('DROP TABLE ' . $this->enquote($this->tablename)); error("Create table '{$this->tablename}' failed: " . $e->getMessage()); return FALSE; } } // Store this table in the instantiated tables array $GLOBALS['tables'][$this->tablename] = $this->tablename; // Create table succeeded return TRUE; }
$ecole = $_POST["ecole"]; $classe = $_POST["classe"]; print load($ecole, $classe); break; case 'migrate': $ids = $_POST["ids"]; $ecole = $_POST["ecole"]; $classe = $_POST["classe"]; $fecole = $_POST["fecole"]; $fclasse = $_POST["fclasse"]; //$ar_ids = explode(",",$ids); foreach ($ids as &$value) { $where .= "`enfantid`='{$value}' OR "; } $where = substr($where, 0, -4); print migrate($ecole, $classe, $where); update_history($fecole, $fclasse, $ecole, $classe); break; } ///////////////functions//////////////// function update_history($fecole, $fclasse, $tecole, $tclasse) { $mysqli = new mysqli(DBSERVER, DBUSER, DBPWD, DB); $query = "INSERT INTO `migrate_history` (`idmigrate`,`from_ecole`,`from_classe`,`to_ecole`,`to_classe`,`date`) VALUES (NULL,'{$fecole}','{$fclasse}','{$tecole}','{$tclasse}',CURRENT_TIMESTAMP)"; $mysqli->query($query); $mysqli->close(); } function migrate($ecole, $classe, $where) { $mysqli = new mysqli(DBSERVER, DBUSER, DBPWD, DB); $query = "UPDATE `enfants` SET `ecole`='{$ecole}',`classe`='{$classe}' WHERE {$where}";
function safecss_init() { // Register safecss as a custom post_type register_post_type('safecss', array('supports' => array('revisions'))); // Short-circuit WP if this is a CSS stylesheet request if (isset($_GET['custom-css'])) { header('Content-Type: text/css', true, 200); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT'); // 1 year $blog_id = $_GET['csblog']; if (is_int($blog_id)) { switch_to_blog($blog_id); $current_plugins = apply_filters('active_plugins', get_option('active_plugins')); } safecss_print(); exit; } // Do migration routine if necessary if (!empty($_GET['page']) && 'editcss' == $_GET['page'] && is_admin()) { migrate(); } add_action('wp_head', 'safecss_style', 101); if (!current_user_can('switch_themes') && !is_super_admin()) { return; } add_action('admin_menu', 'safecss_menu'); if (isset($_POST['safecss']) && false == strstr($_SERVER['REQUEST_URI'], 'options.php')) { check_admin_referer('safecss'); // Remove wp_filter_post_kses, this causes CSS escaping issues remove_filter('content_save_pre', 'wp_filter_post_kses'); remove_filter('content_filtered_save_pre', 'wp_filter_post_kses'); remove_all_filters('content_save_pre'); safecss_class(); $csstidy = new csstidy(); $csstidy->optimise = new safecss($csstidy); $csstidy->set_cfg('remove_bslash', false); $csstidy->set_cfg('compress_colors', false); $csstidy->set_cfg('compress_font-weight', false); $csstidy->set_cfg('discard_invalid_properties', true); $csstidy->set_cfg('merge_selectors', false); $css = $orig = stripslashes($_POST['safecss']); $css = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $prev = $css); if ($css != $prev) { $warnings[] = 'preg_replace found stuff'; } // Some people put weird stuff in their CSS, KSES tends to be greedy $css = str_replace('<=', '<=', $css); // Why KSES instead of strip_tags? Who knows? $css = wp_kses_split($prev = $css, array(), array()); $css = str_replace('>', '>', $css); // kses replaces lone '>' with > // Why both KSES and strip_tags? Because we just added some '>'. $css = strip_tags($css); if ($css != $prev) { $warnings[] = 'kses found stuff'; } $csstidy->parse($css); $css = $csstidy->print->plain(); if (intval($_POST['custom_content_width']) > 0) { $custom_content_width = intval($_POST['custom_content_width']); } else { $custom_content_width = false; } if ($_POST['add_to_existing'] == 'true') { $add_to_existing = 'yes'; } else { $add_to_existing = 'no'; } if ('preview' == $_POST['action'] || safecss_is_freetrial()) { $is_preview = true; // Save the CSS save_revision($css, $is_preview); // Cache Buster update_option('safecss_preview_rev', intval(get_option('safecss_preview_rev')) + 1); update_option('safecss_preview_add', $add_to_existing); update_option('safecss_preview_content_width', $custom_content_width); wp_redirect(add_query_arg('csspreview', 'true', get_option('home'))); exit; } // Save the CSS save_revision($css); update_option('safecss_rev', intval(get_option('safecss_rev')) + 1); update_option('safecss_add', $add_to_existing); update_option('safecss_content_width', $custom_content_width); add_action('admin_notices', 'safecss_saved'); } // Modify all internal links so that preview state persists if (safecss_is_preview()) { ob_start('safecss_buffer'); } }
CREATE TABLE `schema_migrations` ( `version` varchar(255), PRIMARY KEY (`version`) ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci; EOT; $connection->query($sql); } function should_migrate($migration, $connection) { $should_migrate = $connection->count(array('table' => 'schema_migrations', 'conditions' => array('version' => get_migration_version($migration)))); return !$should_migrate; } function migrate($migration, $connection) { echo 'importing ' . $migration . '... '; $connection->query(utf8_decode(Filesystem::read('db/migrations/' . $migration))); $connection->create(array('table' => 'schema_migrations', 'values' => array('version' => get_migration_version($migration)))); echo 'done' . PHP_EOL; } $connection = Connection::get(Config::read('App.environment')); if (!in_array('schema_migrations', $connection->listSources())) { create_schema_migrations($connection); } $migrations = get_migrations(); foreach ($migrations as $migration) { if (should_migrate($migration, $connection)) { migrate($migration, $connection); } }
case '1.9.10.2': // Fix type "enum" before running the migration with Doctrine Database::query("ALTER TABLE course_category MODIFY COLUMN auth_course_child VARCHAR(40) DEFAULT 'TRUE'"); Database::query("ALTER TABLE course_category MODIFY COLUMN auth_cat_child VARCHAR(40) DEFAULT 'TRUE'"); Database::query("ALTER TABLE c_quiz_answer MODIFY COLUMN hotspot_type varchar(40) default NULL"); Database::query("ALTER TABLE c_tool MODIFY COLUMN target varchar(20) NOT NULL default '_self'"); Database::query("ALTER TABLE c_link MODIFY COLUMN on_homepage char(10) NOT NULL default '0'"); Database::query("ALTER TABLE c_blog_rating MODIFY COLUMN rating_type char(40) NOT NULL default 'post'"); Database::query("ALTER TABLE c_survey MODIFY COLUMN anonymous char(10) NOT NULL default '0'"); Database::query("ALTER TABLE c_document MODIFY COLUMN filetype char(10) NOT NULL default 'file'"); Database::query("ALTER TABLE c_student_publication MODIFY COLUMN filetype char(10) NOT NULL default 'file'"); echo '<a class="btn btn-default" href="javascript:void(0)" id="details_button">' . get_lang('Details') . '</a><br />'; echo '<div id="details" style="display:none">'; // Migrate using the migration files located in: // src/Chamilo/CoreBundle/Migrations/Schema/V110 $result = migrate(110, $manager); echo '</div>'; if ($result) { error_log('Migrations files were executed.'); fixIds($manager); include 'update-files-1.9.0-1.10.0.inc.php'; // Only updates the configuration.inc.php with the new version include 'update-configuration.inc.php'; $configurationFiles = array('mail.conf.php', 'profile.conf.php', 'course_info.conf.php', 'add_course.conf.php', 'events.conf.php', 'auth.conf.php', 'portfolio.conf.php'); foreach ($configurationFiles as $file) { if (file_exists(api_get_path(SYS_CODE_PATH) . 'inc/conf/' . $file)) { copy(api_get_path(SYS_CODE_PATH) . 'inc/conf/' . $file, api_get_path(CONFIGURATION_PATH) . $file); } } } else { error_log('There was an error during running migrations. Check error.log');
function cliMain($argv) { $argc = count($argv); if ($argc < 2) { die("Usage: zombie.php <action> <option=value> ...\n" . "Availabe actions:\n" . "\tcompile\n" . "\tcreate-app\n"); } $action = $argv[1]; $options = array(); for ($i = 2; $i < $argc; ++$i) { $opt = explode("=", $argv[$i], 2); if (count($opt) == 2) { $options[$opt[0]] = $opt[1]; } else { $options[$opt[0]] = true; } } if ($action == "generate-app") { if (!isset($options['app'])) { die("Usage: zombie.php generate-app app=<app name> [template=<template_name>] [option=<value>] ...\n"); } $template = isset($options['template']) ? $options['template'] : 'basic'; $base_dir = "/config/generator"; $template_file = realpath(__DIR__ . "/../config/generator/" . $template) . "/template.php"; if (!file_exists($template_file)) { $base_dir = "/zombie-core/generator/"; $template_file = __DIR__ . "/generator/" . $template . "/template.php"; if (!file_exists($template_file)) { die("unknown template: " . $template . "\n"); } } $app = $options['app']; require_once __DIR__ . "/generator/ZombieTemplate.php"; require $template_file; $template_class = underscoreToClass($template . "_template"); $template = new $template_class($template, $app, $base_dir, $options); $template->run(); } else { if ($action == "compile") { require __DIR__ . "/util/compile/compile.php"; compile($options); } else { if ($action == "migrate") { require __DIR__ . "/util/migrate/migrate.php"; migrate($options); } else { if ($action == "deploy") { require __DIR__ . "/util/deploy.php"; deploy(); } else { if ($action == "install-package") { if (!isset($options['name'])) { die("Usage: zombie.php install-package name=<package name>\n"); } require __DIR__ . "/packages/installer.php"; installPackage($options['name']); } else { if ($action == "kachow") { echo "kachow!\n"; } else { echo "Error: unknown action '" . $action . "'.\n"; } } } } } } }
function safecss_init() { define('SAFECSS_USE_ACE', !jetpack_is_mobile() && !Jetpack_User_Agent_Info::is_ipad() && apply_filters('safecss_use_ace', true)); // Register safecss as a custom post_type // Explicit capability definitions are largely unnecessary because the posts are manipulated in code via an options page, managing CSS revisions does check the capabilities, so let's ensure that the proper caps are checked. register_post_type('safecss', array('supports' => array('revisions'), 'label' => 'Custom CSS', 'can_export' => false, 'rewrite' => false, 'capabilities' => array('edit_post' => 'edit_theme_options', 'read_post' => 'read', 'delete_post' => 'edit_theme_options', 'edit_posts' => 'edit_theme_options', 'edit_others_posts' => 'edit_theme_options', 'publish_posts' => 'edit_theme_options', 'read_private_posts' => 'read'))); // Short-circuit WP if this is a CSS stylesheet request if (isset($_GET['custom-css'])) { header('Content-Type: text/css', true, 200); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT'); // 1 year safecss_print(); exit; } if (isset($_GET['page']) && 'editcss' == $_GET['page'] && is_admin()) { // Do migration routine if necessary migrate(); do_action('safecss_migrate_post'); } add_action('wp_head', 'safecss_style', 101); if (!current_user_can('switch_themes') && !is_super_admin()) { return; } add_action('admin_menu', 'safecss_menu'); if (isset($_POST['safecss']) && false == strstr($_SERVER['REQUEST_URI'], 'options.php')) { check_admin_referer('safecss'); // Remove wp_filter_post_kses, this causes CSS escaping issues remove_filter('content_save_pre', 'wp_filter_post_kses'); remove_filter('content_filtered_save_pre', 'wp_filter_post_kses'); remove_all_filters('content_save_pre'); do_action('safecss_save_pre'); $warnings = array(); safecss_class(); $csstidy = new csstidy(); $csstidy->optimise = new safecss($csstidy); $csstidy->set_cfg('remove_bslash', false); $csstidy->set_cfg('compress_colors', false); $csstidy->set_cfg('compress_font-weight', false); $csstidy->set_cfg('optimise_shorthands', 0); $csstidy->set_cfg('remove_last_;', false); $csstidy->set_cfg('case_properties', false); $csstidy->set_cfg('discard_invalid_properties', true); $csstidy->set_cfg('css_level', 'CSS3.0'); $csstidy->set_cfg('preserve_css', true); $csstidy->set_cfg('template', dirname(__FILE__) . '/csstidy/wordpress-standard.tpl'); $css = $orig = stripslashes($_POST['safecss']); $css = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $prev = $css); if ($css != $prev) { $warnings[] = 'preg_replace found stuff'; } // Some people put weird stuff in their CSS, KSES tends to be greedy $css = str_replace('<=', '<=', $css); // Why KSES instead of strip_tags? Who knows? $css = wp_kses_split($prev = $css, array(), array()); $css = str_replace('>', '>', $css); // kses replaces lone '>' with > // Why both KSES and strip_tags? Because we just added some '>'. $css = strip_tags($css); if ($css != $prev) { $warnings[] = 'kses found stuff'; } do_action('safecss_parse_pre', $csstidy, $css); $csstidy->parse($css); do_action('safecss_parse_post', $csstidy, $warnings); $css = $csstidy->print->plain(); if (isset($_POST['custom_content_width']) && intval($_POST['custom_content_width']) > 0) { $custom_content_width = intval($_POST['custom_content_width']); } else { $custom_content_width = false; } if ($_POST['add_to_existing'] == 'true') { $add_to_existing = 'yes'; } else { $add_to_existing = 'no'; } if ($_POST['action'] == 'preview' || safecss_is_freetrial()) { // Save the CSS $safecss_revision_id = save_revision($css, true); // Cache Buster update_option('safecss_preview_rev', intval(get_option('safecss_preview_rev')) + 1); update_metadata('post', $safecss_revision_id, 'custom_css_add', $add_to_existing); update_metadata('post', $safecss_revision_id, 'content_width', $custom_content_width); if ($_POST['action'] == 'preview') { wp_safe_redirect(add_query_arg('csspreview', 'true', get_option('home'))); exit; } do_action('safecss_save_preview_post'); } // Save the CSS $safecss_post_id = save_revision($css); $safecss_post_revision = get_current_revision(); update_option('safecss_rev', intval(get_option('safecss_rev')) + 1); update_post_meta($safecss_post_id, 'custom_css_add', $add_to_existing); update_post_meta($safecss_post_id, 'content_width', $custom_content_width); update_metadata('post', $safecss_post_revision['ID'], 'custom_css_add', $add_to_existing); update_metadata('post', $safecss_post_revision['ID'], 'content_width', $custom_content_width); add_action('admin_notices', 'safecss_saved'); } // Modify all internal links so that preview state persists if (safecss_is_preview()) { ob_start('safecss_buffer'); } }
<?php // こんな感じに使えると良いな... // SQLから更新後スキーマを作成 $db1 = MySQLDatabase::fromSQL($sql); // PDOから現在のスキーマを作成 $db2 = MySQLDatabase::fromPDO($pdo); // 差分チェック if ($db1 != $db2) { // 差分を作成 $dbdiff = $db2 . diff($db1); // 差分をSQLとして表示 echo $dbdiff; // 更新 $dbdiff . migrate($pdo); } // テーブル名やカラム名のリネームは別に情報を渡す // 差分チェック if ($db1 != $db2) { // 差分を作成 $dbdiff = $db2 . diff($db1, ['table' => ['oldname1' => 'newname1', 'oldname2' => 'newname2'], 'column' => ['table1' => ['oldcolumn1' => 'newcolumn1', 'oldcolumn2' => 'newcolumn2'], 'table2' => ['oldcolumn1' => 'newcolumn1']]]); // 差分をSQLとして表示 echo $dbdiff; // 更新 $dbdiff . migrate($pdo); }
if (isset($_POST['formFilePath'])) { $options_array['filePath'] = $_POST['formFilePath']; } if (isset($_POST['formContentTypes'])) { $options_array['formContentTypes'] = $_POST['formContentTypes']; } if (isset($_POST['formTerms'])) { $options_array['formTerms'] = $_POST['formTerms']; } if (isset($_POST['formDefaultCategory'])) { $options_array['formDefaultCategory'] = $_POST['formDefaultCategory']; } if (isset($_POST['formPermalinkStructure'])) { $options_array['formPermalinkStructure'] = $_POST['formPermalinkStructure']; } $errors = migrate($wp_settings_array, $d_settings_array, $options_array); include "display_step03.migrate.inc.php"; displayResultsPage($wp_settings_array, $d_settings_array, $errors); break; case 4: default: /* print "<pre style='font-size:small'>"; print_r($_POST); print '</pre>'; print '<hr />'; print "<pre style='font-size:small'>"; print_r($options_array); print '</pre>'; print '<hr />'; */
case '1.9.8.2': case '1.9.10': case '1.9.10.2': // Fix type "enum" before running the migration with Doctrine Database::query("ALTER TABLE course_category MODIFY COLUMN auth_course_child VARCHAR(40) DEFAULT 'TRUE'"); Database::query("ALTER TABLE course_category MODIFY COLUMN auth_cat_child VARCHAR(40) DEFAULT 'TRUE'"); Database::query("ALTER TABLE c_quiz_answer MODIFY COLUMN hotspot_type varchar(40) default NULL"); Database::query("ALTER TABLE c_tool MODIFY COLUMN target varchar(20) NOT NULL default '_self'"); Database::query("ALTER TABLE c_link MODIFY COLUMN on_homepage char(10) NOT NULL default '0'"); Database::query("ALTER TABLE c_blog_rating MODIFY COLUMN rating_type char(40) NOT NULL default 'post'"); Database::query("ALTER TABLE c_survey MODIFY COLUMN anonymous char(10) NOT NULL default '0'"); Database::query("ALTER TABLE c_document MODIFY COLUMN filetype char(10) NOT NULL default 'file'"); Database::query("ALTER TABLE c_student_publication MODIFY COLUMN filetype char(10) NOT NULL default 'file'"); // Migrate using the migration files located in: // src/Chamilo/CoreBundle/Migrations/Schema/V110 migrate(110, $manager); fixIds($manager); include 'update-files-1.9.0-1.10.0.inc.php'; // Only updates the configuration.inc.php with the new version include 'update-configuration.inc.php'; $configurationFiles = array('mail.conf.php', 'profile.conf.php', 'course_info.conf.php', 'add_course.conf.php', 'events.conf.php', 'auth.conf.php', 'portfolio.conf.php'); foreach ($configurationFiles as $file) { if (file_exists(api_get_path(SYS_CODE_PATH) . 'inc/conf/' . $file)) { copy(api_get_path(SYS_CODE_PATH) . 'inc/conf/' . $file, api_get_path(CONFIGURATION_PATH) . $file); } } break; default: break; } } else {