<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[PunBB Forums - Little PHP help please (PunBB related)]]></title>
	<link rel="self" href="http://punbb.informer.com/forums/feed/atom/topic/21815/"/>
	<updated>2009-06-25T09:57:07Z</updated>
	<generator>PunBB</generator>
	<id>http://punbb.informer.com/forums/topic/21815/little-php-help-please-punbb-related/</id>
		<entry>
			<title type="html"><![CDATA[Re: Little PHP help please (PunBB related)]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128664/#p128664"/>
			<content type="html"><![CDATA[<p>Actually the best way to add an image is to edit the &#039;New link active&#039; entry in the <a href="http://punbb.informer.com/trac/browser/additions/punbb-1.3/extensions/pun_pm/lang/English/pun_pm.php#L73">language file</a>.</p><p>Or you could create an extension and place your code in pun_pm_fn_unread_messages_end and pun_pm_hd_visit_elements_pre_change hooks.</p>]]></content>
			<author>
				<name><![CDATA[Parpalak]]></name>
				<uri>http://punbb.informer.com/forums/user/13581/</uri>
			</author>
			<updated>2009-06-25T09:57:07Z</updated>
			<id>http://punbb.informer.com/forums/post/128664/#p128664</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Little PHP help please (PunBB related)]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128659/#p128659"/>
			<content type="html"><![CDATA[<p>If you make any changes to the manifest, change the extension&#039;s version so you can &quot;update&quot; it in the ACP.</p>]]></content>
			<author>
				<name><![CDATA[Garciat]]></name>
				<uri>http://punbb.informer.com/forums/user/12481/</uri>
			</author>
			<updated>2009-06-25T03:03:10Z</updated>
			<id>http://punbb.informer.com/forums/post/128659/#p128659</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Little PHP help please (PunBB related)]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128653/#p128653"/>
			<content type="html"><![CDATA[<p>Good point.&nbsp; My &quot;quest&quot; to find the source originally took me to the manifest and I made the change there.&nbsp; Then I realized, &quot;that did nothing&quot; and my quest continued.</p><p>I&#039;ll update the manifest to reflect the changes.&nbsp; Thanks so much. <img src="http://punbb.informer.com/forums/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[RTaulbee]]></name>
				<uri>http://punbb.informer.com/forums/user/15686/</uri>
			</author>
			<updated>2009-06-24T16:04:27Z</updated>
			<id>http://punbb.informer.com/forums/post/128653/#p128653</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Little PHP help please (PunBB related)]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128652/#p128652"/>
			<content type="html"><![CDATA[<p>You can also change the manifest.xml to hold that script and then generate new cache files. then you would not have to worry about that.</p><p>If something ends up in the cache file then is has to come from the manifest.xml.</p>]]></content>
			<author>
				<name><![CDATA[kierownik]]></name>
				<uri>http://punbb.informer.com/forums/user/6341/</uri>
			</author>
			<updated>2009-06-24T15:54:58Z</updated>
			<id>http://punbb.informer.com/forums/post/128652/#p128652</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Little PHP help please (PunBB related)]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128651/#p128651"/>
			<content type="html"><![CDATA[<p>I wondered if that would happen, thanks for the heads up!</p><p>Since it&#039;s just a snippet, I&#039;ll replace it when I install another extension.&nbsp; I don&#039;t think it happens enough for me to go &quot;back to the drawing board&quot; on this.</p>]]></content>
			<author>
				<name><![CDATA[RTaulbee]]></name>
				<uri>http://punbb.informer.com/forums/user/15686/</uri>
			</author>
			<updated>2009-06-24T15:51:39Z</updated>
			<id>http://punbb.informer.com/forums/post/128651/#p128651</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Little PHP help please (PunBB related)]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128650/#p128650"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>RTaulbee wrote:</cite><blockquote><p>Secondly, I modified the cache_hooks.php file to do the &quot;if statement&quot; and perform the swap.<br /></p><div class="codebox"><pre><code>        if(pun_pm_unread_messages_integer() &gt; 0)
            {
                $visit_elements[&#039;&lt;!-- forum_visit --&gt;&#039;] = preg_replace(&#039;#(&lt;p id=&quot;visit-links&quot; class=&quot;options&quot;&gt;.*?)(&lt;/p&gt;)#&#039;, &#039;$1 &lt;span&gt;&lt;a href=&quot;&#039;.forum_link($forum_url[&#039;pun_pm_inbox&#039;]).&#039;&quot;&gt;&lt;img src=&quot;myimage.gif&quot;&gt;&lt;/a&gt;&lt;/span&gt;$2&#039;, $visit_elements[&#039;&lt;!-- forum_visit --&gt;&#039;]);            
            }
        else
            {
                $visit_elements[&#039;&lt;!-- forum_visit --&gt;&#039;] = preg_replace(&#039;#(&lt;p id=&quot;visit-links&quot; class=&quot;options&quot;&gt;.*?)(&lt;/p&gt;)#&#039;, &#039;$1 &lt;span&gt;&lt;a href=&quot;&#039;.forum_link($forum_url[&#039;pun_pm_inbox&#039;]).&#039;&quot;&gt;&#039;.pun_pm_unread_messages().&#039;&lt;/a&gt;&lt;/span&gt;$2&#039;, $visit_elements[&#039;&lt;!-- forum_visit --&gt;&#039;]);    
            }</code></pre></div><p>I realize there are always many ways to solve a problem and this is just one.&nbsp; I also realize that it&#039;s another database query that needs to happen, but performance isn&#039;t an issue.&nbsp; This is for a small forum with maybe 15-20 active posters and only 3-4 online at a time.&nbsp; It may not be the best or what you think is the best, but I understand it and like it.&nbsp; Mission accomplished!</p><p>Thanks for the input again Garcia/Sirena.</p></blockquote></div><p>If you do this then when you then install a new extension or regenerate new cache files the cache_hooks.php gets overwritten with a new one and you will lose the code I think.</p><p>Best is to do is some other way.<br />What way I do not know.<br />Just a hint so you know.</p>]]></content>
			<author>
				<name><![CDATA[kierownik]]></name>
				<uri>http://punbb.informer.com/forums/user/6341/</uri>
			</author>
			<updated>2009-06-24T15:50:03Z</updated>
			<id>http://punbb.informer.com/forums/post/128650/#p128650</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Little PHP help please (PunBB related)]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128649/#p128649"/>
			<content type="html"><![CDATA[<p>@Garciat: Thanks so much for taking the time to work through it.&nbsp; It helped me get on the right track</p><p>@Sirena: Perhaps.&nbsp; Either way I would still have to code in an &quot;if unread messages count &gt; 0&quot; statement which is where the real hang up was.&nbsp; In other words &quot;If unread message count &gt; 0, use this style, otherwise this style&quot; at least I think(?)</p><p>Here&#039;s my final solution.</p><p>I added a function to the pun_pm functions.php file to return an integer instead of a string.&nbsp; I did this because I think it&#039;s cleaner and less clutter than parsing through a string in order to get a number.&nbsp; So now I don&#039;t have to parse the &quot;New Messages (1)&quot; in order to just grab the integer value (which is all I care about for my if statement)</p><div class="codebox"><pre><code>function pun_pm_unread_messages_integer()
{
    global $forum_db, $forum_user, $forum_config, $lang_pun_pm, $pun_pm_inbox_full;

    list($new_messages, $pun_pm_inbox_full) = pun_pm_read_cache();

    if ($new_messages === false)
    {
        pun_pm_deliver_messages();

        //How much delivered messages do we have?
        $query = array(
            &#039;SELECT&#039;    =&gt; &#039;count(id)&#039;,
            &#039;FROM&#039;        =&gt; &#039;pun_pm_messages&#039;,
            &#039;WHERE&#039;        =&gt; &#039;receiver_id = &#039;.$forum_user[&#039;id&#039;].&#039; AND status = \&#039;delivered\&#039; AND deleted_by_receiver = 0&#039;
        );

        $result = $forum_db-&gt;query_build($query) or error(__FILE__, __LINE__);

        list($new_messages) = $forum_db-&gt;fetch_row($result);

        pun_pm_write_cache($forum_user[&#039;id&#039;], $new_messages, $pun_pm_inbox_full);
    }

    return $new_messages;
}</code></pre></div><p>Secondly, I modified the cache_hooks.php file to do the &quot;if statement&quot; and perform the swap.<br /></p><div class="codebox"><pre><code>        if(pun_pm_unread_messages_integer() &gt; 0)
            {
                $visit_elements[\&#039;&lt;!-- forum_visit --&gt;\&#039;] = preg_replace(\&#039;#(&lt;p id=&quot;visit-links&quot; class=&quot;options&quot;&gt;.*?)(&lt;/p&gt;)#\&#039;, \&#039;$1 &lt;span&gt;&lt;a href=&quot;\&#039;.forum_link($forum_url[\&#039;pun_pm_inbox\&#039;]).\&#039;&quot;&gt;&lt;img src=&quot;myimage.gif&quot;&gt;&lt;/a&gt;&lt;/span&gt;$2\&#039;, $visit_elements[\&#039;&lt;!-- forum_visit --&gt;\&#039;]);            
            }
        else
            {
                $visit_elements[\&#039;&lt;!-- forum_visit --&gt;\&#039;] = preg_replace(\&#039;#(&lt;p id=&quot;visit-links&quot; class=&quot;options&quot;&gt;.*?)(&lt;/p&gt;)#\&#039;, \&#039;$1 &lt;span&gt;&lt;a href=&quot;\&#039;.forum_link($forum_url[\&#039;pun_pm_inbox\&#039;]).\&#039;&quot;&gt;\&#039;.pun_pm_unread_messages().\&#039;&lt;/a&gt;&lt;/span&gt;$2\&#039;, $visit_elements[\&#039;&lt;!-- forum_visit --&gt;\&#039;]);    
            }</code></pre></div><p>I realize there are always many ways to solve a problem and this is just one.&nbsp; I also realize that it&#039;s another database query that needs to happen, but performance isn&#039;t an issue.&nbsp; This is for a small forum with maybe 15-20 active posters and only 3-4 online at a time.&nbsp; It may not be the best or what you think is the best, but I understand it and like it.&nbsp; Mission accomplished!</p><p>Thanks for the input again Garcia/Sirena.</p>]]></content>
			<author>
				<name><![CDATA[RTaulbee]]></name>
				<uri>http://punbb.informer.com/forums/user/15686/</uri>
			</author>
			<updated>2009-06-24T15:01:44Z</updated>
			<id>http://punbb.informer.com/forums/post/128649/#p128649</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Little PHP help please (PunBB related)]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128630/#p128630"/>
			<content type="html"><![CDATA[<p>Can&#039;t you just do this via CSS?</p><p>This problem resembles the one solved by CSS over at Flux:</p><p><a href="http://fluxbb.org/forums/topic/2960/adding-an-icon-beside-the-usernames-of-certain-usergroups/">http://fluxbb.org/forums/topic/2960/add &#133; sergroups/</a></p>]]></content>
			<author>
				<name><![CDATA[sirena]]></name>
				<uri>http://punbb.informer.com/forums/user/6921/</uri>
			</author>
			<updated>2009-06-24T02:12:15Z</updated>
			<id>http://punbb.informer.com/forums/post/128630/#p128630</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Little PHP help please (PunBB related)]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128629/#p128629"/>
			<content type="html"><![CDATA[<p>Typo in &quot;Here&#039;s the code in cache_hooks.com&quot;.</p><p>First, I&#039;d check what kind of variable <em>pun_pm_unread_messages()</em> returns.</p><p>After reading &#039;functions.php&#039; inside pun_pm&#039;s directory, the function returns a string formatted like so: &quot;New Messages (X)&quot;.</p><p>So, you should use a regex check for that. Basically,</p><div class="codebox"><pre><code>if(preg_match(&#039;/^&#039;.str_replace(array(&#039;/&#039;,&#039;(%d)&#039;), array(&#039;\/&#039;,&#039;\([0-9]*\)&#039;), $lang_pun_pm[&#039;New link active&#039;]).&#039;$/i&#039;, pun_pm_unread_messages()) &gt; 0)
{
/* whatever you want in here */
}</code></pre></div><p>Note: that could possibly not work with languages other than English.</p><p>As for the &#039;flashy image&#039; you want, I&#039;d use some JavaScript instead. Example:<br /></p><div class="codebox"><pre><code>if(confirm(&#039;You have one or more unread private messages. Would you like to read them?&#039;))
    window.location = &#039;/pun_pm/inbox/&#039;; /* or whatever your relative URL to the inbox is */</code></pre></div><p>All together:<br /></p><div class="codebox"><pre><code>if(preg_match(&#039;/^&#039;.str_replace(array(&#039;/&#039;,&#039;(%d)&#039;), array(&#039;\/&#039;,&#039;\([0-9]*\)&#039;), $lang_pun_pm[&#039;New link active&#039;]).&#039;$/i&#039;, pun_pm_unread_messages()) &gt; 0)
{
$visit_elements[&#039;&lt;!-- forum_visit --&gt;&#039;] .= &quot;&lt;script type=\&quot;text/javascript\&quot;&gt;if(confirm(&#039;You have one or more unread private messages. Would you like to read them?&#039;))
    window.location = &#039;/pun_pm/inbox/&#039;; /* or whatever your relative URL to the inbox is */&lt;/script&gt;&quot;;
}</code></pre></div><p>FYI: do that change on <strong>Line 458</strong> in &#039;extensions/pun_pm/manifest.xml&#039;.</p><p>Let me know if that doesn&#039;t work.</p><p><strong>Notes</strong><br />The $visit_elements[&#039;&lt;!-- forum_visit --&gt;&#039;] variable is probably not the best place to add the javascript, but it just seems to work for me. If it doesn&#039;t work for you, let met know and I&#039;ll find some other variable to put that in.</p><p>The alert message shows up as the page is loading. Meaning that the browser will stop loading until the user click Ok/Cancel. To fix this, you&#039;d have to use jQuery or other JS framework that has an &#039;onload&#039; event to run the alert in.</p><p>I just made this &quot;mod&quot; in 3-5 minutes so don&#039;t just say it doesn&#039;t work. It just needs some polishing.</p><p>- Garciat</p>]]></content>
			<author>
				<name><![CDATA[Garciat]]></name>
				<uri>http://punbb.informer.com/forums/user/12481/</uri>
			</author>
			<updated>2009-06-24T01:52:24Z</updated>
			<id>http://punbb.informer.com/forums/post/128629/#p128629</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Little PHP help please (PunBB related)]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128628/#p128628"/>
			<content type="html"><![CDATA[<p>Don&#039;t shoot me, but I&#039;m a SQL Server, ASP, ASP.Net guy, but like all good programmers, we can quickly adapt to other languages given time.&nbsp; </p><p>So I&#039;m trying to edit a bit of the PunBB &quot;pun_pm&quot; extension.&nbsp; After several hours of tracing code back and reading on the forum, I&#039;ve found that cache_hooks.php is where I want to make my edit.&nbsp; I&#039;ve also found the exact snippet I want to update, but I can&#039;t get it to work yet.</p><p>Idea: When a user gets a PM, show a large flashy image or something to actually get attention.&nbsp; I&#039;ve gone several weeks not noticing the New Message (1) hyperlink.&nbsp; I&#039;m not the only one either.&nbsp; So basically I want to say &quot;when New Message count &gt; 0, show big flashy image, otherwise, business as usual&quot;</p><p>Here&#039;s the code in cache_hooks.com</p><div class="codebox"><pre><code>        $visit_elements[\&#039;&lt;!-- forum_visit --&gt;\&#039;] = preg_replace(\&#039;#(&lt;p id=&quot;visit-links&quot; class=&quot;options&quot;&gt;.*?)(&lt;/p&gt;)#\&#039;, \&#039;$1 &lt;span&gt;&lt;a href=&quot;\&#039;.forum_link($forum_url[\&#039;pun_pm_inbox\&#039;]).\&#039;&quot;&gt;\&#039;.pun_pm_unread_messages().\&#039;&lt;/a&gt;&lt;/span&gt;$2\&#039;, $visit_elements[\&#039;&lt;!-- forum_visit --&gt;\&#039;]);</code></pre></div><p>Here&#039;s what I&#039;m trying to do:<br /></p><div class="codebox"><pre><code>If (pun_pm_unread_messages() &gt; 0)
{
        $visit_elements[\&#039;&lt;!-- forum_visit --&gt;\&#039;] = preg_replace(\&#039;#(&lt;p id=&quot;visit-links&quot; class=&quot;options&quot;&gt;.*?)(&lt;/p&gt;)#\&#039;, \&#039;$1 &lt;span&gt;&lt;a href=&quot;\&#039;.forum_link($forum_url[\&#039;pun_pm_inbox\&#039;]).\&#039;&quot;&gt;&lt;img src=&quot;http://www.blah.com/mybigflashygif.gif&quot;&gt;&lt;/a&gt;&lt;/span&gt;$2\&#039;, $visit_elements[\&#039;&lt;!-- forum_visit --&gt;\&#039;]);
}
else (same as original)
{
        $visit_elements[\&#039;&lt;!-- forum_visit --&gt;\&#039;] = preg_replace(\&#039;#(&lt;p id=&quot;visit-links&quot; class=&quot;options&quot;&gt;.*?)(&lt;/p&gt;)#\&#039;, \&#039;$1 &lt;span&gt;&lt;a href=&quot;\&#039;.forum_link($forum_url[\&#039;pun_pm_inbox\&#039;]).\&#039;&quot;&gt;\&#039;.pun_pm_unread_messages().\&#039;&lt;/a&gt;&lt;/span&gt;$2\&#039;, $visit_elements[\&#039;&lt;!-- forum_visit --&gt;\&#039;]);
}</code></pre></div><p>Thanks for all help</p>]]></content>
			<author>
				<name><![CDATA[RTaulbee]]></name>
				<uri>http://punbb.informer.com/forums/user/15686/</uri>
			</author>
			<updated>2009-06-23T21:21:04Z</updated>
			<id>http://punbb.informer.com/forums/post/128628/#p128628</id>
		</entry>
</feed>
