本文整理汇总了PHP中assert_int函数的典型用法代码示例。如果您正苦于以下问题:PHP assert_int函数的具体用法?PHP assert_int怎么用?PHP assert_int使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_int函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cat_event_category_save
function cat_event_category_save($event, $table_name)
{
global $txpcfg;
extract(doSlash(psa(array('id', 'name', 'old_name', 'parent', 'title'))));
$id = assert_int($id);
$name = sanitizeForUrl($name);
// make sure the name is valid
if (!$name) {
$message = array(gTxt($event . '_category_invalid', array('{name}' => $name)), E_ERROR);
return cat_category_list($message);
}
// don't allow rename to clobber an existing category
$existing_id = safe_field('id', 'txp_category', "name = '{$name}' and type = '{$event}'");
if ($existing_id and $existing_id != $id) {
$message = array(gTxt($event . '_category_already_exists', array('{name}' => $name)), E_ERROR);
return cat_category_list($message);
}
$parent = $parent ? $parent : 'root';
if (safe_update('txp_category', "name = '{$name}', parent = '{$parent}', title = '{$title}'", "id = {$id}")) {
safe_update('txp_category', "parent = '{$name}'", "parent = '{$old_name}'");
}
rebuild_tree_full($event);
if ($event == 'article') {
safe_update('textpattern', "Category1 = '{$name}'", "Category1 = '{$old_name}'");
safe_update('textpattern', "Category2 = '{$name}'", "Category2 = '{$old_name}'");
} else {
safe_update($table_name, "category = '{$name}'", "category = '{$old_name}'");
}
$message = gTxt($event . '_category_updated', array('{name}' => doStrip($name)));
cat_category_list($message);
}
示例2: checkIfNeighbour
function checkIfNeighbour($whichway, $sPosted)
{
$sPosted = assert_int($sPosted);
$dir = $whichway == 'prev' ? '<' : '>';
$ord = $whichway == 'prev' ? 'desc' : 'asc';
return safe_field("ID", "textpattern", "Posted {$dir} from_unixtime({$sPosted}) order by Posted {$ord} limit 1");
}
示例3: __construct
/**
* Constructor.
*
* @param int $id The Image id.
*/
public function __construct($id)
{
$id = assert_int($id);
$rs = safe_row("*", 'txp_image', "id = {$id} LIMIT 1");
if ($rs) {
extract($rs);
$this->m_ext = $ext;
$this->m_id = $id;
}
parent::__construct();
}
示例4: author_edit
/**
* User editor panel.
*
* Accessing requires 'admin.edit' privileges.
*/
function author_edit()
{
global $step, $txp_user;
require_privs('admin.edit');
pagetop(gTxt('tab_site_admin'), '');
$vars = array('user_id', 'name', 'RealName', 'email', 'privs');
$rs = array();
$out = array();
extract(gpsa($vars));
$is_edit = $user_id && $step == 'author_edit';
if ($is_edit) {
$user_id = assert_int($user_id);
$rs = safe_row('*', 'txp_users', "user_id = {$user_id}");
extract($rs);
}
if ($is_edit) {
$out[] = hed(gTxt('edit_author'), 2);
} else {
$out[] = hed(gTxt('add_new_author'), 2);
}
if ($is_edit) {
$out[] = inputLabel('login_name', strong(txpspecialchars($name)));
} else {
$out[] = inputLabel('login_name', fInput('text', 'name', $name, '', '', '', INPUT_REGULAR, '', 'login_name'), 'login_name', 'add_new_author');
}
$out[] = inputLabel('real_name', fInput('text', 'RealName', $RealName, '', '', '', INPUT_REGULAR, '', 'real_name'), 'real_name') . inputLabel('login_email', fInput('email', 'email', $email, '', '', '', INPUT_REGULAR, '', 'login_email'), 'email');
if ($txp_user != $name) {
$out[] = inputLabel('privileges', privs($privs), 'privileges', 'about_privileges');
} else {
$out[] = inputLabel('privileges', strong(get_priv_level($privs))) . hInput('privs', $privs);
}
$out[] = pluggable_ui('author_ui', 'extend_detail_form', '', $rs) . graf(fInput('submit', '', gTxt('save'), 'publish')) . eInput('admin');
if ($user_id) {
$out[] = hInput('user_id', $user_id) . hInput('name', $name) . sInput('author_save');
} else {
$out[] = sInput('author_save_new');
}
echo form(n . tag(join('', $out) . n, 'section', array('class' => 'txp-edit')), '', '', 'post', 'edit-form', '', 'user_edit');
}
示例5: author_delete
function author_delete()
{
require_privs('admin.edit');
$user_id = assert_int(ps('user_id'));
$name = fetch('Realname', 'txp_users', 'user_id', $user_id);
if ($name) {
$rs = safe_delete('txp_users', "user_id = {$user_id}");
if ($rs) {
admin(gTxt('author_deleted', array('{name}' => $name)));
}
}
}
示例6: _setArticle
/**
* Executes the real action for @see udpateArticleId and @see newArticle
* @param array $incoming containing the desired article fields
* @param mixed(string|integer) $article_id the ID of the article to update
* @return mixed integer article id on success, false otherwise
* @access private
*/
function _setArticle($incoming, $article_id = null)
{
global $txpcfg;
$prefs = get_prefs();
extract($prefs);
if (!empty($incoming['Section']) && !$this->getSection($incoming['Section'])) {
return false;
}
if (!empty($incoming['Category1']) && !$this->getCategory($incoming['Category1'])) {
return false;
}
if (!empty($incoming['Category2']) && !$this->getCategory($incoming['Category2'])) {
return false;
}
if ($article_id !== null) {
$article_id = assert_int($article_id);
}
//All validation rules assumed to be passed before this point.
//Do content processing here
$incoming_with_markup = $this->textile_main_fields($incoming, $use_textile);
$incoming['Title'] = $incoming_with_markup['Title'];
if (empty($incoming['Body_html']) && !empty($incoming['Body'])) {
$incoming['Body_html'] = $incoming_with_markup['Body_html'];
}
if (empty($incoming['Excerpt_html']) && !empty($incoming['Excerpt'])) {
$incoming['Excerpt_html'] = $incoming_with_markup['Excerpt_html'];
}
unset($incoming_with_markup);
if (empty($incoming['Posted'])) {
if ($article_id === null) {
$when = !$article_id ? 'now()' : '';
$incoming['Posted'] = $when;
} else {
# do not override post time for existing articles unless Posted is present
unset($incoming['Posted']);
}
} else {
$when = strtotime($incoming['Posted']) - tz_offset();
$when = "from_unixtime({$when})";
}
if ($incoming['Title'] || $incoming['Body'] || $incoming['Excerpt']) {
//Build SQL then and run query
//Prevent data erase if not defined on the update action
//but it was on the DB from a previous creation/edition time
if ($article_id) {
$old = safe_row('*', 'textpattern', "ID = {$article_id}");
//Status should be defined previously. Be sure of that.
if (!has_privs('article.publish', $this->txp_user) && $incoming['Status'] == 4 && $old['Status'] != 4) {
$incoming['Status'] = 3;
}
foreach ($old as $key => $val) {
if (!isset($incoming[$key])) {
$incoming[$key] = $val;
}
}
} else {
//Status should be defined previously. Be sure of that.
if (!has_privs('article.publish', $this->txp_user) && $incoming['Status'] == 4) {
$incoming['Status'] = 3;
}
}
if (empty($incoming['Section']) && $article_id) {
$incoming['Section'] = safe_field('Section', 'textpattern', "ID = {$article_id}");
}
$incoming = $this->_check_keys($incoming, array('AuthorID' => $this->txp_user, 'Annotate' => $comments_on_default, 'AnnotateInvite' => $comments_default_invite, 'textile_body' => $use_textile, 'textile_excerpt' => $use_textile, 'url_title' => stripSpace($incoming['Title'])));
//Build the SQL query
$sql = array();
foreach ($incoming as $key => $val) {
if ($key == 'Posted' && $val == 'now()') {
$sql[] = "{$key} = {$val}";
} elseif ($key != 'ID' && $key != 'uid' && $key != 'feed_time' && $key != 'LastMod' && $key != 'LastModID') {
$sql[] = "{$key} = '" . doSlash($val) . "'";
}
}
$sql[] = 'LastMod = now()';
$sql[] = "LastModID = '" . doSlash($this->txp_user) . "'";
if (!$article_id) {
$sql[] = "uid = '" . doSlash(md5(uniqid(rand(), true))) . "'";
}
if (!$article_id) {
if (empty($incoming['Posted'])) {
$sql[] = "feed_time = curdate()";
} else {
$when = strtotime($incoming['Posted']) - tz_offset();
$when = strftime("%Y-%m-%d", $when);
$sql[] = "feed_time ='" . doSlash($when) . "'";
}
}
$sql = join(', ', $sql);
$rs = $article_id ? safe_update('textpattern', $sql, "ID = {$article_id}") : safe_insert('textpattern', $sql);
$oldstatus = $article_id ? $old['Status'] : '';
if (!$article_id && $rs) {
$article_id = $rs;
//.........这里部分代码省略.........
示例7: mail_comment
function mail_comment($message, $cname, $cemail, $cweb, $parentid, $discussid)
{
global $sitename;
$parentid = assert_int($parentid);
$discussid = assert_int($discussid);
$article = safe_row("Section, Posted, ID, url_title, AuthorID, Title", "textpattern", "ID = {$parentid}");
extract($article);
extract(safe_row("RealName, email", "txp_users", "name = '" . doSlash($AuthorID) . "'"));
$evaluator =& get_comment_evaluator();
$out = gTxt('greeting') . " {$RealName}," . n . n;
$out .= str_replace('{title}', $Title, gTxt('comment_recorded')) . n;
$out .= permlinkurl_id($parentid) . n;
if (has_privs('discuss', $AuthorID)) {
$out .= hu . 'textpattern/index.php?event=discuss&step=discuss_edit&discussid=' . $discussid . n;
}
$out .= gTxt('status') . ": " . $evaluator->get_result('text') . '. ' . implode(',', $evaluator->get_result_message()) . n;
$out .= n;
$out .= gTxt('comment_name') . ": {$cname}" . n;
$out .= gTxt('comment_email') . ": {$cemail}" . n;
$out .= gTxt('comment_web') . ": {$cweb}" . n;
$out .= gTxt('comment_comment') . ": {$message}";
$subject = strtr(gTxt('comment_received'), array('{site}' => $sitename, '{title}' => $Title));
$success = txpMail($email, $subject, $out, $cemail);
}
示例8: author_edit
function author_edit()
{
global $step, $txp_user;
require_privs('admin.edit');
pagetop(gTxt('tab_site_admin'), '');
$vars = array('user_id', 'name', 'RealName', 'email', 'privs');
$rs = array();
extract(gpsa($vars));
$is_edit = $user_id && $step == 'author_edit';
if ($is_edit) {
$user_id = assert_int($user_id);
$rs = safe_row('*', 'txp_users', "user_id = {$user_id}");
extract($rs);
}
$caption = gTxt($is_edit ? 'edit_author' : 'add_new_author');
echo form('<div class="txp-edit">' . n . hed($caption, 2) . n . inputLabel('login_name', $is_edit ? strong($name) : fInput('text', 'name', $name, '', '', '', INPUT_REGULAR, '', 'login_name'), $is_edit ? '' : 'login_name', $is_edit ? '' : 'add_new_author') . n . inputLabel('real_name', fInput('text', 'RealName', $RealName, '', '', '', INPUT_REGULAR, '', 'real_name'), 'real_name') . n . inputLabel('login_email', fInput('text', 'email', $email, '', '', '', INPUT_REGULAR, '', 'login_email'), 'email') . n . inputLabel('privileges', $txp_user != $name ? privs($privs) : hInput('privs', $privs) . strong(get_priv_level($privs)), $is_edit ? '' : 'privileges', 'about_privileges') . n . pluggable_ui('author_ui', 'extend_detail_form', '', $rs) . n . graf(fInput('submit', '', gTxt('save'), 'publish')) . eInput('admin') . ($user_id ? hInput('user_id', $user_id) . sInput('author_save') : sInput('author_save_new')) . '</div>', '', '', 'post', 'edit-form', '', 'user_edit');
}
示例9: doArticle
function doArticle($atts, $thing = NULL)
{
global $pretext, $prefs, $thisarticle;
extract($prefs);
extract($pretext);
extract(gpsa(array('parentid', 'preview')));
$theAtts = lAtts(array('allowoverride' => '1', 'form' => 'default', 'status' => '4', 'pgonly' => 0), $atts, 0);
extract($theAtts);
filterAtts($atts);
// save *all* atts to get hold of the current article filter criteria
if ($pgonly) {
return '';
}
// no output required
// if a form is specified, $thing is for doArticles() - hence ignore $thing here.
if (!empty($atts['form'])) {
$thing = '';
}
if ($status) {
$status = in_array(strtolower($status), array('sticky', '5')) ? 5 : 4;
}
if (empty($thisarticle) or $thisarticle['thisid'] != $id) {
$id = assert_int($id);
$thisarticle = NULL;
$q_status = $status ? 'and Status = ' . intval($status) : 'and Status in (4,5)';
$rs = safe_row("*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod", "textpattern", 'ID = ' . $id . " {$q_status} limit 1");
if ($rs) {
extract($rs);
populateArticleData($rs);
}
}
if (!empty($thisarticle) and ($thisarticle['status'] == $status or gps('txpreview'))) {
extract($thisarticle);
$thisarticle['is_first'] = 1;
$thisarticle['is_last'] = 1;
if ($allowoverride and $override_form) {
$article = parse_form($override_form);
} else {
$article = $thing ? parse($thing) : parse_form($form);
}
if ($use_comments and $comments_auto_append) {
$article .= parse_form('comments_display');
}
unset($GLOBALS['thisarticle']);
return $article;
}
}
示例10: safe_alter
safe_alter('textpattern', "add `uid` varchar(32) not null");
safe_alter('textpattern', "add `feed_time` DATE not null DEFAULT '0000-00-00'");
$rs = safe_rows_start('ID,Posted', 'textpattern', '1');
if ($rs) {
while ($a = nextRow($rs)) {
assert_int($a['ID']);
$feed_time = substr($a['Posted'], 0, 10);
safe_update('textpattern', "uid='" . md5(uniqid(rand(), true)) . "', feed_time='" . doSlash($feed_time) . "'", "ID={$a['ID']}");
}
}
}
// 1.0: populate comments_count field
$rs = safe_rows_start('parentid, count(*) as thecount', 'txp_discuss', 'visible=1 group by parentid');
if ($rs) {
while ($a = nextRow($rs)) {
assert_int($a['parentid']);
safe_update('textpattern', "comments_count=" . $a['thecount'], "ID=" . $a['parentid']);
}
}
// 1.0: Human-friendly title for sections and categories, to solve i18n problems
if (!in_array('title', $txpsect)) {
safe_alter("txp_section", "add `title` varchar(255) not null default ''");
}
if (!in_array('title', $txpcat)) {
safe_alter("txp_category", "add `title` varchar(255) not null default ''");
}
if (safe_count('txp_section', "title=''") > 0) {
safe_update('txp_section', 'title=name', "title=''");
}
if (safe_count('txp_category', "title=''") > 0) {
safe_update('txp_category', 'title=name', "title=''");
示例11: rebuild_tree
function rebuild_tree($parent, $left, $type)
{
$left = assert_int($left);
$right = $left + 1;
$parent = doSlash($parent);
$type = doSlash($type);
$result = safe_column("name", "txp_category", "parent='{$parent}' and type='{$type}' order by name");
foreach ($result as $row) {
$right = rebuild_tree($row, $right, $type);
}
safe_update("txp_category", "lft={$left}, rgt={$right}", "name='{$parent}' and type='{$type}'");
return $right + 1;
}
示例12: replace_post
function replace_post()
{
$id = assert_int(gps('id'));
$rs = safe_row("*", "txp_image", "id = {$id}");
if ($rs) {
$meta = array('category' => $rs['category'], 'caption' => $rs['caption'], 'alt' => $rs['alt']);
} else {
$meta = '';
}
$img_result = image_data($_FILES['thefile'], $meta, $id);
if (is_array($img_result)) {
list($message, $id) = $img_result;
$this->_message($message);
} else {
$this->_error($img_result);
}
$this->_set_view('edit', $id);
}
示例13: link_save
function link_save()
{
global $txpcfg, $vars, $txp_user;
$varray = gpsa($vars);
extract(doSlash($varray));
$id = assert_int($id);
if ($linkname === '' && $url === '' && $description === '') {
link_edit();
return;
}
$author = fetch('author', 'txp_link', 'id', $id);
if (!has_privs('link.edit') && !($author == $txp_user && has_privs('link.edit.own'))) {
link_edit(gTxt('restricted_area'));
return;
}
if (!$linksort) {
$linksort = $linkname;
}
$rs = safe_update("txp_link", "category = '{$category}',\n\t\t\turl = '" . trim($url) . "',\n\t\t\tlinkname = '{$linkname}',\n\t\t\tlinksort = '{$linksort}',\n\t\t\tdescription = '{$description}',\n\t\t\tauthor \t\t= '" . doSlash($txp_user) . "'", "id = {$id}");
if ($rs) {
update_lastmod();
$message = gTxt('link_updated', array('{name}' => doStrip($linkname)));
link_edit($message);
}
}
示例14: file_delete
function file_delete($ids = array())
{
global $file_base_path, $txp_user;
$ids = $ids ? array_map('assert_int', $ids) : array(assert_int(ps('id')));
if (!has_privs('file.delete')) {
if (has_privs('file.delete.own')) {
$ids = safe_column('id', 'txp_file', 'id IN (' . join(',', $ids) . ') AND author=\'' . doSlash($txp_user) . '\'');
} else {
$ids = array();
}
}
if (!empty($ids)) {
$fail = array();
$rs = safe_rows_start('id, filename', 'txp_file', 'id IN (' . join(',', $ids) . ')');
if ($rs) {
while ($a = nextRow($rs)) {
extract($a);
$filepath = build_file_path($file_base_path, $filename);
// Notify plugins of pending deletion, pass file's id and path.
callback_event('file_deleted', '', false, $id, $filepath);
$rsd = safe_delete('txp_file', "id = {$id}");
$ul = false;
if ($rsd && is_file($filepath)) {
$ul = unlink($filepath);
}
if (!$rsd or !$ul) {
$fail[] = $id;
}
}
if ($fail) {
file_list(array(messenger(gTxt('file_delete_failed'), join(', ', $fail)), E_ERROR));
return;
} else {
update_lastmod('file_deleted', $ids);
file_list(gTxt('file_deleted', array('{name}' => join(', ', $ids))));
return;
}
} else {
file_list(array(messenger(gTxt('file_not_found'), join(', ', $ids), ''), E_ERROR));
return;
}
}
file_list();
}
示例15: file_delete
function file_delete($ids = array())
{
global $file_base_path;
$ids = $ids ? array_map('assert_int', $ids) : array(assert_int(ps('id')));
$fail = array();
$rs = safe_rows_start('id, filename', 'txp_file', 'id IN (' . join(',', $ids) . ')');
if ($rs) {
while ($a = nextRow($rs)) {
extract($a);
$filepath = build_file_path($file_base_path, $filename);
$rsd = safe_delete('txp_file', "id = {$id}");
$ul = false;
if ($rsd && is_file($filepath)) {
$ul = unlink($filepath);
}
if (!$rsd or !$ul) {
$fail[] = $id;
}
}
if ($fail) {
file_list(messenger(gTxt('file_delete_failed'), join(', ', $fail), ''));
} else {
file_list(gTxt('file_deleted', array('{name}' => join(', ', $ids))));
}
} else {
file_list(messenger(gTxt('file_not_found'), join(', ', $ids), ''));
}
}