Пример #1
0
function apiKey()
{
    $key = randomString(24);
    // Make sure it doesn't already exist
    $sql = "SELECT * \n\t\t\tFROM user \n\t\t\tWHERE apikey = '" . nice($key) . "'";
    $results = mysql_query($sql);
    $row = mysql_fetch_assoc($results);
    if ($row) {
        return apiKey();
    } else {
        return $key;
    }
}
Пример #2
0
function nice()
{
    echo "<br><hr><br>";
}
$str1 = "Hello";
$str2 = "World";
//string concate...
print $str1 . " " . $str2;
nice();
//string length
print "The length of string {$str1} : " . strlen($str1);
nice();
//string compare...
if (strcmp($str1, $str2) != 0) {
    print "The strings {$str1} and {$str2} are not same.....!<br>";
}
if (strcmp($str1, "Hello") == 0) {
    print "The string {$str1} is Hello!";
}
nice();
//string reverse...
print strrev($str1);
nice();
//strtok() is the function to generate the tokens out of string
?>


</body>

</html>
Пример #3
0
 private function editOrSave($action)
 {
     if (!POST("title")) {
         return getAlert("You need to write a title");
     } elseif (!POST("description")) {
         return getAlert("You need to write a description");
     } elseif (!ping(POST("URL"))) {
         return getAlert("Invalid URL");
     } elseif (FILES("image", "name") === "" and $action === "save") {
         return getAlert("Selected image");
     } elseif (FILES("preview1", "name") === "" and $action === "save") {
         return getAlert("Selected preview");
     } elseif (FILES("preview2", "name") === "" and $action === "save") {
         return getAlert("Selected preview");
     }
     if (FILES("image", "name") !== "") {
         $upload = $this->upload("image");
         if ($upload) {
             $this->image = $upload;
         } else {
             return $this->error;
         }
     } else {
         if ($action === "edit") {
             $this->image = "";
         }
     }
     if (FILES("preview1", "name") !== "") {
         $upload = $this->upload("preview1");
         if ($upload) {
             $this->preview1 = $upload;
         } else {
             return $this->error;
         }
     } else {
         if ($action === "edit") {
             $this->preview1 = "";
         }
     }
     if (FILES("preview2", "name") !== "") {
         $upload = $this->upload("preview2");
         if ($upload) {
             $this->preview2 = $upload;
         } else {
             return $this->error;
         }
     } else {
         if ($action === "edit") {
             $this->preview2 = "";
         }
     }
     $this->ID = POST("ID_Work");
     $this->title = POST("title", "decode", "escape");
     $this->nice = nice($this->title);
     $this->description = POST("description");
     $this->URL = POST("URL");
     $this->state = POST("state");
 }
Пример #4
0
 private function save()
 {
     $this->Db->table("url", "URL");
     $this->Db->values("'{$this->URL}'");
     $insertID1 = $this->Db->save();
     if (is_array($this->image)) {
         $small = $this->image["small"];
         $medium = $this->image["medium"];
     } else {
         $small = NULL;
         $medium = NULL;
     }
     $fields = "ID_User, ID_URL, Title, Nice, Content, Author, Start_Date, Text_Date, Year, Month, Day, Image_Small, Image_Medium, ";
     $fields .= "Enable_Comments, Language, Pwd, State";
     $values = "'" . SESSION("ZanUserID") . "', '{$insertID1}', '{$this->title}', '{$this->nice}', '{$this->content}', '{$this->author}', '{$this->date1}', ";
     $values .= "'{$this->date2}', '{$this->year}', '{$this->month}', '{$this->day}', '{$small}', '{$medium}', '{$this->comments}', ";
     $values .= "'{$this->language}', '{$this->password}', '{$this->state}'";
     $this->Db->table($this->table, $fields);
     $this->Db->values($values);
     $insertID2 = $this->Db->save();
     if ($this->mural) {
         $fields = "ID_Post, Title, URL, Image";
         $values = "'{$insertID2}', '{$this->title}', '{$this->URL}', '{$this->mural}'";
         $this->Db->table("mural", $fields);
         $this->Db->values($values);
         $this->Db->save();
     }
     if (is_array($this->categories)) {
         $this->Db->table("categories2applications");
         foreach ($this->categories as $category) {
             $categories[] = $this->Db->findBy("ID_Category", $category);
         }
         $this->Db->table("categories2records", "ID_Category2Application, ID_Record");
         foreach ($categories as $category) {
             $this->Db->values("'" . $category[0]["ID_Category2Application"] . "', '{$insertID2}'");
             $insertID3 = $this->Db->save();
         }
     }
     if (is_array($this->tags)) {
         foreach ($this->tags as $tag) {
             $this->Db->table("tags", "Title, Nice");
             $this->Db->values("'" . decode($tag) . "', '" . nice($tag) . "'");
             $insertID4 = $this->Db->save();
             $this->Db->table("tags2applications", "ID_Application, ID_Tag");
             $this->Db->values("'3', '{$insertID4}'");
             $insertID5 = $this->Db->save();
             $this->Db->table("tags2records", "ID_Tag2Application, ID_Record");
             $this->Db->values("'{$insertID5}', '{$insertID2}'");
             $insertID6 = $this->Db->save();
         }
     }
     if ($insertID1 === "rollback" or $insertID2 === "rollback") {
         $this->Db->rollBack();
         return getAlert("Insert error");
     } else {
         $this->Db->commit();
         return getAlert("The post has been saved correctly", "success", $this->URL);
     }
 }
