Пример #1
0
 /**
  * @param Mlp_Db_Schema_Interface $db_info
  * @param array                   $columns
  * @return false|int
  */
 private function insert_default(Mlp_Db_Schema_Interface $db_info, array $columns)
 {
     $content = $db_info->get_default_content();
     if (empty($content)) {
         return 0;
     }
     $table = $db_info->get_table_name();
     $to_remove = $db_info->get_autofilled_keys();
     foreach ($to_remove as $remove_key) {
         unset($columns[$remove_key]);
     }
     $keys = join(",", array_keys($columns));
     $sql = "INSERT INTO {$table} ( {$keys} ) VALUES " . $content;
     return $this->wpdb->query($sql);
 }
 /**
  * Load the localization
  *
  * @since 0.1
  * @uses load_plugin_textdomain, plugin_basename
  * @param Mlp_Db_Schema_Interface $languages
  * @return void
  */
 private function import_active_languages(Mlp_Db_Schema_Interface $languages)
 {
     // get active languages
     $mlp_settings = get_site_option('inpsyde_multilingual');
     if (empty($mlp_settings)) {
         return;
     }
     $table = $languages->get_table_name();
     $sql = 'SELECT ID FROM ' . $table . 'WHERE wp_locale = %s OR iso_639_1 = %s';
     foreach ($mlp_settings as $mlp_site) {
         $text = $mlp_site['text'] != '' ? $mlp_site['text'] : $mlp_site['lang'];
         $query = $this->wpdb->prepare($sql, $mlp_site['lang'], $mlp_site['lang']);
         $lang_id = $this->wpdb->get_var($query);
         // language not found -> insert
         if (empty($lang_id)) {
             // @todo add custom name
             $this->wpdb->insert($table, array('english_name' => $text, 'wp_locale' => $mlp_site['lang'], 'http_name' => str_replace('_', '-', $mlp_site['lang'])));
         } else {
             $this->wpdb->update($table, array('priority' => 10), array('ID' => $lang_id));
         }
     }
 }
 /**
  * Insert default content into the given table.
  *
  * @param Mlp_Db_Schema_Interface $db_info Table information.
  * @param array                   $columns Table columns.
  *
  * @return int|bool
  */
 private function insert_default(Mlp_Db_Schema_Interface $db_info, array $columns)
 {
     $table = $db_info->get_table_name();
     // Bail if the table is not empty
     $temp = $this->wpdb->query("SELECT 1 FROM {$table} LIMIT 1");
     if ($temp) {
         return 0;
     }
     $content = $db_info->get_default_content();
     if (empty($content)) {
         return 0;
     }
     $to_remove = $db_info->get_autofilled_keys();
     foreach ($to_remove as $remove_key) {
         unset($columns[$remove_key]);
     }
     $keys = join(",", array_keys($columns));
     $sql = "INSERT INTO {$table} ({$keys}) VALUES {$content};";
     return $this->wpdb->query($sql);
 }