Plugin para importar dedicatorias desde ficheros CSV (no en producción)

git-svn-id: https://192.168.0.254/svn/Proyectos.ASong2U_Web/trunk@153 cd1a4ea2-8c7f-e448-aada-19d1fee9e1d6
This commit is contained in:
David Arranz 2012-08-29 19:16:21 +00:00
parent 6f347b445d
commit 770b3cab30
34 changed files with 7424 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,23 @@
The MIT License
Copyright (c) <2008> <Kazuyoshi Tlacaelel>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,19 @@
EXAMPLES
located in the file "docs/examples/EXAMPLES"
LICENSE
located in the file "LICENSE"
PROJECT
http://code.google.com/p/php-csv-parser/
TESTS
located in the folder "tests"
AUTHOR
Kazuyoshi Tlacaelel
DOCUMENTATION
http://code.google.com/p/php-csv-parser/

View File

@ -0,0 +1,72 @@
#summary Quick sample!
#labels Featured
Lets get started with quick samples
= Quick Samples =
*my_file.csv*
{{{
name, age
john, 13
takaka, 8
}}}
*php script*
{{{
<?php
$csv = new File_CSV_DataSource;
$csv->load('my_file.csv'); // boolean
$csv->getHeaders(); // array('name', 'age');
$csv->getColumn('name'); // array('john', 'tanaka');
$csv->row(1); // array('john', '13');
$csv->connect(); // array(
// array('name' => 'john', 'age' => 13),
// array('name' => 'tanaka', 'age' => 8)
// );
?>
}}}
= Detailed Usage =
{{{
<?php
// usage sample
$csv = new File_CSV_DataSource;
// tell the object to parse a specific file
if ($csv->load('my_file.csv')) {
// execute the following if given file is usable
// get the headers found in file
$array = $csv->getHeaders();
// get a specific column from csv file
$csv->getColumn($array[2]);
// get each record with its related header
// ONLY if all records length match the number
// of headers
if ($csv->isSymmetric()) {
$array = $csv->connect();
} else {
// fetch records that dont match headers length
$array = $csv->getAsymmetricRows();
}
// ignore everything and simply get the data as an array
$array = $csv->getrawArray();
}
?>
}}}

View File

@ -0,0 +1,508 @@
<?php
require_once 'PHPUnit/Framework.php';
require_once "File/CSV/DataSource.php";
require_once "File/CSV/tests/fixtures/csv.php";
/**
* Test class for File_CSV_DataSource.
* Generated by PHPUnit on 2008-10-08 at 20:47:55.
*/
class File_CSV_DataSourceTest extends PHPUnit_Framework_TestCase
{
protected $csv;
protected function setUp()
{
$this->csv = new File_CSV_DataSource;
}
protected function tearDown()
{
$this->csv = null;
}
public function test_uses_must_load_valid_files()
{
// must return true when a file is valid
foreach (fix('valid_files') as $file => $msg) {
$this->assertTrue($this->csv->load(path($file)), $msg);
}
}
public function testSettings()
{
$new_delim = '>>>>';
$this->csv->settings(array('delimiter' => $new_delim));
$expected = array(
'delimiter' => $new_delim,
'eol' => ";",
'length' => 999999,
'escape' => '"'
);
$msg = 'settings where not parsed correctly!';
$this->assertEquals($expected, $this->csv->settings, $msg);
}
public function testHeaders()
{
$this->csv->load(path('symmetric.csv'));
$result = $this->csv->getHeaders();
$this->assertEquals(fix('symmetric_headers'), $result);
}
public function testConnect()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertEquals(fix('symmetric_connection'), $this->csv->connect());
}
public function test_connect_must_return_emtpy_arr_when_not_aisSymmetric()
{
$this->assertTrue($this->csv->load(path('escape_ng.csv')));
$this->assertEquals(array(), $this->csv->connect());
}
public function testSymmetric_OK()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->isSymmetric());
}
public function testSymmetric_NG()
{
$this->assertTrue($this->csv->load(path('asymmetric.csv')));
$this->assertFalse($this->csv->isSymmetric());
}
public function testAsymmetry()
{
$this->assertTrue($this->csv->load(path('asymmetric.csv')));
$result = $this->csv->getAsymmetricRows();
$this->assertEquals(fix('asymmetric_rows'), $result);
}
public function testColumn()
{
$this->assertTrue($this->csv->load(path('asymmetric.csv')));
$result = $this->csv->getColumn('header_c');
$this->assertEquals(fix('expected_column'), $result);
}
public function testRaw_array()
{
$this->assertTrue($this->csv->load(path('raw.csv')));
$this->assertEquals(fix('expected_raw'), $this->csv->getRawArray());
}
public function test_if_connect_ignores_valid_escaped_delims()
{
$this->assertTrue($this->csv->load(path('escape_ok.csv')));
$this->assertEquals(fix('expected_escaped'), $this->csv->connect());
}
public function test_create_headers_must_generate_headers_for_symmetric_data()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->createHeaders('COL'));
$this->assertEquals(fix('expected_headers'), $this->csv->getHeaders());
}
public function tets_create_headers_must_not_create_when_data_is_aisSymmetric()
{
$this->assertTrue($this->csv->load(path('asymmetric.csv')));
$this->assertFalse($this->csv->createHeaders('COL'));
$this->assertEquals(fix('original_headers'), $this->csv->getHeaders());
}
public function test_inject_headers_must_inject_headers_for_symmetric_data()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertEquals(fix('original_headers'), $this->csv->getHeaders());
$this->assertTrue($this->csv->setHeaders(fix('expected_headers')));
$this->assertEquals(fix('expected_headers'), $this->csv->getHeaders());
$this->assertEquals(fix('symmetric_raw_data'), $this->csv->getRows());
}
public function test_inject_headers_must_not_inject_when_data_is_aisSymmetric()
{
$this->assertTrue($this->csv->load(path('asymmetric.csv')));
$this->assertEquals(fix('original_headers'), $this->csv->getHeaders());
$this->assertFalse($this->csv->setHeaders(fix('expected_headers')));
$this->assertEquals(fix('original_headers'), $this->csv->getHeaders());
}
public function test_row_count_is_correct()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$expected_count = count(fix('symmetric_connection'));
$this->assertEquals($expected_count, $this->csv->countRows());
}
public function test_row_fetching_returns_correct_result()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$expected = fix('eighth_row_from_symmetric');
$this->assertEquals($expected, $this->csv->getRow(8));
}
public function test_row_must_be_empty_array_when_row_does_not_exist()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertEquals(array(), $this->csv->getRow(-1));
$this->assertEquals(array(), $this->csv->getRow(10));
}
public function test_connect_must_build_relationship_for_needed_headers_only()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$result = $this->csv->connect(array('header_a'));
$this->assertEquals(fix('header_a_connection'), $result);
}
public function test_connect_must_return_empty_array_if_given_params_are_of_invalid_datatype()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertEquals(array(), $this->csv->connect('header_a'));
}
public function test_connect_should_ignore_non_existant_headers_AND_return_empty_array()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertEquals(array(), $this->csv->connect(array('non_existent_header')));
}
public function test_connect_should_ignore_non_existant_headers_BUT_get_existent_ones()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$result = $this->csv->connect(array('non_existent_header', 'header_a'));
$this->assertEquals(fix('header_a_connection'), $result);
}
public function test_count_getHeaders()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertEquals(5, $this->csv->countHeaders());
}
public function test_raw_array_must_remove_empty_lines()
{
$this->assertTrue($this->csv->load(path('symmetric_with_empty_lines.csv')));
$this->assertEquals(fix('symmetric_connection'), $this->csv->connect());
}
public function test_raw_array_must_remove_empty_records()
{
$this->assertTrue($this->csv->load(path('symmetric_with_empty_records.csv')));
$this->assertEquals(fix('symmetric_connection'), $this->csv->connect());
}
public function test_range_of_rows_should_retrive_specific_rows_only()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$expected = fix('symmetric_range_of_rows');
$this->assertEquals($expected, $this->csv->getRows(range(1, 2)));
}
public function test_non_existent_rows_in_range_should_be_ignored()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$expected = fix('symmetric_range_of_rows');
$this->assertEquals($expected, $this->csv->getRows(array(22, 19, 1, 2)));
}
public function test_fist_row_must_be_zero()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertEquals(fix('first_row_from_symmetric'), $this->csv->getRow(0));
}
public function test_uses_must_flush_internal_data_when_new_file_is_given()
{
$this->assertTrue($this->csv->load(path('another_symmetric.csv')));
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertEquals(fix('symmetric_headers'), $this->csv->getHeaders());
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows());
$this->assertEquals(fix('symmetric_raw_data'), $this->csv->getRawArray());
}
public function test_getCell()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertEquals(fix('first_symmetric_cell'), $this->csv->getCell(0, 0));
}
public function test_header_exists()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
foreach (fix('symmetric_headers') as $h) {
$this->assertTrue($this->csv->hasColumn($h));
}
}
public function test_header_exists_must_return_false_when_header_does_not_exist()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertFalse($this->csv->hasColumn(md5('x')));
}
public function test_fill_getCell()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->fillCell(0, 0, 'hoge hoge'));
$this->assertEquals('hoge hoge', $this->csv->getCell(0, 0));
}
public function test_coordinatable_must_return_true_when_coordinates_exist()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->hasCell(0, 0));
$this->assertFalse($this->csv->hasCell(-1, 0));
$this->assertFalse($this->csv->hasCell(0, -1));
$this->assertFalse($this->csv->hasCell(-1, -1));
$this->assertFalse($this->csv->hasCell(1, 11));
}
public function test_fill_column_must_fill_all_values_of_a_getColumn()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$fh = fix('first_symmetric_header');
$this->assertTrue($this->csv->fillColumn($fh, ''));
$this->assertEquals(fix('empty_column'), $this->csv->getColumn($fh));
}
public function test_append_column_must_create_new_header_and_blank_values()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->appendColumn('extra'));
$se = fix('symmetric_extra_header');
$this->assertEquals($se, $this->csv->getHeaders());
$this->assertEquals(fix('empty_column'), $this->csv->getColumn('extra'));
$this->assertEquals(count($se), $this->csv->countHeaders());
}
public function test_symmetrize_must_convert_asymmetric_file()
{
$this->assertTrue($this->csv->load(path('asymmetric.csv')));
$this->csv->symmetrize();
$this->assertTrue($this->csv->isSymmetric());
}
public function test_symetrize_must_not_alter_symmetric_data()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->csv->symmetrize();
$this->assertEquals(fix('symmetric_headers'), $this->csv->getHeaders());
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows());
$this->assertEquals(fix('symmetric_raw_data'), $this->csv->getRawArray());
}
public function test_remove_column_must_remove_last_column_and_return_true()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->removeColumn('header_e'));
$this->assertEquals(fix('symmetric_raw_data_with_last_colum_removed'), $this->csv->getRawArray());
}
public function test_remove_column_must_remove_second_column_and_return_true()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->removeColumn('header_b'));
$this->assertEquals(fix('symmetric_raw_data_with_second_column_removed'), $this->csv->getRawArray());
}
public function test_remove_column_must_return_false_when_column_does_not_exist()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertFalse($this->csv->removeColumn(md5('header_b')));
}
public function test_remove_row_must_remove_first_row_successfully_and_return_true()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->removeRow(0));
$this->assertEquals(fix('symmetric_rows_without_first_row'), $this->csv->getRows());
}
public function test_remove_row_must_remove_only_third_row_and_return_true()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->removeRow(2));
$this->assertEquals(fix('symmetric_rows_without_third_row'), $this->csv->getRows());
}
public function test_remove_row_must_return_false_and_leave_rows_intact_when_row_does_not_exist()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertFalse($this->csv->removeRow(999999));
}
public function test_rows_must_return_all_rows_when_argument_is_not_an_array()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows('lasdjfklsajdf'));
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows(true));
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows(false));
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows(1));
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows(0));
}
public function test_has_row_must_return_true_when_a_row_exists()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->hasRow(1));
}
public function test_row_must_return_false_when_a_row_does_not_exist()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertFalse($this->csv->hasRow(999999));
}
public function test_fill_row_must_fill_a_row_with_a_string_and_return_true()
{
$this->assertTrue($this->csv->load(path('one_row_only.csv')));
$this->assertTrue($this->csv->fillRow(0, 'hello'));
$this->assertEquals(fix('rows_from_one_row_only_plus_one_filled_with_str_hello'), $this->csv->getRows());
}
public function test_fill_row_mus_fill_a_row_with_an_array_and_return_true()
{
$this->assertTrue($this->csv->load(path('one_row_only.csv')));
$this->assertTrue($this->csv->fillRow(0, $this->csv->getHeaders()));
$this->assertEquals(fix('rows_from_one_row_only_plus_one_filled_with_arr_abc'), $this->csv->getRows());
}
public function test_fill_row_must_fill_a_row_with_a_number_and_return_true()
{
$this->assertTrue($this->csv->load(path('one_row_only.csv')));
$this->assertTrue($this->csv->fillRow(0, 1));
$this->assertEquals(fix('rows_from_one_row_only_plus_one_filled_with_num_1'), $this->csv->getRows());
}
public function test_fill_row_must_not_change_anything_when_given_row_does_not_exist_and_return_false()
{
$this->assertTrue($this->csv->load(path('one_row_only.csv')));
$this->assertFalse($this->csv->fillRow(999, 1));
$this->assertEquals(fix('rows_from_one_row_only'), $this->csv->getRows());
}
public function test_fill_row_must_not_change_anything_when_given_value_is_other_than_string_int_or_array_and_return_false()
{
$this->assertTrue($this->csv->load(path('one_row_only.csv')));
$this->assertFalse($this->csv->fillRow(0, new stdClass));
$this->assertEquals(fix('rows_from_one_row_only'), $this->csv->getRows());
}
// be strict, no looking back from the end of array
public function test_fill_row_must_return_false_when_negative_numbers_are_given()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertFalse($this->csv->fillRow(-1, 'xxx'));
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows());
}
public function test_append_row_must_aggregate_a_row_fill_it_with_values_and_return_true()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->appendRow(fix('one_row_for_symmetric')));
$this->assertEquals(fix('symmetric_rows_plus_one'), $this->csv->getRows());
}
public function test_walk_row_must_replace_values_in_a_row_by_using_a_callback_and_be_true()
{
$this->assertTrue($this->csv->load(path('one_row_only.csv')));
$this->assertTrue($this->csv->walkRow(0, 'callback'));
$this->assertEquals(fix('rows_from_one_row_only_plus_one_filled_with_num_1'), $this->csv->getRows());
}
public function test_walk_row_must_return_false_when_callback_does_not_exist()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$non_existent_callback = md5('');
$this->assertFalse($this->csv->walkRow(1, $non_existent_callback));
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows());
$this->assertEquals(fix('symmetric_headers'), $this->csv->getHeaders());
}
public function test_walk_column_must_replace_values_in_a_column_and_be_true()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$fh = fix('first_symmetric_header');
$this->assertTrue($this->csv->walkColumn($fh, 'callback2'));
$this->assertEquals(fix('empty_column'), $this->csv->getColumn($fh));
}
public function test_walk_column_must_return_false_when_callback_does_not_exist()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$fh = fix('first_symmetric_header');
$non_existent_callback = md5('');
$this->assertFalse($this->csv->walkColumn($fh, $non_existent_callback));
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows());
$this->assertEquals(fix('symmetric_headers'), $this->csv->getHeaders());
}
public function test_walk_grid_must_replace_the_whole_data_set_and_be_true()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$this->assertTrue($this->csv->walkGrid('callback2'));
$this->assertEquals(fix('symmetric_rows_empty'), $this->csv->getRows());
}
public function test_walk_grid_must_return_false_when_callback_does_not_exist()
{
$this->assertTrue($this->csv->load(path('symmetric.csv')));
$non_existent_callback = md5('');
$this->assertFalse($this->csv->walkGrid($non_existent_callback));
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows());
$this->assertEquals(fix('symmetric_headers'), $this->csv->getHeaders());
}
public function test_constructor_must_be_equivalent_to_load()
{
$this->csv = new File_CSV_DataSource(path('symmetric.csv'));
$result = $this->csv->getHeaders();
$this->assertEquals(fix('symmetric_headers'), $result);
$this->assertEquals(fix('symmetric_rows'), $this->csv->getRows());
}
public function test_must_append_row_when_csv_file_only_has_headers_and_array_is_passed_returning_true()
{
$this->csv = new File_CSV_DataSource(path('only_headers.csv'));
$this->assertTrue($this->csv->appendRow(array(1, 2, 3)));
$result = array(array('a' => 1, 'b' => 2, 'c' => 3));
$this->assertEquals($result, $this->csv->connect());
}
public function test_must_append_row_when_csv_file_only_has_headers_and_string_is_passed_returning_true()
{
$this->csv = new File_CSV_DataSource(path('only_headers.csv'));
$this->assertTrue($this->csv->appendRow('1'));
$result = array(array('a' => '1', 'b' => '1', 'c' => '1'));
$this->assertEquals($result, $this->csv->connect());
}
public function test_must_append_row_when_csv_file_only_has_headers_and_numeric_value_is_passed_returning_true()
{
$this->csv = new File_CSV_DataSource(path('only_headers.csv'));
$this->assertTrue($this->csv->appendRow(1));
$result = array(array('a' => 1, 'b' => 1, 'c' => 1));
$this->assertEquals($result, $this->csv->connect());
}
public function test_must_use_headers_as_max_row_padding_when_headers_length_is_longer_than_all_rows_length()
{
$this->csv = new File_CSV_DataSource(path('longer_headers.csv'));
$this->csv->symmetrize();
$this->assertEquals(fix('longer_headers'), $this->csv->connect());
}
}
?>

