|
Syntax for: PHP_CSL_6 . Classes |
<?php
function file_exist($filename) {
global $snippet_root, $snippet_library;
if(file_exists($snippet_root.$snippet_library.$filename)) {
return false;
} else {
return true;
}
}
function file_open($filename) {
global $snippet_root, $snippet_library;
if($fp = @fopen($snippet_root.$snippet_library.$filename, "r")) {
$fp = @fopen($snippet_root.$snippet_library.$filename, "r");
$contents = fread($fp, 80000);
fclose($fp);
$contents = dec_string($contents);
return $contents;
} else {
return false;
}
}
function file_write($filename, $filecontent) {
global $snippet_root, $snippet_library;
if($fp = @fopen( $snippet_root.$snippet_library.$filename,"w ")) {
$contents = fwrite($fp, $filecontent, 80000);
fclose($fp);
return true;
} else {
return false;
}
}
function file_delete($cat, $snip) {
global $snippet_root, $snippet_library, $snippet_ext_d, $snippet_ext_s;
$file_s = $snippet_root.$snippet_library.$cat.".".$snip.$snippet_ext_s;
$file_d = $snippet_root.$snippet_library.$cat.".".$snip.$snippet_ext_d;
chmod($file_s, 0777);
chmod($file_d, 0777);
if(unlink($file_s) && unlink($file_d)) {
// continue
} else {
echo "ERROR TYPE: Library files may be locked !!!<br><Br>";
return false;
}
return true;
}
function dec_string($string) {
return strrev(urldecode($string));
}
function enc_string($string) {
return urlencode(strrev($string));
}
function cats_add($new_cat) {
global $snippet_cats;
// remove invalid characters
$reg = new regex;
$reg->set_string($new_cat);
$new_cat = $reg->get_string();
// read the current cats file
$fp = fopen($snippet_cats,"r");
$old_cat = fread($fp, 80000);
fclose( $fp );
// build the new cats
$old_cat = $new_cat.",".$old_cat;
// split , pattern as cats divider
$d_array = split (",", $old_cat);
// remove duplicate entrys
$data_array = array_unique($d_array);
// order the cats in alphnumerical order asc
sort($data_array);
$new_cat = "";
foreach ($data_array as $tmp) {
$new_cat .= $tmp.",";
}
// write the new cats to file
$fp = fopen($snippet_cats,"w ");
fwrite($fp, $new_cat, 80000);
fclose( $fp );
return true;
}
function cats_get() {
global $snippet_cats;
$fp = fopen($snippet_cats,"r");
$data = fread($fp, 80000);
fclose( $fp );
// split , pattern as cats divider
$data_array = split (",", $data);
$data_array = array_unique($data_array);
return $data_array;
}
function cats_delete($cat) {
global $snippet_cats, $snippet_root, $snippet_library;
global $snippet_ext_s, $snippet_ext_d;
$all_cats = cats_get();
$new_cat = ",";
foreach($all_cats as $tmp_cats) {
if(strlen($tmp_cats) >1) {
if($tmp_cats == $cat) {
// do nowt
} else {
$new_cat .= $tmp_cats.",";
}
}
}
// write the new cats to file
$fp = fopen($snippet_cats,"w ");
fwrite($fp, $new_cat, 80000);
fclose( $fp );
$list_ob = new snips;
$list_ob->snips_list_set($cat);
$list = $list_ob->snips_list_get();
foreach ($list as $f) {
$file_s = $snippet_root.$snippet_library.$cat.".".$f.$snippet_ext_s;
$file_d = $snippet_root.$snippet_library.$cat.".".$f.$snippet_ext_d;
chmod($file_s, 0777);
chmod($file_d, 0777);
if(unlink($file_s) && unlink($file_d)) {
// continue
} else {
echo "ERROR TYPE: Library files may be locked !!!<br><Br>";
return false;
}
}
return true;
}
function cats_edit($old_cat, $new_cat) {
global $snippet_cats, $snippet_root, $snippet_library;
global $snippet_ext_s, $snippet_ext_d;
$reg = new regex;
$reg->set_string($new_cat);
$new_cat = $reg->get_string();
// get a list of all snippets in this category
$list_ob = new snips;
$list_ob->snips_list_set($old_cat);
$list = $list_ob->snips_list_get();
// rename each one
foreach ($list as $f) {
$file_s_old = $snippet_root.$snippet_library.$old_cat.".".$f.$snippet_ext_s;
$file_s_new = $snippet_root.$snippet_library.$new_cat.".".$f.$snippet_ext_s;
$file_d_old = $snippet_root.$snippet_library.$old_cat.".".$f.$snippet_ext_d;
$file_d_new = $snippet_root.$snippet_library.$new_cat.".".$f.$snippet_ext_d;
chmod($file_s_old, 0777);
chmod($file_d_old, 0777);
if(rename($file_s_old, $file_s_new) && rename($file_d_old, $file_d_new)) {
// ok
} else {
echo "ERROR TYPE: Library files may be locked !!!<br><Br>";
return false;
}
}
// rename the category in the 'cats' text file
$all_cats = cats_get();
$final_cat = ",$new_cat,";
foreach($all_cats as $tmp_cats) {
if(strlen($tmp_cats) >1) {
if($tmp_cats == $old_cat) {
// ok
} else {
$final_cat .= $tmp_cats.",";
}
}
}
// write the new cats to file
$fp = fopen($snippet_cats,"w ");
if(fwrite($fp, $final_cat, 80000)) {
fclose( $fp );
return true;
} else {
return false;
}
}
class REGEX {
// var $out_string = "";
function regex($out_string = "") {
$this->out_string = "";
}
function set_string($string) {
$string = ereg_replace("[^A-Za-z0-9\-\_] ", "", $string);
$string = str_replace(" ", "_", $string);
$string = str_replace(".", "", $string);
$string = stripslashes($string);
$string = substr($string, 0, 30);
$this->out_string = $string;
}
function get_string() {
return $this->out_string;
}
}
class SNIPS extends REGEX {
function snips($list="") {
$this->list = $list;
}
function snips_create($cats, $title, $syntax, $description) {
global $snippet_library, $snippet_ext_s, $snippet_ext_d;
global $snippet_s, $snippet_d, $snippet_root;
$reg = new regex;
$reg->set_string($title);
$new_title = $reg->get_string();
$new_syntax = $snippet_root.$snippet_library.$cats.".".$new_title.$snippet_ext_s;
$new_desc = $snippet_root.$snippet_library.$cats.".".$new_title.$snippet_ext_d;
if(!file_exists($new_syntax) && !file_exists($new_desc)) {
// create syntax file
@copy($snippet_root.$snippet_s, $new_syntax);
chmod($new_syntax, 0777);
$this->file_write($cats.".".$new_title.$snippet_ext_s, $syntax);
// create description file
@copy($snippet_root.$snippet_d, $new_desc);
chmod($new_desc, 0777);
$this->file_write($cats.".".$new_title.$snippet_ext_d, $description);
return true;
} else {
return false;
}
}
function snips_list_set($cat) {
global $snippet_library, $snippet_ext_s, $snippet_root;
$dir = opendir($snippet_root.$snippet_library);
$i=0;
$expr = "(^$cat\.{1}) ([a-z0-9\-\_]) ($snippet_ext_s{1}$)";
while ($lib = readdir($dir)) {
if (eregi($expr, $lib)) {
$this->list[$i] = str_replace($cat.".", "", $lib);
$this->list[$i] = str_replace($snippet_ext_s, "", $this->list[$i]);
$i ;
}
}
closedir($dir);
}
function snips_list_get() {
return $this->list;
}
function file_write($filename, $filecontent) {
global $snippet_root, $snippet_library;
if($fp = @fopen( $snippet_root.$snippet_library.$filename,"w ")) {
$filecontent = dec_string($filecontent);
$contents = fwrite($fp, $filecontent, 80000);
fclose($fp);
return true;
} else {
return false;
}
}
}
?>
|
Description for: PHP_CSL_6 . Classes |
The main code for the application, includes all functions and classes.
|
|
|