Tinymce 4 Elfinder absolute path to image - tinymce-4

I've integrated elfinder v2.1 with TinyMce4.
It works great except that the path to the image elfinder give to tinymce is not correct.
The simpliest solution would be to use absolute path. I found some resources to do that with previous version of tinymce (elfinder + tinymce3) but not with version 4.
I try to change some variables in connector.php but without any success.
Here is the actual code:
<?php
error_reporting(0); // Set E_ALL for debuging
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderConnector.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinder.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDriver.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSystem.class.php';
// Required for MySQL storage connector
// include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeMySQL.class.php';
// Required for FTP connector support
// include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeFTP.class.php';
/**
* Simple function to demonstrate how to control file access using "accessControl" callback.
* This method will disable accessing files/folders starting from '.' (dot)
*
* #param string $attr attribute name (read|write|locked|hidden)
* #param string $path file path relative to volume root directory started with directory separator
* #return bool|null
**/
function access($attr, $path, $data, $volume) {
return strpos(basename($path), '.') === 0 // if file/folder begins with '.' (dot)
? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true
: null; // else elFinder decide it itself
}
$opts = array(
// 'debug' => true,
'roots' => array(
array(
'driver' => 'LocalFileSystem', // driver for accessing file system (REQUIRED)
'path' => '../files/', // path to files (REQUIRED)
'URL' => dirname($_SERVER['PHP_SELF']) . '/../files/', // URL to files (REQUIRED)
'accessControl' => 'access' // disable and hide dot starting files (OPTIONAL)
)
)
);
// run elFinder
$connector = new elFinderConnector(new elFinder($opts));
$connector->run();
?>
Anyone knows how to retrieve an absolute url from elfinder?
Thanks

I found a solution by modifying connector.php file and adding the alias option
see: https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
So, in function access, go to $opt
and modify URL and alias like this:
$opts = array(
// 'debug' => true,
'roots' => array(
array(
'driver' => 'LocalFileSystem', // driver for accessing file system (REQUIRED)
'path' => '../files/', // path to files (REQUIRED)
'URL' => 'absolutepath/to/elfinder/files/', // URL to files (REQUIRED)
'alias' => 'absolutepath/to/elfinder/files/',
'accessControl' => 'access' // disable and hide dot starting files (OPTIONAL)
)
)
);
Hope it can help.

Related

How backup automated process to my WordPress Sites using code?

I have used the code below on the c-panel WordPress repository and created a backup folder in the public HTML folder. But not working on I need to know code issue and where I should customize to get my site automatedly by using code.
`function create_backup() {
// Get the site's URL and name
$site_url = get_site_url();
$site_name = get_bloginfo('name');
// Create a filename for the backup using the site's URL and current date
$filename = $site_name . '-' . $site_url . '-' . date('Y-m-d') . '.zip';
// Create a ZIP archive of the site's files
$zip = new ZipArchive;
$zip->open($filename, ZipArchive::CREATE);
$zip->addGlob(ABSPATH . '/*');
$zip->close();
// Send the ZIP archive to a remote location
// Replace "example.com" with the URL of your remote location
$response = wp_remote_post('http://example.com/backups/', array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(
'Content-Type' => 'application/zip'
),
'body' => file_get_contents($filename),
));
}`
Use the wp_schedule_event() or wp_schedule_single_event() function to schedule the custom function to run at a specific time or interval.
And use this Bloew of this code in functions.php
`if ( ! wp_next_scheduled( 'create_backup_event' ) ) {
wp_schedule_event( time(), 'daily', 'create_backup_event' );
}
add_action( 'create_backup_event', 'create_backup' );`
Please notify me where I need to add my domain name and customization needs!
I have tried this on my Name Cheap Hosting. But My inquiry is where should I need to create the Back Folder in the Public Html folder or anywhere else?

tgm register required plugin activation hook not working

I am facing a problem with tgm i have just download the setup from tgm site
http://tgmpluginactivation.com/download/
and when i follow the steps as described on the site and in the downloaded zip file but after follow the steps when i activate my custom theme its simply activated its did not showing any message regarding activating the required plugins
my themes function.php file code is below
<?php
require_once get_template_directory() . '/includes/class-tgm-plugin-activation.php';
add_action( 'tgmpa_register', 'custom_register_required_plugins' );
function custom_register_required_plugins() {
/*
* Array of plugin arrays. Required keys are name and slug.
* If the source is NOT from the .org repo, then source is also required.
*/
$plugins = array(
// This is an example of how to include a plugin bundled with a theme.
array(
'name' => esc_html__('Visual Composer','custom'),
'slug' => 'js_composer',
'source' => get_template_directory() . '/plugins/js-composer.zip',
'required' => false,
'version' => '5.1.1',
'force_activation' => false,
'force_deactivation' => false,
'external_url' => '',
),
);
$config = array(
'id' => 'custom', // Unique ID for hashing notices for multiple instances of TGMPA.
'default_path' => '', // Default absolute path to bundled plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'has_notices' => true, // Show admin notices or not.
'dismissable' => true, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
'is_automatic' => false, // Automatically activate plugins after installation or not.
'message' => '', // Message to output right before the plugins table.
);
tgmpa( $plugins, $config );
}
please tell me whats wrong in this code why after acitvate the theme did not show any message about activate the required plugins

Buddypress bp_activity_add(activity_action) hides the link "target"