Пример #5
0
 private function editOrSave($action)
 {
     if (!POST("title")) {
         return getAlert("You need to write a title");
     }
     if (!POST("category") and POST("ID_Category") === "0") {
         $this->category = 0;
     } else {
         if (POST("category")) {
             $this->category = POST("category");
             $categorynice = nice($this->category);
             $data = $this->Db->call("setCategory('{$this->category}', '{$categorynice}', '" . getXMLang(_webLang, TRUE) . "', 'Active')");
             $this->category = $data[0]["ID_Category"];
         } else {
             $this->category = POST("ID_Category");
         }
     }
     if ($action === "edit") {
         if (FILES("file", "name") !== "") {
             $this->Files = $this->core("Files");
             $this->Files->filename = FILES("file", "name");
             $this->Files->fileType = FILES("file", "type");
             $this->Files->fileSize = FILES("file", "size");
             $this->Files->fileError = FILES("file", "error");
             $this->Files->fileTmp = FILES("file", "tmp_name");
             if (!$this->category or $this->category === 0) {
                 $dir = "www/lib/files/images/gallery/unknown/";
             } else {
                 $data = $this->Db->find($this->category, $this->table);
                 $dir = "www/lib/files/images/gallery/" . $data[0]["Nice"] . "/";
             }
             if (!file_exists($dir)) {
                 mkdir($dir, 0777);
             }
             $upload = $this->Files->upload($dir);
             if ($upload["upload"]) {
                 $this->Images = $this->core("Images");
                 $this->original = $this->Images->getResize("original", $dir, $upload["filename"], _minOriginal, _maxOriginal);
                 $this->medium = $this->Images->getResize("medium", $dir, $upload["filename"], _minOriginal, _maxOriginal);
                 $this->small = $this->Images->getResize("small", $dir, $upload["filename"], _minOriginal, _maxOriginal);
             } else {
                 return getAlert($upload["message"]);
             }
         } else {
             if ($action === "edit") {
                 $this->original = "";
                 $this->medium = "";
                 $this->small = "";
             } else {
                 return getAlert("Selected Image");
             }
         }
     }
     $this->ID = POST("ID_Image");
     $this->title = POST("title", "decode", "escape");
     $this->nice = nice($this->title);
     $this->description = POST("description");
     $this->Situation = POST("Situation");
     $this->date1 = now(4);
     $this->date2 = now(2);
 }
