AMFPHP overiding default function arguments? - argument-passing

I've got this odd problem.
If I make a call on that function through amfphp service browser and give it a valid ID and leave the $num_images field blank amfphp will actually pass a blank string as the argument.
// if i call this function width just an ID
function getWorkers($id, $num_images = 100) {
...
// num_images will be set as ''
}
I can easily override using a check:
function getWorkers($id, $num_images = 100) {
if($num_images=='') $num_images = 100;
...
// num_images will now be really set as 100
}
Anyone experiencing the same with amfphp?

That's odd, I never got that from AMFPHP. If you don't have the latest version try updating your installation of AMFPHP. Also make sure Flash doesn't somehow pass an empty variable as the second variable.
(Copied from the comment.)

Related

Correct parameters for rotation using $BitmapDecoder.GetSoftwareBitmapAsync

I have this PowerShell code:
$AsyncTask = $BitmapDecoder.GetSoftwareBitmapAsync()
But discovered that some of the images coming in are rotated, so experimenting I came up with this:
$BmTf = [BitmapTransform]::new()
$BmTf.Rotation = [BitmapRotation]::None
# $BmTf.Rotation = [BitmapRotation]::Clockwise90Degrees
# $BmTf.Rotation = [BitmapRotation]::Clockwise180Degrees
# $BmTf.Rotation = [BitmapRotation]::Clockwise270Degrees
$AsyncTask = $BitmapDecoder.GetSoftwareBitmapAsync(
[BitmapPixelFormat]::Bgra8,
[BitmapAlphaMode]::Ignore,
$BmTf,
[ExifOrientationMode]::IgnoreExifOrientation,
[ColorManagementMode]::DoNotColorManage
)
While it does work, I'm not familiar BitmapPixelFormat, or the other parameters. The documentation for GetSoftwareBitmapAsync() doesn't appear to give any hints on what the default value it is using for BitmapPixelFormat.
Does anyone know the best values to pass to the version of GetSoftwareBitmapAsync() that takes 5 parameters to mimic the version of GetSoftwareBitmapAsync() that takes 0 parameters?
EDIT:
Just found out that trying [BitmapPixelFormat]::Unknown causes this error:
Exception calling "GetSoftwareBitmapAsync" with "5" argument(s): "The
parameter is incorrect. Windows.Graphics.Imaging: The bitmap pixel
format is unsupported."
But no errors with [BitmapPixelFormat]::Bgra8.
I don't know why GetSoftwareBitmapAsync doesn't like [BitmapPixelFormat]::Unknown, but here is the solution I found.
I need to first load the image to see if it needs rotating. That is done with the original command:
$AsyncTask = $BitmapDecoder.GetSoftwareBitmapAsync()
$SoftwareBitmap = GetAsync( $AsyncTask, ([SoftwareBitmap]) )
Then extract its BitmapPixelFormat:
$BitmapPixelFormat = $SoftwareBitmap.BitmapPixelFormat
And then use $BitmapPixelFormat for all calls to the 5 parameter version of GetSoftwareBitmapAsync().

Codeigniter form validation callback rule issue

I am using Codeigniter 3.x form validation callback method in combination trim and required to validate a field.
The problem is, when I pipe them: trim|required|callback_some_method, the callback method seems to take precedence over trim and required and shows its error message.
Any ideas on this?
EDIT:
This is the rule:
$this->form_validation->set_rules('new_password', 'New Password', 'trim|required|min_length[8]|callback_password_check');
And this is the password_check method:
function password_check($pwd) {
$containsLetterUC = preg_match('/[A-Z]/', $pwd);
$containsLetterLC = preg_match('/[a-z]/', $pwd);
$containsDigit = preg_match('/\d/', $pwd);
$containsSpecial = preg_match('/[^a-zA-Z\d]/', $pwd);
if ( !($containsLetterUC && $containsLetterLC && $containsDigit && $containsSpecial) ) {
$this->form_validation->set_message('password_check', '{field} must contain UPPERCASE and lowercase letters, digits, and special characters.');
return FALSE;
}
return TRUE;
}
The method should return FALSE, but as long as required is before my custom rule and the field is empty, it should stop there with Required field message, NOT the custom method message.
Okay guys, I've managed to solve it by extending the Form_validation library, putting my callback method there and piping as the other rules (without callback_ prefix).
Unfortunately, as described in the code from CI, callbacks validation rules are always verified first, prior to ‘required’ for instance.
There is an official issue opened at CI : https://github.com/bcit-ci/CodeIgniter/issues/5077

What's wrong with my Meteor publication?

