Categories
CMS Php SilverStripe

Extending SilverStripe 3 Site Settings

When you first install your SilverStripe site, the ‘Settings’ menu is pretty limited, offering just Title, Tagline, and a choice of templates.

This is fine, but it’s often useful to add other options, such as logo upload, links to facebook, uploading a banner image that appears on every page.

MySiteConfig.php

In your ‘mysite/code/’ folder, create a new file called ‘MySiteConfig.php’, and insert the following text:

This file creates a ‘DataExtension’. A DataExtension, as the name suggests, is used to extend any set of data. You declare the additional databse fields and relations just as you would when creating a new page.

And you use the function ‘public function updateCMSFields {}’ to add the fields to the CMS page, just as you would when creating a new page.

_config.php

In your ‘mysite’ folder, open the ‘_config,php’ file, and add the following line:

This line simple tells SilverStripe to take the ‘SiteConfig’ (the basic settings that already exist) and add ‘MySiteConfig’ to it.

Dev/Build

Go to your site, log in, and add ‘/dev/build’ to the URL – eg ‘mysite.com/dev/build’ to refresh the database.

Now, in the admin area, go to the site settings page and you should see your new options.

Using these fields in the Template

You can now add a logo, banner image, and enter the facebook / vimeo links – the data is stored in the database, but we need to show it on our page.

We do this by adding ‘$SiteConfig.’ in front of the names of the fields. Eg:

Categories
CMS SilverStripe

Silverstripe 3 Many Many – A Comprehensive Example

I see that the website hosting this resource has disappeared, so I’ll try to save this article, as it might come in handy. The images are gone, so I’m only able to save low quality versions.

How to create set up a many_many relation using the SS3 gridfield

In this article we’re going to a create a very simple shop. We’ll create pages for various product categories. And we’ll create products. Some our products will appear in more than one category.

Eg. Each ‘Category’ -> has many-> Products
and each ‘Porduct’ -> has many -> ‘Categories’

This is many_many relationship. In the database, we end with 3 tables – one containing the Categories, one containing the Products, and one table which contains a list of ‘links’ between the products and categories.

Create the Category Page

Create ProductCategoryPage.php

This is the page on your site that will list the the products.

We define the many_many relation to the product, and then set up the gridfield to allow us to manage the products in the CMS.

We use the config option ‘GridFieldConfig_RelationEditor’ to make the datagrid show the right options. We also add “GridFieldDeleteAction(‘unlinkrelation’)” to the config. This allows us to ‘delete’ a product altogether (from all categories), or just remove (unlink) it from the category page we’re editing.

 

Create the Product Object

Create Product.php

This is the object that contains data about each product – at this stage we simply have a title and a photograph.

We also define the fact that this item belongs to a many_many – this ties the two parts together nicely.

We’ll also define the summary fields shown in the CMS – or else it will just show the ID, which isn’t much use.

We’re adding a function here to show a thumbnail image – why not – it looks nice!

And finally, we’re calling getCMSFields, and setting up a datagrid so that when we’re on a product page, we get a nice table showing us what categories are related to that product.

 

At this stage, upload the files, run a dev/build and create a few ‘ProductCategoryPages’ in your CMS.

Adding New Products

In your CMS, choose one of the new ‘Product Category’ Pages. And move to the ‘Products’ tab.

resizedimage400231-add-product

You should see a screen similar to the image above

Click ‘add product’

resizedimage400231-add-product-2

Give the new product a title, in this case we’ll call it ‘Wheel’ – but don’t bother adding an image. You’ll need to click ‘Create’ first, and then add the image, then ‘Save’ it again.

resizedimage400231-add-product-3

Once you’ve saved your product, click ‘Back’ at the top of the page to return to the main category page

Adding an existing product to another category

Now that we have a product, we can add this product to another category by going to the other page, and again, to the ‘products’ tab

resizedimage400231-add-product-4

Here is another list of products – this time though, instead of clicking ‘Add Product’ to create a new products, we’ll search for an existing product – in this case ‘wheel’.