Пример #6
0
function getScript($js, $application = NULL, $extra = NULL, $getJs = FALSE, $external = FALSE)
{
    $HTML = NULL;
    if (file_exists($js) and !$external) {
        return loadScript($js);
    } else {
        if ($external) {
            return loadScript($js, $application, TRUE);
        } elseif (isset($application)) {
            return loadScript($js, $application);
        } else {
            if ($js === "jquery") {
                return loadScript("www/lib/scripts/js/jquery.js");
            } elseif ($js === "checkbox") {
                $HTML = '	<script type="text/javascript">
								function checkAll(idForm) {
									$("form input:checkbox").attr("checked", "checked");
								}
						
								function unCheckAll(idForm) {
									$("form input:checkbox").removeAttr("checked");
								}
							</script>';
            } elseif ($js === "external") {
                $HTML = '	<script type="text/javascript">
								$(document).ready(function() { 
									$(function() {
										$(\'a[rel*=external]\').click(function() {
											window.open(this.href);
											return false;
										});
									});
								});
							</script>				
							
							<noscript><p class="NoDisplay">' . __("Disable Javascript") . '</p></noscript>';
            } elseif ($js === "show-element") {
                $HTML = '	<script type="text/javascript">
								function showElement(obj) {
									if(obj.className == "no-display") {
										obj.className = "display";
									} else {
										obj.className = "no-display";
									}
								}
							</script>';
            } elseif ($js === "tiny-mce") {
                $HTML = loadScript("www/lib/scripts/js/tiny_mce/tiny_mce.js");
                $HTML .= '<script type="text/javascript">';
                if ($extra === "class") {
                    $HTML .= '		
									tinyMCE.init({
										mode : "textareas",
										editor_selector : "editor",
										editor_deselector : "noeditor",
										theme : "simple"
									});
							';
                } elseif ($extra !== "basic") {
                    $HTML .= '			
									tinyMCE.init({
										mode : "exact",
										elements : "editor",
										theme : "advanced",
										skin : "o2k7",
										cleanup: true,
										plugins : "videos,advcode,safari,pagebreak,style,advhr,advimage,advlink,emotions,preview,media,fullscreen,template,inlinepopups,advimage,media,paste",              
										theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,|,link,unlink,|,videos,image,advcode,|,forecolor,|,charmap,|,pastetext,pasteword,pastetext,fullscreen,pagebreak,preview",
										theme_advanced_buttons2 : "",
										theme_advanced_buttons3 : "",
										theme_advanced_toolbar_location : "top",
										theme_advanced_toolbar_align : "left",
										theme_advanced_statusbar_location : "bottom",
										theme_advanced_resizing : false,
										convert_urls : false,                    
										content_CSS : "css/content.css",               
										external_link_list_url : "lists/link_list.js",
										external_image_list_url : "lists/image_list.js",
										media_external_list_url : "lists/media_list.js"
									});
							';
                } else {
                    $HTML .= '		
									tinyMCE.init({
										mode : "exact",
										elements : "editor",
										theme : "simple",
										editor_selector : "mceSimple"
									});
							';
                }
                $HTML .= '	function insertHTML(content) {
								parent.tinyMCE.execCommand(\'mceInsertContent\', false, content);
							}
						</script>';
            } elseif ($js === "upload") {
                $iPx = POST("iPx") ? POST("iPx") : 'i';
                $iPath = POST("iPath") ? POST("iPath") : 'www/lib/files/images/uploaded/';
                $iPath = POST($iPx . "Dirbase") ? POST($iPx . "Dirbase") : $iPath;
                $iPath = POST($iPx . "Make") ? POST($iPx . "Dir") . slug(POST($iPx . "Dirname")) . _sh : $iPath;
                $dPx = POST("dPx") ? POST("dPx") : "d";
                $dPath = POST("dPath") ? POST("dPath") : "www/lib/files/documents/uploaded/";
                $dPath = POST($dPx . "Dirbase") ? POST($dPx . "Dirbase") : $dPath;
                $dPath = POST($dPx . "Make") ? POST($dPx . "Dir") . nice(POST($dPx . "Dirname")) . _sh : $dPath;
                $application = whichApplication();
                ?>
						<script type="text/javascript">
							$(document).on("ready", function() {
								function uploadResponse(state, file) {
									var path, insert, ok, error, form, message; 
									
									path = '<?php 
                print path($iPath, TRUE);
                ?>
' + file;

									HTML = '\'<img src=\\\'' + path + '\\\' alt=\\\'' + file + '\\\' />\'';
									
									insert = '<li><input name="iLibrary[]" type="checkbox" value="' + path + '" /> <span class="small">00<' + '/span>';
									insert = insert + '<a href="' + path + '" rel="external" title="<?php 
                print __(_("Preview"));
                ?>
"><span class="tiny-image tiny-search">&nbsp;&nbsp;&nbsp;&nbsp;</span><' + '/a>';
									insert = insert + '<a class="pointer" onclick="javascript:insertHTML(' + HTML + ');" title="<?php 
                print __(_("Insert image"));
                ?>
"><span class="tiny-image tiny-add">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;';
									insert = insert + '<span class="bold">' + file + '<' + '/span><' + '/a><' + '/li>';						
									
									if(state == 1) {
										message = '<?php 
                print __(_("The file size exceed the permitted limit"));
                ?>
';
									}
									
									if(state == 2) {
										message = '<?php 
                print __(_("An error has ocurred"));
                ?>
';
									}
									
									if(state == 3) {
										message = '<?php 
                print __(_("The file type is not permitted"));
                ?>
';
									}
									
									if(state == 4) {
										message = '<?php 
                print __(_("A problem occurred when trying to upload file"));
                ?>
';
									}
									
									if(state == 5) {
										message = '<?php 
                print __(_("The file already exists"));
                ?>
';
									}
									
									if(state == 6) {
										message = '<?php 
                print __(_("Successfully uploaded file"));
                ?>
';

										$('#i-add-upload').html = insert + $('#i-add-upload').html;
									}
									
									document.getElementById('i-upload-message').innerHTML = message;
								}												
								
								function uploadDocumentsResponse(dState, dFile, dIcon, dAlt) {
									var dPath, dInsert, dOk, dError, dForm, dMessage, dHTML;
									
									dPath = '<?php 
                print path($dPath, TRUE);
                ?>
' + dFile;					
									dHTML = '\'<a href=\\\'' + dPath + '\\\' title=\\\'' + dFile + '\\\'><img src=\\\'' + dIcon + '\\\' alt=\\\'' + dAlt + '\\\' /></a>\'';
									
									dInsert = '<li><input name="dLibrary[]" type="checkbox" value="' + dPath + '" />';
									dInsert = dInsert + ' <span class="small">00<' + '/span><a href="' + dPath + '" title="<?php 
                print __(_("Download file"));
                ?>
">';
									dInsert = dInsert + '<span class="tiny-image tiny-file">&nbsp;&nbsp;&nbsp;&nbsp;</span><' + '/a>';
									dInsert = dInsert + '<a class="pointer" onclick="javascript:insertHTML(' + dHTML + ');" title="<?php 
                print __(_("Insert file"));
                ?>
">';
									dInsert = dInsert + '<span class="tiny-image tiny-add">&nbsp;&nbsp;&nbsp;&nbsp;</span>';
									dInsert = dInsert + '<span class="bold">' + dFile + '<' + '/span><' + '/a><' + '/li>';								
							
									if(dState == 1) {
										message = '<?php 
                print __(_("The file size exceed the permitted limit"));
                ?>
';
									}
									
									if(dState == 2) {
										message = '<?php 
                print __(_("An error has ocurred"));
                ?>
';
									}
									
									if(dState == 3) {
										message = '<?php 
                print __(_("The file type is not permitted"));
                ?>
';
									}
									
									if(dState == 4) {
										message = '<?php 
                print __(_("A problem occurred when trying to upload file"));
                ?>
';
									}
									
									if(dState == 5) {
										message = '<?php 
                print __(_("The file already exists"));
                ?>
';
									}								
									
									if(dState == 6) {
										message = '<?php 
                print __(_("Successfully uploaded file"));
                ?>
';

										document.getElementById('d-add-upload').innerHTML = dInsert + document.getElementById('d-add-upload').innerHTML;
									}
									
									document.getElementById('d-upload-message').innerHTML = message;
								}
						 	});
						</script>
						
						<noscript><p class="no-display"><?php 
                print __(_("Disable Javascript"));
                ?>
</p></noscript>
					
					<?php 
                return NULL;
            } elseif ($application) {
                $HTML = '<script type="text/javascript" language="javascript">' . $js . '</script>';
            }
            return $HTML;
        }
    }
}
Пример #7
0
<?php

