Jump to content

shortcode and php


Lassie

Recommended Posts

I am working on a wordpress project and one of the plugins I would like to use uses shortcode.

I have not come across this before and I'm not sure if this is php or wordpress issue.

The wordpress forum has to date not replied.

Given that the shortcode is supposed to call the scripts I'm wondering if ther eis anothe rway to initiate the scripts.

The plugin is business directory and the instal says to insert in the deisred location the following shortcode

 

[bizdir_directory]

 

The code is in a directory  - business-directory

The intial file is business-directory.php which needs a config file

I have put the code for these below

<?php
/*
Plugin Name: Business Directory
Plugin URI: http://businessdirectory.squarecompass.com/
Description: The Business Directory plugin for Wordpress is an easy way to host a free directory page for your readers, affiliates, advertisers, community, club members, etc. Allow them to submit a simple advertisement listing for themselves on your blog.
Version: 0.7.1 Beta
Author: Square Compass
Author URI: http://squarecompass.com
*/

require_once('config.php'); //Load Biz-Directory Config File
/*
* Add functions
*/
//Add Actions
add_action('wp_head','bizdir_js_header'); //Add Listing Form Header Ajax Call
add_action('admin_menu','bizdir_navigation'); //Add Directory Tab in the menu
add_action('admin_print_scripts','bizdir_js_admin_header'); //Add Ajax to the admin side
add_action('wp_ajax_bizdir_edit_listing','bizdir_edit_listing' );
add_action('wp_ajax_bizdir_update_listing','bizdir_update_listing' );
add_action('wp_ajax_bizdir_show_manager_home','bizdir_show_manager_home' );
add_action('wp_ajax_bizdir_change_listing_status','bizdir_change_listing_status' );
add_action('wp_ajax_bizdir_delete_listing','bizdir_delete_listing' );
//Add Short Code
add_shortcode("bizdir_addform","bizdir_addform_shortcode"); //Add ShortCode for "Add Form"
add_shortcode("bizdir_directory","bizdir_directory_shortcode"); //Add ShortCode for "Directory"
//Register Hooks
register_activation_hook(__FILE__,'bizdir_install');
//Do Actions
do_action("activate_business-directory/business-directory.php");
/*
*  Insatllation Script
*/
function bizdir_install() {
global $wpdb;
global $bizdir_version;
//The Listings table is where all the user imputed data is stored
switch($bizdir_version) { //Determine the proper update/add script
	case "0.5 Beta":
	case "0.6 Beta":
	case "0.7 Beta":
	case "0.7.1 Beta":
		if($wpdb->get_var("show tables like '".BIZDIRDBTABLE."'") != BIZDIRDBTABLE) {
			$sql = 
				"CREATE TABLE ".BIZDIRDBTABLE." (
					listing_id int(11) NOT NULL AUTO_INCREMENT,
					date_created datetime NULL DEFAULT NULL,
					status tinyint(1) DEFAULT '0' NOT NULL,
					name varchar(100) NULL DEFAULT NULL,
					email varchar(100) NULL DEFAULT NULL,
					company_name varchar(100) NULL DEFAULT NULL,
					company_keywords varchar(100) NULL DEFAULT NULL,
					company_description text NULL DEFAULT NULL,
					company_url varchar(100) NULL DEFAULT NULL,
					company_email varchar(100) NULL DEFAULT NULL,
					company_phone varchar(100) NULL DEFAULT NULL,
					company_street1 varchar(100) NULL DEFAULT NULL,
					company_street2 varchar(100) NULL DEFAULT NULL,
					company_city varchar(100) NULL DEFAULT NULL,
					company_state varchar(100) NULL DEFAULT NULL,
					company_zip varchar(100) NULL DEFAULT NULL,
					company_country varchar(100) NULL DEFAULT NULL,
					PRIMARY KEY (listing_id)
				);"
			;
			require_once(ABSPATH.'wp-admin/includes/upgrade.php');
			dbDelta($sql);
		}
	break;
}
add_option("bizdir_version",$bizdir_version);
}
/*
*  Set Header for Ajax calls
*/
function bizdir_js_header() {
wp_print_scripts(array('sack'));//Include Ajax SACK library 
// Define custom JavaScript function
?>
	<script type='text/javascript' src='<?=BIZDIRCALLBACK?>main.js'></script>
	<script>
		function bizdir_add_listing(name,email,cName,description,keywords,website,cEmail,phone) { //Add Form Ajax Call
			//Deactivate submit button and display processing message
			document.getElementById('bizdir_submit').disabled = true;
			var submit_message = document.getElementById('bizdir_submit_message');
			submit_message.className = "bizdir_message";
			submit_message.innerHTML = "Submitting Form, Please Wait...";
			//Clear inputs with Auto Text
			var all_inputs = document.getElementsByTagName('input');
			for(var i=0;i<all_inputs.length;i++)
				bizdir_clearAutofill(all_inputs[i].id,all_inputs[i].getAttribute('bizdir_autofill'));
			var all_textareas = document.getElementsByTagName('textarea');
			for(var i=0;i<all_textareas.length;i++)
				bizdir_clearAutofill(all_textareas[i].id,all_textareas[i].getAttribute('bizdir_autofill'));
			//Build SACK Call
			var mysack = new sack("<?=BIZDIRCALLBACK?>requests.php");
			mysack.execute = 1;
			mysack.method = 'POST';
			mysack.setVar("action","AddListing");
			mysack.setVar("name",document.getElementById("bizdir_name").value);
			mysack.setVar("email",document.getElementById("bizdir_email").value);
			mysack.setVar("cName",document.getElementById("bizdir_cName").value);
			mysack.setVar("description",document.getElementById("bizdir_description").value);
			mysack.setVar("keywords",document.getElementById("bizdir_keywords").value);
			mysack.setVar("website",document.getElementById("bizdir_website").value);
			mysack.setVar("cEmail",document.getElementById("bizdir_cEmail").value);
			mysack.setVar("phone",document.getElementById("bizdir_phone").value);
			mysack.setVar("street1",document.getElementById("bizdir_street1").value);
			mysack.setVar("street2",document.getElementById("bizdir_street2").value);
			mysack.setVar("city",document.getElementById("bizdir_city").value);
			mysack.setVar("state",document.getElementById("bizdir_state").value);
			mysack.setVar("zip",document.getElementById("bizdir_zip").value);
			mysack.setVar("country",document.getElementById("bizdir_country").value);
			mysack.onError = function() { alert('An ajax error occured while adding your listing. Please reload the page and try again.') };
			mysack.runAJAX();//excecute
			return true;
		}

		function bizdir_search_listings() { //Search Ajax Call
			var search_term = document.getElementById('bizdir_search_term');
			if(search_term.value == "" || search_term.value == null)
				return;
			//Deactivate submit button and display processing message
			document.getElementById('bizdir_search').disabled = true;
			var submit_message = document.getElementById('bizdir_messages');
			submit_message.className = "bizdir_message";
			submit_message.innerHTML = "Searching Listings, Please Wait...";
			//Build SACK Call
			var mysack = new sack("<?=BIZDIRCALLBACK?>requests.php");
			mysack.execute = 1;
			mysack.method = 'POST';
			mysack.setVar("action","SearchListings");
			mysack.setVar("searchTerms",search_term.value);
			mysack.onError = function() { alert('An ajax error occured while searching. Please reload the page and try again.') };
			mysack.runAJAX();//excecute
			return true;
		}

		function bizdir_change_listings_page(offset) { //Jump to the appropriate page in the directory Ajax Call
			//Build SACK Call
			var mysack = new sack("<?=BIZDIRCALLBACK?>requests.php");
			mysack.execute = 1;
			mysack.method = 'POST';
			mysack.setVar("action","ChangePage");
			mysack.setVar("offset",offset);
			mysack.onError = function() { alert('An ajax error occured. Please reload the page and try again.') };
			mysack.runAJAX();//excecute
			return true;
		}
	</script>
<? 
}
/*
*  Navigation
*/
function bizdir_navigation() { 
add_menu_page(
	"Biz-Directory Manager",
	"Business Directory",
	8,
	__FILE__,
	"bizdir_show_manager",
	"http://businessdirectory.squarecompass.com/wp-content/themes/thematic/images/mini_bd_icon.png"
); 
}
/*
*  Add Form Script
*/
function bizdir_addform_shortcode($atts) { 
extract(shortcode_atts(array('width'=>'100%'),$atts));
return 
	"<link rel='stylesheet' href='".BIZDIRCALLBACK."main.css' type='text/css' media='screen'/>".
	"<hr/>".
	bizdir_addform($width).
	"<a href='http://businessdirectory.squarecompass.com/' target='_blank' class='bizdir_notes_grey'>Powered by Business Directory for Wordpress</a>".
	"<hr/>";
}
/*
*  Directory Script
*/
function bizdir_directory_shortcode($atts) {
//get attributes
extract(shortcode_atts(array('width'=>'100%','name'=>'Business Directory'),$atts));
//display Listings
return
	"<link rel='stylesheet' href='".BIZDIRCALLBACK."main.css' type='text/css' media='screen'/>". 
	"<form name='search' onSubmit='bizdir_search_listings(); return false;'>".
		"<b>Search the $name:</b> ".
		"<input type='text' id='bizdir_search_term'/>".
		"<input type='submit' id='bizdir_search' value='Search'/> ".
		"<div style='display:inline;' id='bizdir_messages'> </div>".
	"</form>".
	"<hr/>".
	"<div id='bizdir_directory' style='width:$width'>".bizdir_directory()."</div>".
	"<a href='http://businessdirectory.squarecompass.com/' target='_blank' class='bizdir_notes_grey'>Powered by Business Directory for Wordpress</a>".
	"<hr/>"
;
}
/*
*  Listing Manager
*/
function bizdir_show_manager() { 
echo "
	<link rel='stylesheet' href='".BIZDIRCALLBACK."main.css' type='text/css' media='screen'/>
	<div id='wpbody'>
		<div class='wrap'>
			<a href='http://businessdirectory.squarecompass.com/documentation/' target='_blank'>Business Directory Help/Documentation</a>
			<hr/>
			<div id='bizdir_messages'></div>
			<div id='bizdir_manager'>".bizdir_manager_home()."</div>
		<div>
	</div>
	<a href='http://businessdirectory.squarecompass.com/' target='_blank' class='bizdir_notes_grey'>Powered by Business Directory for Wordpress</a>
	</div>
";
} //Display manager