View File

@ -0,0 +1,4 @@
name,age,skill
john,13,knows magic
tanaka,8,makes sushi
jose,5,dances salsa
1 name age skill
2 john 13 knows magic
3 tanaka 8 makes sushi
4 jose 5 dances salsa

View File

@ -0,0 +1,10 @@
header_a, header_b, header_c, header_d, header_e
1aa, 1bb, 1cc, 1dd, 1ee
2aa, 2bb, 2cc, 2dd, 2ee
3aa, 3bb, 3cc, 3dd, 3ee
4aa, 4bb, 4cc, 4dd, 4ee
5aa, 5bb, 5cc, 5dd, 5ee, extra1
6aa, 6bb, 6cc, 6dd, 6ee
7aa, 7bb, 7cc, 7dd, 7ee
8aa, 8bb, 8cc, 8dd, 8ee, extra2
9aa, 9bb, 9cc, 9dd, 9ee
1 header_a, header_b, header_c, header_d, header_e
2 1aa, 1bb, 1cc, 1dd, 1ee
3 2aa, 2bb, 2cc, 2dd, 2ee
4 3aa, 3bb, 3cc, 3dd, 3ee
5 4aa, 4bb, 4cc, 4dd, 4ee
6 5aa, 5bb, 5cc, 5dd, 5ee, extra1
7 6aa, 6bb, 6cc, 6dd, 6ee
8 7aa, 7bb, 7cc, 7dd, 7ee
9 8aa, 8bb, 8cc, 8dd, 8ee, extra2
10 9aa, 9bb, 9cc, 9dd, 9ee

View File

@ -0,0 +1,3 @@
one, two, three
th,ie, adn, thei
thie, adn, thei
1 one, two, three
2 th,ie, adn, thei
3 thie, adn, thei

View File

@ -0,0 +1,3 @@
one, two, three
"thie,", adn, thei
thie, adn, thei
1 one two three
2 thie, adn thei
3 thie adn thei

View File

@ -0,0 +1,4 @@
one, two, three, four, five, six
1, 2, 3
1, 2, 3, 4
, 2, 3, 4
1 one, two, three, four, five, six
2 1, 2, 3
3 1, 2, 3, 4
4 , 2, 3, 4

View File

@ -0,0 +1,2 @@
a,b,c
1,2,3
1 a b c
2 1 2 3

View File

@ -0,0 +1 @@
a,b,c
1 a b c

View File

@ -0,0 +1,5 @@
h_one, h_two, h_three
v_1one, v_1two, v_1three
v_2one, v_2two, v_2three
v_3one, v_3two, v_3three
1 h_one h_two h_three
2 v_1one v_1two v_1three
3 v_2one v_2two v_2three
4 v_3one v_3two v_3three

View File

@ -0,0 +1,10 @@
header_a, header_b, header_c, header_d, header_e
1aa, 1bb, 1cc, 1dd, 1ee
2aa, 2bb, 2cc, 2dd, 2ee
3aa, 3bb, 3cc, 3dd, 3ee
4aa, 4bb, 4cc, 4dd, 4ee
5aa, 5bb, 5cc, 5dd, 5ee
6aa, 6bb, 6cc, 6dd, 6ee
7aa, 7bb, 7cc, 7dd, 7ee
8aa, 8bb, 8cc, 8dd, 8ee
9aa, 9bb, 9cc, 9dd, 9ee
1 header_a header_b header_c header_d header_e
2 1aa 1bb 1cc 1dd 1ee
3 2aa 2bb 2cc 2dd 2ee
4 3aa 3bb 3cc 3dd 3ee
5 4aa 4bb 4cc 4dd 4ee
6 5aa 5bb 5cc 5dd 5ee
7 6aa 6bb 6cc 6dd 6ee
8 7aa 7bb 7cc 7dd 7ee
9 8aa 8bb 8cc 8dd 8ee
10 9aa 9bb 9cc 9dd 9ee

View File

@ -0,0 +1,20 @@
header_a, header_b, header_c, header_d, header_e
1aa, 1bb, 1cc, 1dd, 1ee
2aa, 2bb, 2cc, 2dd, 2ee
3aa, 3bb, 3cc, 3dd, 3ee
4aa, 4bb, 4cc, 4dd, 4ee
5aa, 5bb, 5cc, 5dd, 5ee
6aa, 6bb, 6cc, 6dd, 6ee
7aa, 7bb, 7cc, 7dd, 7ee
8aa, 8bb, 8cc, 8dd, 8ee
9aa, 9bb, 9cc, 9dd, 9ee
1 header_a header_b header_c header_d header_e
2 1aa 1bb 1cc 1dd 1ee
3 2aa 2bb 2cc 2dd 2ee
4 3aa 3bb 3cc 3dd 3ee
5 4aa 4bb 4cc 4dd 4ee
6 5aa 5bb 5cc 5dd 5ee
7 6aa 6bb 6cc 6dd 6ee
8 7aa 7bb 7cc 7dd 7ee
9 8aa 8bb 8cc 8dd 8ee
10 9aa 9bb 9cc 9dd 9ee

View File

