HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


SOLVED: Need help adding config options

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#65363 (In Topic #14024)
Avatar

Community saint

Making an addon which specifies extra site config options

Hi everyone. As I mentioned in another thread, I'm currently making an ocPortal addon for Flattr.com. At the moment it's just 2 new blocks which show a Flattr button for the site and a Flattr button for a user. This requires 1 custom profile field and 2 config options. The config options aren't showing and the custom profile field shows the description correctly, but the name as "ocp_flattr_id" :( This is what I'm using (aside from the blocks themselves):

lang_custom/EN/flattr.ini

Code

[strings]
FLATTR_ID=Flattr ID
DESCRIPTION_FLATTR_ID=The username of your Flattr.com account.
FLATTR_TYPE=Your site's "type" on Flattr
CONFIG_OPTION_flattr_id=The username of your Flattr.com account.
CONFIG_OPTION_flattr_type=The "type" your site should have on Flattr (what type of thing your site is about). Choices are text, images, video, audio, software or rest.
DEFAULT_CPF_flattr_id_NAME=Flattr ID
DEFAULT_CPF_flattr_id_DESCRIPTION=The username of your Flattr.com account.

sources_custom/hooks/systems/config_default/flattr_id.php

Code

<?php /*

 ocPortal
 Copyright (c) ocProducts, 2004-2010

 See text/EN/licence.txt for full licencing information.


 NOTE TO PROGRAMMERS:
   Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
   **** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****

*/

/**
 * @license             http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
 * @copyright   ocProducts Ltd
 * @package             flattr
 */

class Hook_config_default_flattr_id
{

        /**
         * Gets the details relating to the config option.
         *
         * @return ?array               The details (NULL: disabled)
         */
        function get_details()
        {
                require_lang('flattr');
                return array(
                        'human_name'=>'FLATTR_ID',
                        'the_type'=>'line',
                        'the_page'=>'FEATURE',
                        'section'=>'SOCIAL_NETWORKING_INTEGRATION',
                        'explanation'=>'CONFIG_OPTION_flattr_id',
                        'shared_hosting_restricted'=>'0',
                        'c_data'=>'',

                        'addon'=>'flattr',
                );
        }

        /**
         * Gets the default value for the config option.
         *
         * @return ?string              The default value (NULL: option is disabled)
         */
        function get_default()
        {
                require_lang('flattr');
                return '';
        }

}

sources_custom/hooks/systems/config_default/flattr_type.php

Code

<?php /*

 ocPortal
 Copyright (c) ocProducts, 2004-2010

 See text/EN/licence.txt for full licencing information.


 NOTE TO PROGRAMMERS:
   Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
   **** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****

*/

/**
 * @license             http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
 * @copyright   ocProducts Ltd
 * @package             flattr
 */

class Hook_config_default_flattr_id
{

        /**
         * Gets the details relating to the config option.
         *
         * @return ?array               The details (NULL: disabled)
         */
        function get_details()
        {
                require_lang('flattr');
                return array(
                        'human_name'=>'FLATTR_TYPE',
                        'the_type'=>'line',
                        'the_page'=>'FEATURE',
                        'section'=>'SOCIAL_NETWORKING_INTEGRATION',
                        'explanation'=>'CONFIG_OPTION_flattr_type',
                        'shared_hosting_restricted'=>'0',
                        'c_data'=>'',

                        'addon'=>'flattr',
                );
        }

        /**
         * Gets the default value for the config option.
         *
         * @return ?string              The default value (NULL: option is disabled)
         */
        function get_default()
        {
                require_lang('flattr');
                return '';
        }

}

sources_custom/hooks/systems/ocf_cpf_filter/flattr.php

Code

<?php /*

 ocPortal
 Copyright (c) ocProducts, 2004-2010

 See text/EN/licence.txt for full licencing information.


 NOTE TO PROGRAMMERS:
   Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
   **** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****

*/

/**
 * @license             http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
 * @copyright   ocProducts Ltd
 * @package             flattr
 */

class Hook_ocf_cpf_filter_flattr
{

        /**
         * Find which special CPF's to enable.
         *
         * @return array                        A list of CPF's to enable
         */
        function to_enable()
        {
                require_lang('flattr');
                return array('flattr_id'=>1);
        }

}

With the above in place I've then loaded the following minimodule, which displays "Success!":

adminzone/pages/minimodules_custom/set_up_flattr.php

Code

<?php

// This will set up the required configuration for using Flattr from ocPortal

// Only administrators should be able to run this script
if ($GLOBALS['FORUM_DRIVER']->is_super_admin(get_member()))
{
        // We need to make some configuration options for the site //
        require_code('database_action');

        // The Flattr member ID which should be credited with flattrs of the site
        add_config_option('FLATTR_ID','flattr_id','string','return \'\';','FEATURE','SOCIAL_NETWORKING_INTEGRATION');

        // The Flattr category which this site falls under, from
        // http://api.flattr.com/odapi/categories/human
        // Currently: text, images, video, audio, software, rest
        // We default to 'rest'
        add_config_option('FLATTR_TYPE','flattr_type','string','return \'rest\';','FEATURE','SOCIAL_NETWORKING_INTEGRATION');

        // We need to give a custom profile field to the users //
        $GLOBALS['FORUM_DRIVER']->install_create_custom_field('flattr_id',50,0,1,1,0,'Username for Flattr.com','short_text',0,NULL);

        echo "Success!";
}
else
{
        echo "Not super-user";
}

I've basically cobbled that together from searching through the source code. I've tried it on a test install of a fresh ocPortal 5.0.3 with no luck. Any ideas how to set the CPF name and make the options show in Features->Social Networking Integration?

Thanks!
ChrisW

EDIT: The PHP wasn't displaying :thumbs:


Last edit: by ChrisW
Back to the top
 
Posted
Rating:
#65371
Avatar

For the CPF…

SPECIAL_CPF__ocp_flattr_id=Flattr ID

For the config option…

'string' –> 'line'


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#65385
Avatar

Community saint

Thanks! All 3 are showing up now :D Should have something to upload here pretty soon ;)

/me downloads another copy of the codebook…
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: