Beispiel #1
1
function cimy_um_download_database()
{
    global $cum_upload_path;
    if (!empty($_POST["cimy_um_filename"])) {
        if (strpos($_SERVER['HTTP_REFERER'], admin_url('users.php?page=cimy_user_manager')) !== false) {
            // not whom we are expecting? exit!
            if (!check_admin_referer('cimy_um_download', 'cimy_um_downloadnonce')) {
                return;
            }
            $cimy_um_filename = $_POST["cimy_um_filename"];
            // sanitize the file name
            $cimy_um_filename = sanitize_file_name($cimy_um_filename);
            $cimy_um_fullpath_file = $cum_upload_path . $cimy_um_filename;
            // does not exist? exit!
            if (!is_file($cimy_um_fullpath_file)) {
                return;
            }
            header("Pragma: ");
            // Leave blank for issues with IE
            header("Expires: 0");
            header('Vary: User-Agent');
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Content-Type: text/csv");
            header("Content-Type: application/force-download");
            header("Content-Type: application/download");
            header("Content-Disposition: attachment; filename=\"" . esc_html($cimy_um_filename) . "\";");
            // cannot use esc_url any more because prepends 'http' (doh)
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: " . filesize($cimy_um_fullpath_file));
            readfile($cimy_um_fullpath_file);
            exit;
        }
    }
}
function programmatically_create_post()
{
    $url = 'http://widgets.pinterest.com/v3/pidgets/boards/bradleyblose/my-stuff/pins/';
    $json_O = json_decode(file_get_contents($url), true);
    $id = $json_O['data']['pins'][0]['id'];
    $titlelink = 'https://www.pinterest.com/pin/' . $id . '/';
    $title = get_title($titlelink);
    var_dump($title);
    $original = $json_O['data']['pins'][0]['images']['237x']['url'];
    $image_url = preg_replace('/237x/', '736x', $original);
    $description = $json_O['data']['pins'][0]['description'];
    // Initialize the page ID to -1. This indicates no action has been taken.
    $post_id = -1;
    // Setup the author, slug, and title for the post
    $author_id = 1;
    $mytitle = get_page_by_title($title, OBJECT, 'post');
    var_dump($mytitle);
    // If the page doesn't already exist, then create it
    if (NULL == get_page_by_title($title, OBJECT, 'post')) {
        // Set the post ID so that we know the post was created successfully
        $post_id = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $author_id, 'post_name' => $title, 'post_title' => $title, 'post_content' => $description, 'post_status' => 'publish', 'post_type' => 'post'));
        //upload featured image
        $upload_dir = wp_upload_dir();
        $image_data = file_get_contents($image_url);
        $filename = basename($image_url);
        if (wp_mkdir_p($upload_dir['path'])) {
            $file = $upload_dir['path'] . '/' . $filename;
            $path = $upload_dir['path'] . '/';
        } else {
            $file = $upload_dir['basedir'] . '/' . $filename;
            $path = $upload_dir['basedir'] . '/';
        }
        file_put_contents($file, $image_data);
        //edit featured image to correct specs to fit theme
        $pngfilename = $filename . '.png';
        $targetThumb = $path . '/' . $pngfilename;
        $img = new Imagick($file);
        $img->scaleImage(250, 250, true);
        $img->setImageBackgroundColor('None');
        $w = $img->getImageWidth();
        $h = $img->getImageHeight();
        $img->extentImage(250, 250, ($w - 250) / 2, ($h - 250) / 2);
        $img->writeImage($targetThumb);
        unlink($file);
        //Attach featured image
        $wp_filetype = wp_check_filetype($pngfilename, null);
        $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($pngfilename), 'post_content' => '', 'post_status' => 'inherit');
        $attach_id = wp_insert_attachment($attachment, $targetThumb, $post_id);
        require_once ABSPATH . 'wp-admin/includes/image.php';
        $attach_data = wp_generate_attachment_metadata($attach_id, $targetThumb);
        wp_update_attachment_metadata($attach_id, $attach_data);
        set_post_thumbnail($post_id, $attach_id);
        // Otherwise, we'll stop
    } else {
        // Arbitrarily use -2 to indicate that the page with the title already exists
        $post_id = -2;
    }
    // end if
}
Beispiel #3
0
function pleiofile_add_folder_to_zip(ZipArchive &$zip_archive, ElggObject $folder, $folder_path = "")
{
    if (!empty($zip_archive) && !empty($folder) && elgg_instanceof($folder, "object", "folder")) {
        $folder_title = elgg_get_friendly_title($folder->title);
        $zip_archive->addEmptyDir($folder_path . $folder_title);
        $folder_path .= $folder_title . DIRECTORY_SEPARATOR;
        $file_options = array("type" => "object", "subtype" => "file", "limit" => false, "relationship" => "folder_of", "relationship_guid" => $folder->getGUID());
        // add files from this folder to the zip
        if ($files = elgg_get_entities_from_relationship($file_options)) {
            foreach ($files as $file) {
                // check if the file exists
                if ($zip_archive->statName($folder_path . $file->originalfilename) === false) {
                    // doesn't exist, so add
                    $zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . sanitize_file_name($file->originalfilename));
                } else {
                    // file name exists, so create a new one
                    $ext_pos = strrpos($file->originalfilename, ".");
                    $file_name = substr($file->originalfilename, 0, $ext_pos) . "_" . $file->getGUID() . substr($file->originalfilename, $ext_pos);
                    $zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . sanitize_file_name($file_name));
                }
            }
        }
        // check if there are subfolders
        $folder_options = array("type" => "object", "subtype" => "folder", "limit" => false, "metadata_name_value_pairs" => array("parent_guid" => $folder->getGUID()));
        if ($sub_folders = elgg_get_entities_from_metadata($folder_options)) {
            foreach ($sub_folders as $sub_folder) {
                pleiofile_add_folder_to_zip($zip_archive, $sub_folder, $folder_path);
            }
        }
    }
}
Beispiel #4
0
 /**
  * Set image
  *
  * @param string $keyImg
  *        	Key from the image
  * @param file $imgFile
  *        	The image
  * @throws Exception
  * @return void|string
  */
 protected function setImage($keyImg, $imgFile)
 {
     // If it's false or null we have to remove it from the server
     if (!$imgFile || is_null($imgFile)) {
         return $this->removeImage($keyImg);
     }
     if (strpos($imgFile['name'], '.php') !== false) {
         throw new Exception('For security reasons, the extension ".php" cannot be in your file name.');
     }
     $avatar = wp_handle_upload($_FILES[$keyImg], array('mimes' => array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png'), 'test_form' => false, 'unique_filename_callback' => function ($dir, $name, $ext) use($keyImg) {
         $name = $base_name = sanitize_file_name($this->user_login . '_' . $keyImg);
         $number = 1;
         while (file_exists($dir . "/{$name}{$ext}")) {
             $name = $base_name . '_' . $number;
             $number++;
         }
         return $name . $ext;
     }));
     // Remove the last image
     $this->removeImage($keyImg);
     $metaValue = array();
     $url_or_media_id = $avatar['url'];
     // Set the new image
     if (is_int($url_or_media_id)) {
         $metaValue['media_id'] = $url_or_media_id;
         $url_or_media_id = wp_get_attachment_url($url_or_media_id);
     }
     $metaValue['full'] = $url_or_media_id;
     return update_user_meta($this->ID, $keyImg, $metaValue);
 }
