Advertisement
smaction

Enter Keywords

Mar 28th, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.14 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: scott
  5.  * Date: 3/4/19
  6.  * Time: 2:33 PM
  7.  */
  8. include 'KeywordClass.php';
  9.  
  10. $keytext = $_GET['keywords'];
  11. $customer = $_GET['client'];
  12.  
  13. $keywords = explode("\r\n", $keytext);
  14.  
  15. $usable = new KeywordClass();
  16.  
  17.  
  18.  
  19. $table = '<HTML><TABLE><TH> Keyword </TH><TH> Status </TH><TH> Results</TH>';
  20.  
  21. foreach ($keywords as $keyword){
  22.     if (preg_match('/^[a-z0-9\040]+$/i',$keyword)) {
  23.         //$URL = "http://abc/api/v1/";
  24.         $URL = "http://127.0.0.1/Espo/api/v1/";
  25.         $keyword = str_replace(" ", '+', $keyword);
  26.         $user = 'xxxxx';
  27.         $password = 'xxxxx';
  28.         $action = "Keyterms?select=name&maxSize=100&offset=0&orderBy=createdAt&order=desc&where%5B0%5D%5Btype%5D=textFilter&where%5B0%5D%5Bvalue%5D=" .$keyword ;
  29.         $json = $usable->accessEspo($URL,$action,$user,$password);
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.        switch ($json['total']) {
  37.  
  38.             case 0:
  39.  
  40.                 $use = 'Keyword can be used';
  41.                 $results = $usable->getNumResults($keyword);
  42.  
  43.                 break;
  44.  
  45.             case 1:
  46.  
  47.                 $keyword_id = $json['list'][0]['id'];
  48.                 $action = "Keyterms/" . $keyword_id;
  49.                 $json1 = $usable->accessEspo($URL, $action, $user, $password);
  50.  
  51.                 if(!$json1['approved']){
  52.                     $use = 'Keyword can be used';
  53.                     $results = $usable->getNumResults($keyword);
  54.  
  55.  
  56.                     break;
  57.                 }
  58.                 $account_id = $json1['accountId'];
  59.                 $action = "Account/" . $account_id;
  60.                 $json2 = $usable->accessEspo($URL, $action, $user, $password);
  61.                 $use =  $json2['clientID'];
  62.                 break;
  63.  
  64.             default:
  65.  
  66.                 $use = "Must be checked manually";
  67.                 break;
  68.         }
  69.     }
  70.     else{
  71.         $use = "you have an illegal character";
  72.         $results = '';
  73.  
  74.     }
  75.  
  76.     if($use == 'Keyword can be used'){
  77.         $action = 'Account?select=name,clientID,website,type&maxSize=20&offset=0&orderBy=createdAt&order=desc&where[0][type]=equals&where[0][attribute]=clientID&where[0][value]=' . $customer;
  78.         $json3 = $usable->accessEspo($URL, $action, $user, $password);
  79.  
  80.         $espoAccount = $json3['list'][0]['id'];
  81.         $espoName = $json3['list'][0]['name'];
  82.         $action = 'website?accountId,name,websiteURL,siteType&maxSize=20&offset=0&where[0][type]=equals&where[0][attribute]=accountId&where[0][value]='.$espoAccount.'&where[1][type]=equals&where[1][attribute]=siteType&where[1][value]=Primary+SEO+Build';
  83.         $json4 = $usable->accessEspo($URL, $action, $user, $password);
  84.  
  85.         $webID = $json4['list'][0]['id'];
  86.         $webName = $json4['list'][0]['name'];
  87.         $action = 'Keyterms';
  88.         $params = array('accountId'=>$espoAccount,'accountName'=>$espoName,'generated'=>'True','clientSupplied'=>'false','approved'=>'false','name'=>$keyword);
  89.  
  90.         $json5 = $usable->editEspo($URL,$action,$params,$user,$password);
  91.  
  92.  
  93.     }
  94.  
  95.     $table = $table . "<TR><TD>$keyword</TD><TD>$use</TD><TD>$results</TD></TR>";
  96.  
  97. }
  98.  
  99. $table = $table . '</TABLE><HTML>';
  100.  
  101. echo $table;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement