Example #1
0
 public static function build($className, DateTime $dt = null, TikiMail $tm = null, TikiLib $tikilib = null, $tikiPrefs = null)
 {
     $db = TikiDb::get();
     if (is_null($dt)) {
         $dt = new DateTime();
     }
     if (is_null($tm)) {
         $tm = new TikiMail();
     }
     if (is_null($tikilib)) {
         $tikilib = TikiLib::lib('tiki');
     }
     if (is_null($tikiPrefs)) {
         global $prefs;
         $tikiPrefs = $prefs;
     }
     switch ($className) {
         case 'Reports_Users':
             return new Reports_Users($db, $dt);
         case 'Reports_Cache':
             return new Reports_Cache($db, $dt);
         case 'Reports_Manager':
             global $userlib;
             return new Reports_Manager(Reports_Factory::build('Reports_Users', $dt, $tm, $tikilib), Reports_Factory::build('Reports_Cache', $dt, $tm, $tikilib), Reports_Factory::build('Reports_Send', $dt, $tm, $tikilib), $userlib);
         case 'Reports_Send':
             global $prefs;
             return new Reports_Send($dt, $tm, Reports_Factory::build('Reports_Send_EmailBuilder', $dt, $tm, $tikilib), $tikiPrefs);
         case 'Reports_Send_EmailBuilder':
             return new Reports_Send_EmailBuilder($tikilib, new Reports_Send_EmailBuilder_Factory());
         default:
             throw new Exception("Unknown class {$className}");
     }
 }
 protected function setUp()
 {
     $this->dt = new DateTime();
     $this->dt->setTimestamp(strtotime('2012-03-27 15:55:16'));
     $this->mail = $this->getMock('TikiMail');
     $this->tikilib = $this->getMock('TikiLib', array('get_user_preference'));
     $this->overrideLibs = new TestableTikiLib();
     $this->overrideLibs->overrideLibs(array('calendar' => $this->getMock('MockCalendarLib', array('get_item'))));
     $tikiPrefs = array('short_date_format' => '%Y-%m-%d');
     $this->obj = Reports_Factory::build('Reports_Manager', $this->dt, $this->mail, $this->tikilib, $tikiPrefs);
     parent::setUp();
 }
 function onContinue($homepageUrl)
 {
     global $tikilib, $user, $prefs;
     // Run the parent first
     parent::onContinue($homepageUrl);
     // Show if option is selected
     if ($prefs['feature_user_watches'] === 'y' && $prefs['feature_daily_report_watches'] === 'y') {
         $reportsManager = Reports_Factory::build('Reports_Manager');
         $interval = filter_input(INPUT_POST, 'interval', FILTER_SANITIZE_STRING);
         $view = filter_input(INPUT_POST, 'view', FILTER_SANITIZE_STRING);
         $type = filter_input(INPUT_POST, 'type', FILTER_SANITIZE_STRING);
         $always_email = filter_input(INPUT_POST, 'always_email', FILTER_SANITIZE_NUMBER_INT);
         if ($always_email != 1) {
             $always_email = 0;
         }
         $reportsManager->save($user, $interval, $view, $type, $always_email);
     }
 }
Example #4
0
 /**
  * @param $imageId
  * @param $galleryId
  * @param $name
  * @param $filename
  * @param $description
  * @param $galleryName
  * @param $action
  * @param $user
  */
 function notify($imageId, $galleryId, $name, $filename, $description, $galleryName, $action, $user)
 {
     global $prefs;
     if ($prefs['feature_user_watches'] == 'y') {
         $event = 'image_gallery_changed';
         $nots = $this->get_event_watches($event, $galleryId);
         if ($prefs['feature_daily_report_watches'] == 'y') {
             $reportsManager = Reports_Factory::build('Reports_Manager');
             $reportsManager->addToCache($nots, array("event" => $event, "imageId" => $imageId, "imageName" => $name, "fileName" => $filename, "galleryId" => $galleryId, "galleryName" => $galleryName, "action" => $action, "user" => $user));
         }
         $smarty = TikiLib::lib('smarty');
         include_once 'lib/notifications/notificationemaillib.php';
         $smarty->assign_by_ref('galleryId', $galleryId);
         $smarty->assign_by_ref('galleryName', $galleryName);
         $smarty->assign_by_ref('author', $user);
         $smarty->assign_by_ref('fname', $name);
         $smarty->assign_by_ref('filename', $filename);
         $smarty->assign_by_ref('description', $description);
         $smarty->assign_by_ref('imageId', $imageId);
         sendEmailNotification($nots, 'watch', 'user_watch_image_gallery_changed_subject.tpl', NULL, 'user_watch_image_gallery_upload.tpl');
     }
 }
Example #5
0
 public function testBuild_shouldThrowExceptionForUnknownClass()
 {
     $this->setExpectedException('Exception', 'Unknown class Unknown_Class');
     Reports_Factory::build('Unknown_Class');
 }
Example #6
0
 /**
  * @param $calitemId
  * @param $data
  */
 function watch($calitemId, $data)
 {
     global $prefs, $user;
     $smarty = TikiLib::lib('smarty');
     $tikilib = TikiLib::lib('tiki');
     $nots = $tikilib->get_event_watches('calendar_changed', $data['calendarId']);
     if ($prefs['calendar_watch_editor'] != "y" || $prefs['user_calendar_watch_editor'] != "y") {
         for ($i = count($nots) - 1; $i >= 0; --$i) {
             if ($nots[$i]['user'] == $data["user"]) {
                 unset($nots[$i]);
                 break;
             }
         }
     }
     if ($prefs['feature_daily_report_watches'] == 'y') {
         $reportsManager = Reports_Factory::build('Reports_Manager');
         $reportsManager->addToCache($nots, array('event' => 'calendar_changed', 'calitemId' => $calitemId, 'user' => $user));
     }
     if ($nots) {
         include_once 'lib/webmail/tikimaillib.php';
         $mail = new TikiMail();
         $smarty->assign('mail_new', $new);
         $smarty->assign('mail_data', $data);
         $smarty->assign('mail_calitemId', $calitemId);
         $foo = parse_url($_SERVER["REQUEST_URI"]);
         $machine = $tikilib->httpPrefix(true) . dirname($foo["path"]);
         $machine = preg_replace("!/\$!", "", $machine);
         // just incase
         $smarty->assign('mail_machine', $machine);
         $defaultLanguage = $prefs['site_language'];
         foreach ($nots as $not) {
             $mail->setUser($not['user']);
             $mail_data = $smarty->fetchLang($defaultLanguage, "mail/user_watch_calendar_subject.tpl");
             $mail->setSubject($mail_data);
             $mail_data = $smarty->fetchLang($defaultLanguage, "mail/user_watch_calendar.tpl");
             $mail->setText($mail_data);
             $mail->send(array($not['email']));
         }
     }
 }
