Episerver FIND result not in CMS - find

Sometimes when the user is deleting the page it is not being removed from FIND index. While we are trying to find the issue we want to check if the FIND result is actually there.
For example, on the home page there are news which are coming from FIND. When the user clicks on a news and if the news is not in the CMS they are getting 404.
Is there a way in FIND query to check if the result gotten actually is in CMS. My query is as follows
SearchResults<ContentReference> result = query
.FilterForVisitor()
.InLanguageBranch(languageBranch)
.OrderByDescending(z => z.Changed)
.Take(count)
.Select(z => z.ContentLink)
.GetResult();
var items = contentLoader.GetItems(result.Hits.Select(x => x.Document), new LanguageSelector(languageBranch)).ToList().Cast<T>();
return items;

Related

Algolia Instant Search - how to not do the initial search?

I've been following the example for Algolia's Instant Search at https://www.algolia.com/doc/guides/search/instant-search/ (javascript version)
I understand that for many use-cases (like in the example) it makes sense for the script to run its initial search upon pageload and display the results (basically all results).
In my case though I'd like to not do that initial search. How can I achieve this?
Thanks
You can pass a searchFunction parameter to the instantsearch initializer, which will intercept each search and let you decide whether to perform it or not.
Here's an example taken from this Github issue. The search is not performed if the query is empty, as it will be on page load.
var search = instantsearch({
searchFunction: function(helper) {
if (helper.state.query === '') {
return;
}
helper.search();
}
});
If you have your own logic around when the search should/shouldn't be performed you can use it in here. See the Usage tab of the Initialization section of the docs for more information.

How do I get a list of users who liked a page? [duplicate]

I was wondering if it was possible to query the following:
List of (all) users who like my facebook page, and
Additional information those users have made publicly available (beyond first and last name)
Basically looking to generate detailed marketing stats of users who like my facebook page, if possible. Any suggestions or alternatives welcome.
Thank you.
I am afraid this is NOT possible, follow this bug for more information.
Another proof is the page_fan table you will notice that only the uid field is indexable so you need to know the user id to search it and not the page_id, as you know if a user "likes" a page this would mean he is a "fan" of that page.
After being actively working with the Facebook API for a while now, and following the announcements and API releases (and deprecations) along with the introduction and changes of policies, I can understand that Facebook will only share info about their users by letting them explicitly do so (a.k.a interact/authorize your Apps).
And hence the best thing to do in the absence of such feature is:
Understand your audience through Page Insights
Collect fans interests & info by creating custom apps through Page Tabs and using other Facebook features like Questions
Alright, nobody wants to break Facebook's TOS but they have tied our hands on our own basic data. So, scraping is illegal, but not saving a page. What I have done (and note that I needed this for offline purpose anyway):
Go to https://www.facebook.com/browse/?type=page_fans&page_id={FAN PAGE ID}
Scroll down until you have all of your fans. Save this page on your local machine, let's say, Facebook.html.
Now, using ruby and nokogiri:
require 'nokogiri'
>true
f = File.open('/your_path/Facebook.html')
doc = Nokogiri::HTML.parse(f.read)
doc.xpath('//div[#class="fsl fwb fcb"]/a').each {|link| puts link.content}
Do a graph search likes this: "People who like [your fanpage's name]". You will all the result.
Then create shortcut on your browser with this javascripts code, it will click on the View more link and scrolling until all result are shown in the page:
javascript: i = 0;minutes = 30;counter = minutes * 60;function repeatScroll() {
if (i < counter) {window.scrollTo(0, document.body.scrollHeight);i++;}
setTimeout(repeatScroll, 1000);}repeatScroll();
After that, create other shortcut and run this js code to retrieve all UID from the search result:
javascript:var txt="";e=document.getElementsByClassName("FriendRequestOutgoing");
for(var i=0; i<e.length; i++) {v=e[i].getAttribute("data-profileid");
if(v) txt+=v+"\n"}document.body.innerHTML="<textarea>"+txt+"</textarea>";
A textarea box will appear in the screen with all uid inside. Just copy it to your notepad and import into your Custom Audience in Facebook Ad Manager.
I created and use this code everyday to get all UID with criterial I need.
You can launch any graph search you want.
This is homemade code, so using it without your own responsibility :)
Enjoy them.
It's possible, just not with FQL anymore.
Do a GET of https://www.facebook.com/browse/?type=page_fans&page_id={FAN PAGE ID} and scrape out the users.
Viola.
Now you can get people on your page with this link, or click on Settings button, than on People on the left sidebar. https://www.facebook.com/[PAGENAME]/settings/?tab=people_and_other_pages
If you want to get all the user's photo, press F12 and add these codes to the Console:
javascript:i=0;minutes=30;counter=minutes*60;function repeatScroll(){if(i<counter){window.scrollTo(0, document.body.scrollHeight);i++;}setTimeout(repeatScroll,1000);}repeatScroll();
than, when you reached the bottom of the page:
javascript:var txt="";e=document.getElementsByClassName("img"); for(var i=0; i<e.length; i++) {v=e[i].getAttribute("src"); if(v) txt+="<img src='"+v+"'>\n"}document.body.innerHTML="<textarea>"+txt+"</textarea>";
To display photos: create a HTML page and first insert these lines into that file:
<meta charset="utf-8">
<style>img { width:21px; margin:-1px; }</style>
<div style="width:851px; height:315px;background-color:white;">
<!-- PASTE HERE PHOTOS' CODE YOU GET -->
<span style="color:#3B5998;font-weight:bold;font-size:20px;margin-bottom:4px;">600 like, thank you!</span>
<!-- PASTE HERE PHOTOS' CODE YOU GET -->
</div>
Then create shortcut on your browser with this javascript code, it will click on the View more link and scrolling until all result are shown in the page:
i = 0;
minutes = 30;
counter = minutes * 60;
function repeatScroll() {
if (i < counter) {
window.scrollTo(0, document.body.scrollHeight);
i++;
}
setTimeout(repeatScroll, 1000);
}
repeatScroll();
After that, create other shortcut and run this js code to retrieve all UID from the search result:
var e=document.getElementsByClassName("fsl fwb fcb");
var ids = [];
for(var i = 0 ; i < e.length; i++){
ids.push(JSON.parse(e[i].childNodes[0].getAttribute("data-gt")).engagement.eng_tid);
}
console.log(ids);
load all list
i = 0;
minutes = 30;
counter = minutes * 60;
function repeatScroll() {
if (i < counter) {
window.scrollTo(0, document.body.scrollHeight);
i++;
}
setTimeout(repeatScroll, 1000);
}
repeatScroll();
get id
var e=document.getElementsByClassName("_3cb8");
var ids = [];
for(var i = 0 ; i < e.length; i++){
ids.push(e[i].getAttribute("href"));
}
console.log(ids);
You can get it using facebook open graph.
https://graph.facebook.com/<your-page-name-or-page-id>/likes
For example :
https://graph.facebook.com/chickfila/likes
You need to send graph api call using "id" for more detail about user who like you page.
However, this call will retrieve the other Facebook objects that the page (Chickfila) has liked, NOT the users who have liked the Chickfila page.

