function test_path_is_not_absolute()
 {
     if (!is_callable('path_is_absolute')) {
         $this->markTestSkipped();
     }
     $relative_paths = array('', '.', '..', '../foo', '../', '../foo.bar', 'foo/bar', 'foo', 'FOO', '..\\WINDOWS');
     foreach ($relative_paths as $path) {
         $this->assertFalse(path_is_absolute($path), "path_is_absolute('{$path}') should return false");
     }
 }
 /**
  * Gets the value of the option that stores the path to the certificate file.
  * Relative paths will be converted to absolute, as if relative to WP root.
  * 
  * @since 4.7
  * @return string Absolute path to the certificate file.
  */
 public function get_certificate_path_setting()
 {
     $path = wprss_get_general_setting(self::SETTING_KEY_CERTIFICATE_PATH);
     if (empty($path)) {
         return $path;
     }
     if (!path_is_absolute($path)) {
         $path = ABSPATH . $path;
     }
     return $path;
 }
 public static function render($view, $arguments = array(), $return = false, $loop = null)
 {
     global $post, $posts, $post_id, $current_user, $wpdb, $wp_query, $pagenow, $typenow, $hook_suffix, $current_screen, $wp_version, $wp_did_header, $wp_rewrite, $wp, $wp_post_statuses, $comment, $user_ID;
     $_windows_os = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
     $_path_seperator = '/';
     $_backtrace = debug_backtrace();
     if (isset($_backtrace[1]['file'])) {
         $_origin = $_backtrace[1]['file'];
         if (is_string($_origin) && (!$_windows_os && substr($_origin, 0, 1) == $_path_seperator || $_windows_os && substr($_origin, 1, 1) == ':')) {
             $view .= strstr($view, '.php') ? '' : '.php';
             $_path = substr($_origin, 0, strrpos($_origin, $_path_seperator));
             foreach (array(STYLESHEETPATH, TEMPLATEPATH) as $_theme_path) {
                 if ($_path == $_theme_path && file_exists($_theme_path . $_path_seperator . $view)) {
                     $_file = path_is_absolute($view) ? $view : $_theme_path . $_path_seperator . $view;
                 }
             }
         }
     }
     if (!isset($_file)) {
         foreach (self::$paths as $_display => $_path) {
             $_file = (path_is_absolute($view) ? $view : self::$paths[$_display] . $_path_seperator . 'parts' . $_path_seperator . $view) . (strstr($view, '.php') ? '' : '.php');
             // Check for theme overrides
             if (stristr($_file, '/parts/')) {
                 $_part = '';
                 $_directories = explode($_path_seperator, $_file);
                 for ($i = count($_directories); $i >= 0; $i--) {
                     if (isset($_directories[$i])) {
                         $_part = $_directories[$i] . (empty($_part) ? '' : $_path_seperator) . $_part;
                         if ($_directories[$i] == 'parts') {
                             $_part = $_path_seperator . $_directories[$i - 1] . $_path_seperator . $_part;
                             break;
                         }
                     }
                 }
             }
             if (!path_is_absolute($_file)) {
                 foreach (array('theme', 'parent-theme') as $_theme) {
                     $_path = isset(self::$paths[$_theme]) ? self::$paths[$_theme] : null;
                     if (isset(self::$paths[$_theme]) && isset($_path)) {
                         $_path = substr($_path, 0, strlen($_path) - 8);
                         if (file_exists($_path . $_part)) {
                             $_file = $_path . $_part;
                             break;
                         }
                     }
                 }
             }
             if (file_exists($_file)) {
                 break;
             }
         }
     }
     if ($return) {
         ob_start();
     }
     $_arguments = array($wp_query->query_vars);
     if (isset($arguments) && !empty($arguments)) {
         array_push($_arguments, $arguments);
     }
     foreach ($_arguments as $_object) {
         foreach ($_object as $_key => $_value) {
             ${$_key} = $_value;
         }
     }
     $_file = apply_filters('piklist_render', $_file, $view, $arguments);
     if ($_file) {
         if ($loop && self::is_associative_array($arguments[$loop])) {
             $_depth = 1;
             foreach ($arguments[$loop] as $_key => $_value) {
                 $_depth = is_array($_value) ? count($_value) > $_depth ? count($_value) : $_depth : 1;
             }
             for ($i = 0; $i < $_depth; $i++) {
                 $_loop = array();
                 foreach ($arguments[$loop] as $_key => $_value) {
                     $_loop[$_key] = isset($_value[$i]) ? $_value[$i] : null;
                 }
                 ${$loop} = $_loop;
                 include $_file;
             }
         } elseif ($loop) {
             for ($i = 0; $i < count($arguments[$loop]); $i++) {
                 ${$loop} = $arguments[$loop][$i];
                 include $_file;
             }
         } elseif (file_exists($_file)) {
             include $_file;
         }
     }
     if ($return) {
         $output = ob_get_contents();
         ob_end_clean();
         return $output;
     }
 }
    static function Display()
    {
        global $wpdb;
        wpfb_loadclass('Admin', 'Output');
        WPFB_Core::PrintJS();
        // prints wpfbConf.ajurl
        wp_register_script('jquery-imagepicker', WPFB_PLUGIN_URI . 'extras/jquery/image-picker/image-picker.min.js', array('jquery'), WPFB_VERSION);
        wp_register_style('jquery-imagepicker', WPFB_PLUGIN_URI . 'extras/jquery/image-picker/image-picker.css', array(), WPFB_VERSION);
        if (!current_user_can('manage_options')) {
            wp_die(__('Cheatin&#8217; uh?') . '<!-- manage_options -->');
        }
        // nonce and referer check (security)
        if ((!empty($_POST['reset']) || !empty($_POST['submit'])) && !check_admin_referer('wpfb-update-settings', 'wpfb-nonce')) {
            wp_die(__('Cheatin&#8217; uh?'));
        }
        $post = stripslashes_deep($_POST);
        $action = !empty($post['action']) ? $post['action'] : (!empty($_GET['action']) ? $_GET['action'] : '');
        $messages = array();
        $errors = array();
        $options = get_option(WPFB_OPT_NAME);
        $option_fields = WPFB_Admin::SettingsSchema();
        if (isset($post['reset'])) {
            // keep templates
            $file_tpl = WPFB_Core::$settings->template_file;
            $cat_tpl = WPFB_Core::$settings->template_cat;
            wpfb_loadclass('Setup');
            WPFB_Setup::ResetOptions();
            WPFB_Core::UpdateOption('template_file', $file_tpl);
            WPFB_Core::UpdateOption('template_cat', $cat_tpl);
            $new_options = get_option(WPFB_OPT_NAME);
            $messages = array_merge($messages, WPFB_Admin::SettingsUpdated($options, $new_options));
            unset($new_options);
            $messages[] = __('Settings reseted.', WPFB);
            $options = get_option(WPFB_OPT_NAME);
        } elseif (isset($post['submit'])) {
            // cleanup
            foreach ($option_fields as $opt_tag => $opt_data) {
                if (isset($post[$opt_tag])) {
                    if (!is_array($post[$opt_tag])) {
                        $post[$opt_tag] = trim($post[$opt_tag]);
                    }
                    switch ($opt_data['type']) {
                        case 'number':
                            $post[$opt_tag] = intval($post[$opt_tag]);
                            break;
                        case 'select':
                            // check if value is in options array, if not set to default
                            if (!in_array($post[$opt_tag], array_keys($opt_data['options']))) {
                                $post[$opt_tag] = $opt_data['default'];
                            }
                            break;
                        case 'roles':
                            $post[$opt_tag] = array_values(array_filter($post[$opt_tag]));
                            // the following must not be removed! if the roles array is empty, permissions are assumed to be set for everyone!
                            // so make sure that the admin is explicitly set!
                            if (!empty($opt_data['not_everyone']) && !in_array('administrator', $post[$opt_tag])) {
                                if (!is_array($post[$opt_tag])) {
                                    $post[$opt_tag] = array();
                                }
                                array_unshift($post[$opt_tag], 'administrator');
                            }
                            break;
                        case 'cat':
                            $post[$opt_tag] = empty($post[$opt_tag]) || is_null($cat = WPFB_Category::GetCat($post[$opt_tag])) ? 0 : intval($post[$opt_tag]);
                            break;
                    }
                }
            }
            $post['upload_path'] = str_replace(ABSPATH, '', $post['upload_path']);
            $options['upload_path'] = str_replace(ABSPATH, '', $options['upload_path']);
            $post['download_base'] = trim($post['download_base'], '/');
            if (WPFB_Admin::WPCacheRejectUri($post['download_base'] . '/', $options['download_base'] . '/')) {
                $messages[] = sprintf(__('/%s/ added to rejected URIs list of WP Super Cache.', WPFB), $post['download_base']);
            }
            $tpl_file = $post['template_file'];
            $tpl_cat = $post['template_cat'];
            if (!empty($tpl_file) && (empty($options['template_file_parsed']) || $tpl_file != $options['template_file'])) {
                wpfb_loadclass('TplLib');
                $tpl_file = WPFB_TplLib::Parse($tpl_file);
                $result = WPFB_TplLib::Check($tpl_file);
                if (!$result['error']) {
                    $options['template_file_parsed'] = $tpl_file;
                    $messages[] = __('File template successfully parsed.', WPFB);
                } else {
                    $errors[] = sprintf(__('Could not parse template: error (%s) in line %s.', WPFB), $result['msg'], $result['line']);
                }
            }
            if (!empty($tpl_cat) && (empty($options['template_cat_parsed']) || $tpl_cat != $options['template_cat'])) {
                wpfb_loadclass('TplLib');
                $tpl_cat = WPFB_TplLib::Parse($tpl_cat);
                $result = WPFB_TplLib::Check($tpl_cat);
                if (!$result['error']) {
                    $options['template_cat_parsed'] = $tpl_cat;
                    $messages[] = __('Category template successfully parsed.', WPFB);
                } else {
                    $errors[] = sprintf(__('Could not parse template: error (%s) in line %s.', WPFB), $result['msg'], $result['line']);
                }
            }
            $fb_sub_pages = get_pages(array('child_of' => $options['file_browser_post_id']));
            if ($options['file_browser_post_id'] > 0 && count($fb_sub_pages)) {
                $messages[] = sprintf(__('Warning: The Filebrowser page <b>%s</b> has at least one subpage <b>%s</b>. This will cause unexpected behavior, since all requests to the subpages are redirected to the File Browser Page. Please choose a Page that does not have any subpages for File Browser.', WPFB), get_the_title($post['file_browser_post_id']), get_the_title($fb_sub_pages[0]->ID));
            }
            // save options
            foreach ($option_fields as $opt_tag => $opt_data) {
                $val = isset($post[$opt_tag]) ? $post[$opt_tag] : '';
                $options[$opt_tag] = $val;
            }
            // make sure a short tag exists, if not append one
            $select_opts = array('languages', 'platforms', 'licenses', 'requirements', 'custom_fields');
            foreach ($select_opts as $opt_tag) {
                if (empty($options[$opt_tag])) {
                    $options[$opt_tag] = '';
                    continue;
                }
                $lines = explode("\n", $options[$opt_tag]);
                $lines2 = array();
                for ($i = 0; $i < count($lines); $i++) {
                    $lines[$i] = str_replace('||', '|', trim($lines[$i], "|\r"));
                    if (empty($lines[$i]) || $lines[$i] == '|') {
                        continue;
                    }
                    $pos = strpos($lines[$i], '|');
                    if ($pos <= 0) {
                        $lines[$i] .= '|' . sanitize_key(substr($lines[$i], 0, min(8, strlen($lines[$i]))));
                    }
                    $lines2[] = $lines[$i];
                }
                $options[$opt_tag] = implode("\n", $lines2);
            }
            $old_options = get_option(WPFB_OPT_NAME);
            update_option(WPFB_OPT_NAME, $options);
            WPFB_Core::$settings = (object) $options;
            $messages = array_merge($messages, WPFB_Admin::SettingsUpdated($old_options, $options));
            if (count($errors) == 0) {
                $messages[] = __('Settings updated.', WPFB);
            }
            //refresh any description which can contain opt values
            $option_fields = WPFB_Admin::SettingsSchema();
        }
        if (WPFB_Core::$settings->allow_srv_script_upload) {
            $messages[] = __('WARNING: Script upload enabled!', WPFB);
        }
        $upload_path = WPFB_Core::$settings->upload_path;
        if (!empty($old_options) && path_is_absolute($upload_path) && !path_is_absolute($old_options['upload_path'])) {
            $rel_path = str_replace('\\', '/', $upload_path);
            $rel_path = substr($rel_path, strpos($rel_path, '/') + 1);
            $messages[] = __(sprintf('NOTICE: The upload path <code>%s</code> is rooted to the filesystem. You should remove the leading slash if you want to use a folder inside your Wordpress directory (i.e: <code>%s</code>)', $upload_path, $rel_path), WPFB);
        }
        $action_uri = admin_url('admin.php') . '?page=' . $_GET['page'] . '&amp;updated=true';
        if (!empty($messages)) {
            $message = '';
            foreach ($messages as $msg) {
                $message .= '<p>' . $msg . '</p>';
            }
            ?>
<div id="message" class="updated fade"><?php 
            echo $message;
            ?>
</div>
<?php 
        }
        if (!empty($errors)) {
            $error = '';
            foreach ($errors as $err) {
                $error .= '<p>' . $err . '</p>';
            }
            ?>
<div id="message" class="error fade"><?php 
            echo $error;
            ?>
</div>
<?php 
        }
        ?>
<script type="text/javascript">
/* Option tabs */
jQuery(document).ready( function() {
	try { jQuery('#wpfb-tabs').tabs(); }
	catch(ex) {}
	/*if(typeof(CKEDITOR) != 'undefined') {
		CKEDITOR.plugins.addExternal('wpfilebase', ajaxurl+'/../../wp-content/plugins/wp-filebase/extras/ckeditor/');
		alert( ajaxurl+'/../../wp-content/plugins/wp-filebase/extras/ckeditor/');
	}*/
});
</script>

<div class="wrap">
<div id="icon-options-general" class="icon32"><br /></div>
<h2><?php 
        echo WPFB_PLUGIN_NAME;
        echo ' ';
        _e("Settings");
        ?>
</h2>

<form method="post" action="<?php 
        echo $action_uri;
        ?>
" name="wpfilebase-options">
	<?php 
        wp_nonce_field('wpfb-update-settings', 'wpfb-nonce');
        ?>
	<p class="submit">
	<input type="submit" name="submit" value="<?php 
        _e('Save Changes');
        ?>
" class="button-primary" />
	</p>
	<?php 
        $misc_tags = array('disable_id3', 'search_id3', 'thumbnail_path', 'use_path_tags', 'no_name_formatting');
        if (function_exists('wp_admin_bar_render')) {
            $misc_tags[] = 'admin_bar';
        }
        $limits = array('bitrate_unregistered', 'bitrate_registered', 'traffic_day', 'traffic_month', 'traffic_exceeded_msg', 'file_offline_msg', 'daily_user_limits', 'daily_limit_subscriber', 'daily_limit_contributor', 'daily_limit_author', 'daily_limit_editor', 'daily_limit_exceeded_msg');
        $option_categories = array(__('Common', WPFB) => array('upload_path', 'search_integration'), __('Display', WPFB) => array('file_date_format', 'thumbnail_size', 'auto_attach_files', 'attach_loop', 'attach_pos', 'filelist_sorting', 'filelist_sorting_dir', 'filelist_num', 'decimal_size_format', 'search_result_tpl', 'disable_css'), __('File Browser', WPFB) => array('file_browser_post_id', 'file_browser_cat_sort_by', 'file_browser_cat_sort_dir', 'file_browser_file_sort_by', 'file_browser_file_sort_dir', 'file_browser_fbc', 'late_script_loading', 'folder_icon', 'small_icon_size', 'disable_footer_credits', 'footer_credits_style'), __('Download', WPFB) => array('hide_links', 'disable_permalinks', 'download_base', 'force_download', 'range_download', 'http_nocache', 'ignore_admin_dls', 'accept_empty_referers', 'allowed_referers', 'use_fpassthru'), __('Form Presets', WPFB) => array('default_author', 'default_roles', 'default_cat', 'default_direct_linking', 'languages', 'platforms', 'licenses', 'requirements', 'custom_fields'), __('Limits', WPFB) => $limits, __('Security', WPFB) => array('allow_srv_script_upload', 'fext_blacklist', 'frontend_upload', 'hide_inaccessible', 'inaccessible_msg', 'inaccessible_redirect', 'cat_inaccessible_msg', 'login_redirect_src', 'protect_upload_path', 'private_files'), __('Templates and Scripts', WPFB) => array('template_file', 'template_cat', 'dlclick_js'), __('Sync', WPFB) => array('cron_sync', 'base_auto_thumb', 'remove_missing_files', 'fake_md5'), __('Misc') => $misc_tags);
        ?>
	<div id="wpfb-tabs">
		<ul class="wpfb-tab-menu">
			<?php 
        foreach ($option_categories as $key => $val) {
            echo '<li><a href="#' . sanitize_title($key) . '">' . esc_html($key) . '</a></li>';
        }
        ?>
		</ul>
	<?php 
        $page_option_list = '';
        $n = 0;
        foreach ($option_categories as $opt_cat => $opt_cat_fields) {
            //echo "\n".'<h3>'.$opt_cat.'</h3>';
            echo "\n\n" . '<div id="' . sanitize_title($opt_cat) . '" class="wpfilebase-opttab"><h3>' . $opt_cat . '</h3><table class="form-table">';
            foreach ($opt_cat_fields as $opt_tag) {
                $field_data = $option_fields[$opt_tag];
                $opt_val = $options[$opt_tag];
                echo "\n" . '<tr valign="top">' . "\n" . '<th scope="row">' . $field_data['title'] . '</th>' . "\n" . '<td>';
                $style_class = '';
                if (!empty($field_data['class'])) {
                    $style_class .= ' class="' . $field_data['class'] . '"';
                }
                if (!empty($field_data['style'])) {
                    $style_class .= ' style="' . $field_data['style'] . '"';
                }
                switch ($field_data['type']) {
                    case 'text':
                    case 'number':
                    case 'checkbox':
                        echo '<input name="' . $opt_tag . '" type="' . $field_data['type'] . '" id="' . $opt_tag . '"';
                        echo !empty($field_data['class']) ? ' class="' . $field_data['class'] . '"' : '';
                        if ($field_data['type'] == 'checkbox') {
                            echo ' value="1" ';
                            checked('1', $opt_val);
                        } elseif ($field_data['type'] == 'number') {
                            echo ' value="' . intval($opt_val) . '" size="5" style="text-align: right"';
                        } else {
                            echo ' value="' . esc_attr($opt_val) . '"';
                            if (isset($field_data['size'])) {
                                echo ' size="' . (int) $field_data['size'] . '"';
                            }
                        }
                        echo $style_class . ' />';
                        break;
                    case 'textarea':
                        $code_edit = strpos($opt_tag, 'template_') !== false || isset($field_data['class']) && strpos($field_data['class'], 'code') !== false;
                        $nowrap = !empty($field_data['nowrap']);
                        echo '<textarea name="' . $opt_tag . '" id="' . $opt_tag . '"';
                        if ($nowrap || $code_edit) {
                            echo ' cols="100" wrap="off" style="width: 100%;' . ($code_edit ? 'font-size: 9px;' : '') . '"';
                        } else {
                            echo ' cols="50"';
                        }
                        echo ' rows="' . ($code_edit ? 20 : 5) . '"';
                        echo $style_class;
                        echo '>';
                        echo esc_html($opt_val);
                        echo '</textarea>';
                        break;
                    case 'select':
                        echo '<select name="' . $opt_tag . '" id="' . $opt_tag . '">';
                        foreach ($field_data['options'] as $opt_v => $opt_n) {
                            echo '<option value="' . esc_attr($opt_v) . '"' . ($opt_v == $opt_val ? ' selected="selected" ' : '') . $style_class . '>' . (!is_numeric($opt_v) && $opt_v !== $opt_n ? esc_html($opt_v) . ': ' : '') . esc_html($opt_n) . '</option>';
                        }
                        echo '</select>';
                        break;
                    case 'roles':
                        WPFB_Admin::RolesCheckList($opt_tag, $opt_val, empty($field_data['not_everyone']));
                        break;
                    case 'icon':
                        wp_print_scripts('jquery-imagepicker');
                        wp_print_styles('jquery-imagepicker');
                        echo '<select class="image-picker show-html" name="' . $opt_tag . '" id="' . $opt_tag . '">';
                        ?>
						<?php 
                        foreach ($field_data['icons'] as $icon) {
                            echo '<option data-img-src="' . $icon['url'] . '" value="' . $icon['path'] . '" ' . ($icon['path'] === $opt_val ? ' selected="selected" ' : '') . '>' . basename($icon['path']) . '</option>';
                        }
                        ?>
					</select>
					<script type="text/javascript">
					jQuery(document).ready( function() { jQuery("#<?php 
                        echo $opt_tag;
                        ?>
").imagepicker(); });
					</script>
					<?php 
                        break;
                    case 'cat':
                        echo "<select name='{$opt_tag}' id='{$opt_tag}'>";
                        echo WPFB_Output::CatSelTree(array('selected' => $opt_val));
                        echo "</select>";
                        break;
                }
                if (!empty($field_data['unit'])) {
                    echo ' ' . $field_data['unit'];
                }
                if (!empty($field_data['desc'])) {
                    echo "\n" . '<br />' . str_replace('%value%', is_array($opt_val) ? join(', ', $opt_val) : $opt_val, $field_data['desc']);
                }
                echo "\n</td>\n</tr>";
                $page_option_list .= $opt_tag . ',';
            }
            echo '</table></div>' . "\n";
        }
        ?>
</div> <!--wpfilebase-opttabs-->
	<input type="hidden" name="action" value="update" />
	<input type="hidden" name="page_options" value="<?php 
        echo $page_option_list;
        ?>
" />
	<p class="submit">
	<input type="submit" name="submit" value="<?php 
        _e('Save Changes');
        ?>
" class="button-primary" />
	<input type="submit" name="reset" value="<?php 
        _e('Restore Default Settings', WPFB);
        ?>
" onclick="return confirm('<?php 
        _e('All settings (except default file and category template) will be set to default values. Continue?', WPFB);
        ?>
')" class="button delete" style="float: right;" />
	</p>
</form>
</div>	<!-- wrap -->	
<?php 
    }
Example #5
0
/**
 * Return a base64 encoded SVG icon for use as a data URI.
 *
 * @since 1.4.3
 *
 * @param string $path Path to SVG icon.
 * @return string
 */
function audiotheme_encode_svg($path)
{
    $path = path_is_absolute($path) ? $path : AUDIOTHEME_DIR . $path;
    if (!file_exists($path) || 'svg' !== pathinfo($path, PATHINFO_EXTENSION)) {
        return '';
    }
    return 'data:image/svg+xml;base64,' . base64_encode(file_get_contents($path));
}
 public function scan($no_echo)
 {
     $string_settings = apply_filters('wpml_get_setting', false, 'st');
     if (isset($_POST['wpml_st_theme_localization_type_wpml_td']) && $_POST['wpml_st_theme_localization_type_wpml_td']) {
         $string_settings['use_header_text_domains_when_missing'] = 1;
     } else {
         $string_settings['use_header_text_domains_when_missing'] = 0;
     }
     do_action('wpml_set_setting', 'st', $string_settings, true);
     $this->current_plugin_file = null;
     $this->current_type = 'plugin';
     set_time_limit(0);
     if (preg_replace('#M$#', '', ini_get('memory_limit')) < 128) {
         ini_set('memory_limit', '128M');
     }
     $plugins = array();
     if (!empty($_POST['plugin'])) {
         foreach ($_POST['plugin'] as $plugin) {
             $plugins[] = array('file' => $plugin, 'mu' => 0);
             // regular plugins
         }
     }
     if (!empty($_POST['mu-plugin'])) {
         foreach ($_POST['mu-plugin'] as $plugin) {
             $plugins[] = array('file' => $plugin, 'mu' => 1);
             //mu plugins
         }
     }
     foreach ($plugins as $p) {
         $plugin = $p['file'];
         $this->current_plugin_file = $p['file'];
         $this->scan_starting($plugin);
         if (false !== strpos($plugin, '/') && !$p['mu']) {
             $plugin = dirname($plugin);
         }
         if (!path_is_absolute($plugin)) {
             if ($p['mu']) {
                 $plugin_path = WPMU_PLUGIN_DIR . '/' . $plugin;
                 $this->current_plugin_file = WPMU_PLUGIN_DIR . '/' . $p['file'];
             } else {
                 $plugin_path = WP_PLUGIN_DIR . '/' . $plugin;
                 $this->current_plugin_file = WP_PLUGIN_DIR . '/' . $p['file'];
             }
         } else {
             $this->current_plugin_file = $p['file'];
             $plugin_path = $plugin;
         }
         if (wpml_st_file_path_is_valid($plugin_path) && wpml_st_file_path_is_valid($this->current_plugin_file)) {
             $this->current_path = $plugin_path;
             $text_domain = $this->get_plugin_text_domain();
             $this->init_text_domain($text_domain);
             $this->add_stat(PHP_EOL . sprintf(__('Scanned files from %s:', 'wpml-string-translation'), $plugin));
             $this->scan_plugin_files();
             $this->current_type = 'plugin';
             if (isset($_POST['icl_load_mo']) && $_POST['icl_load_mo'] && !$p['mu']) {
                 $this->add_translations(array_keys($this->get_domains_found()), '');
             }
             $this->copy_old_translations(array_keys($this->get_domains_found()), 'plugin');
             $this->cleanup_wrong_contexts();
             $string_settings = apply_filters('wpml_get_setting', false, 'st');
             $string_settings['plugin_localization_domains'][$p['file']] = $this->get_domains_found();
             do_action('wpml_set_setting', 'st', $string_settings, true);
         } else {
             $this->add_stat(sprintf(__('Invalid file: %s', 'wpml-string-translation'), "/" . $plugin_path));
         }
     }
     $this->add_scan_stat_summary();
     if ($this->current_plugin_file) {
         $plugin_data = get_plugin_data($this->current_plugin_file);
         if ($plugin_data && !is_wp_error($plugin_data)) {
             $this->remove_notice($plugin_data['Name']);
         }
     }
     if (!$no_echo) {
         $this->scan_response();
     }
 }
Example #7
0
 /**
  * path_is_absolute
  * Determine whether a path is relative or absolute
  *
  * @param string $path path to check
  *
  * @return bool
  *
  * @access public
  * @static
  * @since 1.0
  */
 public static function path_is_absolute($path)
 {
     return path_is_absolute($path) || 1 === preg_match('~^[a-z]+://~i', $path);
 }
Example #8
0
 /**
  * Finds out if a path is a subdirectory of another path.
  *
  * @param  string  $dir The absolute path that might be a subdirectory.
  * @param  string  $of  The absolute path to check against.
  * @return boolean      Returns TRUE if the path is a subdirectory, FALSE otherwise.
  */
 function is_subdir($dir, $of)
 {
     if (!@is_dir($dir) || !@is_dir($of)) {
         return false;
     }
     if (!path_is_absolute($dir) || !path_is_absolute($of)) {
         return false;
     }
     if (0 === strpos($dir, $of)) {
         return true;
     }
     return false;
 }
Example #9
0
 			Does the download contain the wpurl or url? */
 if ($localURI) {
     // the URI is local, replace the WordPress url OR blog url with WordPress's absolute path.
     //$patterns = array( '|^'. get_bloginfo('wpurl') . '/' . '|', '|^'. get_bloginfo('url') . '/' . '|');
     $patterns = array('|^' . get_bloginfo('wpurl') . '/' . '|');
     $path = preg_replace($patterns, '', $thefile);
     // account for multisite/network installations since they each have their own upload directory
     if (is_multisite() && $blog_id != 1) {
         // Main site uses the "standard" upload directory so leave that as-is
         $path = '/wp-content/blogs.dir/' . $blog_id . '/' . $path;
     }
     // this is joining the ABSPATH constant, changing any slashes to local filesystem slashes, and then finally getting the real path.
     $thefile = str_replace('/', DIRECTORY_SEPARATOR, path_join(ABSPATH, $path));
     // Local File System path
 } else {
     if (!path_is_absolute($thefile)) {
         //$thefile = path_join( ABSPATH, $thefile );
         // Get the absolute path
         if (!isset($_SERVER['DOCUMENT_ROOT'])) {
             $_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen($_SERVER['PHP_SELF'])));
         }
         // Now substitute the domain for the absolute path in the file url
         $thefile = str_replace('/', DIRECTORY_SEPARATOR, path_join($_SERVER['DOCUMENT_ROOT'], $thefile));
     }
 }
 // If the path wasn't a URI and not absolute, then it made it all the way to here without manipulation, so now we do this...
 // By the way, realpath() returns NOTHING if is does not exist.
 $testfile = realpath($thefile);
 // now do a long condition check, it should not be emtpy, a directory, and should be readable.
 $willDownload = empty($testfile) ? false : !is_file($testfile) ? false : is_readable($testfile);
 if (!$willDownload) {
Example #10
0
 /**
  * Inject static code/markup
  *
  * @return string
  */
 public function export()
 {
     // the code that will be returned
     $code = null;
     // handle callbacks
     if ($this->has_callbacks()) {
         // loop em
         foreach ($this->callbacks as $callback) {
             // execute callback with myself as only argument
             call_user_func($callback, $this);
         }
     }
     // have any files?
     if ($this->files_export->count()) {
         // loop through all files
         foreach ($this->files_export as $file) {
             // resolve file path
             if (path_is_absolute($file)) {
                 // its absolute already, which is good
                 $filename = $file;
             } else {
                 // relative path, need to locate it
                 $filename = $this->component()->locate_file($file);
             }
             // only import each file once!
             if (self::$files_imported->contains($filename)) {
                 // already imported that one
                 continue;
             } else {
                 // push it on to imported stack
                 self::$files_imported->push($filename);
             }
             // inject helpful comment ;)
             //$code .= '/*+++ import source: ' . $filename . ' */' . PHP_EOL;
             // make sure file actually exists
             if (ICE_Files::cache($filename)->is_readable()) {
                 // get entire contents of file
                 $code .= $this->get_file_contents($filename) . PHP_EOL;
                 // success
                 //$code .= '/*--- import complete! */' . PHP_EOL . PHP_EOL;
             } else {
                 //$code .= '/*!!! import failed! */' . PHP_EOL . PHP_EOL;
             }
         }
     }
     // handle strings
     if ($this->has_strings()) {
         //$code .= '/*--- importing strings */' . PHP_EOL;
         $code .= implode(PHP_EOL, $this->strings->to_array()) . str_repeat(PHP_EOL, 2);
         //$code .= '/*!!! importing strings complete */' . PHP_EOL;
     }
     // all done
     return $code;
 }
Example #11
0
 /**
  * Returns image metadata.
  *
  * NOTE: The image must be within the WP_CONTENT/UPLOADS folder or within the STYLESHEETPATH folder.
  *
  * @access public
  * @since  8.1.2
  * @static
  *
  * @param  string $source URL or absolute path to an image.
  *
  * @return mixed          array | object An associative array of image meta or an instance of WP_Error.
  */
 public static function info($source)
 {
     // Define upload path & dir.
     $upload_info = cnUpload::info();
     $theme_url = get_stylesheet_directory_uri();
     $theme_dir = get_stylesheet_directory();
     if (path_is_absolute($source)) {
         // Ensure the supplied path is in either the WP_CONTENT/UPLOADS directory or
         // the STYLESHEETPATH directory.
         if (strpos($source, $upload_info['base_path']) !== FALSE || strpos($source, $theme_dir) !== FALSE) {
             $img_path = $source;
         } else {
             $img_path = FALSE;
         }
     } else {
         // find the path of the image. Perform 2 checks:
         // #1 check if the image is in the uploads folder
         if (strpos($source, $upload_info['base_url']) !== FALSE) {
             $rel_path = str_replace($upload_info['base_url'], '', $source);
             $img_path = $upload_info['base_path'] . $rel_path;
             // #2 check if the image is in the current theme folder
         } else {
             if (strpos($source, $theme_url) !== FALSE) {
                 $rel_path = str_replace($theme_url, '', $source);
                 $img_path = $theme_dir . $rel_path;
             }
         }
     }
     // Fail if we can't find the image in our WP local directory
     if (empty($img_path) || !@file_exists($img_path)) {
         if (empty($img_path)) {
             return new WP_Error('image_path_not_set', esc_html__('The $img_path variable has not been set.', 'connections'));
         } else {
             return new WP_Error('image_path_not_found', __(sprintf('Image path %s does not exist.', $img_path), 'connections'), $img_path);
         }
     }
     // Check if img path exists, and is an image.
     if (($image_info = getimagesize($img_path)) === FALSE) {
         return new WP_Error('image_not_image', __(sprintf('The file %s is not an image.', basename($img_path)), 'connections'), basename($img_path));
     }
     $image_info['path'] = $img_path;
     $image_info['modified'] = filemtime($img_path);
     $image_info = array_merge(pathinfo($img_path), $image_info);
     return $image_info;
 }
Example #12
0
    static function Display()
    {
        global $wpdb, $user_ID;
        wpfb_loadclass('Admin', 'Output');
        $_POST = stripslashes_deep($_POST);
        $_GET = stripslashes_deep($_GET);
        $action = !empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : '');
        $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync'));
        // keep search keyword
        ?>
	<div class="wrap">
	<?php 
        $upload_path = WPFB_Core::$settings->upload_path;
        if (path_is_absolute($upload_path)) {
            echo '<div class="updated fade"><p>';
            printf(__('Custom CSS does only work if upload path is relative to WordPress path. It is currently set to <code>%s</code>, so <b>custom CSS will not work!</b>', WPFB), $upload_path);
            echo "</p></div>";
        }
        switch ($action) {
            default:
                if (!current_user_can('edit_themes')) {
                    wp_die(__('Cheatin&#8217; uh?'));
                }
                // try to use default wp upload path
                $wp_upload = wp_upload_dir();
                $wp_upload_ok = empty($wp_upload['error']) && is_writable($wp_upload['basedir']);
                // if no file at wp upload, fallback to Old custom css path
                $css_path_edit = $wp_upload_ok && (is_file($wp_upload['basedir'] . '/wp-filebase.css') || !empty($_POST['newcontent'])) ? $wp_upload['basedir'] . '/wp-filebase.css' : WPFB_Core::GetOldCustomCssPath();
                $css_path_default = WPFB_PLUGIN_ROOT . 'wp-filebase.css';
                $exists = file_exists($css_path_edit) && is_file($css_path_edit);
                if ($exists && !is_writable($css_path_edit) || !$exists && !is_writable(dirname($css_path_edit))) {
                    ?>
<div class="error default-password-nag"><p><?php 
                    printf(__('%s is not writable!', WPFB), $css_path_edit);
                    ?>
</p></div><?php 
                    break;
                }
                if (!empty($_POST['restore_default'])) {
                    update_option('wpfb_css', WPFB_PLUGIN_URI . 'wp-filebase.css?t=' . time());
                    @unlink($css_path_edit);
                    $exists = false;
                } elseif (!empty($_POST['submit']) && !empty($_POST['newcontent'])) {
                    // write
                    $newcontent = stripslashes($_POST['newcontent']);
                    $newcontent = self::MakeCssUrlsAbsolute($newcontent);
                    $exists = file_put_contents($css_path_edit, $newcontent) !== false;
                    update_option('wpfb_css', $wp_upload_ok ? $wp_upload['baseurl'] . '/wp-filebase.css?t=' . time() : false);
                }
                $fpath = $exists ? $css_path_edit : $css_path_default;
                $content = esc_html(file_get_contents($fpath));
                ?>
<form name="csseditor" id="csseditor" action="<?php 
                echo $clean_uri;
                ?>
&amp;action=edit_css" method="post">
		 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress css" style="width: 98%;"><?php 
                echo $content;
                ?>
</textarea>
		 <input type="hidden" name="action" value="edit_css" />
		<p class="submit">
		<?php 
                echo "<input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File', WPFB) . "' tabindex='2' />";
                ?>
		<?php 
                if ($exists) {
                    echo "<input type='submit' name='restore_default' class='button' onclick=\"return confirm('Sure?')\" value='" . esc_attr__('Restore Default', WPFB) . "' tabindex='3' />";
                }
                ?>
		</p>
		</div>
</form>
<?php 
                break;
                // edit_css
        }
        ?>
</div> <!-- wrap -->
<?php 
    }
 function get_size()
 {
     global $wpdb, $wp_dlm_db_meta;
     $thefile = $this->filename;
     $urlparsed = parse_url($thefile);
     $isURI = array_key_exists('scheme', $urlparsed);
     $localURI = (bool) strstr($thefile, get_bloginfo('wpurl'));
     /* Local TO WORDPRESS!! */
     $filesize = '';
     if ($isURI && $localURI || !$isURI && !$localURI) {
         if ($localURI) {
             // the URI is local, replace the WordPress url OR blog url with WordPress's absolute path.
             //$patterns = array( '|^'. get_bloginfo('wpurl') . '/' . '|', '|^'. get_bloginfo('url') . '/' . '|');
             $patterns = array('|^' . get_bloginfo('wpurl') . '/' . '|');
             $path = preg_replace($patterns, '', $thefile);
             // this is joining the ABSPATH constant, changing any slashes to local filesystem slashes, and then finally getting the real path.
             $thefile = str_replace('/', DIRECTORY_SEPARATOR, path_join(ABSPATH, $path));
             if (@file_exists($thefile)) {
                 $filesize = filesize($thefile);
             }
             // Local File System path
         } elseif (!path_is_absolute($thefile)) {
             //$thefile = path_join( ABSPATH, $thefile );
             // Get the absolute path
             if (!isset($_SERVER['DOCUMENT_ROOT'])) {
                 $_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen($_SERVER['PHP_SELF'])));
             }
             $dir_path = $_SERVER['DOCUMENT_ROOT'];
             // Now substitute the domain for the absolute path in the file url
             $thefile = str_replace('/', DIRECTORY_SEPARATOR, path_join($dir_path, $thefile));
             if (@file_exists($thefile)) {
                 $filesize = filesize($thefile);
             }
         } else {
             if (@file_exists($thefile)) {
                 $filesize = filesize($thefile);
             }
         }
     } elseif ($isURI && ini_get('allow_url_fopen')) {
         // Absolute path outside of wordpress
         if (!function_exists('remote_filesize')) {
             function remote_filesize($url)
             {
                 ob_start();
                 $ch = curl_init($url);
                 curl_setopt($ch, CURLOPT_HEADER, 1);
                 curl_setopt($ch, CURLOPT_NOBODY, 1);
                 $ok = curl_exec($ch);
                 curl_close($ch);
                 $head = ob_get_contents();
                 ob_end_clean();
                 $regex = '/Content-Length:\\s([0-9].+?)\\s/';
                 $count = preg_match($regex, $head, $matches);
                 return isset($matches[1]) ? $matches[1] : "";
             }
         }
         $isHTTP = (bool) ($urlparsed['scheme'] == 'http' || $urlparsed['scheme'] == 'https');
         if (function_exists('get_headers') && $isHTTP) {
             $ary_header = @get_headers($thefile, 1);
             if (is_array($ary_header) && array_key_exists("Content-Length", $ary_header)) {
                 $filesize = $ary_header["Content-Length"];
             }
         } else {
             if (function_exists('curl_init')) {
                 $filesize = remote_filesize($thefile);
                 // I wonder, is this returning something non-numeric?
             } else {
                 $filesize = @filesize($thefile);
             }
         }
     }
     if ($filesize && is_numeric($filesize)) {
         $bytes = array('bytes', 'kB', 'MB', 'GB', 'TB');
         foreach ($bytes as $val) {
             if ($filesize > 1024) {
                 $filesize = $filesize / 1024;
             } else {
                 break;
             }
         }
         $this->size = round($filesize, 2) . " " . $val;
         // Add to DB for quick loading in future
         $wpdb->query("INSERT INTO {$wp_dlm_db_meta} (meta_name, meta_value, download_id) VALUES ('filesize', '" . $wpdb->escape($this->size) . "', '" . $this->id . "')");
     } else {
         // Could not get size, but insert anyway to prevent slow page loads
         $wpdb->query("INSERT INTO {$wp_dlm_db_meta} (meta_name, meta_value, download_id) VALUES ('filesize', '', '" . $this->id . "')");
     }
 }
