Where to put custom function in Joomla - php

I want to create some function for rendering images from within Joomla v1.5.23. That function should be visible through all joomla application.
Where I have to put that function? Should I create plug in, modul or something else?
Best regards

Version info would be helpful, but I believe your answer is to create a plugin. Components are very broad "mini applications" installed and executed within Joomla. Modules are typically pieces of code that display information from a component, or an outside source. Plugins have various places within Joomla, depending on what they do - like authentication, or admin, etc. You'll have to define what role the plugin will play to determine where it fits into that hierarchy. Once done though, the plugin will be loaded, and you'll be able to access it's functions from within Joomla.
This link will show you how to begin by writing a content plugin. Note the events that are available. This isn't too difficult to do, so don't overcomplicate it, and you should be fine. An example of a System Plugin (which sounds like what you're looking for) can be seen at http://docs.joomla.org/Plugin/Events/System.

Related

CMS without front-end part

I am primarily a front-end developer, that means I like to design the websites myself, including scripts, CSS and HTML.
But popular CMSs won't let me to do that. They generate completed webpages as they need to. But I am not able to override the outcome and I have to use the very limiting default pages.
Once I discovered a small CMS called MNews, which was really useful. It let me to write all the pages myself, and at some point, where I wanted to include an article, I wrote a small PHP script:
<div id="article">
<?php
$article_id = 12;
include mnews/inport_article.php;
?>
</div>
And it included then the article with formatting I've set earlier in the setting in the CMS.
However, the customers started to complain that the used CMS is difficult and that they are used to WordPress. But I can't use WordPress because of the non-ability to design the pages myself.
So, do you know another similar CMS, which would let me to do the design and including myself?
I have used Wordpress to create my own pages in PHP. There are two very easy ways to do that.
You can create a shortcode which allows you to run your own PHP command on a page.
If you want to have complete control over the page, you can create your own page template. This allows you to build an entire page from scratch, whilst still having access to Wordpress' features.

Converting PHP site to Joomla

I have a large complex web site currently implemented using PHP and MySQL.
Some of the pages (about, contact us, etc) are largely static, but need to be updated from time to time. I'd like these updates to be able to be done by non technical admins, so I'm migrating the site to Joomla CMS. I've created a Joomla template to reproduce the banners, styling etc of my existing web site and have successfully reproduced the static pages by cutting and pasting into Joomla articles.
I'm now trying to embed my existing dyanamic php pages into the Joomla framework. I assume that I need to convert them into one or more Joomla components? I realize that I'll need to strip out the php code that currently generates banners, menus, etc, but I don't want to make major changes to these php pages, i.e. I don't want to re-implement them to follow an MVC pattern. I'm looking for a simple Joomla 3.2 hello world component tutorial. The tutorials that I've found are either too complex (i.e. MVC) or they're "too simple". By too simple I mean the component is not listed when I select Menu Item Type within the Menu Manager. Can anyone point me to any documentation that explains the minimal config that I need to include in a custom Joomla 3.2 component in order for the component to be listed when selecting Menu Item Type?
Also, should I create one big custom component to wrap my existing PHP application containing multiple pages("views"?)? Conceptually there the system could be considered as about 3 sub-systems, but there is some overlap between the MySQL tables used in these different sub-systems.
I don't need the implementation to be portable, i.e. I'm not trying to create a reusable component that others could use, I just need it to work on my site, using the least amount of work possible.
Thanks, Wayne.
I hope to clarify a bit and give you way out.
In response to your comment on #user3057084, the power of Joomla and its flexibility comes from it being MVC! If you want to wrap your existing code with little modifications, Wordpress will let you do all kind of nasty things! Nasty in the sense of mixing logic with data, i.e. copying and pasting your code and getting it to work quickly.
Joomla coding standards require that you separate models from views. And that you understand how the Joomla MVC implementation works. It will take longer, but you'll learn a useful skill that can and should be applied if you want to write portable maintainable code following Design Patterns.
Now about the way out.
Nothing keeps you from putting your raw php code in a Joomla view, including the database access. It's really ugly and I feel bad even suggesting this, but if it can be a small step towards using a great framework, then the end justifies the means.
The absolute easiest way for you in Joomla would be to create a template override (which you'll do from the admin with a few clicks in the template manager), then throw your code in, and it will run. Then, a little bit at a time, you might learn to separate the parsing of the input in the controller, store / retrieve the data in a model, and leave just the markup in the view.
But are you absolutely sure you need to code for this? There are thousands of (free) extensions out there that might do the job for you with no coding and little configuration, leaving you just a data migration to handle.
Have you had a look at Wordpress yet? In my experience, non-technical people find it easier to administer a wordpress website in comparison to a Joomla website.
When it comes to the menu structures,themes and contact forms and blogs - Wordpress takes the cake.
It would be worth your while to check it out? It might save you hours of frustration?

Creating multilingual wordpress site with shared structure and php functions

I know there are many multilingual wp plugins but I'm not sure which method should I use for this purpose;
I'd like to create a wp site with advanced features, partly coded by myself in php. Then I generally want to create duplicates of this site's structure, design and behavior in other languages, for example, es.blog.com would be a duplicate of en.blog.com. The content, however, shouldn't be shared.
I'd also like to keep changing the code only at one place and make those changes affect all the other languages duplicates, so I assume that means the code itself, or parts of it, would be shared.
Is there a way to have a shared structure, design and functions for several blogs, while the content of each blog is different?
I believe this is a perfect case for WordPress Multisite.
Multilingual Network (forum thread)
I would like for users to choose their language when they first get to the site - so they can choose to read, register, administer the entire site (front end and back) in either English, Kurdish (and perhaps others).
How to set a bilingual or multilingual WordPress multisite blog (blog post)
I need two independent sites to facilitate the plugins and theme localization with an easy way to switch between languages if a translation is available. Another reason is to optimize the search engine indexing. With this solution I can have some language specific posts without translation.
[ update ]
Multilingual Press (plugin)
Each site/blog can then be attributed to a different language. Simply write a post or page in one language and Multilingual-Press will automatically create a duplication of it in the other sites/blogs. These new posts and pages are interlinked and are easily accessible via the post/page editor screen - you can switch back and forth to translate them! Multilingual-Press is WordPress conform, easy to install and doesn't make any changes to the WordPress core. It doesn't harm your website's performance.
You could use any MVC framework to achieve this, and simply store the data in a database with a 'language' field and call only rows from that language.
Google 'MVC Framework'.
A good and free example would be CodeIgniter.
In CodeIgniter, you can include the Wordpress files in your 'libraries' folder then create a model with the specific functions you need to use.
Finally, you would have to create an .HTACCESS file to get the sub-domain section from the URL if you were to use this approach, however, again, there are many tutorials on achieving this, google 'htaccess URL rewrite'
I wouldn't recommend WP for any true multilingual site, searches get messed up, plugin-incompability etc.
Install parallell WP-instances in subdirs and make one the "master" for dev/bugfixes. Content is isolated and you can use standard WP-features without metadata or plugin-hacks.
By "changing the code", I presume you mean the template? It's a simple drag'n'drop in a decent ftp-client.

Which CMS for having a mixture of CMS-enabled pages and my PHP programs?

I'm creating a website which has a public-facing side, which I want selected users to be able to edit like in a CMS, but I also want to create a private intranet side which is made up of pages written in PHP by me to perform certain functions, but are not part of the CMS as such.
So basically I want:
- Some CMS-ified pages which are user-editable
- Some custom pages which use the CMS templating engine, authentication etc..
Which would be the best CMS for this?
Drupal is really good when you need this kind of flexibility. You can easily configure it to link to other pages via the menu system and TBH, it's so flexible, you'll find that anything you would want to hand code for the intranet can be done by installing and configuring existing third party modules, with the option of writing a custom module if you really have to.
We do developments like this and bring all of the intranet stuff into Drupal by putting code into a custom module and having the functions called by simple forms made in Drupal. To see data from internal DBs, tell Drupal the DB details in the config, then use the views module to make lists etc.
Not sure if it's the best, but Drupal is a very good candidate based on your description.
Your custom pages can be implemented in a module (PHP code). Specific URLs can be declared as being handled by your module and the rest of the CMS will not get in the way if you don't want to. From the point of view of your code, Drupal can be seen as a kind of framework.
I might use drupal. From what I've done with it, it seems very customizable. It's more flexible and seems more clean and secure than something like joomla. There are plenty of addon's. I haven't done enough with it to get to the point where I was interfacing my own PHP pages with it, but if I had to try anyone that's what I would go with.
I, however, personally just make my own CMS. It might be more work, but then everything is the way that I want it to be. It depends on how much you want them to be able to edit. For example, I was making a website for a shop, and so I created a place where they could add and remove items, which wasn't that difficult, especially since it was database based. To be able to do things like change menus and appearance and such might be harder...probably look towards something like a CMS.

What to keep in mind when making Wordpress themes

I have been making Wordpress themes for a year or two and keep running into things I need to keep in mind when trying to make my themes as compatible and flexible as possible with their settings, plugins, etc.
Is there a resource that keeps a checklist of all the "don't forgets" of Wordpress theming? What things do you try to keep in mind when building your Wordpress themes?
Examples:
Checking if the author/admin has disabled comments for a particular post.
Remembering to call wp_head() at the end of the <head> tag.
Remembering to call wp_footer() at the end of the <body> tag.
Using bloginfo() variables instead of setting static values for charset, html type, description, etc. so admins can modify such things in the site settings.
Using function_exists() before calling a function from a plugin so it fails gracefully if that plugin isn't installed.
Wordpress documentation has an interesting topic addressing exactly what you're asking: it's called Designing Themes For Public Release. There's also Theme Development General Guidelines. The Templates article is wonderful too.
I don't know other official resources, but it would be interesting to add more info into those three guides. I'm interested in some other answers we may have in your question to complement them.
I'm so used to Wordpress that the examples you wrote just flows automatically when I'm developing, since using a function that outputs domain information such asbloginfo() instead of static values is a good practice in any web development.
A theme development checklist depends more on the intended audience for your theme. If it's beyond the basic blog and moving towards WordPress-as-CMS territory, you'd want to look into:
custom widgets and dynamic sidebars to make features more portable and flexible
support for custom fields, or plugins like MagicFields that implement the former in a whole new way
routing and creating custom templates for different levels of the site (ex: sub-categories get handled by category-x.php)
using a css framework so whoever gets to modify the styles has a higher chance of understanding it better; make sure to include ie support
custom wp-admin section with its own menus, pages, etc.; this is especially necessary if your theme has custom functionality that can be further customized by the user
use the wp_scripts and wp_styles classes and functions to add styles and scripts; this is especially important for javascript, as it prevents duplicate includes and works with dependency scripts (loads jQuery before your jQ script)
make sure the design of the theme doesn't look boring like everything else out there for WordPress
write a theme class; unless you're planning to support PHP4, use PHP5 classes and objects to make your life easier, in terms of feature inheritance and no naming conflicts. look at CodeIgniter and their singleton pattern; it makes custom globals inside template files a lot easier to manage
if you are (and you should be) making your theme a lot more advanced and more like a plugin, then know how to use the WP_Cache and WP_Rewrite objects so your custom queries with $wpdb (yes, you'll need to do these once in a while to get certain custom functionality) are less expensive, and your new pages (if you're rewriting urls) route correctly and your links are correctly dynamically generated, respectively.
last and most importantly, try your hardest to separate presentation (html) from logic (php); this gets hard as you start running custom WP loops and a good solution is the aforementioned theme class.
Our firm also develops a lot of various WordPress & WordPress MU themes & we haven't found any "Official" resources, but one thing we've done is create a basic set of template files can can be used as a "standard" setup in order to speed up our development process.
Then, whenever a new theme needs to be developed, we basically copy / paste this default set of template files into a new theme folder on the WordPress install. For us, items we've included in this default setup are pre-populated header.php, footer.php, index.php, home.php, single.php, functions.php, comments.php, /images (dir), /functions (dir), style.css, /css (dir), /scripts (dir), and a handfull of other items.
Then we've also used Yahoo Grids or Google Blueprint css frames works to also speed up the css work. There's a few other items / files I'm leaving out, but should give you a general idea of what works best for us in our shop.

Categories