예제 #1
0
파일: Form.php 프로젝트: relyd/aidstream
 /**
  * Function to add Sub Elements form to the element.
  *
  * @param string $formClass  Class name of the form to be added.
  * @param string $elementClassName        Class name of the element whose form is added, eg for transaction _tiedstatus the
  * classname is TiedStatus.
  * @param int $elementCount     Count value for the element. It is added as the array key for the element's array
  * @param array $attribs        Array of form element values. 
  */
 public function addSubElement($formClass, $elementClassName, $elementCount, $attribs = null, $multiple = false)
 {
     $subForm = new $formClass();
     $camelCaseToSeperator = new Zend_Filter_Word_CamelCaseToSeparator(" ");
     $title = $camelCaseToSeperator->filter($elementClassName);
     $subForm->removeDecorator('form');
     if ($multiple) {
         $add = new Iati_Form_Element_Note('add');
         $add->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'button'));
         $add->setValue("<a href='#' class='add-element' value='{$elementClassName}'> Add More</a>");
         $add->setOrder(101);
         $remove = new Iati_Form_Element_Note('remove');
         $remove->setValue("<a href='/wep/remove-elements?classname={$elementClassName}' class='remove-this'> Remove This</a>");
         $remove->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'remove button'));
         $remove->setOrder(100);
         $subForm->addElements(array($add, $remove));
     }
     $subForm->addDisplayGroup(array_keys($subForm->getElements()), $elementClassName, array('legend' => $title, 'class' => $subForm->getAttrib('class')));
     $subForm->setElementsBelongTo("{$elementClassName}[{$elementCount}]");
     if ($attribs) {
         $subForm->populate($attribs);
     }
     $subForm->addDecorators(array(array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'options' => array('class' => 'element-wrapper')))));
     $this->addSubForm($subForm, "{$elementClassName}{$elementCount}");
     return $subForm;
 }
 public function getContentsPacked()
 {
     if (!$this->_features) {
         return null;
     }
     $modernizrPath = getcwd() . '/node_modules/modernizr';
     $outputFile = tempnam('./temp', 'modernizr');
     $configAll = json_decode(file_get_contents($modernizrPath . '/lib/config-all.json'), true);
     $allFeatureDetects = $configAll['feature-detects'];
     $options = array();
     foreach ($configAll['options'] as $i) {
         $options[$i] = false;
     }
     $options['mq'] = true;
     $options['setClasses'] = true;
     $featureDetects = array();
     foreach ($this->_features as $f) {
         if (isset($options[strtolower($f)])) {
             //for prefixed
             $options[strtolower($f)] = true;
         } else {
             $filter = new Zend_Filter_Word_CamelCaseToSeparator('/');
             $fFiltered = strtolower($filter->filter($f));
             if (!in_array($fFiltered, $allFeatureDetects)) {
                 throw new Kwf_Exception("Invalid Modernizr Dependency, test doesn't exist: '" . $f . "'");
             }
             $featureDetects[] = $fFiltered;
         }
     }
     foreach ($options as $k => $i) {
         if (!$i) {
             unset($options[$k]);
         }
     }
     $options = array_keys($options);
     $classPrefix = '';
     if (Kwf_Config::getValue('application.uniquePrefix')) {
         $classPrefix = Kwf_Config::getValue('application.uniquePrefix') . '-';
     }
     $config = array('classPrefix' => $classPrefix, 'options' => $options, 'feature-detects' => $featureDetects);
     $configFile = tempnam('temp/', 'modernizrbuild');
     unlink($configFile);
     $configFile .= '.json';
     file_put_contents($configFile, json_encode($config, JSON_PRETTY_PRINT));
     $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node {$modernizrPath}/bin/modernizr --config {$configFile} --uglify --dest " . $outputFile;
     exec($cmd, $out, $retVar);
     if ($retVar) {
         throw new Kwf_Exception("modernizr failed: " . implode("\n", $out));
     }
     $ret = file_get_contents($outputFile);
     unlink($configFile);
     unlink($outputFile);
     //remove comments containing selected tests
     $ret = preg_replace("#\n/\\*!\n\\{.*?\\}\n!\\*/\n#s", '', $ret);
     $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($ret);
     $map = $ret->getMapContentsData(false);
     $map->{'_x_org_koala-framework_masterFiles'} = array(getcwd() . '/node_modules/modernizr/package.json');
     return $ret;
 }
