Ejemplo n.º 1
0
             $no_ext = substr($fs->name, 0, strpos($fs->name, '.'));
             //Upload file to our server
             $fl = PodioFile::get($fs->file_id);
             $fc = $fl->get_raw();
             file_put_contents($upload_path . $fs->name, $fc);
             //Part with convert files from doc(x) to pdf
             $mailMerge = new MailMerge();
             $mailMerge->setUsername($user)->setPassword($password)->setService(MailMerge::SERVICE_FREE);
             $mailMerge->setLocalTemplate($upload_path . $fs->name);
             $mailMerge->assign('software', 'Magic Graphical Compression Suite v1.9');
             $mailMerge->createDocument();
             $document = $mailMerge->retrieveDocument($need_ext);
             file_put_contents($upload_path . $no_ext . $ext_pdf, $document);
             unset($mailMerge);
             // Attached file pdf to our item
             $f = PodioFile::upload($upload_path . $no_ext . $ext_pdf, $no_ext . $ext_pdf);
             $temp_array[] = $f;
             // Removed temp files
             unlink($upload_path . $fs->name);
             unlink($upload_path . $no_ext . $ext_pdf);
         }
     }
     // Create a new collection for files
     $item->files = new PodioCollection($temp_array);
     // Save the item to Podio
     $item->save();
 case 'item.update':
     // Do something. item_id is available in $_POST['item_id']
 // Do something. item_id is available in $_POST['item_id']
 case 'item.delete':
     // Do something. item_id is available in $_POST['item_id']
Ejemplo n.º 2
0
        $string = gmdate('Y-m-d H:i:s') . " item.create webhook received. ";
        $string .= "Post params: " . print_r($_POST, true) . "\n";
        $item_id = (int) $_POST['item_id'];
        // get item
        $item = PodioItem::get($item_id);
        $item_file = $item->files[0];
        $file = PodioFile::get($item_file->file_id);
        $mimetype = $file->mimetype;
        // validate mime and get reader
        $reader_name = $controller->getReaderByMime($mimetype);
        if ($reader_name) {
            file_put_contents(__DIR__ . '/temp/' . $item_file->name, $file->get_raw());
            $file_name_exploded = explode('.', $item_file->name);
            $file_name_no_ext = $file_name_exploded[0];
            $controller->init_pdf_renderer();
            \PhpOffice\PhpWord\Autoloader::register();
            // Creating the new document...
            $phpWord = new \PhpOffice\PhpWord\PhpWord();
            // Read contents
            $source = __DIR__ . '/temp/' . $item_file->name;
            $phpWord = \PhpOffice\PhpWord\IOFactory::load($source, $reader_name);
            //Save pdf file
            $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'PDF');
            $xmlWriter->save(__DIR__ . '/temp/' . $file_name_no_ext . '.pdf');
            $uploadedFile = PodioFile::upload(__DIR__ . '/temp/' . $file_name_no_ext . '.pdf', $file_name_no_ext . '.pdf');
            PodioFile::attach($uploadedFile->file_id, array('ref_type' => 'item', 'ref_id' => $item_id));
        }
        // log request
        file_put_contents($file, $string, FILE_APPEND | LOCK_EX);
        break;
}