Example #14
0
/**
 * Get the first found less file
 * Checks child theme first, then parent
 *
 * @since	2.4.6
 * 
 * @param  [type] $filename [description]
 * @return [type]           [description]
 */
function pl_locate_less($filename)
{
    if (path_is_absolute($filename) && file_exists($filename)) {
        return $filename;
    } else {
        return locate_template(array("less/{$filename}", "less/{$filename}.less"));
    }
}
Example #15
0
 static function InitClass()
 {
     self::$ajax_url = admin_url('admin-ajax.php?action=wpfilebase');
     self::$ajax_url_public = home_url('/?wpfilebase_ajax=1');
     if (defined('WPFB_NO_CORE_INIT')) {
         return;
     }
     // on activation
     self::$settings = (object) get_option(WPFB_OPT_NAME);
     // load lang
     $lang_dir = defined('WPFB_LANG_DIR') ? '../../' . WPFB_LANG_DIR : basename(WPFB_PLUGIN_ROOT) . '/languages';
     load_plugin_textdomain('wp-filebase', false, $lang_dir);
     add_action('parse_query', array(__CLASS__, 'ParseQuery'));
     // search
     add_action('wp_enqueue_scripts', array(__CLASS__, 'EnqueueScripts'));
     add_action('wp_footer', array(__CLASS__, 'Footer'));
     add_action('generate_rewrite_rules', array(__CLASS__, 'GenRewriteRules'));
     add_action(WPFB . '_cron', array(__CLASS__, 'Cron'));
     add_action('wpfilebase_sync', array(__CLASS__, 'Sync'));
     // for Developers: New wp-filebase actions
     add_action('wp_ajax_nopriv_wpfilebase', array(__CLASS__, 'AjaxPublic'));
     add_action('wp_ajax_wpfilebase', array(__CLASS__, 'AjaxAdmin'));
     add_shortcode('wpfilebase', array(__CLASS__, 'ShortCode'));
     // for attachments and file browser
     add_filter('the_content', array(__CLASS__, 'ContentFilter'), 10);
     // must be lower than 11 (before do_shortcode) and after wpautop (>9)
     add_filter('ext2type', array(__CLASS__, 'Ext2TypeFilter'));
     add_filter('pre_set_site_transient_update_plugins', array(__CLASS__, 'PreSetPluginsTransientFilter'));
     add_filter('plugins_api', array(__CLASS__, 'PluginsApiFilter'), 10, 3);
     // register treeview stuff
     wp_register_script('jquery-treeview', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.js', array('jquery'), WPFB_VERSION);
     wp_register_script('jquery-treeview-edit', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.edit.js', array('jquery-treeview'), WPFB_VERSION);
     wp_register_script('jquery-treeview-async', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.async.js', array('jquery-treeview-edit'), WPFB_VERSION);
     wp_register_style('jquery-treeview', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.css', array(), WPFB_VERSION);
     // DataTables
     wp_register_script('jquery-dataTables', WPFB_PLUGIN_URI . 'extras/jquery/dataTables/js/jquery.dataTables.min.js', array('jquery'), WPFB_VERSION);
     wp_register_style('jquery-dataTables', WPFB_PLUGIN_URI . 'extras/jquery/dataTables/css/jquery.dataTables.css', array(), WPFB_VERSION);
     wp_register_script('jquery-dataTables-columnFilter', WPFB_PLUGIN_URI . 'extras/jquery/dataTables/js/jquery.dataTables.columnFilter.js', array('jquery-dataTables'), WPFB_VERSION);
     wp_register_script(WPFB, WPFB_PLUGIN_URI . 'js/common.js', array('jquery'), WPFB_VERSION);
     // cond loading (see Footer)
     if (empty(WPFB_Core::$settings->disable_css)) {
         $wpfb_css = get_option('wpfb_css');
         if ($wpfb_css) {
             // static file?
             wp_enqueue_style(WPFB, strstr($wpfb_css, '//'), array(), WPFB_VERSION, 'all');
         } else {
             $upload_path = path_is_absolute(WPFB_Core::$settings->upload_path) ? '' : WPFB_Core::$settings->upload_path;
             wp_enqueue_style(WPFB, WPFB_Core::PluginUrl("wp-filebase_css.php?rp={$upload_path}"), array(), WPFB_VERSION, 'all');
         }
     }
     $wpfb_admin_page = is_admin() && !empty($_GET['page']) && strpos($_GET['page'], 'wpfilebase_') !== false || defined('WPFB_EDITOR_PLUGIN');
     if ($wpfb_admin_page) {
         wpfb_loadclass('Admin');
     }
     // live admin
     if ($wpfb_admin_page && @$_GET['page'] == 'wpfilebase_filebrowser' || (WPFB_Core::CurUserCanCreateCat() || WPFB_Core::CurUserCanUpload()) && !is_admin()) {
         wp_enqueue_script(WPFB . '-live-admin', WPFB_PLUGIN_URI . 'js/live-admin.js', array('jquery'), WPFB_VERSION);
         if (self::GetOpt('admin_bar')) {
             add_action('admin_bar_menu', array(__CLASS__, 'AdminBar'), 80);
         }
         if (self::GetOpt('file_context_menu')) {
             wp_enqueue_script('jquery-contextmenu', WPFB_PLUGIN_URI . 'extras/jquery/contextmenu/jquery.contextmenu.js', array('jquery'));
             wp_enqueue_style('jquery-contextmenu', WPFB_PLUGIN_URI . 'extras/jquery/contextmenu/jquery.contextmenu.css', array(), WPFB_VERSION);
         }
         wp_enqueue_style('wpfb-live-admin', WPFB_PLUGIN_URI . 'css/live-admin.css', array(), WPFB_VERSION);
     }
     // for admin
     if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
         self::MceAddBtns();
     }
     self::DownloadRedirect();
     if ((WPFB_Core::$settings->frontend_upload || current_user_can('upload_files')) && (!empty($_GET['wpfb_upload_file']) || !empty($_GET['wpfb_add_cat']))) {
         wpfb_call('Admin', empty($_GET['wpfb_upload_file']) ? 'ProcessWidgetAddCat' : 'ProcessWidgetUpload');
     }
     if (isset($_GET['wpfilebase_ajax'])) {
         define('DOING_AJAX', true);
         wpfb_loadclass('Ajax');
         WPFB_Ajax::PublicRequest();
     }
 }
Example #16
0
 static function InitClass()
 {
     if (defined('WPFB_NO_CORE_INIT')) {
         return;
     }
     // used with CSS proxy
     //Load settings
     self::$settings = (object) get_option(WPFB_OPT_NAME);
     // load lang
     $lang_dir = defined('WPFB_LANG_DIR') ? '../../' . WPFB_LANG_DIR : basename(WPFB_PLUGIN_ROOT) . '/languages';
     load_plugin_textdomain(WPFB, 'wp-content/plugins/' . $lang_dir, $lang_dir);
     add_action('parse_query', array(__CLASS__, 'ParseQuery'));
     // search
     add_action('wp_enqueue_scripts', array(__CLASS__, 'EnqueueScripts'));
     add_action('wp_footer', array(__CLASS__, 'Footer'));
     add_action('generate_rewrite_rules', array(__CLASS__, 'GenRewriteRules'));
     add_action(WPFB . '_cron', array(__CLASS__, 'Cron'));
     add_action('wpfilebase_sync', array(__CLASS__, 'Sync'));
     // for Developers: New wp-filebase actions
     add_shortcode('wpfilebase', array(__CLASS__, 'ShortCode'));
     // for attachments and file browser
     add_filter('the_content', array(__CLASS__, 'ContentFilter'), 10);
     // must be lower than 11 (before do_shortcode) and after wpautop (>9)
     add_filter('ext2type', array(__CLASS__, 'Ext2TypeFilter'));
     // register treeview stuff
     //wp_register_script('jquery-cookie', WPFB_PLUGIN_URI.'extras/jquery/jquery.cookie.js', array('jquery'));
     wp_register_script('jquery-treeview', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.js', array('jquery'), WPFB_VERSION);
     wp_register_script('jquery-treeview-edit', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.edit.js', array('jquery-treeview'), WPFB_VERSION);
     wp_register_script('jquery-treeview-async', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.async.js', array('jquery-treeview-edit'), WPFB_VERSION);
     wp_register_style('jquery-treeview', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.css', array(), WPFB_VERSION);
     // DataTables
     wp_register_script('jquery-dataTables', WPFB_PLUGIN_URI . 'extras/jquery/dataTables/js/jquery.dataTables.min.js', array('jquery'), WPFB_VERSION);
     wp_register_style('jquery-dataTables', WPFB_PLUGIN_URI . 'extras/jquery/dataTables/css/jquery.dataTables.css', array(), WPFB_VERSION);
     wp_register_script('jquery-dataTables-columnFilter', WPFB_PLUGIN_URI . 'extras/jquery/dataTables/js/jquery.dataTables.columnFilter.js', array('jquery-dataTables'), WPFB_VERSION);
     wp_register_script(WPFB, WPFB_PLUGIN_URI . 'js/common.js', array('jquery'), WPFB_VERSION);
     // cond loading (see Footer)
     $wpfb_css = get_option('wpfb_css');
     if ($wpfb_css) {
         // static file?
         wp_enqueue_style(WPFB, $wpfb_css, array(), WPFB_VERSION, 'all');
     } else {
         $upload_path = path_is_absolute(WPFB_Core::$settings->upload_path) ? '' : WPFB_Core::$settings->upload_path;
         wp_enqueue_style(WPFB, WPFB_PLUGIN_URI . "wp-filebase_css.php?rp={$upload_path}", array(), WPFB_VERSION, 'all');
     }
     if (is_admin() && !empty($_GET['page']) && strpos($_GET['page'], 'wpfilebase_') !== false || defined('WPFB_EDITOR_PLUGIN')) {
         wpfb_loadclass('Admin');
     }
     // live admin
     if (current_user_can('upload_files') && !is_admin()) {
         wp_enqueue_script(WPFB . '-live-admin', WPFB_PLUGIN_URI . 'js/live-admin.js', array('jquery'), WPFB_VERSION);
         if (self::GetOpt('admin_bar')) {
             add_action('admin_bar_menu', array(__CLASS__, 'AdminBar'), 80);
         }
         if (self::GetOpt('file_context_menu')) {
             wp_enqueue_script('jquery-contextmenu', WPFB_PLUGIN_URI . 'extras/jquery/contextmenu/jquery.contextmenu.js', array('jquery'));
             wp_enqueue_style('jquery-contextmenu', WPFB_PLUGIN_URI . 'extras/jquery/contextmenu/jquery.contextmenu.css', array(), WPFB_VERSION);
         }
     }
     // for admin
     if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
         self::MceAddBtns();
     }
     self::DownloadRedirect();
     if ((WPFB_Core::$settings->frontend_upload || current_user_can('upload_files')) && (!empty($_GET['wpfb_upload_file']) || !empty($_GET['wpfb_add_cat']))) {
         wpfb_call('Admin', empty($_GET['wpfb_upload_file']) ? 'ProcessWidgetAddCat' : 'ProcessWidgetUpload');
     }
 }
Example #17
0
?>
 <img src="<?php 
echo FRM_IMAGES_URL;
?>
/tooltip.png" alt="?" class="frm_help" title="<?php 
printf(__('If you would like to use any extra templates that are not included in Formidable, define the absolute path here. For example, the absolute path to the Formidable template folder is %1$s.', 'formidable'), FRM_TEMPLATES_PATH);
?>
" /></td>
    <td valign="top">
        <input type="text" value="<?php 
echo stripslashes($frmpro_settings->template_path);
?>
" id="frm_template_path" name="frm_template_path" size="70" />
        <?php 
if ($frmpro_settings->template_path != '') {
    if (!path_is_absolute($frmpro_settings->template_path)) {
        _e('The format of that path is incorrect. Please try again.', 'formidable');
    } else {
        ?>
        <a href="javascript:frm_import_templates('frm_import_now')" id="frm_import_now" title="<?php 
        _e('Update Imported Templates Now', 'formidable');
        ?>
"><?php 
        _e('Update Imported Templates Now', 'formidable');
        ?>
</a>
        <?php 
    }
}
?>
        <p class="description"><?php 
Example #18
0
/**
 * Join two filesystem paths together (e.g. 'give me $path relative to $base').
 *
 * If the $path is absolute, then it the full path is returned.
 *
 * @since 2.5.0
 *
 * @param string $base
 * @param string $path
 * @return string The path with the base or absolute path.
 */
function path_join($base, $path)
{
    if (path_is_absolute($path)) {
        return $path;
    }
    return rtrim($base, '/') . '/' . ltrim($path, '/');
}
 function mgjp_move_attachment_files($attachment_id, $new_reldir)
 {
     // basic sanity checks
     if ('attachment' != get_post_type($attachment_id)) {
         return new WP_Error('not_attachment', sprintf(__('The post with ID: %d is not an attachment post type.', 'media-vault'), $attachment_id));
     }
     if (path_is_absolute($new_reldir)) {
         return new WP_Error('new_reldir_not_relative', sprintf(__('The new path provided: %s is absolute. The new path must be a path relative to the WP uploads directory.', 'media-vault'), $new_relpath));
     }
     // Get all file related attachment meta data
     $meta = wp_get_attachment_metadata($attachment_id);
     // meta_key => '_wp_attachment_metadata'
     $file = get_post_meta($attachment_id, '_wp_attached_file', true);
     // meta_key => '_wp_attached_file'
     $backups = get_post_meta($attachment_id, '_wp_attachment_backup_sizes', true);
     // meta_key => '_wp_attachment_backup_sizes'
     // Determine the full paths to the directory where the file
     // currently is and to the directory we want to put the file in.
     $upload_dir = wp_upload_dir();
     $old_reldir = dirname($file);
     if (in_array($old_reldir, array('\\', '/', '.'), true)) {
         $old_reldir = '';
     }
     // If the files are already in the new directory, we don't need
     // to do anything further.
     if ($new_reldir === $old_reldir) {
         return 'sfdfdsfsdd';
     }
     $old_fulldir = path_join($upload_dir['basedir'], $old_reldir);
     $new_fulldir = path_join($upload_dir['basedir'], $new_reldir);
     // Make sure the directory we want to put the files into exists
     // otherwise create it, while setting appropriate permissions.
     if (!wp_mkdir_p($new_fulldir)) {
         return new WP_Error('wp_mkdir_p_error', sprintf(__('There was an error making or verifying the directory at: %s', 'media-vault'), $new_fulldir));
     }
     // Get all filenames for all attached files
     $intermediate_sizes = array();
     if (is_array($meta['sizes'])) {
         foreach ($meta['sizes'] as $size) {
             $intermediate_sizes[] = $size['file'];
         }
     }
     $backup_sizes = array();
     if (is_array($backups)) {
         foreach ($backups as $size) {
             $backup_sizes[] = $size['file'];
         }
     }
     $old_basenames = $new_basenames = array_merge(array(basename($file)), $intermediate_sizes, $backup_sizes);
     // Determine the original filename, to be used to update the guid
     // and if we need to change the filenames because there is already
     // a file with the same name in the destination directory
     $orig_basename = basename($file);
     if (is_array($backups) && isset($backups['full-orig'])) {
         $orig_basename = $backups['full-orig']['file'];
     }
     // Make sure we are not overwriting any existing files in the
     // destination folder. Add numerical increment to filename until
     // there are no conflicts.
     // prep for filename conflict script
     $orig_filename = pathinfo($orig_basename);
     $orig_filename = $orig_filename['filename'];
     $conflict = true;
     $number = 1;
     $separator = '#';
     $med_filename = $orig_filename;
     while ($conflict) {
         $conflict = false;
         foreach ($new_basenames as $basename) {
             if (is_file(path_join($new_fulldir, $basename))) {
                 $conflict = true;
                 break;
             }
         }
         // filename conflict script
         if ($conflict) {
             $new_filename = "{$orig_filename}{$number}";
             $number++;
             $pattern = "{$separator}{$med_filename}";
             $replace = "{$separator}{$new_filename}";
             $new_basenames = explode($separator, ltrim(str_replace($pattern, $replace, $separator . implode($separator, $new_basenames)), $separator));
             $med_filename = $new_filename;
         }
     }
     // php rename() all filepaths in old directory to new path
     // remove duplicate basenames to prevent uneccessary renames
     // from happening
     $unique_old_basenames = array_values(array_unique($old_basenames));
     $unique_new_basenames = array_values(array_unique($new_basenames));
     $i = count($unique_old_basenames);
     while ($i--) {
         $old_fullpath = path_join($old_fulldir, $unique_old_basenames[$i]);
         $new_fullpath = path_join($new_fulldir, $unique_new_basenames[$i]);
         rename($old_fullpath, $new_fullpath);
         if (!is_file($new_fullpath)) {
             return new WP_Error('rename_failed', sprintf(__('Rename failed when trying to move file from: %s, to: %s', 'media-vault'), $old_fullpath, $new_fullpath));
         }
     }
     // Update all attachment filepaths in database to point to the new location
     // $new_basenames[0] should always be the basename of the file
     // from '_wp_attached_media' with the new conflict free filename
     $meta['file'] = path_join($new_reldir, $new_basenames[0]);
     update_post_meta($attachment_id, '_wp_attached_file', $meta['file']);
     // if $new_basenames != $old_basenames we must update the
     // original basename used in the guid as well as the metadata
     // of the intermediate and backup sizes to reflect the
     // filename changes
     if ($new_basenames[0] != $old_basenames[0]) {
         // if $new_basenames != $old_basenames that means the
         // filename conflict script has run and therefore
         // $pattern & $replace are defined
         $orig_basename = ltrim(str_replace($pattern, $replace, $separator . $orig_basename), $separator);
         if (is_array($meta['sizes'])) {
             $i = 0;
             foreach ($meta['sizes'] as $size => $data) {
                 $meta['sizes'][$size]['file'] = $new_basenames[++$i];
             }
         }
         if (is_array($backups)) {
             $i = 0;
             $l = count($backups);
             $new_backup_sizes = array_slice($new_basenames, -$l, $l);
             foreach ($backups as $size => $data) {
                 $backups[$size]['file'] = $new_backup_sizes[$i++];
             }
             update_post_meta($attachment_id, '_wp_attachment_backup_sizes', $backups);
         }
     }
     update_post_meta($attachment_id, '_wp_attachment_metadata', $meta);
     $guid = path_join($new_fulldir, $orig_basename);
     // should I be updating the GUID? the Codex says I should
     // just in case someone wants to disable updating the guid:                       // for attachments.
     if (apply_filters('mgjp_update_guid_on_attachment_files_move', true)) {
         wp_update_post(array('ID' => $attachment_id, 'guid' => $guid));
     }
     // NOT IMPLEMENTED YET: If $rewrite_whole_db flag is set, sanely search through database for instances of
     // old filepath and replace them with new filepath
     // database tables to look through: -> ?
     return true;
 }