diff --git a/Pickles.php b/Pickles.php index 09036b0..1d63a39 100755 --- a/Pickles.php +++ b/Pickles.php @@ -5,10 +5,17 @@ define('PATH', getcwd() . '/'); function __autoload($class) { $file = PATH . '../../pickles/classes/' . str_replace('_', '/', $class) . '.php'; - + if (file_exists($file)) { require_once $file; } + else { + $file = PATH . '../../pickles/models/' . str_replace('_', '/', $class) . '.php'; + + if (file_exists($file)) { + require_once $file; + } + } } ?> diff --git a/classes/Config.php b/classes/Config.php index ddc447a..efc71e2 100755 --- a/classes/Config.php +++ b/classes/Config.php @@ -4,6 +4,8 @@ class Config extends Singleton { private static $instance; + public $timestamp = null; + private function __construct() { } public static function getInstance() { @@ -22,32 +24,34 @@ class Config extends Singleton { } public function load($site) { - // @todo no hardcoded paths! - $file = '/var/www/josh/pickles/config/' . $site . '.xml'; + if (!isset($this->file) || filemtime($this->file) > $this->timestamp) { + // @todo no hardcoded paths! + $file = '/var/www/josh/pickles/config/' . $site . '.xml'; - if (!isset($this->file) || $this->file != $file) { - if (file_exists($file)) { - $this->file = $file; + if (!isset($this->file) || $this->file != $file) { + if (file_exists($file)) { + $this->file = $file; - $config_array = ArrayUtils::object2array(simplexml_load_file($file)); + $config_array = ArrayUtils::object2array(simplexml_load_file($file)); - if (is_array($config_array)) { - foreach ($config_array as $variable => $value) { - if ($value == 'true' || $value == array()) { - $value = (bool) $value; + if (is_array($config_array)) { + foreach ($config_array as $variable => $value) { + if ($value == 'true' || $value == array()) { + $value = (bool) $value; + } + + $this->$variable = $value == array() ? (bool) $value : $value; } - - $this->$variable = $value == array() ? (bool) $value : $value; } + + $this->freeze(); + + return true; + } + else { + Error::addError('Unable to load the configuration file'); + return false; } - - $this->freeze(); - - return true; - } - else { - Error::addError('Unable to load the configuration file'); - return false; } } } diff --git a/classes/Controller.php b/classes/Controller.php index ba040de..043c6a5 100755 --- a/classes/Controller.php +++ b/classes/Controller.php @@ -38,7 +38,8 @@ class Controller extends Object { } else { // Load the model - $file = '../models/' . $name . '.php'; + $file = '../models/' . $name . '.php'; + $shared_file = '../../pickles/models/' . $name . '.php'; if (strpos($name, '/') === false) { $class = $name; @@ -57,10 +58,16 @@ class Controller extends Object { $this->model = new $class; } } + elseif (file_exists($shared_file)) { + if (class_exists($class)) { + $this->model = new $class; + } + } else { $this->model = new Model(); } + if ($this->model->get('auth') == false) { $this->model->set('auth', $this->config->get('behavior', 'auth')); } diff --git a/classes/Singleton.php b/classes/Singleton.php index 8fd6292..9e96095 100644 --- a/classes/Singleton.php +++ b/classes/Singleton.php @@ -27,6 +27,7 @@ class Singleton { public function freeze() { $session = Session::getInstance(); + $this->timestamp = time(); $class = get_class($this); $session->$class = serialize($this); } diff --git a/classes/Viewer/Smarty.php b/classes/Viewer/Smarty.php index f52a897..0dea89f 100644 --- a/classes/Viewer/Smarty.php +++ b/classes/Viewer/Smarty.php @@ -37,7 +37,8 @@ class Viewer_Smarty extends Viewer_Common { $smarty->load_filter('output','trimwhitespace'); // Include custom Smarty functions - $directory = PATH . '../../common/smarty/functions/'; + // @todo Stupid fucking hard coded path + $directory = PATH . '../../pickles/smarty/functions/'; if (is_dir($directory)) { if ($handle = opendir($directory)) { @@ -62,20 +63,33 @@ class Viewer_Smarty extends Viewer_Common { } } + $template = '../templates/' . $this->model->get('name') . '.tpl'; + $shared_template = str_replace('../', '../../pickles/', $template); + + if (!file_exists($template)) { + if (file_exists($shared_template)) { + $template = $shared_template; + } + } + // Pass all of our controller values to Smarty $smarty->assign('navigation', $navigation); $smarty->assign('section', $this->model->get('section')); $smarty->assign('model', $this->model->get('name')); $smarty->assign('action', $this->model->get('action')); // @todo rename me to event... $smarty->assign('event', $this->model->get('action')); // but it almost seems like we don't need these anymore at all - // Thanks to new naming conventions + + // Thanks to new naming conventions $smarty->assign('admin', $this->config->get('admin', 'sections')); - $smarty->assign('template', '../templates/' . $this->model->get('name') . '.tpl'); //$template); + $smarty->assign('template', $template); // Only load the session if it's available + // @todo not entirely sure that the view needs full access to the session (seems insecure at best) + /* if (isset($_SESSION)) { $smarty->assign('session', $_SESSION); } + */ $data = $this->model->getData(); diff --git a/config/ribbonnutrition.com.xml b/config/ribbonnutrition.com.xml index 462633b..2c17ad9 100755 --- a/config/ribbonnutrition.com.xml +++ b/config/ribbonnutrition.com.xml @@ -14,14 +14,32 @@ false + News + FAQs Logout + + + Shopping Home + My Account + View Cart / Checkout + What's on Sale? + What's New? + Shipping / Returns + + Ribbon Nutrition Contact Request Thank you. A member of our staff will respond to your message as soon as possible. joshsherman@gmail.com + + (04:46:10 PM) Dekin Dorcas: sales@... + (04:46:27 PM) Dekin Dorcas: nutritionist@... + (04:46:33 PM) joshrecovery: w0rd + (04:46:46 PM) Dekin Dorcas: general inquiries will be info@... + diff --git a/contrib/dBug b/contrib/dBug new file mode 120000 index 0000000..c9d1e60 --- /dev/null +++ b/contrib/dBug @@ -0,0 +1 @@ +/home/josh/Sites/pickles/contrib/dBug-1.2 \ No newline at end of file diff --git a/contrib/dBug-1.2/dBug.php b/contrib/dBug-1.2/dBug.php new file mode 100644 index 0000000..07c3354 --- /dev/null +++ b/contrib/dBug-1.2/dBug.php @@ -0,0 +1,531 @@ +initJSandCSS(); + } + $arrAccept=array("array","object","xml"); //array of variable types that can be "forced" + $this->bCollapsed = $bCollapsed; + if(in_array($forceType,$arrAccept)) + $this->{"varIs".ucfirst($forceType)}($var); + else + $this->checkType($var); + } + + //get variable name + function getVariableName() { + $arrBacktrace = debug_backtrace(); + + //possible 'included' functions + $arrInclude = array("include","include_once","require","require_once"); + + //check for any included/required files. if found, get array of the last included file (they contain the right line numbers) + for($i=count($arrBacktrace)-1; $i>=0; $i--) { + $arrCurrent = $arrBacktrace[$i]; + if(array_key_exists("function", $arrCurrent) && + (in_array($arrCurrent["function"], $arrInclude) || (0 != strcasecmp($arrCurrent["function"], "dbug")))) + continue; + + $arrFile = $arrCurrent; + + break; + } + + if(isset($arrFile)) { + $arrLines = file($arrFile["file"]); + $code = $arrLines[($arrFile["line"]-1)]; + + //find call to dBug class + preg_match('/\bnew dBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches); + + return $arrMatches[1]; + } + return ""; + } + + //create the main table header + function makeTableHeader($type,$header,$colspan=2) { + if(!$this->bInitialized) { + $header = $this->getVariableName() . " (" . $header . ")"; + $this->bInitialized = true; + } + $str_i = ($this->bCollapsed) ? "style=\"font-style:italic\" " : ""; + + echo " + + + "; + } + + //create the table row header + function makeTDHeader($type,$header) { + $str_d = ($this->bCollapsed) ? " style=\"display:none\"" : ""; + echo " + + \n"; + } + + //error + function error($type) { + $error="Error: Variable cannot be a"; + // this just checks if the type starts with a vowel or "x" and displays either "a" or "an" + if(in_array(substr($type,0,1),array("a","e","i","o","u","x"))) + $error.="n"; + return ($error." ".$type." type"); + } + + //check variable type + function checkType($var) { + switch(gettype($var)) { + case "resource": + $this->varIsResource($var); + break; + case "object": + $this->varIsObject($var); + break; + case "array": + $this->varIsArray($var); + break; + case "NULL": + $this->varIsNULL(); + break; + case "boolean": + $this->varIsBoolean($var); + break; + default: + $var=($var=="") ? "[empty string]" : $var; + echo "
".$header."
".$header.""; + } + + //close table row + function closeTDRow() { + return "
\n\n\n
".$var."
\n"; + break; + } + } + + //if variable is a NULL type + function varIsNULL() { + echo "NULL"; + } + + //if variable is a boolean type + function varIsBoolean($var) { + $var=($var==1) ? "TRUE" : "FALSE"; + echo $var; + } + + //if variable is an array type + function varIsArray($var) { + $var_ser = serialize($var); + array_push($this->arrHistory, $var_ser); + + $this->makeTableHeader("array","array"); + if(is_array($var)) { + foreach($var as $key=>$value) { + $this->makeTDHeader("array",$key); + + //check for recursion + if(is_array($value)) { + $var_ser = serialize($value); + if(in_array($var_ser, $this->arrHistory, TRUE)) + $value = "*RECURSION*"; + } + + if(in_array(gettype($value),$this->arrType)) + $this->checkType($value); + else { + $value=(trim($value)=="") ? "[empty string]" : $value; + echo $value; + } + echo $this->closeTDRow(); + } + } + else echo "".$this->error("array").$this->closeTDRow(); + array_pop($this->arrHistory); + echo ""; + } + + //if variable is an object type + function varIsObject($var) { + $var_ser = serialize($var); + array_push($this->arrHistory, $var_ser); + $this->makeTableHeader("object","object"); + + if(is_object($var)) { + $arrObjVars=get_object_vars($var); + foreach($arrObjVars as $key=>$value) { + + $value=(!is_object($value) && !is_array($value) && trim($value)=="") ? "[empty string]" : $value; + $this->makeTDHeader("object",$key); + + //check for recursion + if(is_object($value)||is_array($value)) { + $var_ser = serialize($value); + if(in_array($var_ser, $this->arrHistory, TRUE)) { + $value = (is_object($value)) ? "*RECURSION* -> $".get_class($value) : "*RECURSION*"; + + } + } + if(in_array(gettype($value),$this->arrType)) + $this->checkType($value); + else echo $value; + echo $this->closeTDRow(); + } + $arrObjMethods=get_class_methods(get_class($var)); + foreach($arrObjMethods as $key=>$value) { + $this->makeTDHeader("object",$value); + echo "[function]".$this->closeTDRow(); + } + } + else echo "".$this->error("object").$this->closeTDRow(); + array_pop($this->arrHistory); + echo ""; + } + + //if variable is a resource type + function varIsResource($var) { + $this->makeTableHeader("resourceC","resource",1); + echo "\n\n"; + switch(get_resource_type($var)) { + case "fbsql result": + case "mssql result": + case "msql query": + case "pgsql result": + case "sybase-db result": + case "sybase-ct result": + case "mysql result": + $db=current(explode(" ",get_resource_type($var))); + $this->varIsDBResource($var,$db); + break; + case "gd": + $this->varIsGDResource($var); + break; + case "xml": + $this->varIsXmlResource($var); + break; + default: + echo get_resource_type($var).$this->closeTDRow(); + break; + } + echo $this->closeTDRow()."\n"; + } + + //if variable is a database resource type + function varIsDBResource($var,$db="mysql") { + if($db == "pgsql") + $db = "pg"; + if($db == "sybase-db" || $db == "sybase-ct") + $db = "sybase"; + $arrFields = array("name","type","flags"); + $numrows=call_user_func($db."_num_rows",$var); + $numfields=call_user_func($db."_num_fields",$var); + $this->makeTableHeader("resource",$db." result",$numfields+1); + echo " "; + for($i=0;$i<$numfields;$i++) { + $field_header = ""; + for($j=0; $j".$field_name.""; + } + echo ""; + for($i=0;$i<$numrows;$i++) { + $row=call_user_func($db."_fetch_array",$var,constant(strtoupper($db)."_ASSOC")); + echo "\n"; + echo "".($i+1).""; + for($k=0;$k<$numfields;$k++) { + $tempField=$field[$k]->name; + $fieldrow=$row[($field[$k]->name)]; + $fieldrow=($fieldrow=="") ? "[empty string]" : $fieldrow; + echo "".$fieldrow."\n"; + } + echo "\n"; + } + echo ""; + if($numrows>0) + call_user_func($db."_data_seek",$var,0); + } + + //if variable is an image/gd resource type + function varIsGDResource($var) { + $this->makeTableHeader("resource","gd",2); + $this->makeTDHeader("resource","Width"); + echo imagesx($var).$this->closeTDRow(); + $this->makeTDHeader("resource","Height"); + echo imagesy($var).$this->closeTDRow(); + $this->makeTDHeader("resource","Colors"); + echo imagecolorstotal($var).$this->closeTDRow(); + echo ""; + } + + //if variable is an xml type + function varIsXml($var) { + $this->varIsXmlResource($var); + } + + //if variable is an xml resource type + function varIsXmlResource($var) { + $xml_parser=xml_parser_create(); + xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0); + xml_set_element_handler($xml_parser,array(&$this,"xmlStartElement"),array(&$this,"xmlEndElement")); + xml_set_character_data_handler($xml_parser,array(&$this,"xmlCharacterData")); + xml_set_default_handler($xml_parser,array(&$this,"xmlDefaultHandler")); + + $this->makeTableHeader("xml","xml document",2); + $this->makeTDHeader("xml","xmlRoot"); + + //attempt to open xml file + $bFile=(!($fp=@fopen($var,"r"))) ? false : true; + + //read xml file + if($bFile) { + while($data=str_replace("\n","",fread($fp,4096))) + $this->xmlParse($xml_parser,$data,feof($fp)); + } + //if xml is not a file, attempt to read it as a string + else { + if(!is_string($var)) { + echo $this->error("xml").$this->closeTDRow()."\n"; + return; + } + $data=$var; + $this->xmlParse($xml_parser,$data,1); + } + + echo $this->closeTDRow()."\n"; + + } + + //parse xml + function xmlParse($xml_parser,$data,$bFinal) { + if (!xml_parse($xml_parser,$data,$bFinal)) { + die(sprintf("XML error: %s at line %d\n", + xml_error_string(xml_get_error_code($xml_parser)), + xml_get_current_line_number($xml_parser))); + } + } + + //xml: inititiated when a start tag is encountered + function xmlStartElement($parser,$name,$attribs) { + $this->xmlAttrib[$this->xmlCount]=$attribs; + $this->xmlName[$this->xmlCount]=$name; + $this->xmlSData[$this->xmlCount]='$this->makeTableHeader("xml","xml element",2);'; + $this->xmlSData[$this->xmlCount].='$this->makeTDHeader("xml","xmlName");'; + $this->xmlSData[$this->xmlCount].='echo "'.$this->xmlName[$this->xmlCount].'".$this->closeTDRow();'; + $this->xmlSData[$this->xmlCount].='$this->makeTDHeader("xml","xmlAttributes");'; + if(count($attribs)>0) + $this->xmlSData[$this->xmlCount].='$this->varIsArray($this->xmlAttrib['.$this->xmlCount.']);'; + else + $this->xmlSData[$this->xmlCount].='echo " ";'; + $this->xmlSData[$this->xmlCount].='echo $this->closeTDRow();'; + $this->xmlCount++; + } + + //xml: initiated when an end tag is encountered + function xmlEndElement($parser,$name) { + for($i=0;$i<$this->xmlCount;$i++) { + eval($this->xmlSData[$i]); + $this->makeTDHeader("xml","xmlText"); + echo (!empty($this->xmlCData[$i])) ? $this->xmlCData[$i] : " "; + echo $this->closeTDRow(); + $this->makeTDHeader("xml","xmlComment"); + echo (!empty($this->xmlDData[$i])) ? $this->xmlDData[$i] : " "; + echo $this->closeTDRow(); + $this->makeTDHeader("xml","xmlChildren"); + unset($this->xmlCData[$i],$this->xmlDData[$i]); + } + echo $this->closeTDRow(); + echo ""; + $this->xmlCount=0; + } + + //xml: initiated when text between tags is encountered + function xmlCharacterData($parser,$data) { + $count=$this->xmlCount-1; + if(!empty($this->xmlCData[$count])) + $this->xmlCData[$count].=$data; + else + $this->xmlCData[$count]=$data; + } + + //xml: initiated when a comment or other miscellaneous texts is encountered + function xmlDefaultHandler($parser,$data) { + //strip '' off comments + $data=str_replace(array("<!--","-->"),"",htmlspecialchars($data)); + $count=$this->xmlCount-1; + if(!empty($this->xmlDData[$count])) + $this->xmlDData[$count].=$data; + else + $this->xmlDData[$count]=$data; + } + + function initJSandCSS() { + echo << + /* code modified from ColdFusion's cfdump code */ + function dBug_toggleRow(source) { + var target = (document.all) ? source.parentElement.cells[1] : source.parentNode.lastChild; + dBug_toggleTarget(target,dBug_toggleSource(source)); + } + + function dBug_toggleSource(source) { + if (source.style.fontStyle=='italic') { + source.style.fontStyle='normal'; + source.title='click to collapse'; + return 'open'; + } else { + source.style.fontStyle='italic'; + source.title='click to expand'; + return 'closed'; + } + } + + function dBug_toggleTarget(target,switchToState) { + target.style.display = (switchToState=='open') ? '' : 'none'; + } + + function dBug_toggleTable(source) { + var switchToState=dBug_toggleSource(source); + if(document.all) { + var table=source.parentElement.parentElement; + for(var i=1;i + + +SCRIPTS; + } + +} +?> \ No newline at end of file diff --git a/models/store.php b/models/store.php new file mode 100644 index 0000000..6c1faf6 --- /dev/null +++ b/models/store.php @@ -0,0 +1,33 @@ +data['subnav'] = $config->get('store', 'sections'); + + // Loads the categories + $categories = $this->db->getArray('SELECT id, name FROM categories WHERE parent_id IS NULL AND visible = "Y" ORDER BY weight;'); + if (is_array($categories)) { + foreach ($categories as $key => $category) { + $categories[$key]['subcategories'] = $this->db->getArray('SELECT id, name FROM categories WHERE parent_id = "' . $category['id'] . '" AND visible = "Y" ORDER BY weight;'); + } + } + + $this->data['categories'] = $categories; + } + + public function __default() { + // Forces store/home as the first page you get when only /store is called + $object = new store_home(); + $object->__default(); + + $this->set('name', 'store/home'); + } + +} + +?> diff --git a/models/store/home.php b/models/store/home.php new file mode 100644 index 0000000..a69f486 --- /dev/null +++ b/models/store/home.php @@ -0,0 +1,14 @@ + diff --git a/smarty/functions/function.var_dump.php b/smarty/functions/function.var_dump.php new file mode 100755 index 0000000..9f3949e --- /dev/null +++ b/smarty/functions/function.var_dump.php @@ -0,0 +1,32 @@ +_tpl_vars; + $variables = array(); + + if (is_array($all_variables)) { + foreach ($all_variables as $name => $value) { + if (!in_array($name, $hidden)) { + $variables['$' . $name] = $value; + } + } + } + + require_once 'contrib/dBug/dBug.php'; + + echo " + + "; + + new dBug($variables); +} + +?> diff --git a/templates/store/categories.tpl b/templates/store/categories.tpl new file mode 100644 index 0000000..6011e1c --- /dev/null +++ b/templates/store/categories.tpl @@ -0,0 +1,12 @@ +
+ {foreach from=$categories item=category} +
+

{$category.name}

+
+
    + {foreach from=$category.subcategories item=subcategory} +
  • {$subcategory.name}
  • + {/foreach} +

+ {/foreach} +
diff --git a/templates/store/featured_product.tpl b/templates/store/featured_product.tpl new file mode 100644 index 0000000..8c59e8f --- /dev/null +++ b/templates/store/featured_product.tpl @@ -0,0 +1,3 @@ + diff --git a/templates/store/home.tpl b/templates/store/home.tpl new file mode 100644 index 0000000..79eab8f --- /dev/null +++ b/templates/store/home.tpl @@ -0,0 +1,8 @@ +
+ {include file="../../pickles/templates/store/navigation.tpl"}

+ {include file="../../pickles/templates/store/categories.tpl"} +
+
+ {include file="../../pickles/templates/store/featured_product.tpl"}

+ {include file="../../pickles/templates/store/top_sellers.tpl"} +
diff --git a/templates/store/navigation.tpl b/templates/store/navigation.tpl new file mode 100644 index 0000000..3f580f0 --- /dev/null +++ b/templates/store/navigation.tpl @@ -0,0 +1,7 @@ +
+ +
diff --git a/templates/store/top_sellers.tpl b/templates/store/top_sellers.tpl new file mode 100644 index 0000000..491ede6 --- /dev/null +++ b/templates/store/top_sellers.tpl @@ -0,0 +1,3 @@ +
+

Top Sellers

+