Project

General

Profile

« Previous | Next » 

Revision 97ff635c

Added by Andreas Kohlbecker about 8 years ago

refactoring media_metadata function

View differences:

modules/cdm_dataportal/cdm_dataportal.module
2007 2007
  return $taxonRelationship->toTaxon->uuid == $focusedTaxon->uuid;
2008 2008
}
2009 2009

  
2010
/**
2011
 * Gets the metadata info such as title or artist of a media file.
2012
 *
2013
 * The function tries at first to get all the info from the file metadata
2014
 * and if it is not avaible look at the media file info stored at the database.
2015
 *
2016
 * @param mixed $media
2017
 *   The media file object for which to get the metadata.
2018
 *
2019
 * @return array
2020
 *   The array with the available specified metadata info.
2021
 * TODO rename to read_media_metadata() and move to *.module.
2022
 */
2023
function cdm_read_media_metadata($media) {
2024

  
2025
  $metadata_caption = array(
2026
    'title' => '',// Media_metadata and media.
2027
    'artist' => '',// Media_metadata and media.
2028
    'rights',// Media_metadata and media.
2029
    'location',// Media_metadata.
2030
    'filename' => '',// Media.
2031
    'mediacreated' => '',// Media.
2032
    'description' => '',
2033
  );// Media.
2034

  
2035
  // Getting the media metadata.
2036
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
2037
  $media_metadata_aux = (array) $media_metadata;
2038

  
2039
  // Filename.
2040
  if (!empty($media->representations[0]->parts[0]->uri)) {
2041
    $fileUri = $media->representations[0]->parts[0]->uri;
2042
    $filename = substr($fileUri, strrpos($fileUri, "/") + 1);
2043
    $metadata_caption['filename'] = $filename;
2044
  }
2045
  else {
2046
    $metadata_caption['filename'] = '';
2047
  }
2048

  
2049
  // Title.
2050
  if (!empty($media_metadata->ObjectName)) {
2051
    $metadata_caption['title'] = $media_metadata->ObjectName;
2052
  }
2053
  elseif (!empty($media_metadata_aux['Object Name'])) {
2054
    $metadata_caption['title'] = $media_metadata_aux['Object Name'];
2055
  }
2056
  elseif (!empty($media->title_L10n)) {
2057
    $metadata_caption['title'] = $media->title_L10n;
2058
  }
2059
  elseif (!empty($media->titleCache)) {
2060
    $metadata_caption['title'] = $media->titleCache;
2061
  }
2062

  
2063
  // Append description to title.
2064
  if (!empty($media->description_L10n)) {
2065
    $metadata_caption['title'] .= '<span class="media-description">' . $media->description_L10n . '<span>';
2066
  }
2067

  
2068
  // Artist.
2069
  if (!empty($media_metadata->Artist)) {
2070
    $metadata_caption['artist'] = '' . $media_metadata->Artist;
2071
  }
2072
  elseif (!empty($media->artist->titleCache)) {
2073
    $metadata_caption['artist'] = $media->artist->titleCache;
2074
  }
2075

  
2076
  // Copyright.
2077
  $metadata_caption['rights'] = array(
2078
    'copyright' => array('agentNames' => array()),
2079
    'license' => array(
2080
      'agentNames' => array(),
2081
      'types' => array(),
2082
      'abbreviatedTexts' => array(),
2083
      'uris' => array(),
2084
    ),
2085
  );
2086
  if (!empty($media_metadata->Copyright)) {
2087
    $metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
2088
  }
2089
  elseif (isset($media->rights) && is_array($media->rights)) {
2090
    foreach ($media->rights as $right) {
2091
      if(isset($right->term)){
2092
        switch ($right->type->uuid) {
2093
          case UUID_RIGHTS_LICENCE:
2094
            $metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? '' . $right->agent->firstname . ' ' . $right->agent->lastname : '');
2095
            $metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? '' . $right->representation_L10n : '');
2096
            $metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? '' . $right->abbreviatedText : '');
2097
            $metadata_caption['rights']['license']['uris'][] = ($right->uri ? '' . $right->uri : '');
2098
            break;
2099
          case UUID_RIGHTS_COPYRIGHT:
2100
            $metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
2101
            break;
2102
        }
2103
      }