Example #7
0
        if ($watch['object'] == '*') {
            $smarty->assign('all', 'y');
            break;
        }
        for ($i = 0; $i < $nb; ++$i) {
            if ($watch['object'] == $categories[$i]['categId']) {
                $categories[$i]['incat'] = 'y';
                break;
            }
        }
    }
    $smarty->assign('categories', $categories);
}
if ($prefs['feature_messages'] == 'y' && $tiki_p_messages == 'y') {
    $unread = $tikilib->user_unread_messages($user);
    $smarty->assign('unread', $unread);
}
$eok = $userlib->get_user_email($user);
$smarty->assign('email_ok', empty($eok) ? 'n' : 'y');
ask_ticket('user-watches');
$reportsUsers = Reports_Factory::build('Reports_Users');
$reportsUsersUser = $reportsUsers->get($user);
$smarty->assign_by_ref('report_preferences', $reportsUsersUser);
$smarty->assign('user_calendar_watch_editor', $tikilib->get_user_preference($user, 'user_calendar_watch_editor'));
$smarty->assign('user_article_watch_editor', $tikilib->get_user_preference($user, 'user_article_watch_editor'));
$smarty->assign('user_wiki_watch_editor', $tikilib->get_user_preference($user, 'user_wiki_watch_editor'));
$smarty->assign('user_blog_watch_editor', $tikilib->get_user_preference($user, 'user_blog_watch_editor'));
$smarty->assign('user_tracker_watch_editor', $tikilib->get_user_preference($user, 'user_tracker_watch_editor'));
$smarty->assign('user_comment_watch_editor', $tikilib->get_user_preference($user, 'user_comment_watch_editor'));
$smarty->assign('mid', 'tiki-user_watches.tpl');
$smarty->display("tiki.tpl");
Example #8
0
	function get_notification_emails($trackerId, $itemId, $options, $status='', $oldStatus='')
	{
		global $prefs, $user;
		$watchers_global = $this->get_event_watches('tracker_modified', $trackerId);
		$watchers_local = $this->get_local_notifications($itemId, $status, $oldStatus);
		$watchers_item = $itemId ? $this->get_event_watches('tracker_item_modified', $itemId, array('trackerId'=>$trackerId)) : array();

		// use daily reports feature only if tracker item has been added or updated
		if ($prefs['feature_daily_report_watches'] == 'y' && !empty($status)) {
			$reportsManager = Reports_Factory::build('Reports_Manager');
			$reportsManager->addToCache(
							$watchers_global,
							array('event' => 'tracker_item_modified', 'itemId' => $itemId, 'trackerId' => $trackerId, 'user' => $user)
			);
			$reportsManager->addToCache(
							$watchers_item,
							array('event' => 'tracker_item_modified', 'itemId' => $itemId, 'trackerId' => $trackerId, 'user' => $user)
			);
		}

		$watchers_outbound = array();
		if ( array_key_exists("outboundEmail", $options) && $options["outboundEmail"]) {
			$emails3 = preg_split('/,/', $options['outboundEmail']);
			foreach ($emails3 as $w) {
				global $user_preferences;
				$userlib = TikiLib::lib('user');
				$u = $userlib->get_user_by_email($w);
				$this->get_user_preferences($u, array('user', 'language', 'mailCharset'));
				if (empty($user_preferences[$u]['language'])) $user_preferences[$u]['language'] = $prefs['site_language'];
				if (empty($user_preferences[$u]['mailCharset'])) $user_preferences[$u]['mailCharset'] = $prefs['users_prefs_mailCharset'];
				$watchers_outbound[] = array('email'=>$w, 'user'=>$u, 'language'=>$user_preferences[$u]['language'], 'mailCharset'=>$user_preferences[$u]['mailCharset']);
			}
		}

		$emails = array();
		$watchers = array();
		foreach (array('watchers_global', 'watchers_local', 'watchers_item', 'watchers_outbound') as $ws) {
			if (!empty($$ws)) {
				foreach ($$ws as $w) {
					$wl = strtolower($w['email']);
					if (!in_array($wl, $emails)) {
						$emails[] = $wl;
						$watchers[] = $w;
					}
				}
			}
		}
		return $watchers;
	}
Example #9
0
 public function get_notification_emails($trackerId, $itemId, $options, $status = '', $oldStatus = '')
 {
     global $prefs, $user;
     $watchers_global = $this->get_event_watches('tracker_modified', $trackerId);
     $watchers_local = $this->get_local_notifications($itemId, $status, $oldStatus);
     $watchers_item = $itemId ? $this->get_event_watches('tracker_item_modified', $itemId, array('trackerId' => $trackerId)) : array();
     if ($this->get_user_preference($user, 'user_tracker_watch_editor') != "y") {
         for ($i = count($watchers_global) - 1; $i >= 0; --$i) {
             if ($watchers_global[$i]['user'] == $user) {
                 unset($watchers_global[$i]);
                 break;
             }
         }
         for ($i = count($watchers_local) - 1; $i >= 0; --$i) {
             if ($watchers_local[$i]['user'] == $user) {
                 unset($watchers_local[$i]);
                 break;
             }
         }
         for ($i = count($watchers_item) - 1; $i >= 0; --$i) {
             if ($watchers_item[$i]['user'] == $user) {
                 unset($watchers_item[$i]);
                 break;
             }
         }
     }
     // use daily reports feature if tracker item has been added or updated
     if ($prefs['feature_daily_report_watches'] == 'y' && !empty($status)) {
         $reportsManager = Reports_Factory::build('Reports_Manager');
         $reportsManager->addToCache($watchers_global, array('event' => 'tracker_item_modified', 'itemId' => $itemId, 'trackerId' => $trackerId, 'user' => $user));
         $reportsManager->addToCache($watchers_item, array('event' => 'tracker_item_modified', 'itemId' => $itemId, 'trackerId' => $trackerId, 'user' => $user));
     }
     // use daily reports feature if a file was attached or removed from a tracker item
     if ($prefs['feature_daily_report_watches'] == 'y' && isset($options["attachment"])) {
         $reportsManager = Reports_Factory::build('Reports_Manager');
         $reportsManager->addToCache($watchers_global, array('event' => 'tracker_file_attachment', 'itemId' => $itemId, 'trackerId' => $trackerId, 'user' => $user, "attachment" => $options["attachment"]));
         $reportsManager->addToCache($watchers_item, array('event' => 'tracker_file_attachment', 'itemId' => $itemId, 'trackerId' => $trackerId, 'user' => $user, 'attachment' => $options['attachment']));
     }
     $watchers_outbound = array();
     if (array_key_exists("outboundEmail", $options) && $options["outboundEmail"]) {
         $emails3 = preg_split('/,/', $options['outboundEmail']);
         foreach ($emails3 as $w) {
             global $user_preferences;
             $userlib = TikiLib::lib('user');
             $u = $userlib->get_user_by_email($w);
             $this->get_user_preferences($u, array('user', 'language', 'mailCharset'));
             if (empty($user_preferences[$u]['language'])) {
                 $user_preferences[$u]['language'] = $prefs['site_language'];
             }
             if (empty($user_preferences[$u]['mailCharset'])) {
                 $user_preferences[$u]['mailCharset'] = $prefs['users_prefs_mailCharset'];
             }
             $watchers_outbound[] = array('email' => $w, 'user' => $u, 'language' => $user_preferences[$u]['language'], 'mailCharset' => $user_preferences[$u]['mailCharset']);
         }
     }
     $emails = array();
     $watchers = array();
     foreach (array('watchers_global', 'watchers_local', 'watchers_item', 'watchers_outbound') as $ws) {
         if (!empty(${$ws})) {
             foreach (${$ws} as $w) {
                 $wl = strtolower($w['email']);
                 if (!in_array($wl, $emails)) {
                     $emails[] = $wl;
                     $watchers[] = $w;
                 }
             }
         }
     }
     return $watchers;
 }
