public function handler_conversationController_formatPostForTemplate($sender, &$formatted, $post, $conversation) { if ($post["deleteTime"]) { return; } $isAnswer = $conversation["answered"] == $post["postId"]; $isFirstPost = $post["memberId"] == $conversation["startMemberId"] && $post["time"] == $conversation["startTime"]; $isAuthor = $conversation["startMemberId"] == ET::$session->userId; if (!$isFirstPost && ($isAuthor || $conversation["canModerate"]) && !$isAnswer) { $label = $conversation["startMemberId"] == ET::$session->userId ? "This answers my question" : "This answers the question"; addToArray($formatted["footer"], "<a href='" . URL("conversation/answer/" . $post["postId"] . "?token=" . ET::$session->token) . "' class='markAsAnswer'><i class='icon-ok'></i> " . T($label) . "</a>", 0); } // If this post is the answer... if ($isAnswer) { $formatted["class"][] = "answer"; addToArray($formatted["info"], "<span class='label label-answered'><i class='icon-ok-sign'></i> " . T("Answer") . "</span>", 100); } // If this is the first post in the conversation and there is an answer... if ($conversation["answered"] and $isFirstPost) { // Get the answer post. $answer = ET::postModel()->getById($conversation["answered"]); $view = $sender->getViewContents("answers/answer", array("answer" => $answer, "conversation" => $conversation)); $formatted["body"] = $formatted["body"] . $view; } }
public function handler_conversationController_formatPostForTemplate($sender, &$formatted, $post, $conversation) { if ($post["deleteMemberId"]) { return; } if ($conversation["startMemberId"] == ET::$session->userId or $conversation["canModerate"]) { addToArray($formatted["controls"], "<a href='" . URL("conversation/answer/" . $post["postId"] . "?token=" . ET::$session->token) . "' title='" . T("This post answered my question") . "' class='control-answer'><i class='icon-ok-sign'></i></a>"); } // If this post is the answer... if ($conversation["answered"] == $post["postId"]) { addToArray($formatted["info"], "<span class='label label-answered'><i class='icon-ok-sign'></i> " . T("Answer") . "</span>", 100); } // If this is the first post in the conversation and there is an answer... if ($conversation["answered"] and $post["memberId"] == $conversation["startMemberId"] and $post["time"] == $conversation["startTime"]) { // Get the answer post. $answer = ET::postModel()->getById($conversation["answered"]); $view = $sender->getViewContents("answers/answer", array("answer" => $answer, "conversation" => $conversation)); // Add this before the "likes" plugin. Bit hacky, but there's no way to prioritize event handlers in esoTalk :( $pos = strpos($formatted["body"], "<p class='likes"); if (!$pos) { $pos = strlen($formatted["body"]); } $formatted["body"] = substr_replace($formatted["body"], $view, $pos, 0); } }
/** * Toggle a plugin. * * @param string $plugin The name of the plugin. * @return void */ public function action_toggle($plugin = "") { if (!$this->validateToken()) { return; } // Get the plugin. $plugins = $this->getPlugins(); if (!$plugin or !array_key_exists($plugin, $plugins)) { return; } // Get the list of currently enabled plugins. $enabledPlugins = C("esoTalk.enabledPlugins"); // If the plugin is currently enabled, take it out of the loaded plugins array. $k = array_search($plugin, $enabledPlugins); if ($k !== false) { unset($enabledPlugins[$k]); // Call the plugin's disable function. ET::$plugins[$plugin]->disable(); } else { if (isset($plugins[$plugin]["info"]["priority"])) { addToArray($enabledPlugins, $plugin, $plugins[$plugin]["info"]["priority"]); } else { $enabledPlugins[] = $plugin; } // Check the plugin's dependencies. $dependencyFailure = false; if (isset(ET::$pluginInfo[$plugin]["dependencies"]) and is_array(ET::$pluginInfo[$plugin]["dependencies"])) { foreach (ET::$pluginInfo[$plugin]["dependencies"] as $name => $minVersion) { // Check the dependency is met, whether it be a plugin or a version of esoTalk. if ($name == "esoTalk" and !version_compare(ESOTALK_VERSION, $minVersion, ">=") or $name != "esoTalk" and (!isset(ET::$plugins[$name]) or !version_compare(ET::$pluginInfo[$name], $minVersion, ">="))) { $this->message(sprintf(T("message.pluginDependencyNotMet"), $name, $minVersion), "warning"); $dependencyFailure = true; } } } if ($dependencyFailure) { $this->redirect(URL("admin/plugins")); return; } // Set up an instance of the plugin so we can call its setup function. if (file_exists($file = PATH_PLUGINS . "/" . sanitizeFileName($plugin) . "/plugin.php")) { include_once $file; } $className = "ETPlugin_{$plugin}"; if (class_exists($className)) { $pluginObject = new $className("addons/plugins/" . $plugin); // Call the plugin's setup function. If the setup failed, show a message. if (($msg = $pluginObject->setup(C("{$plugin}.version"))) !== true) { $this->message(sprintf(T("message.pluginCannotBeEnabled"), $plugin, $msg), "warning"); $this->redirect(URL("admin/plugins")); return; } ET::writeConfig(array("{$plugin}.version" => ET::$pluginInfo[$plugin]["version"])); } } // Write to the config file. ET::writeConfig(array("esoTalk.enabledPlugins" => $enabledPlugins)); $this->redirect(URL("admin/plugins")); }
public function handler_conversationController_formatPostForTemplate($sender, &$formatted, $post, $conversation) { if ($post["deleteMemberId"]) { return; } // Lets check if the Likes plugin is active, // if so we need to output the signature HTML a bit different. if (in_array("Likes", C("esoTalk.enabledPlugins"))) { $signature = ET::formatter()->init($post["preferences"]["signature"])->format()->get(); if ($signature != "") { addToArray($formatted["footer"], "<div class='signature'>" . substr($signature, 0, C("plugin.Signature.characters")) . "</div>", 0); } } else { $signature = $post["preferences"]["signature"]; if ($signature != "") { addToArray($formatted["footer"], "<p class='signature-no-likes'>" . substr($signature, 0, C("plugin.Signature.characters")) . "</p>", 0); } } }
protected function appendEditAttachments($sender, &$formatted, $attachments) { $view = $sender->getViewContents("attachments/edit", array("attachments" => $attachments)); addToArray($formatted["footer"], $view, 0); }
function addToForm($fieldset, $field, $position = false) { return addToArray($this->form[$fieldset], $field, $position); }
/** The location is the user inputted address or station object. However, it may not be the best place to start. There are several different scenarios that have obvious path choices. If it is a station and is the last station of the line, the algorithm doesn't need to determine options until it hits a station with multiple lines. If it isn't the last station, it may be one where either there is only one line or has multiple lines that have the same destination stations. If it is an address and the stations are all on the same line or group of lines, then the station closest to the destination should be used. */ function findStartStations($location, $destination) { $paths = array(); $debug = true; $factor = 1.2; outputDebug("findStartStations (" . $location->toString() . ", " . $destination->toString() . ")", $debug); $originalBox = new Box($location->point, $destination->point); #outputDebug("original box = " . $originalBox->getArea(), $debug); if ($location instanceof Station2) { $visitedStations = array(); foreach ($location->getLines() as $line) { foreach ($line->getConnections() as $connection) { // ignore already visited stations $cid = $connection->id; outputDebug("Looking at next connection " . $line->getName() . "-" . $cid, $debug); if (in_array($cid, $visitedStations)) { outputDebug("visited. skipping.", $debug); continue; } $nextStation = retrieveStation($cid); $visitedStations[] = $cid; // create a new path with this connection $segment = new Segment($location, $nextStation, $location->getOverlapLines($nextStation), $connection->duration, $connection->type); $visited = array(); if ($location->isJunction()) { $visited[] = $location; } if ($nextStation->isJunction()) { #outputDebug("nextStation is a junction.", $debug); $visited[] = $nextStation; #outputDebug("segment = " . $segment->toString(), $debug); $path = new Path($segment, $visited, $destination); $originalArea = $originalBox->getArea(); $pathArea = $path->getBox()->getArea(); outputDebug("findStartStations.compareArea = " . $pathArea . " > " . $originalArea, $debug); if ($originalBox->getArea() * $factor > $path->getBox()->getArea()) { $metaPath = new MetaPath("start", $path); outputDebug("creating path: " . $metaPath->toString(), $debug); $paths = addToArray($paths, $metaPath); } else { #outputDebug("path (" . $path->getBox()->getArea() . ") is greater than originalBox (" . $originalBox->getArea() . ")", $debug); } continue; } outputDebug("nextStation is NOT a junction.", $debug); // here we know that the nextStation is not a junction. $path = new Path($segment, $visited, $destination); if ($originalBox->getArea() * $factor < $path->getBox()->getArea()) { outputDebug("path (" . $path->getBox()->getArea() . ") is greater than originalBox (" . $originalBox->getArea() . ")", $debug); continue; } // extend the path until we find a junction point $metaPath = expandPath($path); if ($metaPath != null) { outputDebug("creating path: " . $metaPath->toString(), $debug); $paths = addToArray($paths, $metaPath); } } } } outputDebug("FINISHED findStartStations (" . $location->toString() . ", " . $destination->toString() . ")", $debug); return $paths; }
function addSection($section, $position = false) { addToArray($this->sections, $section, $position); }
{ global $arrTheArray; return $arrTheArray; } function addToArray(&$arr, $strToAdd) { $arr[] = $strToAdd; } addToArray(getArray(), "xx1"); $a = getArray(); addToArray($a, "xx2"); $b =& $arrTheArray; addToArray($b, "xx3"); addToArray(getArray(), "xx4"); $a = getArray(); addToArray($a, "xx5"); echo "arrTheArray = " . print_r($arrTheArray, 1); /****/ class RefTest { protected $arr; function Add($strToAdd) { $this->addToArray($this->getArray(), $strToAdd); } function &getArray() { if (!$this->arr) { $this->arr = array(); } return $this->arr;
function processShapeCoords($agency) { $shape_filename = $agency . "/shapes.txt"; echo "processing {$shape_filename}\n"; $shapeid_to_shapecoords = array(); if (($shapes = fopen($shape_filename, "r")) === FALSE) { die("error opening {$shape_filename}"); } $num = 1; $SHAPEID_INDEX = null; $LAT_INDEX = null; $LNG_INDEX = null; $SEQ_INDEX = null; while (($row = fgetcsv($shapes, 1000, ",")) !== FALSE) { if ($num == 1) { $SHAPEID_INDEX = array_search('shape_id', $row); $LAT_INDEX = array_search('shape_pt_lat', $row); $LNG_INDEX = array_search('shape_pt_lon', $row); $SEQ_INDEX = array_search('shape_pt_sequence', $row); echo "DEBUG: shape_id index = {$SHAPEID_INDEX}, shape_pt_lat index = {$LAT_INDEX}, " . "shape_pt_lon index = {$LNG_INDEX}, shape_pt_sequence index = {$SEQ_INDEX}\n"; $num++; continue; } $shapeid = $row[$SHAPEID_INDEX]; $lat = floatval($row[$LAT_INDEX]); $lng = floatval($row[$LNG_INDEX]); $seq = intval($row[$SEQ_INDEX]); $point = new stdClass(); $point->lat = $lat; $point->lng = $lng; $point->seq = $seq; addToArray($shapeid_to_shapecoords, $shapeid, $point); } fclose($shapes); echo "Sorting the shape data...\n"; foreach ($shapeid_to_shapecoords as $shapeid => $points_arr) { usort($points_arr, 'sortBySeq'); } echo "Done.\n"; return $shapeid_to_shapecoords; }
$stmt = $mysqli->prepare("SELECT * FROM apk_silja ORDER BY apk DESC LIMIT ?,50"); $stmt->bind_param("i", $numberOfRow); $array = addToArray($stmt); } else { if ($stmt = $mysqli->prepare("SELECT * FROM apk_data WHERE department = ? ORDER BY apk DESC LIMIT ?,50")) { $stmt->bind_param("si", $department, $numberOfRow); $array = addToArray($stmt); } } } } } else { //Hämtar top 50 värden från tabellen apk2 $stmt = $mysqli->prepare("SELECT * FROM apk_data ORDER BY apk DESC LIMIT ?, 50"); $stmt->bind_param("i", $numberOfRow); $array = addToArray($stmt); } //Stänger kopplingen till databasen mysqli_close($mysqli); //Skickar arrayen som json echo json_encode($array); function addToArray($stmt) { $array = array(); if ($stmt->execute()) { $stmt->bind_result($id, $artikelid, $name, $name2, $department, $volym, $price, $alcoholByVolym, $apk, $status); while ($row = $stmt->fetch()) { $temp = array(utf8_encode($id), utf8_encode($artikelid), utf8_encode($name), utf8_encode($name2), utf8_encode($department), utf8_encode($volym), utf8_encode($price), utf8_encode($alcoholByVolym), utf8_encode($apk), utf8_encode($status)); array_push($array, json_encode($temp)); } }
addToArray('password', 'För kort lösenord (minst 6 tecken)'); } } if (strlen($password) > 25) { addToArray('password', 'För långt lösenord'); } if (strlen($password) >= 6 && strlen($password) <= 25 && strlen($password_repeat) >= 6 && strlen($password_repeat) <= 25 && $password_repeat != $password) { addToArray('password_repeat', 'Lösenorden matchar inte varandra'); } if (strlen($user) > 2 && strlen($user) < 20) { $user_exists = sqlSelect("SELECT username, email FROM (SELECT username FROM users WHERE type = 1 AND username = '******') A, (SELECT email FROM users WHERE email = '{$email}') B;"); if ($user_exists) { if ($user_exists[0]['username']) { addToArray('user', 'Användarnamnet är upptaget'); } if ($user_exists[0]['email']) { addToArray('email', 'E-mailadressen är upptagen'); } } } if (count($errors['type']) > 0) { echo json_encode($errors); die; } else { $password = password_hash($password, PASSWORD_DEFAULT); $user = sqlAction("INSERT INTO users (type, facebook_id, username, password, email, registration_date, profile_img, personal_text, reset_password_key) VALUES (1, null, '{$user}', '{$password}', '{$email}', now(), null, null, null);", true); if ($user) { echo json_encode(array('success' => true, 'user_id' => $user)); } } }
function addCSS($styleSheet, $media = false) { addToArray($this->styleSheets, array("href" => $styleSheet, "media" => $media)); }