function bizdir_js_admin_header() { //Set Ajax Calls for manager
wp_print_scripts(array('sack')); //use JavaScript SACK library for Ajax
?>
	<script type='text/javascript' src='<?=BIZDIRCALLBACK?>main.js'></script>
	<script type="text/javascript">
		function bizdir_edit_listing(id) {
			clearMessage();
			//Build SACK Call
			var mysack = new sack("<? bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php");
			mysack.execute = 1;
			mysack.method = 'POST';
			mysack.setVar("action","bizdir_edit_listing");
			mysack.setVar("listing_id",id);
			mysack.onError = function() { alert('An ajax error occured while processing your request. Please reload the page and try again.') };
			mysack.runAJAX();//excecute
			return true;
		}

		function bizdir_update_listing(status) {
			clearMessage();
			//Disable buttons and display message
			document.getElementById('bizdir_save').disabled = true;
			var save_approve = document.getElementById('bizdir_save_approve')
			if(save_approve != null)
				save_approve.disabled = true;
			document.getElementById('bizdir_cancel').disabled = true;
			var submit_message = document.getElementById('bizdir_submit_message')
			submit_message.className = "bizdir_message";
			submit_message.innerHTML = "Submitting...";
			//Build SACK Call
			var mysack = new sack("<? bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php");
			mysack.execute = 1;
			mysack.method = 'POST';
			mysack.setVar("action","bizdir_update_listing");
			if(status == "approve")
				mysack.setVar("status",1);
			mysack.setVar("listing_id",document.getElementById("bizdir_listing_id").value);
			mysack.setVar("name",document.getElementById("bizdir_name").value);
			mysack.setVar("email",document.getElementById("bizdir_email").value);
			mysack.setVar("cName",document.getElementById("bizdir_cName").value);
			mysack.setVar("description",document.getElementById("bizdir_description").value);
			mysack.setVar("keywords",document.getElementById("bizdir_keywords").value);
			mysack.setVar("website",document.getElementById("bizdir_website").value);
			mysack.setVar("cEmail",document.getElementById("bizdir_cEmail").value);
			mysack.setVar("phone",document.getElementById("bizdir_phone").value);
			mysack.setVar("street1",document.getElementById("bizdir_street1").value);
			mysack.setVar("street2",document.getElementById("bizdir_street2").value);
			mysack.setVar("city",document.getElementById("bizdir_city").value);
			mysack.setVar("state",document.getElementById("bizdir_state").value);
			mysack.setVar("zip",document.getElementById("bizdir_zip").value);
			mysack.setVar("country",document.getElementById("bizdir_country").value);
			mysack.onError = function() { alert('An ajax error occured while updating the listing. Please reload the page and try again.') };
			mysack.runAJAX();//excecute
			return true;
		}

		function bizdir_show_manager_home() {
			clearMessage();
			//Build SACK Call
			var mysack = new sack("<? bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php");
			mysack.execute = 1;
			mysack.method = 'POST';
			mysack.setVar("action","bizdir_show_manager_home");
			mysack.onError = function() { alert('An ajax error occured while processing your request. Please reload the page and try again.') };
			mysack.runAJAX();//excecute
			return true;
		}

		function bizdir_change_status(id,status) {
			clearMessage();
			//Build SACK Call
			var mysack = new sack("<? bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php");
			mysack.execute = 1;
			mysack.method = 'POST';
			mysack.setVar("action","bizdir_change_listing_status");
			mysack.setVar("listing_id",id);
			mysack.setVar("status",status);
			mysack.onError = function() { alert('An ajax error occured while processing your request. Please reload the page and try again.') };
			mysack.runAJAX();//excecute
			return true;
		}

		function bizdir_delete_listing(id) {
			clearMessage();
			if(confirm('Are you sure you want to delete this listing? This listing will be perminantly removed.')) {
				//Build SACK Call
				var mysack = new sack("<? bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php");
				mysack.execute = 1;
				mysack.method = 'POST';
				mysack.setVar("action","bizdir_delete_listing");
				mysack.setVar("listing_id",id);
				mysack.onError = function() { alert('An ajax error occured while processing your request. Please reload the page and try again.') };
				mysack.runAJAX();//excecute
			}
			return true;
		}
	</script>
<?
}
The config file is
[code]
<?
$bizdir_relative = "wp-content/plugins/business-directory/";
define('BIZDIRPATH',ABSPATH.$bizdir_relative);
define('BIZDIRRELATIVEPATH',"/".$bizdir_relative);
define('BIZDIRCALLBACK',get_option("siteurl").BIZDIRRELATIVEPATH);
define('BIZDIRDBTABLE',$wpdb->prefix."biz_listings");
define('PERPAGE',30);
//Variables
$bizdir_version = "0.7.1 Beta";
//Require Scripts
require_once('functions.php'); //Load Biz-Directory Functions Library File

[/code]

Link to comment
https://forums.phpfreaks.com/topic/167783-shortcode-and-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.