예제 #3
0
 public function testFilterSeparatesCamelCasedWordsWithProvidedSeparator()
 {
     $string = 'CamelCasedWords';
     $filter = new Zend_Filter_Word_CamelCaseToSeparator(':-#');
     $filtered = $filter->filter($string);
     $this->assertNotEquals($string, $filtered);
     $this->assertEquals('Camel:-#Cased:-#Words', $filtered);
 }
예제 #4
0
 /**
  * Initialize class and log debug message
  * 
  * @return void
  * @access protected
  */
 protected function _initBootstrap()
 {
     // Fiter SeperatorToCamelCase Setup
     $filter = new Zend_Filter_Word_CamelCaseToSeparator('-');
     $this->_module['class'] = $this->getModuleName();
     $this->_module['folder'] = strtolower($filter->filter($this->_module['class']));
     // Info Log
     Zend_Registry::get('logging')->log($this->_module['class'] . ' bootstrap initialized...', Zend_Log::INFO);
 }
예제 #5
0
 public static function getByUrl($Url)
 {
     $TheLuogo = new self();
     try {
         $TheLuogo->fetchRowAndSet("Url = '{$Url}'");
         $TheLuogo = self::get($TheLuogo->IDLocation);
     } catch (Exception $E) {
         $filter = new Zend_Filter_Word_CamelCaseToSeparator();
         $Nome = ucfirst($filter->filter($Url));
         $Data = array('Name' => $Nome, 'Url' => $Url);
         $IDLuogo = $TheLuogo->insert($Data);
         $TheLuogo = self::get($IDLuogo);
     }
     return $TheLuogo;
 }
예제 #6
0
 /**
  * Gets the form elements code to add
  *
  * @param array $fields 
  * @return string
  */
 protected function _getFormElements($fields)
 {
     $upperFirst = new UCFirst();
     $camelCaseToSpace = new CamelCaseToSeparator();
     $elements = '';
     $fields = explode(',', $fields);
     foreach ($fields as $field) {
         list($name, $type) = strpos($field, ':') ? explode(':', $field) : array($field, 'string');
         $ucFirst = $upperFirst->filter($name);
         $label = $camelCaseToSpace->filter($ucFirst);
         switch ($type) {
             case 'text':
                 $elements .= "        \$this->addElement('textarea', " . "'{$name}', array('label' => '{$label}'));" . PHP_EOL;
                 break;
             default:
                 $elements .= "        \$this->addElement('text'," . " '{$name}', array('label' => " . "'{$label}'));" . PHP_EOL;
                 break;
         }
     }
     if (!empty($elements)) {
         $elements .= "        \$this->addElement('submit', 'Save');" . PHP_EOL;
     }
     return $elements;
 }
 /**
  * Constructor
  *
  * @return void
  */
 public function __construct()
 {
     parent::__construct('-');
 }
