I have a content type called "enquiry". I want to embed the node creation form at various places throughout my website. How do I do this via PHP?
sounds like a job for the webform module. if you really want to go the cck route you can try something like this:
$node = new stdClass();
$node->type = 'store_review';
module_load_include('inc', 'node', 'node.pages');
$output = drupal_get_form('store_review_node_form', $node);
print $output;
ref: http://drupal.org/node/464906
Solution:
$node = new stdClass();
$node->type = 'enquiry';
module_load_include('inc', 'node', 'node.pages');
$output = drupal_get_form('enquiry_node_form', $node);
print $output;
Related
i am running a perl script from a linux machine to log onto a router remotely to collect data. few of my client requirements include screenshots of specific configs.
i tried using
Imager::Screenshot
But each time it is printing a black screen. Is there a better way to capture screenshots of the router output, rather capturing the screenshot of the linux screen would work well for me as well.
Thanks in advance
Please refer this coding:
sub new {
my $class = shift;
my #params = ();
#params = #{shift()} if _ARRAY0($_[0]);
my $image = Imager::Screenshot::screenshot( #params );
unless ( _INSTANCE($image, 'Imager') ) {
Carp::croak('Failed to capture screenshot');
}
# Hand off to the parent class
return $class->SUPER::new( image => $image, #_ );
}
give thanks to: Taking Screenshot in perl
I am trying to set up a class for tracking changes in the content by different authors. I did RnD and found text_Diff is the pear package which is responsible for the same. Later, text_diff is maintained at
'http://pear.horde.org/'
I am now trying to run the example
include_once "Text/Diff.php";
include_once "Text/Diff/Renderer.php";
$from_text=file('file.html');
$to_text=file('file_edited.html');
$diff = new Horde_Text_Diff($from_text, $to_text);
$renderer = new Horde_Text_Diff_Renderer();
echo $renderer->render($diff);
and I am getting the error 'Horde_String'
I am not able to find class, any one has idea about this class?. There are multiple Engine like "Native","XDiff","String" and "Shell" ...but I am not able to find what are they and when you use which one..
any help to resolve this error will be a great help.
Thanks
I struggled for hours trying to get this to work. In the end I had to install Horde_Text_Diff by entering the commands (installs the Autoloader described in the linked question in the comment by Keelan):
pear install Horde_Autoloader
pear install Horde_Text_Diff
This installs the packages I believe you need. Then, you need to properly call the autoloader package by tweaking the following code to match the paths for your system.
require_once 'Horde/Autoloader.php';
require_once 'Horde/Autoloader/ClassPathMapper.php';
require_once 'Horde/Autoloader/ClassPathMapper/Default.php';
$autoloader = new Horde_Autoloader();
$autoloader->addClassPathMapper( new Horde_Autoloader_ClassPathMapper_Default('/usr/share/pear') );
$autoloader->registerAutoloader();
Then, if all goes well you should be able to call and use the class by doing something like the following:
$check_diff = new Horde_Text_Diff( $engine = 'auto', $params = array( $from_text, $to_text ) );
$renderer = new Horde_Text_Diff_Renderer_Inline();
echo $renderer->render($check_diff);
Although this isn't totally working for me yet as I'm finding that it only compares the first characters in the strings. Which is a new problem unrelated to getting the class to work :)
Here is my approach, which does not use the Hoard autoloader:
spl_autoload_register(function ($class_name) {
if (substr($class_name, 0, strlen('Horde_')) != 'Horde_')
return false;
$file = substr($class_name, strlen('Horde_')); // omit if not needed
$file = str_replace("_", DIRECTORY_SEPARATOR, $file);
return include_once($file . '.php');
});
function diff($old, $new)
{
$td = new Horde_Text_Diff('auto', array($old, $new));
$rend = new Horde_Text_Diff_Renderer_Unified();
return $rend->render($td);
}
I have a problem with the "new" Facebook plugin for Wordpress. I would like to re-position it on my post page. I've read somewhere else (or maybe here) that you could use the comment box from developers.facebook.com but I want to use the original Facebook plugin. So here goes:
I've found (in the plugin folder) where Facebook have put the code to install comments box in my theme. It looks like this:
public static function the_content_comments_box( $content ) {
global $post;
if ( ! isset( $post ) )
return;
$options = get_option( 'facebook_comments' );
if ( ! is_array( $options ) || empty( $options ) )
return $content;
// closed posts can have comments from their previous open state
// display noscript version of these comments
$content .= "\n" . self::comments_markup( 'noscript' ) . "\n";
// no option via JS SDK to display comments yet not accept new comments
// only display JS SDK version of comments box display if we would like more comments
if ( comments_open( $post->ID ) ) {
$url = apply_filters( 'facebook_rel_canonical', get_permalink() );
if ( $url ) // false could happen. let JS SDK handle compatibility mode
$options['href'] = $url;
$content .= self::js_sdk_markup( $options );
}
return $content;
}
}
How do put the Facebook comments box in the bottom of my post page?
You can look at a random post page here: My temporary site What I'm ultimately trying to do is to have Facebook Comments box after Relaterede indlæg (related posts).
Is this at all possible?
I don't use the FB plugins for Wordpress because they seem bloated to me. However, here's a simple one-line code that I use to add a facebook comments box. You can place it anywhere in any template.
<div class="fb-comments" data-href="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ?>"></div>
PLEASE NOTE: this method requires that you have the Facebook SDK installed on the site. Also, it won't work as a widget unless you have enabled the ability to execute PHP in your widgets (requires a plug-in).
I'm learning Kohana 3.2.0 together with KSmarty for Kohana 3. I'd like to write an anchor on the page like this:
Page list
I can build the url in the controller and pass it to Smarty as a variable but. Is there a way to build the anchor or URL in Smarty template (including "http://www.mysite.cz" part)?
If it is not possible to build the anchor. Is it at least possible to build full URL?
The Reason: I have a main template which includes another template.
The main template will be used by multiple controllers and I would like to avoid building the URL in each controller. Therefore I'll be happy if KSmarty will be able to do it for me.
The only solution I have found is to write custom function. Save following code into function.url.php file in Smarty plugins directory:
function smarty_function_url($params, &$smarty)
{
$type = '';
if(isset($params['type'])) $type = $params['type'];
$protocol = 'http';
if(isset($params['protocol'])) $protocol = $params['protocol'];
$url = '';
if(isset($params['url'])) $url = $params['url'];
$text = '';
if(isset($params['text'])) $text = $params['text'];
switch($params['type'])
{
case 'url':
return Kohana_URL::site($url, $protocol);
case 'anchor':
$url = Kohana_URL::site($url, $protocol);
return "<a href='{$url}'>{$text}</a>";
default:
return Kohana_URL::base('http');
}
}
Examples of use in Smarty template:
{url}
{url type='url' url='admin/categories' protocol='https'}
{url type='anchor' url='admin/articles' text='List of articles'}
The first block in which variables are set I had to write otherwise Smarty was generating notice "Undefined variable...". I'm just PHP student, suggestions for code improvement are welcome.
Hope it will help the others.
I managed to pull out data using autocomplete at my local (http://mysite.dev/swan/autocomplete). The json data is displayed.
But when I applied the same module at live (now a subdomain: http://test.mysite.com/swan/autocomplete with different drupal installs), this autocomplete fails to pull out data. No json data is displayed.
Do you have any idea if this is related to cross domain issue, or any possible cause I might not be aware of?
This is the callback:
/**
* Callback to allow autocomplete of organisation profile text fields.
*/
function swan_autocomplete($string) {
$matches = array();
$result = db_query("SELECT nid, title FROM {node} WHERE status = 1 AND type='organisation' AND title LIKE LOWER ('%s%%')", $string, 0, 40);
while ($obj = db_fetch_object($result)) {
$title = check_plain($obj->title);
//$matches[$obj->nid] = $title;
$matches[$title] = $title;
}
//drupal_json($matches); // fails at safari for first timers
print drupal_to_js($matches);
exit();
}
Any hint would be very much appreciated.
Thanks
It's the conflict with password_policy.module. Other similar modules just do the same blocking. These modules stop any autocomplete query.