Atk4 Step by Step form doesn't load Facebook Like Buttons

I have a array with list of sites, I'm coding a step by step form using http://codepad.agiletoolkit.org/newsletter example.
In the second step I put Like Buttons using the following code:
$attr = array (
'data-send' => FALSE,
'data-layout' => 'button_count',
'data-width' => 100,
'data-show-faces' => FALSE
);
foreach($this->sites as $k => $site) {
$div = $form->add('View_HtmlElement')->setElement('div')->set(NULL);
$attr['data-href'] = $site;
$div->addClass('fb-like');
$div->setAttr($attr);
}
This works good when I access directly, but when I try to access via next button, the Like Buttons doesn't load.
Any solution for this?
The reason why the facebook and some other buttons may not work with AJAX pages is because facebook scripts generally process your HTML only during initial load of the page. When the form in your example goes to next step, it uses AJAX to load additional form. As a result you will need to either manually trigger facebook's scripts to re-walk your page or perform redirects instead of reload. You would need to change:
$this->js()->atk4_load($this->api->getDestinationURL('./step2'))
->execute();
to
$this->js()->univ()->location($this->api->getDestinationURL('./step2'))
->execute();
You may also find this article useful: http://agiletoolkit.org/blog/adding-twitter-button-to-ajax-page/

Programmatically adding an article to Joomla