Beispiel #5
0
 /**
  * Listen for diagnostic log requests and render it
  */
 public function handle_download_data()
 {
     global $typenow;
     if (!isset($typenow) || INSTAGRATEPRO_POST_TYPE !== $typenow) {
         return;
     }
     $download = filter_input(INPUT_GET, 'download');
     if (!isset($download) || 'data' !== $download) {
         return;
     }
     $nonce = filter_input(INPUT_GET, 'nonce');
     if (!isset($nonce) || !wp_verify_nonce($nonce, 'install-data')) {
         return;
     }
     $log = $this->get_install_body();
     $url = parse_url(home_url());
     $host = sanitize_file_name($url['host']);
     $filename = sprintf('%s-intagrate-install-data-%s.txt', $host, date('YmdHis'));
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Length: ' . strlen($log));
     header('Content-Disposition: attachment; filename=' . $filename);
     echo $log;
     exit;
 }
 static function uploadFile($file_url, $path, $file_name)
 {
     $file_name = sanitize_file_name($file_name);
     $full_file_name = $path . DIRECTORY_SEPARATOR . $file_name;
     //Local name
     $response = wp_remote_get($file_url, array('timeout' => 10 * 60 * 60, 'stream' => true, 'filename' => $full_file_name));
     if (is_wp_error($response)) {
         @unlink($full_file_name);
         throw new Exception('Error: ' . $response->get_error_message());
     }
     if (200 != wp_remote_retrieve_response_code($response)) {
         @unlink($full_file_name);
         throw new Exception('Error 404: ' . trim(wp_remote_retrieve_response_message($response)));
     }
     if (substr($file_name, -12) == ".phpfile.txt") {
         $new_file_name = substr($file_name, 0, -12) . ".php";
         $new_file_name = $path . DIRECTORY_SEPARATOR . $new_file_name;
         $moved = @rename($full_file_name, $new_file_name);
         if ($moved) {
             return array('path' => $new_file_name);
         } else {
             @unlink($full_file_name);
             throw new Exception('Error: Copy file.');
         }
     }
     return array('path' => $full_file_name);
 }
/**
 * Display book in a custom format.
 */
function do_open()
{
    if (!array_key_exists('open', $GLOBALS['wp_query']->query_vars)) {
        // Don't do anything and return
        return;
    }
    $action = get_query_var('open');
    if ('download' == $action) {
        // Download
        if (!empty($_GET['filename']) && !empty($_GET['type'])) {
            $filename = sanitize_file_name($_GET['filename']);
            switch ($_GET['type']) {
                case 'xhtml':
                    $ext = 'html';
                    break;
                case 'wxr':
                    $ext = 'xml';
                    break;
                case 'epub3':
                    $ext = '_3.epub';
                    break;
                default:
                    $ext = $_GET['type'];
                    break;
            }
            $filename = $filename . '.' . $ext;
            download_open_export_file($filename);
        }
    }
    wp_die(__('Error: Unknown export format.', 'pressbooks-textbook'));
}
Beispiel #8
0
 /**
  * Validates whether the gallery can be saved
  */
 function validation()
 {
     // If a title is present, we can auto-populate some other properties
     if (isset($this->object->title)) {
         // If no name is present, use the title to generate one
         if (!isset($this->object->name)) {
             $this->object->name = sanitize_file_name(sanitize_title($this->object->title));
             $this->object->name = apply_filters('ngg_gallery_name', $this->object->name);
         }
         // If no slug is set, use the title to generate one
         if (!isset($this->object->slug)) {
             $this->object->slug = nggdb::get_unique_slug(sanitize_title($this->object->title), 'gallery');
         }
     }
     // Set what will be the path to the gallery
     if (empty($this->object->path)) {
         $storage = $this->object->get_registry()->get_utility('I_Gallery_Storage');
         $this->object->path = $storage->get_upload_relpath($this->object);
         unset($storage);
     }
     $this->object->validates_presence_of('title');
     $this->object->validates_presence_of('name');
     $this->object->validates_uniqueness_of('slug');
     $this->object->validates_numericality_of('author');
     return $this->object->is_valid();
 }
 /**
  * Removes all accents from string
  * @param string $filename - any filename with absolute path
  * @param bool $sanitize - Sanitized all special characters as well?
  */
 public static function remove_accents($filename, $sanitize = true)
 {
     # Get path and basename
     $file_info = pathinfo($filename);
     $filename = $file_info['basename'];
     # If available remove all NFD characters before doing anything else
     if (class_exists('Normalizer')) {
         $filename = Normalizer::normalize($filename, Normalizer::FORM_C);
     }
     # Removes accents using wordpress function
     $filename = remove_accents($filename);
     if ($sanitize) {
         # Sanitize special characters for files so that they work in urls
         $filename = sanitize_file_name($filename);
     }
     # And then just remove anything fancy like ¼ and ™
     $filename = self::remove_non_ascii_characters($filename);
     # If this was full path return it like it was before
     # pathinfo returns . for only filenames
     if ($file_info['dirname'] != '.') {
         $filename = $file_info['dirname'] . '/' . $filename;
     }
     # Return full path
     return $filename;
 }