2104
    }
2105
  }
2106
  else {
2107
    $metadata_caption['rights']['agentNames'][] = '';
2108
  }
2109

  
2110
  // Filling the description (though there is no description in the db???).
2111
  // $metadata_caption['description'] = $media->description_L10n;
2112

  
2113
  // Location.
2114
  $metadata_caption['location'] = array();
2115
  $metadata_caption['location']['sublocation'] = !empty($media_metadata->Sublocation) ? $media_metadata->Sublocation : FALSE;
2116
  $metadata_caption['location']['city'] = !empty($media_metadata->City) ? $media_metadata->City : FALSE;
2117
  $metadata_caption['location']['province'] = !empty($media_metadata->Province) ? $media_metadata->Province : FALSE;
2118
  $metadata_caption['location']['country'] = !empty($media_metadata->Country)? $media_metadata->Country : FALSE;
2119

  
2120
  /*
2121
   // Creation date.
2122
   if($media_metadata["Modify Date"])
2123
   $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
2124
   else
2125
   $metadata_caption['mediacreated'] = $media->created;
2126
   */
2127

  
2128
  // Returned value.
2129
  return $metadata_caption;
2130
}
2131 2010

  
2132 2011
/**
2133 2012
 * Collects all the media from a list of description elements.
modules/cdm_dataportal/includes/media.inc
111 111
 */
112 112
function media_feature_icon($feature, $media_url = NULL) {
113 113
  return font_awesome_icon_markup('fa-book', array('alt' => $feature->representation_L10n));
114
}
114
}
115

  
116
/**
117
 * Gets the metadata info such as title or artist of a media file.
118
 *
119
 * The function tries at first to get all the info from the file metadata
120
 * and if it is not available look at the media file info stored at the database.
121
 *
122
 * @param mixed $media
123
 *   The media file object for which to get the metadata.
124
 *
125
 * @return array
126
 *   The array with the available specified metadata info.
127
 */
128
function read_media_metadata($media) {
129

  
130
  $metadata_caption = array(
131
    'title' => '',// Media_metadata and media.
132
    'artist' => '',// Media_metadata and media.
133
    'rights',// Media_metadata and media.
134
    'location',// Media_metadata.
135
    'filename' => '',// Media.
136
    'mediacreated' => '',// Media.
137
    'description' => '',
138
  );// Media.
139

  
140
  // Getting the media metadata.
141
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
142
  $media_metadata_aux = (array) $media_metadata;
143

  
144
  // Filename.
145
  if (!empty($media->representations[0]->parts[0]->uri)) {
146
    $fileUri = $media->representations[0]->parts[0]->uri;
147
    $filename = substr($fileUri, strrpos($fileUri, "/") + 1);
148
    $metadata_caption['filename'] = $filename;
149
  }
150
  else {
151
    $metadata_caption['filename'] = '';
152
  }
153

  
154
  // Title.
155
  if (!empty($media_metadata->ObjectName)) {
156
    $metadata_caption['title'] = $media_metadata->ObjectName;
157
  }
158
  elseif (!empty($media_metadata_aux['Object Name'])) {
159
    $metadata_caption['title'] = $media_metadata_aux['Object Name'];
160
  }
161
  elseif (!empty($media->title_L10n)) {
162
    $metadata_caption['title'] = $media->title_L10n;
163
  }
164
  elseif (!empty($media->titleCache)) {
165
    $metadata_caption['title'] = $media->titleCache;
166
  }
167

  
168
  // Append description to title.
169
  if (!empty($media->description_L10n)) {
170
    $metadata_caption['title'] .= '<span class="media-description">' . $media->description_L10n . '<span>';
171
  }
172

  
173
  // Artist.
174
  if (!empty($media_metadata->Artist)) {
175
    $metadata_caption['artist'] = '' . $media_metadata->Artist;
176
  }
177
  elseif (!empty($media->artist->titleCache)) {
178
    $metadata_caption['artist'] = $media->artist->titleCache;
179
  }
180

  
181
  // Copyright.
182
  $metadata_caption['rights'] = array(
183
    'copyright' => array('agentNames' => array()),
184
    'license' => array(
185
      'agentNames' => array(),
186
      'types' => array(),
187
      'abbreviatedTexts' => array(),
188
      'uris' => array(),
189
    ),
190
  );
191
  if (!empty($media_metadata->Copyright)) {
192
    $metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
193
  }
194
  elseif (isset($media->rights) && is_array($media->rights)) {
195
    foreach ($media->rights as $right) {
196
      if(isset($right->term)){
197
        switch ($right->type->uuid) {
198
          case UUID_RIGHTS_LICENCE:
199
            $metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? '' . $right->agent->firstname . ' ' . $right->agent->lastname : '');
200
            $metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? '' . $right->representation_L10n : '');
201
            $metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? '' . $right->abbreviatedText : '');
202
            $metadata_caption['rights']['license']['uris'][] = ($right->uri ? '' . $right->uri : '');
203
            break;
204
          case UUID_RIGHTS_COPYRIGHT:
205
            $metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
206
            break;
207
        }
208
      }
