We are Using Drupal in out project. Send mail Functionality we are planned to use cronjob. I have created the custom module and also created the hello_cronapi() hook function. My cron name is viewed the admin panel like below path.
Home » Administration » Configuration » System
In Admin panel cronsetting page when check the Force run button cron is running. I have set my cronjob run to every 15 min but it's not run automatically(Every 15 min)
function hello_cronapi($op, $job = NULL){
$items['example_sendmail_cron'] = array(
'description' => 'Send mail with news',
'rule' => '* * * * *', // Every 5 minutes
);
$items['example_news_cron'] = array(
'description' => 'Send mail with news',
'rule' => '*/15 * * * *', // Every 5 minutes
// i must call: example_news_fetch('all')
'callback' => 'example_news_cron',
'arguments' => array('all'),
);
return $items;
}
function example_sendmail_cron() {
echo "Company";
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
$txt = "Jane Doe\n";
fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
fclose($myfile);
exit;
}
function example_news_cron() {
echo "Company";
$myfile = fopen("newfile2.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
$txt = "Jane Doe\n";
fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
fclose($myfile);
exit;
}
In above cronjob is create a file and put the content in the file. But the files is not create
Drupal crons are not run automatically, they are run when a user hits on your pages. If you want a scheduled run, you'll have to setup a cron task on your webserver.
More explanation here : https://www.drupal.org/docs/7/setting-up-cron-for-drupal/configuring-cron-jobs-using-the-cron-command
Related
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?
The situation is as: wordpress installation in root and ci installation in /subdomain1 of subdomain1.domain.com.
I want to perform the following; users from my wordpress site can login with the same credentials in the codeigniter app. I tried methods explained here and in other tutorials but one thing keeps happening. When I add require_once('../wp-load.php'); in the index.php file from ci it and adjusted the load.php file and MY_url_helper.php file it keeps redirecting to: subdomain1.domain.com/index.php/login/wp-admin/install.php I tried to shut off rewriting but it doesn't seem to fix this.
Anyone have a solution? I would really appreciate it!
There are two methods:
1. Load the Wordpress Database in your Codeigniter
To do so add to your "application/config/database.php":
$db['wordpress'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => '#',
'password' => '#',
'database' => '#',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Don't forget to replace '#' with your database login information.
After that you can load the database where ever needed with
$this->load->database('wordpress');
Source: https://www.codeigniter.com/user_guide/database/connecting.html
2. Use the Wordpress wp-load.php
Where ever needed to see if the user is logged in use the following code (PS: at the end there is also a check included how you could check if a user purchased a product via EasyDigitalDownloads in your Wordpress installation - if needed):
<?php
define( 'WP_USE_THEMES', false ); // Do not use the theme files
define( 'COOKIE_DOMAIN', false ); // Do not append verify the domain to the cookie
define( 'DISABLE_WP_CRON', true ); // We don't want extra things running...
//$_SERVER['HTTP_HOST'] = ""; // For multi-site ONLY. Provide the
// URL/blog you want to auth to.
// Path (absolute or relative) to where your WP core is running
require("/var/www/yourdomain.com/htdocs/wp-load.php");
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
} else {
$creds = array();
// If you're not logged in, you should display a form or something
// Use the submited information to populate the user_login & user_password
$creds['user_login'] = "";
$creds['user_password'] = "";
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error( $user ) ) {
echo $user->get_error_message();
} else {
wp_set_auth_cookie( $user->ID, true );
}
}
if ( !is_wp_error( $user ) ) {
// Success! We're logged in! Now let's test against EDD's purchase of my "service."
if ( edd_has_user_purchased( $user->ID, '294', NULL ) ) {
echo "Purchased the Services and is active.";
} else {
echo "Not Purchased";
}
}
Source: http://dovy.io/wordpress/authenticating-outside-of-wordpress-on-diff-domain/
I read dozens of articles, the guidelines, I read everything but I do not understand anything. I'm going crazy. Are three days that I'm trying to post on my facebook fan page through the last 4 API 2.4 SDK.
1. I created the app on facebook but the permissions are almost impossible to enforce
2. I have created the appropriate PHP code with the various authentication codes
the result is always the same: NOTHING
Then the questions:
1. What do you need the app to publish on my fan page?
2. What permissions are needed?
3. If I do not have screenshots to be indicated in the permit to push them through whatever I do (I do the screen shot of the source code?).
4. as you get the access token to the fan page?
A desperate help.
$APP_ID = 'XXXXXXXXXXXXXXXXX'; //app id
$APP_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //app secret
$TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; //access token
$page_id = "XXXXXXXXXXXXXXXXXXXXX"; // facebook page id ottenuto da
$message = "Stiamo testando la pubblicazione delle inserzioni anche su Facebook";
$link = "http://qualcosa";
$name = "Me";
/*$fb = new Facebook\Facebook([
'app_id' => $APP_ID,
'app_secret' => $APP_SECRET,
'default_graph_version' => 'v2.4',
]);
$linkData = [
'link' => 'http://qualcosa/altro',
'message' => $message,
];
var_dump($linkData);
$helper = $fb->getPageTabHelper();
$accessToken = $helper->getAccessToken();
var_dump($accessToken);
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->post('/me/feed', $linkData,$TOKEN);//
} catch(Facebook\Exceptions\FacebookResponseException $e) {
$msg = 'Graph returned an error: ' . $e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
$msg = 'Facebook SDK returned an error: ' . $e->getMessage();
}
var_dump("MSG: ".$msg);
$graphNode = $response->getGraphNode();
var_dump("Graph: ".$graphNode);
$msg = 'Posted with id: ' . $graphNode['id'];
var_dump($msg);
$msg="Nulla";
// I tryed but nothing
try {
FacebookSession::setDefaultApplication($APP_ID, $APP_SECRET);
$session = new FacebookSession($TOKEN);
var_dump($session);
$page_post = (new FacebookRequest( $session, 'POST', '/'. $page_id .'/feed', array(
'access_token' => $TOKEN,
'name' => $name,
'link' => $link,
'picture' => '',
'caption' => 'Test da Cip!',
'message' => $message,
) ))->execute()->getGraphObject()->asArray();
} catch (Facebook\Exceptions\FacebookResponseException $e)
{$msg = 'Graph returned an error: ' . $e->getMessage();}
catch (Facebook\Exceptions\FacebookSDKException $e)
{$msg = 'Facebook SDK returned an error: ' . $e->getMessage();}
// return post_id, optional
var_dump( $page_post );
var_dump($msg);
echo "<br />Finito";
After many attempts I have solved the problem. In graph explorer serves select the App, then the page on publish, assign publishing rights and withdraw the access token created. In the bottom of the page then you can extend the time validity of the token and you will have to use the latter.
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.
I am using symfony 1.4, doctrine orm. I want to generate backend admin generator with single symfony command. I have 56 tables. So I want to know I have to execute 56 command for creating backend modules? How to create all 56 modules in single command?
There is no single command for this.
You can create a task which reads schema.yml, retrieves all models names from there and calls doctrine:generate-module task with each model name.
Here is an example of such task:
class BuildAllModulesTask extends sfBaseTask
{
protected function configure()
{
$this->addOptions(
array(
new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'backend'),
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
)
);
$this->namespace = 'ns';
$this->name = 'build-all-modules';
$this->aliases = array('bam');
$this->briefDescription = 'Builds a module for each model in schema.yml';
$this->detailedDescription = <<<EOF
The Task [Builds a module for each model in schema.yml|INFO]
Call it with:
[php symfony ns:build-all-modules|INFO]
EOF;
$this->addOptions(
array(
new sfCommandOption('app', null, sfCommandOption::PARAMETER_OPTIONAL, 'Application', 'backend')
)
);
}
/**
*
*
* #param array $arguments
* #param array $options
* #return void
*/
protected function execute($arguments = array(), $options = array())
{
$this->logSection('Step 1', 'Read all models from schema.yml');
$yaml = new sfYamlParser();
$models_array = $yaml->parse(file_get_contents(sfConfig::get('sf_config_dir') . '/doctrine/schema.yml'));
$this->logSection('Step 1', 'There are ' . sizeof($models_array) . ' models in the schema.yml');
$this->logSection('STEP 2', 'Go through all models from schema.yml and build an admin module in the "' . $options['app'] . '"');
$sfDoctrineGenerateAdminTask = new sfDoctrineGenerateAdminTask($this->dispatcher, $this->formatter);
$generate_options = array(
'theme' => 'admin', // You can use here some other theme like jroller from ThemeJRoller plugin
'env' => 'prod' // Here you can change to dev to see verbose output
);
foreach ($models_array as $model_name => $model_data) {
if ($model_name == 'options') continue;
$this->logSection('STEP 2', 'Processing "' . $model_name . '"');
$args = array(
'application' => $options['app'],
'route_or_model' => $model_name,
);
$sfDoctrineGenerateAdminTask->run($args, $generate_options);
}
}
}