/** * Answer all media assets below the specified asset * * @param object Asset $asset * @param optional object Id $excludeId * @return object Iterator * @access protected * @since 2/26/07 */ protected function getAllMediaAssets(Asset $asset, $excludeId = null) { if ($excludeId && $excludeId->isEqual($asset->getId())) { return false; } if ($this->mediaFileType->isEqual($asset->getAssetType())) { $tmp = array(); $tmp[] = $asset; $iterator = new HarmoniIterator($tmp); return $iterator; } else { $iterator = new MultiIteratorIterator(); $children = $asset->getAssets(); while ($children->hasNext()) { $result = $this->getAllMediaAssets($children->next(), $excludeId); if ($result) { $iterator->addIterator($result); } } return $iterator; } }
/** * Instantiate a new plugin for an Asset * * @param object Asset $asset * @param object ConfigurationProperties $configuration * @return object Plugin OR string (error string) on error. * @access public * @since 1/12/06 * @static */ public static function newInstance(Asset $asset, Properties $configuration) { $type = $asset->getAssetType(); $pluginManager = Services::getService("PluginManager"); $pluginDir = $pluginManager->getPluginDir($type); $pluginClass = $pluginManager->getPluginClass($type); if (preg_match('/[^a-z0-9_]/i', $pluginClass)) { throw new Exception("Invalid plugin class, '" . $pluginClass . "'."); } $pluginFile = $pluginDir . $pluginClass . ".class.php"; // Check for the file if (!file_exists($pluginFile)) { return _("Error: Plugin not found at '{$pluginFile}'."); } require_once $pluginFile; // Check for the class if (!class_exists($pluginClass)) { return _("Error: Plugin class, '{$pluginClass}', not found."); } // Ensure that the plugin writer didn't override the constructor if (in_array($pluginClass, get_class_methods($pluginClass))) { return _("Error: Plugin class should not have a constructor method, '{$pluginClass}'."); } // Instantiate the plugin $plugin = new $pluginClass(); $plugin->setConfiguration($configuration); $plugin->setAsset($asset); // Execute the decendent's initialization $plugin->initialize(); return $plugin; }
/** * Recursively copies an asset and its children to a new parent. * * @access private */ function _copyAsset(Asset $asset, Id $newParentId) { // Create the new asset $newAsset = $this->createAsset($asset->getDisplayName(), $asset->getDescription(), $asset->getAssetType()); // Move the new asset to the proper parent if it // is not being copied to the dr root. if (!$newParentId->isEqual($this->getId())) { $newParent = $this->getAsset($newParentId); $newParent->addAsset($newAsset->getId()); } // Copy its data // @todo // Copy the children $children = $asset->getAssets(); while ($children->hasNext()) { $childAsset = $children->next(); $this->_copyAsset($childAsset, $newAsset->getId()); } // Return its Id return $newAsset->getId(); }
/** * Record any extra files that are used by plugins * * @param Asset $asset * @return void */ public function recordPluginExtras(Asset $asset) { $audioType = new Type('SeguePlugins', 'edu.middlebury', 'AudioPlayer'); $downloadType = new Type('SeguePlugins', 'edu.middlebury', 'Download'); if ($asset->getAssetType()->isEqual($audioType) || $asset->getAssetType()->isEqual($downloadType)) { $query = 'count(item[wp:post_type = "attachment" and title = "downarrow.gif"])'; if (!$this->xpath->evaluate($query, $this->channel)) { $url = MYPATH . '/images/downarrow.gif'; $element = $this->channel->insertBefore($this->doc->createElement('item'), $this->endFiles); $element->appendChild($this->getElement('title', "downarrow.gif")); $element->appendChild($this->getElement('link', $url)); $element->appendChild($this->getElement('guid', $url))->setAttribute('isPermaLink', 'false'); $element->appendChild($this->getElement('description', 'Download icon.')); $element->appendChild($this->getElement('pubDate', date('r'))); $agentUID = $this->recordAgent($asset->getCreator()); $element->appendChild($this->getElementNS("http://purl.org/dc/elements/1.1/", 'dc:creator', '0')); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_id', '0')); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_date', date('Y-m-d H:i:s'))); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_date_gmt', date('Y-m-d H:i:s'))); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_status', 'closed')); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:ping_status', 'closed')); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:status', 'publish')); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_parent', $asset->getId()->getIdString())); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:menu_order', '0')); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_type', 'attachment')); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_password', '')); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:is_sticky', '0')); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:attachment_url', $url)); } } }
/** * Create and/or return the component for an asset and register it for later fetching * * @param object Asset $asset * @return object SiteComponent * @access public * @since 4/5/06 */ function getSiteComponentFromAsset(Asset $asset) { $id = $asset->getId(); $idString = $id->getIdString(); if (!isset($this->_createdSiteComponents[$idString])) { $type = $asset->getAssetType(); foreach ($this->siteDisplayTypes as $siteDisplayType) { if ($type->isEqual($siteDisplayType)) { $typeKey = ucfirst($type->getKeyword()); break; } } if (!isset($typeKey)) { $typeKey = 'Block'; } $class = "Asset" . $typeKey . "SiteComponent"; try { $xmlDocument = $this->getXmlDocumentFromAsset($asset); $documentElement = $xmlDocument->documentElement; } catch (NonNavException $e) { $documentElement = null; } $this->_createdSiteComponents[$idString] = new $class($this, $asset, $documentElement); } return $this->_createdSiteComponents[$idString]; }