/** * Test the display() function when fallbacks * * @return void */ public function testDisplayFallbacks() { // Setup $this->handler->enable(true)->setType('Article'); $content = 'anything'; // Test without $content if fallbacks, the $Property isn't available in the current Type $response = $this->handler->property('anUnavailableProperty')->fallback('Article', 'about')->display(); $this->assertEquals($response, "vocab='https://schema.org' typeof='Article' property='about'"); // Test with $content if fallbacks, the $Property isn't available in the current Type $response = $this->handler->content($content)->property('anUnavailableProperty')->fallback('Article', 'about')->display(); $this->assertEquals($response, "<span vocab='https://schema.org' typeof='Article'><span property='about'>{$content}</span></span>"); // Test if fallbacks, the $Property isn't available in the current and the fallback Type $response = $this->handler->property('anUnavailableProperty')->fallback('Article', 'anUnavailableProperty')->display(); $this->assertEquals($response, "vocab='https://schema.org' typeof='Article'"); // Test with $content if fallbacks, the $Property isn't available in the current $Type $response = $this->handler->content($content)->property('anUnavailableProperty')->fallback('Article', 'datePublished')->display(); $this->assertEquals($response, "<meta vocab='https://schema.org' typeof='Article' property='datePublished' content='{$content}'/>"); // Test without $content if fallbacks, the Property isn't available in the current Type $response = $this->handler->property('anUnavailableProperty')->fallback('Article', 'datePublished')->display(); $this->assertEquals($response, "vocab='https://schema.org' typeof='Article' property='datePublished'"); }
/** * Test the display() function when fallbacks * * @return void * * @since 3.2 */ public function testDisplayFallbacks() { // Setup $this->handler->enable(true)->setType('Article'); $content = 'anything'; // Test without content if fallbacks, the Property isn't available in the current Type $responce = $this->handler->property('anUnanvailableProperty')->fallback('Article', 'about')->display(); $this->assertEquals($responce, "itemscope itemtype='https://schema.org/Article' itemprop='about'"); // Test wit content if fallbacks, the Property isn't available in the current Type $responce = $this->handler->content($content)->property('anUnanvailableProperty')->fallback('Article', 'about')->display(); $this->assertEquals($responce, "<span itemscope itemtype='https://schema.org/Article'><span itemprop='about'>{$content}</span></span>"); // Test if fallbacks, the Property isn't available in the current and fallback Type $responce = $this->handler->property('anUnanvailableProperty')->fallback('Article', 'anUnanvailableProperty')->display(); $this->assertEquals($responce, "itemscope itemtype='https://schema.org/Article'"); // Test with content if fallbacks, the Property isn't available in the current and fallback Type $responce = $this->handler->content($content)->property('anUnanvailableProperty')->fallback('Article', 'datePublished')->display(); $this->assertEquals($responce, "<meta itemscope itemtype='https://schema.org/Article' itemprop='datePublished' content='{$content}'/>"); // Test withtout content if fallbacks, the Property isn't available in the current and fallback Type $responce = $this->handler->property('anUnanvailableProperty')->fallback('Article', 'datePublished')->display(); $this->assertEquals($responce, "itemscope itemtype='https://schema.org/Article' itemprop='datePublished'"); }
/** * Recursive method to add comments to a flat RSS feed * * @param object $doc JDocumentFeed * @param object $row BlogModelComment * @return void */ private function _comment(&$doc, $row) { // Load individual item creator class $item = new \Hubzero\Document\Type\Feed\Item(); $item->title = Lang::txt('Comment #%s', $row->get('id')) . ' @ ' . $row->created('time') . ' on ' . $row->created('date'); $item->link = Route::url($this->entry->link() . '#c' . $row->get('id')); if ($row->isReported()) { $item->description = Lang::txt('COM_BLOG_COMMENT_REPORTED_AS_ABUSIVE'); } else { $item->description = html_entity_decode(Sanitize::stripAll($row->content())); } $item->description = '<![CDATA[' . $item->description . ']]>'; if ($row->get('anonymous')) { //$item->author = Lang::txt('COM_BLOG_ANONYMOUS'); } else { $item->author = $row->creator()->get('email') . ' (' . $row->creator()->get('name') . ')'; } $item->date = $row->created(); $item->category = ''; $doc->addItem($item); $replies = $row->replies()->whereIn('state', array(1, 3)); if ($replies->count() > 0) { foreach ($replies as $reply) { $this->_comment($doc, $reply); } } }
/** * Given a response object, populate this object. * * This parses the JSON data and parcels out the data to the appropriate * fields. * * @param object $response HPCloud::Transport::Response * A response object. * * @retval HPCloud::Services::IdentityServices * @return \HPCloud\Services\IdentityServices * $this for the current object so it can be used in chaining. */ protected function handleResponse($response) { $json = json_decode($response->content(), TRUE); // print_r($json); $this->tokenDetails = $json['access']['token']; $this->userDetails = $json['access']['user']; $this->serviceCatalog = $json['access']['serviceCatalog']; return $this; }
/** * Create image alias variation by contentObjectAttribute * * @param object $contentObjectAttribute object of class eZContentObjectAtribute * @param array $class Array of object class identifiers to create aliases for only these classes. Optional. Defaults to false * @param array $attributes Array of object image attribute identifiers to create aliases. Optional. Defaults to false * @param array $aliases Array of object image attribute image aliases to create. Optional. Defaults to false * * @return bool true if any image alias generation is called, false if not * @static */ static function createByAttribute($contentObjectAttribute = false, $classes = false, $attributes = false, $aliases = false) { if (!$contentObjectAttribute) { return false; } // Test that content object class attribute identifier matches provided classes if ($classes != false && is_array($classes) && !in_array($contentObjectAttribute->attribute('object')->attribute('class_identifier'), $classes)) { return false; } // Test that content object class attribute identifier matches provided classes if ($attributes != false && is_array($attributes) && !in_array($contentObjectAttribute->attribute('contentclass_attribute_identifier'), $attributes)) { return false; } $results = array(); $result = array(); $createAliases = array(); $executionOptions = self::executionOptions(); // Default image alias settings $relatedSiteAccesses = eZINI::instance('site.ini')->variable('SiteAccessSettings', 'RelatedSiteAccessList'); // Fetch aliases for current siteaccess if ($executionOptions['current-siteaccess']) { if (!$aliases) { // Default image alias settings $createAliases = eZINI::instance('image.ini')->variable('AliasSettings', 'AliasList'); } else { // Parameter image alias to create $createAliases = $aliases; } } else { if (!$aliases) { // Fetch aliases for current siteaccess relateded siteaccesses if (is_array($relatedSiteAccesses)) { foreach ($relatedSiteAccesses as $relatedSiteAccess) { $relatedSiteaccessImageINIOverrideFile = 'settings/siteaccess/' . $relatedSiteAccess . '/image.ini.append.php'; if (file_exists($relatedSiteaccessImageINIOverrideFile)) { // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage('Fetching related siteaccess ' . "'" . $relatedSiteAccess . "'" . ' image.ini:[AliasSettings] AliasList[] image aliases defined', "\n"); } $siteaccessAliases = eZINI::getSiteAccessIni($relatedSiteAccess, 'image.ini')->variable('AliasSettings', 'AliasList'); // Test for siteaccesses if ($siteaccessAliases != false) { // Add siteaccess aliases into array foreach ($siteaccessAliases as $siteaccessAlias) { if (!in_array($siteaccessAlias, $aliases)) { $aliases[] = $siteaccessAlias; } } // Add default settings aliases into array foreach (eZINI::instance('image.ini', 'settings', null, null, false, true)->variable('AliasSettings', 'AliasList') as $defaultSettingAlias) { if (!in_array($defaultSettingAlias, $aliases)) { $aliases[] = $defaultSettingAlias; } } // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 2 && !$executionOptions['iterate']) { self::displayMessage('All siteaccess ' . "'" . $relatedSiteAccess . "'" . ' image.ini:[AliasSettings] AliasList[] image aliases defined'); print_r($aliases); self::displayMessage('', "\n"); } } } } } } else { // Parameter image alias to create $createAliases = $aliases; } } // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 2) { self::displayMessage('All related siteaccess image.ini:[AliasSettings] AliasList[] image aliases defined:'); print_r($createAliases); self::displayMessage('', "\n"); } // Don't try to create original image alias unset($createAliases['original']); // Default datatypes to create image alias variations $imageDataTypeStrings = eZINI::instance('bcimagealias.ini')->variable('BCImageAliasSettings', 'ImageDataTypeStringList'); // Check that content object attribute data type string matches allowed datatype settings if (!in_array($contentObjectAttribute->attribute('data_type_string'), $imageDataTypeStrings) || !$contentObjectAttribute->attribute('has_content')) { return false; } // Fetch content object attribute content the image alias handler object $imageHandler = $contentObjectAttribute->content(); // Fetch eZImageManager instance $imageManager = eZImageManager::factory(); // Fetch all related siteaccess image.ini:[AliasSettings] AliasList[] image aliases defined if (is_array($relatedSiteAccesses) && !$executionOptions['current-siteaccess'] && !$executionOptions['iterate']) { // Fetch all default image aliases for imageManager // $imageManager->readImageAliasesFromINI( 'settings/image.ini' ); // Fetch all siteaccess image aliases for imageManager foreach ($relatedSiteAccesses as $relatedsiteaccess) { $relatedSiteaccessImageINIFileFolder = 'settings/siteaccess/' . $relatedsiteaccess; $relatedSiteaccessImageINIFile = $relatedSiteaccessImageINIFileFolder . '/image.ini.append.php'; if (file_exists($relatedSiteaccessImageINIFile)) { // $imageManager->readImageAliasesFromOverrideINI( 'image.ini.append.php', $relatedSiteaccessImageINIFileFolder ); $imageManager->readImageAliasesFromOverrideINI($relatedsiteaccess, 'image.ini'); } } // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 2) { self::displayMessage("\n" . 'Image manager image aliases', "\n"); print_r(array_keys($imageManager->AliasList)); } } elseif (!$executionOptions['current-siteaccess'] && $executionOptions['iterate']) { $imageManager->readImageAliasesFromOriginalINI('image.ini'); } // Fetch the image alias handler object's alias list $aliasList = $imageHandler->aliasList(); $original = $aliasList['original']; $basename = $original['basename']; // Optional debug output if ($executionOptions['troubleshoot']) { if ($executionOptions['verboseLevel'] >= 4) { self::displayMessage('Current content object image attribute image alias list entries within attribute handler content:', "\n"); print_r($imageHandler->ContentObjectAttributeData['DataTypeCustom']['alias_list']); self::displayMessage('', "\n\n"); } elseif ($executionOptions['verboseLevel'] >= 3) { self::displayMessage('Current content object image attribute image alias list entries within attribute handler content:', "\n"); print_r(array_keys($imageHandler->ContentObjectAttributeData['DataTypeCustom']['alias_list'])); self::displayMessage('', "\n\n"); } else { self::displayMessage('', "\n"); } self::displayMessage('Number of ini image aliases: ' . count($createAliases), "\n\n"); } // Initialize alias foreach counter at one, 1 $aliasCounter = 1; // Iterate through image alias list from settings foreach ($createAliases as $aliasItem) { // Test $aliasItem from $createAliases is in $aliases array if ($aliases != false && is_array($aliases) && !in_array($aliasItem, $aliases)) { continue; } // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage('Iteration ' . $aliasCounter . ' of ' . count($createAliases) . ' | Preparing to attempt to create the "' . $aliasItem . '" image alias variation', "\n"); } // Store a temporary record of the alias not yet created this iteration $result[$aliasItem] = false; // Iterate alias foreach counter $aliasCounter++; /** * Test image alias exists according to imageManager */ if (!$imageManager->hasAlias($aliasItem)) { // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage("\n" . 'eZImageManger claims: ' . '"' . $aliasItem . '"' . ' does not exist in system', "\n\n"); } continue; } // Skip generating aliases which already exist if force option is false if (isset($aliasList[$aliasItem]) && !$executionOptions['regenerate']) { continue; } // Skip generation if force is not true and dry is true if (!$executionOptions['regenerate'] && $executionOptions['dry']) { // Optional debug output if ($executionOptions['troubleshoot']) { // Alert user of dry alias calculation $message = "Dry run: Calculating generation of datatype " . $contentObjectAttribute->attribute('data_type_string') . "type image alias " . '"' . $aliasItem . '"' . ' image variation' . "\n"; self::displayMessage($message); } continue; } // Create $aliasItem the image alias image variation image file on disk immediately if ($imageManager->createImageAlias($aliasItem, $aliasList, array('basename' => $basename))) { // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 3) { self::displayMessage('Specific alias added to aliasList (in attribute):'); print_r($aliasList[$aliasItem]); self::displayMessage('', "\n"); } // Store a record of the alias created this iteration $result[$aliasItem] = true; // Uncomment the following line to write a error log entry (for debug) // error_log( __CLASS__ . __METHOD__ . ": Created alias $aliasItem" ); } else { // Store a record of the alias not created this iteration $result[$aliasItem] = false; // Uncomment the following line to write a error log entry (for debug) // error_log( __CLASS__ . __METHOD__ . ": Fail creating alias $aliasItem" ); } // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 3) { self::displayMessage('Leaving create image alias if block'); self::displayMessage('Looping to next image alias from ini settings', "\n"); } } $aliasesCreated = array_keys($result, true); $aliasesCreatedCount = count($aliasesCreated); // Only prepare alias meta data when alias(s) have been created if (is_array($result) && in_array(true, array_keys($result, true))) { $aliasAlertnativeText = $imageHandler->displayText(isset($original['alertnative_text']) ? $original['alertnative_text'] : ''); $aliasOriginalFilename = $original['original_filename']; self::displayMessage('', "\n"); foreach ($aliasList as $aliasKey => $aliasListItem) { if ($aliases != false && is_array($aliases) && !in_array($aliasKey, $aliases)) { continue; } // Test for newly added alias // if( ( !isset( $aliasListItem['is_new'] ) or $aliasListItem['is_new'] == '' ) && $executionOptions[ 'regenerate' ] ) if ($executionOptions['regenerate']) { $aliasListItem['is_new'] = true; $aliasListItem['is_valid'] = true; } // Prepare meta data $aliasListItem['original_filename'] = $aliasOriginalFilename; $aliasListItem['text'] = $aliasAlertnativeText; // Test for alias file url and add meta data if ($aliasListItem['url']) { $aliasListItemFile = eZClusterFileHandler::instance($aliasListItem['url']); if ($aliasListItemFile->exists()) { $aliasListItem['filesize'] = $aliasListItemFile->size(); } } // Test for newly added alias if ($aliasListItem['is_new']) { eZImageFile::appendFilepath($imageHandler->ContentObjectAttributeData['id'], $aliasListItem['url']); } // Add alias image variation image file meta data back into aliasList $aliasList[$aliasKey] = $aliasListItem; // Track successful generation attempts if (isset($result[$aliasKey]) && $result[$aliasKey]) { $results[] = true; $message = "Created datatype " . $contentObjectAttribute->attribute('data_type_string') . "type image alias " . '"' . $aliasListItem['name'] . '"' . " image variation " . $aliasListItem['url']; self::scriptIterate($message, "\n"); } elseif (!isset($result[$aliasKey])) { $results[] = true; } else { $results[] = false; } } /** * Note: The following code replaces the use of this example private method unavailable at the time of publishing * * $imageHandler->setAliasList( $aliasList ); */ $imageHandler->ContentObjectAttributeData['DataTypeCustom']['alias_list'] = $aliasList; $imageHandler->addImageAliases($aliasList); // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 3) { self::displayMessage('Created image alias list array:'); print_r($aliasList); self::displayMessage('', "\n\n"); self::displayMessage('Created image alias handler object:'); print_r($imageHandler); self::displayMessage('', "\n\n"); } } // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage("\n" . 'Content object attribute image alias image variation generation attempts completed', "\n\n"); $coaID = $contentObjectAttribute->attribute('id'); $coaVersion = (int) $contentObjectAttribute->attribute('version'); $contentObjectAttributeRefetched = eZContentObjectAttribute::fetch($coaID, $coaVersion); if ($executionOptions['verboseLevel'] >= 3) { self::displayMessage('Displaying saved re-feched data_text of attribute image handler. You should see this list fully populated with all created image alias file urls'); print_r($contentObjectAttributeRefetched->attribute('content')->aliasList()); self::displayMessage('', "\n"); $objectLookup = eZContentObject::fetch($contentObjectAttribute->attribute('contentobject_id')); $objectLookupDM = $objectLookup->dataMap(); self::displayMessage('Displaying saved re-feched object attribute aliasList from image handler. You should see this list fully populated with all created image alias file urls'); print_r($objectLookupDM['image']->content()->aliasList(true)); self::displayMessage('', "\n"); } if ($executionOptions['verboseLevel'] >= 3 && !$executionOptions['iterate']) { self::displayMessage('Here are the content object image attribute image alias generation attempt results:'); self::displayMessage('Created aliases will show up as a 1. Theses results do not affect workflow completion as image aliases will not always be created', "\n"); print_r($result); self::displayMessage('', "\n"); } elseif ($executionOptions['verboseLevel'] >= 2 && $executionOptions['iterate']) { self::displayMessage('Here are the content object image attribute image alias generation attempt results:'); self::displayMessage('Created aliases will show up as a 1. Theses results do not affect workflow completion as image aliases will not always be created', "\n"); print_r($result); self::displayMessage('', "\n"); } } // Calculate return results based on execution options and results comparison if (in_array(true, $results) && count($createAliases) == count($result) && !$executionOptions['dry'] && $executionOptions['regenerate']) { // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage('Creation attempts calculate as successful, at least once. All aliases possible attempted'); self::displayMessage('Variation images created: ' . $aliasesCreatedCount . ' out of ' . count($result), "\n"); } return true; } elseif (in_array(true, $results) && !$executionOptions['dry'] && !$executionOptions['regenerate']) { // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage('Creation attempts calculate as successful, at least once. All aliases possible attempted', "\n\n"); self::displayMessage('Variations images created: ' . $aliasesCreatedCount . ' out of ' . count($result), "\n\n"); } return true; } return false; }