Skip to content

Commit

Permalink
Bug #3/#4, Adopt MY_Loader::send_oembed_response() function [iet:37…
Browse files Browse the repository at this point in the history
…29593]

* Re-instate `POParser.php` (removed in: b2cb0cb960)
  • Loading branch information
nfreear committed Jul 7, 2015
1 parent b2cb0cb commit a25032a
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 6 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
# IET-OU / open-media-player-core

Core components of Open Media Player — a unified, accessible online audio and video player solution for The Open University. _Part of the Open Media Player framework._
Core components of Open Media Player — a unified, accessible online audio and video player solution for The Open University. _Part of the Open Media Player framework — more soon!_

* https://mediaplayer.open.ac.uk


## Installation

Install and test using Git and [Composer][],

```sh
git clone https://github.com/IET-OU/open-media-player-core
composer install
composer test
```


---
License: `to be confirmed.`kkx
License: `to be confirmed.`

© 2011-2015 The Open University. ([Institute of Educational Technology][])


[gpl]: http://gnu.org/licenses/gpl-2.0.html "GPL-2.0+"
[parent]: https://github.com/IET-OU/ouplayer
[Institute of Educational Technology]: http://iet.open.ac.uk/
[Composer]: https://getcomposer.org/
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"IET_OU\\Open_Media_Player\\": [ "src", "src/providers", "src/Players" ],
"IET_OU\\SubClasses\\": "src/SubClasses"
},
"classmap": [ "src/third_party/class.pdf2text.php" ]
"classmap": [ "src/third_party/" ]
},
"autoload-dev": {
"psr-4": {
Expand Down
204 changes: 204 additions & 0 deletions src/third_party/POParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
<?php

/**
* Copyright (C) 2008, Iulian Ilea (http://iulian.net), all rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

class POParser
{
private $_filename;

/**
* Format of a msgid entry:
* array(
* 'references' => array(), // each file on a new line
* 'translator-comments' => '',
* 'extracted-comments' => '',
* 'flags' => array(
* 'fuzzy'
* ...
* ),
* 'previous-msgctxt' => '',
* 'previous-msgid' => '',
* 'msgctxt' => '',
* 'msgid' => '',
*
* // when no plural forms
* 'msgstr' => '',
*
* // when plural forms
* 'msgid_pural' => '',
* 'msgstr' => array(
* 0 => '', // singular
* 1 => '', // 1st plural form
* 2 => '', // 2nd plural form
* ...
* n => '' // nth plural form
* )
* )
*
* @see http://www.gnu.org/software/gettext/manual/gettext.html#PO-Files
*/

protected function _dequote($str)
{
return substr($str, 1, -1);
}

public function parse($filename)
{
// basic file verification
if (!is_file($filename)) {
throw new Exception('The specified file does not exist.');
}
if (substr($filename, strrpos($filename, '.')) !== '.po') {
throw new Exception('The specified file is not a PO file.');
}

$lines = file($filename, FILE_IGNORE_NEW_LINES);

// on the first two lines I'm expecting msgid respectively msgstr,
// both containing empty strings
$entries = array(
// array(
// 'msgid' => '',
// 'msgstr' => array('')
// )
);

// parsing headers; stop at the first empty line
$headers = array(
'Project-Id-Version' => '',
'Report-Msgid-Bugs-To' => '',
'POT-Creation-Date' => '',
'PO-Revision-Date' => '',
'Last-Translator' => '',
'Language-Team' => '',
'Content-Type' => '',
'Content-Transfer-Encoding' => '',
'Plural-Forms' => '',
);
$i = 2;
while ($line = $lines[$i++]) {
$line = $this->_dequote($line);
$colonIndex = strpos($line, ':');
if ($colonIndex === false) {
continue;
}
$headerName = substr($line, 0, $colonIndex);
if (!isset($headers[$headerName])) {
continue;
}
// skip the white space after the colon and remove the \n at the end
$headers[$headerName] = substr($line, $colonIndex + 1, -2);
}

$entry = array();
for ($n = count($lines); $i < $n; $i++) {
$line = $lines[$i];
if ($line === '') {
$entries[] = $entry;
$entry = array();
continue;
}
if ($line[0] == '#') {
$comment = substr($line, 3);
switch ($line[1]) {
// translator comments
case ' ': {
if (!isset($entry['translator-comments'])) {
$entry['translator-comments'] = $comment;
}
else {
$entry['translator-comments'] .= "\n" . $comment;
}
break;
}
// extracted comments
case '.': {
if (!isset($entry['extracted-comments'])) {
$entry['extracted-comments'] = $comment;
}
else {
$entry['extracted-comments'] .= "\n" . $comment;
}
break;
}
// reference
case ':': {
if (!isset($entry['references'])) {
$entry['references'] = array();
}
$entry['references'][] = $comment;
break;
}
// flag
case ',': {
if (!isset($entry['flags'])) {
$entry['flags'] = array();
}
$entry['flags'][] = $comment;
break;
}
// previous msgid, msgctxt
case '|': {
// msgi[d]
if ($comment[4] == 'd') {
$entry['previous-msgid'] = $this->_dequote(substr($comment, 6));
}
// msgc[t]xt
else {
$entry['previous-msgctxt'] = $this->_dequote(substr($comment, 8));
}
break;
}
}
}
else if (strpos($line, 'msgid') === 0) {
if ($line[5] === ' ') {
$entry['msgid'] = $this->_dequote(substr($line, 6));
}
// msgid[_]plural
else {
$entry['msgid_plural'] = $this->_dequote(substr($line, 13));
}
}
else if (strpos($line, 'msgstr') === 0) {
// no plural forms
if ($line[6] === ' ') {
$entry['msgstr'] = $this->_dequote(substr($line, 7));
}
// plural forms
else {
if (!isset($entry['msgstr'])) {
$entry['msgstr'] = array();
}
$entry['msgstr'][] = $this->_dequote(substr($line, strpos($line, ' ') + 1));
}
}
else if ($line[0] === '"' && isset($entry['msgstr'])) {
$line = "\n" . preg_replace('/([^\\\\])\\\\n$/', "\$1\n", $this->_dequote($line));
if (!is_array($entry['msgstr'])) {
$entry['msgstr'] .= $line;
}
else {
$entry['msgstr'][count($entry['msgstr']) - 1] .= $line;
}
}
}
return array($headers, $entries);
}
}
2 changes: 1 addition & 1 deletion src/views/oembed/_generic_iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
'callback'=>$callback,
'oembed' =>$oembed,
);
$this->oembed_response($view_data);
$this->send_oembed_response($view_data);
4 changes: 2 additions & 2 deletions src/views/oembed/oupodcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@
'callback'=>$callback,
'oembed' =>$oembed,
);
$this->load->view('oembed/render', $view_data);

$this->send_oembed_response($view_data);

0 comments on commit a25032a

Please sign in to comment.