public function indexAction()
 {
     $request = $this->getRequest();
     $goodies = Model_Pages::getPage(Helper_Config::get('page_goodies'));
     $pin_text = $this->translate('Pyng images from any website as you browse the web with the %s"Pyng It" button.%s');
     if ($goodies) {
         $this->view->pin_text = sprintf($pin_text, '<a href="' . WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=pages&action=read&page_id=' . Helper_Config::get('page_goodies')) . '">', '</a>');
     }
     $methods = glob(dirname(__FILE__) . '/Addpin/*.php');
     $this->view->methods = array();
     if ($methods) {
         $front = $this->getFrontController();
         foreach ($methods as $row => $method) {
             $controller = basename($method, 'Controller.php');
             if ($controller) {
                 $name = $front->formatControllerName('addpin_' . strtolower($controller));
                 if (!class_exists($name, true)) {
                     JO_Loader::loadClass($name);
                 }
                 $instance = new $name();
                 $this->view->methods[isset($instance->SORT) ? $instance->SORT : 0] = $this->view->callChildren('addpin_' . strtolower($controller));
             }
         }
     }
     ksort($this->view->methods);
     $this->view->popup_main_box = $this->view->render('popup_main', 'addpin');
     if ($request->isXmlHttpRequest()) {
         $this->noViewRenderer(true);
         echo $this->view->popup_main_box;
     } else {
         $this->forward('error', 'error404');
     }
 }
Beispiel #2
0
 public static function setClassName($registryClassName = 'JO_Registry')
 {
     if (self::$_registry !== null) {
         throw new Exception('Registry is already initialized');
     }
     if (!is_string($registryClassName)) {
         throw new Exception("Argument is not a class name");
     }
     if (!class_exists($registryClassName)) {
         require_once 'JO_Loader.php';
         JO_Loader::loadClass($registryClassName);
     }
     self::$_registryClassName = $registryClassName;
 }
Beispiel #3
0
 public function __construct($children, $param = '')
 {
     $object = $method = '';
     if (is_array($children)) {
         $object = $children[0];
         $method = isset($children[1]) ? $children[1] : 'index';
     } elseif (preg_match('/^([a-z0-9_]{1,})(->|::|\\/)?([a-z0-9_]{1,})?$/i', $children, $match)) {
         $object = $match[1];
         $method = isset($match[3]) && $match[3] ? $match[3] : false;
     }
     if ($object) {
         $object = $this->_formatName($object);
         if (!class_exists($object, false)) {
             JO_Loader::loadClass($object);
         }
         $class = new $object($param);
         if ($method) {
             parent::__construct($class->{$method}($param));
         } else {
             return $class;
         }
     }
 }
Beispiel #4
0
 /**
  * Prepare a statement and return a PDOStatement-like object.
  *
  * @param  string  $sql  SQL query
  * @return JO_Db_Statement_Mysqli
  */
 public function prepare($sql)
 {
     $this->_connect();
     if ($this->_stmt) {
         $this->_stmt->close();
     }
     $stmtClass = $this->_defaultStmtClass;
     if (!class_exists($stmtClass)) {
         require_once 'JO/Loader.php';
         JO_Loader::loadClass($stmtClass);
     }
     $stmt = new $stmtClass($this, $sql);
     if ($stmt === false) {
         return false;
     }
     $stmt->setFetchMode($this->_fetchMode);
     $this->_stmt = $stmt;
     return $stmt;
 }
Beispiel #5
0
 /**
  * Fetches a new blank row (not from the database).
  *
  * @param  array $data OPTIONAL data to populate in the new row.
  * @param  string $defaultSource OPTIONAL flag to force default values into new row
  * @return JO_Db_Table_Row_Abstract
  */
 public function createRow(array $data = array(), $defaultSource = null)
 {
     $cols = $this->_getCols();
     $defaults = array_combine($cols, array_fill(0, count($cols), null));
     // nothing provided at call-time, take the class value
     if ($defaultSource == null) {
         $defaultSource = $this->_defaultSource;
     }
     if (!in_array($defaultSource, array(self::DEFAULT_CLASS, self::DEFAULT_DB, self::DEFAULT_NONE))) {
         $defaultSource = self::DEFAULT_NONE;
     }
     if ($defaultSource == self::DEFAULT_DB) {
         foreach ($this->_metadata as $metadataName => $metadata) {
             if ($metadata['DEFAULT'] != null && ($metadata['NULLABLE'] !== true || $metadata['NULLABLE'] === true && isset($this->_defaultValues[$metadataName]) && $this->_defaultValues[$metadataName] === true) && !(isset($this->_defaultValues[$metadataName]) && $this->_defaultValues[$metadataName] === false)) {
                 $defaults[$metadataName] = $metadata['DEFAULT'];
             }
         }
     } elseif ($defaultSource == self::DEFAULT_CLASS && $this->_defaultValues) {
         foreach ($this->_defaultValues as $defaultName => $defaultValue) {
             if (array_key_exists($defaultName, $defaults)) {
                 $defaults[$defaultName] = $defaultValue;
             }
         }
     }
     $config = array('table' => $this, 'data' => $defaults, 'readOnly' => false, 'stored' => false);
     $rowClass = $this->getRowClass();
     if (!class_exists($rowClass)) {
         require_once 'JO/Loader.php';
         JO_Loader::loadClass($rowClass);
     }
     $row = new $rowClass($config);
     $row->setFromArray($data);
     return $row;
 }
Beispiel #6
0
 /**
  * Set the adapter's profiler object.
  *
  * The argument may be a boolean, an associative array, an instance of
  * JO_Db_Profiler, or an instance of JO_Config.
  *
  * A boolean argument sets the profiler to enabled if true, or disabled if
  * false.  The profiler class is the adapter's default profiler class,
  * JO_Db_Profiler.
  *
  * An instance of JO_Db_Profiler sets the adapter's instance to that
  * object.  The profiler is enabled and disabled separately.
  *
  * An associative array argument may contain any of the keys 'enabled',
  * 'class', and 'instance'. The 'enabled' and 'instance' keys correspond to the
  * boolean and object types documented above. The 'class' key is used to name a
  * class to use for a custom profiler. The class must be JO_Db_Profiler or a
  * subclass. The class is instantiated with no constructor arguments. The 'class'
  * option is ignored when the 'instance' option is supplied.
  *
  * An object of type JO_Config may contain the properties 'enabled', 'class', and
  * 'instance', just as if an associative array had been passed instead.
  *
  * @param  JO_Db_Profiler|JO_Config|array|boolean $profiler
  * @return JO_Db_Adapter_Abstract Provides a fluent interface
  * @throws JO_Db_Profiler_Exception if the object instance or class specified
  *         is not JO_Db_Profiler or an extension of that class.
  */
 public function setProfiler($profiler)
 {
     $enabled = null;
     $profilerClass = $this->_defaultProfilerClass;
     $profilerInstance = null;
     if ($profilerIsObject = is_object($profiler)) {
         if ($profiler instanceof JO_Db_Profiler) {
             $profilerInstance = $profiler;
         } else {
             if ($profiler instanceof JO_Config) {
                 $profiler = $profiler->toArray();
             } else {
                 /**
                  * @see JO_Db_Profiler_Exception
                  */
                 require_once 'JO/Db/Profiler/Exception.php';
                 throw new JO_Db_Profiler_Exception('Profiler argument must be an instance of either JO_Db_Profiler' . ' or JO_Config when provided as an object');
             }
         }
     }
     if (is_array($profiler)) {
         if (isset($profiler['enabled'])) {
             $enabled = (bool) $profiler['enabled'];
         }
         if (isset($profiler['class'])) {
             $profilerClass = $profiler['class'];
         }
         if (isset($profiler['instance'])) {
             $profilerInstance = $profiler['instance'];
         }
     } else {
         if (!$profilerIsObject) {
             $enabled = (bool) $profiler;
         }
     }
     if ($profilerInstance === null) {
         if (!class_exists($profilerClass)) {
             require_once 'JO/Loader.php';
             JO_Loader::loadClass($profilerClass);
         }
         $profilerInstance = new $profilerClass();
     }
     if (!$profilerInstance instanceof JO_Db_Profiler) {
         /** @see JO_Db_Profiler_Exception */
         require_once 'JO/Db/Profiler/Exception.php';
         throw new JO_Db_Profiler_Exception('Class ' . get_class($profilerInstance) . ' does not extend ' . 'JO_Db_Profiler');
     }
     if (null !== $enabled) {
         $profilerInstance->setEnabled($enabled);
     }
     $this->_profiler = $profilerInstance;
     return $this;
 }
Beispiel #7
0
 /**
  * Constructor.
  *
  * @param array $config
  */
 public function __construct(array $config)
 {
     if (isset($config['table'])) {
         $this->_table = $config['table'];
         $this->_tableClass = get_class($this->_table);
     }
     if (isset($config['rowClass'])) {
         $this->_rowClass = $config['rowClass'];
     }
     if (!class_exists($this->_rowClass)) {
         require_once 'JO/Loader.php';
         JO_Loader::loadClass($this->_rowClass);
     }
     if (isset($config['data'])) {
         $this->_data = $config['data'];
     }
     if (isset($config['readOnly'])) {
         $this->_readOnly = $config['readOnly'];
     }
     if (isset($config['stored'])) {
         $this->_stored = $config['stored'];
     }
     // set the count of rows
     $this->_count = count($this->_data);
     $this->init();
 }
Beispiel #8
0
 /**
  * Factory for JO_Db_Adapter_Abstract classes.
  *
  * First argument may be a string containing the base of the adapter class
  * name, e.g. 'Mysqli' corresponds to class JO_Db_Adapter_Mysqli.  This
  * name is currently case-insensitive, but is not ideal to rely on this behavior.
  * If your class is named 'My_Company_Pdo_Mysql', where 'My_Company' is the namespace
  * and 'Pdo_Mysql' is the adapter name, it is best to use the name exactly as it
  * is defined in the class.  This will ensure proper use of the factory API.
  *
  * First argument may alternatively be an object of type JO_Config.
  * The adapter class base name is read from the 'adapter' property.
  * The adapter config parameters are read from the 'params' property.
  *
  * Second argument is optional and may be an associative array of key-value
  * pairs.  This is used as the argument to the adapter constructor.
  *
  * If the first argument is of type JO_Config, it is assumed to contain
  * all parameters, and the second argument is ignored.
  *
  * @param  mixed $adapter String name of base adapter class, or JO_Config object.
  * @param  mixed $config  OPTIONAL; an array or JO_Config object with adapter parameters.
  * @return JO_Db_Adapter_Abstract
  * @throws JO_Db_Exception
  */
 public static function factory($adapter, $config = array())
 {
     if ($config instanceof JO_Config) {
         $config = $config->toArray();
     }
     /*
      * Convert JO_Config argument to plain string
      * adapter name and separate config object.
      */
     if ($adapter instanceof JO_Config) {
         if (isset($adapter->params)) {
             $config = $adapter->params->toArray();
         }
         if (isset($adapter->adapter)) {
             $adapter = (string) $adapter->adapter;
         } else {
             $adapter = null;
         }
     }
     /*
      * Verify that adapter parameters are in an array.
      */
     if (!is_array($config)) {
         /**
          * @see JO_Db_Exception
          */
         require_once 'JO/Db/Exception.php';
         throw new JO_Db_Exception('Adapter parameters must be in an array or a JO_Config object');
     }
     /*
      * Verify that an adapter name has been specified.
      */
     if (!is_string($adapter) || empty($adapter)) {
         /**
          * @see JO_Db_Exception
          */
         require_once 'JO/Db/Exception.php';
         throw new JO_Db_Exception('Adapter name must be specified in a string');
     }
     /*
      * Form full adapter class name
      */
     $adapterNamespace = 'JO_Db_Adapter';
     if (isset($config['adapterNamespace'])) {
         if ($config['adapterNamespace'] != '') {
             $adapterNamespace = $config['adapterNamespace'];
         }
         unset($config['adapterNamespace']);
     }
     // Adapter no longer normalized- see http://framework.zend.com/issues/browse/ZF-5606
     $adapterName = $adapterNamespace . '_';
     $adapterName .= str_replace(' ', '_', ucwords(str_replace('_', ' ', strtolower($adapter))));
     /*
      * Load the adapter class.  This throws an exception
      * if the specified class cannot be loaded.
      */
     if (!class_exists($adapterName)) {
         require_once 'JO/Loader.php';
         JO_Loader::loadClass($adapterName);
     }
     /*
      * Create an instance of the adapter class.
      * Pass the config to the adapter class constructor.
      */
     self::$dbAdapter_name = $adapterName;
     self::$dbAdapter = new $adapterName($config);
     /*
      * Verify that the object created is a descendent of the abstract adapter type.
      */
     if (!self::$dbAdapter instanceof JO_Db_Adapter_Abstract) {
         /**
          * @see JO_Db_Exception
          */
         require_once 'JO/Db/Exception.php';
         throw new JO_Db_Exception("Adapter class '{$adapterName}' does not extend JO_Db_Adapter_Abstract");
     }
     return self::$dbAdapter;
 }
Beispiel #9
0
 /**
  * Returns an SQL statement for preparation.
  *
  * @param string $sql The SQL statement with placeholders.
  * @return JO_Db_Statement_Oracle
  */
 public function prepare($sql)
 {
     $this->_connect();
     $stmtClass = $this->_defaultStmtClass;
     if (!class_exists($stmtClass)) {
         require_once 'JO/Loader.php';
         JO_Loader::loadClass($stmtClass);
     }
     $stmt = new $stmtClass($this, $sql);
     if ($stmt instanceof JO_Db_Statement_Oracle) {
         $stmt->setLobAsString($this->getLobAsString());
     }
     $stmt->setFetchMode($this->_fetchMode);
     return $stmt;
 }
Beispiel #10
0
 public function callChildrenView($children, $param = '')
 {
     $controller = $action = '';
     if (is_array($children)) {
         $controller = $children[0];
         $action = isset($children[1]) ? $children[1] : 'index';
     } elseif (preg_match('/^([a-z0-9_]{1,})(->|::|\\/)?([a-z0-9_]{1,})?$/i', $children, $match)) {
         $controller = $match[1];
         $action = isset($match[3]) && $match[3] ? $match[3] : 'index';
     }
     if ($controller && $action) {
         $class = $this->formatControllerName($controller);
         $action = $this->formatActionName($action);
         if (!class_exists($class, false)) {
             JO_Loader::loadClass($class);
         }
         /**
          * @var $child JO_Action
          */
         $child = new $class();
         $child->initView();
         call_user_func(array($child, $action), $param);
         $result = $child->getView();
         return $result;
     }
     return null;
 }
Beispiel #11
0
 /**
  * _getTableFromString
  *
  * @param string $tableName
  * @return JO_Db_Table_Abstract
  */
 protected function _getTableFromString($tableName)
 {
     if ($this->_table instanceof JO_Db_Table_Abstract) {
         $tableDefinition = $this->_table->getDefinition();
         if ($tableDefinition !== null && $tableDefinition->hasTableConfig($tableName)) {
             return new JO_Db_Table($tableName, $tableDefinition);
         }
     }
     // assume the tableName is the class name
     if (!class_exists($tableName)) {
         try {
             require_once 'JO/Loader.php';
             JO_Loader::loadClass($tableName);
         } catch (JO_Exception $e) {
             require_once 'JO/Db/Table/Row/Exception.php';
             throw new JO_Db_Table_Row_Exception($e->getMessage(), $e->getCode(), $e);
         }
     }
     $options = array();
     if ($table = $this->_getTable()) {
         $options['db'] = $table->getAdapter();
     }
     if (isset($tableDefinition) && $tableDefinition !== null) {
         $options[JO_Db_Table_Abstract::DEFINITION] = $tableDefinition;
     }
     return new $tableName($options);
 }
Beispiel #12
0
 /**
  * Returns an SQL statement for preparation.
  *
  * @param string $sql The SQL statement with placeholders.
  * @return JO_Db_Statement_Sqlsrv
  */
 public function prepare($sql)
 {
     $this->_connect();
     $stmtClass = $this->_defaultStmtClass;
     if (!class_exists($stmtClass)) {
         /**
          * @see JO_Loader
          */
         require_once 'JO/Loader.php';
         JO_Loader::loadClass($stmtClass);
     }
     $stmt = new $stmtClass($this, $sql);
     $stmt->setFetchMode($this->_fetchMode);
     return $stmt;
 }
Beispiel #13
0
 public static function getControllerActions($controller, $patch = null)
 {
     $actions = array();
     $front = JO_Front::getInstance();
     $filename = $front->classToFilename($controller);
     if (file_exists($patch . '/' . $filename)) {
         if (!class_exists($controller, false)) {
             if ($patch) {
                 JO_Loader::setIncludePaths(array($patch));
             }
             JO_Loader::loadClass($controller);
         }
         $methods = get_class_methods($controller);
         if ($methods) {
             foreach ($methods as $methodName) {
                 if ('Action' == substr($methodName, -6)) {
                     $action = substr($methodName, 0, strlen($methodName) - 6);
                     $actions[$action] = $action;
                 }
             }
         }
     }
     return $actions;
 }
Beispiel #14
0
 public function callChildren($children, $param = '')
 {
     $controller = $action = '';
     if (is_array($children)) {
         $controller = $children[0];
         $action = isset($children[1]) ? $children[1] : 'index';
     } elseif (preg_match('/^([a-z0-9_]{1,})(->|::|\\/)?([a-z0-9_]{1,})?$/i', $children, $match)) {
         $controller = $match[1];
         $action = isset($match[3]) && $match[3] ? $match[3] : 'index';
     }
     if ($controller && $action) {
         $class = $this->formatControllerName($controller);
         if (!class_exists($class, false)) {
             JO_Loader::loadClass($class);
         }
         /* @var $child JO_Action */
         $child = new $class();
         $child->isChildren(true);
         $result = $child->dispatch($controller, $action, $param);
         if (JO_Registry::forceGet('viewSetCallbackChildren')) {
             $result = call_user_func(JO_Registry::forceGet('viewSetCallbackChildren'), $controller, $action, $result);
         }
         return $result;
     }
     return null;
 }