@ 2015-04-26T23:42:06Z <?php
require_once dirname(__FILE__) . '/Common.php';
class Application extends Common {
const DEFAULT_TEMPLATE = 'Craigslist';
const IMAGE_WIDTH = 200;
protected $_formAction = '/Classifieds';
protected $_templateName = null;
protected $_images = array('jpeg' => 'jpeg', 'jpg' => 'jpg', 'gif' => 'gif', 'png' => 'png');
protected $_imageTpl = '<img width="%s" class="image" imgsrc="%s" />';
protected $_linkTpl = '<a target="%s" href="%s">%s</a>';
protected $_zendView = null;
protected $_moduleHelper = null;
/**
* The search text phrase.
* @var string
*/
protected $_searchText = '';
/**
* The indicator to search only the title field.
* @var boolean
*/
protected $_searchTitleOnly = false;
/**
* The indicator to match any words in search phrase.
* @var boolean
*/
protected $_searchAny = false;
/**
* The indicator to exactly match search phrase.
* @var boolean
*/
protected $_searchExact = false;
/**
* The indicator to return only items having media, images, video.
* @var boolean
*/
protected $_searchMediaOnly = false;
/**
* The indicator to return only items having video.
* @var boolean
*/
protected $_searchVideoOnly = false;
/**
* Constructor
* @param Zend_View $view (optional)
*/
public function __construct($view = null) {
$this->_zendView = $view;
if($view) {
try {
/* @var $moduleHelper Classifieds_View_Helper_Classifieds */
$moduleHelper = $view->classifieds() ;
} catch (Exception $e) {
$moduleHelper = null;
}
$this->_moduleHelper = $moduleHelper;
}
$this->_fetchRequest();
$layout = $this->getLayoutTemplate();
$path = $this->getLayoutTemplateFilePath();
$len = strlen($layout);
if(! $len || ! file_exists($path)) {
if($len) {
$msg = 'Template not found: ' . $layout;
$this->addMessage($msg);
}
$this->setLayoutTemplate($this->getDefaultLayoutTemplate());
}
}
/**
* Sorts list of items by sections.
* @param type $index
*/
public function getSection($index = 0) {
}
protected function _fetchRequest() {
$propertyDefs = array(
self::REQUEST_PARAM_ITEM_ID => array('setLayoutTemplate', $this->getLayoutTemplate()),
self::REQUEST_PARAM_SEARCH => array('setSearchText', ''),
self::REQUEST_PARAM_SEARCH_TITLE_ONLY => array('setSearchTitleOnly', 0),
self::REQUEST_PARAM_SEARCH_ANY => array('setSearchAny', 0),
self::REQUEST_PARAM_SEARCH_EXACT => array('setSearchExact', 0),
self::REQUEST_PARAM_SEARCH_MEDIA_ONLY => array('setSearchMediaOnly', 0),
self::REQUEST_PARAM_SEARCH_VIDEO_ONLY => array('setSearchVideoOnly', 0)
);
foreach($propertyDefs as $propName => $properties) {
list($method, $default) = $properties;
$reqValue = $this->_getRequestValue($propName, $default);
$this->$method($reqValue);
}
}
/**
* Returns the template name.
*
* @return string
*/
public function getLayoutTemplate() {
return $this->_templateName;
}
/**
* Sets the template name.
*
* @return Application
*/
public function setLayoutTemplate($templateName) {
$this->_templateName = $templateName;
return $this;
}
/**
* Returns the default template name.
*
* @return string
*/
public function getDefaultLayoutTemplate() {
$templates = $this->getLayoutTemplates();
$return = (is_array($templates) && count($templates)) ? reset($templates) : '';
return $return;
}
/**
* Returns layout parent path.
*
* @return string
*/
public function getLayoutPath() {
$path = $this->getDocumentRoot() . "/classifiedsTemplates";
return $path;
}
/**
* Returns list ov available templates.
*
* @return array
*/
public function getLayoutTemplates() {
$return = array(
self::DEFAULT_TEMPLATE => self::DEFAULT_TEMPLATE,
'Facebook' => 'Facebook'
);
return $return;
}
/**
* Returns the search text phrase.
*
* @return string
*
*/
public function getSearchText() {
return $this->_searchText ;
}
/**
* Sets the search text phrase.
*
* @param string $searchText
*
* @return Application
*/
public function setSearchText($searchText) {
$this->_searchText = $searchText ;
return $this ;
}
/**
* Returns the indicator to search only the title field.
*
* @return boolean
*
*/
public function getSearchTitleOnly() {
return $this->_searchTitleOnly ;
}
/**
* Sets the indicator to search only the title field.
*
* @param boolean $searchTitleOnly
*
* @return Application
*/
public function setSearchTitleOnly($searchTitleOnly) {
$this->_searchTitleOnly = $searchTitleOnly ;
return $this ;
}
/**
* Returns the indicator to match any words in search phrase.
*
* @return boolean
*
*/
public function getSearchAny() {
return $this->_searchAny ;
}
/**
* Sets the indicator to match any words in search phrase.
*
* @param boolean $searchAny
*
* @return Application
*/
public function setSearchAny($searchAny) {
$this->_searchAny = $searchAny ;
return $this ;
}
/**
* Returns the indicator to exactly match search phrase.
*
* @return boolean
*
*/
public function getSearchExact() {
return $this->_searchExact ;
}
/**
* Sets the indicator to exactly match search phrase.
*
* @param boolean $searchExact
*
* @return Application
*/
public function setSearchExact($searchExact) {
$this->_searchExact = $searchExact ;
return $this ;
}
/**
* Returns the indicator to return only items having media, images, video.
*
* @return boolean
*
*/
public function getSearchMediaOnly() {
return $this->_searchMediaOnly ;
}
/**
* Sets the indicator to return only items having media, images, video.
*
* @param boolean $searchMediaOnly
*
* @return Application
*/
public function setSearchMediaOnly($searchMediaOnly) {
$this->_searchMediaOnly = $searchMediaOnly ;
return $this ;
}
/**
* Returns the indicator to return only items having video.
*
* @return boolean
*
*/
public function getSearchVideoOnly() {
return $this->_searchVideoOnly ;
}
/**
* Sets the indicator to return only items having video.
*
* @param boolean $searchVideoOnly
*
* @return Application
*/
public function setSearchVideoOnly($searchVideoOnly) {
$this->_searchVideoOnly = $searchVideoOnly ;
return $this ;
}
public function fetchItems(array $options = array()) {
/* Option values
search Phrase for which to search.
exact Match search phrase exactly (case-insensitive) (default = match all words).
any Match any words in the search phrase (default = match all).
titleonly Search title only (default = search title, description and tags).
mediaonly Returns only records having 1 or more images.
*/
if($this->getSearchMediaOnly()) {
$options['mediaonly'] = true;
}
if($this->getSearchTitleOnly()) {
$options['titleonly'] = true;
}
$exact = false;
if($this->getSearchAny()) {
$options['any'] = true;
} elseif($this->getSearchExact()) {
$options['exact'] = $exact = true;
}
$search = $this->getSearchText();
if(strlen($search)) {
if(! $exact) {
$search = $this->_tidySearch($search);
}
$options['search'] = $search ;
}
if(! isset($options['sort'])) {
$options['sort'] = 'date';
}
$mapper = $this->getMapper();
$items = $mapper->fetch($options);
if(false === $items) {
$this->addMessage($mapper->getMessages()) ;
return false;
}
foreach($items as $key => $item) {
$mediaStats = $this->_setMediaStats($item);
if($this->getSearchVideoOnly()) {
if(! isset($mediaStats['video']) || ! count($mediaStats['video'])) {
unset($items[$key]);
}
}
}
return $items;
}
protected function _setMediaStats($item) {
$mediaStats = array();
$media = $item->getMedia();
$index = 0;
foreach((array)$media as $key => $url) {
$parts = $this->_parseUrl($url) ;
$url = urldecode($url);
$url = str_replace('"', '"', $url);
$contentType = $parts['type'];
switch($contentType) {
case 'image':
$content = sprintf($this->_imageTpl, self::IMAGE_WIDTH, $url);
break;
case 'video':
$break = 1;
// FALL THROUGH
default: // video, link, photo
$content = $contentType;
if(! isset($c[$contentType])) {
$c[$contentType] = 0;
}
else {
$content .= '(' . (++$c[$contentType] + 1). ')';
}
break;
}
$mediaStats[$contentType][] = $url;
$media[$key] = sprintf($this->_linkTpl, '_blank', $url, $content);
$index++;
}
$item->setMedia($media);
$item->setMediaStats($mediaStats);
return $mediaStats;
}
public function getMediaDisplay($item) {
$display = array();
$media = $item->getMediaStats();
if(isset($media['image']) && is_array($media['image'])) {
$display[] = 'pic (' . count($media['image']) . ')';
}
if(isset($media['video']) && is_array($media['video'])) {
$display[] = 'video (' . count($media['video']) . ')';
}
$return = implode(' ', $display) ;
return $return;
}
public function getTotalCount(array $options = array()) {
$mapper = $this->getMapper();
$recordCount = $mapper->getCount($options);
if(false === $recordCount) {
$this->addMessage($mapper->getMessages()) ;
return false;
}
return $recordCount;
}
protected function _parseUrl($url) {
$default = array(
'scheme' => '',
'host' => '',
'port' => '',
'user' => '',
'pass' => '',
'path' => '',
'query' => '',
'fragment' => '',
'extension' => '',
'type' => ''
);
$parts = parse_url($url);
if(! is_array($parts)) {
return $default;
}
$elements = array_merge($default, $parts) ;
if(strlen($elements['path'])) {
$elements['extension'] = strtolower(pathinfo($elements['path'], PATHINFO_EXTENSION));
if(isset($this->_images[$elements['extension']])) {
$elements['type'] = 'image';
}
}
if(! strlen($elements['type'])) {
$elements['type'] = 'link';
if(strlen($elements['host'])) {
$host = strtolower($elements['host']);
if(preg_match('/^www[0-9]*\.(.*)$/', $host, $matches)) {
$host = $matches[1];
}
switch($host) {
case 'vimeo.com':
case 'youtube.com':
case 'youtu.be':
case 'vevo.com':
case 'veoh.com':
case 'metacafe.com':
case 'break.com':
$elements['type'] = 'video';
break;
case 'flickr.com':
// https://www.flickr.com/explore/video/
$elements['type'] = (false !== strpos(strtolower($elements['path']), 'video')) ? 'video' : 'photo';
break;
}
}
}
return $elements;
}
protected function _tidySearch($text) {
require_once dirname(__FILE__) . '/SpellCheck.php';
$speller = new SpellCheck();
$return = $speller->tidy($text, ['replace' => true]);
return $return;
}
public function formatForHtml($script) {
if(! is_string($script) || ! strlen(trim($script))) {
return '';
}
$patterns = array(
'`((?:http|ftp|https):\/\/(?:[\w\-_]+(?:(?:\.[\w\-_]+)+))(?:[\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)`i'
=> '<a href="%s">link%s</a>',
'/(mailto[\\s]*:[\\s]*(?:[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}))/i'
=> ' <a href="%s">email</a>%s ',
'/([^:](?:[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}))/i'
=> ' <a href="mailto:%s">email</a>%s '
);
$replace = array();
$patternIndex = 0;
foreach($patterns as $pattern => $template) {
$matches = preg_split($pattern, $script, -1, PREG_SPLIT_DELIM_CAPTURE);
if(false === $matches) {
return $script;
}
$matchCount = count($matches);
if($matchCount > 1) {
// array_shift($matches);
for($index = 1; $index < $matchCount; $index += 2) {
if(0 == $patternIndex) {
$sequence = ($index > 1) ? ('-' . ($index - 1) / 2) : '' ;
}
$replace[] = sprintf($template, $matches[$index], $sequence);
$matches[$index] ='{{' . (count($replace) - 1) . '}}';
}
$script = implode('', $matches);
}
if(0 == $patternIndex) {
$sequence = '';
}
$patternIndex++;
}
if(count($replace)) {
$script = htmlentities($script);
for($index = 0; $index < count($replace); $index++) {
$script = str_replace('{{' . $index . '}}', $replace[$index], $script);
}
}
return $script;
}
public function getLayoutRelativePath() {
$path = "/classifiedsTemplates/". $this->getLayoutTemplate();
return $path;
}
public function getLayoutTemplatePath() {
$path = $this->getLayoutPath() . '/' . $this->getLayoutTemplate();
return $path;
}
public function getLayoutTemplateFilePath() {
$path = $this->getLayoutTemplatePath() . "/layoutTemplate.php";
return $path;
}
public function getDocumentRoot() {
// /home/procompu/public_html/classifiedsTemplates/Application.php
// /home/procompu/public_html/classifiedsTemplates
// /home/procompu/public_html
if(defined('DOCUMENT_ROOT')) {
$path = DOCUMENT_ROOT;
}
else {
$path = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT');
}
return $path;
}
protected function _getRequestValue($paramName, $default = '') {
$value = isset($_POST[$paramName]) ? $_POST[$paramName] : null;
$return = (is_string($value) && strlen(trim($value))) ? $value : $default;
return $return;
}
public function getFormAction() {
return $this->_formAction;
}
public function setFormAction($action) {
$this->_formAction = $action;
return $this;
}
/**
*
* @return \DataMapper
*/
public function getMapper() {
if(! class_exists('DataMapper', false)) {
$file = dirname(__FILE__) . '/DataMapper.php';
require_once $file;
}
$mapper = new DataMapper();
return $mapper;
}
public function getMessagesHtml($class = 'errorlist') {
$messages = $this->getMessages();
if(! count($messages)) {
return '';
}
if(strlen($class)) {
$class = ' class ="' . $class . '"';
}
$return = "<ul{$class}><li>" . implode("</li>\n<li>", $messages) . "</li>\n</ul>";
return $return;
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for git.master , git.master_jit , rfc.property-hooks Warning: require_once(/in/Common.php): Failed to open stream: No such file or directory in /in/lNQdL on line 3
Fatal error: Uncaught Error: Failed opening required '/in/Common.php' (include_path='.:') in /in/lNQdL:3
Stack trace:
#0 {main}
thrown in /in/lNQdL on line 3
Process exited with code 255 . This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches Archived branches Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:dark mode live preview
43.94 ms | 401 KiB | 8 Q