Add new image field to Joomla 1.7 com_content - joomla

I'm trying to make some changes to com_content component of Joomla 1.7
There are not many docs on specific topic for Joomla 1.7
Maybe you could help me out on this one.
I want to have a separate field for extra image in com_content, specifically to Featured view.
In the administrator's part I managed to add the field - just in html, then into xml file and finally to DB.
Now I'm trying to get that record displayed in my custom html view for Featured articles.
I just used simple code echo $this->item->addimage; but unfortunately it's not displayed.
Any ideas how to achieve that?
Thanks!
And one more thing, as far as I have noticed, component development structure, DB registration and so on, has been changed in Joomla 1.7. Any helpful link(s) where everything is explained well?

Well. If you are sure that your implementation of what you have done works. ie. Embedded image or simply URL link from field you have added are stored in the database have a look into frontpage file /components/com_content/views/featured/tmpl/default_item.php
There you should place your $this->item->addimage variable like:
<img src="<?php echo $this->item->addimage; ?>" />
If you store URL link, or
<img src="image/png;base64,<?php echo $this->item->addimage; ?>" />
if your store the image as RAW base64 encoded data
Edit:
This should solve your problem if you add your articles from frontend (if backend, just let me know)
Firstly create a new column in jos_content table like:
'addimage' varchar(255) DEFAULT NULL
Then modify the following files:
../com_content/views/featured/tmpl/default_image.php [LINE: 29]
29:#</h2>
30:#<?php endif; ?>
32: <?php if(!empty($this->item->addimage)): ?>
33: <img src="<?php echo $this->item->addimage; ?>" alt="ADDIMAGE" />
34: <?php endif; ?>
36: #<?php if ($params->get('show_print_icon') || $params->get('show_email_icon') || $canEdit) : ?>
../com_content/models/articles.php [LINE: 160]
160: # $this->getState(
161: # 'list.select',
162: 'a.id, a.title, a.alias, a.title_alias, a.introtext, a.addimage, ' .
163: #'a.checked_out, a.checked_out_time, ' .
../com_content/models/forms/article.xml [ADD SOMEWHERE]
<field
id="addimage"
name="addimage"
type="text"
label="Add Image"
class="inputbox"
/>
../com_content/views/form/tmpl/edit.php [LINE: 82]
82: #<?php echo $this->form->getInput('created_by_alias'); ?>
83: #</div>
85: <div class="formelm">
86: <?php echo $this->form->getLabel('addimage'); ?>
87: <?php echo $this->form->getInput('addimage'); ?>
88: </div>
90: #<?php if ($this->item->params->get('access-change')): ?>

com_content is really not the way for creating variable content in joomla anymore. It's still the same unflexible code since mambo days.
You should try solutions like K2, flexicontent or my favourite ZOO. They are easy to learn and you can do lots of cool stuff with them. Extra Fields? No Proble., Some of them already exist for Joomla 1.7/2.5.
Hacking the core is always bad. Mainly because you loose your update path.

Related

Getting error when try to download multiple invoices

I modified invoice report template "account.report_invoice_document".
XML Code:
<template id="report_invoice_document_inherit" inherit_id="account.report_invoice_document">
<xpath expr="//div[#class='page']" position="inside">
<div class="row">
<div class="text-left">
<h4><u>Comments</u></h4>
</div>
<div class="text-justify" style="margin-left:10px;">
<p>Data</p>
</div>
</div>
</xpath>
</template>
No Error display on Terminal when I tried to download multiple invoices.
Invoice Report successfully downloaded when it is download from form view.An error has occurred when multiple report download from an account.invoice tree view
I got an error on odoo.
Error:
Odoo Server Error
Traceback (most recent call last):
File "/home/odoo/Documents/odoo11_community/odoo-11.0/addons/web/controllers/main.py", line 1663, in report_download
response = self.report_routes(reportname, docids=docids, converter='pdf')
File "/home/odoo/Documents/odoo11_community/odoo-11.0/odoo/http.py", line 512, in response_wrap
response = f(*args, **kw)
File "/home/odoo/Documents/odoo11_community/odoo-11.0/addons/web/controllers/main.py", line 1612, in report_routes
pdf = report.with_context(context).render_qweb_pdf(docids, data=data)[0]
File "/home/odoo/Documents/odoo11_community/odoo-11.0/odoo/addons/base/ir/ir_actions_report.py", line 641, in render_qweb_pdf
return self._post_pdf(save_in_attachment, pdf_content=pdf_content, res_ids=html_ids), 'pdf'
File "/home/odoo/Documents/odoo11_community/odoo-11.0/odoo/addons/base/ir/ir_actions_report.py", line 524, in _post_pdf
assert len(outlines_pages) == len(res_ids)
AssertionError
try to replace the line:
<h4><u>Comments</u></h4>
by:
<p><u>Comments</u></p>
The problem is th <h4> tag.
The source code in Odoo 11 (odoo/addons/base/ir/ir_actions_report.py) helps:
# In case of multiple docs, we need to split the pdf according the records.
# To do so, we split the pdf based on outlines computed by wkhtmltopdf.
# An outline is a <h?> html tag found on the document. To retrieve this table,
# we look on the pdf structure using pypdf to compute the outlines_pages that is
# an array like [0, 3, 5] that means a new document start at page 0, 3 and 5.

