<?php $file_to_up = getenv('TM_FILEPATH'); //Trim to remove the \n, \r $page_id = (int) trim(`xattr -p id "{$file_to_up}"`); $page = array('page' => array('body_html' => file_get_contents($file_to_up))); $payload = Escape::sh(json_encode($page)); $requestUrlTemp = 'https://%1$s:%2$s@%3$s/admin/pages/%4$s.json'; $requestUrl = sprintf($requestUrlTemp, $config->api_key, $config->password, $config->store, $page_id); // $response = `curl --connect-timeout 20 -X PUT -s -g '{$requestUrl}' -H 'Content-Type: application/json' --data-binary {$payload}`; $response = json_decode($response); if (!($page['page']['body_html'] === $response->page->body_html)) { echo 'Error... Try Again'; return; } echo 'Uploaded to ' . $config->store;
/** * requestItem * * Wrapper for the modal select item dialog. * * notes: * * In textmate shared support/ lib/ ui.rb * can write out example of plist * File.open("/Users/mitch/plist.txt", 'w') {|f| f.write(params.to_plist) } * File.open("/Users/mitch/plist2.txt", 'w') {|f| f.write(e_sh params.to_plist) } * * So, next step, to figure out how to generate plist via php. maybe * write custom one? basically, xml, but needs to have things like linebreaks converted. * can maybe pass through TM libs? or can just make a simple template and drop the info in? * tbd - needs some more experimentation * * @requires Escape class * @param array $options Options for the request dialog. title, prompt, items (array), buttons (array) * @return string **/ public function requestItem($options = array()) { $default = array('title' => 'Select an item', 'prompt' => 'Choose well!', 'items' => array(), 'buttons' => array('Ok', 'Cancel')); $options = $options + $default; $plist = $this->plistCreate($options); $plist = Escape::sh($plist); $result = `{$this->dialog} -cmp {$plist} "RequestItem"`; $xml = new SimpleXMLElement($result); //@todo more error checking/buttons $selection = ''; if (property_exists($xml->dict, 'dict')) { $selection = (string) $xml->dict->dict->array->string; } return $selection; }