I am very new to Joomla (frankly just started exploring the possibility of using Joomla) and need help with programmatically adding articles to Joomla backend tables (please see details below). Also along the same lines, I would like to understand how should values for the columns:
parent_id
lft
rgt
level
be generated for the table jos_assets (#__assets) and what is their functional role (eg are they “pointers/indexes” analogous to, say, an os inode to uniquely indentify a file or are they more functional attributes such as identifying the category, subcategory etc)
It might help to use the following SIMPLIFIED example to illustrate what I am trying to do. Say we have a program that collects various key information such as names of the authors of web articles, the subject type of the articles, the date of articles as well as a link to the article. I want to be able to extend this program to programmatically store this information in Joomla. Currently this information is stored in a custom table and the user, through a custom php web page, can use search criteria say by author name, over a certain range of dates to find the article(s) of interest. The result of this search is then displayed along with a hyperlink to the actual article. The articles are stored locally on the web server and are not external links. The portion of the hyperlink stored in the custom table includes the relative path of the physical document (relative to the web root), so for example:
Author date type html_file
Tom 08-14-2011 WEB /tech/11200/ar_324.html
Jim 05-20-2010 IND /tech/42350/ar_985.html
etc.
With all the advantages that Joomla offers over writing custom php search and presentation pages as well as trending etc, we would really like to switch to it. It seems that among other tables for example that #__assets and #__content can be populated programmatically to populate Joomla from our existing php program (which is used to compile the data) and then use Joomla.
Any examples, suggestions and help is greatly appreciated
Kindest regards
Gar
Just an initial note: Joomla 1.6/1.7 are pretty similar. 1.5 not so much. I'll assume 1.6/1.7, as that's what I'd recommend as a base for a new project.
First up, you'll need to be running with access to the Joomla framework. You could do this through a Component, or a module, or a cron that bootstraps it or whatever. I won't go though how to do that.
But once you do that, creating an article is reasonably simple.
<?php
require_once JPATH_ADMINISTRATOR . '/components/com_content/models/article.php';
$new_article = new ContentModelArticle();
$data = array(
'catid' => CATEGORY_ID,
'title' => 'SOME TITLE',
'introtext' => 'SOME TEXT',
'fulltext' => 'SOME TEXT',
'state' => 1,
);
$new_article->save($data);
The actual list of fields will be a bit longer than that (required fields etc), but you should get sane error messages etc from the Joomla framework which illuminate that.
So in summary:
Load up the Joomla framework so you have access to the DB, components, models, etc
Include the com_content article class, which will handle validation, saving to the database etc for you
Create an article instance with the required fields filled in as appropriate
Call save()
Now that I think about it, that'll probably work in 1.5...
Found a better way to do this without any errors Create a Joomla! Article Programatically
$table = JTable::getInstance('Content', 'JTable', array());
$data = array(
'catid' => 1,
'title' => 'SOME TITLE',
'introtext' => 'SOME TEXT',
'fulltext' => 'SOME TEXT',
'state' => 1,
);
// Bind data
if (!$table->bind($data))
{
$this->setError($table->getError());
return false;
}
// Check the data.
if (!$table->check())
{
$this->setError($table->getError());
return false;
}
// Store the data.
if (!$table->store())
{
$this->setError($table->getError());
return false;
}

t3blog - how to clear cache when user writes comment?

When a user writes a comment then it doesn't become visible right away. It becomes visible if I clear the cache manually.
Usually t3blog stores posts and comments within the t3blog page itself and then one should be able to clear the cache this way.
TCEMAIN.clearCacheCmd = all
However in my t3blog setup the posts and comments are in a separate sysfolder. Here is the setup typoscript
plugin.tx_t3blog_pi1.blogPid = 21
Is there a way I can trigger clear cache when the user submits a new comment?
I have unsuccessfully tried installing an 'aftercommentinsertion' hook.
Finally I solved it by modifying t3blog itself, so that you can specify the uid of the pages that needs to be cleared via typoscript.
# my typoscript code
plugin.tx_t3blog_pi1.blogList {
# clear these pages when a visitor writes a new comment to a post
clearCacheForPIDsAfterCommentInsertion = 1,6,8,24
}
// the file: t3blog/pi1/widgets/blogList/class.singleFunctions.php
protected function insertNewComment(array $data) {
$data['pid'] = t3blog_div::getBlogPid();
$data['date'] = $data['crdate'] = $GLOBALS['EXEC_TIME'];
$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_t3blog_com', $data);
$commendId = $GLOBALS['TYPO3_DB']->sql_insert_id();
$this->updateRefIndex('tx_t3blog_com', $commentId);
// Hook after comment insertion
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'])) {
foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'] as $userFunc) {
$params = array(
'data' => &$data,
'table' => 'tx_t3blog_com',
'postUid' => $data['fk_post'],
'commentUid' => $commendId,
);
t3lib_div::callUserFunction($userFunc, $params, $this);
}
}
// ******************* MY CLEAR CACHE CODE *******************
error_log("t3blog inserted new comment");
$pids = $this->conf['clearCacheForPIDsAfterCommentInsertion'];
$pidArray = is_string($pids) ? t3lib_div::trimExplode(',', $pids, 1) : NULL;
error_log("t3blog clearCacheForPIDsAfterCommentInsertion: ".$pids." -- ".print_r($pidArray, true));
if(is_array($pidArray)) {
$tce = t3lib_div::makeInstance('t3lib_TCEmain');
foreach($pidArray as $pid) {
error_log("t3blog clear_cacheCmd: ".$pid);
$tce->clear_cacheCmd((int)$pid);
}
}
}
I have sendt this code to Dmitry Dulepov (the author of t3blog).
You can add this line in your PAGE TS of the sysfolder (uid=21) holding your blog post:
TCEMAIN.clearCacheCmd = 1,6,8,24
That line will tell that new blog posts shall trigger a clear cache of that exact list of pages. I think your users will need rights to clear cache though...
Reason it goes into the PAGE TS of you sysfolder and not one or all of the pages where your blog is inserted is that... they are (probably) all cached. Your sysfolder is not cached and the new record will be noticed by TYPO3 and tricker a clear cache of the cached pages you just defined by your comma separated string.
Did you try to include the clearCacheCmd in the page TSconfig of the sysfolder where the comments are stored? You can use "all", "pages" or the relevant page uids, cf: http://typo3.org/documentation/document-library/core-documentation/doc_core_tsconfig/4.3.2/view/1/5/#id2505694
This should work if the "user" is a backend user with the relevant priveleges - but I guess, when you say "a user writes a comment", it is a front end user you are talking about, and then this will probably not be of much help.
The solution then would be to have the extension clear the cache upon receiving a comment. This might not be possible for you to do, but the quick fix to this is to mark the page as not cacheable ("Disable cache", Behavior tab). Beware, though, this will cause your server to suffer.