public function feeds() { extract($this->definitions->pathoptions); $basedirs = fileaway_utility::feeds(); $excluded_dirs = fileaway_utility::feeds(true); $wp_excludes = array('wp-admin', 'wp-includes', 'wp-content/themes', 'wp-content/upgrade'); $startswith = array('fa-feed-logo', '_thumb_', 'fileaway-url-parser', 'fileaway-banner-parser', 'index.htm', 'index.php', '.ht'); $endswith = array('ini', 'php'); if (isset($this->options['feed_excluded_exts']) && !empty($this->options['feed_excluded_exts'])) { $endswith = array_unique(array_merge($endswith, preg_split('/(, |,)/', trim($this->options['feed_excluded_exts']), -1, PREG_SPLIT_NO_EMPTY))); } $excludestrings = array(); if (isset($this->options['feed_excluded_files']) && !empty($this->options['feed_excluded_files'])) { $excludestrings = preg_split('/(, |,)/', trim($this->options['feed_excluded_files']), -1, PREG_SPLIT_NO_EMPTY); } if (!isset($this->options['feeds']) || !$this->options['feeds'] || trim($this->options['feeds']) == '' || trim($this->options['feeds']) == '/') { return; } fileaway_utility::timezone(); $storage = $rootpath . trim(trim($this->options['feeds']), '/'); if (!is_dir($storage)) { if (mkdir($storage, 0775, true)) { fileaway_utility::indexmulti($storage, $chosenpath); } } $globallogo = false; if (is_file($storage . '/fa-feed-logo.png')) { $globallogo = $storage . '/fa-feed-logo.png'; } elseif (is_file($storage . '/fa-feed-logo.jpg')) { $globallogo = $storage . '/fa-feed-logo.jpg'; } elseif (is_file($storage . '/fa-feed-logo.gif')) { $globallogo = $storage . '/fa-feed-logo.gif'; } if ($globallogo) { $globallogo = fileaway_utility::urlesc(fileaway_utility::replacefirst($globallogo, rtrim($rootpath, '/'), rtrim($this->options['baseurl'], '/') . '/')); } $feedlimit = isset($this->options['feedlimit']) && is_numeric($this->options['feedlimit']) ? round($this->options['feedlimit'], 0) : false; $hardlinks = array(); $map = is_file($storage . '/fa-directory-map.csv') ? new fileaway_csv($storage . '/fa-directory-map.csv') : false; $now = time(); foreach ($basedirs as $basedir) { $basedir = $rootpath . trim(trim($basedir), '/'); $dirs = fileaway_utility::recursivedirs($basedir); array_unshift($dirs, $basedir); $datestring = $this->options['daymonth'] == 'md' ? 'm/d/Y H:i' : 'd/m/Y H:i'; foreach ($dirs as $k => $dir) { foreach ($wp_excludes as $wp) { if (stripos($dir, $wp) !== false) { continue 2; } } $feedfile = $dir . '/_fa.feed.id.ini'; if (!is_file($feedfile)) { $feedid = uniqid(true); $feedfile_contents = "; Do not move or delete this file, nor alter its contents \n" . "id = " . $feedid; file_put_contents($feedfile, $feedfile_contents); } else { $ini = parse_ini_file($feedfile); $feedid = $ini['id']; } $feed = $storage . '/_feed_' . $feedid . '.xml'; if (fileaway_utility::startswith(fileaway_utility::replacefirst($dir, $rootpath, ''), $excluded_dirs)) { if (is_file($feed)) { unlink($feed); } continue; } $feedlogo = false; if (is_file($dir . '/fa-feed-logo.png')) { $feedlogo = $dir . '/fa-feed-logo.png'; } elseif (is_file($dir . '/fa-feed-logo.jpg')) { $feedlogo = $dir . '/fa-feed-logo.jpg'; } elseif (is_file($dir . '/fa-feed-logo.gif')) { $feedlogo = $dir . '/fa-feed-logo.gif'; } $feedlogo = $feedlogo ? fileaway_utility::urlesc(fileaway_utility::replacefirst($feedlogo, rtrim($rootpath, '/'), rtrim($this->options['baseurl'], '/') . '/')) : $globallogo; $files = array(); $subxml = array(); $initfiles = array_filter(glob("{$dir}/*"), 'is_file'); if ($this->options['recursivefeeds'] == 'true') { $initdirs = glob("{$dir}/*", GLOB_ONLYDIR); if (is_array($initdirs) && count($initdirs) > 0) { foreach ($initdirs as $subdir) { if (in_array(fileaway_utility::replacefirst($subdir, $rootpath, ''), $excluded_dirs)) { continue; } $subfeedfile = $subdir . '/_fa.feed.id.ini'; if (!is_file($subfeedfile)) { continue; } $subini = parse_ini_file($subfeedfile); $subfeedid = $subini['id']; $subfeed = $storage . '/_feed_' . $subfeedid . '.xml'; if (!is_file($subfeed)) { continue; } $sublink = $map ? $this->csvsearch($map->data, $map->titles, trim(fileaway_utility::replacefirst($subdir, $rootpath, ''), '/')) : false; $sublink = $sublink ? $sublink : fileaway_utility::replacefirst($subfeed, $rootpath, rtrim($this->options['baseurl'], '/') . '/'); $subPubDate = $this->options['feeddates'] == 'false' ? null : "<pubDate>" . date($datestring, filemtime($subdir)) . "</pubDate>\n" . ($subxml[] = "<item>\n" . "<title>" . fileaway_utility::basename($subdir) . "</title>\n" . "<link>" . $sublink . "</link>\n" . "<description>RSS Feed</description>\n" . $subPubDate . "</item>\n"); } } } if (is_array($initfiles)) { foreach ($initfiles as $i => $file) { if (fileaway_utility::startswith(fileaway_utility::basename($file), $startswith)) { unset($initfiles[$i]); continue; } if (fileaway_utility::endswith(strtolower(fileaway_utility::basename($file)), $endswith)) { unset($initfiles[$i]); continue; } foreach ($excludestrings as $str) { if (strpos(fileaway_utility::basename($file), $str) !== false) { unset($initfiles[$i]); continue 2; } } $mime = false; $parts = fileaway_utility::pathinfo($file); $ext = strtolower($parts['extension']); if ($this->options['feedlinks'] != 'false') { if (in_array($ext, array('mp3', 'wav', 'ogg'))) { $mime = $ext == 'mp3' ? 'audio/mpeg' : ($ext == 'wav' ? 'audio/vnd.wave' : 'audio/ogg'); } elseif (in_array($ext, array('png', 'gif', 'jpg', 'jpeg'))) { $mime = $ext == 'png' ? 'image/png' : ($ext == 'gif' ? 'image/gif' : 'image/jpeg'); } elseif (in_array($ext, array('avi', 'mpeg', 'mp4', 'ogv', 'mov', 'webm', 'flv', 'wmv', 'mkv'))) { $mime = $ext == 'avi' ? 'video/avi' : ($ext == 'mp4' ? 'video/mp4' : ($ext == 'flv' ? 'video/x-flv' : ($ext == 'mpeg' ? 'video/mpeg' : ($ext == 'ogv' ? 'video/ogg' : ($ext == 'mov' ? 'video/quicktime' : ($ext == 'webm' ? 'video/webm' : ($ext == 'wmv' ? 'video/x-ms-wmv' : 'video/x-matroska'))))))); } if (stripos($file, 's2member-files/')) { $getsub = explode('s2member-files/', fileaway_utility::urlesc($file)); $fileurl = rtrim($this->options['baseurl'], '/') . '/?s2member_file_download=' . $getsub[1]; } else { $fileurl = fileaway_utility::urlesc(fileaway_utility::replacefirst($file, $rootpath, rtrim($this->options['baseurl'], '/') . '/')); } } else { $fileurl = false; } $files['dirname'][] = $parts['dirname']; $files['basename'][] = $parts['basename']; $files['filename'][] = $parts['filename']; $files['extension'][] = $parts['extension']; $files['mime'][] = $mime; $files['datemodified'][] = $this->options['feeddates'] != 'false' ? filemtime($file) : $now; $files['filesize'][] = $this->options['feedsize'] != 'false' ? filesize($file) : false; $files['url'][] = $fileurl; } if (isset($files['datemodified']) && count($files['datemodified']) > 0) { array_multisort($files['datemodified'], SORT_DESC, SORT_NUMERIC, $files['dirname'], $files['basename'], $files['filename'], $files['extension'], $files['mime'], $files['filesize'], $files['url']); } $directory = explode('/', $dir); $directory = array_pop($directory); $stripped_url = str_ireplace(array('http:', 'https:', 'www.', 'ww2.', '//'), '', rtrim($this->options['baseurl'], '/')); $ttl = $this->options['feedinterval'] == 'fifteenminutes' ? 15 : ($this->options['feedinterval'] == 'thirtyminutes' ? 30 : ($this->options['feedinterval'] == 'fortyfiveminutes' ? 45 : 60)); $channellink = $map ? $this->csvsearch($map->data, $map->titles, trim(fileaway_utility::replacefirst($dir, $rootpath, ''), '/')) : $this->options['baseurl']; $description = $channellink ? $channellink : fileaway_utility::replacefirst($dir, $rootpath, rtrim($this->options['baseurl'], '/') . '/'); $channellink = $channellink ? $channellink : $this->options['baseurl']; $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" . "<rss version=\"2.0\">\n" . "<channel>\n" . "<title>" . $stripped_url . " > " . $directory . "</title>\n" . "<link>" . $channellink . "</link>\n" . "<description>" . $description . "</description>\n" . "<lastBuildDate>" . date($datestring) . "</lastBuildDate>\n" . "<pubDate>" . date($datestring) . "</pubDate>\n" . "<ttl>" . $ttl . "</ttl>\n" . "<generator>File Away</generator>\n"; if ($feedlogo) { $xml .= "<image>\n" . "<url>" . $feedlogo . "</url>\n" . "<title>" . str_replace(array('http://', 'https://', 'www.'), '', $this->options['baseurl']) . " > " . $directory . "</title>\n" . "<link>" . $this->options['baseurl'] . "</link>\n" . "</image>\n"; } if (count($subxml > 0)) { $xml .= implode($subxml); } if (isset($files['datemodified']) && count($files['datemodified']) > 0) { foreach ($files['datemodified'] as $k => $file) { if ($feedlimit && $k >= $feedlimit) { break; } $rawname = str_replace('&', 'and', $files['filename'][$k]); if (preg_match('/\\[([^\\]]+)\\]/', $rawname)) { list($thename, $customvalue) = preg_split("/[\\[\\]]/", $rawname); $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('~', '--', '_', '.', '*'), ' ', $thename); } else { $customvalue = false; $thename = str_replace(array('~', '--', '_', '.', '*'), ' ', $rawname); } $thename = preg_replace('/(?<=\\D)-(?=\\D)/', ' ', "{$thename}"); $thename = preg_replace('/(?<=\\d)-(?=\\D)/', ' ', "{$thename}"); $thename = preg_replace('/(?<=\\D)-(?=\\d)/', ' ', "{$thename}"); $showsize = $this->options['feedsize'] == 'false' ? null : "Size: " . fileaway_utility::formatBytes($files['filesize'][$k]) . "."; $filedescription = $customvalue ? $customvalue . ' (' . $files['extension'][$k] . " file. " . $showsize : $files['extension'][$k] . " file. " . $showsize; $pubDate = $this->options['feeddates'] == 'false' ? null : "<pubDate>" . date($datestring, $file) . "</pubDate>\n"; $filelink = $files['url'][$k] ? $files['url'][$k] : $channellink; $xml .= "<item>\n" . "<title>" . $thename . "</title>\n" . "<link>" . $filelink . "</link>\n" . "<description>" . $filedescription . "</description>\n" . $pubDate; if ($files['mime'][$k]) { $xml .= "<enclosure url=\"" . $files['url'][$k] . "\" length=\"" . $files['filesize'][$k] . "\" type=\"" . $files['mime'][$k] . "\" />\n"; } $xml .= "</item>\n"; } } $xml .= "</channel>\n" . "</rss>"; $oldfeed = file_get_contents($feed); if ($xml != $oldfeed) { file_put_contents($feed, $xml); } } } } date_default_timezone_set('UTC'); exit; }
public function display($slug, $defaults) { $output = null; foreach ($this->settings as $id => $setting) { $setting['id'] = $id; extract(wp_parse_args($setting, $defaults)); if ($section !== $slug) { continue; } if (!isset($this->options[$id])) { $this->options[$id] = $dflt; } if (!isset($this->options[$id])) { $this->options[$id] = 0; } if (!$class) { $class = null; } $submit = $submit ? '<br><br><br><span class="fileaway-save-settings fileaway-selectIt">Save Changes</span>' : null; global $is_IE, $is_chrome; $is_opera = preg_match('/opr/i', $_SERVER['HTTP_USER_AGENT']) ? true : false; $chromefix = ($is_chrome or $is_opera ? ' fileaway-abspath-chromefix' : null); $iefix = $is_IE ? ' fileaway-abspath-iefix' : null; $get = new fileaway_definitions(); $pathoptions = $get->pathoptions; $abspath = $pathoptions['chosenpath']; $abspath = strpos($abspath, '/public_html/') !== false ? strstr($abspath, '/public_html/') : (strpos($abspath, '/www/') !== false ? strstr($abspath, '/www/') : $abspath); $rootpath = $pathoptions['rootpath']; $rootpath = strpos($rootpath, '/public_html/') !== false ? strstr($rootpath, '/public_html/') : (strpos($rootpath, '/www/') !== false ? strstr($rootpath, '/www/') : $rootpath); $helplink = $helplink ? '<span class="link-fileaway-help-' . $id . ' fileaway-helplink fileaway-help-iconinfo4"></span>' : null; switch ($type) { case 'text': if ($title) { $output .= '<div class="fileaway-label"><label for="' . $id . '">' . $title . '</label></div>'; } $output .= '<div class="' . $class . '" id="fileaway-container-' . $id . '">'; $output .= '<input class="regular-text ' . $class . '" type="' . $input . '" id="' . $id . '" ' . 'name="fileaway_options[' . $id . ']" placeholder="' . $holder . '" value="' . stripslashes(esc_attr($this->options[$id])) . '" />' . $helplink . '</div>' . $submit; break; case 'basedir': if ($title) { $output .= '<div class="fileaway-label"><label for="' . $id . '">' . $title . '</label></div>'; } $output .= '<div class="' . $class . '" id="fileaway-container-' . $id . '">'; $output .= '<div id="fileaway-wrap-' . $id . '" class="fileaway-wrap-base">' . '<span id="fileaway-abspath-' . $id . '" class="fileaway-abspath' . $chromefix . '">' . $abspath . '</span> ' . '<input class="regular-text ' . $class . '" type="text" id="' . $id . '" name="fileaway_options[' . $id . ']" ' . 'placeholder="' . $holder . '" value="' . esc_attr($this->options[$id]) . '" />' . $helplink . '<br />' . '<div id="fileaway-error-' . $id . '" style="display:none; line-height:14px;">' . '<span class="warning-text">Sorry. You can\'t point to the wp-admin/ or wp-includes/ directories.<br />' . 'Use wp-content/uploads, or custom folders in your installation directory.</span></div></div></div>'; break; case 'rootpath': if ($title) { $output .= '<div class="fileaway-label"><label for="' . $id . '">' . $title . '</label></div>'; } $output .= '<div class="' . $class . '" id="fileaway-container-' . $id . '">'; $output .= '<div id="fileaway-wrap-' . $id . '" class="fileaway-wrap-base">' . '<span id="fileaway-abspath-' . $id . '" class="fileaway-abspath' . $chromefix . '">' . $rootpath . '</span> ' . '<input class="regular-text ' . $class . '" type="text" id="' . $id . '" name="fileaway_options[' . $id . ']" ' . 'placeholder="' . $holder . '" value="' . esc_attr($this->options[$id]) . '" />' . '</div>' . $helplink . '</div>'; break; case 'select': if ($title) { $output .= '<div class="fileaway-label"><label for="' . $id . '">' . $title . '</label></div>'; } $output .= '<div class="' . $class . '" id="fileaway-container-' . $id . '">'; $output .= '<select id="' . $id . '" class="select ' . $class . ' chozed-select" data-placeholder=" " name="fileaway_options[' . $id . ']">'; if (is_array($choices)) { foreach ($choices as $value => $label) { $output .= '<option value="' . esc_attr($value) . '" ' . selected($this->options[$id], $value, false) . '>' . $label . '</option>'; } } $output .= '</select>' . $helplink . '</div>' . $submit; break; case 'customcss': $output .= '<div style="clear:both!important;"></div>'; if ($title) { $output .= '<div class="fileaway-label"><label for="' . $id . '">' . $title . '</label></div>'; } $output .= '<div class="' . $class . '" id="fileaway-container-' . $id . '">'; $output .= '<textarea class="fileaway-customcss ' . $class . '" id="' . $id . '" name="fileaway_options[' . $id . ']" placeholder="' . $holder . '" rows="10" cols="50" ' . '>' . stripslashes(strip_tags($this->options[$id])) . '</textarea>' . $helplink . '</div>'; if ($this->options['css_editor'] === 'syntax') { $output .= '<script>var textcss = document.getElementById("' . $id . '"); var CodeMirror = CodeMirror.fromTextArea(textcss, {lineNumbers: true});</script>'; } else { $output .= '<script>var CodeMirror = false;</script>'; } break; case 'rolescaps': if ($title) { $output .= '<div class="fileaway-label"><label for="' . $id . '">' . $title . '</label></div>'; } $output .= '<div class="' . $class . '" id="fileaway-container-' . $id . '">'; $output .= '<input type="' . $input . '" id="' . $id . '" name="fileaway_options[' . $id . ']" value="' . esc_attr($this->options[$id]) . '" />'; $output .= '<select id="' . $id . '" class="select chozed-select" data-placeholder=" " multiple>'; $roles = fileaway_utility::caps(); if (is_array($roles)) { foreach ($roles as $role => $name) { $permitroles = explode(',', $this->options[$id]); $selected = null; if (is_array($permitroles)) { foreach ($permitroles as $r) { if (trim($r) === $role) { $selected = 'selected'; } } } $output .= '<option value="' . $role . '" ' . $selected . '>' . $name . '</option>'; } } $output .= '</select>' . $helplink . '</div>'; break; case 'users': if ($this->options['loadusers'] == 'true') { if ($title) { $output .= '<div class="fileaway-label"><label for="' . $id . '">' . $title . '</label></div>'; } $output .= '<div class="' . $class . '" id="fileaway-container-' . $id . '">'; $output .= '<input type="' . $input . '" id="' . $id . '" name="fileaway_options[' . $id . ']" value="' . esc_attr($this->options[$id]) . '" />'; $output .= '<select id="' . $id . '" class="select chozed-select" data-placeholder=" " multiple>'; $users = get_users('blog_id=' . $GLOBALS['blog_id'] . '&orderby=nicename'); if (is_array($users)) { foreach ($users as $user) { $approved = explode(',', str_replace(' ', '', $this->options[$id])); $selected = null; if (is_array($approved)) { foreach ($approved as $appr) { if ($appr == $user->ID) { $selected = 'selected'; } } } $output .= '<option value="' . $user->ID . '" ' . $selected . '>' . $user->display_name . '</option>'; } } $output .= '</select>' . $helplink . '</div>'; } else { if ($title) { $output .= '<div class="fileaway-label"><label for="' . $id . '">' . $title . '</label></div>'; } $output .= '<div class="fileaway-overridepassword ' . $class . '" id="fileaway-container-' . $id . '">'; $output .= '<input type="text" class="regular-text fileaway-overridepassword ' . $class . '" ' . 'id="' . $id . '" name="fileaway_options[' . $id . ']" value="' . esc_attr($this->options[$id]) . '" />'; $output .= $helplink . '</div>'; } break; case 'basefeed': $excluded_feeds = $id == 'excluded_feeds' ? true : false; if ($title) { $output .= '<div class="fileaway-label"><label for="' . $id . '">' . $title . '</label>' . '<span id="fileaway_add_new_' . $id . '" class="fileaway-add-another fileaway-selectIt">Add Another</span></div>'; } $output .= '<div class="' . $class . '" id="fileaway-container-' . $id . '" style="margin-bottom:30px;">'; $feeds = fileaway_utility::feeds($excluded_feeds); if (count($feeds) < 1) { $output .= '<div id="fileaway-wrap-' . $id . '_0" data-feed="0" class="fileaway-wrap-base">' . '<span id="fileaway-abspath-' . $id . '_0" class="fileaway-abspath' . $chromefix . '">' . $rootpath . '</span> ' . '<input class="regular-text ' . $class . '" type="text" id="' . $id . '_0" name="fileaway_options[' . $id . '][]" ' . 'placeholder="' . $holder . '" value="" />' . '</div>' . $helplink . '</div>'; } else { foreach ($feeds as $x => $feed) { $multiclass = $x > 0 ? 'fileaway-subsequent' : null; $output .= '<div id="fileaway-wrap-' . $id . '_' . $x . '" data-feed="' . $x . '" class="fileaway-wrap-base ' . $multiclass . '">' . '<span id="fileaway-abspath-' . $id . '_' . $x . '" class="fileaway-abspath' . $chromefix . '">' . $rootpath . '</span> ' . '<input class="regular-text ' . $class . '" type="text" id="' . $id . '_' . $x . '" name="fileaway_options[' . $id . '][]" ' . 'placeholder="' . $holder . '" value="' . esc_attr($feed) . '" />' . '</div>'; $output .= $x > 0 ? null : $helplink; } $output .= '</div>'; } break; } } return $output; }