Skip to content

Commit

Permalink
object titleimage check modified
Browse files Browse the repository at this point in the history
  • Loading branch information
nczirjak-acdh committed Jun 7, 2020
1 parent f20413e commit 52890fe
Showing 1 changed file with 11 additions and 33 deletions.
44 changes: 11 additions & 33 deletions src/Object/ResourceObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(array $data, $config, string $language = 'en')

/**
* get the data based on the property
*
*
* @param string $property
* @return array
*/
Expand All @@ -61,7 +61,7 @@ private function setData(string $prop = null, array $v = null)

/**
* Get the Resource title
*
*
* @return string
*/
public function getTitle(): string
Expand All @@ -81,16 +81,16 @@ public function getIdentifiers(): array

/**
* Get all identifiers which are not acdh related
*
*
* @return type
*/
public function getNonAcdhIdentifiers()
{
$result = array();
if (isset($this->properties["acdh:hasIdentifier"]) && !empty($this->properties["acdh:hasIdentifier"])) {
foreach ($this->properties["acdh:hasIdentifier"] as $k => $v) {
//filter out the baseurl related identifiers and which contains the id.acdh
if ((strpos($v->value, $this->config->getBaseUrl()) === false) &&
if(isset($this->properties["acdh:hasIdentifier"]) && !empty($this->properties["acdh:hasIdentifier"])) {
foreach($this->properties["acdh:hasIdentifier"] as $k => $v) {
//filter out the baseurl related identifiers and which contains the id.acdh
if ( (strpos($v->value, $this->config->getBaseUrl()) === false) &&
(strpos($v->value, 'https://id.acdh.oeaw.ac.at') === false)
) {
$result[] = $v;
Expand Down Expand Up @@ -236,31 +236,10 @@ public function getAccessRestriction(): array
*/
public function getTitleImage(): string
{
$img = '';
if (isset($this->properties["acdh:hasTitleImage"]) && count($this->properties["acdh:hasTitleImage"]) > 0) {
if (isset($this->properties["acdh:hasTitleImage"][0]->value)) {
$img = '';
try {
$client = new \GuzzleHttp\Client();
//$response = $client->get($this->config->getBaseUrl().$this->properties["acdh:hasTitleImage"][0]->value.'');
$response = $client->get('https://arche-thumbnails2.apollo.arz.oeaw.ac.at/'.$this->properties["acdh:hasTitleImage"][0]->value);

if ($response->getStatusCode() == 200) {
if ((isset($response->getHeader('Content-Length')[0]) && $response->getHeader('Content-Length')[0] > 0)) {
if (isset($response->getHeader('Content-Type')[0]) &&
($response->getHeader('Content-Type')[0] == 'image/png' || $response->getHeader('Content-Type')[0] == 'image/jpg'
|| $response->getHeader('Content-Type')[0] == 'image/jpeg')
) {
$img = '<img src="https://arche-thumbnails2.apollo.arz.oeaw.ac.at/'.$this->properties["acdh:hasTitleImage"][0]->value.'?width=200&height=150" />';
}
}
}
} catch (\Exception $ex) {
$img = '';
} catch (\GuzzleHttp\Exception\RequestException $ex) {
$img = '';
}

if (empty($img)) {
if (!empty($this->properties["acdh:hasTitleImage"][0]->value)) {
if ($img = @file_get_contents($this->config->getBaseUrl().$this->properties["acdh:hasTitleImage"][0]->value)) {
if (!empty($img)) {
$img = '<img src="data:image/png;base64,'.base64_encode($img).'" /> ';
Expand Down Expand Up @@ -316,13 +295,12 @@ public function getExpertTableData(): array

/**
* Format the date values for the twig template
*
*
* @param string $property
* @param string $dateFormat
* @return string
*/
public function getFormattedDateByProperty(string $property, string $dateFormat = 'Y') : string
{
public function getFormattedDateByProperty(string $property, string $dateFormat = 'Y') : string {
if (isset($this->properties[$property])) {
if (isset($this->properties[$property][0]->value)) {
$val = strtotime($this->properties[$property][0]->value);
Expand Down

0 comments on commit 52890fe

Please sign in to comment.