Working with packages code

Discussion in 'Subrion CMS Packages Discussions' started by Vasily B., Nov 6, 2012.

  1. Vasily_B.

    Vasily_B. Project Manager

    Hi all,

    Today we've got several questions how to work with the packages code. I took a decision to put them in our forums and post the answers to them here as they could be useful for some other customers who work on the packages for subrion open source content management framework.

    If you check includes/classes/ia.core.php file you can see the following code:

    public function factoryPackage ($name, $package, $type = self::FRONT, $params = null)
    factoryPackage accepts four params, and two of them are mandatory, others have default values. There are two ways to create a new package item class, but you should follow some conventions:
    a. your package item should be placed in packages/package_name/includes/classes/ia.(front|admin).item_name.php
    b. it should end with S, let's say your item is 'boats', then S is trimmed and your class will be create as iaBoat; more examples: recipes -> iaRecipe, lyrics -> iaLyric

    First way to init a new package item class:

    $iaCore->factoryPackage('boat', 'boats');
    this code will init iaBoat class based on packages/boats/includes/classes/ia.front.boat.php where the first param is the item name without S, and the second one is the package name.

    Second way to init a new package item class:

    $iaCore->factoryPackage('item', 'boats', 'front', 'boats')
    This code will do the same as above code. First one is recommended.

    Please see the methods, sometimes you need to pass item name without S, in some other cases you pass package name and it's confusing for autos package - your both package name and item name has the same value - autos. This is different in our publishing or directory package, where you pass articles/listings and publishing/directory.

    I'm not sure. Let's wait for some ideas from our devs.

    I think the only way now to check how it works is to investigate publishing or directory package. I don't imagine how we can describe it, there is a functionality that can be used as an example.

    Sure, you definitely need to have default templates in your packages folder. But if you want to have a specific design for your pages I'd recommend to modify your templates/boatsdefault. Here are more details:
    Templates - Subrion CMS

    Let us know if you have any other questions. Thanks!
  2. Vasily_B.

    Vasily_B. Project Manager

    Two more questions from the same guy:

    No, the system scans templates/ folder only for a templates list. Anyhow here is where the collapse might be. Every package php file should have its own tpl (Ex: you have new-boats page and you wish it to be displayed in new-boats.tpl file). We recommend to have new-boats.tpl file in packages/boats/templates/common folder, as this file will be used if the system cannot find templates/your_template/packages/boats/new-boats.tpl file. So here is the recommended structure for your package template files:

    --------all-other-templates.tpl this folder should contain all tpl files that are processed/used by the package php files

    --------new-boats.tpl and other files that can be copied from packages templates folder but need to have a specific design/layout according to the template.

    See the template structure above. It explains the steps to create a template for packages.

    Please ask if you have more questions.
  3. Vasily_B.

    Vasily_B. Project Manager

    One more template related question:
    Yes, and it should not be there. See the reply above, the system scans for templates/ folder only for the templates. But each package php file should have its own template file, and we do recommend to keep the default version of template file in packages/YOUR_PACKAGE/templates/common/
    That's how it works.
  4. piagent

    piagent New Member

    I can't find an install.xml for the Core.

    1)Does it exist? and where?
    2)Is plan and members in a package?
  5. Vasily_B.

    Vasily_B. Project Manager

    No there is no install.xml for the core version.

    We have a dump file in the install/ folder and it is used during the installation. If you need to add some mysql features to the core version you need to update that dump file.

    Sorry, the question is non clear. Could you please clarify? By default the software does not come with any plans and members except admin account you create during installation. You can create plans in the admin panel -> Manage Plans and you can create it for your items you created in your package.
  6. piagent

    piagent New Member

    I was looking to make changes to make accounts (members) and plans listed in the item list for manage fields. I will look at the dump file to see where it can be done. The best case is to setup things in a package install. Suggestions? note: if you don't have a method, you may have given me a dump method to fix things up in the core from the package using dump files. But please give me a better way.
  7. Gleb_S.

    Gleb_S. Subrion Designer Staff Member

    Hello piagent,

    There is actually no need to list members and plans within the manage fields, as far as you should see account and plan (when sponsored is on) fields in the block of system fields when edit/add item in Admin Panel.
    If no, please let us know, we will check the issue.
  8. piagent

    piagent New Member

    Try this, working with the auto package as my standin I entered the following in the install.
    <page block="autos" name="autos_manufactures" filename="manufactures" menus="menu" url="manage/autos/manufactures/">Manage Manufactures</page>

    I did not add any code to the system and expected an error (part of how I'm learning the system) Parsing Error: Uncaught exception 'SmartyException' with message 'Unable to load template file '/home/boats4s/public_html/BFS-2-2-3-package-boats/admin/templates/common/autos_manufactures.tpl

    So getting an error or warning was expected, what was not expected was where and what it was looking for. When I gave it the tpl at the location I got some text to display (a major win for me). I did start looking at the code flow and I have some questions:

    1)I expected that it would stay within the packages/autos/ directory. I expected it to redirect manage/autos/manufactures/ and would look for /packages/autos/admin/manufactures.php and fail there.

    2)Maybe the logic is since the frontend can take php,tpl,and html as a (block) page with in the view that the backend does the same. So if it doesn't find a .php it looks for a .tpl. Is this correct? But again why did it look outside the package area? Why did it use auto_manufactures.tpl vs manufatures.tpl? Should this be an error? Or is it the case that front and back use common logic and that is just the default.

    3)Can filename= be manufactures.php, manufactures.html or for that matter an external link (frontend allows external pages)?

    I haven't tried putting the tpl in the autos directory, should be interesting.
    Last edited: Dec 1, 2012
  9. piagent

    piagent New Member

    I would think the code should error if outside the package. I also think the file should always be in packages/autos/admin (for admin stuff) and not make a default to name which became auto_manufactures.tpl I think that a precedence of php, tpl and html is not a bad idea, without any renaming.

    In either case the wiki should be updated:

    PackageStructure - Subrion CMS

    <!-- @filename the name of the php file (written without an extension ".php") placed in the admin folder of the package that handles page request -->
    <!-- if no php is found then a search for a tpl in the /packages/yourpackage/templates/admin/name.tpl or /admin/templates/common/name.tpl-->
    Last edited: Dec 1, 2012
  10. Gleb_S.

    Gleb_S. Subrion Designer Staff Member

    Hello piagent,

    As I said before, if you set no filename for the page it will set packages/yourpackage/admin/index.php as a handler. As far as there is no index.php it searches for @name.php file. If there is no such file it searches for @name.tpl file.

    If you set filename for the page you should have there these code:

    It will search for your packages/yourpackage/templates/admin/your_tpl_file.tpl.
    If there is no such a file or you didn't point the php script to the tpl file it searches for common template file.
  11. piagent

    piagent New Member

    Slowly the onion is being peeled. A question about Page Params:

    1)body: Why do some pages have "none" while others have a default (packagename) or install assigned .tpl. I know I can set/reset with display but did not see where those that had none set it that way or was setup via install that why.
    2)How do I use subpage?
    3)How do I use js_file?
    4)Evil question, can a php write to the body (or other areas) directly vs via a tpl? Yes I know tpl is to do separation.

  12. Gleb_S.

    Gleb_S. Subrion Designer Staff Member

    1) If 'none' is set it will render no content. Meaning, It will render header, blocks, and footer but remain the middle part empty. It is set if you have some other code that fills the content part. For example, we set display to 'none' for pages where grid is used.
    So usually you can see the code '$iaView->grid()' before '$iaView->display()'

    If you don't need to render blocks, footer, and header you can use this code:

    2) Please clarify what do you mean by subpage?

    3) SmartyFunctions - Subrion CMS here is the new documentation page for smarty functions, you can find the answer there. It will be expanding constantly.

    4) As far as I know, you can not write to the body with php, however you can use php code in blocks. If you add a block with 'php' type you can run php code there.
  13. piagent

    piagent New Member

    Yes, once I found the code I saw body set to none when using grid.

    subpage was in the page params, see at the end
    Array ( [extension] => / [url_contains_lang_code] => [id] => 1700 [type] => package => / [title] => Manage to find anything that fires up based on it
    Last edited: Dec 4, 2012
  14. Gleb_S.

    Gleb_S. Subrion Designer Staff Member

    The suburl is the path to the file that will return json array of subpages. It is required when you assign menus and blocks for particular pages.
    E.g. if you go to Admin Panel -> Manage Blocks -> edit, check "Members" next to "Visible on Pages" you will see an icon next to it. If you click it a window will open with subpages that block can be assigned to.

    You can found the code inside the file @subrion_folder/js/admin/fields.js

    The code that creates the panel is within this 'if' condition:

    if (!fieldItem)
    If you remove this condition the panel will be displayed on all the 'Manage Fields' pages.

    Yes, it should render.

    I've checked the page and found that it is not required anymore. The page is left from the previous version. You can remove this line from install.xml.
  15. wazza

    wazza Member

    Hi Guys,

    Just a little request :D

    Can you guys add the ability to set @type and @length to the config_groups section?

    I know it works in the fields section.


    Well i have the need (im sure others will too) to set a number field for some options. Please see code below.

    Code (Text):

    {if $config.recipes_enable_ingredients_list_view eq '1' && isset($config.recipes_ingredients_list_view_chars)}
    {if $listing.ingredients}
    <p><span class="muted">{lang key='ingredients'}</span>: <br />{$listing.ingredients|truncate:$config.recipes_ingredients_list_view_chars:"..."}
    <a href="{ia_url item='recipes' type='url' data=$listing}">{lang key='read_more'}</a></p><br />
    This is fine in the fields options but we also need this in the config_groups section.

    At the moment i have to set to @text and obviously if text is entered into the config_group it will break. (based on code above).

    I know it is an admin set value but still would be good to only allow number input.

    Anyways...Just a thought :D

    Thanks guys
    Last edited: Jan 27, 2013
  16. Gleb_S.

    Gleb_S. Subrion Designer Staff Member

  17. wazza

    wazza Member

    Hi Alex,

    Great to hear :D


Share This Page