Example #10
0
 function replace_article($title, $authorName, $topicId, $useImage, $imgname, $imgsize, $imgtype, $imgdata, $heading, $body, $publishDate, $expireDate, $user, $articleId, $image_x, $image_y, $type, $topline, $subtitle, $linkto, $image_caption, $lang, $rating = 0, $isfloat = 'n', $emails = '', $from = '', $list_image_x = '', $list_image_y = '', $ispublished = 'y', $fromurl = false)
 {
     $tikilib = TikiLib::lib('tiki');
     $smarty = TikiLib::lib('smarty');
     if ($expireDate < $publishDate) {
         $expireDate = $publishDate;
     }
     $hash = md5($title . $heading . $body);
     if (empty($imgdata) || $useImage === 'n') {
         // remove image data if not using it
         $imgdata = '';
     }
     $query = 'select `name` from `tiki_topics` where `topicId` = ?';
     $topicName = $this->getOne($query, array($topicId));
     $size = $body ? mb_strlen($body) : mb_strlen($heading);
     $info = array('title' => $title, 'authorName' => $authorName, 'topicId' => (int) $topicId, 'topicName' => $topicName, 'size' => (int) $size, 'useImage' => $useImage, 'image_name' => $imgname, 'image_type' => $imgtype, 'image_size' => (int) $imgsize, 'image_data' => $imgdata, 'isfloat' => $isfloat, 'image_x' => (int) $image_x, 'image_y' => (int) $image_y, 'list_image_x' => (int) $list_image_x, 'list_image_y' => (int) $list_image_y, 'heading' => $heading, 'body' => $body, 'publishDate' => (int) $publishDate, 'expireDate' => (int) $expireDate, 'created' => (int) $this->now, 'author' => $user, 'type' => $type, 'rating' => (double) $rating, 'topline' => $topline, 'subtitle' => $subtitle, 'linkto' => $linkto, 'image_caption' => $image_caption, 'lang' => $lang, 'ispublished' => $ispublished);
     $article_table = $this->table('tiki_articles');
     if ($articleId) {
         $oldArticle = $this->get_article($articleId);
         $article_table->update($info, array('articleId' => (int) $articleId));
         // Clear article image cache because image may just have been changed
         $this->delete_image_cache('article', $articleId);
         $event = 'article_edited';
         $nots = $tikilib->get_event_watches('article_edited', '*');
         $nots2 = $tikilib->get_event_watches('topic_article_edited', $topicId);
         $smarty->assign('mail_action', 'Edit');
         $smarty->assign('mail_old_title', $oldArticle['title']);
         $smarty->assign('mail_old_publish_date', $oldArticle['publishDate']);
         $smarty->assign('mail_old_expiration_date', $oldArticle['expireDate']);
         $smarty->assign('mail_old_data', $oldArticle['heading'] . "\n----------------------\n" . $oldArticle['body']);
     } else {
         $articleId = $article_table->insert($info);
         global $prefs;
         if ($prefs['feature_score'] == 'y') {
             $this->score_event($user, 'article_new');
         }
         $event = 'article_submitted';
         $nots = $tikilib->get_event_watches('article_submitted', '*');
         $nots2 = $tikilib->get_event_watches('topic_article_created', $topicId);
         $smarty->assign('mail_action', 'New');
         // Create tracker item as well if feature is enabled
         if (!$fromurl && $prefs['tracker_article_tracker'] == 'y' && ($trackerId = $prefs['tracker_article_trackerId'])) {
             $trklib = TikiLib::lib('trk');
             $definition = Tracker_Definition::get($trackerId);
             if ($fieldId = $definition->getArticleField()) {
                 $addit = array();
                 $addit[] = array('fieldId' => $fieldId, 'type' => 'articles', 'value' => $articleId);
                 $itemId = $trklib->replace_item($trackerId, 0, array('data' => $addit));
                 TikiLib::lib('relation')->add_relation('tiki.article.attach', 'trackeritem', $itemId, 'article', $articleId);
             }
         }
     }
     $nots3 = array();
     foreach ($nots as $n) {
         $nots3[] = $n['email'];
     }
     foreach ($nots2 as $n) {
         if (!in_array($n['email'], $nots3)) {
             $nots[] = $n;
         }
     }
     if (is_array($emails) && (empty($from) || $from == $prefs['sender_email'])) {
         foreach ($emails as $n) {
             if (!in_array($n, $nots3)) {
                 $nots[] = array('email' => $n, 'language' => $prefs['site_language']);
             }
         }
     }
     global $prefs;
     if ($prefs['user_article_watch_editor'] != "y") {
         for ($i = count($nots) - 1; $i >= 0; --$i) {
             if ($nots[$i]['user'] == $user) {
                 unset($nots[$i]);
                 break;
             }
         }
     }
     if (!isset($_SERVER['SERVER_NAME'])) {
         $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
     }
     if ($prefs['feature_user_watches'] == 'y' && $prefs['feature_daily_report_watches'] == 'y') {
         $reportsManager = Reports_Factory::build('Reports_Manager');
         $reportsManager->addToCache($nots, array('event' => $event, 'articleId' => $articleId, 'articleTitle' => $title, 'authorName' => $authorName, 'user' => $user));
     }
     if (count($nots) || is_array($emails)) {
         include_once 'lib/notifications/notificationemaillib.php';
         $smarty->assign('mail_site', $_SERVER['SERVER_NAME']);
         $smarty->assign('mail_title', $title);
         $smarty->assign('mail_postid', $articleId);
         $smarty->assign('mail_user', $user);
         $smarty->assign('mail_current_publish_date', $publishDate);
         $smarty->assign('mail_current_expiration_date', $expireDate);
         $smarty->assign('mail_current_data', $heading . "\n----------------------\n" . $body);
         sendEmailNotification($nots, 'watch', 'user_watch_article_post_subject.tpl', $_SERVER['SERVER_NAME'], 'user_watch_article_post.tpl');
         if (is_array($emails) && !empty($from) && $from != $prefs['sender_email']) {
             $nots = array();
             foreach ($emails as $n) {
                 $nots[] = array('email' => $n, 'language' => $prefs['site_language']);
             }
             sendEmailNotification($nots, 'watch', 'user_watch_article_post_subject.tpl', $_SERVER['SERVER_NAME'], 'user_watch_article_post.tpl', $from);
         }
     }
     require_once 'lib/search/refresh-functions.php';
     refresh_index('articles', $articleId);
     $tikilib = TikiLib::lib('tiki');
     $tikilib->object_post_save(array('type' => 'article', 'object' => $articleId, 'description' => substr($heading, 0, 200), 'name' => $title, 'href' => "tiki-read_article.php?articleId={$articleId}"), array('content' => $body . "\n" . $heading));
     return $articleId;
 }
