Author: clone

  • 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:

    <?php
    
    class MySiteConfig extends DataExtension {     
    
    	 public static $has_one = array(
    		'HeaderImage' => 'Image',
    		'LogoImage' => 'Image',		
    	);
    
    	 public static $db = array(			
    		'FacebookURL' => "Varchar(250)",
    		'VimeoURL' => "Varchar(250)",				
    	  );
    
        public function updateCMSFields(FieldList $fields) {
    	   $fields->addFieldToTab("Root.Main", new UploadField("LogoImage", "Choose an image for your site logo"));
    	   $fields->addFieldToTab("Root.Main", new UploadField("HeaderImage", "Choose an image for the site header"));
    	   $fields->addFieldToTab("Root.Main", new TextField("FacebookURL", "Enter the full URL of your Facebook page"));	 
    	   $fields->addFieldToTab("Root.Main", new TextField("VimeoURL", "Enter the full URL of your Vimeo page"));	
        }
    }

    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:

    Object::add_extension('SiteConfig', 'MySiteConfig');

    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:

    $SiteConfig.LogoImage.SetRatioSize(250,250)
    <a href="$SiteConfig.FacebookURL">Visit my facebook page</a>
  • 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.

    <?php
    class ProductCategoryPage extends Page {
    
    public static $many_many = array(
    'Products' => 'Product'
    );
    
    public function getCMSFields() {
    $fields = parent::getCMSFields();
    
    $gridFieldConfig = GridFieldConfig_RelationEditor::create()->addComponents(
    new GridFieldDeleteAction('unlinkrelation')
    );
    
    $gridfield = new GridField("Products", "Product", $this->Products(), $gridFieldConfig);
    $fields->addFieldToTab('Root.Products', $gridfield);
    return $fields;
    
    }
    
    }
    
    class ProductCategoryPage_Controller extends Page_Controller {
    
    public static $allowed_actions = array (
    );
    
    public function init() {
    parent::init();
    }
    
    }

     

    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.

    <?php
    
    class Product extends DataObject {
    
    public static $db = array(
    'Title' => 'Varchar'
    );
    
    // One-to-one relationship with profile picture and contact list page
    public static $has_one = array(
    'Image' => 'Image'
    );
    
    public static $belongs_many_many = array(
    'ProductCategoryPage' => 'ProductCategoryPage'
    );
    
    // Summary fields
    public static $summary_fields = array(
    'ID' => 'ID',
    'Thumbnail' => 'Thumbnail',
    'Title' => 'Title'
    
    );
    
    public function getThumbnail() {
    return $this->Image()->CMSThumbnail();
    }
    
    public function getCMSFields() {
    $fields = parent::getCMSFields();
    
    $gridFieldConfig = GridFieldConfig_RelationEditor::create()->addComponents(
    new GridFieldDeleteAction('unlinkrelation')
    );
    $gridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
    
    $gridfield = new GridField("ProductCategoryPage", "ProductCategoryPage", $this->ProductCategoryPage(), $gridFieldConfig);
    $fields->addFieldToTab('Root.ProductCategoryPage', $gridfield);
    return $fields;
    
    }
    
    }

     

    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

    new GridFieldDeleteAction('unlinkrelation')

    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…

    <% loop Products %>
    
    <h3>$Title</h3>
    $Image.SetWidth(100)
    
    <% end_loop %>

     

  • 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. (more…)

  • 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!

  • 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:

    // Change the folowing line: chdir(dirname(__DIR__)); // to: //chdir(dirname(__DIR__));

     

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

  • 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.

    <script type="text/javascript">
    tinyMCE.init({ language : "sr", mode : "textareas", theme : "advanced", plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template", theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,|,forecolor,backcolor,|,code,fullscreen", theme_advanced_buttons2 : "", theme_advanced_buttons3 : "", theme_advanced_buttons4 : "", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", relative_urls : false, file_browser_callback : 'myFileBrowser', external_link_list_url : "/js/myexternallist.js" });
    </script>

     

    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.

    <script type="text/javascript">
    function myFileBrowser (field_name, url, type, win) {
    // You can use the "CKFinder" class to render CKFinder in a page:
    var finder = new CKFinder();
    // The path for the installation of CKFinder (default = "/ckfinder/").
    finder.basePath = '/js/ckfinder/';
    // Name of a function which is called when a file is selected in
    CKFinder.finder.selectActionFunction = SetFileField;
    // Additional data to be passed to the selectActionFunction in a second argument.
    // We'll use this feature to pass the Id of a field that will be updated.
    finder.selectActionData = field_name;
    // Launch CKFinder
    finder.popup();
    }
    </script>

     

    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:

    <script type="text/javascript">
    function SetFileField( fileUrl, data ){
    var frId = getElementsByClassName("clearlooks2", "div")[0].getElementsByTagName("iframe")[0].id;
    document.getElementById(frId).contentWindow.document.getElementById(data["selectActionData"]).value = fileUrl;
    }
    </script>

     

    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.

  • 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.

  • 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.

  • 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

  • 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.