本文整理汇总了PHP中classify函数的典型用法代码示例。如果您正苦于以下问题:PHP classify函数的具体用法?PHP classify怎么用?PHP classify使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了classify函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findCatagory
function findCatagory($tweet)
{
$result = classify($tweet);
print_r($result);
if ($result["positive"] > $result["negative"]) {
return "positive";
} else {
return "negative";
}
}
示例2: findCatagory
function findCatagory($tweet_id, $tweet)
{
global $positive, $negative;
$result = classify($tweet);
//print_r($result);
//if($result["negative"]==0)
//print($result["positive"]." / ".$result["negative"]);
$score = $result["positive"] / $result["negative"];
if ($score > 1) {
$positive[$tweet_id] = $score;
} else {
$negative[$tweet_id] = $score;
}
}
示例3: add_model
function add_model($name, $table = '', array $columns = array(), array $indexes = array(), $parent = 'database', $connection = 'default')
{
static $set = array('database' => '\\Servant\\Mapper\\Database', 'mongodb' => '\\Servant\\Mapper\\MongoDB');
$table = $table ?: underscore($name);
$ucname = classify($name);
$fields['static columns'] = $columns;
$fields['static indexes'] = $indexes;
$connect = compact('table', 'connection');
$out_file = path(APP_PATH, 'app', 'models', "{$name}.php");
isset($set[$parent]) && ($parent = $set[$parent]);
add_class($out_file, $ucname, $parent, array(), $fields, $connect);
}
示例4: send_email_notice
function send_email_notice(&$model, &$rec)
{
global $db;
global $request;
if (!(get_profile_id() && $request->resource == 'groups')) {
return;
}
// get data modesl for 3 tables
$Entry =& $db->get_table('entries');
$Group =& $db->get_table('groups');
$Person =& $db->get_table('people');
// load the first 20 records from the groups table
$Group->find();
// keep a list of people we have notified
$sent_to = array();
// get the name of the table from the data model reference we received
$notify_table = $model->table;
// get the primary key value of the record reference we received
$notify_id = $rec->id;
// if the table that was modified is a metadata table (comments, reviews)
// notify about the "target" table being modified
if (array_key_exists('target_id', $model->field_array)) {
$e = $Entry->find($rec->attributes['target_id']);
if ($e) {
$notify_table = $e->resource;
$notify_id = $e->record_id;
}
}
// get the data model we are notifying about
$datamodel =& $db->get_table($notify_table);
// get the profile data for the current user
$profile = owner_of($rec);
// loop over each group
while ($g = $Group->MoveNext()) {
if (in_array($g->name, array('administrators', 'everyone', 'members'))) {
continue;
}
// if the GROUP has READ or CREATE then do notify its members
if ($rec->id && (in_array($g->name, $datamodel->access_list['read']['id']) || in_array($g->name, $datamodel->access_list['create'][$notify_table]))) {
// loop over each member in the group
while ($m = $g->NextChild('memberships')) {
// get a person activerecord object for the member's person_id
$p = $Person->find($m->person_id);
if ($p) {
$action = $request->action;
$notify = "notify_" . $action;
// get an identities activerecord object for the person's first identity
// this is an example of traversing the result dataset without re-querying
$i = $p->FirstChild('identities');
// if we haven't already sent this person a message
if (isset($m->{$notify}) && $m->{$notify} && is_email($i->email_value) && !in_array($i->email_value, $sent_to)) {
// a token may be set to allow the notify-ee to "EXPRESS" register as a new site user
// it fills in some of the "new user" form info such as e-mail address for them
if (isset($i->token) && strlen($i->token) > 0) {
$addr = $request->url_for(array('resource' => $notify_table, 'id' => $notify_id, 'ident' => $i->token));
} else {
$addr = $request->url_for(array('resource' => $notify_table, 'id' => $notify_id));
}
// this is the HTML content of the e-mail
$html = '
<!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.0 Transitional//EN\\">
<html>
<body>
<br />
<b><u><i>Click on this link:</i></u></b><br />
<br />
<font color="red"><a href="' . $addr . '">' . $addr . '</a></font>
</body>
</html>';
// oh wait, we are not going to send the HTML it is just wasting space for now
// comment this out to try the HTML yourself
$html = false;
// this is the body of the e-mail if ($html == false)
$text = 'Content was updated at the following location:' . "\r\n\r\n" . $addr . "\r\n\r\n";
// change the e-mail subject line depending on what action took place
if ($action == 'post') {
$actionmessage = " created a new ";
} elseif ($action == 'put') {
$actionmessage = " updated a ";
} elseif ($action == 'delete') {
$actionmessage = " deleted a ";
}
// set the e-mail subject to the current user's first name
// classify() converts a table name "nerds" to "Nerd"
// the converse is tableize()
$subject = $profile->given_name . $actionmessage . classify($request->resource);
// this sends e-mail using the xpertmailer package
// the environment() function reads a value from the config.yml file
send_email($i->email_value, $subject, $text, environment('email_from'), environment('email_name'), $html);
// add a new entry to the list of successful (more like woeful) recipients
$sent_to[] = $i->email_value;
}
}
}
}
}
}
示例5: handle_posted_file
function handle_posted_file($filename = "", $att, $profile)
{
global $db, $request, $response;
$response->set_var('profile', $profile);
load_apps();
if (isset($_FILES['media']['tmp_name'])) {
$table = 'uploads';
} else {
$table = 'posts';
}
$modelvar = classify($table);
$_FILES = array(strtolower($modelvar) => array('name' => array('attachment' => $filename), 'tmp_name' => array('attachment' => $att)));
$Post =& $db->model('Post');
$Upload =& $db->model('Upload');
$field = 'attachment';
$request->set_param('resource', $table);
$request->set_param(array(strtolower(classify($table)), $field), $att);
trigger_before('insert_from_post', ${$modelvar}, $request);
$content_type = 'text/html';
$rec = ${$modelvar}->base();
$content_type = type_of($filename);
$rec->set_value('profile_id', get_profile_id());
$rec->set_value('parent_id', 0);
if (isset($request->params['message'])) {
$rec->set_value('title', $request->params['message']);
} else {
$rec->set_value('title', '');
}
if ($table == 'uploads') {
$rec->set_value('tmp_name', 'new');
}
$upload_types = environment('upload_types');
if (!$upload_types) {
$upload_types = array('jpg', 'jpeg', 'png', 'gif');
}
$ext = extension_for(type_of($filename));
if (!in_array($ext, $upload_types)) {
trigger_error('Sorry, this site only allows the following file types: ' . implode(',', $upload_types), E_USER_ERROR);
}
$rec->set_value($field, $att);
$rec->save_changes();
$tmp = $att;
if (is_jpg($tmp)) {
$thumbsize = environment('max_pixels');
$Thumbnail =& $db->model('Thumbnail');
$t = $Thumbnail->base();
$newthumb = tempnam("/tmp", "new" . $rec->id . ".jpg");
resize_jpeg($tmp, $newthumb, $thumbsize);
$t->set_value('target_id', $atomentry->id);
$t->save_changes();
update_uploadsfile('thumbnails', $t->id, $newthumb);
$t->set_etag();
}
$atomentry = ${$modelvar}->set_metadata($rec, $content_type, $table, 'id');
${$modelvar}->set_categories($rec, $request, $atomentry);
$url = $request->url_for(array('resource' => $table, 'id' => $rec->id));
// $title = substr($rec->title,0,140);
// $over = ((strlen($title) + strlen($url) + 1) - 140);
// if ($over > 0)
// $rec->set_value('title',substr($title,0,-$over)." ".$url);
// else
// $rec->set_value('title',$title." ".$url);
// $rec->save_changes();
trigger_after('insert_from_post', ${$modelvar}, $rec);
return true;
}
示例6: array_shift
<?php
$name = array_shift($params);
if (!$name or is_numeric($name) or strpos($name, ':') !== FALSE) {
error("\n Missing model name\n");
} else {
$name = singular($name);
$model_file = path(APP_PATH, 'app', 'models', "{$name}.php");
$model_class = arg('c class') ?: classify($name);
if (!is_file($model_file) && !arg('c class')) {
error("\n Missing '{$name}' model\n");
} else {
is_file($model_file) && (require $model_file);
$fail = FALSE;
$fields = array();
$columns = $model_class::columns();
if (!empty($params)) {
foreach ($params as $key) {
@(list($key, $type) = explode(':', $key));
$type = $type ?: $columns[$key]['type'];
if (!isset($columns[$key])) {
$fail = TRUE;
error("\n Unknown '{$key}' field\n");
} elseif (!($test = field_for($type, $key))) {
$fail = TRUE;
error("\n Unknown '{$type}' type on '{$key}' field\n");
} else {
$fields[$key] = $test;
}
}
} else {
示例7: load
public function load(Model $model)
{
$inflector = Inflector::instance();
$class_name = $this->class_name;
$table = $this->get_table();
$this->set_keys(get_class($model));
if ($this->through) {
$table_name = $table->get_fully_qualified_table_name();
//verify through is a belongs_to or has_many for access of keys
if (!($through_relationship = $table->get_relationship($this->through))) {
throw new HasManyThroughAssociationException("Could not find the association {$this->through} in model " . get_class($model));
}
if (!$through_relationship instanceof HasMany && !$through_relationship instanceof BelongsTo) {
throw new HasManyThroughAssociationException('has_many through can only use a belongs_to or has_many association');
}
$through_table = Table::load(classify($this->through, true));
$through_table_name = $through_table->get_fully_qualified_table_name();
$through_pk = $this->keyify($class_name);
$this->options['joins'] = $this->construct_inner_join_sql($through_table, true);
foreach ($this->foreign_key as $index => &$key) {
$key = "{$through_table_name}.{$key}";
}
}
if (!($conditions = $this->create_conditions_from_keys($model, $this->foreign_key, $this->primary_key))) {
return null;
}
$options = $this->unset_non_finder_options($this->options);
$options['conditions'] = $conditions;
return $class_name::find($this->poly_relationship ? 'all' : 'first', $options);
}
示例8: execute
public static function execute($controller, $action = 'index', $cache = -1)
{
$out = \Sauce\Base::$response;
$hash = md5(URI . '?' . server('QUERY_STRING') . '#' . session_id());
\Sauce\Logger::debug("Executing {$controller}#{$action}");
if ($cache > 0 && ($test = \Cashier\Base::fetch($hash))) {
@(list($out->status, $out->headers, $out->response) = $test);
} else {
$controller_path = path(APP_PATH, 'app', 'controllers');
$controller_base = path($controller_path, 'base.php');
$controller_file = path($controller_path, "{$controller}.php");
if (!is_file($controller_file)) {
throw new \Exception("Missing '{$controller_file}' file");
}
is_file($controller_base) && (require $controller_base);
require $controller_file;
$base_name = classify(basename(APP_PATH));
$class_name = classify($controller);
if (!class_exists($class_name)) {
throw new \Exception("Missing '{$class_name}' class");
}
$app = new $class_name();
$klass = new \ReflectionClass($app);
$type = params('format');
$handle = new \Postman\Handle($app, $type);
$methods = $klass->getMethods(\ReflectionMethod::IS_STATIC);
foreach ($methods as $callback) {
$fn = $callback->getName();
if (substr($fn, 0, 3) === 'as_') {
$handle->register(substr($fn, 3), function () use($class_name, $fn) {
return call_user_func_array("{$class_name}::{$fn}", func_get_args());
});
}
}
$test = $handle->exists($action) ? $handle->execute($action) : array();
$vars = (array) $class_name::$view;
$params = $klass->getStaticProperties();
if ($type) {
if (!in_array($type, $params['responds_to'])) {
throw new \Exception("Unknown response for '{$type}' type");
}
\Sauce\Logger::debug("Using response for '{$type}' type");
if (isset($test[2])) {
$test = $handle->responds($test[2], $params);
} else {
$test = array(202, array(), '');
}
}
@(list($out->status, $out->headers, $out->response) = $test);
$params['status'] && ($out->status = (int) $params['status']);
$params['headers'] && ($out->headers = (array) $params['headers']);
if ($out->response === NULL) {
\Sauce\Logger::debug("Rendering view {$controller}/{$action}.php");
$out->response = partial("{$controller}/{$action}.php", $vars);
if ($params['layout']) {
\Sauce\Logger::debug("Using layout layouts/{$params['layout']}.php");
$layout_file = "layouts/{$params['layout']}.php";
$out->response = partial($layout_file, array('head' => join("\n", $params['head']), 'title' => $params['title'], 'body' => $out->response, 'view' => $vars));
}
}
if ($cache > 0) {
\Sauce\Logger::debug("Caching for {$cache} seconds ({$controller}#{$action})");
\Cashier\Base::store($hash, array($out->status, $out->headers, $out->response), $cache);
}
}
return $out;
}
示例9: get_query
function get_query($id = NULL, $find_by = NULL, &$model)
{
if (isset($model->query)) {
$q = $model->query;
unset($model->query);
return $q;
}
$model->set_param('id', $id);
$model->set_param('find_by', $find_by);
trigger_before('get_query', $model, $this);
$pkfield = $model->primary_key;
if ($model->find_by == NULL) {
$model->set_param('find_by', $model->primary_key);
}
$relfields = array();
$relfields = $model->relations;
$table = $this->prefix . $model->table;
$fieldstring = '';
$sql = "SELECT " . "\n";
if (!array_key_exists($pkfield, $model->field_array)) {
$sql .= "{$table}.{$pkfield} as \"{$table}.{$pkfield}\", " . "\n";
}
foreach ($model->field_array as $fieldname => $datatypename) {
if (strpos($fieldname, ".") === false) {
$fieldname = $table . "." . $fieldname;
}
$fieldstring .= "{$fieldname} as \"{$fieldname}\", " . "\n";
}
$leftsql = "";
$first = true;
if (count($relfields) > 0) {
foreach ($relfields as $key => $val) {
$spl = split("\\.", $val["fkey"]);
if (!$this->models[$spl[0]]->exists) {
${$spl}[0] =& $this->get_table($spl[0]);
}
$leftsql .= "(";
}
foreach ($relfields as $key => $val) {
$spl = split("\\.", $val["fkey"]);
if ($val["type"] == 'child-many') {
$join =& $this->get_table($model->join_table_for($table, $val['tab']));
$spl[0] = $this->prefix . $join->table;
$val["fkey"] = $this->prefix . $join->table . '.' . strtolower(classify($table)) . "_" . $model->foreign_key_for($table);
} else {
foreach ($this->models[$spl[0]]->field_array as $fieldname => $datatypename) {
$fieldstring .= $this->prefix . $spl[0] . "." . $fieldname . " as \"" . $this->prefix . $spl[0] . "." . $fieldname . "\", " . "\n";
}
}
if ($first) {
$leftsql .= $table;
}
$leftsql .= " left join " . $this->prefix . $spl[0] . " on " . $table . "." . $val["col"] . " = " . $val["fkey"];
$leftsql .= ")";
$first = false;
}
}
$fieldstring = substr($fieldstring, 0, -3) . " " . "\n";
$sql .= $fieldstring;
$sql .= "FROM ";
$sql .= $leftsql;
if (!(strlen($leftsql) > 1)) {
$sql .= $table;
}
if (is_array($model->find_by)) {
$findfirst = true;
$op = "AND";
$eq = '=';
foreach ($model->find_by as $col => $val) {
if (is_array($val)) {
list($col, $val) = each($val);
}
if ($col == 'op') {
$op = $val;
} elseif ($col == 'eq') {
$eq = $val;
} else {
if (strpos($col, ".") === false) {
$field = "{$table}.{$col}";
} else {
$field = $this->prefix . $col;
}
if ($findfirst) {
$sql .= " WHERE {$field} {$eq} '{$val}' ";
} else {
$sql .= " {$op} {$field} {$eq} '{$val}' ";
}
$findfirst = false;
}
}
} elseif ($model->id != NULL) {
if (strpos($model->find_by, ".") === false) {
$field = $table . "." . $model->find_by;
} else {
$field = $model->find_by;
}
$sql .= " WHERE {$field} = '" . $model->id . "' ";
}
if (!isset($model->orderby)) {
$model->orderby = $table . "." . $pkfield;
//.........这里部分代码省略.........
示例10: setInferredClassName
/**
* Infers the $this->className based on $this->attributeName.
*
* Will try to guess the appropriate class by singularizing and uppercasing $this->attributeName.
*
* @return void
* @see attribute_name
*/
protected function setInferredClassName()
{
$singularize = $this instanceof HasMany ? true : false;
$this->setClassName(classify($this->attributeName, $singularize));
}
示例11: load
public function load(Model $model)
{
$class_name = $this->class_name;
$this->set_keys(get_class($model));
// since through relationships depend on other relationships we can't do
// this initiailization in the constructor since the other relationship
// may not have been created yet and we only want this to run once
if (!isset($this->initialized)) {
if ($this->through) {
// verify through is a belongs_to or has_many for access of keys
if (!($through_relationship = $this->get_table()->get_relationship($this->through))) {
throw new HasManyThroughAssociationException("Could not find the association {$this->through} in model " . get_class($model));
}
if (!$through_relationship instanceof HasMany && !$through_relationship instanceof BelongsTo) {
throw new HasManyThroughAssociationException('has_many through can only use a belongs_to or has_many association');
}
// save old keys as we will be reseting them below for inner join convenience
$pk = $this->primary_key;
$fk = $this->foreign_key;
$this->set_keys($this->get_table()->class->getName(), true);
$through_table = Table::load(classify($this->through, true));
$this->options['joins'] = $this->construct_inner_join_sql($through_table, true);
// reset keys
$this->primary_key = $pk;
$this->foreign_key = $fk;
}
$this->initialized = true;
}
if (!($conditions = $this->create_conditions_from_keys($model, $this->foreign_key, $this->primary_key))) {
return null;
}
$options = $this->unset_non_finder_options($this->options);
$options['conditions'] = $conditions;
return $class_name::find($this->poly_relationship ? 'all' : 'first', $options);
}
示例12: classify
<?php
echo '<' . '?php';
?>
class Home extends \<?php
echo classify($app_name);
?>
\App\Base
{
}
示例13: add_tweet_user
if (isset($entry['title']['value'])) {
$u = add_tweet_user($entry);
$title = $entry['title']['value'];
$tweeturl = $entry['link'][0]['attr']['href'];
$request->set_param(array('post', 'parent_id'), 0);
$request->set_param(array('post', 'uri'), $tweeturl);
$request->set_param(array('post', 'url'), $tweeturl);
$request->set_param(array('post', 'title'), $title);
$request->set_param(array('post', 'profile_id'), $u->profile_id);
$table = 'posts';
$content_type = 'text/html';
$rec = $Post->base();
$fields = $Post->fields_from_request($request);
$fieldlist = $fields['posts'];
foreach ($fieldlist as $field => $type) {
$rec->set_value($field, $request->params[strtolower(classify($table))][$field]);
}
$Identity =& $db->model('Identity');
$id = $Identity->find($u->profile_id);
$rec->save_changes();
$rec->set_etag($id->person_id);
trigger_after('insert_tweets_via_cron', $Post, $rec);
}
}
}
}
}
}
if ($latest) {
$options[1]['last_id'] = $latest;
}
示例14: virtual_resource
function virtual_resource()
{
global $request;
$model = model_path() . classify($request->resource) . ".php";
if (!file_exists($model)) {
return true;
}
return false;
}
示例15: int
`Salary` int(6) NOT NULL,
PRIMARY KEY (`sl`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ;
--
-- Dumping data for table `table1`
--
INSERT INTO `table1` (`sl`, `Education`, `Sex`, `Work`, `Disease`, `Salary`) VALUES
(1, '9th', 'M', 32, 'Bronchitis', 3000),
(2, '9th', 'M', 30, 'Cholera', 1000),
(3, '9th', 'M', 33, 'Flu', 2000),
(4, '10th', 'F', 35, 'Bronchitis', 2000),
(5, '10th', 'F', 36, 'Cholera', 3000),
(6, '11th', 'M', 37, 'Flu', 3000),
(7, '12th', 'M', 38, 'Cholera', 3000),
(8, '12th', 'F', 38, 'Flu', 3000),
(9, '11th', 'M', 37, 'Bronchitis', 1000),
(10, 'Masters', 'M', 41, 'Cholera', 1000),
(11, 'Bachelors', 'F', 39, 'Bronchitis', 2000),
(12, 'Masters', 'M', 42, 'Flu', 1000),
(13, 'Masters', 'M', 44, 'Flu', 2000),
(14, 'Bachelors', 'F', 38, 'Bronchitis', 1000),
(15, 'Doctorate', 'F', 44, 'Cholera', 2000),
(16, 'Masters', 'F', 40, 'Flu', 1000),
(17, 'Doctorate', 'F', 44, 'Bronchitis', 1000),
(18, 'Doctorate', 'F', 45, 'Cholera', 3000),
(19, 'Doctorate', 'F', 44, 'Cholera', 2000);
*/
classify($X, $n, $table);