本文整理汇总了PHP中functions类的典型用法代码示例。如果您正苦于以下问题:PHP functions类的具体用法?PHP functions怎么用?PHP functions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了functions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$this->folder = functions::q($_POST['id']);
$this->act = functions::q($_POST['op']);
$this->db = new DataBase();
$this->f = new functions();
$this->image = new SimpleImage();
if ($this->act == 'upload') {
$name = $_FILES['uploadfile']['name'];
$exp = explode('.', $name);
$this->ext = $exp[count($exp) - 1];
$filetypes = array('jpg', 'gif', 'bmp', 'png', 'JPG', 'BMP', 'GIF', 'PNG', 'jpeg', 'JPEG');
if (!in_array($this->ext, $filetypes)) {
die("wrong_format");
} else {
$this->photoName();
if ($this->getNum() < $this->_count) {
$this->uploadFile();
} else {
die("Максимальное количество загружаемых фотографий в объявление не должно превышать 6 шт.");
}
}
} elseif ($this->act == 'delete') {
$this->delete();
}
}
示例2: __construct
function __construct($params)
{
$file = 'console-' . date(@$params['log'] ?: 'Y-m-d') . '.log';
$this->_file = \loader::get_temp($file);
$this->_uid = substr(\functions::hash(microtime(true)), -5);
$this->_head();
}
示例3: run
function run()
{
/**@var tf_sat $sat */
$sat = core::module('sat');
$site = $sat->get_current_site();
$json_file = loader::get_public('assets/' . $site->domain . '.json');
$last_mod = @filemtime($json_file);
$tree_last_mod = 0;
if ($last_mod) {
$last_node = $sat->get_node_handle()->set_where('site_id = %d', $sat->get_current_site_id())->set_order('updated_at DESC')->load_first();
$tree_last_mod = $last_node ? $last_node->updated_at : 0;
core::dprint(__METHOD__ . ': cached');
// uptodate
if ($tree_last_mod <= $last_mod) {
$this->renderer->set_ajax_answer(file_get_contents($json_file))->ajax_flush();
return;
}
}
core::dprint(__METHOD__ . ': fetch!');
$tree = $sat->get_current_site_tree();
$allowedKeys = array('title', 'url');
array_walk($tree, function (&$v) use($allowedKeys) {
$v = array_intersect_key($v, array_flip($allowedKeys));
});
$tree = array_values($tree);
// cache
file_put_contents($json_file, functions::json_encode($tree));
$this->renderer->set_ajax_answer($tree)->ajax_flush();
}
示例4: run
/**
* Run block
* Called from module::run_block
*
* Params passed to 'block.data'
* action converted to object!
*
* Extended params passed to {$block.params}
*
* @throws modules_exception
*/
function run($action, $params)
{
$_tag = $this->get_context()->get_tag();
core::dprint('[BLOCK] start ' . $_tag . '::' . $action, core::E_DEBUG);
$return = false;
// @todo check for callable
if (is_callable(array($this, $action))) {
if (!empty($params)) {
// convert parameters to object
$c_params = functions::array2object($params);
$data = call_user_func(array($this, $action), $c_params);
} else {
$data = call_user_func(array($this, $action));
}
// get block builtin properties
$props = $this->get_block($action);
// assign params
$props['params'] = $params;
$return = $this->get_context()->get_core()->lib('renderer')->render_block($props, $data);
} else {
throw new modules_exception('Not callable action supplied - ' . $action);
}
core::dprint('[/BLOCK] end ' . $_tag . '::' . $action, core::E_DEBUG);
return $return;
}
示例5: run
function run()
{
$q = $this->get_param('query');
if (empty($q)) {
$q = functions::request_var('keyword');
}
if (loader::in_ajax()) {
$keyword = trim($q);
} else {
$keyword = trim(urldecode($q));
}
$this->renderer->set_return('keyword', $keyword);
$this->renderer->set_main_title('search');
if (empty($q)) {
return;
}
if (strings::strlen($keyword) < 3) {
$this->renderer->set_message('sat.search_too_short', array('result' => false));
$this->renderer->set_ajax_message('sat.search_too_short');
return false;
}
// make search and redirect to it
$id = $this->make_search($keyword);
// redirect to search results
$url = $this->_controller->get_context()->get_router()->make_url('/search/' . $id . '/');
if (loader::in_ajax()) {
$this->_controller->set_null_template();
$this->renderer->set_ajax_message($this->_found ? sprintf('По вашему запросу найдено %d записей', $this->_found) : 'Подходящих записей не найдено')->set_ajax_result($this->_found)->set_ajax_redirect($url);
} else {
functions::redirect($url);
core::get_instance()->halt();
}
}
示例6: action_system
function action_system()
{
$this->collection->toggle_system($this->params->id, 'true' == functions::request_var('to', 'false'));
if ($this->in_ajax()) {
$this->_ajax_answer(true, i18n::T('Status changed'));
}
}
示例7: __construct
function __construct($dependencies = null, $context)
{
if (empty($dependencies)) {
return;
}
$this->context = $context;
$this->dependencies = is_array($this->dependencies) ? functions::array_merge_recursive_distinct($dependencies, $this->dependencies) : $dependencies;
}
示例8: __construct
public function __construct()
{
parent::__construct();
//necessary
functions::accountExpiration();
$this->playlist_model = new Playlist_Model();
$this->layout_model = new Layout_Model();
}
示例9: Indicadores
function Indicadores($tematica_id)
{
if ($tematica_id > 0) {
return functions::indicadores($tematica_id);
} else {
// todos los indicadores de observatic
return functions::indicador();
}
}
示例10: run
/**
* Remember!
* Assign current item in controller for comment linking!
*/
function run()
{
if (loader::in_ajax() !== true) {
throw new controller_exception('Cant touch this ' . __METHOD__);
return false;
}
core::dprint('run comment modify');
$pctl = core::modules()->get_router()->get_controller();
$user = core::lib('auth')->get_user();
/**
* Parent item, must be assigned thru @see module_controller::set_current_item()
* @var abs_collection_item
*/
$post = $pctl->get_current_item();
// var_dump(get_class($post), core::get_modules()->get_router()->get_name());
if (!$post) {
throw new controller_exception('No item assigned');
}
if (!$post->has_behavior('sat.commentable')) {
throw new controller_exception('Not commentable');
}
$comments = $post->behavior('sat.commentable')->get_attach_model();
//get_comments();
$request = core::lib('request');
$renderer = core::lib('renderer');
$user_id = core::lib('auth')->get_user()->id;
$pid = (int) $request->post('pid', 0);
$limit = core::selfie()->cfg('comment_interval', 60);
$auth = core::lib('auth');
/** @var aregistry $sd */
$sd = $auth->get_current_session()->get_storage();
$time = $sd->comments_last_time;
//$time = $comments->get_last_time($pid, $user_id);
// disallow by interval
if ($time && $time + $limit > time()) {
$pctl->set_null_template();
$renderer->set_ajax_answer(array('status' => false, 'id' => 0, 'message' => vsprintf(i18n::T('sat\\comment_interval_restriction'), $time + $limit - time())))->ajax_flush();
// else core::get_instance()->set_message(array('content', 'comment_interval_restriction'));
return;
// exit
}
$sd->comments_last_time = time();
$username = functions::request_var('username', '');
$text = functions::request_var('text', '');
$api = functions::request_var('api');
$id = $comments->modify(array('user_ip' => core::lib('auth')->get_user_ip(true), 'user_id' => $user_id, 'ctype_id' => $post->get_ctype_id(), 'username' => $username, 'pid' => $pid, 'text' => $text, 'type' => functions::request_var('type', 0), 'tpid' => functions::request_var('tpid', 0), 'api' => $api));
$comment = $comments->get_item_by_id($id);
if (!$comment) {
throw new controller_exception('[ajax] Comment create failed');
}
$comment->load_secondary();
$renderer->set_data('comment', $comment->render())->set_ajax_answer(array('status' => true, 'id' => $id))->set_ajax_message(i18n::T('sat\\comment_posted'));
//->set_main_template('content/comment/view');
$renderer->ajax_flush('shared/comments/comment');
// alright, update counter
return $id;
}
示例11: applyStatus
function applyStatus($id, $act)
{
if ($act == 'top') {
$sql = "UPDATE board SET top_time='" . (14 * 86400 + time()) . "' WHERE id='{$id}'";
} elseif ($act == 'color') {
$sql = "UPDATE board SET is_color='1' WHERE id='" . functions::q($id) . "'";
} elseif ($act == 'important') {
$sql = "UPDATE board SET is_important='1' WHERE id='" . functions::q($id) . "'";
}
return mysql_query($sql);
}
示例12: init_config
/**
* Init config
*/
function init_config($config = array(), $append = false)
{
if (empty($config)) {
return;
}
if (!$append) {
$this->config = $config;
} else {
$this->config = functions::array_merge_recursive_distinct($this->config, $config);
}
}
示例13: getPhoto
function getPhoto($name, $width, $height, $params = "", $method = "echo")
{
$url = HOME . substr($name, 2);
$size = functions::getFullSize(DIR . substr($name, 2), $width, $height);
$width = $size['width'];
$height = $size['height'];
$txt = "<img src=\"" . $url . "\" width=" . $width . " height=" . $height . " " . $params . "/>";
if ($method == "return") {
return $txt;
} else {
echo $txt;
}
}
示例14: init
public function init()
{
// Make a controller copy of $user since it won't report anything back
$user = $this->user;
$this->passChanged = isset($_GET['passchanged']) ? $_GET['passchanged'] : false;
// Is this user allowed here
if (!$user->isSigned() and !isset($_GET['c']) and !$this->passChanged) {
//Redirect
functions::_index();
}
if ($user->isSigned() and $this->passChanged || isset($_GET['c'])) {
$this->_redirect("http://" . $_SERVER['HTTP_HOST'] . "/user/profile");
}
//Proccess Password change
if (count($_POST)) {
// Set some session variables
$pass = array();
$_SESSION['pass'] = $pass;
$_SESSION['pass']['Password'] = $_POST['password'];
$_SESSION['pass']['Password2'] = $_POST['password2'];
$_SESSION['hash'] = $_POST['c'];
// Ensures session is written before redirect.
session_write_close();
if ($_SESSION['hash']) {
$this->_redirect("http://" . $_SERVER['HTTP_HOST'] . "/user/changepassword?c=" . $_SESSION['hash']);
} else {
$this->_redirect("http://" . $_SERVER['HTTP_HOST'] . "/user/changepassword");
}
} else {
if (isset($_SESSION['pass'])) {
$hash = $_SESSION['hash'];
$pass = $_SESSION['pass'];
if (!$user->isSigned() and $hash) {
//Change Password with confirmation hash
$user->newPassword($hash, $pass);
} else {
//Change the Password of signed in user without a confirmation hash
$user->update($pass);
}
// If password was changed
if (!count($user->log->getFormErrors())) {
session_unset();
session_destroy();
// Log the user out
$user->logout();
$this->_redirect("http://" . $_SERVER['HTTP_HOST'] . "/user/changepassword?passchanged=1");
}
}
}
}
示例15: execute
/**
* render|update|create model model ...
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
* @throws \tf_exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
//require('../_tests/loader.php');
$core = $this->core();
$this->prepare_db($input->getOption('database'));
$action = $input->getArgument('action');
if (empty($action)) {
throw new \tf_exception("empty action\n");
}
$ids = $input->getArgument('models');
if (empty($ids)) {
throw new \tf_exception("empty ID\n");
}
if ($ids[0] == '*') {
$ids = Helpers\ModelEnumerator::find();
}
/*
* $action = @$_SERVER['argv'][2] ? : 'render';
if (in_array('--', $_SERVER['argv'])) {
}
*/
$output->writeln('action: ' . $action);
/** @var collection_generator */
$generator = \abs_collection::get_generator();
foreach ($ids as $mid) {
$_mid = explode('.', trim($mid));
if (count($_mid) == 1) {
array_unshift($_mid, 'core');
$container = core::selfie();
} else {
$container = core::module($_mid[0]);
}
if (!$container) {
$output->writeln('skip ' . $mid);
continue;
}
$method = 'get_' . $_mid[1] . '_handle';
// allow model with params: get_model_handle | model('model')
$obj = \functions::is_callable(array($container, $method)) ? $container->{$method}() : $container->model($_mid[1]);
$generator->append_object($obj);
}
$output->writeln($generator->render_table_structure(), OutputInterface::OUTPUT_RAW);
if ($action == 'update') {
$generator->update_table_structure();
}
if ($action == 'create') {
$generator->update_table_structure(true);
}
}