function grav_submit_to_s3($entry, $form)
{
    // no file?  no problem.
    if (empty($entry[GFORM_UPLOAD_FIELD_ID])) {
        return;
    }
    $gfs3 = new S3(awsAccessKey, awsSecretKey);
    // url of uploaded file
    $file_url = $entry[GFORM_UPLOAD_FIELD_ID];
    // filename of uploaded file
    $file_name = $_FILES['input_' . GFORM_UPLOAD_FIELD_ID]['name'];
    // ensure bucket is there
    $gfs3->putBucket(BUCKET_NAME, S3::ACL_AUTHENTICATED_READ);
    // clean up filename, split into parts
    $url_parts = parse_url($file_url);
    $full_path = $_SERVER['DOCUMENT_ROOT'] . substr($url_parts['path'], 1);
    if (is_dir($file_name)) {
        $file_name = basename($file_name);
    }
    // this is the full path to the file on S3
    $filename_to_s3 = UPLOAD_PATH . sanitize_file_name($file_name);
    if ($gfs3->putObjectFile($full_path, BUCKET_NAME, $filename_to_s3, S3::ACL_PUBLIC_READ)) {
        return true;
        // upload success
    } else {
        wp_die('It looks like something went wrong while uploading your file. Please try again in a few moments.');
    }
}
function sp_AdminLinksTag($args = '', $label = '', $toolTip = '')
{
    global $spThisUser, $spDevice;
    # bail if not admin or moderator
    if (!$spThisUser->admin) {
        return;
    }
    # is this admin showing the admin bar?
    if (!isset($spThisUser->sfadminbar) || $spThisUser->sfadminbar == false) {
        return;
    }
    $defs = array('tagId' => 'spAdminLinks', 'tagClass' => 'spAdminLinks', 'icon' => 'sp_AdminLinks.png', 'iconClass' => 'spAdminLinks');
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_AdminLinks_args', $a);
    extract($a, EXTR_SKIP);
    $p = $spDevice == 'mobile' && current_theme_supports('sp-theme-responsive') ? SPABIMAGESMOB : SPABIMAGES;
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $iconClass = esc_attr($iconClass);
    $icon = sp_paint_icon($iconClass, $p, sanitize_file_name($icon));
    $toolTip = esc_attr($toolTip);
    $label = sp_filter_title_display($label);
    $site = SFHOMEURL . "index.php?sp_ahah=admin-bar-links&sfnonce=" . wp_create_nonce('forum-ahah') . "&action=manage";
    $out = "<a class='{$tagClass}' id='{$tagId}' title='{$toolTip}' rel='nofollow' href='javascript:void(null)' onclick='spjDialogAjax(this, \"{$site}\", \"{$label}\", 250, 0, 0);'>";
    if (!empty($icon)) {
        $out .= $icon;
    }
    if (!empty($label)) {
        $out .= $label;
    }
    $out .= "</a>\n";
    $out = apply_filters('sph_AdminLinks', $out, $a);
    echo $out;
}
Beispiel #12
0
 function handle_upload_prefilter($file)
 {
     // We must sanitize before dupe control...
     $file['name'] = sanitize_file_name($file['name']);
     $log = wpro()->debug->logblock('WPRO_Uploads::handle_upload_prefilter()');
     if (wpro()->backends->is_backend_activated() && !$this->disableFileDupeControl) {
         $upload = wp_upload_dir();
         $name = $file['name'];
         $path = trim($upload['url'], '/') . '/' . $name;
         $counter = 0;
         $exists = true;
         while ($exists) {
             $exists = apply_filters('wpro_backend_file_exists', null, $path);
             if (is_null($exists)) {
                 // no wpro_backend_file_exists filter, or the filter returned null.
                 // use standard exists check (using http(s) request...)
                 $exists = wpro()->http->url_exists($path);
             }
             if ($exists) {
                 if (preg_match('/\\.([^\\.\\/]+)$/', $file['name'], $regs)) {
                     $ending = '.' . $regs[1];
                     $preending = substr($file['name'], 0, 0 - strlen($ending));
                     $name = $preending . '_' . $counter . $ending;
                 } else {
                     $name = $file['name'] . '_' . $counter;
                 }
                 $path = trim($upload['url'], '/') . '/' . $name;
                 $counter++;
             }
         }
         $file['name'] = $name;
     }
     return $log->logreturn($file);
 }
Beispiel #13
0
 static function add_image($image_url)
 {
     if (empty($image_url)) {
         return FALSE;
     }
     // Add Featured Image to Post
     $upload_dir = wp_upload_dir();
     // Set upload folder
     $image_data = file_get_contents($image_url);
     // Get image data
     $filename = basename($image_url);
     // Create image file name
     // Check folder permission and define file location
     if (wp_mkdir_p($upload_dir['path'])) {
         $file = $upload_dir['path'] . '/' . $filename;
     } else {
         $file = $upload_dir['basedir'] . '/' . $filename;
     }
     // Create the image  file on the server
     file_put_contents($file, $image_data);
     // Check image file type
     $wp_filetype = wp_check_filetype($filename, NULL);
     // Set attachment data
     $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($filename), 'post_content' => '', 'post_status' => 'inherit');
     // Create the attachment
     $attach_id = wp_insert_attachment($attachment, $file);
     // Include image.php
     require_once ABSPATH . 'wp-admin/includes/image.php';
     // Define attachment metadata
     $attach_data = wp_generate_attachment_metadata($attach_id, $file);
     // Assign metadata to attachment
     wp_update_attachment_metadata($attach_id, $attach_data);
     return $attach_id;
 }
