-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaggedTextMast.php
121 lines (110 loc) · 5.71 KB
/
taggedTextMast.php
1
<?php # THIS FILE MUST HAVE MAC LINE ENDINGS! That means \r aka carriage return################################################################################ $Id: taggedTextMast.php 2322 2015-01-12 03:52:52Z quentin $# This file will output a Tagged Text version of the masthead. The data MUST # be encoded in UTF-16 Big Endian with Carriage Returns for line endings for # everything to work. That means that some things may look really funky # programatically, but are needed due to the constraints of Tagged Text. Also, # this will case PHP to return the wrong line number for errors. Good thing I # don't have any :-)## Note that PHP will slurp up a newline that immediately follows a closing php # tag. For more information, visit these (most likely outdated) links:## http://www.adobe.com/go/learn_id_taggedtext# http://help.adobe.com/en_US/InDesign/6.0/indesign_cs4_taggedtext.pdf## Also, you could view information about the Daily Confusion which Ricky wrote # after reading the aformentioned documentation. Hopefully, I've brought that # knowledge over here appropriately.###############################################################################require_once dirname(__FILE__).'/common.php';### Functions# Takes position title and array of members, returns formatted textfunction formatPosition($title, $members) { # Replace the middle space in <CAPITAL><PERIOD><SPACE><CAPITAL><PERIOD<SPACE> # with a THIN SPACE (U+2009,  ). # This is for cases like "B. D. Colen" -> "B.<THIN SPACE>D. Colen", # "Bruno B. F. Faviero" -> "Bruno B.<THIN SPACE>F. Faviero", and # "Jonathon E. D. Richmond" -> "Jonathan E.<THIN SPACE>D. Richmond PhD" $members = preg_replace( '/([A-Z]\.) ([A-Z]\. )/', '$1' . mb_convert_encoding(' ', 'UTF-8', 'HTML-ENTITIES') . '$2', $members); $seperator = ", "; # Production positioning hack: replace "Associate " with "Assoc-iateN", # where the hyphen is discretionary (aka soft) and the N is a nonbreaking # space. This reduces the liklihood that a line will break as: # _DEPARTMENT_ # Editor: .... Associate # Editor: ... # and cause confusion or bad copyfitting as a result. $title = preg_replace( '/Associate /', 'Assoc' . mb_convert_encoding('­', 'UTF-8', 'HTML-ENTITIES') . 'iate' . mb_convert_encoding(' ', 'UTF-8', 'HTML-ENTITIES'), $title); if ($title == '') return join($seperator, $members); // For AdBoard if (sizeof($members) > 1 and !preg_match("/Staff$/", $title)) { $title = $title . (substr($title, -1) == "s" ? "es" : "s"); } return "<cTypeface:Bold>$title:<cTypeface:> " . join($seperator, $members);}# Takes department name and array of positions to array of members and returns # formatted textfunction formatDepartment($name, $positions) { // Editors at Larger and AdBoard don't modify their dept names if(!($name == "Editors at Large" or $name == "Advisory Board" or $name == "Production Staff for This Issue")) { $name = $name . " Staff"; } $folded = array(); foreach ($positions as $title => $members) { array_push($folded, formatPosition($title, $members)); } $folded = join('; ', $folded); return "<ParaStyle:PROD-Misc\\:MAST\\:PROD-MastDept>$name\r" . "<ParaStyle:PROD-Misc\\:MAST\\:PROD-MastPeople>$folded.";}$depts = getDepartments();// Exec board gets special formatting$exec = getDepartmentMembers(array_shift($depts));header('Content-Type: text/plain; charset="UTF-16BE"');header('Content-Disposition: attachment; filename=masthead.txt');// XXX: Due to a bug in PHP - kinda http://bugs.php.net/34776 (although some // may also argue PHP itself is the bug) - the BOM must be output before we do // the rest of the conversion. Now, this will also cause headers to be sent, // which will mean that when we flush output at the bottom it'll try to send // headers again and emit a warning.echo("\xfe\xff"); // BOM for proper UTF-16BE detectionmb_internal_encoding("UTF-8");mb_http_output("UTF-16BE");ob_start("mb_output_handler");?><UNICODE-MAC><?phpforeach ($exec as $position => $members) { // Exec has Shift-returns (a.k.a just a newline) between titles and names $person = "\n".$members[0];?><ParaStyle:PROD-Misc\:MAST\:PROD-MastTop><cTypeface:Bold><?=$position?><cTypeface:><?=$person?><?php}// Now deal with the rest of the departmentsforeach ($depts as $dept) { $members = getDepartmentMembers($dept); if(sizeof($members) == 0) continue; echo formatDepartment($dept, $members) . "\r";}// Don't forget about Production staff for the issue!echo formatDepartment('Production Staff for This Issue', array("Editor" => array("@@", "@@"), "Staff" => array("@@"), "Copy Editors" => array("@@"))) . "\r";// Time for the copyright with the current year$currentyear=date("Y");?><ParaStyle:PROD-Misc\:MAST\:PROD-MastBottom><cTypeface:Italic>The Tech<cTypeface:> (ISSN 0148-9607) is published on Thursdays during the academic year (except during MIT vacations) and monthly during the summer by The Tech, Room W20-483, 84 Massachusetts Avenue, Cambridge, Mass. 02139. Subscriptions are $50.00 per year (third class). <cTypeface:Bold><cCase:All Caps>Postmaster:<cCase:><cTypeface:> Please send all address changes to our mailing address: The Tech, P.O. Box 397029, Cambridge, Mass. 02139-7029. <cTypeface:Bold><cCase:All Caps>Telephone:<cCase:><cTypeface:> Editorial: (617) 253-1541. Business: (617) 258-8324. Facsimile: (617) 258-8226. <cTypeface:Italic>Advertising, subscription, and typesetting rates available.<cTypeface:> Entire contents <cTypeface:Bold Italic>© <?=$currentyear?> The Tech<cTypeface:>. <cTypeface:Italic>Printed by Turley Publications, Inc.<cTypeface:><?php// Suppress the warning about headers. (See XXX at BOM above)@ob_end_flush();