MO::import_from_reader() WordPress Method

This method is used to read content from an external WordPress blog and import it into the current WordPress installation. This can be useful for importing content from another site that you own, or for importing content from a third-party WordPress blog.

MO::import_from_reader( POMO_FileReader $reader ) #


Parameters

$reader

(POMO_FileReader)(Required)


Top ↑

Return

(bool) True if the import was successful, otherwise false.


Top ↑

Source

File: wp-includes/pomo/mo.php

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
public function import_from_reader( $reader ) {
    $endian_string = MO::get_byteorder( $reader->readint32() );
    if ( false === $endian_string ) {
        return false;
    }
    $reader->setEndian( $endian_string );
 
    $endian = ( 'big' === $endian_string ) ? 'N' : 'V';
 
    $header = $reader->read( 24 );
    if ( $reader->strlen( $header ) != 24 ) {
        return false;
    }
 
    // Parse header.
    $header = unpack( "{$endian}revision/{$endian}total/{$endian}originals_lengths_addr/{$endian}translations_lengths_addr/{$endian}hash_length/{$endian}hash_addr", $header );
    if ( ! is_array( $header ) ) {
        return false;
    }
 
    // Support revision 0 of MO format specs, only.
    if ( 0 != $header['revision'] ) {
        return false;
    }
 
    // Seek to data blocks.
    $reader->seekto( $header['originals_lengths_addr'] );
 
    // Read originals' indices.
    $originals_lengths_length = $header['translations_lengths_addr'] - $header['originals_lengths_addr'];
    if ( $originals_lengths_length != $header['total'] * 8 ) {
        return false;
    }
 
    $originals = $reader->read( $originals_lengths_length );
    if ( $reader->strlen( $originals ) != $originals_lengths_length ) {
        return false;
    }
 
    // Read translations' indices.
    $translations_lengths_length = $header['hash_addr'] - $header['translations_lengths_addr'];
    if ( $translations_lengths_length != $header['total'] * 8 ) {
        return false;
    }
 
    $translations = $reader->read( $translations_lengths_length );
    if ( $reader->strlen( $translations ) != $translations_lengths_length ) {
        return false;
    }
 
    // Transform raw data into set of indices.
    $originals    = $reader->str_split( $originals, 8 );
    $translations = $reader->str_split( $translations, 8 );
 
    // Skip hash table.
    $strings_addr = $header['hash_addr'] + $header['hash_length'] * 4;
 
    $reader->seekto( $strings_addr );
 
    $strings = $reader->read_all();
    $reader->close();
 
    for ( $i = 0; $i < $header['total']; $i++ ) {
        $o = unpack( "{$endian}length/{$endian}pos", $originals[ $i ] );
        $t = unpack( "{$endian}length/{$endian}pos", $translations[ $i ] );
        if ( ! $o || ! $t ) {
            return false;
        }
 
        // Adjust offset due to reading strings to separate space before.
        $o['pos'] -= $strings_addr;
        $t['pos'] -= $strings_addr;
 
        $original    = $reader->substr( $strings, $o['pos'], $o['length'] );
        $translation = $reader->substr( $strings, $t['pos'], $t['length'] );
 
        if ( '' === $original ) {
            $this->set_headers( $this->make_headers( $translation ) );
        } else {
            $entry                          = &$this->make_entry( $original, $translation );
            $this->entries[ $entry->key() ] = &$entry;
        }
    }
    return true;
}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.