Fix a handful of typos in include/pages.php.
Fix a handful of typos in include/pages.php.

File last commit:

2f20c7105050
f1e0050abc35
Show More
transcript.php
182 lines | 6.3 KiB | text/x-php | PhpLexer
/ include / transcript.php
Add most necessary files for admin interface.
r1 <?php
//check that angle brackets are balanced
function bracketbalance($line)
{
#first, if no angle brackets, we're OK
if(substr_count($line, "<") == 0 && substr_count($line, ">") == 0)
return true;
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 if(substr_count($line, "<") != substr_count($line, ">"))
{
return false;
}
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 return true;
}
// Retrieve transcript for this strip from the database, modifying the strip object.
function gettranscript(&$strip)
{
global $mtdb;
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 $result = $mtdb->query('SELECT strip FROM transcript WHERE strip=' . (int)$strip->id );
if($result)
{
$output = '';
/*
#this gets me the highest panel number that has a transcript
# panels beyond that either lack speech or don't exist
# either way, I care not
Might be able to exchange this loop of getOne()s for a getAll() call.
*/
$numPanels = $mtdb->getOne( 'SELECT MAX(panel) FROM transcript WHERE transcript.strip=' . (int)$strip->id );
if( $numPanels ) {
for($i = 1; $i <= $numPanels; $i++) {
$result = $mtdb->query( 'SELECT speaker, speech FROM transcript WHERE transcript.strip=' . (int)$strip->id . ' AND panel=' .$i.' ORDER BY line')
Update include/*.php to use mysqli_* functions.
r4 or mtdie("There was an error fetching the panel count in the transcript for $strip->id, panel $i. " . mysqli_error(), 'SQL Error');
Add most necessary files for admin interface.
r1 if(!$result) continue;
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 $output.= "\nnewpanel\n";
Update include/*.php to use mysqli_* functions.
r4 while($row = mysqli_fetch_row($result)) {
Add most necessary files for admin interface.
r1 if(strlen($row[0]) < 1) continue;
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 $output.= $row[0];
if($row[1] !== '') $output.= ":: ".$row[1];
$output.= "\n";
}
}
}
}
$strip->transcript = $output;
return $output;
}
// Parse submitted transcript from strip object, and insert it into the database.
function savetranscript( &$strip ) {
global $mtdb;
$info = '';
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 $mtdb->query('START TRANSACTION');
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 //remove any old transcript data - it's being replaced
$mtdb->query( 'DELETE FROM transcript WHERE transcript.strip=' . (int)$strip->id );
if( $strip->transcript_posted ) {
$inserter = 'INSERT INTO transcript (strip,panel,line,speaker,speech,search) VALUES (%d,%d,%d,"%s","%s","%s")';
if(strpos($strip->transcript_posted, 'Panel <$n>') !== FALSE) {
# This is probably a scrivener script
$panels = explode('Panel <$n>', $strip->transcript_posted);
$panels = array_map('trim', $panels);
$numPanels = count($panels);
for($i = 0; $i < $numPanels; $i++) {
$lines = explode("\n", $panels[$i]);
$lines = array_map('trim', $lines);
# Initialize speaker controls
$speaker = null;
$has_spoken = true;
for($j = 0; $j < count($lines); $j++) {
$insert_sql = '';
if(strpos($lines[$j], '(') === 0) {
# Line is a note, add it as a comment
Update include/*.php to use mysqli_* functions.
r4 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, '#', mysqli_real_escape_string($mtdb->link, $lines[$j]), '');
Add most necessary files for admin interface.
r1 } elseif(strpos($lines[$j], '[') === 0 || strlen($lines[$j]) == 0) {
# Line is an annotation or blank, do nothing
continue;
} elseif(strpos($lines[$j], 'nospeaking:') === 0) {
# Line contains a list of nonspeaking characters
array_splice($lines, $j, 1, array_map('_nospeaker', explode(',', substr($lines[$j], 11))));
$speaker = trim(substr($lines[$j], 11));
Update include/*.php to use mysqli_* functions.
r4 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, mysqli_real_escape_string($mtdb->link, $speaker), '', '');
Add most necessary files for admin interface.
r1 } elseif($i > 0 && $lines[$j] == strtoupper($lines[$j])) {
# Line designates a new speaker, note speaker
# Handle speakers who did not say anything
if(null !== $speaker && !$has_spoken)
Update include/*.php to use mysqli_* functions.
r4 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, mysqli_real_escape_string($mtdb->link, $speaker), '', '');
Add most necessary files for admin interface.
r1
$speaker = ucfirst(strtolower($lines[$j]));
$has_spoken = false;
} elseif(null !== $speaker) {
# Line is speech, match with speaker and add
if(!bracketbalance($lines[$j]))
$info .= "<p>Warning: Open brackets do not match close brackets in panel $i for speaker ".htmlentities($speaker).'</p>';
$search = preg_replace( '/[[:punct:]]|(?<=\s)\s+/', ' ', strtolower($lines[$j]) );
Update include/*.php to use mysqli_* functions.
r4 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, mysqli_real_escape_string($mtdb->link, $speaker),
mysqli_real_escape_string($mtdb->link, $lines[$j]), mysqli_real_escape_string($mtdb->link, $search));
Add most necessary files for admin interface.
r1 $has_spoken = true;
} else {
# Line is unrecognized, add it as a comment
Update include/*.php to use mysqli_* functions.
r4 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, '#', mysqli_real_escape_string($mtdb->link, $lines[$j]), '');
Add most necessary files for admin interface.
r1 }
if( $insert_sql && false === $mtdb->query( $insert_sql ) ) {
$mtdb->query('ROLLBACK');
Update include/*.php to use mysqli_* functions.
r4 mtdie (mysqli_error(), 'Error inserting transcript.');
Add most necessary files for admin interface.
r1 }
}
if(null !== $speaker && !$has_spoken) {
Update include/*.php to use mysqli_* functions.
r4 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, mysqli_real_escape_string($mtdb->link, $speaker), '', '');
Add most necessary files for admin interface.
r1 if( false === $mtdb->query( $insert_sql ) ) {
$mtdb->query('ROLLBACK');
Update include/*.php to use mysqli_* functions.
r4 mtdie (mysqli_error(), 'Error inserting transcript.');
Add most necessary files for admin interface.
r1 }
}
}
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 } else {
# Assume that this is a Kalium style transcript
$panels = explode('newpanel', $strip->transcript_posted);
$numPanels = count($panels);
foreach($panels as $currPanel)
$currPanel = trim($currPanel);
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 for($i = 1; $i < $numPanels; $i++) {
$lines = explode("\n", $panels[$i]);
$numLines = count($lines);
foreach($lines as $currLine)
$currLine = trim($currLine);
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 for($j = 1; $j < $numLines; $j++) {
$spoken = explode("::", $lines[$j]); // Distinguish between speaker and speech
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 $spoken[0] = trim($spoken[0]); // Strip excess whitespace
$spoken[1] = trim($spoken[1]);
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 if(strlen($spoken[0]) < 1) continue; // Disregard null
$spoken[2] = preg_replace('/[[:punct:]]|(?<=\s)\s+/', ' ', strtolower($spoken[1]) ); // Make searchable text
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 if(!bracketbalance($spoken[1]))
$info .= "<p>Warning: Open brackets do not match close brackets in panel $i for speaker ".htmlentities($spoken[0]).'</p>';
Update include/*.php to use mysqli_* functions.
r4 $insert_sql = sprintf($inserter, (int)$strip->id, (int)$i, (int)$j, mysqli_real_escape_string($mtdb->link, $spoken[0]),
mysqli_real_escape_string($mtdb->link, $spoken[1]), mysqli_real_escape_string($mtdb->link, $spoken[2]) );
Add most necessary files for admin interface.
r1 if( false === $mtdb->query( $insert_sql ) ) {
$mtdb->query('ROLLBACK');
Update include/*.php to use mysqli_* functions.
r4 mtdie (mysqli_error(), 'Error inserting transcript.');
Add most necessary files for admin interface.
r1 }
}
}
}
}
$mtdb->query('COMMIT');
return $info;
}
function _nospeaker($name)
{
return "nospeaking: $name";
}
?>