Ignore:
Timestamp:
Mar 21, 2010, 7:20:07 PM (14 years ago)
Author:
grum
Message:

Fix some bug, enhance some functionnalities, and make plugin ready to be translated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AMetaData/amd_root.class.inc.php

    r5183 r5226  
    2626include_once('JpegMetaData/JpegMetaData.class.php');
    2727include_once(JPEG_METADATA_DIR."Common/L10n.class.php");
     28include_once(JPEG_METADATA_DIR."TagDefinitions/XmpTags.class.php");
    2829
    2930class AMD_root extends common_plugin
     
    3435  public function __construct($prefixeTable, $filelocation)
    3536  {
     37    global $user;
    3638    $this->plugin_name="AMetaData";
    3739    $this->plugin_name_files="amd";
     
    4345    $this->css = new css(dirname($this->filelocation).'/'.$this->plugin_name_files.".css");
    4446    $this->jpegMD=new JpegMetaData();
     47
     48    if(isset($user['language']))
     49    {
     50      L10n::setLanguage($user['language']);
     51    }
    4552  }
    4653
     
    271278
    272279
     280  /**
     281   * This function :
     282   *  - convert arrays (stored as a serialized string) into human readable string
     283   *  - translate value in user language (if value is translatable)
     284   *
     285   * @param String $value         : value to prepare
     286   * @param Boolean $translatable : set to tru if the value can be translated in
     287   *                                the user language
     288   * @param String $separator     : separator for arrays items
     289   * @return String               : the value prepared
     290   */
     291  protected function prepareValueForDisplay($value, $translatable=true, $separator=", ")
     292  {
     293    global $user;
     294
     295    if(preg_match('/^a:\d+:\{.*\}$/is', $value))
     296    {
     297      // $value is a serialized array
     298      $tmp=unserialize($value);
     299
     300      if(count($tmp)==0)
     301      {
     302        return(L10n::get("Unknown"));
     303      }
     304
     305      if(array_key_exists("computed", $tmp) and array_key_exists("detail", $tmp))
     306      {
     307        /* keys 'computed' and 'detail' are present
     308         *
     309         * assume this is the 'exif.exif.Flash' metadata and return the computed
     310         * value only
     311         */
     312        return(L10n::get($tmp['computed']));
     313      }
     314      elseif(array_key_exists("type", $tmp) and array_key_exists("values", $tmp))
     315      {
     316        /* keys 'computed' and 'detail' are present
     317         *
     318         * assume this is an Xmp 'ALT', 'BAG' or 'SEQ' metadata and return the
     319         * values only
     320         */
     321        if($tmp['type']=='alt')
     322        {
     323          /* 'ALT' structure
     324           *
     325           * ==> assuming the structure is used only for multi language values
     326           *
     327           * Array(
     328           *    'type'   => 'ALT'
     329           *    'values' =>
     330           *        Array(
     331           *            Array(
     332           *                'type'  => Array(
     333           *                            'name'  =>'xml:lang',
     334           *                            'value' => ''           // language code
     335           *                           )
     336           *               'value' => ''         //value in the defined language
     337           *            ),
     338           *
     339           *            Array(
     340           *                // data2
     341           *            ),
     342           *
     343           *        )
     344           * )
     345           */
     346          $tmp=XmpTags::getAltValue($tmp, $user['language']);
     347          if(trim($tmp)=="") $tmp="(".L10n::get("not defined").")";
     348
     349          return($tmp);
     350        }
     351        else
     352        {
     353          /* 'SEQ' or 'BAG' structure
     354           *
     355           *  Array(
     356           *    'type'   => 'XXX',
     357           *    'values' => Array(val1, val2, .., valN)
     358           *  )
     359           */
     360          $tmp=$tmp['values'];
     361
     362          if(trim(implode("", $tmp))=="")
     363          {
     364            return("(".L10n::get("not defined").")");
     365          }
     366        }
     367      }
     368
     369
     370      foreach($tmp as $key=>$val)
     371      {
     372        if(is_array($val))
     373        {
     374          if($translatable)
     375          {
     376            foreach($val as $key2=>$val2)
     377            {
     378              $tmp[$key][$key2]=L10n::get($val2);
     379            }
     380            if(count($val)>0)
     381            {
     382              $tmp[$key]="[".implode($separator, $val)."]";
     383            }
     384            else
     385            {
     386              unset($tmp[$key]);
     387            }
     388          }
     389        }
     390        else
     391        {
     392          if($translatable)
     393          {
     394            $tmp[$key]=L10n::get($val);
     395          }
     396        }
     397      }
     398      return(implode($separator, $tmp));
     399    }
     400    else
     401    {
     402      if(trim($value)=="")
     403      {
     404        return("(".L10n::get("not defined").")");
     405      }
     406
     407      if(strpos($value, "|")>0)
     408      {
     409        $value=explode("|", $value);
     410        if($translatable)
     411        {
     412          foreach($value as $key=>$val)
     413          {
     414            $value[$key]=L10n::get($val);
     415          }
     416        }
     417        return(implode("", $value));
     418      }
     419
     420      if($translatable)
     421      {
     422        return(L10n::get($value));
     423      }
     424      return($value);
     425    }
     426  }
     427
    273428} // amd_root  class
    274429
Note: See TracChangeset for help on using the changeset viewer.