@ -0,0 +1,28 @@
header_a, header_b, header_c, header_d, header_e
, , , ,
, , , ,
, , , ,
, , , ,
1aa, 1bb, 1cc, 1dd, 1ee
2aa, 2bb, 2cc, 2dd, 2ee
3aa, 3bb, 3cc, 3dd, 3ee
, , , ,
4aa, 4bb, 4cc, 4dd, 4ee
, , , ,
5aa, 5bb, 5cc, 5dd, 5ee
, , , ,
6aa, 6bb, 6cc, 6dd, 6ee
, , , ,
, , , ,
, , , ,
, , , ,
7aa, 7bb, 7cc, 7dd, 7ee
8aa, 8bb, 8cc, 8dd, 8ee
9aa, 9bb, 9cc, 9dd, 9ee
, , , ,
, , , ,
, , , ,
, , , ,
, , , ,
, , , ,
, , , ,
1 header_a header_b header_c header_d header_e
2
3
4
5
6 1aa 1bb 1cc 1dd 1ee
7 2aa 2bb 2cc 2dd 2ee
8 3aa 3bb 3cc 3dd 3ee
9
10 4aa 4bb 4cc 4dd 4ee
11
12 5aa 5bb 5cc 5dd 5ee
13
14 6aa 6bb 6cc 6dd 6ee
15
16
17
18
19 7aa 7bb 7cc 7dd 7ee
20 8aa 8bb 8cc 8dd 8ee
21 9aa 9bb 9cc 9dd 9ee
22
23
24
25
26
27
28

View File

@ -0,0 +1,10 @@
header_a, header_b, header_c, header_d, header_e
1aa, 1bb, 1cc, 1dd, 1ee
2aa, 2bb, 2cc, 2dd, 2ee
3aa , 3bb , 3cc, 3dd, 3ee
4aa, 4bb, 4cc, 4dd, 4ee
5aa, 5bb, 5cc, 5dd, 5ee
6aa, 6bb, 6cc, 6dd, 6ee
7aa, 7bb, 7cc, 7dd, 7ee
8aa, 8bb, 8cc, 8dd, 8ee
9aa, 9bb, 9cc, 9dd, 9ee
1 header_a header_b header_c header_d header_e
2 1aa 1bb 1cc 1dd 1ee
3 2aa 2bb 2cc 2dd 2ee
4 3aa 3bb 3cc 3dd 3ee
5 4aa 4bb 4cc 4dd 4ee
6 5aa 5bb 5cc 5dd 5ee
7 6aa 6bb 6cc 6dd 6ee
8 7aa 7bb 7cc 7dd 7ee
9 8aa 8bb 8cc 8dd 8ee
10 9aa 9bb 9cc 9dd 9ee

View File

@ -0,0 +1,999 @@
<?php
$fixtures = array (
'symmetric_headers' =>
array (
0 => 'header_a',
1 => 'header_b',
2 => 'header_c',
3 => 'header_d',
4 => 'header_e',
),
'rows_from_one_row_only' => array (
array (
0 => '1',
1 => '2',
2 => '3',
),
),
'rows_from_one_row_only_plus_one_filled_with_num_1' => array (
array (
0 => '1',
1 => '1',
2 => '1',
),
),
'rows_from_one_row_only_plus_one_filled_with_str_hello' => array (
array (
0 => 'hello',
1 => 'hello',
2 => 'hello',
),
),
'rows_from_one_row_only_plus_one_filled_with_arr_abc' => array (
array (
0 => 'a',
1 => 'b',
2 => 'c',
),
),
'symmetric_raw_data_with_second_column_removed' =>
array (
0 =>
array (
0 => 'header_a',
1 => 'header_c',
2 => 'header_d',
3 => 'header_e',
),
1 =>
array (
0 => '1aa',
1 => '1cc',
2 => '1dd',
3 => '1ee',
),
2 =>
array (
0 => '2aa',
1 => '2cc',
2 => '2dd',
3 => '2ee',
),
3 =>
array (
0 => '3aa',
1 => '3cc',
2 => '3dd',
3 => '3ee',
),
4 =>
array (
0 => '4aa',
1 => '4cc',
2 => '4dd',
3 => '4ee',
),
5 =>
array (
0 => '5aa',
1 => '5cc',
2 => '5dd',
3 => '5ee',
),
6 =>
array (
0 => '6aa',
1 => '6cc',
2 => '6dd',
3 => '6ee',
),
7 =>
array (
0 => '7aa',
1 => '7cc',
2 => '7dd',
3 => '7ee',
),
8 =>
array (
0 => '8aa',
1 => '8cc',
2 => '8dd',
3 => '8ee',
),
9 =>
array (
0 => '9aa',
1 => '9cc',
2 => '9dd',
3 => '9ee',
)
),
'symmetric_raw_data_with_last_colum_removed' =>
array (
0 =>
array (
0 => 'header_a',
1 => 'header_b',
2 => 'header_c',
3 => 'header_d',
),
1 =>
array (
0 => '1aa',
1 => '1bb',
2 => '1cc',
3 => '1dd',
),
2 =>
array (
0 => '2aa',
1 => '2bb',
2 => '2cc',
3 => '2dd',
),
3 =>
array (
0 => '3aa',
1 => '3bb',
2 => '3cc',
3 => '3dd',
),
4 =>
array (
0 => '4aa',
1 => '4bb',
2 => '4cc',
3 => '4dd',
),
5 =>
array (
0 => '5aa',
1 => '5bb',
2 => '5cc',
3 => '5dd',
),
6 =>
array (
0 => '6aa',
1 => '6bb',
2 => '6cc',
3 => '6dd',
),
7 =>
array (
0 => '7aa',
1 => '7bb',
2 => '7cc',
3 => '7dd',
),
8 =>
array (
0 => '8aa',
1 => '8bb',
2 => '8cc',
3 => '8dd',
),
9 =>
array (
0 => '9aa',
1 => '9bb',
2 => '9cc',
3 => '9dd',
),
),
'first_symmetric_header' => 'header_a',
'first_symmetric_cell' => '1aa',
'symmetric_extra_header' =>
array (
0 => 'header_a',
1 => 'header_b',
2 => 'header_c',
3 => 'header_d',
4 => 'header_e',
5 => 'extra',
),
'first_row_from_symmetric' =>
array (
0 => '1aa',
1 => '1bb',
2 => '1cc',
3 => '1dd',
4 => '1ee',
),
'eighth_row_from_symmetric' =>
array (
0 => '9aa',
1 => '9bb',
2 => '9cc',
3 => '9dd',
4 => '9ee',
),
'valid_files' =>
array (
'empty.csv' => 'emtpy csv file',
'uppercased.CSV' => 'upper cased extension',
'multcased.CsV' => 'multiple cased extension',
'symmetric.csv' => 'symmetric data',
'asymmetric.csv' => 'asymmetric data',
'escape_ok.csv' => 'valid escape syntax file',
'escape_ok.csv' => 'valid escape syntax file',
'non_csv_extension.txt' => 'non csv-extension file',
),
'expected_headers' =>
array (
0 => 'COL_1',
1 => 'COL_2',
2 => 'COL_3',
3 => 'COL_4',
4 => 'COL_5',
),
'original_headers' =>
array (
0 => 'header_a',
1 => 'header_b',
2 => 'header_c',
3 => 'header_d',
4 => 'header_e',
),
'symmetric_connection' =>
array (
0 =>
array (
'header_a' => '1aa',
'header_b' => '1bb',
'header_c' => '1cc',
'header_d' => '1dd',
'header_e' => '1ee',
),
1 =>
array (
'header_a' => '2aa',
'header_b' => '2bb',
'header_c' => '2cc',
'header_d' => '2dd',
'header_e' => '2ee',
),
2 =>
array (
'header_a' => '3aa',
'header_b' => '3bb',
'header_c' => '3cc',
'header_d' => '3dd',
'header_e' => '3ee',
),
3 =>
array (
'header_a' => '4aa',
'header_b' => '4bb',
'header_c' => '4cc',
'header_d' => '4dd',
'header_e' => '4ee',
),
4 =>
array (
'header_a' => '5aa',
'header_b' => '5bb',
'header_c' => '5cc',
'header_d' => '5dd',
'header_e' => '5ee',
),
5 =>
array (
'header_a' => '6aa',
'header_b' => '6bb',
'header_c' => '6cc',
'header_d' => '6dd',
'header_e' => '6ee',
),
6 =>
array (
'header_a' => '7aa',
'header_b' => '7bb',
'header_c' => '7cc',
'header_d' => '7dd',
'header_e' => '7ee',
),
7 =>
array (
'header_a' => '8aa',
'header_b' => '8bb',
'header_c' => '8cc',
'header_d' => '8dd',
'header_e' => '8ee',
),
8 =>
array (
'header_a' => '9aa',
'header_b' => '9bb',
'header_c' => '9cc',
'header_d' => '9dd',
'header_e' => '9ee',
),
),
'asymmetric_rows' =>
array (
0 =>
array (
0 => '5aa',
1 => '5bb',
2 => '5cc',
3 => '5dd',
4 => '5ee',
5 => 'extra1',
),
1 =>
array (
0 => '8aa',
1 => '8bb',
2 => '8cc',
3 => '8dd',
4 => '8ee',
5 => 'extra2',
),
),
'empty_column' =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
4 => '',
5 => '',
6 => '',
7 => '',
8 => '',
),
'expected_column' =>
array (
0 => '1cc',
1 => '2cc',
2 => '3cc',
3 => '4cc',
4 => '5cc',
5 => '6cc',
6 => '7cc',
7 => '8cc',
8 => '9cc',
),
'symmetric_rows_without_first_row' =>
array (
0 =>
array (
0 => '2aa',
1 => '2bb',
2 => '2cc',
3 => '2dd',
4 => '2ee',
),
1 =>
array (
0 => '3aa',
1 => '3bb',
2 => '3cc',
3 => '3dd',
4 => '3ee',
),
2 =>
array (
0 => '4aa',
1 => '4bb',
2 => '4cc',
3 => '4dd',
4 => '4ee',
),
3 =>
array (
0 => '5aa',
1 => '5bb',
2 => '5cc',
3 => '5dd',
4 => '5ee',
),
4 =>
array (
0 => '6aa',
1 => '6bb',
2 => '6cc',
3 => '6dd',
4 => '6ee',
),
5 =>
array (
0 => '7aa',
1 => '7bb',
2 => '7cc',
3 => '7dd',
4 => '7ee',
),
6 =>
array (
0 => '8aa',
1 => '8bb',
2 => '8cc',
3 => '8dd',
4 => '8ee',
),
7 =>
array (
0 => '9aa',
1 => '9bb',
2 => '9cc',
3 => '9dd',
4 => '9ee',
),
),
'symmetric_rows_without_third_row' =>
array (
0 =>
array (
0 => '1aa',
1 => '1bb',
2 => '1cc',
3 => '1dd',
4 => '1ee',
),
1 =>
array (
0 => '2aa',
1 => '2bb',
2 => '2cc',
3 => '2dd',
4 => '2ee',
),
2 =>
array (
0 => '4aa',
1 => '4bb',
2 => '4cc',
3 => '4dd',
4 => '4ee',
),
3 =>
array (
0 => '5aa',
1 => '5bb',
2 => '5cc',
3 => '5dd',
4 => '5ee',
),
4 =>
array (
0 => '6aa',
1 => '6bb',
2 => '6cc',
3 => '6dd',
4 => '6ee',
),
5 =>
array (
0 => '7aa',
1 => '7bb',
2 => '7cc',
3 => '7dd',
4 => '7ee',
),
6 =>
array (
0 => '8aa',
1 => '8bb',
2 => '8cc',
3 => '8dd',
4 => '8ee',
),
7 =>
array (
0 => '9aa',
1 => '9bb',
2 => '9cc',
3 => '9dd',
4 => '9ee',
),
),
'one_row_for_symmetric' => array (
0 => '10aa',
1 => '10bb',
2 => '10cc',
3 => '10dd',
4 => '10ee',
),
'symmetric_rows_plus_one' => // contains 'one_row_for_symmetric'
array (
0 =>
array (
0 => '1aa',
1 => '1bb',
2 => '1cc',
3 => '1dd',
4 => '1ee',
),
1 =>
array (
0 => '2aa',
1 => '2bb',
2 => '2cc',
3 => '2dd',
4 => '2ee',
),
2 =>
array (
0 => '3aa',
1 => '3bb',
2 => '3cc',
3 => '3dd',
4 => '3ee',
),
3 =>
array (
0 => '4aa',
1 => '4bb',
2 => '4cc',
3 => '4dd',
4 => '4ee',
),
4 =>
array (
0 => '5aa',
1 => '5bb',
2 => '5cc',
3 => '5dd',
4 => '5ee',
),
5 =>
array (
0 => '6aa',
1 => '6bb',
2 => '6cc',
3 => '6dd',
4 => '6ee',
),
6 =>
array (
0 => '7aa',
1 => '7bb',
2 => '7cc',
3 => '7dd',
4 => '7ee',
),
7 =>
array (
0 => '8aa',
1 => '8bb',
2 => '8cc',
3 => '8dd',
4 => '8ee',
),
8 =>
array (
0 => '9aa',
1 => '9bb',
2 => '9cc',
3 => '9dd',
4 => '9ee',
),
9 =>
array (
0 => '10aa',
1 => '10bb',
2 => '10cc',
3 => '10dd',
4 => '10ee',
),
),
'symmetric_rows_empty' =>
array (
0 =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
4 => '',
),
1 =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
4 => '',
),
2 =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
4 => '',
),
3 =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
4 => '',
),
4 =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
4 => '',
),
5 =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
4 => '',
),
6 =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
4 => '',
),
7 =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
4 => '',
),
8 =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
4 => '',
),
),
'symmetric_rows' =>
array (
0 =>
array (
0 => '1aa',
1 => '1bb',
2 => '1cc',
3 => '1dd',
4 => '1ee',
),
1 =>
array (
0 => '2aa',
1 => '2bb',
2 => '2cc',
3 => '2dd',
4 => '2ee',
),
2 =>
array (
0 => '3aa',
1 => '3bb',
2 => '3cc',
3 => '3dd',
4 => '3ee',
),
3 =>
array (
0 => '4aa',
1 => '4bb',
2 => '4cc',
3 => '4dd',
4 => '4ee',
),
4 =>
array (
0 => '5aa',
1 => '5bb',
2 => '5cc',
3 => '5dd',
4 => '5ee',
),
5 =>
array (
0 => '6aa',
1 => '6bb',
2 => '6cc',
3 => '6dd',
4 => '6ee',
),
6 =>
array (
0 => '7aa',
1 => '7bb',
2 => '7cc',
3 => '7dd',
4 => '7ee',
),
7 =>
array (
0 => '8aa',
1 => '8bb',
2 => '8cc',
3 => '8dd',
4 => '8ee',
),
8 =>
array (
0 => '9aa',
1 => '9bb',
2 => '9cc',
3 => '9dd',
4 => '9ee',
),
),
'symmetric_raw_data' =>
array (
0 =>
array (
0 => 'header_a',
1 => 'header_b',
2 => 'header_c',
3 => 'header_d',
4 => 'header_e',
),
1 =>
array (
0 => '1aa',
1 => '1bb',
2 => '1cc',
3 => '1dd',
4 => '1ee',
),
2 =>
array (
0 => '2aa',
1 => '2bb',
2 => '2cc',
3 => '2dd',
4 => '2ee',
),
3 =>
array (
0 => '3aa',
1 => '3bb',
2 => '3cc',
3 => '3dd',
4 => '3ee',
),
4 =>
array (
0 => '4aa',
1 => '4bb',
2 => '4cc',
3 => '4dd',
4 => '4ee',
),
5 =>
array (
0 => '5aa',
1 => '5bb',
2 => '5cc',
3 => '5dd',
4 => '5ee',
),
6 =>
array (
0 => '6aa',
1 => '6bb',
2 => '6cc',
3 => '6dd',
4 => '6ee',
),
7 =>
array (
0 => '7aa',
1 => '7bb',
2 => '7cc',
3 => '7dd',
4 => '7ee',
),
8 =>
array (
0 => '8aa',
1 => '8bb',
2 => '8cc',
3 => '8dd',
4 => '8ee',
),
9 =>
array (
0 => '9aa',
1 => '9bb',
2 => '9cc',
3 => '9dd',
4 => '9ee',
),
),
'expected_raw' =>
array (
0 =>
array (
0 => 'h_one',
1 => 'h_two',
2 => 'h_three',
),
1 =>
array (
0 => 'v_1one',
1 => 'v_1two',
2 => 'v_1three',
),
2 =>
array (
0 => 'v_2one',
1 => 'v_2two',
2 => 'v_2three',
),
3 =>
array (
0 => 'v_3one',
1 => 'v_3two',
2 => 'v_3three',
),
),
'expected_escaped' =>
array (
0 =>
array (
'one' => 'thie,',
'two' => 'adn',
'three' => 'thei',
),
1 =>
array (
'one' => 'thie',
'two' => 'adn',
'three' => 'thei',
),
),
'header_a_connection' =>
array (
0 =>
array (
'header_a' => '1aa',
),
1 =>
array (
'header_a' => '2aa',
),
2 =>
array (
'header_a' => '3aa',
),
3 =>
array (
'header_a' => '4aa',
),
4 =>
array (
'header_a' => '5aa',
),
5 =>
array (
'header_a' => '6aa',
),
6 =>
array (
'header_a' => '7aa',
),
7 =>
array (
'header_a' => '8aa',
),
8 =>
array (
'header_a' => '9aa',
),
),
'symmetric_queries' =>
array (
0 => 'INSERT INTO test_table (header_a, header_b, header_c, header_d, header_e) VALUES (\'1aa\', \'1bb\', \'1cc\', \'1dd\', \'1ee\')',
1 => 'INSERT INTO test_table (header_a, header_b, header_c, header_d, header_e) VALUES (\'2aa\', \'2bb\', \'2cc\', \'2dd\', \'2ee\')',
2 => 'INSERT INTO test_table (header_a, header_b, header_c, header_d, header_e) VALUES (\'3aa\', \'3bb\', \'3cc\', \'3dd\', \'3ee\')',
3 => 'INSERT INTO test_table (header_a, header_b, header_c, header_d, header_e) VALUES (\'4aa\', \'4bb\', \'4cc\', \'4dd\', \'4ee\')',
4 => 'INSERT INTO test_table (header_a, header_b, header_c, header_d, header_e) VALUES (\'5aa\', \'5bb\', \'5cc\', \'5dd\', \'5ee\')',
5 => 'INSERT INTO test_table (header_a, header_b, header_c, header_d, header_e) VALUES (\'6aa\', \'6bb\', \'6cc\', \'6dd\', \'6ee\')',
6 => 'INSERT INTO test_table (header_a, header_b, header_c, header_d, header_e) VALUES (\'7aa\', \'7bb\', \'7cc\', \'7dd\', \'7ee\')',
7 => 'INSERT INTO test_table (header_a, header_b, header_c, header_d, header_e) VALUES (\'8aa\', \'8bb\', \'8cc\', \'8dd\', \'8ee\')',
8 => 'INSERT INTO test_table (header_a, header_b, header_c, header_d, header_e) VALUES (\'9aa\', \'9bb\', \'9cc\', \'9dd\', \'9ee\')',
),
'alternated_header_queries' =>
array (
0 => 'INSERT INTO test_table (header_a, header_c) VALUES (\'1aa\', \'1cc\')',
1 => 'INSERT INTO test_table (header_a, header_c) VALUES (\'2aa\', \'2cc\')',
2 => 'INSERT INTO test_table (header_a, header_c) VALUES (\'3aa\', \'3cc\')',
3 => 'INSERT INTO test_table (header_a, header_c) VALUES (\'4aa\', \'4cc\')',
4 => 'INSERT INTO test_table (header_a, header_c) VALUES (\'5aa\', \'5cc\')',
5 => 'INSERT INTO test_table (header_a, header_c) VALUES (\'6aa\', \'6cc\')',
6 => 'INSERT INTO test_table (header_a, header_c) VALUES (\'7aa\', \'7cc\')',
7 => 'INSERT INTO test_table (header_a, header_c) VALUES (\'8aa\', \'8cc\')',
8 => 'INSERT INTO test_table (header_a, header_c) VALUES (\'9aa\', \'9cc\')',
),
'symmetric_range_of_rows' =>
array (
0 =>
array (
0 => '2aa',
1 => '2bb',
2 => '2cc',
3 => '2dd',
4 => '2ee',
),
1 =>
array (
0 => '3aa',
1 => '3bb',
2 => '3cc',
3 => '3dd',
4 => '3ee',
),
),
'longer_headers' =>
array (
0 =>
array (
'one' => '1',
'two' => '2',
'three' => '3',
'four' => '',
'five' => '',
'six' => '',
),
1 =>
array (
'one' => '1',
'two' => '2',
'three' => '3',
'four' => '4',
'five' => '',
'six' => '',
),
2 =>
array (
'one' => '',
'two' => '2',
'three' => '3',
'four' => '4',
'five' => '',
'six' => '',
),
),
);
function fix($key) {
global $fixtures;
if (!array_key_exists($key, $fixtures)) {
throw new Exception("Fixture not found: '$key' ");
}
return $fixtures[$key];
}
function path($file)
{
return 'File/CSV/tests/data/' . $file;
}
function callback($value)
{
return 1;
}
function callback2($value)
{
return '';
}
?>

