Ejemplo n.º 1
0
 /** 
  * Save cloud setting in option table
  */
 public function update()
 {
     $message = new stdClass();
     switch ($_POST['option_page']) {
         case 'dm_cloud_option_group':
             $option_name = 'dm_cloud_option_name';
             if (!empty($_POST['dm_cloud_option_name']['cloud_user_id_number']) && !empty($_POST['dm_cloud_option_name']['cloud_api_key'])) {
                 $userinfo = new DailymotionCloudOwnMethod($_POST['dm_cloud_option_name']['cloud_user_id_number'], $_POST['dm_cloud_option_name']['cloud_api_key']);
                 try {
                     $USerid = $userinfo->getDailymotionCloudUserInfo();
                     if (get_option($option_name) !== false) {
                         update_option($option_name, $_POST['dm_cloud_option_name']);
                     } else {
                         add_option($option_name, $_POST['dm_cloud_option_name']);
                     }
                     $message->success = 'Settings saved successfully.';
                     print json_encode($message);
                     exit;
                 } catch (Exception $e) {
                     $msg = $e->getMessage();
                     $message->error = $msg;
                     print json_encode($message);
                     exit;
                 }
             } else {
                 $message->error = 'Alert: Incorrect UserId or API Key. Please try again.';
                 print json_encode($message);
                 exit;
             }
             break;
         case 'publish_id_option_group':
             $option_name = 'publish_id_option_name';
             if (!empty($_POST['publish_id_option_name']['dm_channel'])) {
                 if (get_option($option_name) !== false) {
                     update_option($option_name, $_POST['publish_id_option_name']);
                 } else {
                     add_option($option_name, $_POST['publish_id_option_name']);
                 }
                 $message->success = 'Settings saved successfully.';
                 print json_encode($message);
                 exit;
             } else {
                 if (empty($_POST['publish_id_option_name']['dm_channel'])) {
                     $message->error = 'Please select a channel.';
                     print json_encode($message);
                     exit;
                 }
             }
             break;
         case 'dailymotion_option_group':
             $option_name = 'dailymotion_option_auth';
             if (!empty($_POST['dailymotion_option_auth']['dailymotion_apikey']) && !empty($_POST['dailymotion_option_auth']['dailymotion_secretkey'])) {
                 if (get_option($option_name) !== false) {
                     update_option($option_name, $_POST['dailymotion_option_auth']);
                 } else {
                     add_option($option_name, $_POST['dailymotion_option_auth']);
                 }
                 $DailymotionOwnMethod = new DailymotionOwnMethod();
                 try {
                     $conecctionresult = $DailymotionOwnMethod->getDailymotionConnectedInformation();
                 } catch (DailymotionAuthRequiredException $e) {
                     $message->success = $DailymotionOwnMethod->getDMAuthorizationUrl('popup');
                     print json_encode($message);
                     exit;
                 } catch (DailymotionAuthRefusedException $e) {
                     $message->error = $e->getMessage();
                     print json_encode($message);
                     exit;
                 }
             } else {
                 if (empty($_POST['dailymotion_option_auth']['dailymotion_apikey'])) {
                     $message->error = 'Please enter your api key.';
                     print json_encode($message);
                     exit;
                 } else {
                     if (empty($_POST['dailymotion_option_auth']['dailymotion_secretkey'])) {
                         $message->error = 'Please enter your secret key.';
                         print json_encode($message);
                         exit;
                     }
                 }
             }
             break;
         default:
             break;
     }
 }