I have a publication, essentially what's below:
Meteor.publish('entity-filings', function publishFunction(cik, queryArray, limit) {
if (!cik || !filingsArray)
console.error('PUBLICATION PROBLEM');
var limit = 40;
var entityFilingsSelector = {};
if (filingsArray.indexOf('all-entity-filings') > -1)
entityFilingsSelector = {ct: 'filing',cik: cik};
else
entityFilingsSelector = {ct:'filing', cik: cik, formNumber: { $in: filingsArray} };
return SB.Content.find(entityFilingsSelector, {
limit: limit
});
});
I'm having trouble with the filingsArray part. filingsArray is an array of regexes for the Mongo $in query. I can hardcode filingsArray in the publication as [/8-K/], and that returns the correct results. But I can't get the query to work properly when I pass the array from the router. See the debugged contents of the array in the image below. The second and third images are the client/server debug contents indicating same content on both client and server, and also identical to when I hardcode the array in the query.
My question is: what am I missing? Why won't my query work, or what are some likely reasons it isn't working?
In that first screenshot, that's a string that looks like a regex literal, not an actual RegExp object. So {$in: ["/8-K/"]} will only match literally "/8-K/", which is not the same as {$in: [/8-K/]}.
Regexes are not EJSON-able objects, so you won't be able to send them over the wire as publish function arguments or method arguments or method return values. I'd recommend sending a string, then inside the publish function, use new RegExp(...) to construct a regex object.
If you're comfortable adding new methods on the RegExp prototype, you could try making RegExp an EJSON-able type, by putting this in your server and client code:
RegExp.prototype.toJSONValue = function () {
return this.source;
};
RegExp.prototype.typeName = function () {
return "regex";
}
EJSON.addType("regex", function (str) {
return new RegExp(str);
});
After doing this, you should be able to use regexes as publish function arguments, method arguments and method return values. See this meteorpad.
/8-K/.. that's a weird regex. Try /8\-K/.
A minus (-) sign is a range indicator and usually used inside square brackets. The reason why it's weird because how could you even calculate a range between 8 and K? If you do not escape that, it probably wouldn't be used to match anything (thus your query would not work). Sometimes, it does work though. Better safe than never.
/8\-K/ matches the string "8-K" anywhere once.. which I assume you are trying to do.
Also it would help if you would ensure your publication would always return something.. here's a good area where you could fail:
if (!cik || !filingsArray)
console.error('PUBLICATION PROBLEM');
If those parameters aren't filled, console.log is probably not the best way to handle it. A better way:
if (!cik || !filingsArray) {
throw "entity-filings: Publication problem.";
return false;
} else {
// .. the rest of your publication
}
This makes sure that the client does not wait unnecessarily long for publications statuses as you have successfully ensured that in any (input) case you returned either false or a Cursor and nothing in between (like surprise undefineds, unfilled Cursors, other garbage data.

Call TYPO3 plugin from other plugin's body

I need to call typo3 plugin from other plugin's body and pass its result to template. This is pseudo-code that describes what I want to achieve doing this:
$data['###SOME_VARIABLE###'] = $someOtherPlugin->main();
$this->cObj->substituteMarkerArray($someTemplate, $data);
Is it possible?
Thanks!
It doenst work if you use the whole pi construct, e.g. for links, marker function etc, and the TSFE Data can be corrupted.
Dmitry said:
http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1'];
$conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1.'];
$cObj = t3lib_div::makeInstance('tslib_cObj');
$cObj->start(array(), '_NO_TABLE');
$conf['val'] = 1;
$content = $cObj->cObjGetSingle($cObjType, $conf); //calling the main method
You should use t3lib_div:makeInstance method.
There is a working example from TYPO3's "powermail" extension.
function getGeo() {
// use geo ip if loaded
if (t3lib_extMgm::isLoaded('geoip')) {
require_once( t3lib_extMgm::extPath('geoip').'/pi1/class.tx_geoip_pi1.php');
$this->media = t3lib_div::makeInstance('tx_geoip_pi1');
if ($this->conf['geoip.']['file']) { // only if file for geoip is set
$this->media->init($this->conf['geoip.']['file']); // Initialize the geoip Ext
$this->GEOinfos = $this->media->getGeoIP($this->ipOverride ? $this->ipOverride : t3lib_div::getIndpEnv('REMOTE_ADDR')); // get all the infos of current user ip
}
}
}
The answer of #mitchiru is nice and basically correct.
If you have created your outer extension with Kickstarter and you are using pi_base then there is already an instance of tslib_cObj and the whole construct becomes simpler:
// get type of inner extension, eg. USER or USER_INT
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1'];
// get configuration array of inner extension
$cObjConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1.'];
// add own parameters to configuration array if needed - otherwise skip this line
$cObjConf['myparam'] = 'myvalue';
// call main method of inner extension, using cObj of outer extension
$content = $this->cObj->cObjGetSingle($cObjType, $cObjConf);
Firstly, you have to include your plugin class, before using, or outside your class:
include_once(t3lib_extMgm::extPath('myext').'pi1/class.tx_myext_pi1.php');
Secondly in your code (in the main as example)
$res = tx_myext_pi1::myMethod();
This will work for sure (I've checked this): http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html.
Probably Fedir's answer is correct too but I didn't have a chance to try it.
Cheers!

Wordpress TinyMCE: Switch Views

In order to complete my Wordpress Plugin I want to make tinyMCE to switch between a custom Tag (Some|data|here) and a corresponding Image Display in the WYSIWYG-View.
The event should be triggered on load, safe, autosave, switch view etc. Threre are 4 different events defined, but none of them works as expected.
onBeforeSetContent
onGetContent
onPostProcess
onLoadContent
.
ed.onPostProcess.add(function(ed, o) {
if (o.set){
o.content = t._htmlToWysiwyg(o.content, url);
}
if (o.get){
o.content = t._wysiwygToHtml(o.content, t);
}
});
Anyon know the right way?
I do not know what you expect the 4 different events will do (?), but i can see some problems in your code.
1. The object o does not contain fields get and set - so o.get and o.set will never be true! Thus your code will never be called.
2. You are using the variable url, but this one is not defined here.
Working example: You may try to paste a string containing "a" into the editor. Use the following:
ed.onPostProcess.add(function(ed, o) {
//console.log('o:', o);
o.content = o.content.replace(/a/g, "A");
});
You should see that all lower 'a's get replaced by 'A's.