209
    }
210
  }
211
  else {
212
    $metadata_caption['rights']['agentNames'][] = '';
213
  }
214

  
215
  // Filling the description (though there is no description in the db???).
216
  // $metadata_caption['description'] = $media->description_L10n;
217

  
218
  // Location.
219
  $metadata_caption['location'] = array();
220
  $metadata_caption['location']['sublocation'] = !empty($media_metadata->Sublocation) ? $media_metadata->Sublocation : FALSE;
221
  $metadata_caption['location']['city'] = !empty($media_metadata->City) ? $media_metadata->City : FALSE;
222
  $metadata_caption['location']['province'] = !empty($media_metadata->Province) ? $media_metadata->Province : FALSE;
223
  $metadata_caption['location']['country'] = !empty($media_metadata->Country)? $media_metadata->Country : FALSE;
224

  
225
  /*
226
   // Creation date.
227
   if($media_metadata["Modify Date"])
228
   $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
229
   else
230
   $metadata_caption['mediacreated'] = $media->created;
231
   */
232

  
233
  // Returned value.
234
  return $metadata_caption;
235
}
modules/cdm_dataportal/theme/cdm_dataportal.media.theme
188 188
function theme_cdm_media_caption($variables) {
189 189
  $media = $variables['media'];
190 190
  $elements = $variables['elements'];
191
  $media_metadata = cdm_read_media_metadata($media);
191
  $media_metadata = read_media_metadata($media);
192 192

  
193 193
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
194 194
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
......
206 206
      $descriptionPrefix = "- ";
207 207
    }
208 208
    elseif (!($doDescription && $media_metadata['description'])) {
209
      // Use filename as fallbackoption if no description will be shown.
209
      // Use filename as fallback option if no description will be shown.
210 210
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
211 211
      $descriptionPrefix = "- ";
212 212
    }
......
274 274
      $out .= $rights . '</dt>';
275 275
    }
276 276
  }
277
  // TODO add all other metadata elemenst generically.
277
  // TODO add all other metadata elements generically.
278 278
  $out .= '</dl>';
279 279
  // Return value,
280 280
  return $out;
......
642 642
      // Do not add margins if no pass partout is shown.
643 643
      $margins = '';
644 644
    }
645
    $out .= '<div class="appication">Web Application</div>';
645
    $out .= '<div class="application">Web Application</div>';
646 646

  
647 647
    if ($addPassePartout) {
648 648
      $out .= '</div>';
modules/cdm_dataportal/theme/cdm_dataportal.page.theme
577 577
    $partIdx = $partId;
578 578
  }
579 579

  
580
  $media_metadata = cdm_read_media_metadata($media);
580
  $media_metadata = read_media_metadata($media);
581 581
  // $title = $media->titleCache;
582 582
  $title = $media_metadata['title'];
583 583

  
themes/palmweb_2/template.php
144 144
  $media = $variables['media'];
145 145
  $elements = $variables['elements'];
146 146

  
147
  $media_metadata = cdm_read_media_metadata($media);
147
  $media_metadata = read_media_metadata($media);
148 148

  
149 149
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
150 150
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;

Also available in: Unified diff