/**
 * Cron - Thumbnail extraction
 */
function wp_rp_upload_attachment($url, $post_id)
{
    /* Parts copied from wp-admin/includes/media.php:media_sideload_image */
    include_once ABSPATH . 'wp-admin/includes/file.php';
    include_once ABSPATH . 'wp-admin/includes/media.php';
    include_once ABSPATH . 'wp-admin/includes/image.php';
    $tmp = download_url($url);
    preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $url, $matches);
    $file_array['name'] = sanitize_file_name(urldecode(basename($matches[0])));
    $file_array['tmp_name'] = $tmp;
    if (is_wp_error($tmp)) {
        @unlink($file_array['tmp_name']);
        return false;
    }
    $post_data = array('guid' => $url, 'post_title' => 'rp_' . $file_array['name']);
    $attachment_id = media_handle_sideload($file_array, $post_id, null, $post_data);
    if (is_wp_error($attachment_id)) {
        @unlink($file_array['tmp_name']);
        return false;
    }
    $attach_data = wp_get_attachment_metadata($attachment_id);
    $platform_options = wp_rp_get_platform_options();
    $min_width = $platform_options['custom_size_thumbnail_enabled'] ? WP_RP_CUSTOM_THUMBNAILS_WIDTH : WP_RP_THUMBNAILS_WIDTH;
    $min_height = $platform_options['custom_size_thumbnail_enabled'] ? WP_RP_CUSTOM_THUMBNAILS_HEIGHT : WP_RP_THUMBNAILS_HEIGHT;
    if (!$attach_data || $attach_data['width'] < $min_width || $attach_data['height'] < $min_height) {
        wp_delete_attachment($attachment_id);
        return false;
    }
    return $attachment_id;
}
Beispiel #15
0
 function __construct()
 {
     self::$instance =& $this;
     /* GETS INFORMATIONS FROM STYLE.CSS */
     // get themedata version wp 3.4+
     if (function_exists('wp_get_theme')) {
         //get WP_Theme object of customizr
         $tc_theme = wp_get_theme();
         //Get infos from parent theme if using a child theme
         $tc_theme = $tc_theme->parent() ? $tc_theme->parent() : $tc_theme;
         $tc_base_data['prefix'] = $tc_base_data['title'] = $tc_theme->name;
         $tc_base_data['version'] = $tc_theme->version;
         $tc_base_data['authoruri'] = $tc_theme->{'Author URI'};
     } else {
         $tc_base_data = call_user_func('get_' . 'theme_data', get_stylesheet_directory() . '/style.css');
         $tc_base_data['prefix'] = $tc_base_data['title'];
     }
     self::$theme_name = sanitize_file_name(strtolower($tc_base_data['title']));
     //CUSTOMIZR_VER is the Version
     if (!defined('CUSTOMIZR_VER')) {
         define('CUSTOMIZR_VER', $tc_base_data['version']);
     }
     //TC_BASE is the root server path of the parent theme
     if (!defined('TC_BASE')) {
         define('TC_BASE', get_template_directory() . '/');
     }
     //TC_BASE_CHILD is the root server path of the child theme
     if (!defined('TC_BASE_CHILD')) {
         define('TC_BASE_CHILD', get_stylesheet_directory() . '/');
     }
     //TC_BASE_URL http url of the loaded parent theme
     if (!defined('TC_BASE_URL')) {
         define('TC_BASE_URL', get_template_directory_uri() . '/');
     }
     //TC_BASE_URL_CHILD http url of the loaded child theme
     if (!defined('TC_BASE_URL_CHILD')) {
         define('TC_BASE_URL_CHILD', get_stylesheet_directory_uri() . '/');
     }
     //THEMENAME contains the Name of the currently loaded theme
     if (!defined('THEMENAME')) {
         define('THEMENAME', $tc_base_data['title']);
     }
     //TC_WEBSITE is the home website of Customizr
     if (!defined('TC_WEBSITE')) {
         define('TC_WEBSITE', $tc_base_data['authoruri']);
     }
     //this is the structure of the Customizr code : groups => ('path' , 'class_suffix')
     $this->tc_core = apply_filters('tc_core', array('fire' => array(array('inc', 'init'), array('inc', 'utils_settings_map'), array('inc', 'utils'), array('inc', 'resources'), array('inc', 'widgets'), array('inc/admin', 'admin_init'), array('inc/admin', 'admin_page')), 'header' => array(array('inc/parts', 'header_main'), array('inc/parts', 'menu'), array('inc/parts', 'nav_walker')), 'content' => array(array('inc/parts', '404'), array('inc/parts', 'attachment'), array('inc/parts', 'breadcrumb'), array('inc/parts', 'comments'), array('inc/parts', 'featured_pages'), array('inc/parts', 'gallery'), array('inc/parts', 'headings'), array('inc/parts', 'no_results'), array('inc/parts', 'page'), array('inc/parts', 'post_thumbnails'), array('inc/parts', 'post'), array('inc/parts', 'post_list'), array('inc/parts', 'post_metas'), array('inc/parts', 'post_navigation'), array('inc/parts', 'sidebar'), array('inc/parts', 'slider')), 'footer' => array(array('inc/parts', 'footer_main')), 'addons' => apply_filters('tc_addons_classes', array())));
     //end of filters
     //check the context
     if (file_exists(sprintf('%sinc/init-pro.php', TC_BASE)) && 'customizr-pro' == self::$theme_name) {
         require_once sprintf('%sinc/init-pro.php', TC_BASE);
         self::$tc_option_group = 'tc_theme_options';
     } else {
         self::$tc_option_group = 'tc_theme_options';
     }
     //theme class groups instanciation
     $this->tc__($this->tc_core);
 }
