这些功能有什么问题?

我正在为一个电视wordpress网站(www.canal-en-vivo.com)工作几个php函数,该函数根据频道Feed是否存在,将帖子(即频道)的状态从已发布改为草稿。 我把以下两个函数放在一起,但它们似乎不起作用。 你们可以看看通用的代码结构,让我知道如果你看到结构有点怪异吗?

此功能通过检查URL“$ feedurlstr”来确定Feed是否存活

// This function determines whether a given post/channel is live or not 
// based on whether url $feedurlstr has $string in it.

    function LiveOrNot($feedurlstr) {
        global $result;
        // create curl resource
        $ch = curl_init();
        // set url
        curl_setopt($ch, CURLOPT_URL, $feedurlstr);
        //return the transfer as a string
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // $output contains the output string
        $output = curl_exec($ch);
        // close curl resource to free up system resources
        curl_close($ch);      

        $string = "PP['channel_live'] = true";
        if(strstr($output,$string)) {
        $result = "live";
        } else {
        $result = "notlive";
        }
        return $result;
    }

这个函数运行一个SQL查询,它根据前一个函数是否返回$ result为live或notlive来更改每个帖子的状态。

// Function runs SQL query based on channel status $result

    function RunChannelLiveQuery() {
        global $key;
        global $post_ids;
        $key = 'feed';
        // This array includes the Post ID to be checked
        $post_ids = array(2263, 2249); 

        foreach ($post_ids as $id) {
        // Wordpress function to pull value out of a "custom field" - spits URL
            $feedurl = get_post_custom_values($key, $id);
            // turns $feedurl into string
            $feedurlstr = implode($feedurl);
            // Find whether feed is live or not
            LiveOrNot($feedurlstr);

            // Performs DB Query based on live or not
            if ( $result == "live" ) {
                mysql_query ("UPDATE 'wp_posts' SET 'post_status' = 'publish' WHERE 'post_id' = '$id'") or die(mysql_error());
            }
            if ( $result == "notlive" ) {
                mysql_query ("UPDATE 'wp_posts' SET 'post_status' = 'draft' WHERE 'post_id' = '$id'") or die(mysql_error());
            }
        }
    }

关于这些功能团伙可能出错的任何想法?


尝试这个:

LiveOrNot()函数中删除该行

global $result;

并在RunChannelLiveQuery()中 ,替换

LiveOrNot($feedurlstr);

通过

$result = LiveOrNot($feedurlstr);

尽管这不是必需的,但您可能希望使用Wordpress API来更新发布状态

链接地址: http://www.djcxy.com/p/69655.html

上一篇: What is wrong with these functions?

下一篇: Locking in PHP to acheive a crtitical section