예제 #8
0
    /**
     * Creates the show view
     *
     * @param string $entity
     * @param array  $fields
     * @return string
     */
    protected static function createShowView($entity, $fields)
    {
        $upperFirst = new UCFirst();
        $lowerFirst = new LCFirst();
        $camelCaseToSpace = new CamelCaseToSeparator();
        $pluralize = new Pluralize();
        $entityPlural = $pluralize->filter($entity);
        $lowerEntity = $lowerFirst->filter($entity);
        $data = $rendered = '';
        $fields = explode(',', $fields);
        foreach ($fields as $field) {
            $fieldAndType = explode(':', $field);
            list($field, $type) = count($fieldAndType) === 2 ? $fieldAndType : array($field, 'string');
            $ucFirst = $upperFirst->filter($field);
            $field = $camelCaseToSpace->filter($ucFirst);
            $data .= "'get{$ucFirst}' => 'some {$field}'," . PHP_EOL . "            ";
            $rendered .= '$this->rendered->should->haveSelector(\'p>b\', ' . 'array(\'text\' => \'' . $field . ':\'));
        $this->rendered->should->contain(\'some ' . $field . '\');';
        }
        return <<<SHOWVIEW
<?php

namespace {$entityPlural};

use \\PHPSpec\\Context\\Zend\\View as ViewContext;

class DescribeShow extends ViewContext
{
    function before()
    {
        \$this->assign('{$lowerEntity}', \$this->stub('{$entity}', array(
            'getId' => '1',
            {$data}
        )));
    }
    
    function itRendersThe{$entity}()
    {
        \$this->render();
        {$rendered}
    }
}
SHOWVIEW;
    }
예제 #9
0
 public function getContents($language)
 {
     if (isset($this->_contentsCache)) {
         return $this->_contentsCache;
     }
     if (!$this->_features) {
         return null;
     }
     $modernizrPath = dirname(dirname(dirname(dirname(__FILE__)))) . '/node_modules/modernizr';
     $package = json_decode(file_get_contents($modernizrPath . '/package.json'), true);
     $this->_outputFile = getcwd() . '/temp/modernizr-' . $package['version'] . '-' . implode('-', $this->_features) . '/modernizr.js';
     if (file_exists($this->_outputFile)) {
         $ret = file_get_contents($this->_outputFile);
         $this->_contentsCache = $ret;
         return $ret;
     }
     $configAll = json_decode(file_get_contents($modernizrPath . '/lib/config-all.json'), true);
     $allFeatureDetects = $configAll['feature-detects'];
     $options = array();
     foreach ($configAll['options'] as $i) {
         $options[$i] = false;
     }
     $options['mq'] = true;
     $options['setClasses'] = true;
     $featureDetects = array();
     foreach ($this->_features as $f) {
         if (isset($options[strtolower($f)])) {
             //for prefixed
             $options[strtolower($f)] = true;
         } else {
             $filter = new Zend_Filter_Word_CamelCaseToSeparator('/');
             $fFiltered = strtolower($filter->filter($f));
             if (!in_array($fFiltered, $allFeatureDetects)) {
                 throw new Kwf_Exception("Invalid Modernizr Dependency, test doesn't exist: '" . $f . "'");
             }
             $featureDetects[] = $fFiltered;
         }
     }
     foreach ($options as $k => $i) {
         if (!$i) {
             unset($options[$k]);
         }
     }
     $options = array_keys($options);
     $classPrefix = '';
     if (Kwf_Config::getValue('application.uniquePrefix')) {
         $classPrefix = Kwf_Config::getValue('application.uniquePrefix') . '-';
     }
     $config = array('classPrefix' => $classPrefix, 'options' => $options, 'feature-detects' => $featureDetects);
     $configFile = tempnam('temp/', 'modernizrbuild');
     unlink($configFile);
     $configFile .= '.json';
     file_put_contents($configFile, json_encode($config, JSON_PRETTY_PRINT));
     $cmd = "./" . VENDOR_PATH . "/bin/node {$modernizrPath}/bin/modernizr --config {$configFile} --uglify --dest " . dirname($this->_outputFile);
     exec($cmd, $out, $retVar);
     unlink($configFile);
     if ($retVar) {
         throw new Kwf_Exception("modernizr failed: " . implode("\n", $out));
     }
     $ret = file_get_contents($this->_outputFile);
     $this->_contentsCache = $ret;
     return $ret;
 }
예제 #10
0
파일: xmp.php 프로젝트: ameoba32/tiki
 /**
  * Process raw XMP string by converting to a DOM document, replacing legend codes with their meanings,
  * fixing labels, etc.
  *
  * @param 		xml string$xmpstring
  *
  * @return array|bool
  */
 function processRawData($xmpstring)
 {
     //need to do a little preparation before processing fields
     if (!empty($xmpstring)) {
         $xmp = new DOMDocument();
         //create a DOM Document from the XML string
         $xmp->loadXML($xmpstring);
         //convert Dom Document to an array
         //TODO use Zend_Json::fromXml when zend fixes bug (see http://framework.zend.com/issues/browse/ZF-12224)
         $xmparray = $this->xmpDomToArray($xmp);
         //re-label Native Digest fields in tiff and exif sections to keep from overwriting when arrays are flattened
         //in other functions
         $sections = array('exif', 'tiff');
         foreach ($sections as $section) {
             if (isset($xmparray[$section]['NativeDigest'])) {
                 $temp = explode(',', $xmparray[$section]['NativeDigest']['rawval']);
                 $xmparray[$section]['NativeDigest']['rawval'] = implode(', ', $temp);
                 $xmparray[$section][strtoupper($section) . 'NativeDigest'] = $xmparray[$section]['NativeDigest'];
                 unset($xmparray[$section]['NativeDigest']);
             }
         }
         //now we can process fields
         $filter = new Zend_Filter_Word_CamelCaseToSeparator();
         foreach ($xmparray as $group => $fields) {
             foreach ($fields as $name => $field) {
                 if (isset($this->specs[$group][$name])) {
                     //shorten the variable
                     $specname = $this->specs[$group][$name];
                     //convert coded fields into tags
                     if (isset($specname['options'])) {
                         $xmparray[$group][$name]['newval'] = $specname['options'][$xmparray[$group][$name]['rawval']];
                     } else {
                         $xmparray[$group][$name]['newval'] = $xmparray[$group][$name]['rawval'];
                     }
                     //fix labels
                     if (isset($specname['label'])) {
                         $xmparray[$group][$name]['label'] = $specname['label'];
                     } else {
                         //create reading-friendly labels from camel case tags
                         $xmparray[$group][$name]['label'] = $filter->filter($name);
                     }
                 } else {
                     //those not covered in $specs
                     //create reading-friendly labels from camel case tags
                     $xmparray[$group][$name]['label'] = $filter->filter($name);
                     $xmparray[$group][$name]['newval'] = $xmparray[$group][$name]['rawval'];
                 }
                 //deal with arrays
                 if (is_array($field['rawval'])) {
                     if (array_key_exists($name, $this->special)) {
                         $xmparray[$group][$name]['newval'] = $this->specialHandling($name, $field['rawval']);
                     } elseif (isset($field['rawval']['rawval'])) {
                         $xmparray[$group][$name]['newval'] = $field['rawval']['rawval'];
                     } elseif (isset($field['rawval'][0])) {
                         $xmparray[$group][$name]['newval'] = '';
                         foreach ($field['rawval'] as $val) {
                             $xmparray[$group][$name]['newval'] .= $val['rawval'] . '; ';
                         }
                     } else {
                         $xmparray[$group][$name]['newval'] = '';
                         foreach ($field['rawval'] as $val) {
                             $xmparray[$group][$name]['newval'] .= $val['label'] . ': ' . $val['rawval'] . '; ';
                         }
                     }
                 }
                 //convert dates
                 if (array_key_exists($name, array('ModifyDate' => '', 'DateCreated' => '', 'CreateDate' => '', 'MetadataDate' => ''))) {
                     $dateObj = new DateTime($xmparray[$group][$name]['newval']);
                     $date = $dateObj->format('Y-m-d  H:i:s  T');
                     $xmparray[$group][$name]['newval'] = $date;
                 }
             }
         }
     } else {
         return false;
     }
     return $xmparray;
 }
예제 #11
0
 /**
  * Gets the content of scaffolded show view
  *
  * @param string $entity 
  * @param array $fields 
  * @return string
  */
 protected static function _getShowViewContent($entity, $fields)
 {
     $upperFirst = new UCFirst();
     $lowerFirst = new LCFirst();
     $camelCaseToSpace = new CamelCaseToSeparator();
     $camelCaseToDash = new CamelCaseToDash();
     $pluralize = new Pluralize();
     $lowerEntity = $lowerFirst->filter($entity);
     $lowerEntityPlural = $pluralize->filter($lowerEntity);
     $dashedEntityPlural = $camelCaseToDash->filter($lowerEntityPlural);
     $properties = '';
     foreach ($fields as $field) {
         $upper = $upperFirst->filter($field);
         $field = $camelCaseToSpace->filter($field);
         $field = $upperFirst->filter($field);
         $properties .= "  <p>\n    <b>{$field}:</b>\n    <?php echo \$this->escape(\$this->{$lowerEntity}->get{$upper}()) ?></h3>\n  </p>" . PHP_EOL . PHP_EOL;
     }
     return "<h1>Show {$entity}</h1>\n\n{$properties}\n\n<a href=\"<?php echo \$this->baseUrl(" . "'{$dashedEntityPlural}/edit/id/' ." . " (int)\$this->{$lowerEntity}->getId()) ?>\">Edit</a> |\n<a href=\"<?php echo \$this->baseUrl(" . "'{$dashedEntityPlural}') ?>\">Back</a>";
 }
예제 #12
0
파일: db.php 프로젝트: tapiau/muyo
 /**
  * @static
  *
  * @param $name
  * @param $args
  *
  *
  * @return array[self]|self|mixed
  * @throws Lib_Exception
  * @throws Exception
  */
 public static function __callStatic($name, $args)
 {
     $matches = array();
     if (preg_match('/^get(List|Set)*By([a-zA-Z]+)$/', $name, $matches)) {
         /** @var Lib_Model $model */
         $model = new static();
         $cond = array();
         $list = false;
         $set = false;
         if (!empty($matches[1])) {
             if ($matches[1] == 'List') {
                 $list = true;
             } else {
                 $set = true;
             }
         }
         $filter = new Zend_Filter_Word_CamelCaseToSeparator('_');
         $attr = strtolower($filter->filter($matches[2]));
         if ($attr == 'id') {
             $attr = $model->getPrimaryKey();
         }
         if (!array_key_exists($attr, $model->toArray())) {
             $class = get_class($model);
             throw new Exception("Attribute '{$attr}' not exists in model '{$class}'");
         }
         $cond[$attr] = array_shift($args);
         if ($set) {
             return static::getSetBy($cond);
         }
         $result = static::getListBy($cond);
         if (!$list) {
             if (count($result) > 1) {
                 $class = get_class($model);
                 throw new Exception("Trying get more than 1 row by attribute '{$attr}' from model '{$class}'");
             } elseif (count($result) == 1) {
                 return array_shift($result);
             } else {
                 return new static();
             }
         } else {
             return $result;
         }
     } else {
         throw new Exception("Static method '{$name}' not implemented.");
     }
 }
예제 #13
0
 /**
  * Creates the view specs
  *
  * @param string $entity 
  * @param string $commaSeparatedFields 
  * @param string $module
  */
 protected static function _createViewSpecs($entity, $commaSeparatedFields, $module)
 {
     $filter = new CamelCaseToSeparator('-');
     $pluralize = new Pluralize();
     $ds = DIRECTORY_SEPARATOR;
     $module = $module === null ? '' : $module . $ds;
     $controllerDir = strtolower($pluralize->filter($filter->filter($entity)));
     $viewSpecPath = ".{$ds}spec{$ds}views{$ds}{$module}{$controllerDir}";
     if (!file_exists($viewSpecPath)) {
         mkdir($viewSpecPath);
     }
     foreach (self::$_scaffoldActions as $view) {
         ViewSpec::create($viewSpecPath, $entity, $commaSeparatedFields, $view, $module);
     }
 }
예제 #14
0
    /**
     * Renders the content of the scaffolded controller spec
     *
     * @param string $entity 
     * @param array  $fields 
     * @param string $module 
     * @return string  
     */
    protected static function content($entity, $fields, $module)
    {
        $pluralize = new Pluralize();
        $dashIt = new CamelCaseToSeparator();
        $camelize = new DashToCamelCase();
        $lcFirst = new LCFirst();
        $ucFirst = new UCFirst();
        if ($module === null) {
            $module = $camelize->filter($module);
            $namespace = 'namespace ' . $ucFirst->filter($module) . ';' . PHP_EOL;
        } else {
            $namespace = '';
        }
        $entityPlural = $pluralize->filter($entity);
        $lcFirstEntity = $lcFirst->filter($entity);
        $lcFirstEntityPlural = $lcFirst->filter($entityPlural);
        $entityPluralDashed = $dashIt->filter($entityPlural);
        $smallCasedDashedPlural = strtolower($entityPluralDashed);
        $fieldsAndValues = $rendered = '';
        $fields = explode(',', $fields);
        foreach ($fields as $field) {
            $fieldAndType = explode(':', $field);
            list($field, $type) = count($fieldAndType) === 2 ? $fieldAndType : array($field, 'string');
            $fieldType = $type === 'text' ? 'textarea' : 'input';
            $fieldsAndValues .= "'{$field}' => 'some {$field}'," . PHP_EOL . "            ";
        }
        $appForm = "Application_Form_{$entity}Form";
        return <<<CONTROLLER
<?php
{$namespace}

class Describe{$entityPlural}Controller extends \\PHPSpec\\Context\\Zend\\Controller
{
    // GET index
    function itAssignsAll{$entityPlural}ToList()
    {
        \$mapper = \$this->stub('Application_Model_{$entity}Mapper');
        \$mapper->shouldReceive('fetchAll')->andReturn(array());
        \$this->inject('Application.Model.{$entity}Mapper', \$mapper);
        
        \$this->get('{$smallCasedDashedPlural}/index');
        \$this->assigns('{$lcFirstEntityPlural}')->should->be(array());
    }
    
    // GET show
    function itAssignsTheRequested{$entity}ToBeShown()
    {
        \${$lcFirstEntity} = \$this->stub('Application_Model_{$entity}');
        \$mapper = \$this->stub('Application_Model_{$entity}Mapper');
        \$mapper->shouldReceive('find')->andReturn(\${$lcFirstEntity});
        \$this->inject('Application.Model.{$entity}Mapper', \$mapper);
        
        \$this->get('{$smallCasedDashedPlural}/show');
        \$this->assigns('{$lcFirstEntity}')->should->be(\${$lcFirstEntity});
    }
    
    // GET edit
    function itPopulatesTheEditFormWithA{$entity}()
    {
        \${$lcFirstEntity}Array = array(
            'id' => 1,
            {$fieldsAndValues}
        );
        \${$lcFirstEntity} = \$this->stub('Application_Model_{$entity}');
        \${$lcFirstEntity}->shouldReceive('toArray')
             ->andReturn(\${$lcFirstEntity}Array);
        
        \$mapper = \$this->stub('Application_Model_{$entity}Mapper');
        \$mapper->shouldReceive('find')->andReturn(\${$lcFirstEntity});
        \$this->inject('Application.Model.{$entity}Mapper', \$mapper);
        
        \$form = \$this->stub('Application_Form_{$entity}Form');
        \$form->shouldReceive('populate')->with(\${$lcFirstEntity}Array);
        \$this->inject('Application.Form.{$entity}Form', \$form);
        \$this->get('{$smallCasedDashedPlural}/edit/id/1');
        
        \$this->assigns('id')->should->be('1');
        \$this->assigns('form')->should->be(\$form);
    }
    
    // GET new
    function itDisplaysThe{$entity}Form()
    {
        \$this->get('{$smallCasedDashedPlural}/new');
        \$this->assigns('form')->should->beAnInstanceOf('{$appForm}');
    }

    // POST add
    function itAddsTheValid{$entity}()
    {
        \$mapper = \$this->stub('Application_Model_{$entity}Mapper');
        \$mapper->shouldReceive('save')->once();
        \$this->inject('Application.Model.{$entity}Mapper', \$mapper);
        
        \$form = \$this->stub('Application_Form_{$entity}Form');
        \$form->shouldReceive('isValid')->andReturn(true);
        \$this->inject('Application.Form.{$entity}Form', \$form);
        
        \$this->post('{$smallCasedDashedPlural}/add', array(
            {$fieldsAndValues}
        ));
    }
    
    // POST update
    function itUpdatesTheValid{$entity}()
    {
        \$mapper = \$this->stub('Application_Model_{$entity}Mapper');
        \$mapper->shouldReceive('save');
        \$this->inject('Application.Model.{$entity}Mapper', \$mapper);
        
        \$form = \$this->stub('Application_Form_{$entity}Form');
        \$form->shouldReceive('isValid')->andReturn(true);
        \$this->inject('Application.Form.{$entity}Form', \$form);
        
        \$this->post('{$smallCasedDashedPlural}/update/id/1', array(
            {$fieldsAndValues}
        ));
    }
    
    // GET delete
    function itDeletesThe{$entity}()
    {
        \$mapper = \$this->stub('Application_Model_{$entity}Mapper');
        \$mapper->shouldReceive('delete');
        \$this->inject('Application.Model.{$entity}Mapper', \$mapper);
        
        \$this->get('{$smallCasedDashedPlural}/delete/id/1');
        \$this->response->should->redirectTo('/{$lcFirstEntityPlural}');
    }
    
    // this is because we are using the registry as container
    // not needed with a proper non-static IoC container
    function after()
    {
        \$this->clearContainer();
    }

}
CONTROLLER;
    }
예제 #15
0
파일: exif.php 프로젝트: ameoba32/tiki
 /**
  * Process raw EXIF data by converting binary or hex information, replacing legend codes with their meanings,
  * fixing labels, etc.
  *
  * @param		array		$exifraw		Array of raw EXIF data
  *
  * @return 		array		$exif			Array of processed EXIF data, including label, newval and suffix values
  * 												for each field
  */
 function processRawData($exifraw)
 {
     $filter = new Zend_Filter_Word_CamelCaseToSeparator();
     //array of tags to match exif array from file
     foreach ($exifraw as $group => $fields) {
         foreach ($fields as $name => $field) {
             if (isset($field)) {
                 //store raw value
                 $exif[$group][$name]['rawval'] = $field;
                 //thumbnail and ifd0 groups share the same specifications
                 $groupmask = $group == 'THUMBNAIL' ? 'IFD0' : $group;
                 //get tag data from $specs array
                 if (isset($this->specs[$groupmask][$name])) {
                     //shorten the variable
                     $specname = $this->specs[$groupmask][$name];
                     //convert binary values
                     if (isset($specname['binary']) && $specname['binary']) {
                         $exif[$group][$name]['rawval'] = bin2hex($exif[$group][$name]['rawval']);
                     }
                     //start processing rawval into newval
                     if (is_array($exif[$group][$name]['rawval'])) {
                         $exif[$group][$name]['newval'] = $this->processArray($exif[$group][$name]['rawval'], $name);
                         //perform division for rational fields, but only if not an array
                     } elseif (isset($specname['format']) && $specname['format'] == 'rational') {
                         $exif[$group][$name]['newval'] = $this->divide($field);
                         //move rest of rawvals into newvals
                     } else {
                         $exif[$group][$name]['newval'] = $exif[$group][$name]['rawval'];
                     }
                     //now determine display values using option values where they exist
                     if (isset($specname['options'])) {
                         //first handle special cases
                         if ($name == 'ComponentsConfiguration') {
                             $str = $exif[$group][$name]['newval'];
                             $opt = $specname['options'];
                             $disp = $opt[substr($str, 0, 2)] . ' ' . $opt[substr($str, 2, 2)] . ' ' . $opt[substr($str, 4, 2)] . ' ' . $opt[substr($str, 6, 2)];
                             $exif[$group][$name]['newval'] = $disp;
                         } elseif ($name == 'CFAPattern') {
                             $str = $exif[$group][$name]['newval'];
                             $opt = $specname['options'];
                             $disp = '[' . $opt[substr($str, 8, 2)] . ', ' . $opt[substr($str, 10, 2)] . '] [' . $opt[substr($str, 12, 2)] . ', ' . $opt[substr($str, 14, 2)] . ']';
                             $exif[$group][$name]['newval'] = $disp;
                         } else {
                             $exif[$group][$name]['newval'] = $specname['options'][$exif[$group][$name]['newval']];
                         }
                     }
                     //fix labels
                     if (isset($specname['label'])) {
                         $exif[$group][$name]['label'] = $specname['label'];
                     } else {
                         //create reading-friendly labels from camel case tags
                         $exif[$group][$name]['label'] = $filter->filter($name);
                     }
                     if (isset($specname['suffix']) && !is_array($exif[$group][$name]['newval'])) {
                         $exif[$group][$name]['suffix'] = $specname['suffix'];
                     }
                 } else {
                     //those not covered in $specs
                     $exif[$group][$name]['newval'] = $exif[$group][$name]['rawval'];
                     //create reading-friendly labels from camel case tags
                     $exif[$group][$name]['label'] = $filter->filter($name);
                 }
             }
         }
     }
     //*******Special Handling*********//
     //file name is computed by PHP and is meaningless when file is stored in tiki,
     //and dialog box has real name in title so not needed
     unset($exif['FILE']['FileName']);
     //file date is also computed by PHP and represents the time the metadata was extracted. This data is included
     //elsewhere and is not needed here
     unset($exif['FILE']['FileDateTime']);
     //No processing of maker notes yet as specific code is needed for each manufacturer
     //Blank out field since it is very long and will distort the dialog box
     if (!empty($exif['EXIF']['MakerNote']['newval'])) {
         $exif['EXIF']['MakerNote']['newval'] = '(Not processed)';
         unset($exif['EXIF']['MakerNote']['rawval']);
     }
     if (isset($exif['MAKERNOTE'])) {
         $exif['MAKERNOTE'] = "";
         $exif['MAKERNOTE']['Note']['label'] = "";
         $exif['MAKERNOTE']['Note']['newval'] = "(Not processed)";
     }
     //Interpret GPSVersion field
     if (isset($exif['GPS']['GPSVersion'])) {
         $exif['GPS']['GPSVersion']['newval'] = '';
         $len = strlen($exif['GPS']['GPSVersion']['rawval']);
         for ($i = 0; $i < $len; $i = $i + 2) {
             if ($i > 0) {
                 $exif['GPS']['GPSVersion']['newval'] .= '.';
             }
             $exif['GPS']['GPSVersion']['newval'] .= (int) substr($exif['GPS']['GPSVersion']['rawval'], $i, 2);
         }
     }
     //PHP already converts UserComment in the Computed group so use that value
     if (isset($exif['EXIF']['UserComment']) && isset($exif['COMPUTED']['UserComment'])) {
         $exif['EXIF']['UserComment']['newval'] = $exif['COMPUTED']['UserComment']['rawval'];
         unset($exif['COMPUTED']['UserComment']);
     }
     //PHP already converts the FNumber in the Computed group so use that value
     if (isset($exif['EXIF']['FNumber']) && isset($exif['COMPUTED']['ApertureFNumber'])) {
         $exif['EXIF']['FNumber']['newval'] = $exif['COMPUTED']['ApertureFNumber']['rawval'];
         unset($exif['COMPUTED']['ApertureFNumber']);
     }
     return $exif;
 }