function resolve_ids($idents) { /* build up map for all refs to translate them to id */ $refs = array(); $refmap = array(); $qs = array(); foreach ($idents as $ident) { if (!is_numeric($ident)) { $refs[] = $ident; $refmap[$ident] = null; $qs[] = '?'; } } if ($refmap) { // to db lookup to fetch IDs for the refs (any spurious refs will be left with a null id) $rows = db_getAll("SELECT ref,id FROM journo WHERE ref in (" . implode(',', $qs) . ")", $refs); foreach ($rows as $r) { $refmap[$r['ref']] = intval($r['id']); } } // now we can build up the finished list: $journo_ids = array(); foreach ($idents as $ident) { if (is_numeric($ident)) { $journo_ids[] = intval($ident); } else { $journo_ids[] = $refmap[$ident]; } } return $journo_ids; }
function api_getJournoArticles_invoke($params) { $offset = (int) $params['offset']; $limit = (int) $params['limit']; if (!$limit) { $limit = 100; } if (!$offset) { $offset = 0; } $j = $params['journo']; if (!$j) { api_error("required parameter 'journo' is missing"); return; } $jfield = is_numeric($j) ? 'id' : 'ref'; $sql = <<<EOT SELECT a.id, a.title, a.srcorg, a.permalink, a.description, a.pubdate FROM ((article a INNER JOIN journo_attr attr ON a.id=attr.article_id) INNER JOIN journo j ON j.id=attr.journo_id) WHERE a.status='a' AND j.status='a' AND j.{$jfield}=? ORDER BY a.pubdate DESC LIMIT ? OFFSET ? EOT; $articles = db_getAll($sql, $j, $limit, $offset); foreach ($articles as &$a) { $d = new DateTime($a['pubdate']); $a['pubdate'] = $d->format('c'); } $output = array('results' => $articles); api_output($output); }
function __construct($data, $files, $opts) { // get all publications this journo has written for, with article counts assert(array_key_exists('from_ref', $opts)); $from_ref = $opts['from_ref']; $pub_choices = array(); $sql = <<<EOT SELECT o.id, o.shortname, count(*) FROM (((organisation o INNER JOIN article a on o.id=a.srcorg) INNER JOIN journo_attr attr ON attr.article_id=a.id) INNER JOIN journo j ON j.id=attr.journo_id) WHERE j.ref=? GROUP BY o.id,o.shortname ORDER BY count DESC EOT; foreach (db_getAll($sql, $from_ref) as $row) { $pub_choices[$row['id']] = sprintf("%s (%d articles)", $row['shortname'], $row['count']); } $extra_opts = array('initial' => array('from_ref' => $from_ref)); $opts = array_merge($opts, $extra_opts); parent::__construct($data, array(), $opts); $this->error_css_class = 'errors'; $this->fields['from_ref'] = new CharField(array('max_length' => 200, 'required' => TRUE, 'label' => 'Journo to split', 'help_text' => 'eg fred-bloggs', 'readonly' => TRUE, 'validators' => array(array(new JournoValidator(), "execute")))); $this->fields['from_ref']->widget->attrs['readonly'] = TRUE; $this->fields['split_pubs'] = new MultipleChoiceField(array('label' => 'Publications to split off', 'help_text' => 'Articles from the ticked publications will be assigned over to the new journo', 'choices' => $pub_choices, 'widget' => 'CheckboxSelectMultiple')); $this->fields['to_ref'] = new CharField(array('widget' => new TextInput(array('class' => 'journo-lookup')), 'max_length' => 200, 'required' => FALSE, 'label' => 'Destination journo', 'help_text' => 'eg fred-bloggs or leave blank to create a new journo', 'validators' => array(array(new JournoValidator(), "execute")))); }
function fetch_art($art_id) { $art = article_collect($art_id); // journos (article_collect() only grabs active ones) $sql = <<<EOT SELECT j.prettyname, j.ref, j.status, j.oneliner FROM ( journo j INNER JOIN journo_attr attr ON j.id=attr.journo_id ) WHERE attr.article_id=? EOT; $art['journos'] = db_getAll($sql, $art_id); return $art; }
function expand_pubset($matches) { $pubset = $matches[2]; $pub_ids = db_getAll("SELECT m.pub_id FROM (pub_set_map m INNER JOIN pub_set s ON s.id=m.pub_set_id) WHERE s.name=?", $pubset); if (is_null($pub_ids)) { throw new Exception("Unknown pubset '" . $pubset . "'"); } $parts = array(); foreach ($pub_ids as $foo) { $parts[] = "srcorg:" . $foo['pub_id']; } return "(" . implode(' OR ', $parts) . ")"; }
function view() { $P = person_if_signed_on(); if (is_null($P)) { // only for logged-in users header("Location: /"); return; } /* they might have multiple profiles, thus option to specify one here */ $ref = strtolower(get_http_var('ref')); $journo = NULL; if ($ref) { $journo = db_getRow("SELECT * FROM journo WHERE ref=?", $ref); if (!$journo) { header("HTTP/1.0 404 Not Found"); return; } } if (is_null($journo)) { // no journo given - if person is logged on, see if they are associated with a journo (or journos) $editables = db_getAll("SELECT j.* FROM ( journo j INNER JOIN person_permission p ON p.journo_id=j.id) WHERE p.person_id=? AND p.permission='edit'", $P->id()); if (sizeof($editables) == 0) { header("Location: /"); return; } elseif (sizeof($editables) > 1) { /* let user pick which one... */ tmpl_pickjourno($editables); return; } else { // sizeof($editables) == 1 $journo = $editables[0]; // just one journo. } } // is this person allowed to edit this journo? if (!db_getOne("SELECT id FROM person_permission WHERE person_id=? AND journo_id=? AND permission='edit'", $P->id(), $journo['id'])) { // nope $journo = null; } if (!is_null($journo)) { header("Location: /{$journo['ref']}"); } else { header("Location: /f**k"); } }
function view() { page_header("", array('menupage' => 'cover')); // get most-recently-updated journos from event log $recently_updated = array(); $sql = <<<EOT SELECT j.ref AS journo_ref, j.prettyname as journo_prettyname, j.oneliner as journo_oneliner, min(now()-e.event_time) as when FROM event_log e LEFT JOIN journo j ON j.id=e.journo_id WHERE event_time>NOW()-interval '7 days' AND j.status='a' GROUP BY journo_ref, journo_prettyname, journo_oneliner ORDER BY min( now()-e.event_time) ASC LIMIT 10; EOT; $events = db_getAll($sql); foreach ($events as &$ev) { $recently_updated[] = array('ref' => $ev['journo_ref'], 'prettyname' => $ev['journo_prettyname'], 'oneliner' => $ev['journo_oneliner']); } include "../templates/frontpage.tpl.php"; page_footer(); }
function view() { if (!admCheckAccess()) { exit; } // should return error code? $j = get_http_var('j'); $j = strtolower($j); $journo = db_getRow("SELECT id,ref,prettyname,oneliner,status FROM journo WHERE ref=?", $j); if (is_null($journo)) { // TODO: 404 return; } $sql = <<<EOT SELECT p.id,p.email,p.name,perm.permission FROM person p INNER JOIN person_permission perm ON perm.person_id=p.id WHERE perm.permission='edit' AND perm.journo_id=? EOT; $users = db_getAll($sql, $journo['id']); $journo['arts'] = journo_collectArticles($journo, 5); $journo['num_arts'] = db_getOne("SELECT COUNT(*) FROM journo_attr WHERE journo_id=?", $journo['id']); $journo['linked_users'] = $users; template($journo); }
function emit_paper(&$paper) { $paper_id = $paper['id']; print "<h2>{$paper['name']}</h2>\n"; print "<p><em>{$paper['description']}</em></p>\n"; $criteria = db_getAll("SELECT * FROM custompaper_criteria_text WHERE paper_id=?", $paper_id); $queries = array(); foreach ($criteria as $c) { $queries[] = $c['query']; } print "<small>(articles matching \n"; foreach ($queries as $q) { print "\"<code>{$q}</code>\" "; } print " over the last 24 hours)</small>\n"; $end_dt = new DateTime('now', new DateTimeZone('UTC')); $start_dt = new DateTime('now', new DateTimeZone('UTC')); //$start_dt->modify( "-24 days" ); $start_dt->modify("-24 hours"); # print $d->format( DATE_RFC3339 ); $arts = xap_DoQueries($queries, $start_dt->format(DATE_RFC3339), $end_dt->format(DATE_RFC3339)); print "<hr>\n"; if ($arts) { foreach ($arts as $art) { $jl_link = "/article?id={$art['id']}"; $posted = PostedFragment($art); print "<div>\n"; print " <h3><a href=\"{$art['permalink']}\">{$art['title']}</a></h3>\n"; print " {$art['description']}<br/>\n"; print " {$posted} (<a href=\"{$jl_link}\">journalisted page</a>)<br/>\n"; print "</div>\n"; } } else { print "<p>No articles</p>\n"; } }
function api_findJournos_invoke($params) { $name = $params['name']; $offset = (int) $params['offset']; $limit = (int) $params['limit']; if (!$limit) { $limit = 100; } $order = 'lastname'; $orderfields = $order == 'firstname' ? 'firstname,lastname' : 'lastname,firstname'; $vals = array(); $sql = "SELECT id,ref,prettyname,firstname,lastname,oneliner FROM journo WHERE status='a'"; if ($name) { $sql .= " AND prettyname ILIKE( ? )"; $vals[] = "%{$name}%"; } $sql .= " ORDER BY {$orderfields}"; $sql .= " LIMIT ?"; $vals[] = $limit; $sql .= " OFFSET ?"; $vals[] = $offset; $output = array('results' => db_getAll($sql, $vals)); api_output($output); }
function list_publications() { $pubs = db_getAll("SELECT id,shortname,prettyname FROM organisation ORDER BY prettyname"); ?> <div class="main"> <div class="head"><h2>Publications</h2></div> <div class="body"> <ul> <?php foreach ($pubs as $pub) { ?> <li><?php echo publication_link($pub); ?> </li> <?php } ?> </ul> </div> <div class="foot"></div> </div> <!-- end main --> <?php }
function emit_details($person_id) { // general $p = db_getRow("SELECT * FROM person WHERE id=?", $person_id); $subscribed_to_newsletter = false; if (db_getOne("SELECT person_id FROM person_receives_newsletter WHERE person_id=?", $person_id)) { $subscribed_to_newsletter = true; } ?> <h3>viewing user: '******'email']; ?> '</h3> [<a href="/adm/useraccounts?person_id=<?php echo $person_id; ?> &action=changeemail">Change email address</a>]<br/> <br/> id: <?php echo $p['id']; ?> <br/> name: <?php echo $p['name'] ? $p['name'] : "-blank-"; ?> <br/> <?php if ($p['password']) { ?> Password is set <?php } else { ?> No password set<?php } ?> <br/> Logged in <?php echo $p['numlogins']; ?> times<br/> <?php // show newsletter subscription ?> <h4>newsletter</h4> status: <?php if ($subscribed_to_newsletter) { ?> <em>Subscribed</em> <small>[<a href="/adm/useraccounts?person_id=<?php echo $person_id; ?> &action=newsletter_unsubscribe">unsubscribe</a>]</small> <?php } else { ?> <em>not subscribed</em> <small>[<a href="/adm/useraccounts?person_id=<?php echo $person_id; ?> &action=newsletter_subscribe">subscribe</a>]</small> <?php } // show alerts $sql = <<<EOT SELECT a.id,j.ref,j.prettyname,j.oneliner FROM ((alert a INNER JOIN person p ON a.person_id=p.id) INNER JOIN journo j ON a.journo_id=j.id) WHERE p.id=?; EOT; $alerts = db_getAll($sql, $person_id); ?> <h4>alerts</h4> <?php echo sizeof($alerts); ?> alerts set up: <ul> <?php foreach ($alerts as $a) { ?> <li><?php echo admJournoLink($a['ref'], $a['prettyname']); ?> (<?php echo $a['oneliner']; ?> ) <a class="button delete" href="/adm/useraccounts?person_id=<?php echo $person_id; ?> &action=removealert&alert_id=<?php echo $a['id']; ?> ">remove</a></a> </li> <?php } ?> </ul> <h4>Permissions</h4> <?php // show permissions $sql = <<<EOT SELECT p.id, p.permission, j.ref as journo_ref FROM (person_permission p LEFT JOIN journo j ON j.id=p.journo_id) WHERE person_id=? EOT; $perms = db_getAll($sql, $person_id); if ($perms) { ?> <ul> <?php foreach ($perms as $perm) { ?> <li> Can <em><?php echo $perm['permission']; ?> </em> <?php echo is_null($perm['journo_ref']) ? '' : admJournoLink($perm['journo_ref']); ?> <small>[<a href="/adm/useraccounts?person_id=<?php echo $person_id; ?> &action=removeperm&perm_id=<?php echo $perm['id']; ?> ">remove</a>]</small> </li> <?php } ?> </ul> <?php } else { ?> <p>No permissions assigned</p> <?php } emit_addperm_form($person_id); ?> <h4>Generate a login link</h4> <p>This creates a link to allow a user to log in directly</p> <form method="POST" action="/adm/useraccounts"> <input type="hidden" name="person_id" value="<?php echo $person_id; ?> " /> <label for="login_dest">Login destination:</label> <select id="login_dest" name="login_dest"> <option selected value="/profile">/profile</option> <option value="/alert">/alert</option> </select> <button name="action" value="generate_token">Generate</button> </form> <?php }
function emit_popularalertsbox() { $sql = <<<EOT SELECT j.prettyname, j.ref, j.oneliner, count(j.ref) AS cnt FROM (journo j INNER JOIN alert a ON a.journo_id=j.id) GROUP BY j.ref,j.prettyname,j.oneliner ORDER BY cnt DESC LIMIT 10 EOT; $popular = db_getAll($sql); ?> <div class="box"> <div class="head"><h3>Popular alerts</h3></div> <div class="body"> <ul> <?php foreach ($popular as $j) { ?> <li> <a href="<?php echo '/' . $j['ref']; ?> "><?php echo $j['prettyname']; ?> </a> (<?php echo $j['oneliner']; ?> ) <small>[<a href="/alert?Add=1&j=<?php echo $j['ref']; ?> ">add</a>]</small> </li> <?php } ?> </ul> </div> <div class="foot"></div> </div> <?php }
function display() { $sql = <<<EOT SELECT a.id, a.admired_id, a.admired_name, j.prettyname, j.ref as admired_ref, j.oneliner FROM (journo_admired a LEFT JOIN journo j ON a.admired_id=j.id) WHERE a.journo_id=? EOT; $admired = db_getAll($sql, $this->journo['id']); ?> <h2>Which journalists do you recommend?</h2> <form class="admired" method="POST" action="<?php echo $this->pagePath; ?> "> <?php foreach ($admired as $a) { $this->emitEntry($a); } $this->emitEntry(null); // the template entry ?> <input type="hidden" name="ref" value="<?php echo $this->journo['ref']; ?> " /> <input type="hidden" name="action" value="submit" /> <div class="button-area"> <a class="add" href="#">Add a journalist</a><br/> <button class="submit" type="submit">Save changes</button> or <a href="/<?php echo $this->journo['ref']; ?> ">cancel</a> </div> </form> <?php }
function RedirectToOriginalDest($stash) { if (!is_null($stash)) { /* just pass them through to the page they actually wanted. */ stash_redirect($stash); /* NOTREACHED */ } else { $P = person_if_signed_on(); if ($P) { $editables = db_getAll("SELECT j.* FROM ( journo j INNER JOIN person_permission p ON p.journo_id=j.id) WHERE p.person_id=? AND p.permission='edit'", $P->id()); if (sizeof($editables) >= 1) { header("Location: /" . $editables[0]['ref']); exit; } } header("Location: /account"); exit; } }
function grab_articles($f, $o, $ot, $offset, $limit) { global $_time_intervals; global $_sortable_fields; list($conds, $params) = build_query($f); // make sure ordering params are sensible $o = strtolower($o); assert(in_array($o, $_sortable_fields)); $ot = strtolower($ot); assert($ot == 'asc' || $ot == 'desc'); $from_clause = " FROM (article a INNER JOIN organisation o ON o.id=a.srcorg)\n"; $where_clause = ''; if ($conds) { $where_clause = ' WHERE ' . implode(' AND ', $conds) . "\n"; } if ($o == 'publication') { $o = 'lower(o.prettyname)'; } if ($o == 'byline') { $o = 'lower(byline)'; } if ($o == 'title') { $o = 'lower(title)'; } $order_clause = sprintf(" ORDER BY %s %s\n", $o, $ot); $limit_clause = sprintf(" OFFSET %d LIMIT %d\n", $offset, $limit); $sql = "SELECT a.id,a.title,a.byline,a.description,a.permalink, a.pubdate, a.lastscraped, " . "o.id as pub_id, o.shortname as pub_shortname, o.prettyname as pub_name, o.home_url as pub_home_url\n" . $from_clause . $where_clause . $order_clause . $limit_clause; $arts = db_getAll($sql, $params); $sql = "SELECT COUNT(*)\n" . $from_clause . $where_clause; $total = intval(db_getOne($sql, $params)); return array(&$arts, $total); }
function view_claim() { $ref = strtolower(get_http_var('ref')); $iamwhoisay = get_http_var("iamwhoisay"); if (!$iamwhoisay) { // no confirmation box ticked... header("Location: /"); } $journo = db_getRow("SELECT * FROM journo WHERE ref=?", $ref); if (!$journo) { header("HTTP/1.0 404 Not Found"); return; } // we need them logged on first $P = person_register(array('reason_web' => "Register to claim your profile", 'reason_email' => "Register on Journalisted to claim your profile", 'reason_email_subject' => 'Register on Journalisted')); // TODO: show claim pending message if already claimed // has anyone already claimed this journo? $foo = db_getAll("SELECT journo_id FROM person_permission WHERE journo_id=? AND permission='edit'", $journo['id']); if ($foo) { // uhoh... tmpl_already_claimed($journo); return; } // OK - _claim_ the profile! db_do("DELETE FROM person_permission WHERE person_id=? AND journo_id=? AND permission='claimed'", $P->id, $journo['id']); db_do("INSERT INTO person_permission ( person_id,journo_id,permission) VALUES(?,?,?)", $P->id, $journo['id'], 'claimed'); db_commit(); // set persons name if blank // if( $P->name_or_blank() == '' ) { // $P->name( $journo['prettyname'] ); // (does a commit) // } if (!$P->has_password()) { // we'll use an password form which submits to /account instead of here. $passwordbox = new PasswordBox('/account'); } tmpl_welcome($journo, $passwordbox); }
public static function fetch_lots($journo_id = null, $status_filter = '') { $conds = array(); $params = array(); if ($status_filter == 'approved') { $conds[] = "l.approved=?"; $params[] = TRUE; } elseif ($status_filter == 'unapproved') { $conds[] = "l.approved=?"; $params[] = FALSE; } if (!is_null($journo_id)) { $conds[] = "l.journo_id=?"; $params[] = $journo_id; } $whereclause = ''; if ($conds) { $whereclause = ' WHERE ' . implode(' AND ', $conds); } $sql = <<<EOT SELECT l.*, j.ref AS journo_ref, j.prettyname as journo_prettyname FROM journo_weblink l JOIN journo j ON l.journo_id=j.id {$whereclause} \tORDER BY l.id EOT; return db_getAll($sql, $params); }
function journo_fetchRecentEvents($journo_id) { $sql = <<<EOT SELECT event_time, event_type, context_json FROM event_log WHERE journo_id=? AND event_time>NOW()-interval '12 hours' ORDER BY event_time DESC; EOT; $events = db_getAll($sql, $journo_id); foreach ($events as &$ev) { $ev['context'] = json_decode($ev['context_json'], TRUE); $ev['description'] = eventlog_Describe($ev); } return $events; }
function EmitOtherArticles($journo_id) { print "<h3>Other Articles (not covered by scrapers)</h3>\n"; $sql = <<<EOT SELECT * FROM journo_other_articles WHERE journo_id=? ORDER BY pubdate DESC EOT; $rows = db_getAll($sql, $journo_id); ?> <p><?php echo sizeof($rows); ?> other articles:</p> <table> <thead><tr><th>url</th><th>title</th><th>pubdate</th><th>publication</th><th>status</th><th></th></tr></thead> <tbody> <?php foreach ($rows as $row) { ?> <tr class="<?php echo $row['status'] == 'a' ? 'bio_approved' : 'bio_unapproved'; ?> "> <td><a href="<?php echo $row['url']; ?> "><?php echo $row['url']; ?> </a></td> <td><?php echo $row['title']; ?> </td> <td><?php $d = new DateTime($row['pubdate']); echo $d->format('Y-m-d H:i:s'); ?> </td> <td><?php echo $row['publication']; ?> </td> <td><?php echo $row['status']; ?> </td> <td> <a href="?action=remove_otherarticle_confirmed&journo_id=<?php echo $journo_id; ?> &otherarticle_id=<?php echo $row['id']; ?> ">remove</a> <?php if ($row['status'] == 'a') { ?> <a href="?action=disapprove_otherarticle&journo_id=<?php echo $journo_id; ?> &otherarticle_id=<?php echo $row['id']; ?> ">disapprove</a> <?php } else { ?> <a href="?action=approve_otherarticle&journo_id=<?php echo $journo_id; ?> &otherarticle_id=<?php echo $row['id']; ?> ">approve</a> <?php } ?> <td> </tr> <?php } ?> </tbody> </table> <?php /* NO MORE other articles please :-) <form method="post"> <input type="hidden" name="journo_id" value="<?php echo $journo_id; ?>" /> url: <input type="text" name="url" size="40" /> title: <input type="text" name="title" size="40" /><br/> pubdate (yyyy-mm-dd): <input type="text" name="pubdate" /> publication: <input type="text" name="publication" /><br/> <button type="submit" name="action" value="add_otherarticle">Add Other Article</button> </form> */ ?> <?php }
function news_RecentNews($limit = 5) { // recent newsletters $news = null; if (is_null($limit)) { $news = db_getAll("SELECT id,slug,kind,title,posted,date_from,date_to FROM news WHERE status='a' ORDER BY posted DESC"); } else { $news = db_getAll("SELECT id,slug,kind,title,posted,date_from,date_to FROM news WHERE status='a' ORDER BY posted DESC LIMIT ?", $limit); } foreach ($news as &$n) { news_AugmentItem($n); } unset($n); return $news; }
static function from_db($art_id) { $art = db_getRow("SELECT * FROM article WHERE id=?", $art_id); $date_fields = array('pubdate', 'lastscraped', 'firstseen', 'lastseen'); foreach ($date_fields as $f) { $art[$f] = new DrongoDateTime($art[$f]); } // $foo = db_getAll("SELECT j.ref FROM (journo_attr attr INNER JOIN journo j ON j.id=attr.journo_id) WHERE attr.article_id=?", $art_id); $authors = array(); foreach ($foo as $row) { $authors[] = $row['ref']; } $art['authors'] = join(',', $authors); return new ArticleModelForm($art); }
function __construct($journo, $blank = FALSE) { $this->journo = $journo; if (!$blank) { $this->url = get_http_var('url', ''); if ($this->url) { $this->url = clean_url($this->url); } // so we can detect if url is changed $this->prev_url = get_http_var('prev_url', ''); } if ($blank || !$this->url && !$this->prev_url) { $this->state = 'initial'; return; } $msg = is_sane_article_url($this->url); if (!is_null($msg)) { $this->errs['url'] = $msg; $this->state = 'bad_url'; return; } // article already in DB? $art_id = article_find($this->url); if (is_null($art_id)) { // nope - try and scrape it list($ret, $txt) = scrape_ScrapeURL($this->url, $this->journo['ref']); if ($ret != 0) { $this->errs['error_message'] = "Journa<i>listed</i> had problems reading this article"; $this->state = 'scrape_failed'; $this->_register_error(); return; } $arts = scrape_ParseOutput($txt); if (sizeof($arts) < 1) { $this->errs['error_message'] = "Journa<i>listed</i> had problems reading this article"; $this->state = 'scrape_failed'; $this->_register_error(); return; } $art_id = $arts[0]; } // if we get this far, $art_id will be set // fetch some basic details about the article $art = db_getRow("SELECT id,title,permalink,pubdate,srcorg FROM article WHERE id=?", $art_id); $sql = <<<EOT SELECT j.id,j.prettyname,j.ref FROM (journo j INNER JOIN journo_attr attr ON attr.journo_id=j.id) WHERE attr.article_id=? EOT; $journos = db_getAll($sql, $art_id); $art['journos'] = $journos; $this->article = $art; // attributed to the expected journo? $got_expected_journo = FALSE; foreach ($journos as $j) { if ($j['id'] == $this->journo['id']) { $got_expected_journo = TRUE; break; } } if ($got_expected_journo) { // all is well. $this->state = 'done'; return; } else { // $this->errs['error_message'] = "Journa<i>listed</i> had trouble reading the byline"; $this->state = 'journo_mismatch'; $this->_register_error(); return; } }
$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; } header('Content-type: application/json'); print json_encode(array('status' => $status, 'details' => $details, 'results' => $results));
function display() { $weblinks = null; if ($this->badSubmit) { $weblinks = $this->submitted; } else { $weblinks = db_getAll("SELECT * FROM journo_weblink WHERE kind NOT IN ('pingback','twitter') AND journo_id=? ORDER BY rank DESC", $this->journo['id']); } $home_url = ''; $twitter_name = ''; ?> <h2><?php echo $this->journo['prettyname']; ?> on the web</h2> <form class="weblink" method="POST" action="<?php echo $this->pagePath; ?> "> <?php foreach ($weblinks as $w) { $this->emitLinkFields($w); } $this->emitLinkFields(null); ?> <input type="hidden" name="ref" value="<?php echo $this->journo['ref']; ?> " /> <input type="hidden" name="action" value="submit" /> <div class="button-area"> <a class="add" href="#">Add a site</a><br/> <button class="submit" type="submit">Save changes</button> or <a href="/<?php echo $this->journo['ref']; ?> #tab-links">cancel</a> </div> </form> <p>Note: journa<i>listed</i> reserves the right to change or remove links</p> <?php }
function perform($params) { $sql = <<<EOT SELECT o.shortname, COUNT(*) FROM (article a INNER JOIN organisation o ON o.id=a.srcorg) WHERE a.status='a' AND a.pubdate >= date ? AND a.pubdate < (date ? + interval '24 hours') GROUP BY o.shortname ORDER BY COUNT DESC EOT; $rows = db_getAll($sql, $params['from_date'], $params['to_date']); collectColumns($rows); return $rows; }
<?php // missingarticles.php // admin page for scraping submitted articles // sigh... stupid php include-path trainwreck... chdir(dirname(dirname(__FILE__))); require_once '../conf/general'; require_once '../phplib/misc.php'; require_once '../../phplib/db.php'; require_once '../../phplib/utility.php'; require_once '../phplib/adm.php'; require_once 'missingarticle_widget.php'; admPageHeader("Missing Articles", "ExtraHead"); ?> <h2>Missing articles</h2> <p>User-submitted articles we <em>should</em> be able to scrape...</p> <?php $sql = "SELECT m.id,m.journo_id, j.ref, j.prettyname, j.oneliner, m.url, m.submitted, m.reason\n FROM missing_articles m LEFT JOIN journo j ON m.journo_id=j.id\n ORDER BY submitted DESC"; $rows = db_getAll($sql); foreach ($rows as $r) { $w = new MissingArticleWidget($r); $w->emit_full(); } admPageFooter(); function ExtraHead() { MissingArticleWidget::emit_head_js(); }
public static function fetch($filter = null, $offset = null, $limit = null) { $params = array(); $sel_part = self::$sql_select; $from_part = self::$sql_from; $where_part = "reason_code NOT IN ('rejected','resolved')"; if ($filter['expected_ref']) { $where_part .= " AND j.ref=?"; $params[] = $filter['expected_ref']; } $sql = <<<EOT SELECT {$sel_part} FROM {$from_part} WHERE {$where_part} ORDER BY e.submitted DESC EOT; if (!is_null($offset)) { $sql .= " OFFSET ?\n"; $params[] = $offset; } if (!is_null($limit)) { $sql .= " LIMIT ?\n"; $params[] = $limit; } $rows = db_getAll($sql, $params); $art_errs = array(); foreach ($rows as $row) { $sub = new SubmittedArticle(); $sub->from_db_row($row); $art_errs[] = $sub; } return $art_errs; }
function newsList() { $posts = db_getAll("SELECT id,status,title,slug,posted,author,kind,date_from,date_to FROM news ORDER BY posted DESC"); ?> <h2>News Posts</h2> <a href="/adm/news?action=create">Create a new post</a> <ul> <?php foreach ($posts as $p) { ?> <li class="<?php echo $p['status'] == 'a' ? 'approved' : 'unapproved'; ?> " > <?php if ($p['status'] == 'a') { ?> <strong><a href="/news/<?php echo $p['slug']; ?> "><?php echo $p['title']; ?> </a></strong> <?php } else { ?> <strong><?php echo $p['title']; ?> </strong> (unpublished) <?php } ?> <small>posted by <em><?php echo $p['author']; ?> </em>, <?php echo $p['posted']; ?> .</small> <br/> <a href="/adm/news?action=edit&id=<?php echo $p['id']; ?> ">[edit]</a> <small> <a href="/adm/news?action=delete&id=<?php echo $p['id']; ?> ">[delete]</a> </small> <br/> </li> <?php } ?> </ul> <?php }
function article_collect_commentlinks($article_id) { /* profile for various non-newspaper sites we source from - they all use their own terminology */ $profiles = array('digg' => array('scoreterm' => 'diggs', 'prettyname' => 'Digg'), 'reddit' => array('scoreterm' => 'points', 'prettyname' => 'Reddit'), 'newsvine' => array('scoreterm' => 'votes', 'prettyname' => 'Newsvine'), 'fark' => array('scoreterm' => 'votes', 'prettyname' => 'Fark'), 'del.icio.us' => array('scoreterm' => 'saves', 'prettyname' => 'del.icio.us'), 'DEFAULT' => array('scoreterm' => 'points', 'prettyname' => 'unknown')); /* add the newspapers to the list of profiles */ $orgs = db_getAll("SELECT shortname, prettyname FROM organisation"); foreach ($orgs as $o) { $profiles[$o['shortname']] = array('prettyname' => $o['prettyname'], 'scoreterm' => 'points'); } $comment_links = db_getAll("SELECT * FROM article_commentlink WHERE article_id=?", $article_id); foreach ($comment_links as &$c) { $source = $c['source']; $profile = $profiles['DEFAULT']; if (array_key_exists($source, $profiles)) { $profile = $profiles[$source]; } $bits = array(); if (!is_null($c['num_comments'])) { if ($c['num_comments'] > 0) { $bits[] = sprintf("%d comments", $c['num_comments']); } else { $bits[] = "no comments yet"; } } if ($c['score']) { $bits[] = sprintf("%d %s", $c['score'], $profile['scoreterm']); } $c['buzz'] = implode(', ', $bits); $c['source_prettyname'] = $profile['prettyname']; $c['source_scoreterm'] = $profile['scoreterm']; } return $comment_links; }