This flash message helper is from traversymvc: a custom open-source php mvc.
My question is: is it necessary to check if ($_SESSION[$name]) is not empty on line 6(3rd if) when we've already made sure that it is not empty from the if condition before it.
Thanks.
<?php
session_start();
function flash($name = '', $message = '', $class = 'alert alert-success') {
if (!empty($name)) {
if (!empty($message) && empty($_SESSION[$name])) {
if (!empty($_SESSION[$name])) {
unset($_SESSION[$name]);
}
if (!empty($_SESSION[$name . '_class'])) {
unset($_SESSION[$name . '_class']);
}
$_SESSION[$name] = $message;
$_SESSION[$name . '_class'] = $class;
} elseif (empty($message) && !empty($_SESSION[$name])) {
$class = !empty($_SESSION[$name . '_class']) ? $_SESSION[$name . '_class'] : '';
echo '<div class= "' . $class . '" id="msg-flash">' . $_SESSION[$name] . '</div>';
unset($_SESSION[$name]);
unset($_SESSION[$name . '_class']);
}
}
}
Related
I found that error when I test my site in xampp. Uncaught Error: Class "Routeur" not found in (my route)
index:
<?php
session_start();
define("RACINE", $_SERVER["DOCUMENT_ROOT"] . "/projetWebII/");
define("RACINEWEB", "http://" . $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . "/projetWebII/");
function mon_autoloader($classe)
{
$repertoires = array(RACINE . "controleurs/", RACINE . "modeles/", RACINE . "vues/");
foreach($repertoires as $rep)
{
if(file_exists($rep . $classe . ".php"))
{
require_once($rep . $classe . ".php");
return;
}
}
}
spl_autoload_register("mon_autoloader");
Routeur::route();
?>
The file that contains the class is Routeur.php
<?php
class Routeur
{
public static function route()
{
$chaineRequete = $_SERVER["QUERY_STRING"];
$posEperluette = strpos($chaineRequete, "&");
$controleur = substr($chaineRequete, 0, $posEperluette);
if($controleur != "")
{
$classe = "Controleur_" . $controleur;
}
else
{
$classe = "Controleur_Boutique";
}
if(class_exists($classe))
{
$objetControleur = new $classe;
$objetControleur->traite($_REQUEST);
}
else
{
die("Erreur 404! Le controleur n'existe pas.");
}
}
}
?>
any idea about hou to solve it ???? Thanks!!!!
I cant see my file, any sugestion?
I have uploaded a cv successfully from a career page . Now i want to send this in email.
Upload part
if ($_FILES['filecv']['name'] != "") {
$sqldata['att_ment'] = uploadCVFile($_FILES['filecv']);
} else {
$sqldata['att_ment'] = '';
}
CV is uploaded successfully.
uploadCVFile function
function uploadCVFile($uploadedfile)
{
if (!function_exists('wp_handle_upload'))
require_once (ABSPATH . 'wp-admin/includes/file.php');
$upload_overrides = array('test_form' => false);
add_filter('upload_dir', 'cv_uploads_dir');
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
remove_filter('upload_dir', 'cv_uploads_dir');
if ($movefile) {
return basename($movefile['file']); //$uploadedfile['name'];
} else {
return "";
}
}
path set
function cv_uploads_dir($param)
{
$param['subdir'] = '/cvs';
$param['path'] = $param['basedir'] . $param['subdir'];
$param['url'] = $param['baseurl'] . $param['subdir'];
return $param;
}
now i want to send this in email using the wp_mail function. all other data is sent successfully but i dont know how to deal with the cv.
Mail function
function SendCareers_Email($pst)
{
$to = get_option('career_email');
$from = $pst['e-mail'];
$name = $pst['firstname'];
$cvname="/uploads/cvs/".$sqldata['att_ment'];
$subject = "Applying for the job " . $pst['title'];
$message= "Candidate Name:-" . $name . "<br/>";
$message .= "Job Title Applied:-" . $pst['title'] . "<br/>";
if(!empty($pst['country'])){
$message .= "Country Of Resindency:-" . $pst['country'] . "<br/>";
}
if(!empty($pst['nationlaity'])){
$message .= "Nationlaity:-" . $pst['nationlaity'] . "<br/>";
}
$attachments = array( WP_CONTENT_DIR . $cvname );
if(!empty($pst['mobileno'])){
$message .= "Phone Number:-" . $pst['mobileno'] . "<br/>";
}
add_filter('wp_mail_content_type', 'set_career_html_content_type');
$admin_headers = 'From: '.$name.' <'.$from .'>' . "\r\n\\";
wp_mail($to, $subject,$message , $admin_headers,$attachments);
remove_filter('wp_mail_content_type', 'set_career_html_content_type');
}
function set_career_html_content_type()
{
return 'text/html';
}
In your SendCareersEmail function change this part
$cvname="/uploads/cvs/".$_FILES['filecv']['name'];
$attachments = array(
$cvname
);
When inside a function only global variables or variables you pass into the function (in your case $pst) are available. So either pass in $sqldata to the function SendCVEmail($pst, $sqldata) or use the global call of $_FILES['filecv']['name']
I have this function in $root/content/plugins/musicplayer/includes/player.php
public function head_script( $id, $playlist_id, $songs, $in_popup, $autoplay = false ) {
$output = '';
$playlist = '';
$artist = '';
$free = null;
$external = 0;
if ( $songs ) {
$ogg = '';
foreach ( $songs as $song ) {
$free = $song->free;
if ( $song->poster ) {
$poster = esc_url( $song->poster );
} else {
$poster = $this->get_default_playlist_poster( $playlist_id );
}
$playlist .= '{ title : "' . $song->name . '", mp3:"'. esc_url( $song->mp3 ) .'"';
if ( $song->artist )
$playlist .= ', artist : "' . $song->artist . '" ';
if ( $free != 'on' ) {
$playlist .= ',poster : "' . $poster . '" ';
$playlist .= ' },';
}
$playlist = substr( $playlist, 0, -1 );
$output .= '<script type="text/javascript">//<![CDATA[';
$output .= "\n";
$output .= 'jQuery(document).ready(function($) {
new jPlayerPlaylist( {
jPlayer: "#jquery_jplayer_' . $id . '",
cssSelectorAncestor: "#jp_container_' . $id . '" },
['.$playlist.'], {
swfPath: "' . WOLF_JPLAYER_PLUGIN_URL . '/assets/js/src",
wmode: "window", ';
$output .= '});'; // end playlist
if ( ! $in_popup )
$output .= $this->popup();
$output .= '});'; // end document ready playlist
$output .= '//]]></script>';
}
echo $output;
}
How can I use it in $root/content/themes/bigwolf/index.php, with it still being able to call all the functions that are originally and normally called in the native directory, without any problem?
You can include it. That's how you do it.
f1.php
<?php
function func1()
{
echo 'hi';
}
f2.php
<?php
require_once('f1.php'); // require
//include 'f1.php'; // or include
func1();
Obviously musicplayer is a plugin. If it's properly formatted, WordPress will automatically include it. So in the main file of your plugin put
require_once __DIR__ . "/includes/player.php';
That will bring your player.php in and give you access to the functions in it.
HTH,
=C=
I'm trying to implement a function to be able to add directional (up / down) icons next to each of the table headers for a pagination table within CakePHP.
My current code is as follows:
$sort_key = $this->Paginator->sortKey();
$type = $this->Paginator->sortDir() === 'asc' ? 'up' : 'down';
function sortArrows($key, $title, $sort_key, $type)
{
$type_opposite = ($type === 'asc' ? 'down' : 'up');
if($key == $sort_key)
{
$icon = " <i class='fa fa-angle-" . $type . "'></i>";
}
else
{
$icon = " <i class='fa fa-angle-" . $type_opposite . "'></i>";
}
return "'$key', '$title' " . "$icon";
}
Which I am calling on the page as (on each of the table header fields):
<?php echo $this->Paginator->sort(sortArrows('street_suburb', 'Suburb', $sort_key, $type), array('escape' => false)); ?>
This produces the following error:
Notice (8): Array to string conversion [CORE/Cake/View/Helper/HtmlHelper.php, line 372]
I think I am quite close to what I need, I just cannot figure out what I am returning incorrectly from the function to get this to work.
Thanks
Inspired by your solution I have created a Helper extending PaginatorHelper to solve the problem.
Here is the code of file name MyPaginatorHelper.php:
<?php
namespace App\View\Helper;
use Cake\View\Helper\PaginatorHelper;
use Cake\Utility\Inflector;
class MyPaginatorHelper extends PaginatorHelper
{
public function sort($key, $title = null, array $options = [])
{
if (empty($title)) {
$title = $key;
if (strpos($title, '.') !== false) {
$title = str_replace('.', ' ', $title);
}
$title = __(Inflector::humanize(preg_replace('/_id$/', '', $title)));
}
$sortKey = $this->sortKey();
if (strpos($sortKey, '.') !== false) {
$sortKey = substr($sortKey, strpos($sortKey, '.')+1);
}
$sortDir = $this->sortDir() === 'asc' ? 'up' : 'down';
if($key == $sortKey)
{
$title .= " <i class='fa fa-angle-" . $sortDir . "'></i>";
$options['escape'] = false;
}
return parent::sort($key, $title, $options);
}
}
To use this helper you have to add this line in the AppView::initialize() method:
$this->loadHelper('Paginator', ['className' => 'MyPaginator']);
And then all the Paginator->sort() calls will have this feature by default.
I ended up coming up with a solution however I don't know if it is the best way around it. It does work however.
<?php
$sort_key = $this->Paginator->sortKey();
$type = $this->Paginator->sortDir() === 'asc' ? 'up' : 'down';
function sortArrows($key, $title, $sort_key, $type)
{
if($key == $sort_key)
{
$icon = " <i class='fa fa-angle-" . $type . "'></i>";
return $title . " " . $icon;
}
else
{
return $title;
}
}
?>
Called like:
<?php echo $this->Paginator->sort('street_suburb', sortArrows('street_suburb', 'Suburb', $sort_key, $type), array('escape' => false)); ?>
I am having problem with calling a function from another plugin it seems to return nothing tho this does work on other plugin
function caller_func()
{
if (!function_exists('form')) return;
return form($number = null);
}
function chrp1_get_popup(){
$chrp1_popup = '<div id="fullscre"></div>';
$chrp1__query= "post_type=popup-widget-details&showposts=1";
query_posts($chrp1__query);
if (have_posts()) : the_post();
$chrp1_mykey_values = get_post_custom_values('code');
$chrp1_descrip = get_the_content();
$chrp1_popup .= '<span onclick="chrp1_showall();">'.$chrp1_descrip.'</span>';
$chrp1_popup .= '<div id="newsox">';
$chrp1_popup .= '<img src="'.chrp1_PATH.'image/cross.png" class="ccross"
onclick="chrp1_getrid();" width="23"/>';
$getfunc = 'caller_func';
$chrp1_popup .= $getfunc();
$chrp1_popup .= '</div>';
endif; wp_reset_query();
return $chrp1_popup;
}
this code works on my other plugins I want to call but not this one below can anybody help
function form($number = null) {
if ($number == null)
return $this->subscription_form();
$options = get_option('newsletter_forms');
$form = $options['form_' . $number];
if (stripos($form, '<form') !== false) {
$form = str_replace('{newsletter_url}', plugins_url('newsletter/do/subscribe.php'), $form);
} else {
$form = '<form method="post" action="' . plugins_url('newsletter/do/subscribe.php') . '" onsubmit="return newsletter_check(this)">' .
$form . '</form>';
}
$form = $this->replace_lists($form);
return $form;
}
when I check the source code nothing from the form has loaded