// Authenticate the app Podio::authenticate('app', array('app_id' => $app_id, 'app_token' => $app_token)); switch ($_POST['type']) { case 'hook.verify': // Validate the webhook PodioHook::validate($_POST['hook_id'], array('code' => $_POST['code'])); case 'item.create': $item = PodioItem::get($_POST['item_id']); $temp_array = array(); foreach ($item->files as $fs) { $temp_array[] = $fs; if ($fs->mimetype == 'application/msword') { //Get file name withour ext $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
Podio::authenticate_with_app($config['app_id'], $config['app_token']); // Big switch statement to handle the different events switch ($_POST['type']) { // Validate the webhook. This is a special case where we verify newly created webhooks. case 'hook.verify': PodioHook::validate($_POST['hook_id'], array('code' => $_POST['code'])); // An item was created // An item was created case 'item.create': $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