$fp = fopen('../input/input5.txt', 'r');
$nice = 0;
while ($line = trim(fgets($fp))) {
    if (nice($line)) {
        $nice++;
    }
}
echo 'There are ' . $nice . ' nice lines' . PHP_EOL;
function nice($line)
{
    global $argv;
    // don't you judge me, this is quick and dirty
    preg_match_all('/(.)([^\\1]).*\\1\\2/', $line, $matches);
    if (count($matches[0]) === 0) {
        if (!empty($argv[1]) && $argv[1] == '-d') {
            echo $line . ' fails part 1' . PHP_EOL;
        }
        return false;
    }
    unset($matches);
    preg_match_all('/(.).\\1/', $line, $matches);
    if (count($matches[0]) === 0) {
        if (!empty($argv[1]) && $argv[1] == '-d') {
            echo $line . ' fails part 2' . PHP_EOL;
        }
        return false;
    }
    return true;
}
Пример #8
0
 public function editReply()
 {
     $ID_Post = POST("ID_Post");
     $title = POST("title", "decode", "escape");
     $content = cleanTiny(POST("content", "decode", FALSE));
     $nice = nice($title);
     $date1 = now(4);
     $date2 = now(2);
     $hour = date("H:i:s", $date1);
     $this->Db->call("updateReplyTopic('{$ID_Post}', '{$title}', '{$nice}', '{$content}', '{$date1}', '{$date2}', '{$hour}')");
     return TRUE;
 }