Beispiel #16
0
 /**
  * Constructor for the logger.
  *
  * @access public
  * @return void
  */
 public function __construct($handle)
 {
     $this->handles = array();
     $this->handle = sanitize_file_name($handle);
     if (!in_array($this->handle, $this->get_handles())) {
         return false;
     }
 }
Beispiel #17
0
 /**
  * get_file_name.
  */
 function get_file_name()
 {
     $the_file_name = do_shortcode(get_option('wcj_invoicing_' . $this->invoice_type . '_file_name', 'invoice-' . $this->order_id) . '.pdf');
     if ('' == $the_file_name) {
         $the_file_name = 'invoice';
     }
     $the_file_name = sanitize_file_name($the_file_name);
     return apply_filters('wcj_get_' . $this->invoice_type . '_file_name', $the_file_name, $this->order_id);
 }
 function wp_all_import_get_gz($filename, $use_include_path = 0, $targetDir = false)
 {
     $type = 'csv';
     $uploads = wp_upload_dir();
     $targetDir = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $targetDir;
     $tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
     $localPath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
     $fp = @fopen($localPath, 'w');
     $file = @gzopen($filename, 'rb', $use_include_path);
     if ($file) {
         $first_chunk = true;
         while (!gzeof($file)) {
             $chunk = gzread($file, 1024);
             if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
                 $type = 'xml';
                 $first_chunk = false;
             }
             // if it's a 1st chunk, then chunk <? symbols to detect XML file
             @fwrite($fp, $chunk);
         }
         gzclose($file);
     } else {
         $tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
         $localGZpath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
         $request = get_file_curl($filename, $localGZpath, false, true);
         if (!is_wp_error($request)) {
             $file = @gzopen($localGZpath, 'rb', $use_include_path);
             if ($file) {
                 $first_chunk = true;
                 while (!gzeof($file)) {
                     $chunk = gzread($file, 1024);
                     if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
                         $type = 'xml';
                         $first_chunk = false;
                     }
                     // if it's a 1st chunk, then chunk <? symbols to detect XML file
                     @fwrite($fp, $chunk);
                 }
                 gzclose($file);
             }
             @unlink($localGZpath);
         } else {
             return $request;
         }
     }
     @fclose($fp);
     if (preg_match('%\\W(gz)$%i', basename($localPath))) {
         if (@rename($localPath, str_replace('.gz', '.' . $type, $localPath))) {
             $localPath = str_replace('.gz', '.' . $type, $localPath);
         }
     } else {
         if (@rename($localPath, $localPath . '.' . $type)) {
             $localPath = $localPath . '.' . $type;
         }
     }
     return array('type' => $type, 'localPath' => $localPath);
 }
Beispiel #19
0
/**
 * @param $file A $_FILES item
 */
function awpcp_upload_image_file($directory, $filename, $tmpname, $min_size, $max_size, $min_width, $min_height, $uploaded = true)
{
    $filename = sanitize_file_name($filename);
    $newname = wp_unique_filename($directory, $filename);
    $newpath = trailingslashit($directory) . $newname;
    if (!file_exists($tmpname)) {
        return sprintf(__('The specified image file does not exists: %s.', 'AWPCP'), $filename);
    }
    $ext = strtolower(awpcp_get_file_extension($filename));
    $imginfo = getimagesize($tmpname);
    $size = filesize($tmpname);
    $allowed_extensions = array('gif', 'jpg', 'jpeg', 'png');
    if (empty($filename)) {
        return __('No file was selected.', 'AWPCP');
    }
    if ($uploaded && !is_uploaded_file($tmpname)) {
        return __('Unknown error encountered while uploading the image.', 'AWPCP');
    }
    if (empty($size) || $size <= 0) {
        $message = "There was an error trying to find out the file size of the image %s.";
        return __(sprintf($message, $filename), 'AWPCP');
    }
    if (!in_array($ext, $allowed_extensions)) {
        return sprintf(__('The file %s has an invalid extension and was rejected.', 'AWPCP'), $filename);
    } elseif ($size < $min_size) {
        $message = __('The size of %1$s was too small. The file was not uploaded. File size must be greater than %2$d bytes.', 'AWPCP');
        return sprintf($message, $filename, $min_size);
    } elseif ($size > $max_size) {
        $message = __('The file %s was larger than the maximum allowed file size of %s bytes. The file was not uploaded.', 'AWPCP');
        return sprintf($message, $filename, $max_size);
    } elseif (!isset($imginfo[0]) && !isset($imginfo[1])) {
        return sprintf(__('The file %s does not appear to be a valid image file.', 'AWPCP'), $filename);
    } elseif ($imginfo[0] < $min_width) {
        $message = __('The image %s did not meet the minimum width of %s pixels. The file was not uploaded.', 'AWPCP');
        return sprintf($message, $filename, $min_width);
    } elseif ($imginfo[1] < $min_height) {
        $message = __('The image %s did not meet the minimum height of %s pixels. The file was not uploaded.', 'AWPCP');
        return sprintf($message, $filename, $min_height);
    }
    if ($uploaded && !@move_uploaded_file($tmpname, $newpath)) {
        $message = __('The file %s could not be moved to the destination directory.', 'AWPCP');
        return sprintf($message, $filename);
    } else {
        if (!$uploaded && !@copy($tmpname, $newpath)) {
            $message = __('The file %s could not be moved to the destination directory.', 'AWPCP');
            return sprintf($message, $filename);
        }
    }
    if (!awpcp_create_image_versions($newname, $directory)) {
        $message = __('Could not create resized versions of image %s.', 'AWPCP');
        # TODO: unlink resized version, thumbnail and primary image
        @unlink($newpath);
        return sprintf($message, $filename);
    }
    @chmod($newpath, 0644);
    return array('original' => $filename, 'filename' => $newname);
}
 /**
  * Set the export headers
  *
  * @access public
  * @since 1.0
  * @return void
  */
 public function headers()
 {
     ignore_user_abort(true);
     set_time_limit(0);
     nocache_headers();
     header('Content-Type: text/csv; charset=utf-8');
     header('Content-Disposition: attachment; filename=bbp-export-' . sanitize_file_name(get_the_title($this->forum_id)) . '-' . date('m-d-Y') . '.csv');
     header("Expires: 0");
 }
 /**
  * @covers \Pressbooks\CustomCss::getBaseTheme
  */
 public function test_getBaseTheme()
 {
     $input = file_get_contents(PB_PLUGIN_DIR . 'themes-book/pressbooks-book/style.css');
     $output = $this->cc->getCustomCssFolder() . sanitize_file_name('web.css');
     file_put_contents($output, $input);
     $web = $this->cc->getBaseTheme('web');
     $this->assertTrue('pressbooks-book' == $web);
     $prince = $this->cc->getBaseTheme('prince');
     $this->assertFalse('pressbooks-book' == $prince);
 }
