function emit_core() { $ae =& $this->submitted; /* $actions = array(); if($ae->expected_journo && $ae->article) { $actions[] = 'add_journo'; $actions[] = 'replace_journo'; } */ $struck = false; if ($ae->status == 'resolved' || $ae->status == 'rejected') { $struck = true; } ?> <?php if ($struck) { ?> <del> <?php } ?> <small>submitted <?php echo pretty_date(strtotime($ae->when_submitted)); ?> <?php if (!is_null($ae->submitted_by)) { ?> by <a href="/adm/useraccounts?person_id=<?php echo $ae->submitted_by->id; ?> "><?php echo $ae->submitted_by->email; ?> </a> (<?php echo $ae->submitted_by->name; ?> ) <?php } ?> </small> <br/> <a href="<?php echo $ae->url; ?> "><?php echo $ae->url; ?> </a><br/> problem: <?php echo $ae->status; ?> <br/> <?php if (!is_null($ae->article)) { ?> article in the database: <a href="<?php echo article_adm_url($ae->article->id); ?> "><?php echo $ae->article->title; ?> </a> <a class="button edit" href="/adm/editarticle?id36=<?php echo article_id_to_id36($ae->article->id); ?> ">edit</a><br/> <?php if (sizeof($ae->article->authors) > 0) { ?> attributed to: <?php foreach ($ae->article->authors as $author) { echo admJournoLink($author->ref); ?> <?php } } ?> <br/> raw byline: <?php echo $ae->article->byline; ?> <br/> <?php } ?> <?php if (!is_null($ae->expected_journo)) { ?> expected journo: <a class="journo-info" href="/adm/<?php echo $ae->expected_journo->ref; ?> "><?php echo $ae->expected_journo->ref; ?> </a><br/> <?php } ?> <?php if (!is_null($this->scraper_output)) { ?> <div> raw scraper output: <pre><code> <?php echo admMarkupPlainText($this->scraper_output); ?> </code></pre> </div> <?php } ?> <?php if ($struck) { ?> </del> <?php } ?> <?php foreach ($this->allowed_actions() as $action) { echo $this->action_link($action); } ?> <?php }
function article_collect($article_id, $sim_orderby = 'score', $sim_showall = 'no') { $art = db_getRow('SELECT * FROM article WHERE id=?', $article_id); if (is_null($art)) { return null; } $art['article_id'] = $art['id']; $art['id36'] = article_id_to_id36($art['id']); $art['blog_links'] = db_getAll("SELECT * FROM article_bloglink WHERE article_id=? ORDER BY linkcreated DESC", $article_id); // journos $sql = <<<EOT SELECT j.prettyname, j.ref FROM ( journo j INNER JOIN journo_attr attr ON j.id=attr.journo_id ) WHERE attr.article_id=? AND j.status='a'; EOT; $art['journos'] = db_getAll($sql, $article_id); $art['byline'] = article_markup_byline($art['byline'], $art['journos']); $orginfo = db_getRow("SELECT * FROM organisation WHERE id=?", $art['srcorg']); $art['srcorgname'] = $orginfo['prettyname']; $art['sop_name'] = $orginfo['sop_name']; $art['sop_url'] = $orginfo['sop_url']; $art['srcorg_url'] = $orginfo['home_url']; $permalink = $art['permalink']; $d = new datetime($art['pubdate']); $art['pretty_pubdate'] = pretty_date(strtotime($art['pubdate'])); $art['iso_pubdate'] = $d->format('c'); $art['buzz'] = BuzzFragment($art); /* similar articles */ if ($sim_orderby == 'date') { $ord = 'a.pubdate DESC, s.score DESC'; } else { // 'score' $ord = 's.score DESC, a.pubdate DESC'; } $sql = <<<EOT SELECT a.id,a.title, a.srcorg,a.byline,a.permalink,a.pubdate FROM article a INNER JOIN article_similar s ON s.other_id=a.id WHERE s.article_id=? and a.status='a' ORDER BY {$ord} EOT; /* only the first 10 by default */ if ($sim_showall != 'yes') { $sql .= " LIMIT 10"; } $sim_arts = db_getAll($sql, $article_id); foreach ($sim_arts as &$s) { article_augment($s); } unset($s); $art['sim_orderby'] = $sim_orderby; $art['sim_showall'] = $sim_showall; $art['sim_arts'] = $sim_arts; $tags = db_getAll('SELECT tag, freq FROM article_tag WHERE article_id=? ORDER BY freq DESC', $article_id); $sorted_tags = array(); foreach ($tags as $t) { $sorted_tags[$t['tag']] = intval($t['freq']); } ksort($sorted_tags); $art['tags'] = $sorted_tags; $art['comment_links'] = article_collect_commentlinks($article_id); return $art; }
function view() { $art_id = null; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $f = new ArticleModelForm($_POST, array(), array()); if ($f->is_valid()) { $art = $f->save(); db_commit(); // redirect to prevent multiple POSTs $url = sprintf("http://%s/adm/article/%s", $_SERVER['HTTP_HOST'], article_id_to_id36($art['id'])); header("HTTP/1.1 303 See Other"); header("Location: {$url}"); return; } } else { // handle either base-10 or base-36 article ids $art_id = get_http_var('id36'); if ($art_id) { $art_id = article_id36_to_id($art_id); } else { $art_id = get_http_var('id'); } if ($art_id) { $f = ArticleModelForm::from_db($art_id); } else { $initial = array(); if (isset($_GET['url'])) { $initial['permalink'] = $_GET['url']; } if (isset($_GET['journo'])) { $initial['authors'] = $_GET['journo']; } $f = new ArticleModelForm(null, null, array('initial' => $initial)); $art_id = null; } } $v = array('form' => $f, 'art_id' => $art_id); template($v); }
function article_url($article_id, $sim_orderby = 'score', $sim_showall = 'no') { $id36 = article_id_to_id36($article_id); $url = "/article/{$id36}"; $extra = array(); if (strtolower($sim_orderby) == 'date') { $extra[] = 'sim_orderby=date'; } if (strtolower($sim_showall) == 'yes') { $extra[] = 'sim_showall=yes'; } if ($extra) { $url = $url . "?" . implode('&', $extra); } return $url; }
$time_fields = array('pubdate', 'content_scraped'); while ($row = db_fetch_array($r)) { $out = array_cherrypick($row, $fields); // add source publication info $source = array('id' => $row['srcorg'], 'shortname' => $row['shortname'], 'prettyname' => $row['prettyname'], 'home_url' => $row['home_url']); $out['source'] = $source; // sanitize the timestamps foreach ($time_fields as $tf) { $dt = new DateTime($out[$tf]); $out[$tf] = $dt->format('Y-m-d\\TH:i:s.uO'); } $results[] = $out; } // go through and add in id36 and journo data to articles foreach ($results as &$art) { $art['id36'] = article_id_to_id36($art['id']); $sql = <<<EOT SELECT j.prettyname, j.ref FROM ( journo j INNER JOIN journo_attr attr ON j.id=attr.journo_id ) WHERE attr.article_id=? AND j.status='a'; EOT; $journos = array(); foreach (db_getAll($sql, $art['id']) as $j) { $journos[] = array('ref' => $j['ref'], 'prettyname' => $j['prettyname']); } $art['journos'] = $journos; } } catch (Exception $e) { $details = $e->getMessage(); $status = -1; }
function EmitArticle($art) { $orgs = get_org_names(); $orgname = $orgs[$art['srcorg']]; $sql = <<<EOT SELECT a.id, a.title, a.pubdate, a.srcorg, s.score FROM (article_similar s INNER JOIN article a ON a.id=s.other_id ) WHERE s.article_id=? ORDER BY s.score DESC EOT; $similar_articles = db_getAll($sql, $art['id']); foreach ($similar_articles as &$sim) { $sim['srcorgname'] = $orgs[$sim['srcorg']]; } unset($sim); $urls = db_getAll("SELECT url FROM article_url WHERE article_id=?", $art['id']); ?> <table border="1"> <tr><th>title</th><td><h2><?php echo $art['title']; ?> </h2><a class="button edit" href="/adm/editarticle?id36=<?php echo article_id_to_id36($art['id']); ?> ">edit article</a></td></tr> <tr><th>status</th><td><?php echo $art['status']; ?> </td></tr> <tr><th>id</th><td><?php echo $art['id']; ?> [<a href="<?php echo article_url($art['id']); ?> ">go to article page</a>] <tr><th>srcorg</th><td><?php echo $orgname; ?> (id <?php echo $art['srcorg']; ?> )</td></tr> <tr><th>urls</th><td> permalink: <a href="<?php echo $art['permalink']; ?> "><?php echo $art['permalink']; ?> </a><br/> srcurl: <a href="<?php echo $art['srcurl']; ?> "><?php echo $art['srcurl']; ?> </a><br/> all urls <?php echo sizeof($urls); ?> : <ul><?php foreach ($urls as $foo) { $url = $foo['url']; ?> <li><a href="<?php echo $url; ?> "><?php echo $url; ?> </a></li> <?php } ?> </ul> </td></tr> <tr><th>pubdate</th><td><?php echo $art['pubdate']; ?> </td></tr> <tr><th>lastscraped</th><td><?php echo $art['lastscraped']; ?> </td></tr> <tr><th>byline</th> <td> raw byline: "<?php echo $art['byline']; ?> "<br/> attributed to:<br/> <?php EmitAttribution($art); ?> </td> </tr> <tr><th>description</th><td><?php echo $art['description']; ?> </td></tr> <tr><th>srcid</th><td><?php echo $art['srcid']; ?> </td></tr> <tr><th>total_comments</th><td><?php echo $art['total_comments']; ?> </td></tr> <tr><th>total_bloglinks</th><td><?php echo $art['total_bloglinks']; ?> </td></tr> <tr><th>needs_indexing</th><td><?php echo $art['needs_indexing']; ?> </td></tr> <tr><th>last_similar</th><td><?php echo $art['last_similar']; ?> </td></tr> <tr><th>last_comment_check</th><td><?php echo $art['last_comment_check']; ?> </td></tr> <tr><th>images</th><td> <ul> <?php foreach ($art['images'] as $im) { ?> <li> <a href="<?php echo $im['url']; ?> "><?php echo $im['url']; ?> </a><br/> caption: <?php echo h($im['caption']); ?> <br/> credit: <?php echo h($im['credit']); ?> <br/> <?php } ?> </ul> </td> </table> <h2>content</h2> <?php if (is_null($art['content'])) { ?> <p> -- content not scraped -- </p> <?php } else { ?> <table border=1> <tr><th>displayed</th><th>source HTML</th></tr> <tr> <td width="50%"> <?php echo $art['content']; ?> </td> <td width="50%"> <?php $srchtml = htmlentities($art['content'], ENT_COMPAT, 'UTF-8'); $srchtml = str_replace("\n", "<br>\n", $srchtml); print $srchtml; ?> </td> </tr> </table> <?php } ?> <h2>similar articles</h2> <a href="/adm/article?id=<?php echo $art['id']; ?> &action=update_similar">Run similar-articles tool now</a> (to update the list)<br/> <table> <tr><th>score</th><th>other article</th></tr> <?php foreach ($similar_articles as $sim) { ?> <tr> <td><?php echo $sim['score']; ?> </td> <td> <a href="/adm/article?id=<?php echo $sim['id']; ?> "><?php echo $sim['title']; ?> </a>, <?php echo $sim['srcorgname']; ?> , <?php echo $sim['pubdate']; ?> </td> <?php } ?> </table> <?php }