Odoo 10 - QWeb include barcode in report

I am trying to include a QR barcode in a report.
Doing:
https://www.foo.com/report/barcode/QR/test
Generates a valid barcode in the browser.
But using in a QWeb PDF report template:
<img t-att-src="/report/barcode/QR/test"/>
Does not work:
File "/usr/lib/python2.7/dist-packages/odoo/addons/base/ir/ir_qweb/ir_qweb.py", line 300, in _compile_expr
st = ast.parse(expr.strip(), mode='eval')
File "/usr/lib/python2.7/ast.py", line 37, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 1
/report/barcode/QR/test
^
SyntaxError: invalid syntax
You should write as following :
<img t-att-src="'/report/barcode/QR/test'"/>
In QWeb reports for barcode you have to try this code...
<img t-if="o.barcode" t-att-src="'data:image/png;base64,%s' % o.barcode"/>
Also you can try this :
<img t-att-src="'/report/barcode/QR/test?
type=%s&value=%s&width=%s&height=%s' % ('EAN13', o.ean13, 600, 900)"
style="width:100%;height:100px"/>
Define height and width that you want.
In Q-web Report Include the Barcode, that have only include the image in your module,--->>> module_name-->>static-->>src-->>img--->> images.gif.
Code :
Else :
You can directly get the barcode from the report also.
Hope It will Work for you.
Add this to your report file.
<center style="margin:6px 0;">
<img t-if="o.barcode" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' %('Code128',o.barcode,250,50)"/>
</center>

text_field.set not working in test script but works fine in irb

I'm trying to rename a folder from:
<li class="selected rename" id="labelset-624" folderid="624" foldertype="labelset" permissionlevel="2" labelsetid="624">
<div class="folder-insert-drop ui-droppable"></div>
<div class="clear"></div>
<div class="folder-item droppable hoverable empty ui-droppable">
<div id="mlink-labelset-624" class="folder-menu-link" data-hasfullperm="true" data-subfoldertype="undefined"></div>
<div class="expander"></div>
<div class="folder-name labelset label-set">New Label Set</div>
<div class="target-bar"></div>
<div class="folder-rename">
<input value="New Label Set" id="folder-rename-624" maxlength="100" type="text">
</div>
with watir-webdriver using the following commands:
#b.li(:class, "selected rename").div(:class, "folder-rename").text_field.wait_until_present
#b.li(:class, "selected rename").div(:class, "folder-rename").text_field.set labelsetName
#b.li(:class, "selected rename").div(:class, "folder-rename").text_field.send_keys :return
And it gives me the following error:
Watir::Exception::UnknownObjectException: unable to locate element, using {:class=>"selected rename", :tag_name=>"li"}
When I run my test script (test-unit), I can see the value for labelsetName entered into the text field, but it quickly disappears and reverts to the default value. This causes the send_keys statement to err.
When I enter the same commands into irb, it works perfectly. I tried adding sleeps of up to 15 seconds between steps to no avail. Is there any reason the two would work differently? Any suggestions for fixing this going forward?
Unless you have a compelling reason otherwise, try accessing the <input> tag directly using the id attribute:
b.text_field(:id => "folder-rename-624").set "foo"
b.text_field(:id => "folder-rename-624").send_keys :return
And--if there's an associated submit button--try using that instead of send_keys :return.
EDIT: Unfortunately, I can't reproduce the disappearing text issue. But I'm adding this snippet, which should handle the incrementing id attribute:
tfs = b.text_fields
b.text_field(:id => "#{tfs.last.id}").set "foo"
b.text_field(:id => "#{tfs.last.id}").send_keys :return
Turns out that because I had run the test a number of times, each time creating a new folder, that the folder I was trying to rename got pushed off screen. This is what caused the error.

