PHP - Php Comments - Make Function Block Documentation Private To File
Hi all, I have a function that is only used in the file it is declared in :
/index.php Code: [Select] /** * This function is used to display form messages. * * @param string $msg This explains login and session status . * * @access private * * @return string */ function pred($msg) { return "<p class='content' style='color:red;'> $msg</p>"; } I'm using netbeans 7.0 (which by the way rocks !!!!! ), and I don't want to be able to see the documentation in other files when I start typing something similar. I read at pear.net coding standards that the '@param private' can be used on class methods. Is there a way to make the documentation private to the file that the function is declared in? I'm simply trying not to flood other files in the project with needless function suggestions. Thanks in advance. Similar TutorialsHi there people of the PHP forum, This functions intention is to output the same code 4 digit code twice before generating a new one, I can get it to do one fine, but I cannot for the life of me figure out how to get it to repeat twice before changing on the third call. private function KeyGen(){ $Numerical = range(0,9); $Alpha = range("A","Z"); $Keys = array_merge($Numerical, $Alpha); return $Keys[rand(0,35)].$Keys[rand(0,35)].$Keys[rand(0,35)].$Keys[rand(0,35)]; } I am needing it to do this so that each 'set' of 2 calls to the function (within the class) gives the same 4 digit code. At the moment I am just making one call & then assigning that single call to a variable and then referencing that var twice, this is not what I want to do, but it scratches the itch for now... Any idea's/other logic would be greatly appreciated. Cheers, Rw I'm trying to clean up some past coding for a project of mine and this block keeps standing out like a sore thumb, but it works and i can understand it. What it's doing is comparing each of the users submitted data to the admin-set data and then flagging if there any errors or not. Any suggestions on a different approach? Code: [Select] foreach ($_SESSION['usersData'] as $k => $v) { foreach ($this->info as $m => $n) { if ($m == $k) { if ( ($n['required'] && ( empty($v) || !isset($v) ) ) ) { $_SESSION['errors'][$k] = TRUE; } elseif ( (!$this->escape_data($v,$n['type'])) && ($n['required']) ){ $_SESSION['errors'][$k] = true; } elseif ($n['required'] && ($v == $n['default'])) { if ($n['readonly'] != true) $_SESSION['errors'][$k] = true; } elseif ($n['required'] && $n['readonly'] && ($v != $n['default']) ) { # Box is required, set to readonly and has a default value, if this triggers then the user has tampered with our form. $_SESSION['usersData'][$k] = $n['default']; } elseif (isset($_SESSION['errors'][$k])) { unset($_SESSION['errors'][$k]);# = false; } } elseif ( isset($this->info['file']) ) { if ($this->info['file']['required'] && $_FILES['file']['size'] == 0) { $_SESSION['errors']['file'] = TRUE; } else { unset($_SESSION['errors']['file']); } } } } Hi, first post here. I'm wanting to create a php script which will call itself in a recursive function so that nested comments are made .. An example of a perfect hierarchy would be as bellow... Comment #1 -- Comment reply --- Comment reply --- Comment reply ------ Comment reply -------- Comment reply ---------- Comment reply --- Comment reply --- Comment reply Comment #2 -- Comment reply ------ Comment reply -- Comment replyNote how they go deep into the comment replies (should support 7-25 comments in comments/deep) At the moment it only goes three deep as the recursive function doesn't work... I have created the function, but for some reason the line "comment($row['id']);" in the recursive function isn't preforming anything, commented or un commented. However looks fine to me. function comment($reply_to_id){ global $db; echo $reply_to_id; $stmt11 = $db->prepare('SELECT * FROM `posts` WHERE reply_to = :thing'); $stmt11->execute(['thing' => $reply_to_id]); while ($row = $stmt11->fetch()) { echo "<br>"; echo " //----------[UID: ".$row['post_by']."]----------".$row['date']."----------->>> "; echo $row['content']; // comment($row['id']); } } The full code is .. <?php require('includes/config.php'); //define page title $title = 'Thread Page'; //include header template require('layout/header.php'); echo "<h1>the Forum // make post </h1>"; $id = $_GET['id']; $reply = $_GET['reply']; $rando1; $test = $_GET['test']; $index = 1; ?> <?php function indent(){ echo "-"; } function stars($index){ //example to demonstrate star pattern-2 for($i=1; $i<=$index; $i++) { for($j=1; $j<=$i; $j++) { echo '*'; } echo '*'; } } function comment($reply_to_id){ global $db; echo $reply_to_id; $stmt11 = $db->prepare('SELECT * FROM `posts` WHERE reply_to = :thing'); $stmt11->execute(['thing' => $reply_to_id]); while ($row = $stmt11->fetch()) { echo "<br>"; echo " //----------[UID: ".$row['post_by']."]----------".$row['date']."----------->>> "; echo $row['content']; // comment($row['id']); } } ?> <ul> <?php $rando_id = null; // dealing with inital thread $stmt = $db->prepare('SELECT * FROM `topics` WHERE rando_id = :topic_id'); $stmt->execute(['topic_id' => $id]); while ($row = $stmt->fetch()) { echo "Contents:<br>"; echo $row['contents']; echo "<br><br>By: "; $stmt2 = $db->prepare('SELECT * FROM `members` WHERE memberID = :mem_id'); $stmt2->execute(['mem_id' => $row['topic_by']]); while ($row2 = $stmt2->fetch()) { echo "<a href='profile.php?id=".$row2['user_ID']."'>".$row2['username']."</a><br>"; comment($row2['reply_id']); } echo "Timestamp: ".$row['date']."<br>"; echo "<a href='post_post.php?type='>Post reply</a><br>"; echo "----------------------"; echo "<br>"; } echo "<br>"; $stmt3 = $db->prepare('SELECT * FROM `posts` WHERE reply_to = :reply_to'); $stmt3->execute(['reply_to' => $id]); while ($row3 = $stmt3->fetch()) { echo "<br>"; echo "// UID: [".$row3['post_by']."] ---- ".$row3['date']."------->> ".$row3['content']." <a href='post_post.php'>Reply</a>"; // comment($row3['reply_id']); $reply_to_id = $row3['reply_id']; $stmt11 = $db->prepare('SELECT * FROM `posts` WHERE reply_to = :thing'); $stmt11->execute(['thing' => $reply_to_id]); while ($row = $stmt11->fetch()) { // ----------------------------- SEE HERE (sp[lice]) ----------------------------- echo "<br>---[UID:"; echo $row['post_by']."] -- ".$row['date'].": "; echo $row['content']; echo " <a href='reply.php'>Reply</a>"; echo " [Reply to: ".$row['reply_to']."]"; echo " [Reply ID: ".$row['reply_id']."]"; $reply_to_id=$row['reply_id']; $stmt111 = $db->prepare('SELECT * FROM `posts` WHERE reply_to = :thing'); $stmt111->execute(['thing' => $reply_to_id]); while ($row33 = $stmt111->fetch()) { echo "<br>--------[UID:"; echo $row33['post_by']."] -------- ".$row['date'].": "; echo $row33['content']; echo " <a href='reply.php'>Reply</a>"; echo " [Reply to: ".$row33['reply_to']."]"; echo " [Reply ID: ".$row33['reply_id']."]"; echo "<br>"; comment($row33['reply_id']); }} // ------------------------------------------------------ } ?> </ul> <?php if ($user->is_logged_in()){ } else { echo "<h2>Login to create post </h2>"; echo "<a href='login.php'>Click to login</a>"; } ?> <?php //include header template require('layout/footer.php'); ?>
This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=343263.0 Guys/Gals; This below block outputs a very simple progress bar, i'm curious if anyone would see a solution to perform a task when this bar reaches the end as you can see it's set to countinue until width<400 when that 400 is true I and in essence the process is done (even though nothing in reality) i want to display countinue but only when it's done echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' bgcolor='#666666'><tr><td width='506' height='52' valign='top'><script type='text/javascript'>function progress(){if(document.images['bar'].width<400){document.images['bar'].width+=5;document.images['bar'].height=5; }else{clearInterval(ID);}}var ID;window.onload=function(){ID=setInterval('progress();',$cpuspeed);}</script><img src='images/white.gif' name='bar'/><br /><font color='#ffffff'>Cracking....</font></td></tr></table>"; any dideas Hi, I want that user can only read my article but can't download it. neither with save page as or with view source, even not with selecting text. and copy and paste. is there any solution in php to do that. Please help Thanks Can this be done easily enough with php? I've attached my current code below, but don't see how i could add this in. Code: [Select] $name = $_FILES['file']['name']; $temp = $_FILES['file']['tmp_name']; $size = $_FILES['file']['size']; $random = md5(uniqid(rand(), true)); $random = substr($random, 0, 20); if (!$name || !$temp || !$size) { echo "Go back and select a file."; exit(); } foreach ($_FILES as $file) { if ($file['tmp_name'] != null) { $thisext1=explode(".", strtolower($file['name'])); $thisext=$thisext1[count($thisext1)-1]; if (!in_array($thisext, $extensions)) { echo "That file type is not allowed."; exit(); } } } I have a problem with the "comments count" in the toggle link in my blog: www.albertosotophotography.com
I have this script for show/hide comments in main page:
<script type= "text/javascript"> // Show/Hide Comments jQuery(document).ready(function() { // Get #comments div var uniqueAppend = 1; var tempName = 'comments'; while(jQuery("#comments").length > 0 ){ jQuery("#comments").attr('id',tempName + uniqueAppend++).addClass('commentContainer') } var commentsDiv = jQuery('.commentContainer'); // Only do this work if that div isn't empty if (commentsDiv.length) { // Hide #comments div by default jQuery(commentsDiv).hide(); // Append a link to show/hide jQuery('<a/>') .attr('class', 'toggle-comments') .attr('href', '#') .html('Notes') .insertAfter(commentsDiv); // Encase button in .toggle-comments-container div jQuery('.toggle-comments').wrap(jQuery('<div/>', { class: 'toggle-comments-container' })) // When show/hide is clicked jQuery('.toggle-comments').on('click', function(e) { e.preventDefault(); // Show/hide the div using jQuery's toggle() var commentContainer = jQuery(this).parent('.toggle-comments-container').prev('.commentContainer'); jQuery(commentContainer).slideToggle('slow', function() { // change the text of the anchor var anchor = jQuery(commentContainer).siblings('.toggle-comments-container').children('.toggle-comments'); var anchorText = anchor.text() == 'Notes' ? 'Hide' : 'Notes'; jQuery(anchor).html(anchorText); }); }); } // End of commentsDiv.length }); // End of Show/Hide Comments </script>I use: .html('<?php comments_number( '0 notes', '1 note', '% notes' ); ?>')for name the "comments toggle link" with the count of comments for each single post. The problem is that all posts shows the same count: the comments presents in the first post. Someone can help me? Alberto hey guys, I'm quite new to PHP and i was wondering if someone would be able to help me out with this. The code i have checks the database to see if a user has provided a Vimeo ID. If they haven't, $video_check will equal a line of html that says the user hasn't added any videos to their portfolio. If the a vimeo ID is present, i want $video_check to equal a bunch of html and css with a foreach function inside that is used to display the users videos from vimeo. The foreach function works fine when its not assigned to the $video_check variable. How do i structure it so that it displays correctly? If you click on videos on this page you might get a better idea of what i'm talking about. http://www.myfilmportfolio.ie/profile.php?id=33 and here is the code i'm having the problem with: /////// check if user has provided vimeo id ////////////////////////// $vimeoID = $row["vimeoID"]; $video_check=''; if (empty($vimeoID)){ $video_check = '<h3>'.$firstname .' has not added any videos to their portfolio</h3>'; } else{ $video_check = '<div id="stats"> <div style="clear: both;"></div> </div> <div id="wrapper"> <div id="embed"></div> <div id="thumbs"> <ul> <?php foreach ($videos->video as $video): ?> <li> <h4><?=$video->title?></h4> <a href="<?php echo $video->url ?>"> <img src="<?php echo $video->thumbnail_medium ?>" class="thumb" /></a> <p><?=$video->description?></p> <br /> </li> <?php endforeach ?> </ul> </div> </div>'; } if anyone could help me out id really appreciate it. Cheers, G please it is very important!! I have a script (main file is index.php) that is called into an iframe src via an url reference... http://www.xxxx.com/folder/userfolder/folderwithemailname/index.php works perfectly!!.. How can i prevent someone getting direct url access to the file? if someone were to take the url: http://www.xxxx.com/folder/userfolder/folderwithemailname/index.php and place it into the address bar, they have access to the file... points to note: -i have no database for this script, -the iframe is called directly into a html file, - i dont know the userfolder or the emailfolder names, - and the index.php is linked to several other .php and .js and .html files in different folders.... // i can add something like this to these file:(i found this on the net). Add this to the page that you want to only be included <?php if(!defined('MyConst'){die('Direct access not premitted');} ?> then on the pages that include it add <?php define('MyConst', TRUE); ?> this will prevent the files being accessed, but then i cant access the file via the iframe url.. please any ideas??? best regards Tony Hi By the the way the server this site is hosted on is flipping fast! I'm still a php beginner. I have a php file, the entire code is he <?php get_header(); ?> <?php if(!is_paged()) { ?> <div id="top" class="clearfloat"> <div id="headline"> <?php if ( function_exists('show_nivo_slider') ) { show_nivo_slider(); } ?> </div> <div id="featured"> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(8) ) : ?> <?php endif; ?> </div> </div> <div id="middle" class="clearfloat"> <?php $display_categories = array(7, 13, 17, 18, 1528); $i = 1; foreach ($display_categories as $category) { ?> <div id="cat-<?php echo $i; ?>" class="category"> <?php query_posts("showposts=1&cat=$category")?> <span class="cat_title"><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a></span> <a href="<?php echo get_category_link($category);?>"></a> </div> <?php $i++; ?> <?php } ?> </div> <?php } ?> <div id="bottom" class="clearfloat"> <div id="front-list"> <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("cat=-27,-28&paged=$page&posts_per_page=10"); ?> <?php while (have_posts()) : the_post(); ?> <div class="clearfloat"> <h3 class=cat_title><?php the_category(', '); ?> »</h3> <div class="title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div> <div class="meta">[<?php the_time('j M Y') ?> | <?php comments_popup_link('No Comment', 'One Comment', '% Comments');?> | <?php if(function_exists('the_views')) { the_views(); } ?>]</div> <div class="spoiler"> <?php $values = get_post_custom_values("Image"); if (isset($values[0])) { ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php $values = get_post_custom_values("Image"); echo $values[0]; ?>&w=150&h=150&zc=1&q=100" alt="<?php the_title(); ?>" class="left" width="150px" height="150px" /></a> <?php } ?> <?php the_excerpt(); ?> </div> </div> <?php endwhile; ?> <div class="navigation"> <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?> <div class="right"><?php next_posts_link('Next Page »') ?></div> <div class="left"><?php previous_posts_link('« Previous Page') ?></div> <?php } ?> </div> </div> <?php get_sidebar(); ?> </div> <?php get_footer(); ?> I want to remove the following block on line 19 to 33 because I don't need it: <?php $display_categories = array(7, 13, 17, 18, 1528); $i = 1; foreach ($display_categories as $category) { ?> <div id="cat-<?php echo $i; ?>" class="category"> <?php query_posts("showposts=1&cat=$category")?> <span class="cat_title"><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a></span> <a href="<?php echo get_category_link($category);?>"></a> </div> <?php $i++; ?> <?php } ?> </div> <?php } ?> But when I remove that I get the error, unexpected end of file error and references to <?php get_footer(); ?> I need to understand why this is happening, not just how to fix it (although I need that too). My suspicion is one of the endif's. Hey, I'm trying to open a .php file and read a comment block that is in the beginning of the file. I'm having some trouble in that nothing is being echoed out. Here is the reading file: <?php $fb = fopen("tepl.php", "r"); $data = fread($fb, 8192); fclose($fb); var_dump($data); ?> here is the file (tepl.php) being read: <?php /* Name: Test Plugin 1 URI: http://www.theorangeday.com/plugintest/ Description: This is just a test plugin because I need to test how this thing is going to work overall. Author: Thomas Francis Author URI: http://www.theorangeday.com/ Version: 0.1 */ function test_plugin(){ echo "we loaded the test plug"; } ?> the var_dump returns Code: [Select] string(321) " " What's wrong here? Much of the PHP documentation is broken into very small pages. I find that this makes it very difficult to use. Does anyone else find this? I have a hackish but useful program which takes the PHP single-file documentation and splits it into one page per extension, ensuring that links between pages work correctly. It works quite well. I wonder if anyone else would find this useful? If so, then I should have time in the next few weeks to clean it up and make it publicly available. I previously used https://www.phpdoc.org/ (not sure about the part 2 part) but got out of the habit. Wish to change, but had more installation problems than expected. Is it still considered a good solution? If so, any recommendations whether I should install using pear, phar, or other? Thanks Hi all i have stumbled across an issue and really need some help i have got a function below which i am using in a wordpress plugin. here is the code. // Base function function isd_s3player() { // Plugin Url $s3url = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); echo '<object type="application/x-shockwave-flash" data="'.$s3url.'dewplayer-playlist.swf" width="235" height="200" id="dewplayer" name="dewplayer"> <param name="wmode" value="transparent" /> <param name="wmode" value="transparent" /> <param name="movie" value="'.$s3url.'dewplayer-playlist.swf" /> <param name="flashvars" value="showtime=true&autoreplay=true&xml='.$s3url.'playlist.php&autostart=1" /> </object>'; } ok the problem i am having is i cant passed the database variable to the playlist.php which the dewplayer needs to call within the function. is their a way to somehow use or set the playlist.php in this function without having to call it seperatly??? Here is my playlist.php <?php $bucket = get_option("isd-bucket"); $folder = get_option("isd-folder"); //include the S3 class if (!class_exists('S3'))require_once('s3/S3.php'); //AWS access info if (!defined('awsAccessKey')) define('awsAccessKey', 'amazon key'); if (!defined('awsSecretKey')) define('awsSecretKey', 'amazon secret key'); //instantiate the class $s3 = new S3(awsAccessKey, awsSecretKey); // Get the contents of our bucket $bucket_contents = $s3->getBucket($bucket,$folder); header("Content-type: text/xml"); $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; $xml_output .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">\n'; $xml_output .= "<trackList>\n"; foreach ($bucket_contents as $file){ $fname = $file['name']; $furl = "http://$amazon_bucket.s3.amazonaws.com/".urlencode($fname); if(preg_match("/\.mp3$/i", $furl)) { if (isset($outputted[$furl])) { continue; } $xml_output .= "\t<track>\n"; $xml_output .= "\t\t<location>" . $furl . "</location>\n"; $xml_output .= "\t\t<creator>" . $fname . "</creator>\n"; $xml_output .= "\t\t<album>" . $fname . "</album>\n"; $xml_output .= "\t\t<title>" . basename($fname) . "</title>\n"; $xml_output .= "\t\t<annotation>I love this song</annotation>\n"; $xml_output .= "\t\t<duration>32000</duration>\n"; $xml_output .= "\t\t<image>covers/smetana.jpg</image>\n"; $xml_output .= "\t\t<info></info>\n"; $xml_output .= "\t\t<link>" . $furl . "</link>\n"; $xml_output .= "\t</track>\n"; $outputted[$furl] = true; } } $xml_output .= "</trackList>"; echo $xml_output; ?> ok so as you can see right at the top i am trying to grab two option from the database but it doesnt allow you to do it this way within wordpress. So i guess what i am asking is their a way to completely skip the playlist.php file and do everything within the function??? Any help?? form example, in the first page, there is a article, it takes contents from database, if a article is shorter than 1000, it displays the full content on the first page, if its longer than 1000, it will display a short part of article, and displays a 'read more' on the end of the article. how to make this? I think we cant do this by paging function, can we? Hi there, As the question says i tried several things but i can't work it out and my knowledge about php isn't that well. Hi all, Is there a way to get jquery ajax to run a specific PHP function. At the moment Im sending extra paramaters like check=1: Code: [Select] ajaxCall: function(process, obj, type){ $.post("registration-post.php", type + "=" + process + "&check=1", function(data){ alert(data); if(data==""){ $(obj).css(registration.errorNotificationType, registration.validatedColour); }else{ //registration.validationCollection.push($.trim(data)); $('.error').append($.trim(data) + "<br />"); $(obj).css(registration.errorNotificationType, registration.errorColour); registration.progress = false; } } ); } then doing an if statement, if($_POST["check"]==1){ $registration->checkDuplication(); } if($registration->validationBool){ $registration->validateFields(); } but its not really doing the job i need it to do. I'm a little stuck in my own battle to make cleaner coding Hi, I'm creating a PHP application to handle my SQL server and I've run into a bit of a problem; I have two files atm: mainClass.php and testSite.php My mainClass.php looks like this: Code: [Select] class mainClass { private $host = 'localhost'; public function createDb($user,$pass,$dbName) { $con = mysql_connect($host, $user, $pass); if (!$con){ die('Could not connect: '.mysql_error()); } $sql = "CREATE DATABASE `$dbName`;"; if (!mysql_query($sql)){ die('Error 1: '.mysql_error()); } mysql_close(); } }and testSite.php looks like this: Code: [Select] <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <h1>testSite for my PHP app</h1> <?php function __autoload($className){ require_once "./classes/{$className}.php"; } $test = new mainClass(); ?> <form name='createDb' method='post' action=''> User: <input type='text' name='user'><br> Password: <input type='password' name='pass'><br> dbName: <input type='text' name='dbName'><br> <input type='submit' value='Create DB'> </form> </body> </html> What I'm asking is if it is possible to make the form-action from testSite.php run the createDb function from mainClass.php I have pretty much no idea how to do it but I tried like this: Code: [Select] <form name='createDb' method='post' action="<?php $test->createDb($_POST['user'],$_POST['pass'],$_POST['dbName']); ?>"> User: <input type='text' name='user'><br> Password: <input type='password' name='pass'><br> dbName: <input type='text' name='dbName'><br> <input type='submit' value='Log in'> </form>But that just made the whole form disappear so now I'm completely lost, any help greatly appreciated. PS: I'm doing this to get better at PHP so please don't come with advice like "use a framework" or "there already are applications that handles this", I know there is. hi, i am using a database to populate a webpage with text. How do I make a function to add line breaks to the text? an example page I want to use it on it http://www.stayneartheairport.com/bandb.php?id=11084507&airport=manchester You can see the two text areas of description and facilities have no paragraphs or other formatting. I want the code to scan the text - and if there is say <br> - it will remove it an replace it with a line break. |