0

有没有办法可以设置一个 cron 在我的 Drupal 站点上运行视图?我有一个 jQuery 脚本,我想每小时运行一次。

我试过了;

php http://mysite/myview

但我想我离题了。我明白了;

Could not open input file: 

这是我在我的 rss 提要中使用的 js;

// $Id
(function ($) {
Drupal.behaviors.tweetcast = {

attach: function (context, settings) {

$('div.tagspeak:not(.tags-processed)', context).addClass('tags-processed').each(function () {

var mynid, sinceid, updateinfo, sinceurl, author, tweethtml;
var currentsinceid = $('.currentsinceid').val();

var firstring = $(this).html();
var twostring = firstring.replace(/\s/g,'').replace(/^%20OR%20/gim,'').replace(/%20OR$/gim,'').replace(/%20OR%20%$/gim,'').replace(/%20OR%20$/gim,'').replace(/%$/gim,'').replace(/%20OR$/gim,'').toLowerCase();  
var threestring = twostring.replace(/%20or%20/gim,'%20OR%20');
$(this).text(threestring);
var fourstring = threestring.replace(/%20OR%20/gim,' ');
var fivestring = fourstring.replace(/%23/gim,'#');

$(this).closest('.views-row').append('<div class="views-field views-field-replies"></div>');    
tweethtml = $(this).closest('.views-row').find('div.views-field-replies').eq(0);

var twitter_api_url = 'http://search.twitter.com/search.json';
$.ajaxSetup({ cache: true });

$.getJSON( twitter_api_url + '?callback=?&rpp=1&q=' + threestring + '&since_id=' + currentsinceid, function(data) {
$.each(data.results, function(i, tweet) {console.log(tweet);

    if(tweet.text !== undefined) {

    var tweet_html = '<div class="tweetuser">' + tweet.from_user + '</div>';
    tweet_html  += ' <div class="sinceid">' + tweet.id + '</div>';
    tweethtml.append(tweet_html);

    }
});
});
    $.fn.delay = function(time, callback){
    jQuery.fx.step.delay = function(){};
    return this.animate({delay:1}, time, callback);
    }

    $(this).delay(2000, function(){
    title = $(this).closest('.views-row').find('div.views-field-title').eq(0).find('span.field-content').text();
    link = $(this).closest('.views-row').find('div.views-field-path').eq(0).find('span.field-content').text();
    author = $(this).closest('.views-row').find('div.tweetuser').eq(0).text();
    mynid = $(this).closest('.views-row').find('div.mynid').text();
    sinceid = $(this).closest('.views-row').find('div.sinceid').eq(0).text();
    updateinfo = {sinceid: sinceid, mynid: mynid, author: author, title: title, link: link, tags: fivestring};
    sinceurl = Drupal.settings.basePath + 'sinceid';

    $.ajax({
    type: "POST",
    url: sinceurl,
    data: updateinfo,
    success: function(){}
    });
    });
});
}}
})
(jQuery);

这是 php 我的模块;

<?php
// $id:
function sinceid_menu() {
  $items = array();
  $items['sinceid'] = array(
  'title' => 'sinceid',
  'page callback' => 'sinceid_count',
  'description' => 'sinceid',
  'access arguments' => array('access content'),
  'type' => MENU_CALLBACK,
  );
return $items;
}
function sinceid_count() 
{
$sinceid=$_POST['sinceid'];
$mynid=$_POST['mynid'];
$author=$_POST['author'];
$title=$_POST['title'];
$link=$_POST['link'];
$tags=$_POST['tags'];

db_update('node')
->expression('sinceid', $sinceid)
->condition('nid', $mynid)
->execute();

$sql = db_query("SELECT author FROM {authordupe} WHERE author = $author");
$result = db_query($sql);
$how_many_rows = $result->rowCount();
if($how_many_rows == 0) {

db_insert('authordupe')
->fields(array(
'author' => $author,
'title' => $title,
'link' => $link,
'tags' => $tags,
))
->execute();



}   
}
4

1 回答 1

1

在 Drupal 中运行视图的基本代码是

$view = views_get_view('<your_view_machine_name>');
$view->set_display('<optional_display_name>');
$view->execute();

也就是说,您说有一个在视图中运行的 jQuery 脚本。严重地?你的脚本在做什么?我会说当您希望在客户端运行脚本时最好使用 jQuery。您不能编写 php 代码来完成您需要的任何事情并将其放入 cron 钩子中吗?

于 2013-04-15T17:26:52.650 回答