Domain Meta Validation - laravel

I have a code set on Laravel. This is doing dns verification, I want to verify a specific field in the meta tag I want.
Example code
public function verifyDomainDns()
{
$fqdn = sprintf('%s.%s', $this->getVerificationTxtName(), $this->name);
$results = collect(dns_get_record($fqdn, DNS_TXT));
$results = $results->where('type', 'TXT')
->where('txt', $this->verification_token);
$this->domain_verified = $results->isEmpty() ? self::UNVERIFIED : self::VERIFIED;
$this->save();
}
verification_token Auto-generated numbers registered in database
The meta tag I want to verify.
<meta name="book" content="verification_token" />

There is no correlation between what your code is already doing and what you want to do.
One way you can achieve this is to get the contents of the URL with something like file_get_contents(), which will result in you getting the HTML content of the URL.
Once you have this, you can use something like DOMXpath to parse it and get the meta tag's contents.
$html = file_get_contents('https://example.com');
$dom = new DomDocument();
$dom->loadHTML($html);
$xpath = new DomXPath($dom);
$contents = $xpath->query('/html/head/meta[#name="book"]/#content');
if ($contents->length === 0) {
echo 'No tag found';
} else {
foreach ($contents as $content) {
echo $content->value;
}
}

Related

How to compare dynamic url?

I have stored a url in session in laravel. Now i want to compare link between session url which was stored and the url()->previous(). But the problem is url is dynamic.
THe problem i am facing
$url = url('/').'/complete-profile/*';
if(session()->get('url.intended') == $url)
{
return redirect('/home');
}
This doesn't work. how to compare /complete-profile/* with other url.. (*) this can be anything
Try something like this. Builds your URL and the rest check if it contains the word complete-profile :
$url = 'complete-profile';
if (strpos(session()->get('url.intended'), $url) !== false) {
return redirect('/home');
} else {
//
}

How to make a utf-8 report?

