Example #1
0
function flag_banner_crunch()
{
    global $wpdb;
    // check for correct capability
    if (!is_user_logged_in()) {
        die('-1');
    }
    // check for correct FlAG capability
    if (!current_user_can('FlAG Manage gallery')) {
        die('-1');
    }
    if (isset($_POST['path'])) {
        include_once dirname(__FILE__) . '/functions.php';
        $id = flagAdmin::handle_import_file($_POST['path']);
        $file = basename($_POST['path']);
        if (is_wp_error($id)) {
            echo '<p class="error">' . sprintf(__('<em>%s</em> was <strong>not</strong> imported due to an error: %s', 'flag'), $file, $id->get_error_message()) . '</p>';
        } else {
            echo '<p class="success">' . sprintf(__('<em>%s</em> has been added to Media library', 'flag'), $file) . '</p>';
        }
    }
    exit;
}
Example #2
0
 /**
  * flagAdmin::import_mp3()
  *
  * @class flagAdmin
  * @param string $folder contains relative path
  * @return void
  */
 static function import_mp3($folder)
 {
     $created_msg = '';
     // remove trailing slash at the end, if somebody use it
     $folder = str_replace(array('../', '\'', '"', '<', '>', '$', '%', '='), '', $folder);
     $folder = rtrim($folder, '/');
     $path = WINABSPATH . $folder;
     if (!is_dir($path)) {
         echo '<p class="message">' . __('Directory', 'flag') . ' <strong>' . $path . '</strong> ' . __('doesn&#96;t exist!', 'flag') . ' ' . __('Or imported folder name contains special characters.', 'flag') . '</p>';
         return;
     }
     // read list of files
     $ext = array('mp3');
     $new_filelist = flagAdmin::scandir($path, $ext);
     if (empty($new_filelist)) {
         echo '<p class="message">' . __('Directory', 'flag') . ' <strong>' . $path . '</strong> ' . __('does not contain mp3 files', 'flag') . '</p>';
         return;
     }
     $i = 0;
     foreach ($new_filelist as $key => $file) {
         //$new_filelist[$key] = $path . '/' . $file;
         $filename = $path . '/' . $file;
         $id = flagAdmin::handle_import_file($filename);
         if (is_wp_error($id)) {
             $created_msg .= '<p>' . sprintf(__('<em>%s</em> was <strong>not</strong> imported due to an error: %s', 'flag'), $file, $id->get_error_message()) . '</p>';
         } else {
             $i++;
             $created_msg .= '<p>' . sprintf(__('<em>%s</em> has been added to Media library', 'flag'), $file) . '</p>';
         }
     }
     $created_msg .= '<p class="message">' . $i . __(' file(s) successfully added', 'flag') . '</p><div class="hidden">' . $created_msg . '</div>';
     echo $created_msg;
 }