Google Plus Count url - url

I'm trying to get the count of plus one's I have for google plus, I am checking to see if I have the count right with this
https://plusone.google.com/u/0/_/%2B1/fastbutton?count=true&url=MY_URL
I see that google plus rejects my URL (doesn't return 0 or anything)
I wanted to know if anyone can tell me if I have anything wrong in my url, I have these symbols in my url outside of letters and numbers
:
/
.
?
=
&
_
and my url is formatted like this
(protocol)://(server [such as www]).(domain)/(text).php?(text)=(text)&(text)=(digits)&(text)=(text)

Use the URL
https://plusone.google.com/_/+1/fastbutton?url=http%3A%2F%2Fwww.yoursite.com%2Fpath%2Fyour%2fcontent
instead and follow the solution found in this question (parse for window.__SSR = {c:)

I think you're looking for this. It's ugly and Google clearly doesn't support it, but it still works.
function shinra_gplus_get_count( $url ) {
$contents = file_get_contents(
'https://plusone.google.com/_/+1/fastbutton?url='
. urlencode( $url )
);
preg_match( '/window\.__SSR = {c: ([\d]+)/', $contents, $matches );
if( isset( $matches[0] ) )
return (int) str_replace( 'window.__SSR = {c: ', '', $matches[0] );
return 0;
}

Related

QUERY simplification with LAMBDA function

I have this formula so I want to make the same QUERY for each variable and join the results. The given formula works (no error in cell) but it give me only the first query result.
I want the result to be QUERYRESULT1 / QUERYRESULT2 / QUERYRESULT3, etc. and i could repeeat the query for each variable, but I'm asking for a way to make it with only one line (to simplify). Is it possible?
=MAP(
BI3:BI;BL3:BL;BO3:BO;BR3:BR;BU3:BU;BX3:BX;CA3:CA;CD3:CD;CG3:CG;CJ3:CJ;CM3:CM;CP3:CP;
LAMBDA(f;g;h;i;j;k;l;m;n;o;p;q;
TEXTJOIN(" / "; TRUE;
IFNA(
ARRAYFORMULA(
IFERROR(QUERY('BDD Componentes'!AR:AV;"SELECT AV WHERE AR = '"&{f;g;h;i;j;k;l;m;n;o;p;q}&"'";0))
)
)
)
)
)
here I am with the same suggestion as in your previous question. Try it and let me know:
=BYROW({BI3:BI\BL3:BL\BO3:BO\BR3:BR\BU3:BU\BX3:BX\CA3:CA\CD3:CD\CG3:CG\CJ3:CJ\CM3:CM\CP3:C};
LAMBDA(r;
TEXTJOIN(" / "; TRUE;
IFNA(
ARRAYFORMULA(
IFERROR(QUERY('BDD Componentes'!AR:AV;"SELECT AV WHERE AR = '"&r&"'";0))
)
)
)
)
)

What's a way to retrive the "path" portion of dxlHere() and go up two dirs?

We are regularly setting up new DOORS installations on standalone networks, and each of these networks use slightly different drive mappings and installation directories. We have a set of DXL scripts that we copy over to each network that uses DOORS, but these DXL scripts reference some Microsoft Word templates that are used as the basis for custom-developed module export scripts.
We no longer have a DXL expert in-house, and I'm trying to make the scripts more portable so that they no
longer contain hard-coded file paths. Because we copy all of the templates and DXL files in a pre-defined directory structure, I can use the dxlHere() function to figure out the execution path of the DXL script, which would print something like this:
<C:\path\to\include\file\includeFile.inc:123>
<C:\path\to\include\file\includeFile.inc:321>
<Line:2>
<Line:5>
<Line:8>
What I'd like to do is extract everything before file\includeFile.inc:123>, excluding the starting <. Then I want to append templates\template.dotx.
For example, the final result would be:
C:\path\to\inclue\template.dotx
Are there any built-in DXL functions to handle string manipulation like this? Is regex the way to go? If so, what regexp would be appropriate to handle this?
Thanks!
I got this... kind of working.
dxlHere is something I don't work with much, but this seems to work- as long as it's saved to a an actual dxl or inc file (i.e. not just run from the editor)
string s = dxlHere()
string s2 = null
string s3 = null
Regexp r = regexp2 ( "\\..*:.*> $" )
Regexp r2 = regexp2 ( "/" )
if ( r s ) {
s2 = s[ 1 : ( ( start ( 0 ) ) - 1 ) ]
s3 = s[ 1 : ( ( start ( 0 ) ) - 1 ) ]
int x = 0
while ( r2 s2 ) {
x++
s2 = s2[ ( ( start ( 0 ) ) + 1 ) : ]
}
int z = 0
for ( y = 0; y <= length( s3 ); y++ ){
if ( s3[y] == '/' ) {
z++
if ( z == ( x - 2 ) ) {
s = s3[ 0 : y ]
break
}
}
}
}
print s
So we're doing a single regexp to check if we have a valid 'location', then running through it to find ever '/' character, then leaving off the last 2 of them.
Hope this helps!

cl_http_utility not normalizing my url. Why?

Via an enterpreise service consumer I connect to a webservice, which returns me some data, and also url's.
However, I tried all methods of the mentioned class above and NO METHOD seems to convert the unicode-characters inside my url into the proper readable characters.... ( in this case '=' and ';' ) ...
The only method, which runs properly is "is_valid_url", which returns false, when I pass url's like this:
http://not_publish-workflow-dev.hq.not_publish.com/lc/content/forms/af/not_publish/request-datson-internal/v01/request-datson-internal.html?taskId\u003d105862\u0026wcmmode\u003ddisabled
What am I missing?
It seems that this format is for json values. Usually = and & don't need to be written with the \u prefix. To decode all \u characters, you may use this code:
DATA(json_value) = `http://not_publish-workflow-dev.hq.not_publish.com/lc`
&& `/content/forms/af/not_publish/request-datson-internal/v01`
&& `/request-datson-internal.html?taskId\u003d105862\u0026wcmmode\u003ddisabled`.
FIND ALL OCCURRENCES OF REGEX '\\u....' IN json_value RESULTS DATA(matches).
SORT matches BY offset DESCENDING.
LOOP AT matches ASSIGNING FIELD-SYMBOL(<match>).
DATA hex2 TYPE x LENGTH 2.
hex2 = to_upper( substring( val = json_value+<match>-offset(<match>-length) off = 2 ) ).
DATA(uchar) = cl_abap_conv_in_ce=>uccp( hex2 ).
REPLACE SECTION OFFSET <match>-offset LENGTH <match>-length OF json_value WITH uchar.
ENDLOOP.
ASSERT json_value = `http://not_publish-workflow-dev.hq.not_publish.com/lc`
&& `/content/forms/af/not_publish/request-datson-internal/v01`
&& `/request-datson-internal.html?taskId=105862&wcmmode=disabled`.
I hate to answer my own questions, but anyway, I found an own solution, via manually replacing those unicodes. It is similar to Sandra's idea, but able to convert ANY unicode.
I share it here, just in case, any person might also need it.
DATA: lt_res_tab TYPE match_result_tab.
DATA(valid_url) = url.
FIND ALL OCCURRENCES OF REGEX '\\u.{4}' IN valid_url RESULTS lt_res_tab.
WHILE lines( lt_res_tab ) > 0.
DATA(match) = substring( val = valid_url off = lt_res_tab[ 1 ]-offset len = lt_res_tab[ 1 ]-length ).
DATA(hex_unicode) = to_upper( match+2 ).
DATA(char) = cl_abap_conv_in_ce=>uccp( uccp = hex_unicode ).
valid_url = replace( val = valid_url off = lt_res_tab[ 1 ]-offset len = lt_res_tab[ 1 ]-length with = char ).
FIND ALL OCCURRENCES OF REGEX '\\u.{4}' IN valid_url RESULTS lt_res_tab.
ENDWHILE.
WRITE / url.
WRITE / valid_url.

Remove older $_GET from url

I've got some problems with my url on my website. I'm trying to get a link with the given GET parameters, but i'm getting my previous parameter aswell.
My url looks like this:
www.cdwinkel.dev/search-results?genre=Pop&medium=DVD&medium=Single .
It should be:
www.cdwinkel.dev/search-results?genre=Pop&medium=Single .
I'm running the following code:
$data['url'] = createurl();
function createurl(){
$i = 1;
$string = "?";
$keys = array_keys($_GET);
foreach($_GET as $get){
if($get != ""){
$string .= $keys[$i] . "=" . $get ."&";
$i++;
}
}
$string = rtrim($string, "&");
return $string;
}
$i = 1, because my first value in my array is empty.
And my button looks like this:
<a href='".$data['url'].'&medium='.$names[$i]."'>
I guess I should'nt set &medium=.$names[$i] in the href tag,
but I wont get the new $names[$i] in my function, so I won't get a new url if i wont add it in.
I'm looking forward to your responce.
Sincerely,
Kars Takens
At this point i've created an array with the right arraykeys and values.
$url = array_slice($_GET, 1);
This returns the following array:
array (size=2)
'genre' => string 'Pop' (length=3)
'medium' => string 'DVD' (length=3)
After this I decoded this into a new string:
genre=Pop&medium=DVD
I got 6 button which I created in a foreach loop, but i'm getting &medium='VALUE' Twice. This only happens after the first time. So the first time my button works well.
<?php
$names = array_keys($data['tellen']);
$i = 0;
foreach($data['tellen'] as $m){
echo "<li><a href='search-results?".$data['url'].'&medium='.$names[$i]."'>". $names[$i] ." <span class='product-amount'>(". $m[0]->count. ")</span></a></li>";
$i++;
}
Hopefully you can help me further with this information.
I solved my problem by adding this in my forloop:
foreach($data['tellen'] as $m){
if(isset($_GET['medium'])){
unset($_GET['medium']);
$url = array_slice($_GET, 1);
$data['url'] = urldecode(http_build_query($url));
}
echo "<li><a href='search-results?".$data['url'].'&medium='.$names[$i]."'>". $names[$i] ." <span class='product-amount'>(". $m[0]->count. ")</span></a></li>";
$i++;
}

How to detect if the path of a url starts with a certain word

I'm trying to figure out how to get the page name from a facebook page and although I've figured out how to get it from the http://www.facebook.com/pagename version, I can't figure out how to test and get it from the longer version that looks like this http://www.facebook.com/pages/pagename/433425324544. How can I test to see if the path starts with /pages and how can I extract the pagename from it all using one function. Here's what I use to get the page name in the standard form.
function get_facebook_username( $facebook_url ) {
$url = $facebook_url;
$result = preg_match("/(https|http)?:\/\/(www\.)?facebook\.com\/?([^\/]*)/", $url, $matches);
$fb_username = 'default value';
if($result == 1){
$fb_username = $matches[3];
} else {
return;
}
echo "$fb_username";
}
I found a better way to do this I think except it cuts the last letter off the username if the url is in it's shortened version. For example.
//---short
$url = http://www.facebook.com/pagename
//---long
$url = http://www.facebook.com/pages/pagename/7532527927346
<?php
$url = $facebook_username;
$path = parse_url($url, PHP_URL_PATH);
$pathTrimmed = trim($path, 'pages/../0123456789');
echo $pathTrimmed;
?>
//---short
pagenam
//---long
pagename
Why is the short version missing the last letter?
The way I would go about this is to use explode to place the url into an array using the below code:
$url = "http://www.facebook.com/pages/pagename/7532527927346";
$result = explode("/", $url);
You get the following array:
array(6) {
[0]=>
string(5) "http:"
[1]=>
string(0) ""
[2]=>
string(16) "www.facebook.com"
[3]=>
string(5) "pages"
[4]=>
string(8) "pagename"
[5]=>
string(13) "7532527927346"
}
Then a simple if $result[3] == "pages" will allow you to check if the url contains pages.
Ninja Edit
In place of explode, you can also use the preg_split which will return no empty array elements:
$result = preg_split("~/~", $url, -1, PREG_SPLIT_NO_EMPTY);

Resources