Example #11
0
function tiki_setup_events()
{
    global $prefs;
    $events = TikiLib::events();
    $events->reset();
    if ($prefs['feature_wiki'] == 'y') {
        if ($prefs['quantify_changes'] == 'y' && $prefs['feature_multilingual'] == 'y') {
            $events->bind('tiki.wiki.save', Event_Lib::defer('quantify', 'wiki_update'));
        }
        $prefix = $prefs['feature_wiki_userpage_prefix'];
        if ($prefs['feature_wiki_userpage'] && !empty($prefix)) {
            $events->bind('tiki.wiki.save', function ($args) use($events, $prefix) {
                global $prefs;
                if ($prefix == substr($args['object'], 0, strlen($prefix))) {
                    $user = substr($args['object'], strlen($prefix));
                    $events->trigger('tiki.user.update', array('type' => 'user', 'object' => $user));
                }
            });
        }
    }
    if ($prefs['feature_trackers'] == 'y') {
        $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'send_replace_item_notifications'));
        $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'sync_item_geo'));
        if ($prefs['feature_categories'] == 'y') {
            $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'sync_categories'));
            $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'sync_item_auto_categories'));
        }
        if (!empty($prefs['user_trackersync_realname'])) {
            $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'sync_user_realname'));
        }
        if ($prefs['user_trackersync_groups'] == 'y') {
            $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'sync_user_groups'));
        }
        if ($prefs['user_trackersync_geo'] == 'y') {
            $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'sync_user_geo'));
        }
        if ($prefs['groupTracker'] == 'y') {
            $events->bind('tiki.trackeritem.create', Event_Lib::defer('trk', 'group_tracker_create'));
        }
        if ($prefs['userTracker'] == 'y') {
            $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'update_user_account'));
        }
        if ($prefs['feature_freetags'] == 'y') {
            $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'sync_freetags'));
        }
        $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'update_create_missing_pages'));
        if ($prefs['trackerfield_computed'] == 'y') {
            $events->bind('tiki.trackeritem.save', array('Tracker_Field_Computed', 'computeFields'));
        }
        if ($prefs['feature_multilingual'] == 'y') {
            $events->bind('tiki.trackeritem.save', array('Tracker_Field_Language', 'update_language'));
        }
        if ($prefs['trackerfield_icon'] == 'y') {
            $events->bind('tiki.trackeritem.save', array('Tracker_Field_Icon', 'updateIcon'));
        }
        $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'update_tracker_summary'));
        $events->bind('tiki.trackeritem.save', Event_Lib::defer('trk', 'invalidate_item_cache'));
        if ($prefs['tracker_refresh_itemlink_detail'] == 'y') {
            $events->bind('tiki.trackeritem.update', Event_Lib::defer('trk', 'refresh_index_on_master_update'));
        }
    }
    if ($prefs['feature_search'] == 'y' && $prefs['unified_incremental_update'] == 'y') {
        $events->bindPriority(100, 'tiki.save', 'tiki_save_refresh_index');
        $events->bindPriority(100, 'tiki.user.save', 'tiki_save_refresh_index');
    }
    if ($prefs['feature_file_galleries'] == 'y') {
        $events->bind('tiki.save', Event_Lib::defer('filegal', 'save_sync_file_backlinks'));
    }
    if ($prefs['dailyreports_enabled_for_new_users'] == 'y') {
        $events->bind('tiki.user.create', array(Reports_Factory::build('Reports_Users'), 'addUserToDailyReports'));
    }
    if ($prefs['scorm_enabled'] == 'y') {
        $events->bind('tiki.file.create', Event_Lib::defer('scorm', 'handle_file_creation'));
        $events->bind('tiki.file.update', Event_Lib::defer('scorm', 'handle_file_update'));
    }
    if ($prefs['feature_forwardlinkprotocol'] == 'y') {
        $events->bind("tiki.wiki.view", 'tiki_wiki_view_forwardlink');
        $events->bind("tiki.wiki.save", 'tiki_wiki_save_forwardlink');
    }
    $events->bind('tiki.save', Event_Lib::defer('tiki', 'plugin_post_save_actions'));
    // Chain events
    $events->bind('tiki.wiki.update', 'tiki.wiki.save');
    $events->bind('tiki.wiki.create', 'tiki.wiki.save');
    $events->bind('tiki.wiki.save', 'tiki.save');
    $events->bind('tiki.wiki.view', 'tiki.view');
    $events->bind('tiki.trackeritem.update', 'tiki.trackeritem.save');
    $events->bind('tiki.trackeritem.create', 'tiki.trackeritem.save');
    $events->bind('tiki.trackeritem.save', 'tiki.save');
    $events->bind('tiki.file.update', 'tiki.file.save');
    $events->bind('tiki.file.create', 'tiki.file.save');
    $events->bind('tiki.file.save', 'tiki.save');
    $events->bind('tiki.user.update', 'tiki.user.save');
    $events->bind('tiki.user.create', 'tiki.user.save');
}
Example #12
0
function tiki_setup_events()
{
    global $prefs;
    $events = TikiLib::events();
    $events->reset();
    $defer = function ($lib, $function) {
        return Tiki_Event_Lib::defer($lib, $function);
    };
    if ($prefs['feature_wiki'] == 'y') {
        if ($prefs['quantify_changes'] == 'y' && $prefs['feature_multilingual'] == 'y') {
            $events->bind('tiki.wiki.save', $defer('quantify', 'wiki_update'));
        }
        $prefix = $prefs['feature_wiki_userpage_prefix'];
        if ($prefs['feature_wiki_userpage'] && !empty($prefix)) {
            $events->bind('tiki.wiki.save', function ($args) use($events, $prefix) {
                global $prefs;
                if ($prefix == substr($args['object'], 0, strlen($prefix))) {
                    $user = substr($args['object'], strlen($prefix));
                    $events->trigger('tiki.user.update', array('type' => 'user', 'object' => $user));
                }
            });
        }
    }
    if ($prefs['feature_trackers'] == 'y') {
        $events->bind('tiki.trackeritem.save', $defer('trk', 'send_replace_item_notifications'));
        $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_item_geo'));
        if ($prefs['feature_categories'] == 'y') {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_categories'));
            $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_item_auto_categories'));
        }
        if (!empty($prefs['user_trackersync_realname'])) {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_user_realname'));
        }
        if ($prefs['user_trackersync_geo'] == 'y') {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_user_geo'));
        }
        if ($prefs['groupTracker'] == 'y') {
            $events->bind('tiki.trackeritem.create', $defer('trk', 'group_tracker_create'));
        }
        $events->bind('tiki.trackeritem.create', $defer('trk', 'setup_wiki_fields'));
        $events->bind('tiki.trackeritem.update', $defer('trk', 'update_wiki_fields'));
        $events->bind('tiki.trackeritem.delete', $defer('trk', 'delete_wiki_fields'));
        if ($prefs['userTracker'] == 'y') {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'update_user_account'));
        }
        if ($prefs['feature_freetags'] == 'y') {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_freetags'));
        }
        $events->bind('tiki.trackeritem.save', $defer('trk', 'update_create_missing_pages'));
        if ($prefs['trackerfield_computed'] == 'y') {
            $events->bind('tiki.trackeritem.rating', array('Tracker_Field_Computed', 'computeFields'));
            $events->bind('tiki.trackeritem.save', array('Tracker_Field_Computed', 'computeFields'));
        }
        if ($prefs['feature_multilingual'] == 'y') {
            $events->bind('tiki.trackeritem.save', array('Tracker_Field_Language', 'update_language'));
        }
        if ($prefs['trackerfield_icon'] == 'y') {
            $events->bind('tiki.trackeritem.save', array('Tracker_Field_Icon', 'updateIcon'));
        }
        // Certain non-read only fields that can be edited outside of using the tracker field do store a value in the
        // tiki_tracker_item_fields database, and therefore need updates of the tracker field value to be in sync, when
        // edited elsewhere. Completely read-only fields don't have this problem as they don't save anything anyway.
        //
        // A possible solution could have been to avoid storing the value in the database altogether and get the value
        // from the canonical source, but there is code that currently could dependd on it and also it might actually
        // be argued in favor of for performance reasons to have the value in the tiki_tracker_item_fields db as well.
        //
        // TODO: freetags field. There is already handling for the Freetags field in wikiplugin_addfreetag.php which
        // is the most likely place it would be edited outside of tracker field but an event would be cleaner.
        //
        if ($prefs['trackerfield_relation'] == 'y') {
            $events->bind('tiki.social.relation.add', array('Tracker_Field_Relation', 'syncRelationAdded'));
            $events->bind('tiki.social.relation.remove', array('Tracker_Field_Relation', 'syncRelationRemoved'));
        }
        if ($prefs['trackerfield_category'] == 'y') {
            $events->bind('tiki.object.categorized', array('Tracker_Field_Category', 'syncCategoryFields'));
        }
        $events->bind('tiki.trackeritem.save', $defer('trk', 'update_tracker_summary'));
        $events->bind('tiki.trackeritem.save', $defer('trk', 'invalidate_item_cache'));
        $events->bind('tiki.trackeritem.rating', $defer('trk', 'invalidate_item_cache'));
        if ($prefs['tracker_refresh_itemlink_detail'] == 'y') {
            $events->bind('tiki.trackeritem.update', $defer('trk', 'refresh_index_on_master_update'));
        }
        if ($prefs['tracker_wikirelation_synctitle'] == 'y') {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'rename_linked_page'));
        }
    }
    if ($prefs['feature_search'] == 'y' && $prefs['unified_incremental_update'] == 'y') {
        $events->bindPriority(100, 'tiki.save', 'tiki_save_refresh_index');
        $events->bindPriority(100, 'tiki.user.save', 'tiki_save_refresh_index');
        $events->bindPriority(100, 'tiki.social.save', 'tiki_save_refresh_index');
        $events->bindPriority(100, 'tiki.rating', 'tiki_save_refresh_index');
    }
    if ($prefs['feature_file_galleries'] == 'y') {
        $events->bind('tiki.save', $defer('filegal', 'save_sync_file_backlinks'));
    }
    if ($prefs['dailyreports_enabled_for_new_users'] == 'y') {
        $events->bind('tiki.user.create', array(Reports_Factory::build('Reports_Users'), 'addUserToDailyReports'));
    }
    if ($prefs['scorm_enabled'] == 'y') {
        $events->bind('tiki.file.create', $defer('scorm', 'handle_file_creation'));
        $events->bind('tiki.file.update', $defer('scorm', 'handle_file_update'));
    }
    if ($prefs['feature_futurelinkprotocol'] == 'y') {
        if ($prefs['feature_wikilingo'] == 'y') {
            $events->bind("tiki.wiki.view", $defer('wlte', 'wikilingo_flp_view'));
            $events->bind("tiki.wiki.save", $defer('wlte', 'wikilingo_flp_save'));
        } else {
            $events->bind("tiki.wiki.view", $defer('wlte', 'tiki_wiki_view_pastlink'));
            $events->bind("tiki.wiki.save", $defer('wlte', 'tiki_wiki_save_pastlink'));
        }
    }
    if ($prefs['goal_enabled'] == 'y') {
        TikiLib::lib('goalevent')->bindEvents($events);
    }
    $events->bind('tiki.save', $defer('tiki', 'object_post_save'));
    if ($prefs['activity_basic_events'] == 'y') {
        TikiLib::lib('activity')->bindBasicEvents($events);
    }
    if ($prefs['activity_custom_events'] == 'y') {
        try {
            TikiLib::lib('activity')->bindCustomEvents($events);
        } catch (Exception $e) {
            TikiLib::lib('errorreport')->report($e->getMessage());
        }
    }
    if ($prefs['storedsearch_enabled'] == 'y' && $prefs['monitor_enabled'] == 'y') {
        $events->bind('tiki.query.hit', $defer('storedsearch', 'handleQueryNotification'));
    }
    if ($prefs['monitor_enabled'] == 'y') {
        TikiLib::lib('monitor')->bindEvents($events);
    }
    if ($prefs['mustread_enabled'] == 'y') {
        $events->bind('tiki.trackeritem.create', ['Services_MustRead_Controller', 'handleItemCreation']);
        $events->bind('tiki.user.create', ['Services_MustRead_Controller', 'handleUserCreation']);
    }
    if ($prefs['feature_score'] == 'y') {
        TikiLib::lib('score')->bindEvents($events);
    }
    // If the parameter is supplied by the web server, Tiki will expose the username as a response header
    if (!empty($_SERVER['TIKI_HEADER_REPORT_USER'])) {
        $events->bind('tiki.process.render', function () {
            global $user;
            if ($user) {
                header('X-Remote-User: ' . $user);
            }
        });
    }
    // If the parameter is supplied by the web server, Tiki will expose the object type and id as a response header
    if (!empty($_SERVER['TIKI_HEADER_REPORT_OBJECT'])) {
        $events->bind('tiki.process.render', function () {
            if (function_exists('current_object') && ($object = current_object())) {
                header("X-Current-Object: {$object['type']}:{$object['object']}");
            }
        });
    }
    // Chain events
    $events->bind('tiki.object.categorized', 'tiki.save');
    $events->bind('tiki.user.login', 'tiki.view');
    $events->bind('tiki.user.view', 'tiki.view');
    $events->bind('tiki.user.avatar', 'tiki.save');
    $events->bind('tiki.wiki.update', 'tiki.wiki.save');
    $events->bind('tiki.wiki.create', 'tiki.wiki.save');
    $events->bind('tiki.wiki.save', 'tiki.save');
    $events->bind('tiki.wiki.view', 'tiki.view');
    $events->bind('tiki.wiki.attachfile', 'tiki.save');
    $events->bind('tiki.article.create', 'tiki.article.save');
    $events->bind('tiki.article.save', 'tiki.save');
    $events->bind('tiki.article.delete', 'tiki.save');
    $events->bind('tiki.article.view', 'tiki.view');
    $events->bind('tiki.blog.create', 'tiki.blog.save');
    $events->bind('tiki.blog.save', 'tiki.save');
    $events->bind('tiki.blog.delete', 'tiki.save');
    $events->bind('tiki.blog.view', 'tiki.view');
    $events->bind('tiki.blogpost.create', 'tiki.blogpost.save');
    $events->bind('tiki.blogpost.save', 'tiki.save');
    $events->bind('tiki.blogpost.delete', 'tiki.save');
    $events->bind('tiki.trackeritem.update', 'tiki.trackeritem.save');
    $events->bind('tiki.trackeritem.create', 'tiki.trackeritem.save');
    $events->bind('tiki.trackeritem.save', 'tiki.save');
    $events->bind('tiki.trackeritem.delete', 'tiki.save');
    $events->bind('tiki.trackeritem.rating', 'tiki.rating');
    $events->bind('tiki.trackeritem.view', 'tiki.view');
    $events->bind('tiki.trackerfield.update', 'tiki.trackerfield.save');
    $events->bind('tiki.trackerfield.create', 'tiki.trackerfield.save');
    $events->bind('tiki.trackerfield.delete', 'tiki.save');
    $events->bind('tiki.trackerfield.save', 'tiki.save');
    $events->bind('tiki.tracker.update', 'tiki.tracker.save');
    $events->bind('tiki.tracker.create', 'tiki.tracker.save');
    $events->bind('tiki.tracker.delete', 'tiki.save');
    $events->bind('tiki.tracker.save', 'tiki.save');
    $events->bind('tiki.category.update', 'tiki.category.save');
    $events->bind('tiki.category.create', 'tiki.category.save');
    $events->bind('tiki.category.delete', 'tiki.category.save');
    $events->bind('tiki.category.save', 'tiki.save');
    $events->bind('tiki.file.update', 'tiki.file.save');
    $events->bind('tiki.file.create', 'tiki.file.save');
    $events->bind('tiki.file.delete', 'tiki.file.save');
    $events->bind('tiki.file.save', 'tiki.save');
    $events->bind('tiki.file.download', 'tiki.view');
    $events->bind('tiki.filegallery.update', 'tiki.filegallery.save');
    $events->bind('tiki.filegallery.create', 'tiki.filegallery.save');
    $events->bind('tiki.filegallery.delete', 'tiki.filegallery.save');
    $events->bind('tiki.filegallery.save', 'tiki.save');
    $events->bind('tiki.image.create', 'tiki.image.save');
    $events->bind('tiki.image.delete', 'tiki.image.save');
    $events->bind('tiki.image.save', 'tiki.save');
    $events->bind('tiki.image.view', 'tiki.view');
    $events->bind('tiki.imagegallery.create', 'tiki.imagegallery.save');
    $events->bind('tiki.imagegallery.delete', 'tiki.imagegallery.save');
    $events->bind('tiki.imagegallery.save', 'tiki.save');
    $events->bind('tiki.imagegallery.view', 'tiki.view');
    $events->bind('tiki.forum.update', 'tiki.forum.save');
    $events->bind('tiki.forum.create', 'tiki.forum.save');
    $events->bind('tiki.forum.delete', 'tiki.forum.save');
    $events->bind('tiki.forum.save', 'tiki.save');
    $events->bind('tiki.forumpost.create', 'tiki.forumpost.save');
    $events->bind('tiki.forumpost.reply', 'tiki.forumpost.save');
    $events->bind('tiki.forumpost.update', 'tiki.forumpost.save');
    $events->bind('tiki.forumpost.save', 'tiki.save');
    $events->bind('tiki.forumpost.view', 'tiki.view');
    $events->bind('tiki.group.update', 'tiki.group.save');
    $events->bind('tiki.group.create', 'tiki.group.save');
    $events->bind('tiki.group.delete', 'tiki.save');
    $events->bind('tiki.group.save', 'tiki.save');
    $events->bind('tiki.comment.post', 'tiki.comment.save');
    $events->bind('tiki.comment.reply', 'tiki.comment.save');
    $events->bind('tiki.comment.update', 'tiki.comment.save');
    $events->bind('tiki.comment.save', 'tiki.save');
    $events->bind('tiki.user.groupjoin', 'tiki.user.update');
    $events->bind('tiki.user.groupleave', 'tiki.user.update');
    $events->bind('tiki.user.update', 'tiki.user.save');
    $events->bind('tiki.user.create', 'tiki.user.save');
    $events->bind('tiki.user.follow.add', 'tiki.user.network');
    $events->bind('tiki.user.follow.incoming', 'tiki.user.network');
    $events->bind('tiki.user.friend.add', 'tiki.user.network');
    $events->bind('tiki.user.message', 'tiki.user.network');
    $events->bind('tiki.social.like.add', 'tiki.social.save');
    $events->bind('tiki.social.like.remove', 'tiki.social.save');
    $events->bind('tiki.social.favorite.add', 'tiki.social.save');
    $events->bind('tiki.social.favorite.remove', 'tiki.social.save');
    $events->bind('tiki.social.relation.add', 'tiki.social.save');
    $events->bind('tiki.social.relation.remove', 'tiki.social.save');
    $events->bind('tiki.social.rating.add', 'tiki.social.save');
    $events->bind('tiki.social.rating.remove', 'tiki.social.save');
    $events->bind('tiki.query.critical', 'tiki.query.hit');
    $events->bind('tiki.query.high', 'tiki.query.hit');
    $events->bind('tiki.query.low', 'tiki.query.hit');
    $events->bind('tiki.mustread.addgroup', 'tiki.save');
    $events->bind('tiki.mustread.adduser', 'tiki.save');
    $events->bind('tiki.mustread.complete', 'tiki.save');
    $events->bind('tiki.mustread.completed', 'tiki.save');
    $events->bind('tiki.mustread.required', 'tiki.save');
    if (function_exists('fastcgi_finish_request')) {
        // If available, try to send everything to the user at this point
        $events->bindPriority(-10, 'tiki.process.shutdown', 'fastcgi_finish_request');
    }
    // if article indexing is on as part of the rss article generator bind the categorization of objects to ensure
    // that the trackeritem and article are always in sync category-wise
    if (isset($prefs['tracker_article_indexing']) && $prefs['tracker_article_indexing'] == 'y') {
        $events->bind('tiki.object.categorized', $defer('trk', 'sync_tracker_article_categories'));
    }
    //Check the Addons to see if there are any events to bind
    $api = new TikiAddons_Api_Events();
    $api->bindEvents($events);
}
/**
 * @param $type Type of the object commented on, 'wiki' or 'article'
 * @param $id Identifier of the object commented on. For articles, their id and for wiki pages, their name
 * @param $title Comment title
 * @param $content Comment content
 */
