function sssc_fileaway($atts) { extract(shortcode_atts(array('type' => '', 'base' => '', 'sub' => '', 'name' => '', 'paginate' => '', 'pagesize' => '', 'search' => '', 'customdata' => '', 'sortfirst' => '', 's2skipconfirm' => '', 'mod' => '', 'size' => '', 'nolinks' => '', 'debug' => '', 'recursive' => '', 'directories' => '', 'manager' => '', 'password' => '', 'role_override' => '', 'user_override' => '', 'dirman_access' => '', 'drawericon' => '', 'drawerlabel' => '', 'playback' => false, 'playbackpath' => false, 'playbacklabel' => 'Type', 'onlyaudio' => '', 'loopaudio' => 'false', 'bulkdownload' => false, 'images' => '', 'code' => '', 'exclude' => '', 'include' => '', 'only' => '', 'excludedirs' => false, 'onlydirs' => false, 'showto' => '', 'hidefrom' => '', 'style' => '', 'width' => '', 'perpx' => '', 'align' => '', 'textalign' => '', 'heading' => '', 'hcolor' => '', 'color' => '', 'accent' => '', 'iconcolor' => '', 'corners' => '', 'display' => '', 'icons' => '', 'thumbnails' => false, 'maxsrcbytes' => '1887436.8', 'maxsrcheight' => '2500', 'maxsrcwidth' => '3000', 'thumbstyle' => 'widerounded', 'graythumbs' => false), $atts)); global $ssfa_abspath, $ssfa_install; $thefiles = null; $included = null; $excluded = null; $rawnames = null; $iconstyle = null; $icocol = null; $path = null; $ssh = null; $sh = null; $td = null; $bb = null; $fafl = null; $faui = null; $faun = null; $faur = null; $direxcluded = 0; $current_user = wp_get_current_user(); $logged_in = is_user_logged_in(); $showtothese = true; $getthumb = false; $type = $playback ? "table" : $type; $playback = !$playback ? false : ($playback === 'extended' ? 'extended' : 'compact'); $color = $type === "table" && !$color ? "classic" : ($type === "table" && $color === "random" ? false : $color); $iconcolor = $type === "table" && !$iconcolor ? "classic" : ($type === "table" && $iconcolor === "random" ? false : $iconcolor); if ($hidefrom) { if (!$logged_in) { $showtothese = false; } $hidelevels = preg_split('/(, |,)/', $hidefrom); foreach ($hidelevels as $hlevel) { if (current_user_can($hlevel)) { $showtothese = false; } } } if ($showto) { $showtothese = false; $showlevels = preg_split('/(, |,)/', $showto); foreach ($showlevels as $slevel) { if (current_user_can($slevel)) { $showtothese = true; } } } if ($showtothese == false) { return; } $siteaddress = rtrim(get_bloginfo('url'), '/'); $wpaddress = rtrim(get_bloginfo('wpurl'), '/'); if ($siteaddress !== '' && $siteaddress !== null && $siteaddress !== $wpaddress) { $url = $siteaddress; } else { $url = get_site_url(); } $nietzsche = ssfa_hungary_v_denmark(); $fa_userid = $logged_in ? get_current_user_id() : 'fa-nulldirectory'; $fa_username = $logged_in ? strtolower($current_user->user_login) : 'fa-nulldirectory'; $fa_firstlast = $logged_in ? strtolower($current_user->user_firstname . $current_user->user_lastname) : 'fa-nulldirectory'; $fa_userrole = $logged_in ? strtolower(ssfa_currentrole()) : 'fa-nulldirectory'; $uid = rand(0, 9999); $randcolor = array("red", "green", "blue", "brown", "black", "orange", "silver", "purple", "pink"); $tz = get_option('timezone_string'); $timezone = $tz === '' ? 'UTC' : $tz; if (SSFA_JAVASCRIPT === 'footer') { $GLOBALS['ssfa_add_scripts'] = true; } if (SSFA_STYLESHEET === 'footer') { $GLOBALS['ssfa_add_styles'] = true; } $s2mem = $base === 's2member-files' && $GLOBALS['ssfa_s2member'] ? true : false; $base = $base === '1' ? SSFA_BASE1 : ($base === '2' ? SSFA_BASE2 : ($base === '3' ? SSFA_BASE3 : ($base === '4' ? SSFA_BASE4 : ($base === '5' ? SSFA_BASE5 : ($s2mem ? 'wp-content/plugins/s2member-files/' : SSFA_BASE1))))); $base = trim($base, '/'); $base = trim($base, '/'); if ($s2mem) { $sub = false; $directories = false; $recursive = false; $manager = false; $s2skip = $s2skipconfirm === 'yes' ? '&s2member_skip_confirmation' : ''; } $sub = $sub ? trim($sub, '/') : false; $dir = $sub ? $base . '/' . $sub : $base; include SSFA_INCLUDES . 'private-content.php'; $dir = str_replace('//', '/', "{$dir}"); $dir = SSFA_ROOT === 'siteurl' ? $dir : ($ssfa_install ? $ssfa_install . $dir : $dir); if ($private_content == true && !is_dir("{$dir}")) { return null; } $name = $name ? $name : "ssfa-meta-container-{$uid}"; $thefiles .= "<div id='{$name}' class='ssfa-meta-container'>"; $manager = $playback ? false : $manager; if ($manager) { include SSFA_INCLUDES . 'manager-access.php'; } if ($manager) { $type = 'table'; $directories = 1; $bulkdownload = false; } $bulkclass = $bulkdownload ? 'bd-table' : ($manager ? 'mngr-table' : null); $start = "{$dir}"; if ($type !== 'table') { $bulkdownload = false; } if ($directories) { include SSFA_INCLUDES . 'directory-tree-navigation.php'; } include SSFA_INCLUDES . 'shortcode-options.php'; if ($type === 'table') { if ($directories) { $sortfirst = 'filename'; } $typesort = null; $filenamesort = null; $customsort = null; $modsort = null; $sizesort = null; if ($sortfirst === 'type') { $typesort = " data-sort-initial='true'"; } elseif ($sortfirst === 'type-desc') { $typesort = " data-sort-initial='descending'"; } elseif ($sortfirst === 'filename') { $filenamesort = " data-sort-initial='true'"; } elseif ($sortfirst === 'filename-desc') { $filenamesort = " data-sort-initial='descending'"; } elseif ($sortfirst === 'custom') { $customsort = " data-sort-initial='true'"; } elseif ($sortfirst === 'custom-desc') { $customsort = " data-sort-initial='descending'"; } elseif ($sortfirst === 'mod') { $modsort = " data-sort-initial='true'"; } elseif ($sortfirst === 'mod-desc') { $modsort = " data-sort-initial='descending'"; } elseif ($sortfirst === 'size') { $sizesort = " data-sort-initial='true'"; } elseif ($sortfirst === 'size-desc') { $sizesort = " data-sort-initial='descending'"; } else { $filenamesort = " data-sort-initial='true' "; } if ($directories) { $filename = $drawerlabel ? $drawerlabel : "File/Drawer"; } else { $filename = "File Name"; } if ($manager) { $path = '<input type="hidden" id="ssfa-nomenclature" value="" />'; $ss = explode('/', $start); $ss = end($ss); $ssh = '<input type="hidden" id="ssfa-whymenclature" data-path="' . $ss . '" value="' . $ss . '" />'; $sh = '<input type="hidden" id="ssfa-yesmenclature" data-path="' . $start . '" value="' . $start . '" />'; $td = '<input type="hidden" id="ssfa-bad-motivator" data-path="' . trim("{$dir}", '/') . '" value="' . trim("{$dir}", '/') . '" />'; $bb = '<input type="hidden" id="ssfa-smooth-operator" data-path="' . $basebase . '" value="' . $basebase . '" />'; if ($private_content) { $fafl = null; if ($fa_firstlast_used) { $fafl = "<input type='hidden' id='ssfa-fafl' value=\"{$fa_firstlast}\" />"; } $faui = null; if ($fa_userid_used) { $faui = "<input type='hidden' id='ssfa-faui' value=\"{$fa_userid}\" />"; } $faun = null; if ($fa_username_used) { $faun = "<input type='hidden' id='ssfa-faun' value=\"{$fa_username}\" />"; } $faur = null; if ($fa_userrole_used) { $faur = "<input type='hidden' id='ssfa-faur' value=\"{$fa_userrole}\" />"; } } } $typelabel = $playback ? $playbacklabel : "Type"; $typesorter = $playback ? "data-sort-ignore='true'" : "title='Click to Sort' {$typesort}"; $drawericon = $drawericon ? $drawericon : 'drawer'; $data_atts = $manager ? "data-uid='" . $uid . "' data-pg='" . $GLOBALS['post']->ID . "' data-drw=\"{$drawericon}\" data-cls=\"{$style}\"" : null; $thefiles .= "<script type='text/javascript'>jQuery(function(){ jQuery('.footable').footable();});</script>{$searchfield2}" . "<table id='ssfa-table' data-filter='#filter-{$uid}' {$page} class='footable ssfa-sortable {$style} {$textalign} {$bulkclass}' {$data_atts}><thead><tr>" . "<th class='ssfa-sorttype {$style}-first-column' {$typesorter}>" . $typelabel . "</th>" . "<th class='ssfa-sortname' title='Click to Sort'" . $filenamesort . ">{$filename}{$path}{$ssh}{$sh}{$td}{$bb}{$fafl}{$faui}{$faun}{$faur}</th>"; $cells = null; if ($mod !== 'no') { $cells .= '1,'; } if ($size !== 'no') { $cells .= '1,'; } if ($manager) { $cells .= '1,'; } if ($customdata) { $custom_sort = true; $customarray = explode(',', $customdata); foreach ($customarray as $customdatum) { if (preg_match('/[*]/', $customdatum)) { $custom_sort = false; } } foreach ($customarray as $customdatum) { if ($customdatum !== '') { $cells .= '1,'; if (preg_match('/[*]/', $customdatum)) { $customdatum = str_replace('*', '', $customdatum); $custom_sort = true; } if ($custom_sort == true) { $custom_sort = $customsort; } $customdatum = trim($customdatum, ' '); $thefiles .= "<th class='ssfa-sortcustomdata' title='Click to Sort'" . $custom_sort . ">{$customdatum}</th>"; } } } $cells = rtrim($cells, ','); $thefiles .= $mod !== 'no' ? "<th class='ssfa-sortdate' data-type='numeric' title='Click to Sort'" . $modsort . ">Date Modified</th>" : null; $thefiles .= $size !== 'no' ? "<th class='ssfa-sortsize' data-type='numeric' title='Click to Sort'" . $sizesort . ">Size</th>" : null; if ($manager) { $thefiles .= $size !== 'no' ? "<th style='width:90px!important;' class='ssfa-manager' data-sort-ignore='true'>Manage</th>" : null; } $thefiles .= "</tr></thead><tfoot><tr><td colspan='100'>{$pagearea}</td></tr></tfoot><tbody>"; } if ($recursive || $directories) { $globaldirexes = array(); $localdirexes = array(); if ($excludedirs) { $localdirexes = preg_split('/(, |,)/', $excludedirs); } if (SSFA_DIR_EXCLUSIONS) { $globaldirexes = preg_split('/(, |,)/', SSFA_DIR_EXCLUSIONS); } $direxes = array_unique(array_merge($localdirexes, $globaldirexes)); $excludedirs = count($direxes) > 0 ? $direxes : false; $justthesedirs = $onlydirs ? preg_split('/(, |,)/', $onlydirs) : 0; $onlydirs = count($justthesedirs) > 0 ? $justthesedirs : 0; } if ($directories) { $thecells = explode(',', $cells); $ccell = count($thecells); if ($manager && $dirman) { $thefiles .= "<tr id='row-ssfa-create-dir-{$uid}' class='ssfa-drawers'>" . "<td id='folder-ssfa-create-dir-{$uid}' data-value='0' class='ssfa-sorttype {$style}-first-column'>" . "<a id='ssfa-create-dir-{$uid}' href='javascript:'>" . "<span style='font-size:20px; margin-left:3px;' class='ssfa-icon-chart-alt' aria-hidden='true'></span>" . "<br>new" . "</a>" . "</td>" . "<td id='name-ssfa-create-dir-{$uid}' data-value='0' class='ssfa-sortname'>" . '<input id="input-ssfa-create-dir-' . $uid . '" type="text" placeholder="Name Your Sub-Directory" " value="" ' . 'style="width:90%; height:26px; font-size:12px; text-align:center; display:none">' . "</td>"; $icell = 0; foreach ($thecells as $cell) { $icell++; if ($icell < $ccell) { $thefiles .= "<td class='{$style}'> </td>"; } else { $thefiles .= "<td id='manager-ssfa-create-dir-{$uid}' class='{$style}'> </td>"; } } } $checksubdirs = array_filter(glob("{$dir}" . "/*"), 'is_dir'); if (count($checksubdirs) > 0) { $f = 0; foreach (glob("{$dir}" . "/*", GLOB_ONLYDIR) as $k => $folder) { if ($onlydirs) { $direxcluded = 1; foreach ($onlydirs as $onlydir) { if (strripos("{$folder}", "{$onlydir}") !== false) { $direxcluded = 0; continue; } } } if ($excludedirs) { foreach ($excludedirs as $exclude) { if (strripos("{$folder}", "{$exclude}") !== false) { continue 2; } } } if (!$direxcluded) { $f++; $dlink = ssfa_replace_first("{$basebase}", '', "{$folder}"); $folder = str_replace("{$dir}" . '/', '', "{$folder}"); $prettyfolder = str_replace(array('~', '--', '_', '.', '*'), ' ', "{$folder}"); $prettyfolder = preg_replace('/(?<=\\D)-(?=\\D)/', ' ', "{$prettyfolder}"); $prettyfolder = preg_replace('/(?<=\\D)-(?=\\d)/', ' ', "{$prettyfolder}"); $prettyfolder = preg_replace('/(?<=\\d)-(?=\\D)/', ' ', "{$prettyfolder}"); $prettyfolder = ssfa_strtotitle($prettyfolder); $dpath = ltrim("{$dlink}", '/'); $dlink = str_replace('/', '*', "{$dpath}"); $managedir = $manager && $dirman ? "<a href='' id='rename-ssfa-dir-{$uid}-{$f}'>Rename</a><br><a href='' id='delete-ssfa-dir-{$uid}-{$f}'>Delete</a></td>" : ' '; $renamedir = $manager && $dirman ? '<input id="rename-ssfa-dir-' . $uid . '-' . $f . '" type="text" value="' . $folder . '" ' . 'style="width:90%; height:26px; font-size:12px; text-align:center; display:none">' : null; $thefiles .= "<tr id='ssfa-dir-{$uid}-{$f}' class='ssfa-drawers'>" . "<td id='folder-ssfa-dir-{$uid}-{$f}' data-value='00-{$folder}' class='ssfa-sorttype {$style}-first-column'>" . "<a href=\"" . add_query_arg(array('drawer' => $dlink), get_permalink()) . "\" data-name=\"" . $folder . "\" data-path=\"" . $dpath . "\">" . "<span style='font-size:20px; margin-left:3px;' class='ssfa-icon-{$drawericon}' aria-hidden='true'></span>" . "<br>dir" . "</a>" . "</td>" . "<td id='name-ssfa-dir-{$uid}-{$f}' data-value='00-{$folder}' class='ssfa-sortname'>" . "<a href=\"" . add_query_arg(array('drawer' => $dlink), get_permalink()) . "\">" . "<span style='text-transform:uppercase;'>{$prettyfolder}</span>" . "</a>" . $renamedir . "</td>"; $icell = 0; foreach ($thecells as $cell) { $icell++; if ($icell < $ccell) { $thefiles .= "<td class='{$style}'> </td>"; } else { $thefiles .= "<td id='manager-ssfa-dir-{$uid}-{$f}' class='{$style}'>{$managedir}</td>"; } } $thefiles .= "</tr>"; } } } } if ($directories) { $recursive = 0; } $files = $recursive ? ssfa_recursive_files($dir, $onlydirs, $excludedirs) : scandir($dir); date_default_timezone_set($timezone); natcasesort($files); $count = 0; $original_dir = $dir; if (is_array($files)) { foreach ($files as $file) { $link = $recursive ? "{$url}/{$file}" : "{$url}/{$dir}/{$file}"; $slices = pathinfo($link); $extension = isset($slices['extension']) ? $slices['extension'] : false; include SSFA_INCLUDES . 'includes-excludes.php'; if ($excluded == false) { $exts[] = $extension; $locs[] = $slices['dirname']; $fulls[] = $slices['basename']; $rawnames[] = $slices['filename']; $links[] = $recursive ? "{$url}/{$file}" : "{$url}/{$dir}/{$file}"; $dirs[] = $recursive ? str_replace($slices['basename'], '', $file) : $dir; } } } $fcount = count($rawnames); if ($fcount < 1) { if ($debug === 'on' && $logged_in) { include SSFA_INCLUDES . 'file-away-debug.php'; return ssfa_debug($url, $original_dir); } elseif ($fcount < 1 && !$directories) { return; } } if ($playback) { $GLOBALS['ssfa_playback_script'] = true; $used = array(); $sources = $GLOBALS['ssfa_audio']; } $thumbnails = $thumbnails && $type === 'table' && extension_loaded('gd') && function_exists('gd_info') ? $thumbnails : false; if ($thumbnails) { $graythumbs = $graythumbs ? ' ssfa-thumb-bw' : ''; $thumbstyles = array('widerounded', 'widesharp', 'squarerounded', 'squaresharp', 'oval', 'circle'); $thumbstyle = in_array($thumbstyle, $thumbstyles) ? $thumbstyle : 'widerounded'; $thumbwidth = in_array($thumbstyle, array('widerounded', 'widesharp', 'oval')) ? 60 : 40; $thumbheight = 40; $thumbfix = $thumbwidth == 60 ? 'wd_' : 'sq_'; if ($thumbnails !== 'permanent') { $maxsrcbytes = preg_replace('/[^\\d.]+/', '', $maxsrcbytes); $maxsrcwidth = preg_replace('/[^\\d.]+/', '', $maxsrcwidth); $maxsrcheight = preg_replace('/[^\\d.]+/', '', $maxsrcheight); } } if (is_array($rawnames)) { asort($rawnames); foreach ($rawnames as $k => $rawname) { if ($playback && in_array($rawname, $used) && in_array($exts[$k], $sources)) { continue; } $link = $links[$k]; $loc = $locs[$k]; $ext = $exts[$k]; $oext = $ext; $extension = strtolower($ext); $full = $fulls[$k]; $dir = $dirs[$k]; $file = $full; if ($onlydirs) { foreach ($onlydirs as $only) { $keeper = 0; if (strpos("{$dir}", "{$only}") !== false) { $keeper = 1; break; } } if (!$keeper) { continue; } } if ($excludedirs) { foreach ($excludedirs as $ex) { if (strpos("{$dir}", "{$ex}") !== false) { continue 2; } } } if (preg_match('/\\[([^\\]]+)\\]/', $rawname)) { $file_plus_custom = $rawname; list($salvaged_filename, $customvalue) = preg_split("/[\\[\\]]/", $file_plus_custom); $customvalue = str_replace(array('~', '--', '_', '.', '*'), ' ', $customvalue); $customvalue = preg_replace('/(?<=\\D)-(?=\\D)/', ' ', "{$customvalue}"); $customvalue = preg_replace('/(?<=\\d)-(?=\\D)/', ' ', "{$customvalue}"); $customvalue = preg_replace('/(?<=\\D)-(?=\\d)/', ' ', "{$customvalue}"); $thename = str_replace(array('~', '--', '_', '.', '*'), ' ', $salvaged_filename); } else { $file_plus_custom = null; $customvalue = null; $thename = str_replace(array('~', '--', '_', '.', '*'), ' ', $rawname); $salvaged_filename = $rawname; } $thename = preg_replace('/(?<=\\D)-(?=\\D)/', ' ', "{$thename}"); $thename = preg_replace('/(?<=\\d)-(?=\\D)/', ' ', "{$thename}"); $thename = preg_replace('/(?<=\\D)-(?=\\d)/', ' ', "{$thename}"); $ext = !$ext ? '?' : $ext; $ext = substr($ext, 0, 4); $bytes = filesize($dir . '/' . $file); $sortdatekey = date("YmdHis", filemtime($dir . '/' . $file)); $sortdate = SSFA_DAYMONTH === 'dm' ? date("g:i A d/m/Y", filemtime($dir . '/' . $file)) : date("g:i A m/d/Y", filemtime($dir . '/' . $file)); $date = date("F d, Y", filemtime($dir . '/' . $file)); $time = date("g:i A", filemtime($dir . '/' . $file)); if (is_file($dir . '/' . $file) && $thename !== '') { if ($size !== 'no') { $fsize = ssfa_formatBytes($bytes, 1); $fsize = !preg_match('/[a-z]/i', $fsize) ? '1k' : ($fsize === 'NAN' ? '0' : $fsize); } if ($thumbnails) { $getthumb = in_array($extension, array('jpg', 'jpeg', 'gif', 'png')) ? true : false; } if ($manager && $thumbnails && stripos($file, '_thumb_') !== false) { $getthumb = false; } if ($getthumb) { $srcpath = SSFA_ROOT === 'siteurl' ? stripslashes($dir) : ($ssfa_install ? ssfa_replace_first($ssfa_install, '', stripslashes($dir)) : stripslashes($dir)); if ($thumbnails !== "permanent") { $imgprop = getimagesize($ssfa_abspath . $srcpath . '/' . $file); while ($getthumb) { if (isset($imgprop[0]) && $maxsrcwidth && $imgprop[0] > $maxsrcwidth) { $getthumb = false; break; } if (isset($imgprop[1]) && $maxsrcheight && $imgprop[1] > $maxsrcheight) { $getthumb = false; break; } if ($maxsrcbytes && $bytes > $maxsrcbytes) { $getthumb = false; break; } break; } } elseif ($thumbnails === 'permanent') { if (!is_file($ssfa_abspath . $srcpath . '/_thumb_' . $thumbfix . $file)) { ssfa_createthumb($ssfa_abspath . $srcpath . '/' . $file, $ssfa_abspath . $srcpath . '/_thumb_' . $thumbfix . $file, $extension, $thumbwidth, $thumbheight); } $thumblink = is_file($ssfa_abspath . $srcpath . '/_thumb_' . $thumbfix . $file) ? str_replace($file, '_thumb_' . $thumbfix . $file, $link) : false; } } if ($iconcolor) { $icocol = " ssfa-{$iconcolor}"; } if ($color && !$accent) { $accent = $color; $colors = " ssfa-{$color} accent-{$accent}"; } if ($color && $accent) { $colors = " ssfa-{$color} accent-{$accent}"; } if ($color && !$iconcolor) { $useIconColor = $randcolor[array_rand($randcolor)]; $icocol = " ssfa-{$useIconColor}"; } if (!$color && $iconcolor) { $useColor = $randcolor[array_rand($randcolor)]; $colors = " ssfa-{$useColor} accent-{$useColor}"; } if (!$color && !$iconcolor) { $useColor = $randcolor[array_rand($randcolor)]; $colors = " ssfa-{$useColor} accent-{$useColor}"; $icocol = " ssfa-{$useColor}"; } $datemodified = $type !== 'table' && $mod === 'yes' ? "<div class='ssfa-datemodified'>Last modified {$date} at {$time}</div>" : null; $listfilesize = $type !== 'table' && $size !== 'no' ? $style === 'ssfa-minimal-list' ? "<span class='ssfa-listfilesize'>({$fsize})</span>" : "<span class='ssfa-listfilesize'>{$fsize}</span>" : null; $audiocorrect = $playback === 'extended' ? "style='margin-right:10px;'" : ($playback ? "style='display:block; margin-bottom:5px;'" : null); $thename = "<span class='ssfa-filename' {$audiocorrect}>" . ssfa_strtotitle($thename) . "</span>"; $link = $s2mem ? $url . '/?s2member_file_download=' . $file . $s2skip : $link; $fulllink = 'href="' . $link . '"'; include SSFA_INCLUDES . 'file-type-icons.php'; $linktype = $s2mem ? '' : $linktype; if ($playback) { $skipthis = 0; include SSFA_INCLUDES . 'playback.php'; if ($skipthis) { continue; } } else { $player = null; $players = null; } $count += 1; if ($nolinks === 'yes' || $nolinks === 'true') { $nolinkslist = "<a id='ssfa' class='{$display}{$noicons}{$colors}' style='cursor:default'>"; $nolinkstable = "<a id='ssfa' class='{$colors}' style='cursor:default'>"; } else { $nolinkslist = "<a id='ssfa' class='{$display}{$noicons}{$colors}' {$fulllink} {$linktype}>"; $nolinkstable = "<a id='ssfa' class='{$colors}' {$fulllink} {$linktype}>"; } if (!$type || $type !== 'table') { $thefiles .= "{$nolinkslist}<div class='ssfa-listitem {$ellipsis}'><span class='ssfa-topline'>{$icon} {$thename} {$listfilesize}</span> {$datemodified}</div></a>"; } elseif ($type === 'table') { $oext = $manager || $bulkdownload ? $oext : null; $filepath = $manager || $bulkdownload ? '<input id="filepath-ssfa-file-' . $uid . '-' . $count . '" type="hidden" value="' . $dir . '" />' : null; $oldname = $manager || $bulkdownload ? '<input id="oldname-ssfa-file-' . $uid . '-' . $count . '" type="hidden" value="' . $rawname . '" />' : null; $salvaged_filename = $manager ? trim($salvaged_filename, ' ') : $salvaged_filename; if ($manager && $customdata) { $fileinput = '<input id="rawname-ssfa-file-' . $uid . '-' . $count . '" type="text" value="' . $salvaged_filename . '" ' . 'style="width:80%; height:26px; font-size:12px; text-align:center; display:none">'; } elseif ($manager && !$customdata) { $fileinput = '<input id="rawname-ssfa-file-' . $uid . '-' . $count . '" type="text" value="' . $rawname . '" ' . 'style="width:80%; height:26px; font-size:12px; text-align:center; display:none">'; } else { $fileinput = null; } if ($playback && in_array($rawname, $used)) { if ($has_sample && $playback === 'compact') { $iconarea = $player; $thefinalname = $thename; } elseif ($has_sample && $playback === 'extended') { $iconarea = "<br>{$nolinkstable}{$icon}</a>"; $thefinalname = $thename . $players . $player; $players = null; } elseif (!$has_sample && $has_multiple) { $thefinalname = $thename; $iconarea = "<br>{$nolinkstable}{$icon}</a>"; } elseif (!$has_sample && !$has_multiple) { $iconarea = "{$nolinkstable}{$icon} {$ext}</a>"; $thefinalname = "{$nolinkstable}{$thename}</a>"; $players = null; } } else { $iconarea = "{$nolinkstable}{$icon} {$ext}</a>"; $thefinalname = "{$nolinkstable}{$thename}</a>"; $players = null; } if ($getthumb) { $iconarea = "{$nolinkstable}{$icon}</a>"; } $thefiles .= "<tr id='ssfa-file-{$uid}-{$count}' class=''>" . "<td id='filetype-ssfa-file-{$uid}-{$count}' class='ssfa-sorttype {$style}-first-column'>{$iconarea}<input type='hidden' value='{$oext}' /></td>" . "<td id='filename-ssfa-file-{$uid}-{$count}' class='ssfa-sortname'>{$thefinalname}{$players} {$fileinput}{$filepath}{$oldname}</td>"; if ($customdata) { $customvalues = explode(',', $customvalue); foreach ($customarray as $k => $customdatum) { if ($customdatum !== null) { $value = ssfa_strtotitle(trim($customvalues[$k], ' ')); $custominput[$k] = $manager ? '<input id="customdata-' . $k . '-ssfa-file-' . $uid . '-' . $count . '" type="text" value="' . $value . '" ' . 'style="width:80%; height:26px; font-size:12px; text-align:center; display:none">' : null; $thefiles .= "<td id='customadata-cell-{$k}-ssfa-file-{$uid}-{$count}' class='ssfa-sortcustomdata'>" . "<span id='customadata-{$k}-ssfa-file-{$uid}-{$count}'>" . "{$value}" . "</span>" . $custominput[$k] . "</td>"; } } } $thefiles .= $mod !== 'no' ? "<td id='mod-ssfa-file-{$uid}-{$count}' class='ssfa-sortdate' data-value='{$sortdatekey}'>{$sortdate}</td>" : null; $thefiles .= $size !== 'no' ? "<td id='size-ssfa-file-{$uid}-{$count}' class='ssfa-sortsize' data-value='{$bytes}'>{$fsize}</td>" : null; $thefiles .= $manager ? "<td id='manager-ssfa-file-{$uid}-{$count}' class='ssfa-sortmanager'><a href='' id='rename-ssfa-file-{$uid}-{$count}'>Rename</a><br>" . "<a href='' id='delete-ssfa-file-{$uid}-{$count}'>Delete</a></td>" : null; $thefiles .= '</tr>'; } } } } $thefiles .= $type === 'table' ? '</tbody></table>' : null; if ($manager) { include SSFA_INCLUDES . 'bulk-action-content.php'; } if ($bulkdownload) { include SSFA_INCLUDES . 'bulk-download-content.php'; } $thefiles .= "</div></div>"; if ($debug === 'on' && $logged_in) { include SSFA_INCLUDES . 'file-away-debug.php'; return ssfa_debug($url, $original_dir); } elseif ($logged_in && $private_content && $count !== 0) { return $thefiles; } elseif ($private_content !== true && $count !== 0) { return $thefiles; } elseif ($directories && ($private_content !== true || $logged_in && $private_content)) { return $thefiles; } }
function ssfa_fileup($atts) { extract(shortcode_atts(array('name' => false, 'base' => '1', 'sub' => false, 'style' => 'silver-bullet', 'iconcolor' => 'classic', 'width' => '100', 'perpx' => '%', 'align' => 'none', 'filetypes' => false, 'filegroups' => false, 'action' => 'permit', 'showto' => false, 'hidefrom' => false, 'single' => false, 'maxsize' => 10, 'maxsizetype' => 'm', 'uploadlabel' => 'File Up ➚', 'fixedlocation' => false), $atts)); if (SSFA_JAVASCRIPT === 'footer') { $GLOBALS['ssfa_add_scripts'] = true; } if (SSFA_STYLESHEET === 'footer') { $GLOBALS['ssfa_add_styles'] = true; } $current_user = wp_get_current_user(); $logged_in = is_user_logged_in(); // Visibility Permissions $showtothese = true; if ($hidefrom) { if (!$logged_in) { $showtothese = false; } $hidelevels = preg_split('/(, |,)/', $hidefrom); foreach ($hidelevels as $hlevel) { if (current_user_can($hlevel)) { $showtothese = false; break; } } } if ($showto) { $showtothese = false; $showlevels = preg_split('/(, |,)/', $showto); foreach ($showlevels as $slevel) { if (current_user_can($slevel)) { $showtothese = true; break; } } } if (!$showtothese) { return; } // Build Initial Directory $fa_userid = $logged_in ? get_current_user_id() : 'fa-nulldirectory'; $fa_username = $logged_in ? strtolower($current_user->user_login) : 'fa-nulldirectory'; $fa_firstlast = $logged_in ? strtolower($current_user->user_firstname . $current_user->user_lastname) : 'fa-nulldirectory'; $fa_userrole = $logged_in ? strtolower(ssfa_currentrole()) : 'fa-nulldirectory'; $base = $base === '1' ? SSFA_BASE1 : ($base === '2' ? SSFA_BASE2 : ($base === '3' ? SSFA_BASE3 : ($base === '4' ? SSFA_BASE4 : ($base === '5' ? SSFA_BASE5 : SSFA_BASE1)))); $base = trim($base, '/'); $base = trim($base, '/'); $sub = $sub ? trim($sub, '/') : false; $dir = $sub ? $base . '/' . $sub : $base; $playback = false; include SSFA_INCLUDES . 'private-content.php'; $dir = str_replace('//', '/', "{$dir}"); $debugpath = $GLOBALS['ssfa_abspath'] . $dir; $dir = SSFA_ROOT === 'siteurl' ? $dir : ($GLOBALS['ssfa_install'] ? $GLOBALS['ssfa_install'] . $dir : $dir); if ($private_content == true && !is_dir("{$dir}")) { return null; } $start = "{$dir}"; $ss = explode('/', $start); $ss = end($ss); $fixed = $start; $fixed = SSFA_ROOT === 'siteurl' ? $fixed : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS["ssfa_install"], '', $fixed) : $fixed); $fixed = $fixedlocation ? $fixed : null; $path = '<input type="hidden" id="ssfa-upnomenclature" value="' . $fixed . '" />'; $ssh = '<input type="hidden" id="ssfa-upwhymenclature" value="' . $ss . '" />'; $sh = '<input type="hidden" id="ssfa-upyesmenclature" value="' . $start . '" />'; // File Type Permissions $types = array(); if ($filetypes) { $filetypes = preg_split('/(, |,)/', $filetypes); foreach ($filetypes as $type) { $types[] = strtolower(str_replace(array('.', ',', ' '), '', $type)); } } if ($filegroups) { $groups = preg_split('/(, |,)/', strtolower(str_replace(' ', '', $filegroups))); foreach ($GLOBALS['ssfa_filegroups'] as $group => $discard) { if (in_array($group, $groups)) { $types = array_merge($types, $GLOBALS['ssfa_' . $group]); } } } if (count($types) > 0) { $types = array_unique($types); asort($types); $filetypes = '["' . implode('", "', $types) . '"]'; } else { $filetypes = false; } $action = $action === 'prohibit' ? $action : 'permit'; $permitted = ($filetypes || $filegroups) && $action === 'permit' ? $filetypes : 'false'; $prohibited = ($filetypes || $filegroups) && $action === 'prohibit' ? $filetypes : 'false'; // Configure Settings $uid = rand(0, 9999); $name = $name ? $name : "ssfa-meta-container-{$uid}"; $width = is_numeric(preg_replace('[\\D]', '', $width)) ? preg_replace('[\\D]', '', $width) : '100'; $perpx = $perpx === 'px' ? 'px' : '%'; $width = "width:{$width}{$perpx};"; $float = $align === 'left' ? ' float:left;' : ($align === 'right' ? ' float:right;' : null); $margin = $width !== 'width:100%;' ? $align === 'right' ? ' margin-left:15px;' : ' margin-right:15px;' : null; $inlinestyle = $width . $float . $margin; $multiple = $single ? '' : ' multiple=multiple'; $addfiles = $single ? '+ Add File' : '+ Add Files'; // Configure Max File Size Setting $max_file_size = trim(preg_replace('[\\D]', '', $maxsize)); $max_size_type = trim(strtolower($maxsizetype)); $max_file_size = is_numeric($max_file_size) ? $max_file_size : 10; $max_size_type = in_array($max_size_type, array('k', 'm', 'g')) ? $max_size_type : 'm'; $ms = $max_file_size . $max_size_type; $ms = ssfa_phpini(false, true, false, $ms); $pms = ssfa_phpini('post_max_size'); $ums = ssfa_phpini('upload_max_filesize'); $maxsize = $pms < $ms ? $pms : $ms; $maxsize = $ums < $maxsize ? $ums : $maxsize; // Initialize Settings $fixedsetting = $fixedlocation ? '"' . $fixed . '"' : 'false'; $initialize = ' <script type="text/javascript"> jQuery(document).ready(function($){ new FileUp({ form_id: "ssfa_fileup_form", uid: ' . $uid . ', container: "' . $name . '", table: "' . $style . '", iconcolor: "' . $iconcolor . '", maxsize: ' . $maxsize . ', permitted: ' . $permitted . ', prohibited: ' . $prohibited . ', fixed: ' . $fixedsetting . ', loading: "' . SSFA_IMAGES_URL . 'ajax.gif" }); }); </script>'; // Form Output if (!is_dir($debugpath)) { return current_user_can('administrator') ? 'File Up Admin Notice: The initial directory specified does not exist:<br>' . $debugpath : null; } $dropdown = $fixedlocation ? null : '<div id="ssfa-fileup-path-container" style="display:inline-block; float:left;">' . '<div id="ssfa-fileup-directories-select-container">' . '<label for="ssfa-fileup-directories-select" style="display:block!important; margin-bottom:5px!important;">Destination Directory</label>' . '<select name="ssfa-fileup-directories-select" id="ssfa-fileup-directories-select" class="chozed-select ssfa-fileup-directories-select" data-placeholder=" ">' . '<option></option>' . '<option value="' . $start . '">' . $ss . '</option>' . '</select>' . '<br>' . '<div id="ssfa-fileup-action-path" style="margin-top:5px; min-height:25px;">' . '<img id="ssfa-fileup-action-ajax-loading" src="' . SSFA_IMAGES_URL . 'ajax.gif" ' . 'style="width:15px; margin:0 0 0 5px!important; box-shadow:none!important; display:none;">' . '</div>' . '</div>' . '</div>'; $form = '<div class="ssfa_fileup_container" style="' . $inlinestyle . '">' . '<form name="ssfa_fileup_form" id="ssfa_fileup_form" action="javascript:void(0);" enctype="multipart/form-data">' . $path . $ssh . $sh . $dropdown . '<div class="ssfa_fileup_buttons_container" style="text-align:right;">' . '<span class="ssfa_fileup_wrapper" style="text-align:left;">' . '<input type="file" name="ssfa_fileup_files[]" id="ssfa_fileup_files" class="ssfa_hidden_browse"' . $multiple . ' />' . '<span class="ssfa_add_files">' . $addfiles . '</span>' . '<span id="ssfa_submit_upload">' . $uploadlabel . '</span>' . '</span>' . '</div>' . '</form>' . '<div class="ssfa_fileup_files_container"></div>' . '<span id="ssfa_rf" style="display:none;"></span>' . '</div>'; return do_shortcode($initialize . $form); }
$mfile = null; $mfiles = array(); $has_sample = 0; $has_multiple = 0; $samples = array('mp3', 'ogg', 'wav'); foreach ($samples as $sample) { if (!in_array($sample, $sources) && in_array($oext, $samples) && !in_array($oext, $sources)) { $skipthis = 1; } } if (!$skipthis && in_array($oext, $sources)) { $pbdir = $GLOBALS['ssfa_install'] ? rtrim(ssfa_replace_first($GLOBALS['ssfa_install'], '', $dir), '/') . '/' : rtrim($dir, '/') . '/'; if ($playbackpath) { $playbackpath = $GLOBALS['ssfa_install'] ? rtrim(ssfa_replace_first($GLOBALS['ssfa_install'], '', $playbackpath), '/') . '/' : rtrim($playbackpath, '/') . '/'; } else { $playbackpath = $GLOBALS['ssfa_install'] ? rtrim(ssfa_replace_first($GLOBALS['ssfa_install'], '', $dir), '/') . '/' : rtrim($dir, '/') . '/'; } $samplefile = $GLOBALS['ssfa_playback_url'] . $playbackpath . $rawname; $mfilepath = $GLOBALS['ssfa_abspath'] . $playbackpath . $rawname; foreach ($samples as $x => $sample) { if (is_file($mfilepath . '.' . $sample)) { $mfiles[$sample] = $samplefile . '.' . $sample; $has_sample = 1; } } $player = null; if (count($mfiles) > 0) { if ($playback === 'compact') { $mfile = implode('|', $mfiles); $playeratts = array('fileurl' => $mfile, 'class' => 'ssfa-player ' . $icocol, 'loops' => $loopaudio); $player = ssfa_fileaplay($playeratts);
function ssfa_file_manager() { $nonce = $_POST['nextNonce']; if (!wp_verify_nonce($nonce, 'ssfa-fm-nonce')) { die('Granny flew the coop!'); } $action = $_POST['act']; $abspath = $GLOBALS['ssfa_abspath']; $install = $GLOBALS['ssfa_install']; $remove_install = SSFA_ROOT === 'siteurl' ? false : ($install ? true : false); // bulk copy action if ($action === 'bulkcopy') { $from = stripslashes($_POST['from']); $to = stripslashes($_POST['to']); $ext = $_POST['exts']; $destination = SSFA_ROOT === 'siteurl' ? stripslashes($_POST['destination']) : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', stripslashes($_POST['destination'])) : stripslashes($_POST['destination'])); $from = explode('/*//*/', rtrim("{$from}", '/*//*/')); $to = explode('/*//*/', rtrim("{$to}", '/*//*/')); $ext = explode('/*//*/', rtrim($ext, '/*//*/')); $success = 0; $total = 0; $renamers = 0; foreach ($from as $k => $fro) { $fro = SSFA_ROOT === 'siteurl' ? "{$fro}" : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', "{$fro}") : "{$fro}"); $to[$k] = SSFA_ROOT === 'siteurl' ? "{$to[$k]}" : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', "{$to[$k]}") : "{$to[$k]}"); $total++; $newfile = $abspath . "{$to[$k]}"; if (is_file($abspath . "{$fro}") && is_file("{$newfile}")) { $i = 1; $noext = ssfa_replace_last('.' . $ext[$k], '', "{$newfile}"); while (is_file("{$newfile}")) { if ($i == 1) { $noext = "{$noext}" . " ({$i})"; } else { $j = $i - 1; $noext = rtrim("{$noext}", " ({$j})"); $noext = "{$noext}" . " ({$i})"; } $i++; $newfile = "{$noext}" . '.' . $ext[$k]; } $renamers++; } if (is_file($abspath . "{$fro}") && !is_file("{$newfile}")) { copy($abspath . "{$fro}", "{$newfile}"); } if (is_file("{$newfile}")) { $success++; } } $response = $success == 0 ? 'There was a problem copying the files. Please consult your local pharmacist.' : ($success == 1 ? "One file was copied to {$destination} and it no longer feels special." : ($success > 1 ? "{$success} of {$total} files were successfully cloned and delivered in a black caravan to {$destination}." : null)); // bulk move action } elseif ($action === 'bulkmove') { $from = stripslashes($_POST["from"]); $to = stripslashes($_POST["to"]); $ext = $_POST['exts']; $destination = SSFA_ROOT === 'siteurl' ? stripslashes($_POST["destination"]) : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS["ssfa_install"], '', stripslashes($_POST["destination"])) : stripslashes($_POST["destination"])); $from = explode('/*//*/', rtrim("{$from}", '/*//*/')); $to = explode('/*//*/', rtrim("{$to}", '/*//*/')); $ext = explode('/*//*/', rtrim($ext, '/*//*/')); $success = 0; $total = 0; $renamers = 0; foreach ($from as $k => $fro) { $fro = SSFA_ROOT === 'siteurl' ? "{$fro}" : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', "{$fro}") : "{$fro}"); $to[$k] = SSFA_ROOT === 'siteurl' ? "{$to[$k]}" : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', "{$to[$k]}") : "{$to[$k]}"); $total++; $newfile = $abspath . "{$to[$k]}"; if (is_file($abspath . "{$fro}") && is_file("{$newfile}")) { $i = 1; $noext = ssfa_replace_last('.' . $ext[$k], '', $newfile); while (is_file("{$newfile}")) { if ($i == 1) { $noext = "{$noext}" . " ({$i})"; } else { $j = $i - 1; $noext = rtrim("{$noext}", " ({$j})"); $noext = "{$noext}" . " ({$i})"; } $i++; $newfile = "{$noext}" . '.' . $ext[$k]; } $renamers++; } if (is_file($abspath . "{$fro}") && !is_file("{$newfile}")) { rename($abspath . "{$fro}", "{$newfile}"); } if (is_file("{$newfile}")) { $success++; } } $response = $success == 0 ? 'There was a problem moving the files. Please consult your local ouija specialist.' : ($success == 1 ? "One lonesome file was forced to leave all it knew and move to {$destination}." : ($success > 1 ? "{$success} of {$total} files were magically transported to {$destination}. Or was it Delaware?" : null)); // bulk download action } elseif ($action === 'bulkdownload') { $files = stripslashes($_POST["files"]); $files = explode('/*//*/', rtrim("{$files}", '/*//*/')); $zipfiles = array(); $values = array(); foreach ($files as $file) { $file = $remove_install ? ssfa_replace_first($install, '', $abspath . $file) : $abspath . $file; if (file_exists($file)) { $zipfiles[] = $file; $values[] = basename($file); } } $numvals = array_count_values($values); $sitename = get_bloginfo('name'); $time = uniqid(); $destination = SSFA_PLUGIN . '/ssfatemp'; if (!is_dir($destination)) { mkdir($destination); } $filename = $sitename . ' ' . $time . '.zip'; $link = SSFA_PLUGIN_URL . '/ssfatemp/' . $filename; $filename = $destination . '/' . $filename; if (count($zipfiles)) { $zip = new ZipArchive(); $zip->open($filename, ZipArchive::CREATE); foreach ($zipfiles as $k => $zipfile) { $zip->addFile($zipfile, basename($zipfile)); if ($numvals[basename($zipfile)] > 1) { $parts = pathinfo($zipfile); $zip->renameName(basename($zipfile), $parts['filename'] . '_' . $k . '.' . $parts['extension']); } } $zip->close(); } $response = is_file($filename) ? $link : "Error"; // bulk delete action } elseif ($action === 'bulkdelete') { $files = $_POST['files']; $files = explode('/*//*/', rtrim($files, '/*//*/')); $success = 0; $total = 0; foreach ($files as $k => $file) { $file = SSFA_ROOT === 'siteurl' ? $file : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', $file) : $file); $total++; if (is_file($abspath . $file)) { unlink($abspath . $file); } if (!is_file($abspath . $file)) { $success++; } } $response = $success == 0 ? 'There was a problem deleting the files. Please try pressing your delete button emphatically and repeatedly.' : ($success == 1 ? "A million fewer files in the world is a victory. One less file, a tragedy. Farewell, file. Au revoir. Auf Wiedersehen. Adieu." : ($success > 1 ? "{$success} of {$total} files were sent plummeting to the nether regions of cyberspace. Or was it Delaware?" : null)); // delete action } elseif ($action === 'delete') { $pp = SSFA_ROOT === 'siteurl' ? $_POST['pp'] : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', $_POST['pp']) : $_POST['pp']); $oldname = $_POST['oldname']; $ext = $_POST['ext']; $oldfile = $abspath . "{$pp}/{$oldname}.{$ext}"; if (is_file("{$oldfile}")) { unlink("{$oldfile}"); } if (!is_file("{$oldfile}")) { $response = "success"; } elseif (is_file("oldfile")) { $response = "failure"; } // rename action } elseif ($action === 'rename') { $url = stripslashes($_POST['url']); $pp = SSFA_ROOT === 'siteurl' ? $_POST['pp'] : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', stripslashes($_POST['pp'])) : stripslashes($_POST['pp'])); $oldname = stripslashes($_POST['oldname']); $rawname = stripslashes($_POST['rawname']); $ext = $_POST['ext']; $oldfile = $abspath . "{$pp}/{$oldname}.{$ext}"; $customdata = stripslashes($_POST['customdata']); $customdata = rtrim("{$customdata}", ','); if ($customdata !== '') { $customdata = " [{$customdata}]"; } else { $customdata = null; } $newfile = $abspath . "{$pp}/{$rawname}{$customdata}.{$ext}"; if ($newfile !== $oldfile) { $i = 1; while (is_file($newfile)) { if ($i == 1) { $rawname = "{$rawname}" . " ({$i})"; } else { $j = $i - 1; $rawname = rtrim("{$rawname}", " ({$j})"); $rawname = "{$rawname}" . " ({$i})"; } $i++; $newfile = $abspath . "{$pp}/{$rawname}{$customdata}.{$ext}"; } } if ($customdata !== null) { $customdata = " [" . trim(ltrim(rtrim("{$customdata}", "]"), " ["), " ") . "]"; } $newfile = $abspath . "{$pp}/" . trim("{$rawname}", ' ') . "{$customdata}.{$ext}"; $newurl = str_replace("{$pp}/{$oldname}.{$ext}", "", "{$url}"); $newurl = "{$newurl}{$pp}/" . trim("{$rawname}", ' ') . "{$customdata}.{$ext}"; $newoldname = trim("{$rawname}", ' ') . "{$customdata}.{$ext}"; $download = trim("{$rawname}", ' ') . "{$customdata}.{$ext}"; if (is_file("{$oldfile}")) { rename("{$oldfile}", "{$newfile}"); } $errors = ''; if (!is_file("{$newfile}")) { $errors = 'The file was not renamed.'; } $response = array("errors" => $errors, "download" => $download, "pp" => $pp, "newurl" => $newurl, "extension" => $ext, "oldfile" => $oldfile, "newfile" => $newfile, "rawname" => $rawname, "customdata" => $customdata, "newoldname" => $newoldname); // get action path } elseif ($action === 'getactionpath') { $fileup = $_POST['uploadaction'] === 'true' ? 'fileup-' : ''; $build = null; if (SSFA_ROOT === 'siteurl' || SSFA_ROOT !== 'siteurl' && $GLOBALS['ssfa_install'] == false) { $pp = $_POST['pp']; $st = trim($_POST['st'], '/'); } elseif (SSFA_ROOT !== 'siteurl' && $GLOBALS['ssfa_install'] !== false) { $pp = ssfa_replace_first($GLOBALS['ssfa_install'], '', $_POST['pp']); $st = trim(ssfa_replace_first($GLOBALS['ssfa_install'], '', $_POST['st']), '/'); } if ($pp === '/') { $pp = $st; } $pp = trim($pp, '/'); $sht = trim($_POST['sht'], '/'); if (!ssfa_startswith($pp, $st)) { $pp = $st; } $security = $st === $sht ? 0 : 1; $nocrumbs = $security ? trim(ssfa_replace_last("{$sht}", '', "{$st}"), '/') : null; if (strpos($pp, '..') !== false) { $pp = $st; } $dir = $abspath . $pp; $build .= "<option></option>"; $directories = glob($dir . "/*", GLOB_ONLYDIR); if ($directories) { foreach ($directories as $k => $folder) { $direxcluded = 0; if (SSFA_DIR_EXCLUSIONS) { $direxes = preg_split('/(, |,)/', SSFA_DIR_EXCLUSIONS); foreach ($direxes as $direx) { $check = strripos($folder, $direx); if ($check !== false) { $direxcluded = 1; break; } } } if (!$direxcluded) { $folder = str_replace($abspath, '', $folder); $dirname = explode('/', $folder); $dirname = end($dirname); $build .= '<option value="' . $folder . '">' . $dirname . '</option>'; } } } else { $build .= ''; } if ($security) { $pieces = explode('/', trim(trim(ssfa_replace_first("{$nocrumbs}", '', "{$pp}"), '/'), '/')); } else { $pieces = explode('/', trim("{$pp}", '/')); } $piecelink = array(); $breadcrumbs = null; foreach ($pieces as $k => $piece) { $i = 0; $piecelink[$k] = $security ? "{$nocrumbs}/" : null; while ($i <= $k) { $piecelink[$k] .= "{$pieces[$i]}/"; $i++; } $breadcrumbs .= '<a href="javascript:" data-target="' . trim($piecelink[$k], '/') . '" id="ssfa-' . $fileup . 'action-pathpart-' . $k . '">' . ssfa_strtotitle($piece) . '</a> / '; } $breadcrumbs = stripslashes($breadcrumbs); $pp = stripslashes($pp); $build = stripslashes($build); $response = array("ops" => $build, "crumbs" => $breadcrumbs, "pp" => $pp); // Create Sub-Directory } elseif ($action === 'createdir') { $parents = trim(str_replace('.', '', $_POST['parents']), '/'); $newsub = trim(str_replace('.', '', $_POST['newsub']), '/'); $uid = $_POST['uid']; $count = $_POST['count']; $page = $_POST['page']; $drawericon = $_POST['drawer']; $cells = $_POST['cells']; $class = $_POST['cls']; $base = $_POST['base']; $subs = explode('/', $newsub); $first = $subs[0]; $last = $subs[count($subs) - 1]; $start = trim(ssfa_replace_first($base, '', $parents) . '/' . $first, '/'); $drawer = str_replace('/', '*', $start); $parents = SSFA_ROOT === 'siteurl' ? stripslashes($parents) : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', stripslashes($parents)) : stripslashes($parents)); $final = $abspath . $parents . '/' . $newsub; $prettyfolder = str_replace(array('~', '--', '_', '.', '*'), ' ', "{$first}"); $prettyfolder = preg_replace('/(?<=\\D)-(?=\\D)/', ' ', "{$prettyfolder}"); $prettyfolder = preg_replace('/(?<=\\D)-(?=\\d)/', ' ', "{$prettyfolder}"); $prettyfolder = preg_replace('/(?<=\\d)-(?=\\D)/', ' ', "{$prettyfolder}"); $prettyfolder = ssfa_strtotitle($prettyfolder); if (is_dir($final)) { $response = array('status' => 'error', 'message' => 'That directory name already exists in this location.'); } else { $first_exists = is_dir($abspath . $parents . '/' . $first) ? true : false; if (mkdir($final, 0755, true)) { if (!$first_exists) { $status = "insert"; $message = "<tr id='ssfa-dir-{$uid}-{$count}' class='ssfa-drawers'>" . "<td id='folder-ssfa-dir-{$uid}-{$count}' data-value=\"00-{$first}\" class='ssfa-sorttype {$class}-first-column'>" . "<a href=\"" . add_query_arg(array('drawer' => $drawer), get_permalink($page)) . "\" data-path=\"" . $start . "\">" . "<span style='font-size:20px; margin-left:3px;' class='ssfa-icon-{$drawericon}' aria-hidden='true'></span>" . "<br>dir" . "</a>" . "</td>" . "<td id='name-ssfa-dir-{$uid}-{$count}' data-value='00-{$first}' class='ssfa-sortname'>" . "<a href=\"" . add_query_arg(array('drawer' => $drawer), get_permalink($page)) . "\">" . "<span style='text-transform:uppercase;'>{$prettyfolder}</span>" . "</a>" . "<input id='rename-ssfa-dir-{$uid}-{$count}' type='text' value=\"{$first}\" " . "style='width:90%; height:26px; font-size:12px; text-align:center; display:none'>" . "</td>"; $icell = 1; while ($icell < $cells) { $message .= "<td class='{$class}'> </td>"; $icell++; } $message .= "<td id='manager-ssfa-dir-{$uid}-{$count}' class='{$class}'>" . "<a href='' id='rename-ssfa-dir-{$uid}-{$count}'>Rename</a><br><a href='' id='delete-ssfa-dir-{$uid}-{$count}'>Delete</a>" . "</td>"; $message .= "</tr>"; } else { $status = "success"; $message = "Your sub-directories have been sucessfully created."; } $response = array('status' => $status, 'message' => $message, 'uid' => $uid); } else { $response = array('status' => 'error', 'message' => 'Sorry, there was a problem creating that directory for you.'); } } // Rename Directory } elseif ($action === 'renamedir') { $oldpath = trim(str_replace('..', '', $_POST['oldpath']), '/'); $oldpath = SSFA_ROOT === 'siteurl' ? stripslashes($oldpath) : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', stripslashes($oldpath)) : stripslashes($oldpath)); $newname = str_replace(array('..', '/'), '', $_POST['newname']); $pp = explode('/', $oldpath); $newpath = str_replace(end($pp), $newname, $oldpath); $olddata = $_POST['datapath']; $datapp = explode('/', $olddata); $newdata = str_replace(end($datapp), $newname, $olddata); $parents = $_POST['parents']; $parents = SSFA_ROOT === 'siteurl' ? stripslashes($parents) : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', stripslashes($parents)) : stripslashes($parents)); $old = $parents . '/' . end($pp); $dst = $abspath . $newpath; $src = $abspath . $old; $page = $_POST['page']; $drawer = str_replace('/', '*', $newdata); $newurl = add_query_arg(array('drawer' => $drawer), get_permalink($page)); $response = false; if (is_dir($dst)) { $response = array('status' => 'error', 'message' => 'That directory already exists.'); } elseif (!is_dir($src)) { $response = array('status' => 'error', 'message' => "The directory you're trying to rename could not be found."); } else { if (!is_dir("{$dst}")) { mkdir("{$dst}", 0755, true); } $dirs = ssfa_recursive_dirs($src); if (is_array($dirs)) { $dirs = array_reverse($dirs); $fcount = 0; $fscount = 0; $dcount = 1; $dscount = 0; foreach ($dirs as $dir) { $dcount++; $files = false; $filedest = str_replace("{$src}", "{$dst}", "{$dir}"); if (!is_dir($filedest)) { mkdir("{$filedest}", 0755, true); } $files = array_filter(glob("{$dir}" . "/*"), 'is_file'); if (is_array($files)) { foreach ($files as $file) { $fcount++; $filename = pathinfo($file, PATHINFO_BASENAME); if (rename("{$file}", "{$filedest}" . "/" . "{$filename}")) { $fscount++; } } } if (rmdir($dir)) { $dscount++; } } } $basefiles = array_filter(glob("{$src}" . "/*"), 'is_file'); if (is_array($basefiles)) { foreach ($basefiles as $file) { $fcount++; $filename = pathinfo($file, PATHINFO_BASENAME); if (rename("{$file}", "{$dst}" . "/" . "{$filename}")) { $fscount++; } } } if (rmdir($src)) { $dscount++; } if ($fcount > 0 && !$fscount) { $response = array('status' => 'error', 'message' => 'We tried to move the files into the newly-named directory but none of them would budge.'); } elseif ($fcount > 0 && $fcount > $fscount) { $response = array('status' => 'error', 'message' => "We tried to move the files into the newly-named directory, but there were some stragglers, so we couldn't remove the old directory."); } elseif (!is_dir($src)) { $response = array('status' => 'success', 'url' => $newurl, 'newdata' => $newdata, 'newname' => $newname); } else { $response = array('status' => 'error', 'message' => 'An unspecified error occurred.'); } } // Delete Directory } elseif ($action === 'deletedir') { $status = $_POST['status']; $path1 = $_POST['path1']; $path2 = $_POST['path2']; $path = SSFA_ROOT === 'siteurl' ? stripslashes($path1 . '/' . $path2) : ($GLOBALS['ssfa_install'] ? ssfa_replace_first($GLOBALS['ssfa_install'], '', stripslashes($path1 . '/' . $path2)) : stripslashes($path1 . '/' . $path2)); $src = $abspath . $path; $response = false; if (!is_dir("{$src}")) { $response = array('status' => 'error', 'message' => 'The directory marked for deletion could not be found. ' . $path); } else { $dirs = ssfa_recursive_dirs($src); $dirs = is_array($dirs) ? array_reverse($dirs) : $dirs; if ($status === 'life') { $dcount = 0; $fcount = 0; if (is_array($dirs)) { foreach ($dirs as $dir) { $dcount++; $files = false; $files = array_filter(glob("{$dir}" . "/*"), 'is_file'); if (is_array($files)) { foreach ($files as $file) { $fcount++; } } } } $basefiles = array_filter(glob("{$src}" . "/*"), 'is_file'); if (is_array($basefiles)) { foreach ($basefiles as $file) { $fcount++; } } if ($fcount == 0) { $status = 'death'; } else { $filemsg = null; if ($fcount >= 1) { $plufiles = $fcount > 1 ? 'files' : 'file'; $filemsg = ' and ' . $fcount . ' ' . $plufiles; } $dirmsg = null; if ($dcount >= 1) { $pludirs = $dcount > 1 ? 'sub-directories' : 'sub-directory'; $dirmsg = ', ' . $dcount . ' ' . $pludirs; } $message = 'You are about to delete 1 directory' . $dirmsg . $filemsg . ' from the server. This action is permanent and cannot be undone. Are you sure you wish to proceed?'; $response = array('status' => 'confirm', 'message' => $message); } } if ($status === 'death') { $pcount = 1; $pscount = 0; $dcount = 0; $dscount = 0; $fcount = 0; $fscount = 0; if (is_array($dirs)) { foreach ($dirs as $dir) { $dcount++; $files = false; $files = array_filter(glob("{$dir}" . "/*"), 'is_file'); if (is_array($files)) { foreach ($files as $file) { $fcount++; $file = realpath($file); if (is_readable($file)) { if (unlink($file)) { $fscount++; } } } } if (rmdir($dir)) { $dscount++; } } } $basefiles = array_filter(glob("{$src}" . "/*"), 'is_file'); if (is_array($basefiles)) { foreach ($basefiles as $file) { $fcount++; $file = realpath($file); if (is_readable($file)) { if (unlink($file)) { $fscount++; } } } } if (rmdir($src)) { $pscount++; } if ($pscount && $fscount || $pscount && !$fcount) { $success = $pscount == $pcount && $dscount == $dcount && $fscount == $fcount ? 'success' : 'partial'; $success = $fscount == $fcount && !$fcount ? 'success-single' : $success; $filemsg = null; if ($fcount >= 1) { $plufiles = $fcount > 1 ? 'files' : 'file'; $filemsg = ' and ' . $fscount . ' of ' . $fcount . ' ' . $plufiles; } else { $filemsg = ' and ' . $fcount . ' files'; } $dirmsg = null; if ($dcount >= 1) { $pludirs = $dcount > 1 ? 'sub-directories' : 'sub-directory'; $dirmsg = ', ' . $dscount . ' of ' . $dcount . ' ' . $pludirs; } $message = $pscount . ' of 1 directories' . $dirmsg . $filemsg . ' have been removed from the server.'; $response = array('status' => $success, 'message' => $message); } else { $response = array('status' => 'error', 'message' => 'Sorry, but there was an error attempting to remove this directory.'); } } } // report possible saboteur } elseif ($action === 'saboteur') { $user = wp_get_current_user(); $name = $user->display_name; $id = $user->ID; $login = $user->user_login; $time = date('Y-m-d H:i:s', strtotime('NOW')); foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) { if (array_key_exists($key, $_SERVER) === true) { foreach (explode(',', $_SERVER[$key]) as $ip) { if (filter_var($ip, FILTER_VALIDATE_IP) !== false) { $userip = $ip; } } } } $to = get_option('admin_email'); $subject = "Automated Security Alert from File Away re: {$name}"; $message = "This user may have tried to manipulate restricted directories:\r\n\r\n"; $message .= "Name: " . $name . "\r\n"; $message .= "Username: "******"\r\n"; $message .= "User ID: " . $id . "\r\n"; $message .= "IP Address: " . $userip . "\r\n"; $message .= "Time: " . $time . "\r\n\r\n\r\n"; $message .= "Sincerely,\r\n"; $message .= "File Away\r\n"; mail($to, $subject, $message); $response = wp_logout_url(); // FileUp Upload Handler } elseif ($action === 'upload') { if (isset($_POST) && $_SERVER['REQUEST_METHOD'] == "POST") { $file_name = strip_tags($_FILES['upload_file']['name']); $new_name = strip_tags($_POST['new_name']); $file_id = strip_tags($_POST['upload_file_id']); $file_size = $_FILES['upload_file']['size']; $max_file_size = (int) $_POST['max_file_size']; $file_path = trim($_POST['upload_path'], '/'); $location = str_replace('//', '/', $abspath . $file_path . '/' . $new_name); $dir = dirname($location); $_POST['size_check'] = $file_size > $max_file_size ? 'true' : 'false'; if ($file_size > $max_file_size) { echo 'system_error'; } elseif (strpos($dir, '..') !== false) { echo 'system_error'; } else { if (!is_dir($dir)) { mkdir($dir, 0755, true); } $p = pathinfo($location); $filename = $p['filename']; $i = 1; while (is_file($location)) { if ($i == 1) { $filename = $filename . " ({$i})"; } else { $j = $i - 1; $filename = rtrim($filename, " ({$j})"); $filename = $filename . " ({$i})"; } $i++; $name = $filename . '.' . $p['extension']; $location = $p['dirname'] . '/' . $name; } $name = $filename . '.' . $p['extension']; $location = $p['dirname'] . '/' . $name; if (move_uploaded_file(strip_tags($_FILES['upload_file']['tmp_name']), $location)) { echo $file_id; } else { echo 'system_error'; } } exit; } else { echo 'system_error'; exit; } } $response = json_encode($response); header("Content-Type: application/json"); echo $response; exit; }
$crumbs = explode('/', trim("{$dir}", '/')); } $crumblink = array(); if (!$heading) { $addclass = '-noheading'; } $thefiles .= "<div class='ssfa-crumbs{$addclass}'>"; foreach ($crumbs as $k => $crumb) { $prettycrumb = str_replace(array('~', '--', '_', '.', '*'), ' ', $crumb); $prettycrumb = preg_replace('/(?<=\\D)-(?=\\D)/', ' ', $prettycrumb); $prettycrumb = preg_replace('/(?<=\\d)-(?=\\D)/', ' ', $prettycrumb); $prettycrumb = preg_replace('/(?<=\\D)-(?=\\d)/', ' ', $prettycrumb); $prettycrumb = ssfa_strtotitle($prettycrumb); if ($crumb !== '') { $i = 0; while ($i <= $k) { if ($i == 0) { $comma = null; } else { $comma = "*"; } $crumblink[$k] .= $comma . "{$crumbs[$i]}"; $i++; } if ($basebase === $basecheck) { $crumblink[$k] = ltrim(ssfa_replace_first("{$basebase}", '', "{$crumblink[$k]}"), '*'); } $thefiles .= '<a href="' . add_query_arg(array('drawer' => $crumblink[$k]), get_permalink()) . '">' . "{$prettycrumb}" . '</a> / '; } } $thefiles .= "</div>";