Giter VIP home page Giter VIP logo

bearychathook4zentao's Introduction

bearychatHook4zentao

实现将禅道中的动态通知给bearychat

/path_to_zentao/module/action/ext/model/logHistory.php

<?php

/**
     * Log histories for an action.
     * 
     * @param  int    $actionID 
     * @param  array  $changes 
     * @access public
     * @return void
     */
    public function logHistory($actionID, $changes)
    {
        foreach($changes as $change) 
        {
            $change['action'] = $actionID;
            $result = $this->dao->insert(TABLE_HISTORY)->data($change)->exec();
			
			//bearychat notice
			$this->notifyBearychat($actionID, $change['new']);
        }
    }
	
	protected function notifyBearychat($actionID, $text) {
		$action = $this->dao->select('*')->from(TABLE_ACTION)
            ->where('id')->eq($actionID)
            ->fetch();
		
		$_actions = $this->loadModel('action')->transformActions(array($action));
		$action = $_actions[0];
		
		$title = strip_tags(sprintf("%s, %s <em>%s</em> %s %s %s。", $action->date, $action->actor, $action->actionLabel, $action->objectLabel, $action->objectName, 'http://'.(isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '')) . $action->objectLink));
		
		return $this->curlPostPayload2Bearychat($title, $text);//, 'project-' . $action->project . ''
	}
	
	protected function curlPostPayload2Bearychat($title, $text, $channel = 'pms') {
		
		$url = 'https://hook.bearychat.com/your_self_params';//简单的定义于此
		
		$str = array('payload' => json_encode(array('text' => $title, 'markdown' => true, 'channel' => $channel, 'attachments' => array(array('text' => strip_tags($text))))));//
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
		curl_setopt($ch, CURLOPT_TIMEOUT, 1);
		
		if (substr($url, 0, 8) == "https://")
		{
			$opt[CURLOPT_SSL_VERIFYHOST] = 1;
			$opt[CURLOPT_SSL_VERIFYPEER] = FALSE;
		}
		curl_setopt_array($ch, $opt);
		curl_exec($ch);
		curl_close($ch);
	}

bearychathook4zentao's People

Contributors

web3d avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.