Changing an ExpressionEngine Plugin's Parse Order - expressionengine

I have the following ExpressionEngine code in a template:
{exp:hits:count_hits_image entry_id='{exp:test:getpage tag="id"}'}
Where exp:test is a plugin I created to get a channel entry's ID.
The problem I'm having is that exp:hits is being parsed before exp:test, which makes the whole tag disfunctional.
What can I do to tell ExpressionEngine to parse the inside tag first {exp:test}, before parsing the outside tag {exp:hits}?

What you need to do is turn your plugin into a tag pair, so it works like this:
{exp:test:getpage tag="id" parse="inward"}
{exp:hits:count_hits_image entry_id='{id}'}
{/exp:test:getpage}
In your plugin you'd do something like this:
$vars = array();
$vars[0]['id'] = $results->row('id');
return $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $vars);

Try this:
{exp:hits:count_hits_image entry_id='{exp:test:getpage tag="id"}' parse="inward"}

Related

Getting No Urls to Fetch error on Nutch1.16

I am new to apache-nutch and want to crawl few questions on stackoverflow. My urls/seed.txt has following data:-
/questions/58763948/setting-a-list-item-is-converting-it-into-a-tuple
/questions/58763947/start-up-eclipse-an-error-has-occured-see-the-log-file
/questions/58763946/problem-with-the-proxy-using-zap-docker-image-gitlab
/questions/58763945/how-to-select-unique-random-data-based-on-percent-in-sql
/questions/58763943/probelm-with-using-filter-function-to-remove-missing-values-form-a-dataset
/questions/58763942/flutter-keep-data-in-textfield-after-setstate
/questions/58763941/are-receipts-generated-by-google-play-api-v2-and-the-latest-version-v3-compatibl
/questions/58763940/how-to-add-eventhandler-to-popupmenuitem-in-flutter
/questions/58763938/how-to-solve-electron-and-grpc-version-problem-in-angular-project
...
Is there any property which i can include in nutch-site.xml to add https://stackoverflow.com before every url in seed.txt. I don't want to change seed.txt since file is large
No, there is no such configuration property. It's possible to do this by adding the following rule to regex-normalize.xml:
<regex>
<pattern>^/</pattern>
<substitution>https://stackoverflow.com/</substitution>
</regex>
Also make sure that the plugin urlnormalizer-regex is included in the property plugin.includes.

Passing AVP to prefix core function