My report does not write exactly accentuated letters ( french ) , so there are unreadable characters displayed on the report. The runReport.php file is :
<?php
define("ROOT_PATH", "../");
require_once ROOT_PATH . 'config.inc.php';
require_once("java/Java.inc");
class runReport {
function runReport($report, $param, $output) {
$pth = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
$path_parts = pathinfo($pth);
$imageURLPrefix = $path_parts['dirname'] ."/images/";
session_start();
$here = getcwd();
$ctx = java_context()->getServletContext();
$birtReportEngine = java("org.eclipse.birt.php.birtengine.BirtEngine")->getBirtEngine($ctx);
java_context()->onShutdown(java("org.eclipse.birt.php.birtengine.BirtEngine")->getShutdownHook());
try{
$thereport = $birtReportEngine->openReportDesign(RP_REPORT.$report);
$task = $birtReportEngine->createRunAndRenderTask($thereport);
$task->setParameterValue("province", new java("java.lang.Integer", read_post_int("province"));
$taskOptions = new java("org.eclipse.birt.report.engine.api.HTMLRenderOption");
$outputStream = new java("java.io.ByteArrayOutputStream");
$taskOptions->setOutputStream($outputStream);
$taskOptions->setOutputFormat("html");
$ih = new java( "org.eclipse.birt.report.engine.api.HTMLServerImageHandler");
$taskOptions->setImageHandler($ih);
$taskOptions->setEnableAgentStyleEngine(true);
$taskOptions->setBaseImageURL($imageURLPrefix . session_id());
$taskOptions->setImageDirectory($here . "/images/" . session_id());
$task->setRenderOption( $taskOptions );
$task->run();
$task->close();
}
catch (JavaException $e) {
echo $e; //"Error Calling BIRT";
}
echo $outputStream;
}
}
?>
So how to make the report support utf-8 encoding ?
Don't know PHP, but this could just be a problem of your encoding HTTP header. What does the HTML source generated by BIRT look like.
Does it contain a <meta charset="xxx"/> tag?
If it does, this should match the Content-Encoding HTTP header (sent by your server, probably settable with PHP).

Modify the existing canonical link in header

I am using Joomla 2.5 and I want to change the canonical link in the header.
I do this in category view (components/com_content/category/tmpl/default.php)
$url = JURI::root();
$sch = parse_url($url, PHP_URL_SCHEME);
$server = parse_url($url, PHP_URL_HOST);
$canonical = $this->escape($_SERVER['REQUEST_URI']);
$document->addCustomTag('<link rel="canonical" href="'.$sch.'://'.$server.$canonical.'"/>');
It prints the right canonical, but it also leaves the old canonical link there so that I have 2 canonical links in the header.
How can I change or delete the old canonical link?
I have found the following to work for me with Joomla! 3.2.1. You can directly modify the
$_links
variable in the JHtmlDocument object.
I'm doing a subset of the following in a particular view of my component because the URL that Joomla! is coming up with is not correct.
Hope this helps.
$document = JFactory::getDocument();
foreach($document->_links as $key=> $value)
{
if(is_array($value))
{
if(array_key_exists('relation', $value))
{
if($value['relation'] == 'canonical')
{
// we found the document link that contains the canonical url
// change it!
$canonicalUrl = 'http://www.something.com/index.php/component/my-component-name-here/?view=viewNameHere&parameterNameHere=parameterValueUsedInTheViewRightNow
$document->_links[$canonicalUrl] = $value;
unset($document->_links[$key]);
break;
}
}
}
}
What you probably want to do instead is something like the following:
$doc_data = $document->getHeadData();
$url = JURI::root();
$sch = parse_url($url, PHP_URL_SCHEME);
$server = parse_url($url, PHP_URL_HOST);
$canonical = $this->escape($_SERVER['REQUEST_URI']);
$newtag = '<link rel="canonical" href="'.$sch.'://'.$server.$canonical.'"/>'
$replaced = false;
foreach ($doc_data['custom'] as $key=>$c) {
if (strpos($c, 'rel="canonical"')!==FALSE) {
$doc_data['custom'][$key] = $newtag;
$replaced = true;
}
}
if (!$replaced) {
$doc_data['custom'][] = $newtag;
}
$document->setHeadData($doc_data);
This will grab all of the current head data from the document, including the canonical link that you want to replace. It will search through the custom set (where I'm guessing this will be) and if it finds it, replace it with yours. If it doesn't find it, then it tacks it on at the end. Just in case.
Potential problems with this that I can see right away:
If the tag contained rel='canonical' with single quotes it would not be found, so you may have to adjust that.
The tag may have been placed in a different section of what I've termed $doc_data. You may want to do a var_dump($doc_data}; to confirm the location of the variable in this array.

How to get Response of REST API in JSON format by Default in Magento

In magento as we use the REST url to access the data,as http://localhost/magemto/api/rest/products it returns in XML format.
But as my team requirement, I should send the data in JSON format to access AJAX calls easily.. I have used REST client to include a header as 'Content-Type:appilcation/json'.. Then it returns in JSON format.. But I want it as defaultly by the magento API..
Hey, I do have a solution for this, I would like to share with you.
First go to your magento root folder then go to following path
\app\code\core\Mage\Api2\Model\Request.php
Go to the method getAccepTypes() and change with this code below it will fulfill your requirement.
public function getAcceptTypes()
{
$qualityToTypes = array();
$orderedTypes = array();
foreach (preg_split('/,\s*/', $this->getHeader('Accept')) as $definition) {
$typeWithQ = explode(';', $definition);
$mimeType = trim(array_shift($typeWithQ));
// check MIME type validity
if (!preg_match('~^([0-9a-z*+\-]+)(?:/([0-9a-z*+\-\.]+))?$~i', $mimeType)) {
continue;
}
$quality = '1.0'; // default value for quality
if ($typeWithQ) {
$qAndValue = explode('=', $typeWithQ[0]);
if (2 == count($qAndValue)) {
$quality = $qAndValue[1];
}
}
$qualityToTypes[$quality][$mimeType] = true;
}
krsort($qualityToTypes);
foreach ($qualityToTypes as $typeList) {
$orderedTypes += $typeList;
}
unset($orderedTypes);
$orderedTypes=Array
("application/json" => 1);
return array_keys($orderedTypes);
}
Hope this help you.

TYPO3 Extbase: How to render the pagetree from my model?

I want to create some kind of sitemap in extbase/fluid (based on the pagetree). I have loaded the pages table into a model:
config.tx_extbase.persistence.classes.Tx_MyExt_Domain_Model_Page.mapping.tableName = pages
I have created a controller and repository, but get stuck on the part wich can load the subpages as relation into my model.
For example:
$page = $this->pageRepository->findByPid($rootPid);
Returns my rootpage. But how can I extend my model that I can use $page->getSubpages() or $page->getNestedPages()?
Do I have to create some kind of query inside my model? Or do I have to resolve this with existing functions (like the object storage) and how?
I tried a lot of things but can simply figure out how this should work.
you have to overwrite your findByPid repository-method and add
public function findByPid($pid) {
$querySettings = $this->objectManager->create('Tx_Extbase_Persistence_Typo3QuerySettings');
$querySettings->setRespectStoragePage(FALSE);
$this->setDefaultQuerySettings($querySettings);
$query = $this->createQuery();
$query->matching($query->equals('pid', $pid));
$pages = $query->execute();
return $pages;
}
to get all pages. Than you can write your own getSubpages-method like
function getSubpages($currentPid) {
$subpages = $this->pagesRepository->findByPid($currentPid);
if (count($subpages) > 0) {
$i = 0;
foreach($subpages as $subpage) {
$subpageUid = $subpage->getUid();
$subpageArray[$i]['page'] = $subpage;
$subpageArray[$i]['subpages'] = $this->getSubpages($subpageUid);
$i++;
}
} else {
$subpageArray = Array();
}
return $subpageArray;
}
i didn't test this method, but it looks like this to get alle subpages.
i wonder that i couldĀ“t find a typo3 method that return the complete Page-Tree :( So i write a little function (you can use in an extbase extension), for sure not the best or fastes way, but easy to extend or customize ;)
first you need an instance of the PageRepository
$this->t3pageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
this->t3pageRepository->init();
make the init, to set some basic confs, like "WHERE deletet = 0 AND hidden = 0..."
then with this function you get an array with the page data and subpages in. I implement yust up to three levels:
function getPageTree($pid,$deep=2){
$fields = '*';
$sortField = 'sorting';
$pages = $this->t3pageRepository->getMenu($pid,$fields,$sortField);
if($deep>=1){
foreach($pages as &$page) {
$subPages1 = $this->t3pageRepository->getMenu($page['uid'],$fields,$sortField);
if(count($subPages1)>0){
if($deep>=2){
foreach($subPages1 as &$subPage1){
$subPages2 = $this->t3pageRepository->getMenu($subPage1['uid'],$fields,$sortField);
if(count($subPages2>0)){
$subPage1['subpages'] = $subPages2;
}
}
}
$page['subpages'] = $subPages1;
}
}
}
return $pages;
}

Resources