We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19726
    • 239 Posts
    I am having some problems with getting any plugin written. I tried to get the example plugin working, but that just won’t work.

    So right now I have a plugin called "test" which should do something if it gets called, but the alerts don’t show up. Even if I make a syntax error nothing happens, so I must be doing something wrong.

    Right now I have the following code:
    $e = &$modx->Event;
    
    switch ($e->name) {
    	case "OnManagerLogin":
    		$e->alert("Hi $username, Welcome to MODx");
    		break;
    
    	default :	
    		return; // stop here - this is very important. 
    		break;
    }


    The plugin is NOT disabled, and the checkbox with OnManagerLogin on the SystemEvents tab is checked. I also tried other events, but never anything happens.

    Anyone got an idea on what might be wrong?
      • 32963
      • 1,732 Posts
      Your event structure looks ok but there's bug in the CMS header file that's causing the SystemAlerts not to show up.

      Here's a quick fix:

      Save the following code to manager/includes/header.inc.php

      <?php 
      if(IN_MANAGER_MODE!="true") die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the MODx Content Manager instead of accessing this file directly.");
      // count messages
      $sql="SELECT count(*) FROM $dbase.".$table_prefix."user_messages where recipient=".$_SESSION['internalKey']." and messageread=0;";
      $rs = mysql_query($sql); 
      $row = mysql_fetch_assoc($rs);
      $_SESSION['nrnewmessages'] = $row['count(*)'];
      $sql="SELECT count(*) FROM $dbase.".$table_prefix."user_messages where recipient=".$_SESSION['internalKey']."";
      $rs = mysql_query($sql);
      $row = mysql_fetch_assoc($rs);
      $_SESSION['nrtotalmessages'] = $row['count(*)'];
      $messagesallowed = $_SESSION['permissions']['messages'];
      ?>
      <html>
      <head>
      	<title>MODx</title>
      	<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $etomite_charset; ?>" />
      	<link rel="stylesheet" type="text/css" href="media/style/<?php echo $manager_theme ? "$manager_theme/":""; ?>style.css<?php echo "?$theme_refresher";?>" />
      	<link rel="stylesheet" type="text/css" href="media/style/<?php echo $manager_theme ? "$manager_theme/":""; ?>coolButtons2.css<?php echo "?$theme_refresher";?>>" />
      	<script type="text/javascript">var MODX_MEDIA_PATH = "<?php echo IN_MANAGER_MODE ? "media":"manager/media"; ?>";</script>
      	<script type="text/javascript" language="JavaScript" src="media/script/modx.js"></script>
      	<script type="text/javascript" language="JavaScript">
      		document.setIncludePath("media/tvscripts/");
      		document.addEventListener("oninit",function() { 
      			document.include("dynelement");
      		})
      	</script>	
      	<script type="text/javascript" language="JavaScript" src="media/script/cb2.js"></script>
      	<script language="JavaScript" type="text/javascript">
      
      		var MODX_MEDIA_PATH = "media"; // set media path
      
      		function document_onload() {
       			stopWorker();
       			msgCount(); 
       			hideLoader();
       			<?php echo isset($_REQUEST['r']) ? " doRefresh(".$_REQUEST['r'].");" : "" ;?>;  
      		};
      		function document_onunload() {
       			top.scripter.work();
       		};
      		
      		// set tree to default action.		
      		parent.menu.ca = "open";
      
      		function msgCount() {
      			try {
      				top.scripter.startmsgcount(<?php echo $_SESSION['nrnewmessages'] ; ?>,<?php echo $_SESSION['nrtotalmessages'] ; ?>,<?php echo $messagesallowed ; ?>);
      			} catch(oException) {
      				ww = window.setTimeout('msgCount()',1000);
      			}
      		}
      		
      		function stopWorker() {
      			try {
      				parent.scripter.stopWork();
      			} catch(oException) {
      				ww = window.setTimeout('stopWorker()',500);
      			}
      		}
      		
      		function doRefresh(r) {
      			try {
      				rr = r;
      				top.scripter.startrefresh(rr);
      			} catch(oException) {
      				vv = window.setTimeout('doRefresh()',1000);
      			}
      		}
      		var documentDirty=false;
      
      		function checkDirt() {
      			if(documentDirty==true) {
      				event.returnValue = "<?php echo $_lang['warning_not_saved']; ?>";
      			}
      		}
      		
      		function saveWait(fName) {
      			document.getElementById("savingMessage").innerHTML = "<?php echo $_lang['saving']; ?>";
      			for(i = 0; i < document.forms[fName].elements.length; i++) {
      				document.forms[fName].elements[i].disabled='disabled';
      			}
      		}
      
      		var managerPath = "";
      
      		function hideLoader() {
      			document.getElementById('preLoader').style.display = "none";
      		}
      		
      		retry=0;
      		function loadagain(id) {
      			try {
      				top.menu.Sync(<?php echo $syncid; ?>);
      			} catch(oException) {
      				retry=retry + 1;
      				if(retry<4) {
      					xyy=window.setTimeout("loadagain(<?php echo $syncid; ?>)", 2000);
      				} else {
      					//alert("Failed to sync to tree!");
      				}
      			}
      		}
      
      		hideL = window.setTimeout("hideLoader()", 5000);
      		
      	</script>
      <?php
      if($_SESSION['browser']=='ie') {
      ?>   
      	<style>
      	/* stupid box model hack for equally stupid MSIE */
      	.sectionHeader, .sectionBody {
      		width:100%;
      	}
      	</style>
      <?php
      }
      ?>
      	<style>
      	#preLoader {
      		position: 						absolute;
      		z-index:						50000;
      		width:							100%;
      		height:							100%;
      		text-align:						center;
      		vertical-align:					middle;
      	}
      	.preLoaderText {
      		background-color:				#ffffff;
      		width:							300px;
      		height:							150px;
      		padding:						50px;
      		border:							1px solid #003399;
      	}
      	</style>
      </head>
      <body ondragstart="return false" onbeforeunload="checkDirt();">
      
      <div id="preLoader"><table width="100%" height="50%" border="0" cellpadding="0"><tr><td align="center"><div class="preLoaderText"><?php echo $_lang['loading_page']; ?></div></td></tr></table></div>
      
        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 19726
        • 239 Posts
        I made the fix posted above, but the plugin still won't work. Any other ideas?
          • 32963
          • 1,732 Posts
          I made the fix posted above, but the plugin still won't work. Any other ideas?

          Hmmm,

          It works on my build. You might have to wait for TP2 to resolve this one
            xWisdom
            www.xwisdomhtml.com
            The fear of the Lord is the beginning of wisdom:
            MODx Co-Founder - Create and do more with less.
            • 19726
            • 239 Posts
            It works on my build. You might have to wait for TP2 to resolve this one
            ok.

            What is estimated releasedate of TP2 ?
            • There is some final work going on on that front right now with the Rich Text Editors, specifically. Since HTML area is officially a dead project, we're updating to the latest FCK editor and the latest TinyMCE editors. There's also a few bug fixes to finalize and check into the repository as noted in the Bug Reports forum.

              I'll be out of town for the next two days, so I would guess mid-next week unless we can push it out before then.
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me

              This discussion is closed to further replies. Keep calm and carry on.