function sendCommentNotification($type, $id, $title, $content, $commentId = null)
{
    global $user, $tikilib, $smarty, $prefs;
    if ($type == 'wiki') {
        $events = 'wiki_comment_changes';
    } elseif ($type == 'article') {
        $events = 'article_commented';
    } elseif ($type == 'trackeritem') {
        $events = 'trackeritem_commented';
        // Blog comment mail
    } elseif ($type == 'blog') {
        $events = 'blog_comment_changes';
    } else {
        throw new Exception('Unknown type');
    }
    if ($type == 'trackeritem') {
        // Tracker watches are pretty complicated, to get from trklib
        $trklib = TikiLib::lib('trk');
        $trackerId = $trklib->get_tracker_for_item($id);
        $trackerOptions = $trklib->get_tracker_options($trackerId);
        $watches = $trklib->get_notification_emails($trackerId, $id, $trackerOptions);
    } else {
        // Blog comment mail
        $watches = $tikilib->get_event_watches($events, $id);
    }
    $watches2 = $tikilib->get_event_watches('comment_post', $commentId);
    if (!empty($watches2)) {
        $watches = array_merge($watches, $watches2);
    }
    if (($type != 'wiki' || $prefs['wiki_watch_editor'] != 'y' || $prefs['user_wiki_watch_editor'] != 'y') && $prefs['user_comment_watch_editor'] != "y") {
        for ($i = count($watches) - 1; $i >= 0; --$i) {
            if ($watches[$i]['user'] == $user) {
                unset($watches[$i]);
                break;
            }
        }
    }
    if (count($watches)) {
        if ($type == 'wiki') {
            $smarty->assign('mail_objectname', $id);
        } elseif ($type == 'article') {
            global $artlib;
            include_once 'lib/articles/artlib.php';
            $smarty->assign('mail_objectname', $artlib->get_title($id));
            $smarty->assign('mail_objectid', $id);
        } elseif ($type == 'trackeritem') {
            if ($prefs['feature_daily_report_watches'] == 'y') {
                $reportsManager = Reports_Factory::build('Reports_Manager');
                $reportsManager->addToCache($watches, array('event' => 'tracker_item_comment', 'itemId' => $id, 'trackerId' => $trackerId, 'user' => $user, 'threadId' => $commentId));
            }
            $tracker = $trklib->get_tracker($trackerId);
            $smarty->assign('mail_objectid', $id);
            $smarty->assign('mail_objectname', $tracker['name']);
            $smarty->assign('mail_item_title', $trklib->get_isMain_value($trackerId, $id));
        }
        // Blog comment mail
        $smarty->assign('mail_objectid', $id);
        $smarty->assign('objecttype', $type);
        $smarty->assign('mail_user', $user);
        $smarty->assign('mail_title', $title);
        $smarty->assign('mail_comment', $content);
        sendEmailNotification($watches, null, 'user_watch_comment_subject.tpl', null, 'user_watch_comment.tpl');
    }
}
Example #14
0
function tiki_setup_events()
{
    global $prefs;
    $events = TikiLib::events();
    $events->reset();
    $defer = function ($lib, $function) {
        return Tiki_Event_Lib::defer($lib, $function);
    };
    if ($prefs['feature_wiki'] == 'y') {
        if ($prefs['quantify_changes'] == 'y' && $prefs['feature_multilingual'] == 'y') {
            $events->bind('tiki.wiki.save', $defer('quantify', 'wiki_update'));
        }
        $prefix = $prefs['feature_wiki_userpage_prefix'];
        if ($prefs['feature_wiki_userpage'] && !empty($prefix)) {
            $events->bind('tiki.wiki.save', function ($args) use($events, $prefix) {
                global $prefs;
                if ($prefix == substr($args['object'], 0, strlen($prefix))) {
                    $user = substr($args['object'], strlen($prefix));
                    $events->trigger('tiki.user.update', array('type' => 'user', 'object' => $user));
                }
            });
        }
    }
    if ($prefs['feature_trackers'] == 'y') {
        $events->bind('tiki.trackeritem.save', $defer('trk', 'send_replace_item_notifications'));
        $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_item_geo'));
        if ($prefs['feature_categories'] == 'y') {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_categories'));
            $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_item_auto_categories'));
        }
        if (!empty($prefs['user_trackersync_realname'])) {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_user_realname'));
        }
        if ($prefs['user_trackersync_groups'] == 'y') {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_user_groups'));
        }
        if ($prefs['user_trackersync_geo'] == 'y') {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_user_geo'));
        }
        if ($prefs['groupTracker'] == 'y') {
            $events->bind('tiki.trackeritem.create', $defer('trk', 'group_tracker_create'));
        }
        if ($prefs['userTracker'] == 'y') {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'update_user_account'));
        }
        if ($prefs['feature_freetags'] == 'y') {
            $events->bind('tiki.trackeritem.save', $defer('trk', 'sync_freetags'));
        }
        $events->bind('tiki.trackeritem.save', $defer('trk', 'update_create_missing_pages'));
        if ($prefs['trackerfield_computed'] == 'y') {
            $events->bind('tiki.trackeritem.rating', array('Tracker_Field_Computed', 'computeFields'));
            $events->bind('tiki.trackeritem.save', array('Tracker_Field_Computed', 'computeFields'));
        }
        if ($prefs['feature_multilingual'] == 'y') {
            $events->bind('tiki.trackeritem.save', array('Tracker_Field_Language', 'update_language'));
        }
        if ($prefs['trackerfield_icon'] == 'y') {
            $events->bind('tiki.trackeritem.save', array('Tracker_Field_Icon', 'updateIcon'));
        }
        $events->bind('tiki.trackeritem.save', $defer('trk', 'update_tracker_summary'));
        $events->bind('tiki.trackeritem.save', $defer('trk', 'invalidate_item_cache'));
        $events->bind('tiki.trackeritem.rating', $defer('trk', 'invalidate_item_cache'));
        if ($prefs['tracker_refresh_itemlink_detail'] == 'y') {
            $events->bind('tiki.trackeritem.update', $defer('trk', 'refresh_index_on_master_update'));
        }
    }
    if ($prefs['feature_search'] == 'y' && $prefs['unified_incremental_update'] == 'y') {
        $events->bindPriority(100, 'tiki.save', 'tiki_save_refresh_index');
        $events->bindPriority(100, 'tiki.user.save', 'tiki_save_refresh_index');
        $events->bindPriority(100, 'tiki.social.save', 'tiki_save_refresh_index');
        $events->bindPriority(100, 'tiki.rating', 'tiki_save_refresh_index');
    }
    if ($prefs['feature_file_galleries'] == 'y') {
        $events->bind('tiki.save', $defer('filegal', 'save_sync_file_backlinks'));
    }
    if ($prefs['dailyreports_enabled_for_new_users'] == 'y') {
        $events->bind('tiki.user.create', array(Reports_Factory::build('Reports_Users'), 'addUserToDailyReports'));
    }
    if ($prefs['scorm_enabled'] == 'y') {
        $events->bind('tiki.file.create', $defer('scorm', 'handle_file_creation'));
        $events->bind('tiki.file.update', $defer('scorm', 'handle_file_update'));
    }
    if ($prefs['feature_forwardlinkprotocol'] == 'y') {
        $events->bind("tiki.wiki.view", 'tiki_wiki_view_forwardlink');
        $events->bind("tiki.wiki.save", 'tiki_wiki_save_forwardlink');
    }
    $events->bind('tiki.save', $defer('tiki', 'object_post_save'));
    if ($prefs['activity_basic_events'] == 'y') {
        TikiLib::lib('activity')->bindBasicEvents($events);
    }
    if ($prefs['activity_custom_events'] == 'y') {
        try {
            TikiLib::lib('activity')->bindCustomEvents($events);
        } catch (Exception $e) {
            TikiLib::lib('errorreport')->report($e->getMessage());
        }
    }
    // Chain events
    $events->bind('tiki.wiki.update', 'tiki.wiki.save');
    $events->bind('tiki.wiki.create', 'tiki.wiki.save');
    $events->bind('tiki.wiki.save', 'tiki.save');
    $events->bind('tiki.wiki.view', 'tiki.view');
    $events->bind('tiki.trackeritem.update', 'tiki.trackeritem.save');
    $events->bind('tiki.trackeritem.create', 'tiki.trackeritem.save');
    $events->bind('tiki.trackeritem.save', 'tiki.save');
    $events->bind('tiki.trackeritem.delete', 'tiki.save');
    $events->bind('tiki.trackeritem.rating', 'tiki.rating');
    $events->bind('tiki.file.update', 'tiki.file.save');
    $events->bind('tiki.file.create', 'tiki.file.save');
    $events->bind('tiki.file.delete', 'tiki.file.save');
    $events->bind('tiki.file.save', 'tiki.save');
    $events->bind('tiki.forumpost.create', 'tiki.forumpost.save');
    $events->bind('tiki.forumpost.reply', 'tiki.forumpost.save');
    $events->bind('tiki.forumpost.update', 'tiki.forumpost.save');
    $events->bind('tiki.forumpost.save', 'tiki.save');
    $events->bind('tiki.comment.post', 'tiki.comment.save');
    $events->bind('tiki.comment.reply', 'tiki.comment.save');
    $events->bind('tiki.comment.update', 'tiki.comment.save');
    $events->bind('tiki.comment.save', 'tiki.save');
    $events->bind('tiki.user.update', 'tiki.user.save');
    $events->bind('tiki.user.create', 'tiki.user.save');
    $events->bind('tiki.user.follow.add', 'tiki.user.network');
    $events->bind('tiki.user.follow.incoming', 'tiki.user.network');
    $events->bind('tiki.user.friend.add', 'tiki.user.network');
    $events->bind('tiki.social.like.add', 'tiki.social.save');
    $events->bind('tiki.social.like.remove', 'tiki.social.save');
    $events->bind('tiki.social.favorite.add', 'tiki.social.save');
    $events->bind('tiki.social.favorite.remove', 'tiki.social.save');
    $events->bind('tiki.social.relation.add', 'tiki.social.save');
    $events->bind('tiki.social.relation.remove', 'tiki.social.save');
}
Example #15
0
 /**
  * blog_post Stores a blog post
  *
  * @param int $blogId
  * @param string $data
  * @param string $excerpt
  * @param string $user
  * @param string $title
  * @param string $contributions
  * @param string $priv
  * @param bool $is_wysiwyg
  * @access public
  * @return int postId
  */
 function blog_post($blogId, $data, $excerpt, $user, $title = '', $contributions = '', $priv = 'n', $created = 0, $is_wysiwyg = FALSE)
 {
     // update tiki_blogs and call activity functions
     global $prefs;
     $tikilib = TikiLib::lib('tiki');
     $smarty = TikiLib::lib('smarty');
     $wysiwyg = $is_wysiwyg == TRUE ? 'y' : 'n';
     if (!$created) {
         $created = $tikilib->now;
     }
     $data = TikiFilter::get('purifier')->filter($data);
     $excerpt = TikiFilter::get('purifier')->filter($excerpt);
     $query = "insert into `tiki_blog_posts`(`blogId`,`data`,`excerpt`,`created`,`user`,`title`,`priv`,`wysiwyg`) values(?,?,?,?,?,?,?,?)";
     $result = $this->query($query, array((int) $blogId, $data, $excerpt, (int) $created, $user, $title, $priv, $wysiwyg));
     $query = "select max(`postId`) from `tiki_blog_posts` where `created`=? and `user`=?";
     $id = $this->getOne($query, array((int) $created, $user));
     $query = "update `tiki_blogs` set `lastModif`=?,`posts`=`posts`+1 where `blogId`=?";
     $result = $this->query($query, array((int) $created, (int) $blogId));
     $this->add_blog_activity($blogId);
     if ($prefs['feature_user_watches'] == 'y' or $prefs['feature_group_watches'] == 'y') {
         $nots = $tikilib->get_event_watches('blog_post', $blogId);
         if (!isset($_SERVER["SERVER_NAME"])) {
             $_SERVER["SERVER_NAME"] = $_SERVER["HTTP_HOST"];
         }
         if ($prefs['user_blog_watch_editor'] != "y") {
             for ($i = count($nots) - 1; $i >= 0; --$i) {
                 if ($nots[$i]['user'] == $user) {
                     unset($nots[$i]);
                     break;
                 }
             }
         }
         if ($prefs['feature_daily_report_watches'] == 'y') {
             $query = "select `title` from `tiki_blogs` where `blogId`=?";
             $blogTitle = $this->getOne($query, array((int) $blogId));
             $reportsManager = Reports_Factory::build('Reports_Manager');
             $reportsManager->addToCache($nots, array("event" => 'blog_post', "blogId" => $blogId, "blogTitle" => $blogTitle, "postId" => $id, "user" => $user));
         }
         if (count($nots)) {
             include_once "lib/notifications/notificationemaillib.php";
             $smarty->assign('mail_site', $_SERVER["SERVER_NAME"]);
             $smarty->assign('mail_title', $this->get_title($blogId));
             $smarty->assign('mail_post_title', $title);
             $smarty->assign('mail_blogid', $blogId);
             $smarty->assign('mail_postid', $id);
             $smarty->assign('mail_user', $user);
             $smarty->assign('mail_data', $data);
             if ($prefs['feature_contribution'] == 'y' && !empty($contributions)) {
                 $contributionlib = TikiLib::lib('contribution');
                 $smarty->assign('mail_contributions', $contributionlib->print_contributions($contributions));
             }
             sendEmailNotification($nots, "watch", "user_watch_blog_post_subject.tpl", $_SERVER["SERVER_NAME"], "user_watch_blog_post.tpl");
         }
     }
     TikiLib::events()->trigger('tiki.blogpost.create', array('type' => 'blog post', 'object' => $id, 'blog' => $blogId, 'user' => $user));
     if ($prefs['feature_actionlog'] == 'y') {
         $logslib = TikiLib::lib('logs');
         $logslib->add_action('Posted', $blogId, 'blog', "blogId={$blogId}&amp;postId={$id}&amp;add=" . strlen($data) . "#postId{$id}", '', '', '', '', $contributions);
     }
     require_once 'lib/search/refresh-functions.php';
     refresh_index('blog_posts', $id);
     $tikilib->object_post_save(array('type' => 'blog post', 'object' => $id, 'description' => substr($data, 0, 200), 'name' => $title, 'href' => "tiki-view_blog_post.php?postId={$id}"), array('content' => $data));
     return $id;
 }
