diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 87002616c..863484a5e 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -132,29 +132,19 @@ class ApiController extends Zend_Controller_Action $file_base_name = substr($file_base_name, 1); } - // possibly use fileinfo module here in the future. - // http://www.php.net/manual/en/book.fileinfo.php - $ext = pathinfo($file_base_name, PATHINFO_EXTENSION); //Download user left clicks a track and selects Download. if ("true" == $this->_getParam('download')) { //path_info breaks up a file path into seperate pieces of informaiton. //We just want the basename which is the file name with the path //information stripped away. We are using Content-Disposition to specify //to the browser what name the file should be saved as. - // - // By james.moon: - // I'm removing pathinfo() since it strips away UTF-8 characters. - // Using manualy parsing header('Content-Disposition: attachment; filename="'.$file_base_name.'"'); } else { //user clicks play button for track and downloads it. header('Content-Disposition: inline; filename="'.$file_base_name.'"'); } - if (strtolower($ext) === 'mp3') { - $this->smartReadFile($filepath, 'audio/mpeg'); - } else { - $this->smartReadFile($filepath, 'audio/'.$ext); - } + + $this->smartReadFile($filepath, $media->getPropelOrm()->getDbMime()); exit; } else { header ("HTTP/1.1 404 Not Found"); diff --git a/airtime_mvc/application/controllers/WebstreamController.php b/airtime_mvc/application/controllers/WebstreamController.php index 0cafb690b..3e82ad47e 100644 --- a/airtime_mvc/application/controllers/WebstreamController.php +++ b/airtime_mvc/application/controllers/WebstreamController.php @@ -52,13 +52,8 @@ class WebstreamController extends Zend_Controller_Action $hasPermission = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST)); $id = $request->getParam("id"); - if ($id == -1) { - $webstream = new CcWebstream(); - } else { - $webstream = CcWebstreamQuery::create()->findPK($id); - } - if ($id != -1) { + $webstream = CcWebstreamQuery::create()->findPK($id); //we are updating a playlist. Ensure that if the user is a host/dj, that he has the correct permission. $user = Application_Model_User::getCurrentUser(); if ($webstream->getDbCreatorId() != $user->getId()) { @@ -73,11 +68,14 @@ class WebstreamController extends Zend_Controller_Action } $analysis = Application_Model_Webstream::analyzeFormData($request); - - if (Application_Model_Webstream::isValid($analysis)) { - Application_Model_Webstream::save($request, $webstream); - $this->view->statusMessage = "
Webstream saved.
"; - } else { + try { + if (Application_Model_Webstream::isValid($analysis)) { + Application_Model_Webstream::save($request, $id); + $this->view->statusMessage = "
Webstream saved.
"; + } else { + throw new Exception(); + } + } catch (Exception $e) { $this->view->statusMessage = "
Invalid form values.
"; $this->view->analysis = $analysis; } diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index 23ca9d2c2..8e1660394 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -157,7 +157,7 @@ class Application_Model_Playlist $files = array(); $sql = <<id} AND pc.TYPE = 2)) AS temp - ORDER BY temp.position); + ORDER BY temp.position; SQL; $con = Propel::getConnection(); - $rows = $con->query($sql)->fetchAll(); + $rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC); $offset = 0; foreach ($rows as &$row) { diff --git a/airtime_mvc/application/models/Webstream.php b/airtime_mvc/application/models/Webstream.php index 97f74666d..a33575a68 100644 --- a/airtime_mvc/application/models/Webstream.php +++ b/airtime_mvc/application/models/Webstream.php @@ -22,6 +22,11 @@ class Application_Model_Webstream{ } } + public function getOrm() + { + return $this->webstream; + } + public function getName() { return $this->webstream->getDbName(); @@ -151,7 +156,7 @@ class Application_Model_Webstream{ public static function isValid($analysis) { foreach ($analysis as $k => $v) { - if ($v[0] == false) { + if ($v[0] === false) { return false; } } @@ -159,7 +164,34 @@ class Application_Model_Webstream{ return true; } - public static function save($request, $webstream) + /* + * This function is a callback used by curl to let us work + * with the contents returned from an http request. We don't + * actually want to work with the contents however (we just want + * the response headers), so immediately return a -1 in this function + * which tells curl not to download the response body at all. + */ + private function writefn($ch, $chunk) + { + return -1; + } + + private function discoverStreamMime() + { + Logging::log($this->webstream->getDbUrl()); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->webstream->getDbUrl()); + curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); + curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'writefn')); + $result = curl_exec($ch); + $mime = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); + curl_close($ch); + + Logging::log($mime); + return $mime; + } + + public static function save($request, $id) { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); @@ -178,6 +210,10 @@ class Application_Model_Webstream{ } + //$ws = new Application_Model_Webstream($id); + //$webstream = $ws->getOrm(); + + $webstream = new CcWebstream(); $webstream->setDbName($request->getParam("name")); $webstream->setDbDescription($request->getParam("description")); $webstream->setDbUrl($request->getParam("url")); @@ -187,5 +223,15 @@ class Application_Model_Webstream{ $webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC'))); $webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC'))); $webstream->save(); + + $ws = new Application_Model_Webstream($webstream->getDbId()); + + $mime = $ws->discoverStreamMime(); + if ($mime !== false) { + $webstream->setDbMime($mime); + } else { + throw new Exception("Couldn't get MIME type!"); + } + $webstream->save(); } } diff --git a/airtime_mvc/application/models/airtime/map/CcWebstreamTableMap.php b/airtime_mvc/application/models/airtime/map/CcWebstreamTableMap.php index 316553581..5121aa39b 100644 --- a/airtime_mvc/application/models/airtime/map/CcWebstreamTableMap.php +++ b/airtime_mvc/application/models/airtime/map/CcWebstreamTableMap.php @@ -46,6 +46,7 @@ class CcWebstreamTableMap extends TableMap { $this->addColumn('CREATOR_ID', 'DbCreatorId', 'INTEGER', true, null, null); $this->addColumn('MTIME', 'DbMtime', 'TIMESTAMP', true, 6, null); $this->addColumn('UTIME', 'DbUtime', 'TIMESTAMP', true, 6, null); + $this->addColumn('MIME', 'DbMime', 'VARCHAR', false, 255, null); // validators } // initialize() diff --git a/airtime_mvc/application/models/airtime/om/BaseCcWebstream.php b/airtime_mvc/application/models/airtime/om/BaseCcWebstream.php index b570309dc..e5faf12fd 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcWebstream.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcWebstream.php @@ -73,6 +73,12 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent */ protected $utime; + /** + * The value for the mime field. + * @var string + */ + protected $mime; + /** * @var array CcSchedule[] Collection to store aggregation of CcSchedule objects. */ @@ -239,6 +245,16 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent } } + /** + * Get the [mime] column value. + * + * @return string + */ + public function getDbMime() + { + return $this->mime; + } + /** * Set the value of [id] column. * @@ -457,6 +473,26 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent return $this; } // setDbUtime() + /** + * Set the value of [mime] column. + * + * @param string $v new value + * @return CcWebstream The current object (for fluent API support) + */ + public function setDbMime($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->mime !== $v) { + $this->mime = $v; + $this->modifiedColumns[] = CcWebstreamPeer::MIME; + } + + return $this; + } // setDbMime() + /** * Indicates whether the columns in this object are only set to default values. * @@ -501,6 +537,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent $this->creator_id = ($row[$startcol + 5] !== null) ? (int) $row[$startcol + 5] : null; $this->mtime = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null; $this->utime = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null; + $this->mime = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null; $this->resetModified(); $this->setNew(false); @@ -509,7 +546,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent $this->ensureConsistency(); } - return $startcol + 8; // 8 = CcWebstreamPeer::NUM_COLUMNS - CcWebstreamPeer::NUM_LAZY_LOAD_COLUMNS). + return $startcol + 9; // 9 = CcWebstreamPeer::NUM_COLUMNS - CcWebstreamPeer::NUM_LAZY_LOAD_COLUMNS). } catch (Exception $e) { throw new PropelException("Error populating CcWebstream object", $e); @@ -850,6 +887,9 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent case 7: return $this->getDbUtime(); break; + case 8: + return $this->getDbMime(); + break; default: return null; break; @@ -881,6 +921,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent $keys[5] => $this->getDbCreatorId(), $keys[6] => $this->getDbMtime(), $keys[7] => $this->getDbUtime(), + $keys[8] => $this->getDbMime(), ); return $result; } @@ -936,6 +977,9 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent case 7: $this->setDbUtime($value); break; + case 8: + $this->setDbMime($value); + break; } // switch() } @@ -968,6 +1012,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent if (array_key_exists($keys[5], $arr)) $this->setDbCreatorId($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setDbMtime($arr[$keys[6]]); if (array_key_exists($keys[7], $arr)) $this->setDbUtime($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setDbMime($arr[$keys[8]]); } /** @@ -987,6 +1032,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent if ($this->isColumnModified(CcWebstreamPeer::CREATOR_ID)) $criteria->add(CcWebstreamPeer::CREATOR_ID, $this->creator_id); if ($this->isColumnModified(CcWebstreamPeer::MTIME)) $criteria->add(CcWebstreamPeer::MTIME, $this->mtime); if ($this->isColumnModified(CcWebstreamPeer::UTIME)) $criteria->add(CcWebstreamPeer::UTIME, $this->utime); + if ($this->isColumnModified(CcWebstreamPeer::MIME)) $criteria->add(CcWebstreamPeer::MIME, $this->mime); return $criteria; } @@ -1055,6 +1101,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent $copyObj->setDbCreatorId($this->creator_id); $copyObj->setDbMtime($this->mtime); $copyObj->setDbUtime($this->utime); + $copyObj->setDbMime($this->mime); if ($deepCopy) { // important: temporarily setNew(false) because this affects the behavior of @@ -1284,6 +1331,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent $this->creator_id = null; $this->mtime = null; $this->utime = null; + $this->mime = null; $this->alreadyInSave = false; $this->alreadyInValidation = false; $this->clearAllReferences(); diff --git a/airtime_mvc/application/models/airtime/om/BaseCcWebstreamPeer.php b/airtime_mvc/application/models/airtime/om/BaseCcWebstreamPeer.php index 0839a8f9b..4ec74befd 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcWebstreamPeer.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcWebstreamPeer.php @@ -26,7 +26,7 @@ abstract class BaseCcWebstreamPeer { const TM_CLASS = 'CcWebstreamTableMap'; /** The total number of columns. */ - const NUM_COLUMNS = 8; + const NUM_COLUMNS = 9; /** The number of lazy-loaded columns. */ const NUM_LAZY_LOAD_COLUMNS = 0; @@ -55,6 +55,9 @@ abstract class BaseCcWebstreamPeer { /** the column name for the UTIME field */ const UTIME = 'cc_webstream.UTIME'; + /** the column name for the MIME field */ + const MIME = 'cc_webstream.MIME'; + /** * An identiy map to hold any loaded instances of CcWebstream objects. * This must be public so that other peer classes can access this when hydrating from JOIN @@ -71,12 +74,12 @@ abstract class BaseCcWebstreamPeer { * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ private static $fieldNames = array ( - BasePeer::TYPE_PHPNAME => array ('DbId', 'DbName', 'DbDescription', 'DbUrl', 'DbLength', 'DbCreatorId', 'DbMtime', 'DbUtime', ), - BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbName', 'dbDescription', 'dbUrl', 'dbLength', 'dbCreatorId', 'dbMtime', 'dbUtime', ), - BasePeer::TYPE_COLNAME => array (self::ID, self::NAME, self::DESCRIPTION, self::URL, self::LENGTH, self::CREATOR_ID, self::MTIME, self::UTIME, ), - BasePeer::TYPE_RAW_COLNAME => array ('ID', 'NAME', 'DESCRIPTION', 'URL', 'LENGTH', 'CREATOR_ID', 'MTIME', 'UTIME', ), - BasePeer::TYPE_FIELDNAME => array ('id', 'name', 'description', 'url', 'length', 'creator_id', 'mtime', 'utime', ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, ) + BasePeer::TYPE_PHPNAME => array ('DbId', 'DbName', 'DbDescription', 'DbUrl', 'DbLength', 'DbCreatorId', 'DbMtime', 'DbUtime', 'DbMime', ), + BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbName', 'dbDescription', 'dbUrl', 'dbLength', 'dbCreatorId', 'dbMtime', 'dbUtime', 'dbMime', ), + BasePeer::TYPE_COLNAME => array (self::ID, self::NAME, self::DESCRIPTION, self::URL, self::LENGTH, self::CREATOR_ID, self::MTIME, self::UTIME, self::MIME, ), + BasePeer::TYPE_RAW_COLNAME => array ('ID', 'NAME', 'DESCRIPTION', 'URL', 'LENGTH', 'CREATOR_ID', 'MTIME', 'UTIME', 'MIME', ), + BasePeer::TYPE_FIELDNAME => array ('id', 'name', 'description', 'url', 'length', 'creator_id', 'mtime', 'utime', 'mime', ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, ) ); /** @@ -86,12 +89,12 @@ abstract class BaseCcWebstreamPeer { * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 */ private static $fieldKeys = array ( - BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbName' => 1, 'DbDescription' => 2, 'DbUrl' => 3, 'DbLength' => 4, 'DbCreatorId' => 5, 'DbMtime' => 6, 'DbUtime' => 7, ), - BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbName' => 1, 'dbDescription' => 2, 'dbUrl' => 3, 'dbLength' => 4, 'dbCreatorId' => 5, 'dbMtime' => 6, 'dbUtime' => 7, ), - BasePeer::TYPE_COLNAME => array (self::ID => 0, self::NAME => 1, self::DESCRIPTION => 2, self::URL => 3, self::LENGTH => 4, self::CREATOR_ID => 5, self::MTIME => 6, self::UTIME => 7, ), - BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'NAME' => 1, 'DESCRIPTION' => 2, 'URL' => 3, 'LENGTH' => 4, 'CREATOR_ID' => 5, 'MTIME' => 6, 'UTIME' => 7, ), - BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'name' => 1, 'description' => 2, 'url' => 3, 'length' => 4, 'creator_id' => 5, 'mtime' => 6, 'utime' => 7, ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, ) + BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbName' => 1, 'DbDescription' => 2, 'DbUrl' => 3, 'DbLength' => 4, 'DbCreatorId' => 5, 'DbMtime' => 6, 'DbUtime' => 7, 'DbMime' => 8, ), + BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbName' => 1, 'dbDescription' => 2, 'dbUrl' => 3, 'dbLength' => 4, 'dbCreatorId' => 5, 'dbMtime' => 6, 'dbUtime' => 7, 'dbMime' => 8, ), + BasePeer::TYPE_COLNAME => array (self::ID => 0, self::NAME => 1, self::DESCRIPTION => 2, self::URL => 3, self::LENGTH => 4, self::CREATOR_ID => 5, self::MTIME => 6, self::UTIME => 7, self::MIME => 8, ), + BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'NAME' => 1, 'DESCRIPTION' => 2, 'URL' => 3, 'LENGTH' => 4, 'CREATOR_ID' => 5, 'MTIME' => 6, 'UTIME' => 7, 'MIME' => 8, ), + BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'name' => 1, 'description' => 2, 'url' => 3, 'length' => 4, 'creator_id' => 5, 'mtime' => 6, 'utime' => 7, 'mime' => 8, ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, ) ); /** @@ -171,6 +174,7 @@ abstract class BaseCcWebstreamPeer { $criteria->addSelectColumn(CcWebstreamPeer::CREATOR_ID); $criteria->addSelectColumn(CcWebstreamPeer::MTIME); $criteria->addSelectColumn(CcWebstreamPeer::UTIME); + $criteria->addSelectColumn(CcWebstreamPeer::MIME); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.NAME'); @@ -180,6 +184,7 @@ abstract class BaseCcWebstreamPeer { $criteria->addSelectColumn($alias . '.CREATOR_ID'); $criteria->addSelectColumn($alias . '.MTIME'); $criteria->addSelectColumn($alias . '.UTIME'); + $criteria->addSelectColumn($alias . '.MIME'); } } diff --git a/airtime_mvc/application/models/airtime/om/BaseCcWebstreamQuery.php b/airtime_mvc/application/models/airtime/om/BaseCcWebstreamQuery.php index b5bf09979..101bbfbd1 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcWebstreamQuery.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcWebstreamQuery.php @@ -14,6 +14,7 @@ * @method CcWebstreamQuery orderByDbCreatorId($order = Criteria::ASC) Order by the creator_id column * @method CcWebstreamQuery orderByDbMtime($order = Criteria::ASC) Order by the mtime column * @method CcWebstreamQuery orderByDbUtime($order = Criteria::ASC) Order by the utime column + * @method CcWebstreamQuery orderByDbMime($order = Criteria::ASC) Order by the mime column * * @method CcWebstreamQuery groupByDbId() Group by the id column * @method CcWebstreamQuery groupByDbName() Group by the name column @@ -23,6 +24,7 @@ * @method CcWebstreamQuery groupByDbCreatorId() Group by the creator_id column * @method CcWebstreamQuery groupByDbMtime() Group by the mtime column * @method CcWebstreamQuery groupByDbUtime() Group by the utime column + * @method CcWebstreamQuery groupByDbMime() Group by the mime column * * @method CcWebstreamQuery leftJoin($relation) Adds a LEFT JOIN clause to the query * @method CcWebstreamQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query @@ -43,6 +45,7 @@ * @method CcWebstream findOneByDbCreatorId(int $creator_id) Return the first CcWebstream filtered by the creator_id column * @method CcWebstream findOneByDbMtime(string $mtime) Return the first CcWebstream filtered by the mtime column * @method CcWebstream findOneByDbUtime(string $utime) Return the first CcWebstream filtered by the utime column + * @method CcWebstream findOneByDbMime(string $mime) Return the first CcWebstream filtered by the mime column * * @method array findByDbId(int $id) Return CcWebstream objects filtered by the id column * @method array findByDbName(string $name) Return CcWebstream objects filtered by the name column @@ -52,6 +55,7 @@ * @method array findByDbCreatorId(int $creator_id) Return CcWebstream objects filtered by the creator_id column * @method array findByDbMtime(string $mtime) Return CcWebstream objects filtered by the mtime column * @method array findByDbUtime(string $utime) Return CcWebstream objects filtered by the utime column + * @method array findByDbMime(string $mime) Return CcWebstream objects filtered by the mime column * * @package propel.generator.airtime.om */ @@ -359,6 +363,28 @@ abstract class BaseCcWebstreamQuery extends ModelCriteria return $this->addUsingAlias(CcWebstreamPeer::UTIME, $dbUtime, $comparison); } + /** + * Filter the query on the mime column + * + * @param string $dbMime The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return CcWebstreamQuery The current query, for fluid interface + */ + public function filterByDbMime($dbMime = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($dbMime)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $dbMime)) { + $dbMime = str_replace('*', '%', $dbMime); + $comparison = Criteria::LIKE; + } + } + return $this->addUsingAlias(CcWebstreamPeer::MIME, $dbMime, $comparison); + } + /** * Filter the query by a related CcSchedule object * diff --git a/airtime_mvc/build/schema.xml b/airtime_mvc/build/schema.xml index f44043bd1..0773a2675 100644 --- a/airtime_mvc/build/schema.xml +++ b/airtime_mvc/build/schema.xml @@ -422,5 +422,6 @@ + diff --git a/airtime_mvc/build/sql/schema.sql b/airtime_mvc/build/sql/schema.sql index c8d488f97..6fe02acf3 100644 --- a/airtime_mvc/build/sql/schema.sql +++ b/airtime_mvc/build/sql/schema.sql @@ -638,6 +638,7 @@ CREATE TABLE "cc_webstream" "creator_id" INTEGER NOT NULL, "mtime" TIMESTAMP(6) NOT NULL, "utime" TIMESTAMP(6) NOT NULL, + "mime" VARCHAR(255), PRIMARY KEY ("id") );