function thincc_manage() { if (!current_user_can('export')) { wp_die(__('You do not have sufficient permissions to export the content of this site.')); } global $wpdb; ?> <div class="thincc" xmlns="http://www.w3.org/1999/html"> <div class="wrap"> <h2>Export to Thin Common Cartridge</h2> <div id="main"> <form id="thincc-form" action="" method="post"> <div class="options"> <div><input name="export_flagged_only" id="export_only" type="checkbox" checked/><label for="export_only">Only pages marked as export</label></div> <div><input name="use_custom_vars" id="use_custom_vars" type="checkbox" /><label for="use_custom_vars">Sakai compatibility (use custom_param instead of query param)</label></div> <div><input name="include_fm" id="include_fm" type="checkbox" /><label for="include_fm">Include Front Matter</label></div> <div><input name="include_bm" id="include_bm" type="checkbox" /><label for="include_bm">Include Back Matter</label></div> <div><input name="include_parts" id="include_parts" type="checkbox" /><label for="include_parts">Include links to Parts (Include study plans)</label></div> <div><input name="include_guids" id="include_guids" type="checkbox" /><label for="include_guids">Include GUIDs</label></div> <!-- <div><input name="include_fm" id="include_fm" type="checkbox"/><label for="include_fm">Include Front Matter</label> </div>--> <!-- <div><input name="include_bm" id="include_bm" type="checkbox"/><label for="include_bm">Include Back Matter</label> </div>--> <!-- <div><label for="cc_version_selector">CC Version:</label>--> <!-- <select id="cc_version_selector" name="version">--> <!-- <option value="1.1">1.1 (All LMSs)</option>--> <!-- <option value="1.2">1.2 (Bb/Sakai/Canvas)</option>--> <!-- <option value="1.3">1.3 (Canvas/Sakai)</option>--> <!-- <option value="thin">Thin-CC (1.3) (Canvas)</option>--> <!-- </select>--> <!-- </div>--> </div> <div class="submit"> <input type="hidden" name="download" value="<?php echo get_home_path(); ?> "/> <a href="#" class="button-secondary">Preview Thin-CC</a> <input class="button button-primary" type="submit" value="Download CC 1.1 .imscc" name="submit"> </div> </form> <div id="thincc_modal"> <div id="thincc-results-close-holder"><a href="#" id="thincc-results-close">Close</a></div> <div id="thincc-results">Results</div> </div> </div> </div> </div> <?php }
function get_htaccess_file_path() { //global $wp_rewrite; $home_path = get_home_path(); $htaccess_file = $home_path . '.htaccess'; return $htaccess_file; }
function wpFileSearch_directoryProtection($file) { $admin = 'wp-admin'; $content = 'wp-content'; $includes = 'wp-includes'; if (wpFileSearch_extension($file, 2) || wpFileSearch_extension($file, 3) || wpFileSearch_extension($file, 4)) { //eg: .js .txt .html if (wpFileSearch_position($file, $admin) !== false) { return wpFileSearch_formed($file, $admin); } else { if (wpFileSearch_position($file, $content) !== false) { return wpFileSearch_formed($file, $content); } else { if (wpFileSearch_position($file, $includes) !== false) { return wpFileSearch_formed($file, $includes); } else { if (wpFileSearch_position($file, '/') !== false || wpFileSearch_position($file, '\\') !== false) { wp_die(esc_html__('Sneaky, sorry but i cant allow this. Are you sure this is a wordpress file?', 'wpFileSearch')); } else { return substr(get_home_path(), 0, strlen(get_home_path())) . $file; } } } } } wp_die(esc_html__('Invalid or no file wpFileSearch_extension.', 'wpFileSearch')); }
function ewww_image_optimizer_webp_scan() { global $ewww_debug; $ewww_debug .= "<b>ewww_image_optimizer_webp_scan()</b><br>"; $list = array(); $dir = get_home_path(); $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST); $start = microtime(true); $file_counter = 0; foreach ($iterator as $path) { set_time_limit(0); $skip_optimized = false; if ($path->isDir()) { continue; } else { $file_counter++; $path = $path->getPathname(); $newwebpformat = preg_replace('/\\.webp/', '', $path); if (file_exists($newwebpformat)) { continue; } if (preg_match('/\\.webp$/', $path)) { $ewww_debug .= "queued {$path}<br>"; $list[] = $path; } } } $end = microtime(true) - $start; $ewww_debug .= "query time for {$file_counter} files (seconds): {$end} <br>"; return $list; }
function update_mu_htaccess($include_rs_rules = true) { //rs_errlog( "update_mu_htaccess: arg = $include_rs_rules" ); if (defined('SCOPER_NO_HTACCESS')) { return; } $include_rs_rules = $include_rs_rules && get_site_option('scoper_file_filtering'); // scoper_get_option is not reliable for initial execution following plugin activation if (!$include_rs_rules) { delete_site_option('scoper_file_filtered_sites'); } //rs_errlog( "update_mu_htaccess: $include_rs_rules" ); if (file_exists(ABSPATH . '/wp-admin/includes/file.php')) { include_once ABSPATH . '/wp-admin/includes/file.php'; } $home_path = get_home_path(); $htaccess_path = $home_path . '.htaccess'; if (!file_exists($htaccess_path)) { return; } $contents = file_get_contents($htaccess_path); if ($pos_def = ScoperRewriteMU::default_file_rule_pos($contents)) { $fp = fopen($htaccess_path, 'w'); if ($pos_rs_start = strpos($contents, "\n# BEGIN Role Scoper")) { fwrite($fp, substr($contents, 0, $pos_rs_start)); } else { fwrite($fp, substr($contents, 0, $pos_def)); } if ($include_rs_rules) { fwrite($fp, ScoperRewrite::build_site_rules(false)); } fwrite($fp, substr($contents, $pos_def)); fclose($fp); } }
/** * Add HTML5 Boilerplate's .htaccess via WordPress */ function uncode_add_h5bp_htaccess() { $options = get_option(ot_options_id()); $theme_opt = $options['_uncode_htaccess']; $saved_opt = get_option("_uncode_htaccess_performace"); if ($theme_opt === 'on' && $saved_opt !== 'on' || $theme_opt === 'off' && $saved_opt === 'on') { global $wp_rewrite; $home_path = function_exists('get_home_path') ? get_home_path() : ABSPATH; $htaccess_file = $home_path . '.htaccess'; $mod_rewrite_enabled = function_exists('got_mod_rewrite') ? got_mod_rewrite() : false; if (!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() || is_writable($htaccess_file)) { if ($mod_rewrite_enabled) { $h5bp_rules = extract_from_markers($htaccess_file, 'HTML5 Boilerplate'); if ($h5bp_rules === array()) { $filename = dirname(__FILE__) . '/h5bp-htaccess'; update_option("_uncode_htaccess_performace", $theme_opt); return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', extract_from_markers($filename, 'HTML5 Boilerplate')); } else { if ($theme_opt === 'off') { update_option("_uncode_htaccess_performace", $theme_opt); return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', ''); } } } } } }
/** * job_board_rewrite function. * * @access public * @return void */ public function job_board_rewrite() { if (!function_exists('get_home_path')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } $root_path = get_home_path(); $file_existing_permission = ''; /* Getting Rules */ $rules = 'yes' === get_option('job_board_anti_hotlinking') ? $this->job_board_rewrite_rules() : ''; /* Rules Force Files to be Downloaded */ $forcedownload_rule = "AddType application/octet-stream .pdf .txt\n"; /* Changing File to Writable Mode */ if (file_exists($root_path . '.htaccess') && !is_writable($root_path . '.htaccess')) { $file_existing_permission = substr(decoct(fileperms($root_path . '.htaccess')), -4); chmod($root_path . '.htaccess', 0777); } /* Appending .htaccess */ if (file_exists($root_path . '.htaccess') && is_writable($root_path . '.htaccess')) { $rules = explode("\n", $rules); $forcedownload_rule = explode("\n", $forcedownload_rule); // Anti-Hotlinking Rules Writing in .htaccess file if (!function_exists('insert_with_markers')) { require_once ABSPATH . 'wp-admin/includes/misc.php'; } insert_with_markers($root_path . '.htaccess', 'Hotlinking', $rules); // Force Download Rules Writing in .htaccess file insert_with_markers($root_path . '.htaccess', 'Force Download', $forcedownload_rule); /* Revert File Permission */ if (!empty($file_existing_permission)) { chmod($root_path . '.htaccess', $file_existing_permission); } } }
function ewww_image_optimizer_webp_scan() { ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' ); $list = array(); $dir = get_home_path(); $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir ), RecursiveIteratorIterator::CHILD_FIRST ); $start = microtime( true ); $file_counter = 0; foreach ( $iterator as $path ) { set_time_limit ( 0 ); $skip_optimized = false; if ( $path->isDir() ) { continue; } else { $file_counter++; $path = $path->getPathname(); $newwebpformat = preg_replace( '/\.webp/', '', $path ); if ( file_exists( $newwebpformat ) ) { continue; } if ( preg_match( '/\.webp$/', $path ) ) { ewwwio_debug_message( "queued $path" ); $list[] = $path; } } } $end = microtime( true ) - $start; ewwwio_debug_message( "query time for $file_counter files (seconds): $end" ); return $list; }
public static function acp_page() { wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_style("jquery-ui-css", "//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"); $saved = true; if (!is_writable(__DIR__)) { self::show_message(__('Unable to save configuration changes. The plugin folder is not writable.', 'nnorg-wp-affiliatr')); } if (isset($_POST['Update'])) { $nnorg_afltr_path = esc_html(trim($_POST['nnorg_afltr_path'])); if (file_exists(get_home_path() . $nnorg_afltr_path)) { file_put_contents(NNORG_AFLTR_SETTINGS_CFG, $nnorg_afltr_path); } else { self::show_message(__('The new path has not been found and was not saved!', 'nnorg-wp-affiliatr'), true); $saved = false; } } if (file_exists(NNORG_AFLTR_SETTINGS_CFG)) { $nnorg_afltr_path = file_get_contents(NNORG_AFLTR_SETTINGS_CFG); } if ($saved) { if (file_exists(get_home_path() . $nnorg_afltr_path) && file_exists(get_home_path() . $nnorg_afltr_path . '/inc/config/config.php')) { self::show_message(__('Path has been found!', 'nnorg-wp-affiliatr')); } else { self::show_message(__('The given path was not found!', 'nnorg-wp-affiliatr'), true); } } include 'nnorg-wp-affiliatr-view.php'; }
/** * Creates the .htaccess rewrite block which ensures that images in watched directories are filtered by the * adaptive images plugin. * * @author Nevma (info@nevma.gr) * * @param array $data The adaptive images options. If not given then the existing ones from the database will be * used. * * @return string The adaptive images plugin .htaccess rewrite block. */ function adaptive_images_actions_get_htaccess_block($data) { // If no options data given then take what is in the database. if (!$data) { $data = get_option('adaptive-images'); } // Get the directory part of the request, if we are not in the virtual host root directory. $request_uri = $_SERVER['REQUEST_URI']; $request_uri_base = substr($request_uri, 0, strpos($request_uri, '/wp-admin', 1)); // Isolate the relative path of the adaptive images PHP script inside the WordPress installation directory. $wp_home_path = get_home_path(); $wp_home_path = preg_replace('/\\//i', '\\/', $wp_home_path); $wp_home_path = preg_replace('/\\./i', '\\.', $wp_home_path); $adaptive_images_dir_path = dirname(__FILE__); $adaptive_images_dir_path_relative = preg_replace('/' . $wp_home_path . '/i', '', $adaptive_images_dir_path); $adaptive_images_php_script = $request_uri_base . '/' . $adaptive_images_dir_path_relative . '/adaptive-images-script.php'; // If no starting slash then add it. if (strpos($adaptive_images_php_script, '/') !== 0) { $adaptive_images_php_script = '/' . $adaptive_images_php_script; } // Create the watched directories .htaccess block part. $htaccess_rewrite_block = "# BEGIN Adaptive Images\n" . "#=======================\n" . "\n" . "<IfModule mod_rewrite.c>\n" . "\n" . " RewriteEngine On\n" . "\n" . " # Watched directories\n"; for ($k = 0, $length = count($data['watched-directories']); $k < $length; $k++) { $watched_directory = $data['watched-directories'][$k]; $htaccess_rewrite_block .= " RewriteCond %{REQUEST_URI} " . $request_uri_base . '/' . $watched_directory . ($k < $length - 1 ? ' [OR]' : "\n") . "\n"; } // Create the rewrite .htaccess block part. $htaccess_rewrite_block .= " # Redirect images through the adaptive images script\n" . " RewriteRule \\.(?:jpe?g|gif|png)\$ " . $adaptive_images_php_script . " [L]\n" . "\n" . "</IfModule>\n" . "\n" . "# END Adaptive Images"; return $htaccess_rewrite_block; }
/** * Short Description. (use period) * * Long Description. * * @since 1.1 */ public function activate() { // Create our directory if it is not exist $dir_path = get_home_path() . '/' . $this->attempts_dir; $dir_path = (is_dir($dir_path) || mkdir($dir_path, 0777, TRUE)) && is_writable($dir_path) ? $dir_path : FALSE; //Try to open the protected files foreach ($this->protected_files as $sfile) { $include_file = 'wp-content/plugins/hackattempts/include.php'; $insert_text = 'require_once("' . $include_file . '");'; $file = file(get_home_path() . '/' . $sfile, FILE_IGNORE_NEW_LINES); $first_line = array_shift($file); array_unshift($file, $insert_text); // push second line array_unshift($file, $first_line); // Save back the first line $fp = fopen(get_home_path() . '/' . $sfile, 'w'); // Reopen the file fwrite($fp, implode("\n", $file)); fclose($fp); } // Update database if db version has increased $current_db_version = get_option('hackattempts-db-version'); if (!$current_db_version) { $current_db_version = 0; } if (intval($current_db_version) < Hackattempts_Activator::$db_version) { if ($this->create_or_upgrade_db()) { update_option('hackattempts-db-version', Hackattempts_Activator::$db_version); } } wp_schedule_event(time(), 'hourly', 'hackattempts_cleanup'); wp_schedule_event(time(), 'hourly', 'hackattempts_email'); wp_schedule_event(time(), 'hourly', 'hackattempts_check_file_mod'); }
/** * Modify .htaccess file wit new values * * @since 1.0 */ private static function update_htaccess($remove = false) { if (!function_exists('get_home_path')) { require_once WP_Block_Referrer_Spam::$plugin_path . '../../../wp-admin/includes/file.php'; } $htaccess_path = trailingslashit(get_home_path()) . '.htaccess'; self::remove_marker($htaccess_path, self::HTACCESS_MARKER); // remove current WP Block Referrer Spam rules to update them if ($remove) { return true; } $rules = self::build_rules(); if (!empty($rules)) { if (!function_exists('insert_with_markers')) { require_once WP_Block_Referrer_Spam::$plugin_path . '../../../wp-admin/includes/misc.php'; } if (!insert_with_markers($htaccess_path, self::HTACCESS_MARKER, $rules)) { self::htacess_error_admin_notice(); return false; } } else { return false; } return true; }
function plugin_activate_example_activate() { // Activation code here... // let's create some categories upon activation //http://codex.wordpress.org/Function_Reference/wp_insert_category for ($i = 0; $i < 5; $i++) { $catarr = array('cat_name' => 'My Category' . $i, 'category_description' => 'A Cool Category' . $i, 'category_nicename' => 'category-slug' . $i, 'category_parent' => ''); wp_insert_category($catarr); } // should be root path of the wp install $wordpress_path = get_home_path(); require_once $wordpress_path . '/wp-load.php'; //not sure if this line is needed //activate_plugin() is here: require_once $wordpress_path . '/wp-admin/includes/plugin.php'; // we're going to activate our plugins that are dependencies $plugins = array("filters-example", "js-example", "shortcode-example"); // see //http://wordpress.stackexchange.com/questions/62967/why-activate-plugin-is-not-working-in-register-activation-hook foreach ($plugins as $plugin) { $plugin_path = $wordpress_path . 'wp-content/plugins/' . $plugin . '/' . $plugin . '.php'; if (file_exists($plugin_path) && is_plugin_inactive($plugin . '/' . $plugin . '.php')) { // just double check that the plugin exists and unactivated add_action('update_option_active_plugins', 'plugin_activation_dependencies'); } } }
function custom_admin_url() { if (isset($_POST['custom_wpadmin_slug'])) { // sanitize input $wpadmin_slug = trim(sanitize_key(wp_strip_all_tags($_POST['custom_wpadmin_slug']))); $home_path = get_home_path(); // check if permalinks are turned off, if so force push rules to .htaccess if (isset($_POST['selection']) && $_POST['selection'] == '' && $wpadmin_slug != '') { // check if .htaccess is writable if (!file_exists($home_path . '.htaccess') && is_writable($home_path) || is_writable($home_path . '.htaccess')) { // taken from wp-includes/rewrite.php $home_root = parse_url(home_url()); if (isset($home_root['path'])) { $home_root = trailingslashit($home_root['path']); } else { $home_root = '/'; } // create rules $rules = "<IfModule mod_rewrite.c>\n"; $rules .= "RewriteEngine On\n"; $rules .= "RewriteRule ^{$wpadmin_slug}/?\$ " . $home_root . "wp-login.php [QSA,L]\n"; $rules .= "</IfModule>"; // write to .htaccess insert_with_markers($home_path . '.htaccess', 'WPAdminURL', explode("\n", $rules)); } } else { if (isset($_POST['selection']) || isset($_POST['selection']) && $_POST['selection'] == '' && $wpadmin_slug == '') { // remove rules if permalinks were enabled $markerdata = explode("\n", implode('', file($home_path . '.htaccess'))); $found = false; $newdata = ''; foreach ($markerdata as $line) { if ($line == '# BEGIN WPAdminURL') { $found = true; } if (!$found) { $newdata .= "{$line}\n"; } if ($line == '# END WPAdminURL') { $found = false; } } // write back $f = @fopen($home_path . '.htaccess', 'w'); fwrite($f, $newdata); } } // save to db update_option('custom_wpadmin_slug', $wpadmin_slug); // write rewrite rules right away if ($wpadmin_slug != '') { add_rewrite_rule($wpadmin_slug . '/?$', 'wp-login.php', 'top'); } else { flush_rewrite_rules(); } } add_settings_field('custom_wpadmin_slug', 'WP-Admin slug', array($this, 'options_page'), 'permalink', 'optional', array('label_for' => 'custom_wpadmin_slug')); register_setting('permalink', 'custom_wpadmin_slug', 'strval'); }
function roots_htaccess_writable() { if (!is_writable(get_home_path() . '.htaccess')) { if (current_user_can('administrator')) { add_action('admin_notices', create_function('', "echo '<div class=\"error\"><p>" . sprintf(__('Please make sure your <a href="%s">.htaccess</a> file is writable ', 'roots'), admin_url('options-permalink.php')) . "</p></div>';")); } } }
function replace_number() { $cms_path = get_home_path(); $filename = $cms_path . "hella_app/script/set_homevideo.xml"; $data = file($filename); // reads an array of lines function replace_a_line($data) { global $post; $postid = $post->ID; $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail'); $thumburl = $thumb['0']; $key1 = 'kaltura-meta'; $key2 = 'post-number-meta'; $key3 = 'short-title'; $key4 = 'youtube-meta'; $entry_id = get_post_meta($postid, $key1, true); $videourl = "http://cdnapisec.kaltura.com/html5/html5lib/v2.28/mwEmbedFrame.php/p/1741222/uiconf_id/31805682/entry_id/" . $entry_id . "?wid=_1741222&iframeembed=true&entry_id=" . $entry_id; $order = get_post_meta($postid, $key2, true); $comment = get_post_meta($postid, $key3, true); $ytUrl = get_post_meta($postid, $key4, true); if (stristr($data, '<setvar name="video20_name"')) { return "\t" . '<setvar name="video' . $order . '_name" value="' . $postid . '" />' . "\n"; } if (stristr($data, '<setvar name="video20_thumb"')) { return "\t" . '<setvar name="video' . $order . '_thumb" value="' . $thumburl . '" />' . "\n"; } if (stristr($data, '<setvar name="video20_sharelink"')) { return "\t" . '<setvar name="video' . $order . '_sharelink" value="" />' . "\n"; } if (stristr($data, '<setvar name="video20_infolink"')) { return "\t" . '<setvar name="video' . $order . '_infolink" value="" />' . "\n"; } if (stristr($data, '<setvar name="video20_comment"')) { return "\t" . '<setvar name="video' . $order . '_comment" value="' . $comment . '" />' . "\n"; } if (stristr($data, '<setvar name="video20_url"') && $ytUrl != '') { return "\t" . '<setvar name="video' . $order . '_url" value="' . $ytUrl . '" />' . "\n"; } if (stristr($data, '<setvar name="video20_url"') && $videourl != '') { return "\t" . '<setvar name="video' . $order . '_url" value="' . $videourl . '" />' . "\n"; } if (stristr($data, '<setvar name="video20_action"') && $ytUrl != '') { return "\t" . '<setvar name="video' . $order . '_action" value="gotoyoutubevideo" />' . "\n"; } if (stristr($data, '<setvar name="video20_action"') && $videourl != '') { return "\t" . '<setvar name="video' . $order . '_action" value="gotokalturavideo" />' . "\n"; } if (stristr($data, '<setvar name="video20_sortorder"')) { return "\t" . '<setvar name="video' . $order . '_sortorder" value="' . $order . '" />' . "\n"; } $addone = strtr($data, array('video19' => 'video20', 'value="19"' => 'value="20"', 'video18' => 'video19', 'value="18"' => 'value="19"', 'video17' => 'video18', 'value="17"' => 'value="18"', 'video16' => 'video17', 'value="16"' => 'value="17"', 'video15' => 'video16', 'value="15"' => 'value="16"', 'video14' => 'video15', 'value="14"' => 'value="15"', 'video13' => 'video14', 'value="13"' => 'value="14"', 'video12' => 'video13', 'value="12"' => 'value="13"', 'video11' => 'video12', 'value="11"' => 'value="12"', 'video10' => 'video11', 'value="10"' => 'value="11"', 'video9' => 'video10', 'value="9"' => 'value="10"', 'video8' => 'video9', 'value="8"' => 'value="9"', 'video7' => 'video8', 'value="7"' => 'value="8"', 'video6' => 'video7', 'value="6"' => 'value="7"', 'video5' => 'video6', 'value="5"' => 'value="6"', 'video4' => 'video5', 'value="4"' => 'value="5"', 'video3' => 'video4', 'value="3"' => 'value="4"', 'video2' => 'video3', 'value="2"' => 'value="3"', 'video1' => 'video2', 'value="1"' => 'value="2"')); return $addone; return $data; } $data = array_map('replace_a_line', $data); file_put_contents($filename, implode('', $data)); }
/** * {@internal Missing Short Description}} * * @since unknown * * @param unknown_type $file * @return unknown */ function get_real_file_to_edit($file) { if ('index.php' == $file || '.htaccess' == $file) { $real_file = get_home_path() . $file; } else { $real_file = WP_CONTENT_DIR . $file; } return $real_file; }
/** * Update the permalink structure. * * ## DESCRIPTION * * Updates the post permalink structure. * * To regenerate a .htaccess file with WP-CLI, you'll need to add the mod_rewrite module * to your wp-cli.yml or config.yml. For example: * * apache_modules: * - mod_rewrite * * ## OPTIONS * * <permastruct> * : The new permalink structure to apply. * * [--category-base=<base>] * : Set the base for category permalinks, i.e. '/category/'. * * [--tag-base=<base>] * : Set the base for tag permalinks, i.e. '/tag/'. * * [--hard] * : Perform a hard flush - update `.htaccess` rules as well as rewrite rules in database. * * ## EXAMPLES * * wp rewrite structure '/%year%/%monthnum%/%postname%' */ public function structure($args, $assoc_args) { global $wp_rewrite; // copypasta from /wp-admin/options-permalink.php $home_path = get_home_path(); $iis7_permalinks = iis7_supports_permalinks(); $prefix = $blog_prefix = ''; if (!got_mod_rewrite() && !$iis7_permalinks) { $prefix = '/index.php'; } if (is_multisite() && !is_subdomain_install() && is_main_site()) { $blog_prefix = '/blog'; } $permalink_structure = $args[0] == 'default' ? '' : $args[0]; if (!empty($permalink_structure)) { $permalink_structure = preg_replace('#/+#', '/', '/' . str_replace('#', '', $permalink_structure)); if ($prefix && $blog_prefix) { $permalink_structure = $prefix . preg_replace('#^/?index\\.php#', '', $permalink_structure); } else { $permalink_structure = $blog_prefix . $permalink_structure; } } $wp_rewrite->set_permalink_structure($permalink_structure); // Update category or tag bases if (isset($assoc_args['category-base'])) { $category_base = $assoc_args['category-base']; if (!empty($category_base)) { $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $category_base)); } $wp_rewrite->set_category_base($category_base); } if (isset($assoc_args['tag-base'])) { $tag_base = $assoc_args['tag-base']; if (!empty($tag_base)) { $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $tag_base)); } $wp_rewrite->set_tag_base($tag_base); } // make sure we detect mod_rewrite if configured in apache_modules in config self::apache_modules(); // Launch a new process to flush rewrites because core expects flush // to happen after rewrites are set $new_assoc_args = array(); if (\WP_CLI\Utils\get_flag_value($assoc_args, 'hard')) { $new_assoc_args['hard'] = true; if (!in_array('mod_rewrite', (array) WP_CLI::get_config('apache_modules'))) { WP_CLI::warning("Regenerating a .htaccess file requires special configuration. See usage docs."); } } $process_run = WP_CLI::launch_self('rewrite flush', array(), $new_assoc_args, true, true, array('apache_modules', WP_CLI::get_config('apache_modules'))); if (!empty($process_run->stderr)) { // Strip "Warning: " WP_CLI::warning(substr($process_run->stderr, 9)); } WP_CLI::success("Rewrite structure set."); }
/** * Writes message to log. * * @param string $logFile path to log file * @param string $msg */ public static function log($logFile, $msg) { $logPath = get_home_path() . DIRECTORY_SEPARATOR . log; $f = @fopen($logPath . DIRECTORY_SEPARATOR . $logFile, "a"); if (!$f) { return; } fprintf($f, "[%s] %s\n", date("Y-m-d H:i:s"), $msg); fclose($f); }
/** * Adds extra goodness whenever WP writes to .htaccess * * @global object $wp_rewrite * @param string $content * @return boolean */ function htaccess_add_rules($content) { global $wp_rewrite; $home_path = function_exists('get_home_path') ? get_home_path() : ABSPATH; $htaccess_file = $home_path . '.htaccess'; $mod_rewrite_enabled = function_exists('got_mod_rewrite') ? got_mod_rewrite() : false; $firewall_rules = extract_from_markers($htaccess_file, 'Tabula Rasa'); if ($firewall_rules === array()) { $filename = dirname(__FILE__) . '/TR-htaccess'; return $this->prepend_with_markers($htaccess_file, 'Tabula Rasa', extract_from_markers($filename, 'Tabula Rasa')); } return $content; }
public function tableCreate() { $path = get_home_path(); global $wpdb; require_once $path . '/wp-admin/includes/upgrade.php'; $table_name_api = $this->get_api_table(); $table_name_social = $this->get_social_table(); $charset_collate = $wpdb->get_charset_collate(); $api = "CREATE TABLE {$table_name_api} (\n id mediumint(9) NOT NULL AUTO_INCREMENT,\n time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,\n api_name text NOT NULL,\n api_key mediumtext NOT NULL,\n api_secret mediumtext NOT NULL,\n UNIQUE KEY id (id)\n ) {$charset_collate};"; $social = "CREATE TABLE {$table_name_social} (\n id mediumint(9) NOT NULL AUTO_INCREMENT,\n time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,\n social_source text NOT NULL,\n social_content_type text NOT NULL,\n social_title text NOT NULL,\n social_geo text NOT NULL,\n social_url longtext NOT NULL,\n social_api_key mediumtext NOT NULL,\n social_api_secret mediumtext NOT NULL,\n social_api_name text NOT NULL,\n UNIQUE KEY id (id)\n ) {$charset_collate};"; dbDelta($api); dbDelta($social); }
function easy_repeater_repeat_admin_eq() { if (is_rtl()) { wp_enqueue_style('mian-css-admin', plugin_dir_url(__FILE__) . 'css/easy-repeater-admin.css'); wp_enqueue_style('mian-css-admin_rtl', plugin_dir_url(__FILE__) . 'css/rtl.css'); } else { wp_enqueue_style('mian-css-admin', plugin_dir_url(__FILE__) . 'css/easy-repeater-admin.css'); } wp_enqueue_style('font_awesom-admin', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css'); $max_fields_main = get_option('repeat_main_number'); if (empty($max_fields_main)) { $max_fields_main = 10; } $max_fields_mta = get_option('repeat_meta_number'); if (empty($max_fields_mta)) { $max_fields_mta = 10; } /// get current page $screen = get_current_screen(); if ($screen->base == 'post') { $main_type = 'reapeter_meta_id'; $max_fields = $max_fields_mta; } else { $main_type = 'repeat_main_array_save'; $max_fields = $max_fields_main; } ?> <script type="text/javascript"> var pluginurl = '<?php echo plugin_dir_url(__FILE__); ?> ', path = '<?php echo get_home_path(); ?> ', nx = '<?php echo $main_type; ?> ', max_fields = '<?php echo $max_fields; ?> '; </script> <?php wp_enqueue_media(); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('ajax-script', plugin_dir_url(__FILE__) . '/js/easy-repeater-js.js', array('jquery')); wp_localize_script('ajax-script', 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php'))); }
function handle_rhc_uninstall() { $WP_Roles = new WP_Roles(); foreach (array('calendarize_author', 'edit_' . RHC_CAPABILITY_TYPE, 'read_' . RHC_CAPABILITY_TYPE, 'delete_' . RHC_CAPABILITY_TYPE, 'delete_' . RHC_CAPABILITY_TYPE . 's', 'edit_' . RHC_CAPABILITY_TYPE . 's', 'edit_others_' . RHC_CAPABILITY_TYPE . 's', 'edit_published_' . RHC_CAPABILITY_TYPE . 's', 'delete_published_' . RHC_CAPABILITY_TYPE . 's', 'delete_private_' . RHC_CAPABILITY_TYPE . 's', 'delete_others_' . RHC_CAPABILITY_TYPE . 's', 'publish_' . RHC_CAPABILITY_TYPE . 's', 'read_private_' . RHC_CAPABILITY_TYPE . 's', 'manage_' . RHC_VENUE, 'manage_' . RHC_CALENDAR, 'manage_' . RHC_ORGANIZER) as $cap) { $WP_Roles->remove_cap(RHC_ADMIN_ROLE, $cap); } //----- delete_site_transient('update_plugins'); delete_option('rhc_dismiss_help_notice'); $filename = get_home_path() . '.htaccess'; if (file_exists($filename)) { insert_with_markers($filename, 'RHC', array()); } }
/** * unlink debug.log file * * @return type */ function debug_clearlog() { $filePath = get_home_path() . 'wp-content/debug.log'; $result['class'] = 'error'; $result['message'] = __('File debug.log not Removed.', 'debug'); if (file_exists($filePath)) { $status = unlink($filePath); if ($status) { $result['class'] = 'updated'; $result['message'] = __('debug.log file Remove successfully.', 'debug'); } } return $result; }
/** * Update the permalink structure. * * ## OPTIONS * * <permastruct> * : The new permalink structure to apply. * * [--category-base=<base>] * : Set the base for category permalinks, i.e. '/category/'. * * [--tag-base=<base>] * : Set the base for tag permalinks, i.e. '/tag/'. * * [--hard] * : Perform a hard flush - update `.htaccess` rules as well as rewrite rules in database. * * ## EXAMPLES * * wp rewrite structure '/%year%/%monthnum%/%postname%' */ public function structure($args, $assoc_args) { global $wp_rewrite; // copypasta from /wp-admin/options-permalink.php $home_path = get_home_path(); $iis7_permalinks = iis7_supports_permalinks(); $prefix = $blog_prefix = ''; if (!got_mod_rewrite() && !$iis7_permalinks) { $prefix = '/index.php'; } if (is_multisite() && !is_subdomain_install() && is_main_site()) { $blog_prefix = '/blog'; } $permalink_structure = $args[0] == 'default' ? '' : $args[0]; if (!empty($permalink_structure)) { $permalink_structure = preg_replace('#/+#', '/', '/' . str_replace('#', '', $permalink_structure)); if ($prefix && $blog_prefix) { $permalink_structure = $prefix . preg_replace('#^/?index\\.php#', '', $permalink_structure); } else { $permalink_structure = $blog_prefix . $permalink_structure; } } $wp_rewrite->set_permalink_structure($permalink_structure); // Update category or tag bases if (isset($assoc_args['category-base'])) { $category_base = $assoc_args['category-base']; if (!empty($category_base)) { $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $category_base)); } $wp_rewrite->set_category_base($category_base); } if (isset($assoc_args['tag-base'])) { $tag_base = $assoc_args['tag-base']; if (!empty($tag_base)) { $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $tag_base)); } $wp_rewrite->set_tag_base($tag_base); } // make sure we detect mod_rewrite if configured in apache_modules in config self::apache_modules(); // Launch a new process to flush rewrites because core expects flush // to happen after rewrites are set $new_assoc_args = array(); if (isset($assoc_args['hard'])) { $new_assoc_args['hard'] = true; } \WP_CLI::launch_self('rewrite flush', array(), $new_assoc_args); WP_CLI::success("Rewrite structure set."); }
function scrgen_generate_post_screenshot($post_id) { // Workaround bug: http://premium.wpmudev.org/forums/topic/snapshot-faltal-error-on-get_home_path if (!function_exists('get_home_path')) { require_once dirname(__FILE__) . '/../../../wp-admin/includes/file.php'; } $url = get_permalink($post_id); $url_segs = parse_url($url); $phantomjs = scrgen_phantomjs(); if (empty($phantomjs)) { error_log('The phantomjs binary was not found. Make sure it is in your PHP\'s PATH or set the PHANTOMJS constant to its path.'); return; } $relative_path = 'wp-content/screenshots/' . $post_id . '.jpg'; $image_path = get_home_path() . $relative_path; $image_url = get_home_url() . '/' . $relative_path; $job_id = uniqid(); $job_path = "/tmp/{$job_id}.js"; $tmp_path = "/tmp/{$job_id}.jpg"; $width = scrgen_setting('width'); $height = scrgen_setting('height'); $enable_cropping = scrgen_setting('enable_cropping'); $crop_left = scrgen_setting('crop_left'); $crop_top = scrgen_setting('crop_top'); $crop_width = scrgen_setting('crop_width'); $crop_height = scrgen_setting('crop_height'); $url = strip_tags($url); $url = str_replace(';', '', $url); $url = str_replace('"', '', $url); $url = str_replace('\'', '/', $url); $url = str_replace('<?', '', $url); $url = str_replace('<?', '', $url); $url = str_replace('\\077', ' ', $url); $url = escapeshellcmd($url); $src = "\n\n var page = require('webpage').create();\n\n page.viewportSize = { width: {$width}, height: {$height} };\n\n "; if ($enable_cropping) { $src .= "page.clipRect = { top: {$crop_top}, left: {$crop_left}, width: {$crop_width}, height: {$crop_height} };"; } $src .= "\n\n page.open('{$url}', function () {\n page.render('{$tmp_path}');\n phantom.exit();\n });\n\n\n "; file_put_contents($job_path, $src); $exec = $phantomjs . ' ' . $job_path; $escaped_command = escapeshellcmd($exec); exec($escaped_command); unlink($job_path); if (is_file($tmp_path)) { rename($tmp_path, $image_path); do_action('scrgen_post_screenshot_generated', $post_id, $image_url); } }
function mas_settings_page() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $opt_name = 'mas_watermark'; $mas_wp_home_path = get_home_path(); $opt_val = str_replace($mas_wp_home_path, '', get_option($opt_name)); if (isset($_POST[$opt_name]) && !empty($_POST[$opt_name])) { $opt_val_for_db = $mas_wp_home_path . $_POST[$opt_name]; update_option($opt_name, $opt_val_for_db); ?> <div class="updated"><p><strong><?php _e('settings saved.', 'menu-test'); ?> </strong></p></div> <?php } echo '<div class="wrap">'; echo "<h2>" . __('Merge and Share Settings', 'menu-mas') . "</h2>"; ?> <h3>Upload new watermak image </h3> <form name="form1" method="post" action=""> <p><?php _e("Image for watermark:", 'menu-test'); ?> <label>Watermark</label> <span>Put the path of image in your site</span> <span>(ex:wp-content/wp-upload/watermak/watermark.jpg)</span><br> <input type="text" name="<?php echo $opt_name; ?> " value="<?php echo $opt_val; ?> " size="60"> </p> <hr /> <p class="submit"> <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?> " /> </p> </form> </div> <?php }
/** * Define the core functionality of the plugin. * * Set the plugin name and the plugin version that can be used throughout the plugin. * Load the dependencies, define the locale, and set the hooks for the admin area and * the public-facing side of the site. * * @since 1.0.0 */ public function __construct() { //settings require_once dirname(__FILE__) . '../../../../../wp-load.php'; require_once dirname(__FILE__) . '../../../../../wp-admin/includes/file.php'; $this->base_path = get_home_path() . '/'; $this->base_url = get_site_url() . '/'; $this->wp_upload_dir = wp_upload_dir(); $this->base_path_upload = $this->wp_upload_dir['basedir']; $this->base_url_upload = $this->wp_upload_dir['baseurl']; $this->base_path_merged = $this->base_path . 'shared_creativities/'; $this->base_url_merged = $this->base_url . 'shared_creativities/'; $this->log_file = $this->base_url . 'logs/mas.log'; //$this->watermak =get_option('mas_watermark'); }
function roots_add_h5bp_htaccess($content) { global $wp_rewrite; $home_path = get_home_path(); $htaccess_file = $home_path . '.htaccess'; if (!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() || is_writable($htaccess_file)) { if (got_mod_rewrite()) { $h5bp_rules = extract_from_markers($htaccess_file, 'HTML5 Boilerplate'); if ($h5bp_rules === array()) { $filename = __DIR__ . '/h5bp-htaccess'; return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', extract_from_markers($filename, 'HTML5 Boilerplate')); } } } return $content; }
function easy_ads_manager_admin_eq() { if (is_rtl()) { wp_enqueue_style('mian-css-admin_ads', plugin_dir_url(__FILE__) . 'css/easy-ads-manager.css'); wp_enqueue_style('mian-css-admin_rtl_ads', plugin_dir_url(__FILE__) . 'css/rtl.css'); } else { wp_enqueue_style('mian-css-admin_ads', plugin_dir_url(__FILE__) . 'css/easy-ads-manager.css'); } wp_enqueue_style('jquery-ui-datepicker-style', plugin_dir_url(__FILE__) . 'css/jquery-ui.css'); wp_enqueue_style('font_awesom-admin_ads', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css'); ?> <script type="text/javascript"> var pluginurl_ads = '<?php echo plugin_dir_url(__FILE__); ?> ', path_ads = '<?php echo get_home_path(); ?> '; </script> <?php wp_enqueue_media(); wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('ajax-script_ads', plugin_dir_url(__FILE__) . 'js/easy-ads-manager.js', array('jquery')); wp_localize_script('ajax-script_ads', 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php'))); }