View File

@ -0,0 +1,21 @@
The MIT License
Copyright (c) <2009> <Denis Kobozev>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,6 @@
* Add a column for page templates
* Add column for importing post thumbnails
* Add an option to the GUI for specifying a delimiter other than a comma
* Create users if they don't exist (as an option)
* Add support for unix timestamp dates
* Add support for category descriptions

View File

@ -0,0 +1,771 @@
<?php
/*
Plugin Name: CSV Importer
Description: Import data as posts from a CSV file. <em>You can reach the author at <a href="mailto:d.v.kobozev@gmail.com">d.v.kobozev@gmail.com</a></em>.
Version: 0.3.7
Author: Denis Kobozev
*/
/**
* LICENSE: The MIT License {{{
*
* Copyright (c) <2009> <Denis Kobozev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author Denis Kobozev <d.v.kobozev@gmail.com>
* @copyright 2009 Denis Kobozev
* @license The MIT License
* }}}
*/
class CSVImporterPlugin {
var $csv_countries_array = array(
'Australia' => 'Australia',
'Canada' => 'CANADA',
'France' => 'France',
'Germany' => 'Germany',
'Spain' => 'Spain',
'United Kingdom' => 'UK',
'United States' => 'USA'
);
var $defaults = array(
'csv_post_title' => null,
'csv_post_post' => null,
'csv_post_type' => null,
'csv_post_excerpt' => null,
'csv_post_date' => null,
'csv_post_tags' => null,
'csv_post_categories' => null,
'csv_post_author' => null,
'csv_post_slug' => null,
'csv_post_parent' => 0,
'csv_post_video' => null,
'csv_post_destination_country' => null,
'csv_post_destination_name' => null,
'csv_post_destination_email' => null
);
var $log = array();
/**
* Determine value of option $name from database, $default value or $params,
* save it to the db if needed and return it.
*
* @param string $name
* @param mixed $default
* @param array $params
* @return string
*/
function process_option($name, $default, $params) {
if (array_key_exists($name, $params)) {
$value = stripslashes($params[$name]);
} elseif (array_key_exists('_'.$name, $params)) {
// unchecked checkbox value
$value = stripslashes($params['_'.$name]);
} else {
$value = null;
}
$stored_value = get_option($name);
if ($value == null) {
if ($stored_value === false) {
if (is_callable($default) &&
method_exists($default[0], $default[1])) {
$value = call_user_func($default);
} else {
$value = $default;
}
add_option($name, $value);
} else {
$value = $stored_value;
}
} else {
if ($stored_value === false) {
add_option($name, $value);
} elseif ($stored_value != $value) {
update_option($name, $value);
}
}
return $value;
}
/**
* Plugin's interface
*
* @return void
*/
function form() {
$opt_draft = $this->process_option('csv_importer_import_as_draft',
'publish', $_POST);
$opt_cat = $this->process_option('csv_importer_cat', 0, $_POST);
if ('POST' == $_SERVER['REQUEST_METHOD']) {
$this->post(compact('opt_draft', 'opt_cat'));
}
// form HTML {{{
?>
<div class="wrap">
<h2>Import CSV</h2>
<form class="add:the-list: validate" method="post" enctype="multipart/form-data">
<!-- Import as draft -->
<p>
<input name="_csv_importer_import_as_draft" type="hidden" value="publish" />
<label><input name="csv_importer_import_as_draft" type="checkbox" <?php if ('draft' == $opt_draft) { echo 'checked="checked"'; } ?> value="draft" /> Import posts as drafts</label>
</p>
<!-- Parent category -->
<p>Organize into category <?php wp_dropdown_categories(array('show_option_all' => 'Select one ...', 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'name' => 'csv_importer_cat', 'orderby' => 'name', 'selected' => $opt_cat));?><br/>
<small>This will create new categories inside the category parent you choose.</small></p>
<!-- File input -->
<p><label for="csv_import">Upload file:</label><br/>
<input name="csv_import" id="csv_import" type="file" value="" aria-required="true" /></p>
<p class="submit"><input type="submit" class="button" name="submit" value="Import" /></p>
</form>
</div><!-- end wrap -->
<?php
// end form HTML }}}
}
function print_messages() {
if (!empty($this->log)) {
// messages HTML {{{
?>
<div class="wrap">
<?php if (!empty($this->log['error'])): ?>
<div class="error">
<?php foreach ($this->log['error'] as $error): ?>
<p><?php echo $error; ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if (!empty($this->log['notice'])): ?>
<div class="updated fade">
<?php foreach ($this->log['notice'] as $notice): ?>
<p><?php echo $notice; ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div><!-- end wrap -->
<?php
// end messages HTML }}}
$this->log = array();
}
}
/**
* Handle POST submission
*
* @param array $options
* @return void
*/
function post($options) {
if (empty($_FILES['csv_import']['tmp_name'])) {
$this->log['error'][] = 'No file uploaded, aborting.';
$this->print_messages();
return;
}
require_once 'File_CSV_DataSource/DataSource.php';
$time_start = microtime(true);
$csv = new File_CSV_DataSource;
$file = $_FILES['csv_import']['tmp_name'];
$this->stripBOM($file);
if (!$csv->load($file)) {
$this->log['error'][] = 'Failed to load file, aborting.';
$this->print_messages();
return;
}
// pad shorter rows with empty values
$csv->symmetrize();
// WordPress sets the correct timezone for date functions somewhere
// in the bowels of wp_insert_post(). We need strtotime() to return
// correct time before the call to wp_insert_post().
$tz = get_option('timezone_string');
if ($tz && function_exists('date_default_timezone_set')) {
date_default_timezone_set($tz);
}
$skipped = 0;
$imported = 0;
$comments = 0;
foreach ($csv->connect() as $csv_data) {
if ($post_id = $this->create_post($csv_data, $options)) {
$imported++;
$comments += $this->add_comments($post_id, $csv_data);
$this->create_custom_fields($post_id, $csv_data);
} else {
$skipped++;
}
}
if (file_exists($file)) {
@unlink($file);
}
$exec_time = microtime(true) - $time_start;
if ($skipped) {
$this->log['notice'][] = "<b>Skipped {$skipped} posts (most likely due to empty title, body and excerpt).</b>";
}
$this->log['notice'][] = sprintf("<b>Imported {$imported} posts and {$comments} comments in %.2f seconds.</b>", $exec_time);
$this->print_messages();
}
function create_post($data, $options) {
require_once 'youtube.class.php';
extract($options);
$data = array_merge($this->defaults, $data);
$type = $data['csv_post_type'] ? $data['csv_post_type'] : 'post';
$valid_type = (function_exists('post_type_exists') &&
post_type_exists($type)) || in_array($type, array('post', 'page'));
if (!$valid_type) {
$this->log['error']["type-{$type}"] = sprintf(
'Unknown post type "%s".', $type);
}
$friend_email = $data['csv_post_destination_email'];
$country_name = $data['csv_post_destination_country'];
$friend_name = $data['csv_post_destination_name'];
if ($country_name) {
$friend_country = array_search($country_name, $this->csv_countries_array);
}
if (isset($friend_email) && (is_email($friend_email))) {
// Existe un usuario con ese email?
$user_email = get_user_by('email', $friend_email);
if ($user_email) {
$friend_ids = array();
$friend_ids[] = $user_email->ID;
} else {
$friend_ids = array();
if ((!isset($friend_name) || trim($friend_name)==='')) {
return false; // no insertar aquellos que no existan como usuarios y no tengan nick puesto
}
if ((!isset($country_name) || trim($country_name)==='')) {
return false; // no insertar aquellos que no existan como usuarios y no tengan pais puesto
}
}
} else {
return false;
}
$video_url = $data['csv_post_video'];
$videoData = array();
if ((!isYoutubeVideo($video_url)) && (!isVimeoVideo($video_url))) {
return false;
}
if (isYoutubeVideo($video_url)) {
$videoID = getYouTubeVideoID($video_url);
if (checkYoutubeId($videoID) == 1) {
$yt = new youtube($videoID);
$videoData['videoURL'] = $video_url;
$videoData['title'] = $yt->getTitle();
$videoData['description'] = $yt->getDescription();
$videoData['thumbnail'] = $yt->getUrlImage('hqdefault');
}
}
if (isVimeoVideo($video_url)) {
$videoID = getVimeoVideoID($video_url);
if (checkVimeoId($videoID) == 1) {
$xml = getVimeoVideoDetails($videoID);
if ($xml) {
$videoData['videoURL'] = $video_url;
$videoData['title'] = $xml->video->title;
$videoData['description'] = $xml->video->description;
$videoData['thumbnail'] = $xml->video->thumbnail_large;
}
}
}
if (empty($videoData))
return 0;
$new_post = array(
'post_title' => convert_chars($data['csv_post_title']),
'post_content' => wpautop(convert_chars($data['csv_post_post'])),
'post_status' => $opt_draft,
'post_type' => $type,
'post_date' => $this->parse_date($data['csv_post_date']),
'post_excerpt' => convert_chars($data['csv_post_excerpt']),
'post_name' => $data['csv_post_slug'],
'post_author' => $this->get_auth_id($data['csv_post_author']),
'tax_input' => $this->get_taxonomies($data),
'post_parent' => $data['csv_post_parent'],
);
// pages don't have tags or categories
if ('page' !== $type) {
$new_post['tags_input'] = $data['csv_post_tags'];
// Setup categories before inserting - this should make insertion
// faster, but I don't exactly remember why :) Most likely because
// we don't assign default cat to post when csv_post_categories
// is not empty.
//$cats = $this->create_or_get_categories($data, $opt_cat);
$cats = get_category_by_slug(DEDICATION_CATEGORY_SLUG);
$new_post['post_category'] = array($cats->term_id); //$cats['post'];
}
// create!
$id = wp_insert_post($new_post);
if ('page' !== $type && !$id) {
// cleanup new categories on failure
//foreach ($cats['cleanup'] as $c) {
// wp_delete_term($c, 'category');
//}
}
$post_id = $id;
if ($post_id) {
try {
$link = get_permalink($post_id);
$artist_name = $videoData['title'];
$song_name = '';
preg_match('/^(.*) - (.*)$/', $videoData['title'], $ntitle);
if (strlen($ntitle[1]) > 0) {
$artist_name = $ntitle[1];
}
if (strlen($ntitle[2]) > 0) {
$song_name = $ntitle[2];
}
add_post_meta($post_id, 'ghostpool_dedication_artist', $artist_name);
add_post_meta($post_id, 'ghostpool_dedication_song', $song_name);
add_post_meta($post_id, 'ghostpool_dedication_url', $videoData['videoURL']);
if (count($friend_ids) > 0) {
$friend_info = get_userdata($friend_ids[0]);
add_post_meta($post_id, 'ghostpool_destination_user_id', $friend_info->ID);
add_post_meta($post_id, 'ghostpool_destination_user_name', $friend_info->user_login);
$friend_email = $friend_info->user_email;
}
if (isset($friend_email) && (is_email($friend_email))) {
add_post_meta($post_id, 'ghostpool_destination_user_name', $friend_name);
add_post_meta($post_id, 'ghostpool_destination_user_email', $friend_email);
add_post_meta($post_id, 'ghostpool_destination_user_country', $friend_country);
}
$imageurl = $videoData['thumbnail'];
$imageurl = stripslashes($imageurl);
$uploads = wp_upload_dir();
$filename = wp_unique_filename($uploads['path'], basename($imageurl), $unique_filename_callback = null);
$wp_filetype = wp_check_filetype($filename, null);
$fullpathfilename = $uploads['path'] . "/" . $filename;
} catch (Exception $e) {
_log($e);
return 0;
}
try {
if (!substr_count($wp_filetype['type'], "image")) {
return 0;
}
$image_string = fetch_image($imageurl);
$fileSaved = file_put_contents($uploads['path'] . "/" . $filename, $image_string);
if (!$fileSaved) {
return 0;
}
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
'post_content' => '',
'post_status' => 'inherit',
'guid' => $uploads['url'] . "/" . $filename
);
$attach_id = wp_insert_attachment($attachment, $fullpathfilename, $post_id);
if (!$attach_id) {
return 0;
}
$attach_data = wp_generate_attachment_metadata($attach_id, $fullpathfilename);
wp_update_attachment_metadata($attach_id, $attach_data);
update_post_meta($post_id, '_thumbnail_id', $attach_id);
} catch (Exception $e) {
_log($e);
return 0;
}
}
return $id;
}
/**
* Return an array of category ids for a post.
*
* @param string $data csv_post_categories cell contents
* @param integer $common_parent_id common parent id for all categories
* @return array category ids
*/
function create_or_get_categories($data, $common_parent_id) {
$ids = array(
'post' => array(),
'cleanup' => array(),
);
$items = array_map('trim', explode(',', $data['csv_post_categories']));
foreach ($items as $item) {
if (is_numeric($item)) {
if (get_category($item) !== null) {
$ids['post'][] = $item;
} else {
$this->log['error'][] = "Category ID {$item} does not exist, skipping.";
}
} else {
$parent_id = $common_parent_id;
// item can be a single category name or a string such as
// Parent > Child > Grandchild
$categories = array_map('trim', explode('>', $item));
if (count($categories) > 1 && is_numeric($categories[0])) {
$parent_id = $categories[0];
if (get_category($parent_id) !== null) {
// valid id, everything's ok
$categories = array_slice($categories, 1);
} else {
$this->log['error'][] = "Category ID {$parent_id} does not exist, skipping.";
continue;
}
}
foreach ($categories as $category) {
if ($category) {
$term = $this->term_exists($category, 'category', $parent_id);
if ($term) {
$term_id = $term['term_id'];
} else {
$term_id = wp_insert_category(array(
'cat_name' => $category,
'category_parent' => $parent_id,
));
$ids['cleanup'][] = $term_id;
}
$parent_id = $term_id;
}
}
$ids['post'][] = $term_id;
}
}
return $ids;
}
/**
* Parse taxonomy data from the file
*
* array(
* // hierarchical taxonomy name => ID array
* 'my taxonomy 1' => array(1, 2, 3, ...),
* // non-hierarchical taxonomy name => term names string
* 'my taxonomy 2' => array('term1', 'term2', ...),
* )
*
* @param array $data
* @return array
*/
function get_taxonomies($data) {
$taxonomies = array();
foreach ($data as $k => $v) {
if (preg_match('/^csv_ctax_(.*)$/', $k, $matches)) {
$t_name = $matches[1];
if ($this->taxonomy_exists($t_name)) {
$taxonomies[$t_name] = $this->create_terms($t_name,
$data[$k]);
} else {
$this->log['error'][] = "Unknown taxonomy $t_name";
}
}
}
return $taxonomies;
}
/**
* Return an array of term IDs for hierarchical taxonomies or the original
* string from CSV for non-hierarchical taxonomies. The original string
* should have the same format as csv_post_tags.
*
* @param string $taxonomy
* @param string $field
* @return mixed
*/
function create_terms($taxonomy, $field) {
if (is_taxonomy_hierarchical($taxonomy)) {
$term_ids = array();
foreach ($this->_parse_tax($field) as $row) {
list($parent, $child) = $row;
$parent_ok = true;
if ($parent) {
$parent_info = $this->term_exists($parent, $taxonomy);
if (!$parent_info) {
// create parent
$parent_info = wp_insert_term($parent, $taxonomy);
}
if (!is_wp_error($parent_info)) {
$parent_id = $parent_info['term_id'];
} else {
// could not find or create parent
$parent_ok = false;
}
} else {
$parent_id = 0;
}
if ($parent_ok) {
$child_info = $this->term_exists($child, $taxonomy, $parent_id);
if (!$child_info) {
// create child
$child_info = wp_insert_term($child, $taxonomy,
array('parent' => $parent_id));
}
if (!is_wp_error($child_info)) {
$term_ids[] = $child_info['term_id'];
}
}
}
return $term_ids;
} else {
return $field;
}
}
/**
* Compatibility wrapper for WordPress term lookup.
*/
function term_exists($term, $taxonomy = '', $parent = 0) {
if (function_exists('term_exists')) { // 3.0 or later
return term_exists($term, $taxonomy, $parent);
} else {
return is_term($term, $taxonomy, $parent);
}
}
/**
* Compatibility wrapper for WordPress taxonomy lookup.
*/
function taxonomy_exists($taxonomy) {
if (function_exists('taxonomy_exists')) { // 3.0 or later
return taxonomy_exists($taxonomy);
} else {
return is_taxonomy($taxonomy);
}
}
/**
* Hierarchical taxonomy fields are tiny CSV files in their own right.
*
* @param string $field
* @return array
*/
function _parse_tax($field) {
$data = array();
if (function_exists('str_getcsv')) { // PHP 5 >= 5.3.0
$lines = $this->split_lines($field);
foreach ($lines as $line) {
$data[] = str_getcsv($line, ',', '"');
}
} else {
// Use temp files for older PHP versions. Reusing the tmp file for
// the duration of the script might be faster, but not necessarily
// significant.
$handle = tmpfile();
fwrite($handle, $field);
fseek($handle, 0);
while (($r = fgetcsv($handle, 999999, ',', '"')) !== false) {
$data[] = $r;
}
fclose($handle);
}
return $data;
}
/**
* Try to split lines of text correctly regardless of the platform the text
* is coming from.
*/
function split_lines($text) {
$lines = preg_split("/(\r\n|\n|\r)/", $text);
return $lines;
}
function add_comments($post_id, $data) {
// First get a list of the comments for this post
$comments = array();
foreach ($data as $k => $v) {
// comments start with cvs_comment_
if ( preg_match('/^csv_comment_([^_]+)_(.*)/', $k, $matches) &&
$v != '') {
$comments[$matches[1]] = 1;
}
}
// Sort this list which specifies the order they are inserted, in case
// that matters somewhere
ksort($comments);
// Now go through each comment and insert it. More fields are possible
// in principle (see docu of wp_insert_comment), but I didn't have data
// for them so I didn't test them, so I didn't include them.
$count = 0;
foreach ($comments as $cid => $v) {
$new_comment = array(
'comment_post_ID' => $post_id,
'comment_approved' => 1,
);
if (isset($data["csv_comment_{$cid}_author"])) {
$new_comment['comment_author'] = convert_chars(
$data["csv_comment_{$cid}_author"]);
}
if (isset($data["csv_comment_{$cid}_author_email"])) {
$new_comment['comment_author_email'] = convert_chars(
$data["csv_comment_{$cid}_author_email"]);
}
if (isset($data["csv_comment_{$cid}_url"])) {
$new_comment['comment_author_url'] = convert_chars(
$data["csv_comment_{$cid}_url"]);
}
if (isset($data["csv_comment_{$cid}_content"])) {
$new_comment['comment_content'] = convert_chars(
$data["csv_comment_{$cid}_content"]);
}
if (isset($data["csv_comment_{$cid}_date"])) {
$new_comment['comment_date'] = $this->parse_date(
$data["csv_comment_{$cid}_date"]);
}
$id = wp_insert_comment($new_comment);
if ($id) {
$count++;
} else {
$this->log['error'][] = "Could not add comment $cid";
}
}
return $count;
}
function create_custom_fields($post_id, $data) {
foreach ($data as $k => $v) {
// anything that doesn't start with csv_ is a custom field
if (!preg_match('/^csv_/', $k) && $v != '') {
add_post_meta($post_id, $k, $v);
}
}
}
function get_auth_id($author) {
if (is_numeric($author)) {
return $author;
}
$author_data = get_userdatabylogin($author);
return ($author_data) ? $author_data->ID : 0;
}
/**
* Convert date in CSV file to 1999-12-31 23:52:00 format
*
* @param string $data
* @return string
*/
function parse_date($data) {
$timestamp = strtotime($data);
if (false === $timestamp) {
return '';
} else {
return date('Y-m-d H:i:s', $timestamp);
}
}
/**
* Delete BOM from UTF-8 file.
*
* @param string $fname
* @return void
*/
function stripBOM($fname) {
$res = fopen($fname, 'rb');
if (false !== $res) {
$bytes = fread($res, 3);
if ($bytes == pack('CCC', 0xef, 0xbb, 0xbf)) {
$this->log['notice'][] = 'Getting rid of byte order mark...';
fclose($res);
$contents = file_get_contents($fname);
if (false === $contents) {
trigger_error('Failed to get file contents.', E_USER_WARNING);
}
$contents = substr($contents, 3);
$success = file_put_contents($fname, $contents);
if (false === $success) {
trigger_error('Failed to put file contents.', E_USER_WARNING);
}
} else {
fclose($res);
}
} else {
$this->log['error'][] = 'Failed to open file, aborting.';
}
}
}
function csv_admin_menu() {
require_once ABSPATH . '/wp-admin/admin.php';
$plugin = new CSVImporterPlugin;
add_management_page('edit.php', 'CSV Importer', 'manage_options', __FILE__,
array($plugin, 'form'));
}
add_action('admin_menu', 'csv_admin_menu');
?>

