protected function action() { parent::action(); if (!$this->config instanceof I2CE_MagicDataNode) { $this->reshow(true); //show the parent node. return; } $reshow = false; switch ($this->page()) { case 'upload': I2CE::raiseError("Upload on " . $this->config->getPath(false) . "\n" . print_r($_FILES, true)); if (!array_key_exists('upload', $_FILES) || array_key_exists('error', $_FILES['upload']) && $_FILES['upload']['error'] > 0 || ($upload = file_get_contents($_FILES['upload']['tmp_name'])) === false) { $this->userMessage("Could not upload " . $_FILES['upload']['name']); break; } if (strlen($upload) != $_FILES['upload']['size']) { I2CE::raiseError("Upload size mismatch " . strlen($upload) . ' != ' . $_FILES['upload']['size']); $this->userMessage("Could not upload " . $_FILES['upload']['name']); break; } if ($this->config->is_parent()) { $this->userMessage("Cannot set value on parent node"); break; } $content = $this->config; if ($content->is_parent()) { $this->userMessage("Cannot overwrite content node"); break; } if ($content->hasAttribute('binary') && $content->getAttribute('binary')) { $upload = base64_encode($upload); $content->setValue($upload); $content->setAttribute('encoding', 'base64'); $content->setAttribute('binary', '1'); } else { $content->setValue($upload); } break; case 'upload_binary': I2CE::raiseError("Upload Binary on " . $this->config->getPath(false) . "\n" . print_r($_FILES, true)); if (!array_key_exists('upload', $_FILES) || array_key_exists('error', $_FILES['upload']) && $_FILES['upload']['error'] > 0 || ($upload = file_get_contents($_FILES['upload']['tmp_name'])) === false) { $this->userMessage("Could not upload " . $_FILES['upload']['name']); break; } if (strlen($upload) != $_FILES['upload']['size']) { I2CE::raiseError("Upload size mismatch " . strlen($upload) . ' != ' . $_FILES['upload']['size']); $this->userMessage("Could not upload " . $_FILES['upload']['name']); break; } if ($this->config->is_scalar()) { $this->userMessage("Cannot set value on parent node"); break; } $content = $this->config->traverse('content', true, false); $name = $this->config->traverse('name', true, false); $type = $this->config->traverse('type', true, false); if ($content->is_parent()) { $this->userMessage("Cannot overwrite content node"); break; } if ($name->is_parent()) { $this->userMessage("Cannot overwrite content node"); break; } if ($type->is_parent()) { $this->userMessage("Cannot overwrite type node"); break; } //I2CE::raiseError("Setting " . $this->config->getPath() ); $upload = base64_encode($upload); $content->setValue($upload); $name->setValue($_FILES['upload']['name']); $type->setValue($_FILES['upload']['type']); $content->setAttribute('binary', 1); $content->setAttribute('encoding', 'base64'); break; case 'load': I2CE::raiseError("Begin load:" . print_r($this->request(), true)); $transform = false; if (($transform_key = $this->request('transform_key')) && I2CE_MagicDataNode::checkKey($transform_key) && I2CE::getConfig()->setIfIsSet($transform, "/modules/magicDataBrowser/transforms/" . $this->request('transform_key')) && $transform) { if (substr($transform, 0, 7) == 'file://' && (!($transform_file = I2CE::getFileSearch()->search('XSL', $file_name = substr($transform, 7))) || !($transform = file_get_contents($transform_file)))) { I2CE::raiseError("Could not load {$file_name} for transform"); $this->userMessage("Invalid registered transform"); return false; } } else { if (array_key_exists('transform', $_FILES) && !(array_key_exists('error', $_FILES['transform']) && $_FILES['transform']['error'] > 0)) { $transform = file_get_contents($_FILES['transform']['tmp_name']); } } I2CE::raiseError("Loading with transform:{$transform}"); if ($this->actionLoad($transform)) { $this->userMessage("Data successuly loaded"); } else { $this->userMessage("There was a problem loading the data"); } break; case 'erase': $name = $this->config->getName(); $parent = $this->config->traverse('../'); if ($this->isPost() && $this->config->getPath() != $this->config->traverse('/')->getPath()) { //don't allow an erase of the top level node unset($parent->{$name}); } $reshow = true; break; case 'parent': if ($this->isPost() && $this->config->is_indeterminate()) { $this->config->set_parent(); } break; case 'scalar': if ($this->isPost() && $this->config->is_indeterminate()) { $this->config->set_scalar(); } break; case 'add': if ($this->post_exists('browser_magic_data_add_key')) { $key = $this->post('browser_magic_data_add_key'); if (I2CE_MagicDataNode::checkKey($key) && !$this->config->pathExists($key)) { $this->config->traverse($key, true, false); } } break; case 'add_parent': if ($this->post_exists('browser_magic_data_add_key')) { $key = $this->post('browser_magic_data_add_key'); if (I2CE_MagicDataNode::checkKey($key) && !$this->config->pathExists($key) && ($newNode = $this->config->traverse($key, true, false)) instanceof I2CE_MagicDataNode) { $newNode->set_parent(); } } break; case 'add_scalar': if ($this->post_exists('browser_magic_data_add_key')) { $key = $this->post('browser_magic_data_add_key'); if (I2CE_MagicDataNode::checkKey($key) && !$this->config->pathExists($key) && ($newNode = $this->config->traverse($key, true, false)) instanceof I2CE_MagicDataNode) { $newNode->set_scalar(); } } break; case 'set': I2CE::raiseError("Try to set:0"); if ($this->post_exists('browser_magic_data_value') && $this->post_exists('browser_magic_data_key')) { I2CE::raiseError("Try to set:1"); $key = $this->post('browser_magic_data_key'); $value = $this->post('browser_magic_data_value'); if ($this->config->offsetExists($key) && is_scalar($value)) { I2CE::raiseError("Try to set:2"); if ($this->config->is_translatable($key)) { $locales = I2CE_Locales::getPreferredLocales(); reset($locales); $locale = current($locales); $this->config->setTranslation($locale, $value, $key); if ($locale == I2CE_Locales::DEFAULT_LOCALE) { $this->config->__set($key, $value); } } else { $this->config[$key] = $value; } } } //we redirect so a reload does not post and so that if the page's display depends on the value that is being //set, we redisplay it. break; case 'download': if ($errors = I2CE_Dumper::cleanlyEndOutputBuffers()) { I2CE::raiseError("Errors:\n" . $errors); } $value = $this->config->getValue(); header("Cache-Control: max-age=1, s-maxage=1, no-store, no-cache, must-revalidate"); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 10) . " GMT"); header("ETag: PUB" . time()); header("Pragma: no-cache"); header("Content-length: " . strlen($value)); header('Content-Disposition: attachment; filename="' . $this->config->getName() . '"'); $mime_type = I2CE_MimeTypes::magicMimeType($value); I2CE::raiseError($mime_type); header('Content-type:' . $mime_type); session_cache_limiter("nocache"); echo $value; die; case 'trans': $this->config->setTranslatable(null, !$this->config->is_translatable()); break; case 'show': case 'mini': $this->actionDisplayConfig(); $reshow = null; break; default: break; } if ($reshow !== null) { $this->reshow($reshow); } }
/** * Get the magically determined mime type * @returns string */ public function getMimeType() { if ($this->mime_type === false) { //the mime type was not determined yet $this->mime_type = I2CE_MimeTypes::magicMimeType($this->value); } if (!$this->mime_type) { $this->mime_type = $this->defaultMimeType(); } return $this->mime_type; }