Using Ruby, how can I confirm that an XML snippit is valid?

As some of you make know, I'm working on XMPP (Jabber) integration for the StackOverflow chat system, as an XMPP component written in Ruby using the xmpp4r package.
I'm struggling with one issue (well, many issues, but one issue at the moment :-) I am taking the JSON feed from the chat and extracting the HTML for the messages. I am using The Ruby TidyHTML bindings to convert the HTML from the JSON fed to XHTML, so that I can send it as an XMPP message -- since XMPP messages are just XML, converting the HTML to XHTMl should make it valid XML which I can just stick into the <message> stanza.
For most messages, it works great!
However for other messages, it completely chokes -- the XMPP server closes the stream and the script grinds to a halt. (And rchern and others in The Tavern get upset. Well, maybe not upset, but they laugh at me. This makes me sad!)
I am almost certain that what's happing is, for some reason or other, the messages are not valid XML, and so the XMPP server is closing the connection because it encounters a parse error in the XML stream from the Ruby component. Here's an example of one such message:
<message to='jeswah#smart-safe-secure.com/Token' type='groupchat' xmlns='jabber:client'><body><div class="onebox ob-message"><a class="roomname" href="/transcript/message/263372#263372"><span title="2010-11-04 19:20:23Z">1 hour ago</span></a>, by <span class="user-name">Fosco</span> <br/><div class="quote"><div class="room-mini"><div class="room-mini-header"><h3><img class="small-site-logo" title="Gaming" alt="Gaming" width="16" height="16" src="http://sstatic.net/gaming/img/favicon.ico" />&nbsp;<span class="room-name"><a href="http://chat.stackexchange.com/rooms/28/minecraft-talk">Minecraft Talk</a></span></h3><div class="room-mini-description">Everything Minecraft, including classic and survival mode</div></div><div class="room-current-user-count" title="current users">9</div><div class="mspark" style="height:25px;width:205px">
<div class="mspbar" style="width:8px;height:13px;left:0px;"></div><div class="mspbar" style="width:8px;height:9px;left:8px;"></div><div class="mspbar" style="width:8px;height:2px;left:16px;"></div><div class="mspbar" style="width:8px;height:8px;left:24px;"></div><div class="mspbar" style="width:8px;height:1px;left:32px;"></div><div class="mspbar" style="width:8px;height:1px;left:56px;"></div><div class="mspbar" style="width:8px;height:0px;left:64px;"></div><div class="mspbar" style="width:8px;height:0px;left:88px;"></div><div class="mspbar" style="width:8px;height:0px;left:96px;"></div><div class="mspbar" style="width:8px;height:11px;left:104px;"></div><div class="mspbar" style="width:8px;height:7px;left:112px;"></div><div class="mspbar" style="width:8px;height:7px;left:120px;"></div><div class="mspbar" style="width:8px;height:25px;left:128px;"></div><div class="mspbar" style="width:8px;height:14px;left:136px;"></div><div class="mspbar" style="width:8px;height:4px;left:144px;"></div><div class="mspbar" style="width:8px;height:7px;left:152px;"></div><div class="mspbar" style="width:8px;height:19px;left:160px;"></div><div class="mspbar" style="width:8px;height:19px;left:168px;"></div><div class="mspbar" style="width:8px;height:12px;left:176px;"></div><div class="mspbar" style="width:8px;height:11px;left:184px;"></div><div class="mspbar now" style="height:25px;left:154px;"></div></div>
<div class="clear-both"></div></div></div></div></body><html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'><div class="onebox ob-message"><a class="roomname" href="/transcript/message/263372#263372"><span title="2010-11-04 19:20:23Z">1 hour ago</span></a>, by <span class="user-name">Fosco</span><br />
<div class="quote">
<div class="room-mini"><div class="room-mini-header">
<h3><img class="small-site-logo" title="Gaming" alt="Gaming" width="16" height="16" src="http://sstatic.net/gaming/img/favicon.ico" /> <span class="room-name">Minecraft Talk</span></h3>
<div class="room-mini-description">Everything Minecraft, including classic and survival mode</div>
</div>
<div class="room-current-user-count" title="current users">9</div>
<div class="mspark" style="height:25px;width:205px">
<div class="mspbar" style="width:8px;height:13px;left:0px;"></div>
<div class="mspbar" style="width:8px;height:9px;left:8px;"></div>
<div class="mspbar" style="width:8px;height:2px;left:16px;"></div>
<div class="mspbar" style="width:8px;height:8px;left:24px;"></div>
<div class="mspbar" style="width:8px;height:1px;left:32px;"></div>
<div class="mspbar" style="width:8px;height:1px;left:56px;"></div>
<div class="mspbar" style="width:8px;height:0px;left:64px;"></div>
<div class="mspbar" style="width:8px;height:0px;left:88px;"></div>
<div class="mspbar" style="width:8px;height:0px;left:96px;"></div>
<div class="mspbar" style="width:8px;height:11px;left:104px;"></div><div class="mspbar" style="width:8px;height:7px;left:112px;"></div><div class="mspbar" style="width:8px;height:7px;left:120px;"></div><div class="mspbar" style="width:8px;height:25px;left:128px;"></div><div class="mspbar" style="width:8px;height:14px;left:136px;"></div>
<div class="mspbar" style="width:8px;height:4px;left:144px;"></div>
<div class="mspbar" style="width:8px;height:7px;left:152px;"></div>
<div class="mspbar" style="width:8px;height:19px;left:160px;"></div>
<div class="mspbar" style="width:8px;height:19px;left:168px;"></div><div class="mspbar" style="width:8px;height:12px;left:176px;"></div>
<div class="mspbar" style="width:8px;height:11px;left:184px;"></div>
<div class="mspbar now" style="height:25px;left:154px;"></div>
</div>
<div class="clear-both"></div>
</div>
</div>
</div>
</body></html></message>
(This message happened to be a quote of a oneboxed link to a chat room)
Here was the error Ruby gave me:
IOError: stream closed
/usr/lib/ruby/1.8/xmpp4r/stream.rb:594:in `empty?'
/usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:153:in `empty?'
/usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:193:in `pull'
/usr/lib/ruby/1.8/rexml/parsers/sax2parser.rb:92:in `parse'
/usr/lib/ruby/1.8/xmpp4r/streamparser.rb:79:in `parse'
/usr/lib/ruby/1.8/xmpp4r/stream.rb:75:in `start'
/usr/lib/ruby/1.8/xmpp4r/stream.rb:72:in `initialize'
/usr/lib/ruby/1.8/xmpp4r/stream.rb:72:in `new'
/usr/lib/ruby/1.8/xmpp4r/stream.rb:72:in `start'
/usr/lib/ruby/1.8/xmpp4r/connection.rb:119:in `start'
/usr/lib/ruby/1.8/xmpp4r/component.rb:70:in `start'
/usr/lib/ruby/1.8/xmpp4r/connection.rb:77:in `connect'
/usr/lib/ruby/1.8/xmpp4r/component.rb:47:in `connect'
./classes/SOXMPP_Bridge.rb:20:in `initialize'
./soxmpp.rb:81:in `new'
./soxmpp.rb:81
Finally, my question!
Given that sending invalid XML to the XMPP server kicks me off, is there any way using Ruby I can validate (and, preferably, correct) the XML before sending it to the XMPP server? Most likely, correcting it will be a matter of my writing additional code for each case where Tidy isn't producing valid XML, but I'd at least like to stop the script from crashing. So, how can I validate the XML before sending it to the XMPP server?
The actual error in this case is your . According to XEP-0071, section 8, point 5:
Section 11.1 of XMPP Core stipulates that character entities other than the five general entities defined in Section 4.6 of the XML specification (i.e., <, >, &, &apos;, and ") MUST NOT be sent over an XML stream. Therefore implementations of XHTML-IM MUST NOT include predefined XHTML 1.0 entities such as -- instead, implementations MUST use the equivalent character references as specified in Section 4.1 of the XML specification (even in non-obvious places such as URIs that are included in the 'href' attribute).
So this issue is about more than just generating well-formed XML, which is a pre-requisite. You'll also want to ensure that you're only using XHTML from the approved set in section 6.
In short, you need to read XEP-0071.
Maybe actually converting to XML with Nokogiri will help? You can then re-serialize for the XMPP stream.
Also, if you want your stuff to scale a bit and avoid memory bloats, switch to Blather instead of XMPP4r. Also the DSL is pretty awesome!
Don't use Tidy. Use the HTML5 parser, then dump the DOM it generates to XML. If you can produce a DOM, you can produce well-formed XML from it every time. It will also have the advantage of producing roughly the same DOM that most modern browsers will give you.
Are you running on *nix? If so, I'd delegate the problem to xmllint, a program that is a part of libxml2. I work with a system that generates xml before sending it over the net; we validate our xml with xmllint, like so:
command = "xmllint #{temp_file_path} --schema #{schema_file_path} --noout 2>&1"
output = `#{command}`
if $? != 0
temp_dir.keep
$stderr.puts "Error validating xml: running command #{command.inspect}"
$stderr.puts output
exit(1)
end
You'll need to adapt this to your situation, of course, but the basic idea works well. If you don't have a DTD, leave out the "--schema" bit.