function wfu_upload_plugin_clean($label)
{
    $clean = sanitize_file_name($label);
    if (WFU_VAR("WFU_SANITIZE_FILENAME_MODE") != "loose") {
        $search = array('@[^a-zA-Z0-9._]@');
        $replace = array('-');
        $clean = preg_replace($search, $replace, remove_accents($clean));
    }
    return $clean;
}
/**
 * Autoload the class from tinypass plugin directory
 *
 * @param $className
 */
function wp_tinypass_autoloader($className)
{
    if ((preg_match('/^WPTinypass/', $className) || preg_match('/^Tinypass/', $className)) && file_exists(plugin_dir_path(TINYPASS_PLUGIN_FILE_PATH) . 'include/' . $className . '.php')) {
        require_once plugin_dir_path(TINYPASS_PLUGIN_FILE_PATH) . 'include/' . sanitize_file_name($className) . '.php';
    } elseif (preg_match('/^TP/', $className) && file_exists(plugin_dir_path(TINYPASS_PLUGIN_FILE_PATH) . 'include/token/' . $className . '.php')) {
        require_once plugin_dir_path(TINYPASS_PLUGIN_FILE_PATH) . 'include/token/' . sanitize_file_name($className) . '.php';
    } elseif (preg_match('/^TP/', $className) && file_exists(plugin_dir_path(TINYPASS_PLUGIN_FILE_PATH) . 'include/util/' . $className . '.php')) {
        require_once plugin_dir_path(TINYPASS_PLUGIN_FILE_PATH) . 'include/util/' . sanitize_file_name($className) . '.php';
    }
}
Beispiel #24
0
/**
 * Returns absolute path for a file in plugin views folder
 * @param string $file
 */
function fa_view_path($file)
{
    $rel_path = 'views/' . sanitize_file_name($file);
    $path = wp_normalize_path(path_join(FA_PATH, $rel_path));
    if (!is_file($path)) {
        trigger_error(sprintf(__('Template %s does not exist.', 'fapro'), $path), E_USER_WARNING);
    } else {
        return $path;
    }
}
/**
 * Fake sending email. In fact just write a file to the filesystem, so
 * a test service can read it.
 *
 * @param string|array $to Array or comma-separated list of email addresses to send message.
 * @param string $subject Email subject
 * @param string $message Message contents
 *
 * @return bool True if the email got sent (i.e. if the fake email file was written)
 */
function wp_mail($to, $subject, $message)
{
    $file_name = sanitize_file_name(time() . "-{$to}");
    $file_path = trailingslashit(WORDPRESS_FAKE_MAIL_DIR) . $file_name;
    $content = "TO: {$to}" . PHP_EOL;
    $content .= "SUBJECT: {$subject}" . PHP_EOL;
    $content .= WORDPRESS_FAKE_MAIL_DIVIDER . PHP_EOL . $message;
    mkdir(WORDPRESS_FAKE_MAIL_DIR, true);
    return (bool) file_put_contents($file_path, $content);
}
 public function shortcodeExecute($atts, $content = "")
 {
     extract(shortcode_atts(array('url' => '', 'urlgettimeout' => '', 'numberofdisplayeditems' => '', 'oneofthesewordsmustbein' => '', 'oneofthesewordsmustbeindepth' => '', 'oneofthesewordsmustnotbein' => '', 'oneofthesewordsmustnotbeindepth' => '', 'basenode' => ''), $atts));
     $this->feedUrl = $url;
     $this->oneofthesewordsmustbein = $oneofthesewordsmustbein;
     $this->oneofthesewordsmustbeindepth = $oneofthesewordsmustbeindepth;
     $this->oneofthesewordsmustnotbein = $oneofthesewordsmustnotbein;
     $this->oneofthesewordsmustnotbeindepth = $oneofthesewordsmustnotbeindepth;
     /* caching or not? */
     if (!class_exists('FileLoadWithCache') || !class_exists('JSONdecode')) {
         require_once plugin_dir_path(__FILE__) . '/class-fileload-cache.php';
     }
     if (get_option('jci_enable_cache') == 1) {
         # 1 = checkbox "enable cache" activ
         $this->cacheEnable = TRUE;
         # check cacheFolder
         $this->cacheFolder = WP_CONTENT_DIR . '/cache/jsoncontentimporter/';
         $checkCacheFolderObj = new CheckCacheFolder(WP_CONTENT_DIR . '/cache/', $this->cacheFolder);
         # cachefolder ok: set cachefile
         $this->cacheFile = $this->cacheFolder . sanitize_file_name(md5($this->feedUrl)) . ".cgi";
         # cache json-feed
     } else {
         # if not=1: no caching
         $this->cacheEnable = FALSE;
     }
     /* set other parameter */
     if ($numberofdisplayeditems >= 0) {
         $this->numberofdisplayeditems = $numberofdisplayeditems;
     }
     if (is_numeric($urlgettimeout) && $urlgettimeout >= 0) {
         $this->urlgettimeout = $urlgettimeout;
     }
     /* cache */
     $this->cacheEnable = FALSE;
     if (get_option('jci_enable_cache') == 1) {
         $this->cacheEnable = TRUE;
     }
     $cacheTime = get_option('jci_cache_time');
     # max age of cachefile: if younger use cache, if not retrieve from web
     $format = get_option('jci_cache_time_format');
     $cacheExpireTime = strtotime(date('Y-m-d H:i:s', strtotime(" -" . $cacheTime . " " . $format)));
     $this->cacheExpireTime = $cacheExpireTime;
     $this->oauth_bearer_access_key = get_option('jci_oauth_bearer_access_key');
     $fileLoadWithCacheObj = new FileLoadWithCache($this->feedUrl, $this->urlgettimeout, $this->cacheEnable, $this->cacheFile, $this->cacheExpireTime, $this->oauth_bearer_access_key);
     $fileLoadWithCacheObj->retrieveJsonData();
     $this->feedData = $fileLoadWithCacheObj->getFeeddata();
     # build json-array
     $jsonDecodeObj = new JSONdecode($this->feedData);
     $this->jsondata = $jsonDecodeObj->getJsondata();
     $this->basenode = $basenode;
     $this->datastructure = preg_replace("/\n/", "", $content);
     require_once plugin_dir_path(__FILE__) . '/class-json-parser.php';
     $JsonContentParser = new JsonContentParser123($this->jsondata, $this->datastructure, $this->basenode, $this->numberofdisplayeditems, $this->oneofthesewordsmustbein, $this->oneofthesewordsmustbeindepth, $this->oneofthesewordsmustnotbein, $this->oneofthesewordsmustnotbeindepth);
     return apply_filters("json_content_importer_result_root", $JsonContentParser->retrieveDataAndBuildAllHtmlItems());
 }
