/** * Checks the currently authenticated user's permissions for the specified * permission. Returns a boolean value indicating if the action is * permitted. * * @param mixed $Permission The permission (or array of permissions) to check. * @param int $JunctionID The JunctionID associated with $Permission (ie. A discussion category identifier). * @param bool $FullMatch If $Permission is an array, $FullMatch indicates if all permissions specified are required. If false, the user only needs one of the specified permissions. * @param string $JunctionTable The name of the junction table for a junction permission. * @param in $JunctionID The ID of the junction permission. * * @return boolean */ public function checkPermission($Permission, $FullMatch = true, $JunctionTable = '', $JunctionID = '') { if (is_object($this->User)) { if ($this->User->Banned || GetValue('Deleted', $this->User)) { return false; } elseif ($this->User->Admin) { return true; } } // Allow wildcard permission checks (e.g. 'any' Category) if ($JunctionID == 'any') { $JunctionID = ''; } $Permissions = $this->getPermissions(); if ($JunctionTable && !c('Garden.Permissions.Disabled.' . $JunctionTable)) { // Junction permission ($Permissions[PermissionName] = array(JunctionIDs)) if (is_array($Permission)) { $Pass = false; foreach ($Permission as $PermissionName) { if ($this->checkPermission($PermissionName, false, $JunctionTable, $JunctionID)) { if (!$FullMatch) { return true; } $Pass = true; } else { if ($FullMatch) { return false; } } } return $Pass; } else { if ($JunctionID !== '') { $Result = array_key_exists($Permission, $Permissions) && is_array($Permissions[$Permission]) && in_array($JunctionID, $Permissions[$Permission]); } else { $Result = array_key_exists($Permission, $Permissions) && is_array($Permissions[$Permission]) && count($Permissions[$Permission]); } return $Result; } } else { // Non-junction permission ($Permissions = array(PermissionNames)) if (is_array($Permission)) { return arrayInArray($Permission, $Permissions, $FullMatch); } else { return in_array($Permission, $Permissions) || array_key_exists($Permission, $Permissions); } } }
function extras() { function arrayInArray($needles, $haystack) { foreach ($needles as $needle) { if (in_array($needle, $haystack)) { return true; } } return false; } $r = ''; if (arrayInArray(array('temp', 'temperatur', 'varmt', 'kallt', 'väder', 'klimat'), $this->words)) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.vackertvader.se/weather/widgetv3?geonameid=2665577&size=160v3x&days=1"); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $text = curl_exec($ch); curl_close($ch); // Get temp $start = strpos($text, 'class="cel') + 12; $end = strpos($text, '°') - $start + 2; $temp = substr($text, $start, $end); // Get icon $start = strpos($text, 'src') + 5; $end = strpos($text, '.png') - $start + 4; $icon = 'http://www.vackertvader.se' . substr($text, $start, $end); $r .= '<li><a href="http://www.vackertvader.se/link%C3%B6ping-valla"><img src="' . $icon . '" height="32" width="32"><span class="text"><h2>' . $temp . '</h2><p>Väder - Linköping Valla</p></span></a></li>'; /* curl_setopt($ch, CURLOPT_URL, "http://termo.frryd.se/data/temp.txt"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $temp = curl_exec($ch); $temp = substr($temp, 0, strlen($temp)-2); curl_close($ch); $r .= '<li><a href="http://termo.frryd.se/">'.icon('large/knewstuff-32').'<span class="text"><h2>'.$temp.'°C</h2><p>Temperartur - Linköping</p></span></a></li>'; */ } else { if (arrayInArray(array('meningen', 'livet', 'universum', 'allting'), $this->words)) { $r .= '<li><a href="http://en.wikipedia.org/wiki/Meaning_of_life">' . icon('large/knewstuff-32') . '<span class="text"><h2>42</h2><p>Svaret på "den yttersta frågan om meningen med livet, universium och allting" enligt Douglas Adams</p></span></a></li>'; } } return $r; }