public function getFieldValue($app_id, $external_id) { $items = PodioItem::filter($this->app_id, array('limit' => 59)); $items = $items['items']; for ($i = 0; $i < count($items); $i++) { $itemArray[$i] = $items[$i]->item_id; } for ($j = 0; $j < count($itemArray); $j++) { $item = PodioItem::get($itemArray[$j]); $field = $item->field($external_id); if ($field != null) { $value = $field->humanized_value(); $values[$j] = $value; } } return $values; }
require 'vendor/autoload.php'; require_once 'app_setting.inc.php'; use ZendService\LiveDocx\MailMerge; error_log("validate triggerd"); // Setup client Podio::setup($client_id, $client_secret); // Turn on debugging Podio::$debug = true; // 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');
// loads. The goal to avoid having to re-authenticate each time // a page is refreshed. It is enabled by default. // If you open lib/PodioSession.php you can see how simple the // session manager is. It just has get, set and destroy methods. // You can use the Podio::is_authenticated() method to check if // there is a stored access token already present: Podio::setup(CLIENT_ID, CLIENT_SECRET); if (Podio::is_authenticated()) { // There is already authentication present. We can make API // calls without authenticating again: $item = PodioItem::get(YOUR_ITEM_ID); } else { // No authentication present. We have to authentication // before making API calls: Podio::authenticate('app', array('app_id' => YOUR_APP_ID, 'app_token' => YOUR_APP_TOKEN)); $item = PodioItem::get(YOUR_ITEM_ID); } // The downside of the built-in session manager is that it just // stores the access tokens in the $_SESSION. This means that you // will have to re-authenticate a user each time their close their browser // Often you will want to persist the access tokens for a longer period. // To do so you can implement your own session manager. All you need // is to create a class that implements the same get, set and destroy methods. // Then you can store the access tokens in your database or whereever. // When doing the client setup all you need to pass in the name of your session manager // class as an option and it will be used instead of the built-in one. // For example if your session manager class is called 'MySessionManager' Podio::setup(CLIENT_ID, CLIENT_SECRET, array('session_manager' => 'MySessionManager')); // If the built-in session manager is causing you trouble you can disable it. // This can be useful during development to make sure no stale access tokens are stored. Podio::setup(CLIENT_ID, CLIENT_SECRET, array());
$file = __DIR__ . "/webhook.log"; // authenticate 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;