/** * Check for hijacked URL space * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. * @return boolean Indicating success. */ public function _can_handle_redirect($handler_id, array $args, array &$data) { // Process the request immediately if (isset($args[0])) { $mc = net_nemein_redirector_tinyurl_dba::new_collector('node', $this->_topic->guid); $mc->add_constraint('name', '=', $args[0]); $mc->add_value_property('code'); $mc->add_value_property('url'); $mc->execute(); $results = $mc->list_keys(); // No results found if (count($results) === 0) { return false; } // Catch first the configuration option for showing editing interface instead // of redirecting administrators if ($this->_topic->can_do('net.nemein.redirector:noredirect') && !$this->_config->get('admin_redirection')) { midcom::get()->relocate("{$this->_topic->name}/edit/{$args[0]}/"); } foreach ($results as $guid => $array) { $url = $mc->get_subkey($guid, 'url'); $code = $mc->get_subkey($guid, 'code'); break; } // Redirection HTTP code if (!$code) { $code = $this->_config->get('redirection_code'); } midcom::get()->relocate($url, $code); // This will exit } return true; }
/** * Check for duplicate names */ private function duplicate_names() { $mc = net_nemein_redirector_tinyurl_dba::new_collector('name', $this->name); $mc->add_constraint('node', '=', $this->node); // This item already exists, exclude itself from duplicate name check if ($this->guid) { $mc->add_constraint('guid', '<>', $this->guid); } $mc->execute(); if (count($mc->list_keys()) > 0) { return true; } else { return false; } }
/** * Get the item according to the given rule * * @param mixed $rule * @return false on failure or net_nemein_redirector_tinyurl_dba on success */ private function _get_item($rule) { $mc = net_nemein_redirector_tinyurl_dba::new_collector('node', $this->_topic->guid); // Set the rules $mc->begin_group('OR'); $mc->add_constraint('guid', '=', $rule); $mc->add_constraint('name', '=', $rule); $mc->end_group(); $mc->execute(); $keys = $mc->list_keys(); if (count($keys) === 0) { return false; } $item = new net_nemein_redirector_tinyurl_dba(key($keys)); return $item; }