Exemplo n.º 1
0
function wppa_create_pl_htaccess($pl_dirname = '')
{
    global $wpdb;
    // Only supported on single sites at the moment
    if (is_multisite() && !WPPA_MULTISITE_GLOBAL) {
        return false;
    }
    // Where are the photo source files?
    $source_root = str_replace(ABSPATH, '', wppa_opt('wppa_source_dir'));
    // Find permalink root name
    if (!$pl_dirname) {
        $pl_dirname = wppa_opt('wppa_pl_dirname');
    }
    // If no pl_dirname, feature is disabled
    if (!$pl_dirname) {
        return false;
    }
    // Create pl root directory
    $pl_root = WPPA_CONTENT_PATH . '/' . $pl_dirname;
    if (!wppa_mktree($pl_root)) {
        wppa_log('Error', 'Can not create ' . $pl_root);
        return false;
    }
    // Create .htaccess file
    $file = fopen($pl_root . '/.htaccess', 'wb');
    if (!$file) {
        wppa_log('Error', 'Can not create ' . $pl_root . '/.htaccess');
        return false;
    }
    fwrite($file, '<IfModule mod_rewrite.c>');
    fwrite($file, "\n" . 'RewriteEngine On');
    // RewriteBase /wp-content/wppa-pl
    fwrite($file, "\n" . 'RewriteBase /' . str_replace(ABSPATH, '', $pl_root));
    $albs = $wpdb->get_results("SELECT `id`, `name` FROM `" . WPPA_ALBUMS . "` ORDER BY `name` DESC", ARRAY_A);
    if ($albs) {
        foreach ($albs as $alb) {
            $fm = wppa_sanitize_file_name($alb['name'], false);
            $to = $source_root . '/album-' . $alb['id'];
            fwrite($file, "\n" . 'RewriteRule ^' . $fm . '/(.*) /' . $to . '/$1 [NC]');
        }
    }
    fwrite($file, "\n" . '</IfModule>');
    fclose($file);
    return true;
}
Exemplo n.º 2
0
function wppa_add_javascripts()
{
    global $wppa_api_version;
    global $wppa_lang;
    global $wppa_js_page_data_file;
    global $wppa_opt;
    $footer = wppa_switch('wppa_defer_javascript');
    // If the user wants the js in the footer, try to open a tempfile to collect the js data during processing the page
    // If opening a tempfile fails, revert to js in the header.
    if ($footer) {
        $tempdir = WPPA_UPLOAD_PATH . '/temp';
        if (!is_dir($tempdir)) {
            @wppa_mktree($tempdir);
        }
        wppa_delete_obsolete_tempfiles();
        $wppa_js_page_data_file = WPPA_UPLOAD_PATH . '/temp/wppa.' . $_SERVER['REMOTE_ADDR'] . '.js';
        $handle = fopen($wppa_js_page_data_file, 'wb');
        if ($handle) {
            fwrite($handle, '/* WPPA+ Generated Page dependant javascript */' . "\n");
        } else {
            $wppa_js_page_data_file = '';
            $footer = false;
        }
        fclose($handle);
    }
    // WPPA+ Javascript files.
    // All wppa+ js files come in 2 flavours: the normal version and a minified version.
    // If the minified version is available, it will be loaded, else the normal version.
    // If you want to debug js, just delete the minified version; this will cause the normal
    // - readable - version to be loaded.
    $any_lightbox = wppa_opt('lightbox_name') == 'wppa' && (wppa_switch('lightbox_global') || in_array('lightbox', $wppa_opt));
    $js_files = array('wppa', 'wppa-slideshow', 'wppa-ajax-front', 'wppa-lightbox', 'wppa-popup', 'wppa-touch');
    $js_depts = array(array('jquery', 'jquery-form'), array('jquery', 'wppa'), array('jquery', 'wppa'), array('jquery', 'wppa'), array('jquery', 'wppa'), array('jquery', 'wppa'));
    $js_doits = array(true, true, true, $any_lightbox, true, wppa_switch('wppa_slide_swipe') || $any_lightbox);
    $js_footer = array($footer, $footer, $footer, $footer, $footer, $footer);
    foreach (array_keys($js_files) as $idx) {
        if ($js_doits[$idx]) {
            if (is_file(dirname(__FILE__) . '/' . $js_files[$idx] . '.min.js')) {
                wp_enqueue_script($js_files[$idx], WPPA_URL . '/' . $js_files[$idx] . '.min.js', $js_depts[$idx], $wppa_api_version, $js_footer[$idx]);
            } else {
                wp_enqueue_script($js_files[$idx], WPPA_URL . '/' . $js_files[$idx] . '.js', $js_depts[$idx], $wppa_api_version, $js_footer[$idx]);
            }
        }
    }
    // google maps
    if (wppa_opt('wppa_gpx_implementation') == 'wppa-plus-embedded' && strpos(wppa_opt('wppa_custom_content'), 'w#location') !== false) {
        if (wppa_opt('wppa_map_apikey')) {
            wp_enqueue_script('wppa-geo', 'https://maps.googleapis.com/maps/api/js?key=' . wppa_opt('wppa_map_apikey') . '&sensor=false', '', $wppa_api_version, $footer);
        } else {
            wp_enqueue_script('wppa-geo', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', '', $wppa_api_version, $footer);
        }
    }
    // wppa-init
    if (!file_exists(WPPA_PATH . '/wppa-init.' . $wppa_lang . '.js')) {
        wppa_create_wppa_init_js();
        update_option('wppa_ini_js_version_' . $wppa_lang, get_option('wppa_ini_js_version_' . $wppa_lang, '0') + '1');
    }
    if (file_exists(WPPA_PATH . '/wppa-init.' . $wppa_lang . '.js')) {
        wp_enqueue_script('wppa-init', WPPA_URL . '/wppa-init.' . $wppa_lang . '.js', array('wppa'), get_option('wppa_ini_js_version_' . $wppa_lang, $footer));
    }
    // wppa.pagedata
    if ($footer) {
        wp_enqueue_script('wppa-pagedata', WPPA_UPLOAD_URL . '/temp/wppa.' . $_SERVER['REMOTE_ADDR'] . '.js', array('wppa-init'), rand(0, 4711), $footer);
    }
}
function wppa_check_dirs()
{
    if (!is_multisite()) {
        // check if uploads dir exists
        $upload_dir = wp_upload_dir();
        $dir = $upload_dir['basedir'];
        if (!is_dir($dir)) {
            wppa_mktree($dir);
            if (!is_dir($dir)) {
                wppa_error_message(__('The uploads directory does not exist, please do a regular WP upload first.', 'wp-photo-album-plus') . '<br/>' . $dir);
                return false;
            } else {
                if (WPPA_DEBUG) {
                    wppa_ok_message(__('Successfully created uploads directory.', 'wp-photo-album-plus') . '<br/>' . $dir);
                }
            }
        }
        @chmod($dir, 0755);
    }
    // check if wppa dir exists
    $dir = WPPA_UPLOAD_PATH;
    if (!is_dir($dir)) {
        wppa_mktree($dir);
        if (!is_dir($dir)) {
            wppa_error_message(__('Could not create the wppa directory.', 'wp-photo-album-plus') . wppa_credirmsg($dir));
            return false;
        } else {
            if (WPPA_DEBUG) {
                wppa_ok_message(__('Successfully created wppa directory.', 'wp-photo-album-plus') . '<br/>' . $dir);
            }
        }
    }
    @chmod($dir, 0755);
    // check if thumbs dir exists
    $dir = WPPA_UPLOAD_PATH . '/thumbs';
    if (!is_dir($dir)) {
        wppa_mktree($dir);
        if (!is_dir($dir)) {
            wppa_error_message(__('Could not create the wppa thumbs directory.', 'wp-photo-album-plus') . wppa_credirmsg($dir));
            return false;
        } else {
            if (WPPA_DEBUG) {
                wppa_ok_message(__('Successfully created wppa thumbs directory.', 'wp-photo-album-plus') . '<br/>' . $dir);
            }
        }
    }
    @chmod($dir, 0755);
    // check if watermarks dir exists
    $dir = WPPA_UPLOAD_PATH . '/watermarks';
    if (!is_dir($dir)) {
        wppa_mktree($dir);
        if (!is_dir($dir)) {
            wppa_error_message(__('Could not create the wppa watermarks directory.', 'wp-photo-album-plus') . wppa_credirmsg($dir));
            return false;
        } else {
            if (WPPA_DEBUG) {
                wppa_ok_message(__('Successfully created wppa watermarks directory.', 'wp-photo-album-plus') . '<br/>' . $dir);
            }
        }
    }
    @chmod($dir, 0755);
    // check if fonts dir exists
    $dir = WPPA_UPLOAD_PATH . '/fonts';
    if (!is_dir($dir)) {
        wppa_mktree($dir);
        if (!is_dir($dir)) {
            wppa_error_message(__('Could not create the wppa fonts directory.', 'wp-photo-album-plus') . wppa_credirmsg($dir));
            return false;
        } else {
            if (WPPA_DEBUG) {
                wppa_ok_message(__('Successfully created wppa fonts directory.', 'wp-photo-album-plus') . '<br/>' . $dir);
            }
        }
    }
    @chmod($dir, 0755);
    // check if depot dir exists
    if (!is_multisite()) {
        // check if users depot dir exists
        $dir = WPPA_CONTENT_PATH . '/wppa-depot';
        if (!is_dir($dir)) {
            wppa_mktree($dir);
            if (!is_dir($dir)) {
                wppa_error_message(__('Unable to create depot directory.', 'wp-photo-album-plus') . wppa_credirmsg($dir));
                return false;
            } else {
                if (WPPA_DEBUG) {
                    wppa_ok_message(__('Successfully created wppa depot directory.', 'wp-photo-album-plus') . '<br/>' . $dir);
                }
            }
        }
        @chmod($dir, 0755);
    }
    // check the user depot directory
    $dir = WPPA_DEPOT_PATH;
    if (!is_dir($dir)) {
        wppa_mktree($dir);
        if (!is_dir($dir)) {
            wppa_error_message(__('Unable to create user depot directory', 'wp-photo-album-plus') . wppa_credirmsg($dir));
            return false;
        } else {
            if (WPPA_DEBUG) {
                wppa_ok_message(__('Successfully created wppa user depot directory.', 'wp-photo-album-plus') . '<br/>' . $dir);
            }
        }
    }
    @chmod($dir, 0755);
    // check the temp dir
    $dir = WPPA_UPLOAD_PATH . '/temp/';
    if (!is_dir($dir)) {
        wppa_mktree($dir);
        if (!is_dir($dir)) {
            wppa_error_message(__('Unable to create temp directory', 'wp-photo-album-plus') . wppa_credirmsg($dir));
            return false;
        } else {
            if (WPPA_DEBUG) {
                wppa_ok_message(__('Successfully created temp directory.', 'wp-photo-album-plus') . '<br/>' . $dir);
            }
        }
    }
    @chmod($dir, 0755);
    return true;
}
function wppa_check_database($verbose = false)
{
    global $wpdb;
    $any_error = false;
    // Check db tables
    // This is to test if dbdelta did his job in adding tables and columns
    $tn = array(WPPA_ALBUMS, WPPA_PHOTOS, WPPA_RATING, WPPA_COMMENTS, WPPA_IPTC, WPPA_EXIF, WPPA_INDEX);
    $flds = array(WPPA_ALBUMS => array('id' => 'bigint( 20 ) NOT NULL', 'name' => 'text NOT NULL', 'description' => 'text NOT NULL', 'a_order' => 'smallint( 5 ) unsigned NOT NULL', 'main_photo' => 'bigint( 20 ) NOT NULL', 'a_parent' => 'bigint( 20 ) NOT NULL', 'p_order_by' => 'int unsigned NOT NULL', 'cover_linktype' => 'tinytext NOT NULL', 'cover_linkpage' => 'bigint( 20 ) NOT NULL', 'owner' => 'text NOT NULL', 'timestamp' => 'tinytext NOT NULL', 'upload_limit' => 'tinytext NOT NULL', 'alt_thumbsize' => 'tinytext NOT NULL', 'default_tags' => 'tinytext NOT NULL', 'cover_type' => 'tinytext NOT NULL', 'suba_order_by' => 'tinytext NOT NULL'), WPPA_PHOTOS => array('id' => 'bigint( 20 ) NOT NULL', 'album' => 'bigint( 20 ) NOT NULL', 'ext' => 'tinytext NOT NULL', 'name' => 'text NOT NULL', 'description' => 'longtext NOT NULL', 'p_order' => 'smallint( 5 ) unsigned NOT NULL', 'mean_rating' => 'tinytext NOT NULL', 'linkurl' => 'text NOT NULL', 'linktitle' => 'text NOT NULL', 'linktarget' => 'tinytext NOT NULL', 'owner' => 'text NOT NULL', 'timestamp' => 'tinytext NOT NULL', 'status' => 'tinytext NOT NULL', 'rating_count' => "bigint( 20 ) default '0'", 'tags' => 'tinytext NOT NULL', 'alt' => 'tinytext NOT NULL', 'filename' => 'tinytext NOT NULL', 'modified' => 'tinytext NOT NULL', 'location' => 'tinytext NOT NULL'), WPPA_RATING => array('id' => 'bigint( 20 ) NOT NULL', 'photo' => 'bigint( 20 ) NOT NULL', 'value' => 'smallint( 5 ) NOT NULL', 'user' => 'text NOT NULL'), WPPA_COMMENTS => array('id' => 'bigint( 20 ) NOT NULL', 'timestamp' => 'tinytext NOT NULL', 'photo' => 'bigint( 20 ) NOT NULL', 'user' => 'text NOT NULL', 'ip' => 'tinytext NOT NULL', 'email' => 'text NOT NULL', 'comment' => 'text NOT NULL', 'status' => 'tinytext NOT NULL'), WPPA_IPTC => array('id' => 'bigint( 20 ) NOT NULL', 'photo' => 'bigint( 20 ) NOT NULL', 'tag' => 'tinytext NOT NULL', 'description' => 'text NOT NULL', 'status' => 'tinytext NOT NULL'), WPPA_EXIF => array('id' => 'bigint( 20 ) NOT NULL', 'photo' => 'bigint( 20 ) NOT NULL', 'tag' => 'tinytext NOT NULL', 'description' => 'text NOT NULL', 'status' => 'tinytext NOT NULL'), WPPA_INDEX => array('id' => 'bigint( 20 ) NOT NULL', 'slug' => 'tinytext NOT NULL', 'albums' => 'text NOT NULL', 'photos' => 'text NOT NULL'));
    $errtxt = '';
    $idx = 0;
    while ($idx < 7) {
        // Test existence of table
        $ext = wppa_table_exists($tn[$idx]);
        if (!$ext) {
            if ($verbose) {
                wppa_error_message(__('Unexpected error:', 'wp-photo-album-plus') . ' ' . __('Missing database table:', 'wp-photo-album-plus') . ' ' . $tn[$idx], 'red', 'force');
            }
            $any_error = true;
        } else {
            $tablefields = $wpdb->get_results("DESCRIBE {$tn[$idx]};", "ARRAY_A");
            // unset flags for found fields
            foreach ($tablefields as $field) {
                if (isset($flds[$tn[$idx]][$field['Field']])) {
                    unset($flds[$tn[$idx]][$field['Field']]);
                }
            }
            // Fields left?
            if (is_array($flds[$tn[$idx]])) {
                foreach (array_keys($flds[$tn[$idx]]) as $field) {
                    $errtxt .= '<tr><td>' . $tn[$idx] . '</td><td>' . $field . '</td><td>' . $flds[$tn[$idx]][$field] . '</td></tr>';
                }
            }
        }
        $idx++;
    }
    if ($errtxt) {
        $fulltxt = 'The latest update failed to update the database tables required for wppa+ to function properly<br /><br />';
        $fulltxt .= 'Make sure you have the rights to issue SQL commands like <i>"ALTER TABLE tablename ADD COLUMN columname datatype"</i> and run the action on <i>Table VIII-A1</i> on the Photo Albums -> Settings admin page.<br /><br />';
        $fulltxt .= 'The following table lists the missing columns:';
        $fulltxt .= '<br /><table id="wppa-err-table"><thead style="font-weight:bold;"><tr><td>Table name</td><td>Column name</td><td>Data type</td></thead>';
        $fulltxt .= $errtxt;
        $fulltxt .= '</table><b>';
        if ($verbose) {
            wppa_error_message($fulltxt, 'red', 'force');
        }
        $any_error = true;
    }
    // Check directories
    $dn = array(dirname(WPPA_DEPOT_PATH), WPPA_UPLOAD_PATH, WPPA_UPLOAD_PATH . '/thumbs', WPPA_UPLOAD_PATH . '/temp', WPPA_UPLOAD_PATH . '/fonts', WPPA_DEPOT_PATH);
    $idx = 0;
    while ($idx < 6) {
        if (!file_exists($dn[$idx])) {
            // First try to repair
            @wppa_mktree($dn[$idx]);
        } else {
            @chmod($dn[$idx], 0755);
            // there are always people who destruct things
        }
        if (!file_exists($dn[$idx])) {
            // Test again
            if ($verbose) {
                wppa_error_message(__('Unexpected error:', 'wp-photo-album-plus') . ' ' . __('Missing directory:', 'wp-photo-album-plus') . ' ' . $dn[$idx], 'red', 'force');
            }
            $any_error = true;
        } elseif (!is_writable($dn[$idx])) {
            if ($verbose) {
                wppa_error_message(__('Unexpected error:', 'wp-photo-album-plus') . ' ' . __('Directory is not writable:', 'wp-photo-album-plus') . ' ' . $dn[$idx], 'red', 'force');
            }
            $any_error = true;
        } elseif (!is_readable($dn[$idx])) {
            if ($verbose) {
                wppa_error_message(__('Unexpected error:', 'wp-photo-album-plus') . ' ' . __('Directory is not readable:', 'wp-photo-album-plus') . ' ' . $dn[$idx], 'red', 'force');
            }
            $any_error = true;
        }
        $idx++;
    }
    if ($any_error) {
        if ($verbose) {
            wppa_error_message(__('Please de-activate and re-activate the plugin. If this problem persists, ask your administrator.', 'wp-photo-album-plus'), 'red', 'force');
        }
    }
    return !$any_error;
    // True = no error
}
Exemplo n.º 5
0
function wppa_init()
{
    global $blog_id;
    // Upload ( .../wp-content/uploads ) is always relative to ABSPATH,
    // see http://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content_folder
    //
    // Assumption: site_url() corresponds with ABSPATH
    // Our version ( WPPA_UPLOAD ) of the relative part of the path/url to the uploads dir
    // is calculated form wp_upload_dir() by substracting ABSPATH from the uploads basedir.
    $wp_uploaddir = wp_upload_dir();
    // Unfortunately $wp_uploaddir['basedir'] does very often not contain the data promised
    // by the docuentation, so it is unreliable.
    $rel_uploads_path = defined('WPPA_REL_UPLOADS_PATH') ? wppa_trims(WPPA_REL_UPLOADS_PATH) : 'wp-content/uploads';
    // The depot dir is also relative to ABSPATH but on the same level as uploads,
    // but without '/wppa-depot'.
    // If you want to change the name of wp-content, you have also to define WPPA_REL_DEPOT_PATH
    // as being the relative path to the parent of wppa-depot.
    $rel_depot_path = defined('WPPA_REL_DEPOT_PATH') ? wppa_trims(WPPA_REL_DEPOT_PATH) : 'wp-content';
    // For multisite the uploads are in /wp-content/blogs.dir/<blogid>/,
    // so we hope still below ABSPATH
    $wp_content_multi = wppa_trims(str_replace(WPPA_ABSPATH, '', WPPA_CONTENT_PATH));
    // To test the multisite paths and urls, set $debug_multi = true
    $debug_multi = false;
    // Define paths and urls
    if ($debug_multi || is_multisite() && !WPPA_MULTISITE_GLOBAL) {
        if (WPPA_MULTISITE_BLOGSDIR) {
            // Old multisite individual
            define('WPPA_UPLOAD', wppa_trims($wp_content_multi . '/blogs.dir/' . $blog_id));
            define('WPPA_UPLOAD_PATH', WPPA_ABSPATH . WPPA_UPLOAD . '/wppa');
            define('WPPA_UPLOAD_URL', site_url() . '/' . WPPA_UPLOAD . '/wppa');
            define('WPPA_DEPOT', wppa_trims($wp_content_multi . '/blogs.dir/' . $blog_id . '/wppa-depot'));
            define('WPPA_DEPOT_PATH', WPPA_ABSPATH . WPPA_DEPOT);
            define('WPPA_DEPOT_URL', site_url() . '/' . WPPA_DEPOT);
        } elseif (WPPA_MULTISITE_INDIVIDUAL) {
            // New multisite individual
            define('WPPA_UPLOAD', $rel_uploads_path . '/sites/' . $blog_id);
            define('WPPA_UPLOAD_PATH', ABSPATH . WPPA_UPLOAD . '/wppa');
            define('WPPA_UPLOAD_URL', get_bloginfo('wpurl') . '/' . WPPA_UPLOAD . '/wppa');
            define('WPPA_DEPOT', $rel_uploads_path . '/sites/' . $blog_id . '/wppa-depot');
            define('WPPA_DEPOT_PATH', ABSPATH . WPPA_DEPOT);
            define('WPPA_DEPOT_URL', get_bloginfo('wpurl') . '/' . WPPA_DEPOT);
        } else {
            // Not working default multisite
            $user = is_user_logged_in() ? '/' . wppa_get_user() : '';
            define('WPPA_UPLOAD', $rel_uploads_path);
            define('WPPA_UPLOAD_PATH', WPPA_ABSPATH . WPPA_UPLOAD . $user . '/wppa');
            define('WPPA_UPLOAD_URL', site_url() . '/' . WPPA_UPLOAD . $user . '/wppa');
            define('WPPA_DEPOT', wppa_trims($rel_depot_path . '/wppa-depot' . $user));
            define('WPPA_DEPOT_PATH', WPPA_ABSPATH . WPPA_DEPOT);
            define('WPPA_DEPOT_URL', site_url() . '/' . WPPA_DEPOT);
        }
    } else {
        // Single site or multisite global
        define('WPPA_UPLOAD', $rel_uploads_path);
        define('WPPA_UPLOAD_PATH', WPPA_ABSPATH . WPPA_UPLOAD . '/wppa');
        define('WPPA_UPLOAD_URL', site_url() . '/' . WPPA_UPLOAD . '/wppa');
        $user = is_user_logged_in() ? '/' . wppa_get_user() : '';
        define('WPPA_DEPOT', wppa_trims($rel_depot_path . '/wppa-depot' . $user));
        define('WPPA_DEPOT_PATH', WPPA_ABSPATH . WPPA_DEPOT);
        define('WPPA_DEPOT_URL', site_url() . '/' . WPPA_DEPOT);
    }
    wppa_mktree(WPPA_UPLOAD_PATH);
    // Whatever (faulty) path has been calculated, it will be
    wppa_mktree(WPPA_UPLOAD_PATH . '/thumbs');
    // Just to make sure the chmod is right ( 755 )
    wppa_mktree(WPPA_DEPOT_PATH);
    // created and not prevent plugin to activate or function
}
Exemplo n.º 6
0
function wppa_mktree($path)
{
    if (is_dir($path)) {
        wppa_chmod($path);
        return true;
    }
    $bret = wppa_mktree(dirname($path));
    wppa_mkdir($path);
    wppa_chmod($path);
    return is_dir($path);
}
Exemplo n.º 7
0
function wppa_mktree($path)
{
    if (is_dir($path)) {
        @chmod($path, 0755);
        return true;
    }
    $bret = wppa_mktree(dirname($path));
    @mkdir($path);
    @chmod($path, 0755);
    return is_dir($path);
}
function wppa_create_pl_htaccess($pl_dirname = '')
{
    global $wpdb;
    $tim = time();
    // Only supported on single sites at the moment
    if (is_multisite() && !WPPA_MULTISITE_GLOBAL) {
        return false;
    }
    // If there are more than 200 albums, we do this as a cron job
    $n_albs = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "`");
    // Big site?
    if ($n_albs > 200) {
        // Are we a cron job?
        if (wppa_is_cron()) {
            // Remake required?
            if (!get_option('wppa_pl_htaccess_required')) {
                return false;
            }
        } else {
            // Tell cron it must be done
            update_option('wppa_pl_htaccess_required', true);
            return false;
        }
    } else {
        // In cron?
        if (wppa_is_cron()) {
            return false;
        }
    }
    // Either big in cron and required, or small and realtime
    // Where are the photo source files?
    $source_root = str_replace(ABSPATH, '', wppa_opt('source_dir'));
    // Find permalink root name
    if (!$pl_dirname) {
        $pl_dirname = wppa_opt('pl_dirname');
    }
    // If no pl_dirname, feature is disabled
    if (!$pl_dirname) {
        return false;
    }
    // Create pl root directory
    $pl_root = WPPA_CONTENT_PATH . '/' . $pl_dirname;
    if (!wppa_mktree($pl_root)) {
        wppa_log('Error', 'Can not create ' . $pl_root);
        return false;
    }
    // Create .htaccess file
    $file = fopen($pl_root . '/.htaccess', 'wb');
    if (!$file) {
        wppa_log('Error', 'Can not create ' . $pl_root . '/.htaccess');
        return false;
    }
    fwrite($file, '<IfModule mod_rewrite.c>');
    fwrite($file, "\n" . 'RewriteEngine On');
    // RewriteBase /wp-content/wppa-pl
    fwrite($file, "\n" . 'RewriteBase /' . str_replace(ABSPATH, '', $pl_root));
    $albs = $wpdb->get_results("SELECT `id`, `name` FROM `" . WPPA_ALBUMS . "` ORDER BY `name` DESC", ARRAY_A);
    if ($albs) {
        foreach ($albs as $alb) {
            $fm = wppa_get_album_name_for_pl($alb['id'], $alb['name']);
            $to = $source_root . '/album-' . $alb['id'];
            fwrite($file, "\n" . 'RewriteRule ^' . $fm . '/(.*) /' . $to . '/$1 [NC]');
        }
    }
    fwrite($file, "\n" . '</IfModule>');
    fclose($file);
    // Remove required flag
    delete_option('wppa_pl_htaccess_required');
    wppa_log('Dbg', 'Create pl_htaccess took ' . (time() - $tim) . ' seconds.');
    return true;
}
Exemplo n.º 9
0
function wppa_copy_source($name, $from, $to)
{
    global $wppa_supported_photo_extensions;
    // Source files can have uppercase extensions.
    $temp = array();
    foreach ($wppa_supported_photo_extensions as $ext) {
        $temp[] = strtoupper($ext);
    }
    $supext = array_merge($wppa_supported_photo_extensions, $temp);
    if (wppa_switch('keep_sync')) {
        $frompath = wppa_get_source_album_dir($from) . '/' . wppa_strip_ext($name);
        $todir = wppa_get_source_album_dir($to);
        $topath = wppa_get_source_album_dir($to) . '/' . wppa_strip_ext($name);
        if (!is_dir($todir)) {
            @wppa_mktree($todir);
        }
        foreach ($supext as $ext) {
            if (is_file($frompath . '.' . $ext)) {
                @copy($frompath . '.' . $ext, $topath . '.' . $ext);
            }
            if (is_file($frompath . '-o1.' . $ext)) {
                @copy($frompath . '-o1.' . $ext, $topath . '-o1.' . $ext);
            }
        }
    }
}