resizedimage40063-add-product-5

Enter the first few letters of the product in the box next to ‘add product’ and Silverstripe will come with a list of items that match the search. Click on the item you want to add, and then click ‘Link Existing’. The item will now appear in both category pages.

Removing an Item

At the start of this article we added

It’s now that this little line becomes important. It adds an extra icon into right column

add-product-6

These icons are ‘Edit’, ‘Delete’, and ‘Unlink’

‘Delete’ will remove the product from the database – and remove it from any categories it belong to.

The ‘Unlink’ button allows you to remove it from just this page while leaving it in the database for any other pages that it might belong to.

Note. If you click on an item, and then click on the ‘product category’ tab in the top right – you’ll see a list of pages this item belongs to, where you can also unlink a category from the product, or attach a new category. However note that if you click the ‘delete’ button here you will be deleting a page off your site.

Creating the Templates

Now come the fun bit – making the template to display the information.

The details will of course depend how you want your page to look. This is very basic example

Create ProductCategoryPage.ss with your templates Layout folder

Something like the following will be enough to show your products…

 

Categories
Php SilverStripe

SilverStripe 3.0 – Batch Translate

As a common request around the web is to translate the entire Site Tree. Following the post on: https://www.silverstripe.org/customising-the-cms/show/7318 Which was made for SS 2.3.2, I’ve adopted the code to work with SilverStripe 3.0 (Tested on 3.0.5). It gives you the ability to select entire site tree, or just parts of it, and translate it to draft or to published site.

Categories
CMS Php

Some customization of SilverStripe 3.0

I just started with SilverStripe, and here are a few things I stumbled upon while testing the possibilities of this Framework/CMS, hope it will be helpful to someone.
First, some things you can do right in your mysite/_config.php. You can remove most of the admin menu links by using:
CMSMenu::remove_menu_item(‘ReportAdmin’); // Reports link for example
Also, you can define the Admin page title, not to display SilverStripe with:
LeftAndMain::setApplicationName(“MyApplication”);

There are two ways to remove the index.php/ part from the url, but before you do that make sure your mod_rewrite is working. First way is to edit the first line of code in index.php so it says:

define('BASE_SCRIPT_URL',''); // Originally : define('BASE_SCRIPT_URL','index.php/');

The other way is to just completely delete index.php

And for those that don’t like the “Help” link in the admin menu, you have to go a bit deeper and edit /framework/admin/code/LeftAndMain.php.

As it says at line 173:

// can’t be done in cms/_config.php as locale is not set yet

So, you can just comment out the following lines:

/*CMSMenu::add_link(
'Help',
_t('LeftAndMain.HELP', 'Help', 'Menu title'),
self::$help_link
);*/

Happy coding!

Categories
Php

Use Zend Framework 2 from sub folder

I just started testing the Zend Framework 2, and I wanted to give it a quick look around with the Skeleton Application. I didn’t want to add virtual hosts to my local Apache, as I have more important stuff I’m working on, so I just wanted to make a folder for it and run the application.

I’ve read some post about placing it in sub folder, but the real thing was much simpler. What I did was installing the application in https://localhost/zend/, then just copied everything from “public” folder to the sub folder root . After that, it was enough just to comment out the line:

 

It’s just as easy as that, navigate to  https://localhost/zend/, and you should be presented with skeleton application.

Categories
JavaScript

Integrate CKFinder with TinyMCE

I know TinyMCE isn’t very popular lately, since it’s not free any more, but I was asked by a client to fix the file uploading with TinyMCE in their CMS. It uses the last free version of TinyMCE – 1.41, and used to have TinyBrowser integrated for file browsing. As the TinyBrowser stopped working and support is equal to nothing, I decided to integrate CKFinder instead.

It wasn’t an easy task, but bit by bit i somehow managed it. What’s even worse, their CMS didn’t use any frameworks, so I decided to keep it that way, and wrote pure javascript. The script isn’t very nice, but it works.