<?php

/**
 * @package tikiwiki
 */
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
require_once 'tiki-setup.php';
if (php_sapi_name() != 'cli') {
    $access->check_permission('tiki_p_admin');
}
echo "This script is deprecated and does not work in Multitiki installations.\nPlease use 'console.php daily-report:send' instead.";
$access->check_feature('feature_daily_report_watches');
$reportsManager = Reports_Factory::build('Reports_Manager');
$reportsManager->send();
Example #17
0
 function replace_article($title, $authorName, $topicId, $useImage, $imgname, $imgsize, $imgtype, $imgdata, $heading, $body, $publishDate, $expireDate, $user, $articleId, $image_x, $image_y, $type, $topline, $subtitle, $linkto, $image_caption, $lang, $rating = 0, $isfloat = 'n', $emails = '', $from = '', $list_image_x = '', $list_image_y = '', $ispublished = 'y')
 {
     global $smarty, $tikilib;
     if ($expireDate < $publishDate) {
         $expireDate = $publishDate;
     }
     $hash = md5($title . $heading . $body);
     if (empty($imgdata) || $useImage === 'n') {
         // remove image data if not using it
         $imgdata = '';
     }
     $query = 'select `name` from `tiki_topics` where `topicId` = ?';
     $topicName = $this->getOne($query, array($topicId));
     $size = $body ? mb_strlen($body) : mb_strlen($heading);
     if ($articleId) {
         $oldArticle = $this->get_article($articleId);
         $query = 'update `tiki_articles` set `title` = ?, `authorName` = ?, `topicId` = ?, `topicName` = ?, `size` = ?, `useImage` = ?, `image_name` = ?, ';
         $query .= ' `image_type` = ?, `image_size` = ?, `image_data` = ?, `isfloat` = ?, `image_x` = ?, `image_y` = ?, `list_image_x` = ?, `list_image_y` = ?, `heading` = ?, `body` = ?, ';
         $query .= ' `publishDate` = ?, `expireDate` = ?, `created` = ?, `author` = ?, `type` = ?, `rating` = ?, `topline`=?, `subtitle`=?, `linkto`=?, ';
         $query .= ' `image_caption`=?, `lang`=?, `ispublished`=? where `articleId` = ?';
         $result = $this->query($query, array($title, $authorName, (int) $topicId, $topicName, (int) $size, $useImage, $imgname, $imgtype, (int) $imgsize, $imgdata, $isfloat, (int) $image_x, (int) $image_y, (int) $list_image_x, (int) $list_image_y, $heading, $body, (int) $publishDate, (int) $expireDate, (int) $this->now, $user, $type, (double) $rating, $topline, $subtitle, $linkto, $image_caption, $lang, $ispublished, (int) $articleId));
         // Clear article image cache because image may just have been changed
         $this->delete_image_cache('article', $articleId);
         $event = 'article_edited';
         $nots = $tikilib->get_event_watches('article_edited', '*');
         $nots2 = $tikilib->get_event_watches('topic_article_edited', $topicId);
         $smarty->assign('mail_action', 'Edit');
         $smarty->assign('mail_old_title', $oldArticle['title']);
         $smarty->assign('mail_old_publish_date', $oldArticle['publishDate']);
         $smarty->assign('mail_old_expiration_date', $oldArticle['expireDate']);
         $smarty->assign('mail_old_data', $oldArticle['heading'] . "\n----------------------\n" . $oldArticle['body']);
     } else {
         // Insert the article
         $query = 'insert into `tiki_articles` (`title`, `authorName`, `topicId`, `useImage`, `image_name`, `image_size`, `image_type`, `image_data`, ';
         $query .= ' `publishDate`, `expireDate`, `created`, `heading`, `body`, `hash`, `author`, `nbreads`, `votes`, `points`, `size`, `topicName`, ';
         $query .= ' `image_x`, `image_y`, `list_image_x`, `list_image_y`, `type`, `rating`, `isfloat`,`topline`, `subtitle`, `linkto`,`image_caption`, `lang`, `ispublished`) ';
         $query .= ' values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
         $result = $this->query($query, array($title, $authorName, (int) $topicId, $useImage, $imgname, (int) $imgsize, $imgtype, $imgdata, (int) $publishDate, (int) $expireDate, (int) $this->now, $heading, $body, $hash, $user, 0, 0, 0, (int) $size, $topicName, (int) $image_x, (int) $image_y, (int) $list_image_x, (int) $list_image_y, $type, (double) $rating, $isfloat, $topline, $subtitle, $linkto, $image_caption, $lang, $ispublished));
         $query2 = 'select max(`articleId`) from `tiki_articles` where `created` = ? and `title`=? and `hash`=?';
         $articleId = $this->getOne($query2, array((int) $this->now, $title, $hash));
         global $prefs;
         if ($prefs['feature_score'] == 'y') {
             $this->score_event($user, 'article_new');
         }
         $event = 'article_submitted';
         $nots = $tikilib->get_event_watches('article_submitted', '*');
         $nots2 = $tikilib->get_event_watches('topic_article_created', $topicId);
         $smarty->assign('mail_action', 'New');
     }
     $nots3 = array();
     foreach ($nots as $n) {
         $nots3[] = $n['email'];
     }
     foreach ($nots2 as $n) {
         if (!in_array($n['email'], $nots3)) {
             $nots[] = $n;
         }
     }
     if (is_array($emails) && (empty($from) || $from == $prefs['sender_email'])) {
         foreach ($emails as $n) {
             if (!in_array($n, $nots3)) {
                 $nots[] = array('email' => $n, 'language' => $prefs['site_language']);
             }
         }
     }
     global $prefs;
     if ($prefs['user_article_watch_editor'] != "y") {
         for ($i = count($nots) - 1; $i >= 0; --$i) {
             if ($nots[$i]['user'] == $user) {
                 unset($nots[$i]);
                 break;
             }
         }
     }
     if (!isset($_SERVER['SERVER_NAME'])) {
         $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
     }
     if ($prefs['feature_user_watches'] == 'y' && $prefs['feature_daily_report_watches'] == 'y') {
         $reportsManager = Reports_Factory::build('Reports_Manager');
         $reportsManager->addToCache($nots, array('event' => $event, 'articleId' => $articleId, 'articleTitle' => $title, 'authorName' => $authorName, 'user' => $user));
     }
     if (count($nots) || is_array($emails)) {
         include_once 'lib/notifications/notificationemaillib.php';
         $smarty->assign('mail_site', $_SERVER['SERVER_NAME']);
         $smarty->assign('mail_title', $title);
         $smarty->assign('mail_postid', $articleId);
         $smarty->assign('mail_user', $user);
         $smarty->assign('mail_current_publish_date', $publishDate);
         $smarty->assign('mail_current_expiration_date', $expireDate);
         $smarty->assign('mail_current_data', $heading . "\n----------------------\n" . $body);
         $smarty->assign('mail_heading', $heading);
         $smarty->assign('mail_body', $body);
         sendEmailNotification($nots, 'watch', 'user_watch_article_post_subject.tpl', $_SERVER['SERVER_NAME'], 'user_watch_article_post.tpl');
         if (is_array($emails) && !empty($from) && $from != $prefs['sender_email']) {
             $nots = array();
             foreach ($emails as $n) {
                 $nots[] = array('email' => $n, 'language' => $prefs['site_language']);
             }
             sendEmailNotification($nots, 'watch', 'user_watch_article_post_subject.tpl', $_SERVER['SERVER_NAME'], 'user_watch_article_post.tpl', $from);
         }
     }
     require_once 'lib/search/refresh-functions.php';
     refresh_index('articles', $articleId);
     global $tikilib;
     $tikilib->object_post_save(array('type' => 'article', 'object' => $articleId, 'description' => substr($heading, 0, 200), 'name' => $title, 'href' => "tiki-read_article.php?articleId={$articleId}"), array('content' => $body . "\n" . $heading));
     return $articleId;
 }