I have to post to url : https://rightsignature.com/api/templates.xml
One of the arguments is merge_fields and the description is:
Specify the name and email of the roles returned from the prepackageTemplate call. Roles can be references by or by in the form of XML node attributes 'merge_field_name' or 'merge_field_id'. If specified by name (the easiest method), all merge fields with the name specified will take on the value specified. Optional node specifying whether to "lock" the value from the sender is availbed via .
This is what the post xml should look look like:
<merge_fields>
<merge_field merge_field_id="a_233_f309f82jklnm_232">
<value>$100 per hour</value>
<locked>true</locked>
</merge_field>
<merge_field merge_field_name="Employee Name">
<value>J. Employee</value>
</merge_field>
</merge_fields>
This is what xml response looks like:
<merge-fields>
<merge-field>
<page>1</page>
<name>Company Name</name>
<id>a_966_8bffa095998e41ecbdfb624b2fd_5671</id>
</merge-field>
</merge-fields>
Am I suppose to set it to an array like this? :
$arr= array('merge_fields'=>
array('merge_field_email'=>xxx#mail.com),
"another_field"=>"another_value")
)
https://rightsignature.com/api/templates.xml? . $arr
"Well, basically 'it's still AJAX,'" with the encoding being XML not JSON.
You would simply use appropriate XML-manipulation primitives to build and un-build your messages, as discussed here: http://php.net/manual/en/book.xml.php.
It is also possible that the API is what's called SOAP. as discussed here: http://php.net/manual/en/book.soap.php. Or, it might be XML-RPC ("XML remote procedure calls"), as discussed here: http://php.net/manual/en/book.xmlrpc.php.
All three of these pages refer to many other pages with related topics that will be highly-relevant to what you are now trying to do.
It's important that you carefully identify the exact "flavor" of API that you are dealing with, so as to use the most-powerful available libraries of existing code to deal with it at the highest possible level of abstraction. Also, do on-line research (e.g. at GitHub) to see if you can find any existing source-code that already references this API or something very-similar to it. ("Do not do a thing already done.")
The good news is, you know that you're embarking upon "a very, very familiar task" that is well-supported in PHP. And so, to borrow a Perl by-line: "there's more than one way to do it." Search for the most efficient way.
Related
My problem is:
i've got the PHP Client http://community.jaspersoft.com/wiki/php-client-sample-code#About_the_Class from the Jasper Community.
I want to add a Domain with PHP to the Jasper Repository and i've got the needed data in an .xml, like label etc.
In this PHP Client i have to use the class SemanticLayerDataSource to create a domain.
This class got a public variable schema.
But i can't find what this schema needs to work and add an correct domain to repository. There is not info neither on the webside nor in the class.
$semLayer = new SemanticLayerDataSource();
$semLayer->schema = ?????
$semLayer->label = (string)$xml->label; //SimpleXml
.
.
.
Which Data needs schema? An array, a resource or something else? Thank you.
Also a code sample with PHP Client would be really good, cause the documentation is not that good in this point.
Edit: I tried to create a xml as a local file a set for schema the uri of this xml. To create the xml i used this: http://community.jaspersoft.com/wiki/php-client-sample-code#Creating_Binary_Resources
I am able to create a domain, but AdHoc views on this domain doesn't work. I get a null exception from jasper.
According to the REST API docs you need to provide a schema ressource:
<schemaFileReference>
<uri>{schemaFileResourceUri}</uri>
</schemaFileReference>
This ressource represents the whole structure, as written in the domain metadata service description (under the paragraph Working with Domain Schemas):
The v2/domains/metadata service returns only the display information about a Domain, not its internal definition. The fields, joins, filters, and calculated fields that define the internal structure of a Domain make up the Domain design. The XML representation of a Domain design is called the Domain schema.
Currently, there is no REST service to interact with Domain schemas, but you can use the v2/resources service to retrieve the raw schema. First, retrieve the resource descriptor for the Domain. For example, to view the descriptor for the Supermart Domain, use the following request (when logged in as jasperadmin):
GET http://<host>:<port>/jasperserver-pro/rest_v2/resources/Domains/supermartDomain
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<semanticLayerDataSource>
<creationDate>2013-10-10 15:30:31</creationDate>
<description>Comprehensive example of Domain (pre-joined table sets for complex reporting, custom query based dataset, column and row security, I18n bundles)</description>
<label>Supermart Domain</label>
<permissionMask>1</permissionMask>
<updateDate>2013-10-10 15:30:31</updateDate>
<uri>/organizations/organization_1/Domains/supermartDomain</uri>
<version>1</version>
<dataSourceReference>
<uri>/organizations/organization_1/analysis/datasources/FoodmartDataSourceJNDI</uri>
</dataSourceReference>
<bundles>
<bundle>
<fileReference><uri>/organizations/organization_1/Domains/supermartDomain_files/supermart_domain.properties</uri></fileReference>
<locale></locale>
</bundle>
(snip) [...]
The Domain schema is an XML file with a structure explained in the JasperReports Server User Guide. If you wish to modify the schema programmatically, you must write your own parser to access its fields and definitions. You can then replace the schema file in the Domain with one of the file updating methods described in .
Well, i found the solution.
If you want to create a schema per php client, create a new file object.
$file = new \Jaspersoft\Dto\Resource\File();
$file->type = "xml";
$file->label = "MyDomain_schema";
$file->content = base64_encode((string)$schemaXML);
The file content is the base64 encoded (valid) domain schema.
Now set $semLayer->schema = $file. This way works rather good.
Also, there is a way to create the domain via multipart request, but this way is rather complicated with php client. There is a function multipartrequest in the PHP Client, but it seems that this function consists of legacy code.
I am writing import script from csv files and I need to validate data, most of the data is strings so I want to use something like Jinput to sanitize it.
Is there is something Joomla already have for this purpose?
It would be ideal to have something like
$field = JSanitizer::get($data/*array with data*/, "fieldname"/*name of field*/,
'string'/*type of data*/, 'null'/*default value*/);
Also I would need it to work both in Joomla 2.5 and 3.0 versions.
You are probably looking for JFilterInput::clean() This would work as follows:
$field = JFilterInput::clean($data[$fieldname], 'filter');
This does not give a way to set a default value, so you would have to handle that afterwards. This should be the same filtering that is typically done with JInput as well as on JForm elements if you write custom components.
I can't seem to find a good list of all the filters, but you can see an old version of the source here: http://docs.joomla.org/API16:JFilterInput/clean. Most recent version of the function starts at line 162 here: https://github.com/joomla/joomla-cms/blob/master/libraries/joomla/filter/input.php
Note also that you want to pull the field out of the data array yourself. You can actually send it the entire array without a filter setting and it should at least check the entire array for XSS and other issues. If you want more nuanced filtering for integers and such, it would best to do it field by field.
$field = JFilterInput::clean($data[$fieldname], 'filter');
will fire a notice
"Non-static method JFilterInput::clean() should not be called statically"
You should initiate this with JFilterInput::getInstance() first and call it dynamically e.g.:
$field = JFilterInput::getInstance()->clean($data[$fieldname], 'filter');
Tom
You should read Joomla docs and use something like this before parsing file : $string = JRequest::getString( 'description' );
This should work across all version since 1.5
There has been some github projects to implement html purifier as plugin, i found this, but havent chance to tested it, but it should work though.
I've been looking for a way to check if a point is part of a polygon; this polygon is loaded from a file.
All the answers related to this question are solved with javascript, but I require to do this on server-side; this because the result does not need to be shown to the user as a webclient, it needs to be stored and later be used as a parameter to select a group of users (that use the system) inside that area (polygon).
I looked for a Google Maps API for PHP but it looks like it does not exists at all. I found this one, but it is not related to Google and also focuses on the front end.
I also looked for a REST API; it would have been relatively easy to load the content to my php and parse it, but looks like Google put all its efforts on the JS API.
Is there any workaround for this?
Edit 1: As #Spacedman requested, the file format is a KML
Clarification 1: I expected that Google provide a tool for this (as it exists with JS); parsing the file to check via an algorithm is a posibility and I'll have to check if it works properly.
Did you try searching for "php point in polygon" in your favourite search engine? Top hit:
http://assemblysys.com/php-point-in-polygon-algorithm/
It uses a scanline algorithm, and there's some examples. All you need to do is read your polygon file into the right format (you neglected to say what format you have) and call the function.
You can try somthing like this (in php should be similar):
int iCheck=0;
for (i = 0, v = HowManyVecotrsHasThePolygon - 1; i < HowManyVecotrsHasThePolygon; v = i++)
{
if (((vectorPointLatitud[i] > ptoLatitud) != (vectorPointLatitud[v] > ptoLatitud)) && (ptoLongitud < (vectorPointLongitud[v] - vectorPointLongitud[i]) * (ptoLatitud - vectorPointLatitud[i]) / (vectorPointLatitud[v] - vectorPointLatitud[i]) + vectorPointLongitud[i]))
iCheck++;
}
if iCheck is pair the point is outside, even inside
Checkout Polygons Eric Haines. I got the idea from him.
The idea is you've to create a Ray from your point, and check how many intersections between this ray and the Polygons vectors
The algorithm is just a bit of algebra, that you can check in any book.
You could use the PHP V8 PECL extension to execute javascript within PHP. Alternatively, you could call a node.js script using a shell command (which essentially does the same thing).
http://php.net/manual/en/book.v8js.php
http://php.net/manual/en/function.shell-exec.php
I have an idea for a text based game where I would pass commands and arguments to php for it to decide what to do with the player next.
I would type say "go north" or something more complicated like "use key door" into an AJAX form which would send the command to the php script, and I want the php script to know what action it was using eg "use" and also the first and second arguments "key" and "door" and decide what to do next, but Im not sure how to go about it.
Please note I do NOT want to run this from the command line, but from a web based interface.
Say the AJAX form would send a request to /game.php?do=use+key+door...
Then in game.php you could:
$do = $_GET['do'];
list($action, $object) = split(' ', $do, 2);
// $action == 'use'
// $object == 'key door'
You can check out a code and output example here.
(Same goes for$_POST['do'] if you choose to implement your form in POST.)
It seems to me that if you are using ajax, you would use either get or post so in your php script you simply check $_GET or $_POST.
You can acquire the entire string of arguments from one request (textarea, input). You can get this information from _GET or _POST. As for how to handle the information, you have to build a parser. Its complexity is up to you. One of the simpler things you could do would be to split up the request into tokens by spaces (you would get 'go', 'north', or 'use', 'key', 'door'). Inspect your list of keywords to add actions to the stack (go, use) and add actors and actees to the stack (key, door, north). Throw out unnecessary words (on, a, the, etc.). Then go through the stack. If you get "use," you expect two arguments following (actor and actee, e.g. use the key on the door). If you are missing this information, or if it's nonsense (use the blorb on the foon) tell the user the command is invalid. Give them a list of common commands. You may also want to give them a bit of leeway for certain objects and misspellings. You can also read more about lexical parsers to get a better idea about how to do this in a more complex manner.
Here's the code I'm using to generate the request headers:
$headers = array(
new SOAPHEADER($this->_ns,'username',$this->_username,false, $this->_actor),
new SOAPHEADER($this->_ns,'password',$this->_password,false, $this->_actor));
$this->_client->__setSOAPHeaders($headers);
This generates:
<SOAP-ENV:Header>
<ns2:username SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next">test</ns2:username>
<ns2:password SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next">test</ns2:password>
</SOAP-ENV:Header>
That's all fine and dandy.
Here are my two questions:
The API doc requires that username be ns1:username and password be ns2:password. Mine are both ns2. First of all, what is the significance of the ns1|2? How can I fix this?
Second question is just is there a way to generate the same result by only calling SOAPHEADER() once?
Not easy to say whether the namespace makes a difference without seeing the declaration & knowing the service, but usually the receiving service looks only for the tags in that particular namespace. As you add $this->_ns to both of them, of course they'll be the same. You'll have to provide the proper namespace yourself (prefix doesn't matter, uri does).
Why would you want only 1 call?