public static function getInfosMovie($id) { $html = dwn('http://vod.canalplay.com/films/cinema/holiday,297,308,' . $id . '.aspx'); if (strstr($html, 'Object moved to')) { $url = 'http://vod.canalplay.com' . urldecode(Utils::cut('<h2>Object moved to <a href="', '"', $html)); $html = dwn($url); } $story = Utils::cut('alt="L\'histoire" title="L\'histoire" /></h2><p>', '</p>', $html); $title = Utils::cut('var title="', '"', $html); $image = 'http://canalplay-publishing.canal-plus.com/movies/' . $id . '/pictures/' . $id . '_pivot.jpg'; $purpose = Utils::cut('title="A propos du film" /></h2><p>', '</p></div></div>', $html); $distribution = array(); $tab = explode("title=\"Voir tous les films de/avec '", $html); if (count($tab)) { for ($i = 1; $i < count($tab) - 1; $i++) { $seg = trim($tab[$i]); if (strstr($seg, "</a>") && strstr($seg, "underline")) { $person = Utils::cut('\'">', '</a>', $seg); if (!Arrays::inArray($person, $distribution)) { $distribution[] = $person; } } } } $director = null; $actors = array(); if (count($distribution)) { $director = current($distribution); $actors = array(); if (1 < count($distribution)) { for ($j = 1; $j < count($distribution); $j++) { $actors[] = $distribution[$j]; } } } $other = Utils::cut('<li style="clear:left;"><strong><br />', '</li>', $html); list($first, $second) = explode('</strong>- ', $other, 2); list($country, $year) = explode("-", $first, 2); $country = substr($country, 0, -1); $year = repl("\n", '', $year); $year = repl("\r", '', $year); $year = repl("\n", '', $year); list($duration, $dummy) = @explode("\n", $second, 2); $infos = array('title' => $title, 'story' => $story, 'image' => $image, 'purpose' => $purpose, 'director' => $director, 'actors' => $actors, 'country' => $country, 'year' => $year, 'duration' => $duration); return $infos; }
public function __call($method, $args) { if (empty($this->_datas['foreignFields'])) { $this->_datas['foreignFields'] = array(); } if (!Arrays::is($this->_datas['foreignFields'])) { $this->_datas['foreignFields'] = array($this->_datas['foreignFields']); } if (substr($method, 0, 3) == 'get') { $vars = array_values($this->fields()); $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if (Arrays::in($var, $vars) || ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields']) && 'true' != $this->_datas['foreignFields'][$var]) { return $this->_datas['foreignFields'][$var]; } $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $rs = $this->_datas['configModel']['relationship'][$var]; $field = $rs['fieldName']; $classModel = $this->_datas['classModel']; $obj = new $classModel(); if (Arrays::inArray($field, $this->_datas['keys'])) { $modelField = $rs['foreignTable']; if (isset($this->_datas['configModel']['relationship']) && ake($field, $this->_datas['configModel']['relationship'])) { $m = $this->_datas['configModel']['relationship'][$field]; if (ake("entity", $rs)) { $entity = $rs['entity']; } else { $entity = $obj->_entity; } if (null !== $m['type']) { switch ($m['type']) { case 'manyToOne': case 'oneToOne': $nObj = new self($entity, $modelField); if (ake("relationshipKeys", $rs)) { $field = $rs['relationshipKeys']; } if (!is_null($this->{$field})) { if (false === $this->_cache) { $result = $nObj->find($this->{$field}); } else { $result = $nObj->cache($this->_cache)->find($this->{$field}); $this->_cache = false; } $this->_datas['foreignFields'][$var] = $result; return $result; } break; case 'manyToMany': case 'oneToMany': $nObj = new self($entity, $modelField); $getter = $this->pk(); $fk = ake("relationshipKeys", $rs) ? $rs['relationshipKeys'][$field] : $rs['foreignKey']; if (false === $this->_cache) { $result = $nObj->where($nObj->_dbName . '.' . $nObj->_tableName . "." . $fk . " = " . $nObj->quote($this->{$getter}))->select(); } else { $result = $nObj->cache($this->_cache)->where($nObj->_dbName . '.' . $nObj->_tableName . "." . $fk . " = " . $nObj->quote($this->{$getter}))->select(); $this->_cache = false; } $this->_datas['foreignFields'][$var] = $result; return $result; break; } } } } } if (isset($this->{$var}) || is_null($this->{$var})) { return $this->{$var}; } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } return null; } elseif (substr($method, 0, 3) == 'set') { $vars = array_values($this->fields()); $value = $args[0]; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if (Arrays::in($var, $vars) || ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $this->_datas['foreignFields'][$var] = $value; $rs = $this->_datas['configModel']['relationship'][$var]; $setField = $rs['fieldName']; $getter = $rs['foreignKey']; if (Arrays::in($setField, $vars) && isset($value->{$getter})) { $this->{$setField} = $value->{$getter}; return $this; } else { return $this; } } else { $this->{$var} = $value; return $this; } } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } elseif (substr($method, 0, 3) == 'min') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::in($var, $vars)) { return $this->min($var); } } elseif (substr($method, 0, 3) == 'max') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::in($var, $vars)) { return $this->max($var); } } elseif (substr($method, 0, 3) == 'avg') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::in($var, $vars)) { return $this->avg($var); } } elseif (substr($method, 0, 3) == 'sum') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::inArray($var, $vars)) { return $this->sum($var); } } elseif (substr($method, 0, 5) == 'count') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 5))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::inArray($var, $vars)) { return $this->count($var); } } elseif (substr($method, 0, 6) == 'findBy') { $vars = array_values($this->fields()); $value = $args[0]; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 6))); $var = Inflector::lower($uncamelizeMethod); $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $rs = $this->_datas['configModel']['relationship'][$var]; $this->_datas['foreignFields'][$var] = $value; if (is_object($value) && null !== $this->_datas['configModel']['relationship'][$var]) { switch ($this->_datas['configModel']['relationship'][$var]) { case 'manyToOne': case 'oneToOne': $field = $rs['fieldName']; $q = $this->_dbName . '.' . $this->_tableName . "." . $field . " = " . $this->quote($value->{$field}); if (false === $this->_cache) { return $this->where($q)->select(); } else { return $this->cache($this->_cache)->where($q)->select(); $this->_cache = false; } case 'oneToMany': case 'manyToMany': $field = $rs['fieldName']; $pk = $this->pk(); $pkValue = $value->{$pk}; $q = $this->_dbName . '.' . $this->_tableName . "." . $pk . " = " . $this->quote($pkValue); if (false === $this->_cache) { return $this->where($q)->select(); } else { return $this->cache($this->_cache)->where($q)->select(); $this->_cache = false; } } } else { if (Arrays::in($var, $vars) || $var == 'id') { if ($var != 'id') { return $this->findBy($var, $value); } else { return $this->find($value); } } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } } elseif (substr($method, 0, 5) == 'where' && strlen($method) > 5) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 5))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $var = $this->_dbName . '.' . $this->_tableName . '.' . $var; $condition = $args[0]; $operator = isset($args[1]) ? $args[1] : 'AND'; return $this->where("{$var} {$condition}", $operator); } elseif (substr($method, 0, 7) == 'groupBy' && strlen($method) > 7) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 7))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } return $this->groupBy($var); } elseif (substr($method, 0, 7) == 'orderBy') { $direction = count($args) ? $args[0] : 'ASC'; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 7))); $var = Inflector::lower($uncamelizeMethod); return $this->order($var, $direction); } elseif (substr($method, 0, 9) == 'findOneBy') { $vars = array_values($this->fields()); $value = $args[0]; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 9))); $var = Inflector::lower($uncamelizeMethod); if (Arrays::inArray($var, $vars) || $var == 'id') { if ($var != 'id') { return $this->findBy($var, $value, true); } else { return $this->find($value); } } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } else { $vars = array_values($this->fields()); $uncamelizeMethod = Inflector::uncamelize(lcfirst($method)); $var = Inflector::lower($uncamelizeMethod); $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $rs = $this->_datas['configModel']['relationship'][$var]; $this->_datas['foreignFields'][$var] = $value; if (Arrays::in($var, $vars) || ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields'])) { return $this->_datas['foreignFields'][$var]; } if (isset($this->{$var})) { return $this->{$var}; } else { if (!method_exists($this, $method)) { $this->{$method} = $args[0]; } } } } }
protected static function option($value, $display, $selected) { if (is_array($selected)) { $selected = Arrays::inArray($value, $selected) ? 'selected' : null; } else { $selected = (string) $value == (string) $selected ? 'selected' : null; } $attributes = array('value' => View::utf8($value), 'selected' => $selected); return '<option' . Html::attributes($attributes) . '>' . View::utf8($display) . '</option>'; }
/** * Get a row of the cart by its ID * * @param string $rowId The ID of the row to fetch * @return CartCollection */ public function get($rowId) { $cart = $this->getContent(); $rows = $cart->_fields; return Arrays::inArray($rowId, $rows) ? $cart->{$rowId} : null; }
/** * Perform auto inflection on an English word. * * @param string $value * @param array $source * @param array $irregular * @return string */ protected function auto($value, $source, $irregular) { // If the word hasn't been cached, we'll check the list of words that // that are "uncountable". This should be a quick look up since we // can just hit the array directly for the value. if (Arrays::inArray(Inflector::lower($value), $this->config['uncountable'])) { return $value; } // Next, we will check the "irregular" patterns, which contain words // like "children" and "teeth" which can not be inflected using the // typically used regular expression matching approach. foreach ($irregular as $irregular => $pattern) { if (preg_match($pattern = '/' . $pattern . '$/i', $value)) { return preg_replace($pattern, $irregular, $value); } } // Finally we'll spin through the array of regular expressions and // and look for matches for the word. If we find a match we will // cache and return the inflected value for quick look up. foreach ($source as $pattern => $inflected) { if (preg_match($pattern, $value)) { return preg_replace($pattern, $inflected, $value); } } }
function varIsObject($var) { $var_ser = serialize($var); array_push($this->arrHistory, $var_ser); $this->makeTableHeader("object", "object"); if (is_object($var)) { $arrObjVars = get_object_vars($var); foreach ($arrObjVars as $key => $value) { $value = !is_object($value) && !Arrays::isArray($value) && trim($value) == "" ? "[empty string]" : $value; $this->makeTDHeader("object", $key); //check for recursion if (is_object($value) || Arrays::isArray($value)) { $var_ser = serialize($value); if (Arrays::inArray($var_ser, $this->arrHistory, TRUE)) { $value = is_object($value) ? "*RECURSION* -> \$" . get_class($value) : "*RECURSION*"; } } if (Arrays::inArray(gettype($value), $this->arrType)) { $this->checkType($value); } else { echo $value; } echo $this->closeTDRow(); } $arrObjMethods = get_class_methods(get_class($var)); foreach ($arrObjMethods as $key => $value) { $this->makeTDHeader("object", $value); echo "[function]" . $this->closeTDRow(); } } else { echo "<tr><td>" . $this->error("object") . $this->closeTDRow(); } array_pop($this->arrHistory); echo "</table><hr class=thinDebugHr />"; }