I want to create a content plugin on Joomla.
i want to put [picasa id="5551971516356491729"] and that the album will show.
i create a php function that return html for the album.
i will need to had the js code for the light-box.
i have a content plugin that create the light-box can i applay content plugin on another one?
i meen that my plugin will create a code like that [lightbox link="www.example.com/image1.jpg"] and the light-box plugin will generate the html?
Start here http://docs.joomla.org/Creating_a_content_plugin
Your primary function would look something along the lines of...
function onPrepareContent( &$article, &$params, $limitstart )
{
$pattern = '/(\W)[picasa id="([0-9_]+)"](\W)/';
$replacement = '$1#$2$3';
$article->text = preg_replace($pattern, $replacement, $article->text);
return true;
}
You will need to format the new html in a way that your lightbox plugin will detect it and do it's magic.
Related
I'm building a wordpress plugin where I have to render some specific content when appropriated instead of pages.
Here is the current situation (all files are in the root folder of the plugin):
my-template.php
<?php
echo "hi world";
my-plugins-main-php-file.php
//...logic to determine if the content of the page has to be rendered...
function load_template(){
return __DIR__."/my-template.php";
}
add_action('template_include', 'load_template');
And here is the desired result:
my-plugins-main-php-file.php
//...logic to determine if the content of the page has to be rendered...
add_action('string_include_or_some_other_hook',"hi world");
Is there a hook or some other method I can use to render some wordpress content directly from a string?
Thanks!
Here is the solution to my question, thanks to #ArtisticPhoenix:
my-plugins-main-php-file.php
//...logic to determine if the content of the page has to be rendered...
function load_template(){
return __DIR__."/my-template.php";
}
add_action('template_include', 'load_template');
$string = "hi world!";
add_filter('the_content', function() use ($string){
return $string;
});
my-template.php
<?php
the_content();
So i created a plugin that is basically a gallery that you choose options as you go.
First choose Brand
Then Color
Then Style
At each step i am passing the variables via $_GET
So once you have chosen your brand and continue the next page URL is cabinets/?brand=1
Then after you choose your color it is cabinets/?brand=1&color=2
i have written a rewrite for this that is supposed to make pretty urls but all it is doing is showing the home page.
add_filter('rewrite_rules_array','cabinets_rewrite_rules_array');
function cabinets_rewrite_rules_array($rules){
$cabinets_slug = 'cabinets';
$my_cab_rules[$cabinets_slug.'/?$'] = $cabinets_slug."/?brand=$matches[1]";
$my_cab_rules[$cabinets_slug.'/(.+?)/?$'] = $cabinets_slug."/?brand=$matches[1]&color=$matches[2]";
$my_cab_rules[$cabinets_slug.'/(.+?)/(.+?)/?$'] = $cabinets_slug."/?brand=$matches[1]&color=$matches[2]&style=$matches[3]";
return $my_cab_rules + $rules;
}
i have tried many things even as much as updating the htaccess file but i dont want to have to do that since this is a plugin.
Any Idea?
You could try adding your new variables to the list of query vars.
function prfx_add_query_vars($aVars) {
global $wp_query;
$aVars[] = "brand";
$aVars[] = "color";
$aVars[] = "style";
return $aVars;
}
add_filter('query_vars', 'prfx_add_query_vars');
So this is the problem I am running into. If I have a comment object, I want to create a renderable array that is using the display settings of that comment. As of now this is what I have:
$commentNew = comment_load($var);
$reply[] = field_view_value('comment', $commentNew, 'comment_body', $commentNew->comment_body['und'][0]);
Which works fine because I dont have any specific settings setup for the body. But I also have image fields and video embed fields that I need to have rendered the way they are setup in the system. How would I go about doing that?
Drupal core does it with the comment_view() function:
$comment = comment_load($var);
$node = node_load($comment->nid);
$view_mode = 'full'; // Or whatever view mode is appropriate
$build = comment_view($comment, $node, $view_mode);
If you need to change a particular field from the default, use hook_comment_view():
function MYMODULE_comment_view($comment, $view_mode, $langcode) {
$comment->content['body'] = array('#markup' => 'something');
}
or just edit the $build array received from comment_view() as you need to if implementing the hook won't work for your use case.
iam using ckeditor in my website to add the content to the pages.
But I'm not able to understand how I get this content in ckeditor for editing it later...
How to load content into the ckeditor? Iam using the following code to load the editor:
if ( !#file_exists( '../../ckeditor/ckeditor.php' ) )
{
if ( #file_exists('../../ckeditor/ckeditor.js') || #file_exists('../../../ckeditor/ckeditor_source.js') )
printNotFound('CKEditor 3.1+');
else
printNotFound('CKEditor');
}
include_once '../../ckeditor/ckeditor.php';
include_once '../../ckfinder/ckfinder.php';
// This is a check for the CKEditor class. If not defined, the paths in lines 57 and 70 must be checked.
if (!class_exists('CKEditor'))
{
printNotFound('CKEditor');
}
else
{
$ckeditor = new CKEditor();
$ckeditor->basePath = '../../ckeditor/';
$ckfinder = new CKFinder();
$ckfinder->BasePath = '../../ckfinder/'; // Note: BasePath property in CKFinder class starts with capital letter
$ckfinder->SetupCKEditorObject($ckeditor);
$ckeditor->editor('message');
}
One way is to pre-populate the <textarea> field with the appropriate (htmlentities() processed) HTML content. CKEditor will automatically fetch the data, and insert it into the WYSIWYG editor.
See the Integration chapter in the developers guide
For those who not found the answer, the "editor" method of ckeditor allow to load default value
public function editor($name, $value = "", $config = array(), $events = array())
Just pass your default value in the second parameters.
I'm trying to create a function that does a text replacement on the post content when its saved (the_content).
The stub function is below, but how do I obtain a reference to the post content, then return the filtered content back to the "publish_post" routine?
However, my replacement is either not working and/or not passing the updated post_content to the publish function. The values never get replaced.
function my_function() {
global $post;
$the_content = $post->post_content;
$text = " test ";
$post->post_content = str_ireplace($text, '<b>'.$text.'</b>', $the_content );
return $post->post_content;
}
add_action('publish_post', 'my_function');
When you mention the_content, are you referencing the template tag or the filter hook?
the_content as a filter hook only works on post content during database reads, not writes. The filter to use when modifying post content right before it is save to the db is content_save_pre.
Code Example
In your plugin or theme's functions.php, add your function, using $content as the argument. Modify the content any way you wish, and be sure to return $content.
Then use add_filter('filter_name', 'function_name') to run the function when the filter hook is encountered in WordPress.
function add_myself($content){
return $content." myself";
}
add_filter('content_save_pre','add_myself');
If I write a post that includes:
"To the end of posts, I like to add"
when saved to the database and displayed on the site, it will read:
"To the end of posts, I like to add myself".
Your example filter might be revised to look like this:
function my_function($content) {
$text = " test ";
return str_ireplace($text, '<b>'.$text.'</b>', $content );
}
add_filter('content_save_pre','my_function');
Probably easier to do something like this:
function my_function($post) {
$content = str_ireplace(" test ", '<b>'.$text.'</b>', $post->content);
return $content;
}
Less focus was on the interior of the function, but the idea is that you pass the object to the function in the () then call the directly rather than globalizing the value. It should be more direct that way.
the passed variable here is $id. This should work:
function my_function($id) {
$the_post = get_post($id);
$content = str_ireplace(" test ", '<b>'.$text.'</b>', $the_post->post_content);
return $content;
}
add_action('publish_post', 'my_function');