public function testFrom()
 {
     $from = '<p>This is really nice.</p><concrete-picture fID="1" alt="Happy Cat" />';
     // create the default storage location first.
     mkdir($this->getStorageDirectory());
     $this->getStorageLocation();
     $fi = new \Concrete\Core\File\Importer();
     $file = dirname(__FILE__) . '/fixtures/background-slider-blue-sky.png';
     $r = $fi->import($file, 'background-slider-blue-sky.png');
     $path = $r->getRelativePath();
     $translated = \Concrete\Core\Editor\LinkAbstractor::translateFrom($from);
     $to = '<p>This is really nice.</p><img src="' . $path . '" alt="Happy Cat" width="48" height="20">';
     $this->assertEquals('background-slider-blue-sky.png', $r->getFilename());
     $this->assertEquals($to, $translated);
     $c = new \Concrete\Block\Content\Controller();
     $c->content = $from;
     $sx = new SimpleXMLElement('<test />');
     $c->export($sx);
     $content = (string) $sx->data->record->content;
     $this->assertEquals('<p>This is really nice.</p><concrete-picture alt="Happy Cat" file="background-slider-blue-sky.png" />', $content);
 }
Beispiel #2
0
 public function action_document_submit($bID = false)
 {
     if ($this->bID != $bID) {
         return false;
     }
     //print_r( $_FILES );
     //		exit;
     $this->view();
     //$this->set('action', $this->post() );
     if ($this->CheckCase(intval($this->post('CaseID'))) == false) {
         return;
     }
     $error = \Concrete\Core\File\Importer::E_PHP_FILE_ERROR_DEFAULT;
     if (isset($_FILES['document']) && is_uploaded_file($_FILES['document']['tmp_name'])) {
         $file = $_FILES['document']['tmp_name'];
         $filename = $_FILES['document']['name'];
         $importer = new \Concrete\Core\File\Importer();
         $result = $importer->import($file, $filename);
         if ($result instanceof \Concrete\Core\File\Version) {
             //TODO::WARNING!!!
             //потенциальная опастность!
             //пользователь может подделать CaseID и добавить документ к другому делу
             $db = Loader::db();
             $ql = "INSERT INTO `CaseDocuments` ( bID, CaseID, DocumentOwnerID, DocumentID, DocumentDescription, DocumentURL, DocumentDate ) VALUES ( ?, ?, ?, ?, ?, ?, ? )";
             $val = array(intval($bID), intval($this->post('CaseID')), $result->getAuthorUserID(), $result->getFileID(), $this->post('Description'), $result->getURL(), $result->getDateAdded());
             $db->query($ql, $val);
             $this->redirect('/');
         } else {
             $error = $result;
         }
     } else {
         if (isset($_FILES['document'])) {
             $error = $_FILES['document']['error'];
         }
     }
     $this->set('errorMessage', \Concrete\Core\File\Importer::getErrorMessage($error));
 }
    public function testReplacedContent()
    {
        // create the default storage location first.
        mkdir($this->getStorageDirectory());
        $this->getStorageLocation();
        $importer = new Concrete\Core\File\Importer();
        $prefix = $importer->generatePrefix();
        Concrete\Core\File\File::add('test.jpg', $prefix);
        $content = <<<EOL
        <p><concrete-picture alt="Lorem ipsum" file="test.jpg">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
        <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip <concrete-picture file="test.jpg" alt="ex ea commodo consequat." width="200" height="100" style="border: 1px solid black;" /></p>
EOL;
        $expected = <<<EOL
        <p><concrete-picture fID="1" />Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
        <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip <concrete-picture fID="1" /></p>
EOL;
        $inspector = Core::make('import/value_inspector');
        $result = $inspector->inspect($content);
        $this->assertEquals($expected, $result->getReplacedContent());
    }