function enqueue($queueName, $eventName, array $eventData)
 {
     $id = md5(time() . rand(0, 9999) . $eventName);
     $result = Idno::site()->triggerEvent($eventName, $eventData);
     $this->results[$id] = $result;
     return $id;
 }
Example #2
0
 /**
  *  Gatekeeper function that validates input forms and prevents csrf attacks.
  *  Call this from your form action code.
  *
  * @param string $targetURL The URL of the form action that brought us here.
  * @param boolean $haltExecutionOnBadRequest If set to true, the function halts all execution if the form doesn't validate. (True by default.)
  * @return true|false
  */
 public static function validateToken($action = '', $haltExecutionOnBadRequest = true)
 {
     if (Idno::site()->session()->isAPIRequest()) {
         return true;
     }
     return parent::validateToken($action, $haltExecutionOnBadRequest);
 }
Example #3
0
 /**
  * Purifies HTML code
  * @param $html
  * @param $basic_html Should the purifier strip out inline styles and similar attributes? Defaults to false.
  * @return string Purified HTML
  */
 function purify($html, $basic_html = false)
 {
     if ($basic_html) {
         $config = \HTMLPurifier_Config::createDefault();
         $config->set('Cache.SerializerPath', Idno::site()->config()->getUploadPath());
         $config->set('CSS.AllowedProperties', []);
         $config->set('HTML.TidyRemove', 'br@clear');
         $purifier = new \HTMLPurifier($config);
     } else {
         $purifier = $this->purifier;
     }
     return $purifier->purify($html);
 }
Example #4
0
 function init()
 {
     // Account management
     Idno::site()->addPageHandler('/account/settings/?', '\\Idno\\Pages\\Account\\Settings');
     Idno::site()->addPageHandler('/account/settings/notifications/?', '\\Idno\\Pages\\Account\\Settings\\Notifications');
     Idno::site()->addPageHandler('/account/settings/tools/?', '\\Idno\\Pages\\Account\\Settings\\Tools');
     Idno::site()->addPageHandler('/account/settings/following/?', '\\Idno\\Pages\\Account\\Settings\\Following');
     Idno::site()->addPageHandler('/account/settings/following/bookmarklet/?', '\\Idno\\Pages\\Account\\Settings\\Following\\Bookmarklet');
     // Basic registration; this is now always present, but the page will reject the user if registration
     // is closed and a valid invitation code hasn't been provided
     Idno::site()->addPageHandler('/account/register/?', '\\Idno\\Pages\\Account\\Register', true);
     // Password requests
     Idno::site()->addPagehandler('/account/password/?', '\\Idno\\Pages\\Account\\Password', true);
     Idno::site()->addPagehandler('/account/password/reset/?', '\\Idno\\Pages\\Account\\Password\\Reset', true);
     // Known feedback
     Idno::site()->addPageHandler('/account/settings/feedback/?', '\\Idno\\Pages\\Account\\Settings\\Feedback');
     Idno::site()->addPageHandler('/account/settings/feedback/confirm/?', '\\Idno\\Pages\\Account\\Settings\\FeedbackConfirm');
 }
Example #5
0
 /**
  * Pings mentions from a given page to any linked pages
  * @param $pageURL Page URL
  * @param string $text The text to mine for links
  * @return int The number of pings that were sent out
  */
 static function pingMentions($pageURL, $text)
 {
     // There's no point in sending webmentions to private resources
     if (!Idno::site()->config()->isPublicSite()) {
         return false;
     }
     if ($current_page = \Idno\Core\Idno::site()->currentPage()) {
         if ($nowebmention = $current_page->getInput('nomention') || defined('KNOWN_NOMENTION')) {
             return true;
         }
     }
     // Load webmention-client
     require_once \Idno\Core\Idno::site()->config()->path . '/external/mention-client-php/src/IndieWeb/MentionClient.php';
     // Proxy connection string provided
     $proxystring = false;
     if (!empty(\Idno\Core\Idno::site()->config()->proxy_string)) {
         $proxystring = \Idno\Core\Idno::site()->config()->proxy_string;
     }
     $client = new \Idno\Core\MentionClient($pageURL, $text, $proxystring);
     return $client->sendSupportedMentions();
 }
Example #6
0
 /**
  * Retrieve all the account identifiers associated with syndicating to all registered services
  * @return array
  */
 function getServiceAccountsByService()
 {
     $accounts = [];
     if (!empty($this->accounts)) {
         $accounts = $this->accounts;
     }
     $accounts = Idno::site()->triggerEvent('syndication/accounts/get', ['accounts' => $accounts], $accounts);
     return $accounts;
 }
Example #7
0
 /**
  * Return a version of the URL suitable for displaying in templates etc
  * @return string
  */
 function getDisplayURL()
 {
     $url = $this->getURL();
     $urischeme = parse_url($url, PHP_URL_SCHEME);
     if (Idno::site()->isSecure()) {
         $newuri = 'https:';
     } else {
         $newuri = 'http:';
     }
     $url = str_replace($urischeme . ':', $newuri, $url);
     if (substr($url, 0, 1) == ':') {
         $url = substr($url, 1);
     }
     return $url;
     //return str_replace($urischeme . ':', '', $url);
 }
Example #8
0
 function registerEventHooks()
 {
     // Add webmention headers to the top of the page
     Idno::site()->addEventHook('page/head', function (Event $event) {
         if (!empty(site()->config()->hub)) {
             $eventdata = $event->data();
             header('Link: <' . \Idno\Core\Idno::site()->config()->getURL() . 'webmention/>; rel="http://webmention.org/"', false);
             header('Link: <' . \Idno\Core\Idno::site()->config()->getURL() . 'webmention/>; rel="webmention"', false);
         }
     });
     Idno::site()->addEventHook('webmention/sendall', function (Event $event) {
         $data = $event->data();
         $result = self::pingMentions($data['source'], $data['text']);
         $event->setResponse($result);
     });
     Idno::site()->addEventHook('webmention/send', function (Event $event) {
         $data = $event->data();
         $result = self::sendWebmentionPayload($data['source'], $data['target']);
         $event->setResponse($result);
     });
 }