gTxt('draft'), 2 => gTxt('hidden'), 3 => gTxt('pending'), 4 => strong(gTxt('live')), 5 => gTxt('sticky'), ); if (!empty($event) and $event == 'article') { require_privs('article'); $save = gps('save'); if ($save) $step = 'save'; $publish = gps('publish'); if ($publish) $step = 'publish'; switch(strtolower($step)) { case "": article_edit(); break; case "create": article_edit(); break; case "publish": article_post(); break; case "edit": article_edit(); break; case "save": article_save(); break; } } //-------------------------------------------------------------- function article_post() { global $txp_user, $vars, $txpcfg, $prefs; extract($prefs); $incoming = psa($vars); $message=''; $incoming = textile_main_fields($incoming, $use_textile); extract(doSlash($incoming)); extract(array_map('assert_int', psa(array( 'Status', 'textile_body', 'textile_excerpt')))); $Annotate = (int) $Annotate; if ($publish_now==1) { $when = 'now()'; $when_ts = time(); } else { $when = $when_ts = strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second)-tz_offset(); $when = "from_unixtime($when)"; } $Keywords = doSlash(trim(preg_replace('/( ?[\r\n\t,])+ ?/s', ',', preg_replace('/ +/', ' ', ps('Keywords'))), ', ')); if (empty($exp_year)) { $expires = 0; $whenexpires = NULLDATETIME; } else { if(empty($exp_month)) $exp_month=1; if(empty($exp_day)) $exp_day=1; if(empty($exp_hour)) $exp_hour=0; if(empty($exp_minute)) $exp_minute=0; if(empty($exp_second)) $exp_second=0; $expires = strtotime($exp_year.'-'.$exp_month.'-'.$exp_day.' '. $exp_hour.':'.$exp_minute.':'.$exp_second)-tz_offset(); $whenexpires = "from_unixtime($expires)"; } if ($expires) { if ($expires <= $when_ts) { article_edit(gTxt('article_expires_before_postdate')); return; } } if ($Title or $Body or $Excerpt) { if (!has_privs('article.publish') && $Status>=4) $Status = 3; if (empty($url_title)) $url_title = stripSpace($Title_plain, 1); safe_insert( "textpattern", "Title = '$Title', Body = '$Body', Body_html = '$Body_html', Excerpt = '$Excerpt', Excerpt_html = '$Excerpt_html', Image = '$Image', Keywords = '$Keywords', Status = $Status, Posted = $when, Expires = $whenexpires, LastMod = now(), AuthorID = '$txp_user', Section = '$Section', Category1 = '$Category1', Category2 = '$Category2', textile_body = $textile_body, textile_excerpt = $textile_excerpt, Annotate = $Annotate, override_form = '$override_form', url_title = '$url_title', AnnotateInvite = '$AnnotateInvite', custom_1 = '$custom_1', custom_2 = '$custom_2', custom_3 = '$custom_3', custom_4 = '$custom_4', custom_5 = '$custom_5', custom_6 = '$custom_6', custom_7 = '$custom_7', custom_8 = '$custom_8', custom_9 = '$custom_9', custom_10 = '$custom_10', uid = '".md5(uniqid(rand(),true))."', feed_time = now()" ); $GLOBALS['ID'] = mysql_insert_id(); if ($Status>=4) { do_pings(); update_lastmod(); } article_edit( get_status_message($Status).check_url_title($url_title) ); } else article_edit(); } //-------------------------------------------------------------- function article_save() { global $txp_user, $vars, $txpcfg, $prefs; extract($prefs); $incoming = psa($vars); $oldArticle = safe_row('Status, url_title, Title, unix_timestamp(LastMod) as sLastMod, LastModID','textpattern','ID = '.(int)$incoming['ID']); if (! ( ($oldArticle['Status'] >= 4 and has_privs('article.edit.published')) or ($oldArticle['Status'] >= 4 and $incoming['AuthorID']==$txp_user and has_privs('article.edit.own.published')) or ($oldArticle['Status'] < 4 and has_privs('article.edit')) or ($oldArticle['Status'] < 4 and $incoming['AuthorID']==$txp_user and has_privs('article.edit.own')))) { // Not allowed, you silly rabbit, you shouldn't even be here. // Show default editing screen. article_edit(); return; } if ($oldArticle['sLastMod'] != $incoming['sLastMod']) { article_edit(gTxt('concurrent_edit_by', array('{author}' => htmlspecialchars($oldArticle['LastModID']))), TRUE); return; } $incoming = textile_main_fields($incoming, $use_textile); extract(doSlash($incoming)); extract(array_map('assert_int', psa(array('ID', 'Status', 'textile_body', 'textile_excerpt')))); $Annotate = (int) $Annotate; if (!has_privs('article.publish') && $Status>=4) $Status = 3; if($reset_time) { $whenposted = "Posted=now()"; $when_ts = time(); } else { $when = $when_ts = strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second)-tz_offset(); $whenposted = "Posted=from_unixtime($when)"; } if (empty($exp_year)) { $expires = 0; $whenexpires = "Expires=".NULLDATETIME; } else { if(empty($exp_month)) $exp_month=1; if(empty($exp_day)) $exp_day=1; if(empty($exp_hour)) $exp_hour=0; if(empty($exp_minute)) $exp_minute=0; if(empty($exp_second)) $exp_second=0; $expires = strtotime($exp_year.'-'.$exp_month.'-'.$exp_day.' '.$exp_hour.':'.$exp_minute.':'.$exp_second)-tz_offset(); $whenexpires = "Expires=from_unixtime($expires)"; } if ($expires) { if ($expires <= $when_ts) { article_edit(gTxt('article_expires_before_postdate')); return; } } //Auto-Update custom-titles according to Title, as long as unpublished and NOT customized if ( empty($url_title) || ( ($oldArticle['Status'] < 4) && ($oldArticle['url_title'] == $url_title ) && ($oldArticle['url_title'] == stripSpace($oldArticle['Title'],1)) && ($oldArticle['Title'] != $Title) ) ) { $url_title = stripSpace($Title_plain, 1); } $Keywords = doSlash(trim(preg_replace('/( ?[\r\n\t,])+ ?/s', ',', preg_replace('/ +/', ' ', ps('Keywords'))), ', ')); safe_update("textpattern", "Title = '$Title', Body = '$Body', Body_html = '$Body_html', Excerpt = '$Excerpt', Excerpt_html = '$Excerpt_html', Keywords = '$Keywords', Image = '$Image', Status = $Status, LastMod = now(), LastModID = '$txp_user', Section = '$Section', Category1 = '$Category1', Category2 = '$Category2', Annotate = $Annotate, textile_body = $textile_body, textile_excerpt = $textile_excerpt, override_form = '$override_form', url_title = '$url_title', AnnotateInvite = '$AnnotateInvite', custom_1 = '$custom_1', custom_2 = '$custom_2', custom_3 = '$custom_3', custom_4 = '$custom_4', custom_5 = '$custom_5', custom_6 = '$custom_6', custom_7 = '$custom_7', custom_8 = '$custom_8', custom_9 = '$custom_9', custom_10 = '$custom_10', $whenposted, $whenexpires", "ID = $ID" ); if($Status >= 4) { if ($oldArticle['Status'] < 4) { do_pings(); } update_lastmod(); } article_edit( get_status_message($Status).check_url_title($url_title) ); } //-------------------------------------------------------------- function article_edit($message = '', $concurrent = FALSE) { global $vars, $txp_user, $comments_disabled_after, $txpcfg, $prefs; extract($prefs); extract(gpsa(array('view','from_view','step'))); if(!empty($GLOBALS['ID'])) { // newly-saved article $ID = $GLOBALS['ID']; $step = 'edit'; } else { $ID = gps('ID'); } include_once txpath.'/lib/classTextile.php'; $textile = new Textile(); // switch to 'text' view upon page load and after article post if(!$view || gps('save') || gps('publish')) { $view = 'text'; } if (!$step) $step = "create"; if ($step == "edit" && $view=="text" && !empty($ID) && $from_view != 'preview' && $from_view != 'html' && !$concurrent) { $pull = true; //-- it's an existing article - off we go to the db $ID = assert_int($ID); $rs = safe_row( "*, unix_timestamp(Posted) as sPosted, unix_timestamp(Expires) as sExpires, unix_timestamp(LastMod) as sLastMod", "textpattern", "ID=$ID" ); extract($rs); $reset_time = $publish_now = ($Status < 4); } else { $pull = false; //-- assume they came from post if ($from_view=='preview' or $from_view=='html') { $store_out = array(); $store = unserialize(base64_decode(ps('store'))); foreach($vars as $var) { if (isset($store[$var])) $store_out[$var] = $store[$var]; } } else { $store_out = gpsa($vars); if ($concurrent) { $store_out['sLastMod'] = safe_field('unix_timestamp(LastMod) as sLastMod', 'textpattern', 'ID='.$ID); } } extract($store_out); } $GLOBALS['step'] = $step; if ($step == 'create') { $textile_body = $use_textile; $textile_excerpt = $use_textile; } if ($step!='create') { // Previous record? $prev_id = checkIfNeighbour('prev',$sPosted); // Next record? $next_id = checkIfNeighbour('next',$sPosted); } $page_title = ($Title) ? $Title : gTxt('write'); pagetop($page_title, $message); echo n.n.'
'; } // ------------------------------------------------------------- function custField($num, $field, $content) { return n.n.graf(''.br. n.fInput('text', 'custom_'.$num, $content, 'edit', '', '', 22, '', 'custom-'.$num)); } // ------------------------------------------------------------- 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"); } //-------------------------------------------------------------- // remember to show markup help for both body and excerpt // if they are different function side_help($textile_body, $textile_excerpt) { if ($textile_body == USE_TEXTILE or $textile_excerpt == USE_TEXTILE) { return n.hed( ''.gTxt('textile_help').'' , 3, ' class="plain"'). n.' '; } } //-------------------------------------------------------------- function status_radio($Status) { global $statuses; $Status = (!$Status) ? 4 : $Status; foreach ($statuses as $a => $b) { $out[] = n.t.'