• Integrating YAMS with Easy 2 Gallery#

  • goldsky Reply #1, 1 year, 8 months ago

    Reply
    Hello PMS,

    Recently, someone asked me about multilangual ability in Easy 2 Gallery.
    The first thought in my mind was about integrating the YAMS and E2G.
    One thing you should realized is that E2G does not have any relation to the document parsing data, while YAMS runs on it.
    E2G's snippet retrieves all data from its own database.

    I've dug the YAMS's code, and it seems that all the language configurations are stored inside the yams.config.inc.php, which is called by the yams.class.inc.php (Initialise() function).

    I do not need more field in YAMS's module.
    What I'd like to ask is that will you get YAMS provides some CONSTANT values, so when E2G sniffs:
    if(defined(YAMS_CONSTANT_...))

    then the E2G's snippet will make the language conversion itself.
    If you don't mind to do that, then it will be easier for snippets like E2G to integrate the language selection trigger.

    From what I can feel right now, the priority constants are (the names are only to desribe my thought):
      [list]
    • ..._LANGS_LIST
    • ..._LANGS_ACTIVE
    • ..._LANGS_DEFAULT
    [/list]

    If you can provide these, then I can set E2G's module to have more language fields according to that options.

    What do you think?


  • PaulSuckling Reply #2, 1 year, 8 months ago

    Reply
    The best way to get the information you want is to use the getters on the YAMS class:
    global $modx;
    require( $modx->config['base_path'] . 'assets/modules/yams/class/yams.class.inc.php');
    // get an instance of the YAMS singleton class
    $yams = YAMS::GetInstance();
    // get an array of activated language ids
    $activeLangIds = $yams->GetActiveLangIds();
    // get an array of defined but disabled language ids
    $inactiveLangIds = $yams->GetInactiveLangIds();
    // get an array of all language ids
    $allLangIds = array_merge( $activeLangIds, $inactiveLangIds );
    // get the default language id
    $defaultLangId = $yams->GetDefaultLangId();
    

    Not sure about defining constants; they aren't constant since the user can update the configuration and change them.


  • goldsky Reply #3, 1 year, 8 months ago

    Reply
    OK,
    I'll try it in my public class, then.


  • sottwell Reply #4, 1 year, 8 months ago

    Reply
    Not sure about defining constants; they aren't constant since the user can update the configuration and change them.
    That's not what makes a constant; and they are properly called "constant variables", which should give the idea that while they can be changed, they aren't easily changed.

    The whole point is to have a variable value that can't be changed programmatically by accident. It can be changed in configuration or by editing the code (I suppose changing a config file is editing the code), but not during run-time. Well, it could be by having code to re-define it, but you get the general idea.

    If the user updates the configuration, then the next time the script is run the constant variable would have the new value, but it wouldn't change during the run of the script.


  • PaulSuckling Reply #5, 1 year, 8 months ago

    Reply
    Hi Sottwell.

    I do understand what you are saying. I normally use PHP's define to define 'true' constants that are potentially shared between multiple source files/classes and instead use attributes/access control on class members/methods to prevent users from changing values they shouldn't where possible. However, in certain circumstances defined constants can also be used for extra protection from alteration, like you say.

    One problem that arises in this instance is that arrays can't be declared as defined constants. This can be overcome however, by defining a serialized string representation of the array, but this would require the user to unserialize it first. At this point it becomes a standard variable which could be altered and so it's questionable how much added protection is actually being provided by this method.

    Nevertheless, to my development version of YAMS, available via svn from from svn://nashi.podzone.org/yams/trunk/, I have added a file assets/modules/yams/yams.constants.inc.php. This file can be require_once'd in order to define the following four constants that can be accessed as folllows:

    unserialize(YAMS_ACTIVE_LANG_IDS_SERIALIZED)
    unserialize(YAMS_INACTIVE_LANG_IDS_SERIALIZED)
    unserialize(YAMS_ALL_LANG_IDS_SERIALIZED)
    YAMS_DEFAULT_LANG_ID

    If anyone knows of a better way of defining constant arrays, I'd be happy to hear it. Cheers.


  • goldsky Reply #6, 1 year, 7 months ago

    Reply
    you can look how SMF prepares CONSTANTs for CMS integration:
    http://www.simplemachines.org/community/index.php?topic=173483.0


  • PaulSuckling Reply #7, 1 year, 7 months ago

    Reply
    Thanks for the link. SMF uses the same approach to defining object-based constants; serialize. However, it combines all its constants into a single array rather than one constant for each parameter. I can set it up in whichever way you prefer.


  • goldsky Reply #8, 1 year, 7 months ago

    Reply
    I think it's better single constant with array.
    Easier to debug.


  • PaulSuckling Reply #9, 1 year, 7 months ago

    Reply
    I've updated my RC1 development version of YAMS.

    It now includes a file assets/modules/yams/yams.integration.inc.php that defines a single serialized constant to help integration of YAMS with other software with multilingual capabilities, such as Easy 2 Gallery

    To use, require the file at the top of the relevant PHP source file and a constant called YAMS_INTEGRATION_SETTINGS will be defined containing a 'serialized' array of YAMS configuration parameters.

    The array must be unserialised before use. So, for example:
      require_once "....../assets/modules/yams/yams.integration.inc.php"
      $yamsParams = unserialize(YAMS_INTEGRATION_SETTINGS);
      // an array of language ids for languages which are defined
      // and activated
      $yamsParams['active_lang_ids']
      // an array of language ids for languages which are defined
      // but not activated
      $yamsParams['inactive_lang_ids']
      // an array of language ids for all languages
      $yamsParams['all_lang_ids']
      // the default language id
      $yamsParams['default_lang_id']
    


  • goldsky Reply #10, 1 year, 7 months ago

    Reply
    PMS, just a consideration, try to use <link /> rather than <link></link>, and

    Now, I'm starting to connect these out.
    I will surely ask you for some more questions.