function output_css($s = '', $n = '') { $order = ''; if ($n) { if (!is_scalar($n)) { txp_die('Not Found', 404); } $n = do_list_unique($n); $cssname = join("','", doSlash($n)); if (count($n) > 1) { $order = " ORDER BY FIELD(name, '{$cssname}')"; } } elseif ($s) { if (!is_scalar($s)) { txp_die('Not Found', 404); } $cssname = safe_field('css', 'txp_section', "name = '" . doSlash($s) . "'"); } if (!empty($cssname)) { $css = join(n, safe_column_num('css', 'txp_css', "name IN ('{$cssname}')" . $order)); echo $css; } }
/** * _cbe_rndc_pop_art - Admin-side: Generate articles * * See "Rules for articles" in the helpfile * * @return array */ function _cbe_rndc_pop_art(&$message, &$html) { global $event, $comments_on_default, $comments_default_invite; $next_step = NULL; include_once txpath . '/lib/classTextile.php'; $out = array(); $globerrlevel = ''; $message = gTxt(CBE_RNDC_LPFX . 'populate_end'); if (($use_textile = get_pref('use_textile')) == USE_TEXTILE) { include_once txpath . '/lib/classTextile.php'; } $authors = safe_column_num('name', 'txp_users', "`privs`<6"); $posauthor = count($authors) - 1; $sections = safe_column_num('name', 'txp_section', "`on_frontpage`=1 AND `name`!='default'"); $possection = count($sections) - 1; $categories = safe_column_num('name', 'txp_category', " `name`!='root' AND `type`='article'"); $poscategory = count($categories) - 1; $stati = array(STATUS_LIVE, STATUS_LIVE, STATUS_DRAFT, STATUS_LIVE, STATUS_LIVE, STATUS_HIDDEN, STATUS_LIVE, STATUS_LIVE, STATUS_PENDING, STATUS_LIVE, STATUS_LIVE); $posstatus = count($stati) - 1; $rndnb = rand(10, 15); $aAids = array(); $errlevel = "success"; for ($i = 0; $i < $rndnb; $i++) { $seeddate = rand(time() - 300 * 24 * 60 * 60, time() + 60 * 24 * 60 * 60); $in = rand(0, 9); $status = $stati[rand(0, $posstatus)]; $published = date("Y-m-d H:i:s", $seeddate); $lastmod = date("Y-m-d H:i:s"); $expires = in_array($in, array(0, 4, 8)) ? '' : date("Y-m-d H:i:s", strtotime("+{$in} months", $seeddate)); $feeddate = date("Y-m-d", $seeddate); $author = $authors[rand(0, $posauthor)]; $section = $sections[rand(0, $possection)]; $category1 = $categories[rand(0, $poscategory)]; if (($category2 = $in == 0 ? '' : $categories[rand(0, $poscategory)]) == $category1) { $category2 = ''; } $title = substr(_cbe_rndc_sentence(3, 5, 3, 6), 0, -1); $url_title = stripSpace($title, 1); $excerpt = _cbe_rndc_text(6, 10, 2, 8); $arrbody = array(); $parag = rand(2, 5); for ($j = 0; $j < $parag; $j++) { $arrbody[] .= _cbe_rndc_text(6, 8, 5, 10) . n; } $body = join(n, $arrbody); switch ($use_textile) { case USE_TEXTILE: $textile = new Textile(get_pref('doctype')); $title = $textile->TextileThis($title, '', 1); $body_html = $textile->TextileThis($body); $excerpt_html = $textile->TextileThis($excerpt); break; case LEAVE_TEXT_UNTOUCHED: $body_html = trim($body); $excerpt_html = trim($excerpt); break; case CONVERT_LINEBREAKS: $body_html = nl2br(trim($body)); $excerpt_html = nl2br(trim($excerpt)); break; default: break; } if ($insertd = safe_insert("textpattern", "Title = '{$title}',\n Body = '{$body}',\n Body_html = '{$body_html}',\n Excerpt = '{$excerpt}',\n Excerpt_html = '{$excerpt_html}',\n Status = '{$status}',\n Posted = '{$published}',\n Expires = '{$expires}',\n AuthorID = '{$author}',\n LastMod = '{$lastmod}',\n LastModID = '{$author}',\n Section = '{$section}',\n Category1 = '{$category1}',\n Category2 = '{$category2}',\n textile_body = {$use_textile},\n textile_excerpt = {$use_textile},\n Annotate = {$comments_on_default},\n url_title = '" . doSlash($url_title) . "',\n AnnotateInvite = '{$comments_default_invite}',\n uid = '" . md5(uniqid(rand(), true)) . "',\n feed_time = '{$feeddate}'")) { $aAids[] = $insertd; } else { $errlevel = "warning"; $globerrlevel = E_ERROR; } } $out[] = graf(tag(gTxt(CBE_RNDC_LPFX . 'populate_end'), 'span', ' class="' . $errlevel . '"') . ': ' . join(", ", $aAids)); if (!empty($globerrlevel)) { $message .= ' ' . gTxt(CBE_RNDC_LPFX . 'with_errors'); } $back = tag(fInput('submit', 'submit', gTxt(CBE_RNDC_LPFX . 'go_back'), 'publish') . n . sInput(CBE_RNDC_SPFX . 'initiate') . n . eInput($event), 'div'); $html = join(n, $out) . form($back); return $next_step; }
/** * Processes multi-edit actions. */ function list_multi_edit() { global $txp_user, $statuses, $all_cats, $all_authors, $all_sections; extract(psa(array('selected', 'edit_method'))); if (!$selected || !is_array($selected)) { return list_list(); } $selected = array_map('assert_int', $selected); // Empty entry to permit clearing the categories. $categories = array(''); foreach ($all_cats as $row) { $categories[] = $row['name']; } $allowed = array(); $field = $value = ''; switch ($edit_method) { // Delete. case 'delete': if (!has_privs('article.delete')) { if (has_privs('article.delete.own')) { $allowed = safe_column_num("ID", 'textpattern', "ID IN (" . join(',', $selected) . ") AND AuthorID = '" . doSlash($txp_user) . "'"); } $selected = $allowed; } if ($selected && safe_delete('textpattern', "ID IN (" . join(',', $selected) . ")")) { safe_update('txp_discuss', "visible = " . MODERATE, "parentid IN (" . join(',', $selected) . ")"); callback_event('articles_deleted', '', 0, $selected); callback_event('multi_edited.articles', 'delete', 0, compact('selected', 'field', 'value')); update_lastmod('articles_deleted', $selected); now('posted', true); now('expires', true); return list_list(messenger('article', join(', ', $selected), 'deleted')); } return list_list(); break; // Change author. // Change author. case 'changeauthor': $value = ps('AuthorID'); if (has_privs('article.edit') && in_array($value, $all_authors, true)) { $field = 'AuthorID'; } break; // Change category1. // Change category1. case 'changecategory1': $value = ps('Category1'); if (in_array($value, $categories, true)) { $field = 'Category1'; } break; // Change category2. // Change category2. case 'changecategory2': $value = ps('Category2'); if (in_array($value, $categories, true)) { $field = 'Category2'; } break; // Change comment status. // Change comment status. case 'changecomments': $field = 'Annotate'; $value = (int) ps('Annotate'); break; // Change section. // Change section. case 'changesection': $value = ps('Section'); if (in_array($value, $all_sections, true)) { $field = 'Section'; } break; // Change status. // Change status. case 'changestatus': $value = (int) ps('Status'); if (array_key_exists($value, $statuses)) { $field = 'Status'; } if (!has_privs('article.publish') && $value >= STATUS_LIVE) { $value = STATUS_PENDING; } break; } $selected = safe_rows("ID, AuthorID, Status", 'textpattern', "ID IN (" . join(',', $selected) . ")"); foreach ($selected as $item) { if ($item['Status'] >= STATUS_LIVE && has_privs('article.edit.published') || $item['Status'] >= STATUS_LIVE && $item['AuthorID'] === $txp_user && has_privs('article.edit.own.published') || $item['Status'] < STATUS_LIVE && has_privs('article.edit') || $item['Status'] < STATUS_LIVE && $item['AuthorID'] === $txp_user && has_privs('article.edit.own')) { $allowed[] = $item['ID']; } } $selected = $allowed; if ($selected) { $message = messenger('article', join(', ', $selected), 'modified'); if ($edit_method === 'duplicate') { $rs = safe_rows_start("*", 'textpattern', "ID IN (" . join(',', $selected) . ")"); if ($rs) { while ($a = nextRow($rs)) { unset($a['ID'], $a['LastMod'], $a['LastModID'], $a['Expires']); $a['uid'] = md5(uniqid(rand(), true)); $a['AuthorID'] = $txp_user; foreach ($a as $name => &$value) { $value = "`{$name}` = '" . doSlash($value) . "'"; } if ($id = (int) safe_insert('textpattern', join(',', $a))) { safe_update('textpattern', "Title = CONCAT(Title, ' (', {$id}, ')'),\n url_title = CONCAT(url_title, '-', {$id}),\n Posted = NOW(),\n feed_time = NOW()", "ID = {$id}"); } } } $message = gTxt('duplicated_articles', array('{id}' => join(', ', $selected))); } elseif (!$field || safe_update('textpattern', "{$field} = '" . doSlash($value) . "'", "ID IN (" . join(',', $selected) . ")") === false) { return list_list(); } update_lastmod('articles_updated', compact('selected', 'field', 'value')); now('posted', true); now('expires', true); callback_event('multi_edited.articles', $edit_method, 0, compact('selected', 'field', 'value')); return list_list($message); } return list_list(); }
function list_multi_edit() { global $txp_user, $statuses, $all_cats, $all_authors, $all_sections; // Empty entry to permit clearing the categories $categories = array(''); foreach ($all_cats as $row) { $categories[] = $row['name']; } $selected = ps('selected'); if (!$selected or !is_array($selected)) { return list_list(); } $selected = array_map('assert_int', $selected); $method = ps('edit_method'); $changed = false; $ids = array(); $key = ''; if ($method == 'delete') { if (!has_privs('article.delete')) { $allowed = array(); if (has_privs('article.delete.own')) { $allowed = safe_column_num('ID', 'textpattern', 'ID in(' . join(',', $selected) . ') and AuthorID=\'' . doSlash($txp_user) . '\''); } $selected = $allowed; } foreach ($selected as $id) { if (safe_delete('textpattern', "ID = {$id}")) { $ids[] = $id; } } $changed = join(', ', $ids); if ($changed) { safe_update('txp_discuss', "visible = " . MODERATE, "parentid in({$changed})"); callback_event('articles_deleted', '', 0, $ids); } } else { $selected = safe_rows('ID, AuthorID, Status', 'textpattern', 'ID in (' . implode(',', $selected) . ')'); $allowed = array(); foreach ($selected as $item) { if ($item['Status'] >= STATUS_LIVE and has_privs('article.edit.published') or $item['Status'] >= STATUS_LIVE and $item['AuthorID'] == $txp_user and has_privs('article.edit.own.published') or $item['Status'] < STATUS_LIVE and has_privs('article.edit') or $item['Status'] < STATUS_LIVE and $item['AuthorID'] == $txp_user and has_privs('article.edit.own')) { $allowed[] = $item['ID']; } } $selected = $allowed; unset($allowed); switch ($method) { // change author case 'changeauthor': $val = has_privs('article.edit') ? ps('AuthorID') : ''; if (in_array($val, $all_authors)) { $key = 'AuthorID'; } break; // change category1 // change category1 case 'changecategory1': $val = ps('Category1'); if (in_array($val, $categories)) { $key = 'Category1'; } break; // change category2 // change category2 case 'changecategory2': $val = ps('Category2'); if (in_array($val, $categories)) { $key = 'Category2'; } break; // change comments // change comments case 'changecomments': $key = 'Annotate'; $val = (int) ps('Annotate'); break; // change section // change section case 'changesection': $val = ps('Section'); if (in_array($val, $all_sections)) { $key = 'Section'; } break; // change status // change status case 'changestatus': $val = (int) ps('Status'); if (array_key_exists($val, $statuses)) { $key = 'Status'; } if (!has_privs('article.publish') && $val >= STATUS_LIVE) { $val = STATUS_PENDING; } break; default: $key = ''; $val = ''; break; } if ($selected and $key) { foreach ($selected as $id) { if (safe_update('textpattern', "{$key} = '" . doSlash($val) . "'", "ID = {$id}")) { $ids[] = $id; } } $changed = join(', ', $ids); } } if ($changed) { update_lastmod(); return list_list(messenger('article', $changed, $method == 'delete' ? 'deleted' : 'modified')); } return list_list(); }