View File

@ -0,0 +1,2 @@
"csv_post_title","csv_post_post","csv_post_categories","csv_post_tags","csv_comment_1_author","csv_comment_1_content","csv_comment_2_author","csv_comment_2_author_email","csv_comment_2_url","csv_comment_2_content","csv_comment_2_date"
"Minitel","The Minitel is a Videotex online service accessible through the telephone lines, and is considered one of the world's most successful pre-World Wide Web online services.","Testing CSV Importer","test,import,csv","gordon","Wow, I have never heard about such service.","eli","eli@example.com","http://example.com","From its early days, users could make online purchases, make train reservations, check stock prices, search the telephone directory, and chat in a similar way to that now made possible by the Internet.","yesterday"
1 csv_post_title csv_post_post csv_post_categories csv_post_tags csv_comment_1_author csv_comment_1_content csv_comment_2_author csv_comment_2_author_email csv_comment_2_url csv_comment_2_content csv_comment_2_date
2 Minitel The Minitel is a Videotex online service accessible through the telephone lines, and is considered one of the world's most successful pre-World Wide Web online services. Testing CSV Importer test,import,csv gordon Wow, I have never heard about such service. eli eli@example.com http://example.com From its early days, users could make online purchases, make train reservations, check stock prices, search the telephone directory, and chat in a similar way to that now made possible by the Internet. yesterday