OK, let’s get to the coding part. After importing the needed .js files first thing that needed to be done is defining the custom function in TinyMCE initialization that will be called when the Browse button is pressed.

 

Here it’s named myFileBrowser (file_browser_callback : ‘myFileBrowser’). Nothing much to say about that, so let’s skip to myFileBrowser function, which launches the CKBrowser itself.

 

I left the comments from the example I found for using CKBrowser with a textfield. So, basicaly we just init the finder and set what function will be called when the file is selected. SetFileField is the function that is left to be created, and file_name will be contained in the data array passed to the function. Let’s get onto it:

 

This part was a bit tricky, since TinyMCE opens iFrames in modal dialogs I couldn’t just access the text field by it’s id, but had to access it via iFrames id. To do that, as the frames id is generated again with each modal opening, I had to find the current assigned id. I used a bit of trick there, by accessing the overlay div by class, as it is always static (clearlooks2), and then getting element by tag name “iframe”. Once I had that prepared, I was able to get the field by id and populate it’s contents. In my case, as there was no framework support, I used Robert’s Ultimate getElementsByClassName to get the element by class.

I don’t know if this will be useful to someone, as TinyMCE is disappearing from the scene, but if anyone get’s in a similar situation, I’m sure this will help.

Categories
General

Transmit audio over TeamViewer

Update:

With new version of TeamViewer (8.0) audio is transmited by enabling “Computer sounds” from Audio/Video menu. If you need advanced options you can check other options in Audio/Video menu.

With new TeamViewer V 7.0 we’ve got the possibility to transfer audio from, or to, remote PC. The sound quality is not best (depends on the connection, but it’s also meant for voice, not high quality audio).

The trick is using the new “Voive over IP” option, that can be found under “Audio/Video” menu in TeamViewer’s toolbar. After activating this option, a new widget will appear in the panel. Under the volume controls there is “Transmit my audio now” control, which will start the audio transmission from the PC it’s activated on.

Simple as that, but, as it’s a new option it hasn’t been discovered by many.

Categories
General

COM port occupied by unknown application

I’m working on an application that uses COM port for communication with external controller. When I reboot the PC with communication cable connected, Windows opens the port, without any application running, so I can’t access it any more. I was banging my head, searching and asking around for an answer, but, until recently, I couldn’t find where’s the problem.
Finally I managed to find where the problem was:
Windows identifies devices with constant data stream connected to serial port as serial mouse (in this case it was Microsoft Serial Ballpoint), and tries to install them, taking over the control over the port without any process using it. The solution is to wait for Windows to install the device (check Device Manager under Mouses And Other Pointing Devices) and then DISABLING it. If you uninstall the device it will be installed again, and the problem is back.
I hope others will find this solution useful.

Categories
General

Ustupamo svoj medijski prostor

Inicijativa Ivana Ćosića, za ustupanje blogerskog medijskog prostora u društveno odgovorne svrhe.

Stop trgovini decom

Kampanja organizacije Astra — Anti Trafficking Action

httpv://www.youtube.com/watch?v=HR_l7mXLK0Y

maliVEliki ljudi

Kampanja organizacije maliVEliki ljudi

httpv://www.youtube.com/watch?v=JLCy0v-LQoc

Bolje da znaš

Kampanja projekta Podrška u borbi protiv HIV/AIDS-a

httpv://www.youtube.com/watch?v=fJ7xRj_0RZU

Ujedinjeni protiv droge

Kampanja Ujedinjeni protiv droge

httpv://www.youtube.com/watch?v=JNQ8kXWhpzw

Osobe u razvoju

Kampanja organizacije Dečje srce

httpv://www.youtube.com/watch?v=DF6RvsGdJr0

Bitka za bebe

Kampanja Bitka za bebe

httpv://www.youtube.com/watch?v=Myh09_jY49k

Categories
CMS General Php

Conference Republic

Conference Republic web site is online. It’s the first web site running completely on my Complete MeSs system.

The web site design was done by CMYK You.

It’s running on PHP/MySQL base, with jQuery as the JavaScript framework of choice.

You can visit the website at this link.