I am working what appears to be a simple function for opensips 2.2.3, however cannot seem to get it working..
Essentially, extract the groupID from permissions module and add a prefix to R-URI on the egress side.
https://www.opensips.org/Documentation/Script-CoreFunctions-2-2#toc26
http://www.opensips.org/html/docs/modules/2.2.x/permissions.html#idp5689232
Config route looks like this:
route[relay] {
if ( get_source_group("$avp(group)") ) {
# do something with $avp(group)
xlog("group is $avp(group)\n");
};
#Add the string parameter in front of username in R-URI.
#prefix("$avp(group)");
#prefix("$avp(group){s.substr,0,0}");
$avp(22) = "3333#";
prefix("$avp(22)");
Prefix core function prefixes R-URI with variable name ($avp(22)) instead of value of "3333#".
I have tried various syntax versions that are commented out, however to no avail..
If I remove the quotes around the variable name:
prefix($avp(22));
Opensips does not startup at all, complaining about:
syntax error and bad argument, string expected
Am I missing something simple?
or
prefix function is simply not designed to work with variables?
Thank you in advance.
prefix() is somewhat old and unmaintained, hence it does not support variables. However, you can prepend your group to the R-URI username with:
$rU = $avp(group) + $rU;
xlog("My new R-URI is $ru. My new R-URI username is $rU\n");

How to use add_rewrite_rule function, while permalink structure is disabled?

I am using the add_rewrite_rule() function to modify my URL structure.
I'm wanting to use add_rewrite_rule to add a custom rule but these rules only get added in when other than default settings are selected in my permalink settings area.
i.e. in the settings there are following options:
- Default http://localhost/wordpress/?p=123
- Day and name http://localhost/wordpress/2014/08/14/sample-post/
- Month and name http://localhost/wordpress/2014/08/sample-post/
- Numeric http://localhost/wordpress/archives/123
- Post name http://localhost/wordpress/sample-post/
- Custom Structure http://localhost/wordpress
So, when I select other then 'Default', my add_rewrite_rule() function works, but while selecting 'Default', the function doesn't seem to be work. So please suggest me how to work the function in any condition. Any help would be Appriciated.
Update:
I think the problem lies here:
When I use this, while selecting 'Default':
get_option('permalink_structure');
I got nothing.
While in the other cases, there are some values like:
/%postname%/
/archives/%post_id%
/%year%/%monthnum%/%postname%/
The Default permalinks, or so called "Ugly" permalinks, are not adding anything to the .htaccess file, so the Apache rewrite engine is not enabled. Without the rewrite engine, no rewrites can be done. So the short answer is that rewrites are not possible with Default permalinks.
I can recommend you to use rewrites along with query vars. When adding a rewrite rule, pass your custom data to a query var, and build the functionality around that query var. This way your functionality will work in all situations and with all permalink types.
So for example if you have the following rule:
add_rewrite_rule('^sometest/([^/]*)/?','index.php?custom_query_var=$matches[1]', 'top');
and you have the custom_query_var added as a query var by using the following code:
function add_query_vars_filter( $vars ){
$vars[] = "custom_query_var";
return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );
then when Default permalinks are selected, the following URL would work for you:
http://yoursite.com/index.php?custom_query_var=abc
and if "Pretty" permalinks are selected, the URL rewriting would work and your URL would look the following way:
http://yoursite.com/sometest/abc/
which is basically the best that can be achieved with rewrites.
I agree with #Martin. Here's a resource that will help https://core.trac.wordpress.org/ticket/15235
use this:
function my_add_query_vars( $qvars ) {
$qvars[] = 'business-coaching';
$qvars[] = 'country';
$qvars[] = 'territory';
$qvars[] = 'region';
return $qvars;
}
add_action('query_vars', 'my_add_query_vars');
//Write the rule
function add_analytic_rewrite_rule()
{
// Regex:The regex to match the incoming URL is:business-coaching(/([^/]+))?(/([^/]+))?(/([^/]+))?/?
// Redirect Rule :The resulting internal URL: `index.php` because we still use WordPress
// `pagename` or page_id=45 because we use this WordPress page
// `country` : we will assign the first captured regex part to this variable
// `territory` we will assign the second captured regex part to this variable
// `region` we will assign the third captured regex part to this variable
add_rewrite_rule('business-coaching(/([^/]+))?(/([^/]+))?(/([^/]+))?/?','index.php?page_id=45&country=$matches[2]&territory=$matches[`enter code `enter code here`here`4]&region=$matches[6]','top');//superfinal
}
add_action('init', 'add_analytic_rewrite_rule');

Grocery crud : How to get the current id that had been used when editing and viewing a record?

How to get the current id that had been used when editing and viewing a record?
I am currently following the instruction by Alfonso Secas that he posted in this topic..
http://www.grocerycrud.com/forums/topic/1326-how-to-use-grocery-crud-and-image-crud-together/page-2
And now on the part where he said "When editing a record, get the current ID from $this->getStateInfo(); to compose the iframe's source url."
It seems like getStateInfo doesn't exist yet so it shows an error "Fatal error: Call to undefined method Examples::getStateInfo() "
http://www.grocerycrud.com/documentation/options_functions/getState
this will do what u want . give it a try
u need to use the CRUD object to call this function instead of $this ..
You have some options:
Primary key
getStateInfo()->get_primary_key
Last uri segment
end($this->uri->segments)
Does not work in list action.
As a workaround you can use one of CodeIgniter's methods to get id from page url
https://www.codeigniter.com/userguide3/libraries/uri.html
You need to take last segment from URI
$segmentsCount = $this->uri->total_segments();
$itemID = intval($this->uri->segment($segmentsCount));
p.s. it is not best solution but it can do the trick

How can I get some particular link form the links collection

I'm using watir-webdriver have several lines of the same code shown below:
...
<p class="schedule-text">
by
MarketingClub
in
Marketing
</p>
I need to get the first links included in p tag and the second links included in p tag
so using page object I've added the following code:
links(:followees_category, :css => "#home-followees li.animate-in ul li[data-show-id] p.schedule-text a")
...
followees_category_elements.attribute("href")
the last row will give me both links : http://www.somesite2.com, http://www.somesite2.com
Unfortunately, I can't indicate in css :last/:first etc.
the second link can be gotten by changing css to :
#home-followees li.animate-in ul li[data-show-id] p.schedule-text a + a
but how can I get just the first links from such blocks?
Of course, I can get both links and work with every 2nd, but maybe there is an alternative solution?
You can use the css nth-of-type pseudo class to get elements based on their index (or relative position).
For example, a:nth-of-type(1) can be used to return all links that are the first line of their parent:
links(:followees_category, :css => "p.schedule-text a:nth-of-type(1)")
For the second links, you can do a:nth-of-type(2). Note that it is 1-based index.
links(:followees_category, :css => "p.schedule-text a:nth-of-type(2)")
For the first link, you can also do a:first-of-type:
links(:followees_category, :css => "p.schedule-text a:first-of-type")
If the second link is always the last link, you can also do a:last-of-type:
links(:followees_category, :css => "p.schedule-text a:last-of-type")
I would not recommend using css selectors like these, because they make your tests harder to read and more fragile.
But, whatever the selector is in the end, i would use Ruby's Enumerable methods to get the second links like this:
links.select.each_with_index {|_, i| i.odd? }

Resources