View File

@ -0,0 +1,7 @@
"csv_post_title","csv_post_post","csv_post_excerpt","csv_post_categories","csv_post_tags","csv_post_date","csv_post_author","csv_post_slug","csv_ctax_art","csv_ctax_country","my_custom1"
"Vincent Van Gogh","Vincent Willem van Gogh[a 1] (30 March 1853  29 July 1890) was a Dutch post-Impressionist painter whose work had a far-reaching influence on 20th century art for its vivid colors and emotional impact. He suffered from anxiety and increasingly frequent bouts of mental illness throughout his life, and died largely unknown, at the age of 37, from a self-inflicted gunshot wound.","Vincent Willem van Gogh[a 1] (30 March 1853  29 July 1890) was a Dutch post-Impressionist painter","Art, CSV Importer","van gogh, dutch, painter","June 1, 2010","alice","Van-gogh-one","Painting, post-impressionism","Netherlands,France",53
"Claude Monet","Claude Monet (French pronunciation: [klod mɔnɛ]), born Oscar Claude Monet (14 November 1840 5 December 1926)[1] was a founder of French impressionist painting, and the most consistent and prolific practitioner of the movement's philosophy of expressing one's perceptions before nature, especially as applied to plein-air landscape painting. ","Claude Monet (French pronunciation: [klod mɔnɛ]), born Oscar Claude Monet (14 November 1840 5 December 1926)[1] was a founder of French impressionist painting","Art, CSV Importer","monet, french, painter","May 30, 2010","alice","Claude-monet-one","Painting, impressionism","France",40
"Pablo Picasso","Pablo Diego José Francisco de Paula Juan Nepomuceno María de los Remedios Cipriano de la Santísima Trinidad Clito Ruiz y Picasso Ruiz Picasso known as Pablo Ruiz Picasso (25 October 1881  8 April 1973) was a Spanish painter, draughtsman, and sculptor. He is best known for co-founding the Cubist movement and for the wide variety of styles embodied in his work.","Pablo Ruiz Picasso (25 October 1881  8 April 1973) was a Spanish painter, draughtsman, and sculptor.","Art, CSV Importer","picasso, spanish, painter, sculptor","August 25 2009","alice","Pablo-picasso-one","Painting, cubism
Sculpture, cubism","France, Spain",81
"Oscar Wilde","Oscar Fingal O'Flahertie Wills Wilde (16 October 1854 30 November 1900) was an Irish writer, poet, and prominent aesthete. His parents were successful Dublin intellectuals, and from an early age he was tutored at home, where he showed his intelligence, becoming fluent in French and German. ","Oscar Fingal O'Flahertie Wills Wilde (16 October 1854 30 November 1900) was an Irish writer, poet, and prominent aesthete.","Art, CSV Importer","wilde, irish, poet","August 25 2009","bob","Oscar-wilde-one","Poetry, aestheticism
Prose, ""fiction, gothic""","Ireland, UK, France",54
1 csv_post_title csv_post_post csv_post_excerpt csv_post_categories csv_post_tags csv_post_date csv_post_author csv_post_slug csv_ctax_art csv_ctax_country my_custom1
2 Vincent Van Gogh Vincent Willem van Gogh[a 1] (30 March 1853 – 29 July 1890) was a Dutch post-Impressionist painter whose work had a far-reaching influence on 20th century art for its vivid colors and emotional impact. He suffered from anxiety and increasingly frequent bouts of mental illness throughout his life, and died largely unknown, at the age of 37, from a self-inflicted gunshot wound. Vincent Willem van Gogh[a 1] (30 March 1853 – 29 July 1890) was a Dutch post-Impressionist painter Art, CSV Importer van gogh, dutch, painter June 1, 2010 alice Van-gogh-one Painting, post-impressionism Netherlands,France 53
3 Claude Monet Claude Monet (French pronunciation: [klod mɔnɛ]), born Oscar Claude Monet (14 November 1840 – 5 December 1926)[1] was a founder of French impressionist painting, and the most consistent and prolific practitioner of the movement's philosophy of expressing one's perceptions before nature, especially as applied to plein-air landscape painting. Claude Monet (French pronunciation: [klod mɔnɛ]), born Oscar Claude Monet (14 November 1840 – 5 December 1926)[1] was a founder of French impressionist painting Art, CSV Importer monet, french, painter May 30, 2010 alice Claude-monet-one Painting, impressionism France 40
4 Pablo Picasso Pablo Diego José Francisco de Paula Juan Nepomuceno María de los Remedios Cipriano de la Santísima Trinidad Clito Ruiz y Picasso Ruiz Picasso known as Pablo Ruiz Picasso (25 October 1881 – 8 April 1973) was a Spanish painter, draughtsman, and sculptor. He is best known for co-founding the Cubist movement and for the wide variety of styles embodied in his work. Pablo Ruiz Picasso (25 October 1881 – 8 April 1973) was a Spanish painter, draughtsman, and sculptor. Art, CSV Importer picasso, spanish, painter, sculptor August 25 2009 alice Pablo-picasso-one Painting, cubism Sculpture, cubism France, Spain 81
5 Oscar Wilde Oscar Fingal O'Flahertie Wills Wilde (16 October 1854 – 30 November 1900) was an Irish writer, poet, and prominent aesthete. His parents were successful Dublin intellectuals, and from an early age he was tutored at home, where he showed his intelligence, becoming fluent in French and German. Oscar Fingal O'Flahertie Wills Wilde (16 October 1854 – 30 November 1900) was an Irish writer, poet, and prominent aesthete. Art, CSV Importer wilde, irish, poet August 25 2009 bob Oscar-wilde-one Poetry, aestheticism Prose, "fiction, gothic" Ireland, UK, France 54

View File

@ -0,0 +1,19 @@
<?php
// Set up custom taxonomies for CSV Importer custom-taxonomies.csv example. You
// can copy-and-paste the code below to your theme's functions.php file.
add_action('init', 'csv_importer_taxonomies', 0);
function csv_importer_taxonomies() {
register_taxonomy('art', 'post', array(
'hierarchical' => true,
'label' => 'Art',
));
register_taxonomy('country', 'post', array(
'hierarchical' => false,
'label' => 'Country',
));
}
?>

View File

@ -0,0 +1,9 @@
"csv_post_title","csv_post_post","csv_post_categories","csv_post_date","csv_post_author","csv_post_slug","csv_post_type","csv_post_parent"
"[CSV Importer] Assign an author","You can manually assign an author to a post, provided that user exists.","Testing CSV Importer",,"alice",,,
"[CSV Importer] Set a slug","Slugs are supported, too.","Testing CSV Importer",,,"slug-ability",,
"[CSV Importer] Yesterday's post","Dates can be specified in a variety of formats, including plain English (with limitations, of course).","Testing CSV Importer","yesterday",,,,
"[CSV Importer] A year ago","Set date to the same day, a year ago.","Testing CSV Importer","-1 year",,,,
"[CSV Importer] Exact date 1","More precise date formats are supported, too.","Testing CSV Importer","2011, feb 2",,,,
"[CSV Importer] Exact date 2","More precise date formats are supported, too.","Testing CSV Importer","01/01/11",,,,
"[CSV Importer] Parent","You can specify a parent page using its id. The page has to already exist for this to work.","Testing CSV Importer",,,,"page",83
"[CSV Importer] Subcategories","To specify a category structure, use the greater than sign > in the csv_post_categories column.","Testing CSV Importer > Guitars > Electric",,,,,
1 csv_post_title csv_post_post csv_post_categories csv_post_date csv_post_author csv_post_slug csv_post_type csv_post_parent
2 [CSV Importer] Assign an author You can manually assign an author to a post, provided that user exists. Testing CSV Importer alice
3 [CSV Importer] Set a slug Slugs are supported, too. Testing CSV Importer slug-ability
4 [CSV Importer] Yesterday's post Dates can be specified in a variety of formats, including plain English (with limitations, of course). Testing CSV Importer yesterday
5 [CSV Importer] A year ago Set date to the same day, a year ago. Testing CSV Importer -1 year
6 [CSV Importer] Exact date 1 More precise date formats are supported, too. Testing CSV Importer 2011, feb 2
7 [CSV Importer] Exact date 2 More precise date formats are supported, too. Testing CSV Importer 01/01/11
8 [CSV Importer] Parent You can specify a parent page using its id. The page has to already exist for this to work. Testing CSV Importer page 83
9 [CSV Importer] Subcategories To specify a category structure, use the greater than sign > in the csv_post_categories column. Testing CSV Importer > Guitars > Electric

View File

@ -0,0 +1,20 @@
"csv_post_title","csv_post_post","csv_post_type","csv_post_excerpt","csv_post_categories","csv_post_tags","csv_post_date","custom_field_1","custom_field_2"
"[CSV Importer] Test","Don't panic, this is only a test.
The <a href=""http://wordpress.org/extend/plugins/csv-importer/other_notes/"">manual</a> has a lot of useful information.
Unsurprisingly, one of the most frequently asked questions is ""What should I do if my data has commas and double quotes?"".
<em>CSV Importer</em> can be used with any language (just make sure to save the file with UTF-8 encoding):
<blockquote>
A comma-separated values or character-separated values (CSV) file is a simple text format for a database table.
Comma-separated values (CSV) est un format informatique ouvert représentant des données tabulaires sous forme de « valeurs séparées par des virgules ».
CSV (от англ. Comma Separated Values — значения, разделённые запятыми) — текстовый формат, предназначенный для представления табличных данных.
Comma-Separated Values略称CSVは、いくつかのフィールド項目をカンマ「,」で区切ったテキストデータおよびテキストファイル。
</blockquote>",,"This is an excerpt for a CSV Importer test post.","Testing CSV Importer, Testing CSV Importer 2","test,csv","2000-12-31 20:00:12","custom value","custom value 2"
"[CSV Importer] A future post","This is a post that's scheduled to be published in the future (provided that it's not imported as a draft).","post","An excerpt of a future post.","Testing CSV Importer","test,csv,future","2014-01-01 14:00:00",42,43
"[CSV Importer] How to import a page?","To import a page, set csv_post_type column value to ""page"".","page",,,,,,
1 csv_post_title csv_post_post csv_post_type csv_post_excerpt csv_post_categories csv_post_tags csv_post_date custom_field_1 custom_field_2
2 [CSV Importer] Test Don't panic, this is only a test. The <a href="http://wordpress.org/extend/plugins/csv-importer/other_notes/">manual</a> has a lot of useful information. Unsurprisingly, one of the most frequently asked questions is "What should I do if my data has commas and double quotes?". <em>CSV Importer</em> can be used with any language (just make sure to save the file with UTF-8 encoding): <blockquote> A comma-separated values or character-separated values (CSV) file is a simple text format for a database table. Comma-separated values (CSV) est un format informatique ouvert représentant des données tabulaires sous forme de « valeurs séparées par des virgules ». CSV (от англ. Comma Separated Values — значения, разделённые запятыми) — текстовый формат, предназначенный для представления табличных данных. Comma-Separated Values(略称:CSV)は、いくつかのフィールド(項目)をカンマ「,」で区切ったテキストデータおよびテキストファイル。 </blockquote> This is an excerpt for a CSV Importer test post. Testing CSV Importer, Testing CSV Importer 2 test,csv 2000-12-31 20:00:12 custom value custom value 2
3 [CSV Importer] A future post This is a post that's scheduled to be published in the future (provided that it's not imported as a draft). post An excerpt of a future post. Testing CSV Importer test,csv,future 2014-01-01 14:00:00 42 43
4 [CSV Importer] How to import a page? To import a page, set csv_post_type column value to "page". page

View File

@ -0,0 +1,348 @@
=== CSV Importer ===
Contributors: dvkob
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=4YJEU5U2Y4LTS&lc=US&item_name=Support%20CSV%20Importer%20development&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
Tags: csv, import, batch, spreadsheet, excel
Requires at least: 2.0.2
Tested up to: 3.2.1
Stable tag: 0.3.6
Import posts from CSV files into WordPress.
== Description ==
This plugin imports posts from CSV (Comma Separated Value) files into your
WordPress blog. It can prove extremely useful when you want to import a bunch
of posts from an Excel document or the like - simply export your document into
a CSV file and the plugin will take care of the rest.
= Features =
* Imports post title, body, excerpt, tags, date, categories etc.
* Supports custom fields, custom taxonomies and comments
* Deals with Word-style quotes and other non-standard characters using
WordPress' built-in mechanism (same one that normalizes your input when you
write your posts)
* Columns in the CSV file can be in any order, provided that they have correct
headings
* Multilanguage support
== Screenshots ==
1. Plugin's interface
== Installation ==
Installing the plugin:
1. Unzip the plugin's directory into `wp-content/plugins`.
1. Activate the plugin through the 'Plugins' menu in WordPress.
1. The plugin will be available under Tools -> CSV Importer on
WordPress administration page.
== Usage ==
Click on the CSV Importer link on your WordPress admin page, choose the
file you would like to import and click Import. The `examples` directory
inside the plugin's directory contains several files that demonstrate
how to use the plugin. The best way to get started is to import one of
these files and look at the results.
CSV is a tabular format that consists of rows and columns. Each row in
a CSV file represents a post; each column identifies a piece of information
that comprises a post.
= Basic post information =
* `csv_post_title` - title of the post
* `csv_post_post` - body of the post
* `csv_post_type` - `post`, `page` or a custom post type.
__New in version 0.3.2__
In prior versions, importing rows as pages could be specified on a
per-file basis using the plugins UI. In 0.3.2, `csv_post_type` column
was added to support custom post types as well.
Refer to the WordPress
[documentation on custom post types][custom_post_types] for more info
on how to set up custom post types.
* `csv_post_excerpt` - post excerpt
* `csv_post_categories` - a comma separated list of category names or ids.
__New in version 0.3.5__
It's also possible to assign posts to non-existing subcategories, using
&gt; to denote category relationships, e.g. `Animalia > Chordata > Mammalia`.
If any of the categories in the chain does not exist, the plugin will
automatically create it. It's also possible to specify the parent category
using an id, as in `42 > Primates > Callitrichidae`, where `42` is an
existing category id.
* `csv_post_tags` - a comma separated list of tags.
* `csv_post_date` - about any English textual description of a date and time.
For example, `now`, `11/16/2009 0:00`, `1999-12-31 23:55:00`, `+1 week`,
`next Thursday`, `last year` are all valid descriptions. For technical
details, consult PHP's `strtotime()` function [documentation][strtotime].
[custom_post_types]: http://codex.wordpress.org/Custom_Post_Types
[strtotime]: http://php.net/manual/en/function.strtotime.php
= Custom fields =
Any column that doesn't start with `csv_` is considered to be a custom field
name. The data in that column will be imported as the custom fields value.
= General remarks =
* WordPress pages [don't have categories or tags][pages].
* Most columns are optional. Either `csv_post_title`, `csv_post_post` or
`csv_post_excerpt` are sufficient to create a post. If all of these
columns are empty in a row, the plugin will skip that row.
* The plugin will attempt to reuse existing categories or tags; if an
existing category or tag cannot be found, the plugin will create it.
* To specify a category that has a greater than sign (>) in the name, use
the HTML entity `&gt;`
[pages]: http://codex.wordpress.org/Pages
= Advanced usage =
* `csv_post_author` - numeric user id or login name. If not specified or
user does not exist, the plugin will assign the posts to the user
performing the import.
* `csv_post_slug` - post slug used in permalinks.
* `csv_post_parent` - post parent id.
== Custom taxonomies ==
__New in version 0.3.0__
Once custom taxonomies are set up in your theme's functions.php file or
by using a 3rd party plugin, `csv_ctax_(taxonomy name)` columns can be
used to assign imported data to the taxonomies.
__Non-hierarchical taxonomies__
The syntax for non-hierarchical taxonomies is straightforward and is essentially
the same as the `csv_post_tags` syntax.
__Hierarchical taxonomies__
The syntax for hierarchical taxonomies is more complicated. Each hierarchical
taxonomy field is a tiny two-column CSV file, where _the order of columns
matters_. The first column contains the name of the parent term and the second
column contains the name of the child term. Top level terms have to be preceded
either by an empty string or a 0 (zero).
Sample `examples/custom-taxonomies.csv` file included with the plugin
illustrates custom taxonomy support. To see how it works, make sure to set up
custom taxonomies from `functions.inc.php`.
Make sure that the quotation marks used as text delimiters in `csv_ctax_`
columns are regular ASCII double quotes, not typographical quotes like “
(U+201C) and ” (U+201D).
== Comments ==
__New in version 0.3.1__
An example file with comments is included in the `examples` directory.
In short, comments can be imported along with posts by specifying columns
such as `csv_comment_*_author`, `csv_comment_*_content` etc, where * is
a comment ID number. This ID doesn't go into WordPress. It is only there
to have the connection information in the CSV file.
== Frequently Asked Questions ==
> I have quotation marks and commas as values in my CSV file. How do I tell CSV
Importer to use a different separator?
It doesn't really matter what kind of separator you use if your file is
properly escaped. To see what I mean by proper escaping, take a look at
`examples/sample.csv` file which has cells with quotation marks and commas.
If the software you use for exporting to CSV is unable to escape quotation
marks and commas, you might want to give [OpenOffice Calc][calc] a try.
[calc]: http://www.openoffice.org/
> How can I import characters with diacritics, Cyrillic or Han characters?
Make sure to save your CSV file with utf-8 encoding.
Prior to version 6.0.4, MySQL [did not support][5] some rare Han characters. As
a workaround, you can insert characters such as &#x2028e; (U+2028E) by
converting them to HTML entities - &amp;\#x2028e;
[5]: http://dev.mysql.com/doc/refman/5.1/en/faqs-cjk.html#qandaitem-24-11-1-13
> I cannot import anything - the plugin displays "Imported 0 posts in 0.01
seconds."
Update to version 0.3.1 or greater. Previous versions required write access to
the /tmp directory and the plugin failed if access was denied by PHP's safe
mode or other settings.
> I'm importing a file, but not all rows in it are imported and I don't see
a confirmation message. Why?
WordPress can be many things, but one thing it's not is blazing fast. The
reason why not all rows are imported and there's no confirmation message is
that the plugin times out during execution - PHP decides that it has been
running too long and terminates it.
There are a number of solutions you can try. First, make sure that you're not
using any plugins that may slow down post insertion. For example, a Twitter
plugin might attempt to tweet every post you import - not a very good idea
if you have 200 posts. Second, you can break up a file into smaller chunks that
take less time to import and therefore will not cause the plugin to time out.
Third, you can try adjusting PHP's `max_execution_time` option that sets how
long scripts are allowed to run. Description of how to do it is beyond the
scope of this FAQ - you should search the web and/or use your web host's help
to find out how. However, putting the following line in `.htaccess` file inside
public_html directory works for some people:
# Sets max execution time to 2 minutes. Adjust as necessary.
php_value max_execution_time 120
The problem can be approached from another angle, namely instead of giving
scripts more time to run making them run faster. There's not much I can do to
speed up the plugin (you can contact me at dvkobozev at gmail.com if you like
to prove me wrong), so you can try to speed up WordPress. It is a pretty broad
topic, ranging from database optimizations to PHP accelerators such as APC,
eAccelerator or XCache, so I'm afraid you're on your own here.
> I receive the following error when I try to import my CSV file: "Invalid CSV
file: header length and/or row lengths do not match". What's wrong with your
plugin/my file?
Short answer: update to version 0.2.0 or later. Longer answer: the number of
fields (values) in rows in your file does not match the number of columns.
Version 0.2.0 pads such rows with empty values (if there are more columns than
cells in a row) or discards extra fields (if there are less columns than cells
in a row).
> I'm getting the following error: `Parse error: syntax error, unexpected
T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in .../public_html/wp-content/plugins/csv-importer/File_CSV_DataSource/DataSource.php
on line 61`. What gives?
This plugin requires PHP5, while you probably have PHP4 or older. Update your
PHP installation or ask your hosting provider to do it for you.
== Credits ==
This plugin uses [php-csv-parser][3] by Kazuyoshi Tlacaelel.
It was inspired by JayBlogger's [CSV Import][4] plugin.
Contributors:
* Kevin Hagerty (post_author support)
* Edir Pedro (root category option and tableless HTML markup)
* Frank Loeffler (comments support)
* Micah Gates (subcategory syntax)
* David Hollander (deprecation warnings, linebreak handling)
[3]: http://code.google.com/p/php-csv-parser/
[4]: http://www.jayblogger.com/the-birth-of-my-first-plugin-import-csv/
== Changelog ==
= 0.3.7 =
* Make hierarchical custom taxonomy line splitting more robust
* Fix deprecation warnings
= 0.3.6 =
* Fix category cleanup bug
= 0.3.5 =
* Added 'greater-than' category syntax
* Updated the docs
= 0.3.4 =
* Added csv_post_parent column
* Updated the docs
* Got rid of a deprecation warning
= 0.3.3 =
* Fixes incompatibility with versions of WordPress prior to 3.0 introduced
in previous release.
= 0.3.2 =
* Added ability to specify custom post type.
= 0.3.1 =
* Import comments.
* Updated php-csv-parser - the plugin should no longer create files in /tmp.
= 0.3.0 =
* Custom taxonomies.
= 0.2.4 =
* Root category selection, cleaner HTML.
= 0.2.3 =
* Slight speed increase, support for post_author and post_name.
= 0.2.2 =
* Bugfix release to deal with BOM that may occur in UTF-8 encoded files.
= 0.2.1 =
* Ability to import rows as pages, not posts.
* Starting with this version, you can also specify category ids instead of
names.
= 0.2.0 =
* Ability to handle CSV files where the number of cells in rows does not
match the number of columns
* Smart date parsing
* Code cleanup.
= 0.1.3 =
* New option to import posts with published status.
= 0.1.2 =
* Added support for post excerpts.
= 0.1.1 =
* Code cleanup
* Changed column names for CSV input. Sorry if it breaks anything for you,
folks, but it had to be done in order to allow for custom fields such as
`title` ([All in One SEO Pack][1] uses those, for example).
= v0.1.0 =
* Initial version of the plugin
[1]: http://wordpress.org/extend/plugins/all-in-one-seo-pack/
== Upgrade Notice ==
= 0.3.7 =
More robust handling of hierarchical custom taxonomies; removed deprecation
warnings.
= 0.3.6 =
Fix for 'Invalid argument supplied for foreach() on line 268' error message
= 0.3.5 =
Subcategory creation support. Documentation update.
= 0.3.4 =
Post parent support. Documentation update.
= 0.3.3 =
Fixes "Call to undefined function post_type_exists()" error for versions of
Wordpress prior to 3.0
= 0.3.2 =
Adds support for custom post types. Option to import pages has been removed from
the interface. To import a page, add csv_post_type column to your csv file and
set it to "page".
= 0.3.1 =
Adds support for comments
= 0.3.0 =
Adds support for custom taxonomies

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -0,0 +1,177 @@
<?php
/*
* Name: Simple Class Info YouTube
* Description: Get Information of video YouTube
* Development: Chuecko
* Site: http://www.zarpele.com.ar
* License: GNU GENERAL PUBLIC LICENSE (http://www.gnu.org/licenses/gpl.html)
* Version: 1.0
*/
class youtube
{
var $data = '';
var $id = '';
public function youtube($id)
{
if (strlen($id) >=22)
{
parse_str( parse_url( $id, PHP_URL_QUERY ) );
$this->id = $v;
}
else
{
$this->id=$id;
}
$url = "http://gdata.youtube.com/feeds/videos/".$this->id;
$browser_id = "none";
$curl_handle = curl_init();
$options = array
(
CURLOPT_URL=>$url,
CURLOPT_HEADER=>false,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_USERAGENT=>$browser_id
);
curl_setopt_array($curl_handle,$options);
$server_output = curl_exec($curl_handle);
curl_close($curl_handle);
$this->data=$server_output;
}
public function getTitle()
{
$startString = "<media:title type='plain'>";
$endString = "</media:title>";
$tempString = strstr($this->data, $startString);
$endLocation = strpos($tempString, $endString);
$title = substr($tempString, 0, $endLocation);
if (empty($title))
{
$title=false;
}
else
{
$title=substr($title,strlen($startString));
}
return $title;
}
public function getPublished()
{
$startString = "<published>";
$endString = "</published>";
$starLocation = strpos($this->data, $startString);
$tempString = substr($this->data, $starLocation);
$endLocation = strpos($tempString, $endString);
$published = substr($tempString, 0, $endLocation);
if (empty($published))
{
$published=false;
}
else
{
$published=substr($published,strlen($startString));
$published=substr($published,0,10);
}
return $published;
}
public function getDescription()
{
$startString = "<media:description type='plain'>";
$endString = "</media:description>";
$starLocation = strpos($this->data, $startString);
$tempString = substr($this->data, $starLocation);
$endLocation = strpos($tempString, $endString);
$description = substr($tempString, 0, $endLocation);
if (empty($description))
{
$description=false;
}
else
{
$description=substr($description,strlen($startString));
}
return $description;
}
public function getMetaTags()
{
$startString = "<media:keywords>";
$endString = "</media:keywords>";
$starLocation = strpos($this->data, $startString);
$tempString = substr($this->data, $starLocation);
$endLocation = strpos($tempString, $endString);
$metaTags = substr($tempString, 0, $endLocation);
if (empty($metaTags))
{
$metaTags=false;
}
else
{
$metaTags=substr($metaTags,strlen($startString));
}
return $metaTags;
}
public function getUrl()
{
return "http://www.youtube.com/watch?v=".$this->id;
}
public function getUrlImage($option)
{
if($option=='hqdefault')
{
return 'http://i.ytimg.com/vi/'.$this->id.'/hqdefault.jpg';
}
if($option=='default')
{
return 'http://i.ytimg.com/vi/'.$this->id.'/default.jpg';
}
if($option=='grande')
{
return 'http://i.ytimg.com/vi/'.$this->id.'/0.jpg';
}
if($option==1)
{
return 'http://i.ytimg.com/vi/'.$this->id.'/1.jpg';
}
if($option==2)
{
return 'http://i.ytimg.com/vi/'.$this->id.'/2.jpg';
}
if($option==3)
{
return 'http://i.ytimg.com/vi/'.$this->id.'/3.jpg';
}
}
public function getEmbeb($width, $height)
{
$autoplay = 1;
return '<iframe class="youtube-player" type="text/html" width="'.$width.'" height="'.$height.'" src="http://www.youtube.com/embed/'.$this->id.'?autoplay='.$autoplay.'" frameborder="0">
</iframe>';
}
}
?>