/** * method: getHandlerData * * todo: write documentation */ protected function getHandlerData($plugin, $default, $key) { $plugin = self::pluginToName($plugin); if (!$this->handler && count($this->source[self::HD])) { $this->processHandler(); } if (!$this->handler) { // TODO: move into the logging system intead of here error_log("** " . __METHOD__ . " ** " . Amslib_Debug::pdump(true, $this->handler) . " was invalid"); return NULL; } return isset($this->handler[$plugin]) && isset($this->handler[$plugin][$key]) ? Amslib_Array::valid($this->handler[$plugin][$key]) : $default; }
public static function execCallback($key, $callback, $object = NULL) { if (!self::$qp || !is_callable($callback)) { print "FAILED CALLBACK = " . Amslib_Debug::pdump(true, $callback); return; } try { $results = self::$qp->branch()->find($key); } catch (Exception $e) { Amslib_Debug::log("QueryPath Exception", $e->getMessage); } foreach ($results as $r) { $r = Amslib_QueryPath::toArray($r); call_user_func($callback, $r["tag"], $r, $object); } }
/** * method: serviceExportRouterDEBUG * * todo: write documentation */ public static function serviceExportRouterDEBUG($service, $source) { die(Amslib_Debug::pdump(true, self::exportRouterShared())); }
/** * method: setValue * * todo: write documentation */ public function setValue($key, $value) { switch ($key) { case "value": $this->data[$key] = Amslib_Array::valid($this->data[$key]); $this->data[$key] = array_merge($this->data[$key], $value); break; case "translator": $this->data[$key][$value["name"]] = $value; break; case "model": $this->data[$key] = $value; break; case "image": $this->data[$key][$value["id"]] = $value["value"]; break; case "view": $this->data[$key][$value["id"]] = $value; break; default: die(__METHOD__ . ": UNCONVERTED CODE: " . Amslib_Debug::pdump(true, $key, $value)); // THIS IS THE OLD UNCONVERTED CODE // This is important, because otherwise values imported/exported through transfer() will not execute in process() unset($value["import"], $value["export"]); if ($key == "value") { // Search and update any existing values $this->data[$key] = Amslib_Array::valid($this->data[$key]); foreach ($this->data[$key] as &$v) { if ($v["name"] == $value["name"] && !isset($v["export"]) && !isset($v["import"])) { $v["value"] = $value["value"]; return; } } // The value didnt already exist, so we must create it $this->data[$key][] = $value; } else { if (is_string($key)) { $this->data[$key] = $value; } else { $this->data[$key[0]][$key[1]] = $value; } } break; } }
/** * method: getRandomCode * * todo: write documentation * I wonder if this is true, or it's bullshit? could ask someone to verify whether they think it's safe or not * TODO: I was told to replace this with a call to crypt() * TODO: maybe this should move to the Amslib_String object, since it's a string function? * NOTE: actually it's more a utility function, so I'm not sure where to put it, or just leave it here */ public static function getRandomCode($input = NULL) { $args = func_get_args(); $salt = "34v87tetnseoyrtq" . "p3498534978qnxp3" . "895vbpq34985ox4r" . "gwefijoiwy4cbo9t"; $input = $input !== NULL ? Amslib_Debug::pdump(true, $args) : ""; return sha1(implode("__", array($salt, $input, microtime(true), mt_rand(0, 2138713), $salt))); }
public static function deleteFile($filename) { if (!$filename || !is_string($filename) || !file_exists($filename)) { die("filename invalid" . Amslib_Debug::pdump(true, $filename)); return false; } $status = false; ob_start(); $status = unlink($filename); $output = ob_get_clean(); // if the output was not empty, something bad happened, like a warning or error // when this happens, sometimes with file operations, it can break json, or website output // so I use an output buffer to grab all the output without it going to the user in some way // then once I have it, I can do something with it, like output it only to the error log, etc, etc. if (strlen($output)) { $status = false; Amslib_Debug::log("Error or warning executing file operations", $output); } return $status; }
/** * method: translateExtended * * todo: write documentation */ public function translateExtended($n, $i, $l = NULL) { $v = parent::translateExtended($n, $i, $l); if ($v == $n && is_numeric($i)) { $i = intval($i); $l = $this->getIdLang($l); $n = $this->database->escape($n); $r = $this->database->select("value from {$this->table} where name='{$n}' and id_object={$i} and id_lang='{$l}'"); $v = ""; if (is_array($r)) { if (count($r) > 1) { Amslib_Keystore::add(__METHOD__, "Multiple conflicting translations for key({$n}),id_object({$i}) and language({$l})"); } else { if (isset($r[0]["value"])) { $v = trim($r[0]["value"]); } } parent::learnExtended($n, $i, $v, $l); } else { $v = $n; } } else { die("FAIL 1: " . Amslib_Debug::pdump(true, $n, $i, $l, $v)); } return $v; }
/** * method: getArray * * todo: write documentation */ public function getArray($node = false, $attributes = false) { if (!$node) { if (!$this->queryResults) { return NULL; } $node = $this->queryResults; } $data = array(); foreach ($node as $c) { print __METHOD__ . ": nodeType = " . $c->nodeType . ", nodeName = " . $c->nodeName . "<br/>"; $data[$c->nodeName] = $c->hasChildNodes() && $c->nodeType == XML_ELEMENT_NODE ? $this->getArray($c, $attributes) : $c->nodeValue; if ($attributes) { $data[$c->nodeName]["__attr"] = $this->getArray($c->attributes); } } print __METHOD__ . ": data = " . Amslib_Debug::pdump(true, $data); return $data; }
public static function processExport() { foreach (self::$export as $key => $list) { foreach ($list as $name => $value) { $src = is_string($value["src"]) ? self::getPlugin($value["src"]) : $value["src"]; $dst = is_string($value["dst"]) ? self::getPlugin($value["dst"]) : $value["dst"]; $data = false; if (!$src || !$dst) { $sname = is_object($src) ? $src->getName() : "searched: {$value["src"]}"; $dname = is_object($dst) ? $dst->getName() : "searched: {$value["dst"]}"; Amslib_Debug::log("plugin list", Amslib_Plugin_Manager::listPlugin()); Amslib_Debug::log("plugin invalid", intval(is_object($src)) . ", " . intval(is_object($dst)), $sname, $dname, Amslib_Router::getPath()); continue; } switch ($value["key"]) { case "stylesheet": case "javascript": case "font": die("[DIE]EXPORT[{$key}] => " . Amslib_Debug::pdump(true, array($src->getName(), $dst->getName(), $value["key"], $value["val"]))); break; case "view": case "value": // NOTE: if I could change getValue to this, I could refactor all of these branches // together maybe into something very generic // NOTE: the new import/export system works slightly differently from the old one, // we push directly into the import/export queues the information that we // want to pass and it doesn't enter the host plugin, this way, we can skip // a lot of bullshit with regard to internal data and data which is destined // for other plugins, the getValue method should in this case, circumstantially // create objects or just parse the data out of the structure, but it's not // about "getting" the value from the pluing, the $value variable already has // it and in many cases we don't need to do anything except return a particular // key depending on the stucture or type of that data, but in the case of // translators, objects or models, we need to ask the host plugin to create // the object on our behalf and then return and use it, because it might be // that the host plugin is the only plugin which has the correct functionality // necessary to create that object, in these cases getValue will do more than // just return a particular key, but will actually process the input data into // an "output data" to use //$data = $src->getValue($value); $dst->setValue($value["key"], $value["val"]); break; case "service": //Amslib_FirePHP::output("export",$item); // Hmmm, I need a test case cause otherwise I won't know if this works break; case "image": $dst->setValue($value["key"], $value["val"]); break; // We do nothing special with these entries, we simply pass them // We do nothing special with these entries, we simply pass them case "model": case "translator": default: // NOTE: I should change $value["key"] here to $value and make "key" something getValue uses internally $data = $src->getValue($value["key"]); $dst->setValue($value["key"], $data); break; } } } self::$export = NULL; }
/** * method: getHandlerData * * todo: write documentation */ public function getHandlerData($plugin, $default, $name = NULL) { if ($this->handler === false && $this->countHandler()) { $this->processHandler(); } if ($this->handler === false) { // TODO: move into the logging system instead of here Amslib_Debug::log("INVALID HANDLER", Amslib_Debug::pdump(true, $this->handler)); return NULL; } $keys = array(self::HD, $this->handler); if ($plugin !== NULL) { $keys[] = self::pluginToName($plugin); } if ($name !== NULL) { $keys[] = $name; } return $this->getKey($keys, $default); }