how to add your illustrations using DD/Autolinks/Uploads
Ferenc Veres <[email protected]> Mon, 30 Aug 2004 21:43:50 +0200
| Newsgroups | gmane.comp.cms.xaraya.documentation |
|---|---|
| Organization | Xaraya |
| Message-ID | <[email protected]> |
Hi!
I save this message from google cache here (was on old xaraya.com),
works fine for me, but not really the most user friendly way to "just
add some images".
Regards,
Ferenc
In this tutorial by Ilya Voyager, we will use the Images, Autolinks,
DynamicData (DD) and Uploads modules to add illustrations to articles.
Our goal is to allow the user to upload pictures while adding a new
publication. The picture will be inserted into the text by using special
tags. This short "HOWTO" is based on the 0.9.9 release of Xaraya ("full"
distribution).
First of all, we need to install the Images, Autolinks, Uploads and DD
modules and hook them as shown below:
Autolinks -> Articles
Images -> Articles
Uploads -> DD
Uploads -> Articles
DD -> Autolinks
DD -> Articles
Note: the Images and Uploads modules need to be configured properly
after installation in order to start working.
Next we want to create and configure Publication types in which
illustrations will be used. We also need to add DD "File Upload" fields
[Articles -> Publication types -> Article Config -> Dynamic Data Fields
-> Modify], named appropriately like "illustration1", "illustration2"
and so on (if we need 10 illustrations in one article, there should be
10 such fields).
The next step is to make some changes to Xaraya's code. This is
required for the 0.9.9 release; maybe this step will not be needed in
future versions.
We need to add two lines:
xarVarSetCached('Blocks.articles','aid',$aid);
xarVarSetCached('Blocks.articles','ptid',$pubtypeid);
to the file modules/articles/xaruser/display.php just BEFORE the line
$data = xarModCallHooks('item', 'transform', $aid, $data, 'articles');
Our code will save the "article id" and "publication type id" in
Xaraya's cache to retrieve them by the Autolinks module later. The idea
is to do this BEFORE any transform hooks are called.
(Note for developers: actually, both the lines we are inserting are
already in the original module's code, but they are located AFTER
calling the hooks, so this won't work in our case. Maybe, it is better
simply to move them?)
Okay. Let us suppose that we've done that correctly, and Xaraya hasn't
crashed yet :). Now we need to create an autolink, which will replace
tags in text by illustration code.
Here is a template for our autolink type:
<!--- Here:
$url - illustration number
$title - illustration title
--->
<!--- We need to get an article id and pubtype id from the Cache --->
<xar:set name="$aid">xarVarGetCached('Blocks.articles',
'aid')</xar:set>
<xar:set name="$ptid">xarVarGetCached('Blocks.articles',
'ptid')</xar:set>
<xar:if condition="!empty($aid) and !empty($ptid)">
<!--- Getting upload ID using dynamicdata_userapi_getfield
function --->
<xar:set name="$ulid">
xarModAPIFunc('dynamicdata','user','getfield',
array('module' => 'articles',
'itemtype' => $ptid, 'itemid' =>
$aid,'name'=>'illustration'.$url))
</xar:set>
<xar:if condition="!empty($ulid)">
<!--- I don't know why, but getfield returns a
string starting with semicolon (";<ulid>"). Using
regexp to fix it. Does anybody know better way
to do it?
--->
<xar:set name="$fileID">ereg_replace('^;','',$ulid);</xar:set>
<xar:if condition="!empty($fileID)">
<!--- Using 'image-resize' tag to show our
illustration.
Change 'width' property to get rescaled image --->
<xar:image-resize src="$fileID" width="100%"
constrain="1" label="$title"/>
<!--- Maybe, it is good idea to print title here.
You can do it, if you wish:
#$title#
--->
<xar:else/>
<xar:set name="$error">0</xar:set>
</xar:if>
<xar:else/>
<xar:set name="$error">1</xar:set>
</xar:if>
<xar:else/>
<xar:set name="$error">2</xar:set>
</xar:if>
<xar:if condition="!empty($error)">
<!--- Something went wrong --->
[Illustration parsing error: ErrorNo = #$error#, aid = #$aid#,
ptid = #$ptid#]
</xar:if>
This code should be saved as a file in the Autolinks templates folder
(e.g. in modules/autolinks/xartemplates/link-illustration.xd or in an
appropriate theme-specific folder).
Then we need to create an autolink type [Autlinks -> Add type] with
the Name = "ilinktype" and Template Name = "illustration" (since we
saved our template under this name). The last step is to add Autolink
itself [Autolinks -> Add Link] with following properties:
Autolink type = "ilinktype"
Name = "ilink"
Matching key = "\[il:([^:]+):(\d+)\]"
Title = "$2"
Url = "$3"
Click on the "Create" button and then check the flags "Enabled" and
"Match As Regular Expression". Now click on "Update".
Really, that's all!
Now you can simply upload pictures as you create a new article (into
illustrationN fields, N=1,2,3,...) and use following the tag to include
them to your text:
[il:<title>:<number>]
The <number> here is a number of an upload field containing the
picture. E.g., if you've uploaded your pic into "illustration1" field,
you should have "1" as a number:
[il:Test illustration:1]
Of course, you can design your own illustration tags with different
properties (size, alignment and so on) by using the same techniques.
You'll just need to update the template code and autolink properties in
that case, but the idea will be the same.