/**
  * 
  * Erstellt ein neues Yumpu ePaper
  * @param string $file_to_import
  * @param string $title
  * @param description $description
  * @throws YumpuEpaper_repository_exception
  */
 public static function create($file_to_import, $title, $description = "")
 {
     global $wpdb;
     $table_name = $wpdb->prefix . 'yumpu_documents';
     if (strlen($title) < 5 || strlen($title) > 255) {
         throw new YumpuEpaper_repository_exception("need title - Min. length 5 characters, max. length 255 characters");
     }
     if (!empty($description) && strlen($description) < 5) {
         throw new YumpuEpaper_repository_exception("description to short - Min. length 5 characters, max. length 2500 characters");
     }
     if (!empty($description) && strlen($description) > 2500) {
         throw new YumpuEpaper_repository_exception("description to long - Min. length 5 characters, max. length 2500 characters");
     }
     if (empty($description)) {
         $description = null;
     }
     //Nun übertragen wir die Daten an YUMPU
     $YAPI = new YumpuAPI(WP_Yumpu::$API_TOKEN);
     try {
         $result = $YAPI->document_add($file_to_import, $title, $description);
         $source_filename = basename($file_to_import);
         /**
          * Es hat bisher alles geklappt, daher speichern wir die Daten nun in die Datenbank
          */
         $qry = sprintf('INSERT INTO ' . $table_name . ' (progress_id, title, description, source_filename, status) VALUES (\'%s\', \'%s\', \'%s\', \'%s\', \'%s\')', $result->progress_id, $title, $description, $source_filename, 'progress');
         $wpdb->query($qry);
         return $wpdb->insert_id;
     } catch (YumpuAPI_Exception $e) {
         // Eigentlich nicht so toll Exception aus einem Try/Catch werfen
         // Könnte man besser lösen.
         throw new YumpuEpaper_repository_exception(implode("<br>", $YAPI->get_errors()));
     }
 }
 /**
  * AJAX Handler für Admin Aufrufe.
  */
 public function ajax_handler()
 {
     $run = isset($_REQUEST['run']) ? $_REQUEST['run'] : null;
     switch ($run) {
         /**
          * AJAX Call vom Admin zum prüfen des API-TOKEN
          */
         case 'checkAPI_Token':
             $api_token = $_REQUEST['API_TOKEN'];
             $YAPI = new YumpuAPI($api_token);
             try {
                 $YAPI->check_api_key();
                 /**
                  * Wir speichern den API Token
                  */
                 update_option(self::YUMPU_WP_SETTINGS_KEY, $api_token);
                 /**
                  * Und setzen den API-Token direkt.
                  */
                 WP_Yumpu::$API_TOKEN = $api_token;
                 echo json_encode(array('result' => true));
             } catch (YumpuAPI_Exception $e) {
                 echo json_encode(array('result' => false, 'error' => $YAPI->get_errors()));
             }
             break;
             /**
              * AJAX Call vom Admin zum erstellen eines Accounts
              */
         /**
          * AJAX Call vom Admin zum erstellen eines Accounts
          */
         case 'createAccount':
             $acc_email = $_REQUEST['email'];
             $acc_password = $_REQUEST['password'];
             $acc_username = $_REQUEST['username'];
             $acc_firstname = $_REQUEST['firstname'];
             $acc_lastname = $_REQUEST['lastname'];
             $acc_gender = $_REQUEST['gender'];
             $YAPI = new YumpuAPI(null);
             try {
                 $API_TOKEN = $YAPI->account_create($acc_email, $acc_username, $acc_password, $acc_firstname, $acc_lastname, $acc_gender);
                 echo json_encode(array('result' => true, 'error' => array(), 'API_TOKEN' => $API_TOKEN));
             } catch (YumpuAPI_Exception $e) {
                 echo json_encode(array('result' => false, 'error' => $YAPI->get_errors()));
             }
             break;
             /**
              * AJAX Call from Posts to open pdf editor manager
              */
         /**
          * AJAX Call from Posts to open pdf editor manager
          */
         case 'editorActions':
             $WP_Yumpu_Admin_Editor = new WP_Yumpu_Admin_Editor(WP_Yumpu::$PLUGIN_PATH);
             $WP_Yumpu_Admin_Editor->run();
             break;
     }
     exit;
 }