/** * Take the incomming request referrer and decide if we should save this term in our * database * @param incoming request usually $this->here * @return void * @access public */ function parseRequest($request = null) { if ($request) { $referrer = env('HTTP_REFERER'); // Check if from google and page 2 if (strpos($referrer, "google.com")) { if (!SeoUtil::getConfig('searchTerms')) { return; } //parse the term out. if (strpos($referrer, "q=")) { list($ignore, $term) = explode("q=", $referrer); if (strpos($term, "&")) { list($term, $ignore) = explode("&", $term); } $term = trim(urldecode($term)); if ($term && strpos($referrer, "start=")) { //Only proceed if we have a valid term if ($id = $this->field('id', array('SeoSearchTerm.term' => $term))) { $this->itterateCount($id); } else { $data = array('SeoSearchTerm' => array('term' => $term, 'uri' => $request, 'count' => 1)); $this->save($data); } } elseif ($term) { //Delete the term if this was found on the first page. if ($id = $this->field('id', array('SeoSearchTerm.term' => $term))) { $this->delete($id); } } } } } }
/** * Show a honeypot link * to bait scrappers to click on for autobanning * @param string title for link * @param array of options * @return HtmlLink to honeypot action */ function honeyPot($title = 'Click Here', $options = array()) { $options = array_merge(array('rel' => 'nofollow', 'id' => 'honeypot-' . $this->nextId()), $options); $link = $this->Html->link($title, SeoUtil::getConfig('honeyPot'), $options); $javascript = $this->Html->scriptBlock("\n\t\t\tdocument.getElementById('{$options['id']}').style.display = 'none';\n\t\t\tdocument.getElementById('{$options['id']}').style.zIndex = -1;\n\t\t"); return $link . $javascript; }
function startTest() { $this->Seo = new SeoHelper(); $this->Seo->Html = new HtmlHelper(); $cacheEngine = SeoUtil::getConfig('cacheEngine'); if (!empty($cacheEngine)) { Cache::clear($cacheEngine); } }
/** * Initialize the component, set the settings */ function initialize(&$controller, $settings = array()) { $this->Controller = $controller; $this->_set($settings); $this->honeyPot = SeoUtil::getConfig('honeyPot'); if (!$this->__isBanned()) { $this->__handleIfHoneyPot(); } }
/** * Add the IP to the banned list. * @param string ip to ban * @param string note to add to this ban * @return boolean success of save */ function addToBanned($ip = null, $note = "AutoBanned", $is_active = null) { if (!$ip) { $ip = $this->getIpFromServer(); } if ($is_active === null) { $is_active = SeoUtil::getConfig('aggressive'); } return $this->save(array($this->alias => array('ip_range_start' => $ip, 'ip_range_end' => $ip, 'note' => $note, 'is_active' => $is_active))); }
/** * setup */ public function setUp() { parent::setUp(); $Controller = new Controller(); $this->View = new View($Controller); $this->Seo = new SeoHelper($this->View); $this->Seo->Html = new HtmlHelper($this->View); $cacheEngine = SeoUtil::getConfig('cacheEngine'); if (!empty($cacheEngine)) { Cache::clear($cacheEngine); } }
/** * Find, setup, and get the AB test, if we're using Sessions setup in the config, look at that first. * @param array of options * - debug (if true, will always return the test even if it's not active, and regardless of roll) * - return (test|roll|both) default test. * - refresh (will preform the search as normal without the cached test result) default false * @return mixed array test if found and rolled, or boolean depending on return option. */ public function getTest($options = array()) { $options = array_merge(array('debug' => false, 'return' => 'test', 'refresh' => false), (array) $options); $retval = array('test' => false, 'roll' => false); if (!$options['refresh'] && $this->test) { return $this->test; } $this->loadModel('SeoABTest'); if ($test = $this->SeoABTest->findTestByUri(null, $options['debug'])) { if ($this->SeoABTest->isTestable($test)) { $retval['test'] = $test; if (SeoUtil::getConfig('abTesting.session')) { $ab_tests = CakeSession::check('Seo.ABTests') ? CakeSession::read('Seo.ABTests') : array(); } else { $ab_tests = array(); } if (is_array($ab_tests) && isset($ab_tests[$test['SeoABTest']['id']])) { $retval['roll'] = !!$ab_tests[$test['SeoABTest']['id']]; } elseif ($options['debug'] || $this->SeoABTest->roll($test)) { $ab_tests[$test['SeoABTest']['id']] = $test; $retval['roll'] = true; } else { $ab_tests[$test['SeoABTest']['id']] = false; $retval['roll'] = false; } if (SeoUtil::getConfig('abTesting.session')) { CakeSession::write('Seo.ABTests', $ab_tests); } $this->test = $retval; } } switch ($options['return']) { case 'test': return $retval['test']; case 'roll': return $retval['roll']; default: return $retval; } }
/** * Load the settings */ function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds); $this->settings = SeoUtil::getConfig('levenshtein'); }
/** * Decide if we have a test for this request * @param string request (optional will default to REQUEST_URI * @param boolean debug (default false), if true, will also return non active tests based on the request * @return mixed boolean false if no test, otherwise the ABTest will be returned */ public function findTestByUri($request = null, $debug = false) { if ($request === null) { $request = env('REQUEST_URI'); } $fields = array("{$this->SeoUri->alias}.uri", "{$this->alias}.slug", "{$this->alias}.id", "{$this->alias}.roll", "{$this->alias}.priority", "{$this->alias}.testable"); $conditions = array("AND" => array(array('OR' => array("{$this->alias}.start_date IS NULL", "{$this->alias}.start_date <=" => date('Y-m-d'))), array('OR' => array("{$this->alias}.end_date IS NULL", "{$this->alias}.end_date >=" => date('Y-m-d'))))); if (!$debug) { $conditions["{$this->alias}.is_active"] = true; } //Test one of one. if ($test = $this->find('first', array('conditions' => array_merge(array("{$this->SeoUri->alias}.uri" => $request, "{$this->SeoUri->alias}.is_approved" => true), $conditions), 'contain' => array("{$this->SeoUri->alias}.uri"), 'fields' => $fields, 'order' => "{$this->alias}.priority ASC"))) { return $test; } //Check Many to Many and Many to One $cacheEngine = SeoUtil::getConfig('cacheEngine'); if (!empty($cacheEngine)) { $cacheKey = 'seo_ab_tests'; $tests = Cache::read($cacheKey, $cacheEngine); } if (!isset($tests) || empty($tests)) { $tests = $this->find('all', array('conditions' => $conditions, 'contain' => array("{$this->SeoUri->alias}.uri"), 'fields' => $fields, 'order' => "{$this->alias}.priority ASC")); if (!empty($tests) && !empty($cacheEngine)) { Cache::write($cacheKey, $tests, $cacheEngine); } } foreach ($tests as $test) { if (SeoUtil::requestMatch($request, $test[$this->SeoUri->alias]['uri'])) { return $test; } } return false; }
/** * Go through the uri to levenshtein url database and find the closest redirect based in sitemap * @return void */ function __uriToLevenshtein() { $levconfig = SeoUtil::getConfig('levenshtein'); if (!$levconfig['active']) { return; } $this->__loadModel('SeoUrl'); $request = env('REQUEST_URI'); $redirect = $this->SeoUrl->findRedirectByRequest($request); if ($redirect['redirect'] != $request) { if (SeoUtil::getConfig('log')) { CakeLog::write('seo_levenshtein', "Levenshtein Redirect {$request} to {$redirect['redirect']} score {$redirect['shortest']}"); } $this->controller->redirect($redirect['redirect'], 301); } return; }
/** * testGetConfigWithInvalid * * @return void */ public function testGetConfigWithInvalid() { $this->assertNull(SeoUtil::getConfig('invalid')); }
/** * Clear the list of old visits baesd on the current time. * @return boolean success */ function clear() { $cutoff = time() - SeoUtil::getConfig('timeBetweenTriggers'); return $this->deleteAll(array("{$this->alias}.created <=" => date('Y-m-d g:i:s', $cutoff))); }
/** * Send the notification of a regular expression that needs approval. * * @param int id * @return void */ public function sendNotification($id = null) { if ($id) { $this->id = $id; } $this->read(); if (!empty($this->data)) { if (!isset($this->Email)) { App::uses('CakeEmail', 'Network/Email'); $this->Email = new CakeEmail(); if ($email_config = SeoUtil::getConfig('emailConfig')) { $this->Email->config($email_config); } } $this->Email->to(SeoUtil::getConfig('approverEmail')); $this->Email->from(SeoUtil::getConfig('replyEmail')); $this->Email->subject("301 Redirect: {$this->data[$this->alias]['uri']} to {$this->data[$this->SeoRedirect->alias]['redirect']} needs approval"); $this->Email->send("A new regular expression 301 redirect needs to be approved.<br /><br/>\n\n\t\t\t\tURI: {$this->data[$this->alias]['uri']}<br />\n\t\t\t\tREDIRECT: {$this->data[$this->SeoRedirect->alias]['redirect']}<br />\n\t\t\t\tPRIORITY: {$this->data[$this->SeoRedirect->alias]['priority']}<br /><br />\n\n\t\t\t\tLink to approve:<br />\n\t\t\t\t" . SeoUtil::getConfig('parentDomain') . "/admin/seo/seo_redirects/approve/{$this->data[$this->SeoRedirect->alias]['id']}<br /><br />\n\t\t\t\t"); } }
/** * Send the notification of a regular expression that needs approval. * @param int id * @return void */ function sendNotification($id = null) { if ($id) { $this->id = $id; } $this->read(); if (!empty($this->data)) { if (!isset($this->Email)) { App::import('Component', 'Email'); $this->Email = new EmailComponent(); } $this->Email->to = SeoUtil::getConfig('approverEmail'); $this->Email->from = SeoUtil::getConfig('replyEmail'); $this->Email->subject = "301 Redirect: {$this->data[$this->alias]['uri']} to {$this->data[$this->SeoRedirect->alias]['redirect']} needs approval"; $this->Email->sendAs = 'html'; $this->Email->send("A new regular expression 301 redirect needs to be approved.<br /><br/>\n\t\t\t\t\n\t\t\t\tURI: {$this->data[$this->alias]['uri']}<br />\n\t\t\t\tREDIRECT: {$this->data[$this->SeoRedirect->alias]['redirect']}<br />\n\t\t\t\tPRIORITY: {$this->data[$this->SeoRedirect->alias]['priority']}<br /><br />\n\t\t\t\t\n\t\t\t\tLink to approve:<br />\n\t\t\t\t" . SeoUtil::getConfig('parentDomain') . "/admin/seo/seo_redirects/approve/{$this->data[$this->SeoRedirect->alias]['id']}<br /><br />\n\t\t\t\t"); } }
/** * Read Configuration */ public function getConfig($value = '') { return SeoUtil::getConfig($value); }
/** * This is a custom helper to translate ticket_id's * into a full link into redmine based on a a config url 'abTesting.redmine' * (custom functionality you may not need) * * @param mixed $ticket_id (string or int) * @return string $html */ public function redmineLink($ticket_id = null) { if (empty($ticket_id) || !is_numeric($ticket_id)) { return null; } return $this->Html->link($ticket_id, SeoUtil::getConfig('abTesting.redmine') . $ticket_id, array('class' => 'btn btn-mini btn-info', 'target' => '_blank')); }
/** * Wrapper for SeoUtil getConfig * * @param $key * @return mixed */ public function getConfig($key) { return SeoUtil::getConfig($key); }