/**
 * Register scripts commonly used by BuddyPress.
 *
 * @since 2.1.0
 */
function bp_core_register_common_scripts()
{
    $min = bp_core_get_minified_asset_suffix();
    $url = buddypress()->plugin_url . 'bp-core/js/';
    /*
     * Moment.js locale.
     *
     * Try to map current WordPress locale to a moment.js locale file for loading.
     *
     * eg. French (France) locale for WP is fr_FR. Here, we try to find fr-fr.js
     *     (this file doesn't exist).
     */
    $locale = sanitize_file_name(strtolower(get_locale()));
    $locale = str_replace('_', '-', $locale);
    if (file_exists(buddypress()->core->path . "bp-core/js/vendor/moment-js/locale/{$locale}{$min}.js")) {
        $moment_locale_url = $url . "vendor/moment-js/locale/{$locale}{$min}.js";
        /*
         * Try to find the short-form locale.
         *
         * eg. French (France) locale for WP is fr_FR. Here, we try to find fr.js
         *     (this exists).
         */
    } else {
        $locale = substr($locale, 0, strpos($locale, '-'));
        if (file_exists(buddypress()->core->path . "bp-core/js/vendor/moment-js/locale/{$locale}{$min}.js")) {
            $moment_locale_url = $url . "vendor/moment-js/locale/{$locale}{$min}.js";
        }
    }
    // Set up default scripts to register.
    $scripts = array('bp-confirm' => array('file' => "{$url}confirm{$min}.js", 'dependencies' => array('jquery'), 'footer' => false), 'bp-widget-members' => array('file' => "{$url}widget-members{$min}.js", 'dependencies' => array('jquery'), 'footer' => false), 'bp-jquery-query' => array('file' => "{$url}jquery-query{$min}.js", 'dependencies' => array('jquery'), 'footer' => false), 'bp-jquery-cookie' => array('file' => "{$url}vendor/jquery-cookie{$min}.js", 'dependencies' => array('jquery'), 'footer' => false), 'bp-jquery-scroll-to' => array('file' => "{$url}vendor/jquery-scroll-to{$min}.js", 'dependencies' => array('jquery'), 'footer' => false), 'jquery-caret' => array('file' => "{$url}vendor/jquery.caret{$min}.js", 'dependencies' => array('jquery'), 'footer' => true), 'jquery-atwho' => array('file' => "{$url}vendor/jquery.atwho{$min}.js", 'dependencies' => array('jquery', 'jquery-caret'), 'footer' => true), 'bp-plupload' => array('file' => "{$url}bp-plupload{$min}.js", 'dependencies' => array('plupload', 'jquery', 'json2', 'wp-backbone'), 'footer' => true), 'bp-avatar' => array('file' => "{$url}avatar{$min}.js", 'dependencies' => array('jcrop'), 'footer' => true), 'bp-webcam' => array('file' => "{$url}webcam{$min}.js", 'dependencies' => array('bp-avatar'), 'footer' => true), 'bp-cover-image' => array('file' => "{$url}cover-image{$min}.js", 'dependencies' => array(), 'footer' => true), 'bp-moment' => array('file' => "{$url}vendor/moment-js/moment{$min}.js", 'dependencies' => array(), 'footer' => true), 'bp-livestamp' => array('file' => "{$url}vendor/livestamp{$min}.js", 'dependencies' => array('jquery', 'bp-moment'), 'footer' => true));
    // Version 2.7 - Add Moment.js locale to our $scripts array if we found one.
    if (isset($moment_locale_url)) {
        $scripts['bp-moment-locale'] = array('file' => esc_url($moment_locale_url), 'dependencies' => array('bp-moment'), 'footer' => true);
    }
    /**
     * Filters the BuddyPress Core javascript files to register.
     *
     * Default handles include 'bp-confirm', 'bp-widget-members',
     * 'bp-jquery-query', 'bp-jquery-cookie', and 'bp-jquery-scroll-to'.
     *
     * @since 2.1.0 'jquery-caret', 'jquery-atwho' added.
     * @since 2.3.0 'bp-plupload', 'bp-avatar', 'bp-webcam' added.
     * @since 2.4.0 'bp-cover-image' added.
     * @since 2.7.0 'bp-moment', 'bp-livestamp' added.
     *              'bp-moment-locale' is added conditionally if a moment.js locale file is found.
     *
     * @param array $value Array of javascript file information to register.
     */
    $scripts = apply_filters('bp_core_register_common_scripts', $scripts);
    $version = bp_get_version();
    foreach ($scripts as $id => $script) {
        wp_register_script($id, $script['file'], $script['dependencies'], $version, $script['footer']);
    }
}
Beispiel #28
0
 public function getData($url_path = '/teams', $extra = NULL, $template_file = NULL, $useCache = true)
 {
     $wn_current = ltrim(date('W'), '0');
     $wn_previous = ltrim(date('W', strtotime('-7 days')), '0');
     $wn_next = ltrim(date('W', strtotime('+7 days')), '0');
     $extra = str_replace(array('weeknummer=C', 'weeknummer=P', 'weeknummer=N'), array('weeknummer=' . $wn_current, 'weeknummer=' . $wn_previous, 'weeknummer=' . $wn_next), $extra);
     $pluginFolder = dirname(__FILE__);
     if (!isset($template_file) || $template_file == 'template') {
         $template_file = basename($url_path);
         if (strpos($extra, 'slider=1') > -1) {
             // logica voor de slider: 'slider=1'
             $template_file = $template_file . '_slider';
         }
     }
     RainTPL::configure('base_url', NULL);
     RainTPL::configure('tpl_dir', $pluginFolder . '/templates/');
     RainTPL::configure('cache_dir', $pluginFolder . '/cache/');
     RainTPL::configure('path_replace', false);
     $tpl = new RainTPL();
     // standaard 15 minuten cache
     $cache_key = sanitize_file_name($url_path . '_' . $extra);
     if ($useCache && ($cache = $tpl->cache($template_file, $expire_time = 900, $cache_id = $cache_key))) {
         return $cache;
     } else {
         $list = $this->doRequest($url_path, $extra);
         $tpl->assign('logo', strpos($extra, 'logo=1') > -1);
         $tpl->assign('thuisonly', strpos($extra, 'thuisonly=1') > -1);
         $tpl->assign('uitonly', strpos($extra, 'uitonly=1') > -1);
         if (isset($list) && strpos($extra, 'thuis=1') > -1) {
             // logica voor thuisclub eerst in overzichten als 'thuis=1' in $extra zit
             if (strpos($extra, 'uitonly=1') === false) {
                 $thuis = array_filter($list, function ($row) {
                     $length = strlen($this->clubName);
                     return isset($row->ThuisClub) && substr($row->ThuisClub, 0, $length) === $this->clubName;
                 });
                 if (count($thuis) > 0) {
                     $tpl->assign('thuis', $thuis);
                 }
             }
             if (strpos($extra, 'thuisonly=1') === false) {
                 $uit = array_filter($list, function ($row) {
                     $length = strlen($this->clubName);
                     return isset($row->ThuisClub) && substr($row->UitClub, 0, $length) === $this->clubName;
                 });
                 if (count($uit) > 0) {
                     $tpl->assign('uit', $uit);
                 }
             }
         } else {
             $tpl->assign('data', $list);
         }
         return $tpl->draw($template_file, $return_string = true);
     }
 }
Beispiel #29
0
 /**
  * put your comment there...
  * 
  */
 public function setQueueName()
 {
     $type = $this->get('type');
     // Santiize the template name!
     $sanitizedName = strtolower(sanitize_file_name($this->get('name')));
     // Prefix all user templates so it woule be unique when added
     // to Wordpress queue!
     $queueName = "cjt-{$type}-template-{$sanitizedName}";
     $this->set('queueName', $queueName);
     return $this;
 }
/**
 * Save the image with the specified URL locally. To the local filename a uniqe serial is appended to ensure its uniqueness.
 *
 * @param string $url The image remote URL.
 *
 * @return array An array with information about the saved image (*path*: the local path to the image, *url*: the local
 * url, *content_type*: the image content type)
 */
function wl_save_image($url)
{
    $parts = parse_url($url);
    $path = $parts['path'];
    // Get the bare filename (filename w/o the extension).
    // Sanitize filename before saving the current image as attachment
    // See https://codex.wordpress.org/Function_Reference/sanitize_file_name
    $basename = sanitize_file_name(pathinfo($path, PATHINFO_FILENAME) . '-' . uniqid(date('YmdH-')));
    // Chunk the bare name to get a subpath.
    $chunks = chunk_split(strtolower($basename), 3, DIRECTORY_SEPARATOR);
    // Get the base dir.
    $wp_upload_dir = wp_upload_dir();
    $base_dir = $wp_upload_dir['basedir'];
    $base_url = $wp_upload_dir['baseurl'];
    // Get the full path to the local filename.
    $image_path = '/' . $chunks;
    $image_full_path = $base_dir . $image_path;
    $image_full_url = $base_url . $image_path;
    // Create the folders.
    if (!(file_exists($image_full_path) && is_dir($image_full_path))) {
        if (false === mkdir($image_full_path, 0777, true)) {
            wl_write_log("wl_save_image : failed creating dir [ image full path :: {$image_full_path} ]\n");
        }
    }
    // Request the remote file.
    $response = wp_remote_get($url);
    $content_type = wp_remote_retrieve_header($response, 'content-type');
    switch ($content_type) {
        case 'image/jpeg':
        case 'image/jpg':
            $extension = ".jpg";
            break;
        case 'image/svg+xml':
            $extension = ".svg";
            break;
        case 'image/gif':
            $extension = ".gif";
            break;
        case 'image/png':
            $extension = ".png";
            break;
        default:
            $extension = '';
    }
    // Complete the local filename.
    $image_full_path .= $basename . $extension;
    $image_full_url .= $basename . $extension;
    // Store the data locally.
    file_put_contents($image_full_path, wp_remote_retrieve_body($response));
    // wl_write_log( "wl_save_image [ url :: $url ][ content type :: $content_type ][ image full path :: $image_full_path ][ image full url :: $image_full_url ]\n" );
    // Return the path.
    return array('path' => $image_full_path, 'url' => $image_full_url, 'content_type' => $content_type);
}