How to use rake to insert/replace html section in each file?

I'm using rake to create a Table of contents from a bunch of static HTML files.
The question is how do I insert it into all files from within rake?
I have a <ul id="toc"> in each file to aim for. The entire content of that I want to replace.
I was thinking about using Nokogiri or similar to parse the document and replace the DOM node ul#toc. However, I don't like the idea that I have to write the parser's DOM to the HTML file. What if it changes my layouts/indents etc.??
Any thoughts/ideas? Or perhaps links to working examples?
Could you rework the files to .rhtml, where
<ul id="toc">
is replaced with an erb directive, such as
<%= get_toc() %>
where get_toc() is defined in some library module. Write the transformed files as .html (to another directory if you like) and you're in business and the process is repeatable.
Or, come to that, why not just use gsub? Something like:
File.open(out_filename,'w+') do |output_file|
output_file.puts File.read(filename).gsub(/\<ul id="toc"\>/, get_toc())
end
I ended up with an idea similar to what Mike Woodhouse suggested. Only not using erb templates (as I wanted the source files to be freely editable also by non ruby-lovers)
def update_toc(filename)
raise "FATAL: Requires self.toc= ... before replacing TOC in files!" if #toc.nil?
content = File.read(filename)
content.gsub(/<h2 class="toc">.+?<\/ul>/, #toc)
end
def replace_toc_in_all_files
#file_names.each do |name|
content = update_toc(name)
File.open(name, "w") do |io|
io.write content
end
end
end
You can manipulate the document directly and save the resulting output. If you confine your manipulations to a particular element, you won't alter the overall structure and should be fine.
A library like Nokogiri or Hpricot will only adjust your document if it's malformed. I know that Hpricot can be coached to have a more relaxed parsing method, or can operate in a more strict XML/XHTML manner.
Simple example:
require 'rubygems'
require 'hpricot'
document = <<END
<html>
<body>
<ul id="tag">
</ul>
<h1 class="indexed">Item 1</h1>
<h2 class="indexed">Item 1.1</h2>
<h1 class="indexed">Item 2</h1>
<h2 class="indexed">Item 2.1</h2>
<h2 class="indexed">Item 2.2</h2>
<h1>Remarks</h1>
<!-- Test Comment -->
</body>
</html>
END
parsed = Hpricot(document)
ul_tag = (parsed / 'ul#tag').first
sections = (parsed / '.indexed')
ul_tag.inner_html = sections.collect { |i| "<li>#{i.inner_html}</li>" }.to_s
puts parsed.to_html
This will yield:
<html>
<body>
<ul id="tag"><li>Item 1</li><li>Item 1.1</li><li>Item 2</li><li>Item 2.1</li><li>Item 2.2</li></ul>
<h1 class="indexed">Item 1</h1>
<h2 class="indexed">Item 1.1</h2>
<h1 class="indexed">Item 2</h1>
<h2 class="indexed">Item 2.1</h2>
<h2 class="indexed">Item 2.2</h2>
<h1>Remarks</h1>
<!-- Test Comment -->
</body>
</html>

Resources