/**
  * Method launched for the HTTP POST requests
  * 
  * @param  string|null correspond to the URL after /Lan
  * 
  * $instance = new EtherpadLiteClient(Config::get('etherpad-apikey'), Config::get('etherpad-url'));
  * 
  * @throws RestException
  */
 public function post($param = null)
 {
     // Sensure user authentified
     if (!Auth::user()) {
         throw new AuthNotConnectedException();
     }
     $data = RestHandler::getData();
     $padName = "";
     if (isset($data->autogenerate)) {
         // Generate unique random pad name
         $padName = Utilities::generateRandomString(isset($param['padid_length']) ? $param['padid_length'] : 10);
         $custom = true;
     } else {
         if (!isset($data->pad) || !isset($data->pad->pad_name) || $data->pad->pad_name === "") {
             throw new RestException("Unknown call exception", 500);
         } else {
             $padName = $data->pad->pad_name;
         }
     }
     // Ensure pad not already exists
     if (PadComponent::padExists($padName)) {
         throw new PadAlreadyExistsException($padName);
     }
     $cdatas = array('padID' => $padName, 'apikey' => $this->etherpadApiKey, 'text' => Config::get('etherpad-default-text') ? Config::get('etherpad-default-text') : '');
     $result = RestUtilities::callAPI($this->etherpadURLApi . 'createPad', RestMethods::GET, $cdatas);
     //        $result = json_encode(array('code' => 0));
     if ($result) {
         if (isset($result->error)) {
             throw new RestException($result->error);
         } else {
             if ($result->code == 0) {
                 $padConfig = PadConfigComponent::getByUrl($this->etherpadURLPads);
                 $record = array("pad_name" => $padName, "pad_config_id" => $padConfig->id, "creation_date" => date('Y-m-d H:i:s'), "last_update" => date('Y-m-d H:i:s'), "mail_owner" => Auth::user()->email, "status" => 1);
                 if (isset($data->pad->guests)) {
                     $record['guests'] = $data->pad->guests;
                 }
                 $pad = NotesFactory::build(PadComponent::getClass(), $record);
                 $pad->save();
                 $record['url'] = $padName;
                 $userGuests = $this->manageUserGuests($data, $pad);
                 if (count($userGuests['active_emails']) > 0) {
                     // Setting informations
                     $infos = array(array('pad' => array('full_link' => $this->etherpadURLPads . $pad->pad_name, 'pad_name' => $pad->pad_name), 'user' => array('email' => Auth::user()->email)));
                     $this->sendPadInformationsByMail($pad, $userGuests['active_emails'], 'guest_pad', $infos);
                 }
                 if (isset($data->autogenerated)) {
                     // TODO:
                     // Send mail to pad owner
                     // (create new mail template)
                 }
                 return array('data' => array('status' => "success", 'content' => $pad));
             } else {
                 if ($result->code == 1) {
                     // TODO: still in use ?
                     if ($custom) {
                         if (!isset($param['tentative']) || $param['tentative'] < 3) {
                             $opt = array();
                             if (isset($param['tentative'])) {
                                 $opt['tentative'] = $param['tentative'] + 1;
                                 $opt['padid_length'] = isset($param['padid_length']) ? $param['padid_length'] + 1 : 11;
                             } else {
                                 $opt['tentative'] = 1;
                             }
                             $this->post($opt);
                         } else {
                             throw new RestException("Request Time-out", 408);
                         }
                     } else {
                         throw new PadAlreadyExistsException($padName, 409);
                     }
                 } else {
                     throw new PadAlreadyExistsException($padName, 409);
                 }
             }
         }
     } else {
         throw new EtherpadNotFoundException();
     }
 }
Example #2
0
        <body  data-placeholder-focus="false">
            
            <div id='common_popup'></div>
            
                <?php 
    // Header containing all top level elements
    include './pages/menu.php';
    ?>
 
            <main>
                <?php 
    include './pages/banner.php';
    include './pages/subMenu.php';
    // Check if etherpad configuration is found and if etherpad is available
    if (PadConfigComponent::isEtherpadAvailable()) {
        include './pages/sondagesContainer.php';
        include './pages/sondageContent.php';
        include './popup/sondageForm.php';
        include './popup/popups.php';
    } else {
        // Etherpad not found
        include './pages/errors/etherpadNotFound.php';
    }
    ?>
                   
     <!-- Use element -->
     <!--
    <google-map latitude="47.205403" longitude="-1.5631069" zoom="17"></google-map> 
     -->           
            </main>
Example #3
0
<script type="text/javascript" src="./js/lang.js"></script>



<script type="text/javascript" src="./js/main.js"></script>

<!--<script type="text/javascript" src="<?php 
// echo Config::get('site_url') . '/rest.php/Lang';
?>
?callback=lang.setTranslations"></script>-->


<?php 
if (is_dir('./utils/')) {
    foreach (glob('./utils/*.php') as $file) {
        include_once $file;
    }
}
?>


<?php 
$authorized = Auth::isAuthorized() ? 'true' : 'false';
echo '<script type="text/javascript">notes.connected = ' . $authorized . ';</script>';
$etherpadAvailable = PadConfigComponent::isEtherpadAvailable() ? 'true' : 'false';
echo '<script type="text/javascript">notes.etherpad_available = ' . $etherpadAvailable . ';</script>';
?>

<?php 
// Initialize the lang length for translation purpose
echo '<script type="text/javascript">notes.translationSize = ' . Utilities::getDirectorySize(NOTES_BASE . '/language') . ';</script>';