I'm developing a social network with Buddypress, I created a RSS plugin to pull the RSS feed from the specified websites.
Everything is working, except when the RSS is posted to the activity stream. When I create the activity content to print a link, I set the link target to "_new" to open it in a new page.
Here's the code:
function wprss_add_to_activity_feed($item, $inserted_ID) {
$permalink = $item->get_permalink();
$title = $item->get_title();
$admin = get_user_by('login', 'admin');
# Generates the link
$activity_action = sprintf( __( '%s published a new RSS link: %s - ', 'buddypress'), bp_core_get_userlink( $admin->ID ), '' . attribute_escape( wprss_limit_rss_title_chars($title) ) . '');
/* Record this in activity streams */
bp_activity_add( array(
'user_id' => $admin->ID,
'item_id' => $inserted_ID,
'action' => $activity_action,
'component' => 'rss',
'primary_link' => $permalink,
'type' => 'activity_update',
'hide_sitewide' => false
));
}
It should come up with something like that:
Test
But it prints like that:
Test
Why is this happening?
The 'target' attribute is probably getting stripped by BuddyPress's implementation of the kses filters. You can whitelist the attribute as follows:
function se16329156_whitelist_target_in_activity_action( $allowedtags ) {
$allowedtags['a']['target'] = array();
return $allowedtags;
}
add_filter( 'bp_activity_allowed_tags', 'se16329156_whitelist_target_in_activity_action' );
This probably won't retroactively fix the issue for existing activity items - it's likely that they had the offending attribute stripped before being stored in the database. But it should help for future items.

Password encrypt to work with phpbb3 password

I have one question, how to encrypt password from my site to work with phpbb3 password?
This will allow you to set up a basic user.
define('IN_PHPBB', true);
global $db;
global $config;
global $user;
global $auth;
global $cache;
global $template;
global $phpbb_root_path;
global $phpEx;
include('forums/common.php'); // THIS NEEDS TO BE CHANGED TO MATCH YOUR PHPBB3 INSTALL LOCATION;
// Currently, I am assuming you have this page at the root of your domain
// and PHPBB3 is install in the 'forums' subdirectory
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
require($phpbb_root_path .'includes/functions_user.php');
$username = $_POST['user'];
$password = $_POST['password']; // Do not encrypt this password, it is handled later by an MD5 function and PHPBB3's own code
$email = $_POST['email'];
// You should add in a check to verify that the username is unique to your PHPBB3 install, otherwise you'll get errors
// I left this as an exercise for you so that you can handle it how you want (reload the page, fail completely, offer suggestions, etc)
$user_row = array(
'username' => $username,
'user_password' => md5($password), 'user_email' => $email,
'group_id' => 2, // This is the 'Registered Users' group. Change this as you feel is appropriate
'user_timezone' => '0.00', // GMT
'user_dst' => 0, // No Day Light Saving
'user_lang' => 'en',
'user_type' => '0', // This means 'Normal User'
'user_actkey' => '',
'user_dateformat' => 'd M Y H:i',
'user_style' => 1,
'user_regdate' => time(),
);
$id = user_add($user_row); // Returns the ID of the new user
Assumptions:
This file is in the root of your domain and the forums are in the forums subdirectory. If this is not the case, I added comments to show what needs to be changed
No error checking was performed for duplicate user names. It is assumed that you have a method to handle this or can modify this script appropriately

drupal module configuration process uploaded file

How can I process a file upload in a module configuration section? Here is what I have so far.
<?php
function dc_staff_directory_admin_settings()
{
$form['dc_staff_directory_upload_file'] = array(
'#type' => 'file',
'#title' => t('Upload staff directory excel (.xls) file'),
'#description' => t('Uploading a file will replace the current staff directory'),
);
$form['#submit'][] = 'dc_staff_directory_process_uploaded_file';
return system_settings_form($form);
}
function dc_staff_directory_process_uploaded_file($form, &$form_state)
{
//What can I do here to get the file data?
}
If you use the managed_file type instead Drupal will do most of the processing for you, you just need to mark the file for permanent storage in your submit function:
function dc_staff_directory_admin_settings() {
$form['dc_staff_directory_upload_file'] = array(
'#type' => 'managed_file',
'#title' => t('Upload staff directory excel (.xls) file'),
'#description' => t('Uploading a file will replace the current staff directory'),
'#upload_location' => 'public://path/'
);
$form['#submit'][] = 'dc_staff_directory_process_uploaded_file';
$form['#validate'][] = 'dc_staff_directory_validate_uploaded_file';
return system_settings_form($form);
}
function db_staff_directory_validate_uploaded_file($form, &$form_state) {
if (!isset($form_state['values']['dc_staff_directory_upload_file']) || !is_numeric($form_state['values']['dc_staff_directory_upload_file'])) {
form_set_error('dc_staff_directory_upload_file', t('Please select an file to upload.'));
}
}
function dc_staff_directory_process_uploaded_file($form, &$form_state) {
if ($form_state['values']['dc_staff_directory_upload_file'] != 0) {
// The new file's status is set to 0 or temporary and in order to ensure
// that the file is not removed after 6 hours we need to change it's status
// to 1.
$file = file_load($form_state['values']['dc_staff_directory_upload_file']);
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
}
}
The validate function is probably a good idea as well, obviously you won't need it if the file is not a required field.
This is mostly taken from the image_example module, part of the Examples Module. If you really don't want to use the managed_file type have a look at the file_example module in that same collection, it has examples